
:root {
  --bg: #0b1017;
  --bg-rgb: 11, 16, 23;
  --bg-soft: #101822;
  --panel: #131d28;
  --panel-rgb: 19, 29, 40;
  --panel-2: #172331;
  --nav-bg: #0d141d;
  --line: #263548;
  --line-strong: #3a5068;
  --text: #edf3f7;
  --muted: #9cabba;
  --accent: #72d4c7;
  --accent-ink: #07110f;
  --accent-2: #e2ba67;
  --danger: #df7d72;
  --backdrop: rgba(0,0,0,.55);
  --shadow: rgba(0,0,0,.25);
  --hero-glow: rgba(114,212,199,.08);
  --header-bg: rgba(11,16,23,.88);
  --header-line: rgba(58,80,104,.6);
  --panel-gradient-end: rgba(19,29,40,.55);
  --hero-panel-a: rgba(23,35,49,.82);
  --hero-panel-b: rgba(16,24,34,.55);
  --header-h: 74px;
  --max: 1240px;
  --radius: 18px;
}

:root[data-theme="light"] {
  --bg: #f4f7f9;
  --bg-rgb: 244, 247, 249;
  --bg-soft: #edf2f5;
  --panel: #ffffff;
  --panel-rgb: 255, 255, 255;
  --panel-2: #e8eff3;
  --nav-bg: #f8fbfc;
  --line: #cbd7de;
  --line-strong: #99abb6;
  --text: #15212b;
  --muted: #596b77;
  --accent: #087d73;
  --accent-ink: #ffffff;
  --accent-2: #956611;
  --danger: #b94e45;
  --backdrop: rgba(22,33,43,.32);
  --shadow: rgba(26,45,56,.12);
  --hero-glow: rgba(8,125,115,.10);
  --header-bg: rgba(244,247,249,.90);
  --header-line: rgba(153,171,182,.62);
  --panel-gradient-end: rgba(237,242,245,.62);
  --hero-panel-a: rgba(255,255,255,.92);
  --hero-panel-b: rgba(237,242,245,.78);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 76% 4%, var(--hero-glow), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}
a { color: inherit; }
img { max-width: 100%; display: block; }
code { color: var(--accent); font: inherit; }
.skip-link {
  position: fixed; left: 1rem; top: -4rem; z-index: 1000;
  background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 8px;
}
.skip-link:focus { top: 1rem; }

.site-header {
  position: sticky; top: 0; z-index: 100;
  min-height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--header-line);
  background: var(--header-bg);
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: .8rem; text-decoration: none; min-width: 0; }
.brand img { flex: 0 0 auto; }
.brand-copy { display: grid; line-height: 1.15; min-width: 0; }
.brand-copy strong { font-size: .96rem; letter-spacing: .02em; }
.brand-copy small { color: var(--muted); font-size: .68rem; margin-top: .25rem; letter-spacing: .06em; text-transform: uppercase; }

