/* Nexus — a quiet reader for the vault. One sans family, one accent, no decoration. */

:root {
  --bg: #ffffff;
  --bg-alt: #f6f6f7;
  --text: #222326;
  --muted: #6a6c73;
  --faint: #9a9ca3;
  --line: #e7e7ea;
  --accent: #6b57e0;
  --accent-soft: #6b57e014;
  --mark: #fff3a8;
  --graph-line: #c9c9cf;
  --graph-text: #4a4b51;
  --graph-bg: var(--bg);
  --code-keyword: #6b57e0;
  --code-string: #2f7d4f;
  --code-number: #b0612a;
  --code-comment: #8b8d94;
  --code-function: #2d5fa8;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --measure: 44rem;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1c1c1e;
  --bg-alt: #242427;
  --text: #dcdcdf;
  --muted: #a0a1a8;
  --faint: #74757c;
  --line: #333337;
  --accent: #a593ff;
  --accent-soft: #a593ff1c;
  --mark: #6b5d1f;
  --graph-line: #4a4a50;
  --graph-text: #c8c8cc;
  --code-keyword: #b3a5ff;
  --code-string: #7cc895;
  --code-number: #e5a172;
  --code-comment: #7d7f87;
  --code-function: #8ab4f0;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 4.5rem; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--sans); }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0.4rem 0.6rem; font-size: 0.9375rem; min-width: 0; }
input::placeholder { color: var(--faint); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
kbd { font: 0.75rem var(--mono); color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: fixed; left: 1rem; top: -3rem; z-index: 100; background: var(--accent); color: #fff; padding: 0.4rem 0.8rem; border-radius: 6px; }
.skip-link:focus { top: 0.6rem; }
.meta, .count { color: var(--faint); font-size: 0.875rem; font-weight: 400; }
.icon { flex-shrink: 0; }

/* Bar ---------------------------------------------------------------------- */
.bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 1.5rem; height: 3.25rem; padding: 0 1.5rem; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { font-weight: 650; letter-spacing: -0.01em; }
.bar-nav { display: flex; gap: 1.25rem; font-size: 0.9375rem; color: var(--muted); }
.bar-nav a[aria-current] { color: var(--text); }
.bar-button { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-width: 2rem; height: 2rem; border-radius: 6px; color: var(--muted); }
.bar-button:hover { color: var(--text); background: var(--bg-alt); }
.search-open { margin-left: auto; padding: 0 0.5rem; font-size: 0.9375rem; }

/* Index & folders ------------------------------------------------------- */
/* Page changes: the page fades quickly, while the clicked folder row grows into the opened folder's frame
   (matryoshka). Only that row is named (see transition.js); snapshots keep their natural size, anchored
   top-left, so the growing frame reveals its content instead of stretching it. */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: 120ms var(--ease-out) both page-out; }
::view-transition-new(root) { animation: 200ms var(--ease-out) both page-in; }
.nest, a.row[data-vt] { view-transition-class: folder; }
::view-transition-group(*.folder) { animation-duration: 280ms; animation-timing-function: var(--ease-in-out); }
::view-transition-old(*.folder), ::view-transition-new(*.folder) { inline-size: 100%; block-size: 100%; object-fit: none; object-position: left top; border-radius: 14px; }
::view-transition-old(*.folder) { animation: 120ms var(--ease-out) both page-out; }
::view-transition-new(*.folder) { animation: 200ms var(--ease-out) both page-in; }
@keyframes page-out { to { opacity: 0; } }
@keyframes page-in { from { opacity: 0; } }
.page { max-width: 44rem; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
.page-narrow { max-width: var(--measure); }
.page h1 { font-size: 1.75rem; margin: 0 0 1.5rem; }
.dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--c); flex-shrink: 0; display: inline-block; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows + .rows { margin-top: 0.75rem; }
.row { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.75rem; margin: 0 -0.75rem; border-radius: 8px; color: var(--text); transition: background 0.15s; }
.row:hover { background: var(--bg-alt); color: var(--text); }
.row-name { display: flex; align-items: center; gap: 0.65rem; flex: 1; min-width: 0; }
.row .icon { color: var(--faint); width: 16px; transition: transform 0.15s, color 0.15s; }
.row:hover .icon { color: var(--accent); transform: translateX(2px); }
.page > .rows .row { font-size: 1.125rem; font-weight: 500; }
.rows-folders .row-name::before { content: ""; width: 0.9rem; height: 0.7rem; border: 1.5px solid var(--faint); border-radius: 2px 3px 3px 3px; flex-shrink: 0; }

/* Each ancestor folder is a frame around the next one (matryoshka). */
.nest-root { display: inline-block; font-size: 0.875rem; color: var(--faint); margin-bottom: 0.75rem; }
.nest { border: 1px solid var(--line); border-radius: 14px; padding: 0.6rem 0.9rem 0.9rem; background: var(--bg); }
.nest > .nest { margin-top: 0.4rem; }
.nest-label { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9375rem; color: var(--muted); padding: 0.15rem 0; }
.nest-current { padding: 1.1rem 1.25rem 1rem; background: var(--bg-alt); border-color: transparent; }
.nest:not(.nest-current):has(> .nest-current) { background: var(--bg); }
.nest-current h1 { display: flex; align-items: center; gap: 0.6rem; font-size: 1.5rem; margin: 0 0 0.75rem; }
.nest-current .row:hover { background: var(--bg); }
.page > .nest-current { margin-top: 0; }

/* Note --------------------------------------------------------------------- */
.note-layout { display: grid; grid-template-columns: minmax(0, var(--measure)) 15rem; justify-content: center; gap: 4rem; padding: 2.5rem 1.5rem 5rem; }
.note { min-width: 0; }
.crumbs { display: flex; flex-wrap: wrap; gap: 0.4rem; font-size: 0.875rem; color: var(--faint); }
.crumbs a { color: var(--muted); }
.note-header h1 { font-size: 2.125rem; line-height: 1.2; margin: 0.4rem 0 0.5rem; letter-spacing: -0.02em; overflow-wrap: break-word; }
.note-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0; font-size: 0.875rem; color: var(--faint); }
.note-meta a { color: var(--muted); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.note-summary { color: var(--muted); margin: 1rem 0 0; }
.note-header { margin-bottom: 2rem; }
.toc-inline { display: none; }
/* Previous / next note in reading order. */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.pager a { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.7rem 0.9rem; border: 1px solid var(--line); border-radius: 8px; transition: border-color 0.15s; min-width: 0; }
.pager a:hover { border-color: var(--accent); color: inherit; }
.pager-next { text-align: right; grid-column: 2; }
.pager-title { font-weight: 550; overflow-wrap: anywhere; }
.graph-inline { display: none; }
.note-footer { display: flex; gap: 1.5rem; margin-top: 2rem; font-size: 0.875rem; color: var(--faint); }
.note-footer a:hover { color: var(--accent); }

.rail { position: sticky; top: 4.75rem; align-self: start; max-height: calc(100vh - 6rem); display: flex; flex-direction: column; gap: 2rem; font-size: 0.875rem; }
.rail h2 { font-size: 0.8125rem; font-weight: 500; color: var(--faint); margin: 0 0 0.6rem; }
.rail h2 a:hover { color: var(--accent); }
.toc { display: flex; flex-direction: column; overflow-y: auto; min-height: 0; flex-shrink: 1; }
.toc a { color: var(--muted); padding: 0.2rem 0 0.2rem 0.75rem; border-left: 1px solid var(--line); line-height: 1.4; }
.toc a.level-3 { padding-left: 1.5rem; }
.toc a[aria-current] { color: var(--text); border-left-color: var(--accent); }
.rail-graph { flex-shrink: 0; }
.graph-box { height: 15rem; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.graph-box canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* Repository panel (tool notes) */
.repo { display: flex; flex-direction: column; gap: 0.7rem; font-size: 0.875rem; }
.repo-image { display: block; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg-alt); }
.repo-image img { display: block; width: 100%; height: auto; aspect-ratio: 2 / 1; object-fit: cover; }
.repo-name { font-size: 0.9375rem; color: var(--muted); overflow-wrap: anywhere; }
.repo-name strong { color: var(--text); font-weight: 600; }
.repo-name:hover strong { color: var(--accent); }
.repo-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; margin: 0; }
.repo-facts dt { font-size: 0.75rem; color: var(--faint); }
.repo-facts dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; }
.repo-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0; }
.tag { display: inline-block; font-size: 0.8125rem; padding: 0 0.45rem; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); }
.tag:hover { border-color: var(--accent); }
.repo-related h3 { font-size: 0.8125rem; font-weight: 500; color: var(--faint); margin: 0.3rem 0 0.35rem; }
.repo-related h3 a { color: var(--muted); }
.repo-related ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.repo-related li a { font-weight: 550; }
.repo-related li span { display: block; color: var(--faint); font-size: 0.8125rem; line-height: 1.4; }
.repo-inline { display: none; }

