/* Unherd. Layout: an illustrated pasture hero (one sheep outside the fence), then ear-tag case cards; a case opens as story + clues beside the deduction grid, stacking on phones. */
:root {
  --paper: #eef2e6;        /* pale sage ground */
  --surface: #fbfcf7;      /* cards and panels */
  --ink: #1f2a1c;          /* text, grid lines */
  --muted: #5d6b58;
  --line: #cfd8c4;
  --grass: #4c7a3c;        /* pasture green, primary */
  --grass-ink: #ffffff;
  --tag: #f2c230;          /* ear-tag yellow */
  --tag-ink: #3a2e05;
  --rust: #c4501d;         /* barn rust, the stray */
  --yes: #2a7a4f;
  --no: #b0384a;
  --cell: #ffffff;
  --cell-hover: #e6edda;
  --band: #e2e9d6;
  --sky-top: #bfe0ec; --sky-bot: #e8f3e9; --sun: #ffd86b;
  --hill3: #a9c98a; --hill2: #86b267; --hill1: #5f8f48;
  --fence: #7a5a3a; --wool: #ffffff; --sheep-dark: #2b2622;
  --avatar-bg: #e3ead6;
  --shadow: 0 1px 0 rgba(31,42,28,.06), 0 8px 24px -12px rgba(31,42,28,.25);
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --paper: #121a11; --surface: #1a2518; --ink: #e7eedf; --muted: #9aab93; --line: #2f3e2b;
  --grass: #78b15c; --grass-ink: #0e160c; --tag: #e2b52a; --tag-ink: #2a2104; --rust: #f07a45;
  --yes: #5fd197; --no: #f0808f; --cell: #1f2c1d; --cell-hover: #2a3a27; --band: #172116;
  --sky-top: #16233a; --sky-bot: #2a3b44; --sun: #f3ecc8;
  --hill3: #2c4529; --hill2: #23381f; --hill1: #1a2a17;
  --fence: #6b543d; --wool: #dfe4da; --sheep-dark: #11100f; --avatar-bg: #263423;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 28px -14px rgba(0,0,0,.7);
  color-scheme: dark } }
