/* app.css — Knoxy design system.
   Direction (spec §8): "game console at night" — deep calm backdrop, the
   Fitzgerald category colors do the semantic talking, juicy tactile buttons.
   Nintendo, not clinical software. */

/* ---------- tokens ---------- */
:root {
  --bg: #1B2340;
  --surface: #273057;
  --surface-2: #313B6B;
  --text: #F5F7FF;
  --text-dim: #B8C0E0;
  --accent: #FFC53D;

  --cat-person: #F6D659;
  --cat-verb: #5DBB63;
  --cat-describe: #5B9BD5;
  --cat-noun: #F49B42;
  --cat-social: #EE7CA8;
  --cat-misc: #9AA3B2;

  --radius: 20px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  --press-ms: 80ms;

  --font-display: 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, sans-serif;
}

/* ---------- fonts (self-hosted only, Law #2) ---------- */
@font-face {
  font-family: 'Baloo 2';
  src: url('../assets/fonts/baloo2-600.woff2') format('woff2');
  font-weight: 600; font-display: swap;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('../assets/fonts/baloo2-700.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../assets/fonts/atkinson-400.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../assets/fonts/atkinson-700.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}

/* ---------- reset-ish ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* kill double-tap zoom delay */
  overflow: hidden;
}
img { -webkit-user-drag: none; }
button {
  font-family: inherit; color: inherit;
  background: none; border: none; cursor: pointer;
  touch-action: manipulation;
}
/* Focus is for caregiver keyboards; Knox uses touch. Scoped to the surfaces
   that actually respond to keyboard activation — the board's controls fire on
   pointerdown only, so a focus ring there promises a keyboard that does
   nothing, and puts a moving highlight on Knox's fixed grid. */
:focus { outline: none; }
#view-caregiver :focus-visible,
#view-games :focus-visible,
.modal :focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.view { height: 100dvh; width: 100vw; }
[hidden] { display: none !important; }

/* ---------- board layout: strip 15% / grid 75% / nav 10% (§5.1) ---------- */
#view-board {
  display: grid;
  grid-template-rows: minmax(64px, 15%) 1fr minmax(48px, 10%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  gap: 6px;
}

/* ---------- sentence strip ---------- */
#strip {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  margin: 8px 8px 0;
  /* right padding reserves a dead zone for the invisible caregiver corner —
     it must NEVER overlap the ▶/⌫ buttons (it would swallow Knox's taps) */
  padding: 6px 88px 6px 10px;
  box-shadow: var(--shadow);
}
#strip-symbols {
  flex: 1; height: 100%;
  display: flex; align-items: center; gap: 6px;
  overflow-x: auto; scrollbar-width: none;
}
#strip-symbols::-webkit-scrollbar { display: none; }
.strip-chip {
  flex: 0 0 auto;
  height: 88%;
  aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--cat) 12%, var(--surface-2));
  border: 3px solid var(--cat);
  border-radius: 12px;
  padding: 2px;
  transition: box-shadow 150ms, transform var(--press-ms), filter var(--press-ms);
}
.strip-chip img { height: 62%; width: auto; max-width: 90%; object-fit: contain; }
.strip-chip-label { font-size: clamp(9px, 1.3vw, 13px); font-weight: 700; line-height: 1; margin-top: 2px; }
.strip-chip.img-missing img { display: none; }
.strip-chip.img-missing .strip-chip-label { font-size: clamp(11px, 1.6vw, 16px); }
.strip-chip.speaking-now {
  box-shadow: 0 0 0 4px var(--accent);
  transform: scale(1.06);
}
/* Chips are tappable (they re-speak their word), so they must answer a touch
   like every other surface (Law #6). Declared AFTER .speaking-now so a press
   still reads even on the gold-ringed chip that is speaking right now. */
.strip-chip.pressed { transform: scale(0.94); filter: brightness(1.25); }

