/* ─── GOOGLE FONTS (Impeccable Editorial) ──────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&family=Instrument+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Space+Grotesk:wght@400;500;600;700&display=swap');
/* ═══════════════════════════════════════════════════════════════════
   ASCP Board Exam Review — Shared Styles (Global) — v4 IMPECCABLE
   Controls all 17 shared-architecture HTML files
   ═══════════════════════════════════════════════════════════════════ */

/* ─── LOCAL FONTS (offline) ────────────────────────────────────── */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/JetBrainsMono-Regular.ttf) format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(fonts/JetBrainsMono-Medium.ttf) format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/JetBrainsMono-Bold.ttf) format('truetype');
}
@font-face {
  font-family: 'Syne';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/Syne-Regular.ttf) format('truetype');
}
@font-face {
  font-family: 'Syne';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(fonts/Syne-SemiBold.ttf) format('truetype');
}
@font-face {
  font-family: 'Syne';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/Syne-Bold.ttf) format('truetype');
}
@font-face {
  font-family: 'Syne';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url(fonts/Syne-ExtraBold.ttf) format('truetype');
}

/* ─── VARIABLES — Impeccable Editorial Sanctuary ───────────────────── */
:root {
  /* Core palette — OKLCH warm paper + editorial magenta (The One Voice Rule) */
  --bg:        oklch(96% 0.005 350);              /* warm ash cream — The Paper-Not-White Rule */
  --surface:   oklch(98% 0 0);                    /* crisp paper white — inverted surfaces only */
  --surface2:  oklch(92% 0 0);                    /* paper mist */
  --surface3:  oklch(88% 0.005 350);              /* warm mist deep */
  --border:    oklch(82% 0 0);                    /* hairline border */
  --border2:   oklch(72% 0 0);                    /* medium border */
  --accent:    oklch(55% 0.25 350);               /* editorial magenta — the one voice, ≤10% of screen (55% L = AA on paper bg) */
  --accent-dim:oklch(55% 0.25 350 / 0.15);        /* magenta whisper — glow backdrops */
  --accent2:   oklch(52% 0.18 160);               /* editorial green — positive/success only */
  --accent2-dim:oklch(52% 0.18 160 / 0.12);
  --accent3:   oklch(68% 0.15 60);                /* warm orange — warnings only */
  --accent4:   oklch(55% 0.18 300);               /* muted violet — minimal use */
  --text:      oklch(10% 0 0);                    /* deep graphite — body copy, never pure black */
  --text2:     oklch(25% 0 0);                    /* soft charcoal — secondary text, headings 16px+ */
  --text3:     oklch(45% 0 0);                    /* mid ash — tertiary labels, captions (45% L = AA on paper bg) */
  --red:       oklch(55% 0.22 25);                /* warm red — errors only */
  --red-dim:   oklch(55% 0.22 25 / 0.10);
  --yellow:    oklch(56% 0.15 85);                /* goldenrod — exam tips only (darkened for AA on light bg) */
  --yellow-dim:oklch(72% 0.15 85 / 0.08);

  /* Typography — editorial serif display + clean sans body */
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Space Grotesk', 'JetBrains Mono', 'Fira Code', monospace;

  /* Easing — expo-out signature per Impeccable */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-smooth: var(--ease-out);

  /* Spacing scale — 8/16/24/32/48/80/120 */
  --sp-1: 8px;
  --sp-2: 16px;
  --sp-3: 24px;
  --sp-4: 32px;
  --sp-5: 48px;
  --sp-6: 80px;
  --sp-7: 120px;

  /* Elevation — flat at rest, lift on interaction (The Low-Alpha Rule: ≤0.15) */
  --shadow-hover: 0 4px 24px -4px oklch(10% 0 0 / 0.12), 0 1px 3px oklch(10% 0 0 / 0.06);
  --shadow-lifted: 0 20px 40px oklch(10% 0 0 / 0.08);
  --shadow-accent: 0 4px 16px oklch(60% 0.25 350 / 0.10);

  /* Border radius — sharp editorial */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  line-height: 1.6;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
/* Lock scroll on module pages only — index.html scrolls normally */
body:has(.app) {
  overflow: hidden;
}
body {
  opacity: 0;
  animation: pageFadeIn 0.3s var(--ease-out) forwards;
}
@keyframes pageFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ─── PAGE ENTER / EXIT — body opacity fade (no black flash) ─────── */
/* JS sets body opacity directly; this block is documentation only.   */


/* Selection styling — magenta veil per Impeccable */
::selection {
  background: oklch(60% 0.25 350 / 0.25);
  color: oklch(10% 0 0);
}

/* ─── APP LAYOUT ─────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: 38px 1fr;
  height: 100vh;
  position: relative;
  z-index: 1;
  transition: grid-template-columns 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.app.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}
.app.sidebar-collapsed .sidebar {
  overflow: hidden;
  border-right: none;
}

/* ─── SIDEBAR TOGGLE BUTTON ──────────────────────────────────────── */
.sidebar-toggle {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  height: 28px;
  min-width: 28px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.05em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 0.2s var(--ease-out), color 0.2s var(--ease-out), border-color 0.2s var(--ease-out), transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
  flex-shrink: 0;
  line-height: 1;
  padding: 0 10px;
  position: relative;
}
/* Extend tap target to ~44px without enlarging the visible button */
.sidebar-toggle::after {
  content: "";
  position: absolute;
  inset: -9px;
}
.sidebar-toggle .sidebar-toggle-icon {
  font-size: 1.125rem;
  line-height: 1;
}
.sidebar-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}
.sidebar-toggle.collapsed {
  padding: 0;
  width: 28px;
}
.sidebar-toggle.collapsed .sidebar-toggle-label {
  display: none;
}

/* ─── HEADER ─────────────────────────────────────────────────────── */
.header {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: relative;
  z-index: 10;
}
.header > div:first-child { flex: 1; min-width: 0; }
.header-title {
  font-size: 1rem; font-weight: 700; color: var(--accent);
  letter-spacing: 2px; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0; flex: 1; /* flex item must be shrinkable for ellipsis to work */
}
/* Back to index button */
.back-btn {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  font-family: var(--mono);
  letter-spacing: 0.5px;
  text-decoration: none;
  transition: background-color 0.25s var(--transition-smooth), color 0.25s var(--transition-smooth), border-color 0.25s var(--transition-smooth), transform 0.25s var(--transition-smooth), box-shadow 0.25s var(--transition-smooth);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
  flex-shrink: 0;
}
/* Hit-slop: extend tap target to ~44px without enlarging visuals */
.back-btn::after {
  content: "";
  position: absolute;
  inset: -6px -4px;
}
.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  transform: translateX(-2px);
}
.header-badge {
  font-size: 0.8125rem; padding: 3px 10px;
  border: 1px solid var(--accent2); color: var(--accent2);
  border-radius: 2px; letter-spacing: 1px;
  background: rgba(45,134,89,0.06);
  transition: background-color 0.3s var(--transition-smooth), color 0.3s var(--transition-smooth), border-color 0.3s var(--transition-smooth), transform 0.3s var(--transition-smooth);
}
.header-badge:hover {
  background: var(--accent2-dim);
  transform: translateY(-1px);
}
/* ─── STATS-BAR NAV LINKS ────────────────────────────────────────── */
#nav-links {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}
.dash-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.875rem;
  font-family: var(--mono);
  letter-spacing: 1px;
  transition: color 0.2s;
}
.dash-link:hover { color: var(--accent2); }
.logout-btn {
  background: rgba(194,48,56,0.10);
  color: var(--red);
  border: 1px solid rgba(194,48,56,0.16);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.875rem;
  font-family: var(--mono);
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 0.2s;
}
.logout-btn:hover { background: rgba(194,48,56,0.16); }

/* Sidebar logout — shown only on mobile (inside drawer) */
.sidebar-logout-btn { display: none; }
.sidebar-dash-link { display: none; }
#sidebar-nav { display: none; }

/* Sidebar close strip — shown only inside mobile drawer */
.sidebar-close-strip {
  display: none;
}

