:root {
    /* Rich Modern Theme */
    --primary: #6366f1; /* Indigo */
    --primary-dark: #4338ca;
    --secondary: #ec4899; /* Pink */
    --accent: #14b8a6; /* Teal */
    --bg-gradient-start: #0f172a; /* Slate 900 */
    --bg-gradient-end: #1e1b4b; /* Indigo 950 */
    --surface: rgba(255, 255, 255, 0.05);
    --surface-hover: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc; /* Slate 50 */
    --text-muted: #cbd5e1; /* Slate 300 */
    
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-bg-gradient: linear-gradient(135deg, var(--primary), var(--secondary));
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 20px;
    overflow-x: hidden;
}

/* Add a dynamic background glowing orb */
body::before {
    content: '';
    position: fixed;
    top: -20%;
    left: -10%;
    width: 60%;
    height: 60%;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 60%);
    border-radius: 50%;
    z-index: -1;
    animation: pulse 10s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
}
body::after {
    content: '';
    position: fixed;
    bottom: -20%;
    right: -10%;
    width: 60%;
    height: 60%;
    background: radial-gradient(circle, rgba(236, 72, 153, 0.15) 0%, transparent 60%);
    border-radius: 50%;
    z-index: -1;
    animation: pulse 12s infinite alternate-reverse cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes pulse {
    0% { transform: scale(1) translate(0, 0); }
    100% { transform: scale(1.1) translate(30px, -30px); }
}

.container {
    max-width: 650px;
    width: 100%;
    position: relative;
    z-index: 1;
}

h1 {
    text-align: center;
    margin-bottom: 25px;
    font-size: 2.8rem;
    font-weight: 800;
    background: linear-gradient(to right, #a5b4fc, #fbcfe8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    letter-spacing: -0.5px;
}

/* Glassmorphism Panel */
.stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 25px;
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    padding: 15px 25px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-muted);
}

.stats div {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stats div > span {
    color: var(--text-main);
    font-size: 1.2rem;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    perspective: 1000px;
    margin-bottom: 30px;
}

.card {
    height: 120px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
    cursor: pointer;
    border-radius: 16px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 25px rgba(0, 0, 0, 0.2);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 16px;
    font-size: 3rem;
    border: 1px solid var(--glass-border);
}

.card-front {
    background-color: var(--card-bg);
    color: #1e293b;
    transform: rotateY(180deg);
    box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
}

.card-back {
    background: var(--card-bg-gradient);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    position: relative;
    overflow: hidden;
}

/* Inner glow for card back */
.card-back::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, transparent 50%);
    border-radius: 16px;
}

.card.flipped {
    transform: rotateY(180deg);
}

.card.matched {
    transform: rotateY(180deg) scale(0.95);
    box-shadow: 0 0 25px rgba(20, 184, 166, 0.5); /* Teal glow */
}

/* Hint flip */
.card.hint {
    box-shadow: 0 0 20px rgba(236, 72, 153, 0.5); /* Pink glow for hints */
}

.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

button {
    padding: 12px 28px;
    border: none;
    border-radius: 30px;
    background: var(--surface);
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    gap: 8px;
}

button:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

button:active {
    transform: translateY(0);
}

#restart-btn {
    background: linear-gradient(135deg, var(--secondary), #f43f5e);
    border-color: transparent;
}

#restart-btn:hover {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    box-shadow: 0 5px 20px rgba(244, 63, 94, 0.4);
}

.level-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    background: var(--surface);
    padding: 6px;
    border-radius: 30px;
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
}

.level-btn {
    padding: 8px 20px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    box-shadow: none;
}

.level-btn:hover {
    background: transparent;
    color: var(--text-main);
    box-shadow: none;
    transform: none;
}

.level-btn.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    max-width: 450px;
    width: 90%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    animation: scaleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes scaleIn {
    to { transform: scale(1); }
}

.modal h2 {
    color: #fbcfe8;
    margin-bottom: 20px;
    font-size: 2.2rem;
    font-weight: 800;
}

.modal p {
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: var(--text-muted);
}

.modal p span {
    color: var(--text-main);
    font-weight: 700;
}

.leaderboard {
    margin-top: 30px;
    margin-bottom: 30px;
    text-align: left;
    background: rgba(0,0,0,0.2);
    border-radius: 16px;
    padding: 20px;
}

.leaderboard h3 {
    text-align: center;
    margin-bottom: 15px;
    color: var(--accent);
    font-weight: 600;
    font-size: 1.2rem;
}

.leaderboard-list {
    list-style: none;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.95rem;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-item span:last-child {
    color: var(--accent);
    font-weight: 700;
}

#play-again-btn {
    width: 100%;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    padding: 15px;
    font-size: 1.1rem;
    border-color: transparent;
}

#play-again-btn:hover {
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

/* Floating scores animation */
.score-float {
    position: absolute;
    color: var(--accent);
    font-weight: 800;
    font-size: 1.5rem;
    z-index: 10;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
    pointer-events: none;
    animation: floatUp 1s ease-out forwards;
}

@keyframes floatUp {
    0% { opacity: 0; transform: translateY(10px) scale(0.8); }
    20% { opacity: 1; transform: translateY(0) scale(1.1); }
    100% { opacity: 0; transform: translateY(-40px) scale(1); }
}

footer {
    margin-top: 40px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    opacity: 0.7;
}

@media (max-width: 550px) {
    .game-board {
        gap: 8px;
    }
    .card { height: 90px; border-radius: 12px; }
    .card-face { font-size: 2rem; border-radius: 12px; }
    h1 { font-size: 2.2rem; }
}

@media (max-width: 380px) {
    .game-board { gap: 6px; }
    .stats { flex-direction: column; align-items: center; gap: 10px; }
    .card { height: 75px; border-radius: 8px; }
    .card-face { font-size: 1.5rem; border-radius: 8px; }
}
