/* Every number on the site is in the pixel font: this face only covers digits and the symbols
   around them ($ % + , . / :), and it comes first in the text stacks, so numbers render in
   Silkscreen while the letters around them stay in the readable font. Questions opt out. */
@font-face {
  font-family: "Herd Numbers";
  src: url("/fonts/silkscreen-400-latin.woff2") format("woff2");
  unicode-range: U+0024-0025, U+002B-002C, U+002E-003A;
  font-display: swap;
  size-adjust: 88%;
}
/* Herdict: a sunny pixel meadow. */
:root {
  --bg: #eef6e8;
  --surface: #fffdf6;
  --ink: #2f2a3a;
  --muted: #6c6878;
  --line: #d9dccb;
  --edge: #2f2a3a;         /* chunky pixel outlines */
  --accent: #e0533d;       /* barn red */
  --accent-ink: #fffdf6;
  --grass: #5aa84a;
  --grass-soft: #cfe8c4;
  --pasture: #9fd486;
  --pasture-edge: #6eb354;
  --good: #2f9e6b;
  --radius: 8px;
  --pixel: "Silkscreen", ui-monospace, monospace;
  /* Silkscreen is the pixel voice: logo, buttons, labels, numbers.
     Nunito is for anything people have to read: questions, headlines, captions. */
  --display: "Herd Numbers", "Nunito", ui-rounded, system-ui, sans-serif;
  --text: "Herd Numbers", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --plain: "Nunito", ui-rounded, system-ui, sans-serif; /* question text: no pixel numbers */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121722;
    --surface: #1b2230;
    --ink: #f3f1ea;
    --muted: #a3a9b8;
    --line: #2e3748;
    --edge: #0a0d14;
    --accent: #ff6b55;
    --accent-ink: #1a1212;
    --grass: #7cc35e;
    --grass-soft: #2b4330;
    --pasture: #2f4a32;
    --pasture-edge: #4d7a45;
    --good: #5fd39b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
.muted { color: var(--muted); }
.center { text-align: center; }
canvas.pixel, .pasture img, .logo img { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---------- header ---------- */
.top { max-width: 640px; margin: 0 auto; padding: 16px; display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 8px; font-family: var(--pixel); font-weight: 700; font-size: 20px; text-decoration: none; letter-spacing: 0.04em; }
.logo img { width: 28px; height: 28px; }
nav { display: flex; gap: 16px; align-items: center; font-size: 15px; }
nav a { text-decoration: none; color: var(--muted); }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
nav a:hover, button.link:hover { color: var(--ink); }

main { max-width: 640px; margin: 0 auto; padding: 0 16px 64px; }

/* ---------- type ---------- */
.eyebrow { font-family: var(--pixel); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 8px 0; }
.question { font-family: var(--display); font-size: clamp(26px, 6vw, 36px); line-height: 1.15; font-weight: 700; margin: 0 0 24px; text-wrap: balance; }
.question.small { font-size: clamp(20px, 4.6vw, 26px); margin-bottom: 16px; }
.headline { font-family: var(--display); font-size: clamp(22px, 5vw, 28px); font-weight: 700; line-height: 1.2; margin: 0; text-wrap: balance; }
.headline.small { font-size: clamp(18px, 4vw, 21px); margin: 14px 0 6px; }
.headline em { font-style: normal; color: var(--accent); }

/* ---------- cards & buttons ---------- */
.card {
  background: var(--surface);
  border: 2px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: 0 4px 0 var(--edge);
  padding: 20px;
  margin-bottom: 18px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%;
  border: 3px solid var(--edge);
  border-radius: 6px;
  padding: 14px 24px;
  font-family: var(--pixel);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.03em;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 5px 0 var(--edge);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translateY(1px); box-shadow: 0 4px 0 var(--edge); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--edge); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn.secondary { background: var(--surface); color: var(--ink); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.fine { font-size: 14px; color: var(--muted); text-align: center; margin: 12px 0 0; }

/* ---------- slider ---------- */
.card.guess { padding-top: 14px; }
.guess-label { margin: 0 0 6px; font-family: var(--pixel); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.picker { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; }
.value { display: flex; align-items: baseline; gap: 6px; }
.value input {
  width: 4.5ch; font-family: var(--display); font-size: 30px; font-weight: 700; text-align: right;
  border: 0; border-bottom: 3px solid var(--line); background: transparent; color: var(--ink); padding: 0;
  -moz-appearance: textfield;
}
.value input::-webkit-inner-spin-button, .value input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.value input:focus { outline: none; border-color: var(--accent); }
.value .unit { color: var(--muted); font-size: 15px; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
.range-ends { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: -2px; }

/* ---------- game run ---------- */
body.run-mode .top { display: none; }
.runbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0 10px; }
.runlogo { font-family: var(--pixel); font-weight: 700; font-size: 18px; text-decoration: none; }
.runlogo span { color: var(--muted); font-weight: 400; font-size: 13px; }
.pips { display: flex; gap: 6px; }
.pip { width: 30px; height: 30px; border-radius: 4px; display: grid; place-items: center; font-family: var(--pixel); font-size: 12px;
  background: var(--surface); border: 2px solid var(--line); color: var(--muted); }
.pip.done { border-color: var(--edge); background: var(--grass-soft); font-size: 15px; }
.pip.now { border-color: var(--accent); color: var(--accent); }
.runscore { text-align: right; line-height: 1; }
.runscore b { font-family: var(--display); font-size: 24px; font-variant-numeric: tabular-nums; }
.runscore span { color: var(--muted); font-size: 13px; }

.timer { height: 8px; border: 2px solid var(--edge); border-radius: 3px; background: var(--surface); overflow: hidden; margin-bottom: 14px; }
.timer div { height: 100%; background: var(--grass); transform-origin: left; transition: transform 0.1s linear, background 0.3s; }
body.hurry .timer div { background: var(--accent); }
.tleft { float: right; font-variant-numeric: tabular-nums; letter-spacing: 0; }
body.hurry .tleft { color: var(--accent); }

/* The question is the loudest thing on screen. Its words pop in one by one, then the slider fades in. */
.question.ask { font-size: clamp(30px, 7vw, 44px); line-height: 1.12; margin: 6px 0 28px; }
.question.ask span { display: inline-block; opacity: 0; transform: translateY(0.4em); animation: word-in 0.35s steps(4) forwards; animation-delay: calc(var(--i) * 55ms); }
@keyframes word-in { to { opacity: 1; transform: none; } }
.ask-after { opacity: 0; animation: fade-up 0.4s ease-out forwards; animation-delay: calc(var(--n) * 55ms + 250ms); }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- herd meter ---------- */
.herdmeter { margin: 0 0 14px; }
.pasture {
  display: grid; grid-template-columns: repeat(25, 1fr); gap: 2px 1px; align-content: end;
  aspect-ratio: 25 / 2; /* room for two rows of 25 sheep */
  padding: 6px; border: 2px solid var(--edge); border-radius: 6px;
  background: linear-gradient(var(--pasture), var(--pasture)) padding-box;
  box-shadow: inset 0 -4px 0 var(--pasture-edge);
}
.pasture:empty::before { content: "your pasture is empty"; grid-column: 1 / -1; font-family: var(--pixel); font-size: 11px; color: color-mix(in srgb, var(--ink) 55%, transparent); text-align: center; padding: 4px 0; }
.pasture img { width: 100%; height: auto; display: block; }
.pasture img.new { animation: baa-in 0.45s steps(5) both; }
@keyframes baa-in { 0% { transform: translateY(-14px) scale(0.4); opacity: 0; } 60% { transform: translateY(2px) scale(1.15); opacity: 1; } 100% { transform: none; } }
.herdline { margin: 6px 0 0; font-size: 13px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.herdline b { color: var(--ink); }
.herdline .sep { padding: 0 4px; }

/* ---------- reveal ---------- */
.score { display: flex; align-items: center; gap: 20px; }
.ring { --p: 0; flex: none; width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--grass-soft) 0); border: 2px solid var(--edge); }
.ring span { width: 70px; height: 70px; border-radius: 50%; background: var(--surface); display: grid; place-items: center;
  font-family: var(--display); font-size: 26px; font-weight: 700; border: 2px solid var(--edge); }
.score p { margin: 2px 0; }
.verdict { font-family: var(--display); font-weight: 700; font-size: 22px; margin: 0 0 4px !important; }
.plus { color: var(--accent); animation: pop 0.5s 0.3s both cubic-bezier(.3,1.6,.5,1); display: inline-block; }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } to { transform: none; opacity: 1; } }
.reveal .score { margin-bottom: 12px; }
.source { font-size: 13px; color: var(--muted); margin: 10px 0 0; line-height: 1.45; }
.source a { color: var(--ink); }
.levelup { margin: 0 0 14px; padding: 12px 16px; border: 2px solid var(--edge); border-radius: 6px; text-align: center;
  font-family: var(--pixel); font-size: 14px; background: var(--grass-soft); box-shadow: 0 4px 0 var(--edge);
  animation: pop 0.5s both cubic-bezier(.3,1.6,.5,1); }

.chart svg { width: 100%; height: auto; display: block; overflow: visible; margin-top: 8px; }
.chart .bar { fill: var(--grass-soft); }
.chart .bar.peak { fill: var(--grass); }
.chart .axis { fill: var(--muted); font-size: 12px; }
.chart .gline { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 4 3; }
.chart .mlabel { fill: var(--grass); font-size: 13px; font-weight: 800; }
.chart .glabel { fill: var(--accent); font-size: 12px; font-weight: 800; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin-top: 12px; }
.stats.four { grid-template-columns: repeat(4, 1fr); margin-top: 0; }
.stats div { padding: 8px 4px; }
.stats b { display: block; font-family: var(--display); font-size: 22px; line-height: 1.2; }
.stats span { font-size: 13px; color: var(--muted); }

/* ---------- ending ---------- */
.stage { position: relative; margin: 6px 0 0; border: 3px solid var(--edge); border-radius: 6px; overflow: hidden; box-shadow: 0 5px 0 var(--edge); background: #86cdf0; }
.stage.lone { background: #8ea3b8; }
.stage canvas { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; }
.skip { position: absolute; right: 8px; bottom: 8px; font-family: var(--pixel); font-size: 11px; color: #fff; background: rgb(47 42 58 / 60%); border: 0; border-radius: 4px; padding: 5px 9px; cursor: pointer; }
.bubble { position: absolute; left: 40%; top: 74%; transform: translate(-10%, -100%); font-family: var(--pixel); font-size: clamp(10px, 2.6vw, 14px);
  background: #fff; color: #2f2a3a; border: 2px solid #2f2a3a; border-radius: 4px; padding: 3px 8px; animation: pop 0.4s both; }
.bubble::after { content: ""; position: absolute; left: 10px; bottom: -8px; border: 4px solid transparent; border-top-color: #2f2a3a; }
.congrats { position: absolute; left: 0; right: 0; top: 12%; text-align: center; font-family: var(--pixel); font-weight: 700; font-size: clamp(18px, 6vw, 40px);
  color: #fff; text-shadow: 3px 3px 0 #e0533d, 6px 6px 0 #2f2a3a; animation: pop 0.5s both cubic-bezier(.3,1.6,.5,1), blink 0.6s steps(2) 0.5s 6; }
@keyframes blink { 50% { opacity: 0.35; } }
.ending-caption { font-family: var(--display); font-size: 18px; font-weight: 600; text-align: center; margin: 14px 0 18px; min-height: 1.5em; text-wrap: balance; }
.wrapup { animation: fade-up 0.5s ease-out both; }

.finale { text-align: center; }
.big-total { font-family: var(--display); line-height: 1; margin: 8px 0 4px; }
.big-total b { font-size: 84px; font-weight: 700; font-variant-numeric: tabular-nums; }
.big-total span { font-size: 24px; color: var(--muted); font-weight: 700; }
.tier { font-family: var(--pixel); font-size: 15px; color: var(--accent); margin: 4px 0 0; }
.squares { font-size: 28px; letter-spacing: 4px; margin: 10px 0 16px; }
.recap { list-style: none; padding: 0; margin: 0; text-align: left; }
.recap li { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-top: 2px dashed var(--line); font-size: 15px; }
.recap b { font-family: var(--display); font-variant-numeric: tabular-nums; }
.countdown { font-family: var(--pixel); font-size: 30px; letter-spacing: 0.04em; }
.replay { margin-top: 10px; font-size: 14px; }
.rq { font-family: var(--display); font-size: 21px; margin: 0; line-height: 1.25; }
.locked-q h3 { margin: 0 0 6px; font-family: var(--display); }
.locked-q .btn { margin-top: 12px; }

/* ---------- stats page ---------- */
.history { list-style: none; padding: 0; margin: 0; }
.history li { border-top: 2px dashed var(--line); }
.history li:first-child { border-top: 0; }
.history a { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 12px 0; text-decoration: none; align-items: center; }
.history .q { font-weight: 600; }
.history .meta { font-size: 13px; color: var(--muted); }
.pill { font-family: var(--display); font-weight: 700; border: 2px solid var(--edge); border-radius: 4px; padding: 3px 10px; background: var(--grass-soft); min-width: 52px; text-align: center; }

/* ---------- intro ---------- */
body.intro-mode .top { display: none; }
body.intro-mode main { max-width: none; padding: 0; }
body.intro-mode { background: #3f7334; }
.hero { min-height: 100vh; display: flex; flex-direction: column; }
.sky { position: relative; background: #86cdf0; }
.sky canvas { display: block; width: 100%; height: min(56.25vw, 66vh); object-fit: cover; object-position: center bottom; }
.titles { position: absolute; left: 0; right: 0; top: 9%; text-align: center; pointer-events: none; padding: 0 16px; }
.title { margin: 0; font-family: var(--pixel); font-weight: 700; font-size: clamp(42px, 11vw, 120px); line-height: 1; letter-spacing: 0.06em;
  color: #fffdf5; text-shadow: 3px 3px 0 #e0533d, 6px 6px 0 #2f2a3a; }
.kicker { margin: 14px 0 0; font-family: var(--pixel); font-size: clamp(11px, 2.4vw, 18px); letter-spacing: 0.24em; text-transform: uppercase; color: #2f2a3a; }
.field { flex: 1; background: linear-gradient(#5f9e45, #3f7334 220px); color: #fffdf5; padding: 26px 16px 48px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.sub { margin: 0 0 22px; color: #e9f5df; font-size: 17px; }
.sub span, .meta span { color: #b5d8a2; padding: 0 4px; }
.begin {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 16px 36px; text-decoration: none;
  font-family: var(--pixel); font-weight: 700; font-size: clamp(16px, 4vw, 22px); letter-spacing: 0.04em;
  background: #e0533d; color: #fffdf5; border: 4px solid #2f2a3a; border-radius: 6px; box-shadow: 0 6px 0 #2f2a3a;
  transition: transform 0.08s, box-shadow 0.08s;
}
.begin:hover { transform: translateY(2px); box-shadow: 0 4px 0 #2f2a3a; }
.begin:active { transform: translateY(5px); box-shadow: 0 1px 0 #2f2a3a; }
.meta { margin: 18px 0 0; font-size: 14px; color: #e9f5df; }
.meta b { color: #fff; }
.intro-error { max-width: 440px; padding: 14px 18px; border: 3px solid #2f2a3a; border-radius: 6px; background: #fff3ef; color: #7a2418; }
.intro-links { display: flex; gap: 22px; margin-top: 20px; font-size: 15px; }
.intro-links a, .intro-links button { color: #e9f5df; text-decoration: underline; text-underline-offset: 3px; background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
.intro-links a:hover, .intro-links button:hover { color: #fff; }
.teaser { display: block; width: min(100%, 460px); margin-top: 30px; padding: 16px 18px; text-align: left; text-decoration: none;
  background: #fffdf6; color: #2f2a3a; border: 3px solid #2f2a3a; border-radius: 6px; box-shadow: 0 5px 0 #2f2a3a; }
.teaser span { display: block; }
.teaser-label { font-family: var(--pixel); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: #5aa84a; }
.teaser-head { font-family: var(--display); font-size: 21px; font-weight: 700; line-height: 1.2; margin: 6px 0; }
.teaser-head em { font-style: normal; color: #e0533d; }
.teaser-q { font-size: 14px; color: #6c6878; }
.rules { list-style: none; padding: 0; margin: 30px 0 0; font-family: var(--pixel); font-size: 13px; color: #e9f5df; line-height: 1.6; max-width: 520px; }
.rules li { padding: 3px 0; }
.rules li::before { content: "▸"; color: #ffd23f; padding-right: 8px; }

/* ---------- dialog & toast ---------- */
dialog { border: 3px solid var(--edge); border-radius: 8px; padding: 24px; max-width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 6px 0 var(--edge); }
dialog::backdrop { background: rgb(15 20 12 / 55%); }
dialog h2 { margin-top: 0; font-family: var(--pixel); font-size: 20px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 6px; font-family: var(--pixel); font-size: 13px; }

@media (max-width: 420px) {
  .card { padding: 16px; }
  .btn-row { grid-template-columns: 1fr; }
  .pip { width: 26px; height: 26px; font-size: 11px; }
  .pip.done { font-size: 13px; }
  .runlogo span { display: none; }
  .big-total b { font-size: 68px; }
  .stats.four b { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .question.ask span, .ask-after, .pasture img.new, .plus, .levelup, .congrats, .wrapup { animation: none; opacity: 1; transform: none; }
}

/* Numbers use Silkscreen: in Pixelify Sans a 2 reads like an 8 and a 5 like an S. */
.runscore b, .ring span, .big-total b, .stats b, .recap b, .pill, .value input, .plus,
.headline em, .teaser-head em, .herdline b { font-family: var(--pixel); font-weight: 400; }
.big-total b { font-size: 72px; letter-spacing: -0.02em; }
.value input { font-size: 26px; width: 5ch; }
.runscore b { font-size: 21px; }
.ring span { font-size: 24px; }

/* ---------- readable text ---------- */
.question, .headline, .rq, .teaser-head, .ending-caption, .verdict { font-weight: 800; letter-spacing: -0.01em; }
.question.ask span { animation: word-in 0.45s cubic-bezier(.2,.8,.3,1) forwards; animation-delay: calc(var(--i) * 45ms); }
.ask-after { animation-delay: calc(var(--n) * 45ms + 200ms); }
/* Headline percentages read as part of the sentence, so they stay in the sentence's font. */
.headline em, .teaser-head em { font-family: var(--display); font-weight: 800; }
.guess-label { font-family: var(--display); font-size: 16px; font-weight: 800; letter-spacing: 0; text-transform: none; color: var(--ink); margin-bottom: 4px; }

/* ---------- page transitions ---------- */
/* The old screen drifts up and fades; the new one rises in. */
::view-transition-old(root) { animation: 180ms ease-in both page-out; }
::view-transition-new(root) { animation: 320ms cubic-bezier(.2,.8,.3,1) 60ms both page-in; }
@keyframes page-out { to { opacity: 0; transform: translateY(-10px); } }
@keyframes page-in { from { opacity: 0; transform: translateY(14px); } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}
.rank { margin: 6px 0 0; font-size: 14px; font-weight: 700; color: var(--muted); }

/* ---------- playing on the farm ---------- */
/* The farm fills the screen behind the question (a band across the top on tall phone screens).
   The HUD floats on top, the question sits on a dark pixel card, the controls dock at the bottom. */
.farm { display: none; position: fixed; left: 0; right: 0; top: 0; height: 100vh; z-index: 0; background: #86cdf0; view-transition-name: farm; }
.farm canvas { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center bottom; }
body.farm-mode { background: #3f7334; }
body.farm-mode .farm { display: block; }
body.farm-mode main { position: relative; z-index: 1; max-width: 720px; padding: 112px 16px 150px; }
@media (max-aspect-ratio: 1/1) {
  .farm { height: 44vh; }
  .farm canvas { object-position: 78% bottom; } /* keep the barn in view on narrow screens */
  body.farm-mode main { padding-top: calc(44vh - 34px); }
}

/* dark pixel panels with notched corners, like an old game UI */
.panel, .hud-panel {
  --surface: #1f1c2c; --ink: #f6f2e8; --muted: #b3aec4; --line: #3a3550; --edge: #0d0b14;
  --grass-soft: #33503a; --grass: #7cc35e; --accent: #ff6b55;
  background: rgb(31 28 44 / 92%); color: var(--ink);
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px), 0 10px);
}
.panel { padding: 22px 24px; margin-bottom: 16px; box-shadow: none; }
.panel .eyebrow { color: #ff9b80; }
.qcard .question { margin-bottom: 14px; }
.hint { margin: 0; font-family: var(--pixel); font-size: 12px; letter-spacing: 0.12em; color: var(--muted); }
.gain { margin-top: 6px !important; font-weight: 800; color: var(--grass); }
.panel .levelup { margin: 16px 0 0; background: var(--grass-soft); color: var(--ink); border-color: var(--edge); box-shadow: none; }
.panel .source a { color: var(--ink); }

.hud { position: fixed; z-index: 2; top: 0; left: 0; right: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px; padding: 12px 16px; max-width: 1100px; margin: 0 auto; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-panel { justify-self: start; display: flex; flex-direction: column; padding: 8px 16px 10px; min-width: 150px; }
.hud-panel.right { justify-self: end; align-items: flex-end; }
.hud-label { font-family: var(--pixel); font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.hud-num { font-family: var(--pixel); font-weight: 400; font-size: 26px; line-height: 1.1; color: #7cc35e; }
.hud-num small { font-size: 12px; color: var(--muted); }
.hud-num.score { color: #ff8a73; }
.hud-sub { font-family: var(--pixel); font-size: 10px; color: #ffd23f; margin-top: 2px; max-width: 30vw; }
.hud-mid { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.hud-logo { font-family: var(--pixel); font-weight: 700; font-size: 15px; letter-spacing: 0.08em; text-decoration: none; color: #fffdf5; text-shadow: 2px 2px 0 #e0533d, 3px 3px 0 #2f2a3a; }
.hud-logo span { font-weight: 400; font-size: 11px; text-shadow: none; color: #2f2a3a; }
.hud .pip { background: rgb(31 28 44 / 85%); border-color: #0d0b14; color: #b3aec4; }
.hud .pip.done { background: #33503a; }
.hud .pip.now { border-color: #ff6b55; color: #ff6b55; }

.controls { position: fixed; z-index: 2; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center;
  padding: 26px max(16px, calc((100vw - 760px) / 2)) calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, rgb(20 18 30 / 92%) 32%); color: #f6f2e8; }
.controls.next { grid-template-columns: 1fr; }
.controls .range-ends { color: #b3aec4; }
.controls input[type="range"] { accent-color: #ff6b55; }
.valbox { display: flex; align-items: baseline; gap: 6px; padding: 6px 10px; background: #13111c; border: 2px solid #3a3550; }
.valbox input { width: 4.2ch; font-family: var(--pixel); font-size: 24px; text-align: right; color: #f6f2e8; background: transparent; border: 0; padding: 0; -moz-appearance: textfield; }
.valbox input::-webkit-inner-spin-button, .valbox input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.valbox input:focus { outline: none; }
.valbox:focus-within { border-color: #ff6b55; }
.valbox span { font-size: 13px; color: #b3aec4; }
.btn.lock { width: auto; padding: 14px 22px; }

.dial { position: relative; width: 58px; height: 58px; }
.dial svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.dial circle { fill: none; stroke-width: 4; }
.dial-bg { stroke: #3a3550; }
.dial-fg { stroke: #7cc35e; transition: stroke-dashoffset 0.1s linear, stroke 0.3s; }
body.hurry .dial-fg { stroke: #ff6b55; }
.dial span { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--pixel); font-size: 18px; color: #7cc35e; }
body.hurry .dial span { color: #ff6b55; }

@media (max-width: 560px) {
  .controls { grid-template-columns: auto 1fr auto; padding-top: 20px; gap: 10px; }
  .controls .btn.lock { grid-column: 1 / -1; width: 100%; }
  .dial { width: 48px; height: 48px; }
  .hud { padding: 8px 10px; gap: 6px; }
  .hud-panel { min-width: 0; padding: 6px 10px 8px; }
  .hud-num { font-size: 20px; }
  .hud-logo span { display: none; }
  .hud .pip { width: 22px; height: 22px; font-size: 10px; }
  .hud .pip.done { font-size: 11px; }
  .panel { padding: 18px; }
}

/* The answer controls (timer, slider, lock in) sit right under the question card, not docked
   at the bottom of the screen. Same for the Next button under a reveal. */
.controls {
  position: static;
  padding: 16px 20px;
  margin: -10px 0 16px;
  background: rgb(31 28 44 / 92%);
  border-top: 2px dashed #3a3550;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px));
}
.qcard { margin-bottom: 0; clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%, 0 10px); padding-bottom: 18px; }
.controls.next { background: none; border: 0; clip-path: none; padding: 0; margin-top: 0; }
body.farm-mode main { padding-bottom: 40px; }
@media (max-width: 560px) {
  .controls { padding: 14px; }
}

/* ---------- first load ---------- */
/* Only show "Loading…" if the app is genuinely slow; never as a flash on a normal reload. */
.boot { opacity: 0; animation: boot-show 0.2s 0.8s forwards; }
@keyframes boot-show { to { opacity: 1; } }
body.intro-mode .boot { display: none; }
/* Before the meadow is drawn, the intro is already sky above grass, so there's no dark flash. */
body.intro-mode { background: linear-gradient(#86cdf0 0, #86cdf0 min(56.25vw, 66vh), #5f9e45 min(56.25vw, 66vh), #3f7334 calc(min(56.25vw, 66vh) + 220px)); background-color: #3f7334; }

/* ---------- full-screen ending ---------- */
/* The ending plays on the full-screen farm canvas; these float over it. */
body.farm-mode .congrats { position: fixed; z-index: 3; top: 24vh; left: 0; right: 0; }
body.farm-mode .skip { position: fixed; z-index: 3; right: 16px; bottom: 16px; font-size: 13px; padding: 8px 14px; background: rgb(31 28 44 / 85%); }
.panel.finale { text-align: center; }
.panel.finale .ending-caption { margin: 0 0 14px; font-size: 20px; color: #ffd23f; }
.panel.finale .recap li { border-top-color: #3a3550; }
.panel.next-up { text-align: center; }
.panel .countdown { color: #f6f2e8; }
.panel .replay { color: #b3aec4; }
.panel.finale .rank { color: #b3aec4; }
/* Results slide up a little lower on big screens, so the end of the scene stays in view above them. */
@media (min-aspect-ratio: 1/1) { body.farm-mode .wrapup { margin-top: 18vh; } }
@media (max-aspect-ratio: 1/1) {
  body.farm-mode .congrats { top: 14vh; }
  body.farm-mode .skip { top: calc(44vh - 44px); bottom: auto; }
}
body.farm-mode.winter { background: #e3ebf3; }
body.farm-mode.winter .farm { background: #8ea3b8; }

/* ---------- every answer, on the farm ---------- */
.results-head .question { margin: 0; }
.panel .rq { color: var(--ink); margin-bottom: 4px; }
.panel .stats span { color: var(--muted); }
.panel.locked-q .btn { margin-top: 12px; }
@media (min-aspect-ratio: 1/1) { body.farm-mode .results-head { margin-top: 18vh; } }

/* ---------- last 5 seconds ---------- */
/* A soft red blush on both sides of the screen that gently breathes. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(to right, rgb(224 64 50 / 34%), transparent 14%, transparent 86%, rgb(224 64 50 / 34%));
  opacity: 0;
  transition: opacity 0.6s ease;
}
body.farm-mode.hurry::before { opacity: 1; animation: blush 1.1s ease-in-out infinite alternate; }
@keyframes blush { from { opacity: 0.55; } to { opacity: 1; } }
@media (max-width: 560px) {
  body::before { background: linear-gradient(to right, rgb(224 64 50 / 30%), transparent 18%, transparent 82%, rgb(224 64 50 / 30%)); }
}
@media (prefers-reduced-motion: reduce) {
  body.farm-mode.hurry::before { animation: none; opacity: 0.8; }
}

/* ---------- side buttons (sound, settings, animals) ---------- */
.sidebtns { position: fixed; z-index: 5; right: 14px; top: 112px; display: flex; flex-direction: column; gap: 6px; }
body.intro-mode .sidebtns { top: 16px; }
body:not(.intro-mode):not(.farm-mode):not(.run-mode) .sidebtns { top: 72px; }
.sidebtn { width: 46px; height: 46px; display: grid; place-items: center; padding: 0; cursor: pointer;
  background: rgb(31 28 44 / 88%); border: 2px solid #0d0b14; box-shadow: inset 0 0 0 2px #3a3550; color: #b3aec4; }
.sidebtn svg { width: 24px; height: 24px; fill: currentColor; }
.sidebtn:hover { color: #f6f2e8; }
.sidebtn:active { transform: translateY(2px); }
.sidebtn.off { color: #6c6880; }
@media (max-width: 560px) {
  .sidebtns { right: 8px; top: 96px; gap: 4px; }
  .sidebtn { width: 36px; height: 36px; }
  .sidebtn svg { width: 18px; height: 18px; }
}

/* ---------- pixel dialogs (settings, animals) ---------- */
.pixel-dlg { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow: auto; padding: 22px 26px 26px;
  background: #1a1726; color: #f6f2e8; border: 3px solid #0d0b14; box-shadow: inset 0 0 0 2px #3a3550, 0 8px 0 #0d0b14; border-radius: 0; }
.pixel-dlg::backdrop { background: rgb(10 8 16 / 62%); }
.dlg-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dlg-top h2 { margin: 0; font-family: var(--pixel); font-size: 18px; letter-spacing: 0.12em; text-transform: uppercase; }
.dlg-x { width: 40px; height: 40px; font-family: var(--pixel); font-size: 16px; color: #b3aec4; background: #13111c; border: 2px solid #3a3550; cursor: pointer; }
.dlg-x:hover { color: #fff; }
.dlg-sub { margin: 0 0 16px; color: #b3aec4; font-size: 15px; }
.dlg-sub b { color: #ffd23f; font-family: var(--pixel); font-weight: 400; }

.setting { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 16px 0; border-bottom: 2px dashed #2c283c; }
.setting:last-child { border-bottom: 0; }
.setting h3 { margin: 0 0 4px; font-family: var(--pixel); font-size: 14px; letter-spacing: 0.1em; text-transform: uppercase; }
.setting p { margin: 0; font-size: 14px; color: #b3aec4; max-width: 30ch; }
.switch { position: relative; width: 108px; height: 42px; padding: 4px; background: #0d0b14; border: 2px solid #3a3550; cursor: pointer; display: flex; }
.switch span { width: 56px; display: grid; place-items: center; font-family: var(--pixel); font-size: 13px; color: #1a1726;
  background: #8f8aa3; box-shadow: inset 0 3px 0 #c4c0d4, inset 0 -3px 0 #6c6880; transition: transform 0.12s steps(3), background 0.12s; }
.switch.on { border-color: #7cc35e; box-shadow: 0 0 10px rgb(124 195 94 / 45%); }
.switch.on span { transform: translateX(44px); background: #7cc35e; box-shadow: inset 0 3px 0 #b6e6a2, inset 0 -3px 0 #4f8f3e; }

.animal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.animal { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 20px 10px 16px; cursor: pointer;
  background: #13111c; border: 2px solid #2c283c; color: #f6f2e8; font: inherit; }
.animal:hover { border-color: #4a4562; }
.animal.on { border-color: #7cc35e; box-shadow: 0 0 12px rgb(124 195 94 / 40%), inset 0 0 0 2px #2b4330; }
.animal-art { min-height: 76px; display: flex; align-items: flex-end; gap: 6px; }
.animal b { font-family: var(--pixel); font-weight: 400; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; }
.animal.on b { color: #7cc35e; }
.animal small { font-family: var(--pixel); font-size: 10px; letter-spacing: 0.08em; color: #8f8aa3; text-transform: uppercase; }
.animal.locked { cursor: not-allowed; }
.animal.locked .animal-art { filter: grayscale(1) brightness(0.55); opacity: 0.7; }
.animal.locked b { color: #8f8aa3; }

.unlock { margin: 0 0 14px; padding: 10px 14px; background: #2b4330; border: 2px solid #4f8f3e; font-weight: 700; }
.unlock .link { color: #ffd23f; font-weight: 800; text-decoration: underline; margin-left: 6px; }

/* ---------- settings that change the look ---------- */
body.no-glow::before { display: none; }
body.colorblind { --grass: #4ea1ff; --grass-soft: #cfe3ff; --accent: #ff9f1c; }
body.colorblind .panel, body.colorblind .hud-panel { --grass: #5fb0ff; --grass-soft: #21385a; --accent: #ffa733; --muted: #d6d2e4; }
body.colorblind .hud-num { color: #5fb0ff; }
body.colorblind .hud-num.score { color: #ffa733; }
body.colorblind .dial-fg, body.colorblind .dial span { stroke: #5fb0ff; color: #5fb0ff; }
body.colorblind.hurry .dial-fg, body.colorblind.hurry .dial span { stroke: #ffa733; color: #ffa733; }
body.colorblind .switch.on { border-color: #5fb0ff; }
body.colorblind .switch.on span { background: #5fb0ff; }

/* ---------- intro: the meadow flows into the page ---------- */
/* No hard line under the pixel scene: the section below starts in exactly the scene's grass colour,
   fades smoothly to deep green, and carries the scene's grass dots (sized to the scene's pixels)
   until they fade out. */
.hero { --px: var(--scene-px, calc(100vw / 320)); }
.field {
  position: relative;
  background: linear-gradient(#78bf59 0, #6aaf4f 90px, #55963f 210px, #437c35 340px, #3f7334 460px);
}
.field::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 300px;
  pointer-events: none;
  background:
    conic-gradient(at var(--px) var(--px), transparent 75%, #5f9e45 0) 0 0 / calc(var(--px) * 11) calc(var(--px) * 6),
    conic-gradient(at var(--px) var(--px), transparent 75%, #5f9e45 0) calc(var(--px) * 5.5) calc(var(--px) * 3) / calc(var(--px) * 11) calc(var(--px) * 6);
  -webkit-mask-image: linear-gradient(#000, transparent);
  mask-image: linear-gradient(#000, transparent);
}
.field > * { position: relative; }
/* A soft shadow keeps the light text readable on the lighter green at the top. */
.field .sub, .field .meta, .field .intro-links { text-shadow: 0 1px 0 rgb(30 60 20 / 45%), 0 0 10px rgb(30 60 20 / 35%); }
.field .sub { color: #ffffff; font-weight: 600; }
body.intro-mode { background: linear-gradient(#86cdf0 0, #86cdf0 min(56.25vw, 66vh), #78bf59 min(56.25vw, 66vh), #3f7334 calc(min(56.25vw, 66vh) + 460px)); background-color: #3f7334; }
/* Phones: on the intro, the side buttons sit in a row across the top and the title moves below them. */
@media (max-width: 560px) {
  body.intro-mode .sidebtns { flex-direction: row; top: 8px; }
  body.intro-mode .titles { top: 52px; }
}

/* ---------- intro: two tidy cards under the button ---------- */
.intro-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; width: min(100%, 880px); margin-top: 30px; text-align: left; }
.intro-cards:has(#teaserSlot:empty) { grid-template-columns: minmax(0, 460px); justify-content: center; }
#teaserSlot:empty { display: none; }
#teaserSlot .teaser, .intro-card { display: block; width: 100%; height: 100%; margin: 0; padding: 16px 18px;
  background: #fffdf6; color: #2f2a3a; border: 3px solid #2f2a3a; border-radius: 6px; box-shadow: 0 5px 0 #2f2a3a; text-shadow: none; }
.teaser.placeholder .teaser-head, .teaser.placeholder .teaser-q { background: #ece7da; border-radius: 3px; margin-top: 8px; height: 22px; }
.teaser.placeholder .teaser-q { width: 70%; height: 14px; }
.steps-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: 16px; line-height: 1.4; }
.steps-list li { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; }
.steps-list li + li { border-top: 2px dashed #ece7da; }
.steps-list b { flex: none; width: 24px; height: 24px; display: grid; place-items: center; margin-top: -1px;
  font-family: var(--pixel); font-weight: 400; font-size: 11px; color: #fffdf6; background: #5aa84a; border: 2px solid #2f2a3a; }
.steps-list strong { color: #e0533d; }
#teaserSlot .teaser { display: flex; flex-direction: column; }
.teaser-more { margin-top: auto; padding-top: 14px; font-family: var(--pixel); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: #e0533d; }
#teaserSlot .teaser:hover .teaser-more { text-decoration: underline; }

/* ---------- pixel sheep score badges ---------- */
.sheep-badge { display: block; image-rendering: pixelated; image-rendering: crisp-edges; height: auto; }
.pip .sheep-badge { width: 22px; }
.pip.done { background: rgb(31 28 44 / 85%); }
.hud .pip.done { background: #1f1c2c; }
.squares { display: flex; justify-content: center; gap: 10px; }
.squares .sheep-badge { width: 42px; }
.history .meta { display: flex; gap: 4px; align-items: center; margin-top: 4px; }
.history .meta .sheep-badge { width: 20px; }
.badge-empty { display: inline-block; width: 20px; height: 15px; border: 2px dashed var(--line); }
@media (max-width: 420px) { .pip .sheep-badge { width: 18px; } .squares .sheep-badge { width: 34px; } }

/* ---------- no overlaps when scrolling ---------- */
/* The HUD and side buttons belong to the top of the page on game screens, so they scroll away
   instead of staying pinned while panels slide underneath them. */
.hud { position: absolute; }
body.farm-mode .sidebtns { position: absolute; }
/* Narrower screens: side buttons sit in a small row centred under the question boxes. */
@media (max-width: 900px) {
  body.farm-mode .sidebtns, body.run-mode .sidebtns { flex-direction: row; top: 86px; right: 50%; transform: translateX(50%); }
  body.farm-mode .sidebtn { width: 34px; height: 34px; }
  body.farm-mode .sidebtn svg { width: 17px; height: 17px; }
}
@media (max-width: 900px) and (min-aspect-ratio: 1/1) {
  body.farm-mode main { padding-top: 140px; }
}
/* A perfect 100 glows gold and twinkles, so it never reads as the yellow "ok" sheep. */
.sheep-badge.gold { filter: drop-shadow(0 0 2px #ffcf3a) drop-shadow(0 0 7px rgb(255 190 40 / 85%)); animation: twinkle 1.6s ease-in-out infinite; }
@keyframes twinkle { 50% { filter: drop-shadow(0 0 2px #ffcf3a) drop-shadow(0 0 3px rgb(255 190 40 / 55%)); } }
@media (prefers-reduced-motion: reduce) { .sheep-badge.gold { animation: none; } }

/* Pixel icons inside text (white sheep, tractor), sized to sit on the text line. */
.inline-icon { display: inline-block; height: 1.15em; width: auto; vertical-align: -0.2em; margin-right: 6px; image-rendering: pixelated; image-rendering: crisp-edges; }
.levelup .inline-icon.tractor { height: 1.6em; vertical-align: -0.45em; margin-right: 10px; }
.tier .inline-icon { height: 1.3em; vertical-align: -0.3em; }

/* ---------- pixel numbers everywhere (except in questions) ---------- */
body { font-family: var(--text); }
button, input, select, textarea { font-family: inherit; }
/* The questions themselves keep their numbers in the normal font. */
.question, .rq, .teaser-q, .recap li > span, .locked-q h3 { font-family: var(--plain); }
/* "You scored 220/500" uses the question style but isn't a question. */
.results-head .question { font-family: var(--display); }
/* Chart labels ("most popular 2", "you 15", axis ends). */
.chart text { font-family: var(--pixel); font-weight: 400; letter-spacing: 0.02em; }
/* While a farm page loads, show the farm's sky (not a "Loading…" line). */
body.farm-mode .boot { display: none; }
