/* ══════════════════════════════════════════════════════════════════
   Resources — Shared Stylesheet
   ══════════════════════════════════════════════════════════════════ */

/* ── CSS variables ──────────────────────────────────────────────── */
:root {
  --bg:         #ffffff;
  --surface:    #f6f8fa;
  --border:     #d0d7de;
  --text:       #1f2328;
  --muted:      #656d76;
  --accent:     #0969da;
  --accent2:    #1a7f37;
  --accent3:    #cf222e;
  --accent4:    #8250df;
  --code-bg:    #f6f8fa;
  --code-text:  #1f2328;
  --fig-bg:     #f0f6ff;
  --fig-border: #0969da;
  --inprac-bg:  #dafbe1;
  --inprac-border: #1a7f37;
  --warn-bg:    #fff8c5;
  --warn-border:#9a6700;
  --sidebar-w:  240px;
}
.dark {
  --bg:         #0d1117;
  --surface:    #161b22;
  --border:     #30363d;
  --text:       #e6edf3;
  --muted:      #8b949e;
  --accent:     #58a6ff;
  --accent2:    #3fb950;
  --accent3:    #ff7b72;
  --accent4:    #d2a8ff;
  --code-bg:    #161b22;
  --code-text:  #e6edf3;
  --fig-bg:     #1c2333;
  --fig-border: #58a6ff;
  --inprac-bg:  #112d21;
  --inprac-border: #3fb950;
  --warn-bg:    #2d2200;
  --warn-border:#d4a72c;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.75;
  transition: background .2s, color .2s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin-bottom: 1em; }
ul, ol { padding-left: 1.6em; margin-bottom: 1em; }
li { margin-bottom: .3em; }

/* ── Top bar ──────────────────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 200;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 28px;
  backdrop-filter: blur(8px);
}
header .title-bar { display: flex; align-items: baseline; gap: 12px; }
header h1 { font-size: 1.15rem; font-weight: 400; letter-spacing: .02em; font-family: "Bitcount Single Ink", sans-serif; }
header h1 a { color: inherit; text-decoration: none; }
header h1 a:hover { color: var(--accent); text-decoration: none; }
header .subtitle { font-size: .8rem; color: var(--muted); }
#theme-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 6px 14px;
  cursor: pointer; font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
  transition: all 0.2s ease;
}
#theme-btn:hover { background: var(--border); transform: translateY(-1px); }
#theme-btn:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Layout: sidebar + content ──────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
nav.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 42px;
  height: calc(100vh - 42px);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 24px 0 40px;
  background: var(--surface);
}
nav.sidebar .nav-group { margin-bottom: 6px; }
nav.sidebar .nav-section {
  display: block; padding: 7px 20px;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); cursor: default; margin-top: 10px;
}
nav.sidebar a.nav-item {
  display: block; padding: 5px 20px 5px 28px;
  font-size: 13px; color: var(--muted);
  border-left: 2px solid transparent;
  transition: color .15s, border-color .15s;
  text-decoration: none;
}
nav.sidebar a.nav-item:hover { color: var(--text); }
nav.sidebar a.nav-item:focus { outline: 2px solid #58a6ff; outline-offset: 2px; }
nav.sidebar a.nav-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(88,166,255,.07);
}
nav.sidebar a.nav-item.topic-link {
  padding-left: 20px;
  font-weight: 500;
}
nav.sidebar a.nav-item.topic-link.current,
nav.sidebar a.nav-item.toc-item.current {
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}

/* Main content */
main { flex: 1; max-width: 820px; padding: 48px 52px 100px; min-width: 0; }

/* ── Typography ──────────────────────────────────────────────── */
h1.doc-title {
  font-size: 2.2rem; font-weight: 400; line-height: 1.2;
  margin-bottom: 6px; letter-spacing: .01em;
  font-family: "Bitcount Single Ink", sans-serif;
}
.doc-meta { color: var(--muted); font-size: 13px; margin-bottom: 36px; }
.doc-meta span { margin-right: 18px; }