.progress-wrap {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.875rem; color: var(--text3);
}
/* Module header right cluster — progress counter + nav links + theme toggle */
#header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
/* #nav-links has margin-left:auto for stats-bar context — neutralize inside cluster */
#header-right #nav-links { margin-left: 0; }
.progress-bar-outer {
  width: 120px; height: 3px;
  background: var(--border); border-radius: 2px;
  overflow: hidden;
}
.progress-bar-inner {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.6s var(--transition-smooth);
}

/* ─── SIDEBAR ────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0 0 12px 0;
  position: relative;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 4px;
}

/* ─── SIDEBAR SEARCH ─────────────────────────────────────────────── */
.search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  z-index: 5;
  background: var(--surface);
}
.search-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 9px 12px 9px 32px;
  font-size: 1rem;
  font-family: var(--mono);
  font-weight: 500;
  border-radius: 4px;
  outline: none;
  transition: border-color 0.15s var(--ease-out), background-color 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a8279' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background-color: var(--surface2);
}
.search-input::placeholder { color: var(--text3); }

/* ─── TREE NODES ─────────────────────────────────────────────────── */
.tree-node {
  cursor: pointer;
  user-select: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s var(--transition-smooth), transform 0.3s var(--transition-smooth);
}
.tree-node.tree-visible {
  opacity: 1;
  transform: translateY(0);
  animation: fadeSlideIn 0.3s var(--transition-smooth) both;
}
.tree-label {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; font-size: 0.9375rem; color: var(--text2);
  border-left: 1px solid transparent;
  transition: background-color 0.25s var(--transition-smooth), color 0.25s var(--transition-smooth), border-color 0.25s var(--transition-smooth), transform 0.25s var(--transition-smooth), box-shadow 0.25s var(--transition-smooth);
  line-height: 1.45;
  position: relative;
}
.tree-label:hover {
  background: var(--surface2);
  color: var(--text);
  border-left-color: var(--border2);
  transform: translateX(2px);
}
.tree-label.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-left-color: var(--accent);
}
/* Visited node indicator */
.tree-label.visited {
  color: var(--text3);
}
.tree-label.visited::after {
  content: '✓';
  position: absolute;
  right: 10px;
  font-size: 0.75rem;
  color: var(--accent2);
  opacity: 0.6;
  font-weight: 700;
}
.tree-label.visited:hover {
  color: var(--text);
}
.tree-label.visited.active {
  color: var(--accent);
}
.tree-label .icon { font-size: 1.125rem; flex-shrink: 0; transition: transform 0.2s ease; }
.tree-label:hover .icon { transform: scale(1.15); }
.tree-label .label-text { flex: 1; }
.tree-section-header {
  font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text3); padding: 16px 16px 6px;
  font-weight: 600;
  position: relative;
  border-top: 1px solid rgba(186,176,163,0.50);
  margin-top: 4px;
}
.tree-section-header:first-child {
  border-top: none;
  margin-top: 0;
}
.tree-section-header::before {
  content: '▸';
  margin-right: 6px;
  color: var(--accent);
  font-size: 0.75rem;
}

/* ─── SEARCH MATCH COUNT BADGE ───────────────────────────────── */
.search-match-count {
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(184,51,106,0.25);
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: auto;
  flex-shrink: 0;
  font-weight: 600;
}

/* Module sidebar search summary ("5 of 15 nodes match") */
.search-summary {
  font-size: 0.875rem;
  color: var(--accent);
  padding: 6px 12px 8px;
  letter-spacing: 0.5px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* Module sidebar search empty state */
.search-empty {
  font-size: 0.9375rem;
  color: var(--text2);
  padding: 20px 12px;
  text-align: center;
  font-weight: 500;
}
.search-empty b {
  color: var(--accent);
  font-weight: 600;
}

/* ─── MAIN ───────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-height: 0;
}

/* ─── MODE TABS ──────────────────────────────────────────────── */
.mode-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
  position: relative;
}
.mode-tab {
  padding: 7px 18px;
  font-size: 0.9375rem; font-family: var(--mono); font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase;
  cursor: pointer; color: var(--text3);
  border-bottom: 2px solid transparent;
  border-right: 1px solid var(--border);
  background: transparent;
  transition: background-color 0.25s var(--transition-smooth), color 0.25s var(--transition-smooth), border-color 0.25s var(--transition-smooth), transform 0.25s var(--transition-smooth), box-shadow 0.25s var(--transition-smooth);
  user-select: none;
  position: relative;
}
.mode-tab:hover {
  color: var(--text2);
  background: var(--surface3);
}
.mode-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--surface);
}

/* ─── CONTENT PANES — must flex-fill .detail-panel and allow inner scroll ─── */
#detail-content,
#learn-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ─── DETAIL PANEL ───────────────────────────────────────────── */
.detail-panel {
  flex: 1;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-height: 0;
}
.detail-header {
  padding: 3px 16px 3px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
  background: var(--surface2);
}
/* Make the inner <div> (title + breadcrumb) a single-line flex row */
.detail-header > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.detail-title {
  font-size: 1.25rem; font-weight: 500;
  color: var(--accent);
  letter-spacing: 0;
  font-family: var(--serif);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.detail-breadcrumb {
  font-size: 0.8125rem; color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}
.detail-badge {
  font-size: 0.8125rem; padding: 3px 10px;
  border-radius: 2px;
  background: var(--surface3); color: var(--text2);
  border: 1px solid var(--border);
}
.detail-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex; flex-direction: column;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.detail-page {
  padding: 18px 24px 12px;
  flex: 1;
  overflow-y: visible;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}


.detail-body::-webkit-scrollbar { width: 4px; }
.detail-body {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.detail-body::-webkit-scrollbar-track { background: transparent; }
.detail-body::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 4px;
}

/* ─── FIELD ROWS ─────────────────────────────────────────────── */
.field-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  line-height: 1.85;
  transition: background-color 0.25s var(--transition-smooth), color 0.25s var(--transition-smooth), border-color 0.25s var(--transition-smooth), transform 0.25s var(--transition-smooth), box-shadow 0.25s var(--transition-smooth);
  border-radius: 4px;
  margin-bottom: 2px;
  border-left: 1px solid transparent;
  max-width: 100%;
}
/* Alternating row subtle background */
.field-row:nth-child(even) {
  background: rgba(26,23,20,0.025);
}
.field-row:hover {
  background: var(--accent-dim);
  border-color: var(--border2);
  border-left-color: var(--accent);
}
.field-row:last-child { border-bottom: none; margin-bottom: 0; }
.field-label {
  color: var(--text2);
  font-size: 0.9375rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  line-height: 1.85;
  padding-top: 2px;
  align-self: start;
  word-break: break-word;
  transition: color 0.2s ease;
}
.field-row:hover .field-label {
  color: var(--text2);
}
.field-value {
  color: var(--text);
  font-size: 1.0625rem;
  font-family: var(--mono);
  font-weight: 500;
  line-height: 1.7;
  word-break: break-word;
  overflow-wrap: anywhere;
  padding-left: 14px;
  border-left: 1px solid var(--border2);
  max-width: 72ch;
  transition: border-color 0.25s var(--transition-smooth);
}
/* V3: Break long text into readable chunks */
.field-value br + br,
.field-value p + p { margin-top: 0.5em; }
.field-value em {
  color: var(--accent);
  font-style: italic;
  font-weight: 500;
}
.field-row:hover .field-value {
  border-left-color: var(--accent);
}
.field-value.highlight { color: var(--accent2); }
.field-value.warning { color: var(--yellow); }
.field-value.danger { color: var(--red); }
.field-value.info { color: var(--accent); }
.field-value.exam-tip { color: var(--yellow); }
/* Exam Tip field — highlighted with background tint */
.field-row.exam-tip-row {
  background: var(--yellow-dim);
  border-left: 1px solid var(--yellow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-top: 6px;
  position: relative;
}
.field-row.exam-tip-row:hover {
  background: rgba(184,134,11,0.10);
  border-left-color: var(--yellow);
}
.field-row.exam-tip-row .field-label {
  color: var(--yellow);
}
.field-row.exam-tip-row .field-value {
  border-left-color: rgba(184,134,11,0.20);
  color: var(--yellow);
}
.section-divider {
  font-size: 0.75rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--accent); padding: 10px 0 4px; font-weight: 700;
  border-bottom: 1px solid var(--border2); margin-bottom: 2px;
}

