/* ══════════════════════════════════════════════════════════
   what_can_go_wrong.html  ·  page-specific styles
   ══════════════════════════════════════════════════════════ */

:root {
    --bg: #0a0a10;
    --bg-2: #12131c;
    --bg-panel: rgba(22, 23, 32, 0.75);
    --fg: #eef0f5;
    --text: #eef0f5;
    --text-dim: #d4d7e0;
    --muted: #8b90a3;
    --border: rgba(255, 255, 255, 0.09);
    --border-hover: rgba(255, 255, 255, 0.18);

    /* page semantic palette */
    --c-clean:    #58a6ff;
    --c-distort:  #ff5c7a;
    --c-noise:    #ffcf5c;
    --c-fixed:    #7be089;
    --c-sample:   #c084fc;
    --c-mark:     #22c55e;
    --c-stable:   #58a6ff;
    --c-unstable: #ff5c7a;
    --accent: var(--site-accent);
    --accent-soft: var(--site-accent-soft);
    --accent-soft-faint: var(--site-accent-soft-faint);
    --accent-soft-edge: var(--site-accent-soft-edge);

    --grid-line: rgba(255, 255, 255, 0.06);
    --grid-zero: rgba(255, 255, 255, 0.30);
    --tick-line: rgba(255, 255, 255, 0.25);
    --slider-track: rgba(255, 255, 255, 0.12);
    --pill-bg: rgba(255, 255, 255, 0.03);

    --body-size: 17px;
    --math-size: 18px;
    --hero-size: 60px;
}

[data-theme="light"] {
    --bg: #f5f5f7;
    --bg-2: #ffffff;
    --bg-panel: rgba(255, 255, 255, 0.92);
    --fg: #1a1a1e;
    --text: #1a1a1e;
    --text-dim: #2b2d38;
    --muted: #6a6f7c;
    --border: rgba(0, 0, 0, 0.10);
    --border-hover: rgba(0, 0, 0, 0.22);

    --c-clean:    #1d4ed8;
    --c-distort:  #dc2626;
    --c-noise:    #b88200;
    --c-fixed:    #2f8f3f;
    --c-sample:   #7e22ce;
    --c-mark:     #15803d;
    --c-stable:   #1d4ed8;
    --c-unstable: #dc2626;

    --grid-line: rgba(0, 0, 0, 0.07);
    --grid-zero: rgba(0, 0, 0, 0.32);
    --tick-line: rgba(0, 0, 0, 0.22);
    --slider-track: rgba(0, 0, 0, 0.12);
    --pill-bg: rgba(0, 0, 0, 0.03);
}

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

