/* ==========================================
   NOCO EMS Education - Global Styles
   ========================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* CSS Variables for Theming
   ------------------------------------------
   The one token block for the whole site. Solid values sit in :root
   (light) and [data-theme="dark"]. Theme-independent scales (radius,
   spacing, type, layout, z-index, motion) sit in :root only and are
   inherited everywhere. Anything defined FROM another token (aliases,
   color-mix() tints, gradients over brand stops) lives in the derived
   block after the dark one, declared on ':root, [data-theme]' so a
   themed sub-tree re-resolves it against its own theme.
   Breakpoint tiers (custom properties can't be used in @media):
   960px, 768px (primary), 600px (phone), 480px (small phone).
   The light block also matches [data-theme="light"], so a light
   sub-tree inside a dark page (dev.php's side-by-side columns)
   re-resolves the light values. */
:root,
[data-theme="light"] {
    /* Native controls (date/time picker icons, number spinners, select
       popups, scrollbars) follow the theme; the dark block flips it. */
    color-scheme: light;

    /* Brand chrome — the same in both themes (chrome is navy in both).
       --brand-red follows the admin site colour (derived block). */
    --brand-navy: #0c1929;
    --brand-navy-2: #142742;
    --brand-navy-3: #1e3a5f;
    --brand-hero: linear-gradient(135deg, rgba(12, 25, 41, 0.92) 0%, rgba(20, 39, 66, 0.9) 50%, rgba(30, 58, 95, 0.85) 100%);
    --brand-gold: #d9b380;

    /* Brand + accent tokens */
    --primary-soft: #3A6FA8;
    --primary-light: #E8F1F8;
    /* Text-safe blue: links, outline labels, text on tints and hover
       rows. --primary-soft is decorative (text only directly on the card). */
    --primary-text: #2F5F94;
    --secondary-light: #EAF7EE;
    --accent-warm: #C5824B;
    --accent-light: #FDF3ED;

    /* Surface / page tokens — light mode is meant to read as light, so
       container/card surfaces are near-white with subtle warmth. */
    --neutral-bg: #F5F7FA;
    --neutral-light: #FAFBFC;
    --container-bg: rgba(255, 255, 255, 0.78);
    --card-bg: #FFFFFF;
    /* Raised area inside a solid section (row hover, table head, open
       accordion head). --hover-bg and --card-hover alias it. */
    --surface-2: #F1F4F8;
    --input-bg: #FFFFFF;
    --result-card-bg: #FFFFFF;
    /* Listing-card glass (used with backdrop blur), the tray behind
       grouped cards, and the modal/sheet backdrop. */
    --surface-glass: linear-gradient(160deg, rgba(255, 255, 255, 0.96) 0%, rgba(240, 245, 251, 0.93) 55%, rgba(226, 236, 248, 0.9) 100%);
    --surface-glass-hover: linear-gradient(160deg, rgba(255, 255, 255, 0.98) 0%, rgba(244, 248, 253, 0.95) 55%, rgba(233, 241, 251, 0.93) 100%);
    --surface-tray: linear-gradient(160deg, #dbe5f2 0%, #d0dcec 55%, #c6d5e9 100%);
    --scrim: rgba(0, 0, 0, 0.55);

    /* Text — dark navy on light surfaces meets WCAG AA easily. */
    --text-primary: #0E1620;
    --text-secondary: #344256;
    --text-muted: #56657C;
    /* Labels on -fill tokens and navy chrome; on bright identity hues. */
    --text-on-fill: #FFFFFF;
    --text-on-chrome-muted: rgba(255, 255, 255, 0.8);
    --text-on-bright: #0E1620;

    /* Borders — soft cool-gray. --border-strong identifies a control
       (inputs, checkboxes, unselected segments) at 3:1 or better. */
    --border-soft: #D4E1EC;
    --border-medium: #B8CDE0;
    --border-strong: #7D8DA6;

    /* Frames: widths, the tactile listing frame, the soft panel frame. */
    --frame-w: 3px;
    --frame-w-inset: 1.5px;
    --frame-listing: #0c1929;
    --frame-listing-hover: #0c1929;
    --frame-panel: rgba(180, 195, 215, 0.6);

    /* Status text — AA on the card and on its own tint. The old -soft
       names alias these, and the -tint/-border pairs mix from them
       (derived block). --ce-text is the gold CE identity. */
    --success-text: #1E7345;
    --warning-text: #9A4A07;
    --danger-text: #B03A2E;
    --info-text: #2E5C8A;
    --ce-text: #765522;

    /* Shadows (colour aliases; prefer the --elev-* scale) */
    --shadow-soft: rgba(60, 80, 110, 0.08);
    --shadow-medium: rgba(60, 80, 110, 0.14);

    /* Elevation: 0 flat, 1 resting, 2 interactive hover, 3 overlay,
       4 modal. Dark mode redefines them in black. */
    --elev-0: none;
    --elev-1: 0 4px 14px rgba(80, 90, 130, 0.06), 0 1px 3px rgba(80, 90, 130, 0.04);
    --elev-2: 0 10px 24px rgba(80, 90, 130, 0.12), 0 2px 6px rgba(80, 90, 130, 0.06);
    --elev-3: 0 10px 30px rgba(40, 50, 75, 0.12);
    --elev-4: 0 12px 40px rgba(0, 0, 0, 0.3);

    /* Page-level gradient anchors (used in a few places) */
    --body-gradient-start: #FDE8E0;
    --body-gradient-end: #FDF5E6;

    /* Alerts (bg/border alias the danger tint pair; derived block) */
    --alert-text: #721c24;

    /* Solid fills for white-label buttons and badges. Same value in
       BOTH themes (white text passes >= 5:1 on each). Hover is
       color-mix(fill 85%, #000), active 75%. The -soft names stay for
       text and light tints only — never as a fill under white text. */
    --primary-fill: #3A6FA8;
    --success-fill: #1E7345;
    --warning-fill: #B45309;
    --danger-fill: #B03A2E;
    --info-fill: #2E5C8A;
    --neutral-fill: #52627A;

    /* Radius scale */
    --r-xs: 4px;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-pill: 999px;

    /* Spacing — 4px grid, plus the named icon gap and padding roles
       (--pad-card equals card-header.css --lib-card-pad). */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --gap-icon: 0.4rem;
    --pad-card: 2rem;
    --pad-panel: 1.5rem;
    --pad-reading: 3rem;
    --pad-inset: 0.75rem 1rem;

    /* Layout + hit targets */
    --page-max: 1400px;
    --page-max-narrow: 1000px;
    --page-gutter: 2rem;
    --w-read: 72ch;
    --w-form: 600px;
    --control-h: 2.5rem;
    --control-h-lg: 3rem;

    /* Stacking — aligned with Bootstrap 5.3 */
    --z-sticky: 1020;
    --z-nav: 1030;
    --z-fab: 1040;
    --z-modal-backdrop: 1050;
    --z-modal: 1055;
    --z-toast: 1090;

    /* Motion — the single card lift and timing */
    --lift-card: -4px;
    --dur-fast: 150ms;
    --dur: 220ms;
    --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);

    /* Type — font stacks and the size ladder (applied in the Type scale
       section further down). */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
    --fs-display: clamp(2.25rem, 1.5rem + 3vw, 3.75rem);
    --fs-page-title: clamp(1.9rem, 1.4rem + 1.8vw, 2.5rem);
    --fs-page-subtitle: 1.125rem;
    --fs-topic-title: clamp(1.6rem, 1.35rem + 0.7vw, 1.85rem); /* Learn topic viewer h2.topic-viewer-title */
    --fs-section-title: 1.3rem;
    --fs-card-title: 1.35rem;
    --fs-band-title: 1.15rem;
    --fs-band-label: 0.95rem;
    --fs-lead: 1.125rem;
    --fs-body: 1rem;
    --fs-body-sm: 0.95rem;
    --fs-meta: 0.85rem;
    --fs-sm: 0.875rem;
    --fs-xs: 0.78rem;
    --fs-eyebrow: 0.72rem;
    --fs-2xs: 0.7rem;
    --fs-stat: 2rem;
    --fs-stat-sm: 1.3rem;
    --ls-eyebrow: 0.06em;

    /* Focus */
    --focus-offset: 2px;
}

/* Responsive steps of the scale tokens. */
@media (max-width: 768px) {
    :root, [data-theme] {
        --pad-card: 1.5rem;
        --page-gutter: 1rem;
        --fs-lead: 1rem;
    }
}
@media (max-width: 600px) {
    :root, [data-theme] {
        --pad-reading: 1.25rem;
    }
}
@media (pointer: coarse) {
    :root, [data-theme] {
        --control-h: 2.75rem;
    }
}
@media (prefers-reduced-motion: reduce) {
    :root, [data-theme] {
        --lift-card: 0px;
        --dur-fast: 0ms;
        --dur: 0ms;
    }
}

