:root {
  color-scheme: dark;
  --ink: #282035;
  --cream: #fff5db;
  --paper: #fff4d9;
  --apricot: #ffac85;
  --mint: #b6efdb;
  --lavender: #c6b4da;
  --sans: "Inter", "Hiragino Sans", "Yu Gothic", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --display: "Archivo Black", "Arial Black", "Helvetica Neue", Arial, sans-serif;
  font-family: var(--sans);
  font-synthesis: weight style;
  background: #211b2b;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-width: 0; }
body {
  color: var(--cream);
  background-color: #211b2b;
  background-image:
    radial-gradient(ellipse at 52% 58%, #40304c70, transparent 75%),
    radial-gradient(circle at 2px 2px, #bfa2c026 1px, transparent 1.25px);
  background-size: auto, 14px 14px;
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible {
  outline: 3px solid #147a74;
  outline-offset: 4px;
}
.tool:focus-visible, #pauseButton:focus-visible { outline-color: var(--mint); }
button:disabled { cursor: default; opacity: .55; }

#app {
  width: min(100%, 77rem);
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-inline: auto;
  padding: max(1.15rem, env(safe-area-inset-top)) max(3.25%, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(3.25%, env(safe-area-inset-left));
}
.masthead, .brand, .tools, .tool, .control-strip, .hardware, .scoreboard, .hud { display: flex; align-items: center; }
.masthead { justify-content: space-between; gap: .65rem; padding: 0 .18rem; margin-bottom: 1rem; }
.brand { gap: .6rem; min-width: 0; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: .6rem .6rem .6rem .16rem;
  background: var(--apricot);
  color: var(--ink);
  box-shadow: inset 0 1px 0 #fff7;
}
.brand-mark svg { width: 1.38rem; height: 1.38rem; }
.brand-name {
  font: 950 italic clamp(.9rem, 1.65vw, 1.25rem)/1 var(--display);
  letter-spacing: -.035em;
  white-space: nowrap;
}
.tools { justify-content: flex-end; gap: .48rem; }
.tool {
  justify-content: center;
  gap: .45rem;
  min-height: 2.75rem;
  padding: .35rem .8rem;
  border: 1px solid #75647b;
  background: #332839;
  border-radius: 999px;
  color: #fff4e3;
  font-size: .81rem;
  font-weight: 720;
}
.icon { display: inline-block; width: 1.13rem; height: 1.13rem; vertical-align: middle; flex: none; }
.tool svg, #pauseButton svg { width: 1.13rem; height: 1.13rem; flex: none; }

.cabinet {
  position: relative;
  margin: 0;
  padding: clamp(5px, .7vw, 10px) clamp(5px, .7vw, 10px) 0;
  background: #46384d;
  border: 1px solid #85728b;
  border-radius: 1.38rem;
  box-shadow: inset 0 2px 0 #64526d, 0 3px 0 #160f1c, 0 15px 40px #100c192e;
}
#stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 100%;
  height: clamp(24rem, min(69svh, 55vw), 40rem);
  border-radius: .93rem;
  border: 2px solid #2c2238;
  background: linear-gradient(#a8a2d0, #f7c0ba 56%, #514772);
}
#gameCanvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }
body[data-screen="playing"] #gameCanvas { touch-action: none; }
.menu {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(1.15rem, 3.4vh, 2rem);
  padding: clamp(1.15rem, 5.25%, 4.6rem);
  pointer-events: none;
}
.game-title { color: var(--ink); position: relative; width: max-content; max-width: 100%; }
.title-prefix {
  display: table;
  padding: .34em .68em .32em;
  margin-left: .2rem;
  color: var(--cream);
  background: var(--ink);
  font: 900 italic clamp(.77rem, 1.5vw, 1.12rem)/1 var(--display);
  letter-spacing: .15em;
  transform: rotate(-3deg);
}
.title-dash {
  width: max-content;
  margin: .05em .12em 0 -.035em;
  color: #fff2cd;
  font: 1000 italic clamp(5rem, 9.5vw, 8.8rem)/.88 var(--display);
  letter-spacing: -.085em;
  -webkit-text-stroke: .041em var(--ink);
  paint-order: stroke fill;
  text-shadow: .008em .016em var(--ink), .019em .031em var(--ink),
    .026em .040em #ffaf87, .037em .054em #ffaf87, .048em .069em #ffaf87,
    .051em .080em var(--ink), .063em .09em var(--ink);
  transform: rotate(-3deg) skewX(-4deg);
  transform-origin: 5% 80%;
}
.menu-card {
  position: relative;
  color-scheme: light;
  color: var(--ink);
  width: min(100%, 24rem);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 1rem 1rem 1rem .3rem;
  box-shadow: 4px 5px 0 var(--ink);
  padding: clamp(1rem, 2.1vw, 1.5rem);
  pointer-events: auto;
}
.menu-card h2 { margin: 0 0 .75rem; font-size: clamp(1.2rem, 2.25vw, 1.85rem); letter-spacing: -.045em; line-height: 1.15; }
.menu-card p { margin: 0 0 1.1rem; line-height: 1.55; overflow-wrap: anywhere; }
.menu-card:lang(ko) { word-break: keep-all; }
.menu-card .choose-heading {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .18rem .48rem;
  font-size: .93rem;
  letter-spacing: -.025em;
  line-height: 1.5;
}
.choose-heading span { white-space: nowrap; }
.choose-heading span[lang="en"] {
  color: #615268;
  font-size: .83rem;
  font-weight: 650;
  letter-spacing: .005em;
}
.languages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .44rem; }
.language-option, .primary, .secondary {
  position: relative;
  min-height: 2.95rem;
  border: 1.5px solid var(--ink);
  border-radius: .55rem;
  color: var(--ink);
  font-weight: 800;
  background: #fff9e8;
  box-shadow: 0 2px 0 var(--ink);
  padding: .44rem .63rem;
  touch-action: manipulation;
}
.language-option { padding-inline: .15rem; }
.language-option b { font-size: 1rem; line-height: 1.12; }
.language-option[aria-pressed="true"] { background: #e0ecdc; }
.language-option:active, .primary:active, .secondary:active {
  transform: translateY(2px);
  box-shadow: none;
}
.primary, .secondary { min-width: 5.25rem; padding-inline: 1rem; }
.primary { background: var(--apricot); }
#startButton { width: 100%; display: flex; align-items: center; justify-content: center; gap: .45rem; }
#pausePane, #resultsPane { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
#pausePane h2, #resultsPane h2, #resultsPane .result-grid { grid-column: 1 / -1; }
#pausePane button, #resultsPane button { min-width: 0; padding-inline: .35rem; overflow-wrap: anywhere; }
.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .5rem;
  margin: 0 0 .5rem;
}
.result-grid > div { padding: .65rem .75rem; border-radius: .5rem; background: #eadfcf; }
.result-grid small, .scoreboard small { display: block; font-size: .78rem; font-weight: 750; line-height: 1.25; }
.result-grid strong, .scoreboard strong { display: block; font: 900 1.65rem/1.18 var(--display); font-variant-numeric: tabular-nums; }
body:is([data-screen="paused"],[data-screen="results"]) .game-title { display: none; }
body:is([data-screen="paused"],[data-screen="results"]) .menu {
  align-items: center;
  justify-content: center;
  background: #291c3b58;
}
.hud {
  pointer-events: none;
  position: absolute;
  inset: .9rem .95rem auto;
  justify-content: space-between;
  align-items: flex-start;
}
.scoreboard, #pauseButton, .toast {
  border: 1.5px solid #33293d;
  border-radius: .6rem;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 2px 3px 0 #33293d;
}
.scoreboard { gap: .85rem; padding: .4rem .8rem; }
.scoreboard > div + div { border-left: 1px solid #b5a7af; padding-left: .85rem; }
.scoreboard strong { font-size: 1.22rem; }
#pauseButton {
  pointer-events: auto;
  display: inline-flex;
  gap: .4rem;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: .4rem .7rem;
  font-weight: 800;
}
.toast {
  position: absolute;
  top: 22%;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 2rem);
  padding: .5rem .9rem;
  transform: translateX(-50%);
  text-align: center;
  font-weight: 800;
  background: var(--mint);
  pointer-events: none;
}
.control-strip {
  min-height: 2.55rem;
  padding-inline: .75rem;
  justify-content: space-between;
  gap: .5rem;
  text-align: center;
  color: #f5e6f1;
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.35;
}
.hardware { gap: .26rem; width: 2.15rem; }
.hardware > * {
  display: block;
  width: .33rem;
  height: .33rem;
  border-radius: 50%;
  background: #ad94ae;
  box-shadow: inset 0 1px 0 #fff4;
}
.hardware > :first-child { background: var(--mint); }
.speaker {
  display: inline-block;
  width: 2.15rem;
  height: .68rem;
  opacity: .75;
  transform: skew(-13deg);
  background: repeating-linear-gradient(90deg, #221c2c 0 3px, transparent 3px 6px);
}
.credit {
  margin: .85rem 0 0;
  color: #cfbdd0;
  text-align: center;
  font-size: .75rem;
  line-height: 1.5;
  letter-spacing: .065em;
}
@media (hover: hover) {
  .tool:hover { background: #54415a; border-color: #b09bb2; }
  .language-option:hover, .secondary:hover { background: #d7efe1; }
  .primary:hover { background: #ffc5a4; }
  #pauseButton:hover { background: #eee2ed; }
}
@media (max-width: 640px) and (orientation: portrait) {
  #app {
    padding: max(.8rem, env(safe-area-inset-top)) max(.62rem, env(safe-area-inset-right))
      max(.65rem, env(safe-area-inset-bottom)) max(.62rem, env(safe-area-inset-left));
  }
  .masthead { margin: 0 .15rem .65rem; }
  .brand { gap: .37rem; }
  .brand-mark { width: 1.9rem; height: 1.9rem; }
  .tools { gap: .28rem; }
  .tool { padding: .3rem .55rem; font-size: .78rem; }
  #stage { height: clamp(23.5rem, calc(100svh - 8.7rem), 47rem); }
  .cabinet { border-radius: 1rem; }
  #stage { border-radius: .68rem; }
  .menu { padding: clamp(1rem, 5vw, 1.8rem); padding-top: clamp(1.35rem, 5svh, 2.5rem); justify-content: space-between; gap: .65rem; }
  .title-prefix { font-size: clamp(.78rem, 3.3vw, 1rem); }
  .title-dash { font-size: clamp(4.25rem, 17vw, 6.6rem); }
  .menu-card { width: min(100%, 27rem); align-self: center; padding: 1rem; }
  .control-strip { min-height: 2.25rem; font-size: .75rem; padding-inline: .42rem; }
  .credit { margin-top: .6rem; font-size: .75rem; }
  .hud { inset: .6rem .65rem auto; }
}
@media (max-width: 365px) {
  .tool-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .tool { min-width: 2.75rem; }
  .menu-card { padding: .8rem; }
  .menu-card .choose-heading { gap: .1rem .36rem; }
  .hardware, .speaker { width: 1.35rem; }
}
@media (orientation: landscape) and (max-height: 550px) {
  #app { padding-block: max(.35rem, env(safe-area-inset-top)) max(.35rem, env(safe-area-inset-bottom)); padding-inline: max(.6rem, env(safe-area-inset-left)) max(.6rem, env(safe-area-inset-right)); }
  .masthead { margin-bottom: .25rem; }
  .brand-mark { width: 1.75rem; height: 1.75rem; }
  .cabinet { padding: 4px 4px 0; border-radius: .9rem; }
  #stage { height: max(15rem, calc(100svh - 5.7rem)); border-radius: .6rem; }
  .menu { justify-content: center; gap: .5rem; padding: .6rem 3%; }
  .title-prefix { font-size: .71rem; }
  .title-dash { font-size: clamp(3.15rem, 8vw, 5.3rem); }
  .menu-card { padding: .7rem .85rem; width: min(56%, 23.5rem); }
  .menu-card h2, .menu-card p { margin-bottom: .45rem; }
  .control-strip { min-height: 1.55rem; }
  .credit { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .tool, .language-option, .primary, .secondary { transition: background-color .14s, border-color .14s; }
}

/* The lobby is a compact deck of selectable runner portraits and route tickets. */
body { --route-accent: #f6ae94; --route-paper: #f9decb; }
body[data-level="1"] { --route-accent: #a9d5ec; --route-paper: #dcebf3; }
body[data-level="2"] { --route-accent: #ccbae9; --route-paper: #e8def3; }
body[data-screen="title"] .menu {
  padding: clamp(.85rem, 3.4%, 2.8rem);
  gap: clamp(.6rem, 1.6svh, 1rem);
}
body[data-screen="title"] .game-title { flex: none; }
body[data-screen="title"] .title-prefix { font-size: .72rem; }
body[data-screen="title"] .title-dash { font-size: clamp(3rem, 6.2vw, 5.15rem); }
body[data-screen="title"] .menu-card {
  width: min(47%, 26rem);
  min-width: min(18rem, 100%);
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #9b879f #f1e5d1;
  padding: clamp(.8rem, 1.5vw, 1.15rem);
}
#lobbyTitle { font-size: clamp(1.2rem, 2vw, 1.63rem); margin: 0 0 .65rem; }
.picker { min-inline-size: 0; border: 0; margin: 0 0 .65rem; padding: 0; }
.picker legend {
  display: block;
  padding: 0;
  margin-bottom: .32rem;
  color: #5b4a60;
  font-size: .81rem;
  line-height: 1.3;
  font-weight: 800;
}
.picker, .picker > :is(div, .pick-row) {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .33rem;
}
.picker > :is(div, .pick-row) { grid-column: 1 / -1; }
.pick {
  position: relative;
  min-width: 0;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  overflow: hidden;
  padding: .24rem .22rem .28rem;
  border: 1px solid #ac97a3;
  border-radius: .45rem;
  background: #fff9ea;
  color: var(--ink);
  font-size: .83rem;
  font-weight: 780;
  line-height: 1.19;
  overflow-wrap: anywhere;
  touch-action: manipulation;
}
.pick:focus-visible { z-index: 1; outline-offset: 1px; }
.pick:is([aria-pressed="true"],[aria-checked="true"]) {
  border-color: var(--ink);
  background: var(--route-paper);
  box-shadow: inset 0 0 0 1px var(--ink);
}
.pick:is([aria-pressed="true"],[aria-checked="true"])::after {
  content: "";
  position: absolute;
  inset: .2rem .2rem auto auto;
  width: .73rem;
  height: .73rem;
  background: var(--ink);
  border-radius: 50%;
  pointer-events: none;
}
.pick:is([aria-pressed="true"],[aria-checked="true"])::before {
  content: "";
  position: absolute;
  top: .37rem;
  right: .4rem;
  width: .31rem;
  height: .18rem;
  border-left: 1.5px solid white;
  border-bottom: 1.5px solid white;
  transform: rotate(-45deg);
  z-index: 1;
}
.pick.runner canvas {
  display: block;
  width: clamp(2.35rem, 3.8vw, 3.1rem);
  height: auto;
  aspect-ratio: 1;
  image-rendering: pixelated;
}
.pick.runner span { margin-top: .08rem; }
.pick.level { justify-content: flex-start; padding: .25rem .14rem .32rem; gap: .25rem; }
.swatch {
  display: block;
  flex: none;
  width: calc(100% - .3rem);
  height: clamp(1.4rem, 2.4vw, 1.95rem);
  overflow: hidden;
  border-radius: .18rem;
  background: linear-gradient(165deg, #9a9cce 0 36%, #ffcaad 37% 68%, #957b98 69% 80%, #645771 81%);
}
.swatch canvas { display: block; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.pick.level:nth-of-type(2) .swatch {
  background: linear-gradient(165deg, #7d9ecd 0 36%, #fcc0d8 37% 68%, #ac89ad 69% 80%, #695c8b 81%);
}
.pick.level:nth-of-type(3) .swatch {
  background: linear-gradient(165deg, #594e98 0 36%, #bc95d7 37% 68%, #768ead 69% 80%, #47456b 81%);
}
#titlePane .instructions {
  margin: .45rem 0 .6rem;
  font-size: .875rem;
  line-height: 1.43;
  color: #53465a;
}
#titlePane #startButton { min-height: 2.75rem; }
.hud { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: .5rem; }
#pauseButton { grid-column: 3; }
.stage-chip {
  grid-column: 2;
  justify-self: center;
  align-self: start;
  max-width: 100%;
  margin-top: .2rem;
  padding: .33rem .72rem;
  overflow: hidden;
  color: var(--ink);
  background: var(--route-paper);
  border: 1.5px solid var(--ink);
  border-radius: 99px;
  box-shadow: 1px 2px 0 var(--ink);
  font-size: .84rem;
  line-height: 1.25;
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-intro {
  position: absolute;
  inset: auto .75rem 8%;
  width: fit-content;
  max-width: calc(100% - 1.5rem);
  margin: 0 auto;
  padding: .55rem 1rem;
  border: 2px solid var(--ink);
  border-radius: .45rem;
  color: var(--ink);
  background: var(--route-paper);
  box-shadow: 3px 3px 0 var(--ink);
  font-weight: 850;
  text-align: center;
  pointer-events: none;
}
.menu-card .result-route {
  display: block;
  grid-column: 1 / -1;
  justify-self: start;
  margin: 0 0 .22rem;
  padding: .24rem .55rem;
  border-radius: .25rem;
  color: #493c51;
  background: var(--route-paper);
  font-size: .8rem;
  font-weight: 760;
}
.scene-caption {
  position: absolute;
  inset: 1rem 1rem auto auto;
  max-width: 44%;
  display: flex;
  align-items: center;
  overflow: hidden;
  gap: .5rem;
  padding: .26rem .66rem .26rem .28rem;
  color: #31283c;
  background: #fff1dbe8;
  border: 1px solid #6a5973;
  border-radius: .38rem;
  box-shadow: 1px 2px 0 #3d324b6b;
  font-weight: 740;
  font-size: .82rem;
  line-height: 1.25;
  pointer-events: none;
}
.scene-number {
  flex-shrink: 0;
  border-radius: .15rem;
  padding: .23em .4em;
  color: var(--cream);
  background: #4a3d59;
  font-family: ui-monospace, monospace;
}
#sceneName { overflow-wrap: anywhere; }
body:not([data-screen="language"]):not([data-screen="title"]) .scene-caption { display: none; }
@media (hover: hover) {
  .pick:hover { border-color: var(--ink); background-color: #eae8da; }
  .pick:is([aria-pressed="true"],[aria-checked="true"]):hover { background-color: var(--route-paper); }
}
@media (max-width: 640px) and (orientation: portrait) {
  body[data-screen="title"] .menu { padding: clamp(.6rem, 3vw, 1rem); gap: .6rem; }
  body[data-screen="title"] .game-title { margin-left: .5rem; }
  body[data-screen="title"] .title-prefix { font-size: .65rem; }
  body[data-screen="title"] .title-dash { font-size: clamp(2.85rem, 12vw, 4.2rem); }
  body[data-screen="title"] .menu-card { width: min(100%, 27rem); padding: .8rem .9rem; }
  .pick.level span { font-size: .8rem; }
  .stage-chip { font-size: .74rem; padding-inline: .45rem; }
  .scene-caption { inset: .6rem .6rem auto auto; max-width: 45%; gap: .3rem; font-size: .74rem; }
}
@media (orientation: landscape) and (max-height: 550px) {
  body[data-screen="title"] .game-title { display: none; }
  body[data-screen="title"] .menu { padding: .5rem 2%; }
  body[data-screen="title"] .menu-card { width: min(61%, 32rem); max-height: 100%; padding: .65rem .8rem; }
  #lobbyTitle { font-size: 1.08rem; margin-bottom: .35rem; }
  #titlePane { display: grid; grid-template-columns: 1.15fr 1fr; gap: .18rem .45rem; }
  #lobbyTitle, #titlePane .instructions, #titlePane #startButton { grid-column: 1 / -1; }
  .picker { margin-bottom: .15rem; }
  .picker, .picker > :is(div, .pick-row) { gap: .15rem; }
  .picker legend { margin-bottom: .15rem; }
  .pick { font-size: .76rem; padding-inline: .1rem; }
  .pick.runner canvas { width: 2rem; }
  .pick.level { padding-block: .2rem; }
  .swatch { height: 1.05rem; }
  #titlePane .instructions { margin: .1rem 0 .15rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .stage-intro { animation: stage-arrival .25s ease-out; }
  @keyframes stage-arrival {
    from { transform: translateY(.45rem); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
}
