/* ============================================================
   Card chrome and diagram components.

   Every block names its accent once (--fam / --fam-soft, set in reader.css)
   and everything here — the rail, the label medallion, the flow rails, the
   summary cards — is built out of those two, so a new block type only has to
   pick a colour to look right.
   ============================================================ */

/* ---------------------------------------------------------- card chrome */

/* one accent rail per card, drawn instead of a border so it follows the
   rounded corner and never fights the card's own border */
.block:not(.block--heading):not(.block--plain)::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: var(--radius) 0 0 var(--radius);
    background: linear-gradient(180deg, var(--fam), color-mix(in srgb, var(--fam) 22%, transparent));
    pointer-events: none;
}

.block__label { color: var(--fam); gap: 9px; margin-bottom: 12px; }
.block__label svg {
    width: 24px;
    height: 24px;
    padding: 4.5px;
    box-sizing: border-box;
    border-radius: 8px;
    color: var(--fam);
    background: color-mix(in srgb, var(--fam) 13%, var(--surface-2));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--fam) 20%, transparent);
    flex: none;
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .block:not(.block--heading):not(.block--plain) {
        transition: box-shadow var(--t), border-color var(--t);
    }
    .block:not(.block--heading):not(.block--plain):hover {
        box-shadow: var(--shadow-sm);
        border-color: color-mix(in srgb, var(--fam) 32%, var(--border));
    }
}

/* types that read better with their own texture */
.block[data-type="definition"] .block__body > p:first-child {
    font-size: 1.04em;
    color: var(--text-strong);
}
.block[data-type="memory_trick"],
.block[data-type="remember"] { border-style: dashed; }

/* the three cards a student must not skim past get a solid medallion */
.block[data-type="common_error"] .block__label svg,
.block[data-type="warning"] .block__label svg,
.block[data-type="important"] .block__label svg {
    background: var(--fam);
    /* the page background, not white: in dark mode --fam is a light pastel and
       white on it is unreadable, while --bg contrasts with the fill either way */
    color: var(--bg);
    box-shadow: none;
}

/* ---------------------------------------------------------- shared diagram bits */

.viz { margin: .6em 0 .75em; }
.viz:first-child { margin-top: 0; }
.viz:last-child { margin-bottom: 0; }

/* a drawing inside an untyped card would otherwise inherit the neutral card
   accent and come out grey — a diagram always earns a colour */
.block--text .viz,
.block--text .keycards,
.block--text .steplist,
.block--media .viz { --fam: var(--fam-steps-a); }

.viz__cap {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .76em;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--fam);
    margin-bottom: 11px;
}
.viz__cap::before {
    content: "";
    width: 14px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    flex: none;
}

.viz-mono {
    font-family: var(--font-mono);
    font-size: .89em;
    letter-spacing: -.01em;
}

/* A drawing or a program that was stored as prose. Every column of a box
   drawing depends on the exact spacing, so nothing here may reflow. */
.viz-pre {
    margin: .6em 0 .75em;
    padding: 13px 15px;
    border-radius: var(--radius-sm);
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    color: var(--code-text);
    font-family: var(--font-mono);
    font-size: .82em;
    line-height: 1.6;
    white-space: pre;
    overflow-x: auto;
    tab-size: 4;
    -moz-tab-size: 4;
}
.viz-pre:first-child { margin-top: 0; }
.viz-pre:last-child { margin-bottom: 0; }
/* box drawings only close up when the lines almost touch */
.viz-pre--art { line-height: 1.2; }

/* ---------------------------------------------------------- formulas */

/* A formula copied out of rendered maths arrives one symbol per line; this is
   where the limits go back above and below the operator. */
.mathx {
    display: flex;
    align-items: center;
    gap: .1em;
    margin: .5em 0 .65em;
    padding: 10px 15px;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-left: 3px solid var(--fam);
    font-size: 1.15em;
    line-height: 1.2;
    overflow-x: auto;
}
.mathx:first-child { margin-top: 0; }
.mathx__op {
    font-size: 1.9em;
    line-height: .9;
    color: var(--fam);
    flex: none;
}
.mathx__lim {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    font-size: .58em;
    line-height: 1.15;
    color: var(--muted);
    flex: none;
    margin-right: .3em;
    min-height: 2.1em;
}
.mathx__hi { display: block; }
.mathx__lo { display: block; margin-top: auto; }
.mathx__body {
    font-family: "Cambria Math", "Latin Modern Math", Georgia, serif;
    font-style: italic;
    color: var(--text-strong);
    white-space: nowrap;
}
.mathx__body sup {
    font-style: normal;
    font-size: .68em;
    vertical-align: super;
    line-height: 0;
}

/* A complete formula card: formal equations first, symbol definitions second,
   and supporting exam notes last. This is intentionally typeset like a compact
   answer sheet rather than a code block. */