/* Dark Theme Variables */
[data-theme="dark"] {
    color-scheme: dark;
    --primary-soft: #5A8BC4;
    --primary-light: #1E3A52;
    --primary-text: #8DB9E8;
    --secondary-light: #2C4038;
    --accent-warm: #B8845F;
    --accent-light: #3D3128;
    --neutral-bg: #0F1424;
    --neutral-light: #151B2E;
    --text-primary: #F5F8FB;
    --text-secondary: #CED6E4;
    --text-muted: #8B96AB;
    --border-soft: #2A3248;
    --border-medium: #3A4258;
    --border-strong: #6B7A96;
    --success-text: #81C995;
    --warning-text: #F0B26B;
    --danger-text: #F28B82;
    --info-text: #8DB9E8;
    --ce-text: #d9b380;
    --shadow-soft: rgba(0, 0, 0, 0.4);
    --shadow-medium: rgba(0, 0, 0, 0.5);
    --elev-1: 0 4px 16px rgba(0, 0, 0, 0.3);
    --elev-2: 0 10px 26px rgba(0, 0, 0, 0.45);
    --elev-3: 0 10px 30px rgba(0, 0, 0, 0.5);
    --elev-4: 0 12px 44px rgba(0, 0, 0, 0.6);
    --body-gradient-start: #0B1220;
    --body-gradient-end: #1C1A3A;
    --container-bg: #0F1424;
    --card-bg: #161C30;
    --surface-2: #1D2340;
    /* Recessed field well: darker than the card (#161C30) so a field
       never vanishes into the panel it sits on. */
    --input-bg: #0E1426;
    --result-card-bg: #0F1424;
    --surface-glass: linear-gradient(160deg, rgba(14, 20, 38, 0.92) 0%, rgba(5, 9, 20, 0.88) 55%, rgba(18, 27, 52, 0.92) 100%);
    --surface-glass-hover: linear-gradient(160deg, rgba(19, 27, 50, 0.95) 0%, rgba(9, 14, 30, 0.92) 55%, rgba(24, 35, 66, 0.95) 100%);
    --surface-tray: linear-gradient(160deg, #1a2540 0%, #141d34 55%, #101828 100%);
    --frame-listing: rgba(160, 180, 220, 0.65);
    --frame-listing-hover: rgba(190, 210, 245, 0.9);
    --frame-panel: rgba(140, 160, 200, 0.4);
    --alert-text: #FFD0D0;
}

/* Derived tokens: aliases and composites of other tokens. Declared on
   every [data-theme] element (not just :root) so each reference
   re-resolves against that element's theme. */
:root, [data-theme] {
    /* Brand. The admin site colour drives the red; --site-color is only
       emitted on pages that load the navbar, hence the fallback. Caps
       and rules only — never text and never a status colour. */
    --brand-navy-soft: var(--brand-navy-3);
    --brand-band: linear-gradient(135deg, var(--brand-navy) 0%, var(--brand-navy-2) 100%);
    --brand-red: var(--site-color, #c0392b);

    /* Surface and colour-role aliases */
    --hover-bg: var(--surface-2);
    --card-hover: var(--surface-2);
    --link-color: var(--primary-text);
    --input-border: var(--border-strong);

    /* Legacy status names resolve to the AA text tokens in both themes
       (dark warning is no longer the decorative --accent-warm). */
    --success-soft: var(--success-text);
    --secondary-soft: var(--success-text);
    --warning-soft: var(--warning-text);
    --danger-soft: var(--danger-text);
    --info-soft: var(--info-text);

    /* Alert and result-chip names point at the matching tint/border. */
    --alert-bg: var(--danger-tint);
    --alert-border: var(--danger-border);
    --result-blue-bg: var(--info-tint);
    --result-blue-border: var(--info-border);
    --result-orange-bg: var(--warning-tint);
    --result-orange-border: var(--warning-border);

    /* Focus and the one selected state */
    --focus-color: var(--primary-text);
    --focus-color-chrome: var(--brand-gold);
    --focus-outline: 2px solid var(--focus-color);
    --focus-ring: 0 0 0 2px var(--card-bg), 0 0 0 4px var(--focus-color);
    --selected-bg: linear-gradient(135deg, var(--brand-navy-2) 0%, var(--brand-navy-3) 100%);
}

/* color-mix() tokens: tints (12%) and borders (35%) of each status over
   the card, the primary tint, the neutral button surface, and the
   fill/brand hover shades. The solid per-theme values are the fallback
   for engines without color-mix(); they sit in their own rules because
   a plain earlier line can't act as a fallback for a custom property
   (any value parses, so the later line always wins and then fails at
   use time). */
:root, [data-theme] {
    --neutral-tint: #ECECED;
    --primary-tint: #E6ECF2;
    --primary-fill-hover: #315E8F;
    --primary-fill-active: #2C537E;
    --brand-red-hover: #C9574B;
    --brand-red-deep: #902B20;
    --success-tint: #E4EEE9;
    --success-border: #B0CEBE;
    --warning-tint: #F3E9E1;
    --warning-border: #DCC0A8;
    --danger-tint: #F6E7E6;
    --danger-border: #E3BAB6;
    --info-tint: #E6EBF1;
    --info-border: #B6C6D6;
    --ce-tint: #FAF4ED;
}
[data-theme="dark"] {
    --neutral-tint: #282E40;
    --primary-tint: #242F46;
    --success-tint: #23313C;
    --success-border: #3B5953;
    --warning-tint: #302E37;
    --warning-border: #625045;
    --danger-tint: #30293A;
    --danger-border: #63434D;
    --info-tint: #242F46;
    --info-border: #405370;
    --ce-tint: #31313B;
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
    :root, [data-theme] {
        --neutral-tint: color-mix(in srgb, var(--text-primary) 8%, var(--card-bg));
        --primary-tint: color-mix(in srgb, var(--primary-text) 12%, var(--card-bg));
        --primary-fill-hover: color-mix(in srgb, var(--primary-fill) 85%, #000);
        --primary-fill-active: color-mix(in srgb, var(--primary-fill) 75%, #000);
        --brand-red-hover: color-mix(in srgb, var(--brand-red) 85%, #fff);
        --brand-red-deep: color-mix(in srgb, var(--brand-red) 75%, #000);
        --success-tint: color-mix(in srgb, var(--success-text) 12%, var(--card-bg));
        --success-border: color-mix(in srgb, var(--success-text) 35%, var(--card-bg));
        --warning-tint: color-mix(in srgb, var(--warning-text) 12%, var(--card-bg));
        --warning-border: color-mix(in srgb, var(--warning-text) 35%, var(--card-bg));
        --danger-tint: color-mix(in srgb, var(--danger-text) 12%, var(--card-bg));
        --danger-border: color-mix(in srgb, var(--danger-text) 35%, var(--card-bg));
        --info-tint: color-mix(in srgb, var(--info-text) 12%, var(--card-bg));
        --info-border: color-mix(in srgb, var(--info-text) 35%, var(--card-bg));
        --ce-tint: color-mix(in srgb, var(--brand-gold) 14%, var(--card-bg));
    }
}

/* Global Reset */
* {
    box-sizing: border-box;
}

/* Base site background rendered as a fixed-positioned html::before
   pseudo-element instead of `background-attachment: fixed` on body.
   The fixed-attachment approach misbehaves on iOS Safari and Android
   Chrome when the dynamic URL bar animates, leaving a white gap at
   the bottom of the page during scroll. A real position:fixed layer
   handles the viewport change cleanly. The solid html background is
   a final fallback in case any pixel slips through. */
html {
    background: #DCCFE2;
    min-height: 100%;
    /* Kill the elastic overscroll bounce at the document edges — the top of
       the page is the top, the bottom is the bottom. (Also disables mobile
       pull-to-refresh, which is fine for an app-style site.) */
    overscroll-behavior-y: none;
}
html::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -10;
    background:
        radial-gradient(ellipse at 40% 20%, rgba(135, 180, 230, 0.3) 0%, transparent 55%),
        radial-gradient(ellipse at 90% 30%, rgba(170, 200, 240, 0.25) 0%, transparent 50%),
        radial-gradient(ellipse at 10% 50%, rgba(150, 190, 235, 0.2) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 85%, rgba(210, 150, 175, 0.15) 0%, transparent 45%),
        radial-gradient(ellipse at 20% 90%, rgba(200, 140, 170, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 95%, rgba(190, 150, 180, 0.1) 0%, transparent 45%),
        linear-gradient(180deg, #B8D4F0 0%, #CDDAEF 20%, #DCCFE2 38%, #E0D5E0 50%, #D8D5E8 65%, #D8D0E5 80%, #E0D0E0 100%);
    pointer-events: none;
}
html[data-theme="dark"] {
    background: #0B1220;
}
html[data-theme="dark"]::before {
    background: linear-gradient(180deg, #0B1220 0%, #0F1A2E 20%, #141B3A 45%, #1C1A3A 70%, #24183A 100%);
}

/* Atmosphere layer over the base gradient, site-wide: soft radial glows
   in the brand red and navy near the top of the viewport, and the same
   diagonal pinstripe the card header bands use, at a whisper, fading
   out toward the bottom. Same fixed-layer technique as html::before
   (see the note above), one step closer to the content. Started life as
   the landing-page hero backdrop and was promoted to every page. */
html::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -9;
    pointer-events: none;
    background:
        radial-gradient(42% 50% at 20% 18%, rgba(192, 57, 43, 0.16) 0%, rgba(192, 57, 43, 0) 70%),
        radial-gradient(46% 55% at 80% 22%, rgba(29, 53, 87, 0.18) 0%, rgba(29, 53, 87, 0) 70%),
        repeating-linear-gradient(115deg, rgba(12, 25, 41, 0.045) 0 2px, rgba(12, 25, 41, 0) 2px 12px);
    -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 45%, rgba(0, 0, 0, 0.35) 75%, transparent 100%);
    mask-image: linear-gradient(180deg, #000 0%, #000 45%, rgba(0, 0, 0, 0.35) 75%, transparent 100%);
}
html[data-theme="dark"]::after {
    background:
        radial-gradient(42% 50% at 20% 18%, rgba(255, 107, 107, 0.14) 0%, rgba(255, 107, 107, 0) 70%),
        radial-gradient(46% 55% at 80% 22%, rgba(90, 130, 190, 0.20) 0%, rgba(90, 130, 190, 0) 70%),
        repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.035) 0 2px, rgba(255, 255, 255, 0) 2px 12px);
}

/* Body Styling — transparent so the html::before gradient shows through.
   Flex column with min-height: 100vh so the footer's `margin-top: auto`
   pushes it to the bottom when content is short, but the page itself
   scrolls naturally — the navbar and footer sit in normal document flow
   and scroll with the rest of the page. */
body {
    background: transparent;
    overscroll-behavior-y: none;   /* pair with the html rule — some browsers scroll on body */
    padding: 0;
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    transition: color 0.3s ease;
    position: relative;
}

/* Embedded modes (iframe-loaded admin / schedule modals) render without
   the global navbar/footer. The bootstrap script never wraps content for
   them, so the body must stay scrollable on its own — undo the fixed-
   viewport lock that the regular full-page chrome relies on. */
body.admin-embedded,
body.sched-embedded {
    height: auto;
    min-height: 0;
    overflow: visible;
    display: block;
}

/* Schedule modal iframes should read as a single clean card surface:
   suppress the site background gradients inside the iframe so the
   parent page's dimmed backdrop + white modal panel are all you see. */
html:has(body.sched-embedded) {
    background: var(--card-bg);
}
html:has(body.sched-embedded)::before,
html:has(body.sched-embedded)::after,
body.sched-embedded::before,
body.sched-embedded::after {
    display: none;
}

/* Page content region. Header and footer flow with the page now, so this
   wrapper just expands to take any leftover height (so footer lands at
   the viewport bottom on short pages) and otherwise grows with content.
   The FLScrollbar wrap and inner .fl-scroll are still created at runtime
   (the bootstrap script in navbar.php is shared with embedded modes), but
   they no longer act as the page's scroll container — FLScrollbar's track
   auto-hides when the inner content isn't taller than its container. */
.page-scroll {
    flex: 1;
    position: relative;
    width: 100%;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 60% 15%, rgba(140, 185, 235, 0.35) 0%, transparent 55%),
        radial-gradient(ellipse at 15% 35%, rgba(180, 210, 245, 0.25) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 25%, rgba(160, 195, 240, 0.2) 0%, transparent 50%),
        radial-gradient(ellipse at 30% 80%, rgba(220, 155, 180, 0.18) 0%, transparent 45%),
        radial-gradient(ellipse at 70% 90%, rgba(200, 145, 175, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 95%, rgba(215, 160, 190, 0.12) 0%, transparent 45%),
        linear-gradient(180deg, #A8C8E8 0%, #BED0EE 18%, #D0CADD 36%, #DDD2DA 50%, #D8CEE0 65%, #D5C8DE 80%, #E2CDD8 100%);
    opacity: 0;
    animation: sunrisePulse 20s ease-in-out infinite;
    z-index: -1;
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(160, 200, 245, 0.3) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 40%, rgba(150, 190, 240, 0.2) 0%, transparent 50%),
        radial-gradient(ellipse at 60% 85%, rgba(215, 150, 180, 0.16) 0%, transparent 45%),
        radial-gradient(ellipse at 15% 95%, rgba(205, 155, 185, 0.12) 0%, transparent 45%),
        radial-gradient(ellipse at 85% 80%, rgba(195, 145, 175, 0.1) 0%, transparent 50%),
        linear-gradient(180deg, #C0D8F2 0%, #CDDCF0 18%, #DBCFE0 36%, #E5D5DB 50%, #DDD2E5 65%, #D8CCE0 80%, #DEC8D8 100%);
    opacity: 0;
    animation: sunrisePulse 20s ease-in-out infinite 10s;
    z-index: -1;
    pointer-events: none;
}

/* Dark mode body stays transparent — the fixed html::before pseudo
   handles the gradient (see the dark-mode rule there above). */
[data-theme="dark"] body {
    background: transparent;
    animation: none;
}

[data-theme="dark"] body::before,
[data-theme="dark"] body::after {
    display: none;
}

@keyframes sunrisePulse {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}


/* Container */
.container {
    border: none;
    padding: 2rem;
    background-color: transparent;
    border-radius: 16px;
    box-shadow: none;
    max-width: 1400px;
    transition: all 0.3s ease;
}

/* ---------- Bootstrap 5.3 bridge ----------
   Bootstrap 5.3 paints every component from its --bs-* variables, so
   the site maps those variables onto its tokens rather than setting
   background-color and friends directly. A direct property leaves
   :hover, :active, :focus and :disabled on Bootstrap's own values
   (the #0d6efd flash). The modal, table and accordion bridges sit in
   the repair layer at the end of this file. */
:root {
    --bs-border-radius: var(--r-sm);
    --bs-border-radius-sm: var(--r-sm);
    --bs-border-radius-lg: var(--r-md);
    --bs-border-radius-xl: var(--r-lg);
    --bs-border-radius-pill: var(--r-pill);
}

/* Section card (.card): one opaque surface. The body is transparent
   and shows the card. No hover movement: calculator cards hold inputs,
   and a card that jumps under the pointer moves the field being aimed
   at. A branded head is .card-header + .tool-section-header (Tools). */
.card {
    --bs-card-bg: var(--card-bg);
    --bs-card-color: var(--text-primary);
    --bs-card-cap-color: var(--text-primary);
    --bs-card-cap-bg: var(--surface-2);
    --bs-card-border-color: var(--border-medium);
    --bs-card-border-width: 1.5px;
    --bs-card-border-radius: var(--r-lg);
    --bs-card-inner-border-radius: calc(var(--r-lg) - 1.5px);
    box-shadow: var(--elev-1);
}

.card-header {
    border-bottom: 1px solid var(--border-soft);
}

.card-body {
    color: var(--text-primary);
}

/* Buttons — Bootstrap 5.3 paints every .btn state from its --bs-btn-*
   variables, so the solid variants are routed through the fill tokens
   (white label in both themes) instead of setting background-color,
   which Bootstrap's focus/active states overrode with its own blue.
   Each variant names its fill in
   --btn-fill; the shared rule derives hover (85% toward black) and
   active (75%). The old hover swap to --secondary-soft (primary
   buttons turning green) is gone. */
.btn-primary { --btn-fill: var(--primary-fill); }
.btn-success { --btn-fill: var(--success-fill); }
.btn-danger  { --btn-fill: var(--danger-fill); }
.btn-warning { --btn-fill: var(--warning-fill); }

.btn-primary,
.btn-success,
.btn-danger,
.btn-warning {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--btn-fill);
    --bs-btn-border-color: var(--btn-fill);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: color-mix(in srgb, var(--btn-fill) 85%, #000);
    --bs-btn-hover-border-color: color-mix(in srgb, var(--btn-fill) 85%, #000);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: color-mix(in srgb, var(--btn-fill) 75%, #000);
    --bs-btn-active-border-color: color-mix(in srgb, var(--btn-fill) 75%, #000);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--btn-fill);
    --bs-btn-disabled-border-color: var(--btn-fill);
}

.btn-primary {
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-medium);
}

/* Neutral (Close / Cancel / Reset): a quiet tinted surface with the
   theme's text colour. It used to be white on --text-secondary, which
   is a pale fill in dark mode (1.46:1, 1.07:1 on hover). */
.btn-secondary {
    --bs-btn-color: var(--text-primary);
    --bs-btn-bg: var(--neutral-tint);
    --bs-btn-border-color: var(--border-medium);
    --bs-btn-hover-color: var(--text-primary);
    --bs-btn-hover-bg: color-mix(in srgb, var(--text-primary) 14%, var(--card-bg));
    --bs-btn-hover-border-color: var(--border-medium);
    --bs-btn-active-color: var(--text-primary);
    --bs-btn-active-bg: color-mix(in srgb, var(--text-primary) 20%, var(--card-bg));
    --bs-btn-active-border-color: var(--border-medium);
    --bs-btn-disabled-color: var(--text-primary);
    --bs-btn-disabled-bg: var(--neutral-tint);
    --bs-btn-disabled-border-color: var(--border-medium);
    --bs-btn-border-width: 1px;
}

/* Every .btn: 8px corners (12px for .btn-lg), weight 600, a 40px
   minimum hit area (44px on touch screens) and a centred icon + label
   row. Bootstrap's focus glow is replaced by the site focus outline
   (Focus section). .btn-sm keeps Bootstrap's compact height with a
   mouse and grows to the touch minimum on coarse pointers. Tools keeps
   its own 48px sizing in tools/includes/tool-common.css. */
.btn {
    --bs-btn-border-radius: var(--r-sm);
    --bs-btn-font-weight: 600;
    --bs-btn-focus-box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--gap-icon);
    min-height: var(--control-h);
}

.btn-lg, .btn-group-lg > .btn {
    --bs-btn-border-radius: var(--r-md);
    --bs-btn-font-size: 1.05rem;
    min-height: var(--control-h-lg);
}

.btn-sm, .btn-group-sm > .btn {
    min-height: 0;
}

@media (pointer: coarse) {
    .btn-sm, .btn-group-sm > .btn {
        min-height: var(--control-h);
    }
}

/* A label built from block children (stacked score + caption, a
   two-line choice) stays inline-block so each child keeps its own
   line; in a flex row they would sit side by side. Start- and
   end-aligned labels keep their alignment. */
.btn:has(> div, > p, > br, > ul, > ol, > table) {
    display: inline-block;
}
.btn.text-start { justify-content: flex-start; }
.btn.text-end { justify-content: flex-end; }

/* Outline buttons: transparent, with a token label and border; hover,
   press and .active use the matching tint. Stock Bootstrap flashed
   #0d6efd (and its green/red/amber/cyan siblings) on hover outside
   Tools. Moved here from tools/includes/tool-common.css so every page
   gets the same recipe. Status tones read their colours from
   --btn-tone-*; the label carries the meaning, so the border can be
   the quiet 35% mix. */
.btn-outline-primary {
    --bs-btn-color: var(--primary-text);
    --bs-btn-border-color: var(--primary-soft);
    --bs-btn-hover-color: var(--primary-text);
    --bs-btn-hover-bg: var(--primary-tint);
    --bs-btn-hover-border-color: var(--primary-soft);
    --bs-btn-active-color: var(--primary-text);
    --bs-btn-active-bg: var(--primary-tint);
    --bs-btn-active-border-color: var(--primary-soft);
    --bs-btn-disabled-color: var(--primary-text);
    --bs-btn-disabled-bg: transparent;
    --bs-btn-disabled-border-color: var(--primary-soft);
}

.btn-outline-secondary {
    --bs-btn-color: var(--text-primary);
    --bs-btn-border-color: var(--border-medium);
    --bs-btn-hover-color: var(--text-primary);
    --bs-btn-hover-bg: var(--surface-2);
    --bs-btn-hover-border-color: var(--border-medium);
    --bs-btn-active-color: var(--text-primary);
    --bs-btn-active-bg: var(--surface-2);
    --bs-btn-active-border-color: var(--border-medium);
    --bs-btn-disabled-color: var(--text-primary);
    --bs-btn-disabled-bg: transparent;
    --bs-btn-disabled-border-color: var(--border-medium);
}

.btn-outline-success { --btn-tone-text: var(--success-text); --btn-tone-tint: var(--success-tint); --btn-tone-border: var(--success-border); --btn-tone-fill: var(--success-fill); }
.btn-outline-danger,
.btn-quiet-danger    { --btn-tone-text: var(--danger-text);  --btn-tone-tint: var(--danger-tint);  --btn-tone-border: var(--danger-border);  --btn-tone-fill: var(--danger-fill); }
.btn-outline-warning { --btn-tone-text: var(--warning-text); --btn-tone-tint: var(--warning-tint); --btn-tone-border: var(--warning-border); --btn-tone-fill: var(--warning-fill); }
.btn-outline-info    { --btn-tone-text: var(--info-text);    --btn-tone-tint: var(--info-tint);    --btn-tone-border: var(--info-border);    --btn-tone-fill: var(--info-fill); }

.btn-outline-success,
.btn-outline-danger,
.btn-quiet-danger,
.btn-outline-warning,
.btn-outline-info {
    --bs-btn-color: var(--btn-tone-text);
    --bs-btn-border-color: var(--btn-tone-border);
    --bs-btn-hover-color: var(--btn-tone-text);
    --bs-btn-hover-bg: var(--btn-tone-tint);
    --bs-btn-hover-border-color: var(--btn-tone-border);
    --bs-btn-active-color: var(--btn-tone-text);
    --bs-btn-active-bg: var(--btn-tone-tint);
    --bs-btn-active-border-color: var(--btn-tone-border);
    --bs-btn-disabled-color: var(--btn-tone-text);
    --bs-btn-disabled-bg: transparent;
    --bs-btn-disabled-border-color: var(--btn-tone-border);
}

/* Segmented toggles (.btn-check + label). A neutral choice uses the
   one selected state (navy gradient, white label); a choice that
   carries meaning (severity) fills with its status colour. Bootstrap
   paints only :checked from the active variables, so the last rule
   extends the same paint to the press, before the input flips.
   A button that can't be an input (a custom tool toggle) takes the
   same selected state from .is-selected or aria-pressed="true". The
   ti-check glyph and the .is-gold-ring variant are in the shared
   components block at the end of this file. */
.btn-check:checked + .btn-outline-primary,
.btn-check:active + .btn-outline-primary,
.btn-check:checked + .btn-outline-secondary,
.btn-check:active + .btn-outline-secondary,
.btn-outline-primary.is-selected,
.btn-outline-primary[aria-pressed="true"],
.btn-outline-secondary.is-selected,
.btn-outline-secondary[aria-pressed="true"] {
    --bs-btn-active-color: var(--text-on-fill);
    --bs-btn-active-bg: var(--brand-navy-3);
    --bs-btn-active-border-color: var(--brand-navy-3);
    background-image: var(--selected-bg);
}

.btn-check:checked + :is(.btn-outline-success, .btn-outline-danger, .btn-outline-warning, .btn-outline-info),
.btn-check:active + :is(.btn-outline-success, .btn-outline-danger, .btn-outline-warning, .btn-outline-info),
:is(.btn-outline-success, .btn-outline-danger, .btn-outline-warning, .btn-outline-info):is(.is-selected, [aria-pressed="true"]) {
    --bs-btn-active-color: var(--text-on-fill);
    --bs-btn-active-bg: var(--btn-tone-fill);
    --bs-btn-active-border-color: var(--btn-tone-fill);
}

.btn-check:active + .btn,
.btn.is-selected,
.btn[aria-pressed="true"] {
    color: var(--bs-btn-active-color);
    background-color: var(--bs-btn-active-bg);
    border-color: var(--bs-btn-active-border-color);
}

/* Form Controls — one recipe for every field, both themes. The well is
   --input-bg (white in light, the recessed #0E1426 in dark), framed by
   --border-strong, which identifies a control at 3:1 or better on both
   the card and the well. Hover darkens the frame to the link blue;
   focus adds the two-tone --focus-ring outside it. */
.form-control, .form-select {
    background-color: var(--input-bg);
    border: 2px solid var(--border-strong);
    color: var(--text-primary);
    border-radius: var(--r-sm);
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.form-control:hover, .form-select:hover {
    border-color: var(--primary-text);
}

.form-control:focus, .form-select:focus {
    background-color: var(--input-bg);
    border-color: var(--focus-color);
    color: var(--text-primary);
    box-shadow: var(--focus-ring);
}

.form-control:disabled, .form-select:disabled {
    background-color: var(--neutral-bg);
    border-color: var(--border-strong);
    color: var(--text-muted);
}

/* Bootstrap's select chevron is a fixed dark stroke; on the dark well
   it needs a light one. */
[data-theme="dark"] .form-select {
    --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23CED6E4' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

/* iOS Safari zooms the page into any field set below 16px. (The -lg
   sizes are already larger; 1em here is the parent's size, so they are
   left alone rather than pulled down to 16px.) */
@media (max-width: 768px) {
    .form-control:not(.form-control-lg),
    .form-select:not(.form-select-lg) {
        font-size: max(16px, 1em);
    }
}

.form-label {
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

/* Alerts: the shared component (every tone, the icon slot and
   .callout) lives in SHARED COMPONENTS at the end of this file. */

/* Text Utilities */
.text-primary {
    color: var(--primary-soft) !important;
}

.text-secondary {
    color: var(--text-secondary) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

/* ---------- Readability battery (legacy, fenced) ----------
   The rules marked "battery" below force --text-primary onto text so
   pages written before the token system stay legible, at the cost of
   erasing colours components set themselves (status arrows, labels on
   navy). They apply only under body:not(.fl-v2). Each page family adds
   class "fl-v2" to <body> once its pages pass in both themes, and
   deletes its own !important patches in the same upload; Phase 14
   deletes the battery once every page has the class. The :where()
   wrapper adds no specificity, so every rule keeps the weight it had.
   The battery: .display-*, .lead, .card-title, .bg-light (+ all
   descendants), inline-background .rounded boxes, the five inline
   pastel backgrounds, .card-body headings/p/span/div, .table th/td,
   ul/ol/li, strong/b, p and label colours. */

/* Battery: display text */
:where(body:not(.fl-v2)) :is(.display-1, .display-2, .display-3, .display-4, .display-5, .display-6) {
    color: var(--text-primary) !important;
    font-weight: 600;
}

/* Battery: lead text */
:where(body:not(.fl-v2)) .lead {
    color: var(--text-primary) !important;
}

/* Battery: card titles */
:where(body:not(.fl-v2)) .card-title {
    color: var(--text-primary) !important;
}

/* Battery: all text in light backgrounds */
:where(body:not(.fl-v2)) .bg-light,
:where(body:not(.fl-v2)) .bg-light * {
    color: var(--text-primary) !important;
}

/* Bootstrap text color overrides for better readability */
.text-white {
    color: #FFFFFF !important;
}

[data-theme="dark"] .text-white {
    color: #FFFFFF !important;
}

/* Headers. Bootstrap sets every heading to 500; the three structural
   levels are bold and the small ones semi-bold. The level follows the
   document outline; the size comes from the heading's class. */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
}

h1, h2, h3 {
    font-weight: 700;
    line-height: 1.25;
}

h4, h5, h6 {
    font-weight: 600;
}

/* Links. Hover keeps the link colour (it used to turn green) and
   underlines plain links. A link with a class (button, card, tab, nav
   item) styles its own hover, so :where() holds the underline at the
   weight of one class and any component rule wins. .text-link is the
   explicit underlined link. */
a {
    color: var(--primary-soft);
    text-decoration: none;
    transition: all 0.3s ease;
}

:where(a:not([class])):hover {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

/* Input Groups — the addon is a raised tile in the same frame as the
   field beside it. */
.input-group-text {
    background-color: var(--surface-2);
    border: 2px solid var(--border-strong);
    color: var(--text-secondary);
}

/* Tables */
.table {
    color: var(--text-primary);
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--card-bg);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .card-body {
        padding: 1rem !important;
    }
}

/* Utility Classes */
.shadow-soft {
    box-shadow: 0 2px 8px var(--shadow-soft) !important;
}

.shadow-medium {
    box-shadow: 0 4px 12px var(--shadow-medium) !important;
}

.bg-container {
    background-color: var(--container-bg) !important;
}

.bg-card {
    background-color: var(--card-bg) !important;
}

.border-soft {
    border-color: var(--border-soft) !important;
}

.border-medium {
    border-color: var(--border-medium) !important;
}

/* Battery: result boxes with an inline background colour */
:where(body:not(.fl-v2)) .rounded[style*="background-color"] {
    color: var(--text-primary) !important;
}

:where(body:not(.fl-v2)) .rounded[style*="background-color"] :is(h1, h2, h3, h4, h5, h6, p),
:where(body:not(.fl-v2)) .rounded[style*="background-color"] :is(.display-1, .display-2, .display-3, .display-4, .display-5, .display-6) {
    color: var(--text-primary) !important;
}

/* Battery: all text in card bodies (status pills keep their tone) */
:where(body:not(.fl-v2)) .card-body :is(h1, h2, h3, h4, h5, h6, p, span, div):where(:not(.status-pill)) {
    color: var(--text-primary);
}

/* Override Bootstrap's text-muted on light backgrounds */
.bg-light .text-muted {
    color: var(--text-muted) !important;
}

/* Ensure proper contrast in all alert boxes (status pills keep their
   tone; .alert-title and .alert-heading out-rank this at two classes) */
.alert h1, .alert h2, .alert h3, .alert h4, .alert h5, .alert h6,
.alert p, .alert div {
    color: inherit;
}
.alert span:where(:not(.status-pill)) {
    color: inherit;
}

/* Battery: inline pastel backgrounds */
:where(body:not(.fl-v2)) :is([style*="background-color: #e3f2fd"], [style*="background-color: #e8f5e9"], [style*="background-color: #fff3e0"], [style*="background-color: #f3e5f5"], [style*="background-color: #fff3cd"]),
:where(body:not(.fl-v2)) :is([style*="background-color: #e3f2fd"], [style*="background-color: #e8f5e9"], [style*="background-color: #fff3e0"], [style*="background-color: #f3e5f5"], [style*="background-color: #fff3cd"]) * {
    color: var(--text-primary) !important;
}

/* Battery: table cells */
:where(body:not(.fl-v2)) :is(.table, .table-bordered) :is(th, td) {
    color: var(--text-primary) !important;
}

/* Battery: list text */
:where(body:not(.fl-v2)) :is(ul, ol, li) {
    color: var(--text-primary);
}

/* Strong/bold text (the colour is battery) */
strong, b {
    font-weight: 600;
}
:where(body:not(.fl-v2)) :is(strong, b) {
    color: var(--text-primary);
}

/* Paragraph rhythm (the colour is battery) */
p {
    line-height: 1.6;
}
:where(body:not(.fl-v2)) p {
    color: var(--text-primary);
}

/* Form text helpers */
.form-text {
    color: var(--text-secondary);
}

/* Small text */
small, .small {
    color: var(--text-secondary);
}

/* Improve contrast in result boxes */
.display-1, .display-2, .display-3, .display-4, .display-5, .display-6 {
    font-weight: 700 !important;
}

/* Better contrast for h6 (often used for labels) */
h6 {
    font-weight: 600;
}

/* Placeholder text: the muted token at full opacity (5.9:1 light, 6.2:1
   on the dark well). .form-control::placeholder out-ranks Bootstrap's
   own rule, which used a translucent body colour. */
input::placeholder,
textarea::placeholder,
select::placeholder,
.form-control::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* Label weight (the colour is battery). Button weight lives in the
   .btn base (--bs-btn-font-weight). */
label {
    font-weight: 600;
}
:where(body:not(.fl-v2)) label {
    color: var(--text-primary);
}

/* ==========================================
   Site Footer
   ========================================== */
/* Decorative section dividers */
.section-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 3rem auto;
    max-width: 600px;
    color: var(--text-muted);
}

.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(120, 140, 180, 0.3) 50%, transparent 100%);
}

.section-divider i {
    font-size: 1.2rem;
    color: rgba(120, 140, 180, 0.5);
}

[data-theme="dark"] .section-divider::before,
[data-theme="dark"] .section-divider::after {
    background: linear-gradient(90deg, transparent 0%, rgba(90, 130, 180, 0.25) 50%, transparent 100%);
}

[data-theme="dark"] .section-divider i {
    color: rgba(90, 130, 180, 0.5);
}

.site-footer {
    text-align: center;
    padding: 0.5rem 1.25rem;
    font-size: 0.8rem;
    /* Footer is a dark slate gradient now, so the muted-dark default
       text disappears. Use light colors regardless of theme. */
    color: #C8D2E0;
    /* Mirror of the navbar: steel blue rising into deep navy, with the
       brand-red accent line where the bar meets the page. */
    border-top: 2px solid rgba(146, 43, 32, 0.75);
    margin-top: auto;
    background: linear-gradient(315deg, rgba(12, 25, 41, 0.97) 0%, rgba(24, 42, 68, 0.95) 55%, rgba(40, 66, 102, 0.93) 100%);
    box-shadow: 0 -4px 20px rgba(12, 25, 41, 0.25), inset 0 -1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(16px) saturate(1.3);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
    /* Sits at the end of the document. The body flex column with
       min-height: 100vh and .page-scroll's flex: 1 means short pages
       still land the footer at the viewport bottom; long pages scroll
       past it normally. */
    flex-shrink: 0;
    z-index: 900;
}

[data-theme="dark"] .site-footer {
    background: linear-gradient(315deg, #0A0F1C 0%, #10172A 70%, #16223A 100%);
    border-top: 2px solid rgba(146, 43, 32, 0.55);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.5);
}

.footer-copyright {
    font-weight: 600;
    text-align: right;
    /* Sits in the RIGHT slot of the 3-column .footer-row grid. */
    justify-self: end;
}

/* Footer links: a light tint of the admin site colour, white with an
   underline on hover and keyboard focus. 40% site colour (not the 70%
   first planned): measured where the links actually sit on the light
   footer's gradient, 70% gave 3.6-4.1:1 at desktop widths and about
   3:1 on a phone; 40% keeps 4.5:1 or better in both themes for the
   live #E01B24 and the default #c0392b. A link wraps as a whole
   ("Development Log" no longer splits across lines on a phone). */
.site-footer a {
    color: color-mix(in srgb, var(--site-color, #c0392b) 40%, #FFFFFF);
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
    transition: color 0.2s ease;
}

.site-footer a:hover,
.site-footer a:focus-visible {
    color: #FFFFFF;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.site-footer .footer-sep {
    margin: 0 0.5rem;
    opacity: 0.4;
}

/* Footer is a 3-column grid: copyright left, links centered, theme
   toggle right. Switched from flex space-between so the links
   stay anchored to the visual center regardless of how wide the
   side columns get. */
.footer-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.4rem;
}
.footer-row .footer-links { text-align: center; justify-self: center; }

.footer-theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    /* Sits in the LEFT slot of the 3-column .footer-row grid. */
    justify-self: start;
    padding: 0.4rem 0.9rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    /* Match the navbar pills + .seg-tab so every button across the
       site shares one silhouette. */
    border-radius: var(--r-md, 12px);
    color: #C8D2E0;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.footer-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.3);
    color: #FFFFFF;
}
.footer-theme-toggle i { font-size: 1rem; }
/* Dark theme shows the sun (switch to light): brand gold on the navy. */
[data-theme="dark"] .footer-theme-toggle i { color: var(--brand-gold); }

/* Mobile widths — collapse the footer's 3-column grid to a vertical
   stack with every row (copyright, links, theme toggle) centered. The
   theme toggle gets the site's 44px touch height and each link a
   24px-plus tap area. */
@media (max-width: 768px) {
    .footer-row {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 0.5rem;
    }
    .footer-row .footer-copyright,
    .footer-row .footer-links,
    .footer-row .footer-theme-toggle {
        justify-self: center;
        text-align: center;
    }
    .footer-theme-toggle {
        min-height: 44px;
    }
    .site-footer .footer-links a {
        display: inline-block;
        padding-block: 0.3rem;
    }
}

@media print {
    /* Entrance animations must not reach paper. A card that was hidden on
       screen only starts its fade-in when the print routine reveals it, so
       the print snapshot would catch it mid-animation: faint text pushed
       down by the translateY, i.e. a blank band that "fades in" on page 1. */
    .fade-in {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .site-footer {
        display: none !important;
    }
    /* The custom overlay scrollbar is an absolutely-positioned element with a
       background; when printed it renders as a rectangular block/void down the
       page. It has no meaning on paper, so drop it and let the scroll wrapper
       flow naturally. */
    .fl-scrollbar-track,
    .fl-scrollbar-thumb {
        display: none !important;
    }
    .fl-scrolled > .fl-scroll {
        overflow: visible !important;
        height: auto !important;
        max-height: none !important;
    }
}

/* =========================================================
   SHARED COMPONENTS
   Primitives consolidated from module CSS files. Load-order-wise
   these live in styles.css so every page gets them; module CSS
   that overrides (e.g. a tighter breadcrumb margin on view pages)
   still wins via later load order.
   ========================================================= */

/* Breadcrumb nav */
.breadcrumb-nav {
    margin-bottom: 2rem;
    /* Temporarily hidden site-wide while evaluating the look without
       breadcrumbs. Remove this `display: none` to restore them. */
    display: none;
}

.breadcrumb-nav a {
    color: var(--primary-soft);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: color 0.2s ease;
}

.breadcrumb-nav a:hover {
    color: var(--text-primary);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

/* Empty state — the Library's dashed placeholder, for every "nothing
   here yet" message. Markup:
     <div class="empty-state" role="status">   (role only for live results)
       <i class="ti ti-... empty-state-icon" aria-hidden="true"></i>
       <h2 class="empty-state-title">Title</h2>   (any element; styled by class)
       <p class="empty-state-text">Text</p>
       [one .btn-primary or .pill-btn]
     </div>
   Older markup (a bare <i>, an h2/h3 and a p inside .empty-state)
   renders the same. .empty-state--compact drops the frame for use in
   tables, cards and accordions; .empty-state--success is "all caught
   up". The icon bobs only with .is-animated, and never under reduced
   motion. Aliases: .res-empty, .admin-empty-state. */
.empty-state,
.res-empty,
.admin-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
    border: 2px dashed var(--border-medium);
    border-radius: var(--r-lg);
    background: transparent;
    color: var(--text-secondary);
}

.empty-state-icon,
.empty-state > i,
.res-empty > i,
.admin-empty-state > i {
    font-size: 2.6rem;
    line-height: 1;
    color: var(--primary-soft);
    margin-bottom: 0.85rem;
}

.empty-state-title,
.empty-state h2,
.empty-state h3 {
    font-size: var(--fs-card-title);
    font-weight: 700;
    line-height: 1.25;
    color: var(--text-primary);
    margin: 0 0 0.4rem;
}

.empty-state-text,
.empty-state > p:not(.empty-state-title),
.res-empty > p,
.admin-empty-state > p {
    font-size: var(--fs-body);
    line-height: 1.55;
    max-width: 48ch;
    margin: 0;
    color: var(--text-secondary);
}

.empty-state > p:not(.empty-state-title) + p:not(.empty-state-title),
.empty-state-text + .empty-state-text {
    margin-top: 0.5rem;
}

.empty-state > .btn,
.empty-state > .pill-btn {
    margin-top: 1rem;
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
    .empty-state,
    .res-empty,
    .admin-empty-state {
        border-color: color-mix(in srgb, var(--primary-soft) 22%, var(--border-soft));
        background: color-mix(in srgb, var(--primary-soft) 4%, transparent);
    }
}

.empty-state--compact {
    padding: 1.25rem;
    border: 0;
    background: none;
}

.empty-state--compact .empty-state-icon,
.empty-state--compact > i {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.empty-state--compact .empty-state-title,
.empty-state--compact h2,
.empty-state--compact h3 {
    font-size: var(--fs-body);
}

.empty-state--success {
    border-color: var(--success-border);
    background: var(--success-tint);
}

.empty-state--success .empty-state-icon,
.empty-state--success > i {
    color: var(--success-text);
}

@keyframes flEmptyBob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

@media (prefers-reduced-motion: no-preference) {
    .empty-state.is-animated .empty-state-icon,
    .empty-state.is-animated > i {
        animation: flEmptyBob 2.6s ease-in-out infinite;
    }
}

/* Admin floating edit cog: a navy chrome button with a gold ring, the
   same in both themes. Bumped up (bottom 5rem) so it doesn't overlap
   the footer's Light/Dark mode toggle. Above sticky bars, under modals
   and toasts (--z-fab). */
.admin-edit-cog {
    position: fixed;
    bottom: 5rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--brand-navy);
    color: #fff;
    border: 2px solid var(--brand-gold);
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--elev-3);
    transition: transform var(--dur) var(--ease-out), background-color var(--dur) var(--ease-out),
                box-shadow var(--dur) var(--ease-out);
    z-index: var(--z-fab, 1040);
    text-decoration: none;
}

.admin-edit-cog:hover {
    transform: scale(1.1);
    background: var(--brand-navy-3);
    box-shadow: var(--elev-4);
    color: #fff;
}

.admin-edit-cog:active {
    transform: scale(0.95);
}

/* The open phone menu (navbar.php moves it to <body>, z 999) sits under
   --z-fab, so the cog would cover the end of its rows: hide the cog
   while the menu is open. */
@media (max-width: 960px) {
    body:has(> .navbar-nav.show) .admin-edit-cog {
        display: none;
    }
}

/* Fade-in animation */
.fade-in {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

.fade-in-delay-1 { animation-delay: 0.06s; }
.fade-in-delay-2 { animation-delay: 0.12s; }
.fade-in-delay-3 { animation-delay: 0.18s; }
.fade-in-delay-4 { animation-delay: 0.24s; }
/* Extended ramp so card grids cascade per-card instead of animating
   as one block. Listing templates emit fade-in-delay-N with N capped
   at 8; anything past the 8th card lands together on the last step. */
.fade-in-delay-5 { animation-delay: 0.30s; }
.fade-in-delay-6 { animation-delay: 0.36s; }
.fade-in-delay-7 { animation-delay: 0.42s; }
.fade-in-delay-8 { animation-delay: 0.48s; }

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Honor the OS-level motion preference: show everything immediately. */
@media (prefers-reduced-motion: reduce) {
    .fade-in {
        animation: none;
        opacity: 1;
        transform: none;
    }
}

/* ---------- Frosted glass card surface ----------
   Applied to every listing/panel card across modules. Module CSS
   only needs to declare its card-specific properties (padding,
   border-radius, layout) — the translucent appearance, border,
   shadow, blur, and transition all come from here.

   Token-driven in both themes (--surface-frost and the --elev-listing
   pair are declared with the shared components at the end of this
   file); the canonical class is .surface-listing.
*/
.category-card,
.question-card,
.score-card,
.res-card {
    background-color: var(--surface-frost);
    border: var(--frame-w) solid var(--frame-panel);
    box-shadow: var(--elev-1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Interactive listing cards — hover lift. Static panels (question,
   score) are excluded, and so is any card tagged .is-static unless it
   is a link. */
.category-card:where(a, :not(.is-static)):hover,
.res-card:where(a, :not(.is-static)):hover {
    transform: translateY(var(--lift-card));
    text-decoration: none;
    color: inherit;
}

/* ---------- Tactile listing dialect ----------
   The framed look the Learn library pioneered, now shared by every
   listing card: near-black 3px frame (steel-blue in dark mode), a
   quiet diagonal surface sheen over the frosted glass, and blue-cast
   shadows. Placed after the frosted base above so these win the
   same-specificity cascade. */
.category-card,
.res-card {
    border: var(--frame-w) solid var(--frame-listing);
    background: var(--surface-glass);
    box-shadow: var(--elev-listing);
}

.category-card:where(a, :not(.is-static)):hover,
.res-card:where(a, :not(.is-static)):hover {
    border-color: var(--frame-listing-hover);
    background: var(--surface-glass-hover);
    box-shadow: var(--elev-listing-hover);
}

/* "Login required" notice shown on the login page when REQUIRE_LOGIN is on */
.hero-login-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    color: var(--text-primary);
    background: color-mix(in srgb, var(--site-color) 12%, transparent);
    border: 1.5px solid color-mix(in srgb, var(--site-color) 40%, transparent);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin: 0 0 1.5rem;
    line-height: 1.4;
    text-align: center;
}

.hero-login-notice i {
    font-size: 1.1rem;
    color: var(--site-color);
    flex-shrink: 0;
}

/* =========================================================
   Custom overlay scrollbar (see includes/custom-scrollbar.js)
   Wraps a scroll container's children in .fl-scroll, hides the
   native scrollbar, and renders a chunkier track + thumb that
   works identically in Firefox (which can't size native
   scrollbars) and all Chromium/WebKit browsers.
   ========================================================= */
/* .fl-scrolled is applied to the former scroll container by the JS.
   Permissive: just provides the positioning context and hides the
   native scrollbar on the inner wrapper. Each consumer (TOC, SCORM
   content, etc.) supplies its own height mechanic via overrides —
   flex: 1 when the parent gives height, or max-height otherwise. */
.fl-scrolled {
    position: relative;
    overflow: visible;
}
.fl-scrolled > .fl-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    /* No reserved gutter — the custom track sits over the right edge
       of the content like a native overlay scrollbar. Full-bleed
       elements (hero banners, etc.) reach the viewport edge. */
    box-sizing: border-box;
}
.fl-scrolled > .fl-scroll::-webkit-scrollbar { display: none; }

.fl-scrollbar-track {
    position: absolute;
    top: 8px;
    right: 6px;
    bottom: 8px;
    width: 20px;
    background: rgba(120, 140, 180, 0.15);
    border-radius: 12px;
    z-index: 5;
    user-select: none;
}
.fl-scrollbar-thumb {
    position: absolute;
    left: 3px;
    right: 3px;
    top: 0;
    min-height: 36px;
    background: #7a8ca8;
    border-radius: 10px;
    cursor: grab;
    transition: background 0.15s ease;
    will-change: transform, height;
}
.fl-scrollbar-thumb:hover { background: #4A7BA7; }
.fl-scrollbar-thumb.fl-dragging { cursor: grabbing; background: #4A7BA7; }

[data-theme="dark"] .fl-scrollbar-track { background: rgba(90, 130, 180, 0.15); }
[data-theme="dark"] .fl-scrollbar-thumb { background: #5A8BC4; }
[data-theme="dark"] .fl-scrollbar-thumb:hover,
[data-theme="dark"] .fl-scrollbar-thumb.fl-dragging { background: #8DB9E8; }

/* ==========================================
   Bootstrap dark-theme repair layer
   ------------------------------------------
   Bootstrap 5 ships light-only surfaces (modals, .bg-light, table
   tints) and the site never sets data-bs-theme, while the
   readability battery above forces near-white text in dark mode.
   Together that used to produce white-on-white modals and pastel
   tables with invisible text. This block bridges every Bootstrap
   surface onto the site tokens. It must stay at the END of the file:
   several rules win against the battery above only by source order.
   ========================================== */

/* Modals follow the card surface in both themes. Bootstrap modals read
   the --bs-modal-* variables (16px panel, header corners one border
   inside it) and a .55 backdrop. The plain .modal-content rules also
   cover hand-built modals that borrow the class without a .modal. */
.modal {
    --bs-modal-bg: var(--card-bg);
    --bs-modal-color: var(--text-primary);
    --bs-modal-border-color: var(--border-soft);
    --bs-modal-border-radius: var(--r-lg);
    --bs-modal-inner-border-radius: calc(var(--r-lg) - var(--bs-modal-border-width));
    --bs-modal-header-border-color: var(--border-soft);
    --bs-modal-footer-border-color: var(--border-soft);
    --bs-modal-footer-bg: var(--neutral-bg);
}

.modal-backdrop {
    --bs-backdrop-opacity: 0.55;
}

.modal-content {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-soft);
}

.modal-header {
    border-bottom-color: var(--border-soft);
}

.modal-footer {
    border-top-color: var(--border-soft);
    background-color: var(--neutral-bg);
}

[data-theme="dark"] .modal-content {
    box-shadow: var(--elev-4);
}

[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(180%);
}

/* .bg-light means "subtle panel", not "always #f8f9fa". */
[data-theme="dark"] .bg-light {
    background-color: var(--card-hover) !important;
}

/* Bootstrap 5.3 paints every table cell from --bs-table-bg (white by
   default, regardless of theme). Base tables go transparent so the
   page surface shows through, rules are the soft hairline, and hover
   rows lift to --surface-2. Tinted variants get dark counterparts from
   the status tint/border pairs. */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border-soft);
    --bs-table-striped-color: var(--text-primary);
    --bs-table-active-color: var(--text-primary);
    --bs-table-hover-color: var(--text-primary);
    --bs-table-hover-bg: var(--surface-2);
}

[data-theme="dark"] .table-light,
[data-theme="dark"] .table-secondary {
    --bs-table-bg: var(--surface-2);
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border-medium);
}

[data-theme="dark"] .table-primary,
[data-theme="dark"] .table-info {
    --bs-table-bg: var(--info-tint);
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--info-border);
}

[data-theme="dark"] .table-success {
    --bs-table-bg: var(--success-tint);
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--success-border);
}

[data-theme="dark"] .table-warning {
    --bs-table-bg: var(--warning-tint);
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--warning-border);
}

[data-theme="dark"] .table-danger {
    --bs-table-bg: var(--danger-tint);
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--danger-border);
}

/* Dark table heads go brand navy instead of Bootstrap charcoal, and
   keep white text in BOTH themes (the readability battery above would
   otherwise paint them near-black in light mode). */
.table-dark {
    --bs-table-bg: var(--brand-navy-2);
    --bs-table-color: #F5F8FB;
    --bs-table-border-color: var(--brand-navy-3);
}

.table-dark th,
.table-dark td {
    color: #F5F8FB !important;
}

/* Accordions sit on the card surface; the open head lifts to
   --surface-2. Bootstrap draws its focus ring with box-shadow on
   :focus (so a mouse click shows it too, and an item's overflow can
   clip it); the site outline on :focus-visible replaces it, drawn
   inside the button (Focus section). */
.accordion {
    --bs-accordion-color: var(--text-primary);
    --bs-accordion-bg: var(--card-bg);
    --bs-accordion-border-color: var(--border-soft);
    --bs-accordion-border-radius: var(--r-md);
    --bs-accordion-inner-border-radius: calc(var(--r-md) - var(--bs-accordion-border-width));
    --bs-accordion-btn-color: var(--text-primary);
    --bs-accordion-btn-bg: var(--card-bg);
    --bs-accordion-btn-focus-border-color: var(--focus-color);
    --bs-accordion-btn-focus-box-shadow: none;
    --bs-accordion-active-color: var(--text-primary);
    --bs-accordion-active-bg: var(--surface-2);
}

/* Status text utilities must survive the readability battery — a
   .text-danger classification losing its color is a safety problem
   on clinical pages. Compound selectors out-rank the forcing rules. */
.text-success,
.card-body .text-success,
.table .text-success,
.bg-light .text-success,
.modal-body .text-success {
    color: var(--success-soft) !important;
}

.text-danger,
.card-body .text-danger,
.table .text-danger,
.bg-light .text-danger,
.modal-body .text-danger {
    color: var(--danger-soft) !important;
}

.text-warning,
.card-body .text-warning,
.table .text-warning,
.bg-light .text-warning,
.modal-body .text-warning {
    color: var(--warning-soft) !important;
}

.text-info,
.card-body .text-info,
.table .text-info,
.modal-body .text-info {
    color: var(--info-soft) !important;
}

.text-white,
.card-body .text-white,
.display-1.text-white, .display-2.text-white, .display-3.text-white,
.display-4.text-white, .display-5.text-white, .display-6.text-white {
    color: #FFFFFF !important;
}

/* Alert variants (.alert-primary, .alert-secondary): see the shared
   .alert in SHARED COMPONENTS at the end of this file. */

/* List groups sit on whatever card hosts them. */
.list-group-item {
    background-color: transparent;
    color: var(--text-primary);
    border-color: var(--border-soft);
}

.list-group-item-action:hover,
.list-group-item-action:focus {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}

/* Native Bootstrap checks, radios and switches, both themes: the field
   well framed by --border-strong (a control boundary at 3:1 or better)
   and the primary fill once checked (white glyph at 5.2:1). Bootstrap
   glows blue on every focus, mouse included; keyboard focus gets the
   site ring instead. 1.15em boxes with a 1.5px frame, centred on the
   first text line; the switch knob and the indeterminate state are in
   the shared components block at the end of this file. */
.form-check-input {
    --bs-form-check-bg: var(--input-bg);
    background-color: var(--input-bg);
    border: 1.5px solid var(--border-strong);
    width: 1.15em;
    height: 1.15em;
    margin-top: 0.175em;
}

.form-check-input:checked {
    background-color: var(--primary-fill);
    border-color: var(--primary-fill);
}

.form-check-input:focus {
    border-color: var(--border-strong);
    box-shadow: none;
}

.form-check-input:checked:focus {
    border-color: var(--primary-fill);
}

.form-check-input:focus-visible {
    box-shadow: var(--focus-ring);
}

[data-theme="dark"] .progress {
    background-color: var(--neutral-light);
}

/* Deliberate, subtle striping in dark mode (Bootstrap's default black
   overlay reads as mud on the dark surfaces). */
[data-theme="dark"] .table-striped {
    --bs-table-striped-bg: rgba(255, 255, 255, 0.04);
    --bs-table-striped-color: var(--text-primary);
}



/* ============================================================
   Type scale — one ladder for every module's page and card text.
   Module stylesheets load after this file, so these are written
   with a `body` prefix to out-rank their single-class rules; the
   clamp() on the page title replaces the per-module mobile steps.
   The --fs-* tokens themselves live in the top :root block.
   ============================================================ */
body .admin-title {
    font-size: var(--fs-page-title);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.01em;
}
body .admin-subtitle {
    font-size: var(--fs-page-subtitle);
    line-height: 1.5;
}
body .section-title {
    font-size: var(--fs-section-title);
    font-weight: 700;
    line-height: 1.25;
}
body .category-title, body .res-title {
    font-size: var(--fs-card-title);
    font-weight: 700;
    line-height: 1.25;
}
/* Titles that sit on the card header band keep the band size. */
body .lib-card-head > h2, body .lib-card-head > h3 {
    font-size: var(--fs-band-title);
}
body .category-description, body .res-desc {
    font-size: var(--fs-body);
    line-height: 1.55;
}

/* ============================================================
   Icon sizing — one size per context. Nav icons are set in
   navbar.css (1.15 / 1.2rem); these cover cards and buttons.
   ============================================================ */
.btn i, .btn .ti, .admin-tab i, .topic-nav-btn i {
    font-size: 1.05em;
    line-height: 1;
    vertical-align: -0.12em;
}
.lib-card-head > h2 i, .lib-card-head > h3 i, .section-title i {
    font-size: 1.1em;
    line-height: 1;
    vertical-align: -0.1em;
    margin-right: 0.3em;
}

/* ============================================================
   Listing cards — one hover / focus language for every .lib-card:
   the same lift, the same shadow, and a keyboard focus ring that
   matches the pointer hover. Div cards with inner links use
   :focus-within so tabbing into them reads the same as hovering.
   Only links and cards not tagged .is-static react: shells and
   unlinked cards take .is-static and stay put. :where() keeps the
   old (0,2,0) weight so module overrides still win.
   ============================================================ */
.lib-card {
    transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) ease,
                border-color var(--dur) ease, background var(--dur) ease;
}
.lib-card:where(a, :not(.is-static)):hover,
.lib-card:where(a, :not(.is-static)):focus-visible,
.lib-card:where(a, :not(.is-static)):focus-within {
    transform: translateY(var(--lift-card));
}
/* The solid two-tone --focus-ring (3:1 or better on any surface) sits in
   front of the hover elevation and stands in for the outline. Div cards
   take it only for keyboard focus inside them (:has(:focus-visible)),
   so a mouse click on an inner button draws no ring; that selector is
   a separate rule so engines without :has() still keep the first. */
a.lib-card:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring), var(--elev-listing-hover);
}
.lib-card:where(a, :not(.is-static)):has(:focus-visible) {
    box-shadow: var(--focus-ring), var(--elev-listing-hover);
}
@media (prefers-reduced-motion: reduce) {
    .lib-card, .lib-card:hover, .lib-card:focus-visible, .lib-card:focus-within {
        transition: none;
        transform: none;
    }
}

