/* ── Reset & base ───────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --purple: #7c35ee;
  --purple-light: #a06bff;
  --green:  #4caf50;
  --red:    #e53935;
  --bg:     #0f0f1a;
  --card:   #1a1a2e;
  --text:   #f0f0f0;
  --muted:  #888;
  --radius: 14px;
}

/* Dark mode is default (TV-friendly) */
body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 20px;
  transition: background 0.3s, color 0.3s;
}

/* Light mode override */
body.light {
  --bg:   #f0f0f0;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted:#555;
}

/* ── Header ─────────────────────────────────── */
#header {
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

#header h1 {
  font-size: clamp(1.4em, 3vw, 2em);
  color: var(--purple-light);
  letter-spacing: 1px;
}

/* header toolbar buttons */
.hbtn {
  background: var(--card);
  color: var(--text);
  border: 1.5px solid #333;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.hbtn:hover { background: #2a2a3e; transform: translateY(-1px); }
body.light .hbtn:hover { background: #e0e0e0; }

/* ── Selector screen ────────────────────────── */
#selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  margin-top: 40px;
  width: 100%;
  max-width: 600px;
}

#selector h2 {
  font-size: clamp(1.4em, 3vw, 1.9em);
  color: var(--muted);
  font-weight: 400;
}

#quizSelect {
  width: 100%;
  padding: 16px 20px;
  font-size: clamp(1.1em, 2.2vw, 1.4em);
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--purple);
  border-radius: var(--radius);
  outline: none;
  cursor: pointer;
}

#selector-row {
  display: flex;
  gap: 14px;
  width: 100%;
}

#shuffleToggle {
  padding: 16px 22px;
  font-size: clamp(1em, 2vw, 1.2em);
  border-radius: var(--radius);
  border: 2px solid #444;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
#shuffleToggle.on {
  border-color: var(--purple-light);
  color: var(--purple-light);
  background: rgba(124, 53, 238, 0.15);
}

#startBtn {
  flex: 1;
  padding: 16px;
  font-size: clamp(1.1em, 2.5vw, 1.5em);
  font-weight: bold;
  background: linear-gradient(135deg, var(--purple), #a06bff);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(124, 53, 238, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
#startBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 26px rgba(124, 53, 238, 0.6);
}

/* ── Quiz screen ────────────────────────────── */
#quiz-screen {
  display: none;
  width: 100%;
  max-width: 1100px;
  flex-direction: column;
  gap: 18px;
}

#progress-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

#q-counter {
  font-size: clamp(1em, 2vw, 1.3em);
  color: var(--purple-light);
  font-weight: bold;
  white-space: nowrap;
  min-width: 120px;
}

#progress-track {
  flex: 1;
  height: 10px;
  background: #2a2a3a;
  border-radius: 999px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, var(--purple), var(--purple-light));
  transition: width 0.4s ease;
  border-radius: 999px;
}

#timer-track {
  height: 8px;
  background: #2a2a3a;
  border-radius: 999px;
  overflow: hidden;
  margin-top: -8px;
}
#time-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(to right, #7c35ee, #a06bff);
  transition: width 1s linear, background 0.5s;
  border-radius: 999px;
}

#questionBox {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 32px;
  border: 1.5px solid #2a2a3e;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  display: flex;
  align-items: flex-start;
  gap: 20px;
  position: relative;
}

#questionText {
  flex: 1;
  font-size: clamp(1.4em, 3vw, 2.2em);
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

#timer-circle-wrap {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  position: relative;
}
#timer-svg {
  width: 64px;
  height: 64px;
  transform: rotate(-90deg);
}
#timer-svg circle.bg {
  stroke: #2a2a3e;
  stroke-width: 5;
  fill: none;
}
#timer-svg circle.arc {
  stroke: var(--purple-light);
  stroke-width: 5;
  fill: none;
  stroke-dasharray: 169.6;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.5s;
  stroke-linecap: round;
}
#timer-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9em;
  font-weight: bold;
  color: var(--purple-light);
}
#timer-label.urgent { color: var(--red); }

#status-badge {
  text-align: center;
  font-size: 1.1em;
  font-weight: bold;
  min-height: 28px;
  color: var(--purple-light);
}

#optionsContainer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {
  #optionsContainer { grid-template-columns: 1fr; }
}

.opt-btn {
  background: var(--card);
  color: var(--text);
  border: 2px solid #2a2a3e;
  border-radius: var(--radius);
  padding: 22px 24px;
  font-size: clamp(1.1em, 2.2vw, 1.6em);
  font-weight: 500;
  text-align: left;
  cursor: default;
  transition: border-color 0.3s, background 0.3s, transform 0.2s;
  line-height: 1.3;
  word-break: break-word;
}

.opt-btn.correct {
  background: rgba(76, 175, 80, 0.18) !important;
  border-color: var(--green) !important;
  color: #81c784 !important;
  font-weight: bold;
  transform: scale(1.02);
  box-shadow: 0 0 20px rgba(76, 175, 80, 0.3);
}
.opt-btn.wrong {
  background: rgba(229, 57, 53, 0.12) !important;
  border-color: var(--red) !important;
  color: #e57373 !important;
  opacity: 0.7;
}

#controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 6px;
  flex-wrap: wrap;
}

.ctrl-btn {
  padding: 13px 26px;
  font-size: clamp(1em, 1.8vw, 1.2em);
  font-weight: bold;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.ctrl-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
.ctrl-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

#btnPause  { background: linear-gradient(135deg, #ff9800, #ffb74d); color: #fff; }
#btnResume { background: linear-gradient(135deg, #4caf50, #81c784); color: #fff; }
#btnSkip   { background: linear-gradient(135deg, #2196f3, #64b5f6); color: #fff; }
#btnStop