/* ==========================================================================
   plasticity.css — shared styling for the neural plasticity demos.

   Same Swiss/grid vocabulary as spins.css so the two demo sets feel like one
   site, with its own palette: the colour of a quantity is fixed across every
   figure here (pre-synaptic blue, post-synaptic amber, LTP green, LTD
   magenta), so a colour means the same thing from one page to the next.
   ========================================================================== */

:root {
    --bg: #ffffff;
    --fg: #111111;
    --muted: #666666;
    --accent: #0d9488;
    --panel: #f5f5f5;
    --panel-2: #ececec;
    --border: #e0e0e0;
    --canvas-bg: #ffffff;
    --grid: #e8e8e8;
    --note-bg: #f7f7f7;

    /* quantity colours: identical across the whole demo set */
    --c-pre: #2563eb;
    --c-post: #d97706;
    --c-ltp: #0e9f6e;
    --c-ltd: #c026d3;
    --c-neuron: #64748b;
    --c-membrane: #1a1a1a;
    --c-thresh: #dc2626;
    --c-rate: #6b7280;
    --c-theory: #7c3aed;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e0e11;
        --fg: #ededed;
        --muted: #9a9aa2;
        --accent: #2dd4bf;
        --panel: #17171b;
        --panel-2: #1f1f25;
        --border: #2b2b33;
        --canvas-bg: #121216;
        --grid: #26262e;
        --note-bg: #16161a;

        --c-pre: #60a5fa;
        --c-post: #fbbf24;
        --c-ltp: #34d399;
        --c-ltd: #e879f9;
        --c-neuron: #94a3b8;
        --c-membrane: #ededed;
        --c-thresh: #f87171;
        --c-rate: #9ca3af;
        --c-theory: #c4b5fd;
    }
}

:root[data-theme="dark"] {
    --bg: #0e0e11;
    --fg: #ededed;
    --muted: #9a9aa2;
    --accent: #2dd4bf;
    --panel: #17171b;
    --panel-2: #1f1f25;
    --border: #2b2b33;
    --canvas-bg: #121216;
    --grid: #26262e;
    --note-bg: #16161a;

    --c-pre: #60a5fa;
    --c-post: #fbbf24;
    --c-ltp: #34d399;
    --c-ltd: #e879f9;
    --c-neuron: #94a3b8;
    --c-membrane: #ededed;
    --c-thresh: #f87171;
    --c-rate: #9ca3af;
    --c-theory: #c4b5fd;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    padding: 0 0 72px;
    background: var(--bg);
    color: var(--fg);
    font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

.wrap {
    max-width: 1080px;
    margin: 0 auto;
    padding: 28px 24px 0;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 26px;
}

.navlinks {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    align-items: center;
}

.nav-link {
    text-decoration: none;
    color: var(--fg);
    font-weight: 600;
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
}

.nav-link:hover { color: var(--accent); }

.theme-toggle {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 12px;
    padding: 6px 10px;
    cursor: pointer;
    flex: none;
}

.theme-toggle:hover { color: var(--fg); border-color: var(--fg); }

/* ---------- header ---------- */

header.page {
    border-bottom: 3px solid var(--fg);
    padding-bottom: 18px;
    margin-bottom: 26px;
}

.kicker {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin: 0 0 10px;
}

h1 {
    font-size: clamp(26px, 4.4vw, 40px);
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1.08;
    margin: 0 0 12px;
    text-transform: uppercase;
}

.subtitle {
    font-size: 16px;
    font-weight: 300;
    color: var(--muted);
    max-width: 68ch;
    margin: 0;
}

.subtitle.eqline {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 14px;
    font-weight: 400;
}

h2 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.2px;
    margin: 0 0 12px;
}

h3 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0 0 10px;
}

/* ---------- panels and figure layout ---------- */

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 18px;
    margin-bottom: 20px;
}

.figs {
    display: grid;
    gap: 18px;
    margin-bottom: 20px;
    align-items: start;
}

.figs.two { grid-template-columns: 1.55fr 1fr; }
.figs.two-even { grid-template-columns: 1fr 1fr; }
.figs.side { grid-template-columns: 270px 1fr; }

@media (max-width: 880px) {
    .figs.two,
    .figs.two-even,
    .figs.side { grid-template-columns: 1fr; }

    /* Once the sidebar stops being a sidebar it sits above the figures, and a
       phone reader has to scroll past every slider to reach the thing the page
       is about. Put the figures first and the controls under them. */
    .figs.side > :first-child { order: 2; }
    .figs.side > :last-child { order: 1; }
}

