/* ==========================================================================
   REW Pro Field Manual — Dark Technical Instrument Theme
   ========================================================================== */

:root {
  /* Core surfaces */
  --bg-canvas: #0a0d12;
  --bg-surface: #11161f;
  --bg-elevated: #171e2a;
  --bg-inset: #0d1118;
  --bg-hover: #1d2636;

  /* Borders */
  --border-subtle: #222b3a;
  --border-strong: #324056;
  --border-focus: #38bdf8;

  /* Typography */
  --text-primary: #e6ecf5;
  --text-secondary: #9aa7bd;
  --text-muted: #6c7a93;

  /* Analyzer trace palette */
  --accent-cyan: #38bdf8;
  --accent-cyan-dim: rgba(56, 189, 248, 0.14);
  --accent-amber: #f59e0b;
  --accent-amber-dim: rgba(245, 158, 11, 0.14);
  --accent-emerald: #10b981;
  --accent-emerald-dim: rgba(16, 185, 129, 0.14);
  --accent-rose: #f43f5e;
  --accent-rose-dim: rgba(244, 63, 94, 0.14);
  --accent-violet: #a78bfa;
  --accent-violet-dim: rgba(167, 139, 250, 0.14);

  /* Fonts */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Layout & radii */
  --max-width: 1220px;
  --lesson-max: 920px;
  --header-h: 64px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-float: 0 12px 32px rgba(0, 0, 0, 0.55);
}

/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-canvas);
  background-image:
    radial-gradient(circle at 12% 0%, rgba(56, 189, 248, 0.06), transparent 36%),
    radial-gradient(circle at 88% 8%, rgba(167, 139, 250, 0.05), transparent 32%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

a:hover {
  color: #7dd3fc;
}

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

h1, h2, h3, h4 {
  margin: 0 0 0.65rem;
  color: var(--text-primary);
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 650;
}

h1 { font-size: clamp(1.75rem, 3.2vw, 2.5rem); }
h2 { font-size: clamp(1.3rem, 2.2vw, 1.65rem); }
h3 { font-size: 1.12rem; }
h4 { font-size: 0.96rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }

p {
  margin: 0 0 1rem;
  color: var(--text-secondary);
}

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

strong {
  color: var(--text-primary);
  font-weight: 600;
}

code,
kbd,
pre {
  font-family: var(--font-mono);
}

code {
  font-size: 0.86em;
  background: rgba(56, 189, 248, 0.09);
  border: 1px solid rgba(56, 189, 248, 0.18);
  color: #bae6fd;
  padding: 0.12em 0.42em;
  border-radius: var(--radius-sm);
}

pre {
  margin: 0;
  padding: 0.9rem 1.05rem;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.55;
  color: #dbeafe;
}

pre code {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.kbd {
  display: inline-block;
  font-size: 0.78em;
  padding: 0.12em 0.45em;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 999;
  padding: 0.75rem 1rem;
  background: var(--accent-cyan);
  color: #06131c;
  font-weight: 700;
}

.skip-link:focus {
  left: 0.75rem;
  top: 0.75rem;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 13, 18, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: var(--header-h);
  padding: 0.6rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--text-primary);
  flex-shrink: 0;
}

.brand:hover {
  color: var(--text-primary);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-title {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.site-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.4rem 0.62rem;
  border-radius: var(--radius-sm);
  font-size: 0.81rem;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid transparent;
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.nav-link[aria-current="page"] {
  color: var(--accent-cyan);
  background: var(--accent-cyan-dim);
  border-color: rgba(56, 189, 248, 0.3);
}

.nav-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.nav-link[aria-current="page"] .nav-num {
  color: var(--accent-cyan);
}

.nav-link.is-complete::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.7);
  margin-left: 0.15rem;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 38px;
  height: 38px;
  padding: 0 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.nav-toggle-bar {
  height: 2px;
  width: 100%;
  background: var(--text-primary);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* ==========================================================================
   Page Shell & Buttons
   ========================================================================== */

.page-shell {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.58rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent-cyan);
  color: #06131c;
}

.btn-primary:hover {
  background: #7dd3fc;
  color: #06131c;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--accent-cyan);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}

.btn-ghost:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

.btn-success {
  background: var(--accent-emerald-dim);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.4);
}

.btn-sm {
  padding: 0.38rem 0.72rem;
  font-size: 0.78rem;
}

/* ==========================================================================
   Landing Page — Hero, Progress Widget & Curriculum Grid
   ========================================================================== */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(290px, 0.95fr);
  gap: 1.75rem;
  align-items: start;
  padding: 1.75rem;
  margin-bottom: 2.5rem;
  background: linear-gradient(180deg, var(--bg-surface) 0%, #0e131b 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.eyebrow,
.section-kicker,
.detail-kicker {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-cyan);
  margin-bottom: 0.55rem;
}

.hero-lead {
  font-size: 1rem;
  max-width: 66ch;
  margin-bottom: 1.15rem;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.meta-pill {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-secondary);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

.progress-widget {
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.2rem;
}

.progress-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.65rem;
}

.widget-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.progress-fraction {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.progress-bar {
  height: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-emerald));
  border-radius: 999px;
  transition: width 0.35s ease;
}

.progress-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.stat-cell {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-mono {
  font-size: 0.74rem;
  color: var(--accent-cyan);
}

.progress-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.section-sub {
  max-width: 56ch;
  font-size: 0.92rem;
}

.curriculum-section,
.reference-section,
.platform-section {
  margin-bottom: 2.75rem;
}

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1.1rem;
}

.lesson-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.lesson-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.lesson-card.is-complete {
  border-color: rgba(16, 185, 129, 0.35);
}

.lesson-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
}

