        :root {
    color-scheme: light;
    /* Brand accents (text / icons / borders) */
    --primary: #007bff;
    --primary-dark: #0056b3;
    --success: #28a745;
    --success-dark: #1e7e34;
    --danger: #dc3545;
    --when: #0b2e59;
    --level: #b45309;
    --info-accent: #1c7ed6;
    --info-accent-2: #339af0;
    --info-solid: #1c7ed6;
    --info-solid-2: #339af0;
    --warning-amber: #e67700;
    --warning-gold: #fab005;
    --orange: #f57c00;
    --cancel: #ffc107;
    --cancel-text: #3a2f00;
    --whatsapp: #25d366;
    /* Filled-button surfaces keep their saturated brand colour so
       white label text stays readable in both themes. */
    --primary-solid: #007bff;
    --primary-solid-hover: #0056b3;
    --success-solid: #28a745;
    --danger-solid: #dc3545;
    --bg-gray-btn: #6c757d;
    /* Surfaces */
    --bg-body: #f8f9fa;
    --bg-card: #ffffff;
    --bg-elevated: #ffffff;
    --bg-subtle: #f1f3f5;
    --bg-subtle-2: #e9ecef;
    --bg-inset: #f0f2f5;
    --bg-neutral: #eef2f7;
    --bg-neutral-2: #eef1f4;
    --bg-warm: #f9f9f9;
    --bg-hover: #e7f1ff;
    --bg-hover-2: #f8fbff;
    --bg-selected: #e7f1ff;
    /* Text */
    --text-main: #212529;
    --text-strong: #333333;
    --text-navy: #2c3e50;
    --text-body: #495057;
    --text-muted: #5a6268;
    --text-soft: #6c757d;
    --text-faint: #6a7076;
    --text-disabled: #98a0a8;
    --text-on-accent: #ffffff;
    /* Borders */
    --border: #e9ecef;
    --border-strong: #dee2e6;
    --border-soft: #eeeeee;
    --border-faint: #f5f5f5;
    --border-input: #dddddd;
    --border-muted: #cccccc;
    --border-neutral: #e0e0e0;
    /* Semantic tints: info */
    --info-bg: #e7f5ff;
    --info-border: #d6e4ff;
    --info-text: #1971c2;
    --info-deep: #1864ab;
    --info-violet: #364fc7;
    --info-navy: #084298;
    --info-navy-bg: #cfe2ff;
    --info-steel: #2b5c8a;
    --info-soft-bg: #f1f8ff;
    --info-softer-bg: #f2faff;
    --info-softer-border: #cbe7fb;
    --info-track: #d0ebff;
    --info-waiting-bg: #dbe4ff;
    --info-hub-bg: #eef4ff;
    /* Semantic tints: success */
    --success-bg: #d3f9d8;
    --success-soft-bg: #e8f5e9;
    --success-soft-border: #a5d6a7;
    --success-chip-bg: #d1e7dd;
    --success-chip-text: #0f5132;
    --success-badge-bg: #d4edda;
    --success-badge-text: #155724;
    --success-text: #2b8a3e;
    /* Semantic tints: warning */
    --warning-bg: #fff3bf;
    --warning-chip-bg: #fff3cd;
    --warning-text: #856404;
    --warning-night-bg: #fff3e0;
    --warning-night-border: #ff9800;
    --warning-box-bg: #fff8e6;
    --warning-box-border: #f0e0b0;
    --warning-box-text: #5a4a1a;
    --warning-medal-text: #5f3f00;
    --warning-medal-text-2: #5c2c00;
    /* Semantic tints: danger */
    --danger-bg: #ffe3e3;
    --danger-strong-bg: #ffebee;
    --danger-chip-bg: #f8d7da;
    --danger-chip-text: #842029;
    --danger-text: #c92a2a;
    --danger-border: #c62828;
    --danger-soft-bg: #fdecea;
    --danger-warn-text: #d9534f;
    /* Semantic tints: neutral */
    --neutral-bg: #e2e3e5;
    --neutral-text: #41464b;
    --neutral-role-bg: #e9ecef;
    --neutral-lvl-bg: #eef2f7;
    --neutral-lvl-text: #343a40;
    /* Radius scale */
    --radius-card: 12px;
    --radius-control: 10px;
    --radius-pill: 999px;
    --nav-height: 65px;
    --safe-area-bottom: env(safe-area-inset-bottom);
}

/* Dark is its own system: near-black base, a stepped surface ladder,
   off-white text, softened accents and tinted semantic colours. */
