/* ================================================================
   K-12 Theme System
   Scoped to `body.k12-scope` — won't affect any non-K12 pages.
   Controlled via [data-k12-theme] and [data-k12-mode] attributes.

   Themes: minimalstudy, classroom, softpastel, academic, nature
   Modes:  light, dark
   ================================================================ */

/* ---- Theme variables ---- */

body.k12-scope[data-k12-theme="minimalstudy"][data-k12-mode="light"] {
    --k12-bg:          #ffffff;
    --k12-surface:     #f9fafb;
    --k12-surface-2:   #f3f4f6;
    --k12-text:        #111827;
    --k12-text-muted:  #6b7280;
    --k12-text-faint:  #9ca3af;
    --k12-primary:     #4f46e5;
    --k12-primary-soft:#eef2ff;
    --k12-accent:      #10b981;
    --k12-border:      #d1d5db; /* gray-300 — one step darker than before for clearer separation */
    --k12-border-soft: #e5e7eb; /* gray-200 */
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(99,102,241,0.08) 0%, transparent 60%);
}
body.k12-scope[data-k12-theme="minimalstudy"][data-k12-mode="dark"] {
    --k12-bg:          #0a0a0a;
    --k12-surface:     #171717;
    --k12-surface-2:   #262626;
    --k12-text:        #f4f4f5;
    --k12-text-muted:  #a1a1aa;
    --k12-text-faint:  #71717a;
    --k12-primary:     #818cf8;
    --k12-primary-soft:rgba(129,140,248,0.12);
    --k12-accent:      #34d399;
    --k12-border:      #27272a;
    --k12-border-soft: #1f1f23;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(129,140,248,0.12) 0%, transparent 65%);
}

body.k12-scope[data-k12-theme="classroom"][data-k12-mode="light"] {
    --k12-bg:          #fefce8;
    --k12-surface:     #fffbea;
    --k12-surface-2:   #fef3c7;
    --k12-text:        #1c1917;
    --k12-text-muted:  #57534e;
    --k12-text-faint:  #a8a29e;
    --k12-primary:     #65a30d;
    --k12-primary-soft:#ecfccb;
    --k12-accent:      #d97706;
    --k12-border:      #e7e5d4;
    --k12-border-soft: #faf7e5;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(101,163,13,0.12) 0%, transparent 60%);
}
body.k12-scope[data-k12-theme="classroom"][data-k12-mode="dark"] {
    --k12-bg:          #1c1917;
    --k12-surface:     #292524;
    --k12-surface-2:   #44403c;
    --k12-text:        #fef3c7;
    --k12-text-muted:  #d6d3d1;
    --k12-text-faint:  #a8a29e;
    --k12-primary:     #84cc16;
    --k12-primary-soft:rgba(132,204,22,0.15);
    --k12-accent:      #f59e0b;
    --k12-border:      #44403c;
    --k12-border-soft: #292524;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(132,204,22,0.15) 0%, transparent 60%);
}

body.k12-scope[data-k12-theme="softpastel"][data-k12-mode="light"] {
    --k12-bg:          #fdf4ff;
    --k12-surface:     #faf5ff;
    --k12-surface-2:   #f3e8ff;
    --k12-text:        #3b0764;
    --k12-text-muted:  #6b21a8;
    --k12-text-faint:  #a855f7;
    --k12-primary:     #a855f7;
    --k12-primary-soft:#f3e8ff;
    --k12-accent:      #ec4899;
    --k12-border:      #e9d5ff;
    --k12-border-soft: #f3e8ff;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(168,85,247,0.12) 0%, transparent 60%);
}
body.k12-scope[data-k12-theme="softpastel"][data-k12-mode="dark"] {
    --k12-bg:          #1e1033;
    --k12-surface:     #2d1b4a;
    --k12-surface-2:   #4c1d95;
    --k12-text:        #fce7f3;
    --k12-text-muted:  #e9d5ff;
    --k12-text-faint:  #c084fc;
    --k12-primary:     #c084fc;
    --k12-primary-soft:rgba(192,132,252,0.15);
    --k12-accent:      #f472b6;
    --k12-border:      #4c1d95;
    --k12-border-soft: #2d1b4a;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(192,132,252,0.18) 0%, transparent 65%);
}

body.k12-scope[data-k12-theme="academic"][data-k12-mode="light"] {
    --k12-bg:          #fafafa;
    --k12-surface:     #ffffff;
    --k12-surface-2:   #f4f4f5;
    --k12-text:        #0f172a;
    --k12-text-muted:  #475569;
    --k12-text-faint:  #94a3b8;
    --k12-primary:     #1e40af;
    --k12-primary-soft:#dbeafe;
    --k12-accent:      #7c3aed;
    --k12-border:      #e2e8f0;
    --k12-border-soft: #f1f5f9;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(30,64,175,0.08) 0%, transparent 60%);
}
body.k12-scope[data-k12-theme="academic"][data-k12-mode="dark"] {
    --k12-bg:          #0f172a;
    --k12-surface:     #1e293b;
    --k12-surface-2:   #334155;
    --k12-text:        #f1f5f9;
    --k12-text-muted:  #cbd5e1;
    --k12-text-faint:  #94a3b8;
    --k12-primary:     #60a5fa;
    --k12-primary-soft:rgba(96,165,250,0.15);
    --k12-accent:      #a78bfa;
    --k12-border:      #334155;
    --k12-border-soft: #1e293b;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(96,165,250,0.12) 0%, transparent 65%);
}

