:root {
  color-scheme: dark;
  --bg: #07120f;
  --panel: #102018;
  --panel-2: #172c22;
  --line: rgba(204, 245, 206, 0.26);
  --text: #f8fff8;
  --muted: #c0dcc7;
  --leaf: #7de38d;
  --gold: #f6d35f;
  --water: #6bd6ff;
  --coral: #ff8a65;
  --purple: #b084f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #0f332b 0%, #07120f 42%, #08110d 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overflow-x: hidden;
}

body[data-view="game"] {
  background: #020807;
  overflow: hidden;
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
}

.runner-shell {
  display: grid;
  gap: clamp(12px, 2vw, 18px);
  min-height: 100vh;
  padding: clamp(10px, 1.8vw, 22px);
}

body[data-view="game"] .runner-shell {
  display: block;
  padding: 0;
}

.map-home,
.runner-card,
.hud,
.control-row,
.grownup-panel,
.prompt-row article {
  border: 1px solid var(--line);
  border-radius: 8px;
}

.map-home {
  backdrop-filter: blur(18px) saturate(1.14);
  -webkit-backdrop-filter: blur(18px) saturate(1.14);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 30%),
    radial-gradient(circle at 84% 20%, rgba(107, 214, 255, 0.12), transparent 26%),
    linear-gradient(180deg, rgba(11, 30, 22, 0.74), rgba(7, 18, 15, 0.86));
  display: grid;
  gap: clamp(10px, 1.4vw, 16px);
  margin: 0 auto;
  max-width: 1220px;
  padding: clamp(12px, 1.8vw, 18px);
  width: 100%;
}

body[data-view="game"] .map-home {
  display: none;
}

.map-copy {
  align-items: start;
  display: grid;
  gap: 7px;
  grid-template-columns: minmax(0, 1fr);
  padding: 4px clamp(4px, 1vw, 10px);
}

.eyebrow {
  color: var(--leaf);
  font-size: 0.78rem;
  font-weight: 950;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.05rem, 4.2vw, 3.75rem);
  line-height: 0.96;
}

h2 {
  font-size: clamp(1.3rem, 2.5vw, 2.25rem);
  line-height: 1;
}

.lede {
  color: var(--muted);
  font-size: clamp(1rem, 1.55vw, 1.22rem);
  font-weight: 850;
  justify-self: start;
  line-height: 1.25;
  max-width: 38ch;
}

.map-board {
  aspect-ratio: 16 / 9;
  background: #0d241c;
  border: 1px solid rgba(246, 211, 95, 0.38);
  border-radius: 8px;
  box-shadow:
    0 22px 80px rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  counter-reset: stop;
  min-height: 330px;
  overflow: hidden;
  position: relative;
}

.map-board::after {
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  content: "";
  inset: 8px;
  pointer-events: none;
  position: absolute;
}

.map-board::before {
  background:
    linear-gradient(180deg, rgba(6, 19, 15, 0), rgba(6, 19, 15, 0.08)),
    radial-gradient(circle at 52% 52%, transparent 0 34%, rgba(8, 21, 15, 0.16) 72%);
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
  z-index: 1;
}

.map-art {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.map-node {
  --node-color: var(--gold);
  align-items: center;
  backdrop-filter: blur(18px) saturate(1.35);
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.28), transparent 22%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05) 46%, rgba(7, 18, 15, 0.28)),
    color-mix(in srgb, var(--node-color), transparent 82%);
  border: 1px solid rgba(255, 255, 255, 0.54);
  box-shadow:
    0 14px 32px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    inset 4px 0 0 color-mix(in srgb, var(--node-color), white 10%),
    inset 0 -18px 30px rgba(7, 18, 15, 0.16);
  color: var(--text);
  counter-increment: stop;
  display: grid;
  gap: 3px;
  grid-template-columns: minmax(0, 1fr);
  justify-items: start;
  min-height: clamp(46px, 5.2vw, 58px);
  padding: 7px 10px 7px 12px;
  position: absolute;
  transform: translate(-50%, -50%);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
  width: clamp(104px, 10vw, 132px);
  z-index: 2;
}

