:root {
  color-scheme: dark;
  --ink: #070b1d;
  --night: #0d1430;
  --panel: rgba(11, 20, 48, 0.84);
  --panel-solid: #111b3b;
  --line: rgba(182, 205, 255, 0.17);
  --muted: #9aaed5;
  --white: #f3f5ff;
  --amber: #ffc46b;
  --amber-hot: #ffe5a4;
  --teal: #68c9b1;
  --coral: #df786f;
  --stage-ratio: 16 / 9;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--ink);
}

* { box-sizing: border-box; }

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

body {
  min-width: 320px;
  overflow-x: hidden;
  color: var(--white);
  background:
    radial-gradient(circle at 79% 7%, rgba(75, 137, 153, 0.13), transparent 25rem),
    radial-gradient(circle at 12% 88%, rgba(53, 56, 128, 0.18), transparent 28rem),
    var(--ink);
}

button, kbd { font: inherit; }
button { color: inherit; }

.app-shell {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: clamp(14px, 2vw, 28px) clamp(14px, 3vw, 52px) 16px;
}

.topbar, .footer-note {
  width: min(1440px, 100%);
  margin-inline: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 15px;
  border-bottom: 1px solid var(--line);
  letter-spacing: 0.035em;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.wordmark-mark, .spark-icon, .seed-icon { display: inline-grid; place-items: center; }

.wordmark-mark {
  width: 14px;
  height: 18px;
  border: 1px solid var(--amber);
  border-radius: 8px 8px 5px 5px;
  box-shadow: 0 0 15px rgba(255, 196, 107, 0.62);
  transform: rotate(45deg) scale(0.72);
}

.sound-toggle, .text-button {
  border: 0;
  padding: 5px 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sound-toggle:hover, .sound-toggle:focus-visible, .text-button:hover, .text-button:focus-visible { color: var(--amber-hot); }

.game-shell {
  width: min(1440px, 100%);
  flex: 1;
  display: grid;
  place-items: center;
  margin: 0 auto;
  padding: clamp(14px, 3vh, 28px) 0;
}

.stage {
  position: relative;
  isolation: isolate;
  width: min(100%, calc((100svh - 145px) * 16 / 9));
  aspect-ratio: var(--stage-ratio);
  overflow: hidden;
  border: 1px solid rgba(173, 206, 255, 0.22);
  border-radius: 16px;
  background: #101b3d;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.42), 0 0 0 5px rgba(101, 151, 192, 0.04);
}

.stage::before, .stage::after {
  content: "";
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}

.stage::before { border: 1px solid rgba(255, 235, 184, 0.06); border-radius: inherit; }
.stage::after { background: linear-gradient(180deg, rgba(4, 6, 18, 0.12), transparent 28%, transparent 75%, rgba(3, 6, 16, 0.26)); }

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 6;
  inset: 18px 20px auto;
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(160px, 1fr) minmax(280px, 1.6fr);
  align-items: center;
  gap: 22px;
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.54);
}

.hud-chapter, .hud-progress { display: flex; flex-direction: column; gap: 4px; }
.hud-overline, .eyebrow { color: var(--amber); font-size: 0.62rem; letter-spacing: 0.19em; text-transform: uppercase; }
.hud-chapter strong { font-size: 0.82rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; }
.hud-progress { max-width: 240px; }
.progress-label { color: rgba(243, 245, 255, 0.75); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; }
.progress-track { height: 3px; overflow: hidden; border-radius: 99px; background: rgba(243, 245, 255, 0.18); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--amber)); box-shadow: 0 0 12px rgba(255, 196, 107, 0.65); transition: width 160ms ease-out; }

