/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #0b0f1a;
  --surface:       #141926;
  --surface2:      #1e2639;
  --border:        #2a3450;
  --accent:        #6366f1;
  --accent-h:      #818cf8;
  --electric-blue: #38bdf8;
  --green:         #22c55e;
  --red:           #ef4444;
  --amber:         #f59e0b;
  --text:          #f1f5f9;
  --muted:         #64748b;
  --radius:        12px;
  --font:          'Inter', sans-serif;
  --font-disp:     'Space Grotesk', sans-serif;
  /* avatar colours */
  --p0-color:  #6366f1;
  --p1-color:  #22c55e;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}
.hidden { display: none !important; }

/* Screen-reader only text */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Global focus-visible ring */
*:focus { outline: none; }
*:focus-visible {
  outline: 2px solid var(--accent-h);
  outline-offset: 3px;
  border-radius: 4px;
}
.word-input:focus-visible { outline: none; border-color: var(--accent); }
.submit-btn:focus-visible  { outline: 2px solid #16a34a; outline-offset: 2px; }

/* ── Shared utilities ─────────────────────────────────────────────── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dots::after {
  content: '';
  animation: dotdot 1.2s steps(3,end) infinite;
}
@keyframes dotdot {
  0%  { content: ''; }
  33% { content: '.'; }
  66% { content: '..'; }
  100%{ content: '...'; }
}

.btn-primary, .btn-ghost, .btn-copy {
  padding: 10px 22px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s, transform .1s, border-color .18s;
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-primary, .btn-copy {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover, .btn-copy:hover { background: var(--accent-h); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }
.btn-primary:active, .btn-copy:active, .btn-ghost:active { transform: scale(.96); }

.input-field {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: .9rem;
  outline: none;
  transition: border-color .2s;
}
.input-field:focus { border-color: var(--accent); }
.input-field.small { font-size: .82rem; padding: 7px 11px; }
.input-field.large {
  font-size: 1.4rem;
  text-align: center;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.room-code-display {
  font-family: var(--font-disp);
  font-size: 2rem; font-weight: 800;
  letter-spacing: 8px;
  color: var(--accent-h);
  padding: 10px 20px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
}
.link-row { display: flex; gap: 8px; width: 100%; }
.join-error { color: var(--red); font-size: .82rem; }
.join-buttons { display: flex; gap: 10px; justify-content: center; }

/* Overlays (landing page) */
.overlay {
  position: fixed; inset: 0;
  background: rgba(11,15,26,.85);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.overlay-box {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 400px; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  text-align: center;
  animation: pop .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes pop {
  from { transform: scale(.92); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.overlay-title { font-size: 1.25rem; font-weight: 700; }
.overlay-sub   { font-size: .83rem; color: var(--muted); }
.waiting-dots  { }

/* ── HOME PAGE ────────────────────────────────────────────────────── */
.home-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 20px;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(99,102,241,.2) 0%, transparent 65%),
    var(--bg);
}
.hero { width: 100%; max-width: 480px; }
.hero-inner { display: flex; flex-direction: column; align-items: center; gap: 24px; }

.logo-mark {
  display: flex; gap: 5px;
  background: transparent; border-radius: 0;
  box-shadow: none; width: auto; height: auto; padding: 0;
}
.logo-tile {
  width: 34px; height: 38px;
  background: var(--surface2);
  border: 2px solid rgba(255,255,255,.12);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-disp); font-size: 16px; font-weight: 800;
  color: var(--text); letter-spacing: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.06);
}
.logo-tile-changed {
  background: rgba(56,189,248,.12);
  border-color: var(--electric-blue);
  color: var(--electric-blue);
  box-shadow: 0 2px 16px rgba(56,189,248,.35), inset 0 1px 0 rgba(56,189,248,.1);
}
.site-title {
  font-family: var(--font-disp);
  font-size: clamp(2.6rem, 9vw, 3.8rem);
  font-weight: 800; letter-spacing: -3px; line-height: 1;
  margin-top: -6px;
}
.site-title span { color: var(--accent); }

.tagline {
  text-align: center; color: var(--muted);
  font-size: 1.02rem; line-height: 1.65;
  max-width: 320px;
}
.tagline strong { color: var(--text); font-weight: 700; }

/* ── Demo tile sequence ───────────────────────────────────────────── */
.demo-tiles-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 20px 24px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; width: 100%;
}
.demo-tile-row {
  display: flex; gap: 10px; justify-content: center;
}
.demo-tile {
  width: 64px; height: 70px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-disp); font-size: 1.75rem; font-weight: 800;
  color: var(--text);
  user-select: none;
  transition: border-color .3s, background .3s, color .3s;
}
.demo-tile.flip {
  background: rgba(56,189,248,.18);
  border-color: var(--electric-blue);
  color: var(--electric-blue);
  box-shadow: 0 0 14px rgba(56,189,248,.3);
  animation: demo-flip .5s cubic-bezier(.34,1.56,.64,1);
}
@keyframes demo-flip {
  0%   { transform: scaleY(0.05) translateY(4px); opacity: .4; }
  55%  { transform: scaleY(1.1); }
  100% { transform: scaleY(1); opacity: 1; }
}
/* trail of past words */
.demo-chain {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap; justify-content: center;
  min-height: 22px;
}
.demo-chain-word {
  font-family: var(--font-disp); font-size: .68rem; font-weight: 700;
  letter-spacing: 1.5px; color: var(--muted);
  padding: 2px 7px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 5px;
  transition: opacity .4s;
}
.demo-chain-word.active { color: var(--text); border-color: rgba(99,102,241,.4); }
.demo-chain-word.fading { opacity: 0; }
.demo-chain-arrow {
  font-size: .55rem; color: var(--border);
}

