/* /host — the control panel.
 *
 * Deliberately not themed. A venue's Halloween pack can make the player and screen
 * views as dark and atmospheric as it likes; the host still has to read this on a
 * phone, one-handed, under a stage light, while a room waits. So: flat surfaces,
 * strong contrast, big hit areas, no decoration.
 */

:root {
  --bg: #0B0A14;
  --surface: #16142440;
  --panel: #171528;
  --panel-2: #1F1C33;
  --line: #2C2844;
  --text: #F2F0FA;
  --muted: #9A94B8;
  --primary: #FFE500;
  --accent: #00E5FF;
  --danger: #FF3B6B;
  --ok: #3DDC84;
  --radius: 14px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Hiding, once, for everything.
 *
 * The browser's own [hidden] rule is a bare attribute selector, so any class rule
 * that sets `display` outranks it and the element stays on screen. That bit us for
 * real: the join-code box kept its `display: grid` after a QR scan had already
 * filled the code in, so players arriving by QR were still shown a box asking them
 * to type something. Every `.thing[hidden] { display: none }` below this line was
 * the same bug found one element at a time. This rule ends the class of them. */
[hidden] { display: none !important; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0 0 12px; font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.4rem; }

a { color: var(--accent); }

.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.pane { padding: 16px; max-width: 1280px; margin: 0 auto; }
.pane[hidden] { display: none; }
.centred { min-height: 100dvh; display: grid; place-items: center; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

/* ---------------- forms ---------------- */
label { display: block; margin: 12px 0 6px; font-size: 13px; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin-top: 14px; }
label.check input { width: 20px; height: 20px; accent-color: var(--primary); }

input, select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .14s var(--ease), background-color .16s var(--ease), border-color .16s var(--ease);
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .42; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #0B0A14; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #0B0A14; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #0B0A14; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-block { width: 100%; margin-top: 18px; }
.btn-sm { min-height: 38px; padding: 6px 14px; font-size: 14px; }

.err {
  margin: 14px 0 0; padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 59, 107, .14);
  color: var(--danger);
  font-size: 14px; font-weight: 600;
}
.err[hidden] { display: none; }

/* ---------------- auth ---------------- */
.auth-card { width: min(420px, 92vw); text-align: left; }
.auth-card .mark { display: block; margin: 0 auto 12px; }
.auth-card h1 { text-align: center; margin-bottom: 18px; }
.auth-card .muted { text-align: center; margin: 14px 0 0; }

/* ---------------- topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0 14px;
  margin-bottom: 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar strong { font-size: 16px; }

.pill {
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--panel-2);
  font-size: 12px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
}
.pill-quiet { color: var(--muted); }
.pill[data-status="live"] { background: rgba(61, 220, 132, .18); color: var(--ok); }
.pill[data-status="paused"] { background: rgba(255, 229, 0, .16); color: var(--primary); }
.pill[data-status="ended"] { background: rgba(255, 59, 107, .16); color: var(--danger); }

.joincode {
  font-family: "Righteous", system-ui, sans-serif;
  font-size: 22px; letter-spacing: .16em;
  color: var(--primary);
}

/* ---------------- setup ---------------- */
.setup-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 16px; align-items: start; }

.session-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.session-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.session-list .s-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-list .s-code { font-family: "Righteous", system-ui, sans-serif; color: var(--primary); letter-spacing: .1em; }

/* ---------------- control bar ---------------- */
.controlbar {
  position: sticky; top: 58px; z-index: 25;
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.ctrl-group { display: flex; gap: 8px; flex-wrap: wrap; }
.controlbar .btn { min-width: 84px; }

.modes { margin-left: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px; gap: 4px; }
.mode-btn {
  min-height: 38px;
  padding: 6px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: background-color .16s var(--ease), color .16s var(--ease);
}
.mode-btn.is-on { background: var(--accent); color: #0B0A14; }

/* ---------------- deck strip ---------------- */
.deckstrip {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  scrollbar-width: thin;
}
.deck-item {
  flex: none;
  min-width: 130px; max-width: 190px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  transition: border-color .16s var(--ease), background-color .16s var(--ease);
}
.deck-item:hover { border-color: var(--muted); }
.deck-item.is-current { border-color: var(--accent); background: rgba(0, 229, 255, .1); }
.deck-item.is-past { opacity: .5; }
.deck-type { display: block; font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.deck-title { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.deck-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }

/* ---------------- live grid ---------------- */
.live-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 16px; align-items: start; }

.lq-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.lq-timer { font-family: "Righteous", system-ui, sans-serif; font-size: 26px; font-variant-numeric: tabular-nums; }
.lq-timer.is-urgent { color: var(--danger); }
.live-question h2 { font-size: 1.3rem; line-height: 1.25; margin-bottom: 14px; }

.lq-answer {
  display: flex; align-items: baseline; gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(61, 220, 132, .12);
  border: 1px solid rgba(61, 220, 132, .4);
  margin-bottom: 10px;
}
.lq-answer[hidden] { display: none; }
.lq-answer-label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ok); }
.lq-answer strong { font-size: 17px; }
.lq-expl { margin: 0 0 12px; font-size: 14px; }
.lq-expl[hidden] { display: none; }

.lq-progress { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.lq-bar { flex: 1; height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.lq-bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--accent); transition: width .3s var(--ease); }

/* ---------------- teams ---------------- */
.teams-head { display: flex; align-items: baseline; gap: 10px; }
.teams-head h2 { margin-bottom: 12px; }
.team-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 62vh; overflow-y: auto; }

