/* ==========================================================================
   Dark Mode Theme - joshuawwy.com
   Aesthetic: "Warm Evening Light" - deep espresso tones, not cold blacks
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Variables - Dark Mode Override
   -------------------------------------------------------------------------- */
html[data-theme="dark"], html[data-theme="dark"] * {
    /* Backgrounds - warm charcoal/espresso tones */
    --cream: #1C1815 !important;
    --warm-white: #252220 !important;

    /* Accent colors - slightly brightened for dark background contrast */
    --terracotta: #D4815A !important;
    --terracotta-light: #E8A882 !important;
    --sage: #8FB592 !important;
    --sage-light: #3D5240 !important;
    --soft-brown: #A08970 !important;

    /* Text - warm off-whites */
    --text-dark: #E8E2DC !important;
    --text-muted: #A89B8C !important;

    /* Decorative colors - muted for dark mode */
    --peach: #3D2E26 !important;
    --lavender: #2E2835 !important;
    --gold: #D4B87A !important;
    --gold-light: #4A4030 !important;

    /* Semantic colors - adjusted for dark backgrounds */
    --red-muted: #D4685A !important;
    --green-muted: #6A9A6E !important;
}

/* CSS-only fallback for users with JS disabled */
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]), html:not([data-theme="light"]) * {
        --cream: #1C1815 !important;
        --warm-white: #252220 !important;
        --terracotta: #D4815A !important;
        --terracotta-light: #E8A882 !important;
        --sage: #8FB592 !important;
        --sage-light: #3D5240 !important;
        --soft-brown: #A08970 !important;
        --text-dark: #E8E2DC !important;
        --text-muted: #A89B8C !important;
        --peach: #3D2E26 !important;
        --lavender: #2E2835 !important;
        --gold: #D4B87A !important;
        --gold-light: #4A4030 !important;
        --red-muted: #D4685A !important;
        --green-muted: #6A9A6E !important;
    }
}

/* --------------------------------------------------------------------------
   Paper Texture Overlay
   -------------------------------------------------------------------------- */
[data-theme="dark"] body::before {
    opacity: 0.015;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) body::before {
        opacity: 0.015;
    }
}

/* --------------------------------------------------------------------------
   Floating Blobs - Subtler in dark mode
   -------------------------------------------------------------------------- */
[data-theme="dark"] .blob {
    opacity: 0.06;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .blob {
        opacity: 0.06;
    }
}

/* --------------------------------------------------------------------------
   Card Shadows - Darker, more diffused
   -------------------------------------------------------------------------- */
