:root { --bg:#000000; --panel:#111a2e; --text:#e8eefc; --muted:#a9b6d6; --accent:#7aa2ff; --good:#5eead4; --warn:#fbbf24; --viz-pane-height:465px; }
* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body {
    margin: 0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
    background: radial-gradient(1200px 800px at 20% 0%, #142043, var(--bg));
    color: var(--text);
    overflow-y: scroll;
}
header { padding: 18px 18px 10px; position: relative; }
header h1 { margin: 0 0 6px; font-size: 18px; font-weight: 700; }
header p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.35; max-width: 980px; }
.pageNav {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    position: absolute;
    top: 18px;
    right: 18px;
}
.pageNavButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 74px;
    min-height: 34px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.05);
    color: var(--text);
    text-decoration: none;
    font-size: 12px;
    line-height: 1;
}
.pageNavButton:hover {
    background: rgba(255,255,255,0.09);
}
.pageNavButton.is-disabled {
    color: rgba(232,238,252,0.45);
    cursor: default;
    pointer-events: none;
}

.wrap { display: grid; grid-template-columns: 560px minmax(0, 1fr); gap: 14px; padding: 14px 18px 18px; }
@media (max-width: 980px) { .wrap { grid-template-columns: 1fr; } }

.card {
    background: color-mix(in oklab, var(--panel) 92%, black);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
}
.card h2 { margin: 0 0 10px; font-size: 14px; color: #dbe6ff; }
.controlBox {
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    padding: 12px;
}
.controlBox h2 {
    margin-bottom: 0;
}
.row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin: 10px 0; }
.row label { color: var(--muted); font-size: 12px; }
.row .val { font-variant-numeric: tabular-nums; font-size: 12px; color: #dbe6ff; }

select, button, input[type="range"] {
    width: 100%;
}
select {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 10px;
    padding: 10px 10px;
    outline: none;
}
input[type="number"] {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 10px;
    padding: 10px 10px;
    outline: none;
    width: 100%;
}
button {
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.06);
    color: var(--text);
    padding: 10px 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 80ms ease, background 120ms ease;
    font-weight: 600;
}
button:hover { background: rgba(255,255,255,0.09); }
button:active { transform: translateY(1px); }
button.primary.stage-active {
    border-color: rgba(255, 255, 255, 0.35);
    background: rgba(122,162,255,0.14);
}
button.primary.stage-active:hover { background: rgba(122,162,255,0.20); }
#btnStep.stage-active, #btnRunAll.stage-active {
    border-color: rgba(16,185,129,0.45);
    background: rgba(16,185,129,0.16);
    color: #d9fffa;
}
#btnStep.stage-active:hover, #btnRunAll.stage-active:hover {
    background: rgba(16,185,129,0.24);
}
#btnDescend.stage-active {
    border-color: rgba(245,158,11,0.5);
    background: rgba(245,158,11,0.2);
    color: #fff7ed;
}
#btnDescend.stage-active:hover {
    background: rgba(245,158,11,0.3);
}
#lrRange {
    accent-color: #f59e0b;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btnRow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 10px; }
.small { font-size: 12px; color: var(--muted); line-height: 1.35; }

.stats {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 10px; margin-top: 10px;
}
.pill {
    border: 1px solid rgba(255,255,255,0.10);
    background: rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 10px 10px;
}
.pill .k { font-size: 11px; color: var(--muted); }
.pill .v { margin-top: 3px; font-size: 14px; font-variant-numeric: tabular-nums; }
#chainRuleInfo {
    height: 220px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(169,182,214,0.45) rgba(255,255,255,0.05);
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.45;
    padding-right: 6px;
}
#chainRuleInfo::-webkit-scrollbar {
    width: 10px;
}
#chainRuleInfo::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
}
#chainRuleInfo::-webkit-scrollbar-thumb {
    background: rgba(169,182,214,0.45);
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.05);
}
#chainRuleInfo::-webkit-scrollbar-thumb:hover {
    background: rgba(169,182,214,0.62);
}