h2.section-heading {
  font-size: 1.55rem; font-weight: 400;
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px; margin: 56px 0 20px;
  scroll-margin-top: 60px;
  font-family: "Bitcount Single Ink", sans-serif;
}
h2.section-heading .section-num {
  color: var(--muted); margin-right: 10px; font-weight: 400;
}
h3.sub-heading {
  font-size: 1.1rem; font-weight: 600;
  margin: 32px 0 12px; scroll-margin-top: 60px;
}
h4.minor-heading {
  font-size: .95rem; font-weight: 600;
  margin: 20px 0 8px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; font-size: .8rem;
}

/* ── Figures ────────────────────────────────────────────────── */
figure {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 24px 0;
}
figure img {
  width: 100%; display: block;
  border-bottom: 1px solid var(--border);
}
figcaption {
  padding: 11px 16px;
  font-size: 13px; color: var(--muted); line-height: 1.55;
}
figcaption strong { color: var(--text); }
figcaption .fig-num { color: var(--accent); font-weight: 700; margin-right: 4px; }
figcaption .run-ref {
  display: inline-block; margin-top: 5px;
  font-family: monospace; font-size: 11.5px;
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 7px; color: var(--accent2);
}

.fig-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 24px 0; }
.fig-row figure { margin: 0; }

/* ── Callout boxes ──────────────────────────────────────────── */
.box {
  border-radius: 8px; padding: 16px 20px; margin: 20px 0;
  border: 1px solid var(--border);
}
.box-title {
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; margin-bottom: 8px;
}
.box.inprac {
  background: var(--inprac-bg); border-color: var(--inprac-border);
}
.box.inprac .box-title { color: var(--accent2); }
.box.warning {
  background: var(--warn-bg); border-color: var(--warn-border);
}
.box.warning .box-title { color: var(--warn-border); }
.box.formula {
  background: var(--surface); border-color: var(--border);
  font-size: 1.05rem; text-align: center;
}

/* ── Code ────────────────────────────────────────────────────── */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 13px; line-height: 1.55;
  margin: 14px 0;
}
code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
pre code { color: var(--accent2); }
p code, li code {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; font-size: 13px;
  color: var(--accent3);
}

/* ── Comparison table ────────────────────────────────────────── */
.cmp-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 16px 0; }
.cmp-table th, .cmp-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.cmp-table th { background: var(--surface); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.cmp-table tr:last-child td { border-bottom: none; }
.cmp-table tr:hover td { background: rgba(88,166,255,.04); }

/* ── Abstract ────────────────────────────────────────────────── */
.abstract {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 20px 24px; margin-bottom: 40px;
  font-size: 14px; color: var(--muted); line-height: 1.7;
}
.abstract strong { color: var(--text); }

/* ── Section divider ─────────────────────────────────────────── */
.sec-divider { border: none; border-top: 1px solid var(--border); margin: 48px 0 0; }

/* ── Breadcrumb ──────────────────────────────────────────────── */
.breadcrumb {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.breadcrumb a { color: var(--accent); }
.breadcrumb .sep { margin: 0 6px; opacity: 0.5; }

/* ── Topic prev/next navigation ──────────────────────────────── */
.topic-nav {
  display: flex;
  justify-content: space-between;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  margin-top: 48px;
  font-size: 13.5px;
}
.topic-nav a { color: var(--accent); }

/* ── Sidebar toggle ───────────────────────────────────────── */
#hamburger-btn {
  background: transparent; border: 1px solid transparent;
  color: var(--text); border-radius: 6px; padding: 6px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease;
}
#hamburger-btn:hover { background: var(--surface); border-color: var(--border); }
#hamburger-btn:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
#sidebar-close-btn {
  display: none;
  background: none; border: none;
  color: var(--muted); font-size: 22px; cursor: pointer;
  padding: 10px 20px; text-align: right; width: 100%;
}
.sidebar-overlay {
  display: none;
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,.4); z-index: 240;
}
.sidebar-overlay.active { display: block; }

/* Desktop sidebar collapse */
@media (min-width: 901px) {
  nav.sidebar { transition: width .2s, padding .2s, opacity .2s; }
  nav.sidebar.collapsed {
    width: 0; padding: 0; overflow: hidden; opacity: 0;
    border-right: none;
  }
}

