/* ---------- design tokens: "The Fellowship Line" ----------
   Cream paper and navy ink, with the four route-map line colours as the only
   accents: red (Core Principles) leads, and doubles as the site accent. */

:root {
  --font-sans: "Jost", "Futura", "Avenir Next", "Century Gothic", system-ui, sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;

  --bg: #f2ede2;
  --card-bg: #fffdf7;
  --text: #1b2a41;
  --text-muted: #565d6b;
  --border: #d9d0be;
  --border-soft: #e6dfd0;
  --accent: #b03a2e;
  --accent-2: #b03a2e;
  --accent-soft: #f6e3de;
  --accent-contrast: #fffdf7;
  --done: #2a7549;
  --done-bg: #e1efe4;
  --progress: #845a09;
  --progress-bg: #f7ebcf;
  --not-started: #565d6b;
  --not-started-bg: #ebe5d8;
  --star: #845a09;
  --star-bg: #f7ebcf;
  --studying: #b03a2e;
  --weak: #b91c1c;
  --weak-bg: #fbe4e1;
  --ink-button: #1b2a41;
  --ink-button-text: #fffdf7;
  --card-rule: #c9d9ec;
  --card-margin: #e0857c;
  --on-line: #ffffff; /* text on a line-coloured fill */

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 16px;
  --radius-pill: 999px;

  --shadow-sm: none;
  --shadow-md: 0 1px 0 var(--border);
  --shadow-lg: 0 14px 30px -18px rgba(27, 42, 65, 0.45);
  --shadow: var(--shadow-sm);

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Dark palette applies when the OS/browser prefers dark AND the user hasn't
   explicitly picked light via the toggle, OR when the user has explicitly
   picked dark -- see the inline theme-resolving script in index.html, which
   sets data-theme on <html> before first paint to avoid a flash. The night
   version of the same map: deep navy ground, cream ink, brighter lines. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1522;
    --card-bg: #172033;
    --text: #ede6d6;
    --text-muted: #a3a9b7;
    --border: #2d3954;
    --border-soft: #222c43;
    --accent: #ef7a6e;
    --accent-2: #ef7a6e;
    --accent-soft: #3a2426;
    --accent-contrast: #0f1522;
    --done: #5cc28a;
    --done-bg: #15301f;
    --progress: #e8b04a;
    --progress-bg: #33280f;
    --not-started: #a3a9b7;
    --not-started-bg: #1f2940;
    --star: #f2c14e;
    --star-bg: #332711;
    --studying: #ef7a6e;
    --weak: #f87171;
    --weak-bg: #3a1c1c;
    --ink-button: #ede6d6;
    --ink-button-text: #0f1522;
    --card-rule: #26344f;
    --card-margin: #7a3a36;
    --on-line: #0f1522;

    --shadow-lg: 0 18px 36px -20px rgba(0, 0, 0, 0.7);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1522;
  --card-bg: #172033;
  --text: #ede6d6;
  --text-muted: #a3a9b7;
  --border: #2d3954;
  --border-soft: #222c43;
  --accent: #ef7a6e;
  --accent-2: #ef7a6e;
  --accent-soft: #3a2426;
  --accent-contrast: #0f1522;
  --done: #5cc28a;
  --done-bg: #15301f;
  --progress: #e8b04a;
  --progress-bg: #33280f;
  --not-started: #a3a9b7;
  --not-started-bg: #1f2940;
  --star: #f2c14e;
  --star-bg: #332711;
  --studying: #ef7a6e;
  --weak: #f87171;
  --weak-bg: #3a1c1c;
  --ink-button: #ede6d6;
  --ink-button-text: #0f1522;
  --card-rule: #26344f;
  --card-margin: #7a3a36;
  --on-line: #0f1522;

  --shadow-lg: 0 18px 36px -20px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }

::selection {
  background: var(--accent);
  color: var(--accent-contrast);
}

html { color-scheme: light dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* slim modern scrollbar (webkit); harmless no-op elsewhere */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-pill);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.topbar {
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--card-bg) 88%, transparent);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
  min-width: 0;
}

.topbar-home {
  color: inherit;
  text-decoration: none;
}

.icon-btn[aria-current="page"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.icon-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.icon-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.exemption-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.exemption-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Six icons plus the title don't fit a phone at full size. */
@media (max-width: 640px) {
  .topbar-inner { padding: 12px 16px; gap: 10px; }
  .topbar h1 { font-size: 0.95rem; line-height: 1.2; }
  .topbar-right { gap: 6px; flex-shrink: 0; }
  .topbar .icon-btn { width: 32px; height: 32px; font-size: 0.95rem; }
  .topbar .sync-status { display: none; }
}

.sync-status {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
}

.sync-status.local { background: var(--not-started-bg); color: var(--not-started); }
.sync-status.syncing { background: var(--progress-bg); color: var(--progress); }
.sync-status.synced { background: var(--done-bg); color: var(--done); }

.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.exam-card {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.exam-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.exam-code {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.exam-pct {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.exam-bar {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--not-started-bg);
  margin-top: 12px;
  overflow: hidden;
}

.exam-bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%;
  transition: width 0.4s var(--ease);
}

.module-list {
  margin-top: 14px;
  display: none;
  flex-direction: column;
  gap: 6px;
}

.exam-card.open .module-list { display: flex; }

.module-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  padding: 6px 0;
  border-top: 1px solid var(--border-soft);
}

.module-row:first-child { border-top: none; }

.module-id { color: var(--text-muted); min-width: 40px; }

.status-badge {
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 4px 11px;
  font-size: 0.74rem;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
  transition: transform 0.15s var(--ease), filter 0.15s var(--ease);
}

.status-badge:hover { transform: translateY(-1px); filter: brightness(1.03); }

.status-badge.not-started { background: var(--not-started-bg); color: var(--not-started); }
.status-badge.in-progress { background: var(--progress-bg); color: var(--progress); }
.status-badge.done { background: var(--done-bg); color: var(--done); }
.status-badge:disabled { opacity: 0.5; cursor: wait; transform: none; }

.exam-card.loading .exam-code::after {
  content: " loading\2026";
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8rem;
}

.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 17, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.settings-panel[hidden] {
  display: none;
}

.settings-card {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 22px;
  max-width: 440px;
  width: 92%;
  box-shadow: var(--shadow-lg);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-header h2 { font-size: 1.1rem; letter-spacing: -0.01em; }

.text-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  margin-bottom: 10px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.settings-actions {
  display: flex;
  gap: 8px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-contrast);
  border-color: transparent;
}

.btn.primary:hover {
  box-shadow: var(--shadow-md);
  filter: brightness(1.05);
}

.settings-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 10px;
}

.auth-error {
  font-size: 0.8rem;
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}

.auth-error.is-error {
  background: var(--progress-bg);
  color: var(--progress);
}

.settings-card {
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.settings-actions { flex-wrap: wrap; }

.settings-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.settings-section h3 {
  font-size: 0.95rem;
  margin: 0 0 6px;
}

.link-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.link-btn:hover { color: var(--text); }
.link-btn.danger { color: var(--weak); }

.delete-confirm {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--weak);
  border-radius: var(--radius-sm);
  background: var(--weak-bg);
}

.delete-confirm label.settings-note { display: block; }

.btn.danger,
.btn.danger:hover {
  background: var(--weak);
  border-color: var(--weak);
  color: var(--card-bg);
}

