:root {
    --blue: #1f77b4;
    --red: #d62728;
    --ink: #1a1a2e;
    --muted: #6b7280;
    --bg: #f3f4f8;
    --card: #ffffff;
    --ok: #1a8a4f;
    --ok-bg: #e6f6ee;
    --bad: #c0392b;
    --bad-bg: #fdecea;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    margin: 0;
    padding: 28px 16px 60px;
    text-align: center;
}

header { max-width: 1100px; margin: 0 auto 18px; }

h1 {
    font-size: 30px;
    margin: 0 0 6px;
    letter-spacing: -0.5px;
}

.lead { font-size: 16px; color: var(--muted); margin: 0 auto 14px; max-width: 720px; }
.lead strong { color: var(--ink); }

/* ---- summary bar ---- */
.summary {
    display: inline-block;
    background: var(--ink);
    color: #fff;
    padding: 10px 22px;
    border-radius: 999px;
    font-size: 16px;
    margin-bottom: 14px;
    min-height: 20px;
}
.summary b { color: #ffd54f; }

/* ---- controls ---- */
.controls { margin: 4px 0 8px; }

button {
    padding: 11px 18px;
    margin: 5px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid var(--ink);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    transition: all .12s ease;
}
button:hover:not(:disabled) { background: var(--ink); color: #fff; }
button:disabled { opacity: .45; cursor: default; }

/* ---- layout ---- */
.container {
    display: flex;
    justify-content: center;
    gap: 26px;
    flex-wrap: wrap;
    max-width: 1100px;
    margin: 0 auto;
}

.panel {
    background: var(--card);
    width: 490px;
    padding: 18px;
    border-radius: 14px;
    box-shadow: 0 6px 22px rgba(20, 20, 60, 0.10);
    border: 1px solid #e6e8f0;
}

.panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
}
.panel-head h2 { margin: 0; font-size: 21px; }
.arch {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    background: #eef0f6;
    color: #444;
    padding: 3px 8px;
    border-radius: 6px;
}

canvas#linearCanvas, canvas#nnCanvas {
    width: 450px;
    height: 450px;
    border: 1px solid #d6d9e6;
    border-radius: 10px;
    margin-top: 12px;
    background: #fff;
}

/* ---- stats ---- */
.stats { margin-top: 14px; }

.stat-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
    margin-bottom: 10px;
}
.stat-value {
    font-size: 46px;
    font-weight: 800;
    letter-spacing: -1px;
    color: var(--muted);
    transition: color .2s;
}
.stat-hero.ok .stat-value { color: var(--ok); }
.stat-hero.bad .stat-value { color: var(--bad); }
.stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--muted);
    margin-top: 3px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    border-top: 1px solid #eceef5;
    padding-top: 10px;
}
.stat-grid > div { display: flex; flex-direction: column; }
.stat-grid b {
    font-size: 18px;
    color: var(--ink);
}
.stat-grid span {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
}

/* ---- sparkline ---- */
.spark { width: 410px; height: 46px; margin-top: 10px; }
.spark-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
    margin-top: -4px;
}

/* ---- verdict ---- */
.verdict {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    background: #eef0f6;
    color: var(--muted);
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.verdict.ok { background: var(--ok-bg); color: var(--ok); }
.verdict.bad { background: var(--bad-bg); color: var(--bad); }
.verdict.busy { background: #fff8e1; color: #8a6d00; }

/* ---- legend ---- */
.legend {
    margin: 26px auto 8px;
    font-size: 13px;
    color: var(--muted);
    max-width: 900px;
}
.dot {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 3px;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,.2);
}
.dot.blue { background: var(--blue); }
.dot.red { background: var(--red); }
.ring {
    display: inline-block;
    width: 14px; height: 14px;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 3px;
    border: 2px solid #111;
    background: transparent;
}
.swatch.grad {
    display: inline-block;
    width: 46px; height: 12px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 3px;
    background: linear-gradient(90deg, var(--blue), #fff, var(--red));
    border: 1px solid rgba(0,0,0,.15);
}

.footnote {
    max-width: 760px;
    margin: 14px auto 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--muted);
}
.footnote em { color: var(--blue); font-style: normal; font-weight: 600; }

/* ===========================================================
   PART 2 — depth without nonlinearity
   =========================================================== */
.divider {
    max-width: 760px;
    margin: 44px auto 30px;
    border: none;
    border-top: 2px dashed #c8ccd9;
}
header.part { max-width: 1100px; margin: 0 auto 18px; }
header.part h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -0.5px; }

/* three-across row uses slimmer panels */
.container.triple { gap: 18px; }
.panel.sm { width: 380px; padding: 16px; }
.panel.sm .panel-head h2 { font-size: 18px; }
.panel.sm .arch { font-size: 11px; }
canvas.sm {
    width: 340px;
    height: 340px;
    border: 1px solid #d6d9e6;
    border-radius: 10px;
    margin-top: 12px;
    background: #fff;
}
.panel.sm .stat-value { font-size: 40px; }
.spark.sm { width: 300px; height: 42px; }

