:root {
  color-scheme: light dark;
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1c1a1f;
  --muted: #6d6873;
  --border: #e3ded6;
  --accent: #5a48d8;
  --accent-text: #ffffff;
  --good: #1f9d63;
  --good-text: #ffffff;
  --warn: #b5541a;
  --team-0: #e5484d;
  --team-1: #3b74f0;
  --team-2: #22a067;
  --team-3: #d99a00;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 6px 18px rgb(0 0 0 / 0.04);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141317;
    --surface: #1f1d24;
    --surface-2: #2a2730;
    --text: #efedf3;
    --muted: #a39fab;
    --border: #34313b;
    --accent: #8b7cff;
    --accent-text: #120f1f;
    --good: #35c483;
    --good-text: #06150e;
    --warn: #f0a46b;
    --team-0: #ff6b6f;
    --team-1: #6b9bff;
    --team-2: #3fcf8a;
    --team-3: #f5c542;
    --shadow: none;
  }
}

.team-0 { --team: var(--team-0); }
.team-1 { --team: var(--team-1); }
.team-2 { --team: var(--team-2); }
.team-3 { --team: var(--team-3); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 8px; }
[hidden] { display: none !important; }

/* ---- layout ---- */

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}
.center-page { min-height: 100dvh; display: grid; place-items: center; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.stack { display: grid; gap: 12px; }
.stack > * { margin: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.hint { color: var(--muted); font-size: 0.92rem; }
.lead { font-size: 1.1rem; font-weight: 600; }
.eyebrow {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 0;
}
.brand { font-weight: 800; letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.room-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 4px 8px 4px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.banner-offline {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 6px 16px;
  background: var(--warn);
  color: #fff;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
}

/* ---- controls ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, background-color 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn-big { width: 100%; min-height: 60px; border-radius: 16px; font-size: 1.15rem; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 0.92rem; }
.btn-good { background: var(--good); border-color: transparent; color: var(--good-text); }
.btn-skip { background: var(--surface-2); border-color: transparent; }
.btn-text {
  border: 0;
  background: none;
  padding: 8px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.btn:focus-visible, .btn-text:focus-visible, .chip:focus-visible, .seg button:focus-visible, .result-row:focus-visible, input:focus-visible,
textarea:focus-visible, .lang-toggle:has(select:focus-visible) {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}
/* The code shows; the invisible list on top of it opens the phone's own picker. */
.lang-toggle { position: relative; display: inline-block; }
.lang-toggle select { position: absolute; inset: 0; width: 100%; opacity: 0; font-size: 16px; cursor: pointer; }

.field { display: grid; gap: 6px; }
.field-label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
input.text, textarea.text {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.05rem;
}
textarea.text { display: block; min-height: 132px; padding: 12px 14px; line-height: 1.4; resize: vertical; }
input.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
}

.seg { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.seg button {
  flex: 1;
  min-height: 38px;
  padding: 6px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}
.seg button.on { background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }
.seg button:disabled { cursor: default; }
.seg button:disabled:not(.on) { opacity: 0.55; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.chip.on { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.chip:disabled { cursor: default; }
.chip:disabled:not(.on) { opacity: 0.6; }
.chip-count { margin-left: 2px; font-weight: 500; opacity: 0.7; }
/* "Select all" / "Clear all" after the themes: a button, not a theme. */
.chip-all { border-style: dashed; background: transparent; font-weight: 500; }

/* ---- home ---- */

.home { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.home-top { position: absolute; top: 12px; right: 16px; }
.logo { font-size: clamp(2.3rem, 10vw, 3.2rem); font-weight: 900; letter-spacing: -0.03em; line-height: 1.02; margin: 0; }
.tagline { color: var(--muted); font-size: 1.05rem; margin: 8px 0 20px; text-wrap: balance; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.heading { display: grid; gap: 4px; }
.heading > * { margin: 0; }
.stack > .heading { padding-bottom: 4px; }
.steps { list-style: none; counter-reset: step; display: grid; gap: 10px; margin: 0 0 20px; padding: 0; }
.steps li { counter-increment: step; display: flex; align-items: flex-start; gap: 12px; }
.steps li::before {
  content: counter(step);
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 800;
}
.steps li > span { padding-top: 2px; text-wrap: pretty; }
.about { margin: 0 0 4px; text-wrap: pretty; }
.home-feedback { margin: 0; text-align: center; }

/* ---- lobby ---- */

.invite-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.invite-link {
  flex: 1 1 180px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.teams { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.team {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--border);
  border-top: 6px solid var(--team);
  border-radius: 14px;
}
.team.mine { border-color: var(--team); }
.spectators { --team: var(--muted); grid-column: 1 / -1; }
.spectators .hint { margin: 0; }
.team-head { display: flex; align-items: center; gap: 8px; }
.team-dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--team); }
.members { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; flex: 1; }
.members li { display: flex; align-items: center; gap: 4px; }
.member-info { display: flex; flex: 1; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; }
.members li.offline .member-name { color: var(--muted); }
.member-name { overflow-wrap: anywhere; }
.tag {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}
/* The host's cross that removes a player: at the end of their line in a team, or of their row in the leaderboard. */
.kick {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.kick:hover { background: var(--surface-2); color: var(--text); }
.kick:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.members .kick { flex: none; margin: -6px -6px -6px 0; }
.team-btn { border-color: var(--team); }
.team-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.team-buttons .team-btn::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--team);
}

/* ---- game ---- */

.scoreboard { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.score {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 2px solid transparent;
  border-radius: 99px;
  background: var(--surface);
}
.score.active { border-color: var(--team); }
.score b { font-variant-numeric: tabular-nums; }
.score-target { margin-left: auto; color: var(--muted); font-size: 0.9rem; }

.turn-banner { border-top: 6px solid var(--team); }
.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--warn);
  font-weight: 600;
}

.timer { margin: 4px 0 12px; }
.timer-digits {
  font-size: 3.2rem;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.timer-digits.urgent { color: var(--team-0); }
.timer-bar { height: 8px; overflow: hidden; border-radius: 99px; background: var(--surface-2); }
.timer-bar > div { height: 100%; background: var(--accent); transition: width 0.2s linear; }

.word-card {
  margin-bottom: 12px;
  padding: 28px 16px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.word {
  margin: 8px 0 24px;
  font-size: clamp(2rem, 10vw, 3.3rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.word-small { font-size: clamp(1.6rem, 8vw, 2.4rem); margin: 4px 0 8px; }
.answer-buttons { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; margin-bottom: 12px; }
.answer-buttons .btn { min-height: 76px; border-radius: 18px; font-size: 1.2rem; }

.big-count { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* What a bot said about the word on screen, newest last and brightest, and how its hearing goes. */
.bot-panel { display: grid; gap: 8px; margin: 12px 0; text-align: left; }
.bot-lines { display: grid; gap: 6px; }
.bot-line { display: flex; gap: 6px; margin: 0; padding: 8px 12px; border-radius: 14px; background: var(--surface-2); color: var(--muted); }
.bot-line:last-child { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--text); font-weight: 600; }
.bot-heard { margin: 0; overflow-wrap: anywhere; }
.speech-debug {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font: 11px/1.35 ui-monospace, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.results { display: grid; gap: 4px; margin: 8px 0 0; padding: 0; list-style: none; }
.results li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface-2);
}
.result-word { overflow-wrap: anywhere; }
.result-tag { flex: none; font-size: 0.9rem; font-weight: 700; }
.results li.hit .result-tag { color: var(--good); }
.results li.missed { color: var(--muted); }
.results li.missed .result-tag { font-weight: 500; }
.results li.stolen .result-tag { color: var(--team); }
/* A word that can still be corrected: the whole row is the button, and its tag looks like one. */
.results li.result-correct { padding: 0; }
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 6px 10px;
  border: 0;
  border-radius: inherit;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.result-row:disabled { opacity: 0.6; cursor: default; }
.result-correct .result-tag { padding: 2px 10px; border: 1px solid var(--border); border-radius: 99px; background: var(--surface); }
.results li.result-choice { flex-wrap: wrap; }
.result-choice .chips { flex-basis: 100%; }

.winner { border-top: 6px solid var(--team, var(--accent)); }
.trophy { font-size: 3rem; line-height: 1.2; }
.ranking { display: grid; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; text-align: left; }
.ranking li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface-2);
}
.ranking li b { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ---- leaderboard ---- */

.leaderboard h2 { margin-top: 0; }
.board { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.board th,
.board td { padding: 6px 0 6px 10px; text-align: right; white-space: nowrap; }
.board th { padding-top: 0; color: var(--muted); font-size: 0.75rem; font-weight: 700; }
.board td { border-top: 1px solid var(--border); }
.board .board-place { width: 1.5em; padding-left: 0; color: var(--muted); text-align: left; }
.board .board-name { width: 100%; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.board-name .team-dot { display: inline-block; margin-right: 6px; }
.board-name .tag { margin-left: 6px; vertical-align: 1px; }
.board tr.mine td { font-weight: 700; }
.board tr.offline .member-name { color: var(--muted); }
.board .board-kick { width: 32px; padding: 0 0 0 4px; }
.board-kick .kick { margin-right: -6px; vertical-align: middle; }
.leaderboard .hint { margin: 10px 0 0; }

/* ---- feedback ---- */

/* The form opens at the top of the screen, clear of the phone's keyboard. */
.sheet {
  width: min(100% - 32px, 528px);
  max-width: none;
  max-height: calc(100dvh - 32px - env(safe-area-inset-top));
  margin: calc(16px + env(safe-area-inset-top)) auto auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 48px rgb(0 0 0 / 0.25);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet > * { padding: 16px; }
.sheet p { text-wrap: pretty; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-error { color: var(--warn); font-weight: 600; }

/* ---- voice ---- */

.voice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
.icon { display: inline-flex; }
.icon svg { display: block; }
.btn-voice { min-height: 40px; }
.btn-mic { width: 44px; padding: 0; }
.btn-mic.on { background: var(--good); border-color: transparent; color: var(--good-text); }
.voice-people { display: flex; flex: 1; flex-wrap: wrap; gap: 6px; min-width: 0; }
.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 0.8rem;
  font-weight: 700;
  outline: 2px solid transparent;
  transition: outline-color 0.1s;
}
.avatar.speaking { outline-color: var(--good); }
.voice-note { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 0.85rem; }

/* ---- reactions ---- */

/* The bar stays at the bottom of the screen: the page makes room for it, the toast shows above it. */
.page:has(.reaction-bar) { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
body:has(.reaction-bar) .toast { bottom: calc(88px + env(safe-area-inset-bottom)); }
.reaction-bar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 6;
  display: flex;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
  transform: translateX(-50%);
}
.reaction-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.reaction-btn:active { transform: scale(0.85); }
.reaction-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.reaction-bar.cooling .reaction-btn { opacity: 0.4; }

/* Reactions rise from the bottom of the screen, or from just above the bar, within the page's
   column. Short of the explainer's buttons even on a small phone; taps go through them. */
.reactions {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 7;
  width: min(100%, 560px);
  overflow: hidden;
  pointer-events: none;
  transform: translateX(-50%);
}
body:has(.reaction-bar) .reactions { bottom: 68px; }
.reaction {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  opacity: 0;
  animation: reaction-float ease-out forwards;
}
.reaction-emoji { font-size: 2.2rem; line-height: 1; }
.reaction-name {
  max-width: 8rem;
  padding: 1px 8px;
  overflow: hidden;
  border: 2px solid var(--team, var(--muted));
  border-radius: 99px;
  background: var(--surface);
  font-size: 0.75rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@keyframes reaction-float {
  0% { opacity: 0; transform: translate(-50%, 24px) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--drift, 0px)), -150px); }
}
@keyframes reaction-fade {
  0%, 100% { opacity: 0; transform: translateX(-50%); }
  10%, 80% { opacity: 1; transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  .reaction { animation-name: reaction-fade; }
}

@media (max-width: 360px) {
  .teams { grid-template-columns: 1fr; }
  .answer-buttons { grid-template-columns: 1fr; }
  .reaction-btn { width: 42px; height: 42px; font-size: 1.4rem; }
}
