/* MCQ Read - light/dark via CSS custom properties on [data-theme]. */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --ink: #14181d;
  --ink-2: #5a6472;
  --ink-3: #8b95a3;
  --line: #e2e6ec;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e7f0ff;
  --good: #17803d;
  --good-soft: #e6f6ec;
  --warn: #9a6400;
  --warn-soft: #fdf3d8;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --topbar-h: 56px;
}

html[data-theme="dark"] {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232c;
  --ink: #e7edf4;
  --ink-2: #a3adba;
  --ink-3: #6f7a88;
  --line: #262d37;
  --accent: #5b9dff;
  --accent-ink: #06101f;
  --accent-soft: #16283f;
  --good: #58d68d;
  --good-soft: #10281a;
  --warn: #e3b341;
  --warn-soft: #2b2312;
  --bad: #ff7b72;
  --bad-soft: #2d1614;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0e1116;
    --panel: #161b22;
    --panel-2: #1c232c;
    --ink: #e7edf4;
    --ink-2: #a3adba;
    --ink-3: #6f7a88;
    --line: #262d37;
    --accent: #5b9dff;
    --accent-ink: #06101f;
    --accent-soft: #16283f;
    --good: #58d68d;
    --good-soft: #10281a;
    --warn: #e3b341;
    --warn-soft: #2b2312;
    --bad: #ff7b72;
    --bad-soft: #2d1614;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

/* The gate is a fixed full-screen overlay, so an author `display` rule would
   otherwise beat the UA rule for [hidden] and leave it swallowing clicks. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- lock screen ---------- */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 50;
}

.gate-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 10px;
}

.gate-title { margin: 0; font-size: 24px; letter-spacing: -0.01em; }
.gate-sub { margin: 0 0 8px; color: var(--ink-2); font-size: 13px; }
.gate-label { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }

