/* =========================================================================
   AI House-Design — dashboard styles
   Aesthetic: architect's drafting paper — cool light ground, blueprint grid,
   ink-blue accent, dimension-line roadmap. Type: Space Grotesk (display),
   IBM Plex Sans (body), IBM Plex Mono (labels/annotations/code).
   ========================================================================= */

:root {
  /* --- paper & ink --- */
  --paper:      #e7edf2;   /* cool drafting-paper ground */
  --paper-2:    #f4f7fa;   /* raised surfaces / cards */
  --paper-3:    #dbe3ea;   /* insets, table zebra */
  --grid:       rgba(31, 92, 153, 0.055);
  --grid-major: rgba(31, 92, 153, 0.10);

  --ink:        #14273b;   /* primary text — near-black blue */
  --ink-soft:   #47596c;   /* secondary text */
  --ink-faint:  #6b7c8d;   /* annotations */
  --line:       #c1ccd7;   /* hairlines / borders */
  --line-soft:  #d5dde5;

  /* --- architect ink-blue accent --- */
  --accent:        #1f5c99;
  --accent-strong: #123f6b;
  --accent-tint:   rgba(31, 92, 153, 0.10);
  --accent-tint-2: rgba(31, 92, 153, 0.18);

  /* --- semantic status --- */
  --done:         #3f8f6b;  --done-tint:    rgba(63, 143, 107, 0.15);
  --active:       #c08411;  --active-tint:  rgba(192, 132, 17, 0.16);
  --planned:      #7d8b99;  --planned-tint: rgba(125, 139, 153, 0.16);
  --risk:         #b0553f;  --risk-tint:    rgba(176, 85, 63, 0.14);

  /* --- type --- */
  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body:    "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* --- geometry --- */
  --r-sm: 4px;  --r-md: 8px;  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(18, 39, 59, 0.06), 0 8px 24px rgba(18, 39, 59, 0.07);
  --shadow-sm: 0 1px 2px rgba(18, 39, 59, 0.08);
  --topbar-h: 60px;
  --sidebar-w: 288px;
  --content-max: 900px;
  --measure: 72ch;   /* comfortable reading column for doc prose (~68–75ch) */
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--paper);
  /* blueprint grid: fine 24px lines + heavier 120px module lines */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px);
  background-size: 24px 24px, 24px 24px, 120px 120px, 120px 120px;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration-color: var(--accent-tint-2); }
a:hover { color: var(--accent-strong); }

/* --- focus: always visible for keyboard users --- */
:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.skip-link {
  position: fixed; top: -60px; left: 12px; z-index: 100;
  background: var(--accent-strong); color: #fff;
  padding: 10px 16px; border-radius: var(--r-md);
  font-family: var(--font-mono); font-size: 0.85rem;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 12px; color: #fff; }

/* =========================================================================
   Top bar
   ========================================================================= */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: rgba(244, 247, 250, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: 11px;
  text-decoration: none; color: var(--ink);
}
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: var(--r-md);
  background: var(--accent-strong); color: #eaf2fb;
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-family: var(--font-display); font-weight: 600; font-size: 1.06rem; letter-spacing: -0.01em; }
.brand-sub {
  font-family: var(--font-mono); font-size: 0.66rem; text-transform: uppercase;
  letter-spacing: 0.16em; color: var(--ink-faint); margin-top: 2px;
}

.topbar-meta {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-soft);
}
.topbar-meta .meta-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--line);
  border-radius: 100px; background: var(--paper-2);
  white-space: nowrap;
}
.topbar-meta .meta-chip b { color: var(--ink); font-weight: 600; }

/* hamburger — hidden on desktop */
.nav-toggle {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 40px; height: 40px; padding: 0 9px;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--r-md);
  cursor: pointer;
}
.nav-toggle span { display: block; height: 2px; background: var(--ink); border-radius: 2px; transition: transform 0.2s ease, opacity 0.2s ease; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* =========================================================================
   Layout
   ========================================================================= */
.layout { display: flex; align-items: flex-start; }

.sidebar {
  position: sticky; top: var(--topbar-h);
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 20px 14px 40px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(244,247,250,0.55), rgba(244,247,250,0.15));
}

