:root {
  color-scheme: light;
  --bg: #faf6ec;
  --surface: #fffdf6;
  --surface-2: #f1e9d6;
  --ink: #201b12;
  --muted: #5c5344;
  --line: #d8cbb0;
  --accent: #8a3b1c;
  --accent-ink: #ffffff;
  --focus: #1a4fd6;
  --ok: #1e6b2e;
  --bad: #a31616;
  --warn: #7a4d00;
  --trunk-frame: #4a3b28;
  --trunk-bed: #e7dcc3;
  --cell-empty: #efe6d0;
  --cell-grid: #d3c5a5;
  --p-sack: #b98a3e;
  --p-sack-ink: #241a08;
  --p-bundle: #cfc4a8;
  --p-bundle-ink: #2a2416;
  --p-demijohn: #3f7d4e;
  --p-demijohn-ink: #0f2413;
  --p-bucket: #4f6f9e;
  --p-bucket-ink: #101c2c;
  --p-rooster: #dfe8ee;
  --p-rooster-ink: #1c2b33;
  --c-bar: #8a3b1c;
  --c-track: #e2d6ba;
  --c-marker: #1a4fd6;
  --radius: 10px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14110b;
  --surface: #1e1a12;
  --surface-2: #292218;
  --ink: #f2e9d5;
  --muted: #c4b694;
  --line: #4d4230;
  --accent: #e8a06a;
  --accent-ink: #221204;
  --focus: #9db9ff;
  --ok: #8fd694;
  --bad: #ff9d9d;
  --warn: #ffd479;
  --trunk-frame: #0d0b07;
  --trunk-bed: #241e13;
  --cell-empty: #2b2417;
  --cell-grid: #4d4230;
  --p-sack: #8a5f22;
  --p-sack-ink: #fdf3dd;
  --p-bundle: #6e6350;
  --p-bundle-ink: #fdf6e3;
  --p-demijohn: #2e6b40;
  --p-demijohn-ink: #eef7ee;
  --p-bucket: #37567e;
  --p-bucket-ink: #eaf2fb;
  --p-rooster: #5b6b74;
  --p-rooster-ink: #f4fafc;
  --c-bar: #e8a06a;
  --c-track: #38301f;
  --c-marker: #9db9ff;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "DejaVu Serif", serif;
  line-height: 1.6;
  font-size: 1.0625rem;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
}

.topbar .brand { font-weight: bold; color: var(--ink); text-decoration: none; }
.topbar .project-name { color: var(--muted); text-decoration: none; }
.topbar nav { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }

a { color: var(--accent); }
[data-theme="dark"] a { color: var(--accent); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--surface);
  padding: 0.5rem 1rem;
  z-index: 50;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

main { max-width: 68ch; margin: 0 auto; padding: 0 1rem 4rem; }
main.wide { max-width: 1100px; }

.hero { padding: 2.5rem 0 1rem; }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
  font-family: Verdana, Geneva, sans-serif;
}
h1 { font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.12; margin: 0 0 0.75rem; text-wrap: balance; }
.deck { font-size: 1.2rem; color: var(--ink); max-width: 56ch; }
.source-cue { color: var(--muted); font-size: 0.9rem; }

/* ---------- game ---------- */
.game-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1.5rem 0;
}
.game-top { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.75rem; }
.game-top h2 { font-size: 1.25rem; margin: 0 1rem 0 0; }
.instructions { margin: 0.25rem 0 0.75rem; color: var(--muted); font-size: 0.95rem; }

.game-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .game-layout { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); align-items: start; }
}

.trunk {
  background: var(--trunk-frame);
  border-radius: 14px;
  padding: clamp(10px, 2vw, 18px);
}
.trunk-lid {
  height: 26px;
  border: 2px solid var(--trunk-frame);
  border-bottom: none;
  border-radius: 60px 60px 0 0;
  background: var(--surface-2);
  margin-bottom: 6px;
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  background: var(--trunk-bed);
  border-radius: 6px;
  padding: 6px;
  touch-action: manipulation;
}
.cell {
  aspect-ratio: 1 / 1;
  background: var(--cell-empty);
  border: 1px solid var(--cell-grid);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.cell.filled { border-color: transparent; }
.cell.active { outline: 2px dashed var(--focus); outline-offset: -2px; }
.cell svg { width: 70%; height: 70%; }

.f-sack { background: var(--p-sack); color: var(--p-sack-ink); }
.f-bundle { background: var(--p-bundle); color: var(--p-bundle-ink); }
.f-demijohn { background: var(--p-demijohn); color: var(--p-demijohn-ink); }
.f-bucket { background: var(--p-bucket); color: var(--p-bucket-ink); }
.f-rooster { background: var(--p-rooster); color: var(--p-rooster-ink); }

.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
button, .btn {
  font: inherit;
  font-family: Verdana, Geneva, sans-serif;
  font-size: 0.95rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: bold; }
button[aria-pressed="true"] { outline: 3px solid var(--focus); }

.status-line { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.95rem; color: var(--muted); margin-top: 0.5rem; }
.live {
  margin-top: 0.5rem;
  min-height: 2.6em;
  padding: 0.5rem 0.75rem;
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  font-size: 0.98rem;
}
.live.good { border-left-color: var(--ok); }
.live.bad { border-left-color: var(--bad); }

.ledger { font-size: 0.93rem; }
.ledger h3 { font-size: 1rem; margin: 0 0 0.5rem; font-family: Verdana, Geneva, sans-serif; }
.ledger ol, .ledger ul { margin: 0.25rem 0 0.75rem; padding-left: 1.25rem; }
.ledger li[data-state="placed"] { color: var(--ok); }
.ledger li[data-state="broken"] { color: var(--bad); text-decoration: line-through; }
.ledger details { margin-bottom: 0.25rem; }
.ledger summary { cursor: pointer; min-height: 44px; }

.game-error {
  border: 2px solid var(--bad);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  display: none;
}
.game-error.show { display: block; }

/* ---------- editorial ---------- */
.chapter { margin: 3rem 0; }
.chapter h2 { font-size: clamp(1.5rem, 3.4vw, 2.1rem); line-height: 1.2; text-wrap: balance; }
.prose p { max-width: 62ch; }
.answer-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}
.answer-box strong { font-size: 1.1rem; }

figure { margin: 1.5rem 0; }
figure img { max-width: 100%; height: auto; border-radius: 8px; display: block; }
figcaption { color: var(--muted); font-size: 0.9rem; margin-top: 0.5rem; }

.proxy-bar { margin: 1rem 0; }
.proxy-row { display: grid; grid-template-columns: 9.5rem 1fr 4.5rem; gap: 0.6rem; align-items: center; margin: 0.4rem 0; font-size: 0.95rem; }
.proxy-track { background: var(--c-track); border-radius: 6px; height: 1.5rem; position: relative; }
.proxy-fill { background: var(--c-bar); border-radius: 6px; height: 100%; }
.proxy-marker { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--c-marker); }

.calc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 1.25rem 0; }
.calc label { display: block; margin: 0.6rem 0 0.2rem; font-weight: bold; }
.calc input {
  font: inherit;
  width: 100%;
  max-width: 20rem;
  padding: 0.5rem 0.7rem;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.calc output { display: block; font-size: 1.3rem; margin-top: 0.75rem; }

.method { font-size: 0.95rem; color: var(--muted); }
.method dt { font-weight: bold; color: var(--ink); }
.method dd { margin: 0 0 0.5rem; }

footer.site {
  border-top: 1px solid var(--line);
  padding: 1.5rem 1rem 3rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 68ch;
  margin: 0 auto;
}
footer.site .spacer { flex: 1; }
