/* ============ aarna Archive — styles ============ */
/* Theme tokens. Light is default; [data-theme=dark] overrides. */
:root {
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --bg: #fafafa;
  --bg-raised: #ffffff;
  --bg-sunken: #f1f3f5;
  --text: #1a2233;
  --text-soft: #55617a;
  --text-faint: #8b96ad;
  --border: #e4e8ef;
  --accent: #4f46e5;          /* indigo — single accent everywhere */
  --accent-soft: #eef0ff;
  --accent-text: #3f38c9;
  --ok: #0f9d58;
  --warn: #b7791f;
  --danger: #c0392b;
  --mark: #fff3bf;
  --shadow: 0 8px 30px rgba(20, 24, 40, .10);
  --radius: 12px;
  --topbar-h: 56px;
  --sidebar-w: 272px;
  --toc-w: 220px;
  --font-scale: 1;   /* reader-adjustable article text size (A− / A+) */
}
:root[data-theme='dark'] {
  --bg: #0f1117;
  --bg-raised: #171a23;
  --bg-sunken: #0b0d12;
  --text: #e6e9f0;
  --text-soft: #a3adc2;
  --text-faint: #67718a;
  --border: #262b38;
  --accent: #818cf8;
  --accent-soft: #23264a;
  --accent-text: #a5aeff;
  --mark: #4d3f10;
  --shadow: 0 8px 30px rgba(0, 0, 0, .45);
}

/* Reading light — warm sepia, low blue light. Layered on either theme. */
:root[data-warm='1'] {
  --bg: #f7efdc;
  --bg-raised: #fbf5e8;
  --bg-sunken: #efe5cb;
  --text: #3d3423;
  --text-soft: #6d6049;
  --text-faint: #95876b;
  --border: #e3d6b8;
  --accent: #8a5a12;
  --accent-soft: #f0e3c3;
  --accent-text: #7c4f0a;
  --mark: #f3d996;
  --shadow: 0 8px 30px rgba(90, 70, 30, .14);
}
:root[data-theme='dark'][data-warm='1'] {
  --bg: #16120d;
  --bg-raised: #1f1913;
  --bg-sunken: #100d09;
  --text: #eadfcb;
  --text-soft: #b5a78d;
  --text-faint: #7c705b;
  --border: #33291d;
  --accent: #d9a94e;
  --accent-soft: #33270f;
  --accent-text: #e6bc6a;
  --mark: #4d3c10;
  --shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
#warmBtn.on { color: #b7791f; background: var(--accent-soft); }

* { box-sizing: border-box; }
/* NOTE: never add `scroll-behavior: smooth` here — Chrome silently drops ALL
   programmatic scrolls (scrollTo/scrollIntoView) with it at non-100% browser
   zoom, which breaks search-result navigation and anchor links. */
body {
  margin: 0; font-family: var(--font-body); background: var(--bg); color: var(--text);
  font-size: 15.5px; line-height: 1.65; -webkit-font-smoothing: antialiased;
}
.msym {
  font-family: 'Material Symbols Rounded'; font-weight: normal; font-style: normal;
  font-size: 20px; line-height: 1; letter-spacing: normal; text-transform: none;
  display: inline-block; white-space: nowrap; word-wrap: normal; direction: ltr;
  font-variation-settings: 'opsz' 20, 'wght' 400;
  user-select: none;
}
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 12px; top: 12px; z-index: 100; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px; }