[data-theme="dark"] {
    color-scheme: dark;
    --primary: #4dabf7;
    --primary-dark: #74c0fc;
    --success: #40c057;
    --success-dark: #2f9e44;
    --danger: #ff6b6b;
    --when: #8ecae6;
    --level: #ffb454;
    --info-accent: #4dabf7;
    --info-accent-2: #339af0;
    --info-solid: #1f6fc0;
    --info-solid-2: #2b82da;
    --warning-amber: #ffd43b;
    --warning-gold: #ffd43b;
    --orange: #e8590c;
    --cancel: #ffd43b;
    --cancel-text: #3a2f00;
    --whatsapp: #25d366;
    --primary-solid: #1f6fc0;
    --primary-solid-hover: #2b82da;
    --success-solid: #237a35;
    --danger-solid: #c92a2a;
    --bg-gray-btn: #4a4a4a;
    --bg-body: #121212;
    --bg-card: #1e1e1e;
    --bg-elevated: #262626;
    --bg-subtle: #2a2a2a;
    --bg-subtle-2: #333333;
    --bg-inset: #2a2a2a;
    --bg-neutral: #2a2a2a;
    --bg-neutral-2: #2a2a2a;
    --bg-warm: #242424;
    --bg-hover: rgba(77, 171, 247, 0.16);
    --bg-hover-2: rgba(77, 171, 247, 0.10);
    --bg-selected: rgba(77, 171, 247, 0.16);
    --text-main: #e8e8e8;
    --text-strong: #dcdcdc;
    --text-navy: #cbd5e1;
    --text-body: #c2c2c2;
    --text-muted: #a3a3a3;
    --text-soft: #a0a0a0;
    --text-faint: #909090;
    --text-disabled: #6b6b6b;
    --text-on-accent: #ffffff;
    --border: #2e2e2e;
    --border-strong: #3a3a3a;
    --border-soft: #2e2e2e;
    --border-faint: #262626;
    --border-input: #3a3a3a;
    --border-muted: #3a3a3a;
    --border-neutral: #3a3a3a;
    --info-bg: rgba(77, 171, 247, 0.15);
    --info-border: rgba(77, 171, 247, 0.30);
    --info-text: #74c0fc;
    --info-deep: #a5d8ff;
    --info-violet: #a5b4fc;
    --info-navy: #a5d8ff;
    --info-navy-bg: rgba(77, 171, 247, 0.15);
    --info-steel: #9ec5e8;
    --info-soft-bg: rgba(77, 171, 247, 0.10);
    --info-softer-bg: rgba(77, 171, 247, 0.10);
    --info-softer-border: rgba(77, 171, 247, 0.30);
    --info-track: rgba(77, 171, 247, 0.22);
    --info-waiting-bg: rgba(99, 102, 241, 0.18);
    --info-hub-bg: rgba(77, 171, 247, 0.14);
    --success-bg: rgba(64, 192, 87, 0.18);
    --success-soft-bg: rgba(64, 192, 87, 0.14);
    --success-soft-border: rgba(64, 192, 87, 0.35);
    --success-chip-bg: rgba(64, 192, 87, 0.18);
    --success-chip-text: #69db7c;
    --success-badge-bg: rgba(64, 192, 87, 0.18);
    --success-badge-text: #69db7c;
    --success-text: #69db7c;
    --warning-bg: rgba(255, 193, 7, 0.18);
    --warning-chip-bg: rgba(255, 193, 7, 0.16);
    --warning-text: #ffd43b;
    --warning-night-bg: rgba(255, 152, 0, 0.16);
    --warning-night-border: #ffa94d;
    --warning-box-bg: rgba(255, 193, 7, 0.12);
    --warning-box-border: rgba(255, 193, 7, 0.30);
    --warning-box-text: #ffd8a8;
    --warning-medal-text: #3a2f00;
    --warning-medal-text-2: #3a1d00;
    --danger-bg: rgba(255, 107, 107, 0.18);
    --danger-strong-bg: rgba(255, 107, 107, 0.16);
    --danger-chip-bg: rgba(255, 107, 107, 0.18);
    --danger-chip-text: #ff8787;
    --danger-text: #ff8787;
    --danger-border: #ff6b6b;
    --danger-soft-bg: rgba(255, 107, 107, 0.14);
    --danger-warn-text: #ff8787;
    --neutral-bg: rgba(255, 255, 255, 0.08);
    --neutral-text: #adb5bd;
    --neutral-role-bg: rgba(255, 255, 255, 0.08);
    --neutral-lvl-bg: rgba(255, 255, 255, 0.08);
    --neutral-lvl-text: #ced4da;
}

