/* ==========================================================================
   Smartfall: "1-bit"
   Black ink on white paper, pixel type, hard shadows, dithered greys.
   Mobile-first; centred at 520px on desktop.
   ========================================================================== */

/* Digits only, from Jersey 15: its 5 and 2 can't be mistaken for S and Z (Silkscreen's and
   Pixelify's can). unicode-range makes every number on the page use it automatically;
   size-adjust lifts it to the cap height of the other two pixel fonts. The weight range
   stops the browser faking a smeary bold. */
@font-face {
  font-family: 'SF Digits';
  src: url(https://fonts.gstatic.com/s/jersey15/v4/_6_9EDzuROGsUuk2TWjiZYAg.woff2) format('woff2');
  unicode-range: U+0030-0039, U+002F;
  size-adjust: 115%;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: #000;
  --paper: #fff;
  --muted: #555;
  --line: 3px;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);

  /* 1-bit tones (crisp SVG tiles) */
  --dither-12: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' shape-rendering='crispEdges'%3E%3Crect width='1' height='1'/%3E%3Crect x='2' y='2' width='1' height='1'/%3E%3C/svg%3E");
  --dither-25: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' shape-rendering='crispEdges'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E");
  --dither-50: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' shape-rendering='crispEdges'%3E%3Crect width='1' height='1'/%3E%3Crect x='1' y='1' width='1' height='1'/%3E%3C/svg%3E");
  --diag: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='6' height='6' shape-rendering='crispEdges'%3E%3Crect width='1' height='1'/%3E%3Crect x='1' y='1' width='1' height='1'/%3E%3Crect x='2' y='2' width='1' height='1'/%3E%3Crect x='3' y='3' width='1' height='1'/%3E%3Crect x='4' y='4' width='1' height='1'/%3E%3Crect x='5' y='5' width='1' height='1'/%3E%3C/svg%3E");

  --font-ui: 'SF Digits', 'Pixelify Sans', ui-monospace, 'Courier New', monospace;
  --font-display: 'SF Digits', 'Silkscreen', 'Pixelify Sans', ui-monospace, monospace;
  --font-mono: 'SF Digits', 'Silkscreen', 'Pixelify Sans', ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.35;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
canvas { image-rendering: pixelated; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.defs { position: absolute; }
:focus-visible { outline: 3px dashed var(--ink); outline-offset: 3px; }
kbd {
  font-family: var(--font-mono); font-size: .72em; padding: 1px 5px; margin: 0 1px;
  border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); background: var(--paper);
}

/* --------------------------------------------------------------------- screen texture */
#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -4; display: block; }
.grid-paper {
  position: fixed; inset: 0; z-index: -3; pointer-events: none; opacity: .1;
  background-image: radial-gradient(var(--ink) 1px, transparent 1.2px);
  background-size: 12px 12px;
}
/* LCD screen-door: a faint pixel lattice over everything */
.scanlines {
  position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: .045;
  background:
    linear-gradient(var(--ink) 1px, transparent 1px) 0 0 / 3px 3px,
    linear-gradient(90deg, var(--ink) 1px, transparent 1px) 0 0 / 3px 3px;
}
/* danger: dithered edges creeping in */
#vignette {
  position: fixed; inset: 0; z-index: 30; pointer-events: none; opacity: 0;
  background: var(--dither-50);
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 55%, #000 100%);
  mask-image: radial-gradient(ellipse at center, transparent 55%, #000 100%);
}
body.danger #vignette { animation: danger-pulse 1.2s steps(3) infinite; }
@keyframes danger-pulse { 0%, 100% { opacity: .35; } 50% { opacity: .9; } }
/* losses: the whole screen inverts for a beat */
#bloom { position: fixed; inset: 0; z-index: 88; pointer-events: none; opacity: 0; backdrop-filter: invert(1); -webkit-backdrop-filter: invert(1); }
#bloom.invert { animation: invert-flash .26s steps(1) 1; }
@keyframes invert-flash { 0% { opacity: 1; } 35% { opacity: 0; } 60% { opacity: 1; } 100% { opacity: 0; } }

body.desat #app::after {
  content: ''; position: fixed; inset: 0; z-index: 50; pointer-events: none;
  background: var(--dither-25); opacity: .55; animation: fade-steps 1.2s steps(5) both;
}
@keyframes fade-steps { from { opacity: 0; } to { opacity: .55; } }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 60; pointer-events: none; }
#overlay-layer { position: fixed; inset: 0; z-index: 70; pointer-events: none; }

/* --------------------------------------------------------------------- layout */
#app {
  position: relative; max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding: 0 16px; padding-bottom: env(safe-area-inset-bottom);
}
.screen { min-height: 100vh; min-height: 100dvh; }
.top-spacer { flex: 1; }