[data-theme="dark"] .tool-card:hover {
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .comparison-hero-card:hover {
    box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .related-card:hover {
    box-shadow: 0 8px 20px -8px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .comparison-table {
    box-shadow: 0 4px 20px -8px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .cta-button {
    box-shadow: 0 4px 15px -5px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .cta-button:hover {
    box-shadow: 0 8px 25px -8px rgba(0, 0, 0, 0.5);
}

/* --------------------------------------------------------------------------
   Borders - Use inverted opacity
   -------------------------------------------------------------------------- */
[data-theme="dark"] footer {
    border-top-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .resources-section {
    border-top-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .resource-category h3 {
    border-bottom-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .resource-category.apps h3 {
    border-bottom-color: var(--sage);
}

[data-theme="dark"] .resource-category.tuition h3 {
    border-bottom-color: var(--gold);
}

[data-theme="dark"] .resource-category.comparisons h3 {
    border-bottom-color: var(--lavender);
}

[data-theme="dark"] .related-card {
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .fair-section {
    border-color: rgba(255, 255, 255, 0.1);
}

/* --------------------------------------------------------------------------
   Table Rows - Alternating backgrounds
   -------------------------------------------------------------------------- */
[data-theme="dark"] .table-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

/* --------------------------------------------------------------------------
   Gradient Sections
   -------------------------------------------------------------------------- */
[data-theme="dark"] .problem-section {
    background: linear-gradient(135deg, #2A2420 0%, #1C1815 100%);
}

[data-theme="dark"] .benefits-section {
    background: linear-gradient(135deg, #1E2820 0%, #1C1815 100%);
}

[data-theme="dark"] .highlight-box {
    background: linear-gradient(135deg, #2A2518 0%, #1C1815 100%);
}

[data-theme="dark"] .cost-calculator {
    border-color: rgba(201, 168, 108, 0.2);
}

[data-theme="dark"] .cta-section {
    border-color: var(--sage-light);
}

/* --------------------------------------------------------------------------
   Cost Bar Wrappers
   -------------------------------------------------------------------------- */
[data-theme="dark"] .cost-bar-wrapper {
    background: rgba(255, 255, 255, 0.05);
}

/* --------------------------------------------------------------------------
   Resource Links Hover
   -------------------------------------------------------------------------- */
[data-theme="dark"] .resource-links a:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* --------------------------------------------------------------------------
   Badge Colors
   -------------------------------------------------------------------------- */
[data-theme="dark"] .badge.free {
    background: var(--sage-light);
    color: var(--sage);
}

[data-theme="dark"] .badge.paid {
    background: var(--gold-light);
    color: var(--gold);
}

/* --------------------------------------------------------------------------
   Comparison Hero Cards - Borders
   -------------------------------------------------------------------------- */
[data-theme="dark"] .comparison-hero-card.anki {
    border-color: var(--sage);
}

[data-theme="dark"] .comparison-hero-card.hellochinese {
    border-color: rgba(0, 188, 212, 0.4);
}

[data-theme="dark"] .comparison-hero-card.duchainese {
    border-color: rgba(255, 193, 7, 0.4);
}

[data-theme="dark"] .comparison-hero-card.skritter {
    border-color: rgba(255, 152, 0, 0.4);
}

[data-theme="dark"] .comparison-hero-card.chineseskill {
    border-color: rgba(76, 175, 80, 0.4);
}

[data-theme="dark"] .comparison-hero-card.berries {
    border-color: rgba(233, 30, 140, 0.4);
}

[data-theme="dark"] .comparison-hero-card.wang {
    border-color: rgba(30, 58, 138, 0.4);
}

[data-theme="dark"] .comparison-hero-card.tienhsia {
    border-color: rgba(139, 0, 0, 0.4);
}

/* --------------------------------------------------------------------------
   Theme Toggle Button
   -------------------------------------------------------------------------- */
.theme-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 100;
}

.theme-toggle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--soft-brown);
    background: var(--warm-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    padding: 0;
}

.theme-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .theme-toggle:hover {
    box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.5);
}

.theme-toggle:focus {
    outline: none;
}

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

.theme-toggle-icon {
    position: absolute;
    width: 22px;
    height: 22px;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.theme-toggle-icon svg {
    width: 100%;
    height: 100%;
    fill: var(--soft-brown);
    display: block;
}

/* Light mode: show sun, hide moon */
.theme-toggle-icon.sun {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.theme-toggle-icon.moon {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

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

[data-theme="dark"] .theme-toggle-icon.moon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* CSS-only fallback for toggle icons */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle-icon.sun {
        opacity: 0;
        transform: rotate(90deg) scale(0.5);
    }

    :root:not([data-theme="light"]) .theme-toggle-icon.moon {
        opacity: 1;
        transform: rotate(0deg) scale(1);
    }
}

/* --------------------------------------------------------------------------
   Language Switcher in Theme Controls
   -------------------------------------------------------------------------- */
.theme-controls .lang-switcher {
    position: static;
    top: auto;
    right: auto;
    margin-bottom: 0;
}

/* --------------------------------------------------------------------------
   Mobile Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .theme-controls {
        position: relative;
        top: 0;
        right: 0;
        justify-content: center;
        margin-bottom: 1rem;
    }

    .theme-controls .lang-switcher {
        text-align: center;
    }

    .theme-toggle {
        width: 40px;
        height: 40px;
    }

    .theme-toggle-icon {
        width: 20px;
        height: 20px;
    }
}

/* --------------------------------------------------------------------------
   Smooth Transitions for Theme Change
   -------------------------------------------------------------------------- */
html {
    transition: background-color 0.3s ease;
}

body,
.tool-card,
.comparison-hero-card,
.comparison-table,
.problem-section,
.benefits-section,
.cta-section,
.resource-category,
.resource-links a,
.related-card,
.fair-section,
.cost-calculator,
footer {
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

h1, h2, h3, p, span, a, li {
    transition: color 0.3s ease;
}

.blob {
    transition: opacity 0.3s ease;
}
