/* ============================================================================
   COMMENTARIUS STREAMLINED — DESIGN SYSTEM
   ============================================================================

   THESIS: A commentary pipeline is a network with parallel traffic, so it is
   drawn as one — Harry Beck's transit diagram, where stages are stations and
   chapters are trains. Refuses the generated-UI console (near-black + neon +
   glow) and refuses the card grid.

   OWN-WORLD: Deep slate ground, never pure black. Structure is line-work, not
   boxes. Five named lines each own a colour and a job — TEXT chalk, SOURCES
   amber, NOTES signal blue, VOCAB teal, ENRICH violet — and colour is never
   used decoratively outside that system. Stations are ring nodes; termini are
   double rings. Overpass (drawn from Highway Gothic) carries every label,
   because this is wayfinding. Geometry is orthogonal and 45° only. No glow,
   no gradient text, no glass, no rounded cards.

   RULE: any colour on this surface must name a line. If it does not name a
   line, it is chalk, dim chalk, or ground.
   ========================================================================= */

/* ── Tokens ───────────────────────────────────────────────────────────── */
:root {
    /* Ground: deep slate with a blue cast */
    --st-ground:        #12161d;
    --st-ground-raised: #171d26;
    --st-well:          #1c2430;
    --st-rule:          #2a3340;
    --st-rule-bright:   #3b4756;

    /* Chalk: the map is drawn in chalk on slate */
    --st-chalk:         #e9edf2;
    --st-chalk-dim:     #97a3b2;
    --st-chalk-faint:   #667485;

    /* The five lines. Each names a job. */
    --line-text:        #e9edf2;  /* source text          */
    --line-sources:     #e8a33d;  /* uploaded commentaries */
    --line-notes:       #5b9bff;  /* merged notes trunk    */
    --line-vocab:       #35b8a4;  /* vocabulary            */
    --line-enrich:      #9b7be8;  /* cleaner/linker/images */

    /* Line tints for fills and inactive states */
    --line-text-dim:    rgba(233, 237, 242, 0.22);
    --line-sources-dim: rgba(232, 163, 61, 0.22);
    --line-notes-dim:   rgba(91, 155, 255, 0.22);
    --line-vocab-dim:   rgba(53, 184, 164, 0.22);
    --line-enrich-dim:  rgba(155, 123, 232, 0.22);

    /* Service status */
    --st-good:          #35b8a4;
    --st-wait:          #e8a33d;
    --st-fault:         #ff6b5e;

    /* Type: Overpass descends from Highway Gothic — signage, not fashion */
    --st-font: 'Overpass', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --st-mono: 'Overpass Mono', ui-monospace, 'SF Mono', Consolas, monospace;

    /* Geometry: transit maps have square ends and honest corners */
    --st-radius: 2px;
    --st-line-w: 7px;

    --st-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    --st-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

/* ── Base ─────────────────────────────────────────────────────────────── */
.st-root {
    background: var(--st-ground);
    color: var(--st-chalk);
    font-family: var(--st-font);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.st-root *,
.st-root *::before,
.st-root *::after {
    box-sizing: border-box;
}

.st-root ::selection {
    background: var(--line-notes);
    color: var(--st-ground);
}

/* ── Wayfinding type ──────────────────────────────────────────────────── */
.st-label {
    font-family: var(--st-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--st-chalk-dim);
}

.st-label--line { color: var(--st-chalk); }

.st-display {
    font-family: var(--st-font);
    font-weight: 700;
    letter-spacing: -0.022em;
    line-height: 1.04;
    font-size: clamp(2.25rem, 5vw, 3.5rem);
}

.st-lede {
    font-size: 1.0625rem;
    color: var(--st-chalk-dim);
    max-width: 42ch;
}

.st-note {
    font-size: 0.875rem;
    color: var(--st-chalk-dim);
}

/* Roundel: the transit wordmark */
.st-roundel {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    text-decoration: none;
    color: var(--st-chalk);
}

.st-roundel-mark {
    width: 22px;
    height: 22px;
    border: 3px solid var(--line-notes);
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}

.st-roundel-mark::after {
    content: '';
    position: absolute;
    left: -5px;
    right: -5px;
    top: 50%;
    height: 3px;
    margin-top: -1.5px;
    background: var(--st-chalk);
}

.st-roundel-text {
    font-weight: 700;
    font-size: 0.9375rem;
    letter-spacing: 0.02em;
}

.st-roundel-text em {
    font-style: normal;
    font-weight: 400;
    color: var(--st-chalk-dim);
}

/* ── Controls: platform signage, not app buttons ──────────────────────── */
.st-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    padding: 0.9375rem 1.625rem;
    font-family: var(--st-font);
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    border: 2px solid transparent;
    border-radius: var(--st-radius);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.16s var(--st-ease),
                border-color 0.16s var(--st-ease),
                color 0.16s var(--st-ease);
}

/* Something went wrong, or is about to. This is service status, not a line —
   amber waits, red stops — so it takes the status tokens rather than borrowing
   the sources line's amber, which would imply the notice is about uploaded
   commentaries.

   No accent rule. Elsewhere on this surface a coloured left rule distinguishes
   one card from its identical neighbours — which thread, which line, which
   state. A notice has no neighbours: it appears alone at the head of the form,
   and the mono tag already says CONFIRM NEEDED in the status colour. A rule
   here would be decoration wearing the clothes of wayfinding. */
.st-notice, .notice {
    border: 1px solid var(--st-rule-bright);
    border-radius: var(--st-radius);
    background: var(--st-ground-raised);
    padding: 1rem 1.125rem 1.125rem;
    margin: 0 0 2rem;
}

.notice__tag {
    margin: 0 0 0.5rem;
    font-family: var(--st-mono);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--st-wait);
}

