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

body {
    font-family: Consolas, monospace;
    background-color: #1a1a1a;
    color: #ffffff;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.age-gate {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #1a1a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.age-gate-content {
    background-color: #2a2a2a;
    padding: 2rem;
    border-radius: 10px;
    text-align: center;
    max-width: 400px;
}

.age-gate-content h2 {
    margin-bottom: 1rem;
}

.age-gate-content button {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    margin-top: 1rem;
}

.game-container {
    max-width: 800px;
    width: 100%;
    height: 100vh;
    min-height: 600px;
    padding: 10px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background-color: #1a1a1a;
    overflow: hidden;
}

.game-header {
    text-align: center;
    margin-bottom: 5px;
    flex-shrink: 0;
    min-height: 100px;
    position: relative;
    z-index: 3;
    background-color: #1a1a1a;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding-top: 10px;
}

.game-header h1 {
    margin: 0;
    padding: 10px;
    position: relative;
    z-index: 3;
}

.game-stats {
    width: 100%;
    padding: 5px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 0;
    font-size: 1.2em;
    color: #fff;
    flex-shrink: 0;
    height: 30px;
    position: relative;
    z-index: 3;
    background-color: #1a1a1a;
}

.level-info {
    margin-top: 10px;
    font-size: 1.2rem;
}

.game-area {
    position: relative;
    width: 100%;
    flex: 1;
    background-color: #1a1a1a;
    border-radius: 10px;
    overflow: visible;
    margin: 30px 0 10px 0;
    display: flex;
    flex-direction: column;
}

#gameCanvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: 100%;
    width: auto;
    height: 100%;
    object-fit: contain;
    display: block;
    z-index: 1;
    background-color: #1a1a1a;
    opacity: 0;
    transition: opacity 2s ease;
}

#gameCanvas.visible {
    opacity: 1;
}

.puzzle-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 250px);
    background-color: #1a1a1a;
    padding: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 2s ease;
    pointer-events: auto;
    z-index: 2;
    overflow: visible;
}

.puzzle-container.fade-out {
    background-color: rgba(0, 0, 0, 0);
    pointer-events: none;
}

.puzzle {
    width: 100%;
    height: 100%;
    max-width: 900px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.memory-grid {
    width: min(100%, 75vh);
    aspect-ratio: 0.67;
    display: grid;
    gap: 8px;
    padding: 8px;
    grid-template-columns: repeat(4, 1fr);
    margin: 0 auto;
    position: relative;
    z-index: 2;
}

@media (max-width: 480px) {
    .memory-grid {
        width: 100%;
        gap: 4px;
        padding: 4px;
    }
    
    .memory-card {
        aspect-ratio: 1;
    }
    
    .memory-card .card-front,
    .memory-card .card-back {
        border-radius: 4px;
    }
}

.memory-card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s;
    cursor: pointer;
    aspect-ratio: 1;
}

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

.memory-card .card-front,
.memory-card .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 8px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
}

.memory-card .card-front {
    background-color: rgba(76, 175, 80, 0.8);
    color: white;
    font-size: 2rem;
}

.memory-card .card-back {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: #2196F3;
    backface-visibility: hidden;
    transform: rotateY(180deg);
    transition: background-color 0.5s ease;
}

.memory-card .card-back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: filter 0.5s ease;
}

.memory-card .card-back.darkened {
    background-color: #1a1a1a;
}

.memory-card .card-back img.darkened {
    filter: brightness(0.6);
}

.memory-card.matched .card-back {
    background-color: #1a1a1a;
}

.memory-card.matched .card-back img {
    filter: brightness(0.6);
    transition: filter 0.5s ease;
}

@keyframes matchedCardAnimation {
    0% { transform: scale(1) rotateY(180deg); }
    40% { transform: scale(1.1) rotateY(180deg); }
    100% { transform: scale(1) rotateY(180deg); }
}

.controls {
    margin-top: 5px;
    padding: 5px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-shrink: 0;
}

.controls button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    background-color: #4CAF50;
    color: white;
    min-width: 120px;
    transition: background-color 0.3s ease;
}

.controls button.start-over {
    background-color: #FFA500;
}

.controls button:disabled {
    background-color: #666;
    cursor: not-allowed;
}

.controls button:hover:not(:disabled) {
    background-color: #45a049;
}

.controls button.start-over:hover:not(:disabled) {
    background-color: #FF8C00;
}

.loading-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #fff;
    font-size: 1.2rem;
    background-color: #1a1a1a;
    border-radius: 10px;
    z-index: 9999;
}

.puzzle-container .loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: auto;
    height: auto;
    background-color: #1a1a1a;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes scatterCard {
    0% {
        transform: rotateY(180deg) translate(0, 0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: rotateY(180deg) translate(var(--scatter-x), var(--scatter-y)) rotate(var(--scatter-rotate));
        opacity: 0;
    }
}

.memory-card.scatter {
    animation: scatterCard 2.2s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
    pointer-events: none;
    z-index: 10;
}

/* Ensure matched cards stay flipped during scatter */
.memory-card.scatter .card-front {
    transform: rotateY(180deg);
}

.memory-card.scatter .card-back {
    transform: rotateY(0deg);
}

/* Keep the darkened state during scatter */
.memory-card.matched.scatter .card-back img.faded {
    filter: brightness(0.4);
}

/* Preserve existing animations */
.memory-card.matched {
    animation: matchedCardAnimation 1.2s ease forwards;
}

.memory-card.matched.scatter {
    animation: scatterCard 1.5s ease-in forwards;
}

.finale-container {
    background-color: #1a1a1a;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 101;
    pointer-events: auto;
}

.finale-container * {
    pointer-events: auto;
    position: relative;
}

.finale-container img {
    max-width: 90%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 10px;
    margin: 20px 0;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.finale-container h1 {
    font-size: 3em;
    margin: 0;
    animation: pulse 2s infinite;
}

.finale-container h2 {
    font-size: 2em;
    margin: 10px 0;
}

.finale-container button {
    margin-top: 20px;
    padding: 15px 30px;
    font-size: 1.2em;
    background: rgba(76, 175, 80, 0.8);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.finale-container button:hover {
    background: rgba(76, 175, 80, 1);
    transform: scale(1.05);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
} 