/* ============================================================
   joshuacscott.com — Design Token System + Styles
   Academic print aesthetic + Japanese principles (ma, kanso, shibui)
   ============================================================ */

/* --- Self-hosted fonts (no Google Fonts dependency) ---
   Variable woff2 files cover the full weight range (400-600) per style.
   font-display: swap shows the fallback first; metric-overridden fallback
   aliases below match the webfont's vertical rhythm to minimize CLS. */

@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/fonts/source-serif-4.woff2') format('woff2');
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: italic;
  font-weight: 400 600;
  font-display: swap;
  src: url('/fonts/source-serif-4-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('/fonts/inter.woff2') format('woff2');
}

/* Metric-overridden fallback aliases — Georgia (for serif) and Arial (for
   UI sans) re-described to match the webfont's vertical metrics. While the
   webfont is loading, the browser uses these aliases, so when the webfont
   arrives, the swap doesn't reflow text. */
@font-face {
  font-family: 'Source Serif 4 Fallback';
  src: local('Georgia');
  size-adjust: 102%;
  ascent-override: 92.5%;
  descent-override: 27%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'Inter Fallback';
  src: local('Arial');
  size-adjust: 107%;
  ascent-override: 96.8%;
  descent-override: 24.4%;
  line-gap-override: 0%;
}

/* --- Design Tokens --- */

:root {
  /* Colors — warm stone/parchment palette */
  --color-bg: #F7F5F0;
  --color-surface: #FFFFFF;
  --color-text: #1C1917;
  --color-text-muted: #57534E;
  --color-accent: #2D3A6E;
  --color-accent-hover: #1E2A54;
  --color-rule: #D6D3D1;
  --color-rule-light: #E7E5E4;
  --color-footnote-bg: #F0EDE8;
  --color-accent-wash: rgba(45, 58, 110, 0.12);
  --color-accent-wash-hover: rgba(45, 58, 110, 0.22);
  --color-shadow: rgba(0, 0, 0, 0.08);

  /* Typography — fallback aliases ('Source Serif 4 Fallback', 'Inter Fallback')
     have metric overrides that match the webfont's metrics; this prevents
     CLS on font-load swap. */
  --font-body: "Source Serif 4", "Source Serif 4 Fallback", Georgia, "Times New Roman", serif;
  --font-heading: "Source Serif 4", "Source Serif 4 Fallback", Georgia, "Times New Roman", serif;
  --font-mono: "Source Code Pro", Menlo, Consolas, monospace;
  --font-ui: "Inter", "Inter Fallback", "Helvetica Neue", Arial, sans-serif;

  /* Type scale (1.25 — major third) */
  --text-sm: 0.8rem;
  --text-base: 1rem;
  --text-md: 1.125rem;
  --text-lg: 1.25rem;
  --text-xl: 1.563rem;
  --text-2xl: 1.953rem;
  --text-3xl: 2.441rem;

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


/* --- Reset & Base --- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  overflow-y: scroll;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Layout --- */

.site-content {
  max-width: 75ch;
  margin-inline: auto;
  padding-inline: clamp(1rem, 5vw, 3rem);
  padding-block: var(--space-2xl);
}

.nowrap {
  white-space: nowrap;
}

main {
  flex: 1;
  padding-block: var(--space-3xl);
}


/* --- Skip to Content --- */

.skip-to-content {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-accent);
  color: var(--color-bg);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  text-decoration: none;
  z-index: 100;
  border-radius: 0 0 4px 4px;
}

.skip-to-content:focus {
  top: 0;
}


/* --- Site Header --- */

.site-header {
  padding-block: var(--space-xl);
  border-bottom: 1px solid var(--color-rule);
}

.site-header-inner {
  max-width: 75ch;
  margin-inline: auto;
  padding-inline: clamp(1rem, 5vw, 3rem);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-xl);
}

.site-name {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-variant: small-caps;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--color-text);
}

.site-name:hover {
  color: var(--color-accent);
}

.site-nav {
  display: flex;
  gap: var(--space-lg);
  list-style: none;
}