html, body {
    background: var(--bg);
    color: var(--fg);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: var(--body-size);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
body { overflow-x: hidden; min-height: 100vh; }

.katex { font-size: var(--math-size) !important; }
.katex-display { margin: 0.6em 0 !important; }
.katex-display > .katex { font-size: calc(var(--math-size) * 1.06) !important; }
h1 .katex, h2 .katex, h3 .katex { font-size: inherit !important; }

a { color: var(--accent); }

.brand {
    position: fixed; top: 20px; left: 24px; z-index: 40;
    font-size: 12px; color: var(--muted);
    letter-spacing: 0.08em; text-transform: uppercase;
    font-family: 'JetBrains Mono', monospace;
    display: flex; align-items: center; gap: 10px;
}
.brand .mark {
    width: 10px; height: 10px; border-radius: 50%;
    background: conic-gradient(var(--c-clean), var(--c-fixed), var(--c-distort), var(--c-noise), var(--c-clean));
}

.back-btn {
    position: fixed; top: 14px; right: 56px; z-index: 9999;
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 14px; border-radius: 999px;
    background: var(--bg-panel); border: 1px solid var(--border);
    color: var(--fg); text-decoration: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
    backdrop-filter: blur(8px); transition: all 0.15s;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }

.landing {
    min-height: 100vh; display: grid; place-items: center;
    padding: 120px 56px 80px; text-align: center; position: relative;
}
.landing .meta {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; color: var(--muted);
    letter-spacing: 0.2em; text-transform: uppercase;
    margin-bottom: 28px;
}
h1.hero {
    font-size: var(--hero-size); line-height: 1.02;
    font-weight: 600; letter-spacing: -0.025em;
    margin: 0 auto 24px; max-width: 22ch;
}
h1.hero em {
    font-style: normal;
    background: linear-gradient(135deg, var(--c-clean), var(--c-distort));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.landing .sub {
    color: var(--muted); font-size: 18px;
    max-width: 64ch; margin: 12px auto 0; line-height: 1.6;
}
.landing .tags {
    margin-top: 36px; display: flex; gap: 12px;
    justify-content: center; flex-wrap: wrap;
}
.field-tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px; color: var(--muted);
    letter-spacing: 0.12em; text-transform: uppercase;
    display: inline-block; padding: 4px 10px;
    border: 1px solid var(--border); border-radius: 4px;
}
.scroll-hint {
    position: absolute; bottom: 32px; left: 50%; transform: translateX(-50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px; letter-spacing: 0.2em;
    color: var(--muted); text-transform: uppercase;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.scroll-hint .line {
    width: 1px; height: 32px;
    background: linear-gradient(var(--muted), transparent);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 0.3; } 50% { opacity: 1; }
}

section.scene {
    min-height: 100vh; padding: 100px 40px 80px;
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.5fr);
    gap: 28px; align-items: start;
    border-bottom: 1px solid var(--border);
}
section.scene .copy { max-width: 560px; }

.eyebrow {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 18px;
    display: flex; align-items: center; gap: 10px;
}
.eyebrow .num { color: var(--accent); }
.eyebrow .bar { flex: 0 0 28px; height: 1px; background: var(--accent); }

h2 {
    font-size: 34px; line-height: 1.12;
    font-weight: 600; letter-spacing: -0.02em;
    margin: 0 0 18px; color: var(--fg);
}
h2 em { font-style: normal; }
h2 em.clean   { color: var(--c-clean); }
h2 em.distort { color: var(--c-distort); }
h2 em.noise   { color: var(--c-noise); }
h2 em.fixed   { color: var(--c-fixed); }

h3 {
    font-size: 17px; font-weight: 600;
    margin: 22px 0 8px; color: var(--fg); letter-spacing: -0.01em;
}

p { margin: 0 0 14px; color: var(--text-dim); }
p.lead { font-size: calc(var(--body-size) + 1px); color: var(--fg); }
p.dim  { color: var(--muted); }

strong { color: var(--fg); font-weight: 600; }

.eq-block {
    display: block; margin: 16px 0;
    padding: 14px 18px;
    background: var(--accent-soft-faint);
    border: 1px solid var(--accent-soft-edge);
    border-radius: 10px; text-align: center; color: var(--fg);
    overflow-x: auto;
}

.callout {
    margin-top: 18px; padding: 14px 18px;
    border-left: 2px solid var(--accent);
    background: var(--accent-soft-faint);
    border-radius: 0 8px 8px 0;
    font-size: 14px; color: var(--text-dim); line-height: 1.7;
}

.fix-callout {
    margin-top: 14px; padding: 14px 18px;
    border-left: 2px solid var(--c-fixed);
    background: rgba(123, 224, 137, 0.06);
    border-radius: 0 8px 8px 0;
    font-size: 14px; color: var(--text-dim); line-height: 1.7;
}
.fix-callout strong { color: var(--c-fixed); }
[data-theme="light"] .fix-callout {
    background: rgba(47, 143, 63, 0.07);
}

.plot-stack {
    display: flex; flex-direction: column; gap: 14px;
    width: 100%; max-width: 760px;
}

.plot-box {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 12px; background: var(--bg-2);
    overflow: hidden; width: 100%;
}
.plot-box.bode-pair { aspect-ratio: 1 / 1.05; }
.plot-box.bode-side { aspect-ratio: 2 / 1; }
.plot-box.splane    { aspect-ratio: 1 / 1; max-width: 540px; margin: 0 auto; }
.plot-box.single    { aspect-ratio: 1.9 / 1; }
.plot-box.tall      { aspect-ratio: 1 / 1.05; }
.plot-box.dual      { aspect-ratio: 1.4 / 1; }
.plot-box.response  { aspect-ratio: 2 / 1; min-height: 260px; }
.plot-box.ecg-wide  { aspect-ratio: 3.2 / 1; min-height: 250px; }
.plot-box.step      { aspect-ratio: 1.25 / 1; min-height: 390px; }
.plot-box.noise-side { aspect-ratio: 1.55 / 1; min-height: 300px; }
.plot-box.noise-bode { aspect-ratio: 2.6 / 1; min-height: 260px; }
.plot-box.alias-side { aspect-ratio: 1.55 / 1; min-height: 300px; }
.plot-box.alias-nyquist { aspect-ratio: 2.9 / 1; min-height: 270px; }
.plot-box svg { display: block; width: 100%; height: 100%; }

.response-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(320px, 1fr));
    gap: 14px;
}

