/* Percentile — paper, ink and one signal orange. Brand colors live in
   brand/README.md; keep these tokens in sync with scripts/build-brand.mjs. */
:root {
  --bg: #f5f2ea;
  --text: #121212;
  --muted: #5e5950;
  --line: rgba(18, 18, 18, 0.1);
  --track: rgba(18, 18, 18, 0.1);
  --accent: #ff5b2e;
  --accent-soft: rgba(255, 91, 46, 0.16);
  --button-text: #f5f2ea;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --text: #f5f2ea;
    --muted: #aaa49a;
    --line: rgba(245, 242, 234, 0.12);
    --track: rgba(245, 242, 234, 0.14);
    --accent: #ff6a40;
    --accent-soft: rgba(255, 106, 64, 0.2);
    --button-text: #0f0f0f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Top bar: logo left, segmented tabs right */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 4px; }
.logo { display: inline-flex; color: var(--text); text-decoration: none; }
.logo svg { height: 24px; width: auto; display: block; }
.logo .dot { fill: var(--accent); }
.tabs { display: flex; padding: 3px; border-radius: 999px; background: var(--track); }
.tabs a {
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  transition: color 150ms ease, background-color 150ms ease;
}
.tabs a[aria-current="page"] { background: var(--text); color: var(--bg); }

/* Question */
.prompt { display: flex; flex-direction: column; gap: 12px; }
.meta {
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sponsor { margin: 0; font-size: 0.78rem; color: var(--muted); }
.question {
  margin: 4px 0 0;
  font-size: clamp(1.6rem, 7vw, 2.05rem);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
/* The question stays on screen above its reveal, one size down. */
.question.small { font-size: clamp(1.2rem, 5.4vw, 1.4rem); line-height: 1.2; }

/* Progress: the logo's pieces. Orange dot = answered, ring = current. */
.progress { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dots { display: flex; align-items: center; gap: 8px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid var(--track); }
.dots i.done { background: var(--accent); border-color: var(--accent); }
.dots i.current { width: 14px; height: 14px; border-color: var(--text); }
.step {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.category { margin: 0; font-size: 0.78rem; font-weight: 600; color: var(--accent); }
.category:empty { display: none; }

/* Play */
.play { display: flex; flex-direction: column; gap: 14px; }
.readout {
  margin: 8px 0 0;
  text-align: center;
  font-size: clamp(5rem, 26vw, 6.5rem);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.06em;
  font-variant-numeric: tabular-nums;
}
.readout .pct { font-size: 0.4em; letter-spacing: 0; color: var(--accent); vertical-align: 0.95em; margin-left: 0.04em; }

.slider {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 48px; /* generous touch target */
  margin: 0;
  background: transparent;
  cursor: grab;
  touch-action: pan-y;
}
.slider:active { cursor: grabbing; }
.slider:focus-visible { outline: none; }
.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 6px var(--accent-soft); }
.slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 6px var(--accent-soft); }
.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--text) var(--fill), var(--track) var(--fill));
}
.slider::-moz-range-track { height: 6px; border-radius: 999px; background: var(--track); }
.slider::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--text); }
/* The thumb is the logo's ring: "your guess". */
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px;
  height: 30px;
  margin-top: -12px;
  border-radius: 50%;
  background: var(--bg);
  border: 7px solid var(--text);
  transition: transform 120ms var(--ease);
}
.slider:active::-webkit-slider-thumb { transform: scale(1.15); }
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  border: 7px solid var(--text);
}
.scale {
  display: flex;
  justify-content: space-between;
  margin-top: -8px;
  padding: 0 4px;
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.button {
  appearance: none;
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: var(--button-text);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 100ms var(--ease), opacity 150ms ease;
}
.button:hover { opacity: 0.9; }
.button:active { transform: scale(0.98); }
.fineprint { margin: -4px 0 0; text-align: center; color: var(--muted); font-size: 0.78rem; }

/* Reveal */
.reveal { display: flex; flex-direction: column; align-items: stretch; gap: 14px; text-align: center; }
.track {
  position: relative;
  height: 6px;
  margin: 40px 12px 40px;
  border-radius: 999px;
  background: var(--track);
}
.gap {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent-soft);
  transition: left 1s var(--ease), width 1s var(--ease);
}
.marker { position: absolute; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; }
/* Same pair as the logo: ring = your guess, solid dot = the truth. */
.marker.guess { width: 22px; height: 22px; background: var(--bg); border: 6px solid var(--text); z-index: 1; }
.marker.actual {
  width: 24px;
  height: 24px;
  background: var(--accent);
  z-index: 2;
  transition: left 1s var(--ease);
}
.tag {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.72rem;
  color: var(--muted);
}
.tag b { color: var(--text); font-variant-numeric: tabular-nums; }
.guess .tag { bottom: calc(100% + 10px); }
.actual .tag { top: calc(100% + 10px); }
.no-motion .gap, .no-motion .marker.actual { transition: none; }

