/* Theme palette. color-scheme: light dark makes light-dark() follow the
   operating-system preference by default; the data-theme overrides below let
   the toggle force one scheme regardless of the system setting. */
:root {
  color-scheme: light dark;

  --bg:          light-dark(#ffffff, #0f141a);
  --sidebar-bg:  light-dark(#f7f8fa, #141a21);
  --border:      light-dark(#e3e6ea, #2a323d);
  --text:        light-dark(#1f2933, #d8dee6);
  --muted:       light-dark(#6b7682, #8c97a4);
  --accent:      light-dark(#2563eb, #6fa0ff);
  --lede:        light-dark(#3a4753, #a9b4bf);

  --surface:       light-dark(#ffffff, #1a212b);
  --surface-hover: light-dark(#eef1f5, #232c37);
  --nav-active-bg: light-dark(#eef4ff, #18243a);
  --row-border:    light-dark(#f0f1f3, #232a33);

  --do:          light-dark(#15803d, #56d97e);
  --do-bg:       light-dark(#f0fdf4, #11271a);
  --dont:        light-dark(#b91c1c, #f87171);
  --dont-bg:     light-dark(#fef2f2, #2a1517);
  --consider:    light-dark(#b45309, #f1b24a);
  --consider-bg: light-dark(#fffbeb, #2a2210);
  --never:       light-dark(#6d28d9, #c4b5fd);
  --never-bg:    light-dark(#f5f3ff, #1f1838);
  --ask:         light-dark(#6d28d9, #c4b5fd);
  --ask-bg:      light-dark(#f3e8ff, #251838);
  --avoid:       light-dark(#c2410c, #fb923c);
  --avoid-bg:    light-dark(#fff7ed, #2a1c10);

  --never-row-bg:     light-dark(#fef2f2, #2a1517);
  --never-row-border: light-dark(#fecaca, #5c2528);
  --always-row-bg:     light-dark(#f0fdf4, #11271a);
  --always-row-border: light-dark(#bbf7d0, #1f5236);

  --why-bg:     light-dark(#eff4ff, #15233c);
  --why-border: light-dark(#c7d7fe, #2d4470);
  --code-bg:    light-dark(#f3f4f6, #232a33);

  --danger:     light-dark(#dc2626, #f87171);
  --danger-bg:  light-dark(#fef2f2, #2a1517);

  --depth-bg:     light-dark(#fff7ed, #2a1c10);
  --depth-border: light-dark(#fed7aa, #5a3a1c);
  --depth-text:   light-dark(#9a3412, #fb923c);

  --maxw: 760px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  display: flex;
}

/* ---------- Light / dark theme toggle ---------- */
.theme-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 30;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: 0 1px 3px rgba(0,0,0,.10);
  cursor: pointer;
  padding: 0;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 18px; height: 18px; display: none; }
/* In light mode offer the moon (switch to dark); in dark mode offer the sun. */
.theme-toggle[data-mode="light"] .moon { display: block; }
.theme-toggle[data-mode="dark"]  .sun  { display: block; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 300px;
  flex: 0 0 300px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  padding: 28px 0 60px;
}

/* ---------- Hide / resize ---------- */
.sidebar-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
}
.sidebar-resizer:hover { background: rgba(37, 99, 235, .25); }
body.resizing { cursor: col-resize; user-select: none; }

body.sidebar-hidden .sidebar { display: none; }

/* docked hide button, top-right of the brand block */
.sidebar-hide {
  position: absolute;
  top: 22px;
  right: 14px;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  padding: 0;
}
.sidebar-hide:hover { color: var(--text); background: var(--surface-hover); }

/* floating show button, appears only when the menu is hidden */
.sidebar-toggle {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  cursor: pointer;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 0;
}
.sidebar-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; }
body.sidebar-hidden .sidebar-toggle { display: flex; }

.sidebar .brand {
  display: block;
  position: relative;
  padding: 0 24px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  color: inherit;
  text-decoration: none;
}
.sidebar a.brand:hover h1 { color: var(--accent); }
.sidebar .brand h1 {
  font-size: 16px;
  margin: 0;
  letter-spacing: .2px;
  transition: color .15s ease;
}
.sidebar .brand p {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0 0;
}

.nav-group { margin: 6px 0; }

/* Zero-Tolerance group — header looks normal; the red emphasis is on the page link.
   The group is always expanded, so its chevron is hidden. */
.nav-group.danger > button .chev { display: none; }
.nav-group.danger ul li a {
  color: var(--danger);
  font-weight: 600;
}
.nav-group.danger ul li a::before {
  content: "\26D4"; /* ⛔ */
  margin-right: 6px;
}
.nav-group.danger ul li a:hover { background: var(--danger-bg); }
.nav-group.danger ul li a.active {
  border-left-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
}

.nav-group > button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 24px 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-group > button .chev {
  transition: transform .15s ease;
  font-size: 10px;
}
.nav-group.collapsed > button .chev { transform: rotate(-90deg); }
.nav-group.collapsed ul { display: none; }

.nav-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-group ul li a {
  display: block;
  padding: 6px 24px 6px 32px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  border-left: 2px solid transparent;
}
.nav-group ul li a:hover { background: var(--surface-hover); }
.nav-group ul li a.active {
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  background: var(--nav-active-bg);
}

/* ---------- Content ---------- */
.content {
  flex: 1;
  padding: 56px 48px 120px;
  max-width: calc(var(--maxw) + 96px);
  /* Query container so before/after pairs can stack based on the real content
     width (which changes as the sidebar is resized), not the viewport. */
  container-type: inline-size;
}
.content .eyebrow {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}
.content h1 {
  font-size: 30px;
  margin: 0 0 16px;
  line-height: 1.25;
}
.content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.content a:hover { text-decoration: none; }
.content .lede {
  font-size: 18px;
  color: var(--lede);
  margin-bottom: 32px;
}
.content h2 {
  font-size: 21px;
  margin: 40px 0 12px;
  padding-top: 12px;
}

/* ---------- Rule list ---------- */
.rules { margin: 0; padding: 0; list-style: none; }
.rules li {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--row-border);
  align-items: baseline;
}
.tag {
  flex: 0 0 84px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 5px;
  text-align: center;
}
.tag.do { color: var(--do); background: var(--do-bg); }
.tag.dont { color: var(--dont); background: var(--dont-bg); }
.tag.consider { color: var(--consider); background: var(--consider-bg); }
/* Ask = a prompt to reflect. Purple, distinct from the do/consider greens. */
.tag.ask { color: var(--ask); background: var(--ask-bg); }
/* Avoid = the soft negative (mirror of Consider). Orange — discourage, with
   room for justified exceptions; weaker than Do not's red and Never's alarm. */
.tag.avoid { color: var(--avoid); background: var(--avoid-bg); }

/* Always = hard requirement. Solid green, white text — the positive mirror of Never. */
.tag.always {
  color: #fff;
  background: #16a34a;
  box-shadow: 0 0 0 1px #15803d inset;
  letter-spacing: .8px;
}
/* Never = hard stop. Solid red, white text, louder than everything else. */
.tag.never {
  color: #fff;
  background: #dc2626;
  box-shadow: 0 0 0 1px #991b1b inset;
  letter-spacing: .8px;
}
/* Zero-Tolerance chip — wider to fit the longer label */
.tag.zt { flex-basis: 124px; }

/* make the whole row of a Never rule read as a warning */
.rules li:has(.tag.never) {
  background: var(--never-row-bg);
  border-bottom-color: var(--never-row-border);
  border-radius: 6px;
  padding-left: 10px;
  margin: 2px 0;
}
/* make the whole row of an Always rule read as a firm positive */
.rules li:has(.tag.always) {
  background: var(--always-row-bg);
  border-bottom-color: var(--always-row-border);
  border-radius: 6px;
  padding-left: 10px;
  margin: 2px 0;
}

.example {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 16px 16px;
  margin: 16px 0;
  font-size: 14px;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.example .label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  display: block;
  margin-bottom: 8px;
}
code { font-family: "SF Mono", Consolas, monospace; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: 90%; }

/* The example's main code is a proper block: dark editor-style panel,
   monospace, comfortable line height. <br> in the source becomes real lines.
   It stays dark in both themes by design (an editor surface). */
.example > code {
  display: block;
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.7;
  white-space: normal;
  overflow-x: auto;
  border: 1px solid #1e293b;
}
.example > code .cmt { color: #7c8aa5; font-style: italic; }
/* the explanatory note under the code */
.example > p { color: var(--text); font-size: 13.5px; }
.example p code { background: var(--code-bg); }

/* Before/after pairs — an anti-pattern and its fix shown side by side.
   A bad example tagged "variant":"bad" next to a "good" one is grouped by
   the renderer into .example-pair; the cards stack when the column is narrow. */
.example-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
  align-items: start;
}
.example-pair .example { margin: 0; height: 100%; }
@container (max-width: 620px) {
  .example-pair { grid-template-columns: 1fr; }
}
.example.bad  { border-top: 3px solid var(--dont); }
.example.good { border-top: 3px solid var(--do); }
.example.bad  .label { color: var(--dont); }
.example.good .label { color: var(--do); }
.example.bad  .label::before { content: "\2717\00a0"; }  /* ✗ */
.example.good .label::before { content: "\2713\00a0"; }  /* ✓ */

/* Why it matters — the takeaway. Made prominent: accent band, left bar, label. */
.why {
  margin-top: 40px;
  padding: 18px 22px 18px 24px;
  background: var(--why-bg);
  border: 1px solid var(--why-border);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  font-size: 15.5px;
  line-height: 1.7;
}
.why strong { color: var(--accent); }

/* Book-style previous / next footer. Two cards spanning the content width;
   prev sits left, next right (a spacer holds the slot when one end is missing). */
.pagenav {
  display: flex;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.pagenav a {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, background .15s;
}
.pagenav a:hover { border-color: var(--accent); background: var(--surface-hover); }
.pagenav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pagenav .pn-spacer { flex: 1 1 0; }
.pagenav .pn-next { justify-content: flex-end; text-align: right; }
.pagenav .pn-arrow { font-size: 20px; color: var(--muted); line-height: 1; }
.pagenav a:hover .pn-arrow { color: var(--accent); }
.pagenav .pn-text { display: flex; flex-direction: column; min-width: 0; }
.pagenav .pn-dir {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); margin-bottom: 2px;
}
.pagenav .pn-title { font-size: 15px; font-weight: 600; }
@media (max-width: 560px) {
  .pagenav { flex-direction: column; }
}

/* Experience-level filter (sidebar) — a slider over the ordered scale
   All → Foundational → Intermediate → Advanced. Sized to stay readable even
   when the sidebar is dragged down to its minimum width. */
.levelfilter { padding: 0 16px 16px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.levelfilter .lf-label {
  display: block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--muted); margin: 0 0 8px;
}
.levelfilter .lf-label .lf-cur { color: var(--accent); }
.lf-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; margin: 0; padding: 0;
  background: var(--border); border-radius: 999px; cursor: pointer;
  accent-color: var(--accent);
}
.lf-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.25); cursor: pointer; margin-top: -6px;
}
.lf-range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.25); cursor: pointer;
}
.lf-range:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.lf-scale {
  display: flex; justify-content: space-between; gap: 2px;
  margin-top: 6px; font-size: 9.5px; font-weight: 600; letter-spacing: .2px;
  color: var(--muted);
}
.lf-scale span { cursor: pointer; white-space: nowrap; }
.lf-scale span:hover { color: var(--accent); }
.lf-scale span.on { color: var(--accent); }

/* Per-topic level badge (topic page header) */
.levelbadge {
  display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; padding: 3px 10px; border-radius: 999px; margin: -4px 0 18px;
}
.levelbadge.lvl-foundational { color: var(--do); background: var(--do-bg); }
.levelbadge.lvl-intermediate { color: var(--consider); background: var(--consider-bg); }
.levelbadge.lvl-advanced     { color: var(--never); background: var(--never-bg); }

/* Command legend on the index page */
.legend { border-collapse: separate; border-spacing: 0; width: 100%; margin: 14px 0 8px; }
.legend td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 14.5px;
}
.legend tr:last-child td { border-bottom: none; }
.legend td:first-child { width: 96px; white-space: nowrap; }
.legend .tag { display: inline-block; }
.legend .eg { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; }
.legend .eg em { color: var(--text); font-style: italic; }

/* Reference tables (e.g. the HTTP status code list) */
.codes { width: 100%; border-collapse: separate; border-spacing: 0; margin: 6px 0 4px; font-size: 14.5px; }
.codes th, .codes td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.codes th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.codes td:first-child { white-space: nowrap; font-weight: 600; color: var(--accent); }
.codes tr:last-child td { border-bottom: none; }
.codes .cls { font-variant-numeric: tabular-nums; }

.depthbar {
  background: var(--depth-bg);
  border: 1px solid var(--depth-border);
  color: var(--depth-text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 28px;
}

/* Print: drop the navigation chrome and show only the content. */
@media print {
  .sidebar,
  .theme-toggle,
  .sidebar-hide,
  .levelfilter { display: none !important; }

  .content {
    flex: none;
    max-width: none;
    width: 100%;
    padding: 24px;
  }

  /* Keep the bright Never/Always tags in colour when printing. */
  .tag.never,
  .tag.always {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