/* ── Lobby stats strip ────────────────────────────────────────────── */
.lobby-stats {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; width: 100%;
  padding: 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.lobby-stat {
  display: flex; align-items: center; gap: 7px;
}
.lobby-stat-val {
  font-family: var(--font-disp); font-size: 1rem; font-weight: 800;
  color: var(--text);
}
.lobby-stat-label {
  font-size: .68rem; color: var(--muted);
  font-weight: 600; text-transform: uppercase; letter-spacing: .8px;
}
.lobby-stat-sep {
  width: 1px; height: 22px; background: var(--border);
}
.online-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); flex-shrink: 0;
  animation: pulse-dot 2s ease infinite;
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
  50%       { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

/* ── Name input ───────────────────────────────────────────────────── */
.name-row { width: 100%; }

/* ── Action grid ──────────────────────────────────────────────────── */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px; width: 100%;
}

/* Primary card spans full width with filled accent background */
.action-card.primary {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: flex-start;
  gap: 16px;
  padding: 18px 22px;
  background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
  border-color: transparent;
  border-radius: var(--radius);
}
.action-card.primary:hover {
  background: linear-gradient(135deg, var(--accent-h) 0%, #8b5cf6 100%);
  border-color: transparent;
  transform: translateY(-2px);
}
.action-card.primary .card-label { color: #fff; font-size: 1rem; }
.action-card.primary .card-sub   { color: rgba(255,255,255,.7); }
.action-card.primary .card-icon  { font-size: 1.75rem; flex-shrink: 0; }

.action-card {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 16px 12px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .2s, transform .12s, background .2s;
  text-align: center;
}
.action-card:hover { border-color: var(--accent); background: var(--surface2); transform: translateY(-2px); }
.action-card:active { transform: scale(.97); }
.card-icon  { font-size: 1.45rem; }
.card-label { font-weight: 700; font-size: .88rem; color: var(--text); }
.card-sub   { font-size: .7rem; color: var(--muted); line-height: 1.4; }

/* ═══════════════════════════════════════════════════════════════════
   GAME PAGE
═══════════════════════════════════════════════════════════════════ */
.game-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;           /* fill exactly the viewport */
  overflow: hidden;
  background: var(--bg);
}

/* ── Top timer bar ─────────────────────────────────────────────────── */
.top-timer-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--surface2);
  z-index: 999;
}
.top-timer-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
  transition: transform .12s linear, background .4s;
}
.top-timer-fill.warning { background: var(--amber); }
.top-timer-fill.danger  { background: var(--red); box-shadow: 0 0 6px var(--red); }

