/* ax vs kagent tutorial styles. Layer order: reset, tokens, base, layout, components, diagrams, utilities, print. */
@layer reset, tokens, base, layout, components, diagrams, utilities, print;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body, h1, h2, h3, h4, p, figure, dl, dd, ol, ul, pre, blockquote { margin: 0; }
  img, svg { display: block; max-width: 100%; }
  button, input { font: inherit; color: inherit; }
  table { border-collapse: collapse; }
}

@layer tokens {
  :root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f6;
    --border: #e1e5ec;
    --border-strong: #8a94a6;
    --text: #141a26;
    --text-muted: #556074;
    --chrome-accent: #334155;
    --on-chrome: #ffffff;
    --link: #1d4ed8;
    --ax: #059669;
    --ax-text: #047857;
    --ax-strong: #047857;
    --ax-soft: #e6f6ef;
    --kg: #4338ca;
    --kg-text: #4338ca;
    --kg-strong: #3730a3;
    --kg-soft: #eceafd;
    --sub: #b45309;
    --sub-text: #92400e;
    --sub-strong: #92400e;
    --sub-soft: #fdf3e3;
    --on-strong: #ffffff;
    --info: #0369a1;
    --info-soft: #e8f4fb;
    --caution: #b91c1c;
    --caution-soft: #fdeeee;
    --ok: #15803d;
    --ok-soft: #e9f7ee;
    --code-bg: #f3f5f9;
    --code-inline-bg: #eef1f6;
    --code-border: #dde2ea;
    --syn-key: #6d28d9;
    --syn-string: #047857;
    --syn-number: #b45309;
    --syn-comment: #5f6876;
    --syn-cmd: #1d4ed8;
    --syn-flag: #9a3412;
    --syn-prompt: #5f6876;
    --focus-ring: #2563eb;
    --diagram-line: #556074;
    --shadow-1: 0 1px 2px rgb(16 24 40 / .06);
    --shadow-2: 0 8px 24px rgb(16 24 40 / .08);

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    --fs-xs: .75rem;
    --fs-sm: .875rem;
    --fs-md: 1rem;
    --fs-lg: 1.125rem;
    --fs-xl: 1.375rem;
    --fs-2xl: 1.75rem;
    --fs-3xl: 2.5rem;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px;
    --space-6: 24px; --space-7: 32px; --space-8: 40px; --space-9: 48px; --space-10: 64px;
    --sidebar-w: 260px;
    --topbar-h: 52px;
    --content-pad: clamp(16px, 3vw, 48px);
  }
  :root[data-theme-effective="dark"] {
    color-scheme: dark;
    --bg: #0b0e14;
    --surface: #12161f;
    --surface-2: #1a202b;
    --border: #263040;
    --border-strong: #6b778c;
    --text: #e7eaf1;
    --text-muted: #9aa4b8;
    --chrome-accent: #cbd5e1;
    --on-chrome: #0b0e14;
    --link: #93b4ff;
    --ax: #34d399;
    --ax-text: #34d399;
    --ax-strong: #6ee7b7;
    --ax-soft: #0f2a22;
    --kg: #a5a0ff;
    --kg-text: #a5a0ff;
    --kg-strong: #c4c1ff;
    --kg-soft: #1d1b3d;
    --sub: #fbbf24;
    --sub-text: #fbbf24;
    --sub-strong: #fcd34d;
    --sub-soft: #2d220c;
    --on-strong: #0b0e14;
    --info: #7dd3fc;
    --info-soft: #0c2533;
    --caution: #fca5a5;
    --caution-soft: #2e1414;
    --ok: #86efac;
    --ok-soft: #0d2617;
    --code-bg: #0e121a;
    --code-inline-bg: #1c2230;
    --code-border: #263040;
    --syn-key: #c4b5fd;
    --syn-string: #86efac;
    --syn-number: #fdba74;
    --syn-comment: #8b95a8;
    --syn-cmd: #93c5fd;
    --syn-flag: #fdba74;
    --syn-prompt: #8b95a8;
    --focus-ring: #93b4ff;
    --diagram-line: #9aa4b8;
    --shadow-1: none;
    --shadow-2: 0 8px 24px rgb(0 0 0 / .4);
  }
}

