/* ============ base ============ */
/* Dark is the default theme; the light overrides below kick in when
   <html data-theme="light"> is set (see theme.js). */
:root {
  --bg: #0d1117;
  --panel: #161d27;
  --panel-2: #1d2634;
  --border: #2a3547;
  --text: #e8ebf1;
  --muted: #97a3b6;
  --primary: #3b82f6;
  --accent: #8b5cf6;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --red: #E53935;
  --blue: #1E88E5;
  --yellow: #FDD835;
  --green: #43A047;
  /* nav backdrop tint — derived from --bg so it follows the theme */
  --nav-bg: color-mix(in srgb, var(--bg) 88%, transparent);
}

:root[data-theme="light"] {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #eef2f8;
  --border: #d3dae6;
  --text: #14203a;
  --muted: #5a6a85;
  --primary: #2563eb;
  --accent: #7c3aed;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --nav-bg: color-mix(in srgb, var(--bg) 88%, transparent);
}

/* Smooth the flip between themes without animating page load. */
body { transition: background-color .2s ease, color .2s ease; }

* { box-sizing: border-box; }

/* the hidden attribute must win over display rules like .row { display:flex } */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 700; }
a { color: var(--primary); text-decoration: none; }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }

/* ============ site chrome ============ */
.site-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--nav-bg);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(8px);
}
.site-nav nav { display: flex; align-items: center; }
.site-nav .brand {
  color: var(--text); font-weight: 800; font-size: 1.1rem;
  display: flex; align-items: center; gap: 4px;
}
.brand-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.brand-dot.red { background: var(--red); }
.brand-dot.blue { background: var(--blue); }
.brand-dot.yellow { background: var(--yellow); }
.brand-dot.green { background: var(--green); margin-right: 8px; }
.site-nav nav a { color: var(--muted); margin-left: 22px; font-weight: 600; }
.site-nav nav a:hover { color: var(--text); }

.site-main { padding: 28px; max-width: 1500px; margin: 0 auto; }

