/* ============================================================
   TriviaDB — shared design system
   One identity across landing / host / play / admin.
   Late-night game-show arcade: deep indigo, amethyst neon,
   a gold join-code marquee as the signature element.
   ============================================================ */

:root {
  /* Surfaces */
  --bg:            #0d0616;
  --bg-2:          #120a20;
  --surface:       #180d2b;
  --surface-2:     #21143c;
  --surface-3:     #2b1b4d;
  --border:        #33234f;
  --border-strong: #4a3370;

  /* Ink */
  --text:      #f3ecff;
  --text-dim:  #c3b3e6;
  --text-mute: #8f7cb8;

  /* Accents */
  --primary:        #a855f7;
  --primary-bright: #c084fc;
  --primary-deep:   #7c3aed;
  --primary-glow:   rgba(168, 85, 247, 0.45);
  --cyan:           #22d3ee;
  --gold:           #fcd34d;
  --gold-glow:      rgba(252, 211, 77, 0.35);
  --success:        #2dd4a7;
  --success-deep:   #10906f;
  --danger:         #fb5a6a;
  --danger-deep:    #b23140;
  --warning:        #fbbf3c;

  /* Shape */
  --radius:    14px;
  --radius-sm: 9px;
  --radius-lg: 22px;
  --ring:      0 0 0 3px var(--primary-glow);

  --font-display: "Bricolage Grotesque", "Trebuchet MS", system-ui, sans-serif;
  --font-body:    "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:    "Space Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --shadow:    0 18px 50px -22px rgba(0, 0, 0, 0.85);
  --shadow-sm: 0 8px 22px -14px rgba(0, 0, 0, 0.8);
}

*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(60rem 60rem at 12% -10%, rgba(124, 58, 237, 0.28), transparent 60%),
    radial-gradient(48rem 48rem at 108% 8%, rgba(34, 211, 238, 0.14), transparent 55%),
    radial-gradient(50rem 50rem at 50% 120%, rgba(168, 85, 247, 0.12), transparent 60%);
  background-attachment: fixed;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--primary); color: #fff; }

a { color: var(--primary-bright); text-decoration: none; }
a:hover { color: #e9d5ff; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 800; line-height: 1.05; letter-spacing: -0.02em; }

/* ---------- Top bar ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.35rem clamp(1rem, 4vw, 2.25rem);
}

header h1 {
  font-size: clamp(1.5rem, 1rem + 2vw, 2.1rem);
  background: linear-gradient(100deg, #fff 10%, var(--primary-bright) 55%, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

header nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }

header nav a,
header > a {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dim);
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.15s;
}
header nav a:hover,
header > a:hover {
  color: var(--text);
  border-color: var(--primary);
  background: rgba(168, 85, 247, 0.12);
  transform: translateY(-1px);
}

/* ---------- Page body ---------- */
main {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.5rem clamp(1rem, 4vw, 2.25rem) 4rem;
}

/* Narrower single-column pages read better centered */
body.page-play main,
body.page-host main { max-width: 720px; }
body.page-home main { max-width: 760px; }

/* ---------- Cards / sections ---------- */
section {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.25rem, 3vw, 2rem);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

section h2 {
  font-size: 1.35rem;
  margin-bottom: 1.1rem;
  color: var(--text);
}
section h2 + * { margin-top: 0; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 0.5rem;
}

.muted { color: var(--text-mute); font-size: 0.9rem; margin-bottom: 1rem; }
.muted strong { color: var(--text-dim); }

.header-right { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.session { font-size: 0.82rem; color: var(--text-mute); }
.session strong { color: var(--text-dim); font-weight: 600; }
.session a { color: var(--primary-bright); }

/* ---------- Forms ---------- */
label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-dim);
  margin-bottom: 0.9rem;
}

input, select, textarea {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input::placeholder { color: var(--text-mute); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
  background: var(--bg-2);
}
textarea { min-height: 5rem; resize: vertical; line-height: 1.5; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-mute) 50%),
                    linear-gradient(135deg, var(--text-mute) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.2rem;
  cursor: pointer;
}

/* ---------- Buttons ---------- */
button, .btn {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.72rem 1.35rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease, background 0.15s;
  background: linear-gradient(180deg, var(--primary), var(--primary-deep));
  box-shadow: 0 10px 24px -12px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
button:hover, .btn:hover { transform: translateY(-2px); box-shadow: 0 16px 30px -12px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.28); }
button:active, .btn:active { transform: translateY(0); filter: brightness(0.96); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: var(--ring), var(--shadow-sm); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border-strong);
  color: var(--text);
  box-shadow: none;
}
.btn-ghost:hover { border-color: var(--primary); background: rgba(168, 85, 247, 0.12); box-shadow: none; }

