:root {
  --void: oklch(0.13 0.008 300);
  --surface: oklch(0.17 0.01 300);
  --surface-2: oklch(0.205 0.012 300);
  --paper: oklch(0.94 0.014 95);
  --ink: oklch(0.18 0.014 300);
  --white: oklch(0.96 0.008 300);
  --muted: oklch(0.67 0.014 300);
  --line: oklch(0.31 0.015 300);
  --accent: oklch(0.62 0.115 304);
  --accent-soft: oklch(0.245 0.035 304);
  --display: "Bahnschrift", "Avenir Next", "Century Gothic", sans-serif;
  --label: "Lucida Console", "Courier New", monospace;
}

* { box-sizing: border-box; }
html { background: var(--void); }
body {
  margin: 0;
  background: var(--void);
  color: var(--white);
  font-family: var(--display);
  min-width: 300px;
  overflow-x: clip;
}
button, a { -webkit-tap-highlight-color: transparent; }
button, .ticket-cta {
  border: 1px solid var(--line);
  border-radius: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
}
button { background: transparent; padding: 10px 16px; }
button:focus-visible, a:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
button:disabled { cursor: wait; opacity: .45; }
[hidden] { display: none !important; }

header, main, footer {
  margin: auto;
  width: min(1440px, calc(100% - clamp(32px, 7vw, 112px)));
}
header {
  align-items: center;
  background: color-mix(in oklch, var(--void) 94%, transparent);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 17px 0;
  position: sticky;
  top: 0;
  z-index: 20;
}
header::before {
  background: var(--void);
  content: "";
  inset: 0 calc((100vw - 100%) / -2);
  position: absolute;
  z-index: -1;
}
.brand {
  align-items: center;
  color: inherit;
  display: flex;
  gap: 13px;
  text-decoration: none;
}
.brand img {
  height: 46px;
  object-fit: cover;
  width: 46px;
}
.brand span { display: grid; gap: 5px; }
.brand b { font-size: 12px; letter-spacing: .14em; }
.brand small { color: var(--muted); font: 9px/1 var(--label); letter-spacing: .12em; }
.header-actions, .settings { align-items: center; display: flex; }
.header-actions { gap: 18px; }
.settings { gap: 2px; }
.settings button {
  border: 0;
  color: var(--muted);
  font: 10px/1 var(--label);
  padding: 12px 10px;
  text-transform: uppercase;
}
.settings button:hover, .settings button[aria-pressed="true"] { color: var(--white); }

.ticket-cta {
  align-items: center;
  background: var(--accent-soft);
  border-color: color-mix(in oklch, var(--accent) 52%, var(--line));
  display: inline-flex;
  font: 700 10px/1 var(--label);
  gap: 24px;
  justify-content: space-between;
  letter-spacing: .12em;
  padding: 14px 16px;
  text-decoration: none;
  transition: background .18s ease, border-color .18s ease, transform .18s cubic-bezier(.22,1,.36,1);
}
.ticket-cta:hover {
  background: color-mix(in oklch, var(--accent-soft) 72%, var(--surface-2));
  border-color: var(--accent);
  transform: translateY(-1px);
}
.ticket-cta:active { transform: translateY(0); }

#menu { padding: clamp(40px, 5vw, 64px) 0 36px; }
.intro {
  align-items: end;
  display: flex;
  justify-content: space-between;
  padding: 0 0 22px;
}
.eyebrow, .choice-label, .event-date, footer {
  font: 700 10px/1.4 var(--label);
  letter-spacing: .16em;
  text-transform: uppercase;
}
.eyebrow { color: var(--muted); margin: 0; }
.event-date { display: flex; gap: 36px; margin: 0; }
.event-date span:first-child { color: var(--white); }

.postcard {
  background: var(--paper);
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
}
.postcard > img {
  display: block;
  mix-blend-mode: multiply;
  width: 100%;
}
.choices {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin: 20px auto 0;
  max-width: 1040px;
}
.choice {
  border-color: var(--line);
  background: var(--surface);
  min-height: 126px;
  overflow: hidden;
  padding: 20px 24px;
  position: relative;
  text-align: left;
  transition: background .18s ease, border-color .18s ease, transform .18s cubic-bezier(.22,1,.36,1);
}
.choice.early {
  background: color-mix(in oklch, var(--accent-soft) 34%, var(--surface));
  border-color: color-mix(in oklch, var(--accent) 38%, var(--line));
}
.choice.late { background: var(--surface); }
.choice:hover {
  background: var(--surface-2);
  border-color: color-mix(in oklch, var(--muted) 68%, var(--line));
  transform: translateY(-1px);
}
.choice:active { transform: translateY(0); }
.choice:disabled { transform: none; }
.choice-label { opacity: .62; }
.choice strong {
  display: block;
  font-size: clamp(25px, 2.3vw, 32px);
  font-weight: 500;
  letter-spacing: -.035em;
  line-height: 1;
  margin: 12px 0 10px;
}
.choice strong span { float: right; font-size: .7em; }
.choice small { color: var(--muted); font-size: 14px; }
.footnote {
  color: var(--muted);
  font: 9px/1.5 var(--label);
  letter-spacing: .12em;
  margin: 22px 0 0;
  text-align: center;
  text-transform: uppercase;
}

footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  font-size: 9px;
  justify-content: space-between;
  padding: 24px 0 30px;
}

.game-heading {
  align-items: end;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 42px 0 22px;
}
.game-heading h2 {
  font-size: clamp(22px, 2.2vw, 32px);
  font-weight: 500;
  letter-spacing: -.035em;
  margin: 7px 0 0;
}
.game-heading button, #change {
  border-color: var(--line);
  color: var(--muted);
  font: 10px/1 var(--label);
  text-transform: uppercase;
}
.game-heading button:hover, #change:hover { border-color: var(--white); color: var(--white); }
.hud {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom: 0;
  display: flex;
  font: 700 10px/1 var(--label);
  gap: 28px;
  letter-spacing: .08em;
  padding: 12px 16px;
}
.hud #distance { flex: 1; }
.hud button { border-color: rgb(255 255 255 / .3); font-size: 10px; padding: 6px 10px; text-transform: uppercase; }
.hud button:hover { border-color: var(--white); }
.stage {
  background: #e5e7e0;
  border: 1px solid var(--line);
  border-top: 0;
  overflow: hidden;
  position: relative;
}
canvas {
  display: block;
  height: min(66vh, 720px);
  min-height: 400px;
  touch-action: none;
  width: 100%;
}
.caption {
  background: var(--white);
  border: 0;
  bottom: 14px;
  box-shadow: 5px 5px 0 rgb(21 19 26 / .16);
  color: var(--ink);
  font-family: "Comic Sans MS", "Segoe Print", cursive;
  font-size: 15px;
  left: 50%;
  max-width: 85%;
  padding: 9px 16px;
  pointer-events: none;
  position: absolute;
  text-align: center;
  transform: translateX(-50%) rotate(-1deg);
  width: max-content;
}
.caption:empty { display: none; }
.controls {
  align-items: center;
  color: var(--muted);
  display: flex;
  font: 9px/1.4 var(--label);
  gap: 16px;
  justify-content: space-between;
  letter-spacing: .04em;
  padding: 18px 0 25px;
  text-transform: uppercase;
}
.keys { display: flex; flex-wrap: wrap; gap: 17px; }
.keys > span { align-items: center; display: flex; gap: 5px; }
kbd {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--white);
  font: inherit;
  padding: 3px 6px;
}
#hint { color: var(--muted); }
#pause-screen {
  align-items: center;
  background: rgb(9 9 11 / .94);
  color: var(--white);
  display: flex;
  flex-direction: column;
  inset: 0;
  justify-content: center;
  position: absolute;
}
#pause-screen h2 {
  font-size: clamp(34px, 5vw, 62px);
  font-weight: 500;
  letter-spacing: -.05em;
  margin: 0;
}
#pause-screen p { color: var(--muted); }
#pause-screen button { background: var(--accent-soft); border-color: color-mix(in oklch, var(--accent) 52%, var(--line)); }

.touch-controls {
  align-items: center;
  display: none;
  gap: 8px;
  justify-content: space-between;
  padding: 0 0 22px;
}
.touch-controls button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--white);
  flex: 1;
  font-weight: 700;
  min-height: 54px;
  touch-action: none;
  user-select: none;
}
.touch-controls button:active, .touch-controls button.pressed { background: var(--accent-soft); }
.touch-guide { color: var(--muted); display: none; font: 9px/1.5 var(--label); text-transform: uppercase; }
.dpad { display: grid; gap: 4px; grid-template-columns: repeat(3,44px); grid-template-rows: repeat(2,44px); }
.dpad button { font-size: 21px; min-height: 44px; padding: 0; }
.dpad [data-key="ArrowUp"] { grid-column: 2; }
.dpad [data-key="ArrowLeft"] { grid-column: 1; grid-row: 2; }
.dpad [data-key="ArrowDown"] { grid-column: 2; grid-row: 2; }
.dpad [data-key="ArrowRight"] { grid-column: 3; grid-row: 2; }
.touch-actions { display: flex; gap: 7px; }
.touch-actions button { min-height: 58px; }