.map-node::before {
  align-items: center;
  backdrop-filter: blur(10px) saturate(1.25);
  -webkit-backdrop-filter: blur(10px) saturate(1.25);
  background: rgba(255, 247, 214, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 999px;
  color: #07120f;
  content: counter(stop);
  display: grid;
  font-size: 0.58rem;
  font-weight: 950;
  height: 18px;
  left: -8px;
  line-height: 1;
  place-items: center;
  position: absolute;
  top: -8px;
  width: 18px;
}

.map-node:hover,
.map-node:focus-visible,
.map-node.is-active {
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.42), transparent 24%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.08) 46%, rgba(7, 18, 15, 0.2)),
    color-mix(in srgb, var(--node-color), transparent 68%);
  border-color: rgba(255, 255, 255, 0.86);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.32),
    0 0 0 4px color-mix(in srgb, var(--node-color), transparent 68%),
    inset 0 1px 0 rgba(255, 255, 255, 0.74),
    inset 4px 0 0 color-mix(in srgb, var(--node-color), white 8%);
  color: var(--text);
  outline: 0;
  transform: translate(-50%, -50%) scale(1.035);
}

.map-node.is-complete {
  border-color: var(--gold);
}

.map-node.is-complete::after {
  align-items: center;
  background: var(--gold);
  border: 2px solid #07120f;
  border-radius: 999px;
  color: #07120f;
  content: "done";
  display: grid;
  font-size: 0.68rem;
  font-weight: 950;
  height: 28px;
  line-height: 1;
  padding: 0 7px;
  position: absolute;
  right: -8px;
  top: -10px;
}

.node-icon {
  display: none;
}

.map-node strong {
  font-size: clamp(0.72rem, 0.88vw, 0.86rem);
  line-height: 1.02;
  text-align: left;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}

.node-label {
  color: rgba(248, 255, 248, 0.84);
  font-size: clamp(0.58rem, 0.7vw, 0.68rem);
  font-weight: 900;
  line-height: 1;
  text-align: left;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.48);
}

.map-node:hover .node-label,
.map-node:focus-visible .node-label,
.map-node.is-active .node-label {
  color: var(--text);
}

.map-node-shapes {
  --node-color: var(--coral);
  left: 16%;
  top: 48%;
}

.map-node-letters {
  --node-color: #67d7d0;
  left: 32%;
  top: 20%;
}

.map-node-syllables {
  --node-color: #8be8ff;
  left: 32%;
  top: 43%;
}

.map-node-families {
  --node-color: #ffd166;
  left: 39%;
  top: 31%;
}

.map-node-bubbles {
  --node-color: #9cefff;
  left: 22%;
  top: 70%;
}

.map-node-numbers {
  --node-color: var(--gold);
  left: 49%;
  top: 45%;
}

.map-node-lanes {
  --node-color: #a7f070;
  left: 49%;
  top: 26%;
}

.map-node-river {
  --node-color: #6bd6ff;
  left: 61%;
  top: 28%;
}

.map-node-patterns {
  --node-color: var(--purple);
  left: 47%;
  top: 67%;
}

.map-node-emotions {
  --node-color: #9ee66f;
  left: 77%;
  top: 51%;
}

.map-node-memory {
  --node-color: #8cc8ff;
  left: 80%;
  top: 20%;
}

.map-node-survival {
  --node-color: #ff6f59;
  left: 78%;
  top: 68%;
}

.map-node-spinner {
  --node-color: #6bd6ff;
  left: 63%;
  top: 70%;
}

.map-node-tunnel {
  --node-color: #b87342;
  left: 58%;
  top: 47%;
}

.runner-card {
  background: rgba(8, 17, 13, 0.76);
  display: grid;
  gap: 10px;
  padding: 10px;
}

body[data-view="map"] .runner-card {
  display: none;
}

body[data-view="game"] .runner-card {
  background: #020807;
  border: 0;
  border-radius: 0;
  inset: 0;
  display: block;
  height: 100vh;
  overflow: hidden;
  padding: 0;
  position: fixed;
  z-index: 10;
}

.back-map-button {
  background: var(--gold);
  color: #07120f;
  min-height: 48px;
  min-width: 84px;
}

.scholar-progress,
.certificate-panel {
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04)),
    rgba(16, 32, 24, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  box-shadow:
    0 14px 32px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.scholar-progress {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  padding: 10px 12px;
}

.scholar-progress span {
  color: var(--muted);
  font-weight: 900;
}

.scholar-progress strong {
  color: var(--gold);
  font-size: 1.18rem;
}

.certificate-panel {
  border-color: rgba(246, 211, 95, 0.72);
  display: grid;
  gap: 6px;
  padding: 14px;
}

.certificate-panel[hidden] {
  display: none;
}

.hud {
  align-items: center;
  background: rgba(16, 32, 24, 0.9);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(230px, 1fr) auto;
  padding: 12px;
}

body[data-view="game"] .hud {
  backdrop-filter: blur(10px);
  background: linear-gradient(90deg, rgba(8, 21, 15, 0.88), rgba(8, 21, 15, 0.52));
  border-color: rgba(232, 255, 212, 0.22);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.24);
  grid-template-columns: minmax(290px, 0.9fr) minmax(360px, 0.72fr);
  left: 16px;
  padding: 10px 12px;
  position: absolute;
  right: 16px;
  top: 14px;
  z-index: 6;
}