body.k12-scope[data-k12-theme="nature"][data-k12-mode="light"] {
    --k12-bg:          #f0fdf4;
    --k12-surface:     #dcfce7;
    --k12-surface-2:   #bbf7d0;
    --k12-text:        #14532d;
    --k12-text-muted:  #166534;
    --k12-text-faint:  #4ade80;
    --k12-primary:     #15803d;
    --k12-primary-soft:#dcfce7;
    --k12-accent:      #a16207;
    --k12-border:      #bbf7d0;
    --k12-border-soft: #dcfce7;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(21,128,61,0.12) 0%, transparent 60%);
}
body.k12-scope[data-k12-theme="nature"][data-k12-mode="dark"] {
    --k12-bg:          #0f2027;
    --k12-surface:     #14332a;
    --k12-surface-2:   #166534;
    --k12-text:        #d1fae5;
    --k12-text-muted:  #86efac;
    --k12-text-faint:  #4ade80;
    --k12-primary:     #4ade80;
    --k12-primary-soft:rgba(74,222,128,0.15);
    --k12-accent:      #fbbf24;
    --k12-border:      #166534;
    --k12-border-soft: #14332a;
    --k12-hero:        radial-gradient(ellipse at 50% 0%, rgba(74,222,128,0.15) 0%, transparent 60%);
}

/* ---- Apply variables to the page ---- */

body.k12-scope[data-k12-theme] {
    background: var(--k12-bg) !important;
    color: var(--k12-text) !important;
    transition: background-color 0.2s ease, color 0.2s ease;
}
body.k12-scope[data-k12-theme] .hero-bg {
    background: var(--k12-hero) !important;
}

/* Re-theme the most common dark-utility patterns used across K12 pages.
   These cascade into tool cards, hero sections, cards, badges. */
body.k12-scope[data-k12-theme] .bg-white\/5,
body.k12-scope[data-k12-theme] .bg-white\/\[0\.03\],
body.k12-scope[data-k12-theme] .bg-white\/\[0\.04\],
body.k12-scope[data-k12-theme] .bg-white\/\[0\.05\],
body.k12-scope[data-k12-theme] .bg-white\/\[0\.06\],
body.k12-scope[data-k12-theme] .bg-black\/20 {
    background-color: var(--k12-surface) !important;
}
body.k12-scope[data-k12-theme] .bg-white\/10,
body.k12-scope[data-k12-theme] .bg-white\/15,
body.k12-scope[data-k12-theme] .bg-white\/20 {
    background-color: var(--k12-surface-2) !important;
}
body.k12-scope[data-k12-theme] .border-white\/5,
body.k12-scope[data-k12-theme] .border-white\/\[0\.06\],
body.k12-scope[data-k12-theme] .border-white\/\[0\.08\],
body.k12-scope[data-k12-theme] .border-white\/10 {
    border-color: var(--k12-border) !important;
}
body.k12-scope[data-k12-theme] .border-white\/15,
body.k12-scope[data-k12-theme] .border-white\/20 {
    border-color: var(--k12-border-soft) !important;
}

/* Text color overrides — common Tailwind white-alpha patterns */
body.k12-scope[data-k12-theme] .text-white,
body.k12-scope[data-k12-theme] .text-white\/90 {
    color: var(--k12-text) !important;
}
body.k12-scope[data-k12-theme] .text-white\/80,
body.k12-scope[data-k12-theme] .text-white\/70,
body.k12-scope[data-k12-theme] .text-gray-200,
body.k12-scope[data-k12-theme] .text-gray-300 {
    color: var(--k12-text) !important;
}
body.k12-scope[data-k12-theme] .text-white\/60,
body.k12-scope[data-k12-theme] .text-white\/50,
body.k12-scope[data-k12-theme] .text-gray-400,
body.k12-scope[data-k12-theme] .text-gray-500 {
    color: var(--k12-text-muted) !important;
}
body.k12-scope[data-k12-theme] .text-white\/40,
body.k12-scope[data-k12-theme] .text-white\/30,
body.k12-scope[data-k12-theme] .text-gray-600 {
    color: var(--k12-text-faint) !important;
}

