/* ==========================================================================
   spins.css — shared styling for the MRI spin-physics demos.
   Swiss/grid look to match the rest of the site, with a dark mode for
   lecture halls and an explicit [data-theme] override for projectors.
   ========================================================================== */

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

    /* physics colours: kept identical across the whole demo set so a colour
       always means the same quantity from one figure to the next */
    --c-mz: #1d4ed8;
    --c-mxy: #0f9d58;
    --c-net: #ff3300;
    --c-spin: #4a6fa5;
    --c-b0: #8b5cf6;
    --c-b1: #d97706;
    --c-env: #9ca3af;
    --c-up: #d92b2b;
    --c-down: #1f5fd0;
}

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

        --c-mz: #60a5fa;
        --c-mxy: #4ade80;
        --c-net: #ff5c33;
        --c-spin: #8ab4f8;
        --c-b0: #c4b5fd;
        --c-b1: #fbbf24;
        --c-env: #6b7280;
        --c-up: #f87171;
        --c-down: #60a5fa;
    }
}

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

    --c-mz: #60a5fa;
    --c-mxy: #4ade80;
    --c-net: #ff5c33;
    --c-spin: #8ab4f8;
    --c-b0: #c4b5fd;
    --c-b1: #fbbf24;
    --c-env: #6b7280;
    --c-up: #f87171;
    --c-down: #60a5fa;
}

* { 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;
}

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

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

.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;
}

.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;
}

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; }

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

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

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;
}

.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;
}

.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;
}

/* ---------- 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;
}

/* ---------- 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 { margin: 0 0 12px; padding-left: 20px; max-width: 76ch; }
.note li { margin-bottom: 7px; }
.note ul: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;
}

/* ---------- 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;
}

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

/* ---------- 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) {
    .grid { grid-template-columns: 1fr; }
}