.strip-btn {
  flex: 0 0 auto;
  height: 82%; aspect-ratio: 1;
  display: grid; place-items: center;
  background: var(--surface-2);
  border-radius: 16px;
  font-size: clamp(20px, 3vw, 30px);
  box-shadow: var(--shadow);
  transition: transform var(--press-ms), filter var(--press-ms), background 300ms;
}
.strip-btn.pressed { transform: scale(0.94); filter: brightness(1.2); }
#strip-delete.holding { animation: hold-pulse 1.5s linear forwards; }
@keyframes hold-pulse {
  0% { background: var(--surface-2); }
  100% { background: #4a3a6b; transform: scale(0.9); }
}

/* the speak robot */
#strip-speak { background: var(--accent); }
#robot { width: 74%; height: 74%; }
.robot-head { fill: #1B2340; }
.robot-antenna { stroke: #1B2340; stroke-width: 3; }
.robot-antenna-tip { fill: #1B2340; }
.robot-eye { fill: var(--accent); }
.robot-mouth { fill: var(--accent); }
#strip-speak.speaking .robot-mouth { animation: talk 280ms ease-in-out infinite alternate; }
#strip-speak.speaking .robot-antenna-tip { animation: blink-tip 560ms ease-in-out infinite alternate; }
@keyframes talk {
  from { height: 3px; y: 42px; }
  to { height: 12px; y: 37px; }
}
@keyframes blink-tip { from { opacity: 1; } to { opacity: 0.4; } }

#caregiver-corner {
  position: absolute; top: 0; right: 0;
  width: 80px; height: 100%;
  /* invisible by design — a child gate, not a discoverable button.
     Lives entirely inside #strip's right padding: zero overlap with
     any control Knox uses. */
}
.strip-btn { position: relative; z-index: 1; } /* belt & suspenders vs. overlays */

/* ---------- symbol grid ---------- */
#grid {
  display: grid;
  grid-template-rows: repeat(var(--rows, 5), 1fr);
  grid-template-columns: repeat(var(--cols, 8), 1fr);
  gap: 8px;
  padding: 4px 8px;
  min-height: 0;
}
.cell { border-radius: var(--radius); min-width: 0; min-height: 0; }
.cell.empty { background: rgba(255, 255, 255, 0.025); }
.cell.symbol {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px 4px 4px;
  background: color-mix(in srgb, var(--cat) 12%, var(--surface));
  border: 6px solid var(--cat);           /* Fitzgerald key (§5.2) */
  box-shadow: var(--shadow);
  transition: transform var(--press-ms) ease-out, filter var(--press-ms) ease-out;
}
.cell.symbol.pressed { transform: scale(0.94); filter: brightness(1.25); }
.symbol-img { flex: 1; min-height: 0; width: auto; max-width: 86%; object-fit: contain; pointer-events: none; }
.symbol-label {
  font-weight: 700;
  font-size: clamp(12px, 1.8vw, 20px);
  line-height: 1.15;
  text-align: center;
  pointer-events: none;
}
.cell.symbol.img-missing .symbol-img { display: none; }
.cell.symbol.img-missing .symbol-label { font-size: clamp(16px, 2.6vw, 30px); }

/* ---------- nav ---------- */
#nav {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
  padding: 0 8px 8px;
}
.nav-btn {
  background: var(--surface);
  border-radius: 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(14px, 2vw, 22px);
  color: var(--text-dim);
  box-shadow: var(--shadow);
  transition: transform var(--press-ms), filter var(--press-ms);
}
.nav-btn.active { color: var(--text); background: var(--surface-2); }
.nav-btn.pressed { transform: scale(0.96); filter: brightness(1.2); }
/* Games tab hidden by caregiver: slot stays, button goes inert & invisible
   so nav geometry never changes (Law #1 applies to nav too). */
.nav-btn.slot-hidden { visibility: hidden; pointer-events: none; }
.nav-icon { font-size: 1.1em; }

/* ---------- rotate overlay ---------- */
#rotate-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: grid; place-items: center;
}
.rotate-card { text-align: center; font-family: var(--font-display); font-size: 26px; }
.rotate-tablet {
  width: 90px; height: 140px; margin: 0 auto 24px;
  border: 6px solid var(--accent); border-radius: 14px;
  animation: rotate-hint 2s ease-in-out infinite;
}
@keyframes rotate-hint {
  0%, 20% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(90deg); }
}

