/* ============================================================
   Words on Demand — 10-foot TV UI
   Design rules from the strategy doc:
   - Large, high-contrast focus states visible across a room
   - Everything reachable by 4-way D-pad + OK
   - No fine text, no pointer-dependent controls
   ============================================================ */

:root {
  --bg: #0f1220;
  --bg-2: #171b2e;
  --panel: #1e2338;
  --text: #f4f6ff;
  --muted: #9aa3c7;
  --accent: #5b8cff;
  --accent-2: #7a5bff;

  --correct: #4caf7d;
  --present: #d8a53a;
  --absent: #3a4060;

  --focus-ring: #ffd34d;
  --del: #c65b5b;

  /* 10-foot scale: sizes are deliberately large, but clamp to viewport height so
     the board + keyboard + hint always fit. On a full-screen 16:9 TV the height is
     the binding dimension, so grow tiles off vh to fill the vertical space; the
     floor keeps laptop/browser windows (short viewports) looking as before. */
  --tile: clamp(2.6rem, 7.2vh, 5.4rem);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 18px; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 50% -10%, var(--bg-2), var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- screen switching ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4vh 6vw;
}
.screen.is-active { display: flex; }

/* ---------- shared buttons ---------- */
.btn {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  border: 3px solid transparent;
  border-radius: var(--radius);
  padding: 1.1rem 2.4rem;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.btn-ghost { background: transparent; border: 3px solid var(--absent); }
/* A focusable-but-inert button (e.g. the hint once it's spent for the row or
   only one letter remains). Dimmed; still shows the focus ring so the D-pad
   never gets stranded, but a press is a no-op in JS. */
.btn.is-disabled { opacity: .4; }

/* THE focus state — the single most important 10-foot affordance */
.focusable.is-focused {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 6px rgba(255, 211, 77, .35), 0 12px 30px rgba(0,0,0,.4);
  transform: scale(1.06);
  background: var(--bg-2);
}
.btn-primary.focusable.is-focused {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

/* ============================ HOME ============================ */
.home-inner { text-align: center; max-width: 900px; }
.logo {
  font-size: 5.5rem;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1;
}
.logo span { color: var(--accent); }
.tagline { font-size: 1.6rem; color: var(--muted); margin-top: .6rem; }

.stats-row {
  display: flex;
  justify-content: center;
  gap: 3.5rem;
  margin: 3rem 0;
}
.stat { display: flex; flex-direction: column; }
.stat-num { font-size: 3rem; font-weight: 800; }
.stat-label { font-size: 1.1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.home-actions { display: flex; flex-direction: column; gap: 1.4rem; align-items: center; }
.home-actions .btn { min-width: 26rem; }
.daily-note { margin-top: 2rem; color: var(--muted); font-size: 1.1rem; }

/* ============================ GAME ============================ */
/* The header is fixed at the top, so the game screen lays content out from the
   top with padding that clears the header — otherwise the centered board slides
   up under the "Puzzle #…" title. */
#game {
  justify-content: flex-start;
  padding-top: clamp(4rem, 7vh, 8vh);
  gap: clamp(.6rem, 1.5vh, 1.4rem);
}
.game-header {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 2vh 5vw;
  z-index: 10;
}
.header-title { font-size: 1.6rem; font-weight: 700; }
/* Flame + count on top, a "Day Streak" caption underneath (mirrors the
   home-screen stat) so the flame's meaning is spelled out. */
.header-streak { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.header-streak[hidden] { display: none; }
.streak-top { display: flex; align-items: center; gap: .4rem; font-size: 1.6rem; font-weight: 700; }
.streak-label {
  font-size: .85rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}
.icon-btn {
  font-size: 1.3rem; font-weight: 600; color: var(--text);
  background: transparent; border: 3px solid transparent; border-radius: 10px;
  padding: .5rem 1rem; cursor: pointer;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile));
  gap: .6rem;
}

/* Color legend — explains tile colors at a glance (visible from the couch). */
.legend {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 1.5rem;
}
.legend-item {
  display: flex; align-items: center; gap: .5rem;
  font-size: 1.1rem; color: var(--muted);
}
.legend-item .swatch { width: 1.3rem; height: 1.3rem; border-radius: 4px; }
.board-row { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: .6rem; }
.tile {
  width: var(--tile); height: var(--tile);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(2.6rem, 4vh, 3.4rem); font-weight: 800; text-transform: uppercase;
  border: 3px solid var(--absent);
  border-radius: 10px;
  background: var(--bg-2);
  transition: transform .15s ease, background .3s ease, border-color .3s ease;
}
.tile.filled { border-color: var(--muted); transform: scale(1.04); }
.tile.correct { background: var(--correct); border-color: var(--correct); }
.tile.present { background: var(--present); border-color: var(--present); }
.tile.absent  { background: var(--absent);  border-color: var(--absent); }

/* Carried-down known-correct letter: shown green but dimmed so it reads as
   "already locked in, not something you just typed". */
.tile.locked {
  background: var(--correct); border-color: var(--correct);
  opacity: .8;
}
/* Where the next typed letter will land — a soft pulse so the eye finds it
   across a room without a hard blinking caret. */
.tile.cursor {
  border-color: var(--focus-ring);
  box-shadow: inset 0 0 0 3px rgba(255, 211, 77, .45);
  animation: cursor-pulse 1.1s ease-in-out infinite;
}
@keyframes cursor-pulse {
  0%, 100% { box-shadow: inset 0 0 0 3px rgba(255, 211, 77, .25); }
  50%      { box-shadow: inset 0 0 0 3px rgba(255, 211, 77, .65); }
}

/* ---------- keyboard ---------- */
.keyboard { display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.kb-row { display: flex; gap: .5rem; }
.key {
  /* Width grows with the viewport so the 10-key top row fills the screen instead
     of leaving big side gutters on a wide TV; the floor keeps narrow windows tidy. */
  min-width: clamp(3.4rem, 6.2vw, 6rem); height: clamp(2.8rem, 6vh, 4.2rem);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(1.4rem, 2vw, 2rem); font-weight: 700; text-transform: uppercase;
  background: var(--panel); color: var(--text);
  border: 3px solid transparent; border-radius: 10px;
  cursor: pointer;
}
.key.key-wide { min-width: clamp(6rem, 9vw, 9rem); font-size: 1.1rem; }
/* ENTER shows the remote's Play/pause glyph (⏯) — pressing the physical
   Play/pause button submits the guess. Accented as the primary action. */
.key.key-enter { background: var(--accent); }
/* DEL shows the remote's Rewind glyph (⏪) — its own warm-red so it reads as
   "remove/erase", distinct from the blue ENTER and the neutral letter keys. */
.key.key-del { background: var(--del); }
/* ENTER/DEL stack a remote glyph over a word caption ("Enter" / "Erase") so the
   action is unmistakable at 10 feet. flex-column centers the two lines. */
.key.key-enter, .key.key-del { flex-direction: column; gap: .1rem; line-height: 1; }
.key-glyph { font-size: 1.4rem; }
.key-caption { font-size: .8rem; font-weight: 600; letter-spacing: .04em; text-transform: none; }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent  { background: var(--absent); opacity: .55; }

.hint-bar { margin: 0; }
/* The hint is a real, tappable control — give it a solid filled surface and a
   clear border so it reads as a button (the old transparent ghost style looked
   like plain text). The "Watch Ad" pill spells out the cost up front. */
.btn.btn-hint {
  display: inline-flex; align-items: center; gap: .7rem;
  background: var(--panel);
  border: 3px solid var(--accent);
  padding: .85rem 1.6rem;
  font-size: 1.4rem;
}
.hint-icon { font-size: 1.5rem; }
.hint-badge {
  font-size: 1rem; font-weight: 700; letter-spacing: .03em;
  background: var(--accent); color: var(--bg);
  padding: .25rem .7rem; border-radius: 999px; white-space: nowrap;
}
.hint-badge[hidden] { display: none; }
/* When spent for the row / only one letter left, .is-disabled dims the whole
   button (see .btn.is-disabled); mute the badge so it doesn't stay loud. */
.btn.btn-hint.is-disabled .hint-badge { background: var(--muted); }
/* Persistent revealed-letter readout under the hint button. Sticks around until
   the next guess (unlike the transient toast) so it's readable at a glance. */
.hint-reveal {
  margin: .7rem 0 0; font-size: 1.3rem; font-weight: 700;
  color: var(--present); letter-spacing: .02em;
}
.hint-reveal[hidden] { display: none; }

/* ============================ RESULT ============================ */
.result-inner { text-align: center; max-width: 800px; }
#result-title { font-size: 3.4rem; font-weight: 800; }
.result-word { font-size: 1.8rem; color: var(--muted); margin: .5rem 0 1.5rem; }
.result-word strong { color: var(--accent); text-transform: uppercase; letter-spacing: .1em; }
.result-grid { display: inline-grid; gap: .25rem; margin: 1.5rem 0 2.5rem; }
.result-grid .mini-row { display: grid; grid-template-columns: repeat(5, 1.6rem); gap: .25rem; }
.result-grid .mini { width: 1.6rem; height: 1.6rem; border-radius: 4px; background: var(--absent); }
.result-grid .mini.correct { background: var(--correct); }
.result-grid .mini.present { background: var(--present); }

/* ============================ AD ============================ */
.ad-inner { text-align: center; width: 100%; max-width: 1000px; }
.ad-label { color: var(--muted); text-transform: uppercase; letter-spacing: .2em; font-size: 1rem; margin-bottom: 1rem; }
.ad-box {
  background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9; display: flex; flex-direction: column;
  align-items: center; justify-content: center; position: relative;
}
.ad-fake { font-size: 2rem; color: #6b7290; }
.ad-progress { position: absolute; bottom: 0; left: 0; right: 0; height: 8px; background: #222; }
.ad-progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width .1s linear; }
.ad-skip { margin-top: 1.5rem; font-size: 1.3rem; color: var(--muted); }
/* D-pad escape hatch — only shown if an ad overruns/freezes. */
#btn-ad-continue { margin-top: 1.5rem; }
#btn-ad-continue[hidden] { display: none; }

/* ============================ HOW TO ============================ */
.howto-inner { max-width: 800px; }
.howto-inner h2 { font-size: 3rem; margin-bottom: 1.5rem; }
.howto-list { list-style: none; font-size: 1.5rem; line-height: 2.4; }
.swatch { display: inline-block; width: 1.4rem; height: 1.4rem; border-radius: 4px; vertical-align: middle; margin-right: .3rem; }
.swatch.correct { background: var(--correct); }
.swatch.present { background: var(--present); }
.swatch.absent { background: var(--absent); }
.howto-inner .btn { margin-top: 2rem; }

/* ============================ HISTORY ============================ */
#history { justify-content: flex-start; padding-top: 6vh; }
.history-inner { width: 100%; max-width: 760px; display: flex; flex-direction: column; align-items: center; }
.history-inner h2 { font-size: 2.6rem; margin-bottom: .5rem; }
.history-summary { color: var(--muted); font-size: 1.2rem; margin-bottom: 1.5rem; }
.history-empty { color: var(--muted); font-size: 1.3rem; text-align: center; padding: 2rem 0; }
/* Scrollable list so a long history never pushes the Back button off-screen. */
.history-list {
  width: 100%; overflow-y: auto; max-height: 58vh;
  display: flex; flex-direction: column; gap: .8rem; margin-bottom: 1.5rem;
}
.history-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; background: var(--panel); border-radius: 12px; padding: 1rem 1.4rem;
}
.history-title { font-size: 1.4rem; font-weight: 700; }
.history-word { color: var(--accent); letter-spacing: .08em; margin-left: .4rem; }
.history-sub { color: var(--muted); font-size: 1.1rem; margin-top: .2rem; }
.history-when { color: var(--muted); font-size: .95rem; margin-top: .15rem; opacity: .8; }
.history-grid { display: inline-grid; gap: .18rem; }
.history-grid .mini-row { display: grid; grid-template-columns: repeat(5, .9rem); gap: .18rem; }
.history-grid .mini { width: .9rem; height: .9rem; border-radius: 2px; background: var(--absent); }
.history-grid .mini.correct { background: var(--correct); }
.history-grid .mini.present { background: var(--present); }

/* ---------- build badge (bottom-right version stamp) ---------- */
#build-badge {
  position: fixed; bottom: .6rem; right: .8rem;
  font-size: .85rem; color: var(--muted); opacity: .5;
  letter-spacing: .04em; pointer-events: none; z-index: 200;
  font-variant-numeric: tabular-nums;
}

/* ---------- toast (invalid word etc.) ---------- */
.toast {
  position: fixed; top: 12vh; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-weight: 700; font-size: 1.3rem;
  padding: 1rem 2rem; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease; z-index: 100;
}
.toast.show { opacity: 1; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.board-row.shake { animation: shake .4s ease; }

/* ---------- modal overlay (exit confirmation) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 8, 18, .78);
  backdrop-filter: blur(3px);
  animation: modal-fade .18s ease;
}
.modal-overlay[hidden] { display: none; }
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--panel);
  border: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 2.6rem 3rem 2.8rem;
  max-width: 46rem; text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
  animation: modal-pop .22s cubic-bezier(.2, .9, .3, 1.3);
}
@keyframes modal-pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-emoji { font-size: 4.4rem; line-height: 1; margin-bottom: .6rem; }
.modal-title { font-size: 2.2rem; font-weight: 800; margin-bottom: .6rem; }
.modal-body { font-size: 1.4rem; color: var(--muted); margin-bottom: 2rem; }
.modal-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* Destructive choice — visually distinct from the reassuring primary. */
.btn-danger { background: var(--present); color: var(--bg); }