/* --------------------------------------------------------------------- shared components */
.card {
  position: relative; background: var(--paper);
  border: var(--line) solid var(--ink); box-shadow: 6px 6px 0 var(--ink);
}
.icon-btn {
  width: 40px; height: 40px; border: 0; background: transparent; padding: 0;
  display: inline-grid; place-items: center; color: var(--ink);
}
.icon-btn:hover { background: var(--ink); color: var(--paper); }
.icon-btn:active { transform: translate(1px, 1px); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: square; stroke-linejoin: miter; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.mute-btn .off { display: none; }
body.muted .mute-btn .on { display: none; }
body.muted .mute-btn .off { display: inline; }

.btn {
  position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: var(--line) solid var(--ink); background: var(--paper); color: var(--ink);
  padding: 10px 18px; font-weight: 600; min-height: 48px; box-shadow: var(--shadow);
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active, .btn.pressed { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { cursor: default; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-xl .btn-label::before { content: '▶ '; animation: blink 1s steps(1) infinite; }
.btn-ghost { background: var(--paper); }
.btn-xl { width: 100%; min-height: 76px; font-size: 18px; }
.btn-lg { min-height: 54px; font-size: 16px; }
.btn-label { font-family: var(--font-display); font-weight: 700; font-size: .95em; letter-spacing: .02em; }
.btn-sub { font-size: 13px; font-weight: 400; opacity: .85; }
.link-btn { background: none; border: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; padding: 8px; }
.link-btn:hover { background: var(--ink); color: var(--paper); text-decoration: none; }
.pulse { animation: nudge 1.2s steps(1) infinite; }
@keyframes nudge { 0%, 100% { transform: none; box-shadow: var(--shadow); } 50% { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); } }
@keyframes blink { 50% { opacity: 0; } }
.tag {
  font-family: var(--font-display); font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 6px; background: var(--ink); color: var(--paper); border: 2px solid var(--ink);
}
.tag.endless { background: var(--paper); color: var(--ink); }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 18px 0 22px; }

/* --------------------------------------------------------------------- pixel mascot */
.mascot { display: block; overflow: visible; }
.mascot .ink { fill: var(--ink); }
.mascot .paper { fill: var(--paper); }
.mascot .arm-a { animation: wave-a 1s steps(1) infinite; }
.mascot .arm-b { visibility: hidden; animation: wave-b 1s steps(1) infinite; }
@keyframes wave-a { 0%, 49% { visibility: visible; } 50%, 100% { visibility: hidden; } }
@keyframes wave-b { 0%, 49% { visibility: hidden; } 50%, 100% { visibility: visible; } }
.mascot .mascot-body { transform-box: fill-box; transform-origin: 50% 100%; }
.mascot.jump .mascot-body { animation: m-jump .5s steps(5) 1; }
.mascot.cheer .mascot-body { animation: m-jump .35s steps(3) 2; }
.mascot.flinch .mascot-body { animation: m-flinch .45s steps(4) 1; }
.mascot.nervous .mascot-body { animation: m-shiver .3s steps(2) infinite; }
.mascot.fallen .arm { animation: none; }
.mascot.fallen .arm-b { visibility: hidden; }
.mascot.fallen .mascot-body { transform-origin: 50% 50%; transform: translateY(3px) rotate(90deg); transition: transform .8s steps(4); }
@keyframes m-jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-5px); } 70% { transform: translateY(-2px); } }
@keyframes m-flinch { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-2px) rotate(-8deg); } 75% { transform: translateX(2px) rotate(6deg); } }
@keyframes m-shiver { 0% { transform: translateX(-.5px); } 100% { transform: translateX(.5px); } }