/* ── Sidebar bottom section (GitHub link) ─────────────────── */
.sidebar-bottom {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
nav.sidebar {
  display: flex;
  flex-direction: column;
}
.sidebar-github {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 12.5px;
  color: var(--muted);
  text-decoration: none;
}
.sidebar-github:hover { color: var(--accent); text-decoration: none; }
.sidebar-github svg { flex-shrink: 0; }

/* ── Header actions (back button area) ────────────────────── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  #sidebar-close-btn { display: block; }
  nav.sidebar {
    position: fixed; top: 0; left: 0;
    width: 280px;
    height: 100vh; z-index: 250;
    transform: translateX(-100%);
    transition: transform .3s ease;
  }
  nav.sidebar.open { transform: translateX(0); }
  main { padding: 32px 22px 80px; }
  .fig-row { grid-template-columns: 1fr; }
}

/* ── Dashboard inside layout ──────────────────────────────── */
.layout .dashboard { flex: 1; min-width: 0; }

/* ══════════════════════════════════════════════════════════════════
   Dashboard-specific styles
   ══════════════════════════════════════════════════════════════════ */

.dashboard { max-width: 1000px; margin: 0 auto; padding: 48px 28px 80px; }
.dashboard .hero {
  text-align: center;
  margin-bottom: 48px;
  padding: 20px 0;
}
.dashboard .hero h1 {
  font-size: 2.4rem; font-weight: 400; letter-spacing: .01em;
  margin-bottom: 6px;
  font-family: "Bitcount Single Ink", sans-serif;
}
.dashboard .hero p {
  color: var(--muted); font-size: 14px; margin: 0;
}

.category { margin-bottom: 44px; }
.category-heading {
  font-size: 1.25rem; font-weight: 400;
  border-bottom: 2px solid var(--border);
  padding-bottom: 6px; margin-bottom: 16px;
  color: var(--text);
  font-family: "Bitcount Single Ink", sans-serif;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}
a.card {
  display: flex;
  flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  text-decoration: none;
  color: inherit;
}
a.card:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
  text-decoration: none;
}
a.card h3 {
  font-size: .95rem; font-weight: 600; margin-bottom: 6px;
  color: var(--text);
  transition: color 0.25s ease;
}
a.card:hover h3 {
  color: var(--accent);
}
a.card p {
  font-size: 13px; color: var(--muted); margin-bottom: 14px;
  line-height: 1.55;
}
.tag {
  display: inline-block;
  font-size: 11px; font-weight: 500;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px; margin-right: 6px; margin-top: auto;
  color: var(--muted);
  transition: border-color 0.25s ease, color 0.25s ease;
}
a.card:hover .tag {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── External-link card indicator ──────────────────────────────── */
a.card[href^="https://"] {
  border-style: dashed;
  position: relative;
}
a.card[href^="https://"]::after {
  content: "↗";
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 13px;
  color: var(--muted);
  opacity: 0.6;
}

/* ── TOC icon badges ────────────────────────────────────────────── */
.ext-icon {
  font-size: 10px;
  opacity: 0.55;
  vertical-align: super;
  margin-left: 2px;
}
.pdf-badge {
  font-size: 10px; font-weight: 400;
  color: var(--muted);
  margin-left: 3px;
}

/* ── Gallery ─────────────────────────────────────────────────────── */
main.main--wide { max-width: none; padding-left: 28px; padding-right: 28px; }
.gallery-grid { column-width: 260px; gap: 14px; }
.gallery-card { break-inside: avoid; margin-bottom: 14px; display: block; }
.gallery-card img { border-radius: 8px; width: 100%; display: block; cursor: zoom-in; }
.gallery-card figcaption { font-size: 12px; padding: 5px 2px; }
.gallery-card.hidden { display: none; }
#gallery-search { width: 100%; padding: 9px 14px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); margin-bottom: 20px; }
#lightbox { display:none; position:fixed; inset:0; background:rgba(0,0,0,.85);
  z-index:1000; align-items:center; justify-content:center; cursor:zoom-out; }
#lightbox.open { display:flex; }
#lightbox img { max-width:90vw; max-height:90vh; border-radius:8px; }

/* ── Site footer ───────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 24px 20px 32px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.site-footer a {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.site-footer a:hover { color: var(--accent); }
.footer-icon { border-radius: 2px; }
