:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7c77;
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  --accent-ink: #ffffff;
  --bar: #2a78d6;
  --bar-other: #a9a8a2;
  --track: #ebe9e4;
  --good: #1a7f37;
  --danger: #c4312f;
  --warn: #9a6700;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262624;
    --border: #34332f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8d8c84;
    --accent: #3987e5;
    --accent-soft: #1c3a5e;
    --bar: #3987e5;
    --bar-other: #6b6a64;
    --track: #2a2a27;
    --good: #4ac26b;
    --danger: #f47067;
    --warn: #d29922;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #262624;
  --border: #34332f;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #8d8c84;
  --accent: #3987e5;
  --accent-soft: #1c3a5e;
  --bar: #3987e5;
  --bar-other: #6b6a64;
  --track: #2a2a27;
  --good: #4ac26b;
  --danger: #f47067;
  --warn: #d29922;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.eyebrow {
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.muted { color: var(--muted); }

/* Buttons ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  padding: 0.6em 1.1em;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 0.35em 0.7em; font-size: 0.875rem; }

/* Badges ----------------------------------------------------------------- */
.letter {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 1.8em;
  height: 1.8em;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.85em;
}

/* Timer ------------------------------------------------------------------ */
.timer { display: flex; align-items: center; gap: 0.75em; }
.timer-track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  border-radius: 3px;
  transform-origin: left;
}
.timer.urgent .timer-fill { background: var(--danger); }
.timer-text { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.5ch; text-align: right; }
.timer.urgent .timer-text { color: var(--danger); }

/* Bar chart -------------------------------------------------------------- */
.bars { display: grid; gap: 0.9em; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "label value" "track track";
  gap: 0.35em 1em;
  align-items: end;
}
.bar-label { grid-area: label; display: flex; align-items: center; gap: 0.6em; min-width: 0; }
.bar-label .text { overflow-wrap: anywhere; }
.bar-value { grid-area: value; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-2); }
.bar-value strong { color: var(--text); font-weight: 700; margin-right: 0.35em; }
.bar-track {
  grid-area: track;
  height: 1.1em;
  border-radius: 4px;
  background: var(--track);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--bar);
  border-radius: 0 4px 4px 0;
  transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.bar-row.is-top .bar-label .text { font-weight: 700; }
.bar-row.is-top .letter { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.you-tag {
  font-size: 0.7em;
  font-weight: 700;
  padding: 0.15em 0.5em;
  border-radius: 999px;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  white-space: nowrap;
}
.chart-note { margin-top: 0.9em; font-size: 0.85em; color: var(--muted); }

/* Open-answer groups ----------------------------------------------------- */
.groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18em), 1fr));
  gap: 0.9em;
}
.group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em 1.1em;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  min-width: 0;
  animation: rise 0.5s both;
}
.group > * { flex-shrink: 0; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75em; }
.group-label { font-weight: 700; font-size: 1.1em; overflow-wrap: anywhere; }
.group-count { font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.group-count strong { color: var(--text); }
.group-share { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.group-share > div { height: 100%; background: var(--bar); border-radius: 0 3px 3px 0; }
.group.other .group-share > div { background: var(--bar-other); }
.group-summary { color: var(--text-2); font-size: 0.9em; }
.quotes { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35em; }
.quotes li {
  font-size: 0.9em;
  padding-left: 0.75em;
  border-left: 2px solid var(--border);
  overflow-wrap: anywhere;
}
.quotes .times { color: var(--muted); font-size: 0.85em; margin-left: 0.3em; }
.quotes .more { border: none; padding-left: 0; color: var(--muted); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.spinner {
  width: 1.2em;
  height: 1.2em;
  border-radius: 50%;
  border: 3px solid var(--track);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 0.75em; color: var(--text-2); }

.empty { color: var(--muted); padding: 1em 0; }

.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  display: inline-block;
  flex: none;
}
.conn-dot.on { background: var(--good); }

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