/* ---------- topbar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 40;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: color-mix(in srgb, var(--bg-raised) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 7px; text-decoration: none; color: var(--text); white-space: nowrap; }
.brand-mark { font-weight: 800; font-size: 18px; letter-spacing: .01em; }
.brand-sup {
  font-size: 8.5px; font-weight: 700; letter-spacing: .1em; color: var(--accent-text);
  align-self: flex-start; margin: 2px 0 0 -2px;
}
.brand-sub { font-weight: 600; font-size: 12.5px; color: var(--accent-text); text-transform: uppercase; letter-spacing: .14em; }

/* ---------- loaders ---------- */
/* Boot splash — shown until the first route has fully rendered. */
.boot {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center;
  justify-content: center; background: var(--bg); transition: opacity .28s ease;
}
.boot.done { opacity: 0; pointer-events: none; }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.boot-mark { font-weight: 800; font-size: 26px; color: var(--text); letter-spacing: -.01em; }
.boot-mark sup { font-size: 10px; font-weight: 700; letter-spacing: .1em; color: var(--accent-text); margin-left: 5px; }
.boot-bar { width: 120px; height: 2px; border-radius: 2px; background: var(--border); overflow: hidden; position: relative; }
.boot-bar::before {
  content: ''; position: absolute; inset: 0; width: 45%; border-radius: 2px;
  background: var(--accent); animation: loadslide 1s ease-in-out infinite;
}
/* Route-change progress — a 2px indeterminate bar over the topbar. */
.loadbar {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 210;
  pointer-events: none; opacity: 0; transition: opacity .18s ease; overflow: hidden;
}
.loadbar.active { opacity: 1; }
.loadbar::before {
  content: ''; display: block; height: 100%; width: 38%; border-radius: 2px;
  background: var(--accent); animation: loadslide .9s ease-in-out infinite;
}
@keyframes loadslide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(310%); }
}
.searchbox {
  flex: 1 1 auto; max-width: 460px; margin: 0 auto; height: 36px;
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text-faint); cursor: pointer; font-family: inherit; font-size: 13.5px;
}
.searchbox:hover { border-color: var(--accent); }
.searchbox-text { flex: 1; text-align: left; }
kbd {
  font-family: var(--font-mono); font-size: 11px; padding: 2px 6px; border-radius: 5px;
  background: var(--bg-raised); border: 1px solid var(--border); color: var(--text-soft);
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.iconbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; min-width: 36px;
  padding: 0 8px; border: none; border-radius: 9px; background: transparent;
  color: var(--text-soft); cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600;
  text-decoration: none;
}
.iconbtn:hover { background: var(--bg-sunken); color: var(--text); }
.iconbtn .caret { font-size: 16px; margin-left: -4px; }
.raw-btn { border: 1px solid var(--border); }
.fontsize { display: flex; align-items: center; }
.fontsize .iconbtn { min-width: 32px; padding: 0 4px; }
.fontsize-reset {
  font-size: 11px; font-variant-numeric: tabular-nums; min-width: 42px;
  justify-content: center; color: var(--text-faint);
}
.raw-btn.active { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.nav-toggle { display: none; }

/* Ask AI dropdown */
.aimenu { position: relative; }
.aimenu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px; z-index: 60;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; display: none;
}
.aimenu-panel.open { display: block; }
.aimenu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px;
  border: none; background: none; border-radius: 8px; cursor: pointer; text-align: left;
  color: var(--text); font-family: inherit; font-size: 13.5px; font-weight: 500; text-decoration: none;
}
.aimenu-item:hover { background: var(--accent-soft); color: var(--accent-text); }
.aimenu-item .sub { display: block; font-size: 11.5px; color: var(--text-faint); font-weight: 400; }
.aimenu-sep { height: 1px; background: var(--border); margin: 6px 4px; }

/* ---------- layout ---------- */
.layout { display: flex; padding-top: var(--topbar-h); min-height: 100vh; }
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w);
  overflow-y: auto; border-right: 1px solid var(--border); background: var(--bg);
  display: flex; flex-direction: column; z-index: 30;
}
.sidenav { flex: 1; padding: 18px 12px 12px; }
.sidenav-group { margin-bottom: 4px; }
.sidenav-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em;
  color: var(--text-faint); padding: 14px 10px 6px;
}
.sidenav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px;
  color: var(--text-soft); text-decoration: none; font-size: 13.5px; font-weight: 500;
}
.sidenav a .msym { font-size: 18px; color: var(--text-faint); }
.sidenav a:hover { background: var(--bg-sunken); color: var(--text); }
.sidenav a.active { background: var(--accent-soft); color: var(--accent-text); }
.sidenav a.active .msym { color: var(--accent-text); }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); }
.sidebar-meta { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; }
.sidebar-scrim { display: none; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); margin-right: var(--toc-w); }
.article { max-width: 820px; margin: 0 auto; padding: 36px 40px 24px; }
.pagefoot { max-width: 820px; margin: 0 auto; padding: 0 40px 60px; }