/* Popover: link previews and glossary definitions */
.popover { position: absolute; z-index: 60; width: min(24rem, calc(100vw - 1rem)); max-height: 20rem; overflow: hidden; padding: 0.8rem 1rem 0.9rem; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 40px #0002; font-size: 0.875rem; animation: popover-in 140ms var(--ease-out); }
.popover::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2.5rem; background: linear-gradient(transparent, var(--bg)); pointer-events: none; }
.popover:has(.popover-link)::after { display: none; }
@keyframes popover-in { from { opacity: 0; transform: translateY(4px); } }
.popover-head { display: flex; flex-direction: column; gap: 0.1rem; margin-bottom: 0.5rem; }
.popover-head strong { font-size: 1rem; }
.popover-body.prose { font-size: 0.875rem; line-height: 1.6; }
.popover-body .figure-zoom { margin: 0.5rem auto; }
.popover-body img { max-height: 8rem; }
.popover-body .callout { margin: 0.6rem 0; }
.popover-body h1, .popover-body h2, .popover-body h3, .popover-body h4 { font-size: 0.9375rem; margin: 0.8rem 0 0.3rem; }
.popover-body .recall details, .popover-body .recall-answer { display: none; }
.popover-link { display: inline-block; margin-top: 0.4rem; color: var(--accent); }
.term { text-decoration: underline dotted var(--faint); text-underline-offset: 3px; cursor: help; }
.term:hover, .term:focus-visible { text-decoration-color: var(--accent); }

