/* ============================================================
   DCN from first principles — design system
   Dark, documentation-grade. One accent. Depth via borders.
   ============================================================ */

:root {
  --bg: #0a0d12;
  --bg2: #0d1117;
  --panel: #10151d;
  --panel2: #141a24;
  --inset: #0a0e14;
  --border: rgba(255,255,255,.07);
  --border2: rgba(255,255,255,.14);
  --text: #e6ecf3;
  --muted: #96a1b2;
  --faint: #5d6878;
  --accent: #33d6bd;
  --accent-ink: #062a26;
  --accent-dim: rgba(51,214,189,.13);
  --blue: #5b9cf6;
  --amber: #e0a458;
  --red: #e35d55;
  --violet: #a78bfa;
  --green: #7bd88f;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --head: 'Space Grotesk', 'Instrument Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 264px;
  --content-w: 760px;
  --content-max: 1000px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(51,214,189,.28); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

code, .mono {
  font-family: var(--mono);
  font-size: .86em;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .08em .35em;
  color: #cfe6e0;
  white-space: nowrap;
}
pre {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
}
pre code { background: none; border: none; padding: 0; white-space: pre; color: #b7c3d2; }

/* ---------- layout ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg2);
  scrollbar-width: thin;
  scrollbar-color: #2a323e transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: #232a34; border-radius: 4px; }

.sidebar-inner { padding: 20px 14px 40px; }

.brand {
  display: block;
  padding: 6px 10px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.brand-title {
  font-family: var(--head);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.2px;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand-title .tick { color: var(--accent); font-family: var(--mono); font-size: 13px; }
.brand-sub {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--faint);
  margin-top: 3px;
}

.nav-part {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--faint);
  padding: 16px 10px 5px;
}
.nav-link {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.4;
  cursor: pointer;
  border-left: 2px solid transparent;
}
.nav-link .n {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  min-width: 16px;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,.03); text-decoration: none; }
.nav-link.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-left-color: var(--accent);
}
.nav-link.active .n { color: var(--accent); }
.nav-link .read { color: var(--faint); font-size: 9px; margin-left: auto; }
.nav-link .read.on { color: var(--accent); }

.content {
  flex: 1;
  min-width: 0;
  padding: 48px 48px 120px;
  max-width: calc(var(--sidebar-w) + var(--content-max) + 96px);
}

.main-col { max-width: var(--content-w); margin: 0 auto; }
section.chapter { padding-top: 26px; margin-bottom: 84px; }

/* topbar for mobile */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(10,13,18,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  align-items: center;
  gap: 12px;
}
.topbar .brand-title { font-size: 14px; border: none; margin: 0; padding: 0; }
.topbar button {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}

/* ---------- typography ---------- */

.kicker {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .18em;
  color: var(--accent);
  margin: 0 0 10px;
}
.kicker .dim { color: var(--faint); }

h1 {
  font-family: var(--head);
  font-size: clamp(21px, 2.4vw, 26px);
  font-weight: 600;
  letter-spacing: -0.4px;
  line-height: 1.25;
  margin: 0 0 6px;
  color: var(--text);
}
.lede {
  font-size: 16.5px;
  color: var(--muted);
  line-height: 1.6;
  margin: 6px 0 8px;
  max-width: 64ch;
}

h2 {
  font-family: var(--head);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.2px;
  margin: 40px 0 10px;
  padding-top: 8px;
}
h2 .hnum { font-family: var(--mono); font-size: 11px; color: var(--faint); font-weight: 400; margin-right: 8px; }
h3 {
  font-family: var(--head);
  font-size: 15px;
  font-weight: 600;
  margin: 26px 0 8px;
}

p { margin: 12px 0; max-width: 70ch; }
p.tight, li.tight { margin: 6px 0; }

ul, ol { padding-left: 24px; margin: 12px 0; }
li { margin: 5px 0; max-width: 68ch; }
li::marker { color: var(--faint); }

strong { color: #f2f6fa; font-weight: 600; }
em { color: var(--muted); }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 40px 0;
}

.small { font-size: 13px; color: var(--muted); }

/* ---------- callouts ---------- */

.callout {
  border: 1px solid var(--border2);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px 16px 10px;
  margin: 20px 0;
}
.callout .co-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted);
  background: var(--inset);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.callout p { margin: 6px 0; font-size: 14.5px; }
.callout p:last-child { margin-bottom: 2px; }
.callout.key .co-label { color: var(--accent); border-color: rgba(51,214,189,.35); }
.callout.fail .co-label { color: var(--amber); border-color: rgba(224,164,88,.4); }
.callout.doit .co-label { color: var(--blue); border-color: rgba(91,156,246,.4); }
.callout.warn .co-label { color: var(--red); border-color: rgba(227,93,85,.4); }

/* ---------- tables ---------- */

.tbl-wrap { overflow-x: auto; margin: 18px 0; border: 1px solid var(--border); border-radius: 8px; }
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--panel);
  min-width: 480px;
}
table.tbl th {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
  text-align: left;
  color: var(--faint);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border2);
  background: var(--inset);
  white-space: nowrap;
}
table.tbl td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.tbl tr:last-child td { border-bottom: none; }
table.tbl td.num, table.tbl th.num { text-align: right; font-family: var(--mono); font-size: 12px; }
table.tbl tr.hl td { background: rgba(51,214,189,.06); }