.btn.danger:disabled,
.btn.danger:disabled:hover {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: var(--weak);
}

/* ---------- gamification bar ---------- */

.game-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.game-stat {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.game-stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.game-stat-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.game-stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.game-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---------- home exam cards ---------- */

.exam-card {
  cursor: pointer;
  position: relative;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease), border-color 0.18s var(--ease);
}

.exam-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border);
}

.exam-card.studying {
  border-color: var(--studying);
  box-shadow: 0 0 0 2px var(--studying), var(--shadow-sm);
}

.exam-card.completed {
  border-color: var(--done);
  box-shadow: 0 0 0 2px var(--done), var(--shadow-sm);
}

.status-ribbon {
  position: absolute;
  top: -10px;
  left: 14px;
  color: var(--accent-contrast);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}

.status-ribbon.studying-ribbon {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.status-ribbon.completed-ribbon {
  background: var(--done);
}

.exam-card-heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.exam-name {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---------- back link ---------- */

.back-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  margin-bottom: 18px;
  transition: opacity 0.15s var(--ease);
}

.back-link:hover {
  text-decoration: underline;
  opacity: 0.85;
}

/* ---------- subject view ---------- */

.subject-head {
  margin-bottom: 22px;
}

.subject-code {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  padding: 3px 11px;
  margin-bottom: 9px;
}

.subject-head h2 {
  margin: 0 0 7px;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.015em;
}

.subject-blurb {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.55;
  max-width: 640px;
}

.mixed-session-btn {
  margin-top: 14px;
  font-weight: 700;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.module-card {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.module-card.clickable {
  cursor: pointer;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.module-card.clickable:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.module-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.module-card-id {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.module-card-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.005em;
}

.module-card-desc {
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
  flex: 1;
}

.module-card-desc.muted, .module-card-foot.muted {
  color: var(--text-muted);
  font-style: italic;
}

.module-card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}

.mastery-track {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--not-started-bg);
  overflow: hidden;
}

.mastery-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--star);
  transition: width 0.4s var(--ease);
}

.mastery-label {
  color: var(--star);
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- flashcard view ---------- */

.flash-head {
  margin-bottom: 14px;
}

.flash-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.flash-title-row h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.015em;
}

.flash-progress {
  font-size: 0.85rem;
  color: var(--star);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.flash-progress-track {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--not-started-bg);
  overflow: hidden;
  margin-top: 9px;
}

.flash-progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--star);
  transition: width 0.4s var(--ease);
}

.flash-mode-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.mode-tab {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  border-radius: var(--radius-pill);
  padding: 7px 15px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
}

.mode-tab:hover { transform: translateY(-1px); }

.mode-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.shuffle-btn {
  margin-left: auto;
  font-size: 0.8rem;
  padding: 7px 13px;
}

.card-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 18px 0;
}

.card-dot {
  min-width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
  transition: transform 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.card-dot:hover { transform: translateY(-1px); }

.card-dot.active {
  border-color: var(--accent);
  color: var(--accent);
}

.card-dot.mastered {
  background: var(--star-bg);
  color: var(--star);
  border-color: var(--star);
}

.flashcard {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 30px 26px;
  box-shadow: var(--shadow-md);
  max-width: 620px;
  position: relative;
  min-height: 220px;
}

.flashcard.is-mastered {
  border-color: var(--star);
}

.flashcard-star {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 1.3rem;
}

.flashcard-source {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  padding: 4px 11px;
  text-decoration: none;
  margin-bottom: 12px;
}

.flashcard-source:hover {
  text-decoration: underline;
}

.flashcard-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-bottom: 11px;
}

.flashcard-question {
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  margin-bottom: 18px;
  line-height: 1.45;
}

