/* The theme control sits with the existing navigation on each screen. */
.theme-story-tools, .theme-admin-tools {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.theme-admin-tools { margin-bottom: 26px; }
.theme-admin-tools .brand-mark { margin: 0; }

ipq-theme {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--ink-soft);
}
ipq-theme::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 11px;
  width: 13px;
  height: 13px;
  box-sizing: border-box;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
  transform: translateY(-50%);
  pointer-events: none;
}
ipq-theme select {
  min-height: 38px;
  margin: 0;
  padding: 5px 4px 5px 30px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background-color: var(--card);
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
ipq-theme select:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.theme-story-tools ipq-theme select:focus-visible { outline-color: #fff; }

@media (min-width: 981px) {
  .quiz-header { grid-template-columns: minmax(155px, 1fr) minmax(180px, 2fr) auto; }
}
@media (max-width: 1100px) {
  .quiz-clock ipq-theme select { width: 39px; padding: 0; color: transparent; appearance: none; }
  .quiz-clock ipq-theme option { color: var(--ink); background: var(--card); }
  .quiz-clock ipq-theme::before { left: 13px; }
}
@media (max-width: 780px) {
  :is(.topbar-actions, .teacher-top-actions, .official-top-actions, .teacher-question-meta) ipq-theme select {
    width: 39px;
    padding: 0;
    color: transparent;
    appearance: none;
  }
  :is(.topbar-actions, .teacher-top-actions, .official-top-actions, .teacher-question-meta) ipq-theme option {
    color: var(--ink);
    background: var(--card);
  }
  :is(.topbar-actions, .teacher-top-actions, .official-top-actions, .teacher-question-meta) ipq-theme::before { left: 13px; }
}
@media (max-width: 650px) {
  .topbar, .official-topbar, .teacher-topbar { height: auto; min-height: 66px; flex-wrap: wrap; gap: 8px; padding-block: 10px; }
  .topbar-actions, .official-top-actions, .teacher-top-actions { margin-inline-start: auto; gap: 6px; }
  .official-top-actions .mode-chip { display: none; }
  .topbar-copy { min-width: 0; overflow-wrap: anywhere; }
  .quiz-clock { gap: 6px; }
}
@media (forced-colors: active) {
  ipq-theme::before { background: none; border-inline-start-width: 7px; color: ButtonText; }
}
@media print {
  ipq-theme { display: none; }
}

@media screen {
  :root[data-theme="dark"] {
    color-scheme: dark;
    --paper: #11151e;
    --card: #1b202c;
    --surface-raised: #252b39;
    --surface-hover: #30374a;
    --line: #363e50;
    --line-strong: #647087;
    --ink: #edf0f7;
    --ink-soft: #c1c9d8;
    --muted: #a6afc1;
    --primary: #bab0ff;
    --primary-dark: #cec7ff;
    --primary-soft: #302b4c;
    --green: #84d9b2;
    --green-soft: #19382e;
    --amber: #f3c27e;
    --amber-soft: #3b3021;
    --red: #ff9aa7;
    --red-soft: #422831;
    --on-accent: #161b26;
    --shadow: 0 18px 55px rgba(0, 0, 0, .3);
  }

  :where(html[data-theme="dark"]) .entry-page, :where(html[data-theme="dark"]) .entry-panel, :where(html[data-theme="dark"]) .quiz-page { background: var(--paper); }
  :where(html[data-theme="dark"]) .entry-card { border-color: var(--line); background: var(--card); }
  :where(html[data-theme="dark"]) .entry-brand .brand-mark { color: #5145a6; }
  :where(html[data-theme="dark"]) .sidebar, :where(html[data-theme="dark"]) .topbar, :where(html[data-theme="dark"]) .quiz-header, :where(html[data-theme="dark"]) .mobile-nav { border-color: var(--line); background: var(--card); }
  :where(html[data-theme="dark"]) :is(.fixed-set-card, .question-card, .question-nav, .review-card, .table-wrap,
    .admin-card, .admin-question-card, .category-stat, .choice-card, .flag-button,
    .option-button, .number-button, .btn-secondary) { background-color: var(--card); }
  :where(html[data-theme="dark"]) .field :is(input, select) { background: var(--surface-raised); border-color: var(--line-strong); }
  :where(html[data-theme="dark"]) .field :is(input, select):focus { border-color: var(--primary); }
  :where(html[data-theme="dark"]) input::placeholder { color: var(--muted); }
  :where(html[data-theme="dark"]) .number-button, :where(html[data-theme="dark"]) .choice-card, :where(html[data-theme="dark"]) .option-button { border-color: var(--line-strong); }
  :where(html[data-theme="dark"]) .btn-secondary:hover, :where(html[data-theme="dark"]) .nav-button:hover, :where(html[data-theme="dark"]) tbody tr:hover { background: var(--surface-hover); }
  :where(html[data-theme="dark"]) .btn-secondary:hover { border-color: var(--line-strong); }
  :where(html[data-theme="dark"]) .nav-button.active { background: var(--primary-soft); }
  :where(html[data-theme="dark"]) :is(.clock, .option-key, .tag.neutral, .logout-mini, th, .explanation,
    .admin-options li, .admin-explanation, .admin-question-card[open] summary, .notice code) { background: var(--surface-raised); }
  :where(html[data-theme="dark"]) .setup-summary { background: #27263a; }
  :where(html[data-theme="dark"]) .hero-score, :where(html[data-theme="dark"]) .hero-actions .btn-primary, :where(html[data-theme="dark"]) .btn-primary, :where(html[data-theme="dark"]) .boot-mark,
  :where(html[data-theme="dark"]) .brand-mark, :where(html[data-theme="dark"]) .option-button.selected .option-key, :where(html[data-theme="dark"]) .btn-check, :where(html[data-theme="dark"]) .feedback-mark,
  :where(html[data-theme="dark"]) .option-button.correct-answer .option-key, :where(html[data-theme="dark"]) .option-button.wrong-answer .option-key { color: var(--on-accent); }
  :where(html[data-theme="dark"]) .btn-check:hover { background: #a0e8c7; }
  :where(html[data-theme="dark"]) :is(.skip-link, .avatar, .toast:not(.error)) {
    color: var(--on-accent);
    background: var(--ink);
  }
  :where(html[data-theme="dark"]) .category-card::after { color: rgba(237,240,247,.05); }
  :where(html[data-theme="dark"]) .entry-official-link { color: var(--green); border-color: #3c6455; background: var(--green-soft); }
  :where(html[data-theme="dark"]) .entry-official-link small { color: var(--ink-soft); }
  :where(html[data-theme="dark"]) .source-legend, :where(html[data-theme="dark"]) .tag.source-ai { border-color: #605782; background: var(--primary-soft); }
  :where(html[data-theme="dark"]) .tag.source-ai { color: var(--primary); }
  :where(html[data-theme="dark"]) .tag.source-official { color: var(--green); border-color: #487563; background: var(--green-soft); }
  :where(html[data-theme="dark"]) .choice-card:hover, :where(html[data-theme="dark"]) .option-button:hover { border-color: var(--primary); background: var(--surface-hover); }
  :where(html[data-theme="dark"]) .choice-card.selected, :where(html[data-theme="dark"]) .option-button.selected {
    border-color: var(--primary); background: var(--primary-soft);
  }
  :where(html[data-theme="dark"]) .flag-button.active { background: var(--amber-soft); border-color: var(--amber); }
  :where(html[data-theme="dark"]) .number-button.answered { background: var(--primary-soft); border-color: #746aa2; }
  :where(html[data-theme="dark"]) .number-button.checked, :where(html[data-theme="dark"]) .option-button.correct-answer, :where(html[data-theme="dark"]) .answer-feedback {
    border-color: #598c79; background: var(--green-soft);
  }
  :where(html[data-theme="dark"]) .number-button.current { color: var(--on-accent); border-color: var(--ink); background: var(--ink); }
  :where(html[data-theme="dark"]) .option-button.wrong-answer, :where(html[data-theme="dark"]) .answer-feedback.wrong, :where(html[data-theme="dark"]) .connection-error, :where(html[data-theme="dark"]) .btn-danger {
    border-color: #9a5d6b; background: var(--red-soft);
  }
  :where(html[data-theme="dark"]) .notice strong { color: var(--amber); }
  :where(html[data-theme="dark"]) .admin-login-page { background: radial-gradient(circle at 20% 0, #2c294f, transparent 40%), var(--paper); }
  :where(html[data-theme="dark"]) .admin-options li.correct { color: var(--green); background: var(--green-soft); }
  :where(html[data-theme="dark"]) .quiz-progress, :where(html[data-theme="dark"]) .category-stat-score progress { background: var(--surface-raised); }
  :where(html[data-theme="dark"]) .quiz-progress::-webkit-progress-bar, :where(html[data-theme="dark"]) .category-stat-score progress::-webkit-progress-bar { background: var(--surface-raised); }
  :where(html[data-theme="dark"]) :is(button, a, input, select, summary):focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
}
