/* Backprop explorer — step walkthrough. Hyperstack tokens, theme-aware, no CDNs. */
:root {
  --bg:#fff; --fg:#0f172a; --muted:#475569; --surface:#f1f5f9; --panel:#fff; --border:#e2e8f0; --inset:#f8fafc;
  --primary:#2563eb; --primary-contrast:#fff; --good:#15803d; --warn:#b45309; --bad:#b91c1c; --neuron:#7c3aed;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#0f172a; --fg:#f8fafc; --muted:#a5b1c2; --surface:#1e293b; --panel:#1e293b; --border:#334155; --inset:#0f172a;
    --primary:#60a5fa; --primary-contrast:#0b1220; --good:#22c55e; --warn:#fbbf24; --bad:#f87171; --neuron:#a78bfa; }
}
[data-theme="light"] { --bg:#fff; --fg:#0f172a; --muted:#475569; --surface:#f1f5f9; --panel:#fff; --border:#e2e8f0; --inset:#f8fafc; --primary:#2563eb; --primary-contrast:#fff; --good:#15803d; --warn:#b45309; --bad:#b91c1c; --neuron:#7c3aed; }
[data-theme="dark"] { --bg:#0f172a; --fg:#f8fafc; --muted:#a5b1c2; --surface:#1e293b; --panel:#1e293b; --border:#334155; --inset:#0f172a; --primary:#60a5fa; --primary-contrast:#0b1220; --good:#22c55e; --warn:#fbbf24; --bad:#f87171; --neuron:#a78bfa; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: ui-sans-serif, system-ui, sans-serif; }
#app { padding: 16px; max-width: 1000px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.layout-grid { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
@media (max-width: 800px) { .layout-grid { grid-template-columns: 1fr; } }
.sidebar { display: flex; flex-direction: column; gap: 12px; }
.main-content { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.panel h2 { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }

/* Steps nav */
.steps-nav { display: flex; flex-direction: column; gap: 6px; background: var(--surface); padding: 8px; border-radius: 12px; border: 1px solid var(--border); }
.step-btn { text-align: left; font: inherit; font-size: 13px; font-weight: 600; padding: 9px 12px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; transition: all .15s; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.step-btn:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); color: var(--fg); }
.step-btn.active { background: var(--primary); color: var(--primary-contrast); box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 40%, transparent); }
.step-num { font-size: 11px; font-family: ui-monospace, monospace; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--fg) 10%, transparent); }
.step-btn.active .step-num { background: color-mix(in srgb, var(--fg) 25%, var(--primary)); }

.explain { border-left: 4px solid var(--primary); min-height: 150px; }
.e-title { font-size: 15px; font-weight: 800; color: var(--fg); margin-bottom: 6px; }
.e-desc { font-size: 14px; line-height: 1.6; color: var(--muted); }
.e-desc b { color: var(--fg); }

.controls { display: flex; flex-direction: column; gap: 10px; }
.btn { width: 100%; border: none; border-radius: 9px; padding: 10px; font-weight: 800; font-size: 14px; cursor: pointer; transition: filter .15s, background .15s; color: var(--primary-contrast); }
.btn:hover { filter: brightness(.92); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.run { background: var(--warn); } .btn.step { background: var(--primary); } .btn.train { background: var(--good); } .btn.train.on { background: var(--warn); }
.btn.reset { background: var(--surface); color: var(--fg); border: 1px solid var(--border); }
.btn-row { display: flex; gap: 8px; } .btn-row .btn { flex: 1; }
.inf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inf-grid label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.inf-grid input { width: 100%; background: var(--inset); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; color: var(--fg); font-size: 14px; }
.inf-result { padding: 12px; border-radius: 10px; text-align: center; border: 1px solid var(--border); background: var(--inset); }
.inf-result.buy { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.inf-result.walk { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.inf-result .k { font-size: 12px; color: var(--muted); }
.inf-result .score { font-size: 24px; font-weight: 800; font-family: ui-monospace, monospace; margin: 3px 0; }
.inf-result .verdict { font-size: 14px; font-weight: 800; } .inf-result.buy .verdict { color: color-mix(in srgb, var(--good) 75%, var(--fg)); } .inf-result.walk .verdict { color: color-mix(in srgb, var(--bad) 75%, var(--fg)); }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.m-card { background: var(--panel); padding: 11px; text-align: center; }
.m-k { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.m-v { font-size: 20px; font-weight: 800; font-family: ui-monospace, monospace; margin-top: 3px; }
.m-v.loss { color: var(--bad); }
.converged { padding: 11px 13px; border-radius: 10px; border: 1px solid var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--fg); font-size: 13px; font-weight: 700; display: none; }
.converged.show { display: block; } .converged b { color: color-mix(in srgb, var(--good) 75%, var(--fg)); }

/* Diagram */
.diagram { overflow-x: auto; }
.diagram svg { width: 100%; min-width: 0; height: auto; display: block; }
.conn-g { transition: opacity .3s; }
.dimmed { opacity: .12 !important; }
.bp-g { transition: opacity .3s; }
.bp { stroke-dasharray: 5 4; }
.bp.train { animation: bpflow .55s linear infinite; }
@keyframes bpflow { to { stroke-dashoffset: -18; } }
.fwd.flow { animation: fwdpulse 1.4s ease-in-out infinite; }
@keyframes fwdpulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }

/* Decision graph */
.graph-box { position: relative; width: 100%; max-width: 340px; margin: 0 auto; aspect-ratio: 1/1; background: var(--inset); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.graph-box svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.axlabel { position: absolute; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.axlabel.x { bottom: 5px; width: 100%; text-align: center; }
.axlabel.y { left: 5px; top: 0; bottom: 0; display: flex; align-items: center; writing-mode: vertical-rl; transform: rotate(180deg); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend .it { display: flex; align-items: center; gap: 6px; } .legend .dot { width: 11px; height: 11px; border-radius: 50%; }

/* Sample trace readout */
.trace { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.trace .tr { display: flex; justify-content: space-between; padding: 7px 10px; background: var(--inset); border: 1px solid var(--border); border-radius: 8px; }
.trace .tr .lab { color: var(--muted); } .trace .tr .val { font-family: ui-monospace, monospace; font-weight: 700; }
.trace .tr.out .val { color: var(--good); } .trace .tr.err .val { color: var(--bad); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