.answer-input {
  width: 100%;
  min-height: 80px;
  padding: 11px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  margin-bottom: 14px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.answer-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.flashcard-answer {
  background: var(--accent-soft);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  font-size: 0.95rem;
  line-height: 1.55;
  margin-bottom: 18px;
}

.flashcard-user-answer {
  background: var(--not-started-bg);
  color: var(--text);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  font-size: 0.95rem;
  line-height: 1.55;
  margin-bottom: 12px;
  white-space: pre-wrap;
}

.ai-grade-btn {
  width: 100%;
  margin-bottom: 12px;
  color: var(--accent);
  border-color: var(--accent);
}

.ai-grade-panel {
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-grade-panel.hint {
  color: var(--text-muted);
  background: var(--not-started-bg);
  font-size: 0.82rem;
}

.ai-grade-panel.loading {
  color: var(--text-muted);
  background: var(--not-started-bg);
}

.ai-grade-panel.error {
  color: var(--weak);
  background: var(--weak-bg);
}

.ai-grade-panel.strong {
  background: var(--done-bg);
}

.ai-grade-panel.partial {
  background: var(--progress-bg);
}

.ai-grade-panel.weak {
  background: var(--weak-bg);
}

.ai-grade-verdict {
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.ai-grade-panel.strong .ai-grade-verdict { color: var(--done); }
.ai-grade-panel.partial .ai-grade-verdict { color: var(--progress); }
.ai-grade-panel.weak .ai-grade-verdict { color: var(--weak); }

.ai-grade-feedback {
  color: var(--text);
}

.flash-score-row {
  display: flex;
  gap: 10px;
}

.score-btn {
  flex: 1;
  font-weight: 700;
  padding: 11px 14px;
}

.score-btn.sufficient {
  background: var(--done-bg);
  color: var(--done);
  border-color: var(--done);
}

.score-btn.insufficient {
  background: var(--progress-bg);
  color: var(--progress);
  border-color: var(--progress);
}

.score-btn:disabled {
  opacity: 0.5;
  cursor: wait;
  transform: none;
}

.flash-nav {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  max-width: 620px;
}

.flash-empty {
  color: var(--text-muted);
}

.flash-session-summary {
  max-width: 480px;
  margin: 24px auto 0;
  padding: 32px 28px;
  text-align: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

.summary-badge {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 8px;
}

.flash-session-summary h2 {
  margin: 0 0 4px;
}

.summary-title {
  color: var(--text-muted);
  margin: 0 0 16px;
}

.summary-stats {
  margin: 0 0 6px;
}

.summary-overall {
  margin: 0 0 20px;
  color: var(--text-muted);
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- explanation panel (flashcards + question bank) ---------- */
/* Mobile-first: a full-width section under the card/question by default.
   Only promoted to a right-hand column once there's room for both at a
   readable width (roughly tablet-landscape and up). */

.flashcard-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 620px;
}

@media (min-width: 860px) {
  .flashcard-layout.has-explain {
    flex-direction: row;
    align-items: flex-start;
    max-width: 980px;
  }
  .flashcard-layout.has-explain > .flashcard {
    flex: 1 1 560px;
    min-width: 0;
  }
  .flashcard-layout.has-explain > .explain-panel {
    flex: 1 1 340px;
    max-width: 360px;
    align-self: stretch;
  }
}

.explain-panel {
  background: var(--accent-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 17px 19px;
}

.explain-panel summary {
  cursor: pointer;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--accent);
  list-style: none;
  user-select: none;
}

.explain-panel summary::-webkit-details-marker { display: none; }
.explain-panel summary::before { content: "\25b8\a0"; }
.explain-panel[open] summary::before { content: "\25be\a0"; }

.explain-body {
  margin-top: 11px;
  font-size: 0.88rem;
  line-height: 1.62;
  color: var(--text);
}

.explain-body p { margin: 0 0 10px; }
.explain-body p:last-child { margin-bottom: 0; }

/* ---------- practice exam question bank ---------- */

.qbank-btn {
  margin-top: 10px;
  font-weight: 700;
}

.qbank-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 620px;
  margin: 0 0 16px;
}

.qbank-note a {
  color: var(--accent);
}

.question-card {
  padding: 26px;
}

.question-meta {
  font-size: 0.74rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-bottom: 7px;
}

.question-title {
  margin: 0 0 20px;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.question-part {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-soft);
}

.question-part:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.part-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 7px;
}

.part-label {
  font-weight: 800;
}

.part-marks {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.part-question {
  margin-bottom: 11px;
  line-height: 1.55;
}

.part-answer {
  background: var(--accent-soft);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  font-size: 0.92rem;
  line-height: 1.58;
}

.qbank-reveal-row {
  margin-top: 4px;
}

.qbank-done-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- self-marking and mock papers ---------- */

.self-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.mark-input.text-input {
  width: 5.5em;
  margin: 0;
  padding: 6px 8px;
  font-variant-numeric: tabular-nums;
}

.mark-input[aria-invalid="true"] {
  border-color: var(--weak);
  box-shadow: 0 0 0 3px var(--weak-bg);
}

.self-mark-of { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.self-mark-panel { margin-top: 6px; }

.self-mark-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.self-mark-total { font-weight: 700; font-variant-numeric: tabular-nums; }

.self-mark-error { color: var(--weak); font-size: 0.85rem; font-weight: 600; margin: 10px 0 0; }

.self-mark-history { font-size: 0.8rem; color: var(--text-muted); margin: 12px 0 0; line-height: 1.9; }

.mark-chip {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mark-chip small { font-weight: 400; color: var(--text-muted); }

.score-summary { font-size: 0.85rem; color: var(--text-muted); margin: 8px 0 0; }
.score-summary strong { color: var(--text); }

.vs-pass { font-weight: 700; }
.vs-pass.above { color: var(--done); }
.vs-pass.below { color: var(--weak); }

.mock-btn { margin-top: 10px; }

/* Sticks just under the sticky header; app.js keeps --topbar-h current. */
.mock-bar {
  position: sticky;
  top: calc(var(--topbar-h, 64px) + 8px);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.mock-bar .btn { margin-left: auto; }

.mock-clock, .mock-total {
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.mock-clock.low { color: var(--weak); }

.mock-question { margin-bottom: 14px; }

.mock-intro p { line-height: 1.6; margin: 0 0 12px; }

.mock-note { font-size: 0.82rem; color: var(--text-muted); line-height: 1.55; margin: 8px 0 0; }

.mock-foot { display: flex; justify-content: flex-end; margin: 6px 0 20px; }

.mock-result {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card-bg);
}

.mock-result.pass { border-color: var(--done); background: var(--done-bg); }
.mock-result.fail { border-color: var(--weak); background: var(--weak-bg); }

.mock-result-pct {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mock-result-text { line-height: 1.55; font-size: 0.9rem; }
.mock-result-text strong { display: block; }

/* the dashboard's self-marked bars: the tick is the pass mark */
.dash-bar.pass-bar { position: relative; overflow: visible; }
.dash-bar.pass-bar .dash-bar-fill { background: var(--weak); }
.dash-bar.pass-bar .dash-bar-fill.above { background: var(--done); }

.pass-tick {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
}

/* ---------- spaced repetition ---------- */

.muted { color: var(--text-muted); }

.due-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 15px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.due-banner:empty { display: none; }

.due-banner.has-due {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.due-banner-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.due-banner-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.due-banner-sub a { font-weight: 700; text-decoration: none; }

.due-banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

a.btn { text-decoration: none; display: inline-block; }

.subject-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 14px;
}

.subject-actions .mixed-session-btn { margin-top: 0; }

.srs-label {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  background: var(--not-started-bg);
  color: var(--not-started);
}

.srs-label.due { background: var(--progress-bg); color: var(--progress); }
.srs-label.scheduled { background: var(--done-bg); color: var(--done); }

.due-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--progress-bg);
  color: var(--progress);
  font-size: 0.7rem;
  font-weight: 800;
}

/* ---------- study dashboard ---------- */

.dash-tiles a.game-stat { color: inherit; text-decoration: none; }

.dash-section {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.dash-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.dash-section-head h3 { margin: 0; font-size: 1rem; letter-spacing: -0.01em; }

.dash-sub { margin: 18px 0 8px; font-size: 0.85rem; }

.dash-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 12px;
}

.dash-table { display: flex; flex-direction: column; }

.dash-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 150px;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-top: 1px solid var(--border-soft);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
}

.dash-row:first-child { border-top: none; }
.dash-row:hover { background: var(--accent-soft); }

.dash-row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dash-row-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.dash-row-bar { display: flex; align-items: center; gap: 8px; }

.dash-row-pct {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: right;
}

.dash-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  margin-right: 4px;
}

.dash-bar {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--not-started-bg);
  overflow: hidden;
  min-width: 60px;
}

.dash-bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--star);
}

.dash-bar.weak .dash-bar-fill { background: var(--weak); }

.trouble-list { margin: 0; padding-left: 22px; font-size: 0.85rem; }
.trouble-list li { margin-bottom: 9px; }
.trouble-list a { color: var(--text); text-decoration: none; }
.trouble-list a:hover .trouble-q { text-decoration: underline; }

.trouble-q {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 3px;
}

.trouble-meta { font-size: 0.72rem; color: var(--weak); font-weight: 700; }

.dash-cols {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  gap: 4px;
  align-items: end;
}

.dash-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.dash-col-val {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  min-height: 1em;
  font-variant-numeric: tabular-nums;
}

.dash-col-bar {
  width: 100%;
  max-width: 28px;
  height: 90px;
  display: flex;
  align-items: flex-end;
}

.dash-col-fill {
  width: 100%;
  min-height: 2px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
}

.dash-col-lbl { font-size: 0.64rem; color: var(--text-muted); white-space: nowrap; }

.heat-grid {
  display: grid;
  grid-template-rows: repeat(7, 12px);
  grid-auto-flow: column;
  grid-auto-columns: 12px;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.heat-cell {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--not-started-bg);
}

.heat-cell.l1 { background: color-mix(in srgb, var(--accent) 30%, var(--not-started-bg)); }
.heat-cell.l2 { background: color-mix(in srgb, var(--accent) 55%, var(--not-started-bg)); }
.heat-cell.l3 { background: color-mix(in srgb, var(--accent) 78%, var(--not-started-bg)); }
.heat-cell.l4 { background: var(--accent); }

.heat-legend {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.dash-subject {
  border-top: 1px solid var(--border-soft);
  padding: 10px 0;
}

.dash-subject:first-of-type { border-top: none; }

.dash-subject > summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 150px;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  font-size: 0.9rem;
}

.dash-subject > summary::-webkit-details-marker { display: none; }
.dash-subject > summary .dash-subject-name::before { content: "\25b8\a0"; color: var(--text-muted); }
.dash-subject[open] > summary .dash-subject-name::before { content: "\25be\a0"; }