/* ─── PAGINATION ─────────────────────────────────────────────────── */
.detail-progress {
  height: 2px;
  background: var(--border);
  flex-shrink: 0;
}
.detail-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s var(--transition-smooth);
}
.detail-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 16px 6px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.btn-nav {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 4px 12px;
  border-radius: 0;
  font-size: 0.8125rem;
  cursor: pointer;
  font-family: var(--mono);
  transition: background-color 0.25s var(--transition-smooth), color 0.25s var(--transition-smooth), border-color 0.25s var(--transition-smooth), transform 0.25s var(--transition-smooth), box-shadow 0.25s var(--transition-smooth);
  letter-spacing: 0.5px;
}
.btn-nav:hover {
  background: var(--surface3);
  color: var(--text);
  border-color: var(--text3);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}
.btn-nav.primary {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-nav.primary:hover {
  background: var(--accent-dim);
  box-shadow: var(--shadow-accent);
}
.btn-nav:disabled {
  opacity: 0.2;
  cursor: default;
  transform: none;
  box-shadow: none;
}
.page-info {
  font-size: 0.8125rem; color: var(--text3);
}

/* ─── STATS BAR ──────────────────────────────────────────────────── */
.stats-bar {
  background: var(--surface2);
  border-top: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
}
.stat-item {
  flex: 1;
  padding: 6px 12px;
  border-right: 1px solid var(--border);
  text-align: center;
  transition: background 0.2s;
}
.stat-item:last-child { border-right: none; }
.stat-item:hover { background: var(--surface3); }
.stat-val {
  font-size: 1rem; font-weight: 700;
  color: var(--accent);
}
.stat-lbl {
  font-size: 0.75rem; color: var(--text3);
  text-transform: uppercase; letter-spacing: 1px;
  margin-top: 1px;
}
/* Collapse handle — lets the user reclaim the fixed bottom strip */
.stats-toggle {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 0 10px;
  font-size: 0.75rem;
  line-height: 1;
  align-self: center;
  transition: color 0.2s;
}
.stats-toggle:hover { color: var(--accent); }
.stats-bar.stats-collapsed .stat-item { display: none; }
.stats-bar.stats-collapsed {
  justify-content: flex-end;
  min-height: 24px;
}

/* ─── EMPTY STATE ────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text3);
  gap: 16px;
  position: relative;
}
.empty-icon {
  font-size: 3.5rem;
  opacity: 0.3;
  animation: float 4s ease-in-out infinite;
}
.empty-text {
  font-size: 1rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text3);
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ─── LOADING STATE — shown until JS initializes ──────────────────────── */
.app[data-loading] .sidebar,
.app[data-loading] .main {
  opacity: 0.3;
  pointer-events: none;
  transition: opacity 0.35s ease;
}
.app:not([data-loading]) .sidebar,
.app:not([data-loading]) .main {
  opacity: 1;
}
.loading-indicator {
  font-size: 0.875rem;
  color: var(--text3);
  letter-spacing: 1.5px;
  animation: loadingPulse 1.2s ease-in-out infinite;
}
.loading-indicator::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 8px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes loadingPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════════
   SEARCH HIGHLIGHT — Subtle marks for searched words
   ═══════════════════════════════════════════════════════════════════ */
mark,
.search-highlight {
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 3px;
  box-shadow: 0 0 0 1px rgba(184,51,106,0.18);
}

/* Sidebar search match counter badge */
.search-match-count {
  font-size: 0.75rem;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(184,51,106,0.25);
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: auto;
  flex-shrink: 0;
  letter-spacing: 0.5px;
  font-weight: 700;
}

/* Search results overlay for sidebar deep search */
.search-results-panel {
  position: absolute;
  top: 44px; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  z-index: 4;
  overflow-y: auto;
  padding: 8px 0;
  animation: fadeSlideIn 0.2s var(--transition-smooth);
}
.search-results-panel::-webkit-scrollbar { width: 4px; }
.search-results-panel {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.search-results-panel::-webkit-scrollbar-thumb {
  background: var(--border2); border-radius: 2px;
}
.search-result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.15s var(--transition-smooth), color 0.15s var(--transition-smooth), border-color 0.15s var(--transition-smooth);
}
.search-result-item:hover {
  background: var(--surface2);
}
.search-result-item:active {
  background: var(--surface3);
}
.search-result-title {
  font-size: 0.875rem; color: var(--accent); font-weight: 600;
  margin-bottom: 4px; display: flex; align-items: center; gap: 6px;
}
.search-result-preview {
  font-size: 0.8125rem; color: var(--text3); line-height: 1.4;
  max-height: 36px; overflow: hidden;
}
.search-result-section {
  font-size: 0.75rem; color: var(--text3); letter-spacing: 1px;
  text-transform: uppercase; margin-top: 4px; opacity: 0.7;
}

/* Search status bar */
.search-status {
  padding: 6px 14px;
  font-size: 0.75rem;
  color: var(--text3);
  letter-spacing: 1px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search-status-count {
  color: var(--accent);
  font-weight: 700;
}
.search-clear-btn {
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text3);
  padding: 2px 8px;
  border-radius: 2px;
  cursor: pointer;
  font-family: var(--mono);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.search-clear-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════════
   LEARN MODE
   ═══════════════════════════════════════════════════════════════════ */
.learn-panel {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 28px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 22px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.learn-panel::-webkit-scrollbar { width: 4px; }
.learn-panel {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.learn-panel::-webkit-scrollbar-track { background: transparent; }
.learn-panel::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 4px;
}
.learn-section-title {
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* Alternative class names used in Mycology.html */
.learn-section-label {
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ─── COMPARISON TABLE ───────────────────────────────────────────── */
.comp-block { margin-bottom: 22px; }
.comp-block:last-child { margin-bottom: 0; }
.comp-title {
  font-size: 0.875rem; font-weight: 600;
  color: var(--text2);
  letter-spacing: 0.3px;
  margin-bottom: 8px;
  padding-left: 2px;
}
.comp-table-wrap { overflow-x: auto; border-radius: 6px; border: 1px solid var(--border2); }
.comp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}
.comp-table th {
  background: var(--surface3);
  color: var(--accent);
  font-size: 0.8125rem; letter-spacing: 1px; text-transform: uppercase;
  padding: 10px 14px; text-align: left;
  border-bottom: 2px solid var(--border2);
  border-right: 1px solid var(--border2);
  font-weight: 700;
  white-space: nowrap;
}
.comp-table th:last-child { border-right: none; }
.comp-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  font-size: 1rem; color: var(--text);
  font-weight: 400;
  vertical-align: top; line-height: 1.65;
  transition: background 0.12s;
}
.comp-table td:last-child { border-right: none; }
.comp-table tr:last-child td { border-bottom: none; }
.comp-table tr:nth-child(even) td { background: rgba(26,23,20,0.03); }
.comp-table tr:hover td { background: var(--accent-dim); }
.comp-table td.up { color: var(--accent2); font-weight: 600; }
.comp-table td.down { color: var(--red); font-weight: 600; }
.comp-table td.norm { color: var(--yellow); }
.comp-table td.row-label {
  color: var(--text);
  font-weight: 600;
  font-size: 0.9375rem;
  min-width: 130px;
  background: rgba(26,23,20,0.04);
  border-right: 2px solid var(--border2);
}

/* ─── FLASHCARDS ─────────────────────────────────────────────────── */
.flashcard-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.flashcard-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.flashcard-section-title {
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 2px; text-transform: uppercase;
  color: var(--yellow);
  margin-bottom: 4px;
}
.flashcard {
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  border: 1px solid var(--border2);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.flashcard:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}
.flashcard.flipped {
  border-color: var(--accent);
  box-shadow: var(--shadow-accent);
}
.flashcard-inner {
  width: 100%;
}
.flashcard-front {
  padding: 14px 16px;
  display: flex; flex-direction: column;
  justify-content: flex-start;
  background: var(--surface2);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.flashcard.flipped .flashcard-front {
  border-bottom-color: var(--border2);
}
.flashcard-back {
  max-height: 0;
  overflow: hidden;
  display: flex; flex-direction: column;
  padding: 0 16px;
  background: var(--surface3);
  transition: max-height 0.45s var(--transition-smooth), padding 0.3s var(--transition-smooth);
}
.flashcard.flipped .flashcard-back {
  max-height: 1200px;
  padding: 14px 16px;
}

.card-hint {
  font-size: 0.75rem; color: var(--text3);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 5px;
}
.card-q { font-size: 1rem; color: var(--text); line-height: 1.55; font-weight: 500; }
.card-a {
  font-size: 1rem; color: var(--accent2);
  font-weight: 700; line-height: 1.55;
}
.card-explain {
  font-size: 1rem; color: var(--text2);
  margin-top: 10px; line-height: 1.55;
  border-top: 1px solid var(--border2);
  padding-top: 10px;
  font-weight: 500;
}
.card-tap {
  font-size: 0.75rem; color: var(--text3);
  text-align: right; margin-top: 8px;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.flashcard.flipped .card-tap { opacity: 0; height: 0; margin: 0; overflow: hidden; }

/* ─── MNEMONIC ───────────────────────────────────────────────────── */
.mnemonic-box {
  background: var(--accent-dim);
  border-left: 1px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 16px 18px;
}
.mnemonic-title {
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 2px; text-transform: uppercase;
  color: var(--accent); margin-bottom: 10px;
}
.mnemonic-word {
  font-size: 1.5rem; font-weight: 700;
  color: var(--accent2); font-family: var(--mono);
  letter-spacing: 5px; margin-bottom: 12px;
}
.mnemonic-rows { display: flex; flex-direction: column; gap: 5px; }
.mnemonic-row { display: flex; gap: 10px; align-items: baseline; }
.mnemonic-letter {
  font-size: 1.25rem; font-weight: 700;
  color: var(--accent); font-family: var(--mono);
  min-width: 22px;
}
.mnemonic-meaning {
  font-size: 1rem; color: var(--text); line-height: 1.55; font-weight: 500;
}
.mnemonic-meaning em { color: var(--yellow); font-style: normal; }
.mnemonic-note {
  font-size: 0.8125rem; color: var(--text3);
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
  line-height: 1.5;
}

/* ─── MINI QUIZ ──────────────────────────────────────────────────── */
.quiz-wrap { display: flex; flex-direction: column; gap: 14px; }
.quiz-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.quiz-section-title {
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 2px; text-transform: uppercase;
  color: var(--accent3);
  margin-bottom: 4px;
}
.quiz-card {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 16px;
  transition: border-color 0.2s;
}
.quiz-item {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 16px;
  transition: border-color 0.2s;
}
.quiz-q {
  font-size: 1rem; color: var(--text);
  line-height: 1.6; margin-bottom: 14px; font-weight: 600;
}
.quiz-q span.qnum {
  color: var(--accent);
  font-size: 0.8125rem; font-weight: 700;
  letter-spacing: 1px; display: block; margin-bottom: 4px;
}
.quiz-options { display: flex; flex-direction: column; gap: 5px; }
.quiz-opt {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 1rem; color: var(--text);
  font-weight: 500;
  transition: background-color 0.2s var(--transition-smooth), color 0.2s var(--transition-smooth), border-color 0.2s var(--transition-smooth), transform 0.2s var(--transition-smooth), box-shadow 0.2s var(--transition-smooth);
  line-height: 1.55;
}
.quiz-opt:hover {
  border-color: var(--border2);
  color: var(--text);
  transform: translateX(2px);
}
.quiz-opt.correct {
  border-color: var(--accent2);
  color: var(--accent2);
  background: var(--accent2-dim);
}
.quiz-opt.wrong {
  border-color: var(--red);
  color: var(--red);
  background: rgba(194,48,56,0.06);
}
.quiz-opt.disabled {
  cursor: default;
  pointer-events: none;
  opacity: 0.5;
}
.quiz-opt.correct.disabled { opacity: 1; }
.opt-letter {
  font-weight: 700; font-size: 0.8125rem;
  color: var(--text3); flex-shrink: 0; margin-top: 1px;
}
.quiz-opt.correct .opt-letter { color: var(--accent2); }
.quiz-opt.wrong .opt-letter { color: var(--red); }
.quiz-explain {
  font-size: 0.9375rem; color: var(--text2);
  font-weight: 500;
  margin-top: 10px; padding: 12px 14px;
  background: var(--accent2-dim);
  border-left: 1px solid var(--accent2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  line-height: 1.55;
  display: none;
}
.quiz-explain.show {
  display: block;
  animation: fadeSlideIn 0.3s var(--transition-smooth);
}
.quiz-explain strong { color: var(--accent2); }

/* ─── ALGORITHM ──────────────────────────────────────────────────── */
.algo-wrap { display: flex; flex-direction: column; align-items: center; gap: 0; }
.algo-node {
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 10px 18px;
  font-size: 0.875rem; color: var(--text);
  text-align: center;
  min-width: 240px; max-width: 340px;
  line-height: 1.45; position: relative;
}
.algo-node.start {
  border-color: var(--accent); color: var(--accent);
  font-weight: 700; font-size: 0.8125rem;
  letter-spacing: 1px; text-transform: uppercase;
  background: rgba(184,51,106,0.05);
}
.algo-node.decision {
  background: rgba(184,51,106,0.06);
  border-color: var(--accent); font-weight: 500;
}
.algo-node.result-pos {
  border-color: var(--accent2); color: var(--accent2);
  background: rgba(45,134,89,0.06);
}
.algo-node.result-neg {
  border-color: var(--yellow); color: var(--yellow);
  background: rgba(184,134,11,0.06);
}
.algo-node.result-end {
  border-color: var(--accent3); color: var(--accent3);
  background: rgba(212,118,60,0.06);
  font-size: 0.8125rem;
}
.algo-arrow { display: flex; flex-direction: column; align-items: center; gap: 0; }
.algo-arrow-line { width: 2px; height: 18px; background: var(--border2); }
.algo-arrow-head {
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--border2);
}
.algo-label { font-size: 0.75rem; color: var(--text3); letter-spacing: 0.5px; }
.algo-branch {
  display: flex; justify-content: center; gap: 20px;
  width: 100%; align-items: flex-start;
}
.algo-branch-arm { display: flex; flex-direction: column; align-items: center; gap: 0; }
.algo-branch-label { font-size: 0.75rem; color: var(--text3); letter-spacing: 0.5px; padding: 2px 0; }
.algo-h-line { height: 2px; background: var(--border2); }
.algo-split { display: flex; align-items: flex-start; width: 100%; justify-content: center; }

/* ─── FILL-IN-THE-BLANK ─────────────────────────────────────────── */
.fitb-wrap { display: flex; flex-direction: column; gap: 10px; }
.fitb-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fitb-section-title {
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 2px; text-transform: uppercase;
  color: var(--red);
  margin-bottom: 4px;
}
.fitb-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px 16px;
}
.fitb-sentence { font-size: 1rem; color: var(--text); line-height: 2; font-weight: 500; }
.fitb-blank {
  display: inline-block;
  min-width: 80px;
  border-bottom: 2px dashed var(--border2);
  color: transparent;
  background: transparent;
  font-family: var(--mono);
  font-size: 1rem;
  padding: 0 4px;
  cursor: pointer;
  transition: background-color 0.25s var(--transition-smooth), color 0.25s var(--transition-smooth), border-color 0.25s var(--transition-smooth), transform 0.25s var(--transition-smooth), box-shadow 0.25s var(--transition-smooth);
  position: relative;
  vertical-align: bottom;
}
.fitb-blank:hover {
  border-bottom-color: var(--accent);
  background: rgba(184,51,106,0.04);
}
.fitb-blank.revealed {
  color: var(--accent2);
  border-bottom-color: var(--accent2);
  background: rgba(45,134,89,0.06);
  border-radius: 2px;
}
.fitb-btn {
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text3);
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--mono);
  letter-spacing: 0.5px;
  transition: background-color 0.2s var(--transition-smooth), color 0.2s var(--transition-smooth), border-color 0.2s var(--transition-smooth), transform 0.2s var(--transition-smooth), box-shadow 0.2s var(--transition-smooth);
  margin-top: 8px;
}
.fitb-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── TOOL BADGES ────────────────────────────────────────────────── */
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 3px;
  margin-bottom: 10px;
}
.tool-badge.compare { background: rgba(184,51,106,0.10); color: var(--accent); border: 1px solid rgba(184,51,106,0.22); }
.tool-badge.flash { background: rgba(184,134,11,0.10); color: var(--yellow); border: 1px solid rgba(184,134,11,0.25); }
.tool-badge.mnemonic { background: rgba(45,134,89,0.10); color: var(--accent2); border: 1px solid rgba(45,134,89,0.25); }
.tool-badge.quiz { background: rgba(212,118,60,0.10); color: var(--accent3); border: 1px solid rgba(212,118,60,0.25); }
.tool-badge.algo { background: rgba(124,92,191,0.10); color: var(--accent4); border: 1px solid rgba(124,92,191,0.25); }
.tool-badge.fitb { background: rgba(194,48,56,0.10); color: var(--red); border: 1px solid rgba(194,48,56,0.25); }

/* ─── CALLOUT BOXES (used in field values) ────────────────────────── */
.callout {
  background: var(--surface3);
  border-left: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 4px 0;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  font-weight: 500;
}
.callout.cyan {
  border-left-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text);
}
.callout.red {
  border-left-color: var(--red);
  background: var(--red-dim);
  color: var(--text);
}
.callout.green {
  border-left-color: var(--accent2);
  background: var(--accent2-dim);
  color: var(--text);
}
.callout.yellow {
  border-left-color: var(--yellow);
  background: var(--yellow-dim);
  color: var(--text);
}
.callout-lbl {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: inherit;
  opacity: 0.85;
}