.toc {
  position: fixed; top: var(--topbar-h); right: 0; bottom: 0; width: var(--toc-w);
  overflow-y: auto; padding: 28px 18px; font-size: 12.5px;
}
.toc-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--text-faint); margin-bottom: 8px; }
.toc a { display: block; padding: 4px 0 4px 10px; color: var(--text-soft); text-decoration: none; border-left: 2px solid var(--border); }
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--accent-text); border-left-color: var(--accent); }

/* ---------- article typography ----------
   Sizes inside .article are em-based so the A−/A+ text-size control
   (--font-scale on the base size) scales everything proportionally. */
.article { font-size: calc(15.5px * var(--font-scale)); }
.article h1 { font-size: 1.94em; font-weight: 800; letter-spacing: -.02em; margin: 0 0 6px; line-height: 1.25; }
.article .pagelede { font-size: 1.03em; color: var(--text-soft); margin: 0 0 26px; }
.article h2 {
  font-size: 1.35em; font-weight: 700; letter-spacing: -.01em; margin: 38px 0 12px;
  padding-top: 10px; scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.article h3 { font-size: 1.06em; font-weight: 700; margin: 26px 0 8px; scroll-margin-top: calc(var(--topbar-h) + 16px); }
.article p { margin: 10px 0; }
.article ul, .article ol { margin: 10px 0; padding-left: 24px; }
.article li { margin: 5px 0; }
.article li::marker { color: var(--accent); }
.article a { color: var(--accent-text); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.article a:hover { border-bottom-color: var(--accent); }
.article code {
  font-family: var(--font-mono); font-size: .86em; background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: 6px; padding: 1.5px 6px;
}
.article pre {
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; font-size: .84em; line-height: 1.55;
}
.article pre code { background: none; border: none; padding: 0; }
.article table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: .87em; display: block; overflow-x: auto; }
.article th, .article td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; vertical-align: top; }
.article th { background: var(--bg-sunken); font-weight: 600; white-space: nowrap; }
.article blockquote {
  margin: 14px 0; padding: 10px 16px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 10px 10px 0; color: var(--text-soft);
}
.article hr { border: none; border-top: 1px solid var(--border); margin: 30px 0; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }

/* section chips on overview */
.chipgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 20px 0; }
.chip {
  display: flex; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-raised); text-decoration: none; color: var(--text);
}
.chip:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.chip .msym { color: var(--accent); font-size: 22px; }
.chip b { display: block; font-size: 14px; }
.chip span.desc { font-size: 12.5px; color: var(--text-soft); line-height: 1.45; display: block; }

/* ---------- diagram cards ---------- */
.diagram-card {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-raised);
  margin: 18px 0; overflow: hidden;
}
.diagram-card-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--border);
  font-size: 12.5px; font-weight: 600; color: var(--text-soft);
}
.diagram-card-body { padding: 14px; overflow-x: auto; display: flex; justify-content: center; min-height: 120px; align-items: center; cursor: zoom-in; }
.diagram-loading { color: var(--text-faint); font-size: 13px; }
.diagram-card-body svg { max-width: 100%; height: auto; }

/* diagram fullscreen modal */
.overlay {
  position: fixed; inset: 0; z-index: 80; background: rgba(10, 12, 20, .55);
  backdrop-filter: blur(4px); display: flex; align-items: flex-start; justify-content: center;
}
.overlay[hidden], .toast[hidden] { display: none; }
.diagram-modal {
  width: min(96vw, 1400px); height: 92vh; margin-top: 3vh; display: flex; flex-direction: column;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.diagram-modal-bar {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 10px 18px;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px;
}
.diagram-modal-actions { display: flex; gap: 4px; }
/* Centering must be done with auto margins, NOT grid/flex `center` alignment:
   auto margins collapse to 0 when the diagram overflows, keeping every edge
   scrollable — alignment-based centering clips top/left unreachably. */
.diagram-modal-body { flex: 1; overflow: auto; display: flex; padding: 20px; cursor: grab; overscroll-behavior: contain; }
.diagram-modal-body:active { cursor: grabbing; }
.diagram-modal-body svg { display: block; margin: auto; flex: none; }

/* ---------- search ---------- */
.search-panel {
  width: min(94vw, 640px); margin-top: 9vh; background: var(--bg-raised);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; max-height: 72vh;
}
.search-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.search-head .msym { color: var(--text-faint); }
#searchInput {
  flex: 1; border: none; outline: none; background: none; color: var(--text);
  font-family: inherit; font-size: 16px;
}
.search-results { overflow-y: auto; padding: 8px; overscroll-behavior: contain; }
/* While any overlay is open the page behind must not scroll. The lock must
   sit on <html> — body-only overflow:hidden still lets wheel events that
   start over a fixed overlay scroll the document in Chrome. */