.btn-success { background: linear-gradient(180deg, var(--success), var(--success-deep)); box-shadow: 0 10px 24px -12px rgba(45, 212, 167, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25); }
.btn-danger  { background: linear-gradient(180deg, var(--danger), var(--danger-deep)); box-shadow: 0 10px 24px -12px rgba(251, 90, 106, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
.btn-sm { padding: 0.42rem 0.8rem; font-size: 0.82rem; border-radius: 8px; }

.btn-row { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-top: 0.4rem; }

/* ---------- Multi-select popover ---------- */
.field-label {
  font-size: 0.82rem; font-weight: 600; color: var(--text-dim);
  margin-bottom: 0.4rem;
}
.multiselect { position: relative; margin-bottom: 0.9rem; }
.ms-trigger {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  font: inherit; font-weight: 500; text-align: left; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 0.7rem 0.85rem;
  box-shadow: none;
}
.ms-trigger:hover { transform: none; border-color: var(--primary); box-shadow: none; }
.ms-trigger[aria-expanded="true"] { border-color: var(--primary); box-shadow: var(--ring); }
.ms-caret {
  width: 0; height: 0; flex: 0 0 auto;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 6px solid var(--text-mute);
}
.ms-popover {
  position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 0.5rem; max-height: 16rem; overflow-y: auto;
}
.ms-actions { display: flex; justify-content: flex-end; padding: 0.1rem 0.35rem 0.4rem; }
.ms-link {
  font: inherit; font-size: 0.8rem; font-weight: 600; color: var(--primary-bright);
  background: none; border: none; box-shadow: none; padding: 0.1rem 0.2rem; cursor: pointer;
}
.ms-link:hover { transform: none; box-shadow: none; text-decoration: underline; }
.ms-option {
  display: flex; flex-direction: row; align-items: center; gap: 0.55rem;
  padding: 0.45rem 0.5rem; border-radius: 7px; margin: 0;
  font-size: 0.9rem; font-weight: 500; color: var(--text); cursor: pointer;
}
.ms-option:hover { background: rgba(168, 85, 247, 0.12); }
.ms-option input { width: auto; margin: 0; accent-color: var(--primary); cursor: pointer; }

/* ============================================================
   Landing
   ============================================================ */
body.page-home #sample-question p strong { font-size: 1.15rem; color: var(--text); }
body.page-home #sample-question ul { list-style: none; margin-top: 0.9rem; display: grid; gap: 0.55rem; }
body.page-home #sample-question li {
  padding: 0.7rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
}

/* ============================================================
   Join code marquee — the signature element (host + play)
   ============================================================ */
.code-marquee {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(2.6rem, 1rem + 9vw, 4.75rem);
  letter-spacing: 0.16em;
  text-align: center;
  color: var(--gold);
  padding: 0.6rem 0.5rem 0.7rem;
  margin: 0.2rem 0 0.3rem;
  text-shadow: 0 0 26px var(--gold-glow), 0 2px 0 rgba(0, 0, 0, 0.35);
  border-top: 1px dashed var(--border-strong);
  border-bottom: 1px dashed var(--border-strong);
  background: repeating-linear-gradient(-45deg, rgba(252, 211, 77, 0.05) 0 12px, transparent 12px 24px);
}
.join-hint { text-align: center; color: var(--text-mute); font-size: 0.9rem; margin-top: 0.15rem; }
.join-hint strong { color: var(--text-dim); font-family: var(--font-mono); }

/* ---------- Lobby / status ---------- */
.lobby-head { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin: 1.3rem 0 0.9rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.8rem; font-weight: 600;
  padding: 0.4rem 0.8rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
}
.chip strong, .chip #status, .chip #player-count { color: var(--text); font-weight: 700; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 8px var(--primary); }
.chip.count::before { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

/* ---------- Player list ---------- */
#players { list-style: none; display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.3rem 0 0.5rem; }
#players:empty::after { content: "Waiting for players…"; color: var(--text-mute); font-size: 0.9rem; font-style: italic; }
#players li {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-weight: 600; font-size: 0.9rem;
  animation: pop 0.25s ease;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Question + answers ---------- */
.question-area:not(:empty) { margin-top: 1.4rem; }
#question p strong { font-family: var(--font-display); font-size: clamp(1.15rem, 0.9rem + 1vw, 1.55rem); font-weight: 800; display: block; margin-bottom: 1rem; line-height: 1.2; }

/* host renders <ol><li>, play renders <ol><li><button.answer> */
#question ol { list-style: none; display: grid; gap: 0.7rem; grid-template-columns: 1fr 1fr; counter-reset: opt; }
#question ol li { counter-increment: opt; }

/* host: plain option rows */
body.page-host #question ol li {
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 600;
  position: relative;
}
body.page-host #question ol li.correct {
  border-color: var(--success);
  background: linear-gradient(180deg, rgba(45, 212, 167, 0.18), rgba(45, 212, 167, 0.06));
  color: #d8fff3;
  box-shadow: 0 0 0 1px var(--success), 0 10px 26px -16px rgba(45, 212, 167, 0.6);
}

