/*
 * System fonts only. No external resources. The token block is shared with the project website and the
 * explorer (they deploy separately and carry their own copy); keep the three in step.
 */

:root {
  color-scheme: light;
  --bg: #f4f3ec;
  --surface: #fffefa;
  --surface-2: #eae9df;
  --border: #d2d1c2;
  --border-strong: #a9a996;
  --text: #151a14;
  --muted: #50594d;
  --accent: #b8ea55;
  --accent-hover: #a8dc43;
  --accent-ink: #132006;
  --accent-text: #386000;
  --hidden-ink: #151a14;
  --warn-bg: #fff3cf;
  --warn-border: #d3ae3a;
  --warn-text: #563e00;
  --no-bg: #fbe6e0;
  --no-text: #8a2413;
  --ok-bg: #e2f3c4;
  --ok-text: #2c4d00;
  --focus: #0b5cc0;
  --mark-bg: #132006;
  --mark-fg: #c6f26b;
  --glow: rgba(184, 234, 85, 0.35);
  --rule: rgba(21, 26, 20, 0.055);
  --shadow: 0 1px 0 rgba(21, 26, 20, 0.04), 0 14px 34px -20px rgba(21, 26, 20, 0.28);
  --shadow-lift: 0 1px 0 rgba(21, 26, 20, 0.05), 0 22px 44px -22px rgba(21, 26, 20, 0.34);

  --radius-s: 8px;
  --radius: 14px;
  --radius-l: 22px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --measure: 46rem;
  --gutter: clamp(1rem, 4vw, 1.75rem);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0f0c;
    --surface: #121713;
    --surface-2: #1a211b;
    --border: #2a342b;
    --border-strong: #46543f;
    --text: #e9efe6;
    --muted: #a0ad9f;
    --accent: #c6f26b;
    --accent-hover: #d4f78a;
    --accent-ink: #132006;
    --accent-text: #c6f26b;
    --hidden-ink: #c6f26b;
    --warn-bg: #2a2210;
    --warn-border: #6b5416;
    --warn-text: #f1cf7a;
    --no-bg: #34170f;
    --no-text: #ffab98;
    --ok-bg: #1d2b0c;
    --ok-text: #c6f26b;
    --focus: #9ad0ff;
    --mark-bg: #c6f26b;
    --mark-fg: #132006;
    --glow: rgba(198, 242, 107, 0.12);
    --rule: rgba(233, 239, 230, 0.045);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.02), 0 18px 40px -22px rgba(0, 0, 0, 0.8);
    --shadow-lift: 0 1px 0 rgba(255, 255, 255, 0.03), 0 24px 48px -22px rgba(0, 0, 0, 0.9);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f0c;
  --surface: #121713;
  --surface-2: #1a211b;
  --border: #2a342b;
  --border-strong: #46543f;
  --text: #e9efe6;
  --muted: #a0ad9f;
  --accent: #c6f26b;
  --accent-hover: #d4f78a;
  --accent-ink: #132006;
  --accent-text: #c6f26b;
  --hidden-ink: #c6f26b;
  --warn-bg: #2a2210;
  --warn-border: #6b5416;
  --warn-text: #f1cf7a;
  --no-bg: #34170f;
  --no-text: #ffab98;
  --ok-bg: #1d2b0c;
  --ok-text: #c6f26b;
  --focus: #9ad0ff;
  --mark-bg: #c6f26b;
  --mark-fg: #132006;
  --glow: rgba(198, 242, 107, 0.12);
  --rule: rgba(233, 239, 230, 0.045);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.02), 0 18px 40px -22px rgba(0, 0, 0, 0.8);
  --shadow-lift: 0 1px 0 rgba(255, 255, 255, 0.03), 0 24px 48px -22px rgba(0, 0, 0, 0.9);
}


/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 6.5rem; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font: 17px/1.65 var(--font); font-kerning: normal; overflow-wrap: break-word; }
a { color: inherit; text-decoration-color: var(--border-strong); text-underline-offset: 0.2em; text-decoration-thickness: 1px; transition: text-decoration-color 0.15s var(--ease), color 0.15s var(--ease); }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--accent-ink); }
code, pre, kbd { font-family: var(--mono); font-size: 0.86em; }
code { background: var(--surface-2); border-radius: 5px; padding: 0.1em 0.35em; overflow-wrap: anywhere; }
kbd { border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 0.35em; background: var(--surface); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 0.75rem; top: -4rem; z-index: 60; background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 10px; font-weight: 650; }
.skip:focus { top: 0.5rem; }