.verdict { margin: 0; font-size: 2.4rem; line-height: 1.05; font-weight: 800; letter-spacing: -0.035em; }
.verdict-detail { margin: -6px 0 0; color: var(--muted); font-size: 1.05rem; }
.aggregate { margin: 0; font-size: 0.95rem; color: var(--muted); line-height: 1.4; }
/* How the points were worked out, on every reveal and the final screen. */
.points {
  align-self: center;
  margin: 0;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--track);
  font-size: 0.92rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.scoring-rule { margin: -6px 0 0; font-size: 0.92rem; color: var(--muted); line-height: 1.4; }

/* Behind the number */
.fact { margin: 2px 0; padding: 16px 18px 14px; border-radius: 16px; background: var(--track); text-align: left; }
.fact-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.fact-label svg { width: 18px; height: 18px; flex: none; color: var(--text); }
.fact-label .dot { fill: var(--accent); }
.fact-text { margin: 0; font-size: 1.08rem; line-height: 1.4; font-weight: 600; letter-spacing: -0.01em; text-wrap: pretty; }
.fact-text b { color: var(--accent); font-weight: 700; }
.fact-source { display: inline-block; margin-top: 8px; font-size: 0.88rem; color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 6px 0;
  padding: 16px 0;
  border-block: 1px solid var(--line);
}
.stats div { display: flex; flex-direction: column-reverse; gap: 2px; }
.stats div + div { border-left: 1px solid var(--line); }
.stats dt { color: var(--muted); font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.stats dd { margin: 0; font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.share-status { margin: -6px 0 0; min-height: 1.2em; font-size: 1rem; color: var(--muted); white-space: pre-line; }
.countdown { margin: 0; color: var(--muted); font-size: 1rem; }
.countdown strong { color: var(--text); font-family: var(--mono); font-weight: 600; }
.source { margin: 0; font-size: 0.88rem; color: var(--muted); }
.ad-slot { margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--line); min-height: 50px; }

/* Final score */
.final { display: flex; flex-direction: column; gap: 14px; text-align: center; }
.total {
  margin: 4px 0 0;
  font-size: clamp(4.4rem, 22vw, 5.4rem);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.06em;
  font-variant-numeric: tabular-nums;
}
.total small { font-size: 0.3em; letter-spacing: -0.02em; color: var(--muted); }
.final .verdict { margin-top: -2px; }

/* Where you stand: percentile, players and the day's curve. */
.standing { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 0; padding: 14px 16px 12px; border-radius: 16px; background: var(--track); text-align: left; }
.standing-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 0 4px; }
.standing-head b { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em; }
.standing.good .standing-head b { color: var(--accent); }
.standing-head span { color: var(--muted); font-size: 0.9rem; font-weight: 600; white-space: nowrap; }
.standing-note { margin: 0; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.standing-note:empty { display: none; }
.standing svg { display: block; width: 100%; height: auto; overflow: visible; }
.standing .area { fill: var(--track); }
.standing .beaten { fill: var(--accent-soft); }
.standing .line { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.standing .avg { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.standing .avg-label, .standing .tick { font-size: 12px; fill: var(--muted); }
.standing .beat { font-size: 13.5px; font-weight: 800; fill: var(--accent); }
.standing .pin { stroke: var(--text); stroke-width: 2; }
.standing .ring { fill: var(--bg); stroke: var(--text); stroke-width: 3.5; }
.standing .you { fill: var(--text); }
.standing .you-text { font-size: 12px; font-weight: 700; fill: var(--bg); }
.standing .axis { stroke: var(--muted); stroke-width: 1; }
.standing-axis { margin: 0; text-align: center; font-size: 0.82rem; color: var(--muted); }

/* One row per question; tap to open the question, track and fact. */
.results { list-style: none; margin: 4px 0 0; padding: 0; text-align: left; }
.results li { border-top: 1px solid var(--line); }
.results li:last-child { border-bottom: 1px solid var(--line); }
.results summary {
  display: grid;
  grid-template-columns: 1.4em 1fr auto 2.2em;
  align-items: center;
  gap: 10px;
  padding: 12px 0 10px;
  cursor: pointer;
  list-style: none;
}
.results summary::-webkit-details-marker { display: none; }
.results summary::after {
  content: "Question & behind the number ▾";
  grid-column: 2 / -1;
  margin-top: -4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}
.results details[open] summary::after { content: "Hide ▴"; }
.results .n { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.results .what { display: flex; flex-direction: column; min-width: 0; }
.results .cat { font-weight: 700; font-size: 1.02rem; }
.results .ga { font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.results .ga b { color: var(--text); }
.results .ga em { font-style: normal; font-weight: 800; color: var(--accent); }
.results .meter { display: flex; gap: 3px; }
.results .meter i { width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--accent); }
.results .meter i.on { background: var(--accent); }
.results .score { font-weight: 800; font-size: 1.15rem; text-align: right; font-variant-numeric: tabular-nums; }
.results .more { display: flex; flex-direction: column; gap: 10px; padding: 0 0 14px calc(1.4em + 10px); }
.results .q { margin: 0; font-weight: 700; line-height: 1.3; }
.results .fact { margin: 0; }
.results .fact-text { font-size: 0.92rem; }

/* Mini You/Actual track: same ring-and-dot pair as the reveal. */
.mini { position: relative; height: 6px; margin: 24px 8px 22px; border-radius: 999px; background: var(--track); }
.mini-gap { position: absolute; top: 0; bottom: 0; background: var(--accent-soft); }
.mini-guess, .mini-actual { position: absolute; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; }
.mini-guess { width: 16px; height: 16px; background: var(--bg); border: 4px solid var(--text); z-index: 1; }
.mini-actual { width: 16px; height: 16px; background: var(--accent); z-index: 2; }
.mini span { position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 0.68rem; color: var(--muted); }
.mini span b { color: var(--text); font-variant-numeric: tabular-nums; }
.mini-guess span { bottom: calc(100% + 6px); }
.mini-actual span { top: calc(100% + 6px); }

/* Archive */
.archive-list { list-style: none; margin: -12px 0 0; padding: 0; }
.archive-list li + li { border-top: 1px solid var(--line); }
.archive-list a {
  display: grid;
  grid-template-columns: 2.6em 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 16px 2px;
  color: var(--text);
  text-decoration: none;
}
.archive-list a:active { opacity: 0.7; }
.archive-list .num { font-family: var(--mono); font-size: 0.92rem; color: var(--muted); }
.archive-list .when { display: flex; flex-direction: column; min-width: 0; font-weight: 600; font-size: 1.05rem; }
.archive-list .when small { color: var(--muted); font-size: 0.88rem; font-weight: 500; }
.archive-list .result {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 1.1rem;
}
.archive-list .result::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.archive-list .result.todo {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--text);
  font-size: 0.8rem;
  font-weight: 700;
}
.archive-list .result.todo::before { content: none; }
.archive-empty { margin: 0; color: var(--muted); padding: 8px 0 24px; line-height: 1.7; font-size: 1rem; }

.footer {
  margin-top: auto;
  padding-top: 12px;
  text-align: center;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.noscript { text-align: center; padding: 24px; }

/* Share stays reachable on any phone: when the final screen is taller than
   the window, it rides along at the bottom until you scroll to its place.
   Next question is deliberately not pinned: it sits after the answer and
   "Behind the number", so players scroll past them on their way. */
.final #share {
  position: sticky;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 5;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
/* Stay solid over the content behind them (taps can leave :hover stuck on phones). */
.final #share:hover { opacity: 1; }

/* Short phones (iPhone SE and similar): tighten the reveal and final screens
   so Next question and Share stay on screen. Keyed to the physical screen
   (the `short` class, set once in each page's <head>), not a max-height media
   query: Safari's toolbar collapses as you scroll, which changes the viewport
   height and would make everything jump in size mid-scroll. */
.short .app { gap: 16px; }
.short .prompt { gap: 8px; }
.short .meta { padding-bottom: 8px; }
.short .question { font-size: clamp(1.3rem, 5.6vw, 1.55rem); }
.short .reveal { gap: 8px; }
.short .track { margin: 28px 12px 30px; }
.short .verdict { font-size: 1.85rem; }
.short .verdict-detail { margin-top: -4px; }
.short .stats { margin: 2px 0; padding: 10px 0; }
.short .stats dd { font-size: 1.25rem; }
.short .fact { padding: 12px 14px 10px; }
.short .fact-text { font-size: 0.95rem; }
.short .fact-source { margin-top: 4px; }
.short .button { min-height: 50px; }
.short .final { gap: 10px; }
.short .total { font-size: 4rem; }
.short .results summary { padding: 9px 0 7px; }

/* Gentle entrance */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.prompt, .play, .reveal, .final, .archive-list { animation: rise 500ms var(--ease) both; }
.play, .reveal, .final, .archive-list { animation-delay: 80ms; }
.final.no-motion { animation: none; }

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