/* play: buzzer buttons */
.answer {
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  padding: 1.1rem 1.15rem 1.1rem 3rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  position: relative;
}
.answer::before {
  content: counter(opt, upper-alpha);
  position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%);
  width: 1.6rem; height: 1.6rem; display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 0.85rem; font-weight: 700;
  color: #fff; border-radius: 7px;
  background: linear-gradient(180deg, var(--primary), var(--primary-deep));
  box-shadow: 0 0 12px var(--primary-glow);
}
.answer:not(:disabled):hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 16px 32px -18px var(--primary-glow); }
.answer:disabled { cursor: default; opacity: 0.55; }
.answer:disabled:hover { transform: none; }

#question p:last-child:not(:first-child) {
  margin-top: 1rem; text-align: center; font-size: 0.95rem; color: var(--text-dim);
}
#question p:last-child strong { color: var(--success); font-family: var(--font-mono); }

/* ---------- Timer ---------- */
#timer:not(:empty) {
  margin-top: 1.2rem;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.6rem;
  text-align: center;
  color: var(--gold);
  text-shadow: 0 0 16px var(--gold-glow);
}

/* ============================================================
   Play — join / score
   ============================================================ */
body.page-play #status { }
.play-meta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
#my-score { font-family: var(--font-mono); font-weight: 700; color: var(--gold); }

/* ============================================================
   Admin
   ============================================================ */
body.page-admin main { max-width: 1120px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.9rem; margin-bottom: 1.2rem; }
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat .num { font-family: var(--font-mono); font-weight: 700; font-size: 1.9rem; color: var(--text); line-height: 1; }
.stat .num.accent { color: var(--primary-bright); }
.stat .lbl { font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-mute); margin-top: 0.45rem; }
.stat-break { margin-top: 0.9rem; font-size: 0.85rem; color: var(--text-dim); line-height: 1.7; }
.stat-break b { color: var(--text); font-weight: 700; }

.toolbar { display: flex; gap: 0.9rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.1rem; }
.toolbar label { margin-bottom: 0; min-width: 11rem; flex: 1 1 11rem; }
.toolbar button { flex: 0 0 auto; }

/* Table */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 640px;
}
thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left;
  font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-mute); font-weight: 700;
  padding: 0.75rem 0.9rem;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
tbody td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-dim); }
tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.014); }
tbody tr:hover td { background: rgba(168, 85, 247, 0.08); color: var(--text); }
tbody td:first-child { color: var(--text); font-weight: 500; max-width: 34rem; }
tbody tr:last-child td { border-bottom: none; }
#questions tbody:empty::after { content: "No questions match these filters."; }
#questions:has(tbody:empty)::after { content: ""; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0.25rem 0.55rem; border-radius: 999px;
  border: 1px solid var(--border-strong); color: var(--text-dim);
  background: var(--surface-2); white-space: nowrap;
}
.badge.easy   { color: #7ff0cf; border-color: rgba(45, 212, 167, 0.4); background: rgba(45, 212, 167, 0.1); }
.badge.medium { color: #ffe08a; border-color: rgba(251, 191, 60, 0.4); background: rgba(251, 191, 60, 0.1); }
.badge.hard   { color: #ffb3bc; border-color: rgba(251, 90, 106, 0.4); background: rgba(251, 90, 106, 0.12); }
.badge.yes    { color: #7ff0cf; border-color: rgba(45, 212, 167, 0.45); background: rgba(45, 212, 167, 0.12); }
.badge.no     { color: var(--text-mute); }

.row-actions { display: flex; gap: 0.4rem; white-space: nowrap; }

/* Add-question form: two columns on wide screens */
#add-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
#add-form label:nth-child(4), /* Question textarea */
#add-form label:nth-child(6), /* Incorrect textarea */
#add-form > button { grid-column: 1 / -1; }
#add-form > button { justify-self: start; }

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  #question ol { grid-template-columns: 1fr; }
  #add-form { grid-template-columns: 1fr; }
  header { justify-content: center; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