.mission {
  display: grid;
  gap: 5px;
}

#instructionText,
#statusText,
.prompt-row p {
  color: var(--muted);
}

.stats {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(76px, 1fr));
}

.stats div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 2px;
  min-height: 60px;
  padding: 8px 10px;
  text-align: center;
}

.stats span,
.panel-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stats strong {
  color: var(--gold);
  font-size: clamp(1rem, 1.8vw, 1.5rem);
  line-height: 1.05;
  word-break: break-word;
}

.stage-wrap {
  display: grid;
  overflow: hidden;
  position: relative;
}

body[data-view="game"] .stage-wrap {
  inset: 0;
  place-items: center;
  position: absolute;
}

canvas {
  aspect-ratio: 16 / 9;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  display: block;
  touch-action: none;
  width: 100%;
}

body[data-view="game"] canvas {
  align-self: center;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  height: max(100vh, calc(100vw * 9 / 16));
  justify-self: center;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max(100vw, calc(100vh * 16 / 9));
}

.tunnel-canvas {
  background: #150c07;
  inset: 0;
  position: absolute;
  z-index: 1;
}

.tunnel-canvas[hidden],
#gameCanvas[hidden] {
  display: none;
}

.stage-overlay {
  align-items: center;
  background:
    radial-gradient(circle at 50% 48%, rgba(5, 12, 9, 0.18) 0 130px, rgba(5, 12, 9, 0.06) 260px),
    linear-gradient(180deg, rgba(5, 12, 9, 0.12), rgba(5, 12, 9, 0.5));
  border-radius: 8px;
  cursor: pointer;
  display: none;
  inset: 1px;
  justify-items: center;
  padding: 18px;
  place-content: center;
  position: absolute;
  text-align: center;
  z-index: 5;
}

.stage-overlay:focus-visible {
  outline: 3px solid var(--water);
  outline-offset: -6px;
}

.stage-overlay.show {
  display: grid;
}

.stage-overlay strong {
  color: var(--gold);
  font-size: clamp(1.35rem, 3.2vw, 2.6rem);
  filter: drop-shadow(0 3px 0 rgba(5, 12, 9, 0.68));
  margin-bottom: 8px;
}

.stage-overlay span {
  color: var(--text);
  font-weight: 900;
  margin-bottom: 16px;
  max-width: 30ch;
}

.stage-start-button {
  background: var(--gold);
  border: 3px solid rgba(255, 255, 255, 0.88);
  box-shadow:
    0 14px 38px rgba(0, 0, 0, 0.34),
    0 0 0 8px rgba(246, 211, 95, 0.18);
  color: #07120f;
  font-size: clamp(1.2rem, 2.4vw, 2rem);
  min-height: 74px;
  min-width: 240px;
  padding: 0 34px;
}

.stage-start-button:hover,
.stage-start-button:focus-visible {
  background: #ffe377;
  outline: 0;
  transform: translateY(-1px) scale(1.03);
}

.control-row {
  align-items: center;
  background: rgba(16, 32, 24, 0.9);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
}

body[data-view="game"] .control-row {
  backdrop-filter: blur(10px);
  background: rgba(8, 21, 15, 0.78);
  border-color: rgba(232, 255, 212, 0.22);
  bottom: 14px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.3);
  left: 16px;
  padding: 10px;
  position: absolute;
  right: 16px;
  z-index: 6;
}

.control-row button {
  background: var(--leaf);
  color: #06200f;
  display: grid;
  min-height: 48px;
  padding: 0 18px;
  place-items: center;
}

#resetButton {
  background: var(--gold);
}

.control-row .back-map-button {
  background: var(--gold);
  color: #07120f;
}

#speakButton {
  background: var(--water);
}

#jumpButton,
#duckButton,
#boostButton,
#brakeButton {
  background: #213c30;
  color: var(--text);
}

#boostButton {
  background: var(--water);
  color: #06200f;
}

#brakeButton {
  background: var(--purple);
  color: #07120f;
}

.phone-controls {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(58px, 1fr));
}

.phone-controls button {
  background: #213c30;
  color: var(--text);
}

body[data-style="phone"] .runner-control {
  display: none;
}

body[data-style="runner"] .phone-controls,
body[data-style="slither"] .phone-controls,
body[data-style="slither"] .runner-control {
  display: none;
}

