*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           oklch(97% 0.008 80);
  --bg-raised:    oklch(93% 0.010 80);
  --bg-surface:   oklch(90% 0.010 80);
  --fg:           oklch(18% 0.010 80);
  --fg-muted:     oklch(48% 0.010 80);
  --teal:         oklch(52% 0.13 195);
  --teal-subtle:  oklch(92% 0.04 195);
  --teal-border:  oklch(85% 0.06 195);
  --teal-dim:     oklch(75% 0.08 195);
  --amber:        oklch(60% 0.13 75);
  --amber-subtle: oklch(95% 0.04 75);
  --amber-border: oklch(88% 0.07 75);
  --rule:         oklch(86% 0.008 80);
  --font-body:    'DM Sans', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
  --font-display: 'Syne', sans-serif;
}

/* Dark theme token overrides — applied via class on html */
html.dark {
  --bg:           oklch(13% 0.012 220);
  --bg-raised:    oklch(17% 0.012 220);
  --bg-surface:   oklch(20% 0.012 220);
  --fg:           oklch(91% 0.006 80);
  --fg-muted:     oklch(78% 0.010 200);
  --teal:         oklch(68% 0.14 195);
  --teal-subtle:  oklch(20% 0.06 195);
  --teal-border:  oklch(30% 0.08 195);
  --teal-dim:     oklch(42% 0.10 195);
  --amber:        oklch(78% 0.14 75);
  --amber-subtle: oklch(18% 0.06 75);
  --amber-border: oklch(28% 0.08 75);
  --rule:         oklch(26% 0.010 220);
}

html { scroll-behavior: auto; } /* we handle scrolling manually during transition */

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  /* All color properties transition smoothly */
  transition:
    background-color 0.8s ease,
    color 0.8s ease;
}

/* Transition overlay — visible during the scroll-lock phase */
#theme-curtain {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  /* In light mode it fades to dark; in dark it's already transparent */
  background: oklch(13% 0.012 220);
  transition: opacity 0s;
}

/* Progress bar */
.scroll-bar {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0%;
  background: var(--teal);
  z-index: 300;
  transition: background-color 0.8s ease;
}

/* ── Layout ── */
.container { max-width: 860px; margin: 0 auto; padding: 0 48px; }

/* ── Nav ── */
nav {
  padding: 28px 48px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 860px;
  margin: 0 auto;
  transition: border-color 0.8s ease;
}
html.dark nav { border-bottom: 1px solid var(--rule); }

.nav-label {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
  white-space: nowrap;
  transition: color 0.8s ease;
}
.nav-brand { color: var(--teal); transition: color 0.8s ease; text-decoration: none; }
.nav-dot { color: var(--rule); transition: color 0.8s ease; }

/* ── Hero ── */
.hero {
  padding: 80px 0 96px;
  border-bottom: 1px solid var(--rule);
  position: relative;
  overflow: hidden;
  transition: border-color 0.8s ease;
}

.hero-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}
html.dark .hero-grid { opacity: 0.5; }

.hero-inner { position: relative; z-index: 1; }

.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: color 0.8s ease;
}
html.dark .hero-eyebrow::before {
  content: '';
  display: inline-block;
  width: 24px;
  height: 1px;
  background: var(--teal);
  flex-shrink: 0;
}

.hero-title {
  font-size: clamp(52px, 7vw, 84px);
  font-weight: 300;
  line-height: 1.05;
  letter-spacing: -0.025em;
  color: var(--fg);
  margin-bottom: 36px;
  transition: color 0.8s ease, font-family 0.1s;
}
html.dark .hero-title { font-family: var(--font-display); }

.hero-title .accent {
  color: var(--teal);
  transition: color 0.8s ease, display 0s;
}
html:not(.dark) .hero-title .accent { font-style: italic; display: inline; }
html.dark .hero-title .accent { display: block; }

.hero-tagline {
  font-size: 20px;
  font-weight: 300;
  line-height: 1.55;
  color: var(--fg-muted);
  max-width: 580px;
  margin-bottom: 44px;
  text-wrap: pretty;
  transition: color 0.8s ease;
}

