/* 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 and the game's own look:
   ink on paper, with the player's digits in pen blue. */
:root {
  color-scheme: light dark;
  --bg: #f3f1ea;
  --bg-2: #e7e3d8;
  --panel: rgba(255, 253, 248, 0.8);
  --panel-solid: #fffdf8;
  --ink: #1c2233;
  --muted: #636a7c;
  --line: rgba(28, 34, 51, 0.12);
  --accent: #2f3a6e; /* white button text on it is 10.6:1 */
  --accent-deep: #1f2750;
  --accent-ink: #ffffff;
  --pen: #2f55c8;
  --gold: #e0a019;
  --gold-dim: rgba(28, 34, 51, 0.15);
  --bad: #d23c45;
  --bad-soft: rgba(210, 60, 69, 0.16);
  --dim: rgba(243, 241, 234, 0.66);
  --display: Fraunces, Georgia, 'Times New Roman', serif;
  --display-weight: 800; /* the weight hub/game.css gives display text */
  --text: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* the grid */
  --edge: #1c2233;
  --grid: #b9bcc8;
  --cell: #fffdf8;
  --cell-peer: #eceef6;
  --cell-same: #cfd9fb;
  --cell-sel: #ffe08a;
  --note: #6a7186;
  --shadow: rgba(40, 44, 80, 0.2);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --bg-2: #181b26;
    --panel: rgba(34, 38, 54, 0.75);
    --panel-solid: #1e2231;
    --ink: #eceef6;
    --muted: #9aa1b5;
    --line: rgba(236, 238, 246, 0.11);
    --accent: #9fb0ff;
    --accent-deep: #7388ee;
    --accent-ink: #0d1230;
    --pen: #9db8ff;
    --gold: #f6c945;
    --gold-dim: rgba(236, 238, 246, 0.17);
    --bad: #ff6b74;
    --bad-soft: rgba(255, 107, 116, 0.2);
    --dim: rgba(18, 20, 28, 0.64);
    --edge: #8189a3;
    --grid: #3a4058;
    --cell: #1e2231;
    --cell-peer: #272c40;
    --cell-same: #37427a;
    --cell-sel: #6a5516;
    --note: #9aa1b5;
    --shadow: rgba(0, 0, 0, 0.5);
  }
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--text);
  -webkit-font-smoothing: antialiased;
  background: linear-gradient(180deg, var(--bg), var(--bg-2)) fixed;
}
.app {
  width: 100%;
  max-width: 600px;
  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: 10px;
}

/* ---------------------------------------------------------------- header */
.logo { margin: 0; font-family: var(--display); font-weight: 800; font-size: 2.1rem; line-height: 1; letter-spacing: -0.01em; }
.logo span { color: var(--pen); }
.day { margin: 4px 0 0; font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }

/* ---------------------------------------------------------------- HUD */
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 42px; }
.hud-day { display: flex; flex-direction: column; line-height: 1.15; }
.hud-day b { font-family: var(--display); font-weight: 800; font-size: 1.2rem; }
.hud-day span { font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
.counts { display: flex; align-items: center; gap: 16px; }
.count { display: flex; flex-direction: column; align-items: flex-end; line-height: 1; }
.count b { font-family: var(--text); font-weight: 800; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.count small { font-size: 0.66rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-top: 3px; }
#timer { min-width: 3.1em; text-align: right; transition: color 0.4s ease; }
#timer.over { color: var(--muted); }

/* ---------------------------------------------------------------- board */
.stage { position: relative; display: flex; justify-content: center; }
.board {
  --size: 340px;
  position: relative;
  width: var(--size);
  height: var(--size);
  padding: 3px;
  border-radius: 10px;
  background: var(--edge);
  box-shadow: 0 10px 24px var(--shadow);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  transition: filter 0.35s ease, opacity 0.35s ease;
}
.board:focus-visible { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--pen); }
.cells {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 1px;
  background: var(--grid);
  border-radius: 7px;
  overflow: hidden;
  cursor: pointer;
}
.row { display: contents; }
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background: var(--cell);
  color: var(--pen);
  font: 700 calc(var(--size) * 0.064) / 1 var(--text);
  font-variant-numeric: tabular-nums;
}
.cell.gv { color: var(--ink); font-weight: 800; }
.cell .v { font-weight: inherit; }
/* The lines between the 3×3 boxes, drawn over the hairlines between squares. */
.boxes { position: absolute; inset: 3px; pointer-events: none; }
.boxes i { position: absolute; background: var(--edge); }
.boxes i:nth-child(-n + 2) { top: 0; bottom: 0; width: 3px; margin-left: -1.5px; }
.boxes i:nth-child(n + 3) { left: 0; right: 0; height: 3px; margin-top: -1.5px; }
.boxes i:nth-child(1) { left: 33.333%; }
.boxes i:nth-child(2) { left: 66.667%; }
.boxes i:nth-child(3) { top: 33.333%; }
.boxes i:nth-child(4) { top: 66.667%; }