.hud-right { display: flex; align-items: center; justify-content: flex-end; gap: 13px; }
.spark-count, .seed-count, .pulse-meter, .dash-meter { display: flex; align-items: center; gap: 6px; min-height: 24px; padding: 5px 8px; border: 1px solid rgba(206, 221, 255, 0.17); border-radius: 999px; background: rgba(8, 13, 32, 0.42); color: rgba(243, 245, 255, 0.86); font-size: 0.67rem; letter-spacing: 0.08em; text-transform: uppercase; }
.spark-icon { width: 9px; height: 9px; border: 1px solid var(--amber-hot); border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.seed-icon { color: var(--amber); font-size: 0.88rem; text-shadow: 0 0 10px var(--amber); }
.pulse-meter { color: var(--amber-hot); }
.dash-meter { color: var(--teal); }

.loading-card {
  position: absolute;
  z-index: 8;
  inset: 50% auto auto 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.loading-orb { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 18px var(--amber); animation: breathe 1.2s ease-in-out infinite; }

.screen-panel {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  align-items: center;
  padding: clamp(30px, 7vw, 104px);
  background: linear-gradient(90deg, rgba(7, 11, 29, 0.86), rgba(7, 11, 29, 0.55) 55%, rgba(7, 11, 29, 0.13));
}

.screen-copy { width: min(470px, 100%); }
.screen-copy h1, .screen-copy h2 { margin: 7px 0 14px; color: var(--white); font-size: clamp(3rem, 8vw, 7rem); font-weight: 600; letter-spacing: -0.075em; line-height: 0.9; }
.screen-copy h2 { font-size: clamp(2.5rem, 5vw, 5.2rem); }
.lede { max-width: 390px; margin: 0 0 26px; color: rgba(234, 239, 255, 0.8); font-size: clamp(0.9rem, 1.35vw, 1.08rem); line-height: 1.65; }

.primary-button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid rgba(255, 229, 164, 0.75);
  border-radius: 999px;
  background: linear-gradient(120deg, #ffc46b, #f3a967);
  color: #101329;
  cursor: pointer;
  box-shadow: 0 7px 26px rgba(255, 185, 100, 0.2);
  font-size: 0.77rem;
  font-weight: 720;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}

.primary-button:hover, .primary-button:focus-visible { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(255, 195, 107, 0.34); filter: brightness(1.06); }
.primary-button:active { transform: translateY(0); }
.text-button { display: block; margin: 18px 0 0; }

.control-row { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 30px; color: rgba(234, 239, 255, 0.56); font-size: 0.68rem; letter-spacing: 0.045em; text-transform: uppercase; }
kbd { display: inline-block; min-width: 20px; margin-right: 4px; padding: 3px 5px; border: 1px solid rgba(234, 239, 255, 0.25); border-bottom-width: 2px; border-radius: 4px; color: rgba(243, 245, 255, 0.88); font-size: 0.6rem; line-height: 1; text-align: center; text-transform: none; }

.title-rune { position: absolute; right: 12%; top: 23%; width: min(26vw, 250px); aspect-ratio: 1; opacity: 0.7; transform: rotate(45deg); }
.title-rune::before, .title-rune::after, .title-rune span, .title-rune i, .title-rune b { content: ""; position: absolute; inset: 12%; border: 1px solid rgba(255, 218, 138, 0.46); border-radius: 50%; box-shadow: 0 0 22px rgba(255, 196, 107, 0.22); }
.title-rune::after { inset: 29%; border-color: rgba(105, 201, 178, 0.56); }
.title-rune span { inset: 44%; border-radius: 0; background: var(--amber); box-shadow: 0 0 32px 8px rgba(255, 196, 107, 0.5); }
.title-rune i { inset: 2%; border-radius: 0; border-color: rgba(111, 151, 229, 0.24); }
.title-rune b { inset: 50%; border-radius: 0; border-color: var(--teal); transform: scale(4.6); }

.pause-screen, .chapter-screen, .complete-screen { place-items: center; text-align: center; background: rgba(7, 11, 29, 0.7); backdrop-filter: blur(7px); }
.pause-screen .screen-copy, .chapter-screen .screen-copy, .complete-screen .screen-copy { display: grid; justify-items: center; }
.pause-screen .lede, .chapter-screen .lede, .complete-screen .lede { max-width: 430px; }
.completion-note { margin: 22px 0 0; color: var(--muted); font-size: 0.7rem; letter-spacing: 0.13em; text-transform: uppercase; }

.hint-toast {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: 21px;
  max-width: min(90%, 430px);
  padding: 9px 14px;
  border: 1px solid rgba(255, 220, 147, 0.23);
  border-radius: 999px;
  background: rgba(8, 13, 32, 0.66);
  color: rgba(243, 245, 255, 0.82);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.hint-toast.is-visible { transform: translate(-50%, 0); opacity: 1; }

.crossfade { position: absolute; z-index: 20; inset: 0; background: var(--ink); pointer-events: none; opacity: 0; }
.crossfade.is-active { animation: crossfade 1.4s ease both; }

.touch-controls { position: absolute; z-index: 9; inset: auto 14px 14px; display: none; justify-content: space-between; align-items: end; pointer-events: none; }
.touch-cluster { display: flex; gap: 10px; pointer-events: auto; }
.touch-cluster button { width: 54px; height: 48px; border: 1px solid rgba(224, 233, 255, 0.28); border-radius: 15px; background: rgba(8, 13, 32, 0.58); color: rgba(243, 245, 255, 0.86); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.24); cursor: pointer; font-size: 1.05rem; touch-action: none; user-select: none; -webkit-user-select: none; }
.touch-actions button:first-child { color: var(--amber); }
.touch-actions button:last-child { color: var(--teal); }
.touch-cluster button.is-held, .touch-cluster button:active { border-color: var(--amber); background: rgba(255, 196, 107, 0.2); transform: translateY(1px); }

.footer-note { display: flex; justify-content: space-between; padding-top: 8px; color: rgba(154, 174, 213, 0.6); font-size: 0.62rem; letter-spacing: 0.12em; text-transform: uppercase; }

[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--amber-hot); outline-offset: 4px; }

@keyframes breathe { 0%, 100% { opacity: 0.42; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.22); } }
@keyframes crossfade { 0% { opacity: 0; } 30%, 72% { opacity: 0.92; } 100% { opacity: 0; } }