.notice--stop .notice__tag { color: var(--st-fault); }

.notice__list {
    margin: 0;
    padding-left: 1.125rem;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--st-chalk);
}

.notice__body {
    margin: 0.75rem 0 0;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--st-chalk-dim);
}

.notice__go { margin-top: 0.875rem; }

.st-btn--go {
    background: var(--line-notes);
    border-color: var(--line-notes);
    color: var(--st-ground);
}

.st-btn--go:hover {
    background: #79aeff;
    border-color: #79aeff;
}

.st-btn--quiet {
    background: transparent;
    border-color: var(--st-rule-bright);
    color: var(--st-chalk-dim);
}

.st-btn--quiet:hover {
    border-color: var(--st-chalk-dim);
    color: var(--st-chalk);
}

.st-btn:focus-visible {
    outline: 2px solid var(--st-chalk);
    outline-offset: 3px;
}

.st-btn__arrow {
    font-family: var(--st-mono);
    font-weight: 400;
    transition: transform 0.18s var(--st-ease);
}

.st-btn:hover .st-btn__arrow { transform: translateX(3px); }

/* ── Fields ───────────────────────────────────────────────────────────── */
.st-field { margin-bottom: 1.5rem; }

.st-field__tag {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 0.625rem;
}

.st-field__idx {
    font-family: var(--st-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    color: var(--line-notes);
}

.st-field__name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--st-chalk);
}

.st-field__req {
    margin-left: auto;
    font-family: var(--st-mono);
    font-size: 0.625rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--st-chalk-faint);
}

.st-input,
.st-select,
.st-textarea {
    width: 100%;
    padding: 0.8125rem 1rem;
    background: var(--st-well);
    border: 1px solid var(--st-rule-bright);
    border-radius: var(--st-radius);
    font-family: var(--st-font);
    font-size: 1rem;
    color: var(--st-chalk);
    transition: border-color 0.16s var(--st-ease),
                box-shadow 0.16s var(--st-ease);
}

.st-textarea {
    font-family: var(--st-mono);
    font-size: 0.8125rem;
    line-height: 1.8;
    min-height: 220px;
    resize: vertical;
}

.st-input:focus,
.st-select:focus,
.st-textarea:focus {
    outline: none;
    border-color: var(--line-notes);
    box-shadow: inset 0 0 0 1px var(--line-notes);
}

.st-input::placeholder,
.st-textarea::placeholder { color: var(--st-chalk-faint); }

.st-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2397a3b2' stroke-width='1.6' stroke-linecap='square'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}

.st-select option { background: var(--st-ground-raised); color: var(--st-chalk); }

/* Checkbox: a station node you switch on */
.st-check {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.9375rem;
    line-height: 1.5;
}

.st-check input[type="checkbox"] {
    appearance: none;
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.1875rem;
    flex-shrink: 0;
    background: var(--st-well);
    border: 2px solid var(--st-rule-bright);
    border-radius: 50%;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: border-color 0.16s var(--st-ease);
}

.st-check input[type="checkbox"]:checked {
    border-color: var(--line-notes);
}

.st-check input[type="checkbox"]:checked::after {
    content: '';
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--line-notes);
}

.st-check input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--st-chalk);
    outline-offset: 2px;
}

/* ── Transit map ──────────────────────────────────────────────────────── */
.st-map { width: 100%; height: auto; display: block; overflow: visible; }

.st-map .route {
    fill: none;
    stroke-width: var(--st-line-w);
    stroke-linecap: square;
    stroke-linejoin: miter;
}

.st-map .route--text    { stroke: var(--line-text); }
.st-map .route--sources { stroke: var(--line-sources); }
.st-map .route--notes   { stroke: var(--line-notes); }
.st-map .route--vocab   { stroke: var(--line-vocab); }
.st-map .route--enrich  { stroke: var(--line-enrich); }

