/* Table Trivia Live: shared styles for the host screen and the phone page. */
:root {
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --bg: #E8EEF1;
  --surface: #F8FAFB;
  --ink: #14232C;
  --muted: #4F636E;
  --line: #C5D2D9;
  --accent: #0B6F79;
  --on-accent: #FFFFFF;
  --good: #17794A;
  --bad: #B3261E;
  --oa: #B54A00;
  --ob: #2457C5;
  --oc: #A3307A;
  --od: #00798C;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D1A20; --surface: #152730; --ink: #E7EFF2; --muted: #93A9B3; --line: #2A414C;
    --accent: #3FC4D0; --on-accent: #042329; --good: #4CCB86; --bad: #FF7A70;
    --oa: #FF9A52; --ob: #7DA4FF; --oc: #F07BC0; --od: #4FD1E3;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 16px; line-height: 1.5;
  padding-block: 20px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.app { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.app.narrow { max-width: 520px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; letter-spacing: -0.01em; }
.brand svg { color: var(--accent); flex: none; }
.conn { font-size: 0.85rem; font-weight: 700; color: var(--bad); border: 2px solid var(--bad); border-radius: 6px; padding: 0 8px; }

.panel { background: var(--surface); border: 2px solid var(--line); border-radius: 10px; padding: 24px; min-width: 0; }
.label { display: block; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.muted { color: var(--muted); }
.btn { font: inherit; font-weight: 700; cursor: pointer; border-radius: 8px; padding: 12px 20px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.big { padding: 16px 28px; font-size: 1.15rem; width: 100%; }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.input { font: inherit; font-size: 1.1rem; width: 100%; padding: 12px 14px; border: 2px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 0.9rem; }
.msg { color: var(--bad); font-weight: 700; min-height: 1.5em; }
kbd { font-family: var(--font-mono); font-size: 0.75rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--bg); color: var(--muted); }

/* timer */
.timer { display: flex; align-items: center; gap: 12px; }
.track { flex: 1; height: 14px; background: var(--line); border-radius: 7px; overflow: hidden; }
.fill { height: 100%; width: 100%; background: var(--accent); }
.fill.low { background: var(--bad); }
.tnum { font-family: var(--font-mono); font-weight: 700; font-size: 1.4rem; min-width: 4.4ch; text-align: right; font-variant-numeric: tabular-nums; }
.tnum.low { color: var(--bad); }

/* question card */
.qcard { background: var(--surface); border: 2px solid var(--line); border-radius: 10px; padding: 22px 24px; }
.qcard .cat { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.question { font-size: clamp(1.4rem, 3.4vw, 2.4rem); line-height: 1.18; font-weight: 700; letter-spacing: -0.01em; }

/* option colours: the host tiles and the phone buttons share them so players can match by colour */
.o0 { --o: var(--oa); } .o1 { --o: var(--ob); } .o2 { --o: var(--oc); } .o3 { --o: var(--od); }
.badge { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; font-family: var(--font-mono); font-weight: 700; font-size: 1.05rem; color: var(--o); background: color-mix(in srgb, var(--o) 16%, var(--surface)); }

/* host tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 14px; }
.tile { position: relative; overflow: hidden; display: flex; align-items: center; gap: 14px; min-height: 84px; padding: 14px 16px; border: 2px solid var(--line); border-radius: 10px; background: var(--surface); font-size: clamp(1.1rem, 2.2vw, 1.7rem); font-weight: 500; }
.tile > * { position: relative; z-index: 1; }
.tile .bar { position: absolute; z-index: 0; left: 0; top: 0; bottom: 0; width: 0; background: color-mix(in srgb, var(--o) 20%, var(--surface)); }
.tile .ttext { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.2; }
.tile .tcount { font-family: var(--font-mono); font-weight: 700; font-size: 1.2rem; }
.tile.correct { border-color: var(--good); }
.tile.correct .ttext::after { content: "  \2713"; color: var(--good); font-weight: 700; }
.tile.dim { opacity: 0.6; }

/* leaderboard */
.lb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lb li { display: grid; grid-template-columns: 2.4rem minmax(0, 1fr) auto auto; gap: 12px; align-items: baseline; border: 2px solid var(--line); border-radius: 8px; background: var(--surface); padding: 10px 16px; }
.lb li.first { border-color: var(--accent); }
.lb .rk { font-family: var(--font-mono); font-weight: 700; color: var(--muted); font-size: 1.15rem; }
.lb .nm { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; overflow-wrap: anywhere; }
.lb .dl { font-family: var(--font-mono); font-weight: 700; color: var(--good); min-width: 4.5ch; text-align: right; }
.lb .sc { font-family: var(--font-mono); font-weight: 700; font-size: 1.35rem; min-width: 5ch; text-align: right; }
.lb .sub { grid-column: 2 / -1; color: var(--muted); font-size: 0.9rem; }

/* ---------- host ---------- */
.lobby { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.joinbox { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.joinbox .where { font-size: clamp(1.1rem, 2.4vw, 1.6rem); font-weight: 700; overflow-wrap: anywhere; }
.code { font-family: var(--font-mono); font-weight: 700; font-size: clamp(3.6rem, 11vw, 7rem); letter-spacing: 0.14em; line-height: 1; }
.qr { background: #fff; padding: 10px; border-radius: 8px; width: 190px; height: 190px; }
.qr svg { display: block; width: 100%; height: 100%; }
.joinrow { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.roster { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; min-height: 2.4rem; }
.pill { display: inline-flex; align-items: center; gap: 8px; border: 2px solid var(--line); border-radius: 8px; padding: 4px 6px 4px 12px; font-weight: 700; background: var(--surface); }
.pill.off { opacity: 0.5; }
.pill button { font: inherit; font-size: 0.8rem; cursor: pointer; border: 0; background: transparent; color: var(--muted); padding: 2px 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: inherit; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; border: 2px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); padding: 7px 12px; cursor: pointer; }
.chip .n { font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.chip[aria-pressed="true"]::before { content: "\2713"; font-weight: 700; color: var(--accent); }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 8px; overflow: hidden; max-width: 100%; }
.seg button { font: inherit; font-weight: 700; border: 0; background: var(--surface); color: var(--ink); padding: 9px 16px; cursor: pointer; }
.seg button + button { border-left: 2px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 18px; }
.hud { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hud .where { font-weight: 700; font-size: 1.1rem; }
.hud .where span { color: var(--muted); font-weight: 500; }
.hud .right { display: flex; align-items: center; gap: 12px; }
.answered { font-weight: 700; }
.nextbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.nextbar p { flex: 1 1 240px; font-weight: 500; }
.reveal-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.headline { font-family: var(--font-display); font-weight: 800; font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1.05; }

/* ---------- phone ---------- */
.phone { display: flex; flex-direction: column; gap: 16px; }
.phone .qtext { font-size: clamp(1.3rem, 5.4vw, 1.7rem); line-height: 1.2; font-weight: 700; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 380px) { .answers { grid-template-columns: 1fr; } }
.abtn { font: inherit; font-weight: 700; font-size: 1.1rem; text-align: left; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 10px; min-height: 120px; width: 100%; padding: 12px; background: color-mix(in srgb, var(--o) 10%, var(--surface)); color: var(--ink); border: 3px solid var(--o); border-radius: 10px; }
.abtn .l { font-family: var(--font-mono); font-size: 1.5rem; color: var(--o); line-height: 1; }
.abtn .t { overflow-wrap: anywhere; line-height: 1.2; font-weight: 500; }
.abtn:disabled { cursor: default; }
.abtn.dim { opacity: 0.45; }
.abtn.picked { background: color-mix(in srgb, var(--o) 30%, var(--surface)); opacity: 1; }
.big-status { font-family: var(--font-display); font-weight: 800; font-size: clamp(2rem, 9vw, 2.8rem); line-height: 1.05; }
.big-status.good { color: var(--good); }
.big-status.bad { color: var(--bad); }
.pts { font-family: var(--font-mono); font-weight: 700; font-size: 2.4rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 0; }
.stats div { border-top: 2px solid var(--line); padding-top: 8px; }
.stats dt { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-family: var(--font-mono); font-weight: 700; font-size: 1.35rem; }
.banner { border: 2px solid var(--bad); color: var(--bad); border-radius: 8px; padding: 8px 12px; font-weight: 700; }
.spinner-note { text-align: center; padding: 28px 8px; }

@media (max-width: 820px) {
  .lobby, .reveal-grid { grid-template-columns: minmax(0, 1fr); }
  .panel { padding: 18px; }
}