/* ─── TAGS / BADGES (used inline in field values) ─────────────────── */
.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 0;
  margin-left: 6px;
  vertical-align: middle;
  background: var(--surface3);
  color: var(--text3);
  border: 1px solid var(--border2);
}
.tag-hi, .tag.tag-hi {
  background: var(--yellow-dim);
  color: var(--yellow);
  border-color: rgba(184,134,11,0.30);
}

/* ─── INLINE COLOR SPANS (shorthand color classes) ────────────────── */
.g { color: var(--accent2); font-weight: 600; }
.r { color: var(--red); font-weight: 600; }
.y { color: var(--yellow); font-weight: 600; }
.p { color: var(--accent4); font-weight: 600; }

/* ─── ANIMATIONS ─────────────────────────────────────────────────── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
/* ─── DIRECTIONAL PAGE SLIDES (prev/next navigation) ─────────────── */
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.slide-in-right { animation: slideInRight 0.28s cubic-bezier(0.4, 0, 0.2, 1) both; }
.slide-in-left  { animation: slideInLeft  0.28s cubic-bezier(0.4, 0, 0.2, 1) both; }
.slide-in-up    { animation: slideInUp    0.28s cubic-bezier(0.4, 0, 0.2, 1) both; }
/* Legacy alias — maps to up-slide for first node select */
@keyframes pageSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.page-transition { animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1) both; }

