:root {
  color-scheme: light;
  --bg: #ffffff; --panel: #f5f5f7; --ink: #1d1d1f; --sub: #5c5c61; --tert: #6e6e73;
  --line: #d2d2d7; --line-soft: #ececef; --blue: #0071e3; --green: #1d8a4e; --red: #d70015;
  --header-bg: rgba(255,255,255,0.88); --kbd-bg: rgba(0,0,0,.05); --shadow: rgba(0,0,0,0.14); --blue-strong: #0a5fc0;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1116; --panel: #1a212b; --ink: #e6edf3; --sub: #adbac7; --tert: #8b98a5;
    --line: #30363d; --line-soft: #232a33; --blue: #539bff; --green: #3fb950; --red: #ff6b63;
    --header-bg: rgba(14,17,22,0.85); --kbd-bg: rgba(255,255,255,.08); --shadow: rgba(0,0,0,0.5); --blue-strong: #539bff;
  }
}
*, *::before, *::after { box-sizing: border-box }
html { -webkit-text-size-adjust: 100% }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 17px; line-height: 1.6; -webkit-font-smoothing: antialiased; letter-spacing: -.01em }
::selection { background: rgba(0,113,227,.16) }

/* Shell header */
.shell-header {
  position: sticky; top: 0; z-index: 100; background: var(--header-bg);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line-soft); padding: 0 24px;
}
.shell-header-inner {
  max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 14px; height: 52px;
}
.shell-logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.shell-header-inner > .shell-header-title { flex: 0 1 auto; }
.shell-logo img { width: 22px; height: 22px; }
.shell-logo-text { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.shell-header-sep { width: 1px; height: 20px; background: var(--line); flex-shrink: 0; }
.shell-header-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.shell-header-spacer { flex: 1; }
.shell-search-btn {
  display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: 8px; padding: 6px 12px; font: 400 14px var(--font); color: var(--tert);
  cursor: pointer; transition: border-color .15s;
}
.shell-search-btn:hover { border-color: var(--line); }
.shell-export-btn {
  background: none; border: 1px solid var(--line-soft); border-radius: 8px;
  padding: 6px 12px; font: 500 13px var(--font); color: var(--sub); cursor: pointer;
  display: flex; align-items: center; gap: 5px; transition: border-color .15s;
}
.shell-export-btn:hover { border-color: var(--line); }

/* Metadata bar */
.shell-meta-bar {
  max-width: 1100px; margin: 0 auto; padding: 14px 24px 10px;
}
/* P68 (hardcore): identity is ONE tight line — type + title + badges — so the
   document's primary nav sits directly under the header. Provenance lives in the
   footer "Artifact Metadata" table, never in the prime space above the nav. */
.shell-meta-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.shell-meta-head h1 { font-size: 17px; font-weight: 600; letter-spacing: -.02em; margin: 0; }
.shell-meta-head .shell-artifact-type { align-self: center; }
.shell-meta-head .badges { display: inline-flex; gap: 6px; align-self: center; }
.shell-foot-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.shell-artifact-type {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--blue-strong); background: rgba(0,113,227,.08); padding: 3px 10px; border-radius: 6px;
}
.shell-title-block { width: 100%; margin: 4px 0 0; }
.shell-title-block h1 {
  font-size: clamp(28px, 4vw, 38px); font-weight: 600; letter-spacing: -.025em;
  line-height: 1.1; margin: 0 0 8px; text-wrap: balance;
}
.shell-meta-line {
  font-size: 14px; color: var(--tert); display: flex; flex-wrap: wrap;
  align-items: center; gap: 4px 10px; margin: 0;
}
.shell-meta-line .sep { color: var(--line); }

