/* Wave, Signal & Matter Academy — Editorial Textbook & Python Studio Stylesheet
 * Zero external fonts or CDNs. Supports Dark/Light themes + Print stylesheet.
 * Exposes --bg-card, --text, --accent, --border for interactive visualizers.
 * License: Apache-2.0
 */

:root {
  --bg: #0b101b;
  --bg-sidebar: #0f1625;
  --bg-card: #131c2e;
  --bg-elevated: #19243b;
  --bg-code: #0a0f1a;
  --bg-input: #0d1422;
  --text: #e6edf7;
  --text-strong: #f8fafc;
  --text-muted: #93a4be;
  --border: #24324c;
  --border-strong: #344769;
  --accent: #38bdf8;
  --accent-hover: #7dd3fc;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --solarboot: #2dd4bf;
  --solarboot-soft: rgba(45, 212, 191, 0.14);
  --independent: #a78bfa;
  --independent-soft: rgba(167, 139, 250, 0.15);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Cambria Math", "STIX Two Math", Georgia, "Times New Roman", serif;
  --font-mono: "Cascadia Code", "Fira Code", Consolas, "Liberation Mono", "Courier New", monospace;
  --sidebar-width: 300px;
  --radius: 10px;
}

[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-elevated: #f1f4f9;
  --bg-code: #f4f6fa;
  --bg-input: #ffffff;
  --text: #1e293b;
  --text-strong: #0f172a;
  --text-muted: #52627a;
  --border: #d8e0ec;
  --border-strong: #b7c4d8;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.11);
  --success: #15803d;
  --success-soft: rgba(21, 128, 61, 0.11);
  --warning: #b45309;
  --warning-soft: rgba(180, 83, 9, 0.12);
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, 0.11);
  --solarboot: #0f766e;
  --solarboot-soft: rgba(15, 118, 110, 0.11);
  --independent: #6d28d9;
  --independent-soft: rgba(109, 40, 217, 0.1);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* =========================================================================
 * Layout Shell & Sidebar
 * ========================================================================= */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.mobile-header {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 40;
}

.sidebar-top {
  padding: 16px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-strong);
  text-decoration: none;
}
.brand-link:hover {
  text-decoration: none;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--independent));
  color: #ffffff;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}
.brand-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.mode-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease;
}
.mode-badge:hover {
  border-color: var(--accent);
}
.mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.mode-badge.mode-studio {
  background: var(--success-soft);
  border-color: rgba(34, 197, 94, 0.35);
  color: var(--success);
}
.mode-badge.mode-studio .mode-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}
.mode-badge.mode-static {
  background: var(--warning-soft);
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--warning);
}
.mode-badge.mode-static .mode-dot {
  background: var(--warning);
}

.search-wrap {
  position: relative;
}
.search-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.search-input:focus {
  border-color: var(--accent);
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 60;
}
.search-result-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 12.5px;
}
.search-result-item:last-child {
  border-bottom: none;
}
.search-result-item:hover {
  background: var(--accent-soft);
}
.search-result-kind {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-weight: 700;
}
.search-result-title {
  font-weight: 600;
  color: var(--text-strong);
}
.search-result-snippet {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quick-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.quick-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}
.quick-nav-item:hover {
  background: var(--bg-elevated);
  text-decoration: none;
}
.quick-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.pill-count {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-tracks {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 10px 16px;
}

.track-group {
  margin-bottom: 10px;
}
.track-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 8px;
  border: none;
  background: transparent;
  color: var(--text-strong);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
}
.track-group-header:hover {
  background: var(--bg-elevated);
}
.track-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 7px;
  flex-shrink: 0;
}
.track-group-title {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.track-group-count {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 6px;
}
.track-modules {
  padding-left: 6px;
  margin-top: 3px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.track-group.collapsed .track-modules {
  display: none;
}
.nav-module-link {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text-muted);
  text-decoration: none;
}
.nav-module-link:hover {
  background: var(--bg-elevated);
  color: var(--text-strong);
  text-decoration: none;
}
.nav-module-link.active {
  background: var(--accent-soft);
  color: var(--text-strong);
  font-weight: 600;
}
.nav-check {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
  margin-top: 1px;
}
.nav-check.done {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}
.nav-mod-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  margin-right: 4px;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
}
.footer-progress-row {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.progress-bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-elevated);
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 999px;
  transition: width 0.25s ease;
}
.footer-actions {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

/* =========================================================================
 * Main Content Area & Common Cards
 * ========================================================================= */

.main-content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 28px 36px 72px;
  max-width: 1040px;
  margin: 0 auto;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 22px;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.section-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-strong);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  text-decoration: none;
}
.btn:hover {
  border-color: var(--accent);
  text-decoration: none;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-sm {
  padding: 5px 9px;
  font-size: 12px;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04111f;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #03150a;
}
.btn-warning {
  background: var(--warning-soft);
  border-color: var(--warning);
  color: var(--warning);
}
.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover {
  color: var(--text-strong);
  background: var(--bg-elevated);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-strong);
  border-radius: 7px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Attribution & Meta Badges */
.umbrella-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
}
.umbrella-solarboot {
  background: var(--solarboot-soft);
  border-color: rgba(45, 212, 191, 0.35);
  color: var(--solarboot);
}
.umbrella-independent {
  background: var(--independent-soft);
  border-color: rgba(167, 139, 250, 0.35);
  color: var(--independent);
}
.umbrella-vault {
  background: var(--warning-soft);
  border-color: rgba(245, 158, 11, 0.35);
  color: var(--warning);
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* =========================================================================
 * Overview Dashboard
 * ========================================================================= */

.hero-banner {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12), rgba(167, 139, 250, 0.12));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 28px 28px;
  margin-bottom: 24px;
}
.hero-banner h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.2;
  color: var(--text-strong);
}
.hero-subtitle {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 15.5px;
  max-width: 760px;
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-strong);
  line-height: 1.15;
}
.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

