/* ============================================================
   THE DIGITAL PRODUCT ENGINEERING HANDBOOK
   Design system: "Drafting Table" (light) / "Blueprint" (dark)
   Written by Jakim Digital Solutions — Jakim Kyeyune, Author
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ---------- Design tokens ---------- */
:root{
  /* Light theme: "Drafting Table" — cream paper + navy ink, warm and legible */
  --bg: #F5F2EA;
  --bg-raised: #FFFFFF;
  --bg-sunken: #ECE7DA;
  --ink: #171B1F;
  --ink-soft: #454C54;
  --muted: #6E7680;
  --line: #DCD6C6;
  --line-strong: #C7BFA9;
  --accent: #1F4E6B;
  --accent-deep: #123047;
  --accent-tint: #E7EFF3;
  --teal: #167E73;
  --teal-tint: #E3F3F0;
  --amber: #92650E;
  --amber-tint: #F7EFDE;
  --danger: #A23B33;
  --code-bg: #ECE7DA;
  --grid-line: rgba(31,78,107,0.055);
  --shadow: 0 1px 2px rgba(23,27,31,0.04), 0 8px 24px rgba(23,27,31,0.06);
  --shadow-lg: 0 4px 10px rgba(23,27,31,0.06), 0 20px 48px rgba(23,27,31,0.12);
  --scrollbar: #C7BFA9;
  color-scheme: light;
}

[data-theme="dark"]{
  /* Dark theme: "Blueprint" — literal architectural blueprint, cyan linework on navy */
  --bg: #0A2138;
  --bg-raised: #0F2C46;
  --bg-sunken: #081C30;
  --ink: #E9F3FA;
  --ink-soft: #B9CEDD;
  --muted: #82A0B4;
  --line: rgba(233,243,250,0.14);
  --line-strong: rgba(233,243,250,0.24);
  --accent: #6FD6FF;
  --accent-deep: #9FE6FF;
  --accent-tint: rgba(111,214,255,0.10);
  --teal: #5FE3CC;
  --teal-tint: rgba(95,227,204,0.10);
  --amber: #F3C56B;
  --amber-tint: rgba(243,197,107,0.10);
  --danger: #FF9A8B;
  --code-bg: #081C30;
  --grid-line: rgba(111,214,255,0.075);
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
  --shadow-lg: 0 4px 10px rgba(0,0,0,0.35), 0 24px 60px rgba(0,0,0,0.5);
  --scrollbar: #1B4462;
  color-scheme: dark;
}

/* ---------- Reset ---------- */
*, *::before, *::after{ box-sizing: border-box; }
html{ scroll-behavior: smooth; }
@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; scroll-behavior: auto !important; }
}
body{ margin:0; }
img,svg{ display:block; max-width:100%; }
a{ color: inherit; }
button{ font-family: inherit; }

::selection{ background: var(--accent); color: var(--bg-raised); }

::-webkit-scrollbar{ width:12px; height:12px; }
::-webkit-scrollbar-track{ background: var(--bg); }
::-webkit-scrollbar-thumb{ background: var(--scrollbar); border-radius:20px; border:3px solid var(--bg); }

/* ---------- Base ---------- */
body{
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0/40px 40px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0/40px 40px,
    var(--bg);
  color: var(--ink);
  font-family: 'Newsreader', Georgia, serif;
  font-size: 17px;
  line-height: 1.65;
  transition: background-color .35s ease, color .35s ease;
  min-height: 100vh;
}

.skip-link{
  position: absolute; left: 12px; top: -60px; z-index: 999;
  background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px;
  font-family:'Space Grotesk',sans-serif; font-weight:600; font-size:14px;
  transition: top .2s ease;
}
.skip-link:focus{ top: 12px; }

h1,h2,h3,h4{ font-family:'Space Grotesk',sans-serif; font-weight:600; line-height:1.2; letter-spacing:-0.01em; color: var(--ink); margin: 0 0 .5em; }
p{ margin: 0 0 1.1em; }
code{ font-family:'JetBrains Mono',monospace; font-size:.86em; background: var(--code-bg); padding: .12em .4em; border-radius: 5px; color: var(--accent-deep); }
[data-theme="dark"] code{ color: var(--accent); }

a.inline-link{ color: var(--accent); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; transition: text-decoration-color .15s ease; }
a.inline-link:hover{ text-decoration-color: var(--accent); }

