:root {
    /* LIGHT MODE (Default) */
    --bg-app: #f1f5f9;
    --bg-card: #ffffff;
    --primary: #4f46e5;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --zip-color: #2563eb;
}

html.dark {
    /* DARK MODE */
    --bg-app: #0f172a;
    --bg-card: #1e293b;
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.3);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --zip-color: #3b82f6;
}

/* ===== COLOR THEMES ===== */
html.dark.theme-default {
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.3);
}

html.dark.theme-ocean {
    --primary: #0ea5e9;
    --primary-glow: rgba(14, 165, 233, 0.3);
}

html.dark.theme-emerald {
    --primary: #10b981;
    --primary-glow: rgba(16, 185, 129, 0.3);
}

html.dark.theme-sunset {
    --primary: #f97316;
    --primary-glow: rgba(249, 115, 22, 0.3);
}

html.dark.theme-rose {
    --primary: #f43f5e;
    --primary-glow: rgba(244, 63, 94, 0.3);
}

html.dark.theme-gold {
    --primary: #eab308;
    --primary-glow: rgba(234, 179, 8, 0.3);
}

/* Theme Store Modal */
.theme-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.theme-modal.show {
    opacity: 1;
    pointer-events: auto;
}

.theme-modal-content {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 1.5rem;
    max-width: 350px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--border);
}

.theme-modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.themes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 1rem;
}

.theme-card {
    aspect-ratio: 1;
    border-radius: 12px;
    cursor: pointer;
    border: 3px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: white;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    position: relative;
}

.theme-card:hover {
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.3);
}

.theme-card.active {
    border-color: white;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.theme-icon {
    font-size: 1.5rem;
}

.theme-name {
    font-size: 0.7rem;
    font-weight: 600;
}

.theme-check {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 0.8rem;
    background: white;
    color: #000;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-close-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.theme-close-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== BADGES ===== */
.badges-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 1rem;
}

.badge-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: all 0.2s;
}

.badge-card.locked {
    opacity: 0.5;
    filter: grayscale(1);
    border-style: dashed;
}

.badge-card.unlocked {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
}

.badge-icon {
    font-size: 2rem;
    margin-bottom: 5px;
    display: block;
}

.badge-name {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
}

.badge-desc {
    font-size: 0.65rem;
    color: var(--text-muted);
    line-height: 1.2;
    margin-top: 2px;
}

.badge-check {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 0.8rem;
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Achievement Toast */
.achievement-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 1100;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.achievement-toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    font-size: 2rem;
}

.toast-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
}

.toast-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overscroll-behavior-y: contain;
    /* Prevent pull-to-refresh on mobile */
}

/* Header */
.app-header {
    padding: 20px;
    text-align: center;
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0) 100%);
    position: relative;
}

/* Header buttons - Desktop (absolute positioning) */
.lang-switcher {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    gap: 6px;
}

.theme-toggler,
.sound-btn {
    position: absolute;
    top: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
}

.theme-toggler {
    right: 20px;
}

.sound-btn {
    right: 70px;
}

.app-title {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-main);
    text-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
}

.app-subtitle {
    margin: 5px 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Dashboard Grid */
.games-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding: 20px;
    max-width: 600px;
    margin: 0 auto;
}

.game-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    text-decoration: none;
    color: var(--text-main);
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
    overflow: hidden;
}

.game-card:active {
    transform: scale(0.96);
}

.game-card:hover {
    border-color: var(--primary);
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.game-card:hover .game-icon {
    transform: scale(1.1);
    transition: transform 0.2s;
}

/* Daily Banner Animation */
@keyframes glow {
    0% {
        box-shadow: 0 0 5px #6d28d9;
    }

    50% {
        box-shadow: 0 0 20px #8b5cf6;
    }

    100% {
        box-shadow: 0 0 5px #6d28d9;
    }
}

.daily-banner {
    animation: glow 3s infinite;
    transition: transform 0.2s;
}

.daily-banner:hover {
    transform: scale(1.02);
}

.game-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 10px;
}

.game-name {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.game-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Game Specific Styles (Shared) */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.game-header h1 {
    margin: 0;
    font-size: 1.2rem;
}

.back-btn,
.action-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.back-btn:hover,
.action-btn:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    color: var(--primary);
}

.action-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.4);
    transform: translateY(0);
}

.daily-mode-badge {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 6px rgba(245, 158, 11, 0.3);
    margin-bottom: 10px;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Modals */
.win-overlay,
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.win-overlay.show,
.tutorial-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.win-modal,
.tutorial-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    max-width: 90%;
    width: 320px;
}

.tutorial-modal {
    text-align: left;
}