/* ─── RIPPLE — node selection ─────────────────────────────────────── */
.nav-ripple {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 100;
  transform: scale(0);
  background: var(--accent-dim);
  animation: navRippleExpand 0.6s cubic-bezier(0.2, 0, 0.8, 1) forwards;
}
@keyframes navRippleExpand {
  0%   { transform: scale(0); opacity: 1; }
  60%  { opacity: 0.5; }
  100% { transform: scale(1); opacity: 0; }
}

/* ─── MODE FLIP — reference ↔ learn tab switch ────────────────────── */
.mode-content-in {
  animation: modeFlipIn 0.24s ease-out forwards;
  transform-origin: top center;
}
@keyframes modeFlipIn {
  from { opacity: 0; transform: perspective(800px) rotateX(-9deg) scale(0.975); }
  to   { opacity: 1; transform: perspective(800px) rotateX(0deg)  scale(1);     }
}

/* ─── KEYBOARD SHORTCUT HINT BAR ─────────────────────────────────── */
.shortcut-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 6px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text3);
  letter-spacing: 0.5px;
  opacity: 0;
  transform: translateY(100%);
  transition: transform 0.4s var(--transition-smooth), opacity 0.4s var(--transition-smooth);
  pointer-events: none;
}
.shortcut-bar.visible {
  opacity: 1;
  transform: translateY(0);
}
.shortcut-bar kbd {
  display: inline-block;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 3px;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  margin: 0 2px;
  line-height: 1.6;
}

/* ─── RESPONSIVE — TABLET ────────────────────────────────────────── */
@media (max-width: 1200px) {
  .app {
    grid-template-columns: 260px 1fr;
  }
  .tree-label {
    font-size: 0.875rem;
    padding: 6px 12px;
  }
  /* More readable field rows on medium screens */
  .detail-page {
    padding: 14px 18px 8px;
  }
  .field-row {
    gap: 12px;
    padding: 12px 14px;
  }
  .field-label {
    font-size: 0.875rem;
  }
  .field-value {
    font-size: 1rem;
    line-height: 1.8;
  }
  .detail-header {
    padding: 4px 14px 4px;
  }
  .detail-title {
    font-size: 1.0625rem;
  }
  .learn-panel {
    padding: 14px 16px 24px;
  }
}

