:root {
  color-scheme: dark;
  --ink: #07100f;
  --ink-soft: rgba(9, 17, 17, 0.58);
  --text: #f5efe4;
  --muted: rgba(245, 239, 228, 0.72);
  --line: rgba(245, 239, 228, 0.18);
  --gold: #e8c568;
  --jade: #6ed7a8;
  --rose: #e47890;
  --sky: #78b9d6;
  --focus: #fff3bd;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body,
#app {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    linear-gradient(140deg, rgba(7, 16, 15, 0.92), rgba(22, 18, 28, 0.76)),
    var(--ink);
  color: var(--text);
  letter-spacing: 0;
}

button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.74rem 1rem;
  background: rgba(245, 239, 228, 0.08);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  letter-spacing: 0;
  cursor: pointer;
  backdrop-filter: blur(18px);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

button span {
  display: block;
  margin-top: 0.16rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 520;
}

button:hover,
button:focus-visible {
  border-color: rgba(255, 243, 189, 0.68);
  background: rgba(255, 243, 189, 0.16);
  outline: none;
  transform: translateY(-1px);
}

#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.start-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  text-align: center;
  transition:
    opacity 520ms ease,
    visibility 520ms ease;
}

.start-screen.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.home-controls {
  display: flex;
  justify-content: center;
  margin-top: 0.9rem;
}

.home-sound-toggle {
  min-width: 112px;
  min-height: 42px;
  padding: 0.5rem 0.72rem;
  border-color: rgba(255, 243, 189, 0.34);
  font-size: 0.82rem;
}

.home-sound-toggle span {
  font-size: 0.68rem;
}

.start-copy {
  width: calc(100vw - 2rem);
  max-width: 880px;
  margin: auto;
  text-shadow: 0 2px 28px rgba(0, 0, 0, 0.38);
}

.eyebrow {
  margin: 0 0 1rem;
  color: var(--jade);
  font-size: 0.84rem;
  font-weight: 740;
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 5rem, 5.2rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h1 small {
  display: block;
  margin-top: 0.58rem;
  color: rgba(245, 239, 228, 0.78);
  font-size: clamp(1.15rem, 2rem, 2.15rem);
  font-weight: 560;
}

.intro {
  width: 100%;
  max-width: 720px;
  margin: 1.65rem auto 0;
  color: rgba(245, 239, 228, 0.82);
  font-size: clamp(1rem, 1.08rem, 1.15rem);
  line-height: 1.82;
  line-break: auto;
  overflow-wrap: break-word;
  white-space: normal;
  word-break: normal;
}

.start-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 2rem;
}

.start-actions button {
  width: min(205px, 100%);
}

.primary-action {
  background: linear-gradient(135deg, rgba(232, 197, 104, 0.24), rgba(110, 215, 168, 0.18));
  border-color: rgba(232, 197, 104, 0.48);
}

.visualization-action {
  background: linear-gradient(135deg, rgba(120, 185, 214, 0.2), rgba(232, 197, 104, 0.18));
  border-color: rgba(120, 185, 214, 0.44);
}

.quiet-note {
  width: 100%;
  max-width: 720px;
  margin: 1.45rem auto 0;
  color: rgba(245, 239, 228, 0.62);
  font-size: 0.92rem;
  line-height: 1.65;
  line-break: auto;
  overflow-wrap: break-word;
  white-space: normal;
  word-break: normal;
}

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr);
  align-items: start;
  gap: 1rem;
  padding: max(0.8rem, env(safe-area-inset-top)) max(0.9rem, env(safe-area-inset-right)) 0
    max(0.9rem, env(safe-area-inset-left));
  pointer-events: none;
}

.hud-group,
.session-panel {
  width: fit-content;
  max-width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink-soft);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(22px);
}

.hud-group {
  padding: 0.76rem 0.88rem;
}

.hud-group p,
.session-panel p,
.hud-center p {
  margin: 0;
}

#stageLabel {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 740;
}

