:root {
    --gold: #d4af37;
    --dark-gold: #b28a2b;
    --blood-red: #8a0303;
    --dark-bg: #0a0a0c;
    --glass-bg: rgba(20, 20, 25, 0.7);
    --glass-border: rgba(212, 175, 55, 0.3);
    --text-light: #f4ede4;
}

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

body {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--dark-bg);
    color: var(--text-light);
    overflow: hidden;
    position: relative;
}

.app-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Dark radial gradient imitating a torchlit room or stark dark fantasy theme */
    background: radial-gradient(circle at center, #2c1010 0%, #0a0a0c 70%);
    z-index: -2;
}

.game-container {
    width: 100%;
    max-width: 800px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    z-index: 1;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.6), inset 0 0 10px rgba(212, 175, 55, 0.1);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
}

.game-title {
    font-size: 2rem;
    color: var(--gold);
    text-transform: uppercase;
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
    letter-spacing: 2px;
}

.stats-container {
    display: flex;
    gap: 20px;
    align-items: center;
}

.stat-box {
    text-align: center;
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.8rem;
    color: #aaa;
    letter-spacing: 1px;
    text-transform: uppercase;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--gold), var(--dark-gold));
    color: var(--dark-bg);
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    border-radius: 4px;
    text-transform: uppercase;
    transition: all 0.3s ease;
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(212, 175, 55, 0.7);
}

.btn-primary:active {
    transform: translateY(1px);
}

.memory-game {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 15px;
    width: 640px;
    height: 640px;
    margin: 0 auto;
    perspective: 1000px;
}

.memory-card {
    position: relative;
    cursor: pointer;
    perspective: 1000px;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    border-radius: 8px;
}

.memory-card:hover .card-inner {
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
}

.memory-card:active .card-inner {
    transform: scale(0.95);
    transition: transform 0.1s;
}

.memory-card.flip .card-inner {
    transform: rotateY(180deg);
}

.memory-card.matched .card-inner {
    box-shadow: 0 0 25px rgba(100, 255, 100, 0.4);
    animation: matchPulse 1.5s infinite alternate;
}

@keyframes matchPulse {
    0% { box-shadow: 0 0 15px rgba(212, 175, 55, 0.4); }
    100% { box-shadow: 0 0 30px rgba(212, 175, 55, 0.8), inset 0 0 20px rgba(212, 175, 55, 0.5); }
}

.front-face,
.back-face {
    width: 100%;
    height: 100%;
    position: absolute;
    border-radius: 8px;
    backface-visibility: hidden;
    border: 2px solid var(--dark-gold);
    background: #1a1a1a;
    object-fit: contain;
    padding: 10px;
}

.front-face {
    transform: rotateY(180deg);
    background: radial-gradient(circle, #333, #111);
}

.back-face {
    background: url('img/back.jpg') center/cover;
    padding: 0;
    object-fit: cover;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.5s ease;
    backdrop-filter: blur(5px);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    padding: 50px;
    text-align: center;
    max-width: 500px;
    transform: scale(1);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.8);
}

.victory-title {
    font-size: 3rem;
    color: var(--gold);
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(212, 175, 55, 0.6);
}

.victory-message {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: #ccc;
}

.final-stats {
    font-size: 1.5rem;
    margin-bottom: 30px;
}

.final-stats p {
    margin: 10px 0;
}

.final-stats span {
    color: var(--gold);
    font-weight: bold;
}

@media (max-width: 700px) {
    .memory-game {
        width: 100%;
        max-width: 400px;
        height: auto;
        aspect-ratio: 1/1;
        grid-gap: 10px;
    }
    
    .game-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .game-title {
        font-size: 1.5rem;
    }
    
    .front-face, .back-face {
        padding: 5px;
    }
}