.lesson-code {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent-cyan);
  letter-spacing: 0.06em;
}

.status-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.status-badge.is-complete {
  background: var(--accent-emerald-dim);
  border-color: rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
}

.status-badge.is-in-progress {
  background: var(--accent-amber-dim);
  border-color: rgba(245, 158, 11, 0.35);
  color: #fcd34d;
}

.lesson-card h3 {
  font-size: 1.08rem;
  margin-bottom: 0.55rem;
}

.lesson-card h3 a {
  color: var(--text-primary);
}

.lesson-card h3 a:hover {
  color: var(--accent-cyan);
}

.lesson-card p {
  font-size: 0.9rem;
  flex: 1;
  margin-bottom: 0.9rem;
}

.tag-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
}

.tag-list li {
  font-family: var(--font-mono);
  font-size: 0.71rem;
  color: var(--text-secondary);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  padding: 0.16rem 0.48rem;
  border-radius: var(--radius-sm);
}

.lesson-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.84rem;
}

.quiz-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-cta {
  font-weight: 600;
  font-size: 0.84rem;
}

/* ==========================================================================
   Lesson Page Layout (Shared Canonical Structure Across All 7 Lessons)
   ========================================================================== */

.lesson-shell {
  max-width: var(--max-width);
}

.lesson-layout {
  display: grid;
  grid-template-columns: minmax(0, var(--lesson-max)) minmax(220px, 260px);
  gap: 2rem;
  align-items: start;
}

.lesson-main {
  min-width: 0;
}

