/* Machine Civilization Institute — Countdown to the Machine Age (/countdown)
   One linear page, one idea per section. White paper, EB Garamond throughout,
   IBM Plex Mono for exact measurements, red chalk for Fourth-Order signals. */

:root {
  --paper: #ffffff;
  --surface: #faf9f6;
  --tint: #f3f1ec;
  --ink: #1d1d1b;
  --ink-2: #5d5a55;
  --ink-3: #7d7972;
  --head: #111110;
  --chalk: #9a3322;
  --chalk-soft: rgba(154, 51, 34, 0.09);
  --bio: #265c4e;
  --bio-soft: rgba(38, 92, 78, 0.09);
  --slate: #35526b;
  --ochre: #876026;
  --rule: rgba(17, 17, 16, 0.16);
  --rule-faint: rgba(17, 17, 16, 0.08);
  --serif: "EB Garamond", Garamond, "Iowan Old Style", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --bar-h: 54px;
  --measure: 40rem;
  --stage: 54rem;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--bar-h) + 24px);
}
html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.08rem, 1.02rem + 0.24vw, 1.2rem);
  line-height: 1.62;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--chalk); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
:focus-visible { outline: 1.5px solid var(--chalk); outline-offset: 3px; }
::selection { background: rgba(154, 51, 34, 0.14); }

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- Sticky Top Bar (matches mechciv.org) ---------- */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 0.45rem clamp(16px, 3vw, 28px);
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.brand {
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.88rem;
  letter-spacing: 0.14em;
  color: var(--head);
  white-space: nowrap;
}
.brand:hover { color: var(--chalk); text-decoration: none; }

.top-nav {
  display: flex;
  align-items: center;
  gap: 0.2rem 1.35rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.top-nav::-webkit-scrollbar { display: none; }
.top-nav a {
  color: var(--ink-2);
  font-size: 0.96rem;
  white-space: nowrap;
  padding: 0.18rem 0;
  border-bottom: 1.5px solid transparent;
  transition: color 0.18s ease, border-color 0.18s ease;
}
.top-nav a:hover,
.top-nav a[aria-current="true"] {
  color: var(--chalk);
  text-decoration: none;
  border-bottom-color: var(--chalk);
}

/* ---------- Column Containers ---------- */
.page-wrap {
  max-width: calc(var(--stage) + 4rem);
  margin: 0 auto;
  padding: 0 clamp(18px, 4vw, 32px);
}

.prose {
  max-width: var(--measure);
  margin-inline: auto;
}

.stage {
  max-width: var(--stage);
  margin-inline: auto;
}

/* ---------- Hero & The Big Clock ---------- */
.hero {
  padding: clamp(1.8rem, 4.5vh, 3.2rem) 0 clamp(2.8rem, 6vh, 4.5rem);
  text-align: center;
}

.rule-heavy { height: 2px; background: var(--head); max-width: var(--stage); margin: 0 auto; }
.rule-thin { height: 1px; background: var(--rule); max-width: var(--stage); margin: 0 auto; }

.kicker {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--chalk);
}

.hero-kicker {
  margin-top: 1.35rem;
}

.hero h1 {
  margin: 0 0 0.7rem;
  font-weight: 600;
  font-size: clamp(2.25rem, 1.35rem + 3vw, 3.55rem);
  line-height: 1.06;
  color: var(--head);
  text-wrap: balance;
}

.hero-sub {
  max-width: 37rem;
  margin: 0 auto 1.4rem;
  color: var(--ink-2);
  font-size: clamp(1.06rem, 0.98rem + 0.24vw, 1.2rem);
  line-height: 1.54;
}

/* Clock centerpiece */
.clock-block {
  max-width: 44rem;
  margin: 0 auto 1.6rem;
  padding: 0.6rem 0 0.4rem;
}

.clock-dial-wrap {
  max-width: 32rem;
  margin: 0 auto 0.35rem;
}
.clock-dial-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.clock-readout {
  display: flex;
  justify-content: center;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.3rem clamp(1rem, 3vw, 2.2rem);
  margin: 0.55rem 0 0.45rem;
}