/* ============ landing ============ */
.landing { text-align: center; padding: 48px 0; }
.landing h1 { font-size: 2.6rem; }
.landing .tagline { color: var(--muted); font-size: 1.15rem; margin-bottom: 40px; }
.landing-cards { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.landing-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 30px 26px; width: 300px; color: var(--text);
  transition: transform .15s, border-color .15s;
}
.landing-card:hover { transform: translateY(-4px); border-color: var(--accent); }
.landing-card .landing-icon { font-size: 2.4rem; margin-bottom: 10px; }
.landing-card p { color: var(--muted); }
.landing-houses { margin-top: 40px; display: flex; gap: 12px; justify-content: center; }
.house-pill {
  padding: 6px 18px; border-radius: 999px; font-weight: 700; font-size: .9rem;
  background: color-mix(in srgb, var(--c) 18%, transparent);
  color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
}
/* the raw house colour (esp. yellow) is unreadable as text on the light theme */
:root[data-theme="light"] .house-pill { color: color-mix(in srgb, var(--c) 55%, #000); }

/* ============ forms & buttons ============ */
label { display: block; color: var(--muted); font-size: .85rem; font-weight: 600; margin-bottom: 10px; }
input, select, textarea {
  width: 100%; margin-top: 4px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: .95rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type="color"] { padding: 2px; height: 40px; width: 52px; }
input[type="file"] { padding: 6px; }

.btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 16px; font-size: .92rem; font-weight: 600; font-family: inherit;
  cursor: pointer; white-space: nowrap; transition: filter .1s, background .1s;
}
.btn:hover { filter: brightness(1.2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.wide { width: 100%; }

.form-error { color: var(--danger); font-weight: 600; margin-bottom: 12px; }
.msg { margin-top: 12px; padding: 9px 12px; border-radius: 8px; font-weight: 600; font-size: .9rem; }
.msg.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.msg.err { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

/* ============ auth card ============ */
.auth-wrap { display: flex; justify-content: center; padding: 60px 16px; }
.auth-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px; width: 400px; max-width: 100%;
}
.auth-card h1 { text-align: center; }
.auth-sub { color: var(--muted); text-align: center; margin-top: -6px; margin-bottom: 24px; }
.auth-card .landing-houses { margin-top: 26px; }

/* ============ admin ============ */
.admin-topbar { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.status-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 14px; font-size: .85rem; font-weight: 600; color: var(--muted);
}
.chip.phase { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.chip.conn.on { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.chip.conn.off { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  background: none; border: none; color: var(--muted);
  padding: 10px 18px; font-size: .95rem; font-weight: 700; font-family: inherit; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.live-grid { display: grid; grid-template-columns: 1.1fr 1.2fr 1fr; gap: 22px; }
.qb-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 22px; }
@media (max-width: 1100px) { .live-grid, .qb-grid { grid-template-columns: 1fr; } }

.col { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px; min-width: 0; }
.col.narrow { max-width: 640px; }
.col h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 10px; }
.col h3:first-child { margin-top: 0; }
.row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 10px; }
.row.wrap { flex-wrap: wrap; }
.row label { margin-bottom: 0; }
.row .grow { flex: 1; }
.row input, .row select { margin-top: 4px; }
.hint { color: var(--muted); font-size: .9rem; }

/* question list (live tab) */
.q-list { max-height: 480px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.q-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; background: var(--panel-2);
}
.q-item .q-item-text { flex: 1; min-width: 0; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-item .q-item-meta { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.q-item.asked { opacity: .55; }
.badge {
  font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn);
}

/* current question preview */
.cur-question { border: 1px solid var(--border); border-radius: 10px; padding: 14px; background: var(--panel-2); }
.cur-question.empty { color: var(--muted); text-align: center; padding: 26px; }
.cur-question .cq-text { font-weight: 700; margin-bottom: 10px; }
.cur-question .cq-opt { padding: 5px 10px; border-radius: 7px; margin-bottom: 4px; font-size: .9rem; }
.cur-question .cq-opt.correct { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); font-weight: 700; }
.cur-question .cq-answer { margin-top: 8px; color: var(--ok); font-weight: 700; }
.cur-question img { max-width: 100%; max-height: 140px; border-radius: 8px; margin-bottom: 8px; }

.admin-timer {
  font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums;
  min-width: 90px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 4px 12px;
}
.admin-timer.low { color: var(--danger); }
.timer-row input { max-width: 100px; }

/* mini leaderboard preview inside "on screen now" */
.mini-board { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.mini-row { display: flex; align-items: center; gap: 10px; }
.mini-rank { color: var(--muted); font-size: .8rem; font-weight: 700; flex: 0 0 26px; }
.mini-name {
  font-weight: 700; font-size: .9rem; flex: 0 0 110px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mini-bar-wrap { flex: 1; height: 12px; background: var(--panel); border-radius: 999px; overflow: hidden; }
.mini-bar {
  height: 100%; border-radius: 999px; background: var(--hc);
  box-shadow: 0 0 10px color-mix(in srgb, var(--hc) 50%, transparent);
  transition: width .8s cubic-bezier(.2, .8, .2, 1);
}
.mini-score { font-weight: 800; font-variant-numeric: tabular-nums; flex: 0 0 44px; text-align: right; }

/* staged question banner (admin preview before Start) */
.staged-note {
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  color: var(--warn);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 10px;
  font-weight: 700; font-size: .85rem;
}

/* live team submissions under the current-question preview */
.cq-subs { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sub-chip {
  border-left: 4px solid var(--hc, #888);
  background: var(--panel); border-radius: 6px;
  padding: 3px 9px; font-size: .8rem; font-weight: 700;
}

/* score cards */
.score-cards { display: flex; flex-direction: column; gap: 12px; }
.score-card {
  border: 1px solid var(--border); border-left: 6px solid var(--hc, #888);
  border-radius: 10px; padding: 12px 14px; background: var(--panel-2);
}
.score-card .sc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.score-card .sc-name { font-weight: 800; }
.score-card .sc-total { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-card .sc-rank { color: var(--muted); font-size: .8rem; margin-left: 8px; }
.score-card .sc-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.score-card .sc-actions input { width: 74px; margin-top: 0; }

/* checkbox row (label + checkbox inline) */
.check-row { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check-row input { width: auto; margin: 0; accent-color: var(--accent); }

/* category chips with delete */
.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 6px 4px 12px; font-size: .82rem; font-weight: 600; color: var(--muted);
}
.cat-chip .cat-del {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: .8rem; line-height: 1; padding: 3px 7px; border-radius: 999px; font-family: inherit;
}
.cat-chip .cat-del:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 15%, transparent);
}

/* question bank table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; padding: 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table td.q-cell { max-width: 380px; }
.table tr:hover td { background: var(--panel-2); }
.img-preview { max-height: 90px; border-radius: 8px; }

/* tournaments */
.t-list { display: flex; flex-direction: column; gap: 10px; }
.t-item { border: 1px solid var(--border); border-radius: 10px; padding: 14px; background: var(--panel-2); }
.t-item .t-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.t-item .t-title { font-weight: 800; }
.t-item .t-sub { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.t-item .t-actions { display: flex; gap: 6px; }
.status-pill { font-size: .7rem; font-weight: 800; text-transform: uppercase; padding: 3px 10px; border-radius: 999px; }
.status-pill.Setup { background: color-mix(in srgb, var(--muted) 20%, transparent); color: var(--muted); }
.status-pill.Live { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.status-pill.Completed { background: color-mix(in srgb, var(--primary) 20%, transparent); color: var(--primary); }
.t-item .t-del {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: .9rem; line-height: 1; padding: 5px 9px; border-radius: 999px; font-family: inherit;
}
.t-item .t-del:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 15%, transparent);
}

.round-head { display: flex; gap: 8px; margin-bottom: 4px; }
.round-head span {
  font-size: .72rem; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
}
.round-head .rh-name { flex: 1; }
.round-head .rh-count { flex: 0 0 90px; }
.round-head .rh-x { flex: 0 0 32px; }
.round-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.round-row .rr-name { flex: 1; }
.round-row input[type="number"] { width: 90px; flex: 0 0 90px; }

/* houses */
.house-row {
  display: flex; gap: 10px; align-items: center; margin-bottom: 10px;
  border: 1px solid var(--border); border-left: 6px solid var(--hc, #888);
  border-radius: 10px; padding: 12px; background: var(--panel-2);
}
.house-row input { margin-top: 0; }
.house-row .code-input { max-width: 160px; font-weight: 700; letter-spacing: .04em; }

/* ============ theme toggle ============ */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--panel); color: var(--text);
  font-size: 1.05rem; line-height: 1; cursor: pointer;
  transition: filter .1s, border-color .1s, background .2s, color .2s;
}
.theme-toggle:hover { filter: brightness(1.15); border-color: var(--accent); }
/* in the site nav it lines up with the text links */
.site-nav nav .theme-toggle { margin-left: 22px; }

/* ============ brand logo (uploaded by admin, shown wherever applicable) ============ */
.app-logo {
  height: 34px; width: auto; max-width: 180px; object-fit: contain;
  border-radius: 6px; display: block;
}
.app-logo.on-auth { height: 64px; max-width: 240px; margin: 0 auto 14px; }
.app-logo.on-idle { height: clamp(60px, 12vh, 130px); max-width: 70%; margin: 0 auto 26px; }
.brand-logo-wrap { display: flex; align-items: center; }

/* ============ settings tab (branding + danger zone) ============ */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }
.logo-preview-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 96px; padding: 16px; margin: 12px 0;
  border: 1px dashed var(--border); border-radius: 12px; background: var(--panel-2);
}
.logo-preview-wrap img { max-height: 120px; max-width: 100%; object-fit: contain; }
.logo-preview-wrap .hint { margin: 0; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.danger-zone h3 { color: var(--danger); }

/* ============ mobile / phones ============ */
@media (max-width: 640px) {
  /* nav wraps instead of overflowing; toggle stays reachable */
  .site-nav { padding: 10px 14px; flex-wrap: wrap; gap: 6px 10px; }
  .site-nav .brand { font-size: 1rem; }
  .site-nav nav { flex-wrap: wrap; gap: 4px 6px; }
  .site-nav nav a { margin-left: 0; padding: 5px 9px; font-size: .9rem; }
  .site-nav nav .theme-toggle { margin-left: 4px; width: 34px; height: 34px; }
  .site-main { padding: 14px; }

  /* landing */
  .landing { padding: 24px 0; }
  .landing h1 { font-size: 1.8rem; }
  .landing .tagline { font-size: 1rem; margin-bottom: 24px; }
  .landing-cards { gap: 14px; }
  .landing-card { width: 100%; padding: 22px; }
  .landing-houses { flex-wrap: wrap; margin-top: 26px; }

  /* auth cards */
  .auth-wrap { padding: 24px 12px; }
  .auth-card { padding: 22px; }

  /* admin: tabs wrap instead of scrolling off-screen */
  .admin-topbar { margin-bottom: 12px; }
  .tabs { flex-wrap: wrap; gap: 2px 4px; margin-bottom: 14px; }
  .tab { padding: 8px 11px; font-size: .85rem; }

  .col { padding: 14px; }
  .col.narrow { max-width: 100%; }

  /* form rows stack rather than overflow */
  .row { flex-wrap: wrap; }
  .row .grow { flex-basis: 100%; }
  .timer-row { align-items: center; }
  .timer-row input { max-width: 100%; flex: 1 1 90px; }

  /* houses editor wraps */
  .house-row { flex-wrap: wrap; }
  .house-row .h-name { flex: 1 1 100%; }
  .house-row .code-input { max-width: 100%; flex: 1 1 100%; }

  /* scoring cards */
  .score-card .sc-actions input { flex: 1 1 64px; width: auto; }

  /* tournament round builder */
  .round-row input[type="number"] { flex-basis: 72px; width: 72px; }
  .round-head .rh-count { flex-basis: 72px; }
}
