:root {
  color-scheme: dark;
  --bg: #07090d;
  --bg2: #0c0f15;
  --card: #10141b;
  --card2: #151a23;
  --border: rgba(255, 255, 255, .08);
  --text: #f2f3f5;
  --text2: #b7bbc4;
  --muted: #7f8591;
  --grid: rgba(255, 255, 255, .06);
  --axis: rgba(255, 255, 255, .28);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #9085e9;
  --glow: #6da7ec;
  --code-bg: #0a0d12;
  --k: #c792ea; --str: #9ece6a; --num: #ff9e64; --fn: #7aa2f7; --com: #6b7280;
  --blend: lighter;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f6f3; --bg2: #efeee9; --card: #fcfcfb; --card2: #f3f2ee;
  --border: rgba(0, 0, 0, .09);
  --text: #0b0b0b; --text2: #52514e; --muted: #85847e;
  --grid: rgba(0, 0, 0, .07); --axis: rgba(0, 0, 0, .32);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #4a3aa7;
  --glow: #2a78d6;
  --code-bg: #f1f0ec;
  --k: #7c3aed; --str: #3f7d20; --num: #c2410c; --fn: #1d4ed8; --com: #8a8983;
  --blend: source-over;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f6f6f3; --bg2: #efeee9; --card: #fcfcfb; --card2: #f3f2ee;
    --border: rgba(0, 0, 0, .09);
    --text: #0b0b0b; --text2: #52514e; --muted: #85847e;
    --grid: rgba(0, 0, 0, .07); --axis: rgba(0, 0, 0, .32);
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #4a3aa7;
    --glow: #2a78d6;
    --code-bg: #f1f0ec;
    --k: #7c3aed; --str: #3f7d20; --num: #c2410c; --fn: #1d4ed8; --com: #8a8983;
    --blend: source-over;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.65 "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
h1, h2, h3 { font-family: "Unbounded", "Inter", sans-serif; line-height: 1.15; margin: 0; }
a { color: var(--glow); }
code, pre, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
p code, li code, td code { font-size: .88em; background: var(--card2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; }

/* ---------- nav */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center; gap: 6px; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  transform: translateY(-100%); transition: transform .4s ease;
}
.nav.show { transform: none; }
.nav .brand { font-family: "Unbounded"; font-size: 14px; margin-right: auto; white-space: nowrap; }
.nav a.pill {
  text-decoration: none; color: var(--text2); font-size: 13px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.nav a.pill.on { color: var(--text); border-color: var(--border); background: var(--card2); }
.nav .progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: linear-gradient(90deg, var(--s1), var(--s3), var(--s5)); width: 0; }
.theme-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 15px; margin-left: 6px;
}
@media (max-width: 720px) { .nav a.pill { display: none; } }

/* ---------- hero */
.hero { position: relative; height: 100vh; min-height: 560px; overflow: hidden; }
#heroCanvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.hero-inner {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center;
  padding: 0 max(16px, 7vw); pointer-events: none;
}
.hero .eyebrow { color: var(--glow); font: 600 13px "JetBrains Mono"; letter-spacing: .2em; text-transform: uppercase; }
.hero h1 {
  font-size: clamp(40px, 8.5vw, 118px); font-weight: 800; margin: 14px 0 18px; letter-spacing: -.02em;
  background: linear-gradient(100deg, var(--text) 30%, var(--s1) 55%, var(--s3) 72%, var(--s5));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero .lead { text-shadow: 0 0 18px var(--bg), 0 0 4px var(--bg); max-width: 640px; font-size: clamp(16px, 2vw, 20px); color: var(--text2); }
.hero .readout {
  position: absolute; left: max(16px, 7vw); bottom: 34px; display: flex; gap: 12px; flex-wrap: wrap; pointer-events: none;
}
.chip {
  font: 500 13px "JetBrains Mono"; padding: 8px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--card) 70%, transparent); border: 1px solid var(--border);
  backdrop-filter: blur(8px); color: var(--text2);
}
.chip b { color: var(--text); font-weight: 600; }
.hero .hint { position: absolute; right: max(16px, 4vw); bottom: 38px; color: var(--muted); font-size: 13px; pointer-events: none; }
.scroll-cue { display: inline-block; margin-top: 28px; color: var(--muted); font-size: 14px; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(6px); } }

