:root {
  color-scheme: light dark;
  --bg: #e4f1fa;
  --bg-2: #cfe6f5;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-solid: #ffffff;
  --ink: #0f2a3d;
  --muted: #465f72;
  --line: rgba(15, 42, 61, 0.11);
  --accent: #ff8a3d;
  --accent-deep: #e0651c;
  --accent-ink: #2b1300;
  --cool: #0d6590;
  --gold: #ffb321;
  --star-edge: #a86f00;
  --gold-dim: rgba(15, 42, 61, 0.16);
  --good: #16895a;
  --bad: #cf4a3c;
  --radius: 18px;
  --display: Fredoka, 'Nunito', system-ui, sans-serif;
  --text: Nunito, system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* board palette, read by the canvas renderer */
  --water: #2c8ac6;
  --water-deep: #185b93;
  --water-glint: rgba(255, 255, 255, 0.28);
  --foam: #eef9ff;
  --ice: #f6fcff;
  --ice-2: #d9eefa;
  --ice-side: #8fc4e3;
  --ice-line: rgba(70, 140, 185, 0.17);
  --rock: #7d8d9c;
  --rock-dark: #4c5a68;
  --rock-hi: #b3c0cb;
  --snow: #ffffff;
  --snow-shade: #c6dcec;
  --fish: #ff7a52;
  --fish-belly: #ffc79e;
  --peng: #1d2838;
  --peng-hi: #3d4f67;
  --peng-belly: #fbfdff;
  --beak: #ffa12b;
  --shadow: rgba(18, 60, 92, 0.24);
  --trail: rgba(92, 160, 206, 0.5);
  --hint: rgba(255, 138, 61, 0.9);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #081523;
    --bg-2: #0c2135;
    --panel: rgba(20, 42, 64, 0.72);
    --panel-solid: #11263a;
    --ink: #e4f1fb;
    --muted: #88a5bc;
    --star-edge: transparent;
    --line: rgba(200, 230, 255, 0.1);
    --accent: #ff9447;
    --accent-deep: #d86a1f;
    --accent-ink: #251000;
    --cool: #5cc6ec;
    --gold-dim: rgba(200, 230, 255, 0.16);
    --good: #4fd08a;
    --bad: #ff7466;

    --water: #0f3c63;
    --water-deep: #081f37;
    --water-glint: rgba(150, 205, 255, 0.16);
    --foam: #8ec6ea;
    --ice: #d8ecf9;
    --ice-2: #b3d5ec;
    --ice-side: #4a82a8;
    --ice-line: rgba(30, 80, 120, 0.2);
    --rock: #637281;
    --rock-dark: #37424f;
    --rock-hi: #93a2b0;
    --snow: #f4f9fd;
    --snow-shade: #a3c1d7;
    --peng: #121b27;
    --peng-hi: #34465d;
    --peng-belly: #eef5fb;
    --shadow: rgba(0, 12, 28, 0.38);
    --trail: rgba(64, 128, 178, 0.55);
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--text);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(255, 255, 255, 0.75), transparent 60%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
}
@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(70% 38% at 20% -8%, rgba(70, 255, 190, 0.13), transparent 70%),
      radial-gradient(60% 34% at 85% -10%, rgba(120, 130, 255, 0.16), transparent 70%),
      linear-gradient(180deg, var(--bg), var(--bg-2));
    background-attachment: fixed;
  }
}