/* the squishable home brain */
.brain-btn {
  display: block; width: 156px; height: 117px; margin: 6px auto 14px; padding: 0; border: 0; background: none;
  cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.brain { display: block; width: 100%; height: 100%; overflow: visible; transform-origin: 50% 92%; }
.brain .ink { fill: var(--ink); }
.brain .paper { fill: var(--paper); }
.brain-btn .brain { animation: brain-idle 2.4s steps(2) infinite; }
@media (hover: hover) { .brain-btn:hover .brain { transform: scale(1.04); } }
.brain-btn:active .brain { transform: scale(1.1, .86); animation: none; }
.brain-btn.squish .brain { animation: squish .6s cubic-bezier(.25, 1.4, .5, 1) 1; }
@keyframes brain-idle { 50% { transform: translateY(-2px); } }
@keyframes squish {
  0% { transform: scale(1, 1); }
  14% { transform: scale(1.22, .7); }
  34% { transform: scale(.88, 1.14); }
  54% { transform: scale(1.06, .95); }
  74% { transform: scale(.98, 1.02); }
  100% { transform: scale(1, 1); }
}
body.reduce-motion .brain-btn.squish .brain { animation: none !important; }

/* --------------------------------------------------------------------- home */
#screen-home { display: flex; flex-direction: column; gap: 16px; padding-top: env(safe-area-inset-top); }
.home-top { display: flex; align-items: center; gap: 4px; padding-top: 10px; }
.home-hero { text-align: center; }
.wordmark { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: clamp(30px, 10.6vw, 52px); letter-spacing: .02em; line-height: 1; }
.wm-text { color: var(--ink); text-shadow: 3px 3px 0 var(--paper), 5px 5px 0 var(--ink); }
.brainwave { width: min(300px, 80%); height: 28px; margin: 10px auto 0; display: block; overflow: visible; }
.brainwave path { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linejoin: miter; stroke-linecap: square; stroke-dasharray: 520; animation: wave-run 3s steps(26) infinite; }
@keyframes wave-run { 0% { stroke-dashoffset: 520; } 70%, 100% { stroke-dashoffset: 0; } }
.tagline { color: var(--ink); margin: 12px 0 0; font-size: 16px; }
.tagline b { font-weight: 700; }
.tagline .floor-word { background: var(--ink); color: var(--paper); padding: 0 4px; }
.home-daily { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.daily-head { display: flex; align-items: center; justify-content: space-between; }
.daily-num { font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.daily-num small { font-family: var(--font-ui); color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 6px; }
.daily-streak { font-size: 15px; display: inline-flex; align-items: center; gap: 4px; }
.daily-streak .flame-ic { display: inline-block; width: 12px; height: 15px; animation: flicker 1s steps(2) infinite; }
@keyframes flicker { 50% { transform: translateY(-2px); } }
.next-daily { color: var(--muted); font-size: 14px; text-align: center; }
.next-daily .mono { color: var(--ink); }
#h-endless { width: 100%; }
.done-card { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.done-row { display: flex; justify-content: space-around; text-align: center; }
.done-row b { display: block; font-family: var(--font-display); font-size: 24px; }
.done-row span { font-size: 13px; color: var(--muted); }
.done-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0 auto; }
.done-grid .tier-group { gap: 2px; }
.done-grid .gcell { width: 15px; height: 15px; font-size: 8px; }
.done-pct { text-align: center; font-weight: 700; }

/* --------------------------------------------------------------------- game: top bar + HUD */
#screen-game {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0;
  padding-top: env(safe-area-inset-top);
}
.topbar { display: flex; align-items: center; gap: 6px; height: 46px; flex: none; min-width: 0; border-bottom: var(--line) solid var(--ink); margin: 0 -16px; padding: 0 12px; }
.logo-sm { font-family: var(--font-display); font-weight: 700; font-size: 13px; letter-spacing: .02em; background: none; border: 0; padding: 4px 2px; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-sm:hover { background: var(--ink); color: var(--paper); }
.qnum { font-weight: 700; font-size: 15px; flex: none; }
.topbar .icon-btn { width: 34px; height: 34px; flex: none; }
.topbar .tag { flex: none; }

.hud { text-align: center; flex: none; display: flex; flex-direction: column; align-items: center; perspective: 600px; padding-top: 8px; }
.rank-badge {
  display: inline-block; font-family: var(--font-display); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 8px; background: var(--ink); color: var(--paper); transform-style: preserve-3d;
}
.rank-badge.flip { animation: rank-flip .5s steps(5); }
@keyframes rank-flip { 0% { transform: rotateX(0); } 45% { transform: rotateX(90deg); } 55% { transform: rotateX(-90deg); } 100% { transform: rotateX(0); } }
body.gold-tier .rank-badge::before { content: '★ '; }
body.gold-tier .rank-badge::after { content: ' ★'; }
body.danger .rank-badge { animation: blink 1.2s steps(1) infinite; }

.iq-row { position: relative; margin-top: 4px; width: 100%; display: flex; justify-content: center; }
.hud-mascot { position: absolute; left: 4px; bottom: 0; width: 40px; height: 45px; }
.iq-num {
  --digit-w: .58em;
  --row: .88em;
  display: flex; justify-content: center; position: relative;
  font-family: var(--font-display); font-weight: 700; line-height: 1;
  font-size: clamp(68px, min(22vw, 12.4vh), 136px);
  height: var(--row); color: var(--ink);
  transform-origin: 50% 60%;
}
.iq-col { position: relative; width: var(--digit-w); height: var(--row); overflow: hidden; transition: width .3s steps(3); }
.iq-col.lead-hidden { width: 0; }
.iq-strip { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.iq-strip span { display: block; height: var(--row); line-height: var(--row); text-align: center; }
body.gold-tier .iq-strip span { text-shadow: 3px 3px 0 var(--paper), 6px 6px 0 var(--ink); }
body.danger .iq-num { animation: danger-num 1.2s steps(1) infinite; }
@keyframes danger-num { 0%, 60% { opacity: 1; } 61%, 100% { opacity: .35; } }
.iq-num.pop { animation: iq-pop .4s steps(4); }
@keyframes iq-pop { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 100% { transform: scale(1); } }
.iq-num.glitch { animation: glitch .2s steps(2) 1; }
.iq-num.glitch .iq-strip span, .iq-num.glitching .iq-strip span { text-shadow: -.06em 0 0 rgba(0,0,0,.35), .06em 0 0 rgba(0,0,0,.35); }
.iq-num.glitching { animation: glitch .24s steps(2) infinite; }
@keyframes glitch {
  0% { transform: translate(0, 0); clip-path: inset(0 0 0 0); }
  20% { transform: translate(-4px, 0); clip-path: inset(10% 0 55% 0); }
  40% { transform: translate(4px, 0); clip-path: inset(55% 0 8% 0); }
  60% { transform: translate(-2px, 0); clip-path: inset(30% 0 30% 0); }
  80% { transform: translate(3px, 0); clip-path: inset(0 0 70% 0); }
  100% { transform: translate(0, 0); clip-path: inset(0 0 0 0); }
}
.iq-sub { font-size: 14px; color: var(--ink); margin-top: 4px; }
.iq-sub b { font-weight: 700; }
.iq-sub .warn { background: var(--ink); color: var(--paper); padding: 0 4px; }

.iq-bar { position: relative; width: 100%; height: 12px; margin: 10px 0 4px; border: 2px solid var(--ink); background: var(--paper) var(--dither-12); }
.iq-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 25%; background: var(--ink); transition: width .4s steps(8); }
body.danger .iq-bar-fill { background: var(--paper) var(--dither-50); }
.iq-bar-floor { position: absolute; left: -2px; top: -7px; bottom: -7px; width: 4px; background: var(--ink); }
.iq-bar-floor span { position: absolute; top: 7px; left: 7px; font: 700 8px/1 var(--font-display); color: var(--paper); mix-blend-mode: difference; }
body.danger .iq-bar-floor { animation: blink .6s steps(1) infinite; }
.iq-bar-peak { position: absolute; top: -6px; bottom: -6px; width: 6px; margin-left: -3px; background: var(--paper); border: 2px solid var(--ink); left: 25%; transition: left .4s steps(8); }

/* --------------------------------------------------------------------- status row */
.status-row { display: flex; align-items: center; gap: 8px; height: 38px; margin-top: 8px; flex: none; }
.streak { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px 2px 4px; border: 2px solid var(--ink); background: var(--paper); }
.streak .flame { display: inline-block; width: calc(12px + var(--flame, 0) * .6px); height: calc(15px + var(--flame, 0) * .75px); opacity: .25; }
.flame svg, .flame-ic svg { display: block; width: 100%; height: 100%; fill: currentColor; }
.streak.lit .flame { opacity: 1; animation: flicker .8s steps(2) infinite; }
.streak-n { font-weight: 700; font-size: 15px; }
.streak-mult { font-size: 12px; font-weight: 700; }
.streak.bump { animation: bump .3s steps(3); }
@keyframes bump { 50% { transform: translateY(-3px); } }
body.fever .streak { background: var(--ink); color: var(--paper); }

.danger-chip {
  font: 700 11px var(--font-display); letter-spacing: .04em; padding: 3px 6px;
  background: var(--ink); color: var(--paper); animation: blink 1.2s steps(1) infinite;
}
.lifeline {
  height: 31px; padding: 0 10px; border: 2px solid var(--ink); background: var(--paper);
  font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px;
  box-shadow: var(--shadow-sm);
}
.lifeline:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.lifeline:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }
.lifeline:disabled { cursor: default; box-shadow: none; text-decoration: line-through; background: var(--paper) var(--dither-12); color: var(--muted); }

/* --------------------------------------------------------------------- timer */
.timer { position: relative; height: 12px; border: 2px solid var(--ink); background: var(--paper); margin: 6px 0 10px; flex: none; }
.timer-fill { position: absolute; inset: 0; right: auto; width: 100%; background: var(--ink); }
.timer.amber .timer-fill { background: var(--paper) var(--dither-50); }
.timer.red .timer-fill { background: var(--ink); animation: blink .5s steps(1) infinite; }
.timer.paused .timer-fill { opacity: .5; animation: none; }
.notch { position: absolute; top: -6px; bottom: -6px; width: 2px; background: var(--ink); font-size: 0; }
.notch-l { left: 75%; }
.notch-q { left: 50%; }
.notch-l::before, .notch-q::before { position: absolute; top: 7px; left: 5px; font: 700 8px/1 var(--font-display); color: var(--paper); mix-blend-mode: difference; white-space: nowrap; }
.notch-l::before { content: '×1.5'; }
.notch-q::before { content: '×1.2'; }

/* --------------------------------------------------------------------- question card */
.qcard {
  position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 10px;
  padding: 12px; overflow: hidden; background: var(--paper);
  border: var(--line) solid var(--ink); box-shadow: 5px 5px 0 var(--ink);
}
.qcard.scrolly { overflow-y: auto; }
/* the "camera window": questions fly in and out of this, clipped, room left for the hard shadow */
.qstage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; margin: 0 -6px -6px 0; padding: 0 6px 6px 0; }
.qstage > .qcard { will-change: transform; }
.qcard.enter { animation: card-in .24s steps(4); }
.qcard.leave { animation: card-out .2s steps(3) forwards; }
@keyframes card-in { from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes card-out { to { transform: translateX(-24px); opacity: 0; } }
/* Overclock: marching-ants border */
.qcard.overclock::before {
  content: ''; position: absolute; inset: 3px; pointer-events: none;
  background:
    linear-gradient(90deg, var(--ink) 50%, transparent 0) repeat-x 0 0 / 12px 3px,
    linear-gradient(90deg, var(--ink) 50%, transparent 0) repeat-x 0 100% / 12px 3px,
    linear-gradient(0deg, var(--ink) 50%, transparent 0) repeat-y 0 0 / 3px 12px,
    linear-gradient(0deg, var(--ink) 50%, transparent 0) repeat-y 100% 0 / 3px 12px;
  animation: ants .6s steps(4) infinite;
}
@keyframes ants { to { background-position: 12px 0, -12px 100%, 0 -12px, 100% 12px; } }
.q-head { display: flex; align-items: center; gap: 6px; flex: none; }
.chip { font: 700 10px var(--font-display); letter-spacing: .04em; padding: 3px 6px; background: var(--ink); color: var(--paper); }
.chip.oc { background: var(--paper); color: var(--ink); border: 2px solid var(--ink); padding: 1px 5px; animation: blink 1s steps(1) infinite; }
.chip.diff { background: var(--paper); color: var(--ink); border: 2px solid var(--ink); padding: 1px 5px; letter-spacing: 0; }
.q-prompt { font-size: 18px; font-weight: 600; line-height: 1.25; margin: 0; white-space: pre-line; flex: none; }
.q-prompt.small { font-size: 15.5px; }
.q-prompt.tiny { font-size: 14px; font-weight: 500; line-height: 1.25; }

.seq { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; flex: none; }
.seq span { font: 700 17px var(--font-display); padding: 6px 8px; min-width: 40px; text-align: center; border: 2px solid var(--ink); }
.seq span.q { background: var(--ink); color: var(--paper); animation: blink 1s steps(1) infinite; }

/* answer tiles */
.opts { display: grid; gap: 9px; grid-template-columns: 1fr; margin-top: auto; padding: 0 4px 4px 0; }
.opts.two { grid-template-columns: 1fr 1fr; }
.opts.three { grid-template-columns: 1fr 1fr 1fr; }
.tile {
  position: relative; min-height: 56px; border: var(--line) solid var(--ink); background: var(--paper);
  padding: 9px 10px 9px 36px; text-align: left; font-size: 16px; font-weight: 600; line-height: 1.15;
  display: flex; align-items: center; gap: 8px; overflow: hidden; box-shadow: var(--shadow-sm);
}
.tile .k { position: absolute; left: 7px; top: 50%; transform: translateY(-50%); font: 700 10px var(--font-display); width: 19px; height: 19px; display: grid; place-items: center; border: 2px solid currentColor; }
.tile .lbl { flex: 1; min-width: 0; }
.tile .ic { margin-left: auto; font-weight: 700; font-size: 20px; visibility: hidden; }
.opts.long .tile { font-size: 14.5px; line-height: 1.12; padding-top: 6px; padding-bottom: 6px; }
.opts.three .tile { padding-left: 30px; padding-right: 6px; }
.opts.three .tile .k { left: 6px; }
.tile.mono-tile { font-family: var(--font-display); font-size: 19px; justify-content: center; padding-left: 30px; }
.tile.mono-tile .lbl { text-align: center; }
@media (hover: hover) { .tile:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); } }
.tile:active:not(:disabled), .tile.pressed { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.tile:disabled { cursor: default; color: var(--ink); }
.tile.removed { background: var(--paper) var(--dither-12); color: var(--muted); box-shadow: none; text-decoration: line-through; pointer-events: none; border-style: dashed; }
.tile.locking::after { content: ''; position: absolute; inset: 0; background: var(--dither-25); opacity: .5; animation: shimmer .5s steps(4) infinite; }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.ripple { position: absolute; background: var(--ink); transform: scale(0); animation: ripple .35s steps(4) forwards; pointer-events: none; opacity: .5; }
@keyframes ripple { to { transform: scale(3.5); opacity: 0; } }
.tile.good { background: var(--ink); color: var(--paper); }
.tile.bad { background: var(--paper) var(--diag); animation: tile-shake .3s steps(3); }
.tile.bad .lbl { flex: 0 1 auto; background: var(--paper); text-decoration: line-through; text-decoration-thickness: 2px; padding: 0 3px; }
.tile.reveal { outline: 3px solid var(--ink); outline-offset: 3px; animation: blink .5s steps(1) 4; }
.tile.good .ic, .tile.bad .ic, .tile.reveal .ic { visibility: visible; }
.tile.bad .ic { background: var(--paper); padding: 0 2px; }
.tile.dim { opacity: .35; box-shadow: none; }
@keyframes tile-shake { 33% { transform: translateX(-4px); } 66% { transform: translateX(4px); } }

/* matrix */
.matrix-wrap { display: flex; flex-direction: column; gap: 10px; align-items: center; flex: 1 1 auto; min-height: 0; justify-content: space-between; }
.matrix {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; background: var(--ink);
  width: min(100%, 21vh, 220px); aspect-ratio: 1; flex: none; border: var(--line) solid var(--ink);
}
.matrix .cell { background: var(--paper); display: grid; place-items: center; }
.matrix .cell svg { width: 100%; height: 100%; }
.matrix .cell.missing { font: 700 22px var(--font-display); background: var(--paper) var(--dither-12); }
.matrix .cell.missing.filled { background: var(--paper); }
.opts.matrix-opts { grid-template-columns: repeat(3, 1fr); width: 100%; margin-top: 0; }
.tile.mtile { padding: 3px; min-height: 56px; height: clamp(56px, 8.4vh, 80px); justify-content: center; }
.tile.mtile svg { height: 100%; max-height: 64px; width: auto; aspect-ratio: 1; }
.tile.mtile .k { top: 6px; transform: none; }
.tile.mtile .ic { position: absolute; right: 5px; top: 2px; font-size: 16px; }
.tile.mtile.good { background: var(--paper); outline: 4px solid var(--ink); outline-offset: -8px; }
.tile.mtile.good .ic { color: var(--ink); }
.shape { stroke: var(--ink); stroke-width: 4; stroke-linejoin: miter; }
.shape.solid { fill: var(--ink); }
.shape.outline { fill: none; }
.shape.striped { fill: url(#sf-stripes); }

/* estimation */
.est { display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding: 0 4px 4px 0; }
.est-input-row { display: flex; align-items: stretch; gap: 8px; }
.nudge { width: 52px; min-height: 56px; border: var(--line) solid var(--ink); background: var(--paper); font: 700 24px var(--font-display); box-shadow: var(--shadow-sm); }
.nudge:active { transform: translate(3px, 3px); box-shadow: none; }
.est-field { flex: 1; position: relative; display: flex; align-items: center; border: var(--line) solid var(--ink); background: var(--paper); padding: 0 10px; min-width: 0; }
.est-field:focus-within { outline: 3px dashed var(--ink); outline-offset: 3px; }
.est-field input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; text-align: center; font: 700 24px var(--font-display); padding: 8px 0; }
.est-field input::placeholder { color: var(--muted); font-size: 16px; font-family: var(--font-ui); }
.est-unit { color: var(--muted); font-size: 14px; white-space: nowrap; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }
input[type=range].est-slider { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; }
input[type=range].est-slider::-webkit-slider-runnable-track { height: 10px; border: 2px solid var(--ink); background: var(--paper) var(--dither-12); }
input[type=range].est-slider::-moz-range-track { height: 6px; border: 2px solid var(--ink); background: var(--paper) var(--dither-12); }
input[type=range].est-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 26px; margin-top: -10px; border: 3px solid var(--ink); background: var(--paper); box-shadow: 2px 2px 0 var(--ink); border-radius: 0; }
input[type=range].est-slider::-moz-range-thumb { width: 18px; height: 22px; border: 3px solid var(--ink); background: var(--paper); border-radius: 0; }
.est-range { display: flex; justify-content: space-between; font: 700 10px var(--font-display); margin-top: -6px; }
.est-scale { position: relative; height: 60px; margin: 6px 8px 0; }
.est-scale .axis { position: absolute; left: 0; right: 0; top: 27px; height: 4px; background: var(--ink); }
.est-scale .band { position: absolute; top: 22px; height: 14px; background: var(--paper) var(--dither-50); border: 2px solid var(--ink); }
.est-scale .mk { position: absolute; top: 0; transform: translateX(-50%); text-align: center; font: 700 11px var(--font-display); white-space: nowrap; }
.est-scale .mk i { display: block; width: 4px; height: 24px; margin: 2px auto 0; background: var(--ink); }
.est-scale .mk.guess span { border: 2px solid var(--ink); padding: 0 3px; background: var(--paper); }
.est-scale .mk.actual { top: 30px; }
.est-scale .mk.actual i { height: 14px; margin: 0 auto 2px; }
.est-scale .mk.actual span { background: var(--ink); color: var(--paper); padding: 0 3px; }

/* connections */
.conn { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin-top: auto; padding: 0 3px 3px 0; }
.word {
  min-height: 48px; border: var(--line) solid var(--ink); background: var(--paper); box-shadow: var(--shadow-sm);
  font-weight: 700; font-size: 16px; padding: 4px 8px 4px 24px; position: relative; overflow-wrap: anywhere;
}
.word .k { position: absolute; left: 7px; top: 50%; transform: translateY(-50%); font: 700 9px var(--font-display); }
.word.sel { background: var(--ink); color: var(--paper); transform: translate(3px, 3px); box-shadow: none; }
.word.locked { border-style: dashed; }
.word.locked::after { content: '■'; position: absolute; right: 6px; top: 3px; font-size: 9px; }
.word.good { background: var(--ink); color: var(--paper); box-shadow: none; }
.word.good::before, .word.missed::before { content: '✓'; position: absolute; right: 6px; bottom: 2px; font-weight: 700; }
.word.missed { outline: 3px solid var(--ink); outline-offset: 2px; animation: blink .5s steps(1) 4; }
.word.bad { background: var(--paper) var(--diag); text-decoration: line-through; }
.word.bad::before { content: '✕'; position: absolute; right: 6px; bottom: 2px; font-weight: 700; background: var(--paper); }
.word.dim { opacity: .35; box-shadow: none; }
.word:disabled { cursor: default; color: inherit; }
.word.good:disabled, .word.sel:disabled { color: var(--paper); }
.conn-foot { display: flex; align-items: center; gap: 10px; padding-right: 4px; }
.conn-count { font: 500 13px var(--font-ui); color: var(--muted); flex: 1; }
.conn-foot .lockin { flex: 0 0 auto; min-height: 44px; padding: 6px 18px; }
.lockin { flex: 1; }
.btn.lockin:disabled { background: var(--paper) var(--dither-12); color: var(--muted); box-shadow: none; transform: none; }
.link-reveal { text-align: center; font-weight: 700; font-size: 15px; background: var(--ink); color: var(--paper); padding: 4px 8px; width: 100%; }

/* --------------------------------------------------------------------- stakes + spark + feedback */
.dock { position: relative; flex: none; }
.stakes { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 12px; border: var(--line) solid var(--ink); flex: none; position: relative; }
.stakes button { height: 40px; border: 0; border-left: var(--line) solid var(--ink); background: var(--paper); display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 15px; }
.stakes button:first-child { border-left: 0; }
.stakes button b { font-weight: 700; }
.stakes button span { font-size: 11px; }
.stakes button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.stakes button[data-stake="allin"][aria-checked="true"] b::before { content: '!'; display: inline-block; margin-right: 3px; animation: blink .6s steps(1) infinite; }
.stakes.locked button { pointer-events: none; }
#spark { width: 100%; height: 40px; display: block; margin: 8px 0 10px; flex: none; }

.feedback {
  position: absolute; left: 0; right: 0; bottom: 6px; z-index: 5; padding: 8px 10px;
  background: var(--paper); border: var(--line) solid var(--ink); box-shadow: 5px 5px 0 var(--ink);
  display: flex; flex-direction: column; gap: 6px; animation: fb-in .2s steps(3);
}
@keyframes fb-in { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }
.feedback .fb-title { flex-wrap: wrap; font-family: var(--font-display); font-weight: 700; font-size: 12px; display: flex; align-items: baseline; column-gap: 6px; }
.feedback.good .fb-title { align-self: flex-start; background: var(--ink); color: var(--paper); padding: 1px 6px; }
.feedback .fb-title .muted { font: 600 13.5px var(--font-ui) !important; color: var(--ink); }
.feedback .fb-text { font-size: 14.5px; }
.feedback.compact { padding: 8px 12px; }
.feedback.compact .fb-text { font-size: 13.5px; color: var(--muted); }
.feedback.has-next { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; row-gap: 3px; align-items: center; }
.feedback.has-next .fb-title, .feedback.has-next .fb-text { grid-column: 1; }
.feedback.has-next .fb-text { font-size: 13.5px; line-height: 1.2; }
.fb-next { grid-column: 2; grid-row: 1 / span 2; min-height: 46px; min-width: 92px; padding: 6px 12px; position: relative; flex-direction: row; overflow: hidden; }
.fb-next .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--paper); width: 100%; transform-origin: left; animation: fb-count 4s steps(16) forwards; }
@keyframes fb-count { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* --------------------------------------------------------------------- floating fx text */
.tally { position: fixed; z-index: 75; pointer-events: none; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 3px; }
.tally .t-item { font: 700 12px var(--font-display); padding: 2px 6px; white-space: nowrap; background: var(--paper); border: 2px solid var(--ink); animation: stamp-in .16s steps(2); }
.tally .t-item.base { font-size: 14px; }
.tally .t-item.gold, .tally .t-item.hot { background: var(--ink); color: var(--paper); }
.tally .t-total { font: 700 32px var(--font-display); margin-top: 2px; animation: stamp-in .2s steps(3); }
.tally .t-total, .flyer {
  color: var(--ink);
  text-shadow: 3px 0 0 var(--paper), -3px 0 0 var(--paper), 0 3px 0 var(--paper), 0 -3px 0 var(--paper), 3px 3px 0 var(--paper), -3px -3px 0 var(--paper), 3px -3px 0 var(--paper), -3px 3px 0 var(--paper), 6px 6px 0 var(--ink);
}
@keyframes stamp-in { from { transform: scale(1.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.flyer { position: fixed; z-index: 76; pointer-events: none; font: 700 32px var(--font-display); transform: translate(-50%, -50%); will-change: left, top, transform; }

.stamp {
  position: fixed; left: 50%; top: 38%; z-index: 80; pointer-events: none; white-space: nowrap;
  font: 700 clamp(26px, 8.5vw, 46px) var(--font-display); padding: 8px 14px;
  background: var(--ink); color: var(--paper); box-shadow: 6px 6px 0 var(--paper), 9px 9px 0 var(--ink);
  transform: translate(-50%, -50%) rotate(-4deg);
  animation: stamp-punch 1.1s steps(1) forwards;
}
.stamp small { display: block; font: 600 14px var(--font-ui); text-align: center; margin-top: 2px; }
@keyframes stamp-punch {
  0% { transform: translate(-50%, -50%) rotate(-4deg) scale(2.2); opacity: 0; }
  8% { transform: translate(-50%, -50%) rotate(-4deg) scale(1.3); opacity: 1; }
  16% { transform: translate(-50%, -50%) rotate(-4deg) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
.banner {
  position: fixed; left: 50%; top: 16%; z-index: 81; pointer-events: none; transform: translateX(-50%);
  padding: 12px 18px; white-space: nowrap; font: 700 clamp(15px, 5vw, 24px) var(--font-display);
  background: var(--paper); color: var(--ink); border: 4px solid var(--ink); box-shadow: 8px 8px 0 var(--ink);
  animation: banner 2.6s steps(1) forwards;
}
.banner::before, .banner::after { content: '★'; margin: 0 8px; animation: blink .4s steps(1) infinite; }
@keyframes banner { 0% { opacity: 0; } 5% { opacity: 1; transform: translateX(-50%) translateY(-6px); } 10% { transform: translateX(-50%); } 90% { opacity: 1; } 100% { opacity: 0; } }

.overclock-intro {
  position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; text-align: center; pointer-events: none;
  background: var(--ink); color: var(--paper); animation: oc-intro .9s steps(1) forwards;
}
.overclock-intro h2 { margin: 0; font: 700 clamp(24px, 8.5vw, 52px) var(--font-display); animation: blink .15s steps(1) infinite; }
.overclock-intro p { margin: 10px 0 0; font-size: 18px; font-weight: 600; }
@keyframes oc-intro { 0% { opacity: 1; } 8% { background: var(--paper); color: var(--ink); } 16% { background: var(--ink); color: var(--paper); } 85% { opacity: 1; } 100% { opacity: 0; } }

.game-over-text {
  position: fixed; left: 50%; top: 42%; z-index: 86; transform: translate(-50%, -50%); pointer-events: none;
  font: 700 clamp(24px, 7.5vw, 42px) var(--font-display); white-space: nowrap;
  background: var(--ink); color: var(--paper); padding: 10px 16px; box-shadow: 8px 8px 0 var(--paper), 11px 11px 0 var(--ink);
}
.game-over-text::after { content: '█'; animation: blink .6s steps(1) infinite; margin-left: 2px; }

.target-hit { position: fixed; z-index: 79; pointer-events: none; width: 120px; height: 120px; transform: translate(-50%, -50%); }
.target-hit i { position: absolute; inset: 0; border: 4px solid var(--ink); border-radius: 50%; animation: target .8s steps(5) forwards; }
.target-hit i:nth-child(2) { inset: 25%; animation-delay: .08s; }
.target-hit i:nth-child(3) { inset: 42%; background: var(--ink); animation-delay: .16s; }
@keyframes target { 0% { transform: scale(2.2); opacity: 0; } 40% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* --------------------------------------------------------------------- toasts */
#toasts { position: fixed; left: 50%; top: max(54px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast {
  padding: 7px 12px; font-weight: 600; font-size: 15px; text-align: center;
  background: var(--ink); color: var(--paper); box-shadow: 4px 4px 0 var(--paper), 6px 6px 0 var(--ink);
  animation: toast-in .2s steps(3), toast-out .2s steps(2) 2.2s forwards;
}
.toast.loss { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); box-shadow: var(--shadow); }
@keyframes toast-in { from { transform: translateY(-12px); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(-8px); opacity: 0; } }

/* --------------------------------------------------------------------- 1-bit result glyphs */
.gcell { position: relative; display: inline-grid; place-items: center; width: 100%; aspect-ratio: 1; border: 2px solid var(--ink); background: var(--paper); font: 700 11px var(--font-display); line-height: 1; }
.gcell.g-correct { background: var(--ink); }
.gcell.g-oc { background: var(--ink); color: var(--paper); }
.gcell.g-oc::after { content: '×2'; font-size: 8px; }
.gcell.g-bull::after { content: ''; width: 34%; aspect-ratio: 1; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.gcell.g-partial { background: linear-gradient(135deg, var(--ink) 50%, var(--paper) 50%); }
.gcell.g-wrong { background: var(--paper) var(--diag); }
.gcell.g-timeout { background: var(--paper) var(--dither-25); }
.gcell.g-skip { border-style: dashed; }

/* --------------------------------------------------------------------- results sheet */
.sheet-backdrop, .modal-backdrop { position: fixed; inset: 0; z-index: 95; background: var(--paper) var(--dither-25); opacity: .6; animation: fade-in .2s steps(2); }
@keyframes fade-in { from { opacity: 0; } }
.sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 96; width: min(520px, 100%); max-height: 94dvh; overflow-y: auto;
  transform: translateX(-50%); padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
  background: var(--paper); border: 4px solid var(--ink); border-bottom: 0;
  animation: sheet-up .4s steps(6);
}
@keyframes sheet-up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.sheet-grip { width: 42px; height: 6px; background: var(--ink); margin: 0 auto 10px; }
.r-title { margin: 4px 0 0; text-align: center; font: 700 22px var(--font-display); }
.r-rank { margin: 6px auto 14px; text-align: center; font: 700 11px var(--font-display); text-transform: uppercase; background: var(--ink); color: var(--paper); padding: 3px 8px; width: fit-content; }
.r-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.r-stat { border: 3px solid var(--ink); box-shadow: var(--shadow-sm); padding: 10px 4px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.r-val { font-size: clamp(22px, 7.5vw, 30px); font-weight: 700; }
.r-lab { font-size: 13px; color: var(--muted); }
.r-pct { margin: 16px 0 4px; }
.r-pct-text { font-weight: 700; text-align: center; margin-bottom: 6px; font-size: 16px; }
/* bell curve: "you beat X%" (drawn by bellcurve.js on a pixelated canvas) */
.bell { position: relative; padding-top: 18px; }
.bell canvas { display: block; width: 100%; height: 72px; }
.bell.small { padding-top: 16px; }
.bell.small canvas { height: 48px; }
.bell-you {
  position: absolute; top: 0; transform: translateX(-50%); font: 700 10px/1 var(--font-display);
  background: var(--ink); color: var(--paper); padding: 2px 4px; white-space: nowrap; visibility: hidden;
}
.bell-you.on { visibility: visible; animation: stamp-in .2s steps(2); }
.bell-you::after { content: ''; position: absolute; left: 50%; top: 100%; margin-left: -3px; border: 3px solid transparent; border-top-color: var(--ink); }
.r-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin: 16px auto 4px; max-width: 300px; }
.r-grid .gcell { width: 26px; }
.r-grid.tiers { gap: 7px; max-width: none; flex-wrap: nowrap; }
.tier-group { display: inline-flex; gap: 3px; }
.r-grid.tiers .gcell { width: 17px; }
.r-grid .gcell { animation: stamp-in .14s steps(2); }
.r-actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; margin-top: 16px; padding-right: 4px; }
.r-actions .btn { flex-direction: row; gap: 8px; }
.r-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.sheet .foot { padding-bottom: 8px; }

/* --------------------------------------------------------------------- modals */
.modal {
  position: fixed; left: 50%; top: 50%; z-index: 97; width: min(460px, calc(100vw - 28px)); max-height: calc(100dvh - 32px); overflow-y: auto;
  transform: translate(-50%, -50%); padding: 20px 18px 18px;
  background: var(--paper); border: 4px solid var(--ink); box-shadow: 8px 8px 0 var(--ink);
  animation: modal-in .2s steps(3);
}
@keyframes modal-in { from { opacity: 0; transform: translate(-50%, -46%); } }
.modal h2 { margin: 0 0 14px; font: 700 19px var(--font-display); }
.modal-x { position: absolute; top: 10px; right: 10px; }
.howto-track { display: flex; overflow: hidden; }
.howto-panel { flex: 0 0 100%; padding: 2px; }
.howto-panel h3 { margin: 14px 0 6px; font: 700 15px var(--font-display); }
.howto-panel p { margin: 0; font-size: 16px; }
.howto-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; padding-right: 4px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 10px; height: 10px; border: 2px solid var(--ink); cursor: pointer; }
.dots i.on { width: 22px; background: var(--ink); }
.howto-keys { color: var(--muted); font-size: 13px; margin: 14px 0 0; line-height: 2; }
@media (hover: none) { .howto-keys { display: none; } }
.demo { height: 130px; border: 3px solid var(--ink); background: var(--paper); position: relative; overflow: hidden; display: grid; place-items: center; }
.demo-answer .demo-tile { position: absolute; left: 12%; bottom: 20px; padding: 8px 12px; font: 700 15px var(--font-display); background: var(--ink); color: var(--paper); animation: demo-tap 3s steps(1) infinite; }
.demo-answer .demo-chip { position: absolute; left: 20%; bottom: 60px; font: 700 22px var(--font-display); animation: demo-fly 3s steps(12) infinite; }
.demo-answer .demo-iq { position: absolute; right: 12%; top: 22px; font: 700 42px var(--font-display); }
@keyframes demo-tap { 0%, 10% { transform: none; } 12% { transform: translate(3px, 3px); } 20%, 100% { transform: none; } }
@keyframes demo-fly { 0%, 22% { opacity: 0; transform: translate(0, 0); } 30% { opacity: 1; } 55% { opacity: 1; transform: translate(150px, -40px); } 60%, 100% { opacity: 0; transform: translate(160px, -44px); } }
.demo-seg { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); width: 88%; border: 3px solid var(--ink); font-size: 14px; font-weight: 700; text-align: center; }
.demo-seg span { position: relative; z-index: 1; padding: 10px 2px; color: var(--paper); mix-blend-mode: difference; }
.demo-thumb { position: absolute; top: 0; bottom: 0; left: 0; width: calc(100% / 3); background: var(--paper); animation: demo-thumb 4.5s steps(1) infinite; }
@keyframes demo-thumb { 0%, 32% { transform: translateX(0); } 33%, 65% { transform: translateX(100%); } 66%, 100% { transform: translateX(200%); } }
.demo-bar { position: relative; width: 82%; height: 16px; border: 3px solid var(--ink); background: var(--paper) var(--dither-12); }
.demo-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ink); animation: demo-drain 3.4s steps(10) infinite; }
.demo-floor-mark { position: absolute; left: 22%; top: -10px; bottom: -10px; width: 4px; background: var(--ink); }
.demo-floor-label { position: absolute; left: 13%; bottom: 22px; font: 700 11px var(--font-display); }
@keyframes demo-drain { 0% { width: 70%; } 80%, 100% { width: 18%; } }

