/* AISP Textbook - Page-specific styles */
/* Extends shared.css design system. Base layout inherited from the AIF textbook,
   plus AISP-specific components (confusable pairs, self-checks, CSS diagrams). */

/* Layout: sidebar + main content */
.study-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar TOC */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 280px;
  min-width: 280px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: var(--space-6) 0;
  z-index: 100;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  padding: 0 var(--space-6) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--space-4);
}

.sidebar-header a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: color var(--transition-fast);
}

.sidebar-header a:hover {
  color: var(--accent);
}

.sidebar-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 var(--space-6);
  margin-bottom: var(--space-3);
}

.sidebar nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar nav > ul > li {
  margin-bottom: var(--space-1);
}

.sidebar nav a {
  display: block;
  padding: var(--space-2) var(--space-6);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  line-height: 1.4;
  border-left: 3px solid transparent;
  transition: all var(--transition-fast);
}

.sidebar nav a:hover {
  color: var(--accent);
  background: var(--bg-primary);
  border-left-color: var(--accent);
}

.sidebar nav a.active {
  color: var(--accent);
  background: var(--bg-primary);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc-topic {
  font-weight: 600;
  color: var(--text-primary) !important;
  font-size: var(--text-sm) !important;
}

.toc-subtopic {
  padding-left: calc(var(--space-6) + var(--space-4)) !important;
  font-size: var(--text-xs) !important;
}

/* Mobile TOC toggle */
.toc-toggle {
  display: none;
  position: fixed;
  bottom: var(--space-6);
  left: var(--space-6);
  z-index: 200;
  background: var(--navy);
  color: var(--white);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: var(--text-xl);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
}

/* Main content */
.study-main {
  flex: 1;
  max-width: 52rem;
  margin: 0 auto;
  padding: var(--space-8) var(--space-8) var(--space-16);
}

/* Page header */
.study-header {
  text-align: center;
  margin-bottom: var(--space-12);
  padding-bottom: var(--space-8);
  border-bottom: 2px solid var(--border-color);
}

.study-header h1 {
  font-size: var(--text-4xl);
  color: var(--navy);
  margin-bottom: var(--space-4);
  line-height: 1.2;
}

[data-theme="dark"] .study-header h1 {
  color: var(--accent);
}

.study-header .subtitle {
  font-size: var(--text-lg);
  color: var(--text-muted);
  margin-bottom: var(--space-6);
}

.exam-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  justify-content: center;
  margin-top: var(--space-6);
}

.exam-meta-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-5);
  text-align: center;
}

.exam-meta-item .label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.exam-meta-item .value {
  display: block;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}

/* Topic sections */
.topic-section {
  margin-bottom: var(--space-12);
}

.topic-header {
  background: var(--navy);
  color: var(--white);
  padding: var(--space-6) var(--space-8);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-8);
  position: relative;
  overflow: hidden;
}

[data-theme="dark"] .topic-header {
  background: var(--navy-light);
}

.topic-header h2 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-2);
  color: var(--white);
}

.topic-header .weight-badge {
  display: inline-block;
  background: var(--gold);
  color: var(--navy-dark);
  padding: var(--space-1) var(--space-3);
  border-radius: 9999px;
  font-size: var(--text-sm);
  font-weight: 700;
}

/* Subtopic sections */
.subtopic {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border-color);
}

.subtopic:last-child {
  border-bottom: none;
}

.subtopic-header {
  margin-bottom: var(--space-4);
}

