/* ==========================================================================
   Fattegories - styles
   Colours, spacing and shapes are design tokens below; dark mode swaps the
   colour tokens only. Components use the tokens, never raw colours.
   ========================================================================== */

:root {
  /* Colour */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #121826;
  --text-2: #5b6475;
  --accent: #2459d6;
  --accent-hover: #1d4bb8;
  --accent-soft: #edf2fd;
  --good: #15803d;
  --good-soft: #ecf8f0;
  --bad: #c2312f;
  --bad-soft: #fdf0f0;
  --warn: #a15c07;
  --warn-soft: #fdf6e8;
  --on-accent: #ffffff;

  /* Shape and depth */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --ring: 0 0 0 3px rgba(36, 89, 214, 0.25);

  /* Spacing scale */
  --s1: 4px;  --s2: 8px;  --s3: 12px;  --s4: 16px;  --s5: 24px;  --s6: 32px;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #161a22;
  --surface-2: #1d222c;
  --border: #272d39;
  --border-strong: #363e4d;
  --text: #e7e9ee;
  --text-2: #98a1b2;
  --accent: #3d6fe0;
  --accent-hover: #5583ec;
  --accent-soft: #1b2640;
  --good: #3fb46a;
  --good-soft: #13281b;
  --bad: #ef6461;
  --bad-soft: #2d1718;
  --warn: #e2a33b;
  --warn-soft: #2c2312;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --ring: 0 0 0 3px rgba(85, 131, 236, 0.35);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }

.muted  { color: var(--text-2); }
.small  { font-size: 0.85rem; }
.center { text-align: center; }
.code   { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 700; letter-spacing: 0.08em; }

/* ---------- Layout ---------- */
header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.1rem; font-weight: 750; color: var(--accent); }
.header-right, #room-info { display: flex; align-items: center; gap: var(--s3); }

main { max-width: 760px; margin: 0 auto; padding: var(--s5) var(--s4) var(--s6); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--s5);
  margin-bottom: var(--s4);
}
.card > h2 { margin-bottom: var(--s4); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }

.row, .actions { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: flex-end; }
.actions { align-items: center; margin-top: var(--s4); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--s1); margin-bottom: var(--s4); font-size: 0.85rem; font-weight: 600; color: var(--text-2); }

