/* ============================================================================
   CSCA — colour themes (calm soft-dark set)
   Five palettes; remembered in localStorage["csca_theme"].
   Default: slate (sapphire). Legacy keys indigo/nebula map in theme.js.
   ========================================================================== */

html[data-theme="slate"],
html[data-theme="indigo"]{
  --th-1:#3d7bfd; --th-2:#2f63e0; --th-3:#7cc7fa; --th-4:#9fb0c7;
  --th-glow:#4f8ff7; --th-bg:#0a0d13; --text-tertiary:var(--th-4);
  --primary:#4f8ff7; --primary-strong:#3d7bfd; --secondary:#7fb0fa;
  --accent:#7cc7fa; --cyan:#7cc7fa; --emerald:#3fd9a4;
}
html[data-theme="ocean"],
html[data-theme="nebula"]{
  --th-1:#0284c7; --th-2:#0369a1; --th-3:#5ee9f0; --th-4:#93a8c4;
  --th-glow:#06b6d4; --th-bg:#06101a; --text-tertiary:var(--th-4);
  --primary:#06b6d4; --primary-strong:#0891b2; --secondary:#38bdf8;
  --accent:#5ee9f0; --cyan:#5ee9f0; --emerald:#2dd4bf;
}
html[data-theme="forest"]{
  --th-1:#059669; --th-2:#047857; --th-3:#7ef0c0; --th-4:#9cb4a7;
  --th-glow:#16b364; --th-bg:#08130d; --text-tertiary:var(--th-4);
  --primary:#16b364; --primary-strong:#0d9d58; --secondary:#3fd9a4;
  --accent:#7ef0c0; --cyan:#6ee7d8; --emerald:#3fd9a4;
}
html[data-theme="ember"]{
  --th-1:#f59e0b; --th-2:#d97706; --th-3:#ffd166; --th-4:#b3a494;
  --th-glow:#f6a609; --th-bg:#120c07; --text-tertiary:var(--th-4);
  --primary:#f6a609; --primary-strong:#dd8505; --secondary:#fbbf24;
  --accent:#ffd166; --cyan:#fde68a; --emerald:#34d399;
}
html[data-theme="crystal"]{
  --th-1:#7c6cf5; --th-2:#6554d9; --th-3:#b3a9ff; --th-4:#a3a3c7;
  --th-glow:#8b7ff2; --th-bg:#0a0a13; --text-tertiary:var(--th-4);
  --primary:#8b7ff2; --primary-strong:#7c6cf5; --secondary:#a99ffd;
  --accent:#b3a9ff; --cyan:#93c5fd; --emerald:#34d399;
}

html[data-theme] body{ background:var(--th-bg) !important; }
html[data-theme] body::before{
  background:
    radial-gradient(46% 40% at 80% 4%,  color-mix(in srgb, var(--th-glow) 16%, transparent) 0%, transparent 58%),
    radial-gradient(38% 34% at 10% 18%, color-mix(in srgb, var(--th-3) 10%, transparent) 0%, transparent 62%),
    radial-gradient(50% 44% at 50% 100%, color-mix(in srgb, var(--th-4) 12%, transparent) 0%, transparent 60%)
  !important;
  filter:blur(12px) !important;
}

html[data-theme] .g-btn:not(.ghost),
html[data-theme] .dashboard-hero-action,
html[data-theme] .dashboard-action,
html[data-theme] .start-btn,
html[data-theme] .side-cta,
html[data-theme] .tutor-button,
html[data-theme] .exam-btn.submit,
html[data-theme] .lesson-complete[aria-pressed="true"],
html[data-theme] .g-next-go,
html[data-theme] .c-lang button.on{
  background:var(--th-2) !important;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.18) !important;
  color:#fff !important;
}
html[data-theme="ember"] .g-btn:not(.ghost),
html[data-theme="ember"] .dashboard-hero-action,
html[data-theme="ember"] .dashboard-action,
html[data-theme="ember"] .start-btn,
html[data-theme="ember"] .side-cta,
html[data-theme="ember"] .tutor-button,
html[data-theme="ember"] .exam-btn.submit,
html[data-theme="ember"] .lesson-complete[aria-pressed="true"],
html[data-theme="ember"] .g-next-go,
html[data-theme="ember"] .c-lang button.on{ color:#1c1204 !important; }

html[data-theme] .g-tabs a.on,
html[data-theme] .dashboard-nav a.active,
html[data-theme] .nav-links a.active,
html[data-theme] .tab.on{
  background:color-mix(in srgb, var(--th-1) 22%, transparent) !important;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.14) !important; color:#fff !important;
}
html[data-theme] .filter-btn.active,
html[data-theme] .c-chip.on,
html[data-theme] .chip.acc{
  background:color-mix(in srgb, var(--th-1) 72%, transparent) !important;
  border-color:rgba(255,255,255,.18) !important; color:#fff !important;
}

html[data-theme] .g-bar i,
html[data-theme] .topic-fill,
html[data-theme] .progress-fill,
html[data-theme] .pbar i,
html[data-theme] .qprog i,
html[data-theme] .progress i{ background:var(--th-1) !important; }
html[data-theme] .g-sp path[stroke]{ stroke:var(--th-3) !important; }
html[data-theme] .g-sp path[fill]{ fill:var(--th-3) !important; opacity:.20; }
html[data-theme] .g-sp stop{ stop-color:var(--th-3) !important; }
html[data-theme] .g-bars i{
  background:color-mix(in srgb, var(--th-1) 80%, transparent) !important;
}
html[data-theme] .g-days i.on{
  background:var(--th-1) !important;
  box-shadow:none !important;
}
html[data-theme] #ring-progress{
  stroke:var(--th-1) !important;
  filter:none !important;
}
html[data-theme] .g-dot,
html[data-theme] .g-h2::before,
html[data-theme] .section-title::after,
html[data-theme] .c-group h2::before{
  background:var(--th-3) !important;
  box-shadow:none !important;
}
html[data-theme] .g-gem,
html[data-theme] .c-gem,
html[data-theme] .dashboard-brand-mark,
html[data-theme] .gem{
  background:var(--th-1) !important;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.28) !important;
}