.hero-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  gap: 12px 20px;
  flex-wrap: wrap;
  align-items: baseline;
  transition: color 0.8s ease;
}
.hero-meta span, .hero-meta a { white-space: nowrap; }
.hero-meta a { color: var(--teal); text-decoration: none; transition: color 0.8s ease; }

/* ── Sections ── */
section {
  padding: 72px 0;
  border-bottom: 1px solid var(--rule);
  transition: border-color 0.8s ease;
}
html.dark section { border-bottom: none; border-top: 1px solid var(--rule); }

.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 36px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: color 0.8s ease;
}
html:not(.dark) .section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--rule);
  max-width: 100px;
  transition: background 0.8s ease;
}
.section-label .section-counter {
  color: var(--fg-muted);
  font-size: 10px;
  transition: color 0.8s ease;
}
html:not(.dark) .section-label .section-counter { display: none; }

/* ── Overview ── */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 56px;
  align-items: start;
}

.overview-aside {
  background: var(--teal-subtle);
  border-left: 3px solid var(--teal);
  padding: 24px 24px 24px 20px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--fg);
  transition: background 0.8s ease, border 0.8s ease, padding 0.4s ease;
}
html.dark .overview-aside {
  background: var(--bg-raised);
  border-left: none;
  border: 1px solid var(--rule);
  border-top: 2px solid var(--teal);
  padding: 24px;
}

.overview-aside-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 10px;
  display: block;
  transition: color 0.8s ease;
}
.overview-aside p {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  color: var(--fg-muted);
  margin: 0;
  transition: color 0.8s ease;
}

/* ── Figures ── */
.figure { margin: 40px 0; }
.figure img { width: 100%; display: block; border: 1px solid var(--rule); transition: border-color 0.8s ease; }
.figure figcaption {
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  line-height: 1.5;
  transition: color 0.8s ease;
}
.figure figcaption a { color: var(--teal); text-decoration: none; transition: color 0.8s ease; }
.figure-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 40px 0; }
.figure-pair .figure { margin: 0; }

/* ── Example header ── */
.example-header { display: flex; align-items: baseline; gap: 20px; margin-bottom: 32px; }

.example-number {
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
  color: var(--rule);
  flex-shrink: 0;
  font-size: 56px;
  font-weight: 300;
  line-height: 1;
  transition: color 0.8s ease, font-size 0.4s ease, letter-spacing 0.4s ease;
}
html.dark .example-number {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--teal);
  line-height: normal;
}

.example-title {
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--fg);
  transition: color 0.8s ease;
}

/* ── Terminal / Exchange ── */
.terminal-shell {
  border: 1px solid var(--rule);
  overflow: hidden;
  margin: 28px 0;
  background: var(--bg-raised);
  transition: background 0.8s ease, border-color 0.8s ease;
}
.terminal-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--rule);
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: background 0.8s ease, border-color 0.8s ease;
}
.terminal-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--rule);
  transition: background 0.8s ease;
}
.terminal-dot:nth-child(1) { background: oklch(55% 0.04 25); }
.terminal-dot:nth-child(2) { background: oklch(62% 0.04 65); }
.terminal-dot:nth-child(3) { background: oklch(55% 0.04 145); }
.terminal-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  letter-spacing: 0.06em;
  margin-left: 4px;
  transition: color 0.8s ease;
}
.terminal-body { padding: 24px 28px; }
.terminal-line { display: flex; gap: 14px; margin-bottom: 20px; align-items: flex-start; }
.terminal-line:last-child { margin-bottom: 0; }
.terminal-prompt {
  font-family: var(--font-mono);
  font-size: 13px;
  flex-shrink: 0;
  padding-top: 2px;
  transition: color 0.8s ease;
}
.terminal-prompt--q { color: var(--amber); }
.terminal-prompt--r { color: var(--teal); }
.terminal-text {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.75;
  color: var(--fg);
  transition: color 0.8s ease;
}
.terminal-text .hl { color: var(--teal); font-weight: 500; transition: color 0.8s ease; }
.terminal-text .q { color: var(--amber); font-style: italic; transition: color 0.8s ease; }