@media (max-width: 920px) {
  .hud { grid-template-columns: 1fr auto; gap: 10px; }
  .hud-progress { display: none; }
  .hud-right { grid-column: 1 / -1; justify-content: flex-start; flex-wrap: wrap; }
  .stage { width: min(100%, calc((100svh - 165px) * 16 / 9)); }
}

@media (pointer: coarse), (max-width: 720px) {
  .app-shell { padding: 12px 10px 10px; }
  .topbar { padding-bottom: 11px; }
  .stage { width: 100%; border-radius: 12px; }
  .screen-panel { padding: 12px 16px; background: linear-gradient(90deg, rgba(7, 11, 29, 0.9), rgba(7, 11, 29, 0.62)); }
  .screen-copy h1 { margin-block: 3px 7px; font-size: clamp(2.2rem, 12.5vw, 3.6rem); }
  .screen-copy .lede { max-width: 320px; margin-bottom: 10px; font-size: 0.72rem; line-height: 1.3; }
  .screen-copy .primary-button { min-height: 34px; padding-inline: 12px; font-size: 0.64rem; }
  .title-rune { right: 7%; top: 18%; width: 38vw; opacity: 0.32; }
  .control-row { display: none; }
  .touch-controls { display: flex; }
  .footer-note { font-size: 0.56rem; }
  .footer-note span:last-child { display: none; }
}

@media (max-height: 600px) and (orientation: landscape) {
  .app-shell { padding-block: 8px; }
  .topbar { padding-bottom: 6px; }
  .game-shell { padding-block: 6px; }
  .stage { width: min(100%, calc((100svh - 80px) * 16 / 9)); }
  .screen-panel { padding: 18px 34px; }
  .screen-copy h1 { margin-block: 3px 8px; font-size: clamp(2.6rem, 9vw, 4.5rem); }
  .lede { margin-bottom: 14px; font-size: 0.78rem; }
  .control-row { margin-top: 16px; }
}

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