/* The shared chrome (top bar, buttons, dialogs, stats grid, week strip, toast) is in
   hub/game.css, linked before this file. This sets the tokens it uses, the base shapes the game
   chooses for itself, and the board. */
:root {
  color-scheme: light dark;
  --bg: #fbf4ec;
  --bg-2: #f3e7d9;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-solid: #fffaf4;
  --ink: #2a1d16;
  --muted: #6f5d52;
  --line: rgba(42, 29, 22, 0.13);
  --accent: #c4572e; /* white button text on it is 4.6:1 */
  --accent-deep: #a3431f;
  --accent-ink: #ffffff;
  --good: #2b9a60;
  --bad: #c93a32;
  --shadow: rgba(90, 45, 20, 0.18);
  --gold: #e0a019;
  --gold-dim: rgba(42, 29, 22, 0.15);
  --edge: rgba(42, 29, 22, 0.72);
  --wall: #2a1d16;
  --pending: rgba(42, 29, 22, 0.08); /* a slice that isn't right yet */
  --pending-act: rgba(196, 87, 46, 0.26); /* the one being painted */
  /* a right slice's colour, by its id: no oranges, so none looks like the slice being painted */
  --s0: #bfe3c0; --s1: #c7d7f5; --s2: #f5e0a0; --s3: #e3c8f0; --s4: #a9e0dc;
  --s5: #f5bfcf; --s6: #d9e6a6; --s7: #dccfc1; --s8: #b9c3f0;
  --display: Fredoka, 'Arial Rounded MT Bold', system-ui, sans-serif;
  --text: Nunito, system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1613;
    --bg-2: #221b17;
    --panel: rgba(48, 38, 32, 0.75);
    --panel-solid: #2b221d;
    --ink: #f5ebe2;
    --muted: #bfae9f;
    --line: rgba(245, 235, 226, 0.13);
    --accent: #f0875c;
    --accent-deep: #d26b40;
    --accent-ink: #2a1206;
    --good: #5bd394;
    --bad: #ff7a72;
    --shadow: rgba(0, 0, 0, 0.45);
    --gold: #f6c945;
    --gold-dim: rgba(245, 235, 226, 0.17);
    --edge: rgba(245, 235, 226, 0.75);
    --wall: #fff4ea;
    --pending: rgba(245, 235, 226, 0.09);
    --pending-act: rgba(240, 135, 92, 0.3);
    --s0: #3f6b47; --s1: #3d5384; --s2: #7a6630; --s3: #644480; --s4: #2f6b66;
    --s5: #7d3f52; --s6: #5c6b2c; --s7: #5e5146; --s8: #4a4f8a;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font: 600 16px/1.4 var(--text);
  -webkit-font-smoothing: antialiased;
  background: linear-gradient(180deg, var(--bg), var(--bg-2)) fixed;
}
button { -webkit-tap-highlight-color: transparent; }

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

/* ---------------------------------------------------------------- header */
.logo { margin: 0; font: 700 2.1rem/1 var(--display); color: var(--accent-deep); }
@media (prefers-color-scheme: dark) { .logo { color: var(--accent); } }
.day { margin: 4px 0 0; font-size: 0.78rem; color: var(--muted); }

/* ---------------------------------------------------------------- the board */
.play { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.goalbar { width: 100%; max-width: 440px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.goal { margin: 0; font-size: 0.98rem; color: var(--muted); }
.goal b { color: var(--ink); font: 700 1.15rem/1 var(--display); }
.clock { margin: 0; font: 600 1.15rem/1 var(--display); font-variant-numeric: tabular-nums; }
.stage { position: relative; width: 100%; max-width: 440px; }
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 1px;
  width: min(100%, 62vh, 440px);
  margin: 0 auto;
  aspect-ratio: 1;
  padding: 0;
  border: 3px solid var(--edge);
  border-radius: 14px;
  overflow: hidden;
  background: var(--line);
  container-type: inline-size;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  cursor: pointer;
}
.board:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
.cell {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--panel-solid);
  /* thick edges where a slice meets anything else, set per side by game.js */
  box-shadow:
    inset 0 var(--et, 0px) 0 0 var(--edge),
    inset calc(var(--er, 0px) * -1) 0 0 0 var(--edge),
    inset 0 calc(var(--eb, 0px) * -1) 0 0 var(--edge),
    inset var(--el, 0px) 0 0 0 var(--edge);
  transition: background 0.15s;
}
.cell.cut { background: linear-gradient(var(--pending), var(--pending)), var(--panel-solid); }
.cell.act { background: linear-gradient(var(--pending-act), var(--pending-act)), var(--panel-solid); }
.cell.right { background: var(--fill); }
.dg { font: 600 calc(100cqi / var(--n) * 0.44) / 1 var(--display); font-variant-numeric: tabular-nums; }
.cell.right .dg { font-weight: 700; }
.badge {
  position: absolute;
  top: 3px;
  left: 5px;
  font: 800 calc(100cqi / var(--n) * 0.2) / 1 var(--text);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.badge.over { color: var(--bad); }
.cell.right .badge { color: var(--ink); }
.board:focus-visible .cell.cur { outline: 3px dashed var(--accent); outline-offset: -6px; }
.walls { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.walls path { stroke: var(--wall); stroke-width: 0.1; stroke-linecap: round; fill: none; }
.board.won { animation: won 0.6s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes won { 40% { transform: scale(1.03); } }
.reduce-motion .board.won { animation: none; }
@media (prefers-reduced-motion: reduce) { .board.won { animation: none; } }

.status { margin: 0; min-height: 2.8em; max-width: 440px; text-align: center; color: var(--muted); font-size: 0.92rem; }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* the curtain over an unstarted or paused board */
.stage.veiled .board { filter: blur(10px) saturate(0.6); opacity: 0.55; pointer-events: none; }
.curtain {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(88%, 330px);
  padding: 20px 20px 22px;
  border-radius: 22px;
  text-align: center;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px var(--shadow);
  animation: rise 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
  z-index: 5;
}
.curtain[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, calc(-50% + 16px)) scale(0.96); } }
.reduce-motion .curtain { animation: none; }
@media (prefers-reduced-motion: reduce) { .curtain { animation: none; } }
.cu-kicker { margin: 0; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent-deep); }
@media (prefers-color-scheme: dark) { .cu-kicker { color: var(--accent); } }
.cu-title { margin: 4px 0 6px; font: 700 1.9rem/1.05 var(--display); }
.cu-line { margin: 0 0 16px; color: var(--muted); line-height: 1.4; font-size: 0.95rem; }
.curtain .btn { min-width: 150px; }

/* ---------------------------------------------------------------- buttons */
.btn.wide { margin-top: 16px; }

/* ---------------------------------------------------------------- dialogs and results */
.rules { margin: 0 0 12px; padding-left: 20px; }
.rules li { margin: 0 0 6px; }
.kicker { color: var(--muted); }
.res-line { margin: 0 0 12px; font-size: 1rem; color: var(--muted); }
.res-hero { display: flex; align-items: baseline; gap: 14px; margin: -2px 0 6px; }
.res-time { font-weight: 800; font-size: 2.6rem; line-height: 1; font-variant-numeric: tabular-nums; }
.res-stars { display: flex; gap: 2px; font-size: 1.6rem; }
.res-stars span { color: var(--gold-dim); }
.res-stars span.on { color: var(--gold); }
.section-h { margin: 18px 0 10px; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.wd.today i { outline: 2px dashed var(--accent); outline-offset: -2px; }
.wd.won i { background: var(--good); color: #fff; font-size: 0.62rem; }

.toast { z-index: 10; }

@media (max-width: 380px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
