/**
 * Games for the road (js/games.js) — a full-screen sheet over the guest app.
 *
 * Built for a phone being handed round a moving car: every control is at least 56px tall, text is
 * large, and nothing depends on hover. Colours are the guest app's own tokens (css/glass.css) —
 * the brand's nine, never a new hue — with a literal fallback so the sheet still reads if it is
 * ever opened on a page that does not load glass.css. The five seats wear five of the nine.
 */

.games {
  --g-ink: var(--ink, #2a1226);
  --g-soft: var(--ink-soft, #5b3a54);
  --g-paper: var(--canvas, #fdf4ee);
  --g-card: var(--surface, #fffaf6);
  --g-wash: var(--lavender, #ffe4d5);
  --g-sky: var(--lavender-deep, #ffd9c4);
  --g-accent: var(--violet, #c0492b);
  --g-plum: var(--indigo, #4a2340);
  --g-line: var(--hairline-strong, rgba(74, 35, 64, 0.2));
  --g-on: var(--on-brand, #fff7f1);
  --g-ok-bg: var(--ok-bg, #e5f1ea);
  --g-ok: var(--ok-ink, #1f6f4a);
  --g-bad-bg: var(--danger-bg, #fbe3df);
  --g-bad: var(--danger-ink, #a3261a);
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--g-paper);
  color: var(--g-ink);
  font-size: 1.05rem;
  overscroll-behavior: contain;
}

.games [data-seat="0"].race-token, .game-score[data-seat="0"], .game-player[data-seat="0"] { --seat: #c0492b; }
.games [data-seat="1"].race-token, .game-score[data-seat="1"], .game-player[data-seat="1"] { --seat: #4a2340; }
.games [data-seat="2"].race-token, .game-score[data-seat="2"], .game-player[data-seat="2"] { --seat: #f2603f; }
.games [data-seat="3"].race-token, .game-score[data-seat="3"], .game-player[data-seat="3"] { --seat: #2a1226; }
.games [data-seat="4"].race-token, .game-score[data-seat="4"], .game-player[data-seat="4"] { --seat: #ff9b78; }

.games-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--header-bg, #4a2340);
  color: var(--header-ink, #fff3ea);
}
.games-title {
  flex: 1;
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
}
.games-back,
.games-close {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.games-back[hidden] { visibility: hidden; display: grid; }
.games-back .icon svg,
.games-close .icon svg { width: 24px; height: 24px; }

.games-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

/* The hub wears the hills: three ridges in the brand's own Sky, Ridge far/near and Plum, under the
   title — drawn inline so it costs no request and is there offline. */
.games[data-view="hub"] .games-body {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 120' preserveAspectRatio='none'%3E%3Cpath fill='%23FFD9C4' d='M0 70 60 38l40 20 50-34 60 40 40-18 60 30 50-24 40 16v52H0z'/%3E%3Cpath fill='%23FF9B78' d='M0 86 50 62l50 18 60-30 50 30 60-16 50 22 40-14 40 14v34H0z'/%3E%3Cpath fill='%23F2603F' d='M0 100 70 80l60 14 70-22 60 22 70-12 70 14v24H0z'/%3E%3Cpath fill='%234A2340' d='M0 112 90 98l80 10 90-14 70 12 70-6v20H0z'/%3E%3C/svg%3E") top / 100% 120px no-repeat,
    var(--g-paper);
  padding-top: 132px;
}
.games-offline {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--g-wash);
  color: var(--g-soft);
  font-size: 0.95rem;
}
.games-offline .icon svg { width: 20px; height: 20px; flex: none; }
.games-sub { margin: 4px 0 0; font-size: 1.05rem; }

.game-players { display: flex; flex-direction: column; gap: 8px; }
.game-player { display: flex; gap: 8px; }
.game-player-input {
  flex: 1;
  min-height: 52px;
  padding: 0 14px;
  border: 2px solid var(--seat, var(--g-line));
  border-radius: 12px;
  background: var(--g-card);
  color: var(--g-ink);
  font: inherit;
}

.game-btn {
  min-height: 56px;
  padding: 0 18px;
  border-radius: 14px;
  border: 2px solid var(--g-line);
  background: var(--g-card);
  color: var(--g-ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}
.game-btn:disabled { opacity: 0.55; cursor: default; }
.game-btn[hidden] { display: none; }
.game-primary { background: var(--g-accent); border-color: var(--g-accent); color: var(--g-on); }
.game-ok { background: var(--g-plum); border-color: var(--g-plum); color: var(--g-on); }
.game-ghost { background: transparent; }
.game-player-remove { min-width: 56px; padding: 0; font-size: 1.4rem; }
.game-player-add { border-style: dashed; }
.game-chip.is-on { background: var(--g-sky); border-color: var(--g-accent); }

.game-tiles { display: grid; gap: 10px; }
.game-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 76px;
  padding: 14px 16px;
  border: 0;
  border-left: 6px solid var(--g-accent);
  border-radius: 16px;
  background: var(--g-card);
  box-shadow: 0 6px 18px -12px rgba(74, 35, 64, 0.4);
  color: var(--g-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.game-tile-race, .game-tile-quiz { border-left-color: var(--g-plum); }
.game-tile { position: relative; padding-left: 70px; }
.game-tile::before {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 800;
  background: var(--g-wash);
  color: var(--g-accent);
}
.game-tile-race::before { content: "🚂"; background: var(--g-sky); }
.game-tile-bingo::before { content: "👀"; }
.game-tile-quiz::before { content: "?"; background: var(--g-plum); color: var(--g-on); }
.game-tile-antakshari::before { content: "♪"; }
.game-tile-cards::before { content: "🃏"; }
.game-tile-ttt::before { content: "✕"; }
.game-tile-bingo, .game-tile-antakshari { border-left-color: #f2603f; }
.game-tile-name { font-size: 1.15rem; font-weight: 700; }
.game-tile-desc { color: var(--g-soft); font-size: 0.95rem; }

.game-status { margin: 0; font-size: 1.15rem; font-weight: 700; text-align: center; }
.game-hint { margin: 0; color: var(--g-soft); text-align: center; }
.game-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.game-actions > .game-btn { flex: 1 1 140px; }
.game-tabs { display: flex; gap: 8px; }
.game-tabs > .game-btn { flex: 1; }

.game-scores { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.game-score {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--g-card);
  border: 2px solid var(--seat, var(--g-line));
}
.game-score-n { font-weight: 800; color: var(--seat, var(--g-accent)); }

/* Noughts & crosses */
.ttt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(100%, 360px);
  margin: 0 auto;
  aspect-ratio: 1;
}
.ttt-cell {
  border: 0;
  border-radius: 16px;
  background: var(--g-card);
  box-shadow: inset 0 0 0 2px var(--g-line);
  color: var(--g-accent);
  font-size: clamp(2.4rem, 14vw, 3.6rem);
  font-weight: 800;
  cursor: pointer;
}
.ttt-cell:disabled { cursor: default; }

/* Ukaalo! — the real line, drawn as the hill: Darjeeling at the top, NJP at the foot */
.race-controls { display: flex; gap: 12px; align-items: center; }
.race-die {
  width: 64px;
  height: 64px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--g-card);
  box-shadow: inset 0 0 0 3px var(--g-plum);
  font-size: 2rem;
  font-weight: 800;
}
.race-roll { flex: 1; }
.race-fact:empty { display: none; }
.race-fact {
  display: block;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--g-plum);
  color: var(--g-on);
}
.race-fact-inner { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
.race-fact-stop { font-weight: 800; font-size: 1.1rem; }
.race-fact-ft { font-weight: 700; opacity: 0.85; }
.race-fact-text { grid-column: 1 / -1; line-height: 1.4; }
.race-fact-src { grid-column: 1 / -1; color: inherit; opacity: 0.75; font-size: 0.8rem; }
.race-line {
  list-style: none;
  margin: 0;
  padding: 6px 0 6px 18px;
  position: relative;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 228, 213, 0.0) 0%, var(--g-wash) 100%),
    var(--g-card);
}
.race-line::before {
  /* the track itself: a dashed rail up the hill */
  content: "";
  position: absolute;
  left: 27px;
  top: 18px;
  bottom: 18px;
  border-left: 4px dashed var(--g-plum);
  opacity: 0.35;
}
.race-stop {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 2px 10px 2px 0;
}
.race-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--g-card);
  box-shadow: 0 0 0 3px var(--g-plum);
  z-index: 1;
}
.race-stop-name { font-weight: 650; }
.race-stop-ft { color: var(--g-soft); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.race-loop .race-dot, .race-bonus .race-dot { background: #ff9b78; }
.race-miss .race-dot, .race-reverse .race-dot, .race-jam .race-dot { background: #c0492b; }
.race-end .race-dot { width: 20px; height: 20px; background: var(--g-plum); }
.race-end .race-stop-name { font-size: 1.05rem; font-weight: 800; }
.race-tokens { display: flex; gap: 3px; }
.race-token {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--seat, var(--g-accent));
  color: #fff7f1;
  font-size: 0.75rem;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 0 0 2px #fff7f1;
}
.race-roster { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; font-size: 0.9rem; }
.race-roster-item { display: inline-flex; gap: 6px; align-items: center; }

/* Spot it from the car */
.bingo-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.bingo-cell {
  min-height: 64px;
  padding: 4px;
  border: 0;
  border-radius: 12px;
  background: var(--g-card);
  box-shadow: inset 0 0 0 1.5px var(--g-line);
  color: var(--g-ink);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  /* Whole words where they fit, a hyphen where they do not ("Kanchen-junga"), never a cut mid-word. */
  overflow-wrap: break-word;
  hyphens: auto;
}
.bingo-free { background: var(--g-sky); }
.bingo-note { font-size: 0.62rem; font-weight: 500; color: var(--g-soft); }
.bingo-cell.is-marked { background: var(--seat, var(--g-accent)); color: #fff7f1; box-shadow: none; }
.bingo-cell.is-marked .bingo-note { color: inherit; }
.bingo-who { border-color: var(--seat, var(--g-line)); }
.bingo-who[data-seat="0"] { --seat: #c0492b; }
.bingo-who[data-seat="1"] { --seat: #4a2340; }
.bingo-who[data-seat="2"] { --seat: #f2603f; }
.bingo-who[data-seat="3"] { --seat: #2a1226; }
.bingo-who[data-seat="4"] { --seat: #ff9b78; }
.bingo-cell[data-seat="0"] { --seat: #c0492b; }
.bingo-cell[data-seat="1"] { --seat: #4a2340; }
.bingo-cell[data-seat="2"] { --seat: #f2603f; }
.bingo-cell[data-seat="3"] { --seat: #2a1226; }
.bingo-cell[data-seat="4"] { --seat: #ff9b78; }

/* Antakshari */
.ak-letter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px;
  border-radius: 20px;
  background: var(--g-plum);
  color: var(--g-on);
}
.ak-sing { font-size: 1rem; opacity: 0.9; text-align: center; }
.ak-glyph { font-size: 4.5rem; font-weight: 800; line-height: 1.1; }
.ak-clock { min-height: 1.6em; font-size: 2rem; font-weight: 800; text-align: center; color: var(--g-accent); }
.ak-lengths { display: flex; gap: 8px; justify-content: center; }
.ak-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ak-pick { padding: 0; font-size: 1.5rem; }

/* Family cards */
.cards-stage { display: flex; flex-direction: column; gap: 12px; }
.cards-card {
  min-height: 160px;
  padding: 20px;
  border-radius: 20px;
  background: var(--g-card);
  border: 3px solid var(--g-accent);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.cards-hidden { background: var(--g-wash); border-style: dashed; }
.cards-lead { color: var(--g-soft); font-weight: 700; }
.cards-text { font-size: 1.5rem; font-weight: 800; }

/* Quiz */
.quiz-stage { display: flex; flex-direction: column; gap: 12px; }
.quiz-q { margin: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.4; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option { text-align: left; padding: 12px 16px; line-height: 1.3; }
.quiz-option.is-right { background: var(--g-ok-bg); border-color: var(--g-ok); color: var(--g-ink); opacity: 1; }
.quiz-option.is-wrong { background: var(--g-bad-bg); border-color: var(--g-bad); color: var(--g-ink); opacity: 1; }
.quiz-feedback { display: flex; flex-direction: column; gap: 6px; }
.quiz-feedback:empty { display: none; }
.quiz-verdict { margin: 0; font-weight: 800; font-size: 1.15rem; }
.quiz-verdict.is-right { color: var(--g-ok); }
.quiz-verdict.is-wrong { color: var(--g-bad); }
.quiz-fact { margin: 0; line-height: 1.4; }
.quiz-source { margin: 0; color: var(--g-soft); font-size: 0.85rem; }
.quiz-source a { color: inherit; }

@media (prefers-reduced-motion: no-preference) {
  .game-btn, .game-tile, .ttt-cell { transition: transform 0.12s ease; }
  .game-btn:active, .game-tile:active, .ttt-cell:active { transform: scale(0.97); }
}

:root[data-theme="dark"] .games {
  --g-paper: #1d0c19;
  --g-card: #2a1226;
  --g-ink: #fff3ea;
  --g-soft: #e6c9d9;
  --g-wash: #3a1b33;
  --g-sky: #4a2340;
  --g-line: rgba(255, 228, 213, 0.22);
}
