:root {
    --bg-dark: #0f172a;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --primary: #818cf8;
    --primary-glow: rgba(129, 140, 248, 0.4);
    --accent: #f472b6;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --card-back: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --card-front: rgba(255, 255, 255, 0.1);
    
    --font-family: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--bg-gradient);
    color: var(--text-main);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Background Aesthetics */
.background-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    z-index: -1;
    animation: float 20s infinite alternate ease-in-out;
}

.orb-1 {
    width: 40vw;
    height: 40vw;
    background: var(--primary);
    top: -10%;
    left: -10%;
}

.orb-2 {
    width: 35vw;
    height: 35vw;
    background: var(--accent);
    bottom: -10%;
    right: -10%;
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0); }
    100% { transform: translate(30px, 50px); }
}

/* Layout */
.game-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    max-width: 1200px;
}

/* Header / HUD */
.hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    margin-bottom: 1rem;
    flex-shrink: 0;
    z-index: 10;
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.highlight {
    color: var(--primary);
}

.stats {
    display: flex;
    gap: 1.5rem;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.value {
    font-size: 1.25rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* Game Board */
.game-board-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 1rem;
}

.game-grid {
    display: grid;
    gap: 1rem;
    width: 100%;
    height: 100%;
    max-width: 600px;
    max-height: 600px;
    /* Grid template columns will be set by JS based on difficulty */
    perspective: 1000px;
}

/* Cards */
.card {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
    cursor: pointer;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card:hover {
    transform: scale(1.02);
}

/* When flipped, rotate Y */
.card.flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    user-select: none;
    border: 1px solid var(--glass-border);
}

.card-front {
    background: var(--card-back);
    /* Front is actually the back pattern before flip */
}

.card-back {
    background: rgba(255, 255, 255, 0.1);
    transform: rotateY(180deg);
    backdrop-filter: blur(5px);
    /* Back is the content revealed after flip */
}

.card.matched .card-back {
    background: rgba(129, 140, 248, 0.2);
    box-shadow: 0 0 15px var(--primary-glow);
    animation: pulse-match 0.5s ease-out;
}

@keyframes pulse-match {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.1); }
    100% { transform: rotateY(180deg) scale(1); }
}

/* UI Overlays / Modals */
.ui-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: rgba(30, 41, 59, 0.7);
    padding: 2.5rem;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: center;
    max-width: 90%;
    width: 400px;
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.icon-wrapper {
    margin-bottom: 1.5rem;
}

.giant-emoji {
    font-size: 4rem;
    filter: drop-shadow(0 0 20px rgba(255,255,255,0.2));
}

.modal h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: #fff;
}

.modal p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* Difficulty Select */
.difficulty-select {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 2rem;
}

.diff-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 0.75rem 1.25rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-family);
    font-weight: 500;
}

.diff-btn:hover {
    background: rgba(255,255,255,0.05);
    color: #fff;
}

.diff-btn.selected {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
}

/* CTA Button */
.cta-btn {
    background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 10px 15px -3px rgba(99, 102, 241, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: var(--font-family);
}

.cta-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05), 0 0 20px var(--primary-glow);
}

.cta-btn:active {
    transform: translateY(0);
}

/* Final Stats in Game Over */
.final-stats {
    background: rgba(0,0,0,0.2);
    border-radius: 16px;
    padding: 1rem;
    margin-bottom: 2rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: var(--text-muted);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row span:last-child {
    color: #fff;
    font-weight: 700;
}

.highlight-row span {
    color: var(--accent) !important;
    font-size: 1.1rem;
}

/* Responsive & Orientation adjustments */

/* Mobile Portrait */
@media (max-width: 600px) {
    .game-grid {
        gap: 0.5rem;
    }
    .hud {
        padding: 0.75rem;
    }
    .brand h1 { font-size: 1.25rem; }
    .value { font-size: 1rem; }
}

/* Landscape Mode on Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .game-wrapper {
        flex-direction: row;
        padding: 0.5rem;
    }
    
    .hud {
        flex-direction: column;
        width: 120px;
        margin-bottom: 0;
        margin-right: 1rem;
        padding: 1rem 0.5rem;
        justify-content: center;
        gap: 1rem;
    }
    
    .stats {
        flex-direction: column;
        gap: 1rem;
    }
    
    .brand h1 {
        font-size: 1rem;
        text-align: center;
    }
    
    .game-board-container {
        padding: 0;
    }
    
    .game-grid {
        height: 90vh;
        width: 90vh; /* Make it square-ish based on height */
    }
}