#sec-phase-distortion {
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.8fr);
}
#sec-phase-distortion .plot-stack {
    max-width: clamp(820px, 62vw, 1080px);
}

.instability-grid {
    display: grid;
    grid-template-columns: minmax(340px, 0.95fr) minmax(420px, 1.15fr);
    gap: 14px;
    align-items: stretch;
}
#sec-instability .plot-stack {
    max-width: clamp(800px, 62vw, 1080px);
}

.noise-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(320px, 1fr));
    gap: 14px;
}
#sec-incomplete-noise {
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.8fr);
}
#sec-incomplete-noise .plot-stack {
    max-width: clamp(820px, 62vw, 1080px);
}

#sec-passband-ripple {
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.8fr);
}
#sec-passband-ripple .plot-stack {
    max-width: clamp(860px, 64vw, 1120px);
}
#sec-passband-ripple .plot-box.response {
    aspect-ratio: 1.7 / 1;
    min-height: 330px;
}

.alias-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(320px, 1fr));
    gap: 14px;
}
#sec-aliasing {
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.8fr);
}
#sec-aliasing .plot-stack {
    max-width: clamp(820px, 62vw, 1080px);
}

.plot-box .label {
    position: absolute; top: 10px; left: 14px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--muted); z-index: 2; pointer-events: none;
}
.plot-box .label b {
    font-weight: 600; letter-spacing: 0.06em; color: var(--fg);
}

.toolbar {
    display: flex; gap: 10px 14px; flex-wrap: wrap; align-items: center;
    padding: 10px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border); border-radius: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}
.toolbar .pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    background: var(--pill-bg);
    border: 1px solid var(--border); border-radius: 999px;
    color: var(--text-dim); cursor: pointer;
    text-transform: uppercase; letter-spacing: 0.08em;
    font-size: 10px; transition: all 0.12s; user-select: none;
}
.toolbar .pill:hover { border-color: var(--border-hover); color: var(--fg); }
.toolbar .pill.active {
    background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}
.toolbar .divider {
    width: 1px; height: 18px; background: var(--border); margin: 0 4px;
}
.toolbar .hint {
    color: var(--muted); font-size: 10px;
    letter-spacing: 0.06em; text-transform: none; padding-left: 4px;
}
.toolbar .slider-group {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 4px 8px;
}
.toolbar .slider-group .lab {
    color: var(--muted); font-size: 10px;
    letter-spacing: 0.1em; text-transform: uppercase;
}
.toolbar .slider-group .val {
    color: var(--fg); min-width: 6ch; text-align: right;
    white-space: nowrap;
}
.toolbar input[type="range"] {
    -webkit-appearance: none; appearance: none;
    width: 130px; height: 4px;
    background: var(--slider-track); border-radius: 999px;
    outline: none;
}
.toolbar input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent); cursor: pointer;
    border: 2px solid var(--bg-2);
}
.toolbar input[type="range"]::-moz-range-thumb {
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent); cursor: pointer;
    border: 2px solid var(--bg-2);
}