/* code blocks, with a copy button added by app.js */
.code { position: relative; margin: 1.2rem 0; }
pre { margin: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; overflow-x: auto; line-height: 1.55; tab-size: 2; }
.doc > pre { margin: 1.2rem 0; }
pre code { background: none; padding: 0; font-size: 1em; overflow-wrap: normal; }
.code pre { padding-right: 4.6rem; }
.copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; font: 600 0.74rem/1 var(--font); color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.45rem 0.6rem; cursor: pointer; min-height: 2rem; transition: color 0.15s, border-color 0.15s, background-color 0.15s; }
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }
.copy-btn[data-state="done"] { color: var(--ok-text); background: var(--ok-bg); border-color: transparent; }

/* ------------------------------------------------------------------ status strip and header */

.statusbar { background: var(--warn-bg); color: var(--warn-text); border-bottom: 1px solid var(--warn-border); font-size: 0.84rem; line-height: 1.4; }
.statusbar .inner { display: flex; gap: 0.6rem; align-items: baseline; padding: 0.5rem 1rem; max-width: 84rem; margin: 0 auto; }
.pulse { flex: none; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: currentColor; }

.site-header { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--border); }
.bar { display: flex; align-items: center; gap: 0.6rem; min-height: 3.7rem; padding: 0 1rem; max-width: 84rem; margin: 0 auto; }
.brand { display: inline-flex; align-items: center; gap: 0.6rem; font-weight: 800; letter-spacing: 0.06em; text-decoration: none; white-space: nowrap; border-radius: 10px; }
.mark { display: block; flex: none; }
.mark-frame { fill: var(--mark-bg); }
.mark-solid { fill: var(--mark-fg); }
.mark-open { fill: none; stroke: var(--mark-fg); stroke-width: 1.6; }
.brand-sub { font-weight: 500; color: var(--muted); letter-spacing: 0; }
.nav-toggle { position: absolute; opacity: 0; width: 1px; height: 1px; }
.menu-btn, .theme-btn { font: inherit; font-size: 0.92rem; font-weight: 560; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; min-height: 2.5rem; cursor: pointer; display: inline-flex; align-items: center; gap: 0.45rem; padding: 0 0.85rem; transition: border-color 0.15s, background-color 0.15s; }
.theme-btn { width: 2.5rem; justify-content: center; padding: 0; margin-left: auto; }
.menu-btn { order: -1; }
.nav-toggle:focus-visible + .menu-btn { outline: 2px solid var(--focus); outline-offset: 2px; }
.menu-btn:hover, .theme-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }

.search { position: relative; flex: 1 1 15rem; max-width: 24rem; min-width: 6rem; margin-left: auto; }
.search input { width: 100%; font: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; min-height: 2.5rem; padding: 0 2.4rem 0 0.8rem; transition: border-color 0.15s, box-shadow 0.15s; }
.search input::placeholder { color: var(--muted); opacity: 1; }
.search input:hover { border-color: var(--border-strong); }
.search input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.search .hint { position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%); pointer-events: none; font: 600 0.72rem var(--mono); color: var(--muted); border: 1px solid var(--border-strong); border-radius: 5px; padding: 0 0.35rem; }
.search input:focus ~ .hint, .search input:not(:placeholder-shown) ~ .hint { display: none; }
.results { position: absolute; right: 0; top: 3rem; width: min(32rem, calc(100vw - 2rem)); max-height: 70vh; overflow: auto; list-style: none; margin: 0; padding: 0.35rem; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: 0 18px 44px -18px rgba(0, 0, 0, 0.5); }
.results li a { display: block; padding: 0.6rem 0.75rem; border-radius: 9px; text-decoration: none; }
.results li a:hover, .results li a[aria-selected="true"] { background: var(--surface-2); }
.results li a[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--accent-text); }
.results .r-title { font-weight: 680; }
.results .r-sec { color: var(--muted); font: 600 0.68rem var(--mono); letter-spacing: 0.08em; text-transform: uppercase; margin-left: 0.5rem; }
.results .r-snip { display: block; color: var(--muted); font-size: 0.86rem; line-height: 1.42; margin-top: 0.15rem; }
.results .r-none { padding: 0.9rem 0.8rem; color: var(--muted); }
.results .r-foot { padding: 0.4rem 0.8rem 0.2rem; color: var(--muted); font-size: 0.76rem; }
mark { background: color-mix(in srgb, var(--accent) 70%, transparent); color: inherit; border-radius: 3px; padding: 0 0.1em; }

.site-links { display: flex; gap: 0.2rem; font-size: 0.9rem; }
.site-links a { color: var(--muted); text-decoration: none; padding: 0.4rem 0.6rem; border-radius: 8px; }
.site-links a:hover { color: var(--text); background: var(--surface-2); }

/* ------------------------------------------------------------------ layout: sidebar | content | toc */

