:root {
    --bg: #020617;
    --surface: rgba(30, 41, 59, 0.8);
    --text: #f8fafc;
    --primary: #6366f1;
    --success: #10b981;
    --danger: #ef4444;
    --card-back: #1e293b;
}

[data-theme="light"] {
    --bg: #f8fafc;
    --surface: rgba(255, 255, 255, 0.9);
    --text: #0f172a;
    --primary: #4f46e5;
    --card-back: #cbd5e1;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    transition: background 0.4s;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- NAVIGATION & STATS (Responsive Layout) --- */
.navbar {
    display: flex;
    flex-direction: column; 
    background: var(--surface);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 10px 1rem;
}

.nav-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 10px;
}

.nav-left { font-weight: 800; font-size: 1.1rem; }
.nav-left span { color: var(--primary); }
.nav-center { font-weight: 700; color: var(--primary); font-size: 0.9rem; letter-spacing: 1px; }

.theme-btn {
    background: none;
    border: 1px solid rgba(128,128,128,0.3);
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    color: var(--text);
}

.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
}

.stat {
    background: rgba(0, 0, 0, 0.2);
    padding: 6px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.05);
}

.stat span { display: block; font-size: 0.55rem; text-transform: uppercase; opacity: 0.7; }
.stat b { font-size: 0.95rem; font-weight: 700; }

.warning-box.active b { color: var(--danger); animation: pulse 0.8s infinite; }

/* --- MAIN GAME AREA --- */
.game-area {
    flex: 1;
    display: flex;
    align-items: center; 
    justify-content: center;
    padding: 20px 10px;
}

/* --- GRID SYSTEM --- */
.grid {
    display: grid;
    gap: 10px;
    margin: 0 auto;
    justify-content: center;
}

.grid-l1 { grid-template-columns: repeat(3, 1fr); width: 90vw; max-width: 300px; }
.grid-l2 { grid-template-columns: repeat(4, 1fr); width: 90vw; max-width: 400px; }
.grid-l3 { grid-template-columns: repeat(4, 1fr); width: 90vw; max-width: 420px; }
.grid-l4 { grid-template-columns: repeat(4, 1fr); width: 90vw; max-width: 450px; }

.card { height: 90px; cursor: pointer; perspective: 1000px; }
.card-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: 0.5s; }
.card.flipped .card-inner { transform: rotateY(180deg); }

.front, .back {
    position: absolute; width: 100%; height: 100%; backface-visibility: hidden;
    border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 2.2rem;
}
.front { background: var(--card-back); border: 1px solid rgba(255,255,255,0.1); }
.back { background: var(--primary); transform: rotateY(180deg); color: white; }

.card.matched .back { background: var(--success); box-shadow: 0 0 15px var(--success); }

/* --- DESKTOP REFINEMENT (1024px+) --- */
@media (min-width: 1024px) {
    .navbar {
        flex-direction: row; 
        justify-content: space-between;
        height: 70px;
        padding: 0 10%; 
    }
    .nav-top-row { width: auto; margin-bottom: 0; gap: 3rem; }
    .stats-bar { width: auto; grid-template-columns: repeat(3, 110px); gap: 1.5rem; }
    .stat { padding: 8px 15px; background: rgba(255, 255, 255, 0.03); }
    .stat b { font-size: 1.1rem; }
    .card { height: 110px; }
}

@keyframes rainbow { 0% { filter: hue-rotate(0deg); } 100% { filter: hue-rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

.rainbow-mode { animation: rainbow 5s linear infinite; }

.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.9); align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal-content { background: var(--surface); padding: 3rem; border-radius: 30px; text-align: center; border: 2px solid var(--primary); max-width: 400px; width: 100%; }
.badge { font-size: 4.5rem; margin-bottom: 1rem; }
button#modal-btn { background: var(--primary); color: white; border: none; padding: 14px 40px; border-radius: 12px; font-weight: 800; cursor: pointer; margin-top: 15px; }