.header-controls {
  display: flex; align-items: center; gap: .6rem;
}
.theme-switcher {
  display: flex; align-items: center; gap: 2px;
  padding: 3px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel);
}
.theme-option {
  min-height: 38px; padding: .45rem .62rem;
  display: inline-flex; align-items: center; justify-content: center; gap: .38rem;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font: inherit; font-size: .72rem; font-weight: 700;
  cursor: pointer;
}
.theme-option:hover { color: var(--text); background: var(--bg-soft); }
.theme-option[aria-pressed="true"] {
  color: var(--text); background: var(--bg-soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.theme-icon {
  width: 1em; text-align: center; font-size: .92rem; line-height: 1;
}


.theme-option:focus-visible,
.menu-button:focus-visible,
.nav-close:focus-visible,
.nav-home:focus-visible,
.chapter-links a:focus-visible,
.button:focus-visible,
.chapter-strip a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.menu-button {
  width: 46px; height: 46px; display: grid; place-content: center; gap: 5px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); cursor: pointer;
}
.menu-button span { width: 20px; height: 1.5px; background: currentColor; display: block; transition: .2s ease; }
.menu-button:hover { border-color: var(--line-strong); }

.nav-backdrop {
  position: fixed; inset: 0; z-index: 190;
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}
.site-nav {
  position: fixed; inset: 0 0 0 auto; z-index: 200;
  width: min(440px, 92vw); overflow-y: auto;
  padding: 1.2rem;
  background: var(--nav-bg);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 70px var(--shadow);
  transform: translateX(102%);
  transition: transform .24s ease;
}
.site-nav.open { transform: translateX(0); }
.nav-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.nav-head > div { display: grid; }
.nav-close {
  width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--text); font-size: 1.55rem; cursor: pointer;
}
.nav-home, .site-nav summary, .chapter-links a {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
}
.nav-home { display: block; padding: .85rem 1rem; text-decoration: none; margin-bottom: .8rem; }
.site-nav details { margin-bottom: .8rem; }
.site-nav summary {
  list-style: none; cursor: pointer; padding: .85rem 1rem;
  display: flex; gap: .7rem; align-items: center; font-weight: 650;
}
.site-nav summary::-webkit-details-marker { display: none; }
.site-nav summary span { color: var(--accent); font-variant-numeric: tabular-nums; }
.chapter-links { display: grid; gap: .35rem; padding: .45rem 0 0 .75rem; }
.chapter-links a {
  display: block; padding: .58rem .75rem; text-decoration: none;
  color: var(--muted); font-size: .86rem;
}
.chapter-links a:hover, .nav-home:hover { border-color: var(--line-strong); color: var(--text); }

main { overflow: hidden; }
.hero {
  width: min(var(--max), calc(100% - 2rem));
  min-height: calc(100svh - var(--header-h));
  margin: 0 auto;
  display: grid; grid-template-columns: .92fr 1.08fr;
  align-items: center; gap: clamp(2rem, 5vw, 5rem);
  padding: clamp(3rem, 7vw, 7rem) 0;
}
.eyebrow {
  display: inline-block; margin: 0 0 .8rem;
  color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .15em;
  text-transform: uppercase;
}
.hero h1 {
  margin: 0; font-size: clamp(3.4rem, 7vw, 7.5rem);
  line-height: .88; letter-spacing: -.06em; font-weight: 800;
}
.hero h1 span { color: var(--accent); }
.lede {
  max-width: 660px; margin: 1.6rem 0 0;
  color: var(--muted); font-size: clamp(1rem, 1.3vw, 1.18rem);
}
.hero-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.8rem; }
.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: .7rem 1rem; border-radius: 11px;
  text-decoration: none; font-weight: 700; font-size: .9rem;
}
.button.primary { background: var(--accent); color: var(--accent-ink); }
.button.secondary { border: 1px solid var(--line); background: var(--panel); }
.hero-metrics { display: flex; gap: 1.6rem; margin: 2.1rem 0 0; }
.hero-metrics div { display: grid; gap: .1rem; }
.hero-metrics dt { font-size: 1.4rem; font-weight: 800; color: var(--accent-2); }
.hero-metrics dd { margin: 0; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.hero-visual {
  margin: 0; background: linear-gradient(145deg, var(--hero-panel-a), var(--hero-panel-b));
  border: 1px solid var(--line); border-radius: 24px; padding: clamp(.7rem, 2vw, 1.4rem);
  box-shadow: 0 30px 70px var(--shadow);
}
.hero-visual figcaption { color: var(--muted); font-size: .72rem; margin: .7rem .3rem .1rem; letter-spacing: .05em; text-transform: uppercase; }

.system-section, .modules-section, .logic-section {
  width: min(var(--max), calc(100% - 2rem));
  margin: 0 auto;
  padding: clamp(4rem, 8vw, 7rem) 0;
}
.section-heading { max-width: 830px; }
.section-heading.compact { max-width: 690px; }
.section-heading h2 { margin: 0; font-size: clamp(2rem, 4.5vw, 4.2rem); line-height: 1; letter-spacing: -.045em; }
.section-heading p:last-child { color: var(--muted); max-width: 720px; }

.equation-card {
  margin-top: 2.2rem; padding: clamp(1.2rem, 3vw, 2rem);
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.equation { font: 700 clamp(1.5rem, 4vw, 3.6rem)/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--accent); }
.equation-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin-top: 1.4rem; }
.equation-grid span { padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: .82rem; }
.equation-grid b { color: var(--text); }

