:root {
  color-scheme: light dark;
  --bg: #e9f4dc;
  --bg-2: #d7ebc4;
  --panel: rgba(255, 255, 250, 0.82);
  --panel-solid: #fbfff5;
  --ink: #18301c;
  --muted: #52684f;
  --line: rgba(24, 48, 28, 0.12);
  --accent: #7ed957;
  --accent-deep: #3f8f2a;
  --accent-ink: #0f2a06;
  --gold: #f2b51c;
  --gold-dim: rgba(24, 48, 28, 0.16);
  --bad: #e0483b;
  --ahead: #2b8a3e; /* a frog ahead of its best, under the clock */
  --water: #3f9fdc;
  --radius: 18px;
  --display: 'Lilita One', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --display-weight: 400; /* the weight hub/game.css gives display text */
  --text: Rubik, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --shadow: rgba(30, 60, 30, 0.2);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a14;
    --bg-2: #15241b;
    --panel: rgba(28, 44, 34, 0.82);
    --panel-solid: #1b2b21;
    --ink: #e6f5df;
    --muted: #93ac97;
    --line: rgba(220, 255, 220, 0.11);
    --accent: #86e05c;
    --accent-deep: #5fbf3a;
    --gold: #f6c945;
    --gold-dim: rgba(220, 255, 220, 0.16);
    --bad: #ff6457;
    --ahead: #86e05c;
    --water: #2f80bd;
    --shadow: rgba(0, 0, 0, 0.5);
  }
}
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  height: 100dvh;
  background: radial-gradient(120% 70% at 50% -10%, var(--bg-2), var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 500 15px/1.4 var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.fi-body { fill: var(--accent); }
.fi-leg { fill: var(--accent-deep); }

.app {
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(6px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------------- header */
/* Nothing here changes size when game.js fills it in, so the page doesn't shift on load: the sides
   (two buttons each) keep their width whatever the day label says, and the label has a line reserved. */
.top { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 2px 0 6px; }
.logo {
  margin: 0;
  font: 400 32px/1 var(--display);
  letter-spacing: 0.5px;
  color: var(--accent-deep);
  text-shadow: 0 2px 0 var(--shadow);
}
@media (prefers-color-scheme: dark) { .logo { color: var(--accent); } }
.day { margin: 2px 0 0; min-height: 1.4em; font-size: 12px; line-height: 1.4; color: var(--muted); font-weight: 600; letter-spacing: 0.2px; }
@media (max-width: 360px) {
  .day-url .day { min-height: 2.8em; }
  .day-url .foot { min-height: 70px; } /* the Today's crossing button squeezes the hint onto more lines */
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- hud */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.frogs { display: flex; gap: 2px; align-items: center; min-width: calc(5 * 22px + 4 * 2px); } /* room for five frogs */
.fg { position: relative; width: 22px; height: 22px; opacity: 0.95; transition: opacity 0.2s, transform 0.2s; }
.fg svg { width: 100%; height: 100%; }
.fg.next { transform: scale(1.12); }
.fg.live { transform: scale(1.18); animation: bob 0.9s ease-in-out infinite; }
.fg.lost { opacity: 0.28; filter: grayscale(1); }
.fg.crossed { opacity: 0.45; }
.fg.crossed::after { content: '✓'; position: absolute; right: -3px; bottom: -4px; font: 700 11px/1 var(--text); color: var(--accent-deep); }
.fg i { position: absolute; inset: 0; display: grid; place-items: center; font: 700 18px/1 var(--text); color: var(--bad); font-style: normal; }
.inf { font: 400 20px/1 var(--display); color: var(--muted); margin-left: 4px; }
@keyframes bob { 50% { transform: scale(1.18) translateY(-2px); } }
.clock { text-align: center; }
.clock b { display: block; font: 400 26px/1 var(--display); font-variant-numeric: tabular-nums; letter-spacing: 0.5px; min-width: 4.4ch; }
.clock small, .clock::after, .marks span { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; }
.clock::after { content: 'perfect run'; display: block; height: 0; visibility: hidden; } /* room for the longer label */
.clock small.ahead { color: var(--ahead); }
.clock small.behind { color: var(--bad); }
.marks { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.marks b { display: inline-block; min-width: 5ch; text-align: right; font: 600 13px/1.2 var(--text); color: var(--ink); text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; margin-left: 3px; } /* room for 0:00.0 */

/* ---------------------------------------------------------------- stage */
.stage {
  position: relative;
  flex: 1;
  min-height: 240px;
  display: flex;
  justify-content: center;
  overflow: hidden;
  border-radius: var(--radius);
}
#cv {
  display: block;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px -12px var(--shadow), 0 0 0 1px var(--line);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: var(--water);
}
#cv:focus { outline: none; }
#cv:focus-visible { outline: 3px solid var(--water); outline-offset: 3px; }
#cv:not([style]) { visibility: hidden; } /* until game.js sizes it: its default size jumps on load */
/* Paused: a solid veil hides the frozen traffic (drawn under the prompt and the card). */
.stage.veiled::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: var(--bg-2);
  box-shadow: inset 0 0 0 1px var(--line);
  pointer-events: none; /* a tap on the board still carries on */
}
.prompt {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translate(-50%, -8px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(12, 24, 14, 0.72);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
}
.prompt.on { opacity: 1; transform: translate(-50%, 0); }
.prompt.gold { background: rgba(60, 40, 0, 0.75); color: #ffe48a; }
.card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(320px, calc(100% - 32px));
  padding: 18px 18px 16px;
  border-radius: 20px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.card[hidden] { display: none; }
@media (prefers-color-scheme: dark) { .cd-kicker { color: var(--accent); } }
.cd-stars, .res-stars { display: flex; justify-content: center; gap: 4px; margin: 6px 0 0; font-size: 28px; line-height: 1; }
.cd-stars span, .res-stars span { color: var(--gold-dim); }
.cd-stars span.on, .res-stars span.on { color: var(--gold); animation: star 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes star { from { transform: scale(0.2) rotate(-40deg); opacity: 0; } }

.foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px 8px; padding-top: 8px; min-height: 44px; }
.hint { margin: 0 auto 0 0; flex: 1 1 150px; font-size: 12px; color: var(--muted); } /* the buttons wrap onto a row of their own when they don't fit beside it */
.foot .btn + .btn { margin-left: 0; }
.foot .btn { flex: none; }
#btnToday { margin-left: auto; }
.hint .tc { display: none; }
@media (pointer: coarse) { .hint .kb { display: none; } .hint .tc { display: inline; } }

/* ---------------------------------------------------------------- buttons */
.btn:active { transform: scale(0.97); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost:hover { background: var(--panel); }
.btn.wide { margin-top: 14px; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--water); outline-offset: 2px; }

/* ---------------------------------------------------------------- dialogs */
@keyframes pop { from { opacity: 0; transform: translate(var(--tx, 0), var(--ty, 0)) scale(0.94); } }
.card { --tx: -50%; --ty: -50%; }
.close:focus { outline: none; }
.close:focus-visible { outline: 3px solid var(--water); }
.how-list li { display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: center; font-size: 14px; }
.mini { position: relative; width: 52px; height: 36px; border-radius: 10px; overflow: hidden; }
.mini.road { background: #4c505d; }
.mini.river { background: #3f9fdc; }
.mini.rail { background: repeating-linear-gradient(90deg, #a39a8c 0 6px, #6e4d35 6px 9px); }
.mini.rail::before, .mini.rail::after { content: ''; position: absolute; left: 0; right: 0; height: 3px; background: #e1e4ea; }
.mini.rail::before { top: 9px; }
.mini.rail::after { bottom: 9px; }
.mini.grass { background: #9ad86f; }
.mini i { position: absolute; }
.mini .car { left: 10px; top: 10px; width: 26px; height: 16px; border-radius: 6px; background: #ff6b5e; box-shadow: inset -7px 0 0 rgba(20, 30, 45, 0.45); animation: drive 2.4s linear infinite; }
.mini .log { left: 6px; top: 8px; width: 38px; height: 20px; border-radius: 10px; background: #a0673a; box-shadow: inset -8px 0 0 #e2b783; }
.mini .lamp { left: 20px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: #ff3b30; box-shadow: 0 0 0 3px #1b1b1f, 0 0 12px 4px rgba(255, 60, 50, 0.6); animation: blink 0.5s steps(2) infinite; z-index: 1; }
.mini .bush { left: 14px; top: 6px; width: 24px; height: 24px; border-radius: 50%; background: #3d8a3b; box-shadow: -7px 5px 0 -2px #3d8a3b, 7px 5px 0 -2px #3d8a3b; }
@keyframes drive { from { transform: translateX(-34px); } to { transform: translateX(34px); } }
@keyframes blink { 50% { opacity: 0.25; } }
.section-h { margin: 16px 0 6px; font: 700 12px/1 var(--text); color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.keys { margin: 10px 0 0; font-size: 13px; color: var(--muted); line-height: 1.9; }
.kicker { color: var(--muted); }
.res-hero { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 10px 0 2px; flex-wrap: wrap; }
.res-time { font: 400 44px/1 var(--display); font-variant-numeric: tabular-nums; }
.res-line { margin: 4px 0 0; text-align: center; color: var(--muted); font-weight: 600; font-size: 14px; }
.cd-splits { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; font-size: 13px; }
.splits { margin: 12px auto 0; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.splits caption { color: var(--muted); font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.splits th, .splits td { padding: 3px 10px; text-align: right; }
.splits th[scope="row"], .splits thead th:first-child { text-align: left; }
.splits thead th { color: var(--muted); font-size: 12px; font-weight: 700; }
.splits td:last-child { color: var(--muted); font-weight: 700; }
.splits td.ok { color: inherit; }
.res-frogs { margin: 8px 0 0; text-align: center; font-size: 22px; letter-spacing: 3px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.wd.today i { border: 2px dashed var(--accent-deep); }
.wd.s3 i { background: var(--gold); color: #2a1d00; border-color: transparent; }
.wd.s2 i { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.wd.s1 i { background: color-mix(in srgb, var(--accent) 40%, transparent); border-color: transparent; }
.wd.lost i { color: var(--bad); }
.legend { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 3px 0 8px; vertical-align: -1px; }
.lg.s3 { background: var(--gold); }
.lg.s2 { background: var(--accent); }
.lg.s1 { background: color-mix(in srgb, var(--accent) 40%, transparent); }
.countdown a { color: var(--ink); font-weight: 700; }

.toast { z-index: 10; }

@media (max-width: 380px) {
  .app { padding-left: 8px; padding-right: 8px; }
  .clock b { font-size: 22px; }
  .fg { width: 19px; height: 19px; }
  .frogs { min-width: calc(5 * 19px + 4 * 2px); }
  .hint { font-size: 11px; }
}
/* the same for the site-wide Reduce motion setting (hub/prefs.js) */