/* ---------- sections */
main { position: relative; z-index: 1; }
section.part { padding: 110px max(16px, 6vw) 40px; max-width: 1280px; margin: 0 auto; }
.part-head { display: grid; grid-template-columns: auto 1fr; gap: 6px 22px; align-items: end; margin-bottom: 34px; }
.part-num {
  grid-row: span 2; font: 800 clamp(56px, 9vw, 110px)/.85 "Unbounded";
  background: linear-gradient(160deg, var(--s1), var(--s5)); -webkit-background-clip: text; background-clip: text; color: transparent;
  opacity: .9;
}
.part-head h2 { font-size: clamp(24px, 3.4vw, 40px); }
.part-head .sub { color: var(--text2); max-width: 760px; }
.task {
  border-left: 3px solid var(--s1); background: var(--card); padding: 14px 18px; border-radius: 0 14px 14px 0;
  color: var(--text2); font-size: 15px; margin-bottom: 26px;
}
.task b { color: var(--text); }

.grid2 { display: grid; grid-template-columns: 1.1fr .9fr; gap: 22px; align-items: start; }
.grid2.even { grid-template-columns: 1fr 1fr; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 960px) { .grid2, .grid2.even, .grid3 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 22px;
  position: relative; min-width: 0;
}
.card h3 { font-size: 17px; margin-bottom: 10px; }
.card .cap { color: var(--muted); font-size: 13px; margin-top: 8px; }
.answer {
  background: linear-gradient(160deg, color-mix(in srgb, var(--s1) 13%, var(--card)), var(--card) 55%);
  border: 1px solid color-mix(in srgb, var(--s1) 35%, var(--border));
}
.answer .tag {
  display: inline-block; font: 600 11px "JetBrains Mono"; letter-spacing: .14em; text-transform: uppercase;
  color: var(--glow); margin-bottom: 8px;
}
.answer p, .card p { margin: 0 0 12px; color: var(--text2); }
.answer p:last-child, .card p:last-child { margin-bottom: 0; }
.answer strong, .card strong { color: var(--text); }
ul.clean { margin: 0; padding-left: 18px; color: var(--text2); }
ul.clean li { margin-bottom: 8px; }
ul.clean li::marker { color: var(--glow); }

/* ---------- code */
pre.code {
  margin: 0; background: var(--code-bg); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 20px; overflow-x: auto; font-size: 13.5px; line-height: 1.6;
}
pre.code .hljs-keyword, pre.code .hljs-built_in { color: var(--k); }
pre.code .hljs-string { color: var(--str); }
pre.code .hljs-number, pre.code .hljs-literal { color: var(--num); }
pre.code .hljs-title, pre.code .hljs-title.function_ { color: var(--fn); }
pre.code .hljs-comment { color: var(--com); font-style: italic; }
pre.code .hl { display: inline-block; width: 100%; background: color-mix(in srgb, var(--s1) 16%, transparent); border-radius: 4px; transition: background .3s; }
.code-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.code-head span { font: 500 12px "JetBrains Mono"; color: var(--muted); }