/* Primary / accent color hints */
body.k12-scope[data-k12-theme] .text-indigo-400,
body.k12-scope[data-k12-theme] .text-indigo-300,
body.k12-scope[data-k12-theme] .text-brand-400 {
    color: var(--k12-primary) !important;
}
body.k12-scope[data-k12-theme] .text-emerald-400 {
    color: var(--k12-accent) !important;
}

/* ---- Navbar overrides ----
   The main dashboard navbar uses `.navbar-glass` with a hardcoded dark
   background. Recolor it to match the active K12 theme. Light modes get a
   light glass background; dark modes keep a dark one in the theme's hue.
*/
body.k12-scope[data-k12-theme][data-k12-mode="light"] .navbar-glass {
    background: rgba(255, 255, 255, 0.85) !important;
    border-bottom: 1px solid var(--k12-border) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
body.k12-scope[data-k12-theme][data-k12-mode="dark"] .navbar-glass {
    /* Tinted dark using the theme's surface color so it matches the page */
    background: color-mix(in srgb, var(--k12-bg) 85%, transparent) !important;
    border-bottom: 1px solid var(--k12-border) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* Navbar content — logo icon, links, icons all need the theme's text color */
body.k12-scope[data-k12-theme] #mainNav .nav-logo-text,
body.k12-scope[data-k12-theme] #mainNav .nav-link,
body.k12-scope[data-k12-theme] #mainNav button {
    color: var(--k12-text) !important;
}
body.k12-scope[data-k12-theme] #mainNav .nav-link:hover,
body.k12-scope[data-k12-theme] #mainNav button:hover {
    background-color: var(--k12-surface-2) !important;
}
body.k12-scope[data-k12-theme] #mainNav .nav-logo-icon {
    background: var(--k12-primary-soft) !important;
    color: var(--k12-primary) !important;
}
body.k12-scope[data-k12-theme] #mainNav .nav-logo-icon i {
    color: var(--k12-primary) !important;
}
/* User dropdown panel */
body.k12-scope[data-k12-theme] #userDropdown,
body.k12-scope[data-k12-theme] .dropdown-dark {
    background: var(--k12-surface) !important;
    border: 1px solid var(--k12-border) !important;
    color: var(--k12-text) !important;
}
body.k12-scope[data-k12-theme] #userDropdown a,
body.k12-scope[data-k12-theme] #userDropdown button {
    color: var(--k12-text) !important;
}
body.k12-scope[data-k12-theme] #userDropdown a:hover {
    background-color: var(--k12-surface-2) !important;
}

/* Footer — same fixed-dark treatment needs retheming too */
body.k12-scope[data-k12-theme] footer {
    background: var(--k12-surface) !important;
    border-top: 1px solid var(--k12-border) !important;
    color: var(--k12-text-muted) !important;
}

/* ---- Theme picker (floating bottom-right) ---- */

#k12ThemePicker {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 999;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--k12-surface, rgba(255,255,255,0.95));
    border: 1px solid var(--k12-border, rgba(0,0,0,0.1));
    border-radius: 9999px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 0.75rem;
    color: var(--k12-text, #111);
    backdrop-filter: blur(8px);
}
#k12ThemePicker select,
#k12ThemePicker button {
    background: transparent;
    border: none;
    color: inherit;
    font-size: inherit;
    cursor: pointer;
    outline: none;
    font-weight: 600;
}
#k12ThemePicker select {
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    background: var(--k12-primary-soft, #eee);
}
#k12ThemePicker button.k12-mode-btn {
    width: 1.75rem;
    height: 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    background: var(--k12-primary-soft, #eee);
}
#k12ThemePicker button.k12-mode-btn:hover {
    background: var(--k12-surface-2, #ddd);
}
#k12ThemePicker .k12-picker-label {
    color: var(--k12-text-muted, #666);
    font-weight: 500;
    padding-left: 0.25rem;
}
#k12ThemePicker .k12-picker-sep {
    width: 1px;
    height: 1.25rem;
    background: var(--k12-border, rgba(0,0,0,0.12));
    margin: 0 0.25rem;
}
#k12ThemePicker input[type="text"] {
    width: 10rem;
    padding: 0.25rem 0.65rem;
    border-radius: 9999px;
    background: var(--k12-primary-soft, #eee);
    color: var(--k12-text, #111);
    font-size: inherit;
    font-family: inherit;
    font-weight: 500;
    border: 1px solid var(--k12-border, rgba(0,0,0,0.1));
    outline: none;
}
#k12ThemePicker input[type="text"]::placeholder {
    color: var(--k12-text-faint, #999);
    font-weight: 400;
}
#k12ThemePicker input[type="text"]:focus {
    border-color: var(--k12-primary, #4f46e5);
}
@media (max-width: 768px) {
    #k12ThemePicker {
        /* On narrow screens the picker gets crowded — wrap onto 2 lines */
        flex-wrap: wrap;
        max-width: calc(100vw - 2rem);
    }
    #k12ThemePicker input[type="text"] {
        width: 7rem;
    }
}