.stats-body h3 { margin: 18px 0 8px; font: 700 12px var(--font-display); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-grid div { border: 3px solid var(--ink); padding: 8px 4px; text-align: center; }
.stat-grid b { display: block; font: 700 20px var(--font-display); }
.stat-grid span { font-size: 13px; color: var(--muted); }
.histo { display: flex; flex-direction: column; gap: 5px; }
.histo-row { display: grid; grid-template-columns: 54px 1fr; gap: 8px; align-items: center; font: 700 10px var(--font-display); }
.histo-bar { height: 20px; min-width: 24px; width: 0; display: flex; align-items: center; justify-content: flex-end; padding: 0 6px; font: 700 11px var(--font-display); border: 2px solid var(--ink); background: var(--paper); transition: width .6s steps(8); }
.histo-bar.me { background: var(--ink); color: var(--paper); }
.histo-bar.global { background: var(--paper) var(--dither-12); }

.settings { display: flex; flex-direction: column; gap: 4px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 2px dashed var(--ink); cursor: pointer; }
.toggle > span { flex: 1; display: flex; flex-direction: column; }
.toggle b { font-weight: 700; }
.toggle small { color: var(--muted); font-size: 13px; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle i { width: 48px; height: 26px; border: 3px solid var(--ink); position: relative; flex: none; background: var(--paper); }
.toggle i::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; background: var(--ink); transition: transform .12s steps(2); }
.toggle input:checked + i { background: var(--ink); }
.toggle input:checked + i::after { background: var(--paper); transform: translateX(22px); }
.toggle input:focus-visible + i { outline: 3px dashed var(--ink); outline-offset: 3px; }
.settings-danger { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.settings-danger small { color: var(--muted); font-size: 13px; }
.settings-danger .btn { min-height: 44px; }

/* --------------------------------------------------------------------- responsive */
@media (max-height: 700px) {
  .topbar { height: 42px; }
  .hud { padding-top: 6px; }
  .iq-sub { margin-top: 2px; }
  .iq-bar { margin-top: 8px; }
  .status-row { height: 34px; margin-top: 6px; }
  .iq-num { font-size: clamp(64px, min(22vw, 11.6vh), 136px); }
  .timer { margin: 4px 0 8px; }
  .hud { padding-top: 3px; }
  .qcard { padding: 10px; gap: 8px; }
  .q-prompt { font-size: 17px; }
  .stakes { margin-top: 10px; }
  .stakes button { height: 38px; }
  #spark { height: 30px; margin: 6px 0 8px; }
}
@media (max-width: 400px) {
  .logo-sm { font-size: 11px; }
  .topbar .tag { font-size: 10px; padding: 1px 4px; }
  .seq { gap: 5px; }
  .seq span { font-size: 15px; padding: 5px 6px; min-width: 34px; }
  .hud-mascot { width: 34px; height: 38px; left: 0; }
}
@media (max-width: 360px) {
  .tile { font-size: 15px; }
  .lifeline { padding: 0 7px; }
}
@media (min-width: 700px) {
  #screen-game { padding-bottom: 12px; }
}

/* --------------------------------------------------------------------- reduced motion */
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
  animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .1s !important;
}
body.reduce-motion .stamp, body.reduce-motion .banner, body.reduce-motion .overclock-intro { animation: rm-fade 1.2s steps(1) forwards !important; }
body.reduce-motion .toast { animation: rm-fade 2.4s steps(1) forwards !important; }
body.reduce-motion .stamp { transform: translate(-50%, -50%); }
body.reduce-motion .banner { transform: translateX(-50%); animation-duration: 2.4s !important; }
body.reduce-motion .overclock-intro { animation-duration: .9s !important; }
body.reduce-motion .fb-next .bar { animation: fb-count 4s steps(16) forwards !important; }
body.reduce-motion.danger #vignette { animation: none !important; opacity: .35; }
body.reduce-motion #bloom.invert { animation: none !important; }
body.reduce-motion .mascot .arm-a { animation: none !important; visibility: visible; }
body.reduce-motion .mascot .arm-b { animation: none !important; visibility: hidden; }
@keyframes rm-fade { 0% { opacity: 1; } 100% { opacity: 0; } }
.hud-mascot .mascot { width: 100%; height: 100%; }

/* shown by boot-check.js only if the game failed to start */
#boot-error {
  position: fixed; left: 50%; top: 16px; z-index: 200; transform: translateX(-50%); width: min(460px, calc(100vw - 24px));
  padding: 14px 16px; background: var(--paper); color: var(--ink); border: 4px solid var(--ink); box-shadow: 8px 8px 0 var(--ink);
  font: 15px/1.35 var(--font-ui);
}
#boot-error b { font-family: var(--font-display); font-size: 15px; }
#boot-error p { margin: 6px 0; }
#boot-error ul { margin: 0; padding-left: 18px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; word-break: break-word; }