/* Prose -------------------------------------------------------------------- */
.prose { font-size: 1.0625rem; line-height: 1.72; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 1.1em; }
.prose h1 { font-size: 1.6rem; margin: 2.2em 0 0.6em; }
.prose h2 { font-size: 1.375rem; margin: 2em 0 0.6em; }
.prose h3 { font-size: 1.15rem; margin: 1.7em 0 0.5em; }
.prose h4 { font-size: 1rem; margin: 1.5em 0 0.4em; }
.prose a:not(.figure-zoom) { color: var(--accent); }
.prose a:not(.figure-zoom):hover { text-decoration: underline; text-underline-offset: 3px; }
.prose strong { font-weight: 650; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.prose li { margin: 0.25em 0; }
.prose li > p { margin-bottom: 0.4em; }
.prose li ul, .prose li ol { margin: 0.25em 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }
.prose blockquote { margin: 1.2em 0; padding-left: 1em; border-left: 2px solid var(--line); color: var(--muted); }
.prose img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 4px; background: #fff; }
.figure-zoom { display: block; width: fit-content; max-width: 100%; margin: 1.5em auto; cursor: zoom-in; }
.figure-zoom img { max-height: 42rem; object-fit: contain; }
.unresolved { color: var(--faint); border-bottom: 1px dashed var(--faint); }
mark { background: var(--mark); color: inherit; padding: 0 0.1em; border-radius: 2px; }
.ln-green { color: #228431; }
.ln-red { color: #c72d30; }
:root[data-theme="dark"] .ln-green { color: #5fc26d; }
:root[data-theme="dark"] .ln-red { color: #f0716f; }

.callout { margin: 1.5em 0; padding: 0.85rem 1.1rem; background: var(--bg-alt); border-left: 2px solid var(--accent); border-radius: 0 6px 6px 0; }
.callout-title { font-weight: 600; font-size: 0.9375rem; margin-bottom: 0.4rem; }
.callout > :last-child { margin-bottom: 0; }
.callout-figure { display: flex; flex-direction: column; }
.callout-figure, .callout-layout { background: none; border: 0; padding: 0; border-radius: 0; }
.callout-figure .callout-title { font-weight: 400; font-size: 0.875rem; color: var(--muted); text-align: center; order: 2; }
.callout-figure .figure-zoom { margin: 0.5em auto; }
.callout-figures, .callout-cards, .callout-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.callout-layout > section { margin: 0; min-width: 0; }
.callout-card, .callout-column { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 0.85rem 1rem; font-size: 0.975rem; }
.callout-comic > p { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.callout-comic .figure-zoom { margin: 0; }
.note-embed { margin: 1.5em 0; padding-left: 1rem; border-left: 2px solid var(--line); }
.note-embed > a:first-child { display: block; font-size: 0.875rem; color: var(--muted) !important; margin-bottom: 0.5rem; }

.table-scroll { overflow-x: auto; margin: 1.5em 0; }
.prose table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; line-height: 1.55; }
.prose th { text-align: left; font-weight: 600; }
.prose th, .prose td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th:first-child, .prose td:first-child { padding-left: 0; }

.prose code { font: 0.875em var(--mono); background: var(--bg-alt); padding: 0.1em 0.35em; border-radius: 4px; overflow-wrap: anywhere; }
.code-block { margin: 1.4em 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--bg-alt); }
.code-toolbar { display: flex; justify-content: space-between; padding: 0.3rem 0.75rem; font: 0.8125rem var(--sans); color: var(--faint); border-bottom: 1px solid var(--line); }
.code-toolbar button:hover { color: var(--text); }
.prose pre { margin: 0; padding: 0.9rem 1rem; overflow: auto; font-size: 0.875rem; line-height: 1.6; }
.prose pre code { background: none; padding: 0; overflow-wrap: normal; font-size: inherit; }
.math-block { overflow-x: auto; overflow-y: hidden; margin: 1.2em 0; }

/* Code tokens (build-time highlighting) */
.tok-k { color: var(--code-keyword); }
.tok-s { color: var(--code-string); }
.tok-n { color: var(--code-number); }
.tok-c { color: var(--code-comment); font-style: italic; }
.tok-p { color: var(--code-number); }
.tok-f { color: var(--code-function); }

/* Question → answer revealed in place */
.recall > blockquote { margin-bottom: 0.6rem; padding: 0.8rem 1rem; border-left: 2px solid var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; color: var(--text); }
.recall > blockquote p { margin: 0; }
.recall-answer { margin: 0 0 1.5em; }
.recall-answer > summary { display: inline-flex; cursor: pointer; color: var(--accent); font-size: 0.9375rem; list-style: none; }
.recall-answer > summary::-webkit-details-marker { display: none; }
.recall-answer > summary::before { content: "▸"; margin-right: 0.4rem; transition: transform 0.15s; }
.recall-answer[open] > summary::before { transform: rotate(90deg); }
.recall-body { margin-top: 0.75rem; padding: 0.25rem 0 0.25rem 1rem; border-left: 2px solid var(--line); animation: page-in 200ms var(--ease-out); }
.recall-jump { font-size: 0.875rem; }

/* Flashcards inside a note */
.flashcards-meta { color: var(--muted); font-size: 0.9375rem; }
.flashcards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 0.75rem; margin: 0.75rem 0 1.5rem; }
.flashcard { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.9rem 1rem; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 0.9375rem; line-height: 1.55; transition: border-color 0.15s; }
.flashcard:hover { border-color: var(--faint); }
.flashcard.open { border-color: var(--accent); }
.flashcard-q > :last-child, .flashcard-a > :last-child { margin-bottom: 0; }
.flashcard-q p { margin: 0; font-weight: 550; }
.flashcard-toggle { align-self: flex-start; font-size: 0.8125rem; color: var(--accent); }
.flashcard-a { padding-top: 0.5rem; border-top: 1px solid var(--line); animation: page-in 180ms var(--ease-out); }

/* Interactive equations */
.sim { margin: 1.75em 0; padding: 1rem 1.1rem 1.1rem; border: 1px solid var(--line); border-radius: 10px; font-size: 0.9375rem; }
.sim figcaption { font-weight: 600; margin-bottom: 0.75rem; }
.sim-ions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }
.sim-ions .button { min-height: 2rem; font-size: 0.875rem; }
.sim-ions [aria-checked="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.sim-control { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr) 4.5rem; align-items: center; gap: 0.75rem; margin: 0.35rem 0; color: var(--muted); }
.sim-control input { padding: 0; border: 0; accent-color: var(--accent); width: 100%; }
.sim-control output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.sim-result { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.9rem; margin: 1rem 0 0.25rem; }
.sim-result strong { font-size: 1.375rem; font-variant-numeric: tabular-nums; }
.sim-plot { padding-bottom: 1.5rem; }
.sim-axis { position: relative; height: 5rem; margin: 0.5rem 1.25rem 0; border-bottom: 1px solid var(--line); }
.sim-zero { position: absolute; bottom: 0; width: 1px; height: 0.6rem; background: var(--faint); }
.sim-mark { position: absolute; bottom: 0; transform: translateX(-50%); display: flex; flex-direction: column-reverse; align-items: center; gap: 0.15rem; font-size: 0.8125rem; color: var(--muted); transition: left 0.18s var(--ease-out); white-space: nowrap; }
.sim-mark i { width: 2px; height: 0.9rem; background: var(--faint); }
.sim-mark.raised i { height: 2.1rem; }
.sim-mark.main { color: var(--accent); font-weight: 600; z-index: 1; }
.sim-mark.main i { height: 3rem; background: var(--accent); }
.sim-tick { position: absolute; top: calc(100% + 0.25rem); transform: translateX(-50%); font-size: 0.75rem; color: var(--faint); white-space: nowrap; }
.sim-note { margin: 0.5rem 0 0; font-size: 0.8125rem; }

/* Bases (catalog views inside notes) */
.base { margin: 1.5em 0; font-size: 0.9375rem; }
.base-controls { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
.base-controls label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8125rem; color: var(--muted); }
.base-controls [data-base-count] { margin-left: auto; color: var(--faint); font-size: 0.875rem; padding-bottom: 0.4rem; }
.base .tag { display: inline-block; font-size: 0.8125rem; padding: 0 0.4rem; margin: 0 0.25rem 0.25rem 0; border: 1px solid var(--line); border-radius: 4px; color: var(--muted) !important; }
.base td:nth-child(2) { min-width: 14rem; }
.catalog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1rem; }
.catalog-card { border: 1px solid var(--line); border-radius: 6px; padding: 0.85rem 1rem; min-width: 0; }
.catalog-card h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.catalog-card p { margin: 0.4rem 0; font-size: 0.9375rem; }
.base .pick { width: 1.5rem; padding-right: 0; }
.base .pick input, .catalog-card .pick input { accent-color: var(--accent); margin: 0; padding: 0; }
.catalog-card { position: relative; }
.catalog-card .pick { position: absolute; top: 0.7rem; right: 0.8rem; display: flex; gap: 0.35rem; align-items: center; font-size: 0.8125rem; color: var(--faint); }
.compare { margin-top: 1.25rem; padding: 0.9rem 1rem; border: 1px solid var(--accent); border-radius: 8px; }
.compare-head { display: flex; align-items: baseline; gap: 0.75rem; }
.compare-head .link-button { margin-left: auto; font-size: 0.875rem; }
.compare-table { table-layout: fixed; min-width: 34rem; }
.compare-table thead th:first-child, .compare-table th[scope="row"] { width: 6.5rem; color: var(--muted); font-weight: 500; font-size: 0.875rem; }
.compare-table thead th { font-size: 1rem; }
.compare-table ul { margin: 0; padding-left: 1.1em; }
.compare-table li { margin: 0.15em 0; }

/* Graph -------------------------------------------------------------------- */
.page-graph main { position: relative; }
.graph-stage { position: relative; height: calc(100vh - 3.25rem); height: calc(100dvh - 3.25rem); }
.graph-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.graph-panel { position: absolute; top: 1rem; left: 1rem; display: flex; flex-direction: column; gap: 0.6rem; padding: 0.75rem; width: 14rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 0.875rem; }
.graph-groups { border: 0; margin: 0; padding: 0; display: grid; gap: 0.2rem; }
.graph-groups label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; color: var(--muted); }
.graph-groups input { margin: 0; accent-color: var(--accent); }
.graph-list { position: absolute; left: 1rem; bottom: 1rem; max-width: 18rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 0.875rem; }
.graph-list summary { padding: 0.4rem 0.75rem; cursor: pointer; color: var(--muted); }
.graph-list ul { list-style: none; margin: 0; padding: 0 0.75rem 0.6rem; max-height: 40vh; overflow-y: auto; }
.graph-list li { padding: 0.15rem 0; }
.graph-preview { position: absolute; top: 1rem; right: 1rem; width: 18rem; max-height: calc(100% - 2rem); overflow-y: auto; padding: 1rem 1.1rem 1.1rem; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 40px #0001; font-size: 0.9375rem; animation: popover-in 160ms var(--ease-out); }
.graph-preview > .bar-button { position: absolute; top: 0.5rem; right: 0.5rem; }
.graph-preview .meta { display: flex; align-items: center; gap: 0.45rem; margin: 0; padding-right: 2rem; }
.graph-preview h2 { font-size: 1.2rem; margin: 0.4rem 0 0.5rem; }
.graph-preview-text { color: var(--muted); line-height: 1.55; margin: 0 0 0.75rem; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.graph-preview .button { margin-top: 0.9rem; width: 100%; }

/* Cards -------------------------------------------------------------------- */
.deck-head, .deck-row { display: grid; grid-template-columns: 1.5rem minmax(0, 1fr) 3.5rem 3.5rem; align-items: center; gap: 0.25rem; }
.deck-head { font-size: 0.8125rem; color: var(--faint); padding: 0 0.5rem 0.4rem; border-bottom: 1px solid var(--line); }
.deck-head span:first-child { grid-column: 1 / 3; }
.deck-head span:not(:first-child), .deck-count { text-align: right; }
.deck-tree, .deck-tree ul { list-style: none; margin: 0; padding: 0; }
.deck-row { padding: 0.45rem 0.5rem 0.45rem calc(0.5rem + var(--depth) * 1.25rem); border-radius: 6px; }
.deck-row:hover { background: var(--bg-alt); }
.deck-tree > li > .deck-row { font-weight: 550; }
.deck-toggle { width: 1.25rem; height: 1.25rem; color: var(--muted); font-size: 0.9375rem; transition: transform 0.15s; }
[aria-expanded="true"] > .deck-row > .deck-toggle { transform: rotate(90deg); }
.deck-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-count { font-variant-numeric: tabular-nums; color: var(--faint); }
.deck-count.has-due { color: var(--accent); font-weight: 600; }
.deck-count.has-new { color: var(--text); }
.srs-stats { margin-top: 2.5rem; }
.srs-counts { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; margin: 0 0 1.5rem; color: var(--muted); font-size: 0.9375rem; }
.srs-counts strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart { margin: 0 0 1.75rem; position: relative; }
.chart figcaption { font-size: 0.875rem; color: var(--muted); margin-bottom: 0.4rem; }
.bar-chart { display: block; width: 100%; height: auto; overflow: visible; }
.bar-chart path { fill: var(--accent); opacity: 0.85; transition: opacity 0.15s; }
.bar-chart .bar.active path { opacity: 1; }
.bar-chart .bar.active rect { fill: var(--accent-soft); }
.chart-base { stroke: var(--line); }
.chart-axis { font: 11px var(--sans); fill: var(--faint); }
.chart-tip { position: absolute; top: 1.4rem; padding: 0.2rem 0.5rem; border-radius: 4px; background: var(--text); color: var(--bg); font-size: 0.8125rem; white-space: nowrap; pointer-events: none; }
.chart-empty { margin: 0; padding: 1rem; border: 1px dashed var(--line); border-radius: 6px; color: var(--faint); font-size: 0.875rem; }
.srs-storage { margin-top: 1rem; }
.link-button { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); cursor: pointer; }
.link-button:hover { color: var(--accent); }

.session-top { display: flex; justify-content: space-between; margin: 1rem 0 0.5rem; }
.study-card { min-height: 15rem; padding: 1.75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); touch-action: pan-y; transition: transform 0.2s var(--ease-out), border-color 0.15s; }
.study-card[data-swipe="again"] { border-color: #d0675c; }
.study-card[data-swipe="good"] { border-color: var(--accent); }
.swipe-hint { display: none; text-align: center; margin: 0.6rem 0 0; font-size: 0.8125rem; }
@media (pointer: coarse) { .swipe-hint { display: block; } }
.card-context { margin: 0 0 0.75rem; font-size: 0.8125rem; color: var(--faint); }
#card-question { font-size: 1.25rem; line-height: 1.5; }
.card-answer { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.session-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin: 1.25rem 0 2rem; }
.session-controls kbd { margin-left: 0.5rem; }
.grades { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.5rem; width: 100%; }
.grade { flex-direction: column; gap: 0; min-height: 3.25rem; line-height: 1.25; }
.grade small { font-size: 0.8125rem; color: var(--faint); min-height: 1em; }
.grade kbd { display: none; }
.grade-again span { color: #d0675c; }
.grade-good { border-color: var(--accent); }
.session-done { text-align: center; padding: 2rem 0; }
.session-done h2 { margin: 0 0 0.5rem; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.25rem; padding: 0 0.9rem; border: 1px solid var(--line); border-radius: 6px; font-size: 0.9375rem; color: var(--text); }
.button:hover:not(:disabled) { border-color: var(--faint); color: var(--text); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button:disabled { opacity: 0.4; cursor: default; }

/* Dialogs ------------------------------------------------------------------ */
dialog { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0; box-shadow: 0 20px 60px #0003; }
dialog::backdrop { background: #0004; }
.search-dialog { width: 40rem; max-width: calc(100vw - 2rem); margin: 10vh auto auto; }
.search-field { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.6rem 0.4rem 1rem; border-bottom: 1px solid var(--line); color: var(--faint); }
.search-field input { flex: 1; border: 0; padding: 0.6rem 0; font-size: 1.0625rem; background: none; color: var(--text); }
.search-field input:focus-visible { outline: 0; }
.search-field input::-webkit-search-cancel-button { display: none; }
#search-results { max-height: 60vh; overflow-y: auto; }
#search-results:empty { display: none; }
.result { display: block; padding: 0.55rem 1rem; border-left: 2px solid transparent; }
.result[aria-selected="true"] { background: var(--accent-soft); border-left-color: var(--accent); color: inherit; }
.result-title { display: block; font-weight: 550; }
.result-where { display: block; font-size: 0.8125rem; color: var(--faint); }
.result-section { padding-left: 2rem; }
.result-section .result-title { font-weight: 450; font-size: 0.9375rem; }
.result-text { display: block; font-size: 0.875rem; color: var(--muted); line-height: 1.5; }
.search-empty { margin: 0; padding: 1rem; color: var(--muted); }
.image-dialog { max-width: 95vw; max-height: 95vh; padding: 2.5rem 1rem 0.75rem; }
.image-dialog > button { position: absolute; top: 0.4rem; right: 0.4rem; }
.image-dialog img { display: block; max-width: 90vw; max-height: 80vh; object-fit: contain; background: #fff; }
.image-dialog p { display: flex; justify-content: center; gap: 0.75rem; margin: 0.6rem 0 0; text-align: center; font-size: 0.875rem; color: var(--muted); }
.image-dialog { touch-action: pan-y; }
.image-dialog > .figure-nav { position: absolute; top: 50%; right: auto; transform: translateY(-50%); width: 2.25rem; height: 2.25rem; background: var(--bg); border: 1px solid var(--line); border-radius: 50%; }
.image-dialog > .figure-prev { left: 0.5rem; }
.figure-prev .icon { transform: scaleX(-1); }
.image-dialog > .figure-next { left: auto; right: 0.5rem; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 100; padding: 0.5rem 1rem; border-radius: 6px; background: var(--text); color: var(--bg); font-size: 0.875rem; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.toast.visible { opacity: 1; }

/* Narrow screens ----------------------------------------------------------- */
@media (max-width: 1060px) {
  .note-layout { grid-template-columns: minmax(0, var(--measure)); }
  .rail { display: none; }
  .repo-inline { display: flex; margin: -0.75rem 0 2rem; }
  .repo-inline .repo-image { max-width: 20rem; }
  .graph-inline { display: block; margin-top: 2.5rem; border: 1px solid var(--line); border-radius: 6px; font-size: 0.9375rem; color: var(--muted); }
  .graph-inline summary { padding: 0.5rem 0.75rem; cursor: pointer; }
  .graph-inline .graph-box { border: 0; border-top: 1px solid var(--line); border-radius: 0; }
  .graph-inline + .pager { margin-top: 1.5rem; }
  .toc-inline { display: block; margin: -0.75rem 0 2rem; font-size: 0.9375rem; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; }
  .toc-inline summary { padding: 0.5rem 0.75rem; cursor: pointer; }
  .toc-inline nav { display: flex; flex-direction: column; padding: 0 0.75rem 0.6rem; }
  .toc-inline a { padding: 0.2rem 0; }
  .toc-inline a.level-3 { padding-left: 1rem; }
}
@media (max-width: 640px) {
  .bar { gap: 1rem; padding: 0 1rem; }
  .bar-nav { gap: 1rem; }
  .search-open span, .search-open kbd { display: none; }
  .page, .note-layout { padding: 1.75rem 1rem 4rem; }
  .note-header h1 { font-size: 1.75rem; }
  .prose { font-size: 1rem; }
  .pager { gap: 0.6rem; }
  .flashcards { grid-template-columns: 1fr; }
  .sim-control { grid-template-columns: 5.5rem minmax(0, 1fr) 3.75rem; gap: 0.5rem; }
  .graph-preview { top: auto; bottom: 0.75rem; left: 0.75rem; right: 0.75rem; width: auto; max-height: 50%; }
  .callout-figures, .callout-cards, .callout-columns, .catalog-grid { grid-template-columns: 1fr; }
  .graph-panel { left: 0.75rem; right: 0.75rem; top: 0.75rem; width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .graph-panel input { flex: 1 1 100%; }
  .graph-groups { display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem; }
  .graph-list { left: 0.75rem; right: 0.75rem; bottom: 0.75rem; max-width: none; }
  .search-dialog { margin-top: 1rem; }
  .study-card { padding: 1.25rem; }
  .nest { padding: 0.5rem 0.6rem 0.6rem; border-radius: 12px; }
  .nest-current { padding: 0.9rem 0.9rem 0.75rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  /* Gentler, not zero: the frames cross-fade in place instead of growing. */
  ::view-transition-group(*) { animation: none !important; }
}
@media print {
  .bar, .rail, .toc-inline, .graph-inline, .pager, .repo-inline, .sim, .note-footer, .skip-link { display: none !important; }
  .flashcard-a[hidden], .recall-body { display: block !important; }
  .note-layout { display: block; padding: 0; }
  body { background: #fff; color: #000; }
  .prose { font-size: 11pt; }
  .callout, .figure-zoom, .code-block { break-inside: avoid; }
}