input, select {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 9px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[readonly] { background: var(--surface-2); }
input::placeholder { color: var(--text-2); opacity: 0.7; }

.choices { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.choice {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.choice:hover { border-color: var(--border-strong); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice.disabled { opacity: 0.55; cursor: not-allowed; }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice > span { display: flex; flex-direction: column; }
.choice b { font-weight: 600; }
.choice .muted { font-size: 0.85rem; }

/* ---------- Buttons ---------- */
button {
  font: inherit; font-weight: 600; font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
button:hover { background: var(--surface-2); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-link { background: none; border: none; padding: 4px; color: var(--text-2); text-decoration: underline; font-weight: 500; }
.btn-link:hover { background: none; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 20px; font-size: 1rem; }
.btn-block { display: block; width: 100%; }

#theme-toggle { padding: 6px 9px; line-height: 1; font-size: 1rem; }

/* ---------- Home ---------- */
.home { max-width: 420px; margin: var(--s6) auto 0; }
.home h2 { font-size: 1.25rem; margin-bottom: var(--s5); }
.or { display: flex; align-items: center; gap: var(--s3); margin: var(--s5) 0; color: var(--text-2); font-size: 0.85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.join-row { display: flex; gap: var(--s2); }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.2em; font-family: ui-monospace, Menlo, monospace; }

/* ---------- Lobby ---------- */
.room-banner { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: var(--s2) 0 var(--s5); }
.room-code { font: 800 2rem/1.1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.15em; color: var(--accent); }

.people { list-style: none; margin: 0; padding: 0; }
.person {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: var(--s3);
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.person:last-child { border-bottom: none; }
.person.away { opacity: 0.55; }
.person-name { font-weight: 600; }
.person-tags { display: flex; align-items: center; gap: var(--s1); }
.person-score { min-width: 3ch; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.tag {
  display: inline-block; padding: 1px 8px;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px;
}
.tag-accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

.list-options { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.list-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: var(--s3) var(--s4); text-align: left; font-weight: 400;
  border-color: var(--border);
}
.list-option:hover:not(:disabled) { border-color: var(--accent); background: var(--surface); }
.list-option.chosen { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.list-option:disabled { opacity: 1; cursor: default; }
.list-name { font-weight: 650; font-size: 0.95rem; }

/* ---------- Round header (playing + review) ---------- */
.sticky-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--s4);
  margin: 0 calc(-1 * var(--s4)) var(--s4);
  padding: var(--s3) var(--s4);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.letter {
  flex-shrink: 0; width: 64px; height: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent);
  border-radius: var(--radius-lg);
  font-size: 2.1rem; font-weight: 800; line-height: 1;
}
.letter-label { font-size: 0.55rem; font-weight: 700; letter-spacing: 0.16em; opacity: 0.85; margin-bottom: 2px; }
.bar-middle { flex: 1; min-width: 0; }
.list-title { font-size: 1.15rem; font-weight: 700; }
.timer { font: 700 1.6rem/1 ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
.timer.urgent { color: var(--bad); }

/* ---------- Answering ---------- */
.answers { display: grid; gap: var(--s2); }
.answer-row {
  display: grid; grid-template-columns: 28px 1fr; gap: 2px var(--s3); align-items: center;
  padding: var(--s3) var(--s4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.answer-row .num { grid-row: span 2; color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.answer-row .cat { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.answer-row input { width: 100%; }

/* ---------- Watching (viewers and judge) ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
table.watch { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.watch th, table.watch td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.watch thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); }
table.watch tbody th { font-weight: 600; color: var(--text-2); }
table.watch tbody tr:last-child th, table.watch tbody tr:last-child td { border-bottom: none; }
table.watch td.empty { color: var(--border-strong); }
table.watch td.off { color: var(--bad); text-decoration: line-through; }

/* ---------- Review ---------- */
.entries { list-style: none; margin: 0 0 var(--s4); padding: 0; display: grid; gap: var(--s2); }
.entry {
  display: grid; gap: var(--s2);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius);
}
.entry.accepted { border-left-color: var(--good); }
.entry.rejected { border-left-color: var(--bad); }
.entry.settled  { border-left-color: var(--border); opacity: 0.75; }
.entry.rejected .answer, .entry.settled .answer { text-decoration: line-through; text-decoration-color: var(--text-2); }
.entry-main { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); }
.answer { font-size: 1.1rem; font-weight: 650; word-break: break-word; }
.mine { font-size: 0.78rem; color: var(--text-2); white-space: nowrap; }
.entry-meta { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.tally { font-size: 0.82rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.controls { display: flex; gap: var(--s2); }

.pill {
  display: inline-block; padding: 2px 10px;
  font-size: 0.75rem; font-weight: 650;
  color: var(--text-2); background: var(--surface-2); border-radius: 999px;
}
.pill-good { color: var(--good); background: var(--good-soft); }
.pill-bad  { color: var(--bad);  background: var(--bad-soft); }
.pill-warn { color: var(--warn); background: var(--warn-soft); }

.vote-btn { min-width: 84px; background: transparent; }
.vote-btn.yes { color: var(--good); border-color: var(--good); }
.vote-btn.no  { color: var(--bad);  border-color: var(--bad); }
.vote-btn.yes:hover { background: var(--good-soft); }
.vote-btn.no:hover  { background: var(--bad-soft); }
.vote-btn.yes.on { background: var(--good); color: #fff; }
.vote-btn.no.on  { background: var(--bad);  color: #fff; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%); z-index: 50;
  max-width: 90vw; padding: 10px 16px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.9rem; font-weight: 500;
}

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  header { padding: var(--s3) var(--s4); }
  .card { padding: var(--s4); }
  .person { grid-template-columns: 1fr auto; }
  .person-tags { grid-column: 1; grid-row: 2; }
  .person-score { grid-row: 1 / span 2; grid-column: 2; }
  .letter { width: 52px; height: 52px; font-size: 1.7rem; }
  .timer { font-size: 1.3rem; }
}