.track-cards-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.track-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.track-card h2 {
  margin: 6px 0 6px;
  font-size: 19px;
  color: var(--text-strong);
}
.track-card p {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 14.5px;
}
.module-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.module-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12.5px;
  text-decoration: none;
}
.module-chip:hover {
  border-color: var(--accent);
  text-decoration: none;
}
.module-chip.completed {
  border-color: rgba(34, 197, 94, 0.45);
  background: var(--success-soft);
}

/* =========================================================================
 * Module Reading View
 * ========================================================================= */

.module-header {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.module-header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.module-title {
  margin: 0 0 6px;
  font-size: 28px;
  line-height: 1.22;
  color: var(--text-strong);
}
.module-subtitle {
  margin: 0 0 12px;
  font-size: 15.5px;
  color: var(--text-muted);
}
.module-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.anchor-card {
  border-left: 4px solid var(--accent);
}
.paper-links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.paper-link-pill {
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}
.paper-link-pill strong {
  color: var(--accent);
}
.learning-goals {
  margin: 10px 0 0;
  padding-left: 20px;
}
.learning-goals li {
  margin-bottom: 5px;
}

.visualizer-card {
  padding: 18px 20px;
}
.visualizer-mount {
  margin-top: 12px;
  min-height: 200px;
  border-radius: 8px;
  overflow: hidden;
}
.visualizer-caption {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.textbook-section {
  font-size: 16px;
}
.textbook-section h2.sec-heading {
  margin: 0 0 12px;
  font-size: 21px;
  color: var(--text-strong);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

/* Worked Derivations (Progressive Reveal) */
.derivation-card {
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 16px 18px;
  margin-bottom: 14px;
  background: var(--bg-elevated);
}
.derivation-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-strong);
  margin: 0 0 8px;
}
.derivation-prompt {
  margin-bottom: 12px;
}
.derivation-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.hint-box {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 7px;
  background: var(--bg-card);
  border-left: 3px solid var(--warning);
}
.solution-box {
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: 7px;
  background: var(--bg-card);
  border-left: 3px solid var(--success);
}
.box-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Predict-Before-Run Quiz */
.predict-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
}
.predict-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14.5px;
  text-align: left;
  cursor: pointer;
}
.predict-option:hover {
  border-color: var(--accent);
}
.predict-option.correct {
  border-color: var(--success);
  background: var(--success-soft);
}
.predict-option.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}
.opt-letter {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.predict-feedback {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.predict-feedback.pass {
  border-color: var(--success);
  background: var(--success-soft);
}
.predict-feedback.fail {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* Live Python Playground */
.playground-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 12px 0 10px;
}
.code-editor {
  width: 100%;
  min-height: 270px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-code);
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.55;
  resize: vertical;
  tab-size: 4;
  outline: none;
}
.code-editor:focus {
  border-color: var(--accent);
}
.lab-console {
  margin-top: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-code);
  overflow: hidden;
}
.lab-console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
}
.lab-status-pass {
  color: var(--success);
}
.lab-status-fail {
  color: var(--danger);
}
.lab-console-body {
  margin: 0;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}
.lab-stderr {
  color: #fca5a5;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
  margin-top: 8px;
}
[data-theme="light"] .lab-stderr {
  color: var(--danger);
}
.solution-drawer {
  margin-top: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--bg-elevated);
}

