:root {
  color-scheme: dark;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background-color: #0c151d;
  color: #eef5f5;
  --panel: #14212b;
  --line: #30444f;
  --muted: #a8bcc5;
  --mint: #85ebd2;
  --gold: #f5cb79;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background: radial-gradient(ellipse at 80% 15%, #17323a 0%, transparent 58%);
}
button { font: inherit; }
button:focus-visible { outline: 3px solid #fff0ac; outline-offset: 3px; }
h1[tabindex="-1"]:focus { outline: none; } /* focused by script so screen readers announce it; not a control */
button:disabled { cursor: default; }
h1, h2, p { margin: 0; }

.site-header, main {
  width: min(1080px, 100% - 48px);
  margin-inline: auto;
}
.site-header {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.wordmark {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  padding: 0 5px 0 0;
  border: 0;
  background: transparent;
  color: #eef5f5;
  font-size: 0.96rem;
  font-weight: 760;
  letter-spacing: 0.035em;
  cursor: pointer;
}
main { padding-block: clamp(24px, 5vw, 58px) 38px; }
.stage { display: grid; gap: 16px; }
.stage[data-view='title'], .stage[data-view='result'] {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.65fr);
  align-items: center;
  gap: clamp(22px, 4vw, 50px);
  min-height: min(570px, 75vh);
}
.stage[data-view='game'] { width: min(100%, 830px); margin-inline: auto; }
.eyebrow {
  color: var(--mint);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.73rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.intro h1 {
  margin-top: 12px;
  font-size: clamp(4.25rem, 8.2vw, 6.65rem);
  font-weight: 840;
  line-height: 0.84;
  letter-spacing: -0.073em;
}
.intro h1 span { display: block; color: var(--mint); }
.intro-copy {
  max-width: 27ch;
  margin-top: 24px;
  color: var(--muted);
  font-size: clamp(1rem, 1.6vw, 1.18rem);
  line-height: 1.55;
}
.title-actions, .result-actions, .tutorial-actions, .run-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.title-actions, .result-actions { margin-top: 24px; }

.button {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 13px;
  border: 1px solid #47606b;
  border-radius: 8px;
  background: #1a2a35;
  color: #eaf5f5;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
}
.button:hover { background: #263d47; border-color: #78949d; }
.button.primary { background: var(--mint); color: #08241f; border-color: var(--mint); }
.button.primary:hover { background: #b6f6e7; border-color: #b6f6e7; }
.button.quiet { background: transparent; color: var(--muted); border-color: transparent; }
.button.quiet:hover { background: #1e323d; color: #eef5f5; }
.button:disabled { background: #25373d; color: #b3c4c4; border-color: #344b52; }

.map-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 18px 55px -24px #070c11;
}
.map-header, .map-footer {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 7px 14px;
  padding: 8px 14px;
}
.map-header .eyebrow { color: #b6cad0; }
.map-state {
  display: flex;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}
.map-state::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--mint); }
.map-state[data-paused='true']::before { background: var(--gold); }
.map-state[data-warning='true'] { color: #ffa4a4; }
.map-state[data-warning='true']::before { background: #ffa4a4; }
.board {
  position: relative;
  aspect-ratio: 3 / 2;
  border-block: 1px solid var(--line);
  background: #101c24;
}
canvas, .switches, .pause-cover { position: absolute; inset: 0; width: 100%; height: 100%; }
canvas { display: block; }
.switches { pointer-events: none; }
.switch {
  position: absolute;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #edfcf9;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
}
.switch[data-col='3'] { left: 25%; }
.switch[data-col='4'] { left: 33.333333%; }
.switch[data-col='5'] { left: 41.666667%; }
.switch[data-col='6'] { left: 50%; }
.switch[data-col='7'] { left: 58.333333%; }
.switch[data-col='8'] { left: 66.666667%; }
.switch[data-col='9'] { left: 75%; }
.switch[data-row='2'] { top: 25%; }
.switch[data-row='3'] { top: 37.5%; }
.switch[data-row='4'] { top: 50%; }
.switch[data-row='5'] { top: 62.5%; }
.switch[data-row='6'] { top: 75%; }
.switch span {
  display: grid;
  place-items: center;
  width: clamp(20px, 4.9vw, 30px);
  aspect-ratio: 1;
  border: 2px solid var(--mint);
  border-radius: 50%;
  background: #152832;
  font-family: ui-monospace, Consolas, monospace;
  font-size: clamp(0.67rem, 2.7vw, 0.85rem);
  font-weight: 800;
  transition: color 100ms ease, background-color 100ms ease;
}
.switch:hover span, .switch:focus-visible span { background: var(--mint); color: #132930; }
.switch[data-guide='true']::after {
  content: '';
  position: absolute;
  inset: 1px;
  border: 2px dashed var(--gold);
  border-radius: 50%;
  animation: guide 1.1s ease-in-out infinite alternate;
}
@keyframes guide { to { transform: scale(1.13); opacity: 0.55; } }

.legend { display: flex; align-items: center; flex-wrap: wrap; gap: 3px 15px; list-style: none; margin: 0; padding: 0; }
.legend li, .route-key { display: flex; align-items: center; gap: 5px; color: #d2e0e4; font-size: 0.77rem; }
.legend-mark { font-size: 1rem; line-height: 1; }
[data-signal='blue'] .legend-mark { color: #65c9f1; }
[data-signal='orange'] .legend-mark { color: #f4a555; }
[data-signal='violet'] .legend-mark { color: #e2a0e9; }
[data-signal='green'] .legend-mark { color: #64d7a0; }
.route-key { color: var(--muted); }
.route-key::before { content: ''; width: 17px; height: 3px; border-radius: 4px; background: var(--mint); }

.run-head, .run-foot, .tutorial, .picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 18px;
}
.run-head h1, .picker h1, .results h1 {
  font-size: clamp(1.65rem, 4.5vw, 3.05rem);
  line-height: 1.07;
  letter-spacing: -0.04em;
}
.run-head h1, .results h1 { margin-top: 3px; }
.scoreboard { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stat {
  display: flex;
  min-height: 44px;
  min-width: 61px;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-variant-numeric: tabular-nums;
}
.stat-label { color: var(--muted); font-size: 0.68rem; font-weight: 650; }
.stat strong { font-size: 1rem; line-height: 1.2; }
#lives[data-low='true'] { color: #ffa4a4; }
.run-foot p, .tutorial p { color: var(--muted); font-size: 0.89rem; line-height: 1.5; }
.run-foot .key-help { margin-top: 4px; font-size: 0.8rem; }
kbd { font-family: ui-monospace, Consolas, monospace; color: #e3f2f3; }
.tutorial {
  border: 1px solid #7b6948;
  border-radius: 11px;
  padding: 12px;
  background: #242925;
}
.tutorial h2 { color: #ffe5ad; font-size: 1.04rem; }
.tutorial p { margin-top: 3px; }
.pause-cover { display: grid; place-items: center; background: #0b141de0; }
.pause-card { display: grid; justify-items: center; gap: 12px; }
.pause-card h2 { font-size: 2rem; letter-spacing: -0.04em; }

.result-stars { margin-top: 12px; color: var(--gold); font-size: 1.7rem; letter-spacing: 0.12em; }
.result-summary { margin-top: 13px; color: #d6e3e6; }
.best { margin-top: 6px; color: var(--muted); font-size: 0.88rem; }
.picker { width: min(100%, 830px); margin-inline: auto; }
.level-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 232px), 1fr)); gap: 10px; margin-top: 20px; }
.level-card {
  min-height: 77px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: #edf5f5;
  text-align: left;
  cursor: pointer;
}
.level-card:hover:not(:disabled) { background: #203944; border-color: #64858e; }
.level-card:disabled { color: #9eafb7; }
.level-number {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 33px;
  aspect-ratio: 1;
  border: 1px solid #45616a;
  border-radius: 7px;
  color: var(--mint);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.81rem;
}
.level-card:disabled .level-number { color: #9eafb7; }
.level-card strong, .level-card small { display: block; }
.level-card small { margin-top: 3px; color: var(--muted); font-size: 0.76rem; }
.level-card .level-stars { color: var(--gold); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 680px) {
  .site-header, main { width: calc(100% - 28px); }
  .site-header { min-height: 62px; }
  .stage[data-view='title'], .stage[data-view='result'] { grid-template-columns: 1fr; gap: 24px; min-height: auto; }
  .intro h1 { font-size: clamp(3.65rem, 12vw, 5.5rem); }
  .intro-copy { margin-top: 17px; }
  .title-actions, .result-actions { margin-top: 16px; }
  .map-footer { padding-inline: 10px; }
  .legend { gap: 4px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .switch span { transition: none; }
  .switch[data-guide='true']::after { animation: none; }
}