.dash-subject-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-subject-meta { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }

.dash-subject-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 6px; }

.dash-inactive > summary { grid-template-columns: minmax(0, 1fr) auto; }
.dash-inactive .dash-subject { padding-left: 14px; }

@media (max-width: 640px) {
  .dash-row,
  .dash-subject > summary {
    grid-template-columns: minmax(0, 1fr) 90px;
  }
  .dash-row-meta,
  .dash-subject-meta { grid-column: 1; grid-row: 2; white-space: normal; }
  .dash-row-bar,
  .dash-subject > summary .dash-bar { grid-column: 2; grid-row: 1 / span 2; }
  .dash-row-pct { display: none; }
  .dash-inactive > summary { grid-template-columns: minmax(0, 1fr); }
  .dash-inactive .dash-subject-meta { grid-row: auto; }
  .dash-col-lbl { font-size: 0.55rem; }
  .dash-col:nth-child(even) .dash-col-lbl { visibility: hidden; }
  .dash-col-val { font-size: 0.6rem; }
}

/* ---------- keyboard hint ---------- */

.kbd-hint {
  margin: 18px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.kbd-hint kbd {
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--card-bg);
}

@media (hover: none) {
  .kbd-hint { display: none; }
}

/* ---------- search ---------- */

a.icon-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

.search-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.search-bar .text-input { margin: 0; }
.search-bar #searchInput { flex: 1 1 260px; }
.search-exam { flex: 0 0 auto; width: auto; }

.search-count { font-size: 0.78rem; margin: 0 0 8px; }

.search-result {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.search-result:hover { border-color: var(--accent); }

.search-result-label { font-size: 0.7rem; font-weight: 800; color: var(--accent); }
.search-result-q { font-size: 0.9rem; font-weight: 600; line-height: 1.45; }
.search-result-hit { font-size: 0.82rem; color: var(--text-muted); line-height: 1.45; }

.search-result mark {
  background: var(--star-bg);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

/* ---------- timed question mode ---------- */

.timer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 14px;
  padding: 10px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

.timer-toggle { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; cursor: pointer; }
.timer-rate { width: auto; margin: 0; padding: 6px 10px; }
.timer-note { font-size: 0.75rem; color: var(--text-muted); }

.timer-readout {
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 4.2ch;
}
.timer-readout.low { color: var(--progress); }
.timer-readout.over { color: var(--weak); }

.timer-result { font-weight: 700; }
.timer-result.ok { color: var(--done); }
.timer-result.over { color: var(--weak); }

.card-dot.in-time { box-shadow: inset 0 -3px 0 var(--done); }
.card-dot.over-time { box-shadow: inset 0 -3px 0 var(--weak); }

.pace-row { cursor: default; }
.pace-row:hover { background: none; }
.pace-figure { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 0.8rem; }
.pace-figure.ok { color: var(--done); }
.pace-figure.over { color: var(--weak); }

/* ---------- drills (multiple choice / select-all / cloze) ---------- */
/*
   Reuses the flashcard shell (.flashcard, .flash-head, .explain-panel) so a
   drill reads as the same kind of object as a card. Everything below is the
   bits a card doesn't have: selectable options, the cloze token tray, and the
   marked state. All colours come from the theme tokens, so this follows the
   light/dark toggle without a second palette.

   Correct/wrong deliberately reuse --done and --weak rather than raw green
   and red: those two already carry "good" and "needs work" everywhere else on
   the site, and they're the pair that has been checked against both themes.
*/

.drill-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 18px 0 4px;
}

.drill-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 13px 15px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), transform 0.1s var(--ease);
}

.drill-option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drill-option:active:not(:disabled) { transform: scale(0.995); }
.drill-option:disabled { cursor: default; }

.drill-option-mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: var(--not-started-bg);
  color: var(--not-started);
  font-size: 0.8rem;
  font-weight: 800;
}

.drill-option.picked {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drill-option.picked .drill-option-mark {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* Marked state. The right answer is always highlighted, whether or not it was
   the one picked -- seeing it is the point. A wrong pick is marked separately
   so a select-all with two rights and one wrong reads correctly. */
.drill-option.correct {
  border-color: var(--done);
  background: var(--done-bg);
}

.drill-option.correct .drill-option-mark {
  background: var(--done);
  color: var(--card-bg);
}

.drill-option.wrong {
  border-color: var(--weak);
  background: var(--weak-bg);
}

.drill-option.wrong .drill-option-mark {
  background: var(--weak);
  color: var(--card-bg);
}

.drill-type {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
}

.drill-verdict {
  margin: 16px 0 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: 0.95rem;
}

.drill-verdict.correct { background: var(--done-bg); color: var(--done); }
.drill-verdict.wrong { background: var(--weak-bg); color: var(--weak); }

.drill-why {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-left: 3px solid var(--weak);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--weak-bg);
  font-size: 0.92rem;
  line-height: 1.6;
}

.drill-why strong { color: var(--weak); }

/* ---------- calc (typed numerical answer) ---------- */

.calc-answer { margin: 18px 0 4px; }

.calc-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 700;
}

.calc-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calc-affix {
  color: var(--text-muted);
  font-weight: 700;
}