/* ---- bonus matrix-collapse box ---- */
.bonus {
    max-width: 1100px;
    margin: 34px auto 0;
    background: var(--card);
    border: 1px solid #e6e8f0;
    border-left: 5px solid var(--blue);
    border-radius: 14px;
    padding: 22px 26px;
    box-shadow: 0 6px 22px rgba(20, 20, 60, 0.10);
    text-align: center;
}
.bonus-head {
    font-size: 20px;
    font-weight: 800;
    color: var(--ink);
    margin-bottom: 6px;
}
.bonus-sub {
    font-size: 14px;
    color: var(--muted);
    line-height: 1.55;
    max-width: 760px;
    margin: 0 auto 18px;
}
.bonus-sub strong { color: var(--ink); }

.matrix-eq {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px 6px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 15px;
    margin: 10px auto 16px;
}
.matrix-eq .m {
    background: #eef0f6;
    border: 1px solid #d6d9e6;
    border-radius: 8px;
    padding: 8px 12px;
    color: #444;
    white-space: nowrap;
}
.matrix-eq .m small {
    display: block;
    font-size: 10px;
    color: var(--muted);
    margin-top: 2px;
}
.matrix-eq .m.result {
    background: #e6f6ee;
    border-color: #9ad9b8;
    color: var(--ok);
    font-weight: 700;
}
.matrix-eq .m.bias {
    background: #fff8e1;
    border-color: #ffe08a;
    color: #8a6d00;
    font-weight: 700;
}
.matrix-eq .op { color: var(--muted); font-weight: 700; padding: 0 2px; }
.matrix-eq .op.eq { color: var(--ink); font-size: 18px; }

.collapse-verdict {
    margin-top: 8px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    background: #eef0f6;
    color: var(--muted);
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.collapse-verdict.ok { background: var(--ok-bg); color: var(--ok); }
.collapse-verdict b { color: inherit; }

/* ===========================================================
   PART 3 (S1-3) — embeddings learn similarity from next-token
   =========================================================== */
.s13-wrap {
    display: flex;
    justify-content: center;
    gap: 26px;
    flex-wrap: wrap;
    max-width: 1100px;
    margin: 0 auto;
}
.s13-wrap .panel { width: 490px; text-align: left; }

.s13-help {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.55;
    margin: 8px 0 12px;
}
.s13-help em { color: var(--blue); font-style: normal; font-weight: 600; }
.s13-help code {
    background: #eef0f6;
    padding: 1px 5px;
    border-radius: 5px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12px;
}

/* ---- vocabulary box (the words, visible to the user) ---- */
.s13-vocab { display: flex; flex-direction: column; gap: 9px; }
.s13-cat { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.s13-catname {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
    width: 64px;
    text-align: right;
}
.s13-chips { display: flex; gap: 7px; flex-wrap: wrap; }
.s13-chip {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .12);
}

.panel-head.s13-sub { margin-top: 18px; }
.panel-head.s13-sub h2 { font-size: 18px; }

.s13-presets {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.s13-presets label { font-size: 13px; color: var(--muted); }
.s13-presets select {
    padding: 6px 8px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
    font-family: inherit;
}
.s13-presets button { padding: 7px 12px; font-size: 13px; }

.s13-rows {
    max-height: 224px;
    overflow-y: auto;
    border: 1px solid #e6e8f0;
    border-radius: 10px;
    padding: 9px;
    background: #fafbff;
}
.s13-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.s13-row:last-child { margin-bottom: 0; }
.s13-rn { width: 16px; font-size: 12px; color: var(--muted); text-align: right; }
.s13-input {
    flex: 1;
    padding: 7px 10px;
    font-size: 14px;
    border: 1px solid #d6d9e6;
    border-radius: 7px;
    font-family: inherit;
    color: var(--ink);
}
.s13-input:focus { outline: none; border-color: var(--blue); }
.s13-del {
    padding: 4px 9px;
    font-size: 13px;
    border-color: #d6d9e6;
    color: var(--bad);
}

.s13-corpus {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    gap: 18px;
}

.s13-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 6px 0 4px;
}
.s13-controls label { font-size: 12px; color: var(--muted); }
.s13-controls input {
    width: 68px;
    padding: 6px 8px;
    border: 2px solid var(--ink);
    border-radius: 7px;
    font-size: 13px;
    font-family: inherit;
}
.s13-controls button { padding: 8px 14px; font-size: 14px; }

.s13-metrics { display: flex; gap: 26px; margin: 6px 0 10px; }
.s13-metrics div { display: flex; flex-direction: column; }
.s13-metrics b { font-size: 20px; color: var(--ink); }
.s13-metrics span {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
}

canvas#s13Canvas {
    width: 440px;
    height: 440px;
    border: 1px solid #d6d9e6;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}

.s13-legend {
    margin-top: 8px;
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
}
.s13-leg {
    font-size: 13px;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
}
.s13-legdot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .2);
}

.s13-nn { max-width: 1100px; margin: 18px auto 0; text-align: left; }
.s13-nn-body {
    font-size: 14px;
    color: var(--muted);
    padding: 6px 2px;
    min-height: 42px;
    line-height: 1.6;
}
.s13-nn-q {
    font-weight: 800;
    font-size: 16px;
    color: var(--ink);
    margin-right: 14px;
    padding: 4px 12px;
    background: #eef0f6;
    border-radius: 8px;
}
.s13-nn-item {
    display: inline-block;
    padding: 5px 11px;
    margin: 4px 6px 0 0;
    border-left: 4px solid #ccc;
    background: #fafbff;
    border-radius: 6px;
    font-weight: 600;
    color: var(--ink);
}
.s13-nn-item small { color: var(--muted); font-weight: 400; margin-left: 4px; }