.gate-input {
  width: 100%;
  padding: 11px 12px;
  font-size: 16px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.gate-button {
  margin-top: 4px;
  padding: 11px 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.gate-button:disabled { opacity: 0.6; cursor: progress; }
.gate-error { margin: 2px 0 0; color: var(--bad); font-size: 13px; }

/* ---------- chrome ---------- */

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left, .topbar-mid, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand { font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
}

.icon-button:hover { background: var(--panel-2); color: var(--ink); }
.icon-button:disabled { opacity: 0.35; cursor: default; }

.play-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.play-button .icon-play { fill: currentColor; stroke: none; }
.play-button .icon-pause { fill: currentColor; stroke: none; display: none; }
.play-button[data-state="playing"] .icon-play { display: none; }
.play-button[data-state="playing"] .icon-pause { display: block; }
.play-button[data-state="loading"] { opacity: 0.6; cursor: progress; }

.position {
  color: var(--ink-3);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.speed { display: flex; align-items: center; gap: 7px; }
.speed-label { font-size: 12px; color: var(--ink-3); }
.speed input { width: 96px; accent-color: var(--accent); }
.speed-out { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 44px; }

.chip-button {
  padding: 6px 11px;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-button:hover { color: var(--ink); }

html[data-theme="dark"] .icon-sun,
html[data-theme="auto"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon,
html[data-theme="auto"] .icon-moon { display: block; }
html[data-theme="light"] .icon-moon { display: none; }
html[data-theme="light"] .icon-sun { display: block; }
@media (prefers-color-scheme: light) {
  html[data-theme="auto"] .icon-sun { display: block; }
  html[data-theme="auto"] .icon-moon { display: none; }
}

.body { flex: 1 1 auto; display: flex; min-height: 0; }

/* ---------- sidebar ---------- */

.sidebar {
  width: 286px;
  flex: 0 0 286px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.filters { padding: 12px; display: grid; gap: 12px; border-bottom: 1px solid var(--line); }
.field { display: grid; gap: 6px; }
.field-label { font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-3); }

.segmented { display: flex; gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 9px; }

.segmented button {
  flex: 1 1 0;
  padding: 6px 4px;
  font-size: 12.5px;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button.is-active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

select, input[type="search"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.groups { flex: 1 1 auto; overflow-y: auto; padding: 8px; }

.group { margin-bottom: 4px; }
.group-head {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}

.group-head:hover { background: var(--panel-2); }
.group-head .count { margin-left: auto; font-size: 11.5px; font-weight: 500; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.group-head .caret { color: var(--ink-3); transition: transform 0.15s ease; }
.group[data-open="false"] .caret { transform: rotate(-90deg); }
.group[data-open="false"] .group-items { display: none; }

.group-items { display: grid; padding: 2px 0 6px 14px; }
.group-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 8px;
  font-size: 12.5px;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  text-align: left;
}

.group-item:hover { background: var(--panel-2); color: var(--ink); }
.group-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.group-item .count { margin-left: auto; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.switch input { width: 15px; height: 15px; accent-color: var(--accent); }

.seen-button {
  margin-left: auto;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.seen-button[aria-pressed="true"] { background: var(--good-soft); color: var(--good); border-color: transparent; }
.q-head.is-seen { opacity: 0.75; }

.sidebar-foot { padding: 9px 12px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--ink-3); }

/* ---------- reader ---------- */

.main { flex: 1 1 auto; overflow-y: auto; min-width: 0; }
.reader { max-width: 760px; margin: 0 auto; padding: 22px 18px 96px; display: grid; gap: 16px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.q-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }

.badge {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink-2);
  white-space: nowrap;
}

.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.q-stem { margin: 0; font-size: 17px; line-height: 1.5; white-space: pre-wrap; }

.options { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 7px; }

.option {
  display: flex;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.option .label { flex: 0 0 22px; color: var(--ink-3); font-size: 13px; font-weight: 600; }
.option .text { flex: 1 1 auto; }

.option[data-speaking="true"] { border-color: var(--accent); background: var(--accent-soft); }
.option.is-answer { border-color: var(--good); background: var(--good-soft); }
.option.is-answer .label { color: var(--good); }

.answer-block { display: grid; gap: 8px; }
.answer-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.answer-line .k { font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-3); }
.answer-value { font-size: 16px; font-weight: 650; color: var(--good); }
.answer-value.none { color: var(--warn); font-size: 14px; font-weight: 500; }

.explanation { margin: 0; color: var(--ink-2); white-space: pre-wrap; }
.explanation.is-speaking { color: var(--ink); }

.source-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3); }
.source-row a { color: var(--accent); text-decoration: none; word-break: break-all; }
.source-row a:hover { text-decoration: underline; }

.empty { padding: 60px 20px; text-align: center; color: var(--ink-3); }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: -2px;
}

@keyframes spin { to { transform: rotate(360deg); } }

mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- voice sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 15, 0.45);
  display: grid;
  place-items: end center;
  z-index: 40;
  padding: 0;
}

@media (min-width: 640px) { .sheet { place-items: center; } }

.sheet-card {
  width: min(420px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
}

/* Inside the sheet the voice list has to scroll rather than push the card past
   the bottom of the screen. */
.sheet-card .voice-list { flex: 1 1 auto; min-height: 0; max-height: 46vh; overflow-y: auto; }
.sheet-card .field, .sheet-card .segmented, .sheet-card a { flex: 0 0 auto; }

@media (min-width: 640px) { .sheet-card { border-radius: 16px; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 16px; }
.sheet-note { margin: 0; font-size: 12px; color: var(--ink-3); }
.voice-list { overflow-y: auto; display: grid; gap: 4px; }

.voice-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
}

.voice-item:hover { background: var(--panel-2); }
.voice-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.voice-item .preview { font-size: 11.5px; color: var(--ink-3); font-weight: 500; }

/* Voice Lab rows: name, quality, and the measured time to speak the sample. */
.voice-list { max-height: none; }

.voice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
}

.voice-row:hover { background: var(--panel-2); }
.voice-row.is-active { background: var(--accent-soft); border-color: var(--accent); }
.voice-row-main { display: grid; gap: 1px; min-width: 0; }
.voice-row-name { font-size: 14px; color: var(--ink); }
.voice-row-meta { font-size: 11.5px; color: var(--ink-3); }
.voice-row-actions { display: flex; align-items: center; gap: 6px; }
.voice-row-time { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.voice-row.is-active .voice-row-actions .chip-button:last-child { background: var(--accent); color: var(--accent-ink); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  padding: 10px 14px;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 60;
}

/* ---------- mobile ---------- */

@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  .speed { display: none; }
  .brand { display: none; }
  .reader { padding: 16px 12px 80px; }
  .q-stem { font-size: 16px; }
}

@media (min-width: 801px) {
  #menu-toggle { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