.tutorial-title {
    font-size: 1.4rem;
    font-weight: 800;
    margin: 0 0 15px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tutorial-steps {
    margin: 0 0 20px 0;
    padding: 0 0 0 20px;
    color: #cbd5e1;
    line-height: 1.6;
}

.tutorial-steps li {
    margin-bottom: 10px;
}

.tutorial-img {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.win-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 10px;
    background: linear-gradient(to right, #60a5fa, #a855f7);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.win-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 12px 30px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 15px;
    width: 100%;
}

.win-btn:active {
    transform: scale(0.95);
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 20px 0;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Daily Banner */
.daily-banner {
    background: linear-gradient(135deg, #2e1065 0%, #4c1d95 100%);
    margin: 0 20px 20px;
    padding: 20px;
    border-radius: 16px;
    text-align: center;
    border: 1px solid #6d28d9;
}

.daily-title {
    color: #d8b4fe;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.daily-game {
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* Badge */
.badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #334155;
    color: #fff;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.badge.new {
    background: #ef4444;
}

.badge.soon {
    background: #0f172a;
    border: 1px solid #334155;
    color: #64748b;
}

.section-title {
    padding: 0 20px;
    margin: 20px 0 5px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Achievement Toast */
.achievement-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: linear-gradient(135deg, #6d28d9, #8b5cf6);
    color: white;
    padding: 15px 25px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 10px 40px rgba(109, 40, 217, 0.5);
    z-index: 10000;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.achievement-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.achievement-toast .toast-icon {
    font-size: 2rem;
}

.achievement-toast .toast-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.8;
}

.achievement-toast .toast-name {
    font-size: 1.1rem;
    font-weight: bold;
}

/* ======= ENHANCED DAILY BANNER ======= */
.daily-banner {
    margin: 0 20px 20px;
    padding: 20px;
    background: linear-gradient(135deg, #6d28d9 0%, #8b5cf6 50%, #a855f7 100%);
    border-radius: 20px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(139, 92, 246, 0.4);
}

.daily-badge {
    position: absolute;
    top: 10px;
    right: 15px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 1px;
}

.daily-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.daily-icon {
    font-size: 3rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.daily-info {
    flex: 1;
}

.daily-title {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.daily-game-name {
    color: white;
    font-size: 1.4rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
}

.daily-status {
    font-size: 0.8rem;
    font-weight: 600;
}

.daily-arrow {
    color: white;
    font-size: 2rem;
    opacity: 0.6;
    transition: transform 0.2s;
}

.daily-banner:hover .daily-arrow {
    transform: translateX(5px);
    opacity: 1;
}

/* ======= GAME CARD CHECKMARK ======= */
.game-card.played::after {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.5);
}

/* Modern Mode Buttons (Zip Style) */
.mode-selector {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 20px 0;
    width: 100%;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    min-width: 140px;
}

/* Random Mode Style */
.mode-btn.random {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
    border-color: rgba(59, 130, 246, 0.3);
}

.mode-btn.random:hover,
.mode-btn.random.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

/* Daily Mode Style */
.mode-btn.daily {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.3);
}

.mode-btn.daily:hover,
.mode-btn.daily.active {
    background: #f59e0b;
    color: white;
    border-color: #f59e0b;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
    transform: translateY(-2px);
}

/* Dark Mode Adjustments */
html.dark .mode-btn.random {
    background: rgba(30, 41, 59, 0.5);
    color: #60a5fa;
}

html.dark .mode-btn.daily {
    background: rgba(30, 41, 59, 0.5);
    color: #fbbf24;
}

/* Level Selector Buttons (Grid Size) */
.level-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 15px 0;
}

.level-btn {
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    min-width: 50px;
}

.level-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
}

.level-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

/* ========================================= */
/* MOBILE RESPONSIVE DESIGN */
/* ========================================= */

@media (max-width: 768px) {

    /* 1. Header Optimization */
    .app-header {
        display: grid !important;
        grid-template-areas:
            "lang sound theme"
            "title title title"
            "sub sub sub";
        grid-template-columns: 1fr auto auto;
        align-items: center;
        gap: 10px;
        padding-top: 15px;
        padding-bottom: 20px;
        text-align: center;
    }

    .lang-switcher {
        grid-area: lang;
        position: static !important;
        justify-content: flex-start !important;
        width: auto !important;
        left: auto !important;
        top: auto !important;
    }

    .sound-btn {
        grid-area: sound;
        position: static !important;
        top: auto !important;
        right: auto !important;
        margin: 0 !important;
    }

    .theme-toggler {
        grid-area: theme;
        position: static !important;
        top: auto !important;
        right: auto !important;
        margin: 0 !important;
    }

    .app-title {
        grid-area: title;
        margin-top: 5px;
        font-size: 1.5rem;
    }

    .app-subtitle {
        grid-area: sub;
        font-size: 0.8rem;
    }

    /* 2. Grid Optimization */
    .games-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 10px;
    }

    .game-card {
        padding: 15px;
    }

    .game-icon {
        font-size: 2rem;
        margin-bottom: 5px;
    }

    .game-name {
        font-size: 0.95rem;
    }

    .game-desc {
        font-size: 0.7rem;
    }

    /* 3. Floating Buttons & Safe Area */
    body {
        padding-bottom: 120px;
        /* Ensure content isn't hidden behind FABs */
    }

    .fab-container {
        bottom: 30px !important;
        right: 20px !important;
        gap: 12px !important;
    }

    .fab-container button {
        padding: 12px 20px !important;
        /* Smaller buttons */
        font-size: 0.9rem !important;
    }
}

/* Extra Small Screens */
@media (max-width: 380px) {
    .games-grid {
        grid-template-columns: 1fr;
        /* Single column for very narrow phones if needed, or keep 2 implies compact */
    }

    .app-title {
        font-size: 1.3rem;
    }
}