/* ==========================================================================
   TriviPals design system (v2) — light by default, dark for the projector.
   Loaded after Bootstrap 5.3 on every page. Bootstrap is used for grid,
   forms and utilities; everything visual comes from here.
   Theme switch: <html data-theme="light|dark">. Pages that omit it follow
   the OS preference. The projector sets data-theme="dark" explicitly.
   ========================================================================== */

:root {
  --tp-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tp-radius: 18px;
  --tp-radius-sm: 12px;
  --tp-radius-lg: 26px;

  /* brand */
  --tp-pink: #ff6b9d;
  --tp-pink-ink: #e2457c;
  --tp-violet: #7557f6;
  --tp-cyan: #00bcd4;
  --tp-yellow: #ffbf3f;
  --tp-green: #37c989;
  --tp-red: #ea496d;
  --tp-navy: #211b3d;

  /* light surfaces */
  --tp-bg: #fbf8ff;
  --tp-fg: #171329;
  --tp-card: #ffffff;
  --tp-card-fg: #171329;
  --tp-secondary: #ebe5ff;
  --tp-secondary-fg: #51408e;
  --tp-muted: #f1eff8;
  --tp-muted-fg: #77728c;
  --tp-ink-soft: #514b65;
  --tp-border: #e8e2f2;
  --tp-input: #ded7eb;
  --tp-shadow: 0 10px 30px -18px rgba(33, 27, 61, 0.35);
  --tp-shadow-lg: 0 24px 60px -30px rgba(33, 27, 61, 0.45);
  --tp-hero-grad: linear-gradient(135deg, #211b3d 0%, #7557f6 55%, #ff6b9d 100%);
  --tp-hero-grad-cool: linear-gradient(135deg, #00bcd4 0%, #7557f6 100%);
  --tp-on-hero: #ffffff;
  --tp-on-hero-muted: #ded7f5;
}

:root[data-theme="dark"] {
  --tp-bg: #171329;
  --tp-fg: #fff8fc;
  --tp-card: #24203d;
  --tp-card-fg: #fff8fc;
  --tp-secondary: #332e54;
  --tp-secondary-fg: #e7deff;
  --tp-muted: #2b2744;
  --tp-muted-fg: #b3acc7;
  --tp-ink-soft: #c4bad7;
  --tp-border: #3a3459;
  --tp-input: #4b446c;
  --tp-pink: #ff79a9;
  --tp-violet: #9a86ff;
  --tp-cyan: #5fe3ef;
  --tp-yellow: #ffcf64;
  --tp-green: #62dda8;
  --tp-red: #ff7792;
  --tp-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.7);
  --tp-shadow-lg: 0 24px 60px -30px rgba(0, 0, 0, 0.8);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tp-bg: #171329;
    --tp-fg: #fff8fc;
    --tp-card: #24203d;
    --tp-card-fg: #fff8fc;
    --tp-secondary: #332e54;
    --tp-secondary-fg: #e7deff;
    --tp-muted: #2b2744;
    --tp-muted-fg: #b3acc7;
    --tp-ink-soft: #c4bad7;
    --tp-border: #3a3459;
    --tp-input: #4b446c;
    --tp-pink: #ff79a9;
    --tp-violet: #9a86ff;
    --tp-cyan: #5fe3ef;
    --tp-yellow: #ffcf64;
    --tp-green: #62dda8;
    --tp-red: #ff7792;
    --tp-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.7);
    --tp-shadow-lg: 0 24px 60px -30px rgba(0, 0, 0, 0.8);
  }
}

/* ---------- base ---------- */
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--tp-font);
  background: var(--tp-bg);
  color: var(--tp-fg);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