.nav-group { margin-bottom: 20px; }
.nav-group-label {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 0.66rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.15em; color: var(--ink-faint);
  padding: 0 10px 8px;
}
.nav-group-label .rule { flex: 1; height: 1px; background: var(--line); }
.nav-group.v1 .nav-group-label { color: var(--accent); }
.nav-group.v1 .nav-group-label .rule { background: var(--accent-tint-2); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin: 1px 0;
  border-radius: var(--r-md);
  text-decoration: none; color: var(--ink-soft);
  font-size: 0.9rem; line-height: 1.25;
  border: 1px solid transparent;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.nav-item:hover { background: var(--paper-2); color: var(--ink); }
.nav-item.active {
  background: var(--paper-2); color: var(--ink);
  border-color: var(--line-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-item .idx {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  background: var(--paper-3); color: var(--ink-soft);
  border: 1px solid var(--line-soft);
}
.nav-item .idx.dot {
  width: 22px; background: transparent; border: none;
}
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-item .here {
  font-family: var(--font-mono); font-size: 0.56rem; letter-spacing: 0.12em;
  color: var(--active); border: 1px solid var(--active);
  border-radius: 100px; padding: 1px 5px; text-transform: uppercase;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  box-shadow: 0 0 0 3px var(--paper);
}
.st-done    { background: var(--done); }
.st-active  { background: var(--active); }
.st-planned { background: var(--planned); }

.scrim {
  position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 30;
  background: rgba(18, 39, 59, 0.35);
}

.content {
  flex: 1 1 auto; min-width: 0;
  padding: 34px clamp(20px, 5vw, 56px) 90px;
}
.content-inner { max-width: var(--content-max); margin: 0 auto; }

/* =========================================================================
   Overview — hero
   ========================================================================= */
.hero {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(31,92,153,0.08), transparent 55%),
    var(--paper-2);
  padding: 30px 32px 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero::before { /* corner registration tick, like a drawing sheet */
  content: ""; position: absolute; top: 14px; right: 14px;
  width: 26px; height: 26px;
  border-top: 2px solid var(--accent-tint-2); border-right: 2px solid var(--accent-tint-2);
}
.eyebrow {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--accent); margin: 0 0 10px;
}
.hero h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.8rem, 4vw, 2.7rem); line-height: 1.05;
  letter-spacing: -0.02em; margin: 0 0 12px; color: var(--ink);
}
.hero .tagline {
  font-size: 1.06rem; color: var(--ink-soft); max-width: 60ch; margin: 0 0 22px;
}

.hero-meta { display: flex; flex-wrap: wrap; gap: 10px; }
.stat {
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--paper); padding: 9px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat .k { font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); }
.stat .v { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; color: var(--ink); }

/* --- section framing --- */
.section { margin-top: 40px; }
.section-head {
  display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px;
}
.section-head h2 {
  font-family: var(--font-display); font-weight: 600; font-size: 1.24rem;
  letter-spacing: -0.01em; margin: 0; color: var(--ink);
}
.section-head .num {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--accent);
  border: 1px solid var(--accent-tint-2); border-radius: var(--r-sm);
  padding: 2px 7px;
}
.section-head .rule { flex: 1; height: 1px; background: var(--line); }

/* --- overall progress bar --- */
.progress-wrap {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--paper-2); padding: 20px 22px; box-shadow: var(--shadow-sm);
}
.progress-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.progress-top .pct { font-family: var(--font-display); font-weight: 700; font-size: 1.7rem; color: var(--accent-strong); }
.progress-top .caption { font-family: var(--font-mono); font-size: 0.74rem; color: var(--ink-soft); }
.bar {
  height: 12px; border-radius: 100px; background: var(--paper-3);
  border: 1px solid var(--line-soft); overflow: hidden; position: relative;
}
.bar > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border-radius: 100px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; }
.progress-legend .lg { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-soft); }

/* =========================================================================
   Roadmap (dimension-line) — SVG container
   ========================================================================= */
.roadmap-wrap {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35), transparent),
    var(--paper-2);
  box-shadow: var(--shadow); padding: 8px 8px 14px;
  overflow-x: auto;
}
.roadmap-wrap svg { display: block; width: 100%; min-width: 660px; height: auto; }
.roadmap-legend {
  display: flex; flex-wrap: wrap; gap: 18px; padding: 4px 14px 6px;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-soft);
}
.roadmap-legend .lg { display: inline-flex; align-items: center; gap: 7px; }
.roadmap-legend .sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.12); }