.fig {
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

canvas {
    display: block;
    width: 100%;
    background: var(--canvas-bg);
    border: 1px solid var(--border);
    touch-action: none;
}

.cap {
    font-size: 12px;
    color: var(--muted);
    margin-top: 8px;
    line-height: 1.4;
}

/* ---------- controls ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
}

button {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 14px;
    border: 1px solid var(--fg);
    background: var(--bg);
    color: var(--fg);
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

button:hover { background: var(--fg); color: var(--bg); }

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

button.primary:hover { filter: brightness(1.12); background: var(--accent); color: #fff; }

button.on { background: var(--fg); color: var(--bg); }

button:disabled { opacity: 0.4; cursor: not-allowed; }
button:disabled:hover { background: var(--bg); color: var(--fg); }

.sep {
    width: 1px;
    align-self: stretch;
    background: var(--border);
    margin: 0 4px;
}

.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px 22px;
}

.controls.stack { grid-template-columns: 1fr; }

.control { min-width: 0; }

/* The text of a control label must be wrapped in a <span>: the label itself
   is a flex row, so a bare <sub> would become a separate flex item and get
   spaced away from the character it belongs to. */
.control label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.control label b {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-weight: 500;
    color: var(--fg);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.control input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    margin: 0;
}

.control .hint {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-top: 3px;
    line-height: 1.35;
}

.control select {
    width: 100%;
    font-family: inherit;
    font-size: 13px;
    padding: 6px 8px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
}

.checkrow {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    align-items: center;
}

.checkrow label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    color: var(--fg);
    cursor: pointer;
}

.checkrow input[type="checkbox"] { accent-color: var(--accent); }

/* ---------- readouts and legends ---------- */

.readouts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    padding-top: 12px;
    margin-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.readout { display: flex; gap: 7px; align-items: baseline; }
.readout span { color: var(--muted); font-size: 12px; }
.readout b {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 12px;
    color: var(--muted);
    margin-top: 10px;
}

.legend i {
    display: inline-block;
    width: 14px;
    height: 3px;
    margin-right: 6px;
    vertical-align: middle;
    font-style: normal;
}

.legend i.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend i.tick {
    width: 2px;
    height: 12px;
}

.legend i.dash {
    background: repeating-linear-gradient(to right,
            currentColor 0, currentColor 4px, transparent 4px, transparent 8px);
}

/* ---------- status line ---------- */

.status {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 13px;
    padding: 10px 14px;
    background: var(--panel-2);
    border-left: 3px solid var(--accent);
    margin-bottom: 16px;
}

/* ---------- canvas tooltip ---------- */

.tip {
    position: absolute;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--fg);
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    line-height: 1.5;
    padding: 6px 9px;
    white-space: pre;
}

.tip.on { opacity: 1; }

/* ---------- teaching notes ---------- */

.note {
    background: var(--note-bg);
    border: 1px solid var(--border);
    border-top: 3px solid var(--accent);
    padding: 20px 22px;
    margin-bottom: 20px;
}

.note p { margin: 0 0 12px; max-width: 76ch; }
.note p:last-child { margin-bottom: 0; }
.note ul, .note ol { margin: 0 0 12px; padding-left: 20px; max-width: 76ch; }
.note li { margin-bottom: 7px; }
.note ul:last-child, .note ol:last-child, .note li:last-child { margin-bottom: 0; }

.note code, code {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 0.92em;
    background: var(--panel-2);
    padding: 1px 5px;
}

.eq {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 13px;
    background: var(--panel-2);
    padding: 10px 14px;
    margin: 0 0 12px;
    overflow-x: auto;
}

/* ---------- parameter reference table ---------- */

.paramdoc {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 12px;
}

.paramdoc th, .paramdoc td {
    text-align: left;
    vertical-align: top;
    padding: 8px 12px 8px 0;
    border-bottom: 1px solid var(--border);
}

.paramdoc th {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
}

.paramdoc td.sym {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    white-space: nowrap;
    font-weight: 600;
}

.paramdoc td.typ {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    white-space: nowrap;
    color: var(--muted);
    font-size: 12px;
}

.paramdoc td p { margin: 0; max-width: 60ch; }

@media (max-width: 600px) {
    .paramdoc, .paramdoc tbody, .paramdoc tr, .paramdoc td { display: block; width: 100%; }
    .paramdoc thead { display: none; }
    .paramdoc tr { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 10px; }
    .paramdoc td { border-bottom: none; padding: 0 0 4px; }
}

/* ---------- self-test panel ---------- */

.selftest {
    font-size: 13px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    padding: 16px 18px;
    margin-top: 16px;
}

.selftest .case {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.selftest .case:last-child { border-bottom: none; }

.selftest .name { font-weight: 600; }

.selftest .detail {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 3px;
    line-height: 1.5;
}

.pass { color: var(--c-ltp); font-weight: 700; }
.fail { color: var(--c-thresh); font-weight: 700; }

/* ---------- related-links footer ---------- */

.related {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    font-size: 13px;
    color: var(--muted);
}

.related a { color: var(--fg); }
.related a:hover { color: var(--accent); }

.related .links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    margin-top: 8px;
}

/* ---------- index cards ---------- */

.section { margin-bottom: 44px; }

.section > h2 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin-bottom: 18px;
}

.section > p.lead {
    font-size: 14px;
    color: var(--muted);
    margin: -8px 0 18px;
    max-width: 70ch;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 18px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 20px;
    text-decoration: none;
    color: var(--fg);
    display: flex;
    flex-direction: column;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.card:hover {
    background: var(--accent);
    border-color: var(--accent);
    transform: translateY(-3px);
}

.card:hover * { color: #ffffff; }

.card-title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.2px;
    margin: 0 0 8px;
}

.card-desc {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.45;
    margin: 0 0 16px;
    flex: 1;
}

.card-meta {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

@media (max-width: 600px) {
    .wrap { padding: 20px 16px 0; }
    .panel, .note { padding: 16px; }
    .grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }

    .card:hover { transform: none; }
}