.lesson-toc {
  position: sticky;
  top: calc(var(--header-h) + 1.25rem);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.lesson-toc-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.lesson-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.lesson-toc a {
  display: block;
  font-size: 0.83rem;
  color: var(--text-secondary);
  padding: 0.25rem 0.45rem;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.lesson-toc a:hover {
  color: var(--text-primary);
  border-left-color: var(--accent-cyan);
  background: var(--bg-elevated);
}

.lesson-header {
  padding: 1.6rem 1.75rem;
  margin-bottom: 2rem;
  background: linear-gradient(180deg, var(--bg-surface) 0%, #0e131b 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.lesson-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.lesson-lead {
  font-size: 1.02rem;
  color: var(--text-secondary);
  max-width: 68ch;
  margin-bottom: 1.2rem;
}

.lesson-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

.lesson-meta-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.lesson-section {
  margin-bottom: 2.25rem;
  padding: 1.5rem 1.65rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  scroll-margin-top: calc(var(--header-h) + 1rem);
}

.lesson-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border-subtle);
}

.lesson-section-head h2 {
  margin: 0;
}

/* Section 1: What this is for */
.purpose-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.purpose-card {
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.95rem 1rem;
}

.purpose-card h3 {
  font-size: 0.9rem;
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  margin-bottom: 0.4rem;
}

.purpose-card p {
  font-size: 0.88rem;
}

/* Section 2: Numbered Steps */
.step-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: rew-step;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.step-list > li {
  counter-increment: rew-step;
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 0.95rem;
  align-items: start;
  padding: 1rem 1.1rem;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.step-list > li::before {
  content: counter(rew-step, decimal-leading-zero);
  display: grid;
  place-items: center;
  width: 42px;
  height: 32px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-cyan);
  background: var(--accent-cyan-dim);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: var(--radius-sm);
}

.step-title {
  display: block;
  font-weight: 650;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

.step-body {
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.step-params {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.param-tag {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: #fde68a;
  background: var(--accent-amber-dim);
  border: 1px solid rgba(245, 158, 11, 0.28);
  padding: 0.14rem 0.48rem;
  border-radius: var(--radius-sm);
}

/* Section 3: Reading the Output (Graph Interpretation Blocks) */
.graph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.graph-block {
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-top: 3px solid var(--accent-cyan);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.graph-block.graph-phase { border-top-color: var(--accent-amber); }
.graph-block.graph-decay { border-top-color: var(--accent-violet); }
.graph-block.graph-distortion { border-top-color: var(--accent-rose); }
.graph-block.graph-impedance { border-top-color: var(--accent-emerald); }

.graph-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.graph-header h3 {
  margin: 0;
  font-size: 1rem;
}

.graph-view-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.trace-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.trace-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.trace-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.trace-dot.cyan { background: var(--accent-cyan); }
.trace-dot.amber { background: var(--accent-amber); }
.trace-dot.emerald { background: var(--accent-emerald); }
.trace-dot.rose { background: var(--accent-rose); }
.trace-dot.violet { background: var(--accent-violet); }

.signal-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
}

.metric-box {
  padding: 0.45rem 0.6rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.metric-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
}

.diagnostic-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

.diag-good { color: #6ee7b7; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600; }
.diag-bad { color: #fda4af; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600; }

/* Section 4: Collapsible "Deeper detail" Panels */
.detail-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.detail-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.detail-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.detail-panel:hover,
.detail-panel.is-open,
details.detail-panel[open] {
  border-color: var(--border-strong);
}

.detail-trigger,
details.detail-panel > summary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  background: var(--bg-elevated);
  border: 0;
  color: var(--text-primary);
  text-align: left;
  font-family: var(--font-sans);
  cursor: pointer;
  list-style: none;
}

details.detail-panel > summary::-webkit-details-marker {
  display: none;
}

.detail-trigger-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.detail-title {
  font-size: 1rem;
  font-weight: 650;
  color: var(--text-primary);
}

.detail-chevron {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--accent-cyan);
  border-bottom: 2px solid var(--accent-cyan);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  margin-right: 4px;
}

.detail-trigger[aria-expanded="true"] .detail-chevron,
details.detail-panel[open] > summary .detail-chevron {
  transform: rotate(-135deg);
}

.detail-body {
  padding: 1.2rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

/* Progressive enhancement: hide collapsed body ONLY when JS is active */
.js-enabled .detail-panel[data-collapsible]:not(.is-open) .detail-body {
  display: none;
}

/* Section 5: Worked Example */
.worked-example {
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.05) 0%, var(--bg-inset) 100%);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.35rem;
}

.example-params {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.example-params span strong {
  color: var(--accent-cyan);
}

.example-outcome {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  background: var(--accent-emerald-dim);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-sm);
}

.example-outcome h4 {
  color: #6ee7b7;
  margin-bottom: 0.35rem;
}

/* Section 6: Check Your Understanding (Quiz Blocks) */
.quiz-block {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.quiz-question {
  padding: 1.1rem 1.2rem;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: border-color 0.2s ease;
}

.quiz-question.is-correct {
  border-color: rgba(16, 185, 129, 0.5);
}

.quiz-question.is-incorrect {
  border-color: rgba(244, 63, 94, 0.5);
}

.quiz-question.is-unanswered {
  border-color: rgba(245, 158, 11, 0.55);
}

.quiz-prompt {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.58rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.quiz-option:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.quiz-option input[type="radio"] {
  margin-top: 0.22rem;
  accent-color: var(--accent-cyan);
  flex-shrink: 0;
}

.quiz-option.opt-correct {
  background: var(--accent-emerald-dim);
  border-color: rgba(16, 185, 129, 0.5);
  color: #d1fae5;
}

.quiz-option.opt-wrong {
  background: var(--accent-rose-dim);
  border-color: rgba(244, 63, 94, 0.5);
  color: #ffe4e6;
}

.quiz-feedback {
  margin-top: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  display: none;
}

.quiz-feedback.is-visible {
  display: block;
}

.quiz-feedback.fb-correct {
  background: var(--accent-emerald-dim);
  border-left: 3px solid var(--accent-emerald);
  color: #d1fae5;
}

.quiz-feedback.fb-incorrect {
  background: var(--accent-rose-dim);
  border-left: 3px solid var(--accent-rose);
  color: #ffe4e6;
}

.quiz-feedback.fb-warn {
  background: var(--accent-amber-dim);
  border-left: 3px solid var(--accent-amber);
  color: #fef3c7;
}

.quiz-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.quiz-summary {
  padding: 0.85rem 1.05rem;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  color: var(--text-primary);
  display: none;
}

.quiz-summary.is-visible {
  display: block;
}

.quiz-summary.pass {
  border-color: rgba(16, 185, 129, 0.5);
  background: var(--accent-emerald-dim);
  color: #a7f3d0;
}

/* ==========================================================================
   Callouts, Tables, Code Blocks & Utilities
   ========================================================================== */

.callout {
  padding: 0.95rem 1.1rem;
  margin: 1rem 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  border-left-width: 4px;
  background: var(--bg-inset);
  font-size: 0.9rem;
}

.callout-title {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.callout-info { border-left-color: var(--accent-cyan); }
.callout-info .callout-title { color: var(--accent-cyan); }

.callout-warn { border-left-color: var(--accent-amber); background: rgba(245, 158, 11, 0.06); }
.callout-warn .callout-title { color: var(--accent-amber); }

.callout-danger { border-left-color: var(--accent-rose); background: rgba(244, 63, 94, 0.06); }
.callout-danger .callout-title { color: var(--accent-rose); }

.callout-tip { border-left-color: var(--accent-emerald); background: rgba(16, 185, 129, 0.06); }
.callout-tip .callout-title { color: var(--accent-emerald); }

.callout-mac { border-left-color: var(--accent-violet); background: rgba(167, 139, 250, 0.07); }
.callout-mac .callout-title { color: var(--accent-violet); }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 0.72rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.data-table thead th {
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: rgba(56, 189, 248, 0.04);
}

.cmd-block {
  position: relative;
  margin-bottom: 0.85rem;
}

.cmd-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.copy-btn {
  position: absolute;
  top: 1.75rem;
  right: 0.5rem;
  padding: 0.22rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent-cyan);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.4rem;
}

.dense-list {
  margin: 0.4rem 0 0;
  padding-left: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Tooltips */
.term,
[data-tooltip] {
  border-bottom: 1px dashed var(--accent-cyan);
  color: #cdeeff;
  cursor: help;
}

.rew-tooltip {
  position: fixed;
  z-index: 500;
  max-width: 310px;
  padding: 0.58rem 0.78rem;
  background: #0b1220;
  color: var(--text-primary);
  border: 1px solid var(--accent-cyan);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-float);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.rew-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Lesson Pager & Footer */
.lesson-pager {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 1rem;
  margin-top: 2.25rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}

.pager-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.9rem 1.05rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.pager-link:hover {
  border-color: var(--accent-cyan);
  background: var(--bg-elevated);
}

.pager-next {
  text-align: right;
  margin-left: auto;
}

.pager-dir {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

.pager-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.92rem;
}

.site-footer {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-inset);
  margin-top: auto;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-mono {
  font-family: var(--font-mono);
  font-size: 0.76rem;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 1040px) {
  .lesson-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .lesson-toc {
    position: static;
    order: -1;
  }

  .lesson-toc ul {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .lesson-toc a {
    border-left: 0;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.6rem;
  }
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
    padding: 1.35rem;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1.25rem 1rem;
    background: rgba(12, 16, 23, 0.98);
    border-bottom: 1px solid var(--border-strong);
    box-shadow: var(--shadow-float);
  }

  .site-nav.is-open {
    display: flex;
  }

  .nav-link {
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 1.25rem 0.9rem 3rem;
  }

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

  .lesson-header,
  .lesson-section {
    padding: 1.15rem 1rem;
  }

  .step-list > li {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

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

  .lesson-pager {
    flex-direction: column;
  }

  .pager-next {
    text-align: left;
    margin-left: 0;
  }
}