.site-nav a {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-variant: small-caps;
  letter-spacing: 0.05em;
  text-decoration: none;
  color: var(--color-text-muted);
  transition: color 0.15s ease;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--color-accent);
}


/* --- Site Footer --- */

.site-footer {
  position: relative;
  border-top: 1px solid var(--color-rule);
  padding-block: var(--space-xl);
}

.site-footer-inner {
  max-width: 75ch;
  margin-inline: auto;
  padding-inline: clamp(1rem, 5vw, 3rem);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.site-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-lg);
  align-items: baseline;
}

.site-footer a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--color-accent);
}

.back-to-top {
  font-variant: small-caps;
  letter-spacing: 0.03em;
}

.footer-flag {
  display: inline-block;
  height: 1.25em;
  width: 1.25em;
  vertical-align: -0.3em;
}

.egg-left,
.egg-right {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-family: serif;
  font-size: var(--text-sm);
  opacity: 0.3;
  color: var(--color-text-muted);
}

.egg-left {
  left: clamp(1rem, 5vw, 3rem);
}

.egg-right {
  right: clamp(1rem, 5vw, 3rem);
}


/* --- Page Header --- */

.page-header {
  margin-bottom: var(--space-3xl);
}

.page-header h1 {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

.page-header .subtitle {
  margin-top: var(--space-sm);
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.5;
}


/* --- Home Page --- */

.home-header {
  margin-bottom: var(--space-3xl);
}

.home-name {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--color-text);
  margin-bottom: var(--space-lg);
}

.home-tagline {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
  line-height: 1.5;
  max-width: 50ch;
}

.home-content {
  margin-top: var(--space-2xl);
}

.home-content dl {
  margin: 0;
}

.home-content dt {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-top: var(--space-xl);
}

.home-content dt:first-child {
  margin-top: 0;
}

.home-content dt a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.home-content dt a:hover {
  color: var(--color-accent-hover);
}

.home-content dd {
  margin-left: 0;
  margin-top: var(--space-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
}

.home-content p {
  margin-bottom: var(--space-lg);
  line-height: 1.7;
}


/* --- Prose (article/page content) --- */

.prose {
  overflow-wrap: break-word;
}

.prose h2 {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-top: var(--space-3xl);
  margin-bottom: var(--space-lg);
}

.prose h3 {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.3;
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-md);
}

.prose h4 {
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.4;
  margin-top: var(--space-xl);
  margin-bottom: var(--space-sm);
}

.prose p {
  margin-bottom: 1.5em;
}

.prose a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  transition: color 0.15s ease;
}

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

.prose strong {
  font-weight: 600;
}

.prose em {
  font-style: italic;
}

.prose ul,
.prose ol {
  margin-bottom: 1.5em;
  padding-left: 1.5em;
}

.prose li {
  margin-bottom: var(--space-xs);
}

.prose li > ul,
.prose li > ol {
  margin-top: var(--space-xs);
  margin-bottom: 0;
}

.prose blockquote {
  border-left: 3px solid var(--color-rule);
  padding-left: var(--space-lg);
  margin-bottom: 1.5em;
  color: var(--color-text-muted);
  font-style: italic;
}

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

.prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-footnote-bg);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

.prose pre {
  margin-bottom: 1.5em;
  padding: var(--space-lg);
  background: var(--color-footnote-bg);
  border-radius: 4px;
  overflow-x: auto;
  line-height: 1.5;
}

.prose pre code {
  background: none;
  padding: 0;
  font-size: var(--text-sm);
}

.prose hr {
  border: none;
  border-top: 1px solid var(--color-rule);
  margin-block: var(--space-3xl);
}

.prose img {
  max-width: 100%;
  height: auto;
  display: block;
  margin-block: var(--space-xl);
}

.prose table {
  width: 100%;
  margin-bottom: 1.5em;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.prose th,
.prose td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-rule-light);
  text-align: left;
}

.prose th {
  font-weight: 600;
  border-bottom-color: var(--color-rule);
}


/* --- Appendix Navigation --- */

