:root {
  --bg: #FBF9F4;
  --surface: #F3EFE6;
  --text: #1F1D1A;
  --muted: #6B665E;
  --rule: #E2DCD0;
  --accent: #1F4E79;
  --accent-soft: rgba(31, 78, 121, 0.10);
  --warn: #A1452B;
  --warn-soft: rgba(161, 69, 43, 0.10);
  --ok: #2F6B4F;
  --ok-soft: rgba(47, 107, 79, 0.10);
  --placeholder: #8A6D1F;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131209;
    --surface: #1F1F1F;
    --text: #ECE7DD;
    --muted: #A39C90;
    --rule: #313131;
    --accent: #8DB4DC;
    --accent-soft: rgba(141, 180, 220, 0.12);
    --warn: #E0937A;
    --warn-soft: rgba(224, 147, 122, 0.12);
    --ok: #8CC7A6;
    --ok-soft: rgba(140, 199, 166, 0.12);
    --placeholder: #D9B85C;
  }
}
:root[data-theme="dark"] {
  --bg: #131209;
  --surface: #1F1F1F;
  --text: #ECE7DD;
  --muted: #A39C90;
  --rule: #313131;
  --accent: #8DB4DC;
  --accent-soft: rgba(141, 180, 220, 0.12);
  --warn: #E0937A;
  --warn-soft: rgba(224, 147, 122, 0.12);
  --ok: #8CC7A6;
  --ok-soft: rgba(140, 199, 166, 0.12);
  --placeholder: #D9B85C;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 18px;
  line-height: 28px;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  transition: background-color 300ms var(--ease), color 300ms var(--ease);
}
p, li { text-wrap: pretty; hyphens: manual; }
h1, h2, h3, .statement { text-wrap: balance; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
::selection { background: var(--accent-soft); }

.skip {
  position: absolute; left: 16px; top: -64px; z-index: 50;
  background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: 6px;
  font-size: 14px; line-height: 20px; text-decoration: none;
}
.skip:focus { top: 16px; }

.progress { position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 40; pointer-events: none; }
.progress span { display: block; height: 100%; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); }

/* Header line */
.topbar {
  max-width: 1200px; margin: 0 auto; padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  font-size: 14px; line-height: 20px; color: var(--muted);
}
.topbar .brand { color: var(--text); font-weight: 600; letter-spacing: 0.02em; text-decoration: none; }
.topbar .tools { display: flex; align-items: center; gap: 16px; }
.lang { display: flex; gap: 8px; }
.lang a, .lang span { text-decoration: none; color: var(--muted); }
.lang [aria-current] { color: var(--text); font-weight: 600; }
.lang .soon { opacity: 0.6; cursor: default; }
.theme-toggle {
  appearance: none; border: 1px solid var(--rule); background: transparent; color: var(--text);
  width: 32px; height: 32px; border-radius: 999px; display: inline-grid; place-items: center; cursor: pointer;
  transition: background-color 300ms var(--ease), transform 300ms var(--ease);
}
.theme-toggle:hover { background: var(--surface); }
.theme-toggle:active { transform: scale(0.96); }
.theme-toggle svg { width: 16px; height: 16px; }

/* Layout */
.layout {
  max-width: 1200px; margin: 0 auto; padding: 0 24px;
  display: grid; grid-template-columns: 1fr; gap: 48px;
}
@media (min-width: 1180px) {
  .layout { grid-template-columns: 220px minmax(0, 680px) 1fr; }
}
.toc-side { display: none; }
@media (min-width: 1180px) {
  .toc-side { display: block; }
  .toc-side nav { position: sticky; top: 32px; padding-top: 64px; }
}
.toc-title { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block; padding: 4px 0 4px 12px; border-radius: 4px;
  font-size: 14px; line-height: 20px; color: var(--muted); text-decoration: none;
  box-shadow: inset 2px 0 0 transparent;
  transition: color 300ms var(--ease), box-shadow 300ms var(--ease);
}
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }

main { min-width: 0; }
article { max-width: 680px; margin: 0 auto; padding-bottom: 96px; }

/* Title block */
.title-block { padding: 64px 0 40px; border-bottom: 1px solid var(--rule); margin-bottom: 40px; }
.kicker { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin: 0 0 16px; }
h1 { font-size: 48px; line-height: 48px; font-weight: 600; letter-spacing: -0.025em; margin: 0 0 24px; }
@media (min-width: 640px) { h1 { font-size: 60px; line-height: 60px; } }
.subtitle { font-size: 24px; line-height: 32px; font-weight: 400; letter-spacing: -0.01em; color: var(--muted); margin: 0 0 32px; max-width: 600px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 24px; font-size: 14px; line-height: 20px; color: var(--muted); }
.meta .draft { color: var(--warn); }
.ph { color: var(--placeholder); border-bottom: 1px dashed currentColor; }

