/* ==========================================================================
   Theme Toggle — lean component styles only.
   Token definitions (--text-primary, shadows, color-scheme, etc.) live in
   themes.css. This file owns only the toggle button and transition helpers.
   ========================================================================== */

/* ── No-transition helper (applied by JS during theme switch) ───────────── */
html.no-theme-transition,
html.no-theme-transition *,
html.no-theme-transition *::before,
html.no-theme-transition *::after {
    transition: none !important;
}

/* ── Smooth theme transition (applied by JS during switch) ──────────────── */
html.theme-transitioning body,
html.theme-transitioning .navbar,
html.theme-transitioning .navbar-menu,
html.theme-transitioning .navbar-menu a,
html.theme-transitioning .card,
html.theme-transitioning .container,
html.theme-transitioning .container-card,
html.theme-transitioning section,
html.theme-transitioning footer,
html.theme-transitioning .footer-main,
html.theme-transitioning .blog-card,
html.theme-transitioning .tutorial-card,
html.theme-transitioning .project-card,
html.theme-transitioning .hero,
html.theme-transitioning .tutorials-hero,
html.theme-transitioning input,
html.theme-transitioning textarea,
html.theme-transitioning select,
html.theme-transitioning .theme-toggle-btn {
    transition:
        background-color var(--ease-base),
        color var(--ease-base),
        border-color var(--ease-base),
        box-shadow var(--ease-base) !important;
}

/* ── Toggle button ──────────────────────────────────────────────────────── */
.theme-toggle-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    margin: 0 var(--sp-2);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: var(--text-lg);
    line-height: 1;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    transition:
        color var(--ease-base),
        background-color var(--ease-base),
        border-color var(--ease-base),
        transform var(--ease-base);
    flex-shrink: 0;
    order: 0;
}

.theme-toggle-btn:hover {
    color: var(--primary);
    background-color: var(--primary-bg-subtle);
    border-color: var(--primary-border-subtle);
}

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

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

/* ── Icon container ─────────────────────────────────────────────────────── */
.theme-toggle-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.theme-icon-sun,
.theme-icon-moon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity var(--ease-base), transform var(--ease-base);
    line-height: 1;
}

/* Default state: moon visible, sun hidden */
.theme-icon-sun  { opacity: 0; }
.theme-icon-moon { opacity: 1; }

/* Dark theme: show sun, hide moon */
html[data-theme="dark"] .theme-icon-sun  { opacity: 1; transform: translate(-50%, -50%) rotate(0deg) scale(1); }
html[data-theme="dark"] .theme-icon-moon { opacity: 0; transform: translate(-50%, -50%) rotate(90deg) scale(0.5); }

/* Light theme: show moon, hide sun */
html[data-theme="light"] .theme-icon-moon { opacity: 1; transform: translate(-50%, -50%) rotate(0deg) scale(1); }
html[data-theme="light"] .theme-icon-sun  { opacity: 0; transform: translate(-50%, -50%) rotate(-90deg) scale(0.5); }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 950px) {
    .theme-toggle-btn {
        width: 44px;
        height: 44px;
        margin: 0 var(--sp-1);
        order: 0;
    }
}

/* ── Forced colors (Windows high-contrast) ──────────────────────────────── */
@media (forced-colors: active) {
    .theme-toggle-btn {
        border: 1px solid ButtonText;
    }
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .theme-toggle-btn,
    .theme-icon-sun,
    .theme-icon-moon {
        transition: none !important;
    }

    html.theme-transitioning *,
    html.theme-transitioning *::before,
    html.theme-transitioning *::after {
        transition: none !important;
    }
}

/* ── Print ──────────────────────────────────────────────────────────────── */
@media print {
    .theme-toggle-btn {
        display: none !important;
    }
}