/* Badges */
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 3px 8px; border-radius: 5px; white-space: nowrap;
}
.badge-lock { background: rgba(0,113,227,.08); color: var(--blue-strong); }
.badge-public { background: rgba(29,138,78,.08); color: #1d8a4e; }
.badge-private { background: rgba(215,0,21,.08); color: #d70015; }
.badge-search { background: var(--panel); color: var(--tert); }
.badge-listed { background: var(--panel); color: var(--tert); }
.badge-recurring { background: rgba(139,92,246,.08); color: #8b5cf6; }

/* Tags */
.shell-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.shell-tag {
  font-size: 12px; font-weight: 500; color: var(--sub); background: var(--panel);
  border-radius: 980px; padding: 3px 10px;
}

/* Sources */
.shell-sources { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin: 6px 0 0; }
.shell-sources-label { font-size: 12px; color: var(--tert); font-weight: 500; }
.shell-source {
  font-size: 12px; font-weight: 500; color: var(--sub); background: var(--panel);
  border-radius: 5px; padding: 2px 8px;
}

/* TOC */
.shell-toc {
  max-width: 1100px; margin: 0 auto; padding: 0 24px;
}
.shell-toc details {
  border: 1px solid var(--line-soft); border-radius: 12px; margin: 0 0 4px;
  background: var(--bg); overflow: hidden;
}
.shell-toc summary {
  padding: 12px 16px; font-size: 14px; font-weight: 600; color: var(--sub);
  cursor: pointer; list-style: none;
}
.shell-toc summary::-webkit-details-marker { display: none; }
.shell-toc-list {
  list-style: none; margin: 0; padding: 0 16px 14px;
}
.shell-toc-list li {
  padding: 4px 0; border-bottom: 1px solid var(--line-soft);
}
.shell-toc-list li:last-child { border-bottom: 0; }
.shell-toc-list a {
  font-size: 14px; color: var(--sub); text-decoration: none; display: block;
  padding: 2px 0;
}
.shell-toc-list a:hover { color: var(--blue); }

/* Floating TOC hamburger (appears on scroll) */
.toc-fab {
  position: fixed; top: 68px; right: 24px; z-index: 95;
  width: 44px; height: 44px; display: grid; place-items: center;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; opacity: 0; visibility: hidden;
  transform: translateY(-8px); transition: opacity .2s, transform .2s, visibility .2s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
}
.toc-fab.show { opacity: 1; visibility: visible; transform: translateY(0); }
.toc-fab:hover { border-color: var(--tert); }
.toc-fab svg { width: 20px; height: 20px; }
.toc-panel {
  position: fixed; top: 118px; right: 24px; z-index: 96;
  width: min(88vw, 300px); max-height: 60vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow); padding: 8px 0;
  display: none;
}
.toc-panel.open { display: block; }
.toc-panel .toc-panel-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--tert); padding: 8px 16px 6px;
}
.toc-panel ul { list-style: none; margin: 0; padding: 0; }
.toc-panel li { padding: 0; }
.toc-panel a {
  display: block; font-size: 14px; color: var(--sub); text-decoration: none;
  padding: 7px 16px;
}
.toc-panel a:hover { color: var(--blue); background: var(--line-soft); }
@media (prefers-reduced-motion: reduce) { .toc-fab { transition: none; } }

/* Artifact body container */
.shell-body { max-width: 1100px; margin: 0 auto; padding: 0 0 40px; }

/* Shell footer */
.shell-footer {
  border-top: 1px solid var(--line-soft); padding: 32px 24px 48px;
  max-width: 1100px; margin: 0 auto;
}
.shell-footer-inner {
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center;
}
.shell-footer-brand {
  display: flex; align-items: center; gap: 8px;
}
.shell-footer-brand img { width: 18px; height: 18px; }
.shell-footer-attribution {
  font-size: 14px; color: var(--tert); line-height: 1.6; flex: 1; min-width: 200px;
}
.shell-footer-meta { margin-left: auto; }
.shell-footer-meta {
  font-size: 12px; color: var(--tert); line-height: 1.8;
}
.shell-footer-meta span { display: inline-block; margin-left: 16px; white-space: nowrap; }
.shell-footer-meta span:first-child { margin-left: 0; }

/* Structured metadata block */
.shell-structured-meta {
  margin: 20px 0 0; padding: 16px 18px; background: var(--panel);
  border-radius: 14px; font-size: 13px;
}
.shell-structured-meta summary {
  font-weight: 600; color: var(--sub); cursor: pointer; font-size: 13px;
  list-style: none; padding: 0;
}
.shell-structured-meta summary::-webkit-details-marker { display: none; }
.shell-structured-meta table {
  width: 100%; border-collapse: collapse; margin: 10px 0 0;
}
.shell-structured-meta td {
  padding: 5px 0; font-size: 13px; color: var(--sub); vertical-align: top;
}
.shell-structured-meta td:first-child {
  font-weight: 600; color: var(--tert); width: 160px; white-space: nowrap;
  padding-right: 16px;
}

