/* =========================================================
   XevoNet — Theme system
   System-aware (prefers-color-scheme) with manual override via
   <html data-theme="light"> or <html data-theme="dark">.

   Cascade order (most specific wins):
     1.  :root                                      → light defaults
     2.  @media (prefers-color-scheme: dark) :root  → OS dark
     3.  :root[data-theme="light"]                  → manual light
     4.  :root[data-theme="dark"]                   → manual dark

   Anything that is forced (hero, scenes, footer) uses --force-*
   variables which stay constant across themes.
   ========================================================= */

/* ---------- 1.  Light defaults ---------- */
:root {
    color-scheme: light dark;

    /* App / page surfaces */
    --bg-base:        #fbfbfd;
    --bg-elev:        #ffffff;
    --bg-elev-2:      #f5f5f7;
    --bg-elev-3:      #e8e8ed;
    --bg-overlay:     rgba(255, 255, 255, 0.7);

    /* Ink */
    --txt:            #1d1d1f;
    --txt-dim:        #6e6e73;
    --txt-soft:       #86868b;
    --txt-faint:      rgba(0, 0, 0, 0.30);

    /* Hairlines */
    --hairline:       rgba(0, 0, 0, 0.10);
    --hairline-strong:rgba(0, 0, 0, 0.18);

    /* Marketing section variants
       .m-section.dark   → always black (forced)
       .m-section.lighter→ adapts to theme (light theme = white)
       .m-section.light  → adapts to theme (light theme = off-white) */
    --section-dark-bg:    #000000;
    --section-dark-ink:   #f5f5f7;
    --section-light-bg:   #fbfbfd;
    --section-lighter-bg: #ffffff;
    --section-darker-bg:  #000000;

    /* Liquid Glass material */
    --lg-tint:        rgba(255, 255, 255, 0.55);
    --lg-edge:        rgba(255, 255, 255, 0.55);
    --lg-edge-inner:  rgba(255, 255, 255, 0.85);
    --lg-edge-outer:  rgba(0, 0, 0, 0.06);
    --lg-spec:        rgba(255, 255, 255, 0.55);
    --lg-shadow:      0 1px 2px rgba(0, 0, 0, 0.06),
                      0 20px 40px -12px rgba(0, 0, 0, 0.15);
    --lg-blur:        24px;

    /* Accent (kept constant — purple feels right in both themes) */
    --accent:         #7c5cff;
    --accent-strong:  #6a48ff;
    --accent-soft:    rgba(124, 92, 255, 0.14);
    --accent-ink:     #ffffff;
}

/* ---------- 2.  OS dark default ---------- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-base:        #000000;
        --bg-elev:        #0a0a0c;
        --bg-elev-2:      #111114;
        --bg-elev-3:      #18181c;
        --bg-overlay:     rgba(0, 0, 0, 0.7);

        --txt:            #f5f5f7;
        --txt-dim:        rgba(245, 245, 247, 0.72);
        --txt-soft:       rgba(245, 245, 247, 0.5);
        --txt-faint:      rgba(245, 245, 247, 0.22);

        --hairline:       rgba(255, 255, 255, 0.08);
        --hairline-strong:rgba(255, 255, 255, 0.16);

        --section-light-bg:   #0a0a0c;
        --section-lighter-bg: #18181c;
        --section-darker-bg:  #000000;

        --lg-tint:        rgba(28, 28, 32, 0.55);
        --lg-edge:        rgba(255, 255, 255, 0.10);
        --lg-edge-inner:  rgba(255, 255, 255, 0.18);
        --lg-edge-outer:  rgba(0, 0, 0, 0.5);
        --lg-spec:        rgba(255, 255, 255, 0.10);
        --lg-shadow:      0 1px 2px rgba(0, 0, 0, 0.3),
                          0 20px 40px -12px rgba(0, 0, 0, 0.6);
    }
}

/* ---------- 3.  Manual override: light ---------- */
:root[data-theme="light"] {
    --bg-base:        #fbfbfd;
    --bg-elev:        #ffffff;
    --bg-elev-2:      #f5f5f7;
    --bg-elev-3:      #e8e8ed;
    --bg-overlay:     rgba(255, 255, 255, 0.7);

    --txt:            #1d1d1f;
    --txt-dim:        #6e6e73;
    --txt-soft:       #86868b;
    --txt-faint:      rgba(0, 0, 0, 0.30);

    --hairline:       rgba(0, 0, 0, 0.10);
    --hairline-strong:rgba(0, 0, 0, 0.18);

    --section-light-bg:   #fbfbfd;
    --section-lighter-bg: #ffffff;
    --section-darker-bg:  #000000;

    --lg-tint:        rgba(255, 255, 255, 0.55);
    --lg-edge:        rgba(255, 255, 255, 0.55);
    --lg-edge-inner:  rgba(255, 255, 255, 0.85);
    --lg-edge-outer:  rgba(0, 0, 0, 0.06);
    --lg-spec:        rgba(255, 255, 255, 0.55);
    --lg-shadow:      0 1px 2px rgba(0, 0, 0, 0.06),
                      0 20px 40px -12px rgba(0, 0, 0, 0.15);
}