.subtopic-header h3 {
  font-size: var(--text-xl);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.bloom-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: var(--space-1) var(--space-3);
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Content within subtopics */
.subtopic ul {
  padding-left: var(--space-6);
  margin: var(--space-3) 0;
}

.subtopic li {
  margin-bottom: var(--space-2);
  line-height: 1.6;
  color: var(--text-secondary);
}

.subtopic li strong {
  color: var(--text-primary);
}

.subtopic p {
  margin-bottom: var(--space-4);
  line-height: 1.8;
  color: var(--text-secondary);
}

/* Definition term highlighting */
.def-term {
  font-weight: 700;
  color: var(--accent);
}

[data-theme="dark"] .def-term {
  color: var(--accent-light);
}

/* Callout boxes - extend shared callouts */
.callout {
  margin: var(--space-6) 0;
}

.callout p {
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout ul {
  padding-left: var(--space-6);
  margin: var(--space-2) 0;
}

.callout li {
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.callout-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Exam checklist */
.exam-checklist {
  background: var(--bg-card);
  border: 2px solid var(--gold);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  margin-top: var(--space-12);
}

.exam-checklist h2 {
  color: var(--navy);
  margin-bottom: var(--space-6);
  text-align: center;
}

[data-theme="dark"] .exam-checklist h2 {
  color: var(--gold);
}

.exam-checklist ol {
  padding-left: var(--space-6);
}

.exam-checklist li {
  margin-bottom: var(--space-4);
  line-height: 1.6;
  padding-left: var(--space-2);
}

.exam-checklist li strong {
  color: var(--text-primary);
}

/* Intro section */
.intro-section {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  margin-bottom: var(--space-10);
  border: 1px solid var(--border-color);
}

.intro-section h2 {
  color: var(--navy);
  margin-bottom: var(--space-4);
}

[data-theme="dark"] .intro-section h2 {
  color: var(--accent);
}

.intro-section h3 {
  color: var(--text-primary);
  font-size: var(--text-lg);
  margin: var(--space-6) 0 var(--space-3);
}

.intro-section p {
  margin-bottom: var(--space-3);
  line-height: 1.7;
}

.strategy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.strategy-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: center;
}

.strategy-item .number {
  display: block;
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--accent);
}

.strategy-item .label {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* "In Practice" case study boxes */
.in-practice {
  background: var(--info-bg);
  border: 1px solid var(--info);
  border-left: 4px solid var(--info);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin: var(--space-6) 0;
}

[data-theme="dark"] .in-practice {
  background: rgba(21, 101, 192, 0.08);
}

.in-practice-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--info);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.in-practice p {
  color: var(--text-primary);
  line-height: 1.7;
}

/* "Connecting the Dots" boxes */
.connecting-dots {
  background: var(--highlight-bg);
  border: 1px solid var(--gold);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin: var(--space-6) 0;
}

[data-theme="dark"] .connecting-dots {
  background: rgba(240, 171, 0, 0.06);
}

.connecting-dots-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold-dark);
  margin-bottom: var(--space-3);
}

[data-theme="dark"] .connecting-dots-title {
  color: var(--gold);
}

/* Chapter intro with learning objectives */
.chapter-intro {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-8);
}

.chapter-intro h4 {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-3);
}

.chapter-intro ul {
  padding-left: var(--space-6);
  margin: 0;
}

.chapter-intro li {
  margin-bottom: var(--space-2);
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Chapter summary */
.chapter-summary {
  background: var(--success-bg);
  border: 1px solid var(--success);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-top: var(--space-8);
}

[data-theme="dark"] .chapter-summary {
  background: rgba(46, 125, 50, 0.08);
}

.chapter-summary h4 {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--success);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-3);
}

/* ═══════════════════════════════════════════════════════════════════ */
/* AISP-SPECIFIC COMPONENTS                                             */
/* ═══════════════════════════════════════════════════════════════════ */

/* Learning-objective headings inside a subtopic */
.subtopic h4.lo-title {
  font-size: var(--text-lg);
  color: var(--text-primary);
  margin: var(--space-8) 0 var(--space-3);
  padding-top: var(--space-5);
  border-top: 1px dashed var(--border-color);
}

.subtopic h4.lo-title:first-of-type {
  border-top: none;
  padding-top: 0;
}

/* Spec tag: official exam-spec ID badge on LO headings */
.spec-tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--navy);
  background: var(--highlight-bg);
  border: 1px solid var(--gold);
  padding: 2px 10px;
  border-radius: 9999px;
  vertical-align: middle;
  margin-left: var(--space-2);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

[data-theme="dark"] .spec-tag {
  color: var(--gold);
}