/* Module Flashcards Preview */
.flashcard-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.mini-flashcard {
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  cursor: pointer;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.mini-flashcard:hover {
  border-color: var(--accent);
}
.mini-fc-side {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.module-footer-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

/* =========================================================================
 * Spaced Repetition Review View
 * ========================================================================= */

.srs-controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.srs-stage {
  max-width: 720px;
  margin: 0 auto;
}
.srs-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 28px 28px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.srs-divider {
  border: none;
  border-top: 1px dashed var(--border-strong);
  margin: 18px 0;
}
.srs-rating-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 18px;
}
.srs-rate-btn {
  padding: 12px 10px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-strong);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.srs-rate-btn small {
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-muted);
}
.srs-rate-again:hover { border-color: var(--danger); background: var(--danger-soft); }
.srs-rate-good:hover { border-color: var(--accent); background: var(--accent-soft); }
.srs-rate-easy:hover { border-color: var(--success); background: var(--success-soft); }

/* =========================================================================
 * Survival Vault View
 * ========================================================================= */

.vault-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.vault-tab {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
}
.vault-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.filter-input {
  flex: 1 1 240px;
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
}
.filter-select {
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
}

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}
.symbol-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.symbol-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.symbol-glyph {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}
.symbol-units {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 2px 7px;
  border-radius: 5px;
}
.symbol-formula {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg-elevated);
  overflow-x: auto;
}
.symbol-pitfall {
  font-size: 12.5px;
  padding: 7px 9px;
  border-radius: 6px;
  background: var(--warning-soft);
  border-left: 3px solid var(--warning);
}

.debug-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.sev-pill {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
}
.sev-Critical { background: var(--danger-soft); color: var(--danger); }
.sev-High { background: var(--warning-soft); color: var(--warning); }
.sev-Subtle { background: var(--accent-soft); color: var(--accent); }

.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.debug-block {
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--bg-elevated);
  font-size: 13.5px;
}

.playbook-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.playbook-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}
.playbook-step.checked {
  border-color: rgba(34, 197, 94, 0.45);
  background: var(--success-soft);
}
.playbook-step input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 3px;
  cursor: pointer;
  accent-color: var(--success);
}
.playbook-gate {
  margin-top: 6px;
  font-size: 12.5px;
  padding: 6px 9px;
  border-radius: 6px;
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
}

/* =========================================================================
 * Markdown & Offline LaTeX Math Typography
 * ========================================================================= */

.md-p {
  margin: 0 0 12px;
}
.md-h {
  margin: 18px 0 8px;
  color: var(--text-strong);
}
.md-list {
  margin: 0 0 14px;
  padding-left: 24px;
}
.md-list li {
  margin-bottom: 5px;
}
.md-quote {
  margin: 12px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  border-radius: 0 7px 7px 0;
}
.md-quote p:last-child {
  margin-bottom: 0;
}
.md-hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}
.md-inline-code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.md-code-block {
  margin: 14px 0;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-code);
  overflow: hidden;
}
.md-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.md-code-lang {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.md-copy-btn {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}
.md-copy-btn.copied {
  border-color: var(--success);
  color: var(--success);
}
.md-pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}
.md-table-wrap {
  overflow-x: auto;
  margin: 14px 0;
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.md-table th, .md-table td {
  padding: 8px 11px;
  border: 1px solid var(--border);
}
.md-table th {
  background: var(--bg-elevated);
  color: var(--text-strong);
  font-weight: 700;
}

/* Offline LaTeX Math Styling */
.math-inline, .math-display {
  font-family: var(--font-serif);
  font-size: 1.04em;
  line-height: 1.35;
}
.math-display {
  display: block;
  text-align: center;
  margin: 14px 0;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  font-size: 1.12em;
}
.m-var { font-style: italic; }
.m-greek { font-style: italic; }
.m-greek-up, .m-rm, .m-func, .m-num, .m-text { font-style: normal; }
.m-text { font-family: var(--font-sans); font-size: 0.9em; }
.m-bf, .m-bm { font-weight: 700; }
.m-bm { font-style: italic; }
.m-bf { font-style: normal; }
.m-it { font-style: italic; }
.m-sf { font-family: var(--font-sans); }
.m-tt { font-family: var(--font-mono); font-size: 0.9em; }
.m-cal { font-style: italic; }
.m-bb { font-style: normal; font-weight: 600; }
.m-rel { padding: 0 0.24em; }
.m-bin { padding: 0 0.18em; }
.m-punct { padding-right: 0.16em; }
.m-func { padding: 0 0.1em; }
.m-bigop { font-size: 1.35em; vertical-align: -0.08em; padding: 0 0.08em; }
.math-display .m-bigop { font-size: 1.65em; }
.m-delim-lg { font-size: 1.25em; vertical-align: -0.06em; }
.m-sp-thin { display: inline-block; width: 0.16em; }
.m-sp-med { display: inline-block; width: 0.28em; }
.m-sp-neg { margin-left: -0.14em; }
.m-sp-quad { display: inline-block; width: 1em; }
.m-sp-qquad { display: inline-block; width: 2em; }
.m-tag { float: right; font-size: 0.85em; color: var(--text-muted); }

/* Fractions */
.m-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 0.16em;
  line-height: 1.15;
}
.m-frac-inline {
  font-size: 0.86em;
}
.m-frac-num {
  padding: 0 0.2em 0.08em;
  border-bottom: 1.25px solid currentColor;
}
.m-frac-den {
  padding: 0.08em 0.2em 0;
}

