:root {
    --blue: #6d1caa;
    --blue-dark: #50127f;
    --navy: #401360;
    --ink: #24232c;
    --muted: #565461;
    --soft: #666374;
    --surface: #fff;
    --control-line: #827b8b;
    --theme-strong: var(--blue);
    --theme-heading-ink: var(--blue-dark);
    --theme-heading-bg: color-mix(in srgb, var(--blue) 8%, white);
    --theme-table-head: color-mix(in srgb, var(--blue) 13%, white);
    --theme-tinted: color-mix(in srgb, var(--blue) 6%, #faf9fd);
    --theme-quiet: #f5f6f9;
    --canvas: var(--theme-tinted);
    --blue-soft: color-mix(in srgb, var(--blue) 11%, white);
    --blue-line: color-mix(in srgb, var(--blue) 25%, white);
    --line: color-mix(in srgb, var(--blue) 8%, #e7e5eb);
    --accent-wash: color-mix(in srgb, var(--blue) 4%, white);
    --accent-line: var(--blue-line);
    --accent-focus: var(--blue);
    --accent-glow: color-mix(in srgb, var(--blue) 24%, transparent);
    --toolbar: var(--blue-dark);
    --toolbar-fill: linear-gradient(112deg, var(--toolbar), var(--blue));
    --toolbar-ink: #fff;
    --toolbar-muted: #f4effb;
    --toolbar-line: #ffffff63;
    --toolbar-item: #ffffff0f;
    --toolbar-item-hover: #ffffff18;
}

:root[data-theme='blue'] {
    --blue: #2358dc;
    --blue-dark: #173eaa;
    --navy: #143476;
}

:root[data-theme='red'] {
    --blue: #cb283d;
    --blue-dark: #a31c2c;
    --navy: #7b1825;
}

:root[data-theme='green'] {
    --blue: #147649;
    --blue-dark: #0d5936;
    --navy: #17482f;
}

:root[data-theme-background='quiet'] { --canvas: var(--theme-quiet); }

:root[data-theme-topbar='dark'] {
    --toolbar: #191a26;
    --toolbar-fill: linear-gradient(112deg, #191a26, #2c2c40);
}

:focus-visible { outline-color: var(--accent-focus); }
:is(.auth-body, .cms-public) { background: var(--canvas); color: var(--ink); }

:is(.topbar, .completion-platform-header, .directory-header, .cms-public-header) {
    background: var(--toolbar-fill);
    border-block-end-color: var(--toolbar-line);
    color: var(--toolbar-ink);
}

:is(.topbar, .completion-platform-header, .directory-header, .cms-public-header) .brand,
.topbar .account-link,
.cms-public-header p { color: var(--toolbar-ink); }

:is(.topbar, .completion-platform-header, .directory-header) .brand-wordmark small,
.topbar .topbar-current { color: var(--toolbar-muted); }

.topbar .topbar-brand,
.topbar .account-link { border-color: var(--toolbar-line); }

:is(.topbar, .completion-platform-header, .directory-header) .brand-mark,
.topbar .user-avatar {
    border-color: var(--toolbar-line);
    background: var(--toolbar-item-hover);
    color: var(--toolbar-ink);
}

.topbar .icon-button,
.topbar .button.locale-switch,
.completion-platform-header > .completion-actions .button,
.completion-platform-header .theme-picker > summary,
:is(.directory-header, .cms-public-header) :is(.icon-button, .button) {
    border-color: var(--toolbar-line);
    background: var(--toolbar-item);
    color: var(--toolbar-ink);
}

.topbar .icon-button:hover,
.topbar .button.locale-switch:hover,
.completion-platform-header > .completion-actions .button:hover,
.completion-platform-header .theme-picker > summary:hover,
:is(.directory-header, .cms-public-header) :is(.icon-button, .button):hover,
.directory-header .button[aria-current='page'],
:is(.topbar, .completion-platform-header, .directory-header, .cms-public-header) .theme-picker[open] > summary {
    border-color: #ffffff9c;
    background: var(--toolbar-item-hover);
    color: var(--toolbar-ink);
}

:is(.topbar, .completion-platform-header, .directory-header, .cms-public-header) :is(.brand, .icon-button, .button, .account-link):focus-visible {
    outline-color: var(--toolbar-ink);
}

.directory-header {
    min-inline-size: 0;
    padding: 10px clamp(12px, 2.6vw, 23px);
    border-radius: 0 0 var(--radius) var(--radius);
}

.cms-public-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

:is(.page-heading, .dashboard-welcome, .directory-hero, .cms-article, .auth-card) h1 { color: var(--navy); }

:is(.panel-head, .directory-card, .directory-info, .study-course) h2 { color: var(--theme-heading-ink); }

.panel-head {
    border-block-end-color: var(--accent-line);
    background: var(--theme-heading-bg);
    color: var(--theme-heading-ink);
}

.panel-head.dashboard-panel-head {
    border-block-end-color: transparent;
    background: linear-gradient(112deg, var(--blue-dark), var(--theme-strong));
    color: #fff;
}

.panel-head.dashboard-panel-head :is(h2, a:not(.button)) { color: #fff; }
.panel-head.dashboard-panel-head :focus-visible { outline-color: #fff; }

table thead :is(th, td),
.data-table thead,
.data-table thead :is(th, td) {
    background: var(--theme-table-head);
    color: var(--theme-heading-ink);
}

:is(.metric-card, .completion-metric, .operations-metric, .portal-metric) :is(.metric-value, dd, strong) { color: var(--theme-heading-ink); }

:is(.portal-hero-icon, .completion-hero-icon, .operations-hero-icon, .directory-hero-icon) {
    border-color: var(--blue);
    background: var(--blue);
    color: #fff;
}

:is(.directory-card, .portal-category, .completion-metric, .operations-metric) { border-color: var(--accent-line); }
.portal-category > svg:last-child { color: var(--blue); }

:is(.directory-card, .portal-category, .portal-metric, .operations-tile):hover {
    border-color: var(--blue);
    background-color: var(--accent-wash);
}

:is(.cms-page-meta a, .cms-address, .learning-nav a, .portal-row-date) { color: var(--blue-dark); }

.portal-row-date {
    border-color: var(--accent-line);
    background: var(--blue-soft);
}

.button.primary {
    border-color: var(--blue);
    background: var(--blue);
    color: #fff;
}

.button.primary:hover {
    border-color: var(--blue-dark);
    background: var(--blue-dark);
}

:is(.attendance-nav, .exam-nav, .operations-tabs, .student-sections-nav, .learning-nav, .finance-nav, .timetable-view-options)
    :is(a, button):is(.button, [role='tab']):is([aria-current='page'], [aria-selected='true'], .active, .current) {
    border-color: var(--accent-line);
    background: var(--blue-soft);
    color: var(--blue-dark);
}

.field :is(input, textarea, select):focus { border-color: var(--blue); }
input[type='checkbox'], input[type='radio'], progress { accent-color: var(--blue); }

.theme-picker { position: relative; flex: 0 0 auto; }
.theme-picker > summary { list-style: none; cursor: pointer; }
.theme-picker > summary::-webkit-details-marker { display: none; }

.theme-picker[open] > summary {
    border-color: var(--blue);
    background: var(--blue-soft);
    color: var(--blue-dark);
}

.theme-choices {
    position: absolute;
    z-index: 22;
    inset-block-start: calc(100% + 8px);
    inset-inline-end: 0;
    display: grid;
    gap: 12px;
    inline-size: clamp(260px, 36vw, 360px);
    margin: 0;
    padding: 14px;
    border: 1px solid var(--accent-line);
    border-radius: 13px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 12px 36px #20112b2b;
}

.theme-group {
    min-inline-size: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.theme-group:not(:first-child) { border-block-start: 1px solid var(--line); }
.theme-group legend { margin-block-end: 6px; padding-inline: 0 6px; color: var(--blue-dark); font-weight: 800; }
.theme-option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }

.theme-choice {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px;
    min-inline-size: 0;
    min-block-size: 43px;
    padding: 5px 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-small);
    font-weight: 740;
    line-height: 1.35;
    text-align: start;
}

.theme-choice:hover { border-color: var(--blue); }
.theme-choice[aria-pressed='true'] { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-dark); }

.theme-swatch {
    inline-size: 22px;
    block-size: 18px;
    border: 1px solid color-mix(in srgb, var(--swatch) 76%, #40404a);
    border-radius: 5px;
    background: var(--swatch);
}

[data-theme-choice='purple'] { --swatch: #6d1caa; }
[data-theme-choice='blue'] { --swatch: #2358dc; }
[data-theme-choice='red'] { --swatch: #cb283d; }
[data-theme-choice='green'] { --swatch: #147649; }
[data-theme-choice='color'] { --swatch: var(--blue); }
[data-theme-choice='dark'] { --swatch: #191a26; }
[data-theme-choice='tinted'] { --swatch: var(--theme-tinted); }
[data-theme-choice='quiet'] { --swatch: var(--theme-quiet); }

.theme-check { color: var(--blue-dark); visibility: hidden; }
.theme-choice[aria-pressed='true'] .theme-check { visibility: visible; }

@media (max-width: 600px) {
    .theme-choices {
        --theme-popup-top-resolved: var(--theme-popup-top, calc(var(--header-height) + 8px));
        position: fixed;
        inset-block-start: var(--theme-popup-top-resolved);
        inset-inline: 10px;
        inline-size: auto;
        max-block-size: calc(100dvh - var(--theme-popup-top-resolved) - 12px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .directory-header { gap: 7px; }
}

@media (prefers-reduced-motion: no-preference) {
    :is(.button, .icon-button, .theme-choice, .metric-card, .portal-category, .directory-card) {
        transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease, color .16s ease, translate .16s ease;
    }

    @media (hover: hover) {
        :is(.button, .icon-button, .metric-card, .portal-category):not(:disabled):hover { translate: 0 -1px; }
    }
}

@media print {
    .theme-picker { display: none; }
    table thead :is(th, td), .data-table thead :is(th, td) { background: #fff; color: #222; }
}