/* ── Game header ───────────────────────────────────────────────────── */
.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

/* Player blocks */
.player-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.player-block.right {
  justify-content: flex-end;
}

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--p0-color);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-disp);
  font-size: 1rem; font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  border: 2px solid transparent;
  transition: border-color .3s, box-shadow .3s;
}
.avatar.p1 { background: var(--p1-color); }

/* Active player gets a glowing ring */
.player-block.active .avatar {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(255,255,255,.15);
}

.player-meta {
  min-width: 0;
  display: flex; flex-direction: column; gap: 1px;
}
.player-meta.right { text-align: right; }
.player-name {
  font-size: .8rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 90px;
}
.player-score {
  font-size: .68rem; color: var(--muted); font-weight: 600;
  letter-spacing: .5px;
}
.player-score.leading { color: var(--green); }

/* YOU badge — appears under the local player's name */
.you-badge {
  display: inline-block;
  font-size: .52rem; font-weight: 800; letter-spacing: 1.5px;
  color: var(--accent-h);
  background: rgba(99,102,241,.15);
  border: 1px solid rgba(99,102,241,.3);
  border-radius: 3px;
  padding: 1px 5px;
  text-transform: uppercase;
  margin-top: 1px;
}
.player-meta.right .you-badge { display: block; text-align: right; }

/* ── Central timer ─────────────────────────────────────────────────── */
.timer-centre {
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
}
.timer-ring-wrap {
  position: relative; width: 72px; height: 72px;
}
.timer-ring-wrap svg {
  transform: rotate(-90deg);
  width: 100%; height: 100%;
}
.ring-bg { fill: none; stroke: var(--surface2); stroke-width: 5; }
.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset .25s linear, stroke .4s;
}
.ring-fg.warning { stroke: var(--amber); }
.ring-fg.danger  { stroke: var(--red); }

/* Pulse the whole wrap in the final seconds */
@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.06); }
}
.timer-ring-wrap.urgent { animation: timer-pulse .5s ease infinite; }

.timer-num {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-disp);
  font-size: 1.4rem; font-weight: 800;
  color: var(--text);
}
.turn-badge {
  font-size: .65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted);
  transition: color .25s;
}
.turn-badge.my-turn { color: var(--accent-h); }
/* Active player name brightens too */
.player-block.active .player-name { color: var(--text); }

/* ── Connecting / Waiting states ───────────────────────────────────── */
.overlay-state {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 24px; text-align: center;
  color: var(--muted);
}
.overlay-state .room-code-display { font-size: 1.6rem; letter-spacing: 6px; }
.share-game-btn { margin-top: 8px; }

/* ── Main game area ────────────────────────────────────────────────── */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 12px;
  gap: 16px;
  overflow-y: auto;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

/* ── Word hero ─────────────────────────────────────────────────────── */
.word-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  flex: 1;
  justify-content: center;
  width: 100%;
  position: relative;
}
.word-hero-label {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  transition: color .3s;
}
.word-hero-label.my-turn {
  color: var(--electric-blue);
}

/* One-time tap hint */
.tap-hint {
  position: absolute;
  bottom: -2px;
  left: 50%; transform: translateX(-50%);
  background: rgba(56,189,248,.12);
  border: 1px solid rgba(56,189,248,.35);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: .72rem; font-weight: 600;
  color: var(--electric-blue);
  white-space: nowrap;
  pointer-events: none;
  animation: hint-in .35s ease;
}
.tap-hint.fade-out { animation: hint-out .5s ease forwards; }
@keyframes hint-in {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes hint-out {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateX(-50%) translateY(4px); }
}

/* Tiles */
.word-tiles {
  display: flex;
  gap: var(--tile-gap, 8px);
  justify-content: center;
  align-items: center;
}

.tile {
  /* JS sets --tw and --tf per render */
  width: var(--tw, 80px);
  height: calc(var(--tw, 80px) * 1.12);
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-disp);
  font-size: var(--tf, 2.2rem);
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text);
  user-select: none;
  transition: background .2s, border-color .2s, transform .15s, box-shadow .15s, color .2s;
  flex-shrink: 0;
}

