:root {
  --bg: #f6f4ec;
  --card: #ffffff;
  --ink: #23241f;
  --muted: #5f6157;
  --line: #e0dccd;
  --accent: #3d6b2f;
  --accent-ink: #ffffff;
  --soft: #eaf0dd;
  --ochre: #b5651d;
  --gold: #c99a06;
  --radius: 12px;
  /* The paddock keeps the same colours in light and dark. */
  --grass-a: #8fbf5a;
  --grass-b: #86b652;
  --yard: #d9b77c;
  --rail: #7a4f24;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15170f;
    --card: #1e2117;
    --ink: #ebeadf;
    --muted: #a7a895;
    --line: #34382a;
    --accent: #9ccc73;
    --accent-ink: #13160d;
    --soft: #263020;
    --ochre: #e39a52;
    --gold: #f0c43c;
    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.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: break-word;
}
a { color: var(--accent); }
main { max-width: 680px; margin: 0 auto; padding: 4px 16px 40px; }
h1 { font-size: 1.8rem; line-height: 1.2; margin: 16px 0 8px; }
h2 { font-size: 1.3rem; margin: 32px 0 8px; }
h3 { font-size: 1.05rem; margin: 20px 0 4px; }
.lede { color: var(--muted); margin-top: 0; }
.note { color: var(--muted); font-size: 0.9rem; }

header.site, footer.site { max-width: 680px; margin: 0 auto; padding: 8px 16px; }
header.site { display: flex; align-items: center; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.2rem; color: var(--ink); text-decoration: none; min-height: 44px; letter-spacing: 0.02em; }
header nav { display: flex; gap: 2px; flex-wrap: wrap; }
header nav a { display: inline-flex; align-items: center; padding: 0 10px; min-height: 44px; text-decoration: none; border-radius: 8px; font-size: 0.95rem; }
header nav a:hover { background: var(--soft); }
footer.site { color: var(--muted); font-size: 0.9rem; border-top: 1px solid var(--line); margin-top: 24px; }
footer.site a { display: inline-block; padding: 10px 2px; }

button, .btn {
  font: inherit; font-weight: 650; cursor: pointer;
  min-height: 44px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--ochre); outline-offset: 2px; }

/* Game header */
.game { margin: 4px 0 8px; }
.game-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.game-head h1 { margin: 8px 0 0; font-size: 1.5rem; }
.game-head .day { color: var(--muted); font-size: 0.95rem; }
.late { background: var(--soft); border-radius: 8px; padding: 6px 10px; font-size: 0.9rem; margin: 8px 0 0; }
.status { min-height: 3.2em; margin: 6px 0 8px; font-size: 0.98rem; }
.status strong { color: var(--ochre); }