/* =========================================================================
   Stage cards
   ========================================================================= */
.card-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
}
.stage-card {
  display: flex; flex-direction: column; gap: 12px;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--paper-2); padding: 18px 18px 16px;
  text-decoration: none; color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  position: relative;
}
.stage-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent-tint-2); }
.stage-card.is-current { border-color: var(--active); box-shadow: 0 0 0 1px var(--active-tint), var(--shadow); }

.stage-card .card-top { display: flex; align-items: center; gap: 12px; }
.stage-card .node {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 600; font-size: 1.2rem;
  border: 1.5px solid;
}
.node.st-done    { color: var(--done);    border-color: var(--done);    background: var(--done-tint); }
.node.st-active  { color: var(--active);  border-color: var(--active);  background: var(--active-tint); }
.node.st-planned { color: var(--planned); border-color: var(--planned); background: var(--planned-tint); }

.stage-card .card-top .grow { flex: 1; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 0.64rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 100px; border: 1px solid;
}
.badge.st-done    { color: var(--done);    border-color: var(--done);    background: var(--done-tint); }
.badge.st-active  { color: var(--active);  border-color: var(--active);  background: var(--active-tint); }
.badge.st-planned { color: var(--planned); border-color: var(--planned); background: var(--planned-tint); }
.badge.v1 { color: var(--accent); border-color: var(--accent-tint-2); background: var(--accent-tint); }

.stage-card h3 {
  font-family: var(--font-display); font-weight: 600; font-size: 1.05rem;
  line-height: 1.2; margin: 0; color: var(--ink);
}
.stage-card .mini-bar { height: 7px; }
.stage-card .card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: auto; padding-top: 4px;
}
.stage-card .effort { font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-faint); }
.stage-card .open { font-family: var(--font-mono); font-size: 0.74rem; color: var(--accent); font-weight: 500; }
.stage-card .badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* =========================================================================
   Activity log (dimension-line list)
   ========================================================================= */
.log { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 0; list-style: none; }
.log li { position: relative; padding: 0 0 18px 24px; }
.log li::before {
  content: ""; position: absolute; left: -7px; top: 5px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--paper-2); border: 2px solid var(--accent);
}
.log li:first-child::before { background: var(--accent); }
.log .date { font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-faint); display: block; margin-bottom: 3px; }
.log .text { color: var(--ink-soft); }

/* =========================================================================
   Jump-to chips (master-plan surface)
   ========================================================================= */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 100px;
  background: var(--paper-2); padding: 7px 14px;
  text-decoration: none; color: var(--ink-soft);
  font-size: 0.86rem; box-shadow: var(--shadow-sm);
  transition: border-color 0.14s ease, color 0.14s ease, background 0.14s ease;
}
.chip:hover { color: var(--accent-strong); border-color: var(--accent-tint-2); background: var(--paper); }
.chip .cn { font-family: var(--font-mono); font-size: 0.68rem; color: var(--accent); }

/* =========================================================================
   Document view — markdown surface
   Renders /plans/*.md (via marked) in the drafting aesthetic: same tokens as
   the Overview — Space Grotesk headings, IBM Plex Sans prose on a comfortable
   ~72ch measure, IBM Plex Mono labels/code, ink-blue accent, hairline rules.
   ========================================================================= */

/* --- per-doc header (mono eyebrow + status chip pulled from /api/progress) --- */
.doc-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-bottom: 18px; padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.doc-kicker {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent);
}
.doc-status {
  font-family: var(--font-mono); font-size: 0.66rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 100px; border: 1px solid; margin-left: auto;
}
.doc-status.st-done    { color: var(--done);    border-color: var(--done);    background: var(--done-tint); }
.doc-status.st-active  { color: var(--active);  border-color: var(--active);  background: var(--active-tint); }
.doc-status.st-planned { color: var(--planned); border-color: var(--planned); background: var(--planned-tint); }

.markdown { color: var(--ink); font-size: 1rem; }
.markdown > :first-child { margin-top: 0; }

/* Reading measure: prose stays a narrow, left-aligned column; wide artifacts
   (tables, code/diagrams) break out to the full content width — a technical
   drafting-sheet feel. */
