/* Layout: one narrow column, like a phone game. The board is the hero,
   with a status strip above and a thumb-reach toolbar below. */
:root {
  /* Park neutrals with a slight green bias */
  --bg: #eef2ea;
  --surface: #ffffff;
  --ink: #1d2620;
  --muted: #5d6b61;
  --line: #d3dbcf;
  --accent: #2f6b3a;        /* collar green: primary actions */
  --accent-ink: #ffffff;
  --ball: #d6e45a;          /* tennis ball: focus and highlights */
  --danger: #c4372f;
  --grid: rgba(29, 38, 32, 0.16);
  --wall: #1d2620;
  --mark: rgba(29, 38, 32, 0.55);
  --blocked: rgba(29, 38, 32, 0.22);
  --shadow: 0 1px 2px rgba(29, 38, 32, 0.08), 0 8px 24px rgba(29, 38, 32, 0.08);

  /* Yards: ten pastels, each region gets its own */
  --r0: #f6c3a4; --r1: #b6d8f0; --r2: #d5c4ef; --r3: #bfe3b0; --r4: #f5e092;
  --r5: #f1b4c4; --r6: #a6ddd2; --r7: #e2c9a3; --r8: #c6ccd9; --r9: #dbe79b;

  --font-display: 'Lilita One', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --radius: 14px;
  --col: 520px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151b17; --surface: #1f2722; --ink: #e8eee6; --muted: #9aa99e; --line: #323d36;
    --accent: #8fd18f; --accent-ink: #10200f; --ball: #d6e45a; --danger: #ff7b6e;
    --grid: rgba(0, 0, 0, 0.28); --wall: #0b0f0c; --mark: rgba(255, 255, 255, 0.62);
    --blocked: rgba(0, 0, 0, 0.32); --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
    --r0: #b35a3c; --r1: #3f7aa8; --r2: #7a5fb0; --r3: #4c8f48; --r4: #b08a2a;
    --r5: #a84d6c; --r6: #2f8f86; --r7: #6e6450; --r8: #5a6378; --r9: #6f9a34;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151b17; --surface: #1f2722; --ink: #e8eee6; --muted: #9aa99e; --line: #323d36;
  --accent: #8fd18f; --accent-ink: #10200f; --ball: #d6e45a; --danger: #ff7b6e;
  --grid: rgba(0, 0, 0, 0.28); --wall: #0b0f0c; --mark: rgba(255, 255, 255, 0.62);
  --blocked: rgba(0, 0, 0, 0.32); --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
  --r0: #b35a3c; --r1: #3f7aa8; --r2: #7a5fb0; --r3: #4c8f48; --r4: #b08a2a;
  --r5: #a84d6c; --r6: #2f8f86; --r7: #6e6450; --r8: #5a6378; --r9: #6f9a34;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font-body);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--font-display); font-weight: 400; line-height: 1.1; margin: 0; text-wrap: balance; letter-spacing: 0.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--ball); outline-offset: 2px; }

.app {
  max-width: var(--col);
  margin: 0 auto;
  min-height: 100%;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px max(20px, env(safe-area-inset-bottom, 0px));
}
.screen { display: flex; flex-direction: column; gap: 22px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease;
  min-height: 44px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.icon-btn {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn svg { width: 24px; height: 24px; }

/* ---------- Home ---------- */
.brand { display: flex; align-items: center; gap: 14px; padding-top: 8px; }
.brand-pup { width: 72px; height: 72px; flex: none; transform: rotate(-6deg); }
.logo { font-size: clamp(2.6rem, 11vw, 3.4rem); color: var(--accent); }
.tagline { color: var(--muted); }

.eyebrow { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--muted); }
.daily {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow);
  background-image: radial-gradient(circle at 100% 0, color-mix(in srgb, var(--ball) 35%, transparent) 0, transparent 55%);
}
.daily h2 { font-size: 1.7rem; }
.daily-meta { color: var(--muted); font-size: 0.95rem; }
.daily-text { min-width: 0; }
.daily .btn { flex: none; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font-size: 1.4rem; }
.section-head p { font-size: 0.9rem; }
.sizes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.size-btn {
  width: 100%; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; transition: transform 0.12s ease, border-color 0.15s ease;
}
.size-btn:hover { border-color: var(--accent); }
.size-btn:active { transform: scale(0.98); }
.size-mini { grid-row: span 2; width: 40px; height: 40px; border-radius: 8px; overflow: hidden; display: grid; }
.size-mini i { display: block; }
.size-name { font-family: var(--font-display); font-size: 1.2rem; line-height: 1.1; }
.size-meta { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.home-links { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; }

/* ---------- Game ---------- */
.game { gap: 14px; }
.game-head { display: flex; align-items: center; gap: 8px; }
.game-title { flex: 1; min-width: 0; text-align: center; }
.game-title h2 { font-size: 1.5rem; }
.game-title p { font-size: 0.9rem; }

.status { display: flex; align-items: center; justify-content: space-between; min-height: 32px; padding: 0 4px; }
.treats { display: flex; gap: 6px; }
.treats svg { width: 34px; height: 17px; fill: #e7c38f; stroke: #7a4b2c; transition: opacity 0.3s ease, transform 0.3s ease; }
.treats svg.gone { opacity: 0.2; transform: rotate(-20deg) scale(0.85); fill: none; stroke: var(--muted); }
.treats .off { font-size: 0.85rem; color: var(--muted); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; color: var(--muted); }

.board-wrap { position: relative; }
.board {
  --n: 5;
  position: relative;
  width: min(100%, calc(100dvh - 300px));
  min-width: min(100%, 280px);
  margin: 0 auto;
  aspect-ratio: 1;
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  appearance: none; border: 0; padding: 0; margin: 0; position: relative;
  background: var(--c);
  cursor: pointer;
  display: grid; place-items: center;
  outline: none;
}
.cell::before { /* hover and keyboard focus wash */
  content: ""; position: absolute; inset: 0; background: var(--ink); opacity: 0; transition: opacity 0.1s;
}
@media (hover: hover) { .cell:hover::before { opacity: 0.06; } }
.cell:focus-visible { z-index: 3; box-shadow: inset 0 0 0 3px var(--ball), inset 0 0 0 5px var(--wall); }
.cell .x, .cell .pup, .cell .dot { position: relative; pointer-events: none; }
.cell .x { width: 46%; height: 46%; color: var(--mark); }
.cell .dot { width: 18%; height: 18%; border-radius: 50%; background: var(--blocked); }
.cell .pup { width: 82%; height: 82%; animation: pop 0.28s cubic-bezier(.3, 1.6, .5, 1); }
.cell.bad { background: color-mix(in srgb, var(--danger) 30%, var(--c)); }
.cell.bad .x { color: var(--danger); }
.cell.clash .pup { animation: wiggle 0.5s ease-in-out infinite alternate; filter: drop-shadow(0 0 0 var(--danger)); }
.cell.clash::after { content: ""; position: absolute; inset: 8%; border-radius: 50%; border: 3px solid var(--danger); pointer-events: none; }
.cell.flash { animation: flash 0.9s ease; }
.cell.shake { animation: shake 0.4s ease; }
.board.won .pup { animation: hop 0.6s ease calc(var(--row) * 70ms) 2; }

.walls { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.walls .thin { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.walls .thick { stroke: var(--wall); stroke-width: 3; stroke-linecap: square; vector-effect: non-scaling-stroke; }
.walls .frame { fill: none; stroke: var(--wall); stroke-width: 5; vector-effect: non-scaling-stroke; }

.loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center;
  color: var(--muted); font-weight: 700; background: color-mix(in srgb, var(--bg) 80%, transparent); border-radius: 10px; z-index: 4;
}
.loading-paw { width: 42px; height: 42px; fill: var(--accent); animation: sniff 0.9s ease-in-out infinite alternate; }

.hint-line { text-align: center; color: var(--muted); font-size: 0.92rem; min-height: 1.4em; }

.tools { display: flex; align-items: stretch; justify-content: space-between; gap: 6px; }
.tool, .mode-btn {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.78rem; font-weight: 700; color: var(--muted);
  padding: 8px 10px; border-radius: 12px; min-width: 60px;
}
.tool:hover, .mode-btn:hover { color: var(--ink); }
.tool svg, .mode-btn svg { width: 26px; height: 26px; }
.tool svg.fill { fill: currentColor; }
.tool:disabled { opacity: 0.4; cursor: default; }
.mode { display: flex; background: var(--surface); border-radius: 14px; padding: 4px; gap: 2px; box-shadow: var(--shadow); }
.mode-btn[aria-checked="true"] { background: var(--ball); color: #1d2620; }

/* ---------- Sheets (dialogs) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 12, 0.45); z-index: 20; animation: fade 0.2s ease; }
.sheet {
  position: fixed; z-index: 21; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(100%, var(--col));
  max-height: calc(100% - 40px); overflow-y: auto;
  background: var(--surface); color: var(--ink);
  border-radius: 22px 22px 0 0;
  padding: 26px max(22px, env(safe-area-inset-left, 0px)) max(22px, env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px; align-items: stretch;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
  animation: rise 0.28s cubic-bezier(.2, .9, .3, 1);
}
@media (min-width: 560px) {
  .sheet { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 22px; width: min(calc(100% - 32px), 440px); animation: none; }
}
.sheet h2 { font-size: 1.9rem; }
.sheet-pup { width: 84px; height: 84px; align-self: center; animation: hop 0.6s ease 2; }
.sheet-bone { width: 96px; height: 48px; align-self: center; fill: none; stroke: var(--muted); transform: rotate(-14deg); }
#win h2, #win > p, #lose h2, #lose > p { text-align: center; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.stats div { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; }
.stats dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.stats dd { margin: 0; font-family: var(--font-display); font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.toast { text-align: center; color: var(--accent); font-weight: 700; min-height: 1.5em; }

.rules { margin: 0; padding-left: 1.4em; display: grid; gap: 4px; }
.rules-demo { display: flex; justify-content: center; }
.rules-demo .board { width: 180px; min-width: 0; pointer-events: none; }

.settings { display: grid; gap: 4px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row span { display: grid; gap: 2px; min-width: 0; }
.switch-row small { color: var(--muted); font-size: 0.85rem; line-height: 1.35; }
.switch-row input {
  appearance: none; flex: none; width: 50px; height: 30px; border-radius: 999px; background: var(--line);
  position: relative; cursor: pointer; transition: background-color 0.2s ease; margin: 0;
}
.switch-row input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s ease;
}
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(20px); }
.danger { display: grid; gap: 8px; justify-items: start; }
.confirm { display: grid; gap: 8px; width: 100%; background: var(--bg); border-radius: 12px; padding: 12px; }

/* ---------- Motion ---------- */
@keyframes pop { from { transform: scale(0.3); } to { transform: scale(1); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-18%) rotate(-6deg); } 60% { transform: translateY(0) rotate(4deg); } }
@keyframes wiggle { from { transform: rotate(-8deg); } to { transform: rotate(8deg); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6%); } 75% { transform: translateX(6%); } }
@keyframes flash { 0%, 100% { box-shadow: inset 0 0 0 0 var(--ball); } 30% { box-shadow: inset 0 0 0 5px var(--ball); } }
@keyframes sniff { from { transform: translateX(-6px) rotate(-8deg); } to { transform: translateX(6px) rotate(8deg); } }
@keyframes rise { from { transform: translate(-50%, 30%); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