.vizCol { display: grid; gap: 14px; align-content: start; position: relative; }
.vizToolbar {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 5;
    background: rgba(10,16,30,0.85);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 10px;
    padding: 6px 8px;
    backdrop-filter: blur(3px);
}
.vizToolbar label { font-size: 12px; color: var(--muted); }
.vizToolbar select {
    width: auto;
    min-width: 118px;
    padding: 6px 8px;
    border-radius: 8px;
}
.graphWrap { display: flex; flex-direction: column; gap: 10px; }
.plotWrap { display: flex; flex-direction: column; gap: 10px; }
.graphScroll { min-height: 0; }
.graphWrap h2, .plotWrap h2 { padding-right: 140px; }
#graph { width: 100%; height: var(--viz-pane-height); min-height: var(--viz-pane-height); display: block; }
#plot3d { width: 100%; height: var(--viz-pane-height); }
.vizCol.only-one .graphScroll { flex: 1; min-height: 0; }
.vizCol.only-one #graph { height: 100%; min-height: 0; }
.vizCol.only-one #plot3d { height: 100%; min-height: 0; flex: 1; }
.legend {
    display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; color: var(--muted); font-size: 12px;
}
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.10); }
.dot { width: 10px; height: 10px; border-radius: 999px; display: inline-block; }
.dot.fwd { background: var(--accent); }
.dot.rev { background: var(--good); }
.dot.seed { background: var(--warn); }
.dot.forwardp { background: #ffffff; border: 1px solid rgba(255,255,255,0.45); }
.dot.previewp { background: #f59e0b; }
.dot.datawhite { background: #ffffff; border: 1px solid rgba(255,255,255,0.45); }

.foot { margin-top: 10px; font-size: 12px; color: var(--muted); }
a { color: #b6c7ff; }

.backpropWorkbench {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(420px, 2fr) minmax(280px, 1fr);
    gap: 14px;
    padding: 14px 18px 18px;
    align-items: start;
}
.backpropColumn {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}
.backpropSection {
    min-height: 0;
}
.backpropSpacerPanel {
    min-height: 0;
    flex: 1 1 auto;
}
.backpropInlineControls {
    margin-bottom: 12px;
    padding-bottom: 12px;
}
.backpropTrueSurfacePanel .backpropInlineControls,
.backpropPredictedPanel .backpropInlineControls {
    height: 176px;
    min-height: 176px;
}
.backpropInlineControls h2 {
    margin-bottom: 8px;
}
.backpropCompactControls .row {
    margin: 6px 0;
}
.backpropCompactControls .row label,
.backpropCompactControls .row .val {
    font-size: 11px;
}
.backpropCompactControls select {
    padding: 7px 9px;
    font-size: 12px;
}
.backpropCompactControls input[type="range"] {
    margin-top: -2px;
}
.backpropCompactControls .btnRow {
    margin-top: 8px;
}
.backpropCompactControls button {
    padding: 8px 10px;
    font-size: 12px;
}
.trueSurfaceControls {
    margin-bottom: 12px;
    padding-bottom: 12px;
}
.trueSurfaceTopRow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
    margin-top: 8px;
}
.trueSurfaceTopField {
    min-width: 0;
}
.trueSurfaceTopAction {
    display: flex;
    align-items: end;
}
.trueSurfaceTopAction button {
    width: auto;
    min-width: 120px;
    white-space: nowrap;
}
.networkBuilderCard {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    height: auto;
}
.networkBuilderHeader {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.networkBuilderActions {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.networkBuilderLabel {
    font-size: 11px;
    color: var(--muted);
}
.networkBuilderSelect {
    width: auto;
    min-width: 108px;
    padding: 10px 12px;
}
.networkBuilderActions button {
    width: auto;
    min-width: 84px;
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.1;
}
.builderHelp {
    max-width: 540px;
    margin: 0;
}
.builderLossNote {
    margin: -2px 0 0;
}
.networkBuilderSvg {
    width: 100%;
    flex: 0 0 auto;
    height: auto;
    min-height: 336px;
    display: block;
    border-radius: 12px;
    background:
      radial-gradient(circle at 20% 20%, rgba(122,162,255,0.12), transparent 28%),
      linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
    border: 1px solid rgba(255,255,255,0.08);
}
.backpropPlot {
    width: 100%;
    height: 100%;
    min-height: 208px;
}
.plotFooterActions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}
.plotFooterActions button {
    width: auto;
    min-width: 96px;
    padding: 8px 12px;
}
#btnToggleTrain.training-start {
    border-color: rgba(16,185,129,0.45);
    background: rgba(16,185,129,0.18);
    color: #d9fffa;
}
#btnToggleTrain.training-start:hover {
    background: rgba(16,185,129,0.26);
}
#btnToggleTrain.training-pause {
    border-color: rgba(239,68,68,0.45);
    background: rgba(239,68,68,0.18);
    color: #fff1f2;
}
#btnToggleTrain.training-pause:hover {
    background: rgba(239,68,68,0.26);
}
.backpropTrueSurfacePanel #trueSurfacePlot,
.backpropPredictedPanel #trainSurfacePlot {
    height: 336px;
    min-height: 336px;
}
.backpropLossPlot {
    height: 208px;
    min-height: 176px;
}
.backpropStats {
    grid-template-columns: 1fr 1fr;
}

