:root {
  --night: #0c0817;
  --night-2: #140e26;
  --panel: #1a1233e6;
  --edge: #33275a;
  --edge-dark: #0a0614;
  --text: #f3ead7;
  --muted: #9a8fb8;
  --amber: #ffb547;
  --gold: #ffd166;
  --teal: #5ee6c9;
  --rose: #ff6b8b;
  --lime: #a3e36b;
  --orange: #ff8a3d;
  --ground-h: 27.5%; /* matches Scene.GROUND_FRACTION; % of the viewport box, which (unlike vh on iOS) is what's visible */
  --pixel: "VT323", ui-monospace, monospace;
  --display: "Press Start 2P", "VT323", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
html { touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
body {
  background: var(--night);
  color: var(--text);
  font-family: var(--pixel);
  font-size: 24px;
  line-height: 1.15;
  -webkit-font-smoothing: none;
}

#scene {
  position: fixed; inset: 0; width: 100%; height: 100%;
  transition: transform .25s ease-out; /* slides up while a phone keyboard is open */
  image-rendering: pixelated; image-rendering: crisp-edges;
}
.crt {
  position: fixed; inset: 0; pointer-events: none; z-index: 10;
  background: repeating-linear-gradient(#0000 0 2px, #0c08171f 2px 3px);
  animation: crt-zap 7s steps(1) infinite;
}
.hidden { display: none !important; }

/* Pixel frame */
.tag, .card {
  background: var(--panel);
  box-shadow: 0 0 0 2px var(--edge-dark), 0 0 0 4px var(--edge), 0 4px 0 4px var(--edge-dark), 8px 10px 0 4px #00000055;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed; top: 20px; left: 24px; right: 24px; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
}
.tag { justify-self: start; padding: 4px 12px; font-size: 26px; color: var(--gold); white-space: nowrap; }
.tag.score { justify-self: end; }
.tag.slam { animation: score-slam .5s ease-out; }
.tag.mute {
  position: fixed; right: 24px; bottom: 20px; z-index: 5; padding: 4px; display: flex;
  border: 0; cursor: pointer; color: var(--gold);
}
.tag.mute svg { width: 22px; height: 18px; display: block; }
.tag.mute:hover { color: #fff; }
body.kb .tag.mute { display: none; }

.pips { display: flex; gap: 6px; }
.pip {
  width: 14px; height: 14px; background: #0c0817b3;
  box-shadow: 0 0 0 2px var(--edge-dark), 0 0 0 3px var(--edge);
  transition: background .2s;
}
.pip.now { box-shadow: 0 0 0 2px var(--edge-dark), 0 0 0 3px var(--teal), 0 0 10px #5ee6c988; animation: glow-pulse 1s steps(2) infinite; }
.pip.filled { animation: pip-pop .35s ease-out; }

/* ---------- Centre stage ---------- */
.stage {
  position: fixed; z-index: 4; left: 0; right: 0; top: 64px; bottom: var(--ground-h);
  display: grid; place-items: center; padding: 12px 24px 28px; pointer-events: none;
}
body.free .stage { bottom: 0; padding-bottom: 20px; }
.card {
  pointer-events: auto; width: min(640px, 100%); max-height: 100%; overflow: auto;
  padding: 18px 24px; animation: card-in .35s cubic-bezier(.2, 1.4, .4, 1);
}
.logo {
  margin: 0 0 8px; font-family: var(--display); font-weight: normal; font-size: 44px; letter-spacing: 3px; color: var(--amber);
  text-shadow: 4px 4px 0 #7a3a1a, 0 0 22px #ffb54766; animation: title-flicker 6s infinite;
}
.eyebrow { margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; font-size: 20px; }
.rules { margin: 0 0 16px; padding-left: 22px; }
.rules li { margin: 4px 0; }
.rules b { color: var(--amber); font-weight: normal; }

.bands { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; font-size: 20px; }
.bands span { padding: 1px 6px; color: var(--night); }
.b100 { background: var(--gold); } .b85 { background: var(--teal); } .b60 { background: var(--lime); }
.b30 { background: var(--orange); } .b10 { background: var(--rose); }

.prompt-card { text-align: center; width: fit-content; max-width: min(900px, 100%); padding: 18px 40px; } /* hugs the prompt */
.prompt { margin: 0; font-size: 64px; font-weight: normal; line-height: 1; }
.context { margin: 12px 0 0; color: var(--muted); font-size: 28px; }
.context:empty { display: none; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-size: 28px; cursor: pointer; border: 0; padding: 8px 20px;
  color: var(--night); background: var(--amber);
  box-shadow: 0 0 0 2px var(--edge-dark), 0 4px 0 2px #a0601a;
  transition: transform .08s;
  animation: btn-bob 2.4s ease-in-out infinite;
}
@media (hover: hover) { .btn:hover { background: var(--gold); } }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 2px var(--edge-dark), 0 1px 0 2px #a0601a; }
.btn:focus-visible { outline: 2px dashed var(--teal); outline-offset: 5px; }

/* ---------- Answer bar on the ground ---------- */
.ground {
  position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; height: var(--ground-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  animation: fade-up .3s both;
}
.answer { display: flex; gap: 18px; align-items: stretch; }
.answer .btn { animation: none; font-size: 34px; padding: 0 26px; }
#guess {
  width: 280px; font: inherit; font-size: 64px; text-align: center; letter-spacing: 8px; text-indent: 8px;
  color: var(--gold); background: #0c0817e6; border: 0; padding: 4px 12px; caret-color: var(--teal);
  box-shadow: inset 0 0 0 2px var(--edge-dark), 0 0 0 4px var(--edge), 0 6px 0 4px var(--edge-dark);
}
#guess:focus { outline: none; box-shadow: inset 0 0 0 2px var(--edge-dark), 0 0 0 4px var(--teal), 0 6px 0 4px var(--edge-dark), 0 0 20px #5ee6c955; }
#guess::placeholder { color: #4a3f6a; letter-spacing: 4px; }
.answer.shake { animation: shake .4s; }

.timer {
  position: relative; width: 64px; height: 64px; align-self: center; display: flex; justify-content: center; align-items: center;
  background: #0c0817e6; padding: 6px; box-shadow: 0 0 0 4px var(--edge), 0 6px 0 4px var(--edge-dark);
}
#timer-num { font-size: 32px; color: var(--teal); line-height: 1; }
/* Time left: a bar around the frame that empties clockwise from 12 o'clock */
.timer-ring { position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px); overflow: visible; pointer-events: none; }
#timer-fill { fill: none; stroke: var(--teal); stroke-width: 4; stroke-dasharray: 100 200; shape-rendering: crispEdges; }
.timer.low #timer-num { color: var(--rose); animation: glow-pulse .5s steps(2) infinite; }
.timer.low #timer-fill { stroke: var(--rose); }

.hint { margin: 0; color: var(--text); opacity: .75; font-size: 20px; text-shadow: 2px 2px 0 #000; }
.hint.err { color: var(--rose); opacity: 1; }

/* ---------- Walk overlays ---------- */
.sign, .flash { position: fixed; left: 0; top: 0; z-index: 3; pointer-events: none; transform: translate(-50%, -100%); }
/* Score stakes in the ground: where each score would take you. Below the feet, so the board never hides them. */
.marks { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
.mark-line {
  position: absolute; left: 0; width: 0; height: 9vh; margin-left: -1px;
  border-left: 2px dashed var(--c); opacity: .25; transition: opacity .25s;
  filter: drop-shadow(2px 2px 0 #0009);
}
/* little stake head on the ground surface */
.mark-line::before { content: ""; position: absolute; left: -6px; top: -3px; width: 10px; height: 6px; background: var(--c); }
.mark-line span { position: absolute; top: 100%; left: 0; transform: translateX(-50%); padding-top: 6px; font-size: 22px; color: var(--c); }
/* Dim until the traveller walks over them; the one he lands on lights up fully */
.mark-line.passed { opacity: .75; }
.mark-line.target.passed { opacity: 1; }
.mark-line.target.passed span { font-size: 26px; }

/* +100: the world dims around the traveller, then a flash at the star burst */
.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none; opacity: 0; transition: opacity .9s ease;
  background: radial-gradient(circle at var(--vx, 25%) var(--vy, 70%), transparent 0 9%, #06031070 22%, #060310e0 55%, #060310f5 100%);
}
.vignette.on { opacity: 1; }
.flashbang { position: fixed; inset: 0; z-index: 6; pointer-events: none; opacity: 0; background: radial-gradient(circle, #fff6d8 0%, #ffd16655 60%, transparent 100%); }
.flashbang.go { animation: flashbang .7s ease-out; }
/* Last 5 seconds: the top and side edges glow amber, flaring with each warning bip */
.edge-glow {
  position: fixed; inset: 0; z-index: 4; pointer-events: none; opacity: 0; transition: opacity .3s;
  box-shadow: inset 0 60px 60px -45px #ffb03a, inset 60px 0 60px -45px #ffb03a, inset -60px 0 60px -45px #ffb03a;
}
.edge-glow.on { opacity: .3; }
.edge-glow.on.flare { animation: edge-flare .8s ease-out; }
@keyframes edge-flare { from { opacity: .8; } }

/* Board held above the traveller's head */
.sign {
  padding: 2px 10px; font-size: 30px; color: var(--night); line-height: 1.1;
  box-shadow: 0 0 0 2px var(--edge-dark), 0 4px 0 2px #00000066;
  margin-top: -28px; animation: sign-pop .3s cubic-bezier(.2, 1.6, .4, 1);
}
.sign::after { content: ""; position: absolute; left: 50%; top: 100%; width: 4px; height: 22px; margin-left: -2px; background: #5a3a24; box-shadow: 0 0 0 1px var(--edge-dark); }
/* "+60 Historian" above the board */
.flash {
  display: flex; flex-direction: column; align-items: center; line-height: 1;
  text-shadow: 3px 3px 0 var(--edge-dark); opacity: 0; /* points stay hidden until he stops at his line */
}
.flash b { font-family: var(--display); font-weight: normal; font-size: 26px; }
.flash span { font-size: 22px; text-transform: uppercase; letter-spacing: 2px; margin-top: 4px; }
.flash.arrived { opacity: 1; }
.flash.arrived > * { animation: score-slam .6s ease-out; }
/* Shimmering gold for a perfect answer */
.flash.perfect b, .flash.perfect span {
  background: linear-gradient(90deg, #ffd166, #fff6d8, #5ee6c9, #ff9ec0, #ffd166); background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none;
  filter: drop-shadow(2px 2px 0 var(--edge-dark)) drop-shadow(0 0 10px #ffd16699);
}
.flash.perfect b { font-size: 34px; }
.flash.perfect > * { animation: shimmer 1.4s linear infinite; }
.flash.perfect.arrived > * { animation: score-slam .6s ease-out, shimmer 1.4s linear infinite; }
/* The board flies out of his hands when he trips */
.sign.tumble { animation: sign-tumble .8s cubic-bezier(.3, 0, .6, 1) forwards; }

/* ---------- Reveal ---------- */
/* Number line: guess label above its marker, answer label below its marker */
.line { position: relative; height: 124px; margin: 6px 12px 22px; } /* tall enough for the answer label below */
.line::before { content: ""; position: absolute; left: 0; right: 0; top: 54px; height: 4px; background: var(--edge); }
.gap { position: absolute; top: 52px; height: 8px; animation: grow .5s .3s both steps(12); }
.mark { position: absolute; top: 0; bottom: 0; width: 0; }
.mark::after { content: ""; position: absolute; left: -6px; top: 44px; width: 12px; height: 24px; box-shadow: 0 0 0 2px var(--edge-dark); }
.mark.you::after { background: var(--teal); }
.mark.ans::after { background: var(--gold); }
.lbl {
  position: absolute; left: 0; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; white-space: nowrap;
  font-size: 16px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted);
}
.lbl b { font-family: var(--display); font-weight: normal; font-size: 22px; letter-spacing: 0; margin: 4px 0; }
.you .lbl { top: 0; }
.you .lbl b { color: var(--teal); }
.ans .lbl { top: 70px; }
.ans .lbl b { color: var(--gold); order: -1; }
.mark.ans { animation: drop .35s .15s both; }

.verdict { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 22px; }
.points { font-size: 30px; padding: 0 10px; color: var(--night); animation: score-slam .6s .3s ease-out both; }
.fact { margin: 0 0 14px; font-size: 22px; animation: fade-up .5s .45s both; }
#reveal .btn { display: block; margin-left: auto; font-size: 24px; padding: 6px 16px; }

/* ---------- Done ---------- */
.done-card { width: min(720px, 100%); }
.total { font-family: var(--display); font-size: 56px; line-height: 1; color: var(--gold); margin: 6px 0 10px; text-shadow: 4px 4px 0 #7a3a1a; animation: score-slam .7s ease-out; }
.total small { font-size: 20px; color: var(--muted); text-shadow: none; margin-left: 6px; }
.reached { margin: 0 0 18px; font-size: 22px; color: var(--teal); }

/* Everyone's scores: smooth curve, you marked on it */
.curve { --plot-h: 130px; position: relative; margin: 4px 0 30px; }
.curve svg { display: block; width: 100%; height: var(--plot-h); overflow: visible; }
.curve .area { fill: #5ee6c922; }
.curve .ln { fill: none; stroke: var(--teal); stroke-width: 3; vector-effect: non-scaling-stroke; }
.curve .you { stroke: var(--rose); stroke-width: 2; vector-effect: non-scaling-stroke; }
.you-dot { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; background: var(--rose); box-shadow: 0 0 0 2px var(--edge-dark), 0 0 10px var(--rose); }
.you-lbl { position: absolute; top: calc(100% + 2px); transform: translateX(-50%); font-weight: normal; font-size: 18px; color: var(--rose); letter-spacing: 1px; }
.axis { display: flex; justify-content: space-between; border-top: 2px solid var(--edge); padding-top: 4px; font-size: 16px; color: var(--muted); }
.axis span { width: 0; display: flex; justify-content: center; }
.pct { margin: 0 0 22px; font-size: 22px; color: var(--teal); text-transform: uppercase; letter-spacing: 1px; }

/* Time log: a stake per question over dashed tier lines */
.log-title { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; font-weight: normal; }
.log-title span { color: #6a5f8a; }
.log-title::after { content: ""; flex: 1; border-top: 2px dashed var(--edge); }
.tlog { position: relative; height: 182px; margin: 0 14px 34px 30px; border-left: 2px solid var(--edge); }
.guide { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed var(--c); opacity: .4; }
.guide span { position: absolute; top: 100%; left: 0; transform: translateX(-50%); padding-top: 6px; font-size: 16px; color: var(--c); }
.stake { position: absolute; left: 0; height: 0; width: var(--h); border-top: 2px solid var(--c); margin-top: -1px; animation: stake-out .5s steps(10) backwards; }
.stake i { position: absolute; right: -7px; top: -7px; width: 12px; height: 12px; background: var(--c); box-shadow: 0 0 0 2px var(--edge-dark), 0 0 10px var(--c); }
.stake b { position: absolute; right: calc(100% + 10px); top: -10px; font-weight: normal; font-size: 18px; color: var(--muted); }

.tiles { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 4px; font-size: 20px; }
.tiles li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 4px 8px; background: var(--night-2); animation: fade-up .3s both; }
.tiles li > span:first-child { display: grid; grid-template-columns: 22px 1fr; }
.tiles li b { font-weight: normal; color: var(--muted); }
.tiles li small { grid-column: 2; font-size: 17px; color: var(--muted); }
.tiles li > span:last-child { color: var(--night); padding: 0 8px; flex: none; }
.row { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 8px; }
.card .hint { text-shadow: none; color: var(--muted); }

/* ---------- Animations ---------- */
@keyframes title-flicker { 0%, 93%, 95.5%, 100% { opacity: 1 } 93.6% { opacity: .65 } 94.4% { opacity: .95 } 95% { opacity: .6 } }
@keyframes crt-zap { 0%, 96% { opacity: 1 } 97% { opacity: .4; transform: translateY(2px) } 98% { opacity: .8; transform: translateY(-1px) } }
@keyframes card-in { from { opacity: 0; transform: translateY(30px) scale(.94) } }
@keyframes score-slam { 0% { transform: scale(1) } 35% { transform: scale(1.35) rotate(-2deg); filter: drop-shadow(0 0 14px #ffd166) } 100% { transform: scale(1) } }
@keyframes shake { 0%, 100% { transform: translate(0) } 20% { transform: translate(-8px, 3px) } 40% { transform: translate(7px, -3px) } 60% { transform: translate(-5px, 2px) } 80% { transform: translate(3px, -1px) } }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px) } }
@keyframes glow-pulse { 50% { opacity: .55 } }
@keyframes btn-bob { 0%, 100% { translate: 0 0 } 50% { translate: 0 -3px } }
@keyframes pip-pop { 50% { transform: scale(1.3) } }
@keyframes grow { from { transform: scaleX(0) } }
@keyframes shimmer { to { background-position: -300% 0 } }
@keyframes flashbang { 0% { opacity: .85 } 100% { opacity: 0 } }
@keyframes sign-tumble { 30% { transform: translate(0%, -170%) rotate(80deg) } 100% { transform: translate(60%, 160%) rotate(200deg); opacity: 0 } }
@keyframes fade-in { from { opacity: 0 } }
@keyframes sign-pop { from { transform: translate(-50%, -100%) scale(.2) } }
@keyframes stake-out { from { width: 0 } }
@keyframes drop { from { opacity: 0; transform: translateY(-16px) } }

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  body { font-size: 21px; }
  /* one row: era · small progress pips · score */
  .hud { top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; justify-content: space-between; gap: 8px; } /* pips float midway between the tags */
  .tag { font-size: 19px; padding: 2px 6px; }
  .tag.mute { right: 12px; bottom: max(10px, env(safe-area-inset-bottom)); padding: 3px; }
  #era-tag { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .pips { gap: 3px; }
  .pip { width: 8px; height: 8px; box-shadow: 0 0 0 1px var(--edge-dark), 0 0 0 2px var(--edge); }
  .pip.now { box-shadow: 0 0 0 1px var(--edge-dark), 0 0 0 2px var(--teal), 0 0 6px #5ee6c988; }
  .stage { top: 56px; padding: 8px 16px 16px; }
  .card { padding: 14px 16px; }
  .logo { font-size: 32px; letter-spacing: 2px; }
  .eyebrow { font-size: 18px; }
  .rules { padding-left: 18px; }
  .bands { font-size: 18px; }
  .prompt-card { padding: 14px 18px; }
  .prompt { font-size: 38px; }
  .context { font-size: 22px; margin-top: 8px; }
  .btn { font-size: 24px; }

  .ground { padding-bottom: env(safe-area-inset-bottom); }
  .answer { gap: 10px; }
  .answer .btn { font-size: 28px; padding: 0 18px; }
  #guess { width: 150px; font-size: 50px; letter-spacing: 4px; text-indent: 4px; padding: 2px 8px; }
  .timer { width: 54px; height: 54px; }
  #timer-num { font-size: 28px; }
  .hint { font-size: 18px; }

  .sign { font-size: 26px; }
  .mark-line span { font-size: 18px; }
  .mark-line.target.passed span { font-size: 22px; }

  .lbl b { font-size: 18px; }
  .verdict { font-size: 20px; flex-wrap: wrap; }
  .points { font-size: 26px; }
  .fact { font-size: 20px; }
  .total { font-size: 44px; }
  .tlog { height: 168px; }
  .reached { font-size: 20px; }
  .tiles { font-size: 18px; }
  #reveal { align-self: start; } /* keep the traveller in view below it */
  body[data-view="reveal"] .sign, body[data-view="reveal"] .flash { display: none; } /* tucked behind the card; it repeats them */
}

/* Landscape phones: little height to spare */
@media (max-height: 500px) {
  .hud { top: max(8px, env(safe-area-inset-top)); grid-template-columns: 1fr auto 1fr; }
  .tag { font-size: 20px; padding: 2px 8px; }
  .stage { top: 46px; padding: 6px 16px 10px; }
  .card { padding: 10px 16px; }
  .logo { font-size: 28px; margin-bottom: 4px; }
  .rules { margin-bottom: 10px; }
  .rules li { margin: 2px 0; }
  .bands { margin-bottom: 12px; }
  .prompt { font-size: 34px; }
  .context { font-size: 20px; }
  .answer .btn { font-size: 26px; }
  #guess { font-size: 42px; width: 140px; }
  .timer { width: 48px; height: 48px; }
  .ground { gap: 4px; }
  .line { height: 112px; margin-bottom: 12px; }
  #reveal { justify-self: end; width: min(560px, 68%); } /* the traveller stands at the left */
}

/* Phone keyboard open (game.js sets body.kb and the --vv/--bar/--stage values) */
body.kb .hud { top: calc(var(--vv-top) + 8px); }
body.kb .stage { top: var(--stage-top); bottom: auto; height: var(--stage-h); padding: 4px 16px; align-items: start; } /* card under the HUD, clear of the traveller */
body.kb .ground { top: var(--bar-top); bottom: auto; height: auto; padding: 10px 0; gap: 6px; animation: none; }
body.kb .prompt { font-size: 32px; }
body.kb .context { font-size: 20px; }
body.kb-tight .hud, body.kb-tight .context, body.kb-tight .hint { display: none; }
body.kb-tight .prompt { font-size: 26px; }
body.kb-tight .prompt-card { padding: 8px 14px; }

@media (prefers-reduced-motion: reduce) {
  *, .crt { animation: none !important; transition: none !important; }
}