.clock-unit {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
}
.clock-num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.3rem, 1.4rem + 3.2vw, 3.85rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--head);
}
.clock-num.is-accent { color: var(--chalk); }
.clock-lbl {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

.clock-hms {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin: 0 0 1.35rem;
}

.clock-caption {
  font-size: 0.96rem;
  font-style: italic;
  color: var(--ink-2);
  max-width: 34rem;
  margin: 0 auto 1.25rem;
}

.pace-switch {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
  padding: 3px;
  background: var(--tint);
  border: 1px solid var(--rule);
  border-radius: 3px;
}

.pace-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-2);
  padding: 0.34rem 0.72rem;
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.pace-btn:hover { color: var(--head); }
.pace-btn[aria-pressed="true"] {
  background: var(--paper);
  color: var(--head);
  box-shadow: 0 1px 2px rgba(17, 17, 16, 0.1);
}

/* Three quiet signal anchors beneath the clock */
.signal-strip {
  max-width: var(--stage);
  margin: 2.6rem auto 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.signal-item {
  padding: 1.15rem 1.25rem;
  text-align: left;
  color: inherit;
  border-right: 1px solid var(--rule-faint);
  transition: background 0.16s ease;
}
.signal-item:last-child { border-right: 0; }
.signal-item:hover { background: var(--surface); text-decoration: none; }

.signal-step {
  display: block;
  font-family: var(--mono);
  font-size: 0.67rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 0.25rem;
}
.signal-stat {
  display: block;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.38rem;
  font-weight: 500;
  color: var(--head);
  line-height: 1.15;
}
.signal-stat.is-chalk { color: var(--chalk); }
.signal-note {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.92rem;
  color: var(--ink-2);
  line-height: 1.35;
}

/* ---------- Linear Narrative Chapters ---------- */
.chapter {
  padding: clamp(4rem, 10vh, 7.2rem) 0;
  border-top: 1px solid var(--rule);
}

.chapter-head {
  max-width: var(--measure);
  margin: 0 auto 2.4rem;
}

.chapter-head h2 {
  margin: 0 0 0.85rem;
  font-weight: 600;
  font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.45rem);
  line-height: 1.13;
  color: var(--head);
  text-wrap: balance;
}

.chapter-head p {
  margin: 0 0 0.9rem;
  color: var(--ink);
}
.chapter-head p:last-child { margin-bottom: 0; }

.figure-block {
  max-width: var(--stage);
  margin: 0 auto 2rem;
}

.figure-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem 1.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--rule-faint);
}

.figure-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--head);
}

.figure-kicker-val {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--chalk);
}

.chart-canvas {
  width: 100%;
  position: relative;
}
.chart-canvas svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.figure-caption {
  margin: 0.85rem 0 0;
  font-size: 0.92rem;
  color: var(--ink-2);
  max-width: 44rem;
}

/* ---------- Chapter II: Linear 6-Stage Knowledge Engine Pipeline ---------- */
.ke-pipeline {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.ke-zone-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding-top: 0.5rem;
}
.ke-zone-label.is-gap {
  color: var(--chalk);
  border-top: 1px dashed rgba(154, 51, 34, 0.35);
  margin-top: 0.45rem;
  padding-top: 1rem;
}

.ke-row {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 12.5rem) minmax(0, 1fr) 3.4rem;
  gap: 0.8rem 1rem;
  align-items: center;
}

.ke-sym {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--head);
  text-align: center;
}
.ke-row.is-physical .ke-sym { color: var(--chalk); }

.ke-label strong {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--head);
  line-height: 1.2;
}
.ke-label span {
  display: block;
  font-size: 0.86rem;
  color: var(--ink-2);
  line-height: 1.32;
  margin-top: 0.12rem;
}

.ke-track {
  height: 12px;
  background: var(--tint);
  position: relative;
}
.ke-fill {
  height: 100%;
  background: var(--bio);
  transition: width 0.35s ease;
}
.ke-row.is-transition .ke-fill { background: var(--ochre); }
.ke-row.is-physical .ke-fill { background: var(--chalk); }