#breathLabel,
.session-panel p {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.hud-center {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  width: min(620px, calc(100vw - 2rem));
  max-width: 100%;
  pointer-events: none;
}

.breath-meter {
  --scale: 0.5;
  display: grid;
  place-items: center;
  width: 72px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 243, 189, 0.34);
  border-radius: 999px;
  background: rgba(245, 239, 228, 0.06);
  box-shadow:
    inset 0 0 22px rgba(255, 243, 189, 0.08),
    0 0 30px rgba(110, 215, 168, 0.13);
  backdrop-filter: blur(18px);
}

.breath-meter span {
  width: calc(30px + (26px * var(--scale)));
  aspect-ratio: 1;
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(255, 243, 189, 0.9), rgba(232, 197, 104, 0.32) 52%, transparent 72%),
    rgba(255, 243, 189, 0.24);
  box-shadow: 0 0 34px rgba(255, 243, 189, 0.42);
  transition: width 220ms linear;
}

#promptLabel {
  width: 100%;
  max-width: min(620px, calc(100vw - 2rem));
  padding: 0.56rem 0.72rem;
  border: 1px solid rgba(245, 239, 228, 0.12);
  border-radius: 8px;
  background: rgba(9, 17, 17, 0.38);
  color: rgba(245, 239, 228, 0.86);
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: center;
  overflow-wrap: anywhere;
  white-space: pre-line;
  backdrop-filter: blur(18px);
}

.control-group {
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.46rem;
  pointer-events: auto;
}

.control-group button {
  min-width: 72px;
  min-height: 42px;
  padding: 0.46rem 0.58rem;
  font-size: 0.82rem;
}

.control-group button span {
  font-size: 0.68rem;
}

.menu-toggle {
  display: none;
  pointer-events: auto;
}

.breath-sound-button {
  min-width: 118px;
  border-color: rgba(120, 185, 214, 0.38);
}

.home-button {
  border-color: rgba(110, 215, 168, 0.38);
}

.guide-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: rgba(7, 16, 15, 0.45);
  pointer-events: auto;
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.guide-card {
  width: min(720px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  border: 1px solid rgba(255, 243, 189, 0.3);
  border-radius: 8px;
  padding: clamp(1rem, 3vw, 1.7rem);
  background: rgba(9, 17, 17, 0.78);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(24px);
}

.guide-card h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.4rem, 4vw, 2rem);
  line-height: 1.2;
  letter-spacing: 0;
  text-align: center;
}

.guide-subtitle {
  margin: 0.62rem auto 1rem;
  max-width: 580px;
  color: rgba(245, 239, 228, 0.8);
  font-size: 0.96rem;
  line-height: 1.55;
  text-align: center;
}

.guide-body {
  min-height: 0;
  max-height: min(48vh, 430px);
  overflow-y: auto;
  padding: 0.15rem 0.45rem 0.15rem 0;
  scrollbar-color: rgba(255, 243, 189, 0.45) rgba(245, 239, 228, 0.08);
}

.guide-body h3 {
  margin: 0.9rem 0 0.36rem;
  color: var(--jade);
  font-size: 1rem;
  line-height: 1.3;
}

.guide-body h3:first-child {
  margin-top: 0;
}

.guide-body p,
.guide-body li {
  color: rgba(245, 239, 228, 0.78);
  font-size: 0.93rem;
  line-height: 1.55;
}

.guide-body p {
  margin: 0.22rem 0;
}

.guide-body ul {
  margin: 0;
  padding-left: 1.2rem;
}

.guide-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.72rem;
  margin-top: 1.15rem;
}

.guide-actions button {
  min-width: 150px;
}

.session-panel {
  position: fixed;
  left: max(0.9rem, env(safe-area-inset-left));
  bottom: max(0.9rem, env(safe-area-inset-bottom));
  padding: 0.72rem 0.86rem;
  pointer-events: none;
}

.session-panel p:first-child {
  margin-top: 0;
  color: rgba(245, 239, 228, 0.86);
}

#timeLabel.is-warning {
  color: var(--focus);
  font-weight: 740;
}