/* ============================================================
   Focus — one visible indicator for keyboard users.
   Only :focus-visible is styled, so a mouse click never draws a
   ring. :where() keeps the default at zero specificity, so any
   component with its own focus style still wins. Left out on
   purpose: tabindex="-1" targets (scroll boxes such as content-main
   and Bootstrap modals, which script focuses but Tab never reaches)
   and the Quill editor, whose caret is the indicator.
   ============================================================ */
:where(a, button, [role="button"], [tabindex]:not([tabindex="-1"]), summary, select):where(:not(.ql-editor)):focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-offset);
}

/* Bootstrap components that zero the outline on focus. */
.btn:focus-visible,
.btn-check:focus-visible + .btn,
.nav-link:focus-visible,
.navbar-toggler:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-offset);
}

.nav-link:focus-visible {
    box-shadow: none;
}

/* Drawn inside the button: an accordion item may clip its overflow. */
.accordion-button:focus-visible {
    outline: var(--focus-outline);
    outline-offset: -4px;
}

/* On navy chrome the indicator turns brand gold (9:1 on navy; under 2:1
   on white, so never on light surfaces). The tokens are re-declared on
   the container, so the default rule above, the field ring and any
   component reading --focus-* follow. Page heroes are navy in both
   themes, so they take the gold too. */
