/* ============================================
   Checks & Balances in an Automated Society
   Design System — extends v1 with sidebar TOC
   ============================================ */

:root {
  /* Palette: warm parchment + deep civic green + terracotta */
  --bg: #F2EDE2;
  --bg-elevated: #FBF7EE;
  --bg-card: #FFFFFF;
  --bg-inverse: #1A2419;
  --bg-inverse-2: #243126;

  --ink: #14140F;
  --ink-2: #2A2A22;
  --ink-muted: #5C5A4F;
  --ink-faint: #8A8676;

  --rule: #DDD4C0;
  --rule-strong: #BDB39A;

  --accent: #1F3A2E;
  --accent-2: #2D5742;
  --warm: #B0552D;
  --warm-2: #C77B47;
  --highlight: #E8D9B8;
  --inverse-ink: #F2EDE2;
  --inverse-muted: #C9C3B0;

  --serif: "Source Serif 4", "Source Serif Pro", "EB Garamond", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, monospace;

  --maxw: 1320px;
  --gutter: clamp(20px, 4vw, 56px);
  --col-gap: clamp(24px, 3vw, 56px);

  /* sidebar */
  --sidebar-w: 260px;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  font-feature-settings: "ss01", "kern";
}
img { display: block; max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; text-decoration-color: rgba(31, 58, 46, 0.35); }
a:hover { color: var(--warm); text-decoration-color: var(--warm); }
button { font: inherit; cursor: pointer; }

/* ---------- typography ---------- */
.eyebrow {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--warm);
}
.eyebrow.muted { color: var(--ink-muted); }
.eyebrow.on-dark { color: var(--warm-2); }

h1, h2, h3, h4, h5 {
  font-family: var(--serif);
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin: 0;
}
h1 {
  font-size: clamp(36px, 5vw, 68px);
  line-height: 1.05;
  letter-spacing: -0.022em;
}
h2 {
  font-size: clamp(26px, 3vw, 40px);
  line-height: 1.12;
  letter-spacing: -0.015em;
}
h3 {
  font-size: clamp(20px, 2vw, 26px);
  line-height: 1.2;
}
h4 {
  font-size: 19px;
  font-weight: 500;
  color: var(--accent);
}
h5 {
  font-size: 16px;
  font-family: var(--sans);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
  text-transform: none;
}
p { margin: 0 0 1em 0; color: var(--ink-2); }
.lede { font-size: clamp(19px, 1.8vw, 23px); line-height: 1.5; color: var(--ink-2); }
.small { font-size: 14px; color: var(--ink-muted); }
.label {
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
  color: var(--ink-muted);
}
em { font-style: italic; }
strong { font-weight: 600; color: var(--ink); }

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

/* ---------- container ---------- */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}
.wrap-narrow {
  max-width: 820px;
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}
.wrap-form {
  max-width: 740px;
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(242, 237, 226, 0.92);
  backdrop-filter: saturate(120%) blur(10px);
  -webkit-backdrop-filter: saturate(120%) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  height: 68px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--accent);
  font-family: var(--serif);
  font-weight: 500;
  max-width: 480px;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 100%; height: 100%; }
.brand-name {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand-name strong {
  font-weight: 500;
  font-size: 15.5px;
  letter-spacing: -0.005em;
  color: var(--accent);
}
.brand-name span {
  font-family: var(--sans);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-muted);
  margin-top: 3px;
  font-weight: 500;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--sans);
}
.nav a {
  display: inline-block;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}
.nav a:hover { color: var(--accent); background: rgba(31, 58, 46, 0.06); }
.nav a.current {
  color: var(--accent);
  background: rgba(31, 58, 46, 0.08);
}
.nav-cta {
  margin-left: 10px;
  background: var(--accent);
  color: var(--bg) !important;
  padding: 10px 18px !important;
  border-radius: 999px;
}
.nav-cta:hover { background: var(--accent-2) !important; color: var(--bg) !important; }

.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
}

/* ---------- hero ---------- */
.hero {
  padding: clamp(48px, 7vw, 96px) 0 clamp(40px, 6vw, 72px);
  border-bottom: 1px solid var(--rule);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  inset: auto -10% -40% auto;
  width: 50%;
  height: 80%;
  background: radial-gradient(closest-side, rgba(176, 85, 45, 0.10), transparent 70%);
  pointer-events: none;
}
.hero h1 .em { color: var(--warm); font-style: italic; font-weight: 500; }
.hero-sub {
  font-size: clamp(18px, 1.6vw, 21px);
  color: var(--ink-muted);
  line-height: 1.5;
}
.hero-authors {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-top: 18px;
  font-weight: 500;
}
.hero-authors strong { color: var(--ink); font-weight: 600; }