.appendix-nav {
  margin-top: var(--space-3xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--color-rule);
}

.appendix-nav h2 {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-variant: small-caps;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  font-weight: 400;
  margin-bottom: var(--space-sm);
}

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

.appendix-nav a {
  color: var(--color-accent);
  text-decoration: none;
  font-size: var(--text-sm);
}

.appendix-nav a:hover {
  text-decoration: underline;
}

.appendix-breadcrumb {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-variant: small-caps;
  letter-spacing: 0.03em;
  margin-bottom: var(--space-lg);
}

.appendix-breadcrumb a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.appendix-breadcrumb a::before {
  content: "\2190\00a0";
}

.appendix-breadcrumb a:hover {
  color: var(--color-accent);
}


/* --- Footnotes --- */

.prose .footnotes {
  margin-top: var(--space-3xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--color-rule);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.prose .footnotes hr {
  display: none;
}

.prose .footnotes ol {
  padding-left: 1.5em;
}

.prose .footnotes li {
  margin-bottom: var(--space-md);
  line-height: 1.6;
}

.prose .footnotes li:target {
  background-color: var(--color-footnote-bg);
  padding: var(--space-xs) var(--space-sm);
  margin-left: calc(-1 * var(--space-sm));
  border-radius: 3px;
}

sup a.footnote-ref {
  font-family: var(--font-ui);
  font-size: 0.7em;
  font-weight: 600;
  color: var(--color-accent);
  text-decoration: none;
  background-color: var(--color-accent-wash);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  margin-left: 1px;
  display: inline-block;
}

sup a.footnote-ref:hover {
  background-color: var(--color-accent-wash-hover);
  text-decoration: none;
}

.footnote-backref {
  text-decoration: none;
  color: var(--color-accent);
  margin-left: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
}


/* --- Article Meta --- */

.article-meta {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-variant: small-caps;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3xl);
  display: flex;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.article-meta time {
  white-space: nowrap;
}


/* --- Article List (Writing Index) --- */

.article-list {
  list-style: none;
}

.article-list-item {
  padding-block: var(--space-xl);
  border-bottom: 1px solid var(--color-rule-light);
}

.article-list-item:first-child {
  padding-top: 0;
}

.article-list-item:last-child {
  border-bottom: none;
}

.article-list-item h2 {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: var(--space-xs);
}

.article-list-item h2 a {
  color: var(--color-text);
  text-decoration: none;
}

.article-list-item h2 a:hover {
  color: var(--color-accent);
}

.article-list-item .article-date {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

.article-list-item .article-description {
  color: var(--color-text-muted);
  line-height: 1.5;
}

.external-indicator {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-left: var(--space-sm);
}


/* --- CV Contact Block --- */

.cv-contact {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-3xl);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-lg);
}

.cv-contact a {
  color: var(--color-accent);
  text-decoration: none;
}

.cv-contact a:hover {
  text-decoration: underline;
}


/* --- External Link Indicator (CSS-only) --- */

.prose a[href^="http"]:not([href*="joshuacscott.com"])::after {
  content: " \2197";
  font-size: 0.75em;
  vertical-align: super;
  color: var(--color-text-muted);
  text-decoration: none;
  display: inline-block;
}


/* --- Focus Indicators --- */

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

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


/* --- Responsive: 640px — nav stacking --- */

@media (max-width: 639px) {
  .site-header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-md);
  }

  .site-nav {
    flex-direction: column;
    gap: var(--space-xs);
  }

  .site-nav a {
    display: block;
    padding-block: var(--space-sm);
  }

  .heading-anchor {
    display: none;
  }

  .footnote-tooltip {
    max-width: calc(100vw - 2rem);
  }

  .egg-left,
  .egg-right {
    display: none;
  }

  .prose a[href^="http"]:not([href*="joshuacscott.com"])::after {
    display: none;
  }
}


/* --- Responsive: 768px — desktop body text --- */

@media (min-width: 768px) {
  body {
    font-size: var(--text-md);
  }

  main {
    padding-block: var(--space-4xl);
  }

  .page-header h1 {
    font-size: var(--text-2xl);
  }

  .home-name {
    font-size: var(--text-3xl);
  }
}