/* crystal: light chrome only — reading surfaces stay solid */
html[data-theme="crystal"] :is(
  .g-top, .g-hero, .g-kpi, .g-card, .g-note, .g-search, .g-avatar,
  .g-snap > *, .g-act > *, .g-prog > *, .g-subj, .g-next,
  .main-nav, .side, .toc, .tutor-box, .qmap,
  .analytics-section, .profile-section, .stat-card, .setup-card,
  .quick-access-card, .dashboard-block, .dashboard-hero
){
  background:#12151d !important;
  border-color:rgba(255,255,255,.10) !important;
  backdrop-filter:blur(10px) saturate(110%) !important;
  -webkit-backdrop-filter:blur(10px) saturate(110%) !important;
  box-shadow:0 1px 0 rgba(255,255,255,.06) inset,0 8px 24px -14px rgba(0,0,0,.5) !important;
}
html[data-theme="crystal"] .g-subj-ic{
  background:rgba(255,255,255,.08) !important;
  border-color:rgba(255,255,255,.14) !important;
}
html[data-theme="crystal"] .g-bar{ background:rgba(255,255,255,.10) !important; }
html[data-theme="crystal"] .g-tabs a{ color:#94a3b8 !important; }
html[data-theme="crystal"] .g-k,
html[data-theme="crystal"] .g-desc,
html[data-theme="crystal"] .g-subj-main small,
html[data-theme="crystal"] :is(.snapshot-label,.stat-label,.info-label){ color:#94a3b8 !important; }
html[data-theme="crystal"] :is(.doc, .doc-body, .lesson-section, .qcard, .q-main, .question-option, .mi-row, .exam-bar){
  background-color:#0d0f15 !important;
}
html[data-theme="crystal"] :is(.question-option){ background-color:#11151f !important; }
html[data-theme="crystal"] body::before{
  background:
    radial-gradient(46% 40% at 76% 6%,  color-mix(in srgb, var(--th-1) 18%, transparent) 0%, transparent 58%),
    radial-gradient(40% 38% at 8% 22%,  color-mix(in srgb, var(--th-3) 10%, transparent) 0%, transparent 60%)
  !important;
  opacity:1 !important;
  filter:blur(12px) !important;
}

/* ── switcher ──────────────────────────────────────────────────────────── */
#theme-fab{
  position:fixed; inset-block-end:18px; inset-inline-start:18px; z-index:900;
  width:44px;height:44px;border-radius:12px;display:grid;place-items:center;cursor:pointer;
  background:#12151d;
  border:1px solid rgba(255,255,255,.12);
  backdrop-filter:blur(10px);
  box-shadow:0 8px 24px -12px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.10);
  color:#eaf2ff;transition:transform .18s ease;
}
#theme-fab:hover{transform:translateY(-2px)}
#theme-fab svg{width:19px;height:19px}
#theme-pop{
  position:fixed; inset-block-end:72px; inset-inline-start:18px; z-index:901;
  display:none;gap:9px;padding:11px;border-radius:14px;flex-wrap:wrap;max-width:196px;
  background:#12151d;border:1px solid rgba(255,255,255,.12);
  backdrop-filter:blur(10px);
  box-shadow:0 16px 36px -16px rgba(0,0,0,.85), inset 0 1px 0 rgba(255,255,255,.08);
}
#theme-pop.open{display:flex}
#theme-pop button{
  width:32px;height:32px;border-radius:10px;cursor:pointer;border:2px solid transparent;padding:0;
  transition:transform .15s ease;
}
#theme-pop button:hover{transform:translateY(-2px)}
#theme-pop button[aria-pressed="true"]{border-color:#fff;box-shadow:0 0 0 2px rgba(255,255,255,.22)}
#theme-pop button[data-theme-choice="slate"]{background:linear-gradient(135deg,#4f8ff7,#2f63e0)}
#theme-pop button[data-theme-choice="ocean"]{background:linear-gradient(135deg,#06b6d4,#0369a1 60%,#5ee9f0)}
#theme-pop button[data-theme-choice="forest"]{background:linear-gradient(135deg,#16b364,#047857)}
#theme-pop button[data-theme-choice="ember"]{background:linear-gradient(135deg,#f6a609,#d97706)}
#theme-pop button[data-theme-choice="crystal"]{background:linear-gradient(135deg,#b3a9ff,#7c6cf5 55%,#6554d9)}

@media (max-width:700px){
  #theme-fab{inset-block-end:14px;inset-inline-start:14px;width:40px;height:40px;border-radius:12px}
  #theme-pop{inset-block-end:62px;inset-inline-start:14px}
}
@media (prefers-reduced-motion:reduce){ #theme-fab,#theme-pop button{transition:none} }

/* The theme switcher must clear the phone tab bar: lift the button and its popover
   above it, and keep them clear of the home indicator. */
@media (max-width: 899px) {
  #theme-fab {
    inset-block-end: calc(var(--us-bar-h, 58px) + env(safe-area-inset-bottom, 0px) + 14px);
    inset-inline-start: 14px;
    width: 40px; height: 40px;
  }
  #theme-pop {
    inset-block-end: calc(var(--us-bar-h, 58px) + env(safe-area-inset-bottom, 0px) + 62px);
    inset-inline-start: 14px;
  }
}