/* ---------- modals & PIN pad ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(10, 14, 32, 0.75);
  display: grid; place-items: center;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: min(560px, 92vw);
  max-height: 88dvh;
  overflow-y: auto;
}
.modal h2 { font-family: var(--font-display); margin-bottom: 12px; }
.modal p { color: var(--text-dim); margin-bottom: 12px; line-height: 1.45; }

.pinpad { text-align: center; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0 26px; }
.pin-dot {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--text-dim);
}
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }
.pin-keys {
  display: grid; grid-template-columns: repeat(3, 76px); gap: 12px;
  justify-content: center;
}
.pin-key {
  height: 76px; border-radius: 50%;
  background: var(--surface-2);
  font-size: 28px; font-weight: 700;
  transition: transform var(--press-ms), filter var(--press-ms);
}
.pin-key:active { transform: scale(0.92); filter: brightness(1.3); }
.pin-error { color: #ff9d9d; min-height: 1.4em; margin-top: 14px; }

/* ---------- caregiver mode ---------- */
#view-caregiver { overflow-y: auto; padding: 20px max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left)); }
.cg-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.cg-header h1 { font-family: var(--font-display); font-size: 28px; }
.cg-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.cg-tab {
  padding: 10px 18px; border-radius: 999px;
  background: var(--surface); color: var(--text-dim);
  font-weight: 700; font-size: 15px;
}
.cg-tab.active { background: var(--accent); color: #1B2340; }
.cg-panel { max-width: 900px; }
.cg-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.cg-card h3 { font-family: var(--font-display); margin-bottom: 8px; }
.cg-card p, .cg-card li { color: var(--text-dim); line-height: 1.5; font-size: 15px; }
.cg-card ol, .cg-card ul { padding-left: 22px; margin: 8px 0; }
.cg-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.cg-row label { min-width: 130px; font-weight: 700; }
.cg-row input[type="range"] { flex: 1; min-width: 140px; accent-color: var(--accent); }
.cg-row select, .cg-row input[type="text"], .cg-row input[type="number"] {
  flex: 1; min-width: 140px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid #3d477e; border-radius: 10px;
  padding: 10px 12px; font-size: 16px; font-family: inherit;
}
.btn {
  display: inline-block;
  background: var(--surface-2); color: var(--text);
  border-radius: 12px; padding: 12px 20px;
  font-weight: 700; font-size: 15px;
  box-shadow: var(--shadow);
  transition: transform var(--press-ms), filter var(--press-ms);
}
.btn:active { transform: scale(0.96); filter: brightness(1.2); }
.btn.primary { background: var(--accent); color: #1B2340; }
.btn.danger { background: #7c3a4d; }
.btn.small { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.switch-row input { width: 24px; height: 24px; accent-color: var(--accent); }

.banner {
  background: #4a3a1e; border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 12px; padding: 12px 16px; margin-bottom: 14px;
  font-size: 15px;
}

/* caregiver edit grid (mini board) */
.edit-grid {
  display: grid;
  grid-template-rows: repeat(var(--rows, 5), 64px);
  grid-template-columns: repeat(var(--cols, 8), 1fr);
  gap: 6px; margin: 12px 0;
}
.edit-cell {
  border-radius: 10px;
  border: 3px solid var(--cat, #3d477e);
  background: color-mix(in srgb, var(--cat, #3d477e) 12%, var(--surface-2));
  font-size: 11px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; overflow: hidden; padding: 2px;
  color: var(--text);
}
.edit-cell img { height: 55%; object-fit: contain; }
.edit-cell.hidden-sym { opacity: 0.38; }
.edit-cell.empty-sym { border-style: dashed; color: var(--text-dim); }
.edit-cell.selected { outline: 3px solid var(--accent); }

/* symbol picker */
.sym-search-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px; max-height: 300px; overflow-y: auto; margin-top: 10px;
}
.sym-pick {
  background: var(--surface-2); border-radius: 10px; padding: 6px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700;
}
.sym-pick img { width: 56px; height: 56px; object-fit: contain; }
.sym-pick.selected { outline: 3px solid var(--accent); }

/* record UI */
.rec-controls { display: flex; gap: 12px; align-items: center; margin-top: 10px; }
.rec-btn {
  width: 74px; height: 74px; border-radius: 50%;
  background: #c0392b; color: #fff;
  font-size: 26px; box-shadow: var(--shadow);
}
.rec-btn.recording { animation: rec-pulse 1s ease-in-out infinite; }
@keyframes rec-pulse { 50% { transform: scale(1.08); filter: brightness(1.25); } }

/* dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.stat {
  background: var(--surface-2); border-radius: 14px; padding: 14px; text-align: center;
}
.stat .num { font-family: var(--font-display); font-size: 30px; color: var(--accent); }
.stat .lbl { font-size: 13px; color: var(--text-dim); }
.top-words li { margin: 4px 0; color: var(--text); }

/* ---------- games ---------- */
#view-games { overflow-y: auto; background: var(--bg); }
#view-games.bg-space {
  background:
    radial-gradient(1px 1px at 12% 22%, #fff8 0 1px, transparent 2px),
    radial-gradient(1px 1px at 78% 12%, #fff7 0 1px, transparent 2px),
    radial-gradient(2px 2px at 55% 66%, #fff6 0 1px, transparent 3px),
    radial-gradient(1px 1px at 30% 82%, #fff8 0 1px, transparent 2px),
    radial-gradient(2px 2px at 90% 55%, #fff5 0 1px, transparent 3px),
    var(--bg);
}
.hub { padding: 24px max(24px, env(safe-area-inset-right)) 40px max(24px, env(safe-area-inset-left)); }
.hub-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.hub-header h1 { font-family: var(--font-display); font-size: 30px; }
.star-count {
  font-family: var(--font-display); font-size: 26px; font-weight: 700;
  background: var(--surface); border-radius: 999px; padding: 8px 20px;
  color: var(--accent); box-shadow: var(--shadow);
}
.game-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 26px; }
.game-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 22px; text-align: center;
  font-family: var(--font-display); font-size: 22px; font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform var(--press-ms), filter var(--press-ms);
}
.game-card:active { transform: scale(0.96); filter: brightness(1.2); }
.game-card .emoji { font-size: 44px; display: block; margin-bottom: 8px; }
.game-card .round-note { display: block; font-family: var(--font-body); font-size: 13px; font-weight: 400; color: var(--text-dim); margin-top: 6px; }

/* unlock level map: fixed, published, deterministic (§7.4) */
.unlock-map { display: flex; flex-direction: column; gap: 10px; }
.unlock-step {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: 14px; padding: 12px 16px;
}
.unlock-step .u-stars { font-family: var(--font-display); font-size: 18px; color: var(--accent); min-width: 64px; }
.unlock-step .u-label { font-weight: 700; }
.unlock-step.unlocked { border: 2px solid var(--accent); }
/* Dim the CARD, never the price. Group opacity composited the gold star cost
   down to ~2.6:1 — the one number Knox needs to read ("how many more?") was
   the least legible thing on the row. Pre-composited background instead, so
   the cost keeps full contrast while the row still reads as not-yet-earned. */
.unlock-step.locked { background: #222A4D; }
.unlock-step.locked .u-label { color: var(--text-dim); }
.unlock-step.locked .u-check { opacity: 0.6; }
.unlock-step .u-check { margin-left: auto; font-size: 20px; }

/* in-game shared */
.game-screen {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.game-screen.bg-space { background: radial-gradient(2px 2px at 20% 30%, #fff7 0 1px, transparent 3px), radial-gradient(1px 1px at 70% 20%, #fff8 0 1px, transparent 2px), radial-gradient(2px 2px at 45% 75%, #fff5 0 1px, transparent 3px), var(--bg); }
.game-home {
  position: absolute; top: 10px; left: 10px; z-index: 60;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--surface); font-size: 24px;
  box-shadow: var(--shadow); display: grid; place-items: center;
  transition: transform var(--press-ms), filter var(--press-ms);
}
.game-home.pressed, .game-home:active { transform: scale(0.94); filter: brightness(1.2); }
.game-progress {
  position: absolute; top: 22px; right: 16px; z-index: 60;
  display: flex; gap: 6px;
}
.game-progress .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}
.game-progress .dot.done { background: var(--accent); }

#wow-canvas { flex: 1; width: 100%; touch-action: none; }

/* Match It */
.match-target {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px;
}
/* Tappable on purpose: it re-speaks the prompt. A child who missed "Find…
   juice!" must be able to ask again without an adult (§7.2 errorless). */
.match-target .cell.symbol { width: min(24dvh, 200px); aspect-ratio: 1; position: relative; }
.match-target .cell.symbol::after {
  content: '🔊';
  position: absolute; top: 4px; right: 6px;
  font-size: clamp(14px, 2vw, 20px); opacity: 0.75;
  pointer-events: none;
}
.match-choices {
  flex: 1; display: flex; gap: 18px; align-items: center; justify-content: center;
  padding: 12px 20px 30px; min-height: 0;
}
.match-choices .cell.symbol {
  width: min(26dvh, 220px); aspect-ratio: 1; flex: 0 0 auto;
  transition: opacity 600ms, transform var(--press-ms);
}
.match-choices .cell.symbol.faded { opacity: 0; pointer-events: none; }
/* once answered, no card in the trial takes further taps (no double-counts) */
.match-choices.answered .cell.symbol { pointer-events: none; }

/* Snack Monster */
.monster-stage { display: flex; flex-direction: column; height: 100%; }
.monster-top { display: flex; align-items: center; justify-content: center; gap: 24px; padding: 8px; }
.monster-face { width: min(24dvh, 190px); height: min(24dvh, 190px); }
.monster-request { display: flex; gap: 10px; align-items: center; }
.monster-request .cell.symbol { width: min(13dvh, 110px); aspect-ratio: 1; pointer-events: none; }
.monster-request .plus { font-size: 28px; color: var(--text-dim); font-weight: 700; }
.mini-strip {
  display: flex; gap: 8px; align-items: center; justify-content: center;
  min-height: 74px; margin: 6px auto; padding: 6px 14px;
  background: var(--surface); border-radius: 14px;
  width: fit-content; min-width: 260px;
}
.mini-strip .strip-chip { height: 62px; }
.mini-board {
  display: flex; gap: 14px; align-items: center; justify-content: center;
  padding: 10px 16px 24px; flex-wrap: wrap;
}
.mini-board .cell.symbol { width: min(17dvh, 150px); aspect-ratio: 1; }
.mini-board .cell.symbol.faded { opacity: 0.25; pointer-events: none; transition: opacity 600ms; }

/* celebration overlay — one orchestrated celebration per round (§8) */
.celebrate-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: rgba(15, 20, 45, 0.85);
}
.celebrate-card { text-align: center; font-family: var(--font-display); }
.celebrate-card .big { font-size: 72px; animation: celebrate-bounce 900ms ease; }
.celebrate-card .msg { font-size: 34px; color: var(--accent); margin-top: 10px; }
.celebrate-card .star-gain { font-size: 26px; margin-top: 8px; }
@keyframes celebrate-bounce {
  0% { transform: scale(0.2); }
  55% { transform: scale(1.25); }
  75% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* toast (caregiver-only messaging) */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 12px 24px;
  box-shadow: var(--shadow); z-index: 300;
  font-weight: 700;
}

/* ---------- reduced motion: everything collapses to gentle fades ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 120ms !important;
  }
  .cell.symbol.pressed, .strip-btn.pressed, .nav-btn.pressed,
  .game-home.pressed, .game-home:active { transform: none; filter: brightness(1.35); }
  .strip-chip.speaking-now { transform: none; }
  .rotate-tablet { animation: none; transform: rotate(90deg); }
  /* hold-to-clear: a 0.01ms 'forwards' animation would instantly show the
     fully-armed clear state on every quick tap — show a calm static press
     instead (the hold still works; it just doesn't animate) */
  #strip-delete.holding { animation: none; filter: brightness(1.35); }
}