/* ---------- sims ---------- */

figure.sim {
  margin: 26px 0;
  border: 1px solid var(--border2);
  border-radius: 10px;
  background: var(--panel);
  overflow: hidden;
}
.sim-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .15em;
  color: var(--muted);
}
.sim-title .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
.sim-title .spacer { margin-left: auto; }
.sim-live {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); border: 1px solid rgba(51,214,189,.35); border-radius: 999px; padding: 1px 8px;
}
.sim-root { padding: 0; }
.sim canvas { display: block; width: 100%; }

.sim-cap {
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.55;
}
.sim-cap b { color: var(--text); font-weight: 600; }

.sim-stage { position: relative; }
.sim-hud {
  position: absolute;
  top: 8px; left: 10px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  letter-spacing: .06em;
  pointer-events: none;
  line-height: 1.6;
}
.sim-hud b { color: var(--muted); font-weight: 500; }

/* sim controls */
.sim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  background: var(--inset);
}
.sim-controls .sep { width: 1px; height: 18px; background: var(--border2); margin: 0 4px; }
.sim-controls .label {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .1em; color: var(--faint); margin-right: 2px;
}
.sim-controls .grow { flex: 1; }

button.sbtn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--muted);
  background: var(--panel2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
  white-space: nowrap;
}
button.sbtn:hover { color: var(--text); border-color: rgba(255,255,255,.25); }
button.sbtn:focus-visible, button.sbtn:focus { outline: 1px solid var(--accent); outline-offset: 1px; }
button.sbtn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.sbtn.primary:hover { filter: brightness(1.08); }
button.sbtn.danger { color: var(--red); border-color: rgba(227,93,85,.45); }
button.sbtn.danger:hover { color: #ff8d85; }
button.sbtn[aria-pressed="true"] { color: var(--accent); border-color: rgba(51,214,189,.5); background: var(--accent-dim); }
button.sbtn:disabled { opacity: .45; cursor: default; }

.toggle-row { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.toggle-row input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; }

.slider-row { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.slider-row input[type=range] { width: 110px; accent-color: var(--accent); }
.slider-row .val { font-family: var(--mono); font-size: 11px; color: var(--text); min-width: 52px; }

select.ssel {
  font-family: var(--mono); font-size: 11px; color: var(--text);
  background: var(--panel2); border: 1px solid var(--border2);
  border-radius: 6px; padding: 4px 8px; cursor: pointer;
}
input.stxt {
  font-family: var(--mono); font-size: 11.5px; color: var(--text);
  background: var(--inset); border: 1px solid var(--border2);
  border-radius: 6px; padding: 5px 8px; width: 100%;
}
input.stxt:focus { outline: 1px solid var(--accent); outline-offset: 0; }

/* sim log */
.sim-logwrap {
  border-top: 1px solid var(--border);
  background: var(--inset);
  max-height: 148px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #2a323e transparent;
}
.sim-log { font-family: var(--mono); font-size: 11px; line-height: 1.7; padding: 6px 12px; }
.sim-log .ln { display: flex; gap: 10px; }
.sim-log .t { color: var(--faint); flex: none; min-width: 52px; }
.sim-log .m { color: var(--muted); }
.sim-log .m b { color: var(--text); font-weight: 500; }
.sim-log .ln.ev-warn .m { color: var(--amber); }
.sim-log .ln.ev-bad .m { color: var(--red); }
.sim-log .ln.ev-good .m { color: var(--green); }
.sim-log .ln.ev-ctrl .m { color: var(--blue); }

/* terminal (incident sim) */
.sim-term {
  background: #070a0e;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  padding: 10px 14px;
  min-height: 320px;
  max-height: 420px;
  overflow-y: auto;
}
.sim-term .tline { white-space: pre-wrap; word-break: break-word; }
.sim-term .prompt { color: var(--accent); }
.sim-term .out { color: #b7c3d2; }
.sim-term .err { color: var(--red); }
.sim-term .hintline { color: var(--faint); }
.sim-term input {
  background: none; border: none; outline: none; color: var(--text);
  font: inherit; width: 70%; caret-color: var(--accent);
}

/* chapter footer nav */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 10px;
}
.chapter-nav a {
  color: var(--muted); font-size: 13px; max-width: 46%;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
}
.chapter-nav a:hover { color: var(--text); border-color: var(--border2); text-decoration: none; }
.chapter-nav a .dir { font-family: var(--mono); font-size: 10px; color: var(--faint); display: block; letter-spacing: .12em; text-transform: uppercase; }
.chapter-nav a.next { text-align: right; margin-left: auto; }

/* index page */
.index-hero { padding: 8px 0 6px; }
.index-hero h1 { font-size: clamp(24px, 3vw, 32px); line-height: 1.2; }
.course-index { margin-top: 28px; }
.course-row {
  display: flex; gap: 14px; padding: 9px 12px; border-radius: 8px;
  color: var(--muted); align-items: baseline;
}
.course-row:hover { background: rgba(255,255,255,.03); color: var(--text); text-decoration: none; }
.course-row .cn { font-family: var(--mono); font-size: 11px; color: var(--faint); min-width: 20px; }
.course-row .ct { color: var(--text); font-weight: 500; font-size: 14.5px; }
.course-row .cd { font-size: 12.5px; color: var(--faint); }
.course-row:hover .cn { color: var(--accent); }

/* glossary */
.gloss-filter { margin: 14px 0 6px; }
.gloss-group-label {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .16em; color: var(--faint); margin: 18px 0 4px;
}
.gloss-term { border-bottom: 1px solid var(--border); padding: 8px 2px 10px; }
.gloss-term dt { font-weight: 600; font-size: 14px; color: var(--text); }
.gloss-term dt .mono { color: var(--accent); }
.gloss-term dd { margin: 4px 0 0; font-size: 13.5px; color: var(--muted); }

/* misc */
.pill {
  display: inline-block; font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted); border: 1px solid var(--border2);
  border-radius: 999px; padding: 1px 8px; vertical-align: 2px;
}
.pill.p-acc { color: var(--accent); border-color: rgba(51,214,189,.4); }
.pill.p-amb { color: var(--amber); border-color: rgba(224,164,88,.4); }
.pill.p-red { color: var(--red); border-color: rgba(227,93,85,.4); }

.footnote { font-size: 12.5px; color: var(--faint); border-top: 1px solid var(--border); padding-top: 14px; margin-top: 30px; line-height: 1.6; }

/* responsive */
@media (max-width: 1120px) {
  .content { padding: 40px 28px 100px; }
}
@media (max-width: 860px) {
  .topbar { display: flex; }
  .shell { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.5); width: 280px; flex-basis: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 28px 16px 90px; }
  .main-col { max-width: none; }
  .slider-row input[type=range] { width: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
  button.sbtn { transition: none; }
}

/* keyboard hint */
.kbd {
  font-family: var(--mono); font-size: 10.5px; color: var(--faint);
  border: 1px solid var(--border2); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px;
}