.ke-pct {
  font-family: var(--mono);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: right;
  color: var(--head);
}
.ke-row.is-physical .ke-pct { color: var(--chalk); }

/* Foresight Proof Strip inside Chapter II */
.sub-block {
  max-width: var(--stage);
  margin: 3rem auto 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule-faint);
}

.sub-block-head {
  max-width: var(--measure);
  margin: 0 auto 1.6rem;
}
.sub-block-head h3 {
  margin: 0 0 0.45rem;
  font-size: 1.32rem;
  font-weight: 600;
  color: var(--head);
}
.sub-block-head p {
  margin: 0;
  color: var(--ink-2);
}

.foresight-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--rule);
}

.foresight-row {
  display: grid;
  grid-template-columns: minmax(0, 11.5rem) minmax(0, 11rem) minmax(0, 1fr);
  gap: 0.65rem 1.4rem;
  padding: 1.05rem 0;
  border-bottom: 1px solid var(--rule-faint);
  align-items: baseline;
}
.foresight-row:last-child { border-bottom-color: var(--rule); }

.f-domain {
  font-weight: 600;
  color: var(--head);
  font-size: 1.02rem;
}
.f-sys {
  display: block;
  font-family: var(--mono);
  font-size: 0.69rem;
  color: var(--ink-3);
  margin-top: 0.15rem;
}

.f-jump {
  font-family: var(--mono);
  font-size: 0.92rem;
  color: var(--head);
  white-space: nowrap;
}
.f-jump .arrow { color: var(--ink-3); margin: 0 0.3rem; }
.f-jump strong { color: var(--chalk); font-weight: 600; }
.f-lift {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--bio);
  margin-top: 0.15rem;
}

.f-note {
  font-size: 0.94rem;
  color: var(--ink-2);
  line-height: 1.48;
}

/* ---------- Chapter III: The Monoculture Wedge ---------- */
.wedge-wrap {
  position: relative;
}

.wedge-callout {
  max-width: var(--measure);
  margin: 2rem auto 0;
  padding: 1.05rem 1.3rem;
  background: var(--surface);
  border-left: 2.5px solid var(--chalk);
  font-size: 0.98rem;
  color: var(--ink);
}
.wedge-callout strong { color: var(--head); }

/* ---------- Clean Collapsible Explainers (<details>) ---------- */
.explainer {
  max-width: var(--stage);
  margin: 1.8rem auto 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.explainer summary {
  list-style: none;
  cursor: pointer;
  padding: 0.95rem 0.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  color: var(--ink-2);
  user-select: none;
  transition: color 0.15s ease;
}
.explainer summary::-webkit-details-marker { display: none; }
.explainer summary:hover { color: var(--chalk); }
.explainer summary::after {
  content: "+";
  font-size: 1rem;
  line-height: 1;
  color: var(--chalk);
}
.explainer[open] summary::after { content: "−"; }

.explainer-body {
  padding: 0.35rem 0 1.65rem;
  border-top: 1px solid var(--rule-faint);
  font-size: 0.96rem;
  color: var(--ink-2);
}
.explainer-body p {
  max-width: var(--measure);
  margin: 0.85rem 0;
}
.explainer-body h4 {
  margin: 1.35rem 0 0.45rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--head);
}

.explainer-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1.25rem;
  margin: 0.9rem 0 0.6rem;
}

.btn-subtle {
  appearance: none;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.34rem 0.68rem;
  font-family: var(--mono);
  font-size: 0.71rem;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.btn-subtle:hover { border-color: var(--ink); color: var(--head); text-decoration: none; }
.btn-subtle[aria-pressed="true"] {
  background: var(--head);
  color: #ffffff;
  border-color: var(--head);
}

/* Clean Archival Tables inside Explainers */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.75rem;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.89rem;
}
.data-table th {
  text-align: left;
  font-family: var(--mono);
  font-size: 0.67rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  padding: 0.55rem 0.65rem 0.55rem 0;
  border-bottom: 1.5px solid var(--head);
  white-space: nowrap;
}
.data-table td {
  padding: 0.6rem 0.65rem 0.6rem 0;
  border-bottom: 1px solid var(--rule-faint);
  vertical-align: top;
  color: var(--ink);
}
.data-table tbody tr:last-child td { border-bottom: 1px solid var(--rule); }