.calc-input {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 260px;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.calc-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.calc-input:disabled { opacity: 0.8; }

.calc-hint {
  margin: 6px 0 0;
  font-size: 0.82rem;
}

/* A long formula in a worked solution scrolls on its own rather than
   pushing the card wider than a phone screen. */
.calc-working .katex {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: middle;
  padding: 2px 0;
}

.calc-compare {
  margin: 0 0 12px;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ---------- cloze ---------- */

.cloze-text {
  margin: 18px 0 6px;
  font-size: 1.02rem;
  line-height: 2.1; /* roomy: the slots are taller than the text */
}

.cloze-slot {
  display: inline-block;
  min-width: 96px;
  padding: 3px 11px;
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border);
  background: var(--not-started-bg);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.cloze-slot.filled {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.cloze-slot.correct {
  border-style: solid;
  border-color: var(--done);
  background: var(--done-bg);
  color: var(--done);
}

.cloze-slot.wrong {
  border-style: solid;
  border-color: var(--weak);
  background: var(--weak-bg);
  color: var(--weak);
  text-decoration: line-through;
}

/* The right answer, shown next to a wrong pick inside the same slot. */
.cloze-actual {
  text-decoration: none;
  color: var(--done);
}

.cloze-actual::before { content: "\2192\00a0"; }

.drill-tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg);
}

.drill-tray-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.drill-token {
  padding: 7px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.drill-token:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drill-token.picked {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.drill-btn { margin-top: 10px; }

@media (max-width: 640px) {
  .drill-option { padding: 12px; font-size: 0.92rem; }
  .cloze-text { line-height: 2.3; }
  .cloze-slot { min-width: 80px; }
}

/* ---------- hotspot diagrams ---------- */
/*
   Two layers, styled independently (see docs/diagrams.js for the markup):
   .dg-art is the picture and never reacts to anything; .dg-hot sits on top
   and carries all the interaction. Marking an answer only toggles a class on
   a .hot group, so the diagram underneath never shifts or restyles — a wrong
   answer can't leave the user looking at a misleading picture.

   Every colour is a theme token, so diagrams follow the light/dark toggle
   with no second palette to maintain.
*/

.dg-figure {
  margin: 18px 0 6px;
  padding: 10px 6px 4px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg);
}

.dg-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.dg-caption {
  margin-top: 6px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.dg-hint {
  margin: 8px 0 0;
  font-size: 0.82rem;
}

/* --- artwork layer --- */

.dg-axes line {
  stroke: var(--text-muted);
  stroke-width: 1.5;
}

.dg-axis-title,
.dg-label {
  fill: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
}

.dg-label { fill: var(--text); }

.dg-curve {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* A second curve of the same family (MR against AR, AC against MC) is drawn
   in a quieter weight so the pair reads as related rather than competing. */
.dg-curve.muted { stroke: var(--text-muted); }
.dg-curve.dashed { stroke-dasharray: 7 5; }

.dg-guide {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0.7;
}

.dg-arrow {
  stroke: var(--text-muted);
  stroke-width: 2;
  fill: none;
  opacity: 0.8;
}

.dg-point {
  fill: var(--accent);
  stroke: var(--card-bg);
  stroke-width: 2;
}

/* The deadweight-loss triangle is shaded in the "needs work" colour, since
   that is what it represents everywhere else on the site. */
.dg-dwl {
  fill: var(--weak);
  opacity: 0.22;
  stroke: none;
}

/* --- interactive layer --- */

.hot { outline: none; }

/* The cursor lives on the figure, which is what actually receives the
   pointer: app.js decides which region a click means by measuring distance
   to each one (see nearestHotspot), so the region shapes take no events
   themselves. */
.dg-figure.dg-over { cursor: pointer; }

/* Geometry only. These paths mirror the artwork and are what those distances
   are measured against; they are never painted and never hit-tested. */
.hot-hit {
  fill: none;
  stroke: none;
  pointer-events: none;
}

/* Highlights inherit `color`, so each state only has to set that one
   property rather than juggling fill and stroke per region shape. */
.hot-mark {
  opacity: 0;
  color: var(--accent);
  transition: opacity 0.15s var(--ease);
  pointer-events: none;
}

.hot-mark.line {
  fill: none;
  stroke: currentColor;
  stroke-width: 8;
  stroke-linecap: round;
}

.hot-mark.area,
.hot-mark.dot {
  fill: currentColor;
  stroke: none;
}

.hot.hover .hot-mark { opacity: 0.3; }
.hot:focus-visible .hot-mark { opacity: 0.45; }
.hot.picked .hot-mark { opacity: 0.7; }

.hot.correct .hot-mark {
  opacity: 0.75;
  color: var(--done);
}

.hot.wrong .hot-mark {
  opacity: 0.75;
  color: var(--weak);
}

@media (max-width: 640px) {
  .dg-figure { margin-left: -4px; margin-right: -4px; }
  .dg-axis-title, .dg-label { font-size: 13px; }
}

/* ---------- exam hub (pass rates + IFoA dates) ---------- */

.hub-link {
  display: inline-block;
  margin: 10px 0 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}
.hub-link:hover { text-decoration: underline; }

.hub-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 700;
}
.hub-picker .text-input { width: auto; max-width: 100%; flex: 0 1 420px; margin: 0; }

.hub-subject-line { font-size: 0.8rem; margin: 0 0 16px; }
.hub-subject-line a { color: var(--text-muted); text-decoration: none; }
.hub-subject-line a:hover { color: var(--accent); text-decoration: underline; }

.hub-papers { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }

.hub-paper {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  font-size: 0.9rem;
}
.hub-paper-name { font-weight: 800; color: var(--accent); }
.hub-paper-count { font-weight: 700; font-variant-numeric: tabular-nums; }
.hub-paper.past { background: var(--not-started-bg); color: var(--text-muted); }
.hub-paper.past .hub-paper-name { color: var(--text-muted); }

.hub-keydates {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.82rem;
  line-height: 1.5;
}
.hub-keydates li { padding: 3px 0; }
.hub-keydates li span {
  display: inline-block;
  min-width: 108px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.hub-keydates li.past { color: var(--text-muted); text-decoration: line-through; }

.hub-table-wrap { overflow-x: auto; }

.hub-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.hub-table th,
.hub-table td {
  padding: 8px 6px;
  border-top: 1px solid var(--border-soft);
  text-align: left;
  white-space: nowrap;
}
.hub-table thead th {
  border-top: none;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.hub-table tbody th { font-weight: 700; }
.hub-table .num { text-align: right; }
.hub-table sup { color: var(--progress); cursor: help; }
.hub-rate { width: 40%; min-width: 150px; }
.hub-rate .dash-bar { display: inline-block; vertical-align: middle; width: calc(100% - 56px); flex: none; }
.hub-rate .dash-row-pct { display: inline-block; margin-left: 8px; }

.hub-footnote { margin: 10px 0 0; }

.hub-session .hub-days { margin: 10px 0 12px; display: flex; flex-direction: column; gap: 4px; }

.hub-day {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  align-items: baseline;
  font-size: 0.82rem;
}
.hub-day-date { font-weight: 700; font-variant-numeric: tabular-nums; }
.hub-day-papers { display: flex; flex-wrap: wrap; gap: 4px; }
.hub-day.past { opacity: 0.55; }

.hub-chip {
  padding: 1px 7px;
  border-radius: var(--radius-sm);
  background: var(--not-started-bg);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 600;
}
.hub-chip.mine { background: var(--accent); color: var(--accent-contrast); font-weight: 800; }

.hub-session > summary { grid-template-columns: minmax(0, 1fr) auto; }

@media (max-width: 640px) {
  .hub-picker { flex-wrap: wrap; }
  .hub-picker .text-input { flex: 1 1 100%; }
  .hub-paper { grid-template-columns: 1fr auto; }
  .hub-paper-date { grid-column: 1 / -1; grid-row: 2; font-size: 0.8rem; }
  .hub-day { grid-template-columns: 1fr; gap: 3px; }
  .hub-keydates li span { display: block; min-width: 0; }
  .hub-table th, .hub-table td { padding: 7px 4px; }
  .hub-rate { min-width: 90px; }
  .hub-table thead th { white-space: normal; }
  .hub-sat { display: none; }
}

/* ---------- exam planner (study dashboard) ---------- */

.plan-sitting {
  padding: 12px 0;
  border-top: 1px solid var(--border-soft);
}

.plan-sitting:first-of-type { border-top: none; }
.plan-sitting.past { opacity: 0.8; }

.plan-sitting-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.plan-meta { font-size: 0.75rem; color: var(--text-muted); }

.plan-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.plan-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
}

.plan-chip a { color: inherit; text-decoration: none; }
.plan-chip.done { background: var(--done-bg); color: var(--done); }

.plan-chip-remove {
  border: none;
  background: none;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
}

.plan-chip-remove:hover { background: color-mix(in srgb, currentColor 15%, transparent); }

.plan-add.text-input {
  width: auto;
  max-width: min(100%, 240px);
  margin: 0;
  padding: 5px 10px;
  font-size: 0.8rem;
}

.plan-sitting.empty .plan-add.text-input { color: var(--text-muted); }

.plan-notes {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.plan-sitting .plan-notes { list-style: none; padding-left: 0; }
.plan-notes .plan-warn { color: var(--weak); font-weight: 600; }

.plan-more { margin-top: 6px; }

.plan-summary { margin-top: 6px; border-top: 1px solid var(--border-soft); }
.plan-summary .plan-notes { color: var(--text); font-size: 0.82rem; }

/* ---------- exam results, welcome and "did you pass?" ---------- */

.due-banner[hidden] { display: none; }

.status-ribbon.revised-ribbon {
  background: var(--not-started);
}

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.result-label { font-weight: 700; font-size: 0.9rem; }

.result-choice { display: inline-flex; gap: 0; }
.result-choice .btn { border-radius: 0; margin-left: -1px; }
.result-choice .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.result-choice .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.result-choice .btn[aria-pressed="true"] {
  background: var(--done-bg);
  border-color: var(--done);
  color: var(--done);
  position: relative;
}

.btn.small { padding: 6px 12px; font-size: 0.8rem; }

.results-prompt { border-color: var(--done); }

.result-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-list li,
.plan-notes .plan-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  flex-wrap: wrap;
}

.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.plan-notes .plan-result { color: var(--text); padding: 4px 0; }

.welcome-step {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.welcome-form { display: flex; flex-direction: column; gap: 16px; }

.welcome-group {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--card-bg);
  padding: 10px 18px 12px;
  margin: 0;
}

.welcome-group legend {
  padding: 0 6px;
  font-weight: 800;
  font-size: 0.85rem;
}

.welcome-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  border-top: 1px solid var(--border-soft);
}

.welcome-row:first-of-type { border-top: none; }

.welcome-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  min-width: 0;
}

.welcome-row input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--accent); }