.markdown > h1, .markdown > h2, .markdown > h3, .markdown > h4,
.markdown > p, .markdown > ul, .markdown > ol,
.markdown > blockquote, .markdown > hr { max-width: var(--measure); }

.markdown h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.7rem, 3.6vw, 2.3rem); line-height: 1.1;
  letter-spacing: -0.02em; margin: 0 0 22px; color: var(--ink);
  padding-bottom: 14px; border-bottom: 2px solid var(--accent-tint-2);
}
.markdown h2 {
  font-family: var(--font-display); font-weight: 600; font-size: 1.42rem;
  letter-spacing: -0.01em; margin: 44px 0 16px; color: var(--ink);
  padding-bottom: 8px; border-bottom: 1px solid var(--line);   /* drafting hairline */
}
.markdown h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.14rem; margin: 30px 0 10px; color: var(--ink); }
.markdown h4 {
  font-family: var(--font-mono); font-weight: 600; font-size: 0.8rem;
  letter-spacing: 0.08em; text-transform: uppercase;
  margin: 24px 0 8px; color: var(--ink-faint);
}
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { scroll-margin-top: calc(var(--topbar-h) + 16px); }

/* clickable heading anchors */
.markdown .heading-anchor {
  opacity: 0; margin-left: 8px; text-decoration: none;
  color: var(--accent); font-weight: 400; font-family: var(--font-mono);
  transition: opacity 0.12s ease;
}
.markdown h2:hover .heading-anchor,
.markdown h3:hover .heading-anchor,
.markdown h2:focus-within .heading-anchor,
.markdown h3:focus-within .heading-anchor { opacity: 0.7; }
.markdown :target { scroll-margin-top: calc(var(--topbar-h) + 16px); }
@keyframes flash-target { 0% { background: var(--active-tint); } 100% { background: transparent; } }
.markdown .flash { animation: flash-target 1.6s ease-out; border-radius: var(--r-sm); }

.markdown p { margin: 0 0 14px; }
.markdown strong { font-weight: 600; color: var(--ink); }
.markdown em { color: var(--ink-soft); }

.markdown a {
  color: var(--accent); text-decoration: underline;
  text-underline-offset: 2px; text-decoration-color: var(--accent-tint-2);
  transition: color 0.12s ease, text-decoration-color 0.12s ease;
}
.markdown a:hover { color: var(--accent-strong); text-decoration-color: var(--accent); }
/* external links (app.js sets target=_blank) get an outward affordance */
.markdown a[target="_blank"]::after {
  content: "\2197"; margin-left: 1px; font-size: 0.85em;
  color: var(--accent); text-decoration: none; vertical-align: baseline;
}

.markdown ul, .markdown ol { margin: 0 0 16px; padding-left: 24px; }
.markdown li { margin: 5px 0; }
.markdown li::marker { color: var(--accent); }
.markdown li > ul, .markdown li > ol { margin: 5px 0 6px; }

/* GFM task lists — real checkboxes in the drafting palette (green = done) */
.markdown li:has(> input[type="checkbox"]) { list-style: none; margin-left: -22px; }
.markdown li > input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  position: relative;
  width: 17px; height: 17px; margin: 0 10px 0 0; vertical-align: -3px;
  border: 1.5px solid var(--line); border-radius: 5px;
  background: var(--paper-2); box-shadow: var(--shadow-sm);
  cursor: default; opacity: 1;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.markdown li > input[type="checkbox"]:checked {
  background: var(--done); border-color: var(--done);
}
.markdown li > input[type="checkbox"]:checked::after {   /* crisp drawn check */
  content: ""; position: absolute; left: 5px; top: 1px;
  width: 4px; height: 8px; border: solid #fff;
  border-width: 0 2px 2px 0; transform: rotate(42deg);
}

.markdown blockquote {   /* accent callout / aside, not indented italics */
  margin: 0 0 20px; padding: 14px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-tint);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--ink-soft);
}
.markdown blockquote > :first-child { margin-top: 0; }
.markdown blockquote > :last-child { margin-bottom: 0; }
.markdown blockquote strong { color: var(--accent-strong); }

.markdown hr { border: none; border-top: 1px dashed var(--line); margin: 34px 0; }