/* ---------- 4.  Manual override: dark ---------- */
:root[data-theme="dark"] {
    --bg-base:        #000000;
    --bg-elev:        #0a0a0c;
    --bg-elev-2:      #111114;
    --bg-elev-3:      #18181c;
    --bg-overlay:     rgba(0, 0, 0, 0.7);

    --txt:            #f5f5f7;
    --txt-dim:        rgba(245, 245, 247, 0.72);
    --txt-soft:       rgba(245, 245, 247, 0.5);
    --txt-faint:      rgba(245, 245, 247, 0.22);

    --hairline:       rgba(255, 255, 255, 0.08);
    --hairline-strong:rgba(255, 255, 255, 0.16);

    --section-light-bg:   #0a0a0c;
    --section-lighter-bg: #18181c;
    --section-darker-bg:  #000000;

    --lg-tint:        rgba(28, 28, 32, 0.55);
    --lg-edge:        rgba(255, 255, 255, 0.10);
    --lg-edge-inner:  rgba(255, 255, 255, 0.18);
    --lg-edge-outer:  rgba(0, 0, 0, 0.5);
    --lg-spec:        rgba(255, 255, 255, 0.10);
    --lg-shadow:      0 1px 2px rgba(0, 0, 0, 0.3),
                      0 20px 40px -12px rgba(0, 0, 0, 0.6);
}

/* Body picks up theme automatically. */
body {
    background: var(--bg-base);
    color: var(--txt);
    transition: background 0.4s var(--ease-out, ease-out),
                color 0.4s var(--ease-out, ease-out);
}

/* =========================================================
   Theme toggle (sun / moon / auto-dot)
   ========================================================= */

.theme-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: transparent;
    border: 1px solid var(--hairline-strong);
    color: var(--txt);
    cursor: pointer;
    padding: 0;
    transition: background 0.25s ease, border-color 0.25s ease;
    font-family: inherit;
}
.theme-toggle:hover {
    background: var(--hairline);
}
.theme-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1),
                opacity 0.3s ease;
    position: absolute;
}
.theme-toggle .icon-sun     { opacity: 0; transform: scale(0.5) rotate(-90deg); }
.theme-toggle .icon-moon    { opacity: 0; transform: scale(0.5) rotate( 90deg); }
.theme-toggle .icon-auto    { opacity: 0; transform: scale(0.5);                }

/* Mode: light → show sun */
.theme-toggle[data-effective="light"] .icon-sun {
    opacity: 1; transform: scale(1) rotate(0);
}
.theme-toggle[data-effective="dark"]  .icon-moon {
    opacity: 1; transform: scale(1) rotate(0);
}
/* When set to "auto", reveal the small dot indicator next to the
   currently-effective icon. */
.theme-toggle[data-mode="auto"]::after {
    content: "";
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--bg-base);
}

.theme-toggle-tooltip {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-elev);
    color: var(--txt);
    border: 1px solid var(--hairline);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 200;
}
.theme-toggle:hover .theme-toggle-tooltip,
.theme-toggle:focus-visible .theme-toggle-tooltip {
    opacity: 1;
    transform: translateY(0);
}

/* Disable theme transitions on JS-driven instantaneous changes */
html.theme-flipping *,
html.theme-flipping *::before,
html.theme-flipping *::after {
    transition: none !important;
}