.welcome-how.text-input { width: auto; max-width: 50%; flex-shrink: 1; margin: 0; padding: 5px 10px; font-size: 0.8rem; }
/* Fieldsets default to min-width: min-content, which would stop a row
   shrinking to a phone's width. */
.welcome-group { min-width: 0; }

.welcome-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- route map (home page) ---------- */

:root {
  --rm-principles: #c0392b;
  --rm-practice: #1f5fad;
  --rm-sp: #2e7d4f;
  --rm-sa: #936509;
  --rm-fnd: #6b4f96;
  --rm-warn: #b91c1c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --rm-principles: #ef7a6e;
    --rm-practice: #6ea8f0;
    --rm-sp: #5cc28a;
    --rm-sa: #e8b04a;
    --rm-fnd: #b79be0;
    --rm-warn: #f87171;
  }
}

:root[data-theme="dark"] {
  --rm-principles: #ef7a6e;
  --rm-practice: #6ea8f0;
  --rm-sp: #5cc28a;
  --rm-sa: #e8b04a;
  --rm-fnd: #b79be0;
  --rm-warn: #f87171;
}

.route-map {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 20px 20px 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.route-map:empty { display: none; }

.route-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.route-eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rm-principles);
}

.route-title {
  margin: 4px 0 0;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.route-title em { font-style: normal; color: var(--accent); }

.route-canvas { margin: 8px -20px 0; overflow: hidden; }

.route-svg { display: block; font-family: var(--font-sans); }

.rm-principles { --rm: var(--rm-principles); }
.rm-practice { --rm: var(--rm-practice); }
.rm-sp { --rm: var(--rm-sp); }
.rm-sa { --rm: var(--rm-sa); }

.rm-track { fill: none; stroke: var(--rm); stroke-width: 8; stroke-linecap: round; }
.rm-track.rm-dashed { stroke-dasharray: 12 9; stroke-linecap: butt; opacity: 0.55; }

.rm-start { fill: var(--text); }

.rm-small {
  fill: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.rm-passed-label {
  fill: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.rm-sign rect { fill: var(--text); }
.rm-sign text { fill: var(--card-bg); font-size: 12px; font-weight: 800; letter-spacing: 0.06em; }
.rm-sign.suggested rect { fill: none; stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 4 3; }
.rm-sign.suggested text { fill: var(--text-muted); }
.rm-sign.past rect { fill: var(--text-muted); }

.rm-clash circle { fill: var(--rm-warn); }
.rm-clash text { fill: var(--on-line); font-size: 14px; font-weight: 800; }

.rm-station circle { fill: var(--card-bg); stroke: var(--text); stroke-width: 3.5; }
.rm-station text { fill: var(--text); font-size: 14px; font-weight: 800; }
.rm-station.passed circle { fill: var(--rm); stroke-width: 2.5; }
.rm-station.suggested circle { stroke: var(--text-muted); stroke-width: 2.5; stroke-dasharray: 4 3; }
.rm-station.suggested text { fill: var(--text-muted); font-weight: 600; }
.rm-tick { fill: none; stroke: var(--on-line); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.rm-station:hover circle, .rm-station:focus circle { stroke: var(--accent); stroke-width: 4; }
.rm-station:focus { outline: none; }
.rm-station:focus-visible text { text-decoration: underline; }

.rm-interchange circle { fill: var(--card-bg); stroke: var(--text); stroke-width: 6; }
.rm-interchange .rm-core { fill: var(--text); stroke: none; }
.rm-interchange .rm-name { fill: var(--text); font-size: 15px; font-weight: 800; }
.rm-interchange.faded { opacity: 0.5; }

.rm-fork circle { stroke: none; }
.rm-hit { fill: transparent; }
.rm-fork-arm { fill: none; stroke: var(--rm); stroke-width: 6; stroke-linecap: round; }
.rm-fork .rm-sp-dot { fill: var(--rm-sp); }
.rm-fork .rm-sa-dot { fill: var(--rm-sa); }
.rm-fork:hover .rm-small, .rm-fork:focus .rm-small { fill: var(--accent); }

.rm-here rect { fill: var(--text); }
.rm-here circle { fill: #f2c14e; }
.rm-here path { stroke: var(--text); stroke-width: 1.5; }
.rm-here text { fill: var(--card-bg); font-size: 10px; font-weight: 800; letter-spacing: 0.08em; }

.route-clashes { margin: 4px 0 8px; }

.route-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.route-legend > span { display: inline-flex; align-items: center; gap: 7px; }

.rm-key {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2.5px solid var(--text);
  background: var(--card-bg);
}

.rm-key.passed { background: var(--rm-principles); border-width: 2px; }
.rm-key.suggested { border: 2px dashed var(--text-muted); }

.route-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--border-soft);
}

.route-facts > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px 4px 0;
}

.route-fact-label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.route-fact-value { font-size: 1.02rem; font-weight: 800; }
.route-fact-sub { font-size: 0.78rem; color: var(--text-muted); }

.spec-chooser { margin-top: 12px; border-top: 1px solid var(--border-soft); padding-top: 10px; }
.spec-chooser summary { cursor: pointer; font-weight: 700; font-size: 0.88rem; min-height: 32px; display: flex; align-items: center; }
.spec-chooser fieldset { border: 0; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 16px; }
.spec-chooser legend { font-weight: 800; font-size: 0.8rem; margin-bottom: 4px; }
.spec-option { display: flex; align-items: center; gap: 8px; min-height: 36px; font-size: 0.85rem; cursor: pointer; }
.spec-option.locked { cursor: default; }
.spec-option input { width: 18px; height: 18px; accent-color: var(--accent); }

@media (max-width: 640px) {
  .route-map { padding: 16px 14px 12px; }
  .route-canvas { margin: 8px -14px 0; }
  .route-title { font-size: 1.25rem; }
  .route-facts { grid-template-columns: minmax(0, 1fr); }
  .route-facts > div { padding: 10px 0 4px; border-top: 1px solid var(--border-soft); }
  .route-facts > div:first-child { border-top: none; }
}

/* ======================================================================
   The Fellowship Line — component styles
   Transport-map print: flat paper surfaces with hairline borders, pill
   buttons like station signs, Fraunces for headings, Jost for text, and
   the four line colours as the only accents.
   ====================================================================== */

button, input, select, textarea { font-family: inherit; }

h1, h2, h3,
.subject-head h2,
.game-stat-value,
.route-title,
.flash-session-summary h2 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.subject-head h2 { font-weight: 400; font-size: 2.1rem; line-height: 1.1; }
.route-title { font-weight: 400; font-size: 1.75rem; }
.route-title em { font-style: italic; font-weight: 600; color: var(--text); }

/* icons */
.ico {
  width: 1.15em;
  height: 1.15em;
  flex-shrink: 0;
  vertical-align: -0.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ico-star { fill: var(--star); stroke: var(--star); stroke-width: 1.2; }

/* header: the Route F mark + name, round icon buttons */
.topbar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 1.3rem; }
.topbar-home { display: inline-flex; align-items: center; gap: 12px; }
/* An "F" drawn as a route: a red line with stations at its three ends. */
.mark { width: 30px; height: 30px; flex-shrink: 0; }
.mark-line { fill: none; stroke: var(--rm-principles); stroke-width: 4.6; stroke-linecap: round; stroke-linejoin: round; }
.mark-stop { fill: var(--bg); stroke: var(--text); stroke-width: 2.4; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.icon-btn .ico { width: 19px; height: 19px; }
.icon-btn:hover { background: var(--card-bg); border-color: var(--text); transform: none; }
.icon-btn[aria-current="page"] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* buttons: station-sign pills */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  padding: 9px 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
a.btn { display: inline-flex; }
.btn:hover { transform: none; box-shadow: none; border-color: var(--text); }
.btn.primary {
  background: var(--ink-button);
  color: var(--ink-button-text);
  border-color: var(--ink-button);
}
.btn.primary:hover { filter: none; box-shadow: none; background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn:disabled:hover { border-color: var(--border); }

/* flat paper surfaces */
.game-stat,
.exam-card,
.module-card,
.due-banner,
.dash-section,
.route-map,
.welcome-group,
.explain-panel {
  box-shadow: none;
  border-color: var(--border);
}
.game-stat:hover,
.exam-card:hover,
.module-card.clickable:hover { transform: none; box-shadow: none; border-color: var(--text); }

.game-stat-icon { color: var(--text-muted); }
.game-stat-icon .ico { width: 22px; height: 22px; }
.game-stat-value { font-size: 1.6rem; }

/* home: each subject card carries its line colour */
.exam-card[data-stage="principles"] { --line: var(--rm-principles); }
.exam-card[data-stage="practice"] { --line: var(--rm-practice); }
.exam-card[data-stage="sp"] { --line: var(--rm-sp); }
.exam-card[data-stage="sa"] { --line: var(--rm-sa); }
.exam-card[data-stage="foundations"] { --line: var(--rm-fnd); }
.exam-code { display: inline-flex; align-items: center; gap: 8px; font-size: 1.1rem; }
.exam-code::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 3px solid var(--line, var(--text));
  background: var(--card-bg);
}
.exam-card.completed .exam-code::before { background: var(--line, var(--text)); }
.exam-bar { height: 5px; border-radius: 0; background: var(--border-soft); }
.exam-bar-fill { border-radius: 0; background: var(--line, var(--accent)); }
.exam-card.studying,
.exam-card.completed { box-shadow: none; }
.exam-card.studying { border-color: var(--line, var(--studying)); }
.exam-card.completed { border-color: var(--done); }

.status-ribbon {
  box-shadow: none;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 4px 11px;
  background: var(--text);
  color: var(--bg);
}
.status-ribbon.studying-ribbon { background: var(--line, var(--accent)); color: var(--on-line); }
.status-ribbon.completed-ribbon { background: var(--done); color: var(--on-line); }
.status-ribbon.revised-ribbon { background: var(--text-muted); color: var(--bg); }
.status-ribbon.awaiting-ribbon { background: var(--progress-bg); color: var(--progress); box-shadow: inset 0 0 0 1px var(--progress); }

.subject-code { background: transparent; border: 1.5px solid var(--accent); color: var(--accent); }
.hub-link { display: inline-flex; align-items: center; gap: 6px; }
.mode-tab:hover { transform: none; }

/* flashcards: an index card — red header rule, blue ruled lines */
.flashcard:not(.question-card):not(.drill-card) {
  border-radius: 4px;
  border: 1px solid var(--border);
  background-color: var(--card-bg);
  /* Header rule under the card's label line, and a short ruled band along
     the bottom edge. Full-height ruling can't stay aligned with text of
     every size, so the body of the card is left plain. */
  background-image:
    linear-gradient(var(--card-margin), var(--card-margin)),
    repeating-linear-gradient(to top, transparent 0 11px, var(--card-rule) 11px 12px);
  background-size: 100% 2px, 100% 36px;
  background-position: 0 58px, 0 100%;
  background-repeat: no-repeat, no-repeat;
  padding-bottom: 44px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.flashcard.is-mastered { border-color: var(--border); }
.flashcard-star .ico { width: 24px; height: 24px; }
.flashcard-question { font-family: var(--font-display); font-weight: 400; }
.flashcard-user-answer { font-family: var(--font-display); font-style: italic; }
.question-card, .drill-card { border-radius: 6px; box-shadow: var(--shadow-lg); }

@media (min-width: 641px) {
  .flashcard:not(.question-card):not(.drill-card) { transform: rotate(-0.35deg); }
}

.score-btn { border-radius: var(--radius-pill); }
.score-btn.sufficient { background: var(--rm-principles); border-color: var(--rm-principles); color: var(--on-line); }
.score-btn.insufficient { background: transparent; border-color: var(--rm-practice); color: var(--rm-practice); }
.score-btn.sufficient:hover { background: var(--rm-principles); border-color: var(--text); }
.score-btn:disabled { opacity: 0.75; }

/* the rubber stamp pressed on a graded card */
.card-stamp {
  position: absolute;
  top: 70px;
  right: 34px;
  padding: 8px 18px;
  border: 5px double currentColor;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.88;
  pointer-events: none;
  animation: stamp-in 0.18s var(--ease) both;
}
.card-stamp.good { color: var(--rm-principles); transform: rotate(-12deg); }
.card-stamp.again { color: var(--rm-practice); transform: rotate(8deg); }
@keyframes stamp-in {
  from { opacity: 0; scale: 1.6; }
  to { opacity: 0.88; scale: 1; }
}

.card-dot .ico { width: 14px; height: 14px; vertical-align: -0.15em; }
.mastery-label .ico, .dash-subject-meta .ico { width: 13px; height: 13px; }
.summary-badge { color: var(--done); }
.summary-badge .ico { width: 44px; height: 44px; }

@media (max-width: 640px) {
  .topbar h1 { font-size: 1.05rem; }
  .mark { width: 26px; height: 26px; }
  .topbar-home { gap: 8px; }
  .subject-head h2 { font-size: 1.7rem; }
  .card-stamp { top: 56px; right: 16px; font-size: 1.25rem; }
}

/* ---------- home: subjects grouped by line ---------- */

.exam-groups { display: flex; flex-direction: column; gap: 30px; }

.exam-group[data-stage="principles"] { --line: var(--rm-principles); }
.exam-group[data-stage="practice"] { --line: var(--rm-practice); }
.exam-group[data-stage="sp"] { --line: var(--rm-sp); }
.exam-group[data-stage="sa"] { --line: var(--rm-sa); }
.exam-group[data-stage="foundations"] { --line: var(--rm-fnd); }

.exam-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
  flex-wrap: wrap;
  padding-top: 12px;
  margin-bottom: 14px;
  border-top: 6px solid var(--line);
}

.exam-group-title { margin: 0; font-size: 1.35rem; }

.exam-group-summary {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ---------- brand: "Fellow" with a descriptor ---------- */

.brand { display: flex; flex-direction: column; line-height: 1; }
.brand-name { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub {
  margin-top: 4px;
  font-family: var(--font-sans);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  .brand-name { font-size: 1.25rem; }
  .brand-sub { font-size: 0.55rem; letter-spacing: 0.1em; }
}

.brand-sub { white-space: nowrap; }
.topbar h1 { min-width: 0; overflow: hidden; }

/* Narrow phones: the name alone (the header's icons need the room). */
@media (max-width: 420px) {
  .brand-sub { display: none; }
}

/* The narrowest phones (≈320px): drop the mark and tighten the icons so
   the name still shows in full. */
@media (max-width: 360px) {
  .topbar-inner { gap: 8px; }
  .topbar .mark { display: none; }
  .brand-name { font-size: 1.15rem; }
  .topbar-right { gap: 4px; }
  .topbar .icon-btn { width: 30px; height: 30px; }
  .topbar .icon-btn .ico { width: 17px; height: 17px; }
}

/* ---------- foundations: lessons and prerequisites ---------- */

.paused-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 12px 0 4px;
  padding: 10px 14px;
  max-width: 68ch;
  border-radius: var(--radius-md);
  background: var(--progress-bg);
  color: var(--text);
  font-size: 0.88rem;
}
.paused-note .ico { flex-shrink: 0; width: 17px; height: 17px; margin-top: 1px; color: var(--progress); }

.foundation-note {
  margin: 10px 0 4px;
  font-size: 0.88rem;
  color: var(--text-muted);
  max-width: 62ch;
}

.lesson-panel,
.prereq-panel {
  margin: 14px 0 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--rm-fnd);
  border-radius: var(--radius-xl);
  padding: 14px 18px;
}
.lesson-panel summary,
.prereq-panel summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.92rem;
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.lesson-panel summary::-webkit-details-marker,
.prereq-panel summary::-webkit-details-marker { display: none; }
.lesson-panel summary::after,
.prereq-panel summary::after { content: "\25be"; margin-left: auto; color: var(--text-muted); }
.lesson-panel[open] summary::after,
.prereq-panel[open] summary::after { content: "\25b4"; }
.lesson-panel summary .ico { width: 17px; height: 17px; color: var(--rm-fnd); }

.lesson-body {
  margin-top: 12px;
  font-size: 0.95rem;
  line-height: 1.68;
  max-width: 72ch;
  overflow-wrap: break-word;
}
.lesson-body p { margin: 0 0 12px; }
.lesson-body h4 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 18px 0 6px;
}
.lesson-body ul { margin: 0 0 12px; padding-left: 20px; }
.lesson-body li { margin-bottom: 4px; }
.lesson-body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.lesson-body .worked {
  margin: 12px 0;
  padding: 11px 14px;
  background: var(--accent-soft);
  border-radius: var(--radius-md, 8px);
  font-size: 0.92rem;
  overflow-x: auto;
}

.prereq-panel { margin: 14px 0 6px; }
.prereq-intro { margin: 10px 0; font-size: 0.86rem; color: var(--text-muted); }
.prereq-links { display: flex; flex-wrap: wrap; gap: 8px; }
.prereq-link {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.84rem;
  color: var(--text);
  text-decoration: none;
  background: var(--bg);
}
.prereq-link:hover { border-color: var(--rm-fnd); }
.prereq-code { white-space: nowrap; font-weight: 700; font-size: 0.72rem; letter-spacing: 0.06em; color: var(--rm-fnd); }

/* Sections opened by link (#/dashboard/plan) clear the sticky header. */
.dash-section { scroll-margin-top: 84px; }
.dash-section-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- flashcard notes, flags and "Report a mistake" ---------- */

.card-flag-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  cursor: pointer;
  vertical-align: 1px;
}
.card-flag-btn .ico { width: 12px; height: 12px; }
.card-flag-btn:hover { border-color: var(--progress); color: var(--progress); }
.card-flag-btn.on { background: var(--progress-bg); border-color: var(--progress); color: var(--progress); }
.card-flag-btn.on .ico { fill: currentColor; }

.card-note {
  margin: -6px 0 16px;
  padding: 10px 14px;
  border-left: 3px solid var(--progress);
  background: var(--progress-bg);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 0.9rem;
  line-height: 1.55;
}
.card-note.editing { background: transparent; border-left-color: var(--border); padding-right: 0; }
.card-note-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--progress);
  margin-bottom: 4px;
}
.card-note.editing .card-note-head { color: var(--text-muted); margin-bottom: 6px; }
.card-note-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); }
.card-note .note-input { min-height: 70px; margin-bottom: 8px; }
.card-note-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card-note-add { margin: -8px 0 14px; }

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.link-btn .ico { width: 14px; height: 14px; }