/* ---------- layout w/ sidebar ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: clamp(32px, 4vw, 64px);
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 32px 0 32px;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.45;
  border-right: 1px solid var(--rule);
  padding-right: 18px;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 2px; }

.sidebar-title {
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 0 0 14px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
.sidebar-list { list-style: none; margin: 0; padding: 0; }
.sidebar-list li { margin: 0; }
.sidebar-list a {
  display: flex;
  gap: 10px;
  padding: 7px 10px 7px 12px;
  text-decoration: none;
  color: var(--ink-muted);
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  line-height: 1.35;
}
.sidebar-list a:hover {
  color: var(--accent);
  background: rgba(31, 58, 46, 0.04);
}
.sidebar-list a.active {
  color: var(--accent);
  border-left-color: var(--warm);
  font-weight: 600;
  background: rgba(176, 85, 45, 0.06);
}
.sidebar-list .pillar {
  padding: 0;
  margin-top: 4px;
  border-top: 1px dashed var(--rule);
}
.sidebar-list .pillar:first-child { border-top: none; margin-top: 0; }
.sidebar-list .pillar a {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14.5px;
  color: var(--accent);
  font-weight: 500;
  padding: 16px 10px 6px 0;
  margin-left: 0;
  letter-spacing: -0.005em;
  border-left: none;
  background: transparent;
  text-decoration: none;
}
.sidebar-list .pillar:first-child a { padding-top: 4px; }
.sidebar-list .pillar a:hover {
  color: var(--warm);
  background: transparent;
}
.sidebar-list .num {
  display: inline-block;
  min-width: 18px;
  color: var(--warm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.sidebar-list a.active .num { color: var(--warm); }

.sidebar-foot {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-foot a {
  font-size: 12.5px;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 4px;
}
.sidebar-foot a:hover { color: var(--warm); background: rgba(176, 85, 45, 0.06); }
.sidebar-foot a strong { color: var(--accent); }

/* main column */
.main {
  padding: 32px 0 80px;
  min-width: 0;
}

/* ---------- content sections (within main) ---------- */
.content section {
  padding: 32px 0 32px;
  border-top: 1px solid var(--rule);
  scroll-margin-top: 84px;
}
.content section:first-child { border-top: none; padding-top: 0; }
.content section.spacious { padding-top: 56px; padding-bottom: 24px; }

.pillar-banner {
  background: var(--accent);
  color: var(--bg);
  padding: 36px 36px 38px;
  margin: 32px 0 16px;
  scroll-margin-top: 84px;
  border-radius: 4px;
}
.pillar-banner .eyebrow { color: var(--warm-2); margin-bottom: 12px; display: block; }
.pillar-banner h2 { color: var(--bg); margin: 0; }
.pillar-banner p {
  color: var(--inverse-muted);
  margin: 14px 0 0;
  font-size: 17px;
  max-width: 680px;
}

.section-meta {
  display: flex;
  align-items: baseline;
  gap: 18px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.section-meta .sec-num {
  font-family: var(--serif);
  font-style: italic;
  font-size: 28px;
  color: var(--warm);
  line-height: 1;
  font-weight: 500;
}
.section-meta .sec-tag {
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-muted);
  font-weight: 600;
}
.content h2 { margin-bottom: 18px; }
.content h3 {
  margin: 36px 0 14px;
  color: var(--accent);
}
.content h4 {
  margin: 24px 0 10px;
  color: var(--accent);
  font-size: 18px;
  font-style: italic;
  font-weight: 500;
}
.content p { margin: 0 0 18px; }
.content > section > p:first-of-type { font-size: 19px; color: var(--ink-2); }

/* ---------- lists ---------- */
.content ul, .content ol {
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
}
.content ul > li {
  position: relative;
  padding-left: 22px;
  margin-bottom: 10px;
  color: var(--ink-2);
}
.content ul > li::before {
  content: "—";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--warm);
  font-weight: 500;
}
.content ul ul {
  margin-top: 10px;
  margin-bottom: 4px;
  padding-left: 6px;
}
.content ul ul > li::before {
  content: "·";
  font-size: 22px;
  line-height: 1;
  top: -3px;
}
.content ol {
  counter-reset: list-counter;
}
.content ol > li {
  counter-increment: list-counter;
  position: relative;
  padding-left: 30px;
  margin-bottom: 10px;
  color: var(--ink-2);
}
.content ol > li::before {
  content: counter(list-counter) ".";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--warm);
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
}

/* ---------- callout ---------- */
.callout {
  background: var(--highlight);
  border: 1px solid var(--rule-strong);
  padding: 24px 28px;
  margin: 22px 0;
  border-left: 4px solid var(--warm);
}
.callout p:last-child { margin-bottom: 0; }
.callout strong { color: var(--accent); }

/* ---------- figure ---------- */
figure {
  margin: 32px 0;
  padding: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
}
figure img {
  margin: 0 auto;
  max-height: 460px;
  object-fit: contain;
}
figcaption {
  margin-top: 16px;
  font-size: 14.5px;
  color: var(--ink-muted);
  font-style: italic;
  text-align: center;
  font-family: var(--serif);
  line-height: 1.5;
}