:focus-visible{ outline: 2.5px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

.visually-hidden{ position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }

/* ---------- Layout shell ---------- */
.shell{ display:flex; min-height: 100vh; position: relative; }

.topbar{
  position: sticky; top:0; z-index:60;
  display:flex; align-items:center; gap:14px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.hamburger{
  width:42px; height:42px; border-radius:10px; border:1px solid var(--line);
  background: var(--bg-raised); display:flex; align-items:center; justify-content:center;
  cursor:pointer; flex-shrink:0; transition: border-color .15s ease, transform .15s ease;
}
.hamburger:hover{ border-color: var(--accent); }
.hamburger:active{ transform: scale(.94); }
.hamburger svg{ width:20px; height:20px; }
.hamburger .bar{ stroke: var(--ink); stroke-width:2; stroke-linecap:round; transition: transform .3s ease, opacity .2s ease; transform-origin: center; }
body.nav-open .hamburger .bar1{ transform: translateY(6px) rotate(45deg); }
body.nav-open .hamburger .bar2{ opacity:0; }
body.nav-open .hamburger .bar3{ transform: translateY(-6px) rotate(-45deg); }

.brand{ display:flex; align-items:center; gap:10px; text-decoration:none; margin-right:auto; min-width:0; }
.brand .mark{ width:30px; height:30px; flex-shrink:0; }
.brand .word{ font-family:'Space Grotesk',sans-serif; font-weight:700; font-size:14.5px; letter-spacing:-0.01em; color: var(--ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.brand .word small{ display:block; font-family:'JetBrains Mono',monospace; font-weight:400; font-size:10px; letter-spacing:.08em; color: var(--muted); text-transform:uppercase; }

.topbar-actions{ display:flex; align-items:center; gap:8px; }
.icon-btn{
  width:42px; height:42px; border-radius:10px; border:1px solid var(--line); background: var(--bg-raised);
  display:flex; align-items:center; justify-content:center; cursor:pointer; color: var(--ink);
  transition: border-color .15s ease, transform .15s ease;
}
.icon-btn:hover{ border-color: var(--accent); }
.icon-btn:active{ transform: scale(.94); }
.icon-btn svg{ width:19px; height:19px; }
.theme-toggle .sun{ display:none; }
.theme-toggle .moon{ display:block; }
[data-theme="dark"] .theme-toggle .sun{ display:block; }
[data-theme="dark"] .theme-toggle .moon{ display:none; }

.search-trigger{
  display:flex; align-items:center; gap:8px; height:42px; padding:0 14px 0 12px;
  border-radius:10px; border:1px solid var(--line); background: var(--bg-raised); cursor:pointer;
  color: var(--muted); font-family:'Space Grotesk',sans-serif; font-size:13.5px; transition: border-color .15s ease;
}
.search-trigger:hover{ border-color: var(--accent); }
.search-trigger svg{ width:17px; height:17px; flex-shrink:0; }
.search-trigger kbd{ font-family:'JetBrains Mono',monospace; font-size:10.5px; border:1px solid var(--line-strong); border-radius:4px; padding:1px 5px; color: var(--muted); }
@media (max-width: 720px){ .search-trigger .label{ display:none; } .search-trigger kbd{ display:none; } .search-trigger{ width:42px; padding:0; justify-content:center; } }

/* ---------- Sidebar / drawer ---------- */
.overlay{
  position: fixed; inset:0; background: rgba(10,20,30,.45); backdrop-filter: blur(2px);
  opacity:0; pointer-events:none; transition: opacity .25s ease; z-index:70;
}
body.nav-open .overlay{ opacity:1; pointer-events:auto; }

.sidebar{
  position: fixed; top:0; left:0; bottom:0; width: 320px; max-width: 86vw; z-index:80;
  background: var(--bg-raised); border-right:1px solid var(--line);
  transform: translateX(-100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  display:flex; flex-direction:column;
  box-shadow: var(--shadow-lg);
}
body.nav-open .sidebar{ transform: translateX(0); }

.sidebar-head{ padding: 18px 18px 14px; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:10px; }
.sidebar-head .mark{ width:28px; height:28px; }
.sidebar-head .word{ font-family:'Space Grotesk',sans-serif; font-weight:700; font-size:14px; }
.sidebar-head .word small{ display:block; font-family:'JetBrains Mono',monospace; font-size:9.5px; color: var(--muted); letter-spacing:.08em; text-transform:uppercase; }
.sidebar-close{ margin-left:auto; width:34px; height:34px; border-radius:8px; border:1px solid var(--line); background:transparent; cursor:pointer; display:flex; align-items:center; justify-content:center; color:var(--muted); }
.sidebar-close:hover{ border-color: var(--accent); color: var(--accent); }

.sidebar-progress{ padding: 12px 18px; border-bottom:1px solid var(--line); }
.sidebar-progress .bar-track{ height:6px; border-radius:4px; background: var(--bg-sunken); overflow:hidden; }
.sidebar-progress .bar-fill{ height:100%; background: linear-gradient(90deg, var(--teal), var(--accent)); border-radius:4px; }
.sidebar-progress .label{ margin-top:7px; font-family:'JetBrains Mono',monospace; font-size:10.5px; color: var(--muted); letter-spacing:.03em; display:flex; justify-content:space-between; }

.sidebar-nav{ flex:1; overflow-y:auto; padding: 10px 10px 24px; }
.nav-part{ margin-bottom:4px; }
.nav-part-row{ display:flex; align-items:center; gap:2px; border-radius:8px; }
.nav-part-row:hover{ background: var(--bg-sunken); }
.nav-part-head{
  display:flex; align-items:center; gap:9px; flex:1; min-width:0; text-align:left; background:none; border:none; cursor:pointer;
  padding: 9px 6px 9px 8px; border-radius:8px; color: var(--ink); font-family:'Space Grotesk',sans-serif; font-weight:600; font-size:13.5px;
}
.nav-part-goto{
  flex-shrink:0; width:30px; height:30px; margin-right:4px; border-radius:7px; display:flex; align-items:center; justify-content:center;
  color: var(--muted); text-decoration:none; transition: background .15s ease, color .15s ease;
}
.nav-part-goto svg{ width:14px; height:14px; }
.nav-part-goto:hover{ background: var(--accent-tint); color: var(--accent); }
.nav-part-head .roman{ font-family:'JetBrains Mono',monospace; font-weight:600; font-size:11px; color: var(--accent); width:22px; flex-shrink:0; }
.nav-part-head .ptitle{ flex:1; }
.nav-part-head .count{ font-family:'JetBrains Mono',monospace; font-size:10px; color: var(--muted); }
.nav-part-head .chev{ width:14px; height:14px; color: var(--muted); transition: transform .2s ease; flex-shrink:0; }
.nav-part.open .nav-part-head .chev{ transform: rotate(90deg); }
.nav-part.active-part > .nav-part-head{ background: var(--accent-tint); }
.nav-part.active-part > .nav-part-head .roman{ color: var(--accent); }

.nav-chlist{ list-style:none; margin:0; padding: 2px 0 6px 30px; display:none; }
.nav-part.open .nav-chlist{ display:block; }
.nav-chlist li{ margin:0; }
.nav-chlist a{
  display:block; padding: 6px 10px; border-radius:7px; text-decoration:none; color: var(--ink-soft);
  font-size: 13px; line-height:1.35; border-left:2px solid transparent; margin-left:-2px;
}
.nav-chlist a:hover{ background: var(--bg-sunken); color: var(--ink); }
.nav-chlist a.current{ color: var(--accent); background: var(--accent-tint); border-left-color: var(--accent); font-weight:600; }
.nav-chlist .chnum{ font-family:'JetBrains Mono',monospace; font-size:11px; color: var(--muted); margin-right:6px; }
.nav-chlist a.current .chnum{ color: var(--accent); }

.sidebar-foot{ padding: 14px 18px; border-top:1px solid var(--line); font-family:'JetBrains Mono',monospace; font-size:10.5px; color: var(--muted); line-height:1.6; }
.sidebar-foot a{ color: var(--accent); text-decoration:none; }

/* ---------- Main content ---------- */
.main{ flex:1; min-width:0; }
.container{ max-width: 900px; margin:0 auto; padding: 0 24px; }
.container-wide{ max-width: 1180px; margin:0 auto; padding: 0 24px; }

/* ---------- Search overlay ---------- */
.search-overlay{
  position: fixed; inset:0; z-index:200; background: rgba(8,16,24,.5); backdrop-filter: blur(3px);
  display:flex; align-items:flex-start; justify-content:center; padding: 9vh 20px 20px;
  opacity:0; pointer-events:none; transition: opacity .2s ease;
}
.search-overlay.open{ opacity:1; pointer-events:auto; }
.search-panel{
  width: 100%; max-width: 640px; background: var(--bg-raised); border-radius:16px; border:1px solid var(--line);
  box-shadow: var(--shadow-lg); overflow:hidden; transform: translateY(-10px); transition: transform .2s ease;
}
.search-overlay.open .search-panel{ transform: translateY(0); }
.search-input-row{ display:flex; align-items:center; gap:10px; padding: 16px 18px; border-bottom:1px solid var(--line); }
.search-input-row svg{ width:20px; height:20px; color: var(--muted); flex-shrink:0; }
#searchInput{ flex:1; border:none; outline:none; background:transparent; font-family:'Space Grotesk',sans-serif; font-size:16px; color: var(--ink); }
#searchInput::placeholder{ color: var(--muted); }
.search-esc{ font-family:'JetBrains Mono',monospace; font-size:11px; color: var(--muted); border:1px solid var(--line-strong); border-radius:5px; padding:2px 6px; }
.search-results{ max-height: 56vh; overflow-y:auto; padding: 8px; }
.search-hint{ padding: 22px 18px; color: var(--muted); font-family:'Space Grotesk',sans-serif; font-size:13.5px; text-align:center; }
.search-result{
  display:block; padding: 11px 12px; border-radius:10px; text-decoration:none; color: var(--ink);
  margin-bottom:2px;
}
.search-result:hover, .search-result.sel{ background: var(--accent-tint); }
.search-result .sr-top{ display:flex; align-items:center; gap:8px; margin-bottom:2px; }
.search-result .sr-num{ font-family:'JetBrains Mono',monospace; font-size:11px; color: var(--accent); background: var(--accent-tint); padding:1px 7px; border-radius:5px; }
.search-result .sr-title{ font-family:'Space Grotesk',sans-serif; font-weight:600; font-size:14.5px; }
.search-result .sr-dek{ font-size:12.5px; color: var(--muted); margin-left: 0; }

/* ---------- Reading compass (scroll progress) ---------- */
.compass{
  position: fixed; right: 22px; bottom: 22px; z-index:50; width:56px; height:56px;
  border-radius:50%; background: var(--bg-raised); border:1px solid var(--line); box-shadow: var(--shadow);
  display:flex; align-items:center; justify-content:center; cursor:pointer;
  opacity:0; transform: translateY(10px) scale(.9); pointer-events:none; transition: opacity .25s ease, transform .25s ease;
}
.compass.show{ opacity:1; transform: translateY(0) scale(1); pointer-events:auto; }
.compass svg{ width:100%; height:100%; transform: rotate(-90deg); }
.compass .track{ fill:none; stroke: var(--line); stroke-width:3; }
.compass .fill{ fill:none; stroke: var(--accent); stroke-width:3; stroke-linecap:round; transition: stroke-dashoffset .1s linear; }
.compass .arrow{ position:absolute; width:16px; height:16px; color: var(--accent); }

/* ---------- Buttons / chips ---------- */
.btn{
  display:inline-flex; align-items:center; gap:8px; font-family:'Space Grotesk',sans-serif; font-weight:600; font-size:14.5px;
  padding: 12px 22px; border-radius:10px; text-decoration:none; cursor:pointer; border:1px solid transparent; transition: transform .15s ease, box-shadow .15s ease;
}
.btn:hover{ transform: translateY(-1px); }
.btn:active{ transform: translateY(0); }
.btn-primary{ background: var(--accent); color:#fff; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-ghost{ background: var(--bg-raised); border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover{ border-color: var(--accent); color: var(--accent); }

.chip{
  display:inline-flex; align-items:center; font-family:'JetBrains Mono',monospace; font-size:12px; padding:4px 10px;
  border-radius:6px; background: var(--bg-sunken); color: var(--ink-soft); text-decoration:none; border:1px solid var(--line);
}
a.chip:hover{ border-color: var(--accent); color: var(--accent); }
.chip.plain{ cursor:default; }

/* ============================================================
   HOME PAGE
   ============================================================ */
.hero{ padding: 64px 0 40px; position:relative; }
.hero-eyebrow{
  display:inline-flex; align-items:center; gap:8px; font-family:'JetBrains Mono',monospace; font-size:11.5px;
  letter-spacing:.09em; text-transform:uppercase; color: var(--teal); background: var(--teal-tint);
  border:1px solid color-mix(in srgb, var(--teal) 35%, transparent); padding:6px 12px; border-radius:20px; margin-bottom:22px;
}
.hero-eyebrow .dot{ width:6px; height:6px; border-radius:50%; background: var(--teal); }
.hero h1{
  font-size: clamp(2.4rem, 5.4vw, 4.4rem); line-height:1.04; max-width: 15ch; margin-bottom: .35em;
}
.hero h1 em{ font-style:italic; color: var(--accent); font-weight:600; }
.hero .sub{ font-family:'Newsreader',serif; font-size: clamp(1.05rem, 1.6vw, 1.3rem); color: var(--ink-soft); max-width:56ch; margin-bottom:8px; }
.byline{ font-family:'Space Grotesk',sans-serif; font-size:14px; color: var(--muted); margin-bottom:34px; }
.byline strong{ color: var(--ink); }
.hero-ctas{ display:flex; flex-wrap:wrap; gap:14px; margin-bottom:56px; }

.hero-stats{ display:grid; grid-template-columns: repeat(4,1fr); gap:1px; background: var(--line); border:1px solid var(--line); border-radius:14px; overflow:hidden; margin-bottom:64px; }
.stat{ background: var(--bg-raised); padding: 20px 18px; text-align:left; }
.stat .num{ font-family:'Space Grotesk',sans-serif; font-weight:700; font-size: clamp(1.5rem,2.6vw,2.1rem); color: var(--accent); display:block; line-height:1; margin-bottom:6px; }
.stat .lbl{ font-family:'JetBrains Mono',monospace; font-size:10.5px; letter-spacing:.05em; text-transform:uppercase; color: var(--muted); }
@media (max-width:720px){ .hero-stats{ grid-template-columns: repeat(2,1fr); } }

/* Architecture diagram — signature hero element */
.diagram-wrap{ margin: 0 0 70px; border:1px solid var(--line); border-radius:18px; background: var(--bg-raised); padding: 34px 20px 26px; box-shadow: var(--shadow); overflow-x:auto; }
.diagram-caption{ font-family:'JetBrains Mono',monospace; font-size:10.5px; color: var(--muted); text-align:center; letter-spacing:.05em; text-transform:uppercase; margin-top:18px; }
#archDiagram{ display:block; margin:0 auto; min-width:560px; width:100%; max-width:820px; }
#archDiagram .node-box{ fill: var(--bg-sunken); stroke: var(--line-strong); stroke-width:1.4; }
#archDiagram .node-label{ font-family:'JetBrains Mono',monospace; font-size:12.5px; fill: var(--ink); }
#archDiagram .node-sub{ font-family:'JetBrains Mono',monospace; font-size:9.5px; fill: var(--muted); }
#archDiagram .conn{ fill:none; stroke: var(--line-strong); stroke-width:1.6; }
#archDiagram .pulse{ fill:none; stroke: var(--teal); stroke-width:2.6; stroke-linecap:round; stroke-dasharray: 10 500; }

.section-head{ display:flex; align-items:flex-end; justify-content:space-between; gap:20px; margin-bottom:26px; flex-wrap:wrap; }
.section-head h2{ font-size: clamp(1.5rem,2.6vw,2rem); margin:0; }
.section-head .kicker{ font-family:'JetBrains Mono',monospace; font-size:11px; letter-spacing:.09em; text-transform:uppercase; color: var(--accent); margin-bottom:8px; display:block; }
.section-head p{ color: var(--muted); font-family:'Space Grotesk',sans-serif; font-size:14px; margin:0; max-width:44ch; }

.parts-grid{ display:grid; grid-template-columns: repeat(3,1fr); gap:16px; margin-bottom:70px; }
@media (max-width:900px){ .parts-grid{ grid-template-columns: repeat(2,1fr); } }
@media (max-width:600px){ .parts-grid{ grid-template-columns: 1fr; } }

.part-card{
  position:relative; display:block; text-decoration:none; color: var(--ink);
  border:1px solid var(--line); border-radius:16px; padding: 22px 20px 20px; background: var(--bg-raised);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; overflow:hidden;
}
.part-card:hover{ transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--line-strong); }
.part-card::before{
  content:''; position:absolute; top:0; left:0; width:5px; height:100%; background: var(--accent); opacity:0;
  transition: opacity .18s ease;
}
.part-card:hover::before{ opacity:1; }
.part-card .pnum{ font-family:'JetBrains Mono',monospace; font-size:11px; color: var(--muted); letter-spacing:.06em; }
.part-card .pnum b{ color: var(--accent); font-size:26px; font-weight:700; display:block; margin-bottom:2px; font-family:'Space Grotesk',sans-serif; }
.part-card h3{ font-size:17px; margin: 10px 0 8px; }
.part-card p{ font-size:13.5px; color: var(--muted); margin:0 0 14px; font-family:'Space Grotesk',sans-serif; line-height:1.5; }
.part-card .pcount{ font-family:'JetBrains Mono',monospace; font-size:11px; color: var(--teal); }

.browse-band{ background: var(--bg-raised); border-top:1px solid var(--line); border-bottom:1px solid var(--line); padding: 60px 0; margin-bottom:70px; }
.author-band{ padding: 70px 0 90px; }
.author-card{ display:flex; gap:26px; align-items:flex-start; border:1px solid var(--line); border-radius:18px; padding:30px; background: var(--bg-raised); box-shadow: var(--shadow); flex-wrap:wrap; }
.author-avatar{ width:74px; height:74px; border-radius:14px; background: linear-gradient(135deg, var(--accent), var(--teal)); flex-shrink:0; display:flex; align-items:center; justify-content:center; font-family:'Space Grotesk',sans-serif; font-weight:700; font-size:26px; color:#fff; }
.author-card h3{ font-size:19px; margin-bottom:4px; }
.author-card .role{ font-family:'JetBrains Mono',monospace; font-size:11.5px; color: var(--teal); text-transform:uppercase; letter-spacing:.06em; margin-bottom:12px; }
.author-card p{ color: var(--ink-soft); font-size:15px; max-width:60ch; }

/* ============================================================
   FILTER / BROWSE INDEX
   ============================================================ */
.filter-bar{ display:flex; flex-wrap:wrap; gap:8px; margin-bottom: 28px; }
.filter-chip{
  font-family:'Space Grotesk',sans-serif; font-size:13px; font-weight:600; padding:8px 14px; border-radius:20px;
  border:1px solid var(--line-strong); background: var(--bg-raised); color: var(--ink-soft); cursor:pointer;
}
.filter-chip.active, .filter-chip:hover{ border-color: var(--accent); color: var(--accent); background: var(--accent-tint); }
.browse-list{ display:flex; flex-direction:column; gap:8px; }
.browse-row{
  display:flex; align-items:center; gap:14px; padding:14px 16px; border-radius:12px; border:1px solid var(--line);
  background: var(--bg-raised); text-decoration:none; color: var(--ink); transition: border-color .15s ease, transform .15s ease;
}
.browse-row:hover{ border-color: var(--accent); transform: translateX(3px); }
.browse-row .bnum{ font-family:'JetBrains Mono',monospace; font-size:12px; color: var(--accent); background: var(--accent-tint); padding:4px 9px; border-radius:6px; flex-shrink:0; min-width:52px; text-align:center; }
.browse-row .btitle{ font-family:'Space Grotesk',sans-serif; font-weight:600; font-size:14.5px; flex:1; min-width:200px; }
.browse-row .bdek{ font-size:13px; color: var(--muted); flex:2; min-width:200px; }
.browse-row .bdiv{ font-family:'JetBrains Mono',monospace; font-size:10.5px; color: var(--muted); white-space:nowrap; }
@media (max-width:720px){ .browse-row{ flex-wrap:wrap; } .browse-row .bdek{ display:none; } }
.no-results{ text-align:center; padding:50px 20px; color: var(--muted); font-family:'Space Grotesk',sans-serif; }

/* ============================================================
   PART LANDING PAGE
   ============================================================ */
.part-hero{ padding: 46px 0 20px; }
.breadcrumb{ display:flex; align-items:center; flex-wrap:wrap; gap:6px; font-family:'JetBrains Mono',monospace; font-size:12px; color: var(--muted); margin-bottom:22px; }
.breadcrumb a{ color: var(--muted); text-decoration:none; }
.breadcrumb a:hover{ color: var(--accent); }
.breadcrumb .sep{ opacity:.5; }
.breadcrumb .current{ color: var(--ink); }

.part-hero .pnum-big{ font-family:'Space Grotesk',sans-serif; font-weight:700; font-size: clamp(3rem,9vw,6.5rem); line-height:.9; color: var(--accent); opacity:.9; margin-bottom:4px; }
.part-hero h1{ font-size: clamp(1.8rem,4vw,2.8rem); margin-bottom:16px; }
.part-hero .desc{ font-family:'Newsreader',serif; font-size:1.15rem; color: var(--ink-soft); max-width:64ch; margin-bottom:36px; }

.chapter-list-full{ display:flex; flex-direction:column; gap:10px; margin-bottom:60px; }
.chapter-item{
  display:flex; gap:18px; align-items:flex-start; padding:20px; border-radius:14px; border:1px solid var(--line);
  background: var(--bg-raised); text-decoration:none; color: var(--ink); transition: border-color .15s ease, box-shadow .15s ease;
}
.chapter-item:hover{ border-color: var(--accent); box-shadow: var(--shadow); }
.chapter-item .cnum{ font-family:'Space Grotesk',sans-serif; font-weight:700; font-size:1.6rem; color: var(--line-strong); flex-shrink:0; width:56px; transition: color .15s ease; }
.chapter-item:hover .cnum{ color: var(--accent); }
.chapter-item .cbody h3{ font-size:16.5px; margin-bottom:5px; }
.chapter-item .cbody p{ font-size:13.5px; color: var(--muted); margin:0; font-family:'Newsreader',serif; }
.chapter-item .carrow{ margin-left:auto; align-self:center; width:18px; height:18px; color: var(--muted); flex-shrink:0; transition: transform .15s ease; }
.chapter-item:hover .carrow{ transform: translateX(4px); color: var(--accent); }

.part-nav-footer{ display:flex; justify-content:space-between; gap:16px; padding: 30px 0 70px; border-top:1px solid var(--line); }

/* ============================================================
   CHAPTER PAGE
   ============================================================ */
.chapter-layout{ display:flex; gap:44px; align-items:flex-start; padding: 40px 0 0; }
.chapter-main{ flex:1; min-width:0; max-width: 760px; }
.chapter-rail{ width: 220px; flex-shrink:0; position:sticky; top:88px; display:none; }
@media (min-width:1100px){ .chapter-rail{ display:block; } }

.chapter-head{ margin-bottom: 34px; }
.chapter-head .num-tag{ font-family:'JetBrains Mono',monospace; font-size:12px; color: var(--accent); background: var(--accent-tint); display:inline-block; padding:5px 11px; border-radius:6px; margin-bottom:16px; letter-spacing:.03em; }
.chapter-head h1{ font-size: clamp(1.9rem, 3.6vw, 2.7rem); margin-bottom:14px; }
.chapter-head .dek{ font-family:'Newsreader',serif; font-style:italic; font-size:1.2rem; color: var(--ink-soft); margin-bottom:22px; max-width:60ch; }

.meta-stamp{ display:flex; flex-wrap:wrap; gap:0; border:1px solid var(--line); border-radius:12px; overflow:hidden; margin-bottom:30px; background: var(--bg-raised); }
.meta-item{ flex:1; min-width:130px; padding:12px 16px; border-right:1px solid var(--line); }
.meta-item:last-child{ border-right:none; }
.meta-item .mk{ font-family:'JetBrains Mono',monospace; font-size:9.5px; text-transform:uppercase; letter-spacing:.08em; color: var(--muted); display:block; margin-bottom:5px; }
.meta-item .mv{ font-family:'Space Grotesk',sans-serif; font-size:13px; font-weight:600; }
.meta-item .mv a{ color: var(--accent); text-decoration:none; }
.meta-item .mv a:hover{ text-decoration:underline; }
.meta-item .mv .chip{ margin:2px 4px 2px 0; }
@media (max-width:640px){ .meta-item{ border-right:none; border-bottom:1px solid var(--line); flex-basis:100%; } .meta-item:last-child{ border-bottom:none; } }

.reading-time{ display:flex; align-items:center; gap:6px; font-family:'JetBrains Mono',monospace; font-size:11.5px; color: var(--muted); margin-bottom:34px; }
.reading-time svg{ width:14px; height:14px; }

.chapter-body{ font-size:1.09rem; line-height:1.75; }
.chapter-body h3{ font-size:1.28rem; margin-top:2.2em; margin-bottom:.6em; display:flex; align-items:baseline; gap:10px; scroll-margin-top: 90px; }
.chapter-body h3 .num{ font-family:'JetBrains Mono',monospace; font-size:.62em; font-weight:600; color: var(--accent); background: var(--accent-tint); padding:2px 8px; border-radius:5px; }
.chapter-body ul{ padding-left: 1.3em; margin:0 0 1.3em; }
.chapter-body li{ margin-bottom:.55em; }
.chapter-body li strong{ color: var(--ink); }
.chapter-body p{ margin-bottom:1.2em; }

table.compare{ width:100%; border-collapse:collapse; margin: 1.6em 0 1.8em; font-family:'Space Grotesk',sans-serif; font-size:14.5px; border:1px solid var(--line); border-radius:10px; overflow:hidden; }
table.compare th{ background: var(--bg-sunken); text-align:left; padding:11px 14px; font-weight:600; border-bottom:1px solid var(--line); }
table.compare td{ padding:11px 14px; border-bottom:1px solid var(--line); border-top:none; color: var(--ink-soft); vertical-align:top; }
table.compare tr:last-child td{ border-bottom:none; }
table.compare tr:nth-child(even) td{ background: color-mix(in srgb, var(--bg-sunken) 40%, transparent); }

.callout{ background: var(--teal-tint); border:1px solid color-mix(in srgb, var(--teal) 30%, transparent); border-left:4px solid var(--teal); border-radius:10px; padding:18px 20px; margin: 1.8em 0; font-family:'Newsreader',serif; font-size:1.02rem; color: var(--ink-soft); }
.cl-label{ display:block; font-family:'JetBrains Mono',monospace; font-size:10.5px; text-transform:uppercase; letter-spacing:.08em; color: var(--teal); margin-bottom:8px; font-style:normal; }

/* On-this-page rail */
.otp-label{ font-family:'JetBrains Mono',monospace; font-size:10.5px; text-transform:uppercase; letter-spacing:.08em; color: var(--muted); margin-bottom:12px; }
.otp-list{ list-style:none; margin:0; padding:0; border-left:2px solid var(--line); }
.otp-list li a{ display:block; padding: 6px 0 6px 16px; margin-left:-2px; border-left:2px solid transparent; font-family:'Space Grotesk',sans-serif; font-size:13px; color: var(--muted); text-decoration:none; line-height:1.35; }
.otp-list li a:hover{ color: var(--ink); }
.otp-list li a.active{ color: var(--accent); border-left-color: var(--accent); font-weight:600; }

.chapter-footer-nav{ display:flex; gap:16px; padding: 44px 0 26px; border-top:1px solid var(--line); margin-top:40px; flex-wrap:wrap; }
.nav-card{ flex:1; min-width:220px; display:flex; flex-direction:column; gap:6px; padding:18px 20px; border:1px solid var(--line); border-radius:14px; text-decoration:none; color: var(--ink); background: var(--bg-raised); transition: border-color .15s ease, transform .15s ease; }
.nav-card:hover{ border-color: var(--accent); transform: translateY(-2px); }
.nav-card.next{ text-align:right; align-items:flex-end; }
.nav-card .dir{ font-family:'JetBrains Mono',monospace; font-size:10.5px; text-transform:uppercase; letter-spacing:.08em; color: var(--muted); display:flex; align-items:center; gap:6px; }
.nav-card .dir svg{ width:13px; height:13px; }
.nav-card .navtitle{ font-family:'Space Grotesk',sans-serif; font-weight:600; font-size:15px; }

.part-return{ text-align:center; padding: 10px 0 60px; }
.part-return a{ font-family:'Space Grotesk',sans-serif; font-size:13.5px; color: var(--muted); text-decoration:none; }
.part-return a:hover{ color: var(--accent); }

/* ---------- Footer ---------- */
.site-footer{ border-top:1px solid var(--line); background: var(--bg-raised); padding: 40px 0; margin-top:auto; }
.site-footer .container-wide{ display:flex; justify-content:space-between; align-items:center; gap:20px; flex-wrap:wrap; }
.footer-brand{ font-family:'Space Grotesk',sans-serif; font-weight:600; font-size:13.5px; }
.footer-brand .sub{ font-family:'JetBrains Mono',monospace; font-size:10.5px; color: var(--muted); margin-top:4px; }
.footer-links{ display:flex; gap:22px; font-family:'Space Grotesk',sans-serif; font-size:13px; color: var(--muted); }
.footer-links a{ text-decoration:none; color: var(--muted); }
.footer-links a:hover{ color: var(--accent); }

/* ---------- Motion: reveal on scroll ---------- */
.reveal{ opacity:0; transform: translateY(16px); transition: opacity .6s ease, transform .6s ease; }
.reveal.in{ opacity:1; transform: translateY(0); }

/* ---------- Print ---------- */
@media print{
  .topbar, .sidebar, .overlay, .compass, .search-overlay, .chapter-rail, .part-return, .site-footer, .hero-ctas, .diagram-wrap{ display:none !important; }
  body{ background:#fff; }
  .chapter-layout{ padding:0; }
}
