:root {
  color-scheme: light dark;
  --bg: #eff3f1;
  --panel: #ffffff;
  --ink: #16302c;
  --soft: #4c625e;
  --line: #c3cfcb;
  --accent: #14694f;
  --on-accent: #ffffff;
  --warn: #a3280f;
  --sun: #f2b632;
  --land: #d5e6d6;
  --road: #ffffff;
  --road-edge: #8aa098;
  --trail: #14694f;
  --wood: #b98552;
  --wall: #dfe6ee;
  --radius: 12px;
  --t0: #ffe1a6; --t1: #bfe3f5; --t2: #f7c9d4; --t3: #cfe8b9;
  --t4: #dccff3; --t5: #ffd0b0; --t6: #b5e6da; --t7: #e3ddc6;
  font: 17px/1.5 "Segoe UI Variable Text", "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}
body[data-game="shelf"] { --accent: #86355c; }
body[data-game="split"] { --accent: #2456a8; }
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101a19; --panel: #192725; --ink: #e8f0ed; --soft: #a5b8b2; --line: #39504a;
    --accent: #58c79d; --on-accent: #06231a; --warn: #ff9b85; --land: #1f3a31; --road: #55706a;
    --road-edge: #0d1615; --trail: #f2b632; --wood: #8a5f38; --wall: #22303b;
    --t0: #6a4e10; --t1: #184f69; --t2: #6f2c3d; --t3: #37561d;
    --t4: #47346f; --t5: #6e3a17; --t6: #125648; --t7: #4b4630;
  }
  body[data-game="shelf"] { --accent: #f09cc2; --on-accent: #34081e; }
  body[data-game="split"] { --accent: #8ab8ff; --on-accent: #06204a; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
main, .top { width: min(100% - 28px, 620px); margin-inline: auto; }
main { padding-bottom: 48px; }
.top { padding: 14px 0 0; font-weight: 600; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2 { line-height: 1.15; margin: 0; letter-spacing: -0.015em; text-wrap: balance; }
h1 { font-size: 2rem; font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 750; }
p { margin: 0.5em 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.offscreen { position: fixed; left: -999px; }

button, .button {
  font: inherit; font-weight: 600; color: var(--ink); background: var(--panel);
  border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 16px; min-height: 46px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
.main { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tools { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.say { min-height: 1.5em; font-weight: 600; margin: 10px 0 0; }
.notice, .result { background: var(--panel); border-radius: var(--radius); padding: 18px; }
.result { border-top: 6px solid var(--accent); scroll-margin: 12px; }
.card { font: inherit; white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.note { font-weight: 600; }
.game-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin: 10px 0 14px; }
.meta { margin: 4px 0 0; color: var(--soft); font-variant-numeric: tabular-nums; }
.rules { border: 0; border-radius: 16px; padding: 24px; max-width: min(92vw, 460px); background: var(--panel); color: var(--ink); }
.rules::backdrop { background: rgb(6 20 18 / 0.6); }
.rules ul { padding-left: 1.2em; }
.rules li { margin: 6px 0; }
.keys { color: var(--soft); font-size: 0.92rem; }
@media (pointer: coarse) { .keys { display: none; } }

/* Home */
.home h1 { margin-top: 18px; }
.games { list-style: none; padding: 0; margin: 22px 0; display: grid; gap: 14px; }
.games a {
  display: grid; grid-template-columns: 96px 1fr; gap: 18px; align-items: center; padding: 16px;
  background: var(--panel); border-radius: 16px; color: inherit; text-decoration: none; border: 2px solid transparent;
}
.games a:hover { border-color: var(--accent); }
.games svg { width: 96px; height: 96px; border-radius: 12px; display: block; }
.games p { margin: 4px 0 0; color: var(--soft); }
.games .status { color: var(--ink); font-weight: 600; }
.foot { color: var(--soft); font-size: 0.92rem; }

/* Road Home */
.gauge { margin-bottom: 10px; }
.tank { height: 16px; border-radius: 8px; background: var(--line); overflow: hidden; }
.tank span { display: block; height: 100%; background: var(--accent); transition: width 0.2s; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.map { display: block; width: 100%; max-height: 68vh; background: var(--land); border-radius: 16px; touch-action: none; user-select: none; -webkit-user-select: none; }
.road-edge { stroke: var(--road-edge); stroke-width: 24; stroke-linecap: round; }
.road { stroke: var(--road); stroke-width: 19; stroke-linecap: round; }
.trail { fill: none; stroke: var(--trail); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.cost-dot { fill: var(--panel); stroke: var(--road-edge); stroke-width: 1.5; }
.map text { font-weight: 800; text-anchor: middle; fill: var(--ink); font-variant-numeric: tabular-nums; }
.cost { font-size: 18px; }
.junction circle { fill: var(--road-edge); }
.junction.open circle { fill: var(--panel); stroke: var(--accent); stroke-width: 5; }
.map .home path { fill: #c23b22; stroke: var(--panel); stroke-width: 3; }
.map .home .door { fill: #fff; stroke: none; }
.stop rect { fill: var(--sun); stroke: #16302c; stroke-width: 3; }
.map .stop text { font-size: 23px; fill: #16302c; }
.stop.done rect { fill: #14694f; stroke: #fff; }
.map .stop.done text { fill: #fff; }
.pump circle { fill: #2456a8; stroke: #fff; stroke-width: 3; }
.pump path { fill: #fff; }
.pump.done circle { fill: #6b7b78; }
.pump .strike { stroke: #fff; stroke-width: 4; }
.hint-ring circle { fill: none; stroke: var(--warn); stroke-width: 5; stroke-dasharray: 9 7; }
.van { transition: transform 0.18s ease-out; pointer-events: none; }
.van-body { fill: #16302c; stroke: #fff; stroke-width: 3; }
.van-glass { fill: #bfe3f5; }
.van-wheel { fill: #f2b632; stroke: #16302c; stroke-width: 3; }
.hit { fill: transparent; cursor: pointer; }

/* Shelf */
.shelf {
  display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 3px; padding: 14px 6px 4px;
  background: linear-gradient(var(--wall) calc(100% - 26px), var(--wood) calc(100% - 26px)); border-radius: 14px;
}
.slot { display: grid; grid-template-rows: 1fr 24px; min-width: 0; }
.pos { text-align: center; font-weight: 700; font-size: 0.85rem; color: #fff; text-shadow: 0 1px 2px #0008; }
.space, .item { width: 100%; min-width: 0; height: 88px; padding: 2px; border-radius: 10px; flex-direction: column; gap: 2px; }
.space { background: none; border: 2px dashed color-mix(in srgb, var(--ink) 45%, transparent); }
.item { background: var(--panel); touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.item:disabled { opacity: 1; }
.item.picked { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); transform: translateY(-5px); }
.item.flag { border-color: var(--warn); border-style: dashed; }
.art { width: 100%; max-width: 52px; display: block; pointer-events: none; }
.art svg { width: 100%; display: block; }
.label { font-size: clamp(0.7rem, 3.2vw, 0.85rem); line-height: 1.2; }
.tray { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 3px; min-height: 100px; padding: 6px; margin-top: 4px; }
.tray.empty { min-height: 0; padding: 0; }
.ghost { position: fixed; left: 0; top: 0; width: 56px; margin: -34px 0 0 -28px; pointer-events: none; z-index: 9; }
.clues { padding-left: 1.6em; margin: 8px 0; }
.clues li::marker { font-weight: 700; color: var(--soft); }
.clue { width: 100%; justify-content: flex-start; text-align: left; font-weight: 500; background: none; border: 0; padding: 8px 6px; min-height: 44px; }
.clue:hover { background: var(--panel); }
.clue[aria-pressed="true"] { text-decoration: line-through; color: var(--soft); }
.f1 { fill: #c23b22; } .f2 { fill: #2456a8; } .f3 { fill: #2c8a5f; } .f4 { fill: #f2b632; } .f5 { fill: #3aa0c9; } .f6 { fill: #b0703c; } .fw { fill: #fff; }
.ln { fill: none; stroke: #5d4a52; stroke-width: 2.6; stroke-linecap: round; }
.fw + .ln { stroke: #16302c; }
.lt { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; }
@media (prefers-color-scheme: dark) { .ln { stroke: #d8c6ce; } }

/* Split */
.goal { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.3em; font-size: 1.15rem; margin: 0 0 10px; }
.goal .count { margin-left: auto; font-size: 1rem; color: var(--soft); font-variant-numeric: tabular-nums; }
.split-grid { width: 100%; max-width: 500px; margin-inline: auto; border: 4px solid var(--ink); border-radius: 10px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; background: var(--panel); }
.row { display: grid; grid-template-columns: repeat(var(--n), 1fr); }
.cell { position: relative; aspect-ratio: 1; display: grid; place-items: center; cursor: pointer; box-shadow: inset 1px 1px 0 var(--line); }
.cell .num { font-size: clamp(1.3rem, 6.5vw, 2rem); font-weight: 700; font-variant-numeric: tabular-nums; pointer-events: none; }
.cell .sum { position: absolute; top: 3px; left: 6px; font-size: 0.8rem; font-weight: 700; pointer-events: none; }
.cell[data-tint="0"] { background: var(--t0); } .cell[data-tint="1"] { background: var(--t1); }
.cell[data-tint="2"] { background: var(--t2); } .cell[data-tint="3"] { background: var(--t3); }
.cell[data-tint="4"] { background: var(--t4); } .cell[data-tint="5"] { background: var(--t5); }
.cell[data-tint="6"] { background: var(--t6); } .cell[data-tint="7"] { background: var(--t7); }
.cell.wt::before, .cell.wl::after { content: ""; position: absolute; background: var(--ink); z-index: 1; pointer-events: none; }
.cell.wt::before { left: -2px; right: -2px; top: -2px; height: 4px; }
.cell.wl::after { top: -2px; bottom: -2px; left: -2px; width: 4px; }
.cell[data-state="over"] .sum { color: var(--warn); }
.cell[data-state="over"] .num { text-decoration: underline wavy var(--warn) 2px; }
.cell[data-state="ok"] .num { opacity: 0.75; }
.cell.flag { outline: 3px dashed var(--warn); outline-offset: -7px; }
.cell:focus-visible { outline: 3px solid var(--ink); outline-offset: -5px; }
.cell.drawing { outline: 4px double var(--accent); outline-offset: -6px; }

/* Tester sheet */
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; margin: 14px 0; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
.check-row { align-items: center; }
.check-row .say { flex: 1; margin: 0; min-width: 150px; }
