/* Palette from the book cover: indigo field, a green human side, a cyan machine side, a gold lock. */
:root {
  color-scheme: dark;
  --bg: #1b1232;
  --bg-2: #241a41;
  --panel: #2a1f4a;
  --ink: #ece9f5;
  --muted: #b3aacb;
  --faint: #8279a0;
  --rule: #3a2e5e;
  --human: #5fd39b;
  --machine: #56c8e8;
  --gold: #f0ae3c;
  --coral: #ef6a72;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.65 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--machine); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0; }
h2 { font-size: clamp(1.6rem, 3.2vw, 2.2rem); font-weight: 600; }
h3 { font-size: 1.12rem; font-weight: 600; }
p { margin: 0 0 1rem; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.label { font: 500 .72rem var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.label b { color: var(--gold); font-weight: 500; }

.nav { position: sticky; top: 0; z-index: 10; background: rgba(27, 18, 50, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); }
.nav .wrap { display: flex; align-items: center; gap: 1.25rem; padding: .7rem 16px; flex-wrap: wrap; }
.brand { font: 700 1.1rem var(--serif); color: var(--ink); }
.brand span { color: var(--gold); }
.nav .links { display: flex; gap: 1rem; flex-wrap: wrap; margin-left: auto; font-size: .9rem; }
.nav .links a { color: var(--muted); }
.nav .links a:hover { color: var(--ink); text-decoration: none; }

section { padding: 4rem 0; }
.band { background: var(--bg-2); }
.sec-head { margin-bottom: 2rem; max-width: 70ch; }
.sec-head .label { display: block; margin-bottom: .6rem; }
.sec-head p { color: var(--muted); margin-top: .8rem; }

/* Hero */
.hero { padding: 4rem 0; border-bottom: 1px solid var(--rule); }
.hero .grid { display: grid; grid-template-columns: 1fr 290px; gap: 3rem; align-items: center; }
.hero h1 { font-size: clamp(2.6rem, 7vw, 4.4rem); font-weight: 700; letter-spacing: -.02em; }
.hero h1 em { font-style: normal; color: var(--gold); }
.hero .sub { font: 400 clamp(1.1rem, 2.2vw, 1.35rem) var(--serif); margin: .5rem 0 .3rem; }
.hero .by { color: var(--muted); margin-bottom: 1.4rem; font-size: .95rem; }
.hero .lede { max-width: 60ch; }
.hero .cover img { width: 100%; height: auto; display: block; border-radius: 3px; box-shadow: 0 16px 42px rgba(0,0,0,.5); }
.btns { display: flex; flex-wrap: wrap; gap: .6rem; }
.btn { display: inline-block; padding: .55rem 1rem; border: 1.5px solid var(--gold); color: var(--gold); font-size: .92rem; font-weight: 500; border-radius: 4px; }
.btn:hover { background: rgba(240, 174, 60, .14); text-decoration: none; }
.btn.primary { background: var(--gold); color: #24183f; }
.btn.primary:hover { background: #f7c265; }
.facts { display: flex; gap: 2rem; flex-wrap: wrap; margin-top: 2rem; }
.facts b { display: block; font: 600 1.5rem var(--serif); color: var(--gold); }
.facts span { font-size: .8rem; color: var(--muted); }

.pull { font: italic 1.2rem/1.5 var(--serif); max-width: 62ch; border-left: 3px solid var(--gold); padding-left: 1.1rem; margin: 1.8rem 0 0; }

/* Incidents */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 1.2rem 1.3rem; }
.card .k { font: 500 .74rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--coral); }
.card h3 { margin: .45rem 0 .5rem; }
.card p { color: var(--muted); font-size: .94rem; margin: 0; }

/* Scenario */
.scenario { background: var(--panel); border-left: 4px solid var(--human); border-radius: 8px; padding: 1.5rem 1.6rem; max-width: 78ch; }
.scenario .k { font: 500 .74rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--human); }
.scenario h3 { margin: .4rem 0 .7rem; font-size: 1.3rem; }
.scenario p:last-child { margin-bottom: 0; }

/* Framework grid */
.fw { display: grid; grid-template-columns: 1.15fr 1fr; gap: 2.5rem; align-items: start; }
.grid-wrap { overflow-x: auto; }
table.stack { border-collapse: collapse; width: 100%; min-width: 420px; font-size: .84rem; }
table.stack th { font: 500 .72rem var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--faint); font-weight: 500; padding: .35rem .3rem; text-align: center; }
table.stack th.lv { text-align: left; white-space: nowrap; color: var(--ink); font-family: var(--sans); font-size: .85rem; text-transform: none; letter-spacing: 0; }
table.stack td { border: 1px solid var(--rule); height: 2.2rem; background: rgba(95, 211, 155, .05); }
table.stack tr:nth-child(1) td { background: rgba(86, 200, 232, .07); }
table.stack tr:nth-child(2) td { background: rgba(86, 200, 232, .10); }
table.stack tr:nth-child(4) td, table.stack tr:nth-child(5) td { background: rgba(95, 211, 155, .09); }
table.stack td.hot { background: rgba(240, 174, 60, .3); position: relative; }
table.stack td.hot span { position: absolute; inset: 0; display: grid; place-items: center; font: 600 .7rem var(--mono); color: var(--gold); }
.phases { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.phase { border: 1px solid var(--rule); border-radius: 999px; padding: .25rem .8rem; font-size: .82rem; color: var(--muted); }
.phase b { color: var(--ink); font-weight: 600; }
.fw ul { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: .95rem; }
.fw li { margin: .3rem 0; }
.fw li b { color: var(--ink); }

/* Resilience lab */
.lab { display: grid; grid-template-columns: 320px 1fr; gap: 2rem; background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 1.5rem; }
.lab > * { min-width: 0; }
.field { margin-bottom: .9rem; }
.field label { display: flex; justify-content: space-between; gap: .5rem; font-size: .87rem; margin-bottom: .2rem; }
.field label i { font-family: var(--serif); font-style: italic; color: var(--gold); }
.field output { font-family: var(--mono); color: var(--gold); }
.field input { width: 100%; accent-color: var(--gold); }
.field small { display: block; font-size: .76rem; color: var(--faint); }
.presets { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.presets button { font: 500 .8rem var(--sans); color: var(--ink); background: transparent; border: 1px solid var(--rule); border-radius: 999px; padding: .3rem .75rem; cursor: pointer; }
.presets button:hover { border-color: var(--gold); }
.presets button[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #24183f; }
.readout { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
.readout div { border-top: 3px solid var(--rule); padding-top: .4rem; }
.readout div.r { border-top-color: var(--gold); }
.readout b { display: block; font: 600 1.35rem var(--serif); font-variant-numeric: tabular-nums; }
.readout span { font-size: .78rem; color: var(--muted); }
#curve { width: 100%; height: auto; display: block; }
#curve text { font: 12px var(--mono); fill: var(--faint); }
#curve .axis { stroke: rgba(255,255,255,.12); }
#curve .q { stroke: var(--human); stroke-width: 2.5; fill: none; }
#curve .loss { fill: rgba(239, 106, 114, .3); }
#curve .gain { fill: rgba(95, 211, 155, .25); }
#curve .mark { stroke: var(--gold); stroke-dasharray: 3 3; stroke-width: 1; }
#curve .marklabel { fill: var(--gold); font-size: 11px; }
.formula { font-family: var(--mono); font-size: .85rem; background: rgba(240, 174, 60, .12); padding: .55rem .8rem; border-radius: 4px; margin-top: .9rem; overflow-x: auto; white-space: nowrap; }
.lab-note { font-size: .84rem; color: var(--faint); margin: .8rem 0 0; }

/* Parts */
.parts { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.part { display: grid; grid-template-columns: 3.2rem 1fr; gap: .9rem; background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 1rem 1.2rem; }
.part .n { font: 600 .85rem var(--mono); color: var(--gold); padding-top: .15rem; }
.part p { margin: .2rem 0 0; color: var(--muted); font-size: .93rem; }

/* Methods + features */
.tags { display: flex; flex-wrap: wrap; gap: .5rem; padding: 0; margin: 0; list-style: none; }
.tags li { border: 1px solid var(--rule); border-radius: 999px; padding: .3rem .85rem; font-size: .88rem; color: var(--muted); }
.feats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-top: 2rem; }
.feat { border-top: 2px solid var(--machine); padding-top: .7rem; }
.feat h3 { font-size: 1rem; }
.feat p { color: var(--muted); font-size: .9rem; margin: .25rem 0 0; }

/* Papers */
.papers { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 2.5rem; }
.papers li { break-inside: avoid; padding: .75rem 0; border-bottom: 1px dashed var(--rule); }
.papers .t { font: 600 1rem var(--serif); }
.papers .m { color: var(--muted); font-size: .88rem; }
.see { margin-top: 1.8rem; display: flex; gap: .8rem; flex-wrap: wrap; }

footer { padding: 2rem 0 3rem; color: var(--faint); font-size: .85rem; border-top: 1px solid var(--rule); }
footer .wrap { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

@media (max-width: 880px) {
  .hero .grid, .fw, .lab, .parts { grid-template-columns: 1fr; }
  .hero .cover { max-width: 230px; }
  .cards, .feats { grid-template-columns: 1fr; }
  .readout { grid-template-columns: 1fr 1fr; }
  .papers { columns: 1; }
  section { padding: 3rem 0; }
}
@media (max-width: 520px) { .nav .links { margin-left: 0; gap: .8rem; } }

/* Contents */
.toc { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem 2.5rem; }
.toc details { border-bottom: 1px solid var(--rule); padding: .6rem 0; }
.toc summary { cursor: pointer; font-family: var(--serif); font-weight: 600; font-size: 1.02rem; list-style: none; display: flex; gap: .7rem; align-items: baseline; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary .pn { font: 500 .78rem var(--mono); color: var(--gold); min-width: 2.4rem; }
.toc summary::after { content: "+"; margin-left: auto; color: var(--faint); font-family: var(--mono); }
.toc details[open] summary::after { content: "−"; }
.toc ol { margin: .5rem 0 .2rem 3.1rem; padding: 0; list-style: none; font-size: .92rem; }
.toc ol li { padding: .18rem 0; display: flex; gap: .6rem; color: var(--muted); }
.toc ol li .c { font: .8rem var(--mono); color: var(--faint); min-width: 1.5rem; }
.toc .in-sample { font: .7rem var(--mono); color: var(--human); margin-left: .45rem; }
@media (max-width: 880px) { .toc { grid-template-columns: 1fr; } }