.state-flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 1rem; align-items: center; margin-top: 1rem; }
.state-flow article { min-height: 160px; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-soft); }
.flow-index { color: var(--accent-2); font: 800 .72rem ui-monospace, monospace; }
.state-flow h3 { margin: .55rem 0 .35rem; }
.state-flow p { margin: 0; color: var(--muted); font-size: .9rem; }
.flow-arrow { color: var(--line-strong); font-size: 1.8rem; }

.module-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 2.1rem; }
.module-card {
  display: flex; flex-direction: column; min-width: 0;
  padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--panel-gradient-end));
}
.module-topline { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.module-id { color: var(--accent); font: 800 .78rem ui-monospace, monospace; letter-spacing: .08em; }
.module-status { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }
.module-graphic { width: 100%; margin: 1rem 0; border-radius: 13px; border: 1px solid var(--line); background: var(--nav-bg); }
.module-card h3 { margin: .2rem 0 .45rem; font-size: 1.25rem; }
.module-card p { margin: 0 0 1.1rem; color: var(--muted); font-size: .9rem; }
.chapter-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; margin-top: auto; }
.chapter-strip a {
  display: grid; place-items: center; min-height: 34px;
  border: 1px solid var(--line); border-radius: 7px; text-decoration: none;
  font: 700 .72rem ui-monospace, monospace; color: var(--muted);
}
.chapter-strip a:hover { border-color: var(--accent); color: var(--accent); }

.logic-chain {
  margin-top: 2rem; padding: 1rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.logic-chain span { padding: .7rem .85rem; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 9px; font-size: .82rem; }
.logic-chain i { color: var(--accent); font-style: normal; }

.site-footer {
  width: min(var(--max), calc(100% - 2rem));
  margin: 1rem auto 0; padding: 1.5rem 0 2.2rem;
  display: flex; justify-content: space-between; gap: 1rem; align-items: end;
  border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem;
}
.site-footer > div { display: grid; gap: .2rem; }
.site-footer strong { color: var(--text); }
.site-footer p { margin: 0; }
.site-footer a { color: var(--accent); }

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; min-height: auto; }
  .hero-visual { order: -1; max-width: 760px; }
  .module-grid { grid-template-columns: 1fr; }
  .module-card { display: grid; grid-template-columns: 170px 1fr; grid-template-areas:
      "top top" "graphic title" "graphic text" "chapters chapters"; column-gap: 1.2rem; }
  .module-topline { grid-area: top; }
  .module-graphic { grid-area: graphic; }
  .module-card h3 { grid-area: title; align-self: end; }
  .module-card p { grid-area: text; }
  .chapter-strip { grid-area: chapters; }
}
@media (max-width: 720px) {
  .theme-option { width: 34px; min-height: 34px; padding: 0; }
  .theme-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
  :root { --header-h: 66px; }
  .brand-copy small { display: none; }
  .hero { width: min(100% - 1.2rem, var(--max)); gap: 1.4rem; padding: 1.4rem 0 3.8rem; }
  .hero h1 { font-size: clamp(3rem, 16vw, 5rem); }
  .hero-visual { padding: .45rem; border-radius: 16px; }
  .hero-metrics { gap: 1rem; justify-content: space-between; }
  .system-section, .modules-section, .logic-section { width: min(100% - 1.2rem, var(--max)); padding: 3.6rem 0; }
  .equation-grid { grid-template-columns: 1fr 1fr; }
  .state-flow { grid-template-columns: 1fr; }
  .flow-arrow { transform: rotate(90deg); justify-self: center; }
  .module-card { display: flex; }
  .module-graphic { margin-bottom: .75rem; }
  .site-footer { width: min(100% - 1.2rem, var(--max)); align-items: start; flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}


/* Project-owned SVGs remain intentionally instrument-like.
   Light mode lifts their shell without recoloring state semantics inside the diagrams. */
:root[data-theme="light"] .hero-visual img,
:root[data-theme="light"] .module-graphic {
  box-shadow: inset 0 0 0 1px rgba(21,33,43,.06);
}