html.overlay-open, html.overlay-open body { overflow: hidden; }
.search-hit {
  display: block; padding: 10px 12px; border-radius: 10px; cursor: pointer;
  text-decoration: none; color: var(--text);
}
.search-hit:hover, .search-hit.selected { background: var(--accent-soft); }
.search-hit .hit-row { display: flex; gap: 10px; align-items: flex-start; }
.search-hit .hit-icon { color: var(--text-faint); font-size: 18px; margin-top: 2px; }
.search-hit .hit-main { min-width: 0; flex: 1; }
.search-hit .hit-section { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--accent-text); }
.search-hit .hit-title { font-weight: 600; font-size: 14.5px; margin: 2px 0; }
.search-hit .hit-snippet { font-size: 12.5px; color: var(--text-soft); line-height: 1.5; margin-top: 2px; }
.search-empty { padding: 30px; text-align: center; color: var(--text-faint); font-size: 14px; }
.search-foot {
  display: flex; gap: 18px; padding: 9px 16px; border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-faint);
}

/* ---------- prev/next footer ---------- */
.prevnext { display: flex; gap: 12px; margin-top: 44px; }
.prevnext a {
  flex: 1; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: var(--text); background: var(--bg-raised);
}
.prevnext a:hover { border-color: var(--accent); }
.prevnext .dir { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--text-faint); }
.prevnext .ttl { font-weight: 600; font-size: 14px; color: var(--accent-text); }
.prevnext .next { text-align: right; }

/* ---------- raw view ---------- */
.raw-banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; margin: 0 0 22px;
  background: var(--accent-soft); color: var(--accent-text); border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
}
.article.raw { max-width: 900px; }
.article.raw h1 { font-size: 26px; margin-top: 46px; border-top: 2px solid var(--border); padding-top: 30px; }
.article.raw h1:first-of-type { margin-top: 0; border-top: none; padding-top: 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 90;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow);
}

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .toc { display: none; }
  .main { margin-right: 0; }
}
@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim.show { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 25; background: rgba(10,12,20,.4); }
  .main { margin-left: 0; }
  .article, .pagefoot { padding-left: 20px; padding-right: 20px; }
  .btn-label, .searchbox-text, #searchKbd, .fontsize { display: none; }
  .searchbox { flex: 0 0 auto; max-width: none; margin: 0 0 0 auto; border: none; background: transparent; }
  .brand-sub { display: none; }
}

/* ---------- print ---------- */
@media print {
  .topbar, .sidebar, .toc, .pagefoot, .overlay, .toast, .sidebar-scrim,
  .diagram-card-bar .iconbtn, .raw-banner { display: none !important; }
  .layout { padding-top: 0; }
  .main { margin: 0; }
  .article { max-width: none; padding: 0; }
  body { background: #fff; color: #111; font-size: 12px; }
  .article pre, .article code { background: #f5f5f5; border-color: #ddd; }
  /* Diagrams must each fit on one page or break-inside:avoid manufactures
     blank pages. Cap their height; viewBox keeps the aspect ratio. */
  .diagram-card { break-inside: avoid; border-color: #ccc; }
  .diagram-card-body { min-height: 0; padding: 8px; }
  .diagram-card-body svg {
    max-width: 100% !important; max-height: 150mm;
    width: auto !important; height: auto !important;
  }
  .article h2, .article h3 { break-after: avoid; }
  .article table { display: table; }
  a { color: #111 !important; border-bottom: none !important; }
}