/* ---------- Closing Coda: Five Invariants Ledger & Sources ---------- */
.invariants-ledger {
  max-width: var(--stage);
  margin: 0 auto;
  border-top: 1px solid var(--rule);
}

.inv-row {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 15.5rem) 10.5rem minmax(0, 1fr);
  gap: 0.45rem 1.2rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--rule-faint);
  align-items: baseline;
}
.inv-row:last-child { border-bottom-color: var(--rule); }
.inv-num {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--chalk);
}
.inv-name { font-weight: 600; color: var(--head); }
.inv-status {
  font-family: var(--mono);
  font-size: 0.73rem;
  color: var(--chalk);
  white-space: nowrap;
}
.inv-status.is-mid { color: var(--ochre); }
.inv-note { font-size: 0.93rem; color: var(--ink-2); }

.sources-list {
  list-style: none;
  margin: 1rem 0 1.4rem;
  padding: 0;
  max-width: var(--measure);
}
.sources-list li {
  padding: 0.35rem 0;
  font-size: 0.94rem;
  border-bottom: 1px solid var(--rule-faint);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1.2rem;
}

/* ---------- Colophon ---------- */
.colophon {
  max-width: var(--stage);
  margin: 0 auto;
  padding: 1.6rem 0 4.5rem;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem 1.5rem;
  font-size: 0.92rem;
  color: var(--ink-2);
}

/* ---------- SVG Typography ---------- */
.svg-axis { font-family: var(--mono); font-size: 11px; fill: var(--ink-3); }
.svg-grid { stroke: rgba(17, 17, 16, 0.09); stroke-width: 1; }
.svg-baseline { stroke: rgba(17, 17, 16, 0.38); stroke-width: 1; }
.svg-annot { font-family: var(--mono); font-size: 11px; fill: var(--ink); }
.svg-bar-label { font-family: var(--mono); font-size: 11px; font-weight: 600; fill: #ffffff; }
.svg-chalk { fill: var(--chalk); font-weight: 600; }
.svg-bio { fill: var(--bio); font-weight: 600; }
.svg-halo {
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4.5px;
  stroke-linejoin: round;
}

/* ---------- Floating Hover Tooltip ---------- */
.chart-tip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  max-width: 260px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--ink-2);
  box-shadow: 0 10px 28px -14px rgba(17, 17, 16, 0.35);
  padding: 0.6rem 0.78rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.chart-tip.visible { opacity: 1; }
.tip-head {
  font-family: var(--mono);
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--head);
  margin-bottom: 0.25rem;
}
.tip-val {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--chalk);
  margin-bottom: 0.25rem;
}
.tip-note { font-size: 0.84rem; color: var(--ink-2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 14px);
  z-index: 80;
  background: var(--head);
  color: #ffffff;
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.5rem 0.95rem;
  border-radius: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .top-bar { flex-wrap: wrap; row-gap: 0.35rem; }
  .top-nav { width: 100%; border-top: 1px solid var(--rule-faint); padding-top: 0.35rem; gap: 0.2rem 0.72rem; justify-content: space-between; }
  .top-nav a { font-size: 0.84rem; }
  .signal-strip { grid-template-columns: minmax(0, 1fr); }
  .signal-item { border-right: 0; border-bottom: 1px solid var(--rule-faint); padding: 0.95rem 0.25rem; }
  .signal-item:last-child { border-bottom: 0; }
  .ke-row { grid-template-columns: 2rem minmax(0, 1fr) 3rem; }
  .ke-track { grid-column: 2 / -1; height: 9px; margin-top: -0.35rem; }
  .foresight-row { grid-template-columns: minmax(0, 1fr); gap: 0.35rem; }
  .inv-row { grid-template-columns: 2rem minmax(0, 1fr); gap: 0.25rem 0.7rem; }
  .inv-status, .inv-note { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}