main { flex: 1 0 auto; }
a { color: var(--tp-pink-ink); text-decoration: none; }
a:hover { color: var(--tp-pink-ink); text-decoration: underline; }
:root[data-theme="dark"] a, :root[data-theme="dark"] a:hover { color: var(--tp-pink); }
::selection { background: var(--tp-pink); color: #fff; }
:focus-visible { outline: 3px solid var(--tp-violet); outline-offset: 2px; border-radius: 6px; }
.visually-hidden-focusable:focus { position: static !important; }

/* Bootstrap bridge so forms/alerts/badges pick up the palette */
body {
  --bs-body-bg: var(--tp-bg);
  --bs-body-color: var(--tp-fg);
  --bs-border-color: var(--tp-border);
  --bs-secondary-color: var(--tp-muted-fg);
  --bs-link-color: var(--tp-pink-ink);
  --bs-link-hover-color: var(--tp-pink-ink);
}
.text-muted, .text-body-secondary { color: var(--tp-muted-fg) !important; }
.form-control, .form-select {
  background: var(--tp-card);
  color: var(--tp-fg);
  border: 1px solid var(--tp-input);
  border-radius: var(--tp-radius-sm);
  min-height: 52px;
  padding: 0.7rem 1rem;
  font-size: 1rem;
}
.form-control::placeholder { color: var(--tp-muted-fg); }
.form-control:focus, .form-select:focus {
  background: var(--tp-card);
  color: var(--tp-fg);
  border-color: var(--tp-violet);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--tp-violet) 18%, transparent);
}
.form-control.is-invalid { border-color: var(--tp-red); }
.form-label { font-weight: 700; font-size: 0.9rem; color: var(--tp-ink-soft); margin-bottom: 0.4rem; }
.form-text { color: var(--tp-muted-fg); }
.form-range::-webkit-slider-thumb { background: var(--tp-pink); }
.form-range::-moz-range-thumb { background: var(--tp-pink); }
.form-check-input:checked { background-color: var(--tp-pink); border-color: var(--tp-pink); }
.alert { border-radius: var(--tp-radius-sm); border: 1px solid var(--tp-border); }
.alert-danger { background: color-mix(in srgb, var(--tp-red) 12%, var(--tp-card)); color: var(--tp-fg); }
.alert-success { background: color-mix(in srgb, var(--tp-green) 14%, var(--tp-card)); color: var(--tp-fg); }
.alert-info { background: var(--tp-secondary); color: var(--tp-secondary-fg); }
.alert-warning { background: color-mix(in srgb, var(--tp-yellow) 18%, var(--tp-card)); color: var(--tp-fg); }
.modal-content { background: var(--tp-card); color: var(--tp-fg); border-radius: var(--tp-radius-lg); border: 1px solid var(--tp-border); }
.modal-header, .modal-footer { border-color: var(--tp-border); }
.btn-close { filter: none; }
:root[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
.table { --bs-table-bg: transparent; --bs-table-color: var(--tp-fg); --bs-table-border-color: var(--tp-border); }
.badge { border-radius: 999px; font-weight: 700; letter-spacing: 0.02em; }
.dropdown-menu { background: var(--tp-card); border: 1px solid var(--tp-border); border-radius: var(--tp-radius-sm); box-shadow: var(--tp-shadow); }
.dropdown-item { color: var(--tp-fg); }
.dropdown-item:hover { background: var(--tp-muted); color: var(--tp-fg); }

/* ---------- type ---------- */
.tp-eyebrow {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tp-pink-ink);
  margin-bottom: 0.5rem;
}
:root[data-theme="dark"] .tp-eyebrow { color: var(--tp-pink); }
.tp-eyebrow.on-hero { color: var(--tp-on-hero-muted); }
.tp-eyebrow.violet { color: var(--tp-violet); }
.tp-eyebrow.cyan { color: var(--tp-cyan); }
.tp-h1 {
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin: 0 0 0.6rem;
}
.tp-h2 {
  font-size: clamp(1.4rem, 3.5vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin: 0 0 0.4rem;
}
.tp-h3 { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; margin: 0 0 0.25rem; }
.tp-lead { font-size: 1.05rem; color: var(--tp-ink-soft); margin: 0 0 1.25rem; max-width: 36rem; }
.tp-small { font-size: 0.85rem; color: var(--tp-muted-fg); }
.tp-mono { font-variant-numeric: tabular-nums; letter-spacing: 0.08em; }
.tp-text-pink { color: var(--tp-pink-ink); } :root[data-theme="dark"] .tp-text-pink { color: var(--tp-pink); }
.tp-text-violet { color: var(--tp-violet); }
.tp-text-cyan { color: var(--tp-cyan); }
.tp-text-green { color: var(--tp-green); }
.tp-text-yellow { color: var(--tp-yellow); }
.tp-text-red { color: var(--tp-red); }

/* ---------- nav ---------- */
.tp-nav {
  position: sticky;
  top: 0;
  z-index: 1020;
  background: color-mix(in srgb, var(--tp-bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--tp-border);
}
.tp-nav .navbar { padding: 0.7rem 0; }
.tp-brand { display: flex; align-items: center; gap: 0.6rem; color: var(--tp-fg) !important; text-decoration: none !important; }
.tp-brand img { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; }
.tp-brand-name { font-weight: 800; letter-spacing: 0.12em; font-size: 1rem; line-height: 1; }
.tp-brand-sub { display: block; font-size: 0.6rem; letter-spacing: 0.22em; color: var(--tp-muted-fg); font-weight: 700; margin-top: 3px; }
.tp-nav .nav-link { color: var(--tp-ink-soft); font-weight: 600; padding: 0.45rem 0.8rem; border-radius: 999px; }
.tp-nav .nav-link:hover, .tp-nav .nav-link:focus { color: var(--tp-fg); background: var(--tp-muted); }
.tp-nav .navbar-toggler { border-color: var(--tp-border); }
.tp-nav .navbar-toggler-icon { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%2377728c' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2.5' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e"); }
.tp-avatar {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--tp-secondary); color: var(--tp-secondary-fg);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.95rem;
}

/* ---------- surfaces ---------- */
.tp-card {
  background: var(--tp-card);
  color: var(--tp-card-fg);
  border: 1px solid var(--tp-border);
  border-radius: var(--tp-radius);
  box-shadow: var(--tp-shadow);
  padding: 1.25rem;
}
.tp-card.flat { box-shadow: none; }
.tp-card.tight { padding: 0.9rem 1rem; }
.tp-card.pad-lg { padding: 1.6rem; }
.tp-card.is-selected { border-color: var(--tp-pink); box-shadow: 0 0 0 1px var(--tp-pink), var(--tp-shadow); }
.tp-card-link { display: block; color: inherit; text-decoration: none !important; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.tp-card-link:hover { transform: translateY(-2px); box-shadow: var(--tp-shadow-lg); color: inherit; }
.tp-hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--tp-radius-lg);
  background: var(--tp-hero-grad);
  color: var(--tp-on-hero);
  padding: clamp(1.4rem, 4vw, 2.4rem);
  box-shadow: var(--tp-shadow-lg);
}
.tp-hero.cool { background: var(--tp-hero-grad-cool); }
.tp-hero::after {
  content: "";
  position: absolute; right: -12%; bottom: -40%;
  width: 60%; aspect-ratio: 1; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}
.tp-hero > * { position: relative; z-index: 1; }
.tp-hero .tp-h1, .tp-hero .tp-h2 { color: #fff; }
.tp-hero .tp-lead { color: var(--tp-on-hero-muted); }
.tp-hero a:not(.tp-btn) { color: #fff; text-decoration: underline; }
.tp-tile {
  width: 48px; height: 48px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.3rem; color: #fff; flex-shrink: 0;
}
.tp-tile.pink { background: var(--tp-pink); }
.tp-tile.violet { background: var(--tp-violet); }
.tp-tile.cyan { background: var(--tp-cyan); }
.tp-tile.yellow { background: var(--tp-yellow); color: var(--tp-navy); }
.tp-tile.green { background: var(--tp-green); }
.tp-tile.soft { background: var(--tp-secondary); color: var(--tp-secondary-fg); }
.tp-tile.lg { width: 66px; height: 66px; border-radius: 22px; font-size: 1.8rem; }
.tp-stat { padding: 1rem 1.1rem; }
.tp-stat-label { font-size: 0.68rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--tp-muted-fg); }
.tp-stat-value { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; margin: 0.25rem 0; }
.tp-stat-hint { font-size: 0.8rem; color: var(--tp-muted-fg); }
.tp-divider { border: 0; border-top: 1px solid var(--tp-border); margin: 1.25rem 0; }

/* ---------- buttons ---------- */
.tp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 52px; padding: 0.75rem 1.4rem;
  border-radius: 999px; border: 1px solid transparent;
  font-weight: 800; font-size: 1rem; line-height: 1;
  cursor: pointer; text-decoration: none !important;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, opacity 0.12s;
  white-space: nowrap;
}
.tp-btn:active { transform: scale(0.98); }
.tp-btn:disabled, .tp-btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.tp-btn-primary { background: var(--tp-pink); color: #fff !important; box-shadow: 0 10px 24px -12px var(--tp-pink); }
.tp-btn-primary:hover { background: var(--tp-pink-ink); }
.tp-btn-dark { background: var(--tp-navy); color: #fff !important; }
.tp-btn-dark:hover { background: #2d2552; }
.tp-btn-violet { background: var(--tp-violet); color: #fff !important; }
.tp-btn-green { background: var(--tp-green); color: #fff !important; }
.tp-btn-outline { background: transparent; color: var(--tp-fg) !important; border-color: var(--tp-border); }
.tp-btn-outline:hover { background: var(--tp-muted); }
.tp-btn-ghost { background: transparent; color: var(--tp-ink-soft) !important; }
.tp-btn-ghost:hover { background: var(--tp-muted); color: var(--tp-fg) !important; }
.tp-btn-on-hero { background: rgba(255, 255, 255, 0.14); color: #fff !important; border-color: rgba(255, 255, 255, 0.25); }
.tp-btn-on-hero:hover { background: rgba(255, 255, 255, 0.24); }
.tp-btn-danger { background: var(--tp-red); color: #fff !important; }
.tp-btn-sm { min-height: 40px; padding: 0.45rem 1rem; font-size: 0.9rem; }
.tp-btn-lg { min-height: 60px; padding: 0.9rem 1.8rem; font-size: 1.1rem; }
.tp-btn-block { width: 100%; }
.tp-btn-icon { min-width: 44px; min-height: 44px; padding: 0; border-radius: 12px; }
.tp-btn .spinner-border { width: 1rem; height: 1rem; border-width: 2px; }

/* ---------- chips / pills ---------- */
.tp-chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.5rem 0.95rem; border-radius: 999px;
  background: var(--tp-card); color: var(--tp-fg);
  border: 1px solid var(--tp-border);
  font-weight: 700; font-size: 0.9rem; cursor: pointer; user-select: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tp-chip:hover { border-color: var(--tp-violet); }
.tp-chip.active, .tp-chip[aria-pressed="true"] { background: var(--tp-pink); color: #fff; border-color: var(--tp-pink); }
.tp-chip input { position: absolute; opacity: 0; pointer-events: none; }
.tp-pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.3rem 0.7rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--tp-secondary); color: var(--tp-secondary-fg);
}
.tp-pill.pink { background: var(--tp-pink); color: #fff; }
.tp-pill.green { background: var(--tp-green); color: #fff; }
.tp-pill.yellow { background: var(--tp-yellow); color: var(--tp-navy); }
.tp-pill.red { background: var(--tp-red); color: #fff; }
.tp-pill.cyan { background: var(--tp-cyan); color: #fff; }
.tp-pill.muted { background: var(--tp-muted); color: var(--tp-muted-fg); }
.tp-pill.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: tp-pulse 1.4s ease-in-out infinite; }

/* ---------- game pieces ---------- */
.tp-code {
  font-weight: 800; letter-spacing: 0.18em; font-variant-numeric: tabular-nums;
  font-size: clamp(2rem, 9vw, 3.2rem); line-height: 1; white-space: nowrap;
}
.tp-code-box { background: var(--tp-navy); color: #fff; border-radius: var(--tp-radius); padding: 1rem 1.2rem; text-align: center; }
.tp-code-box .tp-code { color: #fff; }
.tp-code-box .tp-eyebrow { color: #b3acff; }
.tp-progress { height: 8px; border-radius: 999px; background: var(--tp-secondary); overflow: hidden; }
.tp-progress > span { display: block; height: 100%; background: var(--tp-pink); border-radius: 999px; transition: width 0.3s ease; }
.tp-progress.timer > span { transition: width 0.95s linear; }
.tp-progress.timer.warn > span { background: var(--tp-yellow); }
.tp-progress.timer.danger > span { background: var(--tp-red); }
.tp-timer {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 64px; height: 64px; padding: 0 0.6rem; border-radius: 20px;
  background: var(--tp-navy); color: var(--tp-yellow);
  font-weight: 800; font-size: 1.8rem; font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.tp-timer.warn { color: var(--tp-yellow); animation: tp-pulse 1s ease-in-out infinite; }
.tp-timer.danger { color: var(--tp-red); background: #2a1222; animation: tp-pulse 0.5s ease-in-out infinite; }
.tp-question-card { min-height: 220px; display: flex; flex-direction: column; justify-content: flex-end; }
.tp-question-text { font-size: clamp(1.35rem, 4.5vw, 1.9rem); font-weight: 800; line-height: 1.25; letter-spacing: -0.02em; color: #fff; margin: 0; overflow-wrap: anywhere; }
.tp-answer-box { display: flex; gap: 0.9rem; align-items: flex-start; padding: 1.1rem; border-radius: var(--tp-radius); border: 1px solid var(--tp-border); background: var(--tp-card); }
.tp-answer-box.correct { background: var(--tp-green); border-color: var(--tp-green); color: #fff; }
.tp-answer-box.wrong { background: var(--tp-secondary); border-color: var(--tp-border); color: var(--tp-fg); }
.tp-answer-box.pending { background: color-mix(in srgb, var(--tp-yellow) 18%, var(--tp-card)); }
.tp-answer-box .tp-h3 { margin: 0; }
.tp-points-pop { font-weight: 800; font-size: 1.35rem; letter-spacing: -0.02em; }
.tp-bonus { display: inline-flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.4rem; }
.tp-bonus .tp-pill { background: rgba(255, 255, 255, 0.22); color: inherit; }
.tp-answer-box.wrong .tp-bonus .tp-pill { background: var(--tp-muted); color: var(--tp-muted-fg); }
.tp-leader { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 0.9rem; border-radius: 15px; border: 1px solid var(--tp-border); background: var(--tp-card); }
.tp-leader + .tp-leader { margin-top: 0.5rem; }
.tp-leader.me { background: var(--tp-secondary); }
.tp-leader.winner { border-color: var(--tp-pink); }
.tp-rank { width: 32px; height: 32px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.85rem; background: var(--tp-secondary); color: var(--tp-secondary-fg); flex-shrink: 0; }
.tp-rank.first { background: var(--tp-yellow); color: var(--tp-navy); }
.tp-leader-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-leader-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.tp-leader-sub { font-size: 0.72rem; color: var(--tp-muted-fg); font-weight: 600; }
.tp-streak { color: var(--tp-yellow); font-weight: 800; font-size: 0.8rem; }
.tp-banner { display: flex; gap: 0.75rem; align-items: center; padding: 0.8rem 0.95rem; border-radius: var(--tp-radius); border: 1px solid var(--tp-border); background: var(--tp-secondary); color: var(--tp-fg); }
.tp-banner .tp-tile { width: 40px; height: 40px; border-radius: 12px; font-size: 1.05rem; }
.tp-banner-title { font-weight: 800; font-size: 0.85rem; }
.tp-banner-text { font-size: 0.85rem; color: var(--tp-muted-fg); }
.tp-banner-body { flex: 1 1 12rem; min-width: 0; }
.tp-banner.has-action { flex-wrap: wrap; }
.tp-banner-action { margin-left: auto; display: flex; gap: 0.4rem; align-items: center; }
.tp-banner + .tp-banner { margin-top: 0.6rem; }
.tp-banner .tp-btn-icon { min-width: 36px; min-height: 36px; }
.tp-empty { text-align: center; padding: 2rem 1rem; color: var(--tp-muted-fg); }
.tp-empty .tp-tile { margin: 0 auto 0.8rem; }
.tp-kbd { font-family: var(--tp-font); font-weight: 800; letter-spacing: 0.12em; }

/* ---------- toasts ---------- */
.toast-container { position: fixed; right: 1rem; bottom: 1rem; z-index: 1080; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none; max-width: min(92vw, 380px); }
.tp-toast { pointer-events: auto; background: var(--tp-navy); color: #fff; padding: 0.8rem 1rem; border-radius: 14px; box-shadow: var(--tp-shadow-lg); font-weight: 600; font-size: 0.92rem; opacity: 0; transform: translateY(8px); transition: opacity 0.25s ease, transform 0.25s ease; border-left: 4px solid var(--tp-violet); }
.tp-toast.show { opacity: 1; transform: none; }
.tp-toast-success { border-left-color: var(--tp-green); }
.tp-toast-warning { border-left-color: var(--tp-yellow); }
.tp-toast-danger { border-left-color: var(--tp-red); }
.tp-toast-info { border-left-color: var(--tp-cyan); }

/* ---------- footer ---------- */
.tp-footer { border-top: 1px solid var(--tp-border); padding: 1.5rem 0; margin-top: 3rem; color: var(--tp-muted-fg); font-size: 0.85rem; }
.tp-footer a { color: var(--tp-ink-soft); margin-left: 1rem; }

/* ---------- layout helpers ---------- */
.tp-page { padding-top: clamp(1.25rem, 4vw, 2.5rem); padding-bottom: clamp(1.25rem, 4vw, 2.5rem); }
.tp-narrow { max-width: 560px; margin: 0 auto; }
.tp-medium { max-width: 820px; margin: 0 auto; }
.tp-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; }
.tp-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem; }
.tp-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; }
@media (max-width: 575.98px) { .tp-grid-3:not(.keep) { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 767.98px) { .tp-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tp-stack > * + * { margin-top: 0.9rem; }
.tp-sticky-bottom { position: sticky; bottom: 0; padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--tp-bg) 70%, transparent); }
.tp-back { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 14px; background: var(--tp-card); border: 1px solid var(--tp-border); color: var(--tp-fg) !important; text-decoration: none !important; }

/* ---------- player / results pieces ---------- */
.tp-topbar {
  position: sticky; top: 0; z-index: 1020;
  padding: 0.6rem 0;
  background: color-mix(in srgb, var(--tp-bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--tp-border);
}
.tp-topbar-inner { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 0.75rem; }
.tp-topbar-title { text-align: center; font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-score-pill {
  display: inline-flex; align-items: center; gap: 0.4rem; min-height: 36px; padding: 0.3rem 0.8rem; border-radius: 999px;
  background: var(--tp-navy); color: #fff; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tp-score-pill small { font-size: 0.6rem; letter-spacing: 0.14em; color: #b3acff; font-weight: 800; }
.tp-spot-value { font-size: clamp(2rem, 8vw, 2.8rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.tp-overlay {
  position: fixed; inset: 0; z-index: 1060; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; background: var(--tp-hero-grad); color: #fff; text-align: center; overflow: auto;
}
.tp-overlay-inner { width: 100%; max-width: 560px; }
.tp-overlay .tp-eyebrow { color: var(--tp-on-hero-muted); }
.tp-overlay .tp-h1, .tp-overlay .tp-h2 { color: #fff; }
.tp-overlay .tp-lead { color: var(--tp-on-hero-muted); margin-left: auto; margin-right: auto; }
.tp-countdown { font-size: clamp(6rem, 30vw, 11rem); font-weight: 800; line-height: 1; color: var(--tp-yellow); letter-spacing: -0.05em; font-variant-numeric: tabular-nums; }
.tp-podium { display: flex; justify-content: center; gap: 0.6rem; align-items: flex-end; margin-top: 1.5rem; }
.tp-podium-place { flex: 1 1 0; max-width: 170px; background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: var(--tp-radius); padding: 0.9rem 0.6rem; min-width: 0; }
.tp-podium-place.me { outline: 2px solid var(--tp-yellow); outline-offset: 2px; }
.tp-podium-place:nth-child(1) { order: 2; padding-top: 1.5rem; }
.tp-podium-place:nth-child(2) { order: 1; }
.tp-podium-place:nth-child(3) { order: 3; }
.tp-podium-medal { font-size: 2rem; line-height: 1; }
.tp-podium-name { font-weight: 800; font-size: 0.9rem; margin-top: 0.4rem; overflow-wrap: anywhere; }
.tp-podium-score { font-size: 0.8rem; color: var(--tp-on-hero-muted); }
.tp-mic.recording { background: var(--tp-red); color: #fff !important; border-color: var(--tp-red); animation: tp-pulse 1s ease-in-out infinite; }
.tp-recap-q { padding: 0.9rem 0; border-top: 1px solid var(--tp-border); }
.tp-recap-q:first-child { border-top: 0; padding-top: 0; }
.tp-recap-q:last-child { padding-bottom: 0; }
.tp-topbar-actions { display: inline-flex; align-items: center; gap: 0.4rem; }
.tp-sound-btn { min-width: 40px; min-height: 36px; border-radius: 999px; font-size: 1.05rem; color: var(--tp-ink-soft) !important; border: 1px solid var(--tp-border); background: var(--tp-card); }
.tp-sound-btn[aria-pressed="false"] { color: var(--tp-muted-fg) !important; }
.tp-next-in { font-size: 0.85rem; font-weight: 700; color: var(--tp-violet); margin-top: 0.6rem; font-variant-numeric: tabular-nums; }
.tp-next-in b { font-size: 1rem; }

/* ---------- avatars (teams) ---------- */
.tp-avatar-emoji {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 32px; height: 32px; border-radius: 10px; font-size: 1.15rem; line-height: 1;
  background: var(--tp-muted); vertical-align: middle;
}
.tp-avatar-emoji.letter { background: var(--tp-secondary); color: var(--tp-secondary-fg); font-weight: 800; font-size: 0.85rem; }
.tp-h1 .tp-avatar-emoji { width: 1.15em; height: 1.15em; font-size: 0.75em; border-radius: 0.28em; background: rgba(255, 255, 255, 0.16); }
.tp-podium-name .tp-avatar-emoji { width: 28px; height: 28px; font-size: 1rem; background: rgba(255, 255, 255, 0.16); }
.tp-podium-name .tp-avatar-emoji.letter, .tp-h1 .tp-avatar-emoji.letter { color: #fff; }
.tp-banner .tp-avatar-emoji { width: 24px; height: 24px; font-size: 0.95rem; border-radius: 7px; margin-right: 0.15rem; }
.tp-avatar-picker { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.tp-avatar-chip {
  width: 46px; height: 46px; border-radius: 50%; padding: 0; font-size: 1.35rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  background: var(--tp-card); border: 2px solid var(--tp-border);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.tp-avatar-chip:hover { border-color: var(--tp-violet); transform: translateY(-1px); }
.tp-avatar-chip[aria-pressed="true"] { border-color: var(--tp-pink); background: color-mix(in srgb, var(--tp-pink) 14%, var(--tp-card)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tp-pink) 22%, transparent); transform: scale(1.06); }

/* ---------- choice options ---------- */
.tp-choice { display: grid; grid-template-columns: 1fr; gap: 0.65rem; }
.tp-choice-opt {
  --opt: var(--tp-violet);
  position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "letter text mark" "letter bar bar" "letter count count";
  align-items: center; column-gap: 0.8rem; row-gap: 0;
  width: 100%; min-height: 60px; padding: 0.7rem 0.9rem; text-align: left;
  border-radius: var(--tp-radius-sm); border: 2px solid color-mix(in srgb, var(--opt) 30%, transparent);
  background: color-mix(in srgb, var(--opt) 14%, var(--tp-card)); color: var(--tp-fg);
  font: inherit; font-weight: 700; font-size: 1.02rem; line-height: 1.25; cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.2s ease, opacity 0.2s ease;
}
.tp-choice-opt.slot-a { --opt: var(--tp-violet); }
.tp-choice-opt.slot-b { --opt: var(--tp-cyan); }
.tp-choice-opt.slot-c { --opt: var(--tp-pink); }
.tp-choice-opt.slot-d { --opt: var(--tp-yellow); }
button.tp-choice-opt:hover:not(:disabled) { border-color: var(--opt); transform: translateY(-1px); }
button.tp-choice-opt:active:not(:disabled) { transform: scale(0.99); }
button.tp-choice-opt:disabled { cursor: default; }
button.tp-choice-opt:disabled:not(.chosen):not(.correct):not(.wrong) { opacity: 0.6; }
div.tp-choice-opt { cursor: default; }
.tp-choice-letter {
  grid-area: letter; width: 40px; height: 40px; border-radius: 11px; align-self: start;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--opt); color: #fff; font-weight: 800; font-size: 1rem; flex-shrink: 0;
}
.tp-choice-opt.slot-d .tp-choice-letter { color: var(--tp-navy); }
.tp-choice-text { grid-area: text; overflow-wrap: anywhere; }
.tp-choice-mark { grid-area: mark; font-size: 1.3rem; line-height: 1; display: inline-flex; align-items: center; min-width: 1.3rem; justify-content: flex-end; }
.tp-choice-opt.chosen { border-color: var(--opt); box-shadow: 0 0 0 3px color-mix(in srgb, var(--opt) 25%, transparent); }
.tp-choice-opt.chosen .tp-choice-mark::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--opt); }
.tp-choice-opt.correct { --opt: var(--tp-green); border-color: var(--tp-green); background: color-mix(in srgb, var(--tp-green) 18%, var(--tp-card)); box-shadow: none; }
.tp-choice-opt.correct .tp-choice-mark { color: var(--tp-green); }
.tp-choice-opt.wrong { --opt: var(--tp-red); border-color: var(--tp-red); background: color-mix(in srgb, var(--tp-red) 14%, var(--tp-card)); box-shadow: none; }
.tp-choice-opt.wrong .tp-choice-mark { color: var(--tp-red); }
.tp-choice-opt.correct .tp-choice-mark::before, .tp-choice-opt.wrong .tp-choice-mark::before { content: none; }
.tp-choice-opt.dim { opacity: 0.7; }
.tp-choice-bar { grid-area: bar; display: none; height: 7px; border-radius: 999px; background: color-mix(in srgb, var(--opt) 18%, transparent); overflow: hidden; margin-top: 0.45rem; }
.tp-choice-bar > span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--opt); transition: width 0.7s cubic-bezier(0.2, 0.9, 0.3, 1); }
.tp-choice-count { grid-area: count; display: none; font-size: 0.74rem; font-weight: 700; color: var(--tp-muted-fg); margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.tp-choice.revealed .tp-choice-bar, .tp-choice.revealed .tp-choice-count { display: block; }
.tp-choice.revealed .tp-choice-opt { min-height: 0; }

/* ---------- PWA hint ---------- */
.tp-pwa { position: relative; }
.tp-pwa-close { min-width: 36px; min-height: 36px; border-radius: 10px; flex-shrink: 0; }
.tp-pwa .tp-btn-sm { min-height: 36px; padding: 0.35rem 0.85rem; flex-shrink: 0; }

/* ---------- motion ---------- */
@keyframes tp-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes tp-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes tp-pop { 0% { transform: scale(0.8); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@keyframes tp-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.tp-rise { animation: tp-rise 0.4s ease both; }
.tp-pop { animation: tp-pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.tp-shake { animation: tp-shake 0.35s ease; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- host console (batch 3: avatars, choice grid, autopilot, phone bar) ---------- */
.tp-avatar-emoji, .tp-avatar-letter {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.15rem; line-height: 1; background: var(--tp-muted);
}
.tp-avatar-letter { font-size: 0.85rem; font-weight: 800; background: var(--tp-secondary); color: var(--tp-secondary-fg); text-transform: uppercase; }
.tp-avatar-emoji.sm, .tp-avatar-letter.sm { width: 24px; height: 24px; border-radius: 7px; font-size: 0.9rem; }
.tp-avatar-letter.sm { font-size: 0.7rem; }
.tp-podium .tp-avatar-emoji, .tp-podium .tp-avatar-letter { width: 40px; height: 40px; border-radius: 12px; font-size: 1.4rem; background: rgba(255,255,255,0.16); color: #fff; margin: 0 auto 0.3rem; display: flex; }
.tp-finale-winner .tp-avatar-emoji, .tp-finale-winner .tp-avatar-letter { width: 1.15em; height: 1.15em; border-radius: 0.3em; font-size: 0.9em; vertical-align: -0.15em; background: rgba(255,255,255,0.16); color: #fff; margin-right: 0.2em; }

/* 2x2 answer options on the host hero */
.tp-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; margin-top: 1rem; }
.tp-option {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem 0.8rem; border-radius: 14px;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.22); color: #fff;
  font-weight: 700; font-size: 0.98rem; line-height: 1.25; min-height: 52px;
}
.tp-option > * { position: relative; z-index: 1; }
.tp-option-letter { width: 28px; height: 28px; border-radius: 9px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.22); font-size: 0.8rem; font-weight: 800; }
.tp-option-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tp-option-count { font-size: 0.78rem; font-weight: 800; color: var(--tp-on-hero-muted); white-space: nowrap; }
.tp-option-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(255,255,255,0.16); transition: width 0.6s ease; z-index: 0; }
.tp-option.correct { background: var(--tp-green); border-color: var(--tp-green); color: #fff; }
.tp-option.correct .tp-option-letter { background: rgba(255,255,255,0.3); }
.tp-option.correct .tp-option-count { color: #fff; }
.tp-option.correct .tp-option-bar { background: rgba(255,255,255,0.22); }
.tp-option.dim { opacity: 0.75; }
@media (max-width: 575.98px) { .tp-options { grid-template-columns: 1fr; gap: 0.45rem; } }

/* question editor: kind pill + options */
.tp-q-options { list-style: none; margin: 0.4rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.3rem 0.75rem; }
.tp-q-options li { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; color: var(--tp-ink-soft); min-width: 0; }
.tp-q-options li span { overflow-wrap: anywhere; }
.tp-q-options li.correct { color: var(--tp-fg); font-weight: 700; }
.tp-q-options .tp-opt-letter { width: 22px; height: 22px; border-radius: 7px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 0.68rem; font-weight: 800; background: var(--tp-muted); color: var(--tp-muted-fg); }
.tp-q-options li.correct .tp-opt-letter { background: var(--tp-green); color: #fff; }
@media (max-width: 575.98px) { .tp-q-options { grid-template-columns: 1fr; } }
.tp-kind-toggle { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tp-kind-toggle .tp-chip { padding: 0.4rem 0.85rem; font-size: 0.85rem; }
.tp-opt-edit { display: flex; align-items: center; gap: 0.5rem; }
.tp-opt-edit + .tp-opt-edit { margin-top: 0.4rem; }
.tp-opt-edit .tp-opt-letter { width: 28px; height: 28px; border-radius: 9px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 800; background: var(--tp-muted); color: var(--tp-muted-fg); }
.tp-opt-edit .tp-opt-check { width: 28px; text-align: center; font-weight: 800; color: var(--tp-green); opacity: 0; flex-shrink: 0; }
.tp-opt-edit.is-correct .tp-opt-letter { background: var(--tp-green); color: #fff; }
.tp-opt-edit.is-correct .tp-opt-check { opacity: 1; }
.tp-opt-edit.is-correct .form-control { border-color: var(--tp-green); }

/* autopilot switch + shortcuts hint */
.tp-switch { display: inline-flex; align-items: center; gap: 0.55rem; margin: 0; cursor: pointer; font-weight: 700; font-size: 0.88rem; color: var(--tp-ink-soft); }
.tp-switch .form-check-input {
  width: 2.6em; height: 1.4em; margin: 0; cursor: pointer; flex-shrink: 0; border-radius: 2em;
  background-color: var(--tp-muted); border-color: var(--tp-input);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%2377728c'/%3e%3c/svg%3e");
  background-position: left center; background-repeat: no-repeat; background-size: contain;
  transition: background-position 0.15s ease-in-out, background-color 0.15s;
}
.tp-switch .form-check-input:checked { background-position: right center; background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e"); }
.tp-switch .form-check-input:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--tp-violet) 18%, transparent); border-color: var(--tp-violet); }
.tp-switch .form-check-input:checked { background-color: var(--tp-pink); border-color: var(--tp-pink); }
.tp-switch .tp-switch-sub { font-weight: 600; color: var(--tp-muted-fg); }
.tp-autonext { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 800; font-size: 0.88rem; color: var(--tp-violet); font-variant-numeric: tabular-nums; }
.tp-autonext:empty { display: none; }
.tp-kbd-hint { flex-basis: 100%; font-size: 0.75rem; color: var(--tp-muted-fg); font-weight: 600; }
.tp-kbd-hint kbd { font-family: var(--tp-font); font-size: 0.7rem; font-weight: 800; background: var(--tp-muted); color: var(--tp-fg); border: 1px solid var(--tp-border); border-radius: 6px; padding: 0.1rem 0.4rem; }
@media (max-width: 991.98px) { .tp-kbd-hint { display: none; } }

/* start countdown overlay (host) */
.tp-start-overlay .tp-countdown { color: #fff; }
.tp-start-overlay .tp-start-go { font-size: clamp(3rem, 14vw, 6rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1; color: var(--tp-yellow); }

/* host on a phone: the controls bar is pinned to the bottom of the screen (one-handed hosting);
   on desktop it is a plain card at the top of the column. */
#controlsBar.tp-sticky-bottom { background: var(--tp-card); padding: 0.9rem 1rem; }
@media (min-width: 992px) { #controlsBar.tp-sticky-bottom { position: static; } }
@media (max-width: 991.98px) {
  #hostApp { padding-bottom: 7.5rem; }
  #controlsBar.tp-sticky-bottom {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
    border-radius: var(--tp-radius) var(--tp-radius) 0 0; border-bottom: 0;
    padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 30px -18px rgba(33, 27, 61, 0.45);
    gap: 0.45rem;
  }
  #controlsBar.tp-sticky-bottom .tp-btn:not(.d-none) { flex: 1 1 auto; min-height: 46px; padding: 0.5rem 0.8rem; font-size: 0.9rem; }
  #controlsBar.tp-sticky-bottom .tp-hint { font-size: 0.78rem; order: -1; }
  #controlsBar.tp-sticky-bottom .tp-switch { font-size: 0.82rem; margin-left: auto; }
  #controlsBar.tp-sticky-bottom .tp-switch .tp-switch-sub { display: none; }
  #controlsBar.tp-sticky-bottom .tp-autonext { flex-basis: 100%; }
  .toast-container { bottom: 8rem; }
}
}

/* ---------- auth extras ---------- */
.tp-turnstile { display: flex; justify-content: center; min-height: 0; }
.tp-turnstile:empty { display: none; }
.tp-check-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.45rem; }
.tp-check-list li { display: flex; align-items: flex-start; gap: 0.55rem; }
.tp-check-list li .bi { margin-top: 0.1rem; }
.tp-check-list li .bi { font-size: 1.05rem; }
.tp-check-list li.off { color: var(--tp-muted-fg); }