/* music toggle: a note, struck through while the music is off */
.music-btn .slash { stroke-width: 2.6; }
body.music-on .music-btn .slash { display: none; }
body.music-on .music-btn { background: var(--ink); color: var(--paper); }

/* "add to home screen" tip + calendar reminder */
.a2hs { padding: 16px; }
.a2hs h2 { margin: 0 34px 6px 0; font: 700 14px var(--font-display); line-height: 1.3; }
.a2hs p { margin: 0 0 10px; font-size: 15px; }
.a2hs-x { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; }
.a2hs-reminder { border-top: 2px dashed var(--ink); padding-top: 10px; }
.a2hs-reminder small { color: var(--muted); }
.a2hs-reminder p { font-size: 14px; color: var(--muted); margin: 2px 0 10px; }
.a2hs-row { display: flex; gap: 10px; align-items: stretch; padding-right: 4px; }
.a2hs-row input[type=time] {
  flex: 1; min-width: 0; font: 700 18px var(--font-display); padding: 6px 8px;
  border: var(--line) solid var(--ink); background: var(--paper); color: var(--ink); border-radius: 0;
}
.a2hs-row .btn { min-height: 46px; flex-direction: row; }
#set-a2hs { align-self: flex-start; margin-top: 8px; padding-left: 2px; }