/* ---------- controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.btn {
  font: 500 13px "Inter"; color: var(--text); background: var(--card2); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; transition: all .2s;
}
.btn:hover { border-color: var(--glow); }
.btn.on { background: color-mix(in srgb, var(--s1) 22%, var(--card2)); border-color: var(--s1); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.seg .btn { border: 0; border-radius: 0; background: transparent; }
.seg .btn.on { background: color-mix(in srgb, var(--s1) 25%, var(--card2)); }
label.ctl { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text2); }
label.ctl b { color: var(--text); font-family: "JetBrains Mono"; min-width: 34px; }
input[type=range] { accent-color: var(--s1); width: 130px; }

/* ---------- plots */
.plot { position: relative; width: 100%; height: 360px; }
.plot.tall { height: 460px; }
.plot.short { height: 250px; }
.plot canvas, .stage canvas { display: block; width: 100%; height: 100%; }
.stage { position: relative; width: 100%; height: 420px; }
.tip {
  position: absolute; pointer-events: none; opacity: 0; z-index: 5; transition: opacity .12s;
  background: color-mix(in srgb, var(--card) 92%, transparent); border: 1px solid var(--border);
  backdrop-filter: blur(8px); border-radius: 12px; padding: 8px 12px; font-size: 12.5px; white-space: nowrap;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
}
.tip .h { color: var(--muted); font-family: "JetBrains Mono"; margin-bottom: 3px; }
.tip .r { display: flex; align-items: center; gap: 8px; color: var(--text2); }
.tip .r b { color: var(--text); font-family: "JetBrains Mono"; font-weight: 500; margin-left: auto; padding-left: 14px; }
.sw { width: 12px; height: 3px; border-radius: 2px; display: inline-block; flex: none; }
.sw.dash { background-image: linear-gradient(90deg, currentColor 55%, transparent 55%); background-size: 5px 3px; background-color: transparent !important; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text2); margin-top: 10px; }
.legend .li { display: flex; align-items: center; gap: 7px; }
.legend button.li { background: none; border: 1px solid var(--border); color: var(--text2); border-radius: 999px; padding: 4px 11px; cursor: pointer; font: inherit; }
.legend button.li.off { opacity: .38; text-decoration: line-through; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 14px; }
.stat { background: var(--card2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font: 600 22px "JetBrains Mono"; color: var(--text); margin-top: 2px; }
.stat .v small { font-size: 13px; color: var(--muted); font-weight: 400; }

/* ---------- table */
.tbl-wrap { overflow-x: auto; }
table.res { width: 100%; border-collapse: collapse; font-size: 14px; }
table.res th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.res td { padding: 10px; border-bottom: 1px solid var(--border); color: var(--text2); }
table.res td.num { font-family: "JetBrains Mono"; color: var(--text); text-align: right; }
table.res th.num { text-align: right; }
table.res tr.muted td { opacity: .7; }

/* ---------- variant cards */
.vcard { padding: 16px; }
.vcard .mini { height: 170px; border-radius: 12px; background: var(--card2); margin-bottom: 12px; position: relative; overflow: hidden; }
.vcard .mini canvas { width: 100%; height: 100%; display: block; }
.vcard h3 { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.vcard .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.vcard p { font-size: 14px; }
.vgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
@media (max-width: 1100px) { .vgrid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px) { .vgrid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 460px) { .vgrid { grid-template-columns: 1fr; } }

.formula { font-size: 1.05em; overflow-x: auto; padding: 4px 0; }
.big-formula { text-align: center; font-size: 1.3em; padding: 12px 0; }

/* ---------- reveal */
.reveal { opacity: 0; transform: translateY(28px); transition: opacity .8s ease, transform .8s cubic-bezier(.2, .7, .2, 1); }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; transition: none; } .scroll-cue { animation: none; } }

.spacer { height: 22px; }
footer { padding: 70px 16px 60px; text-align: center; color: var(--muted); font-size: 14px; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.summary .card .big { font: 700 26px "Unbounded"; margin-bottom: 6px; }
.dl { display: inline-flex; align-items: center; gap: 8px; margin-top: 18px; text-decoration: none; }
.grid2 > *, .grid3 > * { min-width: 0; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
@media (max-width: 720px) {
  .part-head { grid-template-columns: 1fr; }
  .part-num { grid-row: auto; font-size: 64px; }
  section.part { padding-top: 80px; }
  .stage { max-height: 440px; }
}
