/* Theme tokens are shared by every document. Geometry and permissions stay with their owners. */
:root[data-ui-theme] {
  --ui-canvas:#eaf1f9; --ui-surface:#f7faff; --ui-surface-raised:#fff; --ui-surface-soft:#e4eefb;
  --ui-ink:#182f4b; --ui-muted:#48627e; --ui-border:#c2d2e5;
  --ui-primary:#1b5bc2; --ui-primary-hover:#17499b; --ui-primary-soft:#e0ebfc;
  --ui-link:#164e9b; --ui-header:#163f70; --ui-header-ink:#fff; --ui-header-muted:#d4e6fa;
  --ui-header-control:#244e7c; --ui-header-border:#7194bc;
  --ui-success:#125e3d; --ui-success-bg:#dff2e7; --ui-warning:#784b08; --ui-warning-bg:#fff1d5;
  --ui-danger:#a1253b; --ui-danger-bg:#ffe8ed; --ui-info:#184e7f; --ui-info-bg:#e0eefb;
  --ui-academic:#08695f; --ui-academic-soft:#dff3ee; --ui-commerce:#6529ad; --ui-commerce-soft:#f0e6fd;
  --ui-program:#4035aa; --ui-program-soft:#e9e6fb; --ui-results:#145f38; --ui-results-soft:#e0f3e6;
  --ui-focus:#286acb; --ui-shadow:0 4px 18px #173c6410; --ui-overlay-shadow:0 18px 50px #0b224b30;
  color-scheme:light;
}
:root[data-ui-theme="white"] {
  --ui-canvas:#f7f8fa; --ui-surface:#fff; --ui-surface-raised:#fff; --ui-surface-soft:#f0f3f7;
  --ui-ink:#202c3d; --ui-muted:#516175; --ui-border:#d3dbe5;
  --ui-header:#fff; --ui-header-ink:#173e67; --ui-header-muted:#516175;
  --ui-header-control:#f1f5fa; --ui-header-border:#c2d0df;
}
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) {
  --ui-canvas:#0b1423; --ui-surface:#142338; --ui-surface-raised:#1b2d45; --ui-surface-soft:#203550;
  --ui-ink:#edf3fc; --ui-muted:#b5c6dc; --ui-border:#415773;
  --ui-primary:#2865c7; --ui-primary-hover:#2457a8; --ui-primary-soft:#233f65; --ui-link:#9bc9ff;
  --ui-header:#101d30; --ui-header-ink:#edf3fc; --ui-header-muted:#b5c6dc;
  --ui-header-control:#203550; --ui-header-border:#536f91;
  --ui-success:#a1e4c0; --ui-success-bg:#143c31; --ui-warning:#ffda91; --ui-warning-bg:#48361b;
  --ui-danger:#ffb5c0; --ui-danger-bg:#482536; --ui-info:#b1d8ff; --ui-info-bg:#203c59;
  --ui-academic:#9de0d1; --ui-academic-soft:#193f3c; --ui-commerce:#d6bcff; --ui-commerce-soft:#382650;
  --ui-program:#c7c2ff; --ui-program-soft:#2d2b55; --ui-results:#a1e4c0; --ui-results-soft:#143c31;
  --ui-focus:#9bc9ff; --ui-shadow:0 4px 18px #0003; --ui-overlay-shadow:0 18px 50px #0008;
  color-scheme:dark;
}
/* Semi-dark keeps the same semantic contrast pairs, with softer slate surfaces. */
:root[data-ui-theme="semi-dark"] {
  --ui-canvas:#243449; --ui-surface:#2c3e55; --ui-surface-raised:#344961; --ui-surface-soft:#384f68;
  --ui-ink:#f3f6fc; --ui-muted:#c9d7e8; --ui-border:#6d829b;
  --ui-header:#243449; --ui-header-control:#344961; --ui-header-border:#7b90aa;
  --ui-header-ink:#f3f6fc; --ui-header-muted:#c9d7e8;
}
:root[data-ui-theme], :root[data-ui-theme] body {
  --canvas:var(--ui-canvas); --surface:var(--ui-surface); --ink:var(--ui-ink); --muted:var(--ui-muted);
  --line:var(--ui-border); --primary:var(--ui-primary); --primary-hover:var(--ui-primary-hover);
  --blue:var(--ui-link); --danger:var(--ui-danger); --green:var(--ui-success);
  background:var(--ui-canvas); color:var(--ui-ink);
}
:root[data-ui-theme] body #app-shell { background:var(--ui-canvas); }
:root[data-ui-theme] body .merit-header {
  background:var(--ui-header); color:var(--ui-header-ink); border-bottom:1px solid var(--ui-header-border);
  box-shadow:0 4px 16px #102a4314; gap:12px; padding:10px 22px; align-items:center;
}
:root[data-ui-theme] body:not(.exam-focus) #app-header.merit-header { --header:68px; height:68px; display:flex; background:var(--ui-header); color:var(--ui-header-ink); border-color:var(--ui-header-border); }
:root[data-ui-theme] body:not(.exam-focus) #app-header.merit-header :is(.app-brand-name,.brand) { color:var(--ui-header-ink); }
:root[data-ui-theme] body:not(.exam-focus) #app-header.merit-header :is(.brand-caption,#account-role) { color:var(--ui-header-muted); }
:root[data-ui-theme] body #main-content { background:var(--ui-canvas); }
:root[data-ui-theme] body.student-workspace:not(.exam-focus) #main-content { background:var(--ui-canvas); }
:root[data-ui-theme] body :is(#main-content,main,dialog) :is(input,select,textarea):not([type="range"]):not([type="checkbox"]):not([type="radio"]) { background:var(--ui-surface-raised)!important; color:var(--ui-ink)!important; border-color:var(--ui-border); }
:root[data-ui-theme] body #main-content :is(.student-recent>div,.student-recent>button,.student-ticket,.result-history-card,.results-overview,.empty-state) { background:var(--ui-surface); color:var(--ui-ink); border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body #main-content .student-demo-strip a { background:var(--ui-surface-raised); color:var(--ui-link); }
:root[data-ui-theme] body:not(.exam-focus) { --header:68px; }
:root[data-ui-theme] .merit-header .brand { min-width:0; gap:10px; }
:root[data-ui-theme] .merit-header :is(.brand,.app-brand-name,.brand h1) { color:var(--ui-header-ink); }
:root[data-ui-theme] .merit-header :is(.brand-caption,.brand small,#account-role,#connection) { color:var(--ui-header-muted); }
:root[data-ui-theme] .merit-header .brand-caption { font-size:11px; letter-spacing:.02em; }
:root[data-ui-theme] .merit-header .brand-symbol { width:40px; height:40px; background:#fff; border-radius:11px; padding:3px; }
:root[data-ui-theme] .merit-header .brand-symbol img { width:100%; height:100%; object-fit:contain; }
:root[data-ui-theme] .merit-header > :is(button,a:not(.brand)),
:root[data-ui-theme] .merit-header > .account-menu > summary,
:root[data-ui-theme] .merit-header > .appearance-picker > summary {
  background:var(--ui-header-control); color:var(--ui-header-ink); border:1px solid var(--ui-header-border);
  border-radius:10px; min-height:40px; box-shadow:none; text-decoration:none;
}
:root[data-ui-theme] .merit-header #sidebar-toggle { order:-1; width:40px; padding:8px; margin:0; }
:root[data-ui-theme] .merit-header .spacer { flex:1; }
:root[data-ui-theme] .merit-header #account-role { display:block; font-size:11px; letter-spacing:.04em; }
:root[data-ui-theme] .merit-header #account-name { display:block; color:var(--ui-ink); font-size:14px; padding:8px; overflow-wrap:anywhere; }
:root[data-ui-theme] .merit-header .account-menu-body { background:var(--ui-surface-raised); color:var(--ui-ink); border-color:var(--ui-border); }
:root[data-ui-theme] .appearance-picker { position:relative; flex:0 0 auto; margin:0; padding:0; border:0; background:transparent; color:var(--ui-ink); }
:root[data-ui-theme] .appearance-picker > summary { display:flex; align-items:center; gap:7px; cursor:pointer; list-style:none; padding:8px 11px; min-height:40px; border:1px solid var(--ui-border); border-radius:10px; background:var(--ui-surface-soft); color:var(--ui-ink); font:600 13px/1.4 system-ui,sans-serif; margin:0; }
.appearance-picker > summary::-webkit-details-marker { display:none; }
:root[data-ui-theme] .appearance-options {
  position:absolute; right:0; top:calc(100% + 10px); z-index:1200; width:246px; max-width:calc(100vw - 24px);
  display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:7px; margin:0; padding:14px;
  border:1px solid var(--ui-border); border-radius:14px; background:var(--ui-surface-raised); color:var(--ui-ink); box-shadow:var(--ui-overlay-shadow);
}
:root[data-ui-theme] .appearance-options legend { float:left; width:100%; grid-column:1/-1; padding:0; margin:0 0 8px; font-size:14px; font-weight:700; }
:root[data-ui-theme] .appearance-choice { display:flex; flex-direction:column; align-items:center; gap:7px; padding:8px 4px; margin:0; min-width:0; border:1px solid var(--ui-border); border-radius:9px; background:var(--ui-surface); color:var(--ui-ink); font:600 13px/1.3 system-ui,sans-serif; cursor:pointer; }
:root[data-ui-theme] .appearance-choice:has(:checked) { border-color:var(--ui-focus); box-shadow:inset 0 0 0 1px var(--ui-focus); background:var(--ui-primary-soft); }
:root[data-ui-theme] .appearance-choice input { appearance:auto; width:16px; height:16px; min-height:0; padding:0; margin:0; accent-color:var(--ui-primary); }
.appearance-swatch { width:42px; height:26px; border-radius:5px; border:1px solid #8a9cb2; border-top:6px solid #163f70; background:#e4eefb; }
.appearance-swatch-dark { border-top-color:#080f1a; background:#1b2d45; }
.appearance-swatch-semi-dark { border-top-color:#243449; background:#445b76; }
.appearance-swatch-white { border-top-color:#e1e6ed; background:#fff; }
:root[data-ui-theme] .appearance-options p { grid-column:1/-1; margin:3px 0 0; font:12px/1.4 system-ui,sans-serif; color:var(--ui-muted); }
.appearance-fallback { display:flex; justify-content:flex-end; padding:10px 16px; background:var(--ui-header); }
:root[data-ui-theme] :focus-visible { outline-color:var(--ui-focus); }
:root[data-ui-theme] body :is(dialog,.menu-body,.panel,.card,.login-card,.class-card,.quiz-card,.score-stat,.board-wrap,.queue-row,.empty,.interaction,.exam-tile,.question-card,.dashboard-recent,.dashboard-metric,.admin-live-activity,.table-wrap,.compact-form,.filters,.admin-content-search,.viewer-panel,.review-panel) { background-color:var(--ui-surface); color:var(--ui-ink); border-color:var(--ui-border); }
:root[data-ui-theme] body :is(input,select,textarea):not([type="range"]):not([type="checkbox"]):not([type="radio"]) { background-color:var(--ui-surface-raised); color:var(--ui-ink); border-color:var(--ui-border); }
:root[data-ui-theme] body input::placeholder, :root[data-ui-theme] body textarea::placeholder { color:var(--ui-muted); opacity:1; }
:root[data-ui-theme] body :is(.hint,.muted,.eyebrow) { color:var(--ui-muted); }
:root[data-ui-theme] body :is(.demo-coach,.setup,.library-banner,.admin-center-hero,.admin-workspace-hub,.admin-hub-hero,.recent-work-head,.score-stat,.demo-teaser) { background:var(--ui-surface-soft); color:var(--ui-ink); border-color:var(--ui-border); }
:root[data-ui-theme] body :is(.class-card p,.score-stat span,.demo-teaser p,.lesson-progress small,.chapter span,.recent-work-head,.page-heading p,.room-heading p) { color:var(--ui-muted); }
:root[data-ui-theme] body :is(.keypad button,.demo-coach button,.chapter,.choice) { background:var(--ui-surface-raised); color:var(--ui-ink); border-color:var(--ui-border); }
:root[data-ui-theme] body :is(.keypad button,.chapter,.choice):hover:not(:disabled) { background:var(--ui-primary-soft); }
:root[data-ui-theme] body .choice:has(input:checked) { background:var(--ui-primary-soft); border-color:var(--ui-focus); }
:root[data-ui-theme] body :is(.badge,.result-banner,.learning-nudge) { background:var(--ui-success-bg); color:var(--ui-success); border-color:var(--ui-success); }
:root[data-ui-theme] body .result-banner.incorrect { background:var(--ui-warning-bg); color:var(--ui-warning); }
:root[data-ui-theme] body :is(.sample-card,.sample-copy,.sample-admin-controls) { background:var(--ui-surface); color:var(--ui-ink); border-color:var(--ui-border); }
:root[data-ui-theme] body :is(.sample-copy p,.sample-footnote) { color:var(--ui-muted); }
:root[data-ui-theme] body :is(.sample-progress,.sample-next) { background:var(--ui-success-bg); color:var(--ui-success); border-color:var(--ui-border); }
:root[data-ui-theme] body :is(.sample-next p,.sample-progress p) { color:inherit; }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body button[data-action-icon]:not(.primary):not(.danger):not(.public-cta):not(.public-secondary) { background:var(--ui-surface-soft)!important; color:var(--ui-ink)!important; border-color:var(--ui-border)!important; }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(.exam-header-bar,.exam-question-nav,.exam-option-item,.exam-question,.exam-current-question,.exam-nav-heading,.exam-question-meta,.exam-question-meta>span,.exam-question-meta>a) { background:var(--ui-surface); color:var(--ui-ink); border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(.exam-context,.exam-nav-legend,.exam-question-nav .exam-nav-heading,.exam-timer) { color:var(--ui-ink); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(.numeric-keypad button,.exam-numeric-keypad button,.exam-numerical-keypad button,.exam-integer-keypad button) { background:var(--ui-surface-raised); color:var(--ui-ink); border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(.section-heading h2,.page-header h2,.page-header p,.section-heading p,.dashboard-recent h3,.dashboard-recent a,.recent-work-item strong,.dashboard-attention,.ux-breadcrumbs) { color:var(--ui-ink); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(.recent-work-item,.dashboard-attention,.student-journey,.student-card,.organisation-exam-card,.workspace-tabs,.student-workspace-design) { background-color:var(--ui-surface)!important; color:var(--ui-ink); border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(.table-wrap th,.table-wrap td,.data-table th,.data-table td) { background-color:var(--ui-surface); color:var(--ui-ink); border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body .table-wrap tr:hover td { background:var(--ui-surface-soft); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(#demo-close,#sample-close) { background:var(--ui-surface-soft); color:var(--ui-ink); border-color:var(--ui-border); }
:root[data-ui-theme] .exam-header-bar > .appearance-picker { justify-self:end; grid-column:auto; }
:root[data-ui-theme] body :is(.board th,.board .you) { background:var(--ui-surface-soft); color:var(--ui-ink); }
:root[data-ui-theme] body .demo-stage :is(.eyebrow,.hint), :root[data-ui-theme] body .demo-hero .hint { color:#c5e0ed; }
:root[data-ui-theme] body :is(.demo-stage,.demo-hero) { color:#fff; }
:root[data-ui-theme] #demo-body .demo-question h3 { font-size:clamp(19px,1.8vw,23px); line-height:1.55; font-weight:650; max-width:65ch; letter-spacing:0; }
:root[data-ui-theme] #demo-body :is(.demo-coach p,.result-banner p) { font-size:16px; line-height:1.65; }
:root[data-ui-theme] body :is(button.primary,.primary.button,a.primary) { background:var(--ui-primary); color:#fff; border-color:var(--ui-primary); }
:root[data-ui-theme] body :is(button.primary,.primary.button,a.primary):hover:not(:disabled) { background:var(--ui-primary-hover); }
:root[data-ui-theme="light"] body #main-content > .tab-panel > .page-header { background:linear-gradient(110deg,#dceaff,#dff2ed); border:1px solid var(--ui-border); border-radius:12px; padding:16px; }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(.workspace-tabs,.ai-subtabs,.review-tabs,.admin-layout-picker,.admin-dashboard-detail article,.exam-question-card,.exam-subject-sidebar,.exam-session-header,.learning-practice-card) { background:var(--ui-surface); color:var(--ui-ink); border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body :is(.workspace-tabs,.ai-subtabs,.review-tabs,.room-tabs,.side-tabs) > button { color:var(--ui-link); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body #main-content :is(.page-header,.section-heading) { border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body #main-content :is(.dashboard-metric,.dashboard-metric strong,.dashboard-metric span,.dashboard-metric small) { background:var(--ui-surface); color:var(--ui-ink); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body .appearance-picker { color:var(--ui-ink); }
@media(max-width:800px) {
  :root[data-ui-theme] body:not(.exam-focus) { --header:64px; }
  :root[data-ui-theme] body:not(.exam-focus) #app-header.merit-header { height:64px; padding:8px 12px; gap:8px; }
  :root[data-ui-theme] #app-header.merit-header :is(.brand-caption,.workspace-home,#workspace-back,#motion-toggle) { display:none; }
  :root[data-ui-theme] .merit-header .app-brand-name { font-size:18px; }
  :root[data-ui-theme] .merit-header .brand-symbol { width:34px; height:34px; }
  :root[data-ui-theme] .merit-header #header-logout { display:none; }
  :root[data-ui-theme] .appearance-picker > summary { min-height:44px; min-width:44px; justify-content:center; padding:8px; }
  .appearance-label { display:none; }
  :root[data-ui-theme] .merit-header > .account-menu > summary { min-height:44px; padding:5px; }
  :root[data-ui-theme] .merit-header.app-header { flex-wrap:wrap; padding:10px 12px; gap:8px; }
  :root[data-ui-theme] .merit-header.app-header .brand { flex:1; }
  :root[data-ui-theme] .merit-header.app-header #connection { order:3; flex:1; max-width:none; }
  :root[data-ui-theme] .merit-header.app-header > a:not(.brand) { order:4; font-size:12px; padding:5px 9px; min-height:32px; }
  :root[data-ui-theme] .merit-header.app-header > .appearance-picker { order:2; }
}
@media print {
  :root[data-ui-theme], :root[data-ui-theme] body { --ui-canvas:#fff; --ui-surface:#fff; --ui-surface-raised:#fff; --ui-surface-soft:#f5f5f5; --ui-ink:#111; --ui-muted:#333; color-scheme:light; background:white; color:#111; }
  .appearance-picker,.appearance-fallback { display:none!important; }
}

/* Public entry and lightweight account documents share the same device preference. */
:root[data-ui-theme] body > main { background-color:var(--ui-surface); color:var(--ui-ink); border-color:var(--ui-border); }
:root[data-ui-theme] body > main a:not(.button) { color:var(--ui-link); }
:root[data-ui-theme] body > main .notice { background:var(--ui-info-bg); color:var(--ui-info); }
:root[data-ui-theme] .public-header.merit-header { flex-wrap:wrap; }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) .public-site { background:var(--ui-canvas); color:var(--ui-ink); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) .public-site :is(.public-section,.public-tint,.public-empty,.public-footer,.public-trust-strip,.section-intro,.public-auth-card,.public-login-card,.public-header,.public-nav) { background:var(--ui-surface); color:var(--ui-ink); border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) .public-site :is(.feature-grid article,.intelligence-cards article,.readiness-grid article,.process-grid li,.signal-stack article,.tutor-copy,.board-canvas,.board-toolbar,.board-actions) { background:var(--ui-surface-soft); color:var(--ui-ink); border-color:var(--ui-border); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) .public-site :is(.public-section h2,.public-section h3,.public-section p,.public-section li,.public-section small,.public-nav a,.public-footer a) { color:var(--ui-ink); }
/* Legacy role selectors have higher specificity than standalone page styles. */
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body #main-content :is(.page-header h2,.page-header p,label,.filter-label) { color:var(--ui-ink)!important; }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body:not(.exam-focus) #app-header.merit-header :is(#sidebar-toggle,#workspace-back,.workspace-home) { background:var(--ui-header-control)!important; color:var(--ui-header-ink)!important; border-color:var(--ui-header-border)!important; }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body #main-content .student-demo-strip a { background:var(--ui-surface-raised)!important; color:var(--ui-link)!important; }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body.exam-focus #exam-current-question > .rendered { color:var(--ui-ink); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) body.exam-focus .exam-actions-row { background:var(--ui-surface); border-color:var(--ui-border); }

:root[data-ui-theme] body:not(.exam-focus) #app-header.merit-header #sidebar-toggle { color:var(--ui-header-ink)!important; }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) .public-site .public-cta { background:var(--ui-primary)!important; color:#fff!important; border-color:var(--ui-primary); }
:root:is([data-ui-theme="dark"],[data-ui-theme="semi-dark"]) .public-site .public-secondary { background:var(--ui-surface-raised)!important; color:var(--ui-ink)!important; border-color:var(--ui-border); }

:root[data-ui-theme] .public-site :is(button,a) { transition-property:transform,box-shadow; }