#result {
  margin: auto;
  max-width: 860px;
  padding: clamp(64px, 9vw, 120px) 0 80px;
  text-align: center;
}
#result h1 {
  font-size: clamp(48px, 6vw, 78px);
  font-weight: 500;
  letter-spacing: -.07em;
  line-height: .9;
  margin: 18px 0 0;
}
#result-copy {
  color: var(--muted);
  font-size: 17px;
  line-height: 1.65;
  margin: 30px auto;
  max-width: 610px;
}
.receipt {
  background: var(--paper);
  border: 1px solid color-mix(in oklch, var(--ink) 24%, var(--paper));
  color: var(--ink);
  margin: 46px auto;
  max-width: 500px;
  padding: 28px 32px;
  text-align: left;
  transform: rotate(-1deg);
}
.receipt > div {
  border-bottom: 1px dashed #aaa4ad;
  display: flex;
  font: 12px/1.3 var(--label);
  gap: 16px;
  justify-content: space-between;
  padding: 13px 0;
}
.receipt .receipt-head { padding: 0 0 18px; }
.receipt-head img { height: 58px; object-fit: cover; width: 58px; }
.receipt-head span { font-size: 9px; letter-spacing: .15em; line-height: 1.8; }
.receipt .total { font-size: 14px; }
.receipt > p { font: 10px/1.5 var(--label); margin: 20px 0 0; text-align: center; }
.handwritten-lesson {
  display: block;
  filter: invert(1) grayscale(1) brightness(2);
  height: auto;
  margin: 42px auto;
  mix-blend-mode: screen;
  width: 100%;
}
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.result-actions button {
  border-color: var(--line);
  color: var(--muted);
  font: 10px/1.2 var(--label);
  padding: 15px 18px;
  text-transform: uppercase;
}
.result-actions button:hover { border-color: var(--white); color: var(--white); }
.result-ticket { min-width: 248px; }

dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--white);
  max-width: 95vw;
  padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / .85); }
dialog img { display: block; margin-top: 16px; width: 100%; }
dialog p { color: var(--muted); font-size: 13px; }
dialog button { border-color: var(--line); color: var(--muted); float: right; }

@media (max-width: 960px) {
  .brand small { display: none; }
  .settings button { padding-inline: 7px; }
  .controls { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 900px), (any-pointer: coarse) {
  canvas { height: calc(100svh - 330px); min-height: 270px; }
  .controls { display: none; }
  .touch-controls {
    background: var(--void);
    bottom: 0;
    display: flex;
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    position: sticky;
    z-index: 2;
  }
  .touch-controls button { -webkit-touch-callout: none; -webkit-user-select: none; }
  .touch-guide { display: block; margin: 0 12px; }
  .game-heading { padding: 20px 0 14px; }
  .game-heading h2 { font-size: 18px; }
  .touch-actions button { font-size: 12px; padding: 10px; }
}

@media (max-width: 720px) {
  .header-actions { gap: 8px; }
  .settings { position: static; }
  .settings #sound, .settings #motion { display: none; }
  .settings button { border: 1px solid var(--line); }
  .brand b { font-size: 10px; }
  .brand img { height: 40px; width: 40px; }
  .ticket-cta { gap: 12px; padding: 13px 12px; }
  .intro { align-items: flex-start; flex-direction: column; gap: 14px; }
  .event-date { gap: 18px; }
  .choices { grid-template-columns: 1fr; }
  .choice { min-height: 118px; }
  footer { gap: 28px; line-height: 1.6; }
}

@media (max-width: 540px) {
  header, main, footer { width: calc(100% - 28px); }
  .brand span { display: none; }
  .settings #art { font-size: 8px; padding: 10px 8px; }
  .ticket-cta { font-size: 10px; }
  #menu { padding-top: 34px; }
  .postcard > img { margin: 0; width: 100%; }
  .choice { padding: 18px; }
  .choice-label { font-size: 9px; }
  .choice strong { font-size: 27px; }
  .choice small { display: block; font-size: 14px; line-height: 1.5; }
  .game-heading h2 { font-size: 16px; }
  .game-heading .eyebrow { font-size: 8px; }
  .game-heading button { font-size: 8px; padding: 8px; }
  .hud { font-size: 8px; gap: 8px; padding: 9px; }
  .hud button { padding: 5px 7px; }
  .caption { bottom: 8px; font-size: 12px; padding: 7px 10px; }
  .touch-guide { display: none; }
  .dpad { grid-template-columns: repeat(3,43px); grid-template-rows: repeat(2,40px); }
  .dpad button { min-height: 40px; }
  .receipt { padding: 24px 20px; }
  .result-actions { align-items: stretch; flex-direction: column; }
  .result-actions > * { justify-content: center; width: 100%; }
}

@media (orientation: landscape) and (max-height: 600px) {
  body:has(#play:not([hidden])) header,
  body:has(#play:not([hidden])) footer { display: none; }
  #play .game-heading { gap: 8px; padding: 6px 0; }
  #play .game-heading h2 { font-size: 14px; }
  #play .game-heading .eyebrow { font-size: 8px; margin-bottom: 3px; }
  #play .game-heading button { padding: 6px 10px; }
  #play .hud { padding: 5px 10px; }
  #play canvas { height: calc(100svh - 182px); min-height: 150px; }
  #play .caption { bottom: 8px; font-size: 12px; padding: 5px 12px; }
  #play .touch-controls { padding: 4px 0; }
  #play .dpad button { min-height: 44px; }
  .touch-actions button { min-height: 48px !important; }
  .touch-guide { display: block; font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