.m-binom {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}
.m-binom-inner {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.88em;
  line-height: 1.15;
  padding: 0 0.12em;
}

/* Roots */
.m-sqrt {
  display: inline-flex;
  align-items: baseline;
  margin: 0 0.1em;
}
.m-sqrt-idx {
  font-size: 0.65em;
  margin-right: -0.22em;
  vertical-align: 0.55em;
}
.m-sqrt-sym {
  font-size: 1.12em;
  line-height: 1;
}
.m-sqrt-body {
  border-top: 1.2px solid currentColor;
  padding: 0.04em 0.14em 0 0.1em;
}

/* Scripts & Stacked Limits */
.m-scripted {
  display: inline-flex;
  align-items: baseline;
}
.m-subsup {
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 0.72em;
  line-height: 1.05;
  margin-left: 0.06em;
  vertical-align: -0.22em;
  text-align: left;
}
.m-sup-only, .m-sub-only {
  font-size: 0.73em;
  line-height: 0;
}
.m-op-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1.05;
  margin: 0 0.14em;
}
.m-lim-sup, .m-lim-sub {
  font-size: 0.68em;
  line-height: 1.1;
}

/* Accents */
.m-overline {
  border-top: 1.15px solid currentColor;
  padding-top: 0.05em;
}
.m-underline {
  border-bottom: 1.15px solid currentColor;
  padding-bottom: 0.04em;
}
.m-accent {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  vertical-align: baseline;
}
.m-accent-mark {
  font-size: 0.78em;
  line-height: 0.45;
  margin-bottom: -0.05em;
}
.m-acc-vec .m-accent-mark {
  font-size: 0.68em;
  line-height: 0.6;
}
.m-not {
  text-decoration: line-through;
}

/* Matrices & Aligned Tables */
.m-matrix-wrap {
  display: inline-flex;
  align-items: stretch;
  vertical-align: middle;
  margin: 0 0.15em;
}
.m-mat-delim {
  display: flex;
  align-items: center;
  font-size: 2.1em;
  font-weight: 300;
  line-height: 1;
  padding: 0 0.04em;
  transform: scaleY(1.18);
}
.m-smallmatrix {
  font-size: 0.8em;
}
.m-matrix, .m-cases, .m-aligned {
  border-collapse: collapse;
  display: inline-table;
  vertical-align: middle;
}
.m-matrix td {
  padding: 0.14em 0.42em;
  text-align: center;
}
.m-cases td {
  padding: 0.14em 0.4em;
  text-align: left;
}
.m-aligned td {
  padding: 0.18em 0.22em;
}
.m-al-right { text-align: right; }
.m-al-left { text-align: left; }
.m-al-center { text-align: center; }

/* =========================================================================
 * Modal
 * ========================================================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}
.modal-card {
  width: 100%;
  max-width: 560px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 17px;
}
.modal-body {
  padding: 16px 18px;
  font-size: 14px;
}
.env-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 8px 0 14px;
}
.env-chip {
  padding: 4px 9px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--border);
}
.env-chip.ok {
  background: var(--success-soft);
  border-color: rgba(34, 197, 94, 0.4);
  color: var(--success);
}
.env-chip.miss {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

/* =========================================================================
 * Responsive & Print
 * ========================================================================= */

@media (max-width: 920px) {
  .app-shell {
    flex-direction: column;
  }
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 35;
  }
  .mobile-title {
    font-weight: 700;
    font-size: 14.5px;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 50;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 45;
  }
  .main-content {
    padding: 18px 16px 56px;
  }
}