@layer base {
  @media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
  }
  html { scroll-padding-top: var(--space-6); }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--fs-md);
    line-height: 1.65;
    overflow-wrap: break-word;
  }
  h1, h2, h3, h4 { color: var(--text); scroll-margin-top: var(--space-6); }
  h1 { font-size: var(--fs-3xl); line-height: 1.1; font-weight: 750; letter-spacing: -.02em; }
  h2 { font-size: var(--fs-xl); line-height: 1.3; font-weight: 650; margin-bottom: var(--space-4); }
  h3 { font-size: var(--fs-lg); line-height: 1.4; font-weight: 600; margin: var(--space-6) 0 var(--space-3); }
  h4 { font-size: var(--fs-md); font-weight: 600; margin: var(--space-4) 0 var(--space-2); }
  p, ul, ol, dl, pre, .table-wrap, figure, .callout, .compare { margin-bottom: var(--space-4); }
  ul, ol { padding-left: 1.4em; }
  li + li { margin-top: var(--space-1); }
  a { color: var(--link); text-underline-offset: 2px; }
  a:hover { text-decoration-thickness: 2px; }
  strong { font-weight: 650; }
  code, kbd, samp, pre { font-family: var(--font-mono); font-size: .9em; }
  :not(pre) > code {
    background: var(--code-inline-bg);
    border: 1px solid var(--code-border);
    border-radius: var(--radius-sm);
    padding: .05em .35em;
    overflow-wrap: anywhere;
  }
  hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-7) 0; }
  :focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 2px; }
  main:focus, section:focus { outline: none; }
  ::selection { background: color-mix(in srgb, var(--focus-ring) 30%, transparent); }
}

@layer layout {
  .skip-link {
    position: absolute; left: var(--space-3); top: -100px; z-index: 100;
    background: var(--surface); color: var(--text);
    padding: var(--space-2) var(--space-4); border-radius: var(--radius-md);
    outline: 2px solid var(--focus-ring); font-weight: 600; text-decoration: none;
  }
  .skip-link:focus { top: var(--space-3); }

  .layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
  }
  .sidebar {
    position: sticky; top: 0; align-self: start;
    height: 100vh; overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 0 var(--space-4) var(--space-6);
    font-size: var(--fs-sm);
    display: flex; flex-direction: column; gap: var(--space-4);
  }
  main {
    min-width: 0;
    padding: var(--space-8) var(--content-pad) var(--space-10);
  }
  main > section { padding-top: var(--space-6); margin-top: var(--space-6); border-top: 1px solid var(--border); }
  main > section:first-of-type { border-top: 0; margin-top: var(--space-4); }
  /* Full available width: no constrained content column. Only the whole main caps on very wide screens. */
  main { width: 100%; max-width: 1600px; }

  .topbar { display: none; }

  @media (max-width: 979.98px) {
    .layout { grid-template-columns: minmax(0, 1fr); }
    .topbar {
      display: flex; align-items: center; gap: var(--space-3);
      position: sticky; top: 0; z-index: 40;
      height: var(--topbar-h); padding: 0 var(--space-4);
      background: var(--surface); border-bottom: 1px solid var(--border);
    }
    .topbar .brand { font-size: var(--fs-md); }
    .topbar .topbar-current { color: var(--text-muted); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
    .sidebar {
      position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
      width: min(320px, 86vw); height: 100%;
      transform: translateX(-105%); visibility: hidden;
      box-shadow: var(--shadow-2);
    }
    body.nav-open .sidebar { transform: none; visibility: visible; }
    body.nav-open { overflow: hidden; }
    .scrim { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .45); }
    .scrim[hidden] { display: none; }
    html { scroll-padding-top: calc(var(--topbar-h) + var(--space-4)); }
    h1, h2, h3, h4 { scroll-margin-top: calc(var(--topbar-h) + var(--space-4)); }
    main { padding-top: var(--space-6); }
    h1 { font-size: var(--fs-2xl); line-height: 1.2; }
  }
  @media (prefers-reduced-motion: no-preference) {
    .sidebar { transition: transform .2s ease, visibility .2s; }
    /* Visible at once on open so focus can move into the drawer (AU-04); hide only after the slide out. */
    body.nav-open .sidebar { transition: transform .2s ease, visibility 0s; }
  }
}