.formula-sheet {
    display: grid;
    gap: 13px;
}
.formula-sheet__intro,
.formula-sheet__notes {
    color: var(--text);
    line-height: 1.55;
}
.formula-sheet__intro > p,
.formula-sheet__notes > p { margin-bottom: .35em; }
.formula-lines {
    display: grid;
    gap: 8px;
}
.formula-line {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    min-width: 0;
    border: 1px solid color-mix(in srgb, var(--fam) 22%, var(--border));
    border-radius: 10px;
    background:
        linear-gradient(90deg, color-mix(in srgb, var(--fam) 7%, transparent), transparent 48%),
        var(--surface-2);
    overflow: hidden;
}
.formula-line__n {
    display: grid;
    place-items: center;
    min-height: 54px;
    background: color-mix(in srgb, var(--fam) 13%, transparent);
    color: var(--fam);
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 800;
}
.formula-line__content {
    min-width: 0;
    padding: 10px 15px 11px;
    overflow-x: auto;
}
.formula-line__label {
    display: block;
    margin-bottom: 5px;
    color: var(--fam);
    font-family: var(--font-sans);
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: .075em;
    text-transform: uppercase;
}
.equation {
    min-width: max-content;
    color: var(--text-strong);
    font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", Georgia, serif;
    font-size: clamp(1.08rem, 2.1vw, 1.3rem);
    line-height: 1.45;
    letter-spacing: .01em;
}
.equation--split {
    display: grid;
    grid-template-columns: minmax(max-content, auto) 24px minmax(max-content, 1fr);
    align-items: baseline;
    gap: 5px;
}
.equation__lhs { text-align: right; font-style: italic; }
.equation__op { text-align: center; color: var(--fam); font-weight: 700; }
.equation__rhs { text-align: left; }
.equation sup,
.equation sub,
.formula-where dt sup,
.formula-where dt sub { font-size: .67em; line-height: 0; }
.math-frac {
    display: inline-grid;
    grid-template-rows: auto auto;
    vertical-align: middle;
    margin: 0 .14em;
    text-align: center;
    line-height: 1.1;
}
.math-frac > span:first-child { padding: 0 .2em .08em; border-bottom: 1px solid currentColor; }
.math-frac > span:last-child { padding: .08em .2em 0; }
.math-root { display: inline-flex; align-items: flex-start; }
.math-root > span { border-top: 1px solid currentColor; padding: 0 .16em; }
.math-text { font-family: var(--font-sans); font-size: .82em; font-style: normal; }

.formula-where {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-soft);
}
.formula-where__title {
    padding: 7px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.formula-where dl { margin: 0; }
.formula-where dl > div {
    display: grid;
    grid-template-columns: minmax(72px, .32fr) minmax(0, 1fr);
}
.formula-where dl > div + div { border-top: 1px solid var(--border); }
.formula-where dt,
.formula-where dd { margin: 0; padding: 8px 12px; }
.formula-where dt {
    border-right: 1px solid var(--border);
    color: var(--fam);
    font-family: "Cambria Math", "STIX Two Math", var(--font-mono);
    font-size: 1.05em;
    font-weight: 700;
    text-align: center;
}
.formula-where dd { color: var(--text); }
.formula-sheet__notes {
    padding: 10px 12px;
    border-left: 3px solid color-mix(in srgb, var(--fam) 65%, transparent);
    border-radius: 0 9px 9px 0;
    background: color-mix(in srgb, var(--fam) 6%, transparent);
}

@media (max-width: 520px) {
    .formula-line { grid-template-columns: 28px minmax(0, 1fr); }
    .formula-line__content { padding: 9px 11px 10px; }
    .equation--split { grid-template-columns: max-content 20px max-content; }
    .formula-where dl > div { grid-template-columns: minmax(58px, .3fr) minmax(0, 1fr); }
}

/* ---------------------------------------------------------- vertical flow */

.vflow__list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.vflow__node {
    position: relative;
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 13px;
    padding-bottom: 26px;
}
.vflow__node:last-child { padding-bottom: 0; }

/* the rail joining one box to the next, and the chevron that ends it */
.vflow__node:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 14px;
    top: 32px;
    bottom: 2px;
    width: 2px;
    border-radius: 2px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--fam) 55%, transparent), var(--fam));
}
.vflow__node:not(:last-child)::after {
    content: "";
    position: absolute;
    left: 10px;
    bottom: 4px;
    width: 9px;
    height: 9px;
    border-right: 2px solid var(--fam);
    border-bottom: 2px solid var(--fam);
    border-radius: 0 0 2px 0;
    transform: rotate(45deg);
}

.vflow__step {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    color: var(--fam);
    background: color-mix(in srgb, var(--fam) 12%, var(--surface-2));
    border: 1.5px solid color-mix(in srgb, var(--fam) 34%, transparent);
    position: relative;
    z-index: 1;
}
.vflow__node.is-start .vflow__step {
    background: var(--fam);
    border-color: var(--fam);
    color: var(--bg);
}
.vflow__node.is-end .vflow__step {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--fam) 13%, transparent);
}