@media print {
  body, html {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .sidebar, .mobile-header, .sidebar-backdrop, .playground-toolbar,
  .module-footer-nav, .derivation-controls, .md-copy-btn {
    display: none !important;
  }
  .main-content {
    max-width: 100%;
    padding: 0;
  }
  .card {
    border: 1px solid #cccccc;
    box-shadow: none;
    break-inside: avoid;
  }
}

/* =========================================================================
 * Wave 2: Mastery Checklist, Section Quick-Checks, Mastery Tests & Exams
 * ========================================================================= */

.mastery-checklist {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.mastery-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.mastery-pill:hover {
  border-color: var(--accent);
  color: var(--text-strong);
}
.mastery-pill.passed {
  background: var(--success-soft);
  border-color: rgba(34, 197, 94, 0.5);
  color: var(--success);
}

/* Inline Section Quick-Check */
.quick-check-card {
  margin-top: 18px;
  padding: 15px 17px;
  border-radius: 9px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-left: 4px solid var(--accent);
  background: var(--bg-elevated);
}
.quick-check-card.qc-passed {
  border-left-color: var(--success);
  border-color: rgba(34, 197, 94, 0.45);
}
.quick-check-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.quick-check-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}
.quick-check-card.qc-passed .quick-check-badge {
  color: var(--success);
}

/* Numeric & Step-Order Interactive Controls (shared by Quick-Checks, Mastery Test & Exams) */
.numeric-input-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
}
.numeric-input {
  width: 190px;
  max-width: 100%;
  padding: 8px 11px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
}
.numeric-input:focus {
  border-color: var(--accent);
}
.numeric-unit {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.step-order-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 12px 0;
}
.step-order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
}
.step-order-item.step-correct {
  border-color: var(--success);
  background: var(--success-soft);
}
.step-order-item.step-wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}
.step-rank-num {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.step-order-text {
  flex: 1 1 auto;
  font-size: 14px;
}
.step-order-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.step-move-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-strong);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
.step-move-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.step-move-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Module Mastery Test */
.mastery-test-card {
  border-left: 4px solid var(--independent);
}
.test-score-pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 800;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-strong);
}
.test-score-pill.mastered {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}
.test-question-block {
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 16px 18px;
  margin-bottom: 14px;
  background: var(--bg-elevated);
}
.test-question-block.q-pass {
  border-color: rgba(34, 197, 94, 0.55);
}
.test-question-block.q-fail {
  border-color: rgba(239, 68, 68, 0.5);
}
.test-q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.q-type-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
}
.predict-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Track Capstone Exams View */
.exam-preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.exam-preset-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.exam-preset-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.exam-preset-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.exam-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  margin-bottom: 18px;
}
.exam-timer-pill {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--accent);
}
.exam-summary-banner {
  padding: 20px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  margin-bottom: 18px;
}
.exam-summary-banner.pass {
  border-color: var(--success);
  background: var(--success-soft);
}
.exam-summary-banner.fail {
  border-color: var(--warning);
  background: var(--warning-soft);
}
.weak-modules-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

/* =========================================================================
 * Wave 4: Zero-Storage Hosted Mode Badge & In-App #paper Reader
 * ========================================================================= */

.mode-badge.mode-zero-storage {
  background: var(--solarboot-soft);
  border-color: rgba(45, 212, 191, 0.45);
  color: var(--solarboot);
}
.mode-badge.mode-zero-storage .mode-dot {
  background: var(--solarboot);
}

.paper-reader-layout {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.paper-toc-card {
  border-left: 4px solid var(--accent);
}
.paper-toc-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 6px 14px;
}
.paper-toc-item {
  font-size: 13.5px;
}
.paper-toc-item.toc-sub {
  padding-left: 14px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.paper-toc-link {
  background: none;
  border: none;
  padding: 2px 0;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.paper-toc-link:hover {
  text-decoration: underline;
}

.paper-body-card {
  padding: 28px 32px;
  font-size: 16px;
  line-height: 1.72;
}
.paper-body-card .md-h1 {
  font-size: 26px;
  line-height: 1.25;
  margin-top: 6px;
}
.paper-body-card .md-h2 {
  font-size: 21px;
  margin-top: 28px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.paper-body-card .md-h3 {
  font-size: 17.5px;
  margin-top: 20px;
}

.zero-storage-panel {
  margin-bottom: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid rgba(45, 212, 191, 0.35);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.zero-storage-hint {
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-muted);
}
.zero-storage-btns {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.zero-storage-btns .btn {
  width: 100%;
  justify-content: flex-start;
  font-size: 11.5px;
  padding: 5px 8px;
}
.storage-toast {
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--solarboot-soft);
  border: 1px solid rgba(45, 212, 191, 0.4);
  color: var(--solarboot);
}