/* Board */
.board {
  --n: 6;
  position: relative; width: 100%; max-width: 480px; aspect-ratio: 1; margin: 0 auto;
  display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr);
  border: 4px solid var(--rail); border-radius: 6px; background: var(--grass-a);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.cell {
  appearance: none; border: 0; border-radius: 0; padding: 0; margin: 0; min-height: 0;
  background: var(--grass-a); position: relative; cursor: pointer;
}
.cell.alt { background: var(--grass-b); }
.cell.yard {
  background:
    repeating-linear-gradient(0deg, transparent 0 28%, var(--rail) 28% 34%, transparent 34% 62%, var(--rail) 62% 68%, transparent 68%),
    var(--yard);
}
.cell.yard::after { content: "YARD"; position: absolute; left: 0; right: 0; bottom: 2px; font: 700 9px/1 system-ui, sans-serif; color: #5a3a17; letter-spacing: 0.08em; opacity: 0.7; }
.cell.target { box-shadow: inset 0 0 0 3px rgba(255,255,255,0.9); }
.cell:focus-visible { outline: 3px solid var(--ochre); outline-offset: -3px; z-index: 3; }
.cell svg { width: 100%; height: 100%; display: block; pointer-events: none; }

.piece {
  position: absolute; left: 0; top: 0; pointer-events: none;
  width: calc(100% / var(--n)); height: calc(100% / var(--n));
  transition: transform 0.24s cubic-bezier(.2,.8,.3,1), opacity 0.25s;
  z-index: 2;
}
/* Percent margins here are of the piece (one cell), not the board. */
.piece svg { width: 88%; height: 88%; margin: 6%; display: block; }
.piece.dog { z-index: 2; }
.piece.dog svg { width: 96%; height: 96%; margin: 2%; }
.piece.ghost { opacity: 0.45; z-index: 1; transition: none; }
.piece.ghost.pen { opacity: 0.7; }
.piece.gone { opacity: 0; transform-origin: center; }
.piece.flee svg { animation: hop 0.24s ease-out; }
@keyframes hop { 50% { transform: translateY(-12%); } }
.woof {
  position: absolute; z-index: 4; pointer-events: none; font: 800 14px/1 system-ui, sans-serif;
  background: #fff; color: #222; border-radius: 10px; padding: 5px 7px; border: 2px solid #222;
  transform: translate(-50%, -120%); animation: woof 0.7s ease-out forwards; white-space: nowrap;
}
@keyframes woof { 0% { opacity: 0; transform: translate(-50%, -80%) scale(0.6); } 20% { opacity: 1; transform: translate(-50%, -120%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .piece, .piece.flee svg, .woof { transition: none; animation: none; } }

.meter { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; max-width: 480px; margin: 10px auto 0; }
.meter .count { font-size: 1.05rem; }
.meter .count b { font-size: 1.3rem; }
.meter .buttons { display: flex; gap: 8px; }
.pens { display: inline-flex; gap: 2px; vertical-align: middle; }
.pens svg { width: 22px; height: 22px; }
.pens .out { opacity: 0.3; }

/* Result panel */
.done { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 16px auto 0; max-width: 480px; }
.done h2 { margin: 0 0 4px; }
.stars { font-size: 1.6rem; letter-spacing: 2px; color: var(--gold); }
.done .row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.copied { color: var(--accent); font-weight: 600; min-height: 1.6em; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; margin: 12px 0; }
.stats b { display: block; font-size: 1.5rem; line-height: 1.2; }
.stats span { font-size: 0.8rem; color: var(--muted); line-height: 1.2; display: block; }
.dist { display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; align-items: center; font-size: 0.9rem; }
.dist .bar { background: var(--soft); border-radius: 4px; height: 22px; position: relative; }
.dist .bar i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 4px; min-width: 2px; }
.dist .bar em { position: absolute; right: 6px; top: 0; font-style: normal; line-height: 22px; font-size: 0.8rem; }
.countdown { font-variant-numeric: tabular-nums; }

/* Written pages */
.callout { background: var(--soft); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0; }
.pair { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin: 12px 0 4px; }
.pair .arrow { font-size: 1.4rem; color: var(--muted); }
.pair figcaption, .fig-cap { grid-column: 1 / -1; font-size: 0.9rem; color: var(--muted); text-align: center; }
.mini { --n: 5; border-width: 3px; max-width: 220px; }
.mini .cell { cursor: default; }
.mini .cell.yard::after { content: ""; }
.mini .piece { transition: none; }
figure { margin: 16px 0; }
table.callout { border-collapse: collapse; width: 100%; display: table; padding: 0; overflow: hidden; }
table.callout th, table.callout td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }
pre.callout { white-space: pre-wrap; font: inherit; }

/* Archive */
.months { display: grid; gap: 20px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { font-size: 0.75rem; color: var(--muted); text-align: center; }
.cal a, .cal span.blank {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 48px; border-radius: 8px; text-decoration: none; font-size: 0.95rem; line-height: 1.1;
}
.cal a { background: var(--card); border: 1px solid var(--line); color: var(--ink); }
.cal a small { font-size: 0.75rem; color: var(--muted); }
.cal a.won { background: var(--soft); border-color: var(--accent); }
.cal a.par small { color: var(--gold); }
.cal a.today { outline: 2px solid var(--ochre); }

.ad-slot { margin: 24px 0; min-height: 100px; }
