/* ═══════════════════════════════════════════════════════════════════════════
   GPU Learning Course - Design System (Simplified)
   Modern CSS: @layer, nesting, color-mix(), :has()
   ═══════════════════════════════════════════════════════════════════════════ */

@layer reset, base, components, utilities;

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER: Reset
   ═══════════════════════════════════════════════════════════════════════════ */
@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER: Base
   ═══════════════════════════════════════════════════════════════════════════ */
@layer base {
  :root {
    /* Backgrounds */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a24;
    --bg-card: #16161f;

    /* Text - WCAG AA verified */
    --text-primary: #e8e6e3;
    --text-secondary: #a8a8a8;
    --text-muted: #8a8a8a;

    /* Accents */
    --accent-blue: #4d9fff;
    --accent-green: #34d399;
    --accent-purple: #a78bfa;
    --accent-orange: #fb923c;
    --accent-cyan: #22d3ee;
    --accent-red: #f87171;

    /* Glows (15% accent on transparent) */
    --glow-blue: color-mix(in srgb, var(--accent-blue) 15%, transparent);
    --glow-green: color-mix(in srgb, var(--accent-green) 15%, transparent);
    --glow-purple: color-mix(in srgb, var(--accent-purple) 15%, transparent);
    --glow-orange: color-mix(in srgb, var(--accent-orange) 15%, transparent);
    --glow-cyan: color-mix(in srgb, var(--accent-cyan) 15%, transparent);

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-active: rgba(77, 159, 255, 0.4);

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Typography - Font Families */
    --font-serif: 'Source Serif 4', Georgia, serif;
    --font-mono: 'IBM Plex Mono', monospace;

    /* Typography - Size Scale (min readable: 0.8rem = 13px) */
    --text-xs: 0.8rem;      /* 13px - labels, badges, fine print */
    --text-sm: 0.875rem;    /* 14px - secondary text, captions */
    --text-base: 1rem;      /* 16px - UI text, buttons */
    --text-body: 1.125rem;  /* 18px - body prose */
    --text-lg: 1.25rem;     /* 20px - emphasis, h4 */
    --text-xl: 1.5rem;      /* 24px - h3, section titles */
    --text-2xl: 1.75rem;    /* 28px - h2 */
    --text-3xl: 2.25rem;    /* 36px - h1 */
    --text-4xl: 3rem;       /* 48px - hero display */

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
  }

  /* Focus styles (WCAG 2.4.7) */
  :focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
  }

  :focus:not(:focus-visible) {
    outline: none;
  }

  /* Skip link */
  .skip-link {
    position: absolute;
    top: -100px;
    left: var(--space-md);
    background: var(--accent-blue);
    color: var(--bg-primary);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    z-index: 9999;
    transition: top var(--transition-fast);

    &:focus {
      top: var(--space-md);
    }
  }

  body {
    font-family: var(--font-serif);
    font-size: var(--text-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
  }

  /* Typography */
  h1, h2, h3, h4, h5 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
  }

  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); margin-bottom: 1rem; }
  h3 { font-size: var(--text-lg); margin: 2rem 0 1rem; }
  h4 { font-size: var(--text-base); margin-bottom: 0.5rem; }

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

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

  a {
    color: var(--accent-blue);
    text-decoration: none;
    transition: color var(--transition-fast);

    &:hover {
      color: var(--accent-purple);
    }
  }

  code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--bg-tertiary);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-sm);
  }

  pre {
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;

    code {
      background: none;
      padding: 0;
      font-size: var(--text-sm);
      line-height: 1.6;
    }
  }

  ul, ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
    color: var(--text-secondary);
  }

  li {
    margin-bottom: 0.5rem;
  }

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

  th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
  }

  th {
    background: var(--bg-tertiary);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  td {
    color: var(--text-secondary);
  }

  tr:hover td {
    background: var(--bg-tertiary);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER: Components
   ═══════════════════════════════════════════════════════════════════════════ */
@layer components {

  /* ─────────────────────────────────────────────────────────────────────────
     Button
     ───────────────────────────────────────────────────────────────────────── */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.6rem 1.2rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all var(--transition-fast);

    &:hover {
      background: var(--bg-secondary);
      border-color: var(--accent-blue);
    }

    &--primary {
      background: var(--accent-blue);
      border-color: var(--accent-blue);
      color: var(--bg-primary);

      &:hover {
        background: color-mix(in srgb, var(--accent-blue) 85%, white);
      }
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Card
     ───────────────────────────────────────────────────────────────────────── */
  .card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    margin: var(--space-lg) 0;
    transition: all var(--transition-normal);

    &:hover {
      border-color: var(--border-active);
    }

    &__header {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      margin-bottom: var(--space-lg);
    }

    &__icon {
      width: 32px;
      height: 32px;
      border-radius: var(--radius-md);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: var(--text-base);

      &--blue { background: color-mix(in srgb, var(--accent-blue) 15%, transparent); }
      &--green { background: color-mix(in srgb, var(--accent-green) 15%, transparent); }
      &--purple { background: color-mix(in srgb, var(--accent-purple) 15%, transparent); }
      &--orange { background: color-mix(in srgb, var(--accent-orange) 15%, transparent); }
    }

    &__title {
      font-family: var(--font-mono);
      font-size: var(--text-sm);
      font-weight: 500;
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Callout
     ───────────────────────────────────────────────────────────────────────── */
  .callout {
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin: var(--space-lg) 0;
    border-left: 4px solid;

    &-title, &__title {
      font-family: var(--font-mono);
      font-size: var(--text-sm);
      font-weight: 600;
      margin-bottom: 0.5rem;
    }

    /* Variants - support both .callout.info and .callout--info */
    &.info, &--info {
      background: color-mix(in srgb, var(--accent-blue) 15%, transparent);
      border-color: var(--accent-blue);

      .callout-title, .callout__title { color: var(--accent-blue); }
    }

    &.warn, &--warn {
      background: color-mix(in srgb, var(--accent-orange) 15%, transparent);
      border-color: var(--accent-orange);

      .callout-title, .callout__title { color: var(--accent-orange); }
    }

    &.ok, &--ok {
      background: color-mix(in srgb, var(--accent-green) 15%, transparent);
      border-color: var(--accent-green);

      .callout-title, .callout__title { color: var(--accent-green); }
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Quiz (unified system)
     ───────────────────────────────────────────────────────────────────────── */
  .quiz {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    margin: var(--space-lg) 0;
  }

  .quiz-q {
    font-size: var(--text-body);
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
  }

  .quiz-opts {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
  }

  .quiz-opt {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-secondary);

    &:hover {
      border-color: var(--border-active);
    }

    &.picked .quiz-mark {
      border-width: 6px;
    }

    &.correct {
      border-color: var(--accent-green);
      background: color-mix(in srgb, var(--accent-green) 15%, transparent);

      .quiz-mark {
        border-color: var(--accent-green);
        background: var(--accent-green);
      }
    }

    &.wrong {
      border-color: var(--accent-red);
      background: color-mix(in srgb, var(--accent-red) 10%, transparent);

      .quiz-mark {
        border-color: var(--accent-red);
        background: var(--accent-red);
      }
    }
  }

  .quiz-mark {
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-muted);
    border-radius: 50%;
    flex-shrink: 0;
    transition: all var(--transition-fast);
  }

  .quiz-fb {
    display: none;
    margin-top: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: var(--text-sm);

    &.show { display: block; }
    &.ok { background: color-mix(in srgb, var(--accent-green) 15%, transparent); color: var(--accent-green); }
    &.no { background: color-mix(in srgb, var(--accent-red) 10%, transparent); color: var(--accent-red); }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Section
     ───────────────────────────────────────────────────────────────────────── */
  .section {
    margin-bottom: var(--space-3xl);

    &__number {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      color: var(--accent-purple);
      letter-spacing: 0.1em;
      margin-bottom: var(--space-sm);
    }

    &__title {
      font-size: var(--text-xl);
      margin-bottom: var(--space-lg);
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Chapter Navigation
     ───────────────────────────────────────────────────────────────────────── */
  .chapter-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(10, 10, 15, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 100;
    padding: var(--space-md) var(--space-xl);

    &__inner {
      max-width: 800px;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    &__home {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      color: var(--text-muted);
      letter-spacing: 0.05em;
      transition: color var(--transition-fast);

      &:hover { color: var(--accent-blue); }
    }

    &__progress {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      color: var(--text-muted);
      letter-spacing: 0.05em;

      span {
        color: var(--accent-blue);
        font-weight: 600;
      }
    }
  }

  .chapter-container {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--space-2xl) var(--space-xl) var(--space-3xl);
  }

  .chapter-header {
    margin-bottom: var(--space-2xl);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);

    &__label {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      color: var(--accent-purple);
      letter-spacing: 0.15em;
      text-transform: uppercase;
      margin-bottom: var(--space-sm);
    }

    &__title {
      font-size: var(--text-3xl);
      font-weight: 600;
      margin-bottom: var(--space-md);
    }

    &__desc {
      font-size: var(--text-body);
      color: var(--text-secondary);
      line-height: 1.7;
      max-width: 650px;
    }
  }

  .chapter-footer {
    margin-top: var(--space-3xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--border-subtle);

    &__flow {
      text-align: center;
      margin-bottom: var(--space-xl);
    }

    &__flow-text {
      font-size: var(--text-base);
      color: var(--text-secondary);
      max-width: 500px;
      margin: 0 auto var(--space-lg);
    }

    &__nav {
      display: flex;
      justify-content: space-between;
      gap: var(--space-md);
    }

    &__link {
      flex: 1;
      max-width: 45%;
      padding: var(--space-lg);
      background: var(--bg-card);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-lg);
      transition: all var(--transition-fast);

      &:hover {
        border-color: var(--accent-blue);
        transform: translateY(-2px);
      }

      &--prev { text-align: left; }
      &--next { text-align: right; margin-left: auto; }
    }

    &__link-label {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      color: var(--text-muted);
      letter-spacing: 0.1em;
      text-transform: uppercase;
      margin-bottom: var(--space-xs);
    }

    &__link-title {
      font-size: var(--text-base);
      font-weight: 600;
      color: var(--text-primary);
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Notebook Link
     ───────────────────────────────────────────────────────────────────────── */
  .notebook-link {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
    margin: var(--space-lg) 0;
    transition: all var(--transition-fast);

    &:hover {
      border-color: var(--accent-green);
      background: color-mix(in srgb, var(--accent-green) 15%, transparent);
    }

    &__icon {
      font-size: var(--text-xl);
      flex-shrink: 0;
    }

    &__content {
      flex: 1;
    }

    &__title {
      font-family: var(--font-mono);
      font-size: var(--text-sm);
      font-weight: 600;
      color: var(--text-primary);
      margin-bottom: var(--space-xs);
    }

    &__desc {
      font-size: var(--text-sm);
      color: var(--text-muted);
      margin: 0;
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Form Elements
     ───────────────────────────────────────────────────────────────────────── */
  .input {
    padding: var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    text-align: center;
    width: 60px;
    transition: all var(--transition-fast);

    &:focus {
      outline: none;
      border-color: var(--accent-blue);
      box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-blue) 15%, transparent);
    }
  }

  select {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all var(--transition-fast);

    &:hover { border-color: var(--border-active); }

    &:focus-visible {
      outline: none;
      border-color: var(--accent-blue);
      box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-blue) 15%, transparent);
    }
  }

  input[type="range"] {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    appearance: none;
    cursor: pointer;

    &::-webkit-slider-thumb {
      appearance: none;
      width: 20px;
      height: 20px;
      background: var(--accent-blue);
      border-radius: 50%;
      cursor: pointer;
    }

    &:focus-visible::-webkit-slider-thumb {
      box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-blue) 15%, transparent);
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Prereq Callout (used across chapters)
     ───────────────────────────────────────────────────────────────────────── */
  .prereq-callout {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
    margin-bottom: var(--space-xl);

    &__icon { font-size: var(--text-lg); }

    &__title {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      font-weight: 600;
      color: var(--text-muted);
      margin-bottom: var(--space-xs);
    }

    &__text {
      font-size: var(--text-sm);
      color: var(--text-secondary);
      margin: 0;

      a { margin: 0 var(--space-xs); }
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Diagram Container
     ───────────────────────────────────────────────────────────────────────── */
  .diagram {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    margin: var(--space-lg) 0;
  }

  .diagram-title {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-md);
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Equation
     ───────────────────────────────────────────────────────────────────────── */
  .equation {
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    text-align: center;
    margin: var(--space-lg) 0;
    font-family: var(--font-mono);
    font-size: var(--text-body);
    color: var(--text-primary);

    &__highlight {
      color: var(--accent-blue);
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Canvas
     ───────────────────────────────────────────────────────────────────────── */
  .canvas {
    width: 100%;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Learning Objectives (extends callout pattern)
     ───────────────────────────────────────────────────────────────────────── */
  .learning-objectives {
    background: color-mix(in srgb, var(--accent-purple) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent-purple) 30%, transparent);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);

    &__title {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      font-weight: 600;
      color: var(--accent-purple);
      text-transform: uppercase;
      letter-spacing: 0.1em;
      margin-bottom: var(--space-md);
    }

    &__list {
      list-style: none;
      padding: 0;
      margin: 0;
      counter-reset: objective;
    }

    &__item {
      display: flex;
      align-items: baseline;
      gap: var(--space-sm);
      margin-bottom: var(--space-sm);
      font-size: var(--text-sm);
      color: var(--text-secondary);
      counter-increment: objective;

      &::before {
        content: counter(objective);
        font-family: var(--font-mono);
        font-size: var(--text-xs);
        font-weight: 600;
        color: var(--accent-purple);
        background: color-mix(in srgb, var(--accent-purple) 20%, transparent);
        width: 1.5em;
        height: 1.5em;
        border-radius: 50%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
      }

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

  /* ─────────────────────────────────────────────────────────────────────────
     Chapter Connection (extends callout pattern)
     ───────────────────────────────────────────────────────────────────────── */
  .chapter-connection {
    background: color-mix(in srgb, var(--accent-cyan) 10%, transparent);
    border-left: 4px solid var(--accent-cyan);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    margin-bottom: var(--space-xl);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.6;

    &__label {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      font-weight: 600;
      color: var(--accent-cyan);
      margin-bottom: var(--space-xs);
    }

    strong { color: var(--text-primary); }
    em { color: var(--accent-cyan); font-style: normal; }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Micro Quiz (lightweight modifier for .quiz)
     ───────────────────────────────────────────────────────────────────────── */
  .quiz--micro {
    padding: var(--space-md);
    margin: var(--space-md) 0;
    background: var(--bg-tertiary);

    .quiz-q {
      font-size: var(--text-sm);
      margin-bottom: var(--space-sm);
    }

    .quiz-opt {
      padding: var(--space-sm) var(--space-md);
      font-size: var(--text-sm);
    }

    .quiz-mark {
      width: 16px;
      height: 16px;
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Chunk Divider
     ───────────────────────────────────────────────────────────────────────── */
  .chunk-divider {
    border: none;
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent,
      var(--border-subtle) 20%,
      var(--border-subtle) 80%,
      transparent
    );
    margin: var(--space-2xl) 0;
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Expert Note (collapsible details)
     ───────────────────────────────────────────────────────────────────────── */
  .expert-note {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin: var(--space-md) 0;
    font-size: var(--text-sm);

    &__summary {
      display: flex;
      align-items: center;
      gap: var(--space-sm);
      padding: var(--space-sm) var(--space-md);
      cursor: pointer;
      color: var(--text-muted);
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      transition: color var(--transition-fast);
      list-style: none;

      &::-webkit-details-marker { display: none; }
      &::before {
        content: '+';
        font-weight: bold;
        color: var(--accent-orange);
      }
      &:hover { color: var(--text-secondary); }
    }

    &[open] &__summary::before { content: '−'; }

    &__content {
      padding: 0 var(--space-md) var(--space-md);
      color: var(--text-secondary);
      line-height: 1.6;
      border-top: 1px solid var(--border-subtle);
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Human Scale (inline comparison)
     ───────────────────────────────────────────────────────────────────────── */
  .human-scale {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    background: color-mix(in srgb, var(--accent-green) 15%, transparent);
    padding: 0.1em 0.5em;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    color: var(--accent-green);
    font-family: var(--font-mono);
    white-space: nowrap;

    &::before {
      content: '≈';
      opacity: 0.7;
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Section Progress
     ───────────────────────────────────────────────────────────────────────── */
  .section-progress {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);

    &__bar {
      flex: 1;
      height: 4px;
      background: var(--bg-tertiary);
      border-radius: 2px;
      overflow: hidden;
    }

    &__fill {
      height: 100%;
      background: var(--accent-blue);
      border-radius: 2px;
      transition: width var(--transition-normal);
    }

    &__text {
      font-family: var(--font-mono);
      font-size: var(--text-xs);
      color: var(--text-muted);
      white-space: nowrap;
    }
  }

  /* ─────────────────────────────────────────────────────────────────────────
     Collapsible (generic toggle pattern)
     ───────────────────────────────────────────────────────────────────────── */
  .collapsible {
    &__trigger {
      display: flex;
      align-items: center;
      justify-content: space-between;
      cursor: pointer;
      user-select: none;

      &::after {
        content: '+';
        font-family: var(--font-mono);
        font-weight: bold;
        color: var(--text-muted);
        transition: transform var(--transition-fast);
      }
    }

    &__content {
      display: grid;
      grid-template-rows: 0fr;
      transition: grid-template-rows var(--transition-normal);

      > * {
        overflow: hidden;
      }
    }

    &--open {
      .collapsible__trigger::after {
        content: '−';
      }
      .collapsible__content {
        grid-template-rows: 1fr;
      }
    }
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER: Utilities
   ═══════════════════════════════════════════════════════════════════════════ */
@layer utilities {
  /* Text colors */
  .text-blue { color: var(--accent-blue); }
  .text-green { color: var(--accent-green); }
  .text-purple { color: var(--accent-purple); }
  .text-orange { color: var(--accent-orange); }
  .text-cyan { color: var(--accent-cyan); }
  .text-red { color: var(--accent-red); }
  .text-muted { color: var(--text-muted); }
  .text-secondary { color: var(--text-secondary); }
  .text-small { font-size: var(--text-sm); }

  /* Background colors */
  .bg-blue { background: var(--accent-blue); color: var(--bg-primary); }
  .bg-green { background: var(--accent-green); color: var(--bg-primary); }
  .bg-purple { background: var(--accent-purple); color: var(--bg-primary); }
  .bg-orange { background: var(--accent-orange); color: var(--bg-primary); }

  /* Spacing */
  .mb-0 { margin-bottom: 0 !important; }
  .mt-lg { margin-top: var(--space-lg); }
  .mt-md { margin-top: var(--space-md); }

  /* Flex */
  .flex { display: flex; }
  .flex-wrap { flex-wrap: wrap; }
  .gap-sm { gap: var(--space-sm); }
  .gap-md { gap: var(--space-md); }
  .gap-lg { gap: var(--space-lg); }

  /* Grid */
  .grid { display: grid; gap: 1rem; margin: var(--space-lg) 0; }
  .grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
  .grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

  /* Table wrapper */
  .table-wrap { overflow-x: auto; margin: var(--space-lg) 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .chapter-nav {
    padding: var(--space-sm) var(--space-md);
  }

  .chapter-container {
    padding: var(--space-xl) var(--space-md) var(--space-2xl);
  }

  .chapter-header__title {
    font-size: var(--text-2xl);
  }

  .chapter-footer__nav {
    flex-direction: column;
  }

  .chapter-footer__link {
    max-width: 100%;
    text-align: center;
  }

  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
}