@media (max-width: 980px) {
    .backpropWorkbench {
        grid-template-columns: 1fr;
    }
    .backpropTrueSurfacePanel .backpropInlineControls,
    .backpropPredictedPanel .backpropInlineControls {
        height: auto;
        min-height: 0;
    }
    .networkBuilderSvg {
        min-height: 304px;
    }
    .backpropPlot {
        height: 304px;
    }
    .backpropTrueSurfacePanel #trueSurfacePlot,
    .backpropPredictedPanel #trainSurfacePlot {
        height: 304px;
        min-height: 304px;
    }
    .backpropLossPlot {
        height: 208px;
    }
}

body.autodiff-details {
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    background: #f6f8fa;
    color: #1f2937;
    text-align: center;
}
body.autodiff-details header {
    max-width: 980px;
    margin: 0 auto;
    padding: 22px 22px 10px;
    text-align: left;
}
body.autodiff-details header h1 {
    margin: 0 0 8px;
    font-size: 28px;
    line-height: 1.2;
    color: #1e3a8a;
}
body.autodiff-details header p {
    margin: 0;
    color: #374151;
    line-height: 1.45;
    max-width: none;
}
body.autodiff-details a {
    color: #2c7be5;
}
body.autodiff-details .pageNavButton {
    border-color: rgba(15, 23, 42, 0.12);
    background: #ffffff;
    color: #1f2937;
}
body.autodiff-details .pageNavButton:hover {
    background: #f8fbff;
}
body.autodiff-details .pageNavButton.is-disabled {
    color: rgba(31,41,55,0.4);
}

@media (max-width: 980px) {
    .pageNav {
        position: static;
        margin-top: 12px;
    }
}
body.autodiff-details .wrap {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 14px 22px 22px;
    max-width: 980px;
    margin: 0 auto;
}
body.autodiff-details .card {
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    text-align: left;
}
body.autodiff-details .card h2 {
    margin: 0 0 10px;
    font-size: 18px;
    color: #1f2937;
}
body.autodiff-details .small {
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
}
body.autodiff-details .pill {
    border: 1px solid rgba(44, 123, 229, 0.18);
    background: #f8fbff;
    border-radius: 10px;
    padding: 10px 12px;
}
body.autodiff-details .pill .v {
    margin-top: 0;
}
body.autodiff-details .detailGraphWrap {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
}
body.autodiff-details .detailGraph {
    width: 980px;
    min-width: 980px;
    height: 260px;
    display: block;
}
body.autodiff-details .dgEdge {
    stroke: #64748b;
    stroke-width: 2;
    fill: none;
    marker-end: url(#dArrow);
}
body.autodiff-details .dgNode {
    fill: #ffffff;
    stroke: rgba(15, 23, 42, 0.2);
    stroke-width: 1.5;
}
body.autodiff-details .dgText {
    fill: #1f2937;
    font-size: 14px;
    text-anchor: middle;
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
}
body.autodiff-details mjx-container[display="true"] {
    display: block;
    text-align: center;
    margin: 0.6em 0;
}
body.autodiff-details mjx-container {
    background: transparent !important;
}
body.autodiff-details .mathjax-hidden,
body.autodiff-details .MathJax_Preview,
body.autodiff-details script[type^="math/tex"] {
    display: none !important;
    visibility: hidden !important;
}
body.autodiff-details mjx-assistive-mml,
body.autodiff-details mjx-container + script {
    display: none !important;
}

@media (max-width: 640px) {
    body.autodiff-details header {
        padding: 16px 14px 8px;
    }
    body.autodiff-details .wrap {
        padding: 10px 14px 16px;
    }
    body.autodiff-details header h1 {
        font-size: 24px;
    }
}