@layer components {
  /* Brand */
  .brand { display: inline-flex; align-items: baseline; gap: .35em; font-weight: 750; font-size: var(--fs-lg); letter-spacing: -.01em; text-decoration: none; color: var(--text); }
  .brand .b-ax { color: var(--ax-text); }
  .brand .b-kg { color: var(--kg-text); }
  .brand .b-vs { color: var(--text-muted); font-weight: 500; font-size: .85em; }
  .sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
  .sidebar-head .drawer-close { display: none; }
  /* Brand and version pins stay in view while the contents list scrolls (AD-08). */
  .sidebar-top {
    position: sticky; top: 0; z-index: 3;
    display: flex; flex-direction: column; gap: var(--space-3);
    background: var(--surface); padding: var(--space-5) 0 var(--space-3);
    border-bottom: 1px solid var(--border);
  }
  @media (max-width: 979.98px) { .sidebar-head .drawer-close { display: inline-flex; } }

  /* Pills and badges: solid fills use *-strong with --on-strong text (AA in both themes). */
  .pill {
    display: inline-flex; align-items: center; gap: .35em;
    padding: 2px 9px; border-radius: var(--radius-pill);
    font-size: var(--fs-xs); font-weight: 650; line-height: 1.5;
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
    white-space: nowrap;
  }
  .pill.ax { background: var(--ax-strong); border-color: var(--ax-strong); color: var(--on-strong); }
  .pill.kg { background: var(--kg-strong); border-color: var(--kg-strong); color: var(--on-strong); }
  .pill.sub { background: var(--sub-strong); border-color: var(--sub-strong); color: var(--on-strong); }
  .versions { display: flex; flex-direction: column; gap: var(--space-1); }
  .versions .pill { white-space: normal; justify-content: flex-start; }
  .versions .verified { color: var(--text-muted); font-size: var(--fs-xs); margin-top: var(--space-1); }

  /* Sidebar nav */
  .toc { list-style: none; padding: 0; margin: 0; }
  .toc li { margin: 0; }
  .toc a {
    display: flex; align-items: baseline; gap: var(--space-2);
    padding: 5px var(--space-2); border-radius: var(--radius-sm);
    color: var(--text); text-decoration: none; border-left: 3px solid transparent;
  }
  .toc a:hover { background: var(--surface-2); }
  .toc .num {
    flex: 0 0 auto; min-width: 1.9em; text-align: center;
    font-size: var(--fs-xs); font-weight: 700; font-variant-numeric: tabular-nums;
    color: var(--chrome-accent); border: 1px solid var(--border-strong); border-radius: var(--radius-pill); padding: 0 4px;
  }
  .toc .tag { margin-left: auto; font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
  .toc a[aria-current="page"] { background: var(--surface-2); border-left-color: var(--chrome-accent); font-weight: 650; }
  .toc a[aria-current="page"] .num { background: var(--chrome-accent); border-color: var(--chrome-accent); color: var(--on-chrome); }
  .toc .subtoc { list-style: none; margin: 2px 0 var(--space-2) calc(1.9em + var(--space-4)); padding: 0 0 0 var(--space-2); border-left: 1px solid var(--border); }
  .toc .subtoc a { padding: 3px var(--space-2); font-size: var(--fs-xs); color: var(--text-muted); border-left: 0; }
  .toc .subtoc a:hover { color: var(--text); }
  .toc .subtoc a[aria-current="location"] { color: var(--text); font-weight: 650; background: var(--surface-2); }

  /* Progress */
  .progress { display: grid; gap: var(--space-1); }
  .progress-label { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--text-muted); }
  .progress-track { height: 6px; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
  .progress-bar { height: 100%; width: 0; background: var(--chrome-accent); border-radius: inherit; }
  .read-progress { position: fixed; left: 0; top: 0; height: 3px; width: 100%; z-index: 70; background: var(--chrome-accent); transform-origin: 0 50%; transform: scaleX(0); pointer-events: none; }

  /* Theme switch */
  .theme { display: grid; gap: var(--space-2); margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--border); }
  .theme-buttons { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border-strong); border-radius: var(--radius-md); overflow: hidden; }
  .theme-buttons button {
    min-height: 34px; border: 0; background: var(--surface); color: var(--text);
    font-size: var(--fs-xs); font-weight: 600; cursor: pointer;
  }
  .theme-buttons button + button { border-left: 1px solid var(--border-strong); }
  .theme-buttons button:hover { background: var(--surface-2); }
  .theme-buttons button[aria-pressed="true"] { background: var(--chrome-accent); color: var(--on-chrome); }
  .theme-buttons button:focus-visible { outline-offset: -3px; outline-color: var(--focus-ring); }
  .theme-buttons button[aria-pressed="true"]:focus-visible { outline-color: var(--bg); box-shadow: inset 0 0 0 5px var(--focus-ring); }
  .theme-status { font-size: var(--fs-xs); color: var(--text-muted); }

  /* Generic buttons */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1);
    min-height: 32px; padding: 4px 10px; border-radius: var(--radius-md);
    background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
    font-size: var(--fs-xs); font-weight: 600; cursor: pointer; text-decoration: none;
  }
  .btn:hover { background: var(--surface-2); }

  /* Page head */
  .page-head { margin-bottom: var(--space-6); }
  .eyebrow { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: var(--space-2); }
  .page-head h1 { margin-bottom: var(--space-3); }
  .lede { font-size: var(--fs-lg); color: var(--text-muted); line-height: 1.55; }
  .objectives {
    list-style: none; padding: var(--space-4) var(--space-5); margin-top: var(--space-5);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  }
  .objectives::before { content: "You will learn"; display: block; font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: var(--space-2); }
  .objectives-intro { margin-top: var(--space-5); margin-bottom: 0; font-weight: 600; }
  .objectives-intro + .objectives { margin-top: var(--space-2); }
  .objectives-intro + .objectives::before { content: none; }
  .objectives li { padding-left: 1.4em; position: relative; }
  .objectives li::before { content: ""; position: absolute; left: .2em; top: .62em; width: .5em; height: .5em; border-radius: 2px; background: var(--chrome-accent); }

  /* Heading anchors */
  .anchor { margin-left: .35em; color: var(--text-muted); text-decoration: none; font-weight: 400; opacity: 0; }
  h2:hover .anchor, h3:hover .anchor, .anchor:focus-visible { opacity: 1; }
  @media (hover: none) { .anchor { opacity: .6; } }

  /* Callouts */
  .callout {
    --c: var(--chrome-accent); --c-soft: var(--surface-2);
    background: var(--c-soft); border: 1px solid var(--border); border-left: 4px solid var(--c);
    border-radius: var(--radius-md); padding: var(--space-4) var(--space-5);
  }
  .callout > :last-child { margin-bottom: 0; }
  .callout.key { --c: var(--chrome-accent); --c-soft: var(--surface); box-shadow: var(--shadow-1); }
  .callout.note { --c: var(--info); --c-soft: var(--info-soft); }
  .callout.warn { --c: var(--caution); --c-soft: var(--caution-soft); }
  .callout.lab { --c: var(--ax); --c-soft: var(--surface); }
  /* Checkpoint uses the info hue, clear of all three product colours (AD-04). */
  .callout.checkpoint, .checkpoint { --c: var(--info); --c-soft: var(--info-soft); }
  .checkpoint { background: var(--c-soft); border: 1px solid var(--border); border-left: 4px solid var(--c); border-radius: var(--radius-md); padding: var(--space-4) var(--space-5); margin-bottom: var(--space-4); }
  .checkpoint::before { content: "\2713\00a0 Checkpoint"; display: block; font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text); margin-bottom: var(--space-1); }
  .checkpoint > :last-child { margin-bottom: 0; }
  .checkpoint details summary { cursor: pointer; font-weight: 600; }

  /* Compare grid and cards */
  .compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
  @media (max-width: 719.98px) { .compare { grid-template-columns: minmax(0, 1fr); } }
  .card {
    background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--border-strong);
    border-radius: var(--radius-md); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-1); min-width: 0;
  }
  .card > :last-child { margin-bottom: 0; }
  .card h3 { margin-top: 0; }
  .card.ax { border-top-color: var(--ax); background: linear-gradient(var(--ax-soft), var(--surface) 120px); }
  .card.kg { border-top-color: var(--kg); background: linear-gradient(var(--kg-soft), var(--surface) 120px); }
  .card.sub { border-top-color: var(--sub); background: linear-gradient(var(--sub-soft), var(--surface) 120px); }

  /* Tables */
  .table-wrap {
    overflow-x: auto; max-width: 100%;
    border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface);
  }
  .table-wrap:focus-visible { outline-offset: 2px; }
  table { width: 100%; font-size: var(--fs-sm); line-height: 1.5; }
  caption { caption-side: top; text-align: left; padding: var(--space-3) var(--space-4); font-weight: 650; color: var(--text); border-bottom: 1px solid var(--border); }
  th, td { text-align: left; vertical-align: top; padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border); }
  thead th { background: var(--surface-2); font-weight: 650; white-space: nowrap; }
  tbody th[scope="row"] { font-weight: 600; background: var(--surface); }
  tbody tr:last-child > * { border-bottom: 0; }
  tbody tr:hover > * { background: var(--surface-2); }
  th.ax, td.ax { box-shadow: inset 3px 0 0 var(--ax); }
  th.kg, td.kg { box-shadow: inset 3px 0 0 var(--kg); }
  th.sub, td.sub { box-shadow: inset 3px 0 0 var(--sub); }
  thead th.ax { color: var(--ax-text); }
  thead th.kg { color: var(--kg-text); }
  thead th.sub { color: var(--sub-text); }
  @media (min-width: 720px) { .table-wrap tbody th[scope="row"]:first-child { position: sticky; left: 0; z-index: 1; } }

  /* Code blocks */
  pre {
    position: relative;
    background: var(--code-bg); color: var(--text);
    border: 1px solid var(--code-border); border-radius: var(--radius-md);
    padding: var(--space-4); padding-top: calc(var(--space-4) + 22px);
    overflow-x: auto; line-height: 1.55; font-size: var(--fs-sm); tab-size: 2;
  }
  pre code { font-size: inherit; background: none; border: 0; padding: 0; }
  pre[data-lang]::before, pre[data-label]::before {
    content: attr(data-lang); position: absolute; left: var(--space-4); top: 8px;
    max-width: calc(100% - 7rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-family: var(--font-sans); font-size: var(--fs-xs); font-weight: 650; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .06em;
  }
  /* app.js writes data-label as "YAML · task.yaml"; the language part is already upper case. */
  pre[data-label]::before { content: attr(data-label); text-transform: none; }
  .code-wrap { position: relative; margin-bottom: var(--space-4); }
  .code-wrap > pre { margin-bottom: 0; }
  /* Right-edge fade: this block scrolls sideways (AD-09). */
  .code-wrap.is-scrollable:not(.at-end)::after {
    content: ""; position: absolute; top: 1px; right: 1px; bottom: 1px; width: 32px; pointer-events: none;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    background: linear-gradient(to right, transparent, var(--code-bg));
  }
  .expected .code-wrap.is-scrollable:not(.at-end)::after { background: linear-gradient(to right, transparent, var(--surface)); }
  .copy-btn { position: absolute; top: 6px; right: 6px; z-index: 2; min-height: 28px; padding: 2px 10px; }
  .copy-btn.copied { background: var(--info-soft); border-color: var(--info); color: var(--text); }
  .copy-btn.failed { background: var(--caution-soft); border-color: var(--caution); }
  .tok-key { color: var(--syn-key); }
  .tok-str { color: var(--syn-string); }
  .tok-num { color: var(--syn-number); }
  .tok-com { color: var(--syn-comment); font-style: italic; }
  .tok-cmd { color: var(--syn-cmd); font-weight: 600; }
  .tok-flag { color: var(--syn-flag); }
  .tok-prompt { color: var(--syn-prompt); user-select: none; }
  .tok-punct { color: var(--text-muted); }
  .tok-var { color: var(--syn-number); }

  /* Steps and expected output */
  ol.steps { list-style: none; counter-reset: step; padding-left: 0; }
  ol.steps > li { counter-increment: step; position: relative; padding-left: 2.75rem; margin-top: var(--space-5); }
  ol.steps > li::before {
    content: counter(step); position: absolute; left: 0; top: 0;
    width: 1.9rem; height: 1.9rem; display: grid; place-items: center;
    border-radius: 50%; background: var(--chrome-accent); color: var(--on-chrome);
    font-size: var(--fs-sm); font-weight: 700;
  }
  ol.steps > li > :last-child { margin-bottom: 0; }
  /* Expected output is a neutral panel, not a product hue (AD-04). */
  .expected { border: 1px solid var(--border); border-left: 4px solid var(--border-strong); background: var(--surface-2); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); }
  .expected::before { content: "> Expected output"; display: block; font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: var(--space-2); }
  .expected pre { margin-bottom: 0; background: var(--surface); }
  .expected > :last-child { margin-bottom: 0; }

  /* Glossary */
  dl.glossary { display: grid; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
  dl.glossary dt { font-weight: 650; padding: var(--space-3) var(--space-4) 0; scroll-margin-top: var(--space-6); }
  dl.glossary dd { padding: var(--space-1) var(--space-4) var(--space-3); margin: 0; border-bottom: 1px solid var(--border); }
  dl.glossary dd:last-child { border-bottom: 0; }
  dl.glossary dt:target { background: var(--surface-2); }

  /* Citations */
  .cite { font-size: .72em; line-height: 0; vertical-align: super; margin-left: 1px; }
  .cite a { text-decoration: none; font-weight: 650; padding: 0 1px; }
  .cite a:hover { text-decoration: underline; }

  /* Pager */
  .pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); margin-top: var(--space-9); padding-top: var(--space-6); border-top: 1px solid var(--border); }
  .pager a {
    display: grid; gap: 2px; padding: var(--space-4) var(--space-5);
    border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface);
    color: var(--text); text-decoration: none; min-width: 0;
  }
  .pager a:hover { background: var(--surface-2); }
  .pager .dir { font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
  .pager .target { font-weight: 650; color: var(--link); }
  .pager .next { grid-column: 2; text-align: right; }
  @media (max-width: 539.98px) { .pager { grid-template-columns: minmax(0, 1fr); } .pager .next { grid-column: 1; } }

  /* Back to top */
  .to-top { position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 30; box-shadow: var(--shadow-2); min-height: 40px; padding: 6px 14px; display: inline-flex; align-items: center; gap: var(--space-2); transition: opacity .15s; }
  .to-top[hidden] { display: none; }
  /* Fades out while it sits over a code block, diagram, table or callout (AD-07). */
  .to-top.is-covering { opacity: 0; pointer-events: none; }
  @media (max-width: 979.98px) {
    .to-top { width: 40px; height: 40px; min-height: 40px; padding: 0; justify-content: center; border-radius: 50%; }
    .to-top .to-top-label { display: none; }
  }

  /* Footer */
  .site-foot { margin-top: var(--space-7); font-size: var(--fs-xs); color: var(--text-muted); }
}