.score-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: rgba(7, 16, 15, 0.5);
  pointer-events: auto;
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.score-card {
  width: min(520px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  border: 1px solid rgba(255, 243, 189, 0.32);
  border-radius: 8px;
  padding: clamp(1.2rem, 4vw, 2rem);
  background: rgba(9, 17, 17, 0.78);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  text-align: center;
  backdrop-filter: blur(24px);
}

.score-card .eyebrow {
  margin-bottom: 0.65rem;
}

.score-card h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.35rem, 4vw, 2rem);
  line-height: 1.2;
  letter-spacing: 0;
}

#scoreValue {
  margin: 0.72rem 0 0;
  color: var(--focus);
  font-size: clamp(3.2rem, 14vw, 5.8rem);
  font-weight: 800;
  line-height: 0.98;
}

#scoreSummary {
  margin: 0.78rem auto 0;
  max-width: 430px;
  color: rgba(245, 239, 228, 0.82);
  font-size: 0.98rem;
  line-height: 1.55;
}

.score-details {
  display: grid;
  gap: 0.42rem;
  margin: 1rem auto 1.25rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.42;
}

.score-details p {
  margin: 0;
}

.score-card button {
  min-width: 150px;
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  h1 {
    font-size: 2.7rem;
  }

  h1 small {
    font-size: 1.18rem;
  }

  .start-copy {
    width: min(300px, calc(100vw - 2rem));
  }

  .intro {
    max-width: 300px;
    font-size: 0.96rem;
    line-height: 1.7;
  }

  .quiet-note {
    max-width: 300px;
    font-size: 0.88rem;
  }

  .start-actions {
    display: grid;
  }

  .start-actions button {
    width: min(300px, calc(100vw - 2rem));
  }

  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    justify-items: stretch;
    gap: 0.48rem;
    padding: max(0.7rem, env(safe-area-inset-top)) max(0.7rem, env(safe-area-inset-right)) 0
      max(0.7rem, env(safe-area-inset-left));
  }

  .status-group {
    justify-self: start;
    max-width: calc(100vw - 8.6rem);
  }

  .menu-toggle {
    display: block;
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    min-width: 106px;
    min-height: 42px;
    padding: 0.44rem 0.56rem;
    border-color: rgba(255, 243, 189, 0.38);
    background: rgba(9, 17, 17, 0.62);
    font-size: 0.78rem;
    line-height: 1.15;
  }

  .menu-toggle span {
    font-size: 0.62rem;
  }

  .control-group {
    position: fixed;
    top: calc(max(0.7rem, env(safe-area-inset-top)) + 3.2rem);
    right: max(0.7rem, env(safe-area-inset-right));
    z-index: 8;
    display: none;
    width: min(230px, calc(100vw - 1.4rem));
    grid-template-columns: 1fr;
    justify-content: stretch;
    justify-self: auto;
    gap: 0.46rem;
    order: 3;
  }

  .hud.menu-open .control-group {
    display: grid;
  }

  .control-group button {
    min-width: 0;
    width: 100%;
  }

  .hud-center {
    grid-column: 1 / -1;
    order: 2;
  }

  .breath-meter {
    width: 58px;
  }

  #promptLabel {
    font-size: 0.82rem;
  }

  .session-panel {
    right: max(0.9rem, env(safe-area-inset-right));
    width: auto;
    max-width: none;
    display: grid;
    gap: 0.14rem;
    padding: 0.56rem 0.62rem;
  }

  .session-panel p {
    margin-top: 0;
    font-size: 0.68rem;
    overflow-wrap: anywhere;
  }

  .guide-card {
    width: min(350px, calc(100vw - 1.5rem));
  }

  .guide-body {
    max-height: 42vh;
  }

  .guide-actions {
    display: grid;
  }

  .score-card {
    width: min(340px, calc(100vw - 1.5rem));
  }

  .score-details {
    font-size: 0.8rem;
  }
}

@media (max-height: 680px) {
  .score-card {
    padding: 1rem;
  }

  .score-card .eyebrow {
    margin-bottom: 0.42rem;
  }

  #scoreValue {
    margin-top: 0.4rem;
    font-size: 3.3rem;
  }

  #scoreSummary {
    margin-top: 0.48rem;
    font-size: 0.9rem;
  }

  .score-details {
    margin: 0.62rem auto 0.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
