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

:root {
  --color-bg: #0f0f1a;
  --color-surface: #1a1a2e;
  --color-border: #2a2a4a;
  --color-text: #ecf0f1;
  --color-text-dim: #7f8c8d;
  --color-correct: #27ae60;
  --color-wrong: #c0392b;
  --color-open: #2ecc71;
  --color-reset: #95a5a6;
  --color-accent: #3498db;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

header h1 {
  font-size: 1.4rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.room-id {
  font-size: 1.2rem;
  font-weight: bold;
  color: #f1c40f;
  background: rgba(241, 196, 15, 0.15);
  padding: 4px 12px;
  border-radius: 6px;
  letter-spacing: 2px;
}

.btn-new-room {
  font-size: 0.75rem;
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-dim);
  cursor: pointer;
}

.btn-new-room:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text);
}

.status-connected {
  color: #2ecc71;
  font-size: 0.85rem;
}

.status-connected::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  margin-right: 6px;
}

.status-disconnected {
  color: #e74c3c;
  font-size: 0.85rem;
}

.status-disconnected::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e74c3c;
  margin-right: 6px;
}

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 20px;
}

section h2 {
  font-size: 1rem;
  color: var(--color-text-dim);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Players Table */
#player-table {
  width: 100%;
  border-collapse: collapse;
}

#player-table th,
#player-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

#player-table th {
  color: var(--color-text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.player-online {
  color: #2ecc71;
}

.player-offline {
  color: #e74c3c;
}

.player-won {
  color: #f1c40f;
}

.player-eliminated {
  color: #95a5a6;
}

.row-won {
  background: rgba(241, 196, 15, 0.1);
}

.row-eliminated {
  opacity: 0.5;
}

#no-players {
  color: var(--color-text-dim);
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* Buzz Section */
#phase-display {
  font-size: 1.3rem;
  font-weight: bold;
  margin-bottom: 12px;
  padding: 10px;
  border-radius: 8px;
  text-align: center;
}

#phase-display.idle {
  background: #2c3e50;
}

#phase-display.accepting {
  background: #27ae60;
  animation: pulse 1s ease-in-out infinite;
}

#phase-display.buzzed {
  background: #e67e22;
}

#phase-display.judged {
  background: #8e44ad;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

#buzz-list {
  margin: 12px 0;
}

.buzz-entry {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  margin: 4px 0;
  border-radius: 6px;
  background: rgba(255,255,255,0.05);
}

.buzz-entry.first {
  background: rgba(241, 196, 15, 0.2);
  border: 1px solid rgba(241, 196, 15, 0.4);
}

.buzz-entry.current-answerer {
  background: rgba(243, 156, 18, 0.3);
  border: 1px solid rgba(243, 156, 18, 0.6);
}

#current-answerer {
  font-size: 1.1rem;
  font-weight: bold;
  text-align: center;
  padding: 8px;
  color: #f39c12;
}

/* Judge Buttons */
#judge-buttons {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

#judge-buttons.hidden {
  display: none;
}

.btn-correct, .btn-wrong {
  flex: 1;
  padding: 16px;
  font-size: 1.3rem;
  font-weight: bold;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: white;
  transition: opacity 0.2s;
}

.btn-correct {
  background: var(--color-correct);
}

.btn-wrong {
  background: var(--color-wrong);
}

.btn-correct:hover, .btn-wrong:hover {
  opacity: 0.85;
}

.btn-correct:active, .btn-wrong:active {
  opacity: 0.7;
}

/* Controls */
.controls-row {
  display: flex;
  gap: 12px;
}

.btn-open, .btn-reset, .btn-reset-scores {
  flex: 1;
  padding: 14px;
  font-size: 1.1rem;
  font-weight: bold;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: white;
  transition: opacity 0.2s;
}

.btn-open {
  background: var(--color-open);
}

.btn-reset {
  background: var(--color-reset);
}

.btn-reset-scores {
  background: #e67e22;
}

.btn-open:hover, .btn-reset:hover, .btn-reset-scores:hover {
  opacity: 0.85;
}

.score-adjust {
  white-space: nowrap;
}

.btn-score-adj {
  padding: 2px 8px;
  font-size: 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  margin: 0 1px;
}

.btn-score-adj:hover {
  background: var(--color-accent);
}

.btn-open:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Settings */
.settings-toggle {
  background: none;
  border: none;
  color: var(--color-text-dim);
  font-size: 1rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#settings-body.hidden {
  display: none;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0;
}

.setting-row label {
  color: var(--color-text-dim);
}

.setting-row input,
.setting-row select {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 1rem;
  width: 120px;
}

.btn-save {
  margin-top: 12px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background: var(--color-accent);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
  width: 100%;
}

.btn-save:hover {
  opacity: 0.85;
}

.settings-note {
  margin-top: 12px;
  color: var(--color-text-dim);
  font-size: 0.85rem;
  text-align: center;
}

.btn-save.saved {
  background: var(--color-correct);
  pointer-events: none;
}

.btn-preview {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  margin-left: 8px;
}

.btn-preview:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text);
}

#controls-section {
  grid-column: 1 / -1;
}

#settings-section {
  grid-column: 1 / -1;
}

/* QR Button */
.btn-qr {
  font-size: 0.75rem;
  padding: 4px 10px;
  border: 1px solid #f1c40f;
  border-radius: 6px;
  background: rgba(241, 196, 15, 0.15);
  color: #f1c40f;
  cursor: pointer;
  font-weight: bold;
}

.btn-qr:hover {
  background: rgba(241, 196, 15, 0.3);
}

/* QR Modal */
.qr-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-modal.hidden {
  display: none;
}

.qr-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.qr-modal-content {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.qr-modal-content h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.qr-url {
  font-size: 0.75rem;
  color: var(--color-text-dim);
  word-break: break-all;
  margin-bottom: 16px;
}

#qr-canvas {
  display: block;
  margin: 0 auto 20px;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  max-width: 100%;
}

.qr-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-qr-action {
  padding: 10px 20px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-accent);
  color: white;
  font-size: 0.9rem;
  cursor: pointer;
  flex: 1;
  min-width: 80px;
}

.btn-qr-action:hover {
  opacity: 0.85;
}

.btn-qr-share {
  background: #27ae60;
}

.btn-qr-close {
  background: var(--color-reset);
}