/* Tappable (my turn) */
.tile.tappable {
  cursor: pointer;
}
.tile.tappable:hover {
  border-color: rgba(99,102,241,.6);
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(99,102,241,.25);
}
.tile.tappable:active { transform: scale(.93); }

/* Selected — pulsing ring */
.tile.selected {
  background: rgba(99,102,241,.18);
  border-color: var(--accent);
  color: var(--accent-h);
  transform: translateY(-4px);
  box-shadow: 0 0 0 3px rgba(99,102,241,.25), 0 6px 18px rgba(99,102,241,.3);
  animation: sel-pulse .7s ease-in-out infinite alternate;
}
@keyframes sel-pulse {
  from { box-shadow: 0 0 0 3px rgba(99,102,241,.2), 0 6px 14px rgba(99,102,241,.25); }
  to   { box-shadow: 0 0 0 5px rgba(99,102,241,.4), 0 6px 22px rgba(99,102,241,.45); }
}

/* Just-changed letter — electric blue flash, fades to normal */
@keyframes changed-flash {
  0%   { background: rgba(56,189,248,.35); border-color: var(--electric-blue); color: var(--electric-blue); transform: scale(1.14) translateY(-4px); box-shadow: 0 0 18px rgba(56,189,248,.5); }
  60%  { background: rgba(56,189,248,.12); border-color: rgba(56,189,248,.4);  color: var(--text); box-shadow: none; }
  100% { background: var(--surface2); border-color: var(--border); color: var(--text); transform: scale(1); }
}
.tile.just-changed {
  animation: changed-flash 1.4s ease forwards;
}

/* Pop when word updates */
@keyframes tile-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.14) translateY(-4px); }
  100% { transform: scale(1); }
}
.tile.pop { animation: tile-pop .28s cubic-bezier(.34,1.56,.64,1); }

/* Diff preview (small strip below input) */
.diff-strip {
  display: flex; gap: 5px; justify-content: center;
  min-height: 36px; align-items: center;
}
.diff-tile {
  width: 32px; height: 34px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-disp);
  font-size: .9rem; font-weight: 800;
  text-transform: uppercase;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
}
.diff-tile.changed {
  background: rgba(56,189,248,.15);
  border-color: var(--electric-blue);
  color: var(--electric-blue);
}

/* ── Input zone ────────────────────────────────────────────────────── */
.input-zone {
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  width: 100%;
}
.input-row {
  width: 100%; max-width: 340px;
}
.word-input {
  width: 100%;
  padding: 14px 18px;
  font-family: var(--font-disp);
  font-size: 1.4rem; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 5px;
  text-align: center;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color .2s;
}
.word-input:focus  { border-color: var(--accent); }
.word-input.valid  { border-color: var(--green); }
.word-input.invalid{ border-color: var(--red); }
.word-input:disabled {
  opacity: .22; cursor: not-allowed;
  background: var(--surface);
  border-color: var(--border);
}

.input-hint {
  font-size: .78rem;
  min-height: 18px;
  color: var(--muted);
  text-align: center;
}
.input-hint.ok    { color: var(--green); }
.input-hint.error { color: var(--red); }