body[data-mode="spinner"] #jumpButton,
body[data-mode="spinner"] .ramp-control,
body[data-mode="tunnel"] .phone-controls {
  display: grid;
}

body[data-mode="spinner"] #duckButton {
  display: none;
}

#statusText {
  flex: 1;
  font-weight: 800;
  min-width: 240px;
}

.floating-feedback {
  color: var(--gold);
  filter: drop-shadow(0 3px 0 rgba(6, 19, 15, 0.7));
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  font-weight: 950;
  left: 0;
  pointer-events: none;
  position: absolute;
  text-align: center;
  top: 0;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  z-index: 3;
  animation: floatUp 950ms ease-out forwards;
}

@keyframes floatUp {
  to {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 76px)) scale(1.08);
  }
}

.grownup-panel {
  background: rgba(16, 32, 24, 0.7);
  padding: 0;
}

body[data-view="game"] .grownup-panel {
  display: none;
}

.grownup-panel summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
  padding: 12px 14px;
}

.prompt-row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 0 10px 10px;
}

.prompt-row article {
  background: rgba(20, 39, 30, 0.9);
  display: grid;
  gap: 6px;
  min-height: 84px;
  padding: 10px 12px;
}

@media (max-width: 980px) {
  .hud {
    grid-template-columns: 1fr;
  }

  .map-board {
    min-height: 420px;
  }

  .map-node {
    width: clamp(96px, 16vw, 124px);
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  body[data-view="game"] {
    overflow: hidden;
  }

  .runner-shell {
    padding: 8px;
  }

  body[data-view="game"] .runner-card {
    gap: 8px;
    grid-template-rows: auto auto auto auto;
    overflow-y: auto;
    padding: 8px;
  }

  body[data-view="game"] .hud {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px;
  }

  body[data-view="game"] .mission {
    gap: 2px;
  }

  body[data-view="game"] .eyebrow {
    font-size: 1rem;
  }

  body[data-view="game"] h2 {
    font-size: 1.28rem;
  }

  body[data-view="game"] #instructionText {
    display: none;
  }

  body[data-view="game"] .stats {
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body[data-view="game"] .stats div {
    gap: 3px;
    min-height: 64px;
    padding: 7px 8px;
  }

  body[data-view="game"] .stats span {
    font-size: 1rem;
  }

  body[data-view="game"] .stats strong {
    font-size: 1.5rem;
  }

  body[data-view="game"] .stage-wrap {
    min-height: 0;
  }

  body[data-view="game"] canvas {
    height: max(100vh, calc(100vw * 9 / 16));
    width: max(100vw, calc(100vh * 16 / 9));
  }

  body[data-view="game"] .stage-overlay strong {
    font-size: clamp(1.15rem, 6vw, 1.65rem);
  }

  body[data-view="game"] .stage-overlay span {
    max-width: 24ch;
  }

  body[data-view="game"] .control-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body[data-mode="tunnel"] .phone-controls {
    grid-column: 1 / -1;
  }

  body[data-view="game"] #statusText {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .map-copy {
    padding: 0;
  }

  .map-board {
    aspect-ratio: 9 / 13;
    min-height: 0;
  }

  .map-art {
    object-position: center;
  }

  .map-node {
    min-height: 48px;
    padding: 6px 8px;
    width: 86px;
  }

  .map-node strong {
    font-size: 0.66rem;
  }

  .node-label {
    display: none;
  }

  .map-node-shapes {
    left: 23%;
    top: 38%;
  }

  .map-node-letters {
    left: 36%;
    top: 18%;
  }

  .map-node-syllables {
    left: 34%;
    top: 33%;
  }

  .map-node-families {
    left: 58%;
    top: 19%;
  }

  .map-node-bubbles {
    left: 25%;
    top: 70%;
  }

  .map-node-numbers {
    left: 54%;
    top: 45%;
  }

  .map-node-lanes {
    left: 44%;
    top: 27%;
  }

  .map-node-river {
    left: 74%;
    top: 33%;
  }

  .map-node-patterns {
    left: 49%;
    top: 62%;
  }

  .map-node-emotions {
    left: 76%;
    top: 46%;
  }

  .map-node-memory {
    left: 76%;
    top: 24%;
  }

  .map-node-survival {
    left: 75%;
    top: 66%;
  }

  .map-node-spinner {
    left: 58%;
    top: 73%;
  }

  .map-node-tunnel {
    left: 52%;
    top: 48%;
  }

  .prompt-row {
    grid-template-columns: 1fr;
  }

  .control-row button {
    flex: 1 1 44%;
  }

  .phone-controls {
    flex: 1 1 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
