/* Explain: Styles for the interactive glassmorphism theme toggle button. */
.theme-toggle {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 76px;
    height: 44px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.34);
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.26) 0%, rgba(255, 255, 255, 0.08) 44%, rgba(53, 184, 176, 0.24) 100%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    backdrop-filter: blur(18px) saturate(180%);
    box-shadow:
        0 16px 36px -18px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.55),
        inset 0 -1px 0 rgba(255, 255, 255, 0.12);
    cursor: pointer;
    overflow: hidden;
    isolation: isolate;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 680ms ease, box-shadow 680ms ease, background 680ms ease, transform 180ms ease;
}

.theme-toggle:hover {
    border-color: rgba(255, 255, 255, 0.56);
    box-shadow:
        0 18px 40px -16px rgba(0, 0, 0, 0.62),
        inset 0 1px 0 rgba(255, 255, 255, 0.65),
        0 0 22px -6px rgba(53, 184, 176, 0.5);
}

.theme-toggle:active {
    transform: scale(0.96);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
}

.theme-toggle::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(118deg, rgba(255, 255, 255, 0.40) 0%, rgba(255, 255, 255, 0) 48%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
    z-index: 4;
    opacity: 0.7;
}

/* ---------- Sky atmosphere ---------- */

.theme-toggle__sky {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 1;
}

.theme-toggle__day,
.theme-toggle__night {
    position: absolute;
    inset: 0;
    transition: opacity 720ms ease;
}

.theme-toggle__day {
    background: radial-gradient(circle at 76% 40%, rgba(255, 236, 176, 0.92), rgba(140, 216, 240, 0.62) 44%, rgba(74, 168, 214, 0.42) 82%);
    opacity: 0;
}

.theme-toggle__night {
    background: radial-gradient(circle at 24% 46%, rgba(122, 190, 226, 0.34), rgba(10, 34, 61, 0.72) 60%, rgba(6, 21, 40, 0.92) 100%);
    opacity: 1;
}

.theme-toggle[aria-checked="true"] .theme-toggle__day {
    opacity: 1;
}

.theme-toggle[aria-checked="true"] .theme-toggle__night {
    opacity: 0;
}

/* ---------- Daytime clouds ---------- */

.theme-toggle__cloud {
    position: absolute;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.55);
    opacity: 0;
    transition: opacity 720ms ease;
    z-index: 2;
}

.theme-toggle__cloud--a {
    width: 24px;
    height: 9px;
    top: 12px;
    left: 9px;
}

.theme-toggle__cloud--b {
    width: 16px;
    height: 7px;
    top: 23px;
    left: 18px;
}

.theme-toggle[aria-checked="true"] .theme-toggle__cloud--a {
    opacity: 0.92;
    animation: themeCloudA 8s ease-in-out infinite;
}

.theme-toggle[aria-checked="true"] .theme-toggle__cloud--b {
    opacity: 0.7;
    animation: themeCloudB 10s ease-in-out infinite;
}

/* ---------- Night stars ---------- */

.theme-toggle__star {
    position: absolute;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #EAF8FF;
    box-shadow: 0 0 6px rgba(206, 240, 255, 0.95);
    opacity: 0;
    z-index: 2;
}

.theme-toggle__star--a { top: 11px; right: 11px; }
.theme-toggle__star--b { top: 22px; right: 19px; width: 2px; height: 2px; }
.theme-toggle__star--c { top: 15px; right: 26px; width: 2px; height: 2px; }
.theme-toggle__star--d { top: 27px; right: 12px; width: 2.5px; height: 2.5px; }

.theme-toggle[aria-checked="false"] .theme-toggle__star {
    opacity: 0.9;
    animation: themeTwinkle 3.8s ease-in-out infinite;
}

.theme-toggle[aria-checked="false"] .theme-toggle__star--b { animation-delay: 0.6s; }
.theme-toggle[aria-checked="false"] .theme-toggle__star--c { animation-delay: 1.4s; }
.theme-toggle[aria-checked="false"] .theme-toggle__star--d { animation-delay: 2.1s; }

/* ---------- Knob with sun / moon ---------- */

.theme-toggle__knob {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: radial-gradient(circle at 34% 28%, #FFFFFF 0%, #D9EAF3 56%, #A6C4D6 100%);
    box-shadow:
        0 8px 18px -6px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        inset 0 -2px 4px rgba(11, 35, 56, 0.18);
    transition: transform 680ms cubic-bezier(0.34, 1.16, 0.42, 1), background 680ms ease, box-shadow 680ms ease;
    z-index: 3;
}

.theme-toggle[aria-checked="true"] .theme-toggle__knob {
    transform: translateX(34px);
    background: radial-gradient(circle at 34% 26%, #FFFDF0 0%, #FFD873 56%, #F0AC33 100%);
    box-shadow:
        0 8px 22px -4px rgba(255, 186, 72, 0.75),
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        inset 0 -2px 4px rgba(180, 116, 12, 0.25);
}

.theme-toggle__icon {
    position: absolute;
    font-size: 15px;
    line-height: 1;
    transition: opacity 460ms ease, transform 680ms cubic-bezier(0.34, 1.16, 0.42, 1);
}

.theme-toggle__icon--moon {
    color: #1C4A6A;
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.theme-toggle__icon--sun {
    color: #8A5A05;
    opacity: 0;
    transform: scale(0.35) rotate(-90deg);
}

.theme-toggle[aria-checked="true"] .theme-toggle__icon--moon {
    opacity: 0;
    transform: scale(0.35) rotate(90deg);
}

.theme-toggle[aria-checked="true"] .theme-toggle__icon--sun {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* ---------- Keyframes ---------- */

@keyframes themeCloudA {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(4px); }
}

@keyframes themeCloudB {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-3px); }
}

@keyframes themeTwinkle {
    0%, 100% { opacity: 0.35; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1.15); }
}

/* ---------- Compact screens ---------- */

@media (max-width: 480px) {
    .theme-toggle {
        width: 62px;
        height: 38px;
    }

    .theme-toggle__knob {
        width: 28px;
        height: 28px;
        top: 4px;
        left: 4px;
    }

    .theme-toggle[aria-checked="true"] .theme-toggle__knob {
        transform: translateX(26px);
    }

    .theme-toggle__icon {
        font-size: 13px;
    }

    .theme-toggle__cloud--a { width: 19px; height: 8px; top: 10px; left: 7px; }
    .theme-toggle__cloud--b { width: 13px; height: 6px; top: 20px; left: 14px; }
    .theme-toggle__star--c { display: none; }
}

/* ---------- Accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
    .theme-toggle,
    .theme-toggle__knob,
    .theme-toggle__icon,
    .theme-toggle__day,
    .theme-toggle__night,
    .theme-toggle__cloud,
    .theme-toggle__star {
        transition: none !important;
        animation: none !important;
    }
}