.toc-inline { margin: 0 0 40px; border: 1px solid var(--rule); border-radius: 12px; padding: 12px 16px; }
@media (min-width: 1180px) { .toc-inline { display: none; } }
.toc-inline summary { cursor: pointer; font-size: 14px; line-height: 20px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.toc-inline summary::-webkit-details-marker { display: none; }
.toc-inline summary::after { content: "+"; font-weight: 400; color: var(--muted); transition: transform 300ms var(--ease); }
.toc-inline[open] summary::after { transform: rotate(45deg); }
.toc-inline .toc { margin-top: 12px; }

/* Abstract */
.abstract { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 24px; margin: 0 0 48px; }
.abstract h2 { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
.abstract p { margin: 0 0 16px; }
.abstract p:last-child { margin-bottom: 0; }

/* Body text */
article section { scroll-margin-top: 24px; }
article h2 { font-size: 30px; line-height: 36px; font-weight: 600; letter-spacing: -0.01em; margin: 64px 0 24px; }
article h2 .num { color: var(--muted); font-weight: 400; margin-right: 8px; }
article h3 { font-size: 20px; line-height: 28px; font-weight: 600; margin: 40px 0 12px; }
article p { margin: 0 0 24px; }
article ul, article ol { margin: 0 0 24px; padding-left: 24px; }
article li { margin: 0 0 12px; }
article li::marker { color: var(--muted); }
strong { font-weight: 600; }
.lead { font-size: 20px; line-height: 28px; }
sup.ref { font-size: 12px; line-height: 0; margin-left: 2px; }
sup.ref a { text-decoration: none; padding: 0 2px; }
.term { font-weight: 600; }
.note { font-size: 16px; line-height: 24px; color: var(--muted); }

/* Statement */
.statement-wrap { margin: 80px 0; padding: 48px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.statement { font-size: 30px; line-height: 36px; font-weight: 500; letter-spacing: -0.01em; margin: 0; }
@media (min-width: 640px) { .statement { font-size: 36px; line-height: 40px; } }
.statement .w { color: color-mix(in srgb, var(--text) 30%, transparent); transition: color 600ms var(--ease); }
.statement .w.on { color: var(--text); }
@media (prefers-reduced-motion: reduce) { .statement .w { color: var(--text); transition: none; } }

/* Figures */
figure { margin: 40px 0 48px; }
figcaption { font-size: 14px; line-height: 20px; color: var(--muted); margin-top: 12px; }
figcaption b { color: var(--text); font-weight: 600; }

.scheme { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .scheme { grid-template-columns: 1fr 1fr 1fr; grid-template-areas: "a c b" "t . p" "g g g"; }
  .scheme .n-a { grid-area: a; } .scheme .n-c { grid-area: c; } .scheme .n-b { grid-area: b; }
  .scheme .n-t { grid-area: t; } .scheme .n-p { grid-area: p; } .scheme .n-g { grid-area: g; }
}
.node { border: 1px solid var(--rule); border-radius: 8px; padding: 12px 16px; background: var(--bg); }
.node .label { display: block; font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.node p { margin: 0; font-size: 16px; line-height: 24px; }
.node.n-c { background: var(--surface); }
.node.n-t { border-color: var(--warn); background: var(--warn-soft); }
.node.n-t .label { color: var(--warn); }
.node.n-p { border-color: var(--ok); background: var(--ok-soft); }
.node.n-p .label { color: var(--ok); }
.node.n-g { border-color: var(--accent); background: var(--accent-soft); text-align: center; }
.node.n-g .label { color: var(--accent); }
.scheme-box { border: 1px solid var(--rule); border-radius: 12px; padding: 16px; background: var(--surface); }

.chart { border: 1px solid var(--rule); border-radius: 12px; padding: 16px 8px 8px; background: var(--surface); }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font-family: "Geist", system-ui, sans-serif; fill: var(--muted); }
.chart .t-strong { fill: var(--text); font-weight: 600; }
.chart .t-warn { fill: var(--warn); font-weight: 600; }
.chart .t-ok { fill: var(--ok); font-weight: 600; }
.chart .axis { stroke: var(--muted); stroke-width: 1; }
.chart .zero { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .curve { stroke: var(--accent); stroke-width: 3; fill: none; stroke-linecap: round; }
.chart .z-warn { fill: var(--warn-soft); }
.chart .z-ok { fill: var(--ok-soft); }
.legend { list-style: none; margin: 12px 8px 0; padding: 0; display: grid; gap: 8px; font-size: 14px; line-height: 20px; }
.legend li { margin: 0; position: relative; padding-left: 24px; }
.legend b { font-weight: 600; }
.sw { position: absolute; left: 0; top: 4px; width: 12px; height: 12px; border-radius: 4px; border: 1px solid var(--rule); }
.sw-empty { background: var(--bg); }
.sw-ok { background: var(--ok-soft); border-color: var(--ok); }
.sw-warn { background: var(--warn-soft); border-color: var(--warn); }
.axis-note { margin: 8px 8px 4px; font-size: 14px; line-height: 20px; color: var(--muted); }

.phases { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: stretch; }
@media (min-width: 640px) { .phases { grid-template-columns: 1fr auto 1fr; } }
.phase { border: 1px solid var(--rule); border-radius: 8px; padding: 16px; background: var(--bg); }
.phase .label { display: block; font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.phase h4 { margin: 0 0 8px; font-size: 18px; line-height: 28px; font-weight: 600; }
.phase p { margin: 0; font-size: 16px; line-height: 24px; }
.phase.p2 { border-color: var(--ok); background: var(--ok-soft); }
.shift { display: grid; place-items: center; color: var(--accent); font-size: 14px; line-height: 20px; font-weight: 600; text-align: center; padding: 4px 8px; }
.shift svg { width: 24px; height: 24px; display: block; margin: 0 auto 4px; }
@media (max-width: 639px) { .shift svg { transform: rotate(90deg); } }
.criterion { margin-top: 12px; font-size: 16px; line-height: 24px; border: 1px dashed var(--rule); border-radius: 8px; padding: 12px 16px; background: var(--bg); }

/* Principles */
.principles { list-style: none; padding: 0; margin: 0 0 24px; counter-reset: p; display: grid; gap: 16px; }
.principles li { counter-increment: p; position: relative; padding: 16px 16px 16px 64px; border: 1px solid var(--rule); border-radius: 12px; margin: 0; }
.principles li::before {
  content: counter(p); position: absolute; left: 16px; top: 16px; width: 32px; height: 32px; border-radius: 999px;
  display: grid; place-items: center; font-size: 14px; line-height: 20px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
}
.principles h3 { margin: 0 0 4px; font-size: 18px; line-height: 28px; }
.principles p { margin: 0; font-size: 16px; line-height: 24px; }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: 12px; margin: 0 0 24px; }
table { border-collapse: collapse; width: 100%; min-width: 560px; font-size: 16px; line-height: 24px; }
th, td { text-align: left; vertical-align: top; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
th { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); background: var(--surface); }
tr:last-child td { border-bottom: 0; }
td:first-child { font-weight: 600; }

/* Research */
.research { list-style: none; padding: 0; margin: 0 0 24px; display: grid; gap: 12px; }
.research li { border: 1px solid var(--rule); border-radius: 12px; padding: 16px; margin: 0; }
.research b { display: block; font-weight: 600; margin-bottom: 4px; }
.research span { font-size: 16px; line-height: 24px; }

/* Callouts */
.callout { border: 1px solid var(--rule); border-radius: 12px; padding: 16px 24px; margin: 0 0 24px; background: var(--surface); }
.callout p:last-child { margin-bottom: 0; }

.invite { list-style: none; padding: 0; display: grid; gap: 8px; }
.invite li { padding-left: 24px; position: relative; }
.invite li::before { content: "→"; position: absolute; left: 0; color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 32px 0 0; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px;
  font-family: inherit; font-size: 16px; line-height: 24px; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid var(--text); background: var(--text); color: var(--bg);
  transition: transform 300ms var(--ease), opacity 300ms var(--ease), background-color 300ms var(--ease);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--rule); }
.btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Cite */
.cite { font-size: 14px; line-height: 20px; color: var(--muted); border: 1px solid var(--rule); border-radius: 12px; padding: 16px; margin-top: 24px; }
.cite code { font-family: inherit; color: var(--text); }
.copy-status { margin-left: 8px; color: var(--ok); }

/* References */
.refs { font-size: 16px; line-height: 24px; padding-left: 32px; }
.refs li { margin-bottom: 12px; scroll-margin-top: 24px; }
.refs li:target { background: var(--accent-soft); border-radius: 4px; }
.refs .back { text-decoration: none; margin-left: 4px; }

footer { border-top: 1px solid var(--rule); }
.footer-inner { max-width: 680px; margin: 0 auto; padding: 32px 24px 48px; font-size: 14px; line-height: 20px; color: var(--muted); }
.footer-inner p { margin: 0 0 8px; }

/* Reveal */
.reveal { opacity: 0; transform: translateY(32px); transition: opacity 700ms var(--ease), transform 700ms var(--ease); }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; transition: none; } }
.no-js .reveal { opacity: 1; transform: none; }

@media (max-width: 639px) {
  body { font-size: 18px; line-height: 28px; }
  .layout, .topbar { padding-left: 16px; padding-right: 16px; }
  .title-block { padding-top: 40px; }
  .subtitle { font-size: 20px; line-height: 28px; }
  article h2 { font-size: 24px; line-height: 32px; margin-top: 48px; }
  .abstract { padding: 16px; }
  .principles li { padding-left: 56px; }
  .principles li::before { left: 12px; }
}
@media print {
  .topbar, .toc-side, .toc-inline, .progress, .theme-toggle, .actions { display: none !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
  body { background: #fff; color: #000; }
}

.meta a { color: var(--text); text-decoration-style: dotted; text-underline-offset: 4px; }

/* About the author */
.about-head { display: flex; align-items: center; gap: 16px; margin: 64px 0 24px; }
.about-head h2 { margin: 0 !important; }
.avatar { display: block; width: 80px; height: 80px; border-radius: 999px; object-fit: cover; border: 1px solid var(--rule); background: var(--surface); flex: none; }
@media (max-width: 639px) { .about-head { margin-top: 48px; } .avatar { width: 64px; height: 64px; } }