/* pencil notes: a 3×3 of small digits, shown only in an empty square */
.nt {
  position: absolute;
  inset: 6%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  font: 700 calc(var(--size) * 0.027) / 1 var(--text);
  color: var(--note);
}
.nt i { font-style: normal; visibility: hidden; }
.nt i.on { visibility: visible; }
.nt i.hi { color: var(--pen); font-weight: 800; }

/* the selected square, its row, column and box, and its digit wherever else it is */
.cell.peer { background: var(--cell-peer); }
.cell.same { background: var(--cell-same); }
.cell.sel { background: var(--cell-sel); }
.cell .v:not(:empty) { animation: inkin 0.18s cubic-bezier(0.2, 1.6, 0.4, 1); }
.cell.gv .v { animation: none; }
@keyframes inkin { from { transform: scale(0.5); opacity: 0; } }

/* clashes, hints */
.cell.bad { color: var(--bad); background-image: linear-gradient(var(--bad-soft), var(--bad-soft)); }
.cell.bad .v { animation: shake 0.45s ease both; }
@keyframes shake { 20% { transform: translateX(-8%); } 45% { transform: translateX(7%); } 70% { transform: translateX(-4%); } }
.cell::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.board.spot .cell:not(.hl):not(.tgt)::after { background: var(--dim); animation: dimin 0.35s ease both; }
@keyframes dimin { from { opacity: 0; } }
.cell.pat::after { box-shadow: inset 0 0 0 2px var(--gold); }
.cell.tgt::after { box-shadow: inset 0 0 0 3px var(--pen); animation: ring 0.9s ease-in-out 3; }
@keyframes ring { 50% { box-shadow: inset 0 0 0 5px var(--pen); } }
.board.kbd .cell.sel { outline: 3px solid var(--pen); outline-offset: -3px; z-index: 1; }

/* the win */
.board.won .cells { cursor: default; }
.board.won .cell .v { animation: digitwin 0.6s cubic-bezier(0.2, 1.5, 0.35, 1) var(--w, 0ms) both; }
@keyframes digitwin { 0% { transform: none; } 40% { transform: translateY(-18%) scale(1.15); color: var(--gold); } 100% { transform: none; } }
.board.shine::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 240, 0.6) 50%, transparent 65%) no-repeat;
  background-size: 300% 100%;
  animation: sheen 1.4s ease-in-out 0.25s both;
  mix-blend-mode: soft-light;
}
@keyframes sheen { from { background-position: 120% 0; } to { background-position: -20% 0; } }

/* the curtain over an unstarted or paused grid */
.stage.veiled .board { filter: blur(12px) 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); } }
.cu-kicker { margin: 0; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--pen); }
.cu-title { margin: 4px 0 6px; font-family: var(--display); font-weight: 800; font-size: 2rem; line-height: 1.05; }
.cu-line { margin: 0 0 16px; font-weight: 600; color: var(--muted); line-height: 1.4; font-size: 0.95rem; }
.curtain .btn { min-width: 150px; }

/* ---------------------------------------------------------------- hints, digit pad, buttons */
.hintbar {
  margin: 0;
  min-height: 2.9em;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--muted);
  border-radius: 14px;
  text-wrap: balance;
  transition: background 0.25s ease, color 0.25s ease;
}
.hintbar.on { display: block; text-align: left; color: var(--ink); background: var(--panel); border: 1px solid var(--line); animation: hintin 0.3s ease; }
.hintbar b { color: var(--pen); }
@keyframes hintin { from { opacity: 0; transform: translateY(-4px); } }