svg.bode text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px; fill: var(--muted);
}
svg.bode .grid line { stroke: var(--grid-line); stroke-width: 1; }
svg.bode .grid line.major { stroke: var(--grid-zero); stroke-width: 1.2; }
svg.bode .axis-line { stroke: var(--grid-zero); stroke-width: 1.4; }

svg.bode .trace { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
svg.bode .trace.clean    { stroke: var(--c-clean); }
svg.bode .trace.distort  { stroke: var(--c-distort); }
svg.bode .trace.noise    { stroke: var(--c-noise); }
svg.bode .trace.fixed    { stroke: var(--c-fixed); }
svg.bode .trace.stable   { stroke: var(--c-stable); }
svg.bode .trace.unstable { stroke: var(--c-unstable); }
svg.bode .trace.reference { opacity: 0.38; }
svg.bode .trace.faint    { opacity: 0.35; stroke-width: 1.4; stroke-dasharray: 4 4; }
svg.bode .trace.thin     { stroke-width: 1.4; opacity: 0.7; }

svg.bode .marker-line { stroke: var(--c-mark); stroke-width: 1.4; stroke-dasharray: 5 4; }
svg.bode .marker-dot  { fill: var(--c-mark); stroke: var(--bg-2); stroke-width: 2; }
svg.bode .marker-band { fill: var(--c-mark); opacity: 0.10; }

svg.bode .hover-overlay { fill: transparent; cursor: crosshair; }
svg.bode .hover-vline {
    stroke: var(--fg); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.55;
}
svg.bode .hover-dot { stroke: var(--bg-2); stroke-width: 1.6; }
svg.bode .hover-dot.clean    { fill: var(--c-clean); }
svg.bode .hover-dot.distort  { fill: var(--c-distort); }
svg.bode .hover-dot.noise    { fill: var(--c-noise); }
svg.bode .hover-dot.fixed    { fill: var(--c-fixed); }
svg.bode .readout-bg {
    fill: var(--bg-panel);
    stroke: var(--border); stroke-width: 1;
}
svg.bode .readout-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    fill: var(--text-dim);
}
svg.bode .readout-text.title { fill: var(--fg); }
svg.bode .readout-text.clean    { fill: var(--c-clean); }
svg.bode .readout-text.distort  { fill: var(--c-distort); }
svg.bode .readout-text.noise    { fill: var(--c-noise); }
svg.bode .readout-text.fixed    { fill: var(--c-fixed); }

svg.bode .pole-x   { stroke: var(--c-distort); stroke-width: 2.2; }
svg.bode .pole-x.stable { stroke: var(--c-clean); }
svg.bode .zero-o   { fill: none; stroke: var(--c-fixed); stroke-width: 2; }
svg.bode .axis-arrow { stroke: var(--grid-zero); stroke-width: 1.4; fill: none; }
svg.bode .splane-rhp { fill: var(--c-distort); opacity: 0.06; }

svg.bode foreignObject { overflow: visible; }
svg.bode .legend-pill {
    fill: var(--bg-panel); stroke: var(--border); stroke-width: 1;
}

footer {
    padding: 60px 56px 80px; text-align: center;
    color: var(--muted); font-size: 13px;
    border-top: 1px solid var(--border);
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.08em; text-transform: uppercase;
}

@media (max-width: 900px) {
    section.scene { grid-template-columns: 1fr; padding: 80px 24px 60px; }
    .response-grid { grid-template-columns: 1fr; }
    .instability-grid { grid-template-columns: 1fr; }
    .noise-grid { grid-template-columns: 1fr; }
    .alias-grid { grid-template-columns: 1fr; }
    h1.hero { font-size: 42px; }
    h2 { font-size: 26px; }
    .brand { top: 16px; left: 16px; }
}
