@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/space-grotesk.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

/* The whole skin: ash-white paper and charcoal by day, a campfire night in the dark theme, one ember colour.
   light-dark(day, night). The burning paper keeps its own colours (things.js, render.js). */
:root {
  color-scheme: light dark;

  --bg: light-dark(#F3EEE6, #15110E);
  --surface: light-dark(#FBF8F2, #211B17);  /* the menu sheet */
  --line: light-dark(#E2D9CC, #302822);
  --track: light-dark(#E4DBCE, #2E2621);
  --ink: light-dark(#1F1A17, #F3ECE3);       /* text, char, the guess */
  --muted: light-dark(#6E645B, #A99E92);
  --accent: light-dark(#F08A00, #FFAA33);    /* ember: fills, the true answer */
  --accent-ink: light-dark(#A55200, #FFB547); /* ember for text, AA on the background */
  --on-accent: #1F1A17;
  --focus: light-dark(#A55200, #FFB547);
  --shadow: light-dark(rgba(60, 40, 20, .18), rgba(0, 0, 0, .55));
  --lift: drop-shadow(0 1px 1px light-dark(rgba(60, 40, 20, .3), rgba(0, 0, 0, .6))) drop-shadow(0 5px 9px light-dark(rgba(60, 40, 20, .14), rgba(0, 0, 0, .4)));  /* paper on the table */

  --font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 999px;
  --r-s: 12px;
  --r-l: 22px;

  /* The game, top to bottom, always within the first screen. */
  --bar: 56px;
  --status: 30px;
  --say: 54px;
  --acts: 124px;
  --foot: 40px;
  --board: min(calc(100vw - 32px), calc(100dvh - var(--bar) - var(--status) - var(--say) - var(--acts) - var(--foot) - 30px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 520px);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.noscript { margin: 0 0 16px; padding: 14px 16px; border: 2px dashed var(--line); border-radius: var(--r-s); }
.muted { color: var(--muted); }
.small { font-size: 14px; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 3px; }
a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-ink); }
h1, h2, p { margin: 0; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}

/* ----- the bar: logo, pop out, sound, menu */
.bar {
  display: flex; align-items: center; gap: 4px;
  width: 100%; max-width: 560px; margin: 0 auto;
  height: calc(var(--bar) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  margin-left: -4px; padding: 4px 8px 4px 4px; border-radius: var(--r-s);
  font-size: 23px; font-weight: 700; letter-spacing: -0.035em; text-decoration: none;
}
.brand:hover { color: inherit; }
.brand img { display: block; transition: transform .25s; }
.brand:hover img { transform: rotate(-8deg) scale(1.06); }
.tools { display: flex; gap: 2px; margin-left: auto; margin-right: -6px; }
.ib {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: var(--r-s);
  background: transparent; color: var(--ink);
  cursor: pointer;
}
.ib:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ----- the stage: status, one sentence, the board, the controls. Fixed rows, so nothing jumps. */
.stage {
  display: grid;
  grid-template-rows: var(--status) var(--say) var(--board) var(--acts);
  justify-content: center;
  align-content: center;
  row-gap: 6px;
  width: 100%;
  padding: 4px 0;
}
.stage > * { width: var(--board); }

.status { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; color: var(--muted); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.total { justify-self: end; }
.pips { display: flex; gap: 7px; margin: 0; padding: 0; list-style: none; }
.pips li { width: 10px; height: 10px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--muted); transition: background .3s, box-shadow .3s; }
.pips li.now { box-shadow: inset 0 0 0 2.5px var(--accent); }
.pips li.done { background: var(--ink); box-shadow: none; }

.say { display: grid; align-content: center; justify-items: center; text-align: center; line-height: 1.2; }
.say b { font-size: 21px; font-weight: 700; letter-spacing: -0.025em; }
.say span { color: var(--muted); font-size: 15px; min-height: 1.2em; }
.say .hit { color: var(--accent-ink); font-weight: 700; }

.board { position: relative; height: var(--board); touch-action: manipulation; }
.board canvas { position: absolute; left: 0; width: 100%; }
.paper, .ghost { top: 0; height: 100%; }
.paper { filter: var(--lift); }
.app[data-phase="ready"] .paper { cursor: pointer; }
.app[data-phase="ready"] .board:hover .paper { transform: rotate(-1deg) scale(1.01); }
.paper { transition: transform .3s; }
.fx { top: -25%; height: 125%; pointer-events: none; }
.ghost { color: var(--accent); opacity: 0; transition: opacity .7s; }
.app[data-phase="reveal"] .ghost { opacity: 1; }
.app[data-phase="summary"] .board > canvas { display: none; }

/* ----- the controls: light it, then the guess, then next */
.acts { display: grid; align-content: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 24px;
  border: 1.5px solid var(--ink); border-radius: var(--r);
  background: transparent; color: var(--ink);
  font: 700 17px/1 var(--font); letter-spacing: -0.01em; text-decoration: none;
  cursor: pointer; touch-action: manipulation;
  transition: transform .12s, background .2s, opacity .2s;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.big { min-height: 64px; width: 100%; font-size: 20px; }
.btn .ico { width: 22px; height: 22px; }
.row { display: flex; gap: 10px; justify-content: center; }
.row .btn { flex: 1; }

.guess { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 44px; align-items: center; row-gap: 8px; column-gap: 12px; }
.readout { display: flex; align-items: center; gap: 10px; min-width: 0; }
.readout output { font-size: 40px; font-weight: 700; line-height: 1; letter-spacing: -0.045em; font-variant-numeric: tabular-nums; }
.readout > span { display: grid; min-width: 0; color: var(--muted); font-size: 14px; line-height: 1.2; }
.readout > span span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.app[data-phase="reveal"] .readout output { color: var(--accent-ink); }
.guess .btn { min-width: 128px; }

/* The slider: the track fills with the guess, and after it with the fire, up to the true answer. */
.track { position: relative; grid-column: 1 / -1; --v: 50%; --fill: color-mix(in srgb, var(--ink) 28%, transparent); }
.app[data-phase="reveal"] .track { --fill: var(--accent); }
.track input { display: block; width: 100%; height: 44px; margin: 0; background: transparent; cursor: pointer; -webkit-appearance: none; appearance: none; touch-action: pan-y; }
.track input:disabled { cursor: default; }
.track input::-webkit-slider-runnable-track { height: 12px; border-radius: 6px; background: linear-gradient(to right, var(--fill) var(--v), var(--track) var(--v)); }
.track input::-moz-range-track { height: 12px; border-radius: 6px; background: linear-gradient(to right, var(--fill) var(--v), var(--track) var(--v)); }
.track input::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; margin-top: -9px; border: 4px solid var(--bg); border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 1.5px var(--ink); }
.track input::-moz-range-thumb { width: 22px; height: 22px; border: 4px solid var(--bg); border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 1.5px var(--ink); }
.track input:focus-visible { outline: none; }
.track input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1.5px var(--ink), 0 0 0 5px var(--focus); }
.track input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 1.5px var(--ink), 0 0 0 5px var(--focus); }
.app[data-phase="burning"] .track input::-webkit-slider-thumb { background: var(--muted); box-shadow: 0 0 0 1.5px var(--muted); }
/* where the fire stopped: a small mark on the track at the true answer */
.truth { position: absolute; top: 50%; left: calc(15px + (100% - 30px) * var(--t, 0) / 100); width: 4px; height: 26px; margin: -13px 0 0 -2px; border-radius: 2px; background: var(--accent-ink); opacity: 0; pointer-events: none; }
.app[data-phase="reveal"] .truth { opacity: 1; }

/* ----- the summary on the board: five burnt things and the total */
.sum { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 8px; }
.sum figure { position: relative; margin: 0; display: grid; place-items: center; min-height: 0; border-radius: var(--r-s); background: color-mix(in srgb, var(--ink) 4%, transparent); }
.sum canvas { width: 86%; height: auto; aspect-ratio: 1; margin-bottom: 22px; filter: var(--lift); }
.sum figcaption { position: absolute; left: 0; right: 0; bottom: 6px; display: grid; justify-items: center; line-height: 1.15; font-size: 12px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.sum figcaption b { color: var(--accent-ink); font-size: 17px; font-weight: 700; letter-spacing: -0.03em; }
.sum .score { align-content: center; gap: 2px; background: var(--accent); color: var(--on-accent); }
.sum .score b { font-size: clamp(30px, calc(var(--board) / 8), 52px); line-height: 1; letter-spacing: -0.05em; }
.sum .score span { font-size: 14px; font-weight: 600; }

.flash { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: var(--r-s); background: var(--ink); color: var(--bg); font-weight: 600; white-space: pre-line; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.flash.on { transform: translate(-50%, 0); opacity: 1; }

/* ----- the footer, under the game on the web; gone in the installed app and the pop-out window */
.foot { display: flex; justify-content: center; align-items: center; height: var(--foot); color: var(--muted); font-size: 14px; }
.foot > * { margin: 0 4px; }
.link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; cursor: pointer; }
.link:hover { color: var(--accent-ink); }
:root.app .foot, .pip .foot { visibility: hidden; }

/* ----- the menu: how to play and settings, a native dialog */
.sheet { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 18px 20px 20px; border: 1px solid var(--line); border-radius: var(--r-l); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px var(--shadow); }
.sheet::backdrop { background: rgba(15, 10, 6, .45); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet h2 { font-size: 22px; letter-spacing: -0.025em; }
.how { margin: 0 0 14px; padding-left: 22px; }
.how li { margin: 6px 0; }
.how li::marker { color: var(--accent-ink); font-weight: 700; }
fieldset { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 12px; padding: 10px 0 0; border: 0; border-top: 1px solid var(--line); }
legend { float: left; width: 100%; margin-bottom: 4px; padding: 0; color: var(--muted); font-size: 14px; font-weight: 600; }
fieldset label { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; cursor: pointer; }
input[type="radio"], input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent-ink); }

/* ----- pop out: the page left behind */
.popped { display: grid; place-content: center; justify-items: center; gap: 16px; min-height: 100dvh; padding: 24px; text-align: center; }
.pip { min-height: 100vh; }

/* ----- plain pages: privacy, 404 */
.doc { width: min(100% - 32px, 700px); margin: 0 auto; padding: 28px 0 40px; line-height: 1.6; font-size: 17px; }
.doc-home { display: inline-flex; align-items: center; gap: 10px; font-size: 23px; font-weight: 700; letter-spacing: -0.035em; text-decoration: none; }
.doc h1 { margin: 30px 0 8px; font-size: clamp(32px, 7vw, 46px); line-height: 1.05; letter-spacing: -0.035em; }
.doc h2 { margin: 30px 0 6px; font-size: 21px; letter-spacing: -0.015em; }
.doc .lede { font-size: 20px; font-weight: 600; }
.doc p, .doc li { margin: 6px 0; }
.doc .btn { margin-top: 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