/* ── Insight ── */
.insight {
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  margin-top: 28px;
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.7;
  text-wrap: pretty;
  transition: color 0.8s ease, border-color 0.8s ease;
}
html:not(.dark) .insight { border-top: 2px solid var(--teal); }

/* ── Pull quote ── */
.pull-quote {
  font-size: clamp(22px, 2.8vw, 30px);
  font-weight: 300;
  line-height: 1.4;
  color: var(--fg);
  margin: 52px 0;
  letter-spacing: -0.01em;
  text-wrap: pretty;
  transition: color 0.8s ease, border-color 0.8s ease, padding 0.4s;
}
html:not(.dark) .pull-quote {
  border-left: 3px solid var(--teal);
  padding: 4px 0 4px 28px;
}
html.dark .pull-quote {
  padding: 36px 0;
  border-top: 1px solid var(--teal-dim);
  border-bottom: 1px solid var(--teal-dim);
}
html.dark .pull-quote::before {
  content: 'KEY INSIGHT';
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--teal);
  margin-bottom: 16px;
}

/* ── Steps ── */
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 40px;
  margin: 40px 0;
  transition: gap 0.4s, border-color 0.8s;
}
html.dark .steps { gap: 0; border: 1px solid var(--rule); }
.step { transition: padding 0.4s, border-color 0.8s; }
html.dark .step { padding: 28px 24px; border-right: 1px solid var(--rule); }
html.dark .step:last-child { border-right: none; }
.step-number {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--teal);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: color 0.8s;
}
html.dark .step-number::after { content: ''; flex: 1; height: 1px; background: var(--rule); }
.step-title { font-size: 16px; font-weight: 500; margin-bottom: 8px; color: var(--fg); transition: color 0.8s; }
.step-body { font-size: 14px; color: var(--fg-muted); line-height: 1.6; transition: color 0.8s; }

/* ── Closing ── */
.closing { padding: 80px 0 72px; }
.closing-statement {
  font-size: clamp(20px, 2.5vw, 26px);
  font-weight: 300;
  line-height: 1.5;
  color: var(--fg);
  max-width: 680px;
  text-wrap: pretty;
  margin-bottom: 40px;
  transition: color 0.8s, border-color 0.8s, padding 0.4s;
}
html.dark .closing-statement { border-left: 2px solid var(--teal); padding-left: 24px; }
.closing-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  transition: color 0.8s;
}
.closing-meta a { color: var(--teal); text-decoration: none; transition: color 0.8s; }

.prose p { margin-bottom: 18px; color: var(--fg); transition: color 0.8s; }
.prose p:last-child { margin-bottom: 0; }
.prose p.muted { color: var(--fg-muted); }

/* ── Transition zone (scroll-jacked) ── */
/* A tall spacer between ex2 and ex3 that traps scroll during the theme switch */
#transition-zone {
  /* Height determines how much scroll distance = theme transition.
     We freeze the viewport here and use the scroll to drive the curtain. */
  height: 300vh;
  position: relative;
}

#transition-sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.transition-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-muted);
  opacity: 0;
  transition: opacity 0.4s, color 0.8s;
  text-align: center;
  user-select: none;
}

.transition-label.visible { opacity: 1; }

/* ── GLB Viewer ── */
.viewer-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--rule);
  overflow: hidden;
  transition: border-color 0.8s ease;
}

.viewer-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
  transition: background-color 0.8s ease;
}

.viewer-loading,
.viewer-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  padding: 4px 12px;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.viewer-hint {
  bottom: 36px;
  transition: opacity 0.6s ease;
}

.viewer-hint--hidden { opacity: 0; }

@media (max-width: 700px) {
  .container { padding: 0 24px; }
  nav { padding: 24px; }
  .overview-grid { grid-template-columns: 1fr; gap: 32px; }
  .steps { grid-template-columns: 1fr; }
  html.dark .step { border-right: none; border-bottom: 1px solid var(--rule); }
  .figure-pair { grid-template-columns: 1fr; }
}