/* ─── RESPONSIVE — TABLET (≤768px) — sidebar visible, compact layout ──── */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 40px auto;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-x: clip;
  }
  html, body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-x: clip;
  }
  body:has(.app) { overflow-y: visible; }
  .header {
    position: sticky;
    top: 0;
    padding: 0 10px;
    font-size: 0.875rem;
    gap: 6px;
    z-index: 200;
  }
  .header > div:first-child {
    min-width: 0;
    flex: 1 1 0%;
    width: 0;
    gap: 8px !important;
    overflow: hidden;
  }
  .header-title {
    font-size: 0.875rem;
    letter-spacing: 0.8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }
  .header-badge { display: none; }
  .progress-wrap { display: none; }
  #nav-links { display: none; }
  .back-btn {
    padding: 0 12px;
    height: 36px;
    font-size: 0.875rem;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 0;
    border-radius: 4px;
  }
  .sidebar-toggle {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
  }
  .detail-badge { display: none; }
  .sidebar-close-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    height: 36px;
    border-bottom: 1px solid var(--border2);
    background: color-mix(in srgb, var(--surface) 90%, var(--accent) 10%);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 6;
  }
  .sidebar-close-strip-label {
    font-size: 0.8125rem;
    font-weight: 700;
    font-family: var(--mono);
    letter-spacing: 1.5px;
    color: var(--accent);
    text-transform: uppercase;
  }
  .sidebar-close-strip-btn {
    background: rgba(184,51,106,0.08);
    border: 1px solid rgba(184,51,106,0.25);
    color: var(--accent);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    font-size: 1.125rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
  }
  #sidebar-nav {
    display: flex;
    gap: 8px;
    margin: 12px 10px 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }
  .sidebar-dash-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 10px;
    background: rgba(184,51,106,0.10);
    color: var(--accent);
    border: 1px solid rgba(184,51,106,0.18);
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: var(--mono);
    font-weight: 700;
    letter-spacing: 0.8px;
    text-decoration: none;
    flex: 1;
    text-align: center;
    transition: background 0.2s;
  }
  .sidebar-dash-link:hover { background: rgba(184,51,106,0.18); }
  .sidebar-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 10px;
    background: rgba(194,48,56,0.10);
    color: var(--red);
    border: 1px solid rgba(194,48,56,0.22);
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: var(--mono);
    font-weight: 700;
    letter-spacing: 0.8px;
    cursor: pointer;
    flex: 1;
    flex-shrink: 0;
    transition: background 0.2s;
  }
  .sidebar-logout-btn:hover,
  .sidebar-logout-btn:active { background: rgba(194,48,56,0.16); }
  .sidebar-logout-icon { font-size: 1rem; line-height: 1; }
  .sidebar {
    position: fixed;
    top: 40px;
    left: 0;
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
    width: min(300px, 85vw);
    transform: translateX(-110%);
    transition: transform 0.28s var(--transition-smooth),
                box-shadow 0.28s var(--transition-smooth);
    z-index: 50;
    max-height: none;
    border-right: 1px solid var(--border2);
    border-bottom: none;
    overflow-y: auto;
    box-shadow: none;
  }
  .app.mobile-sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(26, 23, 20, 0.15);
  }
  .mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 40px;
    background: rgba(245, 240, 235, 0.85);
    z-index: 49;
    opacity: 0;
    transition: opacity 0.28s var(--transition-smooth);
  }
  .app.mobile-sidebar-open .mobile-backdrop {
    opacity: 1;
  }
  .sidebar::after { display: none; }
  .main {
    grid-column: 1;
    grid-row: 2;
    overflow: visible;
    min-height: 0;
  }
  .detail-panel,
  .detail-body,
  #detail-content,
  #learn-content {
    overflow: visible !important;
    height: auto !important;
  }
  .stats-bar {
    overflow: hidden;
    max-height: 60px;
    transition: max-height 0.22s ease, opacity 0.18s ease, border-top-color 0.22s ease;
  }
  .mode-tabs {
    position: fixed;
    top: 40px; /* below the 40px mobile .header row */
    left: 0;
    right: 0;
    z-index: 45;
    overflow: hidden;
    max-height: 50px;
    box-shadow: 0 2px 10px oklch(0% 0 0 / 0.07);
    transition: max-height 0.22s ease, opacity 0.18s ease;
  }
  /* Compensate for fixed chrome: tabs strip below header, footer strip above bottom */
  .main {
    padding-top: 50px;
    padding-bottom: 72px;
  }
  .detail-header {
    padding: 3px 10px 3px;
    overflow: hidden;
    max-height: 200px;
    transition: max-height 0.22s ease, padding 0.22s ease,
                opacity 0.18s ease, border-color 0.22s ease;
  }
  .main.topbar-hidden .stats-bar {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
    border-top-color: transparent;
  }
  .main.topbar-hidden .mode-tabs {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
  }
  .main.topbar-hidden .detail-header {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-bottom-color: transparent;
    opacity: 0;
    pointer-events: none;
  }
  .detail-title { font-size: 1rem; }
  .detail-breadcrumb {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }
  .detail-header > div:first-child {
    flex-wrap: wrap;
  }
  .detail-page {
    padding: 12px 14px 8px;
    overflow-x: hidden;
    overflow-y: visible;
    -webkit-overflow-scrolling: auto;
    max-width: 100%;
  }
  .field-row {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 10px 12px;
    max-width: 100%;
  }
  .field-label { font-size: 0.8125rem; }
  .field-value {
    border-left: none;
    padding-left: 0;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    font-size: 1rem;
    line-height: 1.7;
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
  }
  .detail-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 45;
    padding: 8px 10px 12px;
    gap: 6px;
    box-shadow: 0 -2px 10px oklch(0% 0 0 / 0.07);
  }
  .btn-nav {
    padding: 10px 14px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .page-info {
    font-size: 0.8125rem;
    text-align: center;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mode-tab { padding: 13px 16px; font-size: 0.75rem; min-height: 44px; }
  .flashcard-grid { gap: 6px; }
  .quiz-opt { padding: 10px 14px; font-size: 1rem; }
  .learn-panel {
    padding: 14px 14px 24px;
    overflow-x: hidden;
    overflow-y: visible;
    -webkit-overflow-scrolling: auto;
    max-width: 100%;
  }
  .algo-node { min-width: 0; max-width: 100%; padding: 8px 12px; font-size: 0.875rem; }
  .algo-branch { flex-direction: column; gap: 10px; }
  .algo-branch-arm { width: 100%; }
  .stats-bar { display: none !important; }
  .stat-item { display: none; }
  .mnemonic-word { font-size: 1.0625rem; letter-spacing: 3px; }
  .detail-page,
  .detail-page *,
  .learn-panel,
  .learn-panel * {
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
    box-sizing: border-box;
  }
  .field-value ul,
  .field-value ol { padding-left: 20px; margin: 6px 0; list-style-position: outside; }
  .field-value li { margin-bottom: 4px; overflow-wrap: break-word; word-break: break-word; }
  .callout { padding: 10px 12px; margin: 4px 0; font-size: 0.9375rem; }
  .comp-table-wrap { margin-left: 0; margin-right: 0; }
  .comp-table td { min-width: 0; }
  .comp-table th { white-space: normal; }
  .quiz-card,
  .quiz-item { padding: 12px; }
  .fitb-item { padding: 10px 12px; }
  .mnemonic-box { padding: 12px 14px; }
}

/* ─── RESPONSIVE — SMALL MOBILE ──────────────────────────────────── */
@media (max-width: 480px) {
  .header {
    padding: 0 8px;
  }
  .header > div:first-child {
    gap: 6px !important;
  }
  .header-title {
    font-size: 0.8125rem;
    letter-spacing: 0.5px;
  }
  .progress-wrap {
    display: none;
  }
  .back-btn {
    padding: 0 8px;
    font-size: 0.8125rem;
  }
  .sidebar-toggle {
    width: 26px;
    height: 26px;
  }
  #sidebar-nav {
    margin: 8px 8px 6px;
    gap: 6px;
  }
  .sidebar-dash-link,
  .sidebar-logout-btn {
    padding: 8px 6px;
    font-size: 0.8125rem;
  }
  .detail-header {
    padding: 3px 8px 3px;
  }
  .detail-title {
    font-size: 0.875rem;
  }
  .detail-breadcrumb {
    font-size: 0.75rem;
  }
  .detail-page {
    padding: 10px 10px 6px;
  }
  .field-row {
    padding: 8px 10px;
  }
  .field-label {
    font-size: 0.75rem;
  }
  .field-value {
    font-size: 0.9375rem;
    line-height: 1.65;
  }
  .detail-footer {
    padding: 6px 8px 10px;
  }
  .btn-nav {
    padding: 5px 8px;
    font-size: 0.8125rem;
  }
  .page-info {
    font-size: 0.75rem;
  }
  .mode-tab {
    padding: 8px 12px;
    font-size: 0.75rem;
    letter-spacing: 1px;
    min-height: 44px;
  }
  .learn-panel {
    padding: 10px 10px 20px;
  }
  .comp-table {
    font-size: 0.875rem;
  }
  .comp-table th {
    font-size: 0.75rem;
    padding: 8px 10px;
  }
  .comp-table td {
    padding: 8px 10px;
    font-size: 0.875rem;
  }
  .comp-table td.row-label {
    min-width: 100px;
    font-size: 0.875rem;
  }
  .flashcard-front {
    padding: 10px 12px;
  }
  .flashcard.flipped .flashcard-back {
    padding: 10px 12px;
  }
  .card-q {
    font-size: 0.9375rem;
  }
  .card-a {
    font-size: 0.9375rem;
  }
  .card-explain {
    font-size: 0.875rem;
  }
  .quiz-opt {
    padding: 8px 10px;
    font-size: 0.875rem;
  }
  .quiz-q {
    font-size: 0.9375rem;
  }
  .fitb-sentence {
    font-size: 0.9375rem;
  }
  .mnemonic-word {
    font-size: 1.125rem;
    letter-spacing: 2px;
  }
  .mnemonic-letter {
    font-size: 1.0625rem;
  }
  .mnemonic-meaning {
    font-size: 0.875rem;
  }
}

/* ─── RESPONSIVE — ULTRA-SMALL (≤360px) ──────────────────────── */
@media (max-width: 360px) {
  .header {
    padding: 0 6px;
    gap: 4px;
  }
  .header > div:first-child {
    gap: 4px !important;
  }
  .header-title {
    font-size: 0.75rem;
    letter-spacing: 0.3px;
  }
  .back-btn {
    padding: 0 6px;
    font-size: 0.8125rem;
  }
  .sidebar-toggle {
    width: 24px;
    height: 24px;
  }
  #sidebar-nav {
    margin: 6px 6px 4px;
    gap: 4px;
  }
  .sidebar-dash-link,
  .sidebar-logout-btn {
    padding: 6px 4px;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
  }
  .detail-title {
    font-size: 0.8125rem;
  }
  .detail-breadcrumb {
    font-size: 0.75rem;
  }
  .field-row {
    padding: 6px 8px;
  }
  .field-label {
    font-size: 0.75rem;
    letter-spacing: 0.5px;
  }
  .field-value {
    font-size: 0.875rem;
    line-height: 1.6;
  }
  .mode-tab {
    padding: 7px 10px;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    min-height: 44px;
  }
  .btn-nav {
    padding: 4px 6px;
    font-size: 0.75rem;
  }
  .comp-table td.row-label {
    min-width: 80px;
  }
}

