:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface2: #eff2f7;
  --primary: #6264a7;
  --primary-hover: #4f52a7;
  --option-a: #0078d4;
  --option-a-hover: #106ebe;
  --option-b: #c239b3;
  --option-b-hover: #a52d9e;
  --text: #242424;
  --text-muted: #616161;
  --border: #d1d1d1;
  --success: #107c10;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08), 0 0 1px rgba(0, 0, 0, 0.1);
  --transition: 0.15s ease;
}

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

html { font-size: 16px; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ── Typography ── */
h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.3px; }
h2 { font-size: 1.35rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}

/* ── Inputs ── */
input, select {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(98, 100, 167, 0.2);
}
input::placeholder { color: var(--text-muted); }

select option { background: var(--surface); color: var(--text); }

/* ── Buttons ── */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 20px;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
  padding: 12px;
  font-size: 1rem;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  width: 100%;
  padding: 12px;
}
.btn-secondary:hover:not(:disabled) { background: var(--surface2); }

.btn-danger {
  background: #c0392b;
  color: #fff;
  padding: 5px 11px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}
.btn-danger:hover:not(:disabled) { background: #a93226; }

/* ── Forms ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
label { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }

.divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 20px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Error / hint text ── */
.error-msg {
  color: #c0392b;
  font-size: 0.875rem;
  min-height: 1.2em;
  margin-top: 8px;
  text-align: center;
}
.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 10px;
}

/* ── Screens ── */
.screen { display: none; width: 100%; max-width: 600px; }
.screen.active { display: flex; flex-direction: column; align-items: center; gap: 16px; }

/* ── Landing ── */
.landing-header { text-align: center; margin-bottom: 4px; }
.landing-header p { color: var(--text-muted); margin-top: 6px; font-size: 1rem; }

/* ── Lobby ── */
.room-code-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 480px;
}
.room-code-badge span {
  display: block;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 8px;
  color: var(--primary);
  margin-top: 6px;
}

.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
  min-height: 40px;
}
.player-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}
.player-chip .kick-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0 0 0 4px;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.6;
}
.player-chip .kick-btn:hover { opacity: 1; color: #c0392b; }

.lobby-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.rounds-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.rounds-row label { white-space: nowrap; color: var(--text-muted); font-size: 0.9rem; }
.rounds-row select { flex: 1; padding: 8px 12px; }

/* ── Question screen ── */
.round-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.timer-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.timer-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--option-a));
  border-radius: 3px;
  animation: shrink-bar 20s linear forwards;
}
@keyframes shrink-bar {
  from { width: 100%; }
  to   { width: 0%; }
}

.question-text {
  text-align: center;
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.35;
  margin: 8px 0;
  overflow-wrap: anywhere;
  color: var(--text);
}

.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}
@media (min-width: 520px) {
  .options { flex-direction: row; }
  .options .option-btn { flex: 1; }
}

.option-btn {
  min-height: 100px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: var(--radius);
  color: #fff;
  padding: 20px;
  text-align: center;
  line-height: 1.4;
  overflow-wrap: anywhere;
  transition: background var(--transition), transform var(--transition), opacity var(--transition), box-shadow var(--transition);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  width: 100%;
}
.option-btn.option-a { background: var(--option-a); }
.option-btn.option-a:hover:not(:disabled) {
  background: var(--option-a-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 120, 212, 0.35);
}
.option-btn.option-b { background: var(--option-b); }
.option-btn.option-b:hover:not(:disabled) {
  background: var(--option-b-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(194, 57, 179, 0.35);
}

.option-btn.chosen {
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px currentColor, 0 6px 20px rgba(0,0,0,0.15);
  transform: translateY(-2px) scale(1.02);
}
.option-btn.not-chosen { opacity: 0.35; }

.vote-status {
  color: var(--success);
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  min-height: 1.4em;
}

/* ── Results screen ── */
.results-heading { text-align: center; color: var(--text); }
.results-question {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: -8px;
}
.results-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}
@media (min-width: 520px) {
  .results-grid { flex-direction: row; }
  .result-col { flex: 1; }
}

.result-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.result-col.col-a { border-top: 3px solid var(--option-a); }
.result-col.col-b { border-top: 3px solid var(--option-b); }

.result-label {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 10px;
  overflow-wrap: anywhere;
}
.col-a .result-label { color: var(--option-a); }
.col-b .result-label { color: var(--option-b); }

.pct-bar-wrap {
  background: var(--border);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.pct-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
}
.col-a .pct-bar-fill { background: var(--option-a); }
.col-b .pct-bar-fill { background: var(--option-b); }

.vote-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.voter-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.voter-list li {
  font-size: 0.9rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
  color: var(--text);
}
.voter-list li:last-child { border-bottom: none; }

/* ── Game over ── */
.gameover-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.gameover-card h1 { font-size: 2.2rem; }

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  text-align: left;
}
.stat-row {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  font-size: 0.95rem;
}
.stat-row > span:first-child {
  color: var(--text-muted);
  min-width: 0;
}
.stat-row .stat-value {
  font-weight: 700;
  font-size: 1rem;
  text-align: right;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
}

@media (max-width: 420px) {
  .gameover-card h1 { font-size: 1.9rem; }
  .stat-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .stat-row .stat-value { text-align: left; }
}

.play-again-wrap { width: 100%; }

/* ── Disconnect banner ── */
.disconnect-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: #c0392b;
  color: #fff;
  text-align: center;
  padding: 12px;
  font-weight: 600;
  z-index: 9999;
  font-size: 0.95rem;
}
.disconnect-banner a { color: #fff; text-decoration: underline; }

/* ── Utility ── */
.hidden { display: none !important; }
.full-width { width: 100%; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

/* ── Connecting spinner ── */
.connecting {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