/* Search overlay */
.search-overlay {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.search-overlay.open { display: flex; justify-content: center; padding-top: 120px; }
.search-box {
  width: min(92vw, 560px); background: var(--bg); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18); overflow: hidden; max-height: 70vh;
  display: flex; flex-direction: column;
}
.search-input-wrap {
  display: flex; align-items: center; gap: 10px; padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.search-input-wrap svg { flex-shrink: 0; color: var(--tert); }
.search-input {
  flex: 1; border: none; outline: none; font: 400 17px var(--font); color: var(--ink);
  background: transparent; letter-spacing: -.01em;
}
.search-input::placeholder { color: var(--tert); }
.search-results {
  overflow-y: auto; padding: 8px; flex: 1;
}
.search-result {
  padding: 10px 14px; border-radius: 10px; cursor: pointer; font-size: 15px;
  color: var(--ink); line-height: 1.4;
}
.search-result:hover { background: var(--panel); }
.search-result mark { background: rgba(0,113,227,.15); color: var(--ink); border-radius: 2px; padding: 0 1px; }
.search-hint { padding: 20px; text-align: center; font-size: 14px; color: var(--tert); }

/* Chart fullscreen lightbox */
.chart-hint { cursor: zoom-in; }
.chart-lightbox {
  display: none; position: fixed; inset: 0; z-index: 9998;
  background: rgba(0,0,0,0.82); padding: 40px;
  align-items: center; justify-content: center;
}
.chart-lightbox.open { display: flex; }
.chart-lightbox img {
  max-width: 100%; max-height: 100%; background: #fff;
  border-radius: 12px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.chart-lightbox-close {
  position: fixed; top: 20px; right: 20px; width: 44px; height: 44px;
  display: grid; place-items: center; background: rgba(255,255,255,0.14);
  color: #fff; border: none; border-radius: 50%; cursor: pointer;
}
.chart-lightbox-close:hover { background: rgba(255,255,255,0.26); }
.chart-lightbox-close svg { width: 22px; height: 22px; }

/* Export menu */
.export-menu {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12); min-width: 180px; z-index: 200;
  overflow: hidden;
}
.export-menu.open { display: block; }
.export-menu-item {
  display: block; width: 100%; text-align: left; padding: 10px 16px;
  font: 400 14px var(--font); color: var(--ink); background: none; border: none;
  cursor: pointer;
}
.export-menu-item:hover { background: var(--panel); }
.export-wrap { position: relative; }


@media (max-width: 680px) {
  .shell-header { padding: 0 14px; }
  .shell-header-title { font-size: 13px; }
  .shell-header-sep { display: none; }
  .shell-header-inner { gap: 8px; height: 52px; }
  /* Search collapses to a single icon button — the ⌘K hint is meaningless on a
     phone (P-mobile / data-grid "no ⌘K on mobile"), and the full pill overflowed
     the header (measured: scrollWidth 405 > 390). Icon-only, 44px tap target. */
  .shell-search-btn { padding: 0; width: 44px; height: 44px; justify-content: center; }
  .shell-search-btn .shell-search-label,
  .shell-search-btn .shell-kbd { display: none; }
  .shell-export-btn { min-height: 44px; padding: 0 12px; }
  .shell-logo-text { font-size: 14px; }
  .shell-meta-bar { padding: 8px 16px 4px; }
  .shell-toc { padding: 0 16px; }
  .shell-footer { padding: 24px 16px 40px; }
  body { font-size: 16px; }
}

/* Viewing-old-revision banner (moved off inline styles for CSP). */
.rev-banner-wrap { max-width: 1100px; margin: 0 auto; padding: 0 24px; }
.rev-banner {
  background: rgba(139,92,246,.08); color: #6d28d9;
  border: 1px solid rgba(139,92,246,.22); border-radius: 12px;
  padding: 12px 16px; font-size: 14px;
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
}
.rev-banner a { color: #0071e3; text-decoration: none; font-weight: 600; }
.rev-banner-sep { color: var(--line); }
.shell-footer-inner--mt { margin-top: 24px; }
.shell-footer-meta--mt { margin-top: 0; }

.shell-search-btn { gap: 8px; }
.shell-kbd { font: 600 11px var(--font); color: var(--tert); background: var(--kbd-bg); border: 1px solid var(--line-soft); border-radius: 5px; padding: 1px 6px; line-height: 1.4; }