/* --- Responsive: 1024px — full whitespace --- */

@media (min-width: 1024px) {
  .site-header {
    padding-block: var(--space-2xl);
  }

  main {
    padding-block: var(--space-4xl);
  }
}


/* --- JS Enhancements (progressive — no JS = no problem) --- */

.heading-anchor {
  position: absolute;
  left: -1.5em;
  color: var(--color-rule);
  text-decoration: none;
  font-size: 0.8em;
  opacity: 0;
  transition: opacity 0.15s ease;
}

*:hover > .heading-anchor,
.heading-anchor:focus {
  opacity: 1;
  color: var(--color-accent);
}

/* Persistent highlight on footnote text while reading it */
.prose .footnotes li.footnote-active-highlight {
  background-color: var(--color-footnote-bg);
  padding: var(--space-xs) var(--space-sm);
  margin-left: calc(-1 * var(--space-sm));
  border-radius: 3px;
}

/* Fade highlight on return to source text */
.footnote-return-highlight {
  animation: footnote-fade 3.5s ease-out forwards;
}

@keyframes footnote-fade {
  0%, 40% { background-color: var(--color-footnote-bg); }
  100% { background-color: transparent; }
}

.footnote-tooltip {
  position: absolute;
  max-width: 40ch;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface);
  border: 1px solid var(--color-rule);
  border-radius: 4px;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--color-text);
  box-shadow: 0 4px 12px var(--color-shadow);
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 50;
}

.footnote-tooltip.visible {
  opacity: 1;
}

/* Tooltip is appended to <body>, outside .prose, so .prose a styles don't
   apply. Style links explicitly so they're identifiable and clickable —
   the JS keeps the tooltip alive while the cursor is inside it. Override
   :visited too (otherwise the browser default purple/magenta leaks
   through, especially noticeable in dark mode). */
.footnote-tooltip a,
.footnote-tooltip a:visited {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.footnote-tooltip a:hover {
  color: var(--color-accent-hover);
}

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--color-accent);
  width: 0;
  z-index: 99;
  transition: width 0.1s linear;
}


/* --- Dark Mode --- */

/* System preference (respects manual override) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #1C1A17;
    --color-surface: #2A2824;
    --color-text: #F0EDEA;
    --color-text-muted: #9E9A96;
    --color-accent: #8DB4F7;
    --color-accent-hover: #A5C3FF;
    --color-rule: #423E3A;
    --color-rule-light: #36332F;
    --color-footnote-bg: #262420;
    --color-accent-wash: rgba(141, 180, 247, 0.12);
    --color-accent-wash-hover: rgba(141, 180, 247, 0.22);
    --color-shadow: rgba(0, 0, 0, 0.3);
  }
}

/* Manual override */
[data-theme="dark"] {
  --color-bg: #1C1A17;
  --color-surface: #2A2824;
  --color-text: #F0EDEA;
  --color-text-muted: #9E9A96;
  --color-accent: #8DB4F7;
  --color-accent-hover: #A5C3FF;
  --color-rule: #423E3A;
  --color-rule-light: #36332F;
  --color-footnote-bg: #262420;
  --color-accent-wash: rgba(141, 180, 247, 0.12);
  --color-accent-wash-hover: rgba(141, 180, 247, 0.22);
  --color-shadow: rgba(0, 0, 0, 0.3);
}

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-xs) var(--space-sm);
  font-family: var(--font-ui);
  transition: color 0.15s ease;
}

.theme-toggle:hover {
  color: var(--color-accent);
}


/* --- Reduced Motion --- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   Page TOC — sidebar (≥1200px) + inline <details> fallback (<1200px)
   See: ~/.claude/plans/cv-toc-2026-05-07.md
   ============================================================ */

/* baseof.html wraps content in <main><div class="site-content">…</div></main>.
   .site-content has max-width: 75ch which constrains its children. For pages
   with a TOC sidebar, we need .cv-page to be viewport-wide so the absolutely-
   positioned sidebar can be placed in the viewport's left margin. The :has()
   selector lets us override .site-content's constraints only when a TOC page
   is rendering — pages without .cv-page are unaffected. */