/* Depth on dark comes from the surface ladder + borders, not shadows. */
[data-theme="dark"] .modal-content {
    background: var(--bg-elevated);
}

[data-theme="dark"] .rank-badge:not(.rank-1):not(.rank-2):not(.rank-3) {
    background: var(--bg-subtle);
    color: var(--text-body);
}

[data-theme="dark"] .podium-card {
    background: linear-gradient(180deg, #2a2a2a, #202020);
}

[data-theme="dark"] .bottom-nav {
    background: linear-gradient(180deg, rgba(38, 38, 38, 0.92), rgba(30, 30, 30, 0.82));
    border-color: rgba(255, 255, 255, 0.10);
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Raised fills inside panels read as subtle surfaces on dark. */
[data-theme="dark"] .mini-table th,
[data-theme="dark"] .trainer-divider td,
[data-theme="dark"] .example-table th {
    background: var(--bg-subtle);
}

[data-theme="dark"] h2,
[data-theme="dark"] .panel h2 {
    border-bottom-color: var(--border);
}

/* Theme toggle */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    flex: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

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

.theme-toggle:active {
    background: var(--bg-subtle);
}

.theme-toggle svg {
    width: 19px;
    height: 19px;
}

.theme-toggle .icon-sun {
    display: none;
}

.theme-toggle.is-dark .icon-moon {
    display: none;
}

.theme-toggle.is-dark .icon-sun {
    display: block;
}

/* ------------------------------------------------------------------
   Shared UI layer: motion preferences, accessibility helpers, dialog
   behaviour and loading states. Loaded before page-specific CSS.
   ------------------------------------------------------------------ */

/* Honour reduced-motion for every animation/transition, on every page. */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Screen-reader-only content. */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* Skip link: off-screen until keyboard-focused. */
.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 3000;
    transform: translateY(-160%);
    background: var(--primary-solid);
    color: var(--text-on-accent);
    padding: 10px 14px;
    border-radius: var(--radius-control);
    font-weight: 700;
    text-decoration: none;
    transition: transform 0.15s ease;
}

.skip-link:focus {
    transform: translateY(0);
}

/* Dialog plumbing shared by every bottom sheet / modal. */
.modal {
    overscroll-behavior: contain;
}

.modal[aria-hidden="true"] {
    pointer-events: none;
}

body.modal-open {
    overflow: hidden;
}

/* Loading spinner, used instead of bare "Loading..." text. */
.spinner {
    display: inline-block;
    width: 26px;
    height: 26px;
    border: 3px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: tc-spin 0.7s linear infinite;
}

@keyframes tc-spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-block {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 28px;
    color: var(--text-faint);
}

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation-duration: 1.8s;
    }
}

/* Global toast (used by TCUI.toast and the window.alert override). */
.tc-toast {
    position: fixed;
    left: 50%;
    bottom: 90px;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    color: var(--text-strong);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    padding: 14px 18px;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
    font-size: 0.95rem;
    line-height: 1.45;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 9999;
    max-width: 90%;
    width: max-content;
    pointer-events: none;
}

.tc-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.tc-toast.tc-toast-success {
    border-left-color: var(--success);
}

.tc-toast.tc-toast-danger {
    border-left-color: var(--danger);
}

/* Promise-based confirm dialog (TCUI.confirm). */
.tc-confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.tc-confirm-overlay.visible {
    opacity: 1;
}

.tc-confirm {
    background: var(--bg-card);
    color: var(--text-main);
    width: 100%;
    max-width: 420px;
    border-radius: var(--radius-card);
    padding: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    transform: translateY(10px);
    transition: transform 0.18s ease;
}

.tc-confirm-overlay.visible .tc-confirm {
    transform: translateY(0);
}

.tc-confirm-msg {
    margin: 0 0 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-line;
}

.tc-confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.tc-confirm-btn {
    padding: 10px 16px;
    border-radius: var(--radius-control);
    border: 1px solid var(--border-strong);
    background: var(--bg-subtle);
    color: var(--text-strong);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.tc-confirm-btn-primary {
    background: var(--primary-solid);
    border-color: var(--primary-solid);
    color: var(--text-on-accent);
}

.tc-confirm-btn-danger {
    background: var(--danger-solid);
    border-color: var(--danger-solid);
    color: var(--text-on-accent);
}