.team-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 10px 12px;
}
.team-top { display: flex; align-items: center; gap: 10px; }
.team-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-score { font-family: "Righteous", system-ui, sans-serif; color: var(--primary); font-size: 17px; }
.team-answered { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.team-answered.is-in { background: var(--ok); }

.team-members { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.member-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--panel);
  font-size: 12px;
}
.member-chip.is-captain::before { content: "★"; color: var(--primary); }
.member-chip .flag { color: var(--primary); font-weight: 700; }
.member-chip button {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 0 0 0 2px;
}
.member-chip button:hover { color: var(--danger); }

.team-actions { display: flex; gap: 6px; margin-top: 8px; }
.team-actions .btn { min-height: 32px; padding: 4px 10px; font-size: 13px; }

/* ---------------- dialogs / toast ---------------- */
.dlg {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 20px;
  width: min(460px, 92vw);
}
.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.lb-choices { display: grid; gap: 8px; }
.lb-choices .btn { margin-top: 0; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  z-index: 100;
  padding: 11px 20px;
  border-radius: 99px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 14px; font-weight: 600;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.toast[hidden] { display: none; }

/* ---------------- big screen / cast ---------------- */
.dlg-screen { width: min(600px, 94vw); }
.screen-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 10px; }
.screen-actions .btn { flex: 1 1 auto; min-width: 140px; }

.cast-note {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.4em;
}
.cast-note.is-live { color: var(--ok); font-weight: 600; }
.cast-note.is-warn { color: var(--primary); }

.screen-share {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.screen-share img { border-radius: 10px; background: #fff; display: block; }
.screen-url {
  display: block;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--accent);
  font-size: 11px;
  word-break: break-all;
  max-height: 76px;
  overflow-y: auto;
}

@media (max-width: 620px) {
  .screen-share { grid-template-columns: 1fr; justify-items: center; text-align: center; }
}

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  .setup-grid, .live-grid { grid-template-columns: 1fr; }
  .modes { margin-left: 0; width: 100%; justify-content: space-between; }
  .mode-btn { flex: 1; }
  .controlbar { position: static; }
  .controlbar .btn { flex: 1; min-width: 0; }
  .ctrl-group { width: 100%; }
  .team-list { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ---------------- my quizzes ---------------- */
.quiz-home { padding: 18px clamp(14px, 3vw, 28px) 48px; max-width: 1100px; margin: 0 auto; }

.home-head {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.home-head h2 { margin: 0; }

.quiz-cards { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 14px; }
@media (min-width: 820px) {
  .quiz-cards { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
}

.quiz-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 10px;
  align-content: start;
}
/* A room with players waiting in it should be impossible to miss on a phone held
   at arm's length in a dark pub. */
.quiz-card.is-live {
  border-color: color-mix(in srgb, var(--good, #3DDC84) 55%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--good, #3DDC84) 22%, transparent);
}

.qc-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.qc-title { margin: 0; font-size: 18px; }
.qc-meta { margin: 0; text-transform: capitalize; }

.live-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--good, #3DDC84) 16%, transparent);
  color: var(--good, #3DDC84);
  font-size: 12px; font-weight: 700; letter-spacing: .08em;
  white-space: nowrap;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
  animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

.join-panel {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, .18);
}
.join-qr { border-radius: 8px; background: #fff; padding: 4px; flex: 0 0 auto; }
.join-details { display: grid; gap: 2px; min-width: 0; }
.join-label { margin: 0; }
.join-url { margin: 0 0 6px; font-size: 15px; font-weight: 600; word-break: break-all; }
.join-code {
  margin: 0 0 8px;
  font-family: var(--font-heading, inherit);
  font-size: 26px; letter-spacing: .14em;
  color: var(--primary);
}

.qc-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.options { padding: 14px 16px; margin-bottom: 18px; }
.options summary { cursor: pointer; font-weight: 600; }
.options > *:not(summary) { margin-top: 10px; }

/* ---------------- big-screen mirror ---------------- */
.screen-mirror { margin: 0 clamp(14px, 3vw, 28px) 16px; padding: 14px 16px 16px; }

.mirror-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.mirror-head h2 { margin: 0; font-size: 17px; }
.mirror-head .spacer { flex: 1; }

/* 16:9, because that is what a projector is, and the preview lies if it is not. */
.mirror-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #07060E;
}
.mirror-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
/* Expanded, it takes the height a host can actually read from -- still bounded, so
   the controls above it never scroll out of reach mid-question. */
.screen-mirror.is-big .mirror-frame { max-height: 74vh; }
.screen-mirror.is-big { margin-bottom: 20px; }

/* The held answer, covered by default. */
.lq-answer { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lq-peek { margin-left: auto; }
#lqCorrect.is-masked {
  color: var(--muted);
  font-style: italic;
  font-weight: 500;
  letter-spacing: .04em;
}

/* ---------------- explaining the controls ---------------- */
.help-toggle {
  width: 34px;
  padding: 0;
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
}
.help-toggle.is-on {
  border-color: var(--accent, #00E5FF);
  color: var(--accent, #00E5FF);
  background: color-mix(in srgb, var(--accent, #00E5FF) 14%, transparent);
}

.help-banner {
  margin: 0 clamp(14px, 3vw, 28px) 10px;
  padding: 9px 13px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent, #00E5FF) 40%, transparent);
  background: color-mix(in srgb, var(--accent, #00E5FF) 10%, transparent);
  color: var(--accent, #00E5FF);
  font-size: 14px;
}
.help-banner[hidden] { display: none; }

/* In help mode the bar is for reading, and it says so by dimming what it will not do. */
body.is-helping .controlbar .btn:not(.help-toggle),
body.is-helping .mode-btn,
body.is-helping .deck-actions .btn {
  cursor: help;
  opacity: .8;
}

.tip {
  position: fixed;
  z-index: 1400;
  max-width: min(320px, 82vw);
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #14131F;
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
  pointer-events: none;
}
.tip[hidden] { display: none; }