.app {
  width: 100%;
  max-width: 580px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------------------------------------------------------------- header */
.logo {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 2.1rem;
  line-height: 1;
  letter-spacing: 0.01em;
  background: linear-gradient(180deg, var(--cool) 10%, var(--ink) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.day { margin: 3px 0 0; font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }

.icon-btn { touch-action: manipulation; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }

/* ---------------------------------------------------------------- pond tabs */
.ponds {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.ponds[hidden] { display: none; }
/* A weekend's special pond (#231) makes a fourth tab. */
.ponds.four { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 420px) { .ponds.four .tab-s { font-size: 0.7rem; } }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 4px 6px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  transition: background 0.15s ease, transform 0.12s ease;
}
.tab:not(:disabled):hover { background: rgba(127, 170, 200, 0.14); }
.tab:disabled { cursor: default; opacity: 0.5; }
.tab.on { background: var(--panel-solid); box-shadow: inset 0 -3px 0 var(--cool), 0 1px 2px rgba(10, 40, 70, 0.1), 0 4px 12px rgba(10, 40, 70, 0.08); } /* the underline marks it in either theme */
.tab-n { font-family: var(--display); font-weight: 600; font-size: 0.98rem; }
.tab-s { font-size: 0.78rem; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; min-height: 1.1em; }
.tab-s .st { color: var(--gold); }
.tab-s .st.off { color: var(--gold-dim); }

/* ---------------------------------------------------------------- HUD */
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.fish-left { display: flex; gap: 4px; flex-wrap: wrap; }
.fish-left i {
  width: 30px; height: 20px;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 20'%3E%3Cpath d='M8 10 1 3v14z' fill='%23ff7a52'/%3E%3Cellipse cx='16' cy='10' rx='12' ry='7' fill='%23ff7a52'/%3E%3Cellipse cx='17' cy='12.5' rx='8' ry='2.6' fill='%23ffc79e'/%3E%3Ccircle cx='23' cy='8.5' r='1.6' fill='%23222'/%3E%3C/svg%3E");
  transition: opacity 0.3s ease, transform 0.3s ease, filter 0.3s ease;
}
.fish-left i.gone { opacity: 0.25; filter: grayscale(1); transform: scale(0.8); }
.fish-left i.pop { animation: fishpop 0.45s ease; }
@keyframes fishpop { 40% { transform: scale(1.35) rotate(-8deg); } }

.counts { display: flex; align-items: center; gap: 14px; }
.count { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.count b { font-family: var(--display); font-weight: 600; font-size: 1.55rem; font-variant-numeric: tabular-nums; }
.count small { font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-top: 2px; }
.count.par b { color: var(--muted); }
.count b.bump { animation: bump 0.3s ease; }
@keyframes bump { 40% { transform: scale(1.25); } }
.meter { display: flex; gap: 1px; font-size: 1.15rem; }
.meter i { font-style: normal; color: var(--gold); transition: color 0.3s ease, transform 0.3s ease; }
.meter i.off { color: var(--gold-dim); transform: scale(0.85); }

/* ---------------------------------------------------------------- board */
.stage { position: relative; display: flex; justify-content: center; }
#board {
  display: block;
  border-radius: 24px;
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(10, 50, 90, 0.12), 0 18px 40px rgba(10, 50, 90, 0.18);
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
#board:focus-visible { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--cool); }
/* Dark water is close to the dark page: a faint rim shows where the pond ends. */
@media (prefers-color-scheme: dark) { #board:not(:focus-visible) { box-shadow: 0 0 0 1.5px rgba(92, 198, 236, 0.45), 0 18px 40px rgba(0, 0, 0, 0.4); } }

.cleared {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(92%, 380px);
  padding: 14px 16px 16px;
  border-radius: 20px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(10, 40, 70, 0.22);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  animation: rise 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.cleared[hidden] { display: none; }
/* Folded down to one row (the toggle, or a tap on the board), so the final position shows. */
.cl-min {
  position: absolute; top: 6px; right: 8px; width: 32px; height: 32px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 1.1rem; cursor: pointer;
}
.cl-min:hover { color: var(--ink); background: var(--line); }
.cleared.min { display: flex; align-items: center; gap: 8px; padding: 6px 44px 6px 12px; text-align: left; animation: none; }
.cleared.min .cl-stars, .cleared.min .cl-line, .cleared.min #clWatch { display: none; }
.cleared.min .cl-kicker { flex: 1; }
.cleared.min .cl-actions { flex: none; }
.cleared.min .cl-min { top: 50%; transform: translateY(-50%) rotate(180deg); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 18px) scale(0.96); } }
/* Docked below the board (dockCleared() in game.js), in place of the Undo/Restart row. */
.stage.dock { flex-direction: column; align-items: center; gap: 12px; }
.stage.dock .cleared { position: static; transform: none; width: min(100%, 380px); animation-name: rise-dock; }
.stage.dock .cl-min { display: none; }
.stage.dock + .controls { display: none; }
@keyframes rise-dock { from { opacity: 0; transform: translateY(12px) scale(0.96); } }
.cl-kicker { margin: 0; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--cool); }
.cl-stars { font-size: 2rem; line-height: 1.1; letter-spacing: 0.06em; margin: 2px 0; }
.cl-stars span { display: inline-block; color: var(--gold-dim); }
.cl-stars span.on { color: var(--gold); animation: star 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes star { from { transform: scale(0) rotate(-40deg); } }
.cl-line { margin: 0 0 12px; font-weight: 700; }
.cl-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- buttons */
.controls { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.btn { touch-action: manipulation; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.btn.ghost { -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.link { border: 0; background: none; padding: 4px 2px; color: var(--cool); font-weight: 800; font-size: 0.85rem; text-decoration: underline; text-underline-offset: 3px; }

.how { margin: 0; text-align: center; font-size: 0.85rem; color: var(--muted); font-weight: 600; }

/* ---------------------------------------------------------------- dialogs */
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } }

.rules { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.rules li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.4; font-size: 0.95rem; }
.tile { flex: none; width: 34px; height: 34px; border-radius: 9px; box-shadow: inset 0 -4px 0 rgba(0, 40, 80, 0.12); position: relative; overflow: hidden; }
.t-ice { background: linear-gradient(135deg, var(--ice), var(--ice-2)); }
.t-ice::after { content: ''; position: absolute; left: 6px; top: 14px; width: 18px; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, 0.9); transform: rotate(-25deg); }
.t-rock { background: radial-gradient(circle at 50% 70%, var(--rock) 0 46%, transparent 48%), linear-gradient(135deg, var(--ice), var(--ice-2)); }
.t-rock::after { content: ''; position: absolute; left: 10px; top: 9px; width: 14px; height: 6px; border-radius: 50%; background: var(--snow); }
.t-crack { background: linear-gradient(135deg, var(--ice), var(--ice-2)); }
.t-crack::before { content: ""; position: absolute; inset: 4px; border-radius: 6px; background: var(--water); opacity: 0.22; }
.t-crack::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(35deg, transparent 47%, var(--water-deep) 48% 53%, transparent 54%),
    linear-gradient(-50deg, transparent 47%, var(--water-deep) 48% 53%, transparent 54%),
    linear-gradient(95deg, transparent 47%, var(--water-deep) 48% 52%, transparent 53%);
}
.t-snow { background: radial-gradient(circle at 35% 45%, var(--snow) 0 30%, transparent 32%), radial-gradient(circle at 65% 45%, var(--snow) 0 30%, transparent 32%), radial-gradient(circle at 50% 65%, var(--snow) 0 34%, transparent 36%), linear-gradient(135deg, var(--snow-shade), var(--ice-2)); }
.t-water { background: repeating-linear-gradient(170deg, var(--water) 0 7px, var(--water-deep) 7px 12px); }
.t-fish { background: center / 26px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 20'%3E%3Cpath d='M8 10 1 3v14z' fill='%23ff7a52'/%3E%3Cellipse cx='16' cy='10' rx='12' ry='7' fill='%23ff7a52'/%3E%3Cellipse cx='17' cy='12.5' rx='8' ry='2.6' fill='%23ffc79e'/%3E%3Ccircle cx='23' cy='8.5' r='1.6' fill='%23222'/%3E%3C/svg%3E"), linear-gradient(135deg, var(--ice), var(--ice-2)); }
.rule-note { margin: 0 0 10px; line-height: 1.45; font-size: 0.95rem; }
.keys { margin: 4px 0 16px; font-size: 0.85rem; color: var(--muted); }
/* Touch screens get swipe and tap; a mouse and keyboard get the keys. */
.keys-touch { display: none; }
@media (pointer: coarse) {
  .keys-touch { display: block; }
  .keys-mouse { display: none; }
}
/* The help's button stays in view while the rules scroll on short screens. */
#dlgHelp > .btn.primary { position: sticky; bottom: 0; box-shadow: 0 0 0 8px var(--panel-solid); }

/* results */
.kicker { color: var(--cool); }
.res-stars { display: flex; gap: 2px; font-size: 1.45rem; margin: -4px 0 12px; }
.res-stars span { color: var(--gold-dim); }
.res-stars span.on { color: var(--gold); }
.res-ponds { list-style: none; margin: 0 0 10px; padding: 0; border-top: 1px solid var(--line); }
.res-ponds li { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 4px 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.rp-name { font-weight: 800; }
.rp-name small { display: block; font-weight: 600; font-size: 0.78rem; color: var(--muted); }
.rp-moves { font-family: var(--display); font-weight: 600; font-variant-numeric: tabular-nums; }
.rp-moves span { color: var(--muted); font-weight: 500; }
.rp-stars { color: var(--gold); letter-spacing: 0.04em; min-width: 3.4em; text-align: right; }
.rp-stars .off { color: var(--gold-dim); }
.rp-watch { grid-column: 1 / -1; justify-self: start; margin-top: -4px; }
.res-total { margin: 0 0 14px; font-weight: 700; color: var(--muted); }
.res-total b { color: var(--ink); }
.res-actions .btn { flex: 1; }
.section-h { margin: 20px 0 10px; font-size: 0.76rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.wd.done i { border: 0; background: rgba(127, 170, 200, 0.2); }
.wd.perfect i { border: 0; background: var(--gold); color: #3a2600; }
.wd.today i { border-style: solid; border-color: var(--cool); }
.countdown b { font-family: var(--display); font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.progress-note { margin: 0 0 6px; font-weight: 700; }

.toast { z-index: 10; }

@media (max-width: 420px) {
  .logo { font-size: 1.8rem; }
  .icon-btn { width: 36px; height: 36px; border-radius: 11px; }
  .counts { gap: 10px; }
  .count b { font-size: 1.35rem; }
  .fish-left i { width: 24px; height: 16px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  /* A compact cleared card, so most of the board stays visible on a phone. */
  .cleared { bottom: 10px; padding: 10px 12px 12px; border-radius: 16px; }
  .cl-stars { font-size: 1.5rem; }
  .cl-line { margin-bottom: 8px; }
  .cl-actions .btn { flex: 1 1 auto; padding: 0 10px; font-size: 0.92rem; }
}
/* the same for the site-wide Reduce motion setting (hub/prefs.js) */

/* Stars: an amber edge keeps a gold star visible on the light page (3:1), and unearned stars are
   hollow, so earned and unearned differ by shape as well as colour. */
.meter i, .tab-s .st, .cl-stars span.on, .res-stars span.on, .rp-stars { -webkit-text-stroke: 1px var(--star-edge); }
.meter i.off, .tab-s .st.off, .cl-stars span:not(.on), .res-stars span:not(.on), .rp-stars .off { color: transparent; -webkit-text-stroke: 1px var(--muted); }

/* Landscape phones and other short screens: the board fills the left at full height, and the
   header, ponds, status, controls and hint stack on the right. layout() in game.js sizes the
   board from the height alone here. */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    max-width: 960px; display: grid; column-gap: 20px; row-gap: 8px; align-content: start;
    grid-template-columns: minmax(0, calc(100vh - 24px)) minmax(240px, 1fr);
    grid-template-rows: repeat(6, auto) 1fr;
    grid-template-areas: "stage top" "stage banner" "stage tabs" "stage hud" "stage controls" "stage how" "stage .";
  }
  .app > .top { grid-area: top; }
  .app > .banner { grid-area: banner; }
  .app > .ponds { grid-area: tabs; }
  .app > .hud { grid-area: hud; }
  .app > .stage { grid-area: stage; align-self: start; }
  .app > .controls { grid-area: controls; }
  .app > .how { grid-area: how; }
}

/* The weekend special on the results. */
.res-special { margin: 10px 0 4px; padding: 12px 14px; border-radius: 14px; border: 1px dashed var(--line, rgba(0, 0, 0, 0.15)); text-align: center; }
.res-special p { margin: 0 0 10px; font-size: 0.92rem; }
.res-special-rows { margin-top: 8px; }