/* Scenario opener: short business scenario in exam register */
.scenario {
  background: var(--bg-secondary);
  border-left: 4px solid var(--navy-light);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  margin: var(--space-4) 0;
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.7;
}

[data-theme="dark"] .scenario {
  border-left-color: var(--gold);
}

/* Confusable pair: side-by-side disambiguation of adjacent concepts */
.confusable-pair {
  border: 2px solid var(--error);
  border-radius: var(--radius-lg);
  margin: var(--space-6) 0;
  overflow: hidden;
  background: var(--bg-card);
}

.confusable-pair .cp-title {
  background: var(--error-bg);
  color: var(--error);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-3) var(--space-5);
}

[data-theme="dark"] .confusable-pair .cp-title {
  background: rgba(198, 40, 40, 0.15);
}

.confusable-pair .cp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.confusable-pair .cp-side {
  padding: var(--space-4) var(--space-5);
}

.confusable-pair .cp-side + .cp-side {
  border-left: 1px solid var(--border-color);
}

.confusable-pair .cp-side h5 {
  font-size: var(--text-base);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.confusable-pair .cp-side p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}

.confusable-pair .cp-tell {
  border-top: 1px solid var(--border-color);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.confusable-pair .cp-tell strong {
  color: var(--error);
}

/* Self-check: reveal-to-answer questions */
details.self-check {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin: var(--space-3) 0;
}

details.self-check summary {
  cursor: pointer;
  padding: var(--space-3) var(--space-5);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.6;
}

details.self-check summary::marker {
  color: var(--accent);
}

details.self-check .sc-answer {
  padding: var(--space-3) var(--space-5) var(--space-4);
  color: var(--text-secondary);
  border-top: 1px dashed var(--border-color);
  line-height: 1.7;
}

details.self-check .sc-answer p {
  margin-bottom: var(--space-2);
}

/* Drill variant: chapter-level pairing-format questions */
details.self-check.drill {
  border-color: var(--navy-light);
  background: var(--bg-card);
}

details.self-check.drill summary {
  white-space: pre-line;
}

.self-check-block > h4 {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: var(--space-6) 0 var(--space-3);
}

/* ── CSS diagram kit ──────────────────────────────────────────────── */

/* Generic diagram wrapper with caption */
.diagram {
  margin: var(--space-6) 0;
  padding: var(--space-6);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.diagram .diagram-title {
  text-align: center;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

/* Step strip: ordered framework steps (G.U.A.R.D., risk management) */
.step-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: center;
}

.step-strip .step {
  flex: 1;
  min-width: 120px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-top: 4px solid var(--navy);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: center;
}

[data-theme="dark"] .step-strip .step {
  border-top-color: var(--gold);
}

.step-strip .step .step-num {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: var(--white);
  border-radius: 50%;
  font-weight: 700;
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

[data-theme="dark"] .step-strip .step .step-num {
  background: var(--gold);
  color: var(--navy-dark);
}

.step-strip .step .step-name {
  display: block;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.step-strip .step .step-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.5;
}

/* Layer stack: stacked defense layers (7 layers of prompt injection protection) */
.layer-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 520px;
  margin: 0 auto;
}

.layer-stack .layer {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 6px solid var(--navy);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}

[data-theme="dark"] .layer-stack .layer {
  border-left-color: var(--gold);
}

.layer-stack .layer .layer-num {
  display: inline-flex;
  min-width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: var(--white);
  border-radius: 50%;
  font-weight: 700;
  font-size: var(--text-xs);
}

[data-theme="dark"] .layer-stack .layer .layer-num {
  background: var(--gold);
  color: var(--navy-dark);
}

.layer-stack .layer .layer-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: var(--text-sm);
}

.layer-stack .layer .layer-note {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-left: auto;
  text-align: right;
  max-width: 45%;
}

/* Spectrum: attacker-knowledge scale (evasion types) */
.spectrum {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
}

.spectrum .stop {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-bottom: 4px solid var(--info);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: center;
}

.spectrum .stop.stop-1 { border-bottom-color: #2E7D32; }
.spectrum .stop.stop-2 { border-bottom-color: #9E9D24; }
.spectrum .stop.stop-3 { border-bottom-color: #F0AB00; }
.spectrum .stop.stop-4 { border-bottom-color: #E65100; }
.spectrum .stop.stop-5 { border-bottom-color: #C62828; }

.spectrum .stop .stop-name {
  display: block;
  font-weight: 700;
  color: var(--text-primary);
  font-size: var(--text-sm);
  margin-bottom: var(--space-1);
}

.spectrum .stop .stop-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.5;
}

/* Pyramid: EU AI Act risk tiers */
.pyramid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.pyramid .tier {
  text-align: center;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 600;
  min-width: 200px;
}

.pyramid .tier small {
  display: block;
  font-weight: 400;
  font-size: var(--text-xs);
  opacity: 0.92;
  margin-top: 2px;
}

.pyramid .tier-1 { width: 40%; background: #C62828; }
.pyramid .tier-2 { width: 60%; background: #E65100; }
.pyramid .tier-3 { width: 80%; background: #F0AB00; color: var(--navy-dark); }
.pyramid .tier-4 { width: 100%; background: #2E7D32; }

/* Split twins: provider vs deployer responsibility (self-hosted vs hosted) */
.split-twins {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.split-twins .twin {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-card);
}

.split-twins .twin h5 {
  background: var(--navy);
  color: var(--white);
  padding: var(--space-3) var(--space-4);
  margin: 0;
  font-size: var(--text-sm);
  text-align: center;
}

[data-theme="dark"] .split-twins .twin h5 {
  background: var(--navy-light);
}

.split-twins .twin-band {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-color);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.split-twins .twin-band.owner-supplier { background: var(--info-bg); }
.split-twins .twin-band.owner-you { background: var(--highlight-bg); }

[data-theme="dark"] .split-twins .twin-band.owner-supplier { background: rgba(21, 101, 192, 0.1); }
[data-theme="dark"] .split-twins .twin-band.owner-you { background: rgba(240, 171, 0, 0.08); }

.split-twins .twin-band .band-owner {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

/* Pipeline steps: numbered process chain (8-step testing approach) */
.pipeline-steps {
  counter-reset: pipe;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}

.pipeline-steps .pipe-step {
  counter-increment: pipe;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  padding-left: calc(var(--space-4) + 36px);
  position: relative;
}

.pipeline-steps .pipe-step::before {
  content: counter(pipe);
  position: absolute;
  left: var(--space-3);
  top: var(--space-4);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: var(--white);
  border-radius: 50%;
  font-weight: 700;
  font-size: var(--text-xs);
}

[data-theme="dark"] .pipeline-steps .pipe-step::before {
  background: var(--gold);
  color: var(--navy-dark);
}

.pipeline-steps .pipe-step .pipe-name {
  font-weight: 700;
  display: block;
  color: var(--text-primary);
  font-size: var(--text-sm);
  margin-bottom: 2px;
}

.pipeline-steps .pipe-step .pipe-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.5;
}

/* Threat map: input threats column + development-time / runtime bands */
.threat-map {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: minmax(200px, 240px) 1fr;
  grid-template-areas:
    "input dev"
    "input runtime";
}

.threat-map .tm-zone {
  border: 2px solid;
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.threat-map .tm-input   { grid-area: input;   border-color: #C62828; background: rgba(198, 40, 40, 0.05); }
.threat-map .tm-dev     { grid-area: dev;     border-color: #1565C0; background: rgba(21, 101, 192, 0.05); }
.threat-map .tm-runtime { grid-area: runtime; border-color: #6A1B9A; background: rgba(106, 27, 154, 0.05); }

.threat-map .tm-zone h5 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}

.threat-map .tm-zone ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.threat-map .tm-zone li {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin: 0;
}

.threat-map .tm-zone li .impact {
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.threat-map .tm-legend {
  grid-column: 1 / -1;
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding-top: var(--space-2);
}

/* Band diagram: lifecycle bands (poisoning across supplier/dev/runtime) */
.band-diagram {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.band-diagram .band {
  display: grid;
  grid-template-columns: 160px 1fr;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.band-diagram .band .band-label {
  background: var(--navy);
  color: var(--white);
  padding: var(--space-3);
  font-size: var(--text-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
}

[data-theme="dark"] .band-diagram .band .band-label {
  background: var(--navy-light);
}

.band-diagram .band .band-content {
  padding: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  background: var(--bg-card);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.band-diagram .chip {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  padding: 2px 10px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.band-diagram .chip.threat {
  border-color: var(--error);
  color: var(--error);
  font-weight: 600;
}

/* Compare cards: side-by-side concept panels (inversion vs membership etc.) */
.compare-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin: var(--space-4) 0;
}

.compare-cards .cc {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-top: 4px solid var(--info);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.compare-cards .cc h5 {
  margin-bottom: var(--space-2);
  color: var(--text-primary);
  font-size: var(--text-base);
}

.compare-cards .cc p,
.compare-cards .cc ul {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.compare-cards .cc ul {
  padding-left: var(--space-5);
  margin: var(--space-2) 0 0;
}

/* Master table: threat → impact → control and similar reference tables */
.table-scroll {
  overflow-x: auto;
  margin: var(--space-4) 0;
}

.master-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.master-table th {
  background: var(--navy);
  color: var(--white);
  padding: var(--space-3);
  text-align: left;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

[data-theme="dark"] .master-table th {
  background: var(--navy-light);
}

.master-table td {
  border: 1px solid var(--border-color);
  padding: var(--space-3);
  color: var(--text-secondary);
  vertical-align: top;
  line-height: 1.6;
}

.master-table tr:nth-child(even) td {
  background: var(--bg-secondary);
}

.master-table td strong {
  color: var(--text-primary);
}

/* Print styles */
@media print {
  .sidebar,
  .toc-toggle,
  .theme-toggle {
    display: none !important;
  }

  .study-layout {
    display: block;
  }

  .study-main {
    max-width: 100%;
    padding: 0;
  }

  .topic-header {
    background: none !important;
    color: #000 !important;
    border: 2px solid #000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .topic-header h2 {
    color: #000 !important;
  }

  .topic-header .weight-badge {
    border: 1px solid #000;
  }

  .callout,
  .confusable-pair,
  .diagram,
  .in-practice,
  .connecting-dots {
    border: 1px solid #999;
    page-break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .subtopic {
    page-break-inside: avoid;
  }

  details.self-check {
    page-break-inside: avoid;
  }

  .pyramid .tier,
  .step-strip .step,
  .layer-stack .layer,
  .threat-map .tm-zone,
  .master-table th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .exam-checklist {
    page-break-before: always;
  }

  body {
    font-size: 11pt;
  }
}

/* Responsive */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .toc-toggle {
    display: flex;
  }

  .study-main {
    padding: var(--space-6) var(--space-4) var(--space-16);
  }

  .topic-header {
    padding: var(--space-4) var(--space-6);
  }
}

@media (max-width: 640px) {
  .study-header h1 {
    font-size: var(--text-2xl);
  }

  .exam-meta {
    flex-direction: column;
    align-items: center;
  }

  .exam-meta-item {
    width: 100%;
  }

  .strategy-grid {
    grid-template-columns: 1fr;
  }

  .intro-section,
  .exam-checklist {
    padding: var(--space-4);
  }

  .confusable-pair .cp-grid {
    grid-template-columns: 1fr;
  }

  .confusable-pair .cp-side + .cp-side {
    border-left: none;
    border-top: 1px solid var(--border-color);
  }

  .split-twins {
    grid-template-columns: 1fr;
  }

  .threat-map {
    grid-template-columns: 1fr;
    grid-template-areas:
      "input"
      "dev"
      "runtime";
  }

  .band-diagram .band {
    grid-template-columns: 1fr;
  }

  .band-diagram .band .band-label {
    padding: var(--space-2) var(--space-3);
  }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.sidebar-overlay.open {
  display: block;
}