.vflow__box {
    align-self: start;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 11px 15px;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    line-height: 1.5;
    font-size: .95em;
    overflow-wrap: anywhere;
}
.vflow__node.is-start .vflow__box {
    border-color: color-mix(in srgb, var(--fam) 34%, transparent);
}
.vflow__node.is-end .vflow__box {
    background: color-mix(in srgb, var(--fam) 9%, var(--surface-2));
    border-color: color-mix(in srgb, var(--fam) 40%, transparent);
    font-weight: 600;
    color: var(--text-strong);
}

/* ---------------------------------------------------------- horizontal chain */

.hchain__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
}
.hchain__link {
    padding: 7px 14px;
    border-radius: var(--radius-pill);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    font-size: .9em;
    font-weight: 600;
    line-height: 1.4;
}
.hchain__link:last-child {
    background: color-mix(in srgb, var(--fam) 11%, var(--surface-2));
    border-color: color-mix(in srgb, var(--fam) 38%, transparent);
    color: var(--fam);
}
.hchain__arrow {
    width: 8px;
    height: 8px;
    flex: none;
    border-top: 2px solid var(--fam);
    border-right: 2px solid var(--fam);
    border-radius: 0 2px 0 0;
    transform: rotate(45deg);
    opacity: .7;
}

/* ---------------------------------------------------------- assignments */

.assigns__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
    gap: 8px;
}
.assigns__row {
    display: grid;
    grid-template-columns: auto 16px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    padding: 9px 13px;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    border: 1px solid var(--border);
}
.assigns__name {
    font-family: var(--font-mono);
    font-size: .88em;
    font-weight: 700;
    color: var(--fam);
    background: color-mix(in srgb, var(--fam) 12%, var(--surface-2));
    border-radius: 7px;
    padding: 3px 9px;
}
.assigns__arrow {
    width: 8px;
    height: 8px;
    justify-self: center;
    border-bottom: 2px solid var(--fam);
    border-left: 2px solid var(--fam);
    border-radius: 0 0 0 2px;
    transform: rotate(45deg);
    opacity: .7;
}
.assigns__value {
    font-family: var(--font-mono);
    font-size: .88em;
    color: var(--text-strong);
    overflow-wrap: anywhere;
}

/* ---------------------------------------------------------- summary keyword cards */

.keycards {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 258px), 1fr));
    gap: 10px;
}
.keycard {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 11px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid color-mix(in srgb, var(--fam) 18%, var(--border));
    border-left: 3px solid var(--fam);
}
.keycard__n {
    align-self: start;
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: .04em;
    color: var(--fam);
    background: color-mix(in srgb, var(--fam) 12%, var(--surface-2));
    border-radius: 6px;
    padding: 5px 6px;
    line-height: 1;
}
.keycard__c {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.keycard__k {
    font-size: .95em;
    font-weight: 750;
    line-height: 1.35;
    color: var(--text-strong);
    overflow-wrap: anywhere;
}
.keycard__k.viz-mono {
    color: var(--fam);
    font-weight: 700;
}
.keycard__r {
    font-size: .87em;
    line-height: 1.5;
    color: var(--muted);
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .keycard { transition: border-color var(--t-fast), box-shadow var(--t-fast); }
    .keycard:hover {
        border-color: color-mix(in srgb, var(--fam) 45%, transparent);
        border-left-color: var(--fam);
        box-shadow: var(--shadow-xs);
    }
}

/* ---------------------------------------------------------- step ladder */

.steplist {
    list-style: none;
    margin: 0;
    padding: 0;
}
.steplist__item {
    position: relative;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 13px;
    align-items: start;
    padding-bottom: 14px;
}
.steplist__item:last-child { padding-bottom: 0; }
.steplist__item:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 13px;
    top: 30px;
    bottom: 2px;
    width: 2px;
    border-radius: 2px;
    background: color-mix(in srgb, var(--fam) 28%, transparent);
}
.steplist__n {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 700;
    color: var(--fam);
    background: color-mix(in srgb, var(--fam) 12%, var(--surface-2));
    border: 1.5px solid color-mix(in srgb, var(--fam) 32%, transparent);
    position: relative;
    z-index: 1;
}
.steplist__t {
    padding-top: 3px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

/* ---------------------------------------------------------- "X → Y" pairs */

.block__body .pairs {
    gap: 7px 0;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    border: 1px solid var(--border);
}
.block__body .pairs dt { color: var(--text-strong); }
.block__body .pairs dd::before {
    color: var(--fam);
    opacity: .8;
    font-weight: 700;
}

/* ---------------------------------------------------------- narrow screens */

@media (max-width: 480px) {
    .vflow__node { grid-template-columns: 26px minmax(0, 1fr); gap: 11px; padding-bottom: 22px; }
    .vflow__step { width: 26px; height: 26px; font-size: 11px; }
    .vflow__node:not(:last-child)::before { left: 12px; top: 28px; }
    .vflow__node:not(:last-child)::after { left: 8px; }
    .vflow__box { padding: 10px 12px; }
    .keycard { padding: 11px 12px; gap: 9px; }
    .assigns__row { padding: 8px 11px; }
}