.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; }
.key {
  appearance: none;
  min-width: 0;
  height: 54px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  color: var(--pen);
  transition: transform 0.12s ease, background 0.12s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.key b { font: 800 1.45rem/1 var(--text); }
.key small { font: 700 0.66rem/1 var(--text); color: var(--muted); font-variant-numeric: tabular-nums; }
.key:not(:disabled):active { transform: scale(0.93); }
.key:disabled { opacity: 0.45; cursor: default; }
.key.full { opacity: 0.38; }
/* notes mode: the pad's digits shrink to pencil size */
.pad.pencil .key { border-style: dashed; border-color: var(--pen); }
.pad.pencil .key b { font-size: 1.05rem; color: var(--note); }

.controls { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.btn { position: relative; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.btn.icon { width: 44px; padding: 0; }
.badge {
  min-width: 20px; height: 20px;
  padding: 0 5px;
  display: inline-grid; place-items: center;
  border-radius: 99px;
  background: var(--pen);
  color: var(--panel-solid);
  font-size: 0.72rem;
  font-weight: 800;
}
.badge[hidden] { display: none; }
.toggle .sw {
  position: relative;
  width: 30px; height: 18px;
  border-radius: 99px;
  background: var(--gold-dim);
  transition: background 0.2s ease;
}
.toggle .sw::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--panel-solid);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.toggle[aria-pressed='true'] .sw { background: var(--pen); }
.toggle[aria-pressed='true'] .sw::after { transform: translateX(12px); }

/* ---------------------------------------------------------------- dialogs */
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } }
.help-grid { display: grid; grid-template-columns: 112px 1fr; gap: 14px; align-items: center; }
.example {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  aspect-ratio: 1;
  padding: 3px;
  border-radius: 8px;
  background: var(--edge);
  box-shadow: 0 4px 10px var(--shadow);
}
.example i { display: grid; place-items: center; background: var(--cell); font: 800 1.15rem/1 var(--text); font-style: normal; color: var(--ink); }
.example i.pen { background: var(--cell-sel); color: var(--pen); }
.example i:first-child { border-top-left-radius: 5px; }
.example i:nth-child(3) { border-top-right-radius: 5px; }
.example i:nth-child(7) { border-bottom-left-radius: 5px; }
.example i:last-child { border-bottom-right-radius: 5px; }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rules li { line-height: 1.4; font-size: 0.93rem; padding-left: 18px; position: relative; }
.rules li::before { content: ''; position: absolute; left: 0; top: 0.45em; width: 9px; height: 9px; border-radius: 3px; background: var(--pen); }
.how-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.how-list li { display: flex; gap: 12px; align-items: center; line-height: 1.4; font-size: 0.93rem; }
.mini {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--cell-sel);
  box-shadow: inset 0 0 0 2px var(--edge);
  font: 800 1.2rem/1 var(--text);
  color: var(--pen);
}
.mini.notes { grid-template-columns: repeat(3, 1fr); padding: 5px; background: var(--cell); font-size: 0.62rem; color: var(--note); }
.mini.notes i { font-style: normal; }
.mini.hint { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.rule-note { margin: 0 0 10px; line-height: 1.45; font-size: 0.92rem; }
.keys { margin: 4px 0 16px; font-size: 0.82rem; color: var(--muted); line-height: 1.9; }
/* results */
.kicker { color: var(--pen); }
.res-hero { display: flex; align-items: baseline; gap: 14px; margin: -2px 0 6px; }
.res-time { font-family: var(--text); 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); animation: star 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.res-stars span.d0 { animation-delay: 200ms; }
.res-stars span.d1 { animation-delay: 360ms; }
.res-stars span.d2 { animation-delay: 520ms; }
@keyframes star { from { transform: scale(0) rotate(-40deg); } }
.res-line { margin: 0 0 4px; font-weight: 700; color: var(--muted); font-size: 0.9rem; }
.res-actions .btn { flex: 1; }
.section-h { margin: 18px 0 10px; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.wd.done i { border: 0; background: var(--gold-dim); color: var(--ink); }
.wd.clean i { border: 0; background: var(--accent); color: var(--accent-ink); }
.wd.today i { outline: 2px solid var(--pen); outline-offset: -2px; color: var(--ink); }
.legend { display: flex; gap: 6px; align-items: center; justify-content: center; margin: 10px 0 0; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.lg { width: 12px; height: 12px; border-radius: 4px; display: inline-block; margin-left: 8px; }
.lg.clean { background: var(--accent); }
.lg.done { background: var(--gold-dim); }
.countdown b { font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.countdown a { color: inherit; font-weight: 700; }
.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: 12px; }
  .count b { font-size: 1.25rem; }
  .hud-day b { font-size: 1.05rem; }
  .pad { gap: 4px; }
  .key { height: 50px; border-radius: 10px; }
  .key b { font-size: 1.3rem; }
  .controls { gap: 6px; }
  .controls .btn { padding: 0 12px; font-size: 0.9rem; gap: 5px; }
  .controls .btn.icon { width: 44px; padding: 0; }
  .controls .btn svg { width: 16px; height: 16px; }
  .toggle .sw { width: 26px; height: 16px; }
  .toggle .sw::after { width: 12px; height: 12px; }
  .toggle[aria-pressed='true'] .sw::after { transform: translateX(10px); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .help-grid { grid-template-columns: 92px 1fr; gap: 12px; }
  .hintbar { font-size: 0.84rem; }
}
@media (max-width: 380px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .controls { gap: 5px; }
  .controls .btn { padding: 0 9px; gap: 4px; font-size: 0.86rem; }
  .controls .btn.icon { width: 42px; padding: 0; }
  .badge { min-width: 18px; height: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-delay: 0ms !important; }
}
/* the same for the site-wide Reduce motion setting (hub/prefs.js) */
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { animation-delay: 0ms !important; }

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