.sidebar { display: none; padding: 0.5rem 1rem 1rem; border-top: 1px solid var(--border); max-height: calc(100vh - 7rem); overflow: auto; background: var(--bg); }
.site-header:has(.nav-toggle:checked) .sidebar { display: block; }
.layout { max-width: 84rem; margin: 0 auto; padding: 0 1rem; }
main { min-width: 0; padding-block: 1.75rem 3.5rem; outline: none; }
.toc { display: none; }
.toc-inline { margin: 0 0 1.5rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 0.65rem 1rem; }
.toc-inline summary { cursor: pointer; font-weight: 650; font-size: 0.92rem; }

.nav-section { margin: 0.35rem 0; }
.nav-section > summary { cursor: pointer; font: 700 0.72rem/1.3 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); padding: 0.55rem 0.3rem; list-style: none; display: flex; align-items: center; justify-content: space-between; border-radius: 8px; }
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary::after { content: ""; width: 0.45rem; height: 0.45rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform 0.18s var(--ease); margin-right: 0.3rem; }
.nav-section[open] > summary::after { transform: rotate(45deg); }
.nav-section[open] > summary { color: var(--text); }
.nav-section > summary:hover { color: var(--text); }
.nav-section ul { list-style: none; margin: 0 0 0.4rem 0.35rem; padding: 0 0 0 0.6rem; border-left: 1px solid var(--border); }
.nav-section a { display: block; padding: 0.35rem 0.65rem; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: 0.92rem; line-height: 1.35; }
.nav-section a:hover { color: var(--text); background: var(--surface-2); }
.nav-section a[aria-current="page"] { color: var(--text); background: var(--surface-2); box-shadow: inset 2px 0 0 var(--accent-text); font-weight: 640; }

@media (min-width: 62rem) {
  .menu-btn { display: none; }
  .site-header { position: static; display: contents; }
  .bar { position: sticky; top: 0; z-index: 30; width: 100%; max-width: none; padding-inline: max(1rem, calc((100vw - 84rem) / 2 + 1rem)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
  .theme-btn { margin-left: 0; }
  .sidebar { display: block; position: fixed; top: 6rem; left: max(1rem, calc((100vw - 84rem) / 2 + 1rem)); width: 16.5rem; max-height: calc(100vh - 6.6rem); border: 0; padding: 0 0.6rem 1.5rem 0; background: none; scrollbar-width: thin; }
  .layout { display: block; padding-left: calc(16.5rem + 3.5rem); }
  .layout > main { max-width: 48rem; }
}
@media (min-width: 80rem) {
  .layout { display: grid; grid-template-columns: minmax(0, 48rem) 15rem; gap: 3rem; }
  .layout > main { max-width: none; }
  .toc { display: block; position: sticky; top: 5.2rem; align-self: start; max-height: calc(100vh - 6rem); overflow: auto; padding-top: 2.1rem; font-size: 0.88rem; scrollbar-width: thin; }
  .toc-inline { display: none; }
}

/* ------------------------------------------------------------------ reading column */

.crumbs { font-size: 0.86rem; color: var(--muted); margin-bottom: 1rem; }
.crumbs a { color: var(--muted); text-decoration-color: transparent; }
.crumbs a:hover { color: var(--text); text-decoration-color: currentColor; }
.doc { max-width: 44rem; }
.doc h1 { font-size: clamp(2rem, 5.2vw, 2.9rem); line-height: 1.07; letter-spacing: -0.035em; margin: 0 0 0.8rem; text-wrap: balance; font-weight: 780; }
.doc h2 { font-size: clamp(1.4rem, 3vw, 1.75rem); line-height: 1.2; letter-spacing: -0.025em; margin: 2.8rem 0 0.8rem; padding-top: 1.4rem; border-top: 1px solid var(--border); font-weight: 740; }
.doc h3 { font-size: 1.15rem; line-height: 1.3; margin: 2rem 0 0.5rem; letter-spacing: -0.01em; font-weight: 700; }
.doc h4 { font-size: 1rem; margin: 1.5rem 0 0.35rem; }
.anchor { margin-left: 0.45rem; font-weight: 400; text-decoration: none; color: var(--muted); opacity: 0; transition: opacity 0.15s; }
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor, .anchor:focus { opacity: 1; }
.lede { font-size: 1.2rem; line-height: 1.5; color: var(--muted); margin: 0 0 1.6rem; max-width: 40rem; }
.doc p, .doc ul, .doc ol { margin: 0.95rem 0; }
.doc p { text-wrap: pretty; }
.doc ul, .doc ol { padding-left: 1.5rem; }
.doc li + li { margin-top: 0.35rem; }
.doc li::marker { color: var(--muted); }
.doc li > ul, .doc li > ol { margin: 0.35rem 0; }
.doc a:not(.anchor):not(.pn) { text-decoration-color: color-mix(in srgb, var(--accent-text) 55%, transparent); text-decoration-thickness: 1.5px; }
.doc a:not(.anchor):not(.pn):hover { text-decoration-color: currentColor; }

.table-wrap { overflow-x: auto; margin: 1.3rem 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); position: relative; }
.table-wrap:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; line-height: 1.48; }
th, td { text-align: left; vertical-align: top; padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border); min-width: 7.5rem; }
tbody tr:last-child td { border-bottom: 0; }
thead th { background: var(--surface-2); font: 650 0.72rem/1.3 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 40%, transparent); }