/* A route the user has switched off keeps its geometry, loses its service */
.st-map .route.is-off {
    stroke: var(--st-rule-bright);
    stroke-dasharray: 2 9;
    stroke-width: 3px;
}

.st-map .station {
    fill: var(--st-ground);
    stroke-width: 3.5px;
}

.st-map .station--text    { stroke: var(--line-text); }
.st-map .station--sources { stroke: var(--line-sources); }
.st-map .station--notes   { stroke: var(--line-notes); }
.st-map .station--vocab   { stroke: var(--line-vocab); }
.st-map .station--enrich  { stroke: var(--line-enrich); }

.st-map .station.is-off { stroke: var(--st-rule-bright); }

/* Terminus: double ring, the Beck convention for end of line */
.st-map .terminus-outer { fill: none; stroke-width: 2.5px; }

.st-map .st-name {
    font-family: var(--st-font);
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.045em;
    fill: var(--st-chalk);
    text-transform: uppercase;
}

.st-map .st-sub {
    font-family: var(--st-mono);
    font-size: 9.5px;
    font-weight: 400;
    letter-spacing: 0.1em;
    fill: var(--st-chalk-faint);
    text-transform: uppercase;
}

.st-map .st-name.is-off,
.st-map .st-sub.is-off { fill: var(--st-chalk-faint); }

/* Compact: SVG text scales with the viewBox, so a map rendered small enough
   to sit beside a form loses its labels entirely. Drop the glosses and set
   the names larger in user units so they survive the reduction. */
.st-map--compact { min-width: 0 !important; width: 100%; }
.st-map--compact .st-sub { display: none; }
.st-map--compact .st-name { font-size: 18px; letter-spacing: 0.01em; }
.st-map--compact .station { stroke-width: 5px; }
.st-map--compact .terminus-outer { stroke-width: 3.5px; }
.st-map--compact .route { stroke-width: 10px; }

/* Live service states on a station */
.st-map .station.is-running {
    stroke: var(--st-chalk);
    animation: st-pulse 1.6s var(--st-ease-in-out) infinite;
}

.st-map .station.is-done { fill: currentColor; }
.st-map .station.is-fault { stroke: var(--st-fault); }

@keyframes st-pulse {
    0%, 100% { stroke-opacity: 1; }
    50%      { stroke-opacity: 0.35; }
}

/* Chapter markers: trains standing at a station */
.st-train {
    font-family: var(--st-mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.06em;
    fill: var(--st-ground);
}

.st-train-plate { rx: 2; }

/* ── Route drawing: the entry transition ──────────────────────────────── */
.st-draw .route {
    stroke-dasharray: var(--dash, 1400);
    stroke-dashoffset: var(--dash, 1400);
    animation: st-draw-route 1.15s var(--st-ease) forwards;
}

@keyframes st-draw-route {
    to { stroke-dashoffset: 0; }
}

.st-draw .station,
.st-draw .terminus-outer,
.st-draw .st-name,
.st-draw .st-sub {
    opacity: 0;
    animation: st-fade-node 0.4s var(--st-ease) forwards;
}

@keyframes st-fade-node {
    to { opacity: 1; }
}

/* ── Service board: legend + status, the platform indicator ───────────── */
.st-board {
    border-top: 1px solid var(--st-rule);
    border-bottom: 1px solid var(--st-rule);
    padding: 0.875rem 0;
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem 2rem;
}

.st-board__item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.st-board__bar {
    width: 22px;
    height: 5px;
    flex-shrink: 0;
}

.st-board__bar--text    { background: var(--line-text); }
.st-board__bar--sources { background: var(--line-sources); }
.st-board__bar--notes   { background: var(--line-notes); }
.st-board__bar--vocab   { background: var(--line-vocab); }
.st-board__bar--enrich  { background: var(--line-enrich); }

.st-board__name {
    font-family: var(--st-mono);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--st-chalk-dim);
}

/* ── Chrome ───────────────────────────────────────────────────────────── */
.st-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.125rem 2rem;
    border-bottom: 1px solid var(--st-rule);
}

.st-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--st-mono);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--st-chalk-dim);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border: 1px solid transparent;
    border-radius: var(--st-radius);
    transition: color 0.16s var(--st-ease), border-color 0.16s var(--st-ease);
}

.st-back:hover {
    color: var(--st-chalk);
    border-color: var(--st-rule-bright);
}

/* ── Motion policy ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .st-root *,
    .st-root *::before,
    .st-root *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .st-draw .route {
        stroke-dashoffset: 0;
    }

    .st-draw .station,
    .st-draw .terminus-outer,
    .st-draw .st-name,
    .st-draw .st-sub {
        opacity: 1;
    }
}