/* ---------- pull quote ---------- */
.pull {
  border-left: 3px solid var(--warm);
  padding: 6px 0 6px 26px;
  margin: 28px 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(20px, 1.9vw, 24px);
  line-height: 1.4;
  color: var(--accent);
  letter-spacing: -0.005em;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--bg);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: var(--accent-2); color: var(--bg); text-decoration: none; }
.btn.warm { background: var(--warm); color: #fff; }
.btn.warm:hover { background: var(--warm-2); color: #fff; }
.btn.ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--rule-strong);
}
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); background: rgba(31,58,46,0.04); }
.btn .arr { transform: translateY(-0.5px); transition: transform 0.15s ease; }
.btn:hover .arr { transform: translate(2px, -0.5px); }

/* ---------- footer ---------- */
footer {
  background: var(--bg-inverse);
  color: var(--inverse-ink);
  padding: 56px 0 32px;
  margin-top: 64px;
}
footer h4 {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--inverse-muted);
  margin-bottom: 14px;
  font-weight: 600;
}
.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 48px;
  margin-bottom: 36px;
}
.footer-grid a {
  display: block;
  color: var(--inverse-ink);
  text-decoration: none;
  padding: 5px 0;
  font-size: 14.5px;
}
.footer-grid a:hover { color: var(--warm-2); }
.footer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 26px;
  border-top: 1px solid rgba(242, 237, 226, 0.12);
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--inverse-muted);
  flex-wrap: wrap;
  gap: 16px;
}
.footer-brand {
  font-family: var(--serif);
  font-size: 21px;
  color: var(--inverse-ink);
  margin-bottom: 8px;
  line-height: 1.25;
}
.footer-tagline {
  color: var(--inverse-muted);
  font-size: 14.5px;
  max-width: 360px;
  line-height: 1.5;
}

/* ---------- form ---------- */
.form { display: grid; gap: 22px; }
.form-row { display: grid; gap: 22px; grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label {
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
  color: var(--ink-muted);
}
.field .help {
  font-family: var(--serif);
  font-size: 14.5px;
  color: var(--ink-muted);
  font-style: italic;
  margin-top: -2px;
}
.field .counter {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-muted);
  text-align: right;
  margin-top: -2px;
}
.field input, .field textarea, .field select {
  font-family: var(--serif);
  font-size: 17px;
  padding: 14px 16px;
  border: 1px solid var(--rule-strong);
  background: var(--bg-elevated);
  color: var(--ink);
  border-radius: 4px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.field textarea { resize: vertical; min-height: 140px; line-height: 1.55; }
.field textarea.large { min-height: 240px; }
.checkbox-line {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 16px;
  cursor: pointer;
  font-family: var(--serif);
  color: var(--ink-2);
}
.checkbox-line input { margin-top: 6px; flex-shrink: 0; }
.upload-box {
  border: 1.5px dashed var(--rule-strong);
  padding: 22px;
  text-align: center;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-muted);
  background: var(--bg-elevated);
  border-radius: 4px;
  cursor: pointer;
}
.upload-box:hover { border-color: var(--accent); color: var(--accent); }
.upload-box strong { color: var(--accent); font-weight: 600; }

/* ---------- timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline > li {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 28px;
  padding: 22px 0;
  border-top: 1px solid var(--rule);
}
.timeline > li::before { content: none; }
.timeline > li:last-child { border-bottom: 1px solid var(--rule); }
.timeline .tl-when {
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--warm);
  font-weight: 600;
  padding-top: 4px;
  padding-left: 0 !important;
}
.timeline .tl-when::before { content: none !important; }
.timeline h5 { margin-bottom: 6px; font-size: 18px; color: var(--accent); font-family: var(--serif); font-weight: 500; }
.timeline p { color: var(--ink-muted); margin: 0; font-size: 15.5px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  :root { --sidebar-w: 220px; }
  .sidebar { font-size: 12.5px; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .timeline > li { grid-template-columns: 1fr; gap: 6px; }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .sidebar {
    position: relative;
    top: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--rule);
    padding: 18px 0;
    margin-bottom: 24px;
  }
  .sidebar.collapsed .sidebar-inner { display: none; }
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: transparent;
    border: 1px solid var(--rule);
    padding: 10px 14px;
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    border-radius: 6px;
    margin-bottom: 12px;
  }
  .sidebar-toggle::after { content: "▾"; font-size: 11px; }
  .sidebar.collapsed .sidebar-toggle::after { transform: rotate(-90deg); display: inline-block; }
}
.sidebar-toggle { display: none; }

@media (max-width: 640px) {
  body { font-size: 17px; }
  .nav { display: none; }
  .nav.open {
    display: flex;
    position: absolute;
    top: 68px;
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
    flex-direction: column;
    padding: 12px var(--gutter);
    gap: 0;
  }
  .nav.open a { padding: 12px 0; border-bottom: 1px solid var(--rule); border-radius: 0; }
  .nav.open a:last-child { border-bottom: none; }
  .menu-toggle { display: inline-block; }
  .footer-grid { grid-template-columns: 1fr; gap: 28px; }
}
