/* Dark is the fallback. The script in index.html sets data-theme before first paint
   from the saved toggle choice, else the system preference. */
:root {
  --bg: #141518;
  --surface: #1d1f23;
  --surface-2: #25272c;
  --text: #e8e8ea;
  --muted: #9a9ca3;
  --border: #2f3238;
  --accent: #CE4A14;
  --accent-soft: #3a2015;
  --on-accent: #ffffff;
  --ok: #63c27a;
  --ok-soft: #1c3324;
  --warn: #ffa057;
  --warn-soft: #3a2615;
  --danger: #ff7b73;
  --danger-soft: #3d1c1b;
  --answer-bg: #2a1e1a;
  --answer-border: #7a3a1e;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.25);
  --radius: 12px;
  --bar-h: 64px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #1f2023;
  --muted: #6c6d72;
  --border: #e2e0d8;
  --accent: #CE4A14;
  --accent-soft: #fbe9e0;
  --on-accent: #fff;
  --ok: #2b8a3e;
  --ok-soft: #e5f4e8;
  --warn: #d9620b;
  --warn-soft: #fff0e2;
  --danger: #d4322c;
  --danger-soft: #fde8e7;
  --answer-bg: #fdf3ee;
  --answer-border: #f0c3ad;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 6px 20px rgb(0 0 0 / 0.06);
  color-scheme: light;
}

/* Sunset: for dusk, when light mode is too bright but dark mode is too much.
   Dimmer, warm surfaces with less blue, and a plum accent that stays clear of warn/danger. */
:root[data-theme="sunset"] {
  --bg: #d5bcae;
  --surface: #e4d0c4;
  --surface-2: #cbb1a3;
  --text: #2e1f1d;
  --muted: #564040;
  --border: #bea091;
  --accent: #CE4A14;
  --accent-soft: #e9c4ae;
  --on-accent: #fff;
  --ok: #2a5e2e;
  --ok-soft: #cbd3b2;
  --warn: #8c3804;
  --warn-soft: #eac6a3;
  --danger: #98221b;
  --danger-soft: #ebbfb5;
  --answer-bg: #e8d2c6;
  --answer-border: #d29a7c;
  --shadow: 0 1px 2px rgb(70 30 20 / 0.08), 0 6px 20px rgb(70 30 20 / 0.1);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--bar-h) + 16px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 800px; margin: 0 auto; padding: 24px 16px 120px; }

a { color: var(--accent); }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); min-width: 84px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }

/* Square icon-only buttons (menu, theme). */
.icon-btn { flex: none; padding: 9px; line-height: 0; }
.icon-btn svg { display: block; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Shows the current theme's icon; dark is anything that isn't light or sunset. */
.theme-toggle svg { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun,
:root[data-theme="sunset"] .theme-toggle .icon-sunset,
:root:not([data-theme="light"], [data-theme="sunset"]) .theme-toggle .icon-moon { display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- sticky timer bar ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.bar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}
.bar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bar-heading { display: flex; flex-direction: column; min-width: 0; }
.home-link { font-size: 13px; text-decoration: none; color: var(--muted); }
.home-link:hover { color: var(--accent); }
.bar-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-timer { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.clock { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; transition: color 0.2s; }
.clock-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.bar[data-level="warn"] .clock { color: var(--warn); }
.bar[data-level="danger"] .clock { color: var(--danger); }
.paused .clock { opacity: 0.5; }
.bar-controls { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.minutes { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-right: 4px; }
.minutes input {
  width: 58px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 6px;
  text-align: center;
}
.progress { height: 4px; background: var(--surface-2); }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.25s linear, background 0.3s; }
.bar[data-level="warn"] .progress-fill { background: var(--warn); }
.bar[data-level="danger"] .progress-fill { background: var(--danger); }

@media (max-width: 760px) {
  .bar-inner { grid-template-columns: 1fr auto; gap: 8px 12px; }
  .bar-controls { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------- quiz header ---------- */
.quiz-head { margin: 12px 0 28px; }
.quiz-head h1 { font-size: 28px; line-height: 1.25; margin: 0 0 4px; letter-spacing: -0.01em; }
.quiz-path { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.quiz-intro { color: var(--muted); font-size: 15px; }
.quiz-intro p { margin: 0 0 8px; }
.quiz-summary { font-size: 14px; font-weight: 600; margin: 12px 0 0; }

/* ---------- markdown content ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin: 4px 0; }
.md blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--border); color: var(--muted); }
.md table { border-collapse: collapse; margin: 0 0 12px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md h1, .md h2, .md h3, .md h4 { font-size: 16px; margin: 16px 0 8px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }

/* ---------- question cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin: 0 0 22px;
  scroll-margin-top: calc(var(--bar-h) + 16px);
  transition: opacity 0.25s, border-color 0.25s, box-shadow 0.25s;
}
.running .card:not(.active) { opacity: 0.5; }
.running .card:not(.active):hover,
.running .card:not(.active):focus-within { opacity: 1; }
.card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.card.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 6px var(--warn-soft); border-color: var(--warn); } 100% { box-shadow: var(--shadow); } }

.card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.badge {
  flex: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 999px;
  margin-top: 2px;
}
.card-title { flex: 1; font-size: 18px; line-height: 1.35; margin: 0; letter-spacing: -0.005em; }
.chip {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--surface-2);
  padding: 3px 9px;
  border-radius: 999px;
  margin-top: 3px;
  white-space: nowrap;
}
.card.active .chip { color: var(--accent); background: var(--accent-soft); }
.card[data-status="done"] .chip { color: var(--ok); background: var(--ok-soft); }
.card[data-status="timeup"] .chip { color: var(--warn); background: var(--warn-soft); }
.start-here {
  flex: none;
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 3px 4px;
  margin-top: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .start-here, .start-here:focus-visible { opacity: 1; }
.start-here:hover { color: var(--accent); }
.card.active .start-here { display: none; }
@media (hover: none) { .start-here { opacity: 1; } }

.prompt { font-size: 16.5px; margin-bottom: 16px; }

.response textarea {
  display: block;
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font: inherit;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  transition: border-color 0.15s, background 0.15s;
}
.response textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.response-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin: 6px 2px 0; }
.saved-note { opacity: 0; transition: opacity 0.3s; }
.saved-note.show { opacity: 1; }

details.answer { margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
details.answer > summary {
  list-style: none;
  cursor: pointer;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
details.answer > summary::-webkit-details-marker { display: none; }
details.answer > summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
details.answer > summary:hover { color: var(--accent); }
details.answer[open] { border-color: var(--answer-border); background: var(--answer-bg); }
details.answer[open] > summary { color: var(--accent); }
details.answer[open] > summary::before { transform: rotate(45deg); }
.answer-body { padding: 2px 16px 14px; font-size: 15px; }
.no-answer { font-size: 13px; color: var(--muted); margin: 12px 0 0; }

/* ---------- section notes (study-guide headings) ---------- */
.note { margin: 34px 0 16px; }
.note h2 { font-size: 22px; margin: 0 0 6px; }
.note h3 { font-size: 17px; margin: 0 0 6px; color: var(--muted); }
.note .md { color: var(--muted); font-size: 15px; }

/* ---------- end of quiz ---------- */
.quiz-end { text-align: center; padding: 28px 0 0; border-top: 1px solid var(--border); margin-top: 36px; }
.end-summary { font-size: 18px; font-weight: 650; margin: 0 0 16px; }
.end-summary:empty { display: none; }
.end-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.end-note { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- home ---------- */
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 24px 0 4px; }
.home h1 { font-size: 30px; margin: 0; }
.lede { color: var(--muted); margin: 0 0 28px; }
.quiz-group h2 { font-size: 13px; letter-spacing: 0.02em; color: var(--muted); margin: 26px 0 8px; font-weight: 650; }
.quiz-group ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.quiz-group a {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 16px;
  transition: border-color 0.15s, transform 0.15s;
}
.quiz-group a:hover { border-color: var(--accent); }
.qz-title { font-weight: 600; }
.qz-meta { font-size: 13px; color: var(--muted); }
.local-open { margin-top: 32px; }

.error { background: var(--danger-soft); color: var(--danger); padding: 12px 16px; border-radius: 10px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 550;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- study landing ---------- */
.topic-group h2 { font-size: 13px; letter-spacing: 0.02em; color: var(--muted); margin: 26px 0 8px; font-weight: 650; }
.topic-list { display: grid; gap: 8px; }
.topic {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 16px;
}
.topic-title { display: flex; flex-direction: column; min-width: 200px; flex: 1; }
.topic-num { font-size: 13px; color: var(--muted); }
.topic-name { font-weight: 600; }
.topic-links { display: flex; gap: 8px; }
.topic-links .btn { text-decoration: none; display: inline-block; }
a.btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
a.btn { text-decoration: none; display: inline-block; text-align: center; }
button.topic-title { appearance: none; background: none; border: 0; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.topic-title:hover .topic-name { color: var(--accent); }
.topic-details { flex-basis: 100%; display: flex; gap: 16px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted); }
.topic-details[hidden] { display: none; }
.feedback { margin-top: 48px; text-align: center; font-size: 14px; font-style: italic; font-weight: 300; color: var(--muted); }
.study-resources { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.credited-resource { position: relative; display: flex; width: fit-content; }
.credit-ref { position: absolute; top: 0; right: 0; transform: translate(50%, -50%); display: inline-flex; align-items: center; justify-content: center; min-width: 24px; min-height: 24px; border: 2px solid var(--bg); border-radius: 50%; color: var(--on-accent); background: var(--accent); text-decoration: none; }
.credit-ref sup { font-size: 11px; font-weight: 650; line-height: 1; }
.credit-ref:hover, .credit-ref:focus-visible { filter: brightness(1.15); }
.credits { margin-bottom: 24px; font-size: 13px; font-style: normal; font-weight: 400; }
.credits h2 { margin: 0 0 6px; font-size: 13px; font-weight: 650; }
.credits p { margin: 0; padding: 6px 8px; border-radius: 6px; }
.credits p:target { color: var(--text); background: var(--accent-soft); }
button.topic-title { flex-direction: row; align-items: center; gap: 10px; }
.topic-text { display: flex; flex-direction: column; }
.chev { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s, stroke 0.15s; }
.topic { transition: border-color 0.15s, background 0.15s; }
.topic:hover { border-color: var(--accent); background: var(--surface-2); }
.topic:hover .chev { stroke: var(--accent); }
.topic-title[aria-expanded="true"] .chev { transform: rotate(90deg); stroke: var(--accent); }
.topic:has(.topic-title[aria-expanded="true"]) { border-color: var(--accent); }

/* ---------- lesson notes ---------- */
.notes-bar { grid-template-columns: 1fr auto; }
.file-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 20px; }
.file-tabs .btn[aria-selected="true"] { border-color: var(--accent); color: var(--accent); }
.note-card .card-title { margin: 0 0 12px; }
.notes-md { font-size: 15.5px; }
.notes-md h3 { font-size: 17px; margin: 22px 0 8px; }
.notes-md h4 { font-size: 15.5px; margin: 16px 0 6px; color: var(--muted); }
.notes-md ul ul, .notes-md ol ul, .notes-md ul ol { margin-bottom: 0; }
.notes-md em { color: var(--muted); }

/* ---------- flash cards ---------- */
.flashcard { padding: 16px 20px; margin-bottom: 14px; }
.flashcard .card-head { align-items: center; margin-bottom: 0; }
.flashcard .badge { margin-top: 0; min-width: 30px; text-align: center; }
.flashcard .answer-body p { margin: 0; }
.fc-label { font-size: 13px; font-weight: 650; color: var(--muted); margin: 12px 0 2px; }
.fc-label:first-child { margin-top: 4px; }