:root[data-theme="dark"] {
  --paper: #121a11; --surface: #1a2518; --ink: #e7eedf; --muted: #9aab93; --line: #2f3e2b;
  --grass: #78b15c; --grass-ink: #0e160c; --tag: #e2b52a; --tag-ink: #2a2104; --rust: #f07a45;
  --yes: #5fd197; --no: #f0808f; --cell: #1f2c1d; --cell-hover: #2a3a27; --band: #172116;
  --sky-top: #16233a; --sky-bot: #2a3b44; --sun: #f3ecc8;
  --hill3: #2c4529; --hill2: #23381f; --hill1: #1a2a17;
  --fence: #6b543d; --wool: #dfe4da; --sheep-dark: #11100f; --avatar-bg: #263423;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 10px 28px -14px rgba(0,0,0,.7);
  color-scheme: dark }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.55; }
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--display); text-wrap: balance; margin: 0; }
.inner { max-width: 1140px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
:focus-visible { outline: 3px solid var(--rust); outline-offset: 2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 700 .95rem/1 var(--body); padding: 11px 16px; border-radius: 999px; border: 2px solid var(--ink); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; transition: transform .12s ease, background .12s ease; }
.btn:hover { background: var(--cell-hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--grass); border-color: var(--grass); color: var(--grass-ink); }
.btn.primary:hover { filter: brightness(1.06); background: var(--grass); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--cell-hover); }
.btn.big { font-size: 1.05rem; padding: 15px 24px; box-shadow: 0 6px 0 -1px color-mix(in srgb, var(--grass) 55%, #000); }

/* Hero */
.hero { position: relative; overflow: hidden; margin-top: calc(-1 * env(safe-area-inset-top, 0px)); padding-top: calc(env(safe-area-inset-top, 0px) + clamp(40px, 7vw, 80px)); padding-bottom: clamp(170px, 24vw, 260px); }
.scene { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.hero { background: linear-gradient(var(--sky-top), var(--sky-bot) 60%); }
.scene .sky { fill: transparent; }
.scene .sun { fill: var(--sun); }
.scene .hill3 { fill: var(--hill3); } .scene .hill2 { fill: var(--hill2); } .scene .hill1 { fill: var(--hill1); }
.scene .fence rect { fill: var(--fence); }
.scene .stray { animation: graze 3.4s ease-in-out infinite; transform-origin: 790px 239px; }
@keyframes graze { 0%, 100% { transform: translateY(0) rotate(0); } 40% { transform: translateY(-4px) rotate(-3deg); } 60% { transform: translateY(0) rotate(2deg); } }
.hero-inner { position: relative; z-index: 1; max-width: 1140px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 18px; justify-items: start; }
.wordmark { font-weight: 800; font-size: clamp(4rem, 15vw, 8.5rem); line-height: .85; letter-spacing: -.04em; color: var(--ink); }
.w-stray { display: inline-block; color: var(--rust); transform: rotate(-14deg) translate(-.02em, -.1em); margin-right: .015em; animation: wander 6s ease-in-out infinite; }
@keyframes wander { 0%, 100% { transform: rotate(-14deg) translate(-.02em, -.1em); } 50% { transform: rotate(-9deg) translate(-.05em, -.13em); } }
.tagline { margin: 0; max-width: 46ch; font-size: clamp(1.02rem, 2.2vw, 1.2rem); }
.hero-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-top: 6px; }
.hero-meta { font: 700 .78rem/1.3 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* Sections */
.band { padding-block: clamp(40px, 6vw, 72px); }
.band.how { background: var(--band); }
.section-head { display: grid; gap: 6px; margin-bottom: 24px; }
.section-head h2 { font-size: clamp(1.7rem, 4vw, 2.4rem); font-weight: 800; letter-spacing: -.01em; }
.section-head p { margin: 0; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 900px) { .cards { grid-template-columns: minmax(0, 1fr); max-width: 560px; } }
.card { background: var(--surface); border-radius: 26px 26px 14px 14px; box-shadow: var(--shadow); display: grid; grid-template-rows: auto 1fr; overflow: hidden; text-decoration: none; color: inherit; transition: transform .18s ease, box-shadow .18s ease; }
.card:hover { transform: translateY(-4px) rotate(-.4deg); }
.card-tag { position: relative; background: var(--tag); color: var(--tag-ink); padding: 30px 20px 14px; display: flex; justify-content: space-between; align-items: baseline; font: 700 .76rem/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.card-tag::before { content: ""; position: absolute; top: 10px; left: 50%; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--paper); box-shadow: inset 0 1px 2px rgba(0,0,0,.25); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .25; }
.dots i.on { opacity: 1; }
.card-body { padding: 18px 20px 20px; display: grid; gap: 12px; align-content: start; }
.card-body h3 { font-size: 1.45rem; font-weight: 800; line-height: 1.1; }
.card-body p { margin: 0; color: var(--muted); }
.herd { display: flex; }
.herd .av { width: 48px; height: 48px; margin-right: -8px; border: 3px solid var(--surface); border-radius: 50%; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
.status { font: 700 .74rem/1.2 var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.status.home { color: var(--yes); }
.status.going { color: var(--rust); }
.card-foot .btn { padding: 9px 16px; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; counter-reset: s; }
@media (max-width: 760px) { .steps { grid-template-columns: minmax(0, 1fr); } }
.steps li { counter-increment: s; display: grid; gap: 6px; align-content: start; }
.steps li::before { content: counter(s); font: 800 1.4rem/1 var(--display); width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--tag); color: var(--tag-ink); }
.steps b { font-family: var(--display); font-size: 1.15rem; }

.foot { padding-block: 28px 40px; color: var(--muted); font-size: .9rem; }
.foot .inner { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline; }
.foot-mark { font: 800 1.2rem/1 var(--display); color: var(--ink); }

/* Case view */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 10px; }
.back { font-weight: 700; text-decoration: none; padding: 6px 10px; margin-left: -10px; border-radius: 999px; }
.back:hover { background: var(--cell-hover); }
.topbar-mark { font: 800 1.25rem/1 var(--display); }
.timer { font: 700 .95rem/1 var(--mono); font-variant-numeric: tabular-nums; background: var(--band); padding: 7px 10px; border-radius: 999px; min-width: 64px; text-align: center; }
@media (max-width: 480px) { .back span { display: none; } }

.game { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 24px; align-items: start; padding-block: 24px 64px; }
@media (max-width: 900px) { .game { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 22px; min-width: 0; display: grid; gap: 14px; align-content: start; }
@media (max-width: 520px) { .panel { padding: 18px 14px; } }
.eyebrow { font: 700 .72rem/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--rust); }
.story h2 { font-size: clamp(1.8rem, 4vw, 2.3rem); font-weight: 800; line-height: 1.05; }
.setting { margin: 0; max-width: 62ch; }
.cast { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cast li { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cast .av { width: 52px; height: 52px; flex: none; }
.cast b { display: block; font-family: var(--display); font-size: 1.05rem; }
.cast span { display: block; color: var(--muted); font-size: .86rem; line-height: 1.3; }
.question { margin: 0; padding: 12px 16px; background: var(--tag); color: var(--tag-ink); border-radius: 12px; font-weight: 700; }
.clues-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.clues-head h3 { font-size: 1.2rem; }
.hint { color: var(--muted); font-size: .85rem; }
ol.clues { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; counter-reset: clue; }
.clue { counter-increment: clue; display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.clue::before { content: counter(clue); width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--band); font: 700 .8rem/1 var(--mono); color: var(--ink); }
.clue:hover { background: var(--cell-hover); }
.clue.used { color: var(--muted); text-decoration: line-through; }
.clue.used::before { background: var(--yes); color: var(--surface); content: "✓"; }

.grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
table.grid { border-collapse: collapse; font-size: .82rem; margin: 0 auto; }
th.colhead { writing-mode: vertical-rl; transform: rotate(180deg); text-align: left; padding: 6px 2px; height: 124px; white-space: nowrap; font-weight: 500; vertical-align: bottom; }
th.rowhead { text-align: right; padding: 0 8px 0 0; white-space: nowrap; font-weight: 500; }
th.rowhead .rh { display: inline-flex; align-items: center; gap: 6px; }
th.rowhead .av { width: 24px; height: 24px; }
th.grouphead { font: 700 .64rem/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--rust); padding: 4px 0; }
th.rgroup { writing-mode: vertical-rl; transform: rotate(180deg); font: 700 .64rem/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--rust); padding: 0 4px; }
td.cell { width: 32px; height: 32px; min-width: 32px; padding: 0; border: 1px solid var(--line); background: var(--cell); }
td.cell button { width: 100%; height: 100%; display: grid; place-items: center; background: none; border: 0; cursor: pointer; color: var(--ink); font: 700 1rem/1 var(--body); padding: 0; }
td.cell button:hover { background: var(--cell-hover); }
td.cell button[data-v="1"] { color: var(--no); }
td.cell button[data-v="2"] { color: var(--surface); background: var(--yes); }
td.cell.wrong { box-shadow: inset 0 0 0 3px var(--no); }
td.cell.wrong button { animation: shake .4s ease 2; }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
td.blank { border: 0; }
td.cell.bl { border-left: 2px solid var(--ink); } td.cell.bt { border-top: 2px solid var(--ink); }
td.cell.br { border-right: 2px solid var(--ink); } td.cell.bb { border-bottom: 2px solid var(--ink); }
@media (max-width: 520px) { table.grid { font-size: .72rem; } td.cell { width: 26px; height: 26px; min-width: 26px; } th.colhead { height: 104px; } th.rowhead { padding-right: 4px; } th.rowhead .av { display: none; } }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar.center { justify-content: center; }
label.auto { display: flex; gap: 6px; align-items: center; font-size: .85rem; color: var(--muted); margin-left: auto; }
.note { padding: 12px 14px; border-radius: 12px; background: var(--band); border-left: 5px solid var(--muted); }
.note.good { border-color: var(--yes); }
.note.bad { border-color: var(--no); }
.note p { margin: 0; }
.sheet-title { font-size: 1.2rem; margin-top: 6px; }
.answer-scroll { overflow-x: auto; }
table.answer { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.answer th, table.answer td { text-align: left; padding: 6px 6px 6px 0; vertical-align: middle; }
table.answer th { font: 700 .66rem/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
table.answer .who { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
table.answer .who .av { width: 30px; height: 30px; }
table.answer select { width: 100%; font: inherit; padding: 8px 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--cell); color: var(--ink); min-width: 0; }
@media (max-width: 520px) { table.answer .who .av { display: none; } table.answer { font-size: .85rem; } }
.reveal { display: grid; gap: 10px; }
.reveal h3 { font-size: 1.1rem; }
.reveal ol, .reveal ul { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.verdict { font-weight: 700; margin: 0; }

/* Portraits */
.av { display: block; border-radius: 50%; }

/* Solved overlay */
.overlay { position: fixed; inset: 0; z-index: 20; background: color-mix(in srgb, var(--ink) 45%, transparent); display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.done-card { position: relative; width: min(480px, 100%); background: var(--surface); border-radius: 24px; padding: 0 24px 24px; display: grid; gap: 12px; text-align: center; box-shadow: var(--shadow); overflow: hidden; animation: pop .35s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.parade { height: 110px; margin: 0 -24px; background: linear-gradient(var(--sky-top), var(--sky-bot)); position: relative; overflow: hidden; border-bottom: 10px solid var(--hill1); }
.parade .av { position: absolute; bottom: 6px; width: 58px; height: 58px; animation: trot 1.6s ease-out both; }
@keyframes trot { from { transform: translateX(-420px); } 70% { transform: translateX(6px); } 80% { transform: translateX(0) translateY(-8px); } to { transform: translateX(0); } }
.done-card h2 { font-size: 2.2rem; font-weight: 800; color: var(--grass); }
.done-verdict { margin: 0; }
.done-stats { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.done-stats span { font: 700 .8rem/1 var(--mono); letter-spacing: .05em; text-transform: uppercase; background: var(--band); padding: 8px 12px; border-radius: 999px; }
.share-fallback { margin: 0; font: .85rem/1.4 var(--mono); background: var(--band); padding: 10px; border-radius: 10px; user-select: all; white-space: pre-wrap; text-align: left; }
.close { position: absolute; top: 8px; right: 10px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--ink); font-size: 1.4rem; cursor: pointer; }

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