.navbar,
.site-footer,
.fl-band,
.lib-card-head,
.checklist-section .section-header,
.tool-modal .modal-header,
.page-hero,
.learn-hero {
    --focus-color: var(--focus-color-chrome);
    --focus-outline: 2px solid var(--focus-color-chrome);
    --focus-ring: 0 0 0 2px var(--brand-navy), 0 0 0 4px var(--focus-color-chrome);
}

/* ============================================================
   Reduced motion. No universal * rule: spinners, progress bars and
   the simulator alarms keep animating, because they carry meaning.
   What stops: the light-mode background pulse, smooth in-page
   scrolling, and hover lifts and nudges (the empty-state bob only
   runs under no-preference). Module sheets load after this file, so
   the hover list uses !important; an entry can go once its family
   moves the lift onto --lift-card (0 under reduced motion) inside a
   no-preference query.
   Only elements whose resting transform is none are listed, and
   raised active tabs are excluded so hovering them doesn't drop them.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    body::before,
    body::after {
        animation: none;
    }

    :is(
        /* includes/styles.css */
        .btn-primary, .admin-edit-cog, .category-card, .res-card,
        /* includes/navbar.css, profile.css */
        .navbar-brand, .nav-link:not(.active), .btn-save,
        .ach-card.is-unlocked,
        /* learn/ */
        .lib-tab:not(.is-active), .admin-topic-cog, .video-collapse-btn,
        .ap-play-btn, .quiz-submit-btn,
        .ce-enroll-btn, .ce-cert-view-btn, .completion-btn-primary,
        .learn-back-btn, .styled-info-card, .sic-example, .styled-callout,
        /* schedule/, assignments/, study/ */
        .sched-month-cell, .sched-event,
        .sched-month-event, a.sched-team-chip,
        .assign-section-card, .study-show-answer, .study-rate:not(.selected),
        /* admin/ */
        .btn-delete, .btn-edit, .btn-topics, .wysi-add-btn, .wysi-tb-btn,
        /* resources/, quizzes/, tools/tools/css/ */
        .res-open-btn, .res-copy-btn,
        .answer-btn, .btn-next, .qdiff-btn,
        .checklist-btn, .info-btn
    ):hover,
    .admin-edit-cog:active {
        transform: none !important;
    }
}

/* ============================================================
   Theme change — a short cross-fade instead of a hard cut. The
   navbar's toggleTheme() adds .theme-transition to <html> for
   ~400 ms; skipped when the OS asks for reduced motion.
   ============================================================ */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
    transition: background-color 0.35s ease, background-image 0.35s ease, color 0.35s ease,
                border-color 0.35s ease, box-shadow 0.35s ease, fill 0.35s ease, stroke 0.35s ease !important;
    transition-delay: 0s !important;
}

/* ============================================================
   Dark mode polish — surfaces Bootstrap and Quill paint white by
   default, tinted to the site's navy so they read as designed
   rather than inverted.
   ============================================================ */
