:root,
:root[data-theme="light"] {
  color-scheme: light;
  --background: #f6f7f9;
  --panel: #ffffff;
  --control: #ffffff;
  --row: #ffffff;
  --border: #d9dee7;
  --text: #151922;
  --muted: #667085;
  --soft: #eef2f7;
  --primary: #2457d6;
  --primary-hover: #1c43a5;
  --primary-contrast: #ffffff;
  --primary-soft: #eef3ff;
  --primary-soft-border: #bfd0ff;
  --primary-soft-text: #173b8f;
  --selected-bg: #f3f6ff;
  --focus-ring: #89a8ff;
  --good: #116b3a;
  --bad: #9b1c1c;
  --correct-border: #6fc78e;
  --correct-bg: #eaf7ef;
  --correct-fill: #ecf7f0;
  --correct-letter: #ccebd8;
  --incorrect-border: #e19a9a;
  --incorrect-bg: #fff0f0;
  --incorrect-fill: #fff0f0;
  --incorrect-letter: #f7d4d4;
  --bar-fill: #e9efff;
  --log-bg: #111827;
  --log-text: #eef2ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #0f1218;
  --panel: #171b23;
  --control: #1d2330;
  --row: #1a202b;
  --border: #303847;
  --text: #eef2f8;
  --muted: #9aa6b8;
  --soft: #222936;
  --primary: #7ca3ff;
  --primary-hover: #9bb8ff;
  --primary-contrast: #09111f;
  --primary-soft: #192847;
  --primary-soft-border: #345a9e;
  --primary-soft-text: #c3d4ff;
  --selected-bg: #1d2b49;
  --focus-ring: #a8c0ff;
  --good: #82dca6;
  --bad: #ff9b9b;
  --correct-border: #357e57;
  --correct-bg: #183527;
  --correct-fill: #1b3d2b;
  --correct-letter: #214b36;
  --incorrect-border: #8a454f;
  --incorrect-bg: #3b2025;
  --incorrect-fill: #43242a;
  --incorrect-letter: #512c32;
  --bar-fill: #24365c;
  --log-bg: #090c12;
  --log-text: #dbe7ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
  transition:
    background-color 160ms ease,
    color 160ms ease;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-contrast);
  font-weight: 700;
}

button.primary:active,
button.primary:hover {
  background: var(--primary-hover);
}

button.danger {
  border-color: var(--incorrect-border);
  background: var(--incorrect-bg);
  color: var(--bad);
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--control);
  color: var(--text);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.app {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 16px;
}

.topbar > div:first-child {
  min-width: 0;
}

.topbar h1,
.section-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 1.7rem;
}

.section-head h2 {
  font-size: 1.1rem;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}

.join-form {
  display: grid;
  gap: 12px;
}

.host-controls {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.host-controls:not([hidden]) {
  display: grid;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.status-stack {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--primary-soft-border);
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.pill.muted {
  border-color: var(--border);
  background: var(--soft);
  color: var(--muted);
}

.link-button {
  min-height: 32px;
  border: 0;
  padding: 4px 2px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.theme-toggle {
  min-height: 32px;
  border-color: var(--border);
  padding: 4px 10px;
  background: var(--control);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 800;
}

.quote-text {
  min-height: 88px;
  margin: 0 0 12px;
  padding: 16px;
  border-radius: 8px;
  background: var(--soft);
  font-size: 1.3rem;
  font-weight: 750;
}

.timer-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.timer-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--soft);
}

.timer-bar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 120ms linear;
}

.timer-text {
  min-width: 34px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 900;
  text-align: right;
}

.answer-grid {
  display: grid;
  gap: 10px;
}

.answer-button {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 12px;
  text-align: left;
}

.answer-letter {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-weight: 900;
}

.answer-button.selected {
  border-color: var(--primary);
  background: var(--selected-bg);
}

.answer-button.correct {
  border-color: var(--correct-border);
  background: var(--correct-bg);
}

.answer-button.incorrect {
  border-color: var(--incorrect-border);
  background: var(--incorrect-bg);
}

.answer-button.correct:disabled,
.answer-button.incorrect:disabled {
  opacity: 1;
}

.answer-button.correct .answer-letter {
  background: var(--correct-letter);
  color: var(--good);
}

.answer-button.incorrect .answer-letter {
  background: var(--incorrect-letter);
  color: var(--bad);
}

.answer-status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.answer-status.good {
  color: var(--good);
}

.answer-status.bad {
  color: var(--bad);
}

.dashboard-grid {
  display: grid;
  gap: 12px;
}

.list {
  display: grid;
  gap: 8px;
}

.list-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--row);
  overflow: hidden;
}

.list-row strong,
.list-row span,
.stat-row strong,
.stat-row span {
  position: relative;
  z-index: 1;
}

.list-row strong {
  overflow-wrap: anywhere;
}

.list-row span {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.stats-list {
  display: grid;
  gap: 8px;
}

.stat-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  overflow: hidden;
}

.bar-row::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill, 0%);
  background: var(--bar-fill);
  transition: width 180ms ease;
}

.stat-row.bar-row.correct::before {
  background: var(--correct-fill);
}

.stat-row.bar-row.incorrect::before {
  background: var(--incorrect-fill);
}

.debug-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
}

#messageLog {
  max-height: 260px;
  overflow: auto;
  margin: 12px 0 0;
  border-radius: 8px;
  background: var(--log-bg);
  color: var(--log-text);
  padding: 12px;
  font-size: 0.8rem;
}

[hidden] {
  display: none !important;
}

@media (min-width: 720px) {
  .app {
    padding: 24px;
  }

  .topbar h1 {
    font-size: 2rem;
  }

  .join-form {
    grid-template-columns: 1fr 1fr auto;
    align-items: end;
  }

  .host-controls:not([hidden]) {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .answer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
