@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800&display=swap');

:root {
    --primary: #06b6d4;
    /* Cyan 500 */
    --primary-dark: #0891b2;
    --accent: #f59e0b;
    /* Amber 500 */
    --bg-dark: #0f172a;
    /* Slate 900 */
    --bg-light: #1e293b;
    /* Slate 800 */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --card-back-grad-1: #3b82f6;
    /* Blue 500 */
    --card-back-grad-2: #06b6d4;
    /* Cyan 500 */
    --card-matched: #10b981;
    /* Emerald 500 */

    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background: radial-gradient(circle at top, var(--bg-light), var(--bg-dark));
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.container {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    box-shadow: var(--glass-shadow);
    max-width: 900px;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Subtle glow effect behind container */
.container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(6, 182, 212, 0.1) 0%, transparent 70%);
    pointer-events: none;
    z-index: -1;
}

header {
    margin-bottom: 30px;
    text-align: center;
}

h1 {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -1px;
    background: linear-gradient(135deg, #fff, var(--primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 10px 30px rgba(6, 182, 212, 0.3);
    margin-bottom: 10px;
}

.games-hub-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1rem;
    border-radius: 999px;
    border: 1px solid rgba(6, 182, 212, 0.24);
    background: rgba(6, 182, 212, 0.1);
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.25s ease;
}

.games-hub-link:hover {
    transform: translateY(-2px);
    border-color: rgba(245, 158, 11, 0.35);
    background: rgba(245, 158, 11, 0.12);
    box-shadow: 0 10px 20px -10px rgba(6, 182, 212, 0.5);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    /* Allow wrap on very small screens, but aim for single line */
    gap: 10px;
    justify-content: center;
    align-items: flex-end;
    /* Align bottom to handle labels */
    margin-bottom: 20px;
    background: rgba(15, 23, 42, 0.5);
    padding: 15px;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}

label {
    font-size: 0.85rem;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

select,
button {
    width: auto;
    min-width: 80px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 2px solid var(--glass-border);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

select {
    background: var(--bg-dark);
    color: var(--text-main);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
}

select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.1);
}

button {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-weight: 700;
    border: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    height: 38px;
    /* Match height with select approximately */
    display: flex;
    align-items: center;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(6, 182, 212, 0.4);
}

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

/* Specific button styles override */
#sound-btn {
    width: 38px !important;
    padding: 0;
    justify-content: center;
    font-size: 1.1rem !important;
}

.stats-panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.stat-item {
    background: rgba(15, 23, 42, 0.6);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

#game-board {
    display: grid;
    gap: 12px;
    margin: 0 auto;
    justify-content: center;
    perspective: 1000px;
    padding: 20px;
}

/* Card Styling */
.card {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Bouncy transition */
    cursor: pointer;
    container-type: size;
}

/* Hover effect only for non-flipped cards */
.card:not(.flipped):hover {
    transform: translateY(-5px);
}

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    /* Rounder corners */
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    user-select: none;
    font-size: 60cqmin;
    /* Responsive Emoji Size */
}

/* Front Face (The Back of the card pattern) */
.card-front {
    background: linear-gradient(135deg, var(--card-back-grad-1), var(--card-back-grad-2));
    border: 2px solid rgba(255, 255, 255, 0.1);
}

/* Subtle pattern overlay */
.card-front::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(white 1px, transparent 1px);
    background-size: 10px 10px;
    opacity: 0.2;
}

/* Back Face (The Emoji) */
.card-back {
    background: white;
    transform: rotateY(180deg);
    border: 2px solid var(--primary);
}

.card.matched .card-back {
    background: var(--card-matched);
    border-color: var(--card-matched);
    animation: successPulse 0.5s ease-out forwards;
}

@keyframes successPulse {
    0% {
        transform: rotateY(180deg) scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        transform: rotateY(180deg) scale(1.1);
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }

    100% {
        transform: rotateY(180deg) scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Modal Styling */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

.modal-content {
    background: var(--bg-light);
    padding: 50px;
    border-radius: 24px;
    text-align: center;
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 400px;
    width: 90%;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal h2 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: var(--primary);
    font-weight: 800;
}

.modal p {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.stats-summary p {
    font-size: 1.2rem;
    color: var(--text-main);
    margin: 5px 0;
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

#close-modal {
    margin-top: 20px;
    width: auto;
    min-width: 200px;
    font-size: 1.1rem;
}

@media (max-width: 600px) {
    .container {
        padding: 20px;
    }

    h1 {
        font-size: 2rem;
    }

    .stats-panel {
        gap: 10px;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .card-front {
        border-width: 1px;
    }
}

/* Memory Matrix Styles */
.matrix-card {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: rgba(30, 64, 175, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2), 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.matrix-card:hover {
    transform: translateY(-2px);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2), 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

.matrix-card.memory-active {
    background: #ffffff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
    transform: scale(1.05);
}

.matrix-card.memory-correct {
    background: #ffffff;
    cursor: default;
    transform: scale(1);
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
}

.matrix-card.memory-wrong {
    background: #ef4444;
    border-color: #ef4444;
    cursor: default;
    animation: matrixShake 0.4s;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.6);
}

.matrix-card.memory-missed {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    cursor: default;
}

@keyframes matrixShake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    50% {
        transform: translateX(5px);
    }

    75% {
        transform: translateX(-5px);
    }

    100% {
        transform: translateX(0);
    }
}