[data-theme="dark"] .dropdown-menu {
    background-color: var(--card-bg);
    border-color: var(--border-soft);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
[data-theme="dark"] .dropdown-item { color: var(--text-primary); }
[data-theme="dark"] .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:focus { background-color: var(--card-hover); color: var(--text-primary); }
[data-theme="dark"] .dropdown-divider { border-color: var(--border-soft); }
[data-theme="dark"] .list-group-item {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border-color: var(--border-soft);
}
[data-theme="dark"] .ql-snow .ql-tooltip {
    background: #14192D;
    color: #C8D2E0;
    border-color: var(--border-soft);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
[data-theme="dark"] .ql-snow .ql-tooltip input[type="text"] {
    background: #0E1426;
    color: #E8EEF6;
    border-color: var(--border-soft);
}
[data-theme="dark"] .ql-snow .ql-tooltip a { color: var(--primary-soft); }
[data-theme="dark"] .ql-snow .ql-picker-options {
    background: #14192D;
    border-color: var(--border-soft);
}
[data-theme="dark"] .ql-snow .ql-picker-item { color: #C8D2E0; }
[data-theme="dark"] .ql-snow .ql-picker-item:hover,
[data-theme="dark"] .ql-snow .ql-picker-item.ql-selected { color: var(--primary-soft); }
[data-theme="dark"] .ql-editor.ql-blank::before { color: rgba(200, 210, 224, 0.5); }

/* ============================================================
   SHARED COMPONENTS — the one standard version of each repeated
   piece. Old module class names are aliased here and their module
   copies are deleted as each page family migrates. dev.php shows
   every component in both themes.
   ============================================================ */

/* ---- Surfaces, bands, page hero, layout shell ---- */

/* Tokens for this group. Theme-specific values: the dark rule follows
   the light one, so it wins on a dark root and inside dev.php's dark
   column. --surface-frost is the frosted ground of the legacy static
   panels (quiz start/question/score, multiplayer, home about), which
   move to .surface-panel in their family phase. --elev-listing and
   --elev-listing-hover are the branded listing-card shadow pair: the
   old color-mix(--primary-soft) shadows written as plain rgba(), so
   they need no color-mix() fallback. */
:root,
[data-theme="light"] {
    --surface-frost: rgba(252, 253, 255, 0.92);
    --elev-listing: 0 4px 14px rgba(58, 111, 168, 0.1), 0 1px 3px rgba(40, 50, 75, 0.05);
    --elev-listing-hover: 0 18px 36px rgba(58, 111, 168, 0.18), 0 4px 10px rgba(40, 50, 75, 0.06);
}
[data-theme="dark"] {
    --surface-frost: rgba(4, 8, 18, 0.85);
    --elev-listing: 0 6px 18px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(90, 139, 196, 0.18);
    --elev-listing-hover: 0 14px 32px rgba(0, 0, 0, 0.55), 0 0 24px rgba(90, 139, 196, 0.26);
}
:root {
    --page-max-wide: 1600px;
    --page-max-reading: 880px;
}

/* ---------- Page shell ----------
   The page content column: --page-max wide (1400px) with the
   responsive gutter (2rem, 1rem at 768px). --narrow 1000px for
   study and quiz pages, --reading 880px for long prose (About,
   Privacy, Disclaimer, Search), --form 600px for single forms, --wide
   1600px for dense admin grids. Families swap .container for this
   as they migrate. A page on --reading gives its hero
   .page-hero--reading so the title lines up with the column. */
.page-shell {
    width: 100%;
    max-width: var(--page-max);
    margin-inline: auto;
    padding-inline: var(--page-gutter);
    padding-block: var(--space-8) var(--space-12);
}
.page-shell--narrow { max-width: var(--page-max-narrow); }
.page-shell--reading { max-width: var(--page-max-reading); }
.page-shell--form { max-width: var(--w-form); }
.page-shell--wide { max-width: var(--page-max-wide); }

@media (max-width: 768px) {
    .page-shell {
        padding-block: var(--space-6) var(--space-8);
    }
}

/* ---------- Page hero (.page-hero) ----------
   The full-bleed navy band under the navbar, the same in both themes,
   closed by a 3px brand-red cap. The H1 holds only the page or entity
   name with a 1em gold icon; any instruction goes in .page-hero-sub.
   .page-hero-actions takes .icon-btn--chrome or .btn-on-chrome only.
   .page-hero--compact is for the reader, quiz play and drill-downs;
   it hides at 960px, where the reader's own layout takes over.
   Emitted by renderPageHero().
   Aliases: .learn-hero / .learn-hero-inner / .learn-hero-text (with
   its h1 and p; resources/index.php still emits them). */
.page-hero,
.learn-hero {
    /* Capped at 1.9rem, not the 2.5rem --fs-page-title: hero titles
       still carry instruction sentences until each family moves them
       to the subtitle line. */
    --page-hero-title: clamp(1.4rem, 1.1rem + 1vw, 1.9rem);
    margin: 0;
    padding: 1.5rem var(--page-gutter);
    border-bottom: 3px solid var(--brand-red);
    background: var(--brand-hero);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text-on-fill);
}

.page-hero-inner,
.learn-hero-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    max-width: var(--page-max);
    margin: 0 auto;
}

/* Text column matched to .page-shell--reading's content edge. */
.page-hero--reading .page-hero-inner {
    max-width: calc(var(--page-max-reading) - 2 * var(--page-gutter));
}

.page-hero-text,
.learn-hero-text {
    flex: 1 1 20rem;
    min-width: 0;
}

.page-hero h1,
.learn-hero h1 {
    /* No wrap: a long title wraps inside its own text box beside the
       icon, instead of dropping below it and leaving the icon alone
       on the first line (phones). */
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
    color: var(--text-on-fill);
    font-size: var(--page-hero-title);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

/* Leading icon only (direct child): a badge inside the title keeps
   its own icon colour. */
.page-hero h1 > i,
.learn-hero h1 > i {
    flex: 0 0 auto;
    color: var(--brand-gold);
    font-size: 1em;
    line-height: 1;
}

.page-hero-sub,
.learn-hero-text > p {
    max-width: 70ch;
    margin: 0.4rem 0 0;
    color: var(--text-on-chrome-muted);
    font-size: var(--fs-lead);
    font-weight: 400;
    line-height: 1.5;
}

.page-hero-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

/* Compact: the reader / drill-down band. Title steps down; the
   description sits tight under it. */
.page-hero--compact {
    --page-hero-title: 1.5rem;
}

.page-hero--compact .page-hero-sub {
    margin-top: 0.25rem;
    font-size: var(--fs-body-sm);
}

/* The labelled hero action, .btn-on-chrome, is with the other button
   variants in the Buttons group below. */

@media (max-width: 960px) {
    .page-hero--compact {
        display: none;
    }
}

@media (max-width: 768px) {
    .page-hero,
    .learn-hero {
        padding: 1.25rem var(--page-gutter);
    }
}

@media print {
    .page-hero,
    .learn-hero {
        display: none !important;
    }
}

/* ---------- Band (.fl-band) ----------
   The navy strip that heads a framed surface: brand gradient (solid
   navy for card heads), 3px brand-red cap, white text, dark in both
   themes. Top corners are the surface radius minus its frame so they
   sit exactly inside the frame; .fl-band--flush squares them for a
   band inside a clipped tray. Two text treatments only:
     .fl-band          label band: 0.95rem / 800 / uppercase (group
                       trays, admin panel heads, tool sections)
     .fl-band--title   card head: a frosted title strip, sentence case
   Caps carry meaning: default red = reference, .is-cap-gold = input
   or treatment, .is-cap-success = complete, .is-cap-muted = note.
   Parts: .fl-band-title (grows), .fl-band-count (chip),
   .fl-band-chevron, .fl-band-actions (.icon-btn--chrome). A
   collapsible band is <button type="button" class="fl-band"
   aria-expanded aria-controls>. Focus is gold (chrome list above). */
.fl-band {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
    padding: 0.85rem 1.1rem;
    border: 0;
    border-bottom: 3px solid var(--brand-red);
    border-radius: calc(var(--r-lg) - var(--frame-w)) calc(var(--r-lg) - var(--frame-w)) 0 0;
    background: var(--brand-band);
    color: var(--text-on-fill);
    font-size: var(--fs-band-label);
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.fl-band > :is(h2, h3, h4, h5, h6) {
    margin: 0;
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    line-height: 1.3;
}

.fl-band-title {
    flex: 1 1 auto;
    min-width: 0;
}

.fl-band > i,
.fl-band > .ti,
.fl-band > :is(h2, h3, h4, h5, h6, .fl-band-title) > i,
.fl-band-chevron {
    flex: 0 0 auto;
    color: var(--brand-gold);
}

.fl-band-count {
    flex: 0 0 auto;
    padding: 0.15rem 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: var(--r-pill);
    background: rgba(255, 255, 255, 0.14);
    font-size: var(--fs-eyebrow);
    font-weight: 700;
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
}

.fl-band-chevron {
    font-size: 1.15rem;
    transition: transform var(--dur) ease;
}

.fl-band[aria-expanded="false"] .fl-band-chevron {
    transform: rotate(-90deg);
}

.fl-band-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: auto;
}

button.fl-band {
    width: 100%;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--dur) ease, filter var(--dur-fast) ease;
}

button.fl-band:hover {
    filter: brightness(1.25);
}

button.fl-band:where(:not(.is-cap-gold, .is-cap-success, .is-cap-muted)):hover {
    border-bottom-color: var(--brand-red-hover);
}

button.fl-band:focus-visible {
    outline: 2px solid var(--focus-color-chrome);
    outline-offset: -5px;
}

.fl-band.is-cap-gold { border-bottom-color: var(--brand-gold); }
.fl-band.is-cap-success { border-bottom-color: var(--success-fill); }
.fl-band.is-cap-muted { border-bottom-color: var(--brand-red-deep); }

.fl-band--flush {
    border-radius: 0;
}

/* Card-head treatment: solid navy field, centred frosted title strip
   (the .lib-card-head look). */
.fl-band--title {
    justify-content: center;
    min-height: 3.75rem;
    padding: 0.75rem;
    background: var(--brand-navy);
    font-size: var(--fs-band-title);
    font-weight: 700;
    letter-spacing: normal;
    text-transform: none;
}

.fl-band--title > :is(h2, h3, h4, h5, h6, .fl-band-title) {
    flex: 1 1 auto;
    max-width: 100%;
    margin: 0;
    padding: 0.5rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.13);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: inherit;
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    transition: background var(--dur) ease, border-color var(--dur) ease;
}

@media (max-width: 768px) {
    .fl-band--title {
        min-height: 3.4rem;
        padding: 0.6rem;
    }

    .fl-band--title > :is(h2, h3, h4, h5, h6, .fl-band-title) {
        padding: 0.45rem 0.85rem;
        font-size: 1.05rem;
    }
}

/* ---------- Listing surface (.surface-listing) ----------
   The tactile listing card: 3px frame (near-black light, steel dark),
   frosted glass, the branded shadow. Markup: a.surface-listing, or a
   div with one stretched link, opening with an .fl-band--title head.
   Hover and keyboard focus lift it, swap in the hover glass, frame
   and shadow, and brighten the band cap. Only links and cards not
   tagged .is-static react: .is-static is for shells, unlinked cards
   and whole-page containers. .is-locked greys out and never lifts.
   The module card classes (.category-card, .topic-card, ... and
   .lib-card) carry the same tokens in the rules above. */
.surface-listing {
    --listing-pad: var(--pad-card);
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: var(--listing-pad);
    border: var(--frame-w) solid var(--frame-listing);
    border-radius: var(--r-lg);
    background: var(--surface-glass);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: var(--elev-listing);
    color: inherit;
    text-decoration: none;
    transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) ease,
                border-color var(--dur) ease, background var(--dur) ease;
}

/* The head band pulls out to the frame edges. */
.surface-listing > .fl-band:first-child {
    margin: calc(var(--listing-pad) * -1) calc(var(--listing-pad) * -1) var(--space-5);
}

.surface-listing:where(a, :not(.is-static)):where(:not(.is-locked)):hover,
.surface-listing:where(a, :not(.is-static)):where(:not(.is-locked)):focus-visible,
.surface-listing:where(a, :not(.is-static)):where(:not(.is-locked)):focus-within {
    transform: translateY(var(--lift-card));
    border-color: var(--frame-listing-hover);
    background: var(--surface-glass-hover);
    box-shadow: var(--elev-listing-hover);
    color: inherit;
    text-decoration: none;
}

.surface-listing:where(a, :not(.is-static)):where(:not(.is-locked)):is(:hover, :focus-visible, :focus-within) > .fl-band {
    border-bottom-color: var(--brand-red-hover);
}

.surface-listing:where(a, :not(.is-static)):where(:not(.is-locked)):is(:hover, :focus-visible, :focus-within) > .fl-band--title > :is(h2, h3, h4, h5, h6, .fl-band-title) {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.32);
}

/* Keyboard focus: the outline 3px clear of the frame. A div card
   draws it only for keyboard focus inside it; that selector is its
   own rule so engines without :has() keep the first. A .lib-card
   keeps its own two-tone ring instead, so it never shows both. */
a.surface-listing:not(.lib-card):focus-visible {
    outline: var(--focus-outline);
    outline-offset: 3px;
}
.surface-listing:not(.lib-card):where(a, :not(.is-static)):has(:focus-visible) {
    outline: var(--focus-outline);
    outline-offset: 3px;
}

.surface-listing.is-locked {
    filter: grayscale(0.25);
    cursor: not-allowed;
}

/* ---------- Reading / form panel (.surface-panel) ----------
   The long-form surface: opaque card colour in both themes, the soft
   3px panel frame, resting elevation. No hover, lift or focus ring.
   .is-reading opens the padding up for prose. .has-band (always emit
   the class; :has() only enhances) switches to the listing frame and
   lets a leading .fl-band sit flush in the top of the frame. */
.surface-panel {
    --panel-pad: var(--pad-panel);
    padding: var(--panel-pad);
    border: var(--frame-w) solid var(--frame-panel);
    border-radius: var(--r-lg);
    background: var(--card-bg);
    box-shadow: var(--elev-1);
    color: var(--text-primary);
}

.surface-panel.is-reading {
    --panel-pad: var(--pad-reading);
}

.surface-panel.has-band {
    padding-top: 0;
    border-color: var(--frame-listing);
}
.surface-panel:has(> .fl-band:first-child) {
    padding-top: 0;
    border-color: var(--frame-listing);
}

.surface-panel > .fl-band:first-child {
    margin: 0 calc(var(--panel-pad) * -1) var(--space-5);
}

/* ---------- Inset row / tile (.surface-inset) ----------
   Rows and tiles inside a panel or section: the raised --surface-2
   ground with a hairline border. .surface-inset--card is for an inset
   that sits on --surface-2 itself. Clickable rows (a / button) tint
   on hover without moving. Selected rows (.is-selected or
   aria-pressed) take a 2px primary frame and a check; status rows a
   4px left rule in the status text colour. */
.surface-inset {
    padding: var(--pad-inset);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--text-primary);
}

.surface-inset--card {
    background: var(--card-bg);
}

a.surface-inset,
button.surface-inset {
    display: block;
    width: 100%;
    color: inherit;
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

a.surface-inset:hover,
button.surface-inset:hover {
    border-color: var(--primary-soft);
    background: var(--primary-tint);
    color: inherit;
}

/* The second border pixel is an inset shadow, so selecting a row
   doesn't shift its content. */
.surface-inset.is-selected,
.surface-inset[aria-pressed="true"] {
    position: relative;
    padding-right: 2.5rem;
    border-color: var(--primary-soft);
    background: var(--primary-tint);
    box-shadow: inset 0 0 0 1px var(--primary-soft);
}

.surface-inset.is-selected::after,
.surface-inset[aria-pressed="true"]::after {
    content: '\ea5e'; /* ti-check */
    content: '\ea5e' / '';
    position: absolute;
    top: 50%;
    right: 0.85rem;
    transform: translateY(-50%);
    color: var(--primary-text);
    font-family: 'tabler-icons';
    font-size: 1.1rem;
    line-height: 1;
}

.surface-inset.is-success { border-left: 4px solid var(--success-text); }
.surface-inset.is-warning { border-left: 4px solid var(--warning-text); }
.surface-inset.is-danger { border-left: 4px solid var(--danger-text); }
.surface-inset.is-info { border-left: 4px solid var(--info-text); }

/* ---- Buttons, back link, tabs, pills, selected states,
        empty state, tiles, headings, utilities ---- */
/* ---------- Tokens for this group ----------
   Plain per-theme values only. The tab tint ratios differ by theme
   (dark tabs need a stronger tint to read as buttons); the switch knob
   is an image, so each theme names its own colour. Every color-mix()
   below sits in an @supports block, so an engine without it keeps the
   solid token from the base rule. */
:root,
[data-theme="light"] {
    --seg-tab-mix: 6%;
    --seg-tab-mix-hover: 14%;
    --seg-tab-edge-mix: 18%;
    --seg-tab-edge-mix-hover: 45%;
    --switch-knob: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%237D8DA6'/%3e%3c/svg%3e");
}

[data-theme="dark"] {
    --seg-tab-mix: 22%;
    --seg-tab-mix-hover: 32%;
    --seg-tab-edge-mix: 40%;
    --seg-tab-edge-mix-hover: 60%;
    --switch-knob: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%236B7A96'/%3e%3c/svg%3e");
}

/* ---------- Quiet buttons ----------
   Bootstrap variants, so use them with .btn:
   .btn.btn-ghost         tertiary toolbar actions, "Show more": no
                          frame, link-blue label, tint on hover.
   .btn.btn-quiet-danger  row-level destructive actions (Move to trash,
                          Remove, End quiz): the danger tint at rest. Its
                          tone tokens come from the outline-tone rules in
                          the Bootstrap bridge. The final confirm in a
                          dialog stays .btn-danger.
   .btn.btn-on-chrome     a light-on-navy action on a hero or band. */
.btn-ghost {
    --bs-btn-color: var(--primary-text);
    --bs-btn-bg: transparent;
    --bs-btn-border-color: transparent;
    --bs-btn-hover-color: var(--primary-text);
    --bs-btn-hover-bg: var(--primary-tint);
    --bs-btn-hover-border-color: transparent;
    --bs-btn-active-color: var(--primary-text);
    --bs-btn-active-bg: var(--primary-tint);
    --bs-btn-active-border-color: transparent;
    --bs-btn-disabled-color: var(--primary-text);
    --bs-btn-disabled-bg: transparent;
    --bs-btn-disabled-border-color: transparent;
}

.btn-quiet-danger {
    --bs-btn-bg: var(--danger-tint);
    --bs-btn-hover-border-color: var(--danger-text);
    --bs-btn-active-border-color: var(--danger-text);
    --bs-btn-disabled-bg: var(--danger-tint);
}

/* 18% keeps the label at 4.5:1 or better in light mode (20% does not). */
@supports (color: color-mix(in srgb, red 50%, blue)) {
    .btn-quiet-danger {
        --bs-btn-hover-bg: color-mix(in srgb, var(--danger-text) 18%, var(--card-bg));
        --bs-btn-active-bg: color-mix(in srgb, var(--danger-text) 18%, var(--card-bg));
    }
}

.btn-on-chrome {
    --bs-btn-color: #fff;
    --bs-btn-bg: rgba(255, 255, 255, 0.14);
    --bs-btn-border-color: rgba(255, 255, 255, 0.25);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: rgba(255, 255, 255, 0.24);
    --bs-btn-hover-border-color: rgba(255, 255, 255, 0.4);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: rgba(255, 255, 255, 0.24);
    --bs-btn-active-border-color: rgba(255, 255, 255, 0.4);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: rgba(255, 255, 255, 0.14);
    --bs-btn-disabled-border-color: rgba(255, 255, 255, 0.25);
    --focus-color: var(--focus-color-chrome);
    --focus-outline: 2px solid var(--focus-color-chrome);
}

/* ---------- Pill button and back link ----------
   .pill-btn: page-level utility actions (Print, Offline app, Collapse
   all, Reset filters). .page-back: the back link, the first thing
   under the hero on every non-top-level page (pageBack() emits it):
     <a class="page-back" href="..."><i class="ti ti-arrow-left"
        aria-hidden="true"></i> Back to {Parent}</a>
   Only its icon nudges on hover. Aliases: .lib-toggle-all (pill);
   .learn-back-btn (back link). */
.pill-btn,
.lib-toggle-all,
.page-back,
.learn-back-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--gap-icon);
    min-height: var(--control-h);
    padding: 0.45rem 0.95rem;
    border: 1.5px solid var(--border-medium);
    border-radius: var(--r-pill);
    background: var(--primary-tint);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: 600;
    line-height: 1.4;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out);
}