/* --- inline + block code --- */
.markdown code {
  font-family: var(--font-mono); font-size: 0.86em;
  background: var(--paper-3); color: var(--accent-strong);
  padding: 0.1em 0.4em; border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
}
.markdown pre {
  margin: 0 0 22px; padding: 18px 20px;
  background: var(--paper-2);
  border: 1px solid var(--line); border-left: 3px solid var(--accent-tint-2);
  border-radius: var(--r-md); overflow-x: auto;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.markdown pre::before {   /* corner registration tick, like a drawing sheet */
  content: ""; position: absolute; top: 9px; right: 9px;
  width: 11px; height: 11px;
  border-top: 1.5px solid var(--line); border-right: 1.5px solid var(--line);
}
.markdown pre code {
  background: none; border: none; padding: 0; color: var(--ink);
  font-family: var(--font-mono); font-size: 0.82rem; line-height: 1.55;
}
.markdown pre code.hljs { background: transparent; padding: 0; }   /* neutralize github theme surface */

/* harmonize highlight.js (github theme) tokens with the ink-blue palette */
.markdown .hljs-comment, .markdown .hljs-quote { color: var(--ink-faint); font-style: italic; }
.markdown .hljs-keyword, .markdown .hljs-selector-tag,
.markdown .hljs-literal, .markdown .hljs-type,
.markdown .hljs-doctag { color: var(--accent-strong); font-weight: 600; }
.markdown .hljs-string, .markdown .hljs-attr,
.markdown .hljs-regexp, .markdown .hljs-addition { color: var(--done); }
.markdown .hljs-number, .markdown .hljs-symbol, .markdown .hljs-bullet { color: var(--active); }
.markdown .hljs-title, .markdown .hljs-title.function_,
.markdown .hljs-section, .markdown .hljs-name, .markdown .hljs-built_in { color: var(--accent); }
.markdown .hljs-variable, .markdown .hljs-template-variable, .markdown .hljs-attribute { color: var(--ink); }
.markdown .hljs-deletion { color: var(--risk); }
.markdown .hljs-emphasis { font-style: italic; }
.markdown .hljs-strong { font-weight: 700; }

/* --- tables: drafting spec-sheet — hairlines, subtle header, zebra --- */
.markdown .table-scroll {
  overflow-x: auto; margin: 0 0 22px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.markdown table {
  border-collapse: collapse; width: 100%;
  font-size: 0.92rem; background: var(--paper-2);
}
.markdown thead { background: var(--accent-tint); }
.markdown th {
  color: var(--accent-strong); font-family: var(--font-mono); font-weight: 600;
  font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase;
  text-align: left; padding: 10px 14px;
  border-bottom: 1.5px solid var(--accent-tint-2);
}
.markdown td {
  padding: 10px 14px; border-top: 1px solid var(--line-soft);
  vertical-align: top; color: var(--ink);
}
.markdown tbody tr:nth-child(even) { background: var(--paper-3); }
.markdown td code { font-size: 0.82em; }

/* doc footer nav */
.doc-nav {
  display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  margin-top: 44px; padding-top: 20px; border-top: 1px dashed var(--line);
}
.doc-nav a {
  display: flex; flex-direction: column; gap: 2px; max-width: 46%;
  text-decoration: none; padding: 10px 16px; border: 1px solid var(--line);
  border-radius: var(--r-md); background: var(--paper-2); box-shadow: var(--shadow-sm);
  transition: border-color 0.14s ease, transform 0.14s ease;
}
.doc-nav a:hover { border-color: var(--accent-tint-2); transform: translateY(-1px); }
.doc-nav a.next { margin-left: auto; text-align: right; }
.doc-nav .dir { font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.doc-nav .ttl { color: var(--accent); font-size: 0.9rem; }

/* loading / error states */
.state { padding: 60px 20px; text-align: center; color: var(--ink-faint); font-family: var(--font-mono); font-size: 0.86rem; }
.state.error { color: var(--risk); }

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 860px) {
  .nav-toggle { display: flex; }
  .brand-sub { display: none; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 35;
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-100%); transition: transform 0.22s ease;
    background: var(--paper-2); box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar-meta .meta-chip.hide-sm { display: none; }
}
@media (max-width: 560px) {
  .topbar-meta { display: none; }
  .hero { padding: 24px 20px; }
  .content { padding: 24px 18px 70px; }
  .doc-nav a { max-width: 100%; }
}

/* =========================================================================
   Reduced motion
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