/* ─── PAYWALL LOCK INDICATOR ─────────────────────────────────── */
.locked-link {
  opacity: 0.5 !important;
  cursor: pointer !important;
  position: relative;
}
.locked-link::after {
  content: ' 🔒';
  font-size: 0.8125rem;
  opacity: 0.8;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════
   IMPECCABLE DESIGN ADDITIONS — Audit Gap Fixes
   ═══════════════════════════════════════════════════════════════════ */

/* ─── C3: FOCUS-VISIBLE — keyboard focus indicators ─────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-nav:focus-visible,
.mode-tab:focus-visible,
.tree-label:focus-visible,
.search-input:focus-visible,
.global-search-input:focus-visible,
.sidebar-dash-link:focus-visible,
.sidebar-logout-btn:focus-visible,
.quiz-opt:focus-visible,
.fitb-blank:focus-visible,
.fitb-btn:focus-visible,
.flashcard:focus-visible,
.search-result-item:focus-visible,
.search-result-card:focus-visible,
.back-btn:focus-visible,
.top-badge:focus-visible,
.dash-link:focus-visible,
.logout-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Remove default outline for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* ─── C4/C8: PREFERS-REDUCED-MOTION ──────────────────────────────── */
@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;
  }
  body {
    opacity: 1 !important;
    animation: none !important;
  }
}

/* ─── C5/C21: SKIP-LINK + SR-ONLY ─────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--sp-2);
  background: var(--accent);
  color: var(--surface);
  padding: var(--sp-1) var(--sp-2);
  font-size: 1.125rem;
  font-weight: 600;
  font-family: var(--sans);
  z-index: 9999;
  border-radius: 0;
  text-decoration: none;
  letter-spacing: 0.05em;
}
.skip-link:focus {
  top: var(--sp-1);
  outline: 2px solid var(--surface);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── C1: PRINT STYLESHEET ────────────────────────────────────────── */
@media print {
  *, *::before, *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  body { opacity: 1 !important; animation: none !important; }
  .app { display: block !important; height: auto !important; }
  .sidebar, .sidebar-toggle, .mobile-backdrop,
  .header, .stats-bar, .mode-tabs,
  .btn-nav, .page-info, .detail-progress,
  .detail-footer, .search-wrap, .back-btn,
  .progress-wrap, .top-bar, .skip-link,
  #nav-links, #theme-toggle-btn { display: none !important; }
  .main { margin: 0 !important; padding: 16px !important; }
  .detail-panel { height: auto !important; overflow: visible !important; }
  .detail-body { overflow: visible !important; }
  .detail-page { max-width: 100% !important; }
  .field-row { break-inside: avoid; }
  a { text-decoration: underline; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.85em; }
}

/* ─── C9: ACTIVE/PRESSED STATES ───────────────────────────────────── */
.btn-nav:active {
  transform: scale(0.97);
  transition: transform 0.1s ease;
}
.mode-tab:active {
  background: var(--surface3);
  transform: scale(0.97);
}
.tree-label:active {
  background: var(--accent-dim);
}
.sidebar-dash-link:active,
.sidebar-logout-btn:active {
  transform: scale(0.98);
}
.back-btn:active {
  transform: translateX(-2px);
}
.top-badge:active {
  transform: scale(0.97);
}

/* ─── C13: ERROR STATE ─────────────────────────────────────────────── */
.error, .invalid {
  border-color: var(--red) !important;
  color: var(--red);
}
.error-msg {
  display: block;
  font-size: 1rem;
  color: var(--red);
  margin-top: 4px;
  font-weight: 500;
  font-family: var(--sans);
}
input:invalid,
textarea:invalid {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-dim);
}

/* ─── C14: SUCCESS STATE ───────────────────────────────────────────── */
.success {
  border-color: var(--accent2) !important;
  color: var(--accent2);
}
.success-msg {
  display: block;
  font-size: 1rem;
  color: var(--accent2);
  margin-top: 4px;
  font-weight: 500;
  font-family: var(--sans);
}

/* ─── C15/C18: TOOLTIP ─────────────────────────────────────────────── */
.tooltip {
  position: relative;
  cursor: help;
}
.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  font-size: 1rem;
  font-family: var(--sans);
  font-weight: 500;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s var(--ease-out);
  z-index: 50;
}
.tooltip:hover::after,
.tooltip:focus::after {
  opacity: 1;
}
.tooltip::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s var(--ease-out);
  z-index: 50;
}
.tooltip:hover::before,
.tooltip:focus::before {
  opacity: 1;
}

/* ─── C16: TOAST / NOTIFICATION ────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--sp-3);
  right: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  z-index: 300;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--surface);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  font-size: 1.0625rem;
  font-family: var(--sans);
  font-weight: 500;
  line-height: 1.5;
  box-shadow: var(--shadow-lifted);
  pointer-events: auto;
  animation: toastIn 0.3s var(--ease-out) forwards;
  max-width: 360px;
}
.toast.toast-exit {
  animation: toastOut 0.25s ease-in forwards;
}
.toast.toast-success { border-left: 3px solid var(--accent2); }
.toast.toast-error { border-left: 3px solid var(--red); }
.toast.toast-info { border-left: 3px solid var(--accent); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-8px); }
}

/* ─── C17: MODAL OVERLAY ────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 23, 20, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-3);
  animation: fadeIn 0.2s ease-out;
}
.modal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lifted);
  animation: modalIn 0.25s var(--ease-out);
}
.modal-title {
  font-size: 1.3125rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: var(--sp-2);
  font-family: var(--serif);
}
.modal-body {
  font-size: 1.125rem;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: var(--sp-3);
}
.modal-actions {
  display: flex;
  gap: var(--sp-1);
  justify-content: flex-end;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ─── C19: IMAGE / MEDIA RESPONSIVE ────────────────────────────────── */
img, picture, video, svg, figure {
  max-width: 100%;
  height: auto;
}
img {
  border-radius: var(--radius-sm);
}
figure {
  margin: var(--sp-2) 0;
}
figcaption {
  font-size: 1rem;
  color: var(--text3);
  font-family: var(--sans);
  font-weight: 500;
  margin-top: var(--sp-1);
  text-align: center;
}

/* ─── C20: GENERIC TABLE RESPONSIVE WRAPPER ────────────────────────── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: var(--sp-2) 0;
}

/* ─── C22: ARIA STATE STYLING ──────────────────────────────────────── */
[aria-expanded="true"] {
  font-weight: 600;
}
[aria-selected="true"] {
  background: var(--accent);
  color: var(--surface);
}
[aria-selected="false"] {
  background: transparent;
  color: var(--text2);
}
[aria-disabled="true"],
[aria-disabled="true"]:hover {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
[aria-checked="true"]::before {
  content: '✓ ';
  color: var(--accent2);
  font-weight: 700;
}

/* ─── C24: CONSISTENT HOVER LIFT ───────────────────────────────────── */
:root {
  --lift-y: -1px;
  --lift-y-hover: -2px;
  --lift-shadow: var(--shadow-hover);
  --lift-shadow-hover: var(--shadow-lifted);
}

/* ─── C25: TYPOGRAPHY SCALE (h1–h6) ───────────────────────────────── */
h1, .h1 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  font-family: var(--serif);
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: var(--sp-3);
}
h2, .h2 {
  font-size: 1.4375rem;
  font-weight: 600;
  line-height: 1.3;
  font-family: var(--serif);
  color: var(--text);
  letter-spacing: -0.005em;
  margin-bottom: var(--sp-2);
}
h3, .h3 {
  font-size: 1.3125rem;
  font-weight: 600;
  line-height: 1.4;
  font-family: var(--sans);
  color: var(--text);
  margin-bottom: var(--sp-2);
}
h4, .h4 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.45;
  font-family: var(--sans);
  color: var(--text2);
  margin-bottom: var(--sp-1);
}
h5, .h5 {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.5;
  font-family: var(--sans);
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--sp-1);
}
h6, .h6 {
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.5;
  font-family: var(--sans);
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--sp-1);
}