@layer diagrams {
  figure.diagram {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: var(--space-4); margin: var(--space-5) 0; box-shadow: var(--shadow-1); min-width: 0;
  }
  .diagram-scroll { overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: var(--space-1); }
  .diagram-scroll:focus-visible { outline-offset: 2px; }
  .diagram-scroll > svg { width: 100%; height: auto; max-width: 1100px; margin-inline: auto; font-family: var(--font-sans); }
  .diagram-hint { display: none; font-size: var(--fs-xs); color: var(--text-muted); margin: var(--space-1) 0 0; }
  .diagram.is-scrollable .diagram-hint { display: block; }
  figure.diagram figcaption { margin-top: var(--space-3); font-size: var(--fs-sm); color: var(--text-muted); }
  figure.diagram figcaption strong { color: var(--text); }
  .diagram-legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); list-style: none; padding: 0; margin: var(--space-3) 0 0; font-size: var(--fs-xs); color: var(--text-muted); }
  .diagram-legend li { display: inline-flex; align-items: center; gap: var(--space-2); margin: 0; }
  .diagram-legend .sw { width: 14px; height: 14px; border-radius: 3px; border: 2px solid var(--border-strong); background: var(--surface-2); }
  .diagram-legend .sw.ax { border-color: var(--ax); background: var(--ax-soft); }
  .diagram-legend .sw.kg { border-color: var(--kg); background: var(--kg-soft); }
  .diagram-legend .sw.sub { border-color: var(--sub); background: var(--sub-soft); }
  .diagram-legend .sw.dashed { border-style: dashed; background: transparent; border-color: var(--text-muted); }
  .diagram-legend .sw.dashed.ax { border-color: var(--ax); }
  .diagram-legend .sw.dashed.kg { border-color: var(--kg); }
  .diagram-legend .sw + .sw { margin-left: calc(-1 * var(--space-1)); }
  .diagram-legend .ln { width: 22px; height: 0; border-top: 2px solid var(--diagram-line); }
  .diagram-legend .ln.dashed { border-top-style: dashed; }
  .diagram-missing { color: var(--text-muted); font-size: var(--fs-sm); }

  /* SVG classes used by diagrams.js */
  .axkg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
  .mk-muted { fill: var(--diagram-line); }
  .mk-ax { fill: var(--ax); }
  .mk-kg { fill: var(--kg); }
  .mk-sub { fill: var(--sub); }
  svg .n-ax, svg .n-kg, svg .n-sub, svg .n-neutral { stroke-width: 2; }
  svg .n-ax { fill: var(--ax-soft); stroke: var(--ax); }
  svg .n-kg { fill: var(--kg-soft); stroke: var(--kg); }
  svg .n-sub { fill: var(--sub-soft); stroke: var(--sub); }
  svg .n-neutral { fill: var(--surface-2); stroke: var(--diagram-line); }
  svg .n-dashed { fill: none; stroke: var(--text-muted); stroke-dasharray: 6 4; stroke-width: 1.5; }
  svg .n-ax.n-dashed, svg .n-kg.n-dashed, svg .n-sub.n-dashed { fill: none; }
  svg .n-ax.n-dashed { stroke: var(--ax); }
  svg .n-kg.n-dashed { stroke: var(--kg); }
  svg .n-sub.n-dashed { stroke: var(--sub); }
  svg .band { fill: var(--surface-2); stroke: var(--border); stroke-width: 1; }
  svg text { fill: var(--text); font-family: var(--font-sans); }
  svg .t-title { font-size: 15px; font-weight: 700; fill: var(--text); }
  svg .t-body { font-size: 13px; fill: var(--text); }
  svg .t-cap { font-size: 12px; fill: var(--text-muted); }
  svg .t-tag { font-size: 12px; font-weight: 700; letter-spacing: .04em; fill: var(--text-muted); text-transform: uppercase; }
  svg .t-ax { fill: var(--ax-text); }
  svg .t-kg { fill: var(--kg-text); }
  svg .t-sub { fill: var(--sub-text); }
  svg .t-mono { font-family: var(--font-mono); }
  svg .arrow { fill: none; stroke: var(--diagram-line); stroke-width: 1.75; }
  svg .arrow.dashed { stroke-dasharray: 6 4; }
  svg .arrow.ax { stroke: var(--ax); }
  svg .arrow.kg { stroke: var(--kg); }
  svg .arrow.sub { stroke: var(--sub); }
  svg .lifeline { stroke: var(--border-strong); stroke-width: 1.25; stroke-dasharray: 4 4; fill: none; }
  svg .chip { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1; }
  svg .chip.muted { fill: var(--surface-2); stroke: var(--border); }
}