.pill-btn:hover,
.lib-toggle-all:hover,
.page-back:hover,
.learn-back-btn:hover {
    border-color: var(--primary-soft);
    color: var(--text-primary);
    text-decoration: none;
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
    .pill-btn,
    .lib-toggle-all,
    .page-back,
    .learn-back-btn {
        background: color-mix(in srgb, var(--primary-soft) 8%, var(--card-bg));
        border-color: color-mix(in srgb, var(--primary-soft) 25%, var(--border-soft));
    }

    .pill-btn:hover,
    .lib-toggle-all:hover,
    .page-back:hover,
    .learn-back-btn:hover {
        background: color-mix(in srgb, var(--primary-soft) 16%, var(--card-bg));
        border-color: var(--primary-soft);
    }
}

.pill-btn,
.lib-toggle-all {
    flex: 0 0 auto;
}

.pill-btn i,
.lib-toggle-all i,
.page-back i,
.learn-back-btn i {
    font-size: 1rem;
    flex-shrink: 0;
    transition: transform var(--dur-fast) var(--ease-out);
}

.page-back,
.learn-back-btn {
    margin-bottom: 1.25rem;
}

@media (prefers-reduced-motion: no-preference) {
    .page-back:hover i,
    .learn-back-btn:hover i {
        transform: translateX(-2px);
    }
}

/* Phones: a little air under the hero and a larger tap target. */
@media (max-width: 768px) {
    .page-back,
    .learn-back-btn {
        margin-top: 0.75rem;
        margin-bottom: 1rem;
        padding: 0.55rem 1.1rem;
        font-size: 0.92rem;
    }
}

@media print {
    .page-back,
    .learn-back-btn {
        display: none !important;
    }
}

/* ---------- Icon button and modal close ----------
   A square, frameless button holding one Tabler glyph:
     <button type="button" class="icon-btn" aria-label="Delete group">
       <i class="ti ti-trash" aria-hidden="true"></i></button>
   The accessible name (aria-label or visually hidden text) is
   required. 40px, 44px on touch screens (--control-h); Tools sets
   --icon-btn-size to 44px. --outlined adds the neutral surface
   (steppers); --chrome is for navy bands, heroes and the sim stage.
   .modal-close is the same button for every custom modal, sheet,
   popover and lightbox: ti-x with aria-label="Close". */
.icon-btn,
.modal-close {
    --icon-btn-size: var(--control-h);
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    width: var(--icon-btn-size);
    height: var(--icon-btn-size);
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 1.15rem;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out);
}

.icon-btn i,
.icon-btn .ti,
.modal-close i,
.modal-close .ti {
    font-size: 1em;
    line-height: 1;
}

.icon-btn:hover,
.modal-close:hover {
    background: var(--surface-2);
    color: var(--text-primary);
    text-decoration: none;
}

.icon-btn:disabled,
.icon-btn[aria-disabled="true"],
.modal-close:disabled {
    opacity: 0.5;
    pointer-events: none;
}

.icon-btn--outlined {
    background: var(--neutral-tint);
    border-color: var(--border-medium);
    color: var(--text-primary);
}

.icon-btn--outlined:hover {
    background: var(--neutral-tint);
    border-color: var(--primary-text);
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
    .icon-btn--outlined:hover {
        background: color-mix(in srgb, var(--text-primary) 14%, var(--card-bg));
    }
}

/* On navy chrome (both themes): white glyph, white-alpha hover, gold
   focus. A close button on a branded modal head or a band takes the
   same look without the extra class. */
.icon-btn--chrome,
.fl-band .modal-close,
.tool-modal .modal-header .modal-close {
    --focus-color: var(--focus-color-chrome);
    --focus-outline: 2px solid var(--focus-color-chrome);
    color: #fff;
}

.icon-btn--chrome:hover,
.fl-band .modal-close:hover,
.tool-modal .modal-header .modal-close:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

/* Bootstrap modal head: the same pull into the corner as .btn-close. */
.modal-header .modal-close {
    margin: calc(-0.5 * var(--bs-modal-header-padding-y, 1rem)) calc(-0.5 * var(--bs-modal-header-padding-x, 1rem)) calc(-0.5 * var(--bs-modal-header-padding-y, 1rem)) auto;
}

/* ---------- Form actions ----------
   The button row at the end of a form or dialog: [secondary][primary],
   right-aligned. A destructive action placed first sits apart at the
   far start. */
.form-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: var(--space-6);
}

.form-actions > .btn-danger:first-child,
.form-actions > .btn-quiet-danger:first-child,
.form-actions > .btn-outline-danger:first-child {
    margin-right: auto;
}

/* TEMPORARY: admin/styles.css has its own .form-actions with the old
   [Save][Cancel] order from the left. It keeps that layout until the
   admin family moves to [secondary][primary] and deletes its copy
   (and this rule). */
.admin-container .form-actions {
    flex-wrap: nowrap;
    justify-content: flex-start;
}

/* ---------- Search field (.search-field) ----------
   The pill-shaped search box: the form-field well and frame
   (--input-bg, 2px --border-strong) with a leading search glyph.
     <div class="search-field [search-field--lg]">
       <label for="q" class="visually-hidden">Search ...</label>
       <i class="ti ti-search search-field-icon" aria-hidden="true"></i>
       <input type="search" id="q" class="search-field-input" ...>
     </div>
   44px tall; --lg (the /search/ page) is 52px at --fs-lead. Hover
   and focus match .form-control. The navbar's chrome variant is not
   built yet (navbar.css keeps its own). */
.search-field {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.search-field-icon {
    position: absolute;
    top: 50%;
    left: 1rem;
    transform: translateY(-50%);
    font-size: 1.15rem;
    line-height: 1;
    color: var(--text-muted);
    pointer-events: none;
}

.search-field-input {
    width: 100%;
    min-height: 2.75rem; /* 44px */
    padding: 0.5rem 1rem 0.5rem 2.6rem;
    border: 2px solid var(--border-strong);
    border-radius: var(--r-pill);
    background-color: var(--input-bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--fs-body);
    line-height: 1.4;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

/* Safari's search inset would push the text past the glyph. */
.search-field-input::-webkit-search-decoration {
    -webkit-appearance: none;
}

.search-field-input:hover {
    border-color: var(--primary-text);
}

/* The ring is a shadow; the transparent outline still shows in
   forced-colours mode. */
.search-field-input:focus {
    outline: 2px solid transparent;
    border-color: var(--focus-color);
    box-shadow: var(--focus-ring);
}

.search-field-input:disabled {
    background-color: var(--neutral-bg);
    border-color: var(--border-strong);
    color: var(--text-muted);
}

.search-field--lg .search-field-icon {
    left: 1.15rem;
    font-size: 1.4rem;
}

.search-field--lg .search-field-input {
    min-height: 3.25rem; /* 52px */
    padding: 0.6rem 1.25rem 0.6rem 3.1rem;
    font-size: var(--fs-lead);
}

/* ---------- Tabs (.seg-tab) ----------
   Markup: <div class="seg-tabs" role="tablist" aria-label="..."> with
   <button|a class="seg-tab" role="tab" aria-selected aria-controls>
   children (roving tabindex; Left/Right/Home/End). The selected tab is
   .is-active or [aria-selected="true"] (.active / aria-current="page"
   for link rows) on the primary fill, white label at 5.2:1 or better
   in both themes. :focus is never styled like the active tab; keyboard
   focus is the site ring. Rows wrap; .seg-tabs--scroll makes one
   horizontally scrolling row at 600px and below. Aliases: .lib-tabs /
   .lib-tab / .lib-tab-count. */
.seg-tabs,
.lib-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 0.25rem 0 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-soft);
}

.seg-tab,
.lib-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 44px;
    padding: 0.85rem 1.6rem;
    border: 1.5px solid var(--border-medium);
    border-radius: var(--r-md);
    background: var(--primary-tint);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.005em;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--elev-1);
    transition: background-color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-out);
}

.seg-tab i,
.lib-tab i {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.seg-tab:hover,
.lib-tab:hover {
    border-color: var(--primary-soft);
    color: var(--text-primary);
    text-decoration: none;
    box-shadow: var(--elev-2);
}

.seg-tab-count,
.lib-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.9rem;
    height: 1.7rem;
    padding: 0 0.55rem;
    border-radius: var(--r-pill);
    background: var(--primary-tint);
    color: var(--primary-text);
    font-size: 0.85rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
    .seg-tab,
    .lib-tab {
        background: color-mix(in srgb, var(--primary-soft) var(--seg-tab-mix), var(--card-bg));
        border-color: color-mix(in srgb, var(--primary-soft) var(--seg-tab-edge-mix), var(--border-soft));
    }

    .seg-tab:hover,
    .lib-tab:hover {
        background: color-mix(in srgb, var(--primary-soft) var(--seg-tab-mix-hover), var(--card-bg));
        border-color: color-mix(in srgb, var(--primary-soft) var(--seg-tab-edge-mix-hover), var(--card-bg));
    }

    .seg-tab-count,
    .lib-tab-count {
        background: color-mix(in srgb, var(--primary-soft) 18%, transparent);
    }
}

.seg-tab.is-active,
.seg-tab.active,
.seg-tab[aria-selected="true"],
.seg-tab[aria-current="page"],
.lib-tab.is-active,
.lib-tab[aria-selected="true"] {
    border-color: var(--primary-fill-hover);
    background: linear-gradient(135deg, var(--primary-fill) 0%, var(--primary-fill-hover) 100%);
    color: var(--text-on-fill);
    box-shadow: var(--elev-2);
}

.seg-tab.is-active .seg-tab-count,
.seg-tab.active .seg-tab-count,
.seg-tab[aria-selected="true"] .seg-tab-count,
.seg-tab[aria-current="page"] .seg-tab-count,
.lib-tab.is-active .lib-tab-count,
/* A darker chip on the filled tab: white on a white-tinted chip measured
   3.39:1; on 22% black over --primary-fill it is about 7:1. */
.lib-tab[aria-selected="true"] .lib-tab-count {
    background: rgba(0, 0, 0, 0.22);
    color: #fff;
}

/* Hover lift, and the raised selected tab, only when motion is fine. */
@media (prefers-reduced-motion: no-preference) {
    .seg-tab:hover,
    .lib-tab:hover,
    .seg-tab.is-active,
    .seg-tab.active,
    .seg-tab[aria-selected="true"],
    .seg-tab[aria-current="page"],
    .lib-tab.is-active,
    .lib-tab[aria-selected="true"] {
        transform: translateY(-2px);
    }
}

@media (max-width: 600px) {
    .seg-tab,
    .lib-tab {
        gap: 0.55rem;
        padding: 0.7rem 1.15rem;
        font-size: 1rem;
    }

    .seg-tab i,
    .lib-tab i {
        font-size: 1.25rem;
    }

    .seg-tabs--scroll {
        flex-wrap: nowrap;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        scrollbar-width: thin;
        /* Room for the focus ring and the raised tab inside the clip. */
        padding: 0.35rem 0.15rem 1rem;
    }

    .seg-tabs--scroll > .seg-tab {
        flex: 0 0 auto;
        scroll-snap-align: start;
    }
}

/* Rail: the admin tab strip. A navy band in both themes; the selected
   tab is the darkest navy with a red underline; gold focus. Sticks
   0.5rem below the top of the viewport (--sticky-offset adds a sticky
   header's height if the navbar ever becomes sticky). z-index stays
   under the navbar header (1000) so its menus open over the rail.
   One horizontally scrolling row at 768px and below, not sticky. */
.seg-tabs--rail {
    --focus-color: var(--focus-color-chrome);
    --focus-outline: 2px solid var(--focus-color-chrome);
    --focus-ring: 0 0 0 2px var(--brand-navy), 0 0 0 4px var(--focus-color-chrome);
    position: sticky;
    top: calc(var(--sticky-offset, 0px) + 0.5rem);
    z-index: 30;
    gap: 0.5rem;
    padding: 0.5rem;
    border: 0;
    border-radius: var(--r-lg);
    background: var(--brand-band);
    box-shadow: var(--elev-2);
}

.seg-tabs--rail .seg-tab {
    gap: 0.5rem;
    min-height: var(--control-h);
    padding: 0.6rem 1.2rem;
    border-color: transparent;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-on-chrome-muted);
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: none;
}

.seg-tabs--rail .seg-tab i {
    font-size: 1.1rem;
}

.seg-tabs--rail .seg-tab:hover {
    border-color: transparent;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    box-shadow: none;
}

.seg-tabs--rail .seg-tab.is-active,
.seg-tabs--rail .seg-tab.active,
.seg-tabs--rail .seg-tab[aria-selected="true"],
.seg-tabs--rail .seg-tab[aria-current="page"] {
    border-color: rgba(255, 255, 255, 0.22);
    background: var(--brand-navy);
    color: #fff;
    box-shadow: inset 0 -3px 0 var(--brand-red);
}

.seg-tabs--rail .seg-tab .seg-tab-count {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

@media (prefers-reduced-motion: no-preference) {
    .seg-tabs--rail .seg-tab:hover,
    .seg-tabs--rail .seg-tab.is-active,
    .seg-tabs--rail .seg-tab.active,
    .seg-tabs--rail .seg-tab[aria-selected="true"],
    .seg-tabs--rail .seg-tab[aria-current="page"] {
        transform: none;
    }
}

@media (max-width: 768px) {
    .seg-tabs--rail {
        position: static;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .seg-tabs--rail .seg-tab {
        flex: 0 0 auto;
    }
}

@media (max-width: 600px) {
    .seg-tabs--rail .seg-tab {
        padding: 0.5rem 0.9rem;
        font-size: 0.85rem;
    }
}

/* ---------- Filter pills (.seg-pill) ----------
   <div class="seg-pills" role="group" aria-label="..."> holding
   <button type="button" class="seg-pill" aria-pressed="false"> filters
   (or links with aria-current). Each pill may set its own
   --pill-color (an event or status token) for its icon, hover tint and
   selected frame. Selected: .is-active, aria-pressed="true" or
   aria-current, with a leading ti-check. Wraps on wide screens; one
   horizontally scrolling row at 600px and below. */
.seg-pills {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.seg-pill {
    --pill-color: var(--primary-text);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: var(--control-h);
    padding: 0.5rem 1rem;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--r-pill);
    background: var(--card-bg);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out);
}

.seg-pill i {
    font-size: 1.1em;
    color: var(--pill-color);
}

.seg-pill:hover {
    background: var(--surface-2);
    color: var(--text-primary);
    text-decoration: none;
}

.seg-pill.is-active,
.seg-pill[aria-pressed="true"],
.seg-pill[aria-current="page"],
.seg-pill[aria-current="true"] {
    border-color: var(--pill-color);
    background: var(--surface-2);
    color: var(--text-primary);
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
    .seg-pill:hover {
        background: color-mix(in srgb, var(--pill-color) 10%, var(--card-bg));
    }

    .seg-pill.is-active,
    .seg-pill[aria-pressed="true"],
    .seg-pill[aria-current="page"],
    .seg-pill[aria-current="true"] {
        background: color-mix(in srgb, var(--pill-color) 22%, var(--card-bg));
    }
}

@media (max-width: 600px) {
    .seg-pills {
        flex-wrap: nowrap;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        scrollbar-width: thin;
        scrollbar-color: var(--border-strong) transparent;
        /* Room for the focus ring (2px + offset) inside the scroll clip,
           on the sides too: snapping parks the first pill at the edge. */
        padding: 0.25rem 0.35rem 0.5rem;
        scroll-padding-inline: 0.35rem;
    }

    .seg-pills > .seg-pill {
        flex: 0 0 auto;
        scroll-snap-align: start;
    }
}

/* ---------- Selected state: check glyph, gold ring ----------
   The selected paint itself (navy --selected-bg, white label, or the
   status fill on a meaning-bearing group) is in the Bootstrap bridge
   ("Segmented toggles"). This adds the ti-check that says "selected"
   without colour: on .btn.is-selected, .btn[aria-pressed="true"],
   active .seg-pill and selected .choice-tile always, and on
   .btn-check groups that opt in with .has-check (on the group or the
   label), so the existing calculator toggles (NIHSS, GCS, ...) don't
   reflow until their family migrates. .is-gold-ring marks an alternate
   or pediatric mode with a 1.5px gold frame. */
.btn.is-selected::before,
.btn[aria-pressed="true"]::before,
.has-check .btn-check:checked + .btn::before,
.btn-check:checked + .btn.has-check::before,
.seg-pill.is-active::before,
.seg-pill[aria-pressed="true"]::before,
.seg-pill[aria-current="page"]::before,
.seg-pill[aria-current="true"]::before,
.choice-tile.is-selected::after,
input:checked + .choice-tile::after {
    content: "\ea5e";
    content: "\ea5e" / "";
    flex-shrink: 0;
    font-family: 'tabler-icons';
    font-size: 1.1em;
    font-style: normal;
    font-weight: 400;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
}

.btn-check:checked + .btn.is-gold-ring,
.btn.is-selected.is-gold-ring,
.btn[aria-pressed="true"].is-gold-ring {
    --bs-btn-active-border-color: var(--brand-gold);
    box-shadow: inset 0 0 0 0.5px var(--brand-gold);
}

/* ---------- Choice tile ----------
   A big tappable option that keeps the real input (screen readers,
   arrow keys, form posts) and hides it visually. Two markups:
     <label class="choice-tile"><input type="radio" name="q" value="a">
       <span>Answer text</span></label>
     <input type="radio" class="btn-check" id="q-a" name="q">
     <label class="choice-tile" for="q-a">Answer text</label>
   Group the tiles in <fieldset><legend>. The nested form reads its
   checked and focus states with :has(); where :has() is missing,
   script adds .is-selected, and focus falls back to :focus-within
   (also drawn for a mouse click there). */
.choice-tile {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--control-h);
    padding: var(--pad-inset);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--r-md);
    background: var(--card-bg);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out);
}