.submit-btn {
  padding: 13px 36px;
  background: var(--green);
  border: none; border-radius: var(--radius);
  color: #fff;
  font-family: var(--font);
  font-size: 1rem; font-weight: 700;
  cursor: pointer;
  transition: background .18s, transform .1s, opacity .18s;
  width: 100%; max-width: 340px;
}
.submit-btn:hover:not(:disabled) { background: #16a34a; }
.submit-btn:active:not(:disabled) { transform: scale(.97); }
.submit-btn:disabled { opacity: .35; cursor: not-allowed; }

/* Thinking label */
.thinking-label {
  font-size: .82rem; color: var(--muted);
  padding: 7px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
}

/* ── History strip ─────────────────────────────────────────────────── */
.history-section {
  width: 100%;
}
.history-chain {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  padding: 4px 2px;
  scrollbar-width: none;
  justify-content: center;
  flex-wrap: wrap;
}
.history-chain::-webkit-scrollbar { display: none; }

.h-word {
  padding: 3px 9px;
  border-radius: 6px;
  font-family: var(--font-disp);
  font-size: .75rem; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: var(--surface2);
  border: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
}
.h-word.p0    { border-color: rgba(99,102,241,.45); color: rgba(130,140,255,.9); }
.h-word.p1    { border-color: rgba(34,197,94,.4);  color: rgba(74,222,128,.9); }
.h-word.start { opacity: .5; }
@keyframes slide-in {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}
.h-word.new { animation: slide-in .2s ease; }

.h-arrow { color: var(--muted); font-size: .65rem; flex-shrink: 0; }

/* ── Game controls (floating) ──────────────────────────────────────── */
.game-controls {
  position: fixed;
  bottom: 14px; right: 14px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 50;
}
.ctrl-btn {
  width: 38px; height: 38px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
  transition: border-color .2s, color .2s, opacity .2s;
  opacity: .55;
}
.ctrl-btn:hover { opacity: 1; border-color: var(--accent); color: var(--text); }
.ctrl-btn#btnGiveUp:hover { border-color: var(--red); color: var(--red); }
.ctrl-btn.muted { opacity: .25; }

/* ── Game-over screen ──────────────────────────────────────────────── */
.go-screen {
  position: fixed; inset: 0;
  background: rgba(11,15,26,.88);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.go-box {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 28px 22px 24px;
  max-width: 400px; width: 100%;
  display: flex; flex-direction: column;
  align-items: center; gap: 14px;
  text-align: center;
  animation: pop .3s cubic-bezier(.34,1.56,.64,1);
  max-height: 92vh;
  overflow-y: auto;
}
.go-icon   { font-size: 3rem; line-height: 1; }
.go-title  { font-family: var(--font-disp); font-size: 2rem; font-weight: 800; line-height: 1.1; }
.go-reason { font-size: .83rem; color: var(--muted); margin-top: -4px; }

/* Scoreboard */
.go-scoreboard {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; width: 100%;
  padding: 14px 16px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.go-sb-player {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  flex: 1;
}
.go-sb-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--p0-color);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-disp); font-size: 1.1rem; font-weight: 800;
  color: #fff;
  border: 2px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
.go-sb-avatar.p1 { background: var(--p1-color); }
.go-sb-player.winner .go-sb-avatar {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,.25);
}
.go-sb-score {
  font-family: var(--font-disp); font-size: 2rem; font-weight: 800;
  color: var(--text); line-height: 1;
}
.go-sb-player.winner .go-sb-score { color: var(--green); }
.go-sb-name {
  font-size: .73rem; font-weight: 600; color: var(--muted);
  max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.go-sb-vs {
  font-size: .65rem; font-weight: 800; color: var(--muted);
  letter-spacing: 2px; flex-shrink: 0;
}

/* Rounds played */
.go-rounds {
  text-align: center;
  font-size: .85rem; color: var(--muted);
  margin: 6px 0 2px;
}
.go-rounds strong { color: var(--text); font-weight: 700; }

/* Rating / streak stats */
.go-stats {
  display: flex; gap: 16px; flex-wrap: wrap;
  justify-content: center;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
}
.go-stats:empty { display: none; }
.stat-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-value { font-family: var(--font-disp); font-size: 1.3rem; font-weight: 800; }
.stat-value.pos { color: var(--green); }
.stat-value.neg { color: var(--red); }
.stat-label { font-size: .62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

/* Word chain */
.go-chain-wrap { width: 100%; }
.go-chain-label { font-size: .65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.go-chain { max-height: 80px; overflow-y: auto; justify-content: flex-start; padding: 4px; }

/* Primary CTA */
.go-play-again {
  width: 100%; padding: 15px;
  font-size: 1rem; font-weight: 700;
  border-radius: var(--radius);
}

/* Secondary actions row */
.go-secondary {
  display: flex; gap: 10px; width: 100%;
}
.go-secondary .btn-ghost {
  flex: 1; font-size: .85rem; padding: 10px 12px;
  text-decoration: none;
}

.rematch-status { font-size: .78rem; color: var(--muted); min-height: 18px; margin-top: -6px; }

/* ── Turn-start flash on the word area ───────────────────────────── */
@keyframes turn-flash {
  0%   { background: rgba(99,102,241,.12); }
  55%  { background: rgba(99,102,241,.06); }
  100% { background: transparent; }
}
.word-hero.turn-flash { animation: turn-flash .9s ease-out; border-radius: var(--radius); }

/* ── Mobile — up to 480px ─────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Landing */
  .home-page { padding: 20px 14px; }
  .hero-inner { gap: 18px; }
  .action-grid { grid-template-columns: 1fr; }
  .demo-tiles-wrap { padding: 16px 14px 12px; }

  /* Game header — more compact so the tiles get the space */
  .game-header { padding: 7px 10px; gap: 4px; }
  .timer-ring-wrap { width: 60px; height: 60px; }
  .timer-num { font-size: 1.25rem; }
  .avatar { width: 34px; height: 34px; font-size: .85rem; }
  .player-block { gap: 6px; }
  .player-name { font-size: .74rem; max-width: 78px; }
  .player-score { font-size: .6rem; }
  .you-badge { font-size: .48rem; padding: 1px 4px; }
  .turn-badge { font-size: .6rem; }

  /* Game main */
  .game-main { padding: 12px 12px 8px; gap: 10px; }
  .word-hero { gap: 10px; }
  .word-hero-label { font-size: .58rem; }

  /* Input zone */
  .input-zone { gap: 6px; }
  .word-input { font-size: 1.2rem; letter-spacing: 3px; padding: 11px 12px; }
  .submit-btn { padding: 13px; font-size: .95rem; }
  .input-hint { font-size: .72rem; }

  /* Thinking label */
  .thinking-label { font-size: .75rem; padding: 5px 14px; }

  /* History — single horizontal row, no wrapping */
  .history-chain { flex-wrap: nowrap; justify-content: flex-start; }
  .h-word { font-size: .68rem; padding: 2px 7px; }

  /* Game over */
  .go-box { padding: 18px 14px 16px; gap: 10px; }
  .go-icon { font-size: 2.2rem; }
  .go-title { font-size: 1.65rem; }
  .go-reason { font-size: .78rem; }
  .go-scoreboard { padding: 10px 12px; }
  .go-sb-score { font-size: 1.6rem; }
  .go-sb-avatar { width: 38px; height: 38px; font-size: .95rem; }
  .go-sb-name { font-size: .68rem; }
  .go-stats { padding: 8px 10px; gap: 12px; }
  .stat-value { font-size: 1.1rem; }
  .go-chain-label { font-size: .58rem; }
  .go-play-again { padding: 13px; font-size: .95rem; }
}

/* ── Very small phones — up to 360px ─────────────────────────────── */
@media (max-width: 360px) {
  .game-header { padding: 6px 8px; }
  .timer-ring-wrap { width: 54px; height: 54px; }
  .timer-num { font-size: 1.1rem; }
  .avatar { width: 30px; height: 30px; font-size: .8rem; }
  .player-name { max-width: 60px; font-size: .7rem; }
  .demo-tile { width: 50px; height: 56px; font-size: 1.4rem; }
  .action-card.primary { flex-direction: column; gap: 8px; }
}

/* ── Tall screens — give tiles more breathing room ────────────────── */
@media (min-height: 800px) {
  .game-main { padding-top: 24px; gap: 20px; }
}

/* ── Wider than mobile ────────────────────────────────────────────── */
@media (min-width: 520px) {
  .demo-tile { width: 72px; height: 78px; font-size: 1.9rem; }
  .hero-inner { gap: 28px; }
}

/* ── Leaderboard page ─────────────────────────────────────────────── */

.lb-page {
  min-height: 100vh;
  display: flex; justify-content: center;
  padding: 32px 16px 64px;
}
.lb-inner {
  width: 100%; max-width: 620px;
}
.lb-back {
  display: inline-block;
  color: var(--muted); font-size: .85rem;
  text-decoration: none; margin-bottom: 28px;
  transition: color .15s;
}
.lb-back:hover { color: var(--text); }
.lb-header { margin-bottom: 24px; }
.lb-title {
  font-family: var(--font-disp);
  font-size: 2rem; font-weight: 800;
  margin-bottom: .3rem;
}
.lb-sub { font-size: .82rem; color: var(--muted); }
.lb-loading { display: flex; justify-content: center; padding: 64px; }
.lb-empty {
  text-align: center; color: var(--muted);
  padding: 56px 0;
}
.lb-empty-icon { font-size: 3rem; margin-bottom: 12px; }
.lb-empty-sub  { font-size: .82rem; margin-top: 6px; }
.lb-not-ranked {
  text-align: center; font-size: .82rem;
  color: var(--muted); margin-top: 16px;
}
.lb-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.lb-table {
  width: 100%; border-collapse: collapse;
  font-size: .9rem;
}
.lb-table thead th {
  background: var(--surface2);
  padding: 11px 16px;
  text-align: left;
  font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.lb-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.lb-table tbody tr:last-child { border-bottom: none; }
.lb-table tbody tr:hover:not(.lb-me) { background: var(--surface2); }
.lb-table tbody td { padding: 13px 16px; }
.lb-col-rank { width: 48px; font-size: 1.1rem; }
.lb-col-num  { text-align: right; }
.lb-name-cell { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.lb-rating { font-weight: 700; color: var(--electric-blue); }
.lb-me {
  background: rgba(99,102,241,.1) !important;
  box-shadow: inset 2px 0 0 var(--accent);
}
.lb-me .lb-name-cell { color: var(--accent-h); }

/* ── How to Play modal ────────────────────────────────────────────── */
.home-footer-links {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-top: 12px; flex-wrap: wrap;
}
.home-footer-sep { color: var(--border); font-size: .85rem; }
.footer-link {
  background: none; border: none; padding: 0;
  color: var(--muted); font-size: .85rem; font-weight: 500;
  cursor: pointer; font-family: var(--font);
  text-decoration: none;
  transition: color .15s;
}
.footer-link:hover { color: var(--text); }
.htp-box { max-width: 360px; }
.htp-example {
  display: flex; align-items: center;
  justify-content: center; gap: 14px;
  margin: 20px 0;
}
.htp-tiles { display: flex; gap: 5px; }
.htp-tile {
  width: 38px; height: 44px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-disp);
  font-weight: 800; font-size: 1.1rem;
}
.htp-changed {
  background: var(--electric-blue);
  border-color: var(--electric-blue);
  color: #0b0f1a;
}
.htp-arrow { font-size: 1.4rem; color: var(--muted); }
.htp-rules {
  list-style: none; text-align: left;
  font-size: .88rem;
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 16px;
}
.htp-rules li {
  padding-left: 20px; position: relative;
  color: var(--muted); line-height: 1.5;
}
.htp-rules li::before {
  content: '✦'; position: absolute; left: 0;
  color: var(--accent); font-size: .65rem; top: 3px;
}
.htp-rules li strong { color: var(--text); }
.htp-note {
  font-size: .82rem; color: var(--muted);
  margin-bottom: 20px; text-align: center; line-height: 1.5;
}
.htp-note strong { color: var(--text); }
.htp-close-btn { width: 100%; }

/* ── Give Up confirm modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11,15,26,.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 2rem 1.75rem;
  max-width: 300px; width: 90%;
  text-align: center;
  animation: popup .18s ease;
}
.modal-title {
  font-family: var(--font-disp);
  font-size: 1.2rem; font-weight: 700;
  margin-bottom: .4rem;
}
.modal-sub {
  font-size: .85rem; color: var(--muted);
  margin-bottom: 1.5rem;
}
.modal-btns {
  display: flex; gap: .75rem; justify-content: center;
}
.btn-danger {
  padding: 10px 20px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  background: var(--red);
  border: none; color: #fff;
  transition: background .18s, transform .1s;
}
.btn-danger:hover  { background: #dc2626; }
.btn-danger:active { transform: scale(.97); }