/* ─── C26: LINK UNDERLINE / VISITED ────────────────────────────────── */
a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
  text-underline-offset: 2px;
  text-decoration: underline;
  text-decoration-color: transparent;
}
a:hover {
  text-decoration-color: var(--accent);
}
a:visited {
  color: var(--accent4);
}
a:visited:hover {
  text-decoration-color: var(--accent4);
}
/* Override for navigation links that should stay clean */
.tree-label,
.tree-label:visited,
.back-btn,
.back-btn:visited,
.btn-nav,
.btn-nav:visited,
.sidebar-dash-link,
.sidebar-dash-link:visited,
.mode-tab,
.mode-tab:visited {
  text-decoration: none;
}

/* ─── C27: CODE / PRE STYLING ──────────────────────────────────────── */
code, pre {
  font-family: var(--mono);
}
code {
  font-size: 0.9em;
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--accent);
}
pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-2);
  overflow-x: auto;
  font-size: 1.0625rem;
  line-height: 1.6;
  margin: var(--sp-2) 0;
}
pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
}

/* ─── C28: BLOCKQUOTE ──────────────────────────────────────────────── */
blockquote {
  border-left: 3px solid var(--accent);
  padding: var(--sp-1) var(--sp-2);
  margin: var(--sp-2) 0;
  font-family: var(--serif);
  font-style: italic;
  color: var(--text2);
  background: var(--accent-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
blockquote p {
  margin: 0;
}

/* ─── C29: HORIZONTAL RULE ─────────────────────────────────────────── */
hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: var(--sp-3) 0;
}

/* ─── C30: GLOBAL LIST STYLING ────────────────────────────────────── */
ul, ol {
  padding-left: var(--sp-3);
  margin: var(--sp-1) 0;
}
ul { list-style-type: disc; }
ol { list-style-type: decimal; }
li {
  margin-bottom: 4px;
  line-height: 1.6;
}
li > ul, li > ol {
  margin-top: 4px;
  margin-bottom: 4px;
}

/* ─── C7/C11: GLOBAL SCROLLBAR + FIREFOX ──────────────────────────── */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) var(--surface);
}
html::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
html::-webkit-scrollbar-track {
  background: var(--surface);
}
html::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 4px;
}
html::-webkit-scrollbar-thumb:hover {
  background: var(--text3);
}

/* ─── C12: LOADING SKELETON / SHIMMER ─────────────────────────────── */
.skeleton {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--surface3) 50%, transparent 100%);
  animation: shimmer 1.5s ease-in-out infinite;
}
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: 3px;
}
.skeleton-text:last-child {
  width: 60%;
}
.skeleton-heading {
  height: 22px;
  width: 45%;
  margin-bottom: var(--sp-2);
}

/* ─── C2: DARK MODE (prefers-color-scheme + JS toggle) ─────────── */
/* OKLCH dark palette — same hue angles, inverted lightness */
[data-theme="dark"] {
    --bg:        oklch(15% 0.005 350);
    --surface:   oklch(20% 0.005 350);
    --surface2:  oklch(24% 0.005 350);
    --surface3:  oklch(28% 0.005 350);
    --border:    oklch(35% 0 0);
    --border2:   oklch(42% 0 0);
    --accent:    oklch(70% 0.25 350);
    --accent-dim:oklch(70% 0.25 350 / 0.15);
    --accent2:   oklch(70% 0.18 160);
    --accent2-dim:oklch(70% 0.18 160 / 0.12);
    --accent3:   oklch(75% 0.15 60);
    --accent4:   oklch(70% 0.18 300);
    --text:      oklch(96% 0.005 350);
    --text2:     oklch(80% 0 0);
    --text3:     oklch(62% 0 0);
    --red:       oklch(65% 0.22 25);
    --red-dim:   oklch(65% 0.22 25 / 0.15);
    --yellow:    oklch(75% 0.15 85);
    --yellow-dim:oklch(75% 0.15 85 / 0.12);
    --shadow-hover: 0 4px 24px -4px oklch(0% 0 0 / 0.30), 0 1px 3px oklch(0% 0 0 / 0.20);
    --shadow-lifted: 0 20px 40px oklch(0% 0 0 / 0.35);
    --shadow-accent: 0 4px 16px oklch(70% 0.25 350 / 0.15);
    background: oklch(15% 0.005 350);
    color: oklch(96% 0.005 350);
  }
  [data-theme="dark"] img { opacity: 0.92; }
[data-theme="light"] {
    --bg:        oklch(96% 0.005 350);
    --surface:   oklch(98% 0 0);
    --surface2:  oklch(92% 0 0);
    --surface3:  oklch(88% 0.005 350);
    --border:    oklch(82% 0 0);
    --border2:   oklch(72% 0 0);
    --accent:    oklch(55% 0.25 350);
    --accent-dim:oklch(55% 0.25 350 / 0.15);
    --accent2:   oklch(52% 0.18 160);
    --accent2-dim:oklch(52% 0.18 160 / 0.12);
    --accent3:   oklch(68% 0.15 60);
    --accent4:   oklch(55% 0.18 300);
    --text:      oklch(10% 0 0);
    --text2:     oklch(25% 0 0);
    --text3:     oklch(45% 0 0);
    --red:       oklch(55% 0.22 25);
    --red-dim:   oklch(55% 0.22 25 / 0.10);
    --yellow:    oklch(56% 0.15 85);
    --yellow-dim:oklch(72% 0.15 85 / 0.08);
    --shadow-hover: 0 4px 24px -4px oklch(10% 0 0 / 0.12), 0 1px 3px oklch(10% 0 0 / 0.06);
    --shadow-lifted: 0 20px 40px oklch(10% 0 0 / 0.08);
    --shadow-accent: 0 4px 16px oklch(60% 0.25 350 / 0.10);
    background: oklch(96% 0.005 350);
    color: oklch(10% 0 0);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        oklch(15% 0.005 350);
    --surface:   oklch(20% 0.005 350);
    --surface2:  oklch(24% 0.005 350);
    --surface3:  oklch(28% 0.005 350);
    --border:    oklch(35% 0 0);
    --border2:   oklch(42% 0 0);
    --accent:    oklch(70% 0.25 350);
    --accent-dim:oklch(70% 0.25 350 / 0.15);
    --accent2:   oklch(70% 0.18 160);
    --accent2-dim:oklch(70% 0.18 160 / 0.12);
    --accent3:   oklch(75% 0.15 60);
    --accent4:   oklch(70% 0.18 300);
    --text:      oklch(96% 0.005 350);
    --text2:     oklch(80% 0 0);
    --text3:     oklch(62% 0 0);
    --red:       oklch(65% 0.22 25);
    --red-dim:   oklch(65% 0.22 25 / 0.15);
    --yellow:    oklch(75% 0.15 85);
    --yellow-dim:oklch(75% 0.15 85 / 0.12);
    --shadow-hover: 0 4px 24px -4px oklch(0% 0 0 / 0.30), 0 1px 3px oklch(0% 0 0 / 0.20);
    --shadow-lifted: 0 20px 40px oklch(0% 0 0 / 0.35);
    --shadow-accent: 0 4px 16px oklch(70% 0.25 350 / 0.15);
  }
  img { opacity: 0.92; }
}

/* ─── FORM LABELS (H11 support) ──────────────────────────────────── */
label, .form-label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: var(--sans);
}

/* ─── C2: THEME TOGGLE BUTTON ─────────────────────────────────── */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border2);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.0625rem;
  color: var(--text2);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  margin-left: auto;
  flex-shrink: 0;
  position: relative;
}
/* Extend tap target to ~44px without enlarging the visible button */
.theme-toggle-btn::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
}
.theme-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.08);
}
.theme-toggle-btn:active {
  transform: scale(0.94);
}
.theme-toggle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Pages with no header (dashboard, admin, login) — fixed corner placement */
.theme-toggle-btn-floating {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 60;
  margin-left: 0;
  width: 40px;
  height: 40px;
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.theme-toggle-btn-floating::after {
  inset: -2px;
}

/* ─── MODULE FOOTER (injected by shared-logic.js) ────────────────── */
.module-footer {
  text-align: center;
  padding: 24px 16px 32px;
  margin-top: 40px;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text3);
  letter-spacing: 0.5px;
  font-family: var(--mono);
}
.module-footer a {
  color: var(--accent);
  text-decoration: underline;
}
.module-footer a:hover {
  opacity: 0.85;
}