.choice-tile > input[type="radio"],
.choice-tile > input[type="checkbox"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.choice-tile:hover {
    border-color: var(--primary-text);
    background: var(--primary-tint);
}

.choice-tile.is-selected,
input:checked + .choice-tile {
    border-color: var(--primary-fill);
    background: var(--primary-tint);
}

.choice-tile:has(> input:checked) {
    border-color: var(--primary-fill);
    background: var(--primary-tint);
}

.choice-tile:has(> input:checked)::after {
    content: "\ea5e";
    content: "\ea5e" / "";
    flex-shrink: 0;
    font-family: 'tabler-icons';
    font-size: 1.1em;
    font-style: normal;
    font-weight: 400;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
}

.choice-tile::after {
    margin-left: auto;
    color: var(--primary-text);
}

.choice-tile.is-gold-ring.is-selected,
input:checked + .choice-tile.is-gold-ring {
    border-color: var(--brand-gold);
}

.choice-tile.is-gold-ring:has(> input:checked) {
    border-color: var(--brand-gold);
}

/* Focus: the two-tone ring. :focus-within and :focus are the fallbacks;
   where :focus-visible and :has() exist, a mouse click draws none. Each
   selector that needs a newer engine sits in its own rule, so an engine
   without it drops only that rule. */
.choice-tile:focus-within,
input:focus + .choice-tile {
    box-shadow: var(--focus-ring);
}

input:focus:not(:focus-visible) + .choice-tile {
    box-shadow: none;
}

.choice-tile:has(> input:focus:not(:focus-visible)) {
    box-shadow: none;
}

input:focus-visible + .choice-tile {
    box-shadow: var(--focus-ring);
}

.choice-tile:has(> input:focus-visible) {
    box-shadow: var(--focus-ring);
}

.choice-tile.is-disabled,
input:disabled + .choice-tile {
    opacity: 0.55;
    cursor: not-allowed;
}

.choice-tile:has(> input:disabled) {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ---------- Checks and switches (tokens) ----------
   Bootstrap's indeterminate box and its switch knobs are fixed blues
   and a black-alpha knob that vanishes on the dark well. */
.form-check-input[type="checkbox"]:indeterminate {
    background-color: var(--primary-fill);
    border-color: var(--primary-fill);
}

.form-switch .form-check-input,
.form-switch .form-check-input:focus {
    --bs-form-switch-bg: var(--switch-knob);
}

/* Switches keep Bootstrap's 2em x 1em track; only checks and radios
   grow to 1.15em. */
.form-switch .form-check-input {
    height: 1em;
    margin-top: 0.25em;
}

.form-switch .form-check-input:checked {
    --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e");
}

/* ---------- Stat tile ----------
   A big-number readout: value first, label below it.
     <div class="stat-tile"><div class="stat-value num">12 mg</div>
       <div class="stat-label">Loading dose</div></div>
   .stat-value tones (.is-success / -warning / -danger / -accent) pair
   with a word. --sm for summary strips, --lg for a calculator's single
   primary result. .stat-strip lays tiles out in an even row. A live
   result region carries role="status" aria-live="polite". */
.stat-tile {
    height: 100%;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    background: var(--surface-2);
    text-align: center;
}

.stat-value {
    display: block;
    font-size: var(--fs-stat);
    font-weight: 800;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.stat-value.is-success {
    color: var(--success-text);
}

.stat-value.is-warning {
    color: var(--warning-text);
}

.stat-value.is-danger {
    color: var(--danger-text);
}

.stat-value.is-accent {
    color: var(--primary-text);
}

.stat-label {
    display: block;
    margin-top: 0.25rem;
    font-size: var(--fs-eyebrow);
    font-weight: 700;
    letter-spacing: var(--ls-eyebrow);
    line-height: 1.3;
    text-transform: uppercase;
    color: var(--text-muted);
}

.stat-tile--sm {
    padding: 0.75rem 1rem;
}

.stat-tile--sm .stat-value {
    font-size: var(--fs-stat-sm);
}

.stat-tile--lg .stat-value {
    font-size: 2.6rem;
}

.stat-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr));
    gap: 0.75rem;
}

/* ---------- Icon tile ----------
   A square tinted tile behind a section or tool glyph (3.5rem; --lg
   for listing cards, --sm for rows). --brand is the navy tile of tool
   page titles and admin subview heads. Status tones: .is-success,
   .is-warning, .is-danger, .is-info. The glyph is aria-hidden. */
.icon-tile {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: var(--r-md);
    background: var(--primary-tint);
    color: var(--primary-text);
    font-size: 1.6rem;
    line-height: 1;
}

.icon-tile > i,
.icon-tile > .ti {
    font-size: 1em;
    line-height: 1;
}

.icon-tile--lg {
    width: 4.375rem;
    height: 4.375rem;
    font-size: 2rem;
}

.icon-tile--sm {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.25rem;
}

.icon-tile--brand {
    border: 1px solid rgba(146, 43, 32, 0.35);
    background: linear-gradient(135deg, var(--brand-navy) 0%, var(--brand-navy-3) 100%);
    color: #fff;
}

.icon-tile.is-success { background: var(--success-tint); color: var(--success-text); }
.icon-tile.is-warning { background: var(--warning-tint); color: var(--warning-text); }
.icon-tile.is-danger  { background: var(--danger-tint);  color: var(--danger-text); }
.icon-tile.is-info    { background: var(--info-tint);    color: var(--info-text); }

/* ---------- Section head ----------
   A section's title row: the title (h2.section-title) and an optional
   p.section-desc on the left, a .section-actions slot on the right.
     <div class="section-head"><div><h2 class="section-title">...</h2>
       <p class="section-desc">...</p></div>
       <div class="section-actions">...</div></div> */
.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 1rem;
}

.section-head .section-title {
    margin: 0;
}

.section-desc {
    max-width: 70ch;
    margin: 0.35rem 0 0;
    font-size: var(--fs-body-sm);
    line-height: 1.5;
    color: var(--text-secondary);
}

.section-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

/* ---------- Utilities ---------- */
/* Small uppercase label over a value or a group. */
.eyebrow,
.eyebrow-lg {
    font-size: var(--fs-eyebrow);
    font-weight: 700;
    letter-spacing: var(--ls-eyebrow);
    line-height: 1.3;
    text-transform: uppercase;
    color: var(--text-muted);
}

.eyebrow-lg {
    font-size: var(--fs-xs);
}

.eyebrow.on-chrome,
.eyebrow-lg.on-chrome,
.page-hero .eyebrow,
.learn-hero .eyebrow,
.fl-band .eyebrow {
    color: var(--text-on-chrome-muted);
}

/* Numbers that line up in columns and don't jitter as they change. */
.num {
    font-variant-numeric: tabular-nums;
}

/* An explicit text link: underlined, the text-safe blue, and a heavier
   underline in the text colour on hover. Never turns green. */
.text-link {
    color: var(--primary-text);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.text-link:hover {
    color: var(--primary-text);
    text-decoration: underline;
    text-decoration-color: var(--text-primary);
    text-decoration-thickness: 2px;
}

/* ---- Status pills, progress, alerts, toasts, modals ---- */
/* ------------------------------------------------------------
   Status pill / badge / chip
   <span class="status-pill is-success"><i class="ti ti-check"
   aria-hidden="true"></i> Complete</span>. Always icon plus word.
   One colour hook, --pill-color: the tones set it to a status text
   token; a custom pill sets it inline (style="--pill-color: ...")
   on an untoned pill. The tint (12%) and border (35%) mix from it
   over the card; engines without color-mix() get the matching
   solid tint/border tokens instead. Admin's old .is-on / .is-off /
   .is-bad toggles alias success / warning / danger.
   ------------------------------------------------------------ */
.status-pill {
    --pill-color: var(--text-muted);
    --pill-bg: var(--surface-2);
    --pill-border: var(--border-medium);
    --pill-fill: var(--neutral-fill);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--pill-border);
    border-radius: var(--r-pill);
    background: var(--pill-bg);
    color: var(--pill-color);
    font-family: inherit;
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: normal;
    text-decoration: none;
    white-space: nowrap;
    vertical-align: middle;
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
    .status-pill {
        --pill-bg: color-mix(in srgb, var(--pill-color) 12%, var(--card-bg));
        --pill-border: color-mix(in srgb, var(--pill-color) 35%, var(--card-bg));
    }
}

.status-pill > .ti {
    flex: none;
    font-size: 1.1em;
    line-height: 1;
}

.status-pill.is-success,
.status-pill.is-on {
    --pill-color: var(--success-text);
    --pill-fill: var(--success-fill);
}
.status-pill.is-warning,
.status-pill.is-off {
    --pill-color: var(--warning-text);
    --pill-fill: var(--warning-fill);
}
.status-pill.is-danger,
.status-pill.is-bad {
    --pill-color: var(--danger-text);
    --pill-fill: var(--danger-fill);
}
.status-pill.is-info {
    --pill-color: var(--info-text);
    --pill-fill: var(--info-fill);
}
.status-pill.is-muted {
    --pill-color: var(--text-muted);
    --pill-bg: var(--surface-2);
    --pill-fill: var(--neutral-fill);
}
.status-pill.is-brand {
    --pill-color: var(--primary-text);
    --pill-fill: var(--primary-fill);
}
.status-pill.is-ce {
    --pill-color: var(--ce-text);
    --pill-bg: var(--ce-tint);
}

/* Solid tints for engines without color-mix(). */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
    .status-pill.is-success,
    .status-pill.is-on {
        --pill-bg: var(--success-tint);
        --pill-border: var(--success-border);
    }
    .status-pill.is-warning,
    .status-pill.is-off {
        --pill-bg: var(--warning-tint);
        --pill-border: var(--warning-border);
    }
    .status-pill.is-danger,
    .status-pill.is-bad {
        --pill-bg: var(--danger-tint);
        --pill-border: var(--danger-border);
    }
    .status-pill.is-info {
        --pill-bg: var(--info-tint);
        --pill-border: var(--info-border);
    }
    .status-pill.is-brand {
        --pill-bg: var(--primary-tint);
    }
}

