: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;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
*, *::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: rgba(255,255,255,0.88);
  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-logo img { width: 22px; height: 22px; }
.shell-logo-text { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.shell-header-spacer { flex: 1; }
/* .shell-history-btn shares the search button's look but NOT its class: the
   client binds the search-overlay opener to .shell-search-btn. */
.shell-search-btn, .shell-history-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, .shell-history-btn:hover { border-color: var(--line); }
.shell-history-btn { text-decoration: none; }
.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: 20px 24px 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
}
.shell-artifact-type {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--blue); 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: #0071e3; }
.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 rgba(0,0,0,0.14); 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-inner { gap: 8px; }
  .shell-meta-bar { padding: 16px 16px 12px; }
  .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, .shell-history-btn { gap: 8px; }
.shell-kbd { font: 600 11px var(--font); color: var(--tert); background: rgba(0,0,0,.05); border: 1px solid var(--line-soft); border-radius: 5px; padding: 1px 6px; line-height: 1.4; }
/* ── DARK THEME (kulinski.dev palette) (demo override, appended so it wins the
   cascade. base #0a0a0f / surface #141420 / text #f0edf2 / accent #a855d4. ── */
:root{
  color-scheme: dark;
  --bg:#0a0a0f; --panel:#141420;
  --ink:#f0edf2; --sub:#c9c2d4; --tert:#9a92ab;
  --line:#2a2733; --line-soft:#1c1a26;
  --blue:#a855d4; --accent:#a855d4; --green:#4ade80; --red:#f87171;
}
::selection { background: rgba(168,85,212,.28) }
.shell-header { background: rgba(10,10,15,0.82) !important; }
.shell-artifact-type { color: var(--accent); background: rgba(168,85,212,.14); }
.badge-lock { background: rgba(168,85,212,.16); color:#c98be0; }
.badge-public { background: rgba(74,222,128,.14); color:#4ade80; }
.badge-private { background: rgba(248,113,113,.14); color:#f87171; }
.badge-recurring { background: rgba(168,85,212,.14); color:#c98be0; }
.search-result mark { background: rgba(168,85,212,.28); color: var(--ink); }
.chart-lightbox { background: rgba(0,0,0,.62); }
.rev-banner { background: rgba(168,85,212,.12); color:#c98be0; border-color: rgba(168,85,212,.28); }
.rev-banner a { color:#c98be0; }
.shell-kbd { background: rgba(255,255,255,.06); }