.callout { margin: 1.4rem 0; padding: 0.85rem 1.1rem; border: 1px solid var(--border-strong); border-left-width: 5px; border-radius: 12px; background: var(--surface); }
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-title { margin: 0 0 0.3rem !important; font-weight: 720; font-size: 0.95rem; }
.callout p { margin: 0.5rem 0; }
.callout-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.callout-status { background: var(--surface-2); }
.callout-todo { background: var(--no-bg); border-color: var(--no-text); color: var(--no-text); }
.callout-note { border-left-color: var(--accent-text); }
.callout code { background: color-mix(in srgb, currentColor 12%, transparent); }

.cards, .page-list { list-style: none; padding: 0 !important; display: grid; gap: 0.8rem; margin: 1.2rem 0 !important; }
.cards { grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.cards a, .page-list li { display: block; padding: 1rem 1.1rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); text-decoration: none; transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), transform 0.18s var(--ease); }
.cards a:hover, .page-list li:hover { border-color: var(--border-strong); box-shadow: 0 14px 30px -22px rgba(0, 0, 0, 0.5); }
@media (prefers-reduced-motion: no-preference) { .cards a:hover { transform: translateY(-2px); } }
.cards strong { display: block; font-size: 1.02rem; }
.cards span, .page-list span { display: block; color: var(--muted); font-size: 0.9rem; line-height: 1.45; margin-top: 0.25rem; }
.page-list li a { font-weight: 680; }

.toc-title { font: 700 0.72rem/1.3 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.5rem; }
.toc-list { list-style: none; margin: 0.4rem 0 0; padding: 0; border-left: 1px solid var(--border); }
.toc-list a { display: block; padding: 0.25rem 0 0.25rem 0.85rem; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.35; }
.toc-list a:hover { color: var(--text); }
.toc-list a[aria-current="true"] { color: var(--text); border-left-color: var(--accent-text); font-weight: 620; }
.toc-l3 a { padding-left: 1.7rem; font-size: 0.95em; }
.toc-inline .toc-list { border: 0; }
.toc-inline .toc-list a { padding-left: 0.2rem; border: 0; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin: 3rem 0 1.5rem; max-width: 44rem; }
.pn { display: block; padding: 0.85rem 1rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); text-decoration: none; min-width: 0; transition: border-color 0.18s var(--ease); }
.pn:hover { border-color: var(--text); }
.pn-next { text-align: right; grid-column: 2; }
.pn-prev { grid-column: 1; }
.pn-label { display: block; font: 650 0.68rem var(--mono); letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }
.pn-title { font-weight: 680; }
.foot { color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--border); padding-top: 1.1rem; max-width: 44rem; }

html:not(.js) .search, html:not(.js) .theme-btn { display: none; }

@media (max-width: 36rem) {
  body { font-size: 16px; }
  .bar { flex-wrap: wrap; padding-block: 0.5rem; }
  .search { order: 5; flex: 1 1 100%; max-width: none; margin-left: 0; }
  .brand-sub { display: none; }
  .site-links { display: none; }
  .pager { grid-template-columns: 1fr; }
  .pn-next, .pn-prev { grid-column: 1; text-align: left; }
  .bar { gap: 0.4rem; padding-inline: 0.75rem; }
  .menu-btn { padding: 0 0.7rem; }
}
@media (min-width: 36.01rem) and (max-width: 62rem) { .site-links { display: none; } }
.sidebar .site-links-m { display: none; }
@media (max-width: 62rem) { .sidebar .site-links-m { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.8rem; padding-top: 0.8rem; border-top: 1px solid var(--border); } }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

@media print {
  :root, :root[data-theme="dark"] { color-scheme: light; --bg: #fff; --surface: #fff; --surface-2: #f1f1ec; --text: #000; --muted: #333; --border: #bbb; --border-strong: #888; }
  body { font-size: 11pt; background: #fff; color: #000; }
  .site-header, .toc, .toc-inline, .pager, .skip, .anchor, .nav-toggle, .copy-btn, .sidebar { display: none !important; }
  .layout { display: block !important; padding: 0 !important; max-width: none; }
  .statusbar { border: 1px solid #000; background: #fff; color: #000; }
  .table-wrap { overflow: visible; }
  th, td { min-width: 0; }
  pre { white-space: pre-wrap; }
  a { text-decoration: none; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; color: #333; }
  h2, h3, .callout, tr, pre { break-inside: avoid; }
}