.site-content:has(.cv-page) {
  max-width: none;
  padding-inline: 0;
}

.cv-page {
  position: relative;
}

/* Article column inside .cv-page replicates the live .site-content layout
   so the article visually behaves identically to non-TOC pages. */
.cv-page > article {
  max-width: 75ch;
  margin-inline: auto;
  padding-inline: clamp(1rem, 5vw, 3rem);
}

/* Floating sidebar anchor — absolutely positioned in the article's
   left margin space. Article column itself is unchanged. */
.toc-sidebar-anchor {
  position: absolute;
  top: 0;
  width: 200px;
  height: 100%;
}

/* Article-anchored: constant ~32px gap from article column.
   The max(1rem, ...) prevents the sidebar from going off-screen
   on viewports just above the threshold. */
.toc-sidebar-anchor--article {
  left: max(1rem, calc(50% - (75ch / 2) - 200px - 2rem));
}

/* The sticky <details> element — sits at top of anchor;
   pins to top: 2rem when scrolled past. Native collapse via summary click. */
details.toc-sidebar-inner {
  position: sticky;
  top: 2rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: 1.5;
}

details.toc-sidebar-inner > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: var(--text-sm);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-rule);
}
details.toc-sidebar-inner > summary::-webkit-details-marker { display: none; }
details.toc-sidebar-inner > summary::after {
  content: "▸";
  font-size: 0.85em;
  letter-spacing: 0;
}
details.toc-sidebar-inner[open] > summary::after { content: "▾"; }
details.toc-sidebar-inner > summary:hover { color: var(--color-accent); }

details.toc-sidebar-inner ul {
  list-style: none;
  padding: 0;
  margin: 0;
  user-select: none; /* nav surfaces are action affordances, not selectable text */
}
details.toc-sidebar-inner > ul > li { margin-bottom: 0.4rem; }
details.toc-sidebar-inner ul ul {
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--color-rule-light);
}
details.toc-sidebar-inner ul ul li {
  margin-bottom: 0.25rem;
}
details.toc-sidebar-inner a {
  color: var(--color-text);
  text-decoration: none;
  display: block;
  padding: 0.1rem 0;
}
details.toc-sidebar-inner a:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

/* Inline <details> TOC — appears at top of article on narrow viewports.
   Aesthetic matches the desktop sidebar: no box, same flex summary with
   caret right-aligned, same border-bottom under the summary. The rule
   extends to the article column width (the natural context width),
   mirroring how the sidebar's rule extends to its 200px width. */
.page-toc-inline {
  margin: 1.5rem 0 2.5rem;
}
.page-toc-inline > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: flex-start;
  align-items: baseline;
  gap: 0.5rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 600;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-rule);
  user-select: none;
}
.page-toc-inline > summary::-webkit-details-marker { display: none; }
.page-toc-inline > summary::after {
  content: "▸";
  font-size: 0.85em;
  letter-spacing: 0;
}
.page-toc-inline[open] > summary::after { content: "▾"; }
.page-toc-inline > summary:hover { color: var(--color-accent); }
.page-toc-inline[open] > summary { margin-bottom: 0.75rem; }

.page-toc-inline ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: 1.5;
  user-select: none; /* nav surfaces are action affordances, not selectable text */
}
.page-toc-inline > ul > li { margin-bottom: 0.4rem; }
.page-toc-inline ul ul {
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--color-rule-light);
}
.page-toc-inline ul ul li {
  margin-bottom: 0.25rem;
}
.page-toc-inline a {
  color: var(--color-text);
  text-decoration: none;
  display: block;
  padding: 0.1rem 0;
}
.page-toc-inline a:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

/* Viewport swap: sidebar at wide; inline at narrow. Same DOM, CSS-only swap. */
@media (max-width: 1200px) {
  .toc-sidebar-anchor { display: none; }
}
@media (min-width: 1201px) {
  .page-toc-inline { display: none; }
}