/* Modifiers */
.status-pill.is-caps {
    font-size: var(--fs-eyebrow);
    letter-spacing: var(--ls-eyebrow);
    text-transform: uppercase;
}
.status-pill.is-square {
    border-radius: var(--r-xs);
}
.status-pill.is-solid {
    border-color: var(--pill-fill);
    background: var(--pill-fill);
    color: var(--text-on-fill);
}
/* The CE gold has no white-label fill; it carries dark text. */
.status-pill.is-ce.is-solid {
    border-color: var(--brand-gold);
    background: var(--brand-gold);
    color: var(--text-on-bright);
}
.status-pill.on-chrome {
    --pill-color: #fff;
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

/* A pill that is also a control (admin Published/Draft toggles). */
button.status-pill,
a.status-pill {
    cursor: pointer;
    transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
button.status-pill:hover,
a.status-pill:hover {
    border-color: var(--pill-color);
    color: var(--pill-color);
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
    button.status-pill:hover,
    a.status-pill:hover {
        --pill-bg: color-mix(in srgb, var(--pill-color) 22%, var(--card-bg));
    }
}
button.status-pill.is-solid:hover,
a.status-pill.is-solid:hover {
    color: var(--text-on-fill);
}
button.status-pill.is-ce.is-solid:hover,
a.status-pill.is-ce.is-solid:hover {
    color: var(--text-on-bright);
}

/* ------------------------------------------------------------
   Progress bar
   <div class="fl-progress" role="progressbar" aria-valuenow="40"
   aria-valuemin="0" aria-valuemax="100"><div class="fl-progress-bar"
   style="width:40%"></div></div>. Pair it with a visible number:
   wrap both in .fl-progress-row with a .fl-progress-value.
   ------------------------------------------------------------ */
.fl-progress {
    --progress-fill: var(--primary-text);
    display: block;
    width: 100%;
    height: 8px;
    overflow: hidden;
    border-radius: var(--r-pill);
    background: var(--neutral-bg);
    box-shadow: inset 0 0 0 1px var(--border-soft);
}
.fl-progress--compact {
    height: 5px;
}
.fl-progress-bar {
    display: block;
    width: 0;
    max-width: 100%;
    height: 100%;
    border-radius: inherit;
    background: var(--progress-fill);
    transition: width var(--dur) var(--ease-out);
}
.fl-progress.is-complete,
.fl-progress.is-success {
    --progress-fill: var(--success-fill);
}
.fl-progress.is-warning {
    --progress-fill: var(--warning-text);
}
.fl-progress.is-danger {
    --progress-fill: var(--danger-text);
}

.fl-progress-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.fl-progress-row > .fl-progress {
    flex: 1 1 auto;
    min-width: 0;
}
.fl-progress-value {
    flex: none;
    min-width: 3.5ch;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

@media (forced-colors: active) {
    .fl-progress {
        border: 1px solid CanvasText;
    }
    .fl-progress-bar {
        forced-color-adjust: none;
        background: Highlight;
    }
}

/* ------------------------------------------------------------
   Alert
   Bootstrap .alert re-skinned on the status tint/border pairs.
   Body text is --text-primary on every tint; the leading icon, a
   leading <strong> and strong.alert-title take the tone's text
   colour. Each tone sets three hooks (--alert-tone, --alert-tint,
   --alert-edge); the base consumes them, so a module sheet that
   restyles .alert only has to touch geometry.
   Structured markup (new code):
     <div class="alert alert-danger" role="alert">
       <i class="ti ti-alert-circle alert-icon" aria-hidden="true"></i>
       <div class="alert-body"><strong class="alert-title">Not
       saved.</strong> Text.</div>
     </div>
   The icon floats into its own column beside the body, so older
   markup that runs an icon straight into inline text keeps
   flowing normally. Icons: ti-alert-circle (danger),
   ti-alert-triangle (warning), ti-circle-check (success),
   ti-info-circle (info). Submit errors use role="alert";
   confirmations use role="status".
   Aliases: .alert-error = .alert-danger; admin's .admin-alert-error
   and .admin-alert-success = .alert.alert-danger / .alert.alert-success.
   ------------------------------------------------------------ */
.alert,
.admin-alert-error,
.admin-alert-success {
    --alert-tone: var(--text-secondary);
    --alert-tint: var(--surface-2);
    --alert-edge: var(--border-medium);
    --bs-alert-color: var(--text-primary);
    --bs-alert-bg: var(--alert-tint);
    --bs-alert-border-color: var(--alert-edge);
    --bs-alert-border-radius: var(--r-md);
    --bs-alert-link-color: var(--primary-text);
    position: relative;
    margin-bottom: 1rem;
    padding: 1rem 1.25rem;
    border: 2px solid var(--alert-edge);
    border-radius: var(--r-md);
    background: var(--alert-tint);
    color: var(--text-primary);
}

.alert-danger,
.alert-error,
.admin-alert-error {
    --alert-tone: var(--danger-text);
    --alert-tint: var(--danger-tint);
    --alert-edge: var(--danger-border);
}
.alert-warning {
    --alert-tone: var(--warning-text);
    --alert-tint: var(--warning-tint);
    --alert-edge: var(--warning-border);
}
.alert-success,
.admin-alert-success {
    --alert-tone: var(--success-text);
    --alert-tint: var(--success-tint);
    --alert-edge: var(--success-border);
}
.alert-info,
.alert-primary {
    --alert-tone: var(--info-text);
    --alert-tint: var(--info-tint);
    --alert-edge: var(--info-border);
}
.alert-secondary,
.alert-light,
.alert-dark {
    --alert-tone: var(--text-secondary);
    --alert-tint: var(--surface-2);
    --alert-edge: var(--border-medium);
}

/* Two-class weight on the frame colour: module sheets that load
   later reset it with a bare 'border: 2px solid' (currentColor). */
.alert[class],
.admin-alert-error[class],
.admin-alert-success[class] {
    border-color: var(--alert-edge);
}

/* Bootstrap's dismissible padding (the shorthand above resets it). */
.alert.alert-dismissible {
    padding-right: 3rem;
}

/* Icon slot and title */
.alert-icon {
    float: left;
    margin-right: 0.65rem;
    color: var(--alert-tone);
    font-size: 1.25rem;
    line-height: 1.2;
}
.alert-body {
    display: flow-root;
}
.alert-body > :last-child {
    margin-bottom: 0;
}
.alert > .ti:first-child,
.alert > strong:first-child,
.admin-alert-error > .ti:first-child,
.admin-alert-success > .ti:first-child,
.alert .alert-title,
.alert .alert-heading {
    color: var(--alert-tone);
}
.alert .alert-title {
    font-weight: 700;
}

/* Links read as links on every tint (not by colour alone). */
.alert :where(a:not(.btn)) {
    color: var(--primary-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.alert :where(a:not(.btn)):hover {
    color: var(--text-primary);
    text-decoration-thickness: 2px;
}

/* ------------------------------------------------------------
   Callout: Learn content and protocol info boxes. The alert tint
   with a 4px left rule in the tone's text colour, no outer frame.
   <div class="callout is-warning"><strong class="callout-title">
   ...</strong><p>...</p></div>
   Tones: .is-info (default), .is-success, .is-warning, .is-danger,
   .is-muted, .is-brand, .is-ce.
   ------------------------------------------------------------ */
.callout {
    --callout-tone: var(--info-text);
    --callout-tint: var(--info-tint);
    margin: 0 0 1rem;
    padding: 1rem 1.25rem;
    border: 0;
    border-left: 4px solid var(--callout-tone);
    border-radius: var(--r-md);
    background: var(--callout-tint);
    color: var(--text-primary);
}
.callout.is-success {
    --callout-tone: var(--success-text);
    --callout-tint: var(--success-tint);
}
.callout.is-warning {
    --callout-tone: var(--warning-text);
    --callout-tint: var(--warning-tint);
}
.callout.is-danger {
    --callout-tone: var(--danger-text);
    --callout-tint: var(--danger-tint);
}
.callout.is-muted {
    --callout-tone: var(--text-muted);
    --callout-tint: var(--surface-2);
}
.callout.is-brand {
    --callout-tone: var(--primary-text);
    --callout-tint: var(--primary-tint);
}
.callout.is-ce {
    --callout-tone: var(--ce-text);
    --callout-tint: var(--ce-tint);
}
.callout > :last-child {
    margin-bottom: 0;
}
.callout > .ti:first-child,
.callout .callout-title {
    color: var(--callout-tone);
}
.callout .callout-title {
    font-weight: 700;
}

/* ------------------------------------------------------------
   Toast
   <div class="fl-toast-stack" aria-live="polite"> holds
   <div class="fl-toast is-success" role="status"> (role="alert"
   for .is-danger) with an .fl-toast-icon, .fl-toast-msg and an
   .fl-toast-close.icon-btn labelled Dismiss. Bottom-right, newest
   at the bottom, stacking upward; bottom-centre and full width at
   600px and below. A toast is visible as soon as it is inserted
   (it plays its entrance on its own), .is-shown keeps it so, and
   .is-leaving fades it out (it slides only when motion is allowed).
   ------------------------------------------------------------ */
.fl-toast-stack {
    position: fixed;
    right: 1rem;
    bottom: 1.25rem;
    bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    width: 380px;
    max-width: calc(100vw - 2rem);
    pointer-events: none;
}
.fl-toast {
    --toast-tone: var(--info-text);
    --toast-tint: var(--info-tint);
    --toast-edge: var(--info-border);
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    width: 100%;
    padding: 0.8rem 0.9rem;
    border: 1px solid var(--toast-edge);
    border-radius: var(--r-md);
    background: var(--toast-tint);
    box-shadow: var(--elev-3);
    color: var(--text-primary);
    font-size: var(--fs-sm);
    line-height: 1.45;
    pointer-events: auto;
    opacity: 1;
    transition: opacity 0.2s ease;
    animation: fl-toast-in 0.2s ease;
}
.fl-toast.is-success {
    --toast-tone: var(--success-text);
    --toast-tint: var(--success-tint);
    --toast-edge: var(--success-border);
}
.fl-toast.is-warning {
    --toast-tone: var(--warning-text);
    --toast-tint: var(--warning-tint);
    --toast-edge: var(--warning-border);
}
.fl-toast.is-danger {
    --toast-tone: var(--danger-text);
    --toast-tint: var(--danger-tint);
    --toast-edge: var(--danger-border);
}
.fl-toast.is-info {
    --toast-tone: var(--info-text);
    --toast-tint: var(--info-tint);
    --toast-edge: var(--info-border);
}

.fl-toast-icon {
    flex: none;
    color: var(--toast-tone);
    font-size: 1.25rem;
    line-height: 1.2;
}
.fl-toast-msg {
    flex: 1 1 auto;
    min-width: 0;
    padding-top: 0.1rem;
    color: var(--text-primary);
    overflow-wrap: break-word;
}
.fl-toast-close {
    flex: none;
    margin: -0.5rem -0.4rem -0.5rem 0;
}

.fl-toast.is-shown {
    opacity: 1;
}
.fl-toast.is-leaving {
    opacity: 0;
}

@keyframes fl-toast-in {
    from { opacity: 0; }
}
@keyframes fl-toast-slide-in {
    from { opacity: 0; transform: translateY(0.75rem); }
}
@media (prefers-reduced-motion: no-preference) {
    .fl-toast {
        transition: opacity 0.2s ease, transform var(--dur) var(--ease-out);
        animation: fl-toast-slide-in var(--dur) var(--ease-out);
    }
    .fl-toast.is-leaving {
        transform: translateX(1.5rem);
    }
}

@media (max-width: 600px) {
    .fl-toast-stack {
        right: 1rem;
        left: 1rem;
        bottom: 1rem;
        bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        align-items: stretch;
        width: auto;
        max-width: none;
    }
}
@media (max-width: 600px) and (prefers-reduced-motion: no-preference) {
    .fl-toast.is-leaving {
        transform: translateY(0.75rem);
    }
}

@media print {
    .fl-toast-stack {
        display: none;
    }
}

/* ------------------------------------------------------------
   Modal / dialog
   <dialog class="fl-modal [is-wide|is-xl]" aria-labelledby="ID">
     <div class="fl-modal-panel">
       <div class="fl-modal-head"><h2 class="fl-modal-title" id="ID">
         <i class="ti ..." aria-hidden="true"></i> Title</h2>
         <button type="button" class="modal-close" aria-label="Close">
         <i class="ti ti-x" aria-hidden="true"></i></button></div>
       <div class="fl-modal-body">...</div>
       <div class="fl-modal-actions form-actions">[secondary][primary]</div>
     </div>
   </dialog>
   Opened with showModal(). The dialog itself is a transparent
   full-viewport layer (a click on it, outside the panel, is a click
   on the backdrop); the panel scrolls its body inside 86vh. Without
   <dialog>: div.fl-modal[role="dialog"][aria-modal="true"] with
   .is-open draws its own scrim (layer --z-modal over the page; the
   native dialog sits in the top layer). .is-danger tints the title
   icon for destructive confirms. .is-inline renders a closed-in
   static preview (style guide only). Full screen at 600px and below.
   ------------------------------------------------------------ */
.fl-modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: var(--z-modal);
    display: none;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 0 1rem 1rem;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    background: transparent;
    color: var(--text-primary);
}
.fl-modal[open],
.fl-modal.is-open {
    display: block;
}
.fl-modal:focus,
.fl-modal-panel:focus {
    outline: none;
}

.fl-modal::backdrop {
    background: var(--scrim, rgba(0, 0, 0, 0.55));
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.fl-modal:not(dialog).is-open {
    background: var(--scrim);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* Keep the page behind an open modal from scrolling. */
:root:has(.fl-modal:not(.is-inline):is([open], .is-open)) {
    overflow: hidden;
}

.fl-modal-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 560px;
    max-height: 86vh;
    margin: 7vh auto 0;
    overflow: hidden;
    border: 1.5px solid var(--border-medium);
    border-radius: var(--r-lg);
    background: var(--card-bg);
    box-shadow: var(--elev-4);
    color: var(--text-primary);
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
    .fl-modal-panel {
        border-color: color-mix(in srgb, var(--primary-soft) 22%, var(--border-soft));
    }
}
.fl-modal.is-wide .fl-modal-panel {
    max-width: 760px;
}
.fl-modal.is-xl .fl-modal-panel {
    max-width: 900px;
}

.fl-modal-head {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem var(--pad-panel);
}
.fl-modal-head:not(.fl-band) {
    border-bottom: 1px solid var(--border-soft);
}
.fl-modal-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    margin: 0;
    color: var(--text-primary);
    font-size: var(--fs-card-title);
    font-weight: 800;
    line-height: 1.25;
}
.fl-modal-title > .ti {
    flex: none;
    color: var(--primary-soft);
}
.fl-modal.is-danger .fl-modal-title > .ti {
    color: var(--danger-text);
}
.fl-modal-head > .modal-close {
    flex: none;
    margin-right: -0.5rem;
}
/* A tool modal may use a navy .fl-band head instead. */
.fl-band .fl-modal-title {
    color: #fff;
}
.fl-band .fl-modal-title > .ti {
    color: var(--brand-gold);
}

.fl-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: var(--pad-panel);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.fl-modal-body > :last-child {
    margin-bottom: 0;
}

.fl-modal-actions {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.6rem;
    margin: 0;
    padding: 1rem var(--pad-panel);
    border-top: 1px solid var(--border-soft);
}
/* The bar also carries .form-actions; a module sheet that loads later
   restyles that class (admin's margin-top, and the temporary
   .admin-container alignment above), so the bar's own layout is held
   at two classes. */
.fl-modal-actions.form-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.6rem;
    margin: 0;
}

@keyframes fl-modal-in {
    from { opacity: 0; transform: translateY(0.75rem) scale(0.98); }
}
@keyframes fl-modal-fade {
    from { opacity: 0; }
}
@media (prefers-reduced-motion: no-preference) {
    .fl-modal[open] .fl-modal-panel,
    .fl-modal.is-open .fl-modal-panel {
        animation: fl-modal-in var(--dur) var(--ease-out);
    }
    .fl-modal[open]::backdrop {
        animation: fl-modal-fade var(--dur) ease;
    }
}

/* Style-guide preview: a static, closed-in panel with no scrim. */
.fl-modal.is-inline {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    z-index: auto;
    display: block;
    width: auto;
    height: auto;
    padding: 0;
    overflow: visible;
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}
.fl-modal.is-inline .fl-modal-panel {
    max-height: none;
    margin: 0;
    animation: none;
}

@media (max-width: 600px) {
    .fl-modal:not(.is-inline) {
        padding: 0;
    }
    .fl-modal:not(.is-inline) .fl-modal-panel {
        max-width: none;
        height: 100%;
        max-height: none;
        margin: 0;
        border: 0;
        border-radius: 0;
    }
    .fl-modal:not(.is-inline) .fl-modal-head {
        padding-top: max(1rem, env(safe-area-inset-top, 0px));
    }
    .fl-modal:not(.is-inline) .fl-modal-actions {
        padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    }
}
@media (max-width: 480px) {
    .fl-modal-actions {
        flex-direction: column-reverse;
        align-items: stretch;
    }
}

/* ------------------------------------------------------------
   Document card and top bar
   The reader for one reference document: protocols/view.php and
   checklists/view.php. A top bar, then one framed document whose
   navy head band holds the page's only <h1> (these pages have no
   .page-hero):
     <div class="doc-topbar">
       <a class="page-back" href="...">...Back to {Category}</a>
       <div class="doc-topbar-actions">
         <button type="button" class="pill-btn">...Print</button>
       </div>
     </div>
     <article class="doc-card">
       <header class="doc-card-head"><h1>...</h1></header>
       ...document body...
     </article>
   The bar spans the .page-shell (pageBack() on the left, .pill-btn
   actions on the right, wrapping under it on phones); the card is
   capped at 1100px and centred. On small phones the whole shell
   (bar, any banner, card) narrows its gutter to 0.35rem, so every
   edge lines up. The head is the band colour with the protocol
   header's 4px brand-red cap (heavier than .fl-band's 3px, as a
   document title deserves); each module styles the title type
   inside it. The body has no padding of its own: protocol blocks
   and checklist rows carry their insets, so section bands and rows
   run edge to edge. Light mode is white paper in the banded panel's
   listing frame (.surface-panel.has-band). Dark mode is the Learn
   viewer's near-black reading surface, without its backdrop blur
   (the offline app renders every protocol on one page). Print hides
   the bar, squares the card off in a black rule and keeps the fills
   (the band, rows, callouts).
   Aliases: .proto-card and .proto-header, which protocols/print.php
   (the print book and the offline app) still emits. .proto-card
   shares the structure, fill and dark recipe; its own 1px frame,
   18px corners and shadow stay in protocols/includes/view.css.
   ------------------------------------------------------------ */
.doc-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin-bottom: 1rem;
}
.doc-topbar > .page-back {
    margin: 0;
}
.doc-topbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.doc-card,
.proto-card {
    max-width: 1100px;
    margin-inline: auto;
    overflow: hidden;
    background: var(--card-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    color: var(--text-primary);
    transition: none;
}
.doc-card {
    border: var(--frame-w) solid var(--frame-listing);
    border-radius: var(--r-lg);
    box-shadow: var(--elev-1);
}
[data-theme="dark"] .doc-card,
[data-theme="dark"] .proto-card {
    border-color: rgba(140, 160, 200, 0.4);
    background: rgba(4, 8, 18, 0.85);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.doc-card-head,
.proto-header {
    padding: 1.5rem 2rem;
    border-bottom: 4px solid var(--brand-red);
    background: var(--brand-band);
    color: var(--text-on-fill);
    text-align: center;
}

@media (max-width: 768px) {
    .doc-card-head,
    .proto-header {
        padding: 1.1rem 1rem;
    }
}

/* Small phones: the document's shell takes back most of the side gutter
   (0.35rem from the screen edge, the protocol reader's tuned phone
   width), so the top bar, the draft banner and the card share one edge. */
@media (max-width: 480px) {
    .page-shell:has(> .doc-card) {
        padding-inline: 0.35rem;
    }
}

@media print {
    .doc-topbar {
        display: none !important;
    }
    .page-shell:has(> .doc-card) {
        max-width: none;
        padding: 0;
    }
    .doc-card,
    .proto-card,
    [data-theme="dark"] .doc-card,
    [data-theme="dark"] .proto-card {
        border: 2px solid #000;
        border-radius: 0;
        box-shadow: none;
    }
    .doc-card,
    .doc-card *,
    .proto-card,
    .proto-card * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* ------------------------------------------------------------
   Field errors
   A field that failed validation carries aria-invalid="true" (what a
   screen reader announces) or Bootstrap's .is-invalid, or is :invalid
   inside a .was-validated form. Its frame turns --danger-text; focus
   keeps the site's two-tone ring. Bootstrap's fixed red frame, its
   red focus glow and its warning-glyph background image are replaced
   (they ignore the theme). The message is .invalid-feedback in
   --danger-text, with room for a leading icon, linked from the field
   by aria-describedby. Bootstrap shows it after an .is-invalid field;
   add .d-block to show it beside an aria-invalid field:
     <input class="form-control" id="wt" aria-invalid="true"
            aria-describedby="wt-err">
     <div class="invalid-feedback d-block" id="wt-err"><i class="ti
       ti-alert-circle" aria-hidden="true"></i> Enter a weight.</div>
   ------------------------------------------------------------ */
:root,
[data-theme] {
    --bs-form-invalid-color: var(--danger-text);
    --bs-form-invalid-border-color: var(--danger-text);
}

.form-control:is([aria-invalid="true"], .is-invalid),
.was-validated .form-control:invalid,
.form-select:is([aria-invalid="true"], .is-invalid),
.was-validated .form-select:invalid {
    border-color: var(--danger-text);
}

.form-control:is([aria-invalid="true"], .is-invalid),
.was-validated .form-control:invalid {
    background-image: none;
}

/* A select keeps its chevron; only the second (warning) image goes.
   Same weight as Bootstrap's rule, later in the cascade. */
.form-select:is([aria-invalid="true"], .is-invalid):not([multiple]):not([size]),
.form-select:is([aria-invalid="true"], .is-invalid):not([multiple])[size="1"],
.was-validated .form-select:invalid:not([multiple]):not([size]),
.was-validated .form-select:invalid:not([multiple])[size="1"] {
    --bs-form-select-bg-icon: none;
}

.form-control:is([aria-invalid="true"], .is-invalid):focus,
.was-validated .form-control:invalid:focus,
.form-select:is([aria-invalid="true"], .is-invalid):focus,
.was-validated .form-select:invalid:focus {
    border-color: var(--danger-text);
    box-shadow: var(--focus-ring);
}

.form-check-input:is([aria-invalid="true"], .is-invalid),
.was-validated .form-check-input:invalid {
    border-color: var(--danger-text);
}

/* Checked: the danger fill (white glyph at 6:1 in both themes), not
   Bootstrap's text-colour fill. */
.form-check-input:is([aria-invalid="true"], .is-invalid):checked,
.was-validated .form-check-input:invalid:checked {
    border-color: var(--danger-fill);
    background-color: var(--danger-fill);
}

.form-check-input:is([aria-invalid="true"], .is-invalid):focus,
.was-validated .form-check-input:invalid:focus {
    box-shadow: none;
}

.form-check-input:is([aria-invalid="true"], .is-invalid):focus-visible,
.was-validated .form-check-input:invalid:focus-visible {
    box-shadow: var(--focus-ring);
}

.invalid-feedback {
    color: var(--danger-text);
}

.invalid-feedback > .ti:first-child {
    margin-right: 0.3rem;
    font-size: 1.1em;
    vertical-align: -0.125em;
}