@layer utilities {
  .sr-only, .visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .muted { color: var(--text-muted); }
  .ax-text { color: var(--ax-text); }
  .kg-text { color: var(--kg-text); }
  .sub-text { color: var(--sub-text); }
  .full { max-width: none !important; }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition: none !important; animation: none !important; }
  }
}

@layer print {
  @media print {
    :root, :root[data-theme-effective="dark"] {
      color-scheme: light;
      --bg: #ffffff; --surface: #ffffff; --surface-2: #f3f4f6; --border: #cfd4dc; --border-strong: #6b7280;
      --text: #000000; --text-muted: #374151; --chrome-accent: #111827; --on-chrome: #ffffff; --link: #1d4ed8;
      --ax: #047857; --ax-text: #047857; --ax-strong: #047857; --ax-soft: #eef8f3;
      --kg: #3730a3; --kg-text: #3730a3; --kg-strong: #3730a3; --kg-soft: #f1f0fd;
      --sub: #92400e; --sub-text: #92400e; --sub-strong: #92400e; --sub-soft: #fdf6ea;
      --on-strong: #ffffff; --code-bg: #f6f7f9; --code-inline-bg: #f1f3f6; --code-border: #d5dae2;
      --syn-key: #5b21b6; --syn-string: #065f46; --syn-number: #92400e; --syn-comment: #4b5563; --syn-cmd: #1e3a8a;
      --diagram-line: #374151; --shadow-1: none; --shadow-2: none;
    }
    body { font-size: 11pt; }
    .layout { display: block; }
    .sidebar, .topbar, .scrim, .pager, .to-top, .copy-btn, .skip-link, .read-progress, .anchor, .diagram-hint { display: none !important; }
    main { padding: 0; }
    pre { white-space: pre-wrap; overflow: visible; }
    .table-wrap, .diagram-scroll { overflow: visible; }
    .diagram-scroll > svg { min-width: 0 !important; }
    pre, figure, table, .callout, .card, .checkpoint, .expected { break-inside: avoid; }
    h2, h3 { break-after: avoid; }
    main a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .85em; color: var(--text-muted); overflow-wrap: anywhere; }
    .cite a::after { content: none !important; }
  }
}