.report-row { margin-top: 14px; text-align: right; }
.report-link { font-size: 0.78rem; color: var(--text-muted); text-decoration: none; }
.report-link:hover { color: var(--accent); text-decoration: underline; }
.report-link .ico { width: 12px; height: 12px; }

/* ---------- Today card (home) ---------- */

.due-banner.today-card {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}
.today-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.today-title { margin: 0; font-size: 1.3rem; font-weight: 400; }
.today-dash { font-size: 0.82rem; font-weight: 700; color: var(--accent); text-decoration: none; }
.today-dash:hover { text-decoration: underline; }
.today-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
}
.today-row + .today-row { border-top: 1px solid var(--border-soft); padding-top: 12px; }

/* ---------- readiness ---------- */

.readiness-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 10px 0 4px;
  font-size: 0.85rem;
}
.readiness-badge {
  display: inline-block;
  padding: 2px 10px;
  border: 1px solid var(--text);
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.8rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.readiness-badge.small { padding: 0 8px; font-size: 0.72rem; }
.readiness-parts { color: var(--text); }
.readiness-note { flex-basis: 100%; font-size: 0.75rem; color: var(--text-muted); }
.rm-sign .rm-ready { font-weight: 600; }

/* Honour the OS "reduce motion" setting: no transitions, animations or
   smooth scrolling. (The grading stamp's pause is skipped in app.js.) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Waiting for a subject's content file (see loadContent in app.js), or it
   failed to arrive. */
.content-loading {
  color: var(--text-muted);
  margin: 24px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.content-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: content-spin 0.8s linear infinite;
}
@keyframes content-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .content-loading::before { animation: none; }
}
.content-error {
  color: var(--weak);
  background: var(--weak-bg);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin: 16px 0;
}
.content-error p { margin: 0 0 10px; }
.search-status { margin: 8px 0 12px; }
