/* Memory Match Game Styles */

:root {
    --memory-primary: linear-gradient(135deg, #9333ea 0%, #ec4899 100%);
    --memory-secondary: linear-gradient(135deg, #8b5cf6 0%, #d946ef 100%);
    --card-shadow: 0 8px 20px rgba(147, 51, 234, 0.25);
}

body.game-page {
    background: linear-gradient(135deg, #9333ea 0%, #ec4899 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
}

body.game-page::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.12) 2px, transparent 2px);
    background-size: 40px 40px;
    animation: float 20s linear infinite;
    pointer-events: none;
    z-index: 0;
}

.game-main {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 2rem 0;
    position: relative;
    z-index: 1;
}

.navbar, footer {
    position: relative;
    z-index: 1;
}

/* Keep the overlay fixed to the viewport (the global fade-in-up animation
   applies a transform to the wrapper which otherwise creates a containing
   block for position: fixed children, causing a delayed darkening/jump). */
.game-page .game-card-wrapper.animate-fade-in-up {
    animation: fadeIn 0.45s ease-out;
    transform: none !important;
}

/* Game Card */
.game-card-wrapper {
    background: #1e293b;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    border: 4px solid #334155;
    position: relative;
}

.game-card-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 20px;
    padding: 4px;
    background: var(--memory-primary);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    z-index: 2;
}

/* Header / HUD */
.game-header {
    background: #0f172a;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #334155;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.game-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: #f8fafc;
    display: flex;
    align-items: center;
}

.game-stats {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.stat-pill {
    background: #1e293b;
    padding: 0.4rem 1rem;
    border-radius: 50px;
    border: 2px solid #334155;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #94a3b8;
}

.stat-value {
    font-size: 1rem;
    font-weight: 800;
    color: #e879f9;
}

/* Game Stage */
.game-stage-container {
    background: #0f172a;
    position: relative;
    padding: 2rem 1rem;
    min-height: 650px;
}

.memory-game-wrap {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    min-height: 500px;
}

.memory-board {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem;
}

/* Memory Cards */
.memory-card {
    aspect-ratio: 3/4;
    position: relative;
    cursor: pointer;
    perspective: 1000px;
    transition: transform 0.2s ease;
}

.memory-card:hover {
    transform: translateY(-5px);
}

.memory-card:focus {
    outline: 3px solid #ec4899;
    outline-offset: 4px;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--card-shadow);
    border: 3px solid rgba(255, 255, 255, 0.1);
}

.card-back {
    background: linear-gradient(135deg, #b21e2d 0%, #ef4444 100%);
    position: relative;
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.25s ease;
}

.card-back::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.05),
        rgba(255, 255, 255, 0.05) 10px,
        transparent 10px,
        transparent 20px
    );
}

.card-back-pattern {
    font-size: 3rem;
    color: rgba(255, 255, 255, 0.3);
    z-index: 1;
    position: relative;
}

.memory-card.flipped .card-back,
.memory-card.matched .card-back {
    opacity: 0;
    transition-delay: 0.18s; /* fade out after flip starts so it stays cohesive */
}

.card-front {
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
    transform: rotateY(180deg);
    position: absolute;
    top: 0;
    left: 0;
    padding: 0;
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.card-icon {
    font-size: 4rem;
}

/* Matched Cards */
.memory-card.matched {
    pointer-events: none;
}

.memory-card.matched .card-face {
    border-color: #4ade80;
    box-shadow: 0 0 20px rgba(74, 222, 128, 0.4);
}

.memory-card.matched .card-front {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    animation: matchPulse 0.5s ease;
}

@keyframes matchPulse {
    0%, 100% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.1); }
}

/* Shake Animation for Mismatch */
.memory-card.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* Overlay */
.game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem 1rem;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.overlay-content {
    background: white;
    padding: 2rem;
    border-radius: 24px;
    text-align: center;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    border: 4px solid #e2e8f0;
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.overlay-icon {
    font-size: 2.5rem;
    color: #9333ea;
    margin-bottom: 0.75rem;
    animation: float 3s ease-in-out infinite;
}

.overlay-title {
    font-size: 1.75rem;
    font-weight: 900;
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.overlay-subtitle {
    font-size: 1rem;
    color: #64748b;
    margin-bottom: 1.5rem;
}

/* Controls Guide */
.controls-guide {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    background: #f8fafc;
    padding: 1rem;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    flex-wrap: wrap;
}

.control-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: #64748b;
    font-size: 0.9rem;
}

.instruction-icon {
    font-size: 1.5rem;
    color: #9333ea;
}

.control-divider {
    font-weight: 800;
    color: #cbd5e1;
    font-size: 1.5rem;
}

/* Round Info */
.round-info {
    background: #f8fafc;
    padding: 0.875rem;
    border-radius: 12px;
    margin-bottom: 1.25rem;
    border: 2px solid #e2e8f0;
}

.round-info h3 {
    font-size: 1.25rem;
    font-weight: 800;
    color: #9333ea;
    margin-bottom: 0.25rem;
}

.round-info p {
    font-size: 0.95rem;
    color: #64748b;
    margin: 0;
}

/* Round Stats */
.round-stats {
    background: #f8fafc;
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    border: 2px solid #e2e8f0;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e2e8f0;
    font-size: 1.1rem;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row span:first-child {
    color: #64748b;
    font-weight: 600;
}

.stat-row span:last-child {
    color: #1e293b;
    font-weight: 800;
}

.stat-row-total {
    background: linear-gradient(135deg, #9333ea20 0%, #ec489920 100%);
    padding: 1rem;
    margin-top: 0.5rem;
    border-radius: 8px;
    border: 2px solid #9333ea40;
}

.stat-row-total span {
    font-size: 1.25rem;
}

.stat-row-total span:last-child {
    color: #9333ea;
}

/* Victory Screen Styles */
.victory-icon {
    color: #fbbf24;
    animation: victoryBounce 1s ease infinite;
}

@keyframes victoryBounce {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-15px) rotate(5deg); }
}

.victory-stats {
    background: #f8fafc;
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    border: 2px solid #e2e8f0;
}

.multiplier-row {
    background: linear-gradient(135deg, #fef3c720 0%, #fbbf2420 100%);
    padding: 0.75rem 1rem;
    margin: 0.5rem -0.5rem;
    border-radius: 8px;
    border: 2px solid #fbbf2440;
}

.multiplier-row span:last-child {
    color: #d97706;
    font-weight: 900;
}

/* Buttons */
.play-button {
    background: var(--memory-primary);
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.25rem;
    font-weight: 800;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 10px 20px rgba(147, 51, 234, 0.3);
    width: 100%;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.play-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 30px rgba(147, 51, 234, 0.4);
}

.play-button:active {
    transform: translateY(-1px);
}

.secondary-button {
    display: inline-block;
    color: #64748b;
    text-decoration: none;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: color 0.2s;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
}

.secondary-button:hover {
    color: #1e293b;
    background: #f1f5f9;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Footer Controls */
.game-footer {
    padding: 1rem 1.5rem;
    background: #0f172a;
    border-top: 2px solid #334155;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.back-link {
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: #f8fafc;
}

.game-controls-hint {
    font-size: 0.9rem;
    color: #94a3b8;
    display: flex;
    gap: 1rem;
}

.control-btn {
    background: #334155;
    color: #f1f5f9;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.control-btn:hover {
    background: #475569;
    transform: translateY(-2px);
    color: white;
}

.control-btn:active {
    transform: translateY(0);
}

/* Animations */
@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.pulse-animation {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(147, 51, 234, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(147, 51, 234, 0); }
    100% { box-shadow: 0 0 0 0 rgba(147, 51, 234, 0); }
}

/* Responsive */
@media (max-width: 768px) {
    .overlay-content {
        padding: 1.5rem;
        width: 95%;
    }
    
    .game-stage-container {
        min-height: 550px;
        padding: 1.5rem 1rem;
    }
    
    .game-header {
        padding: 0.75rem 1rem;
    }
    
    .game-title {
        font-size: 1.25rem;
    }
    
    .stat-pill {
        padding: 0.3rem 0.75rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .stat-value {
        font-size: 0.9rem;
    }
    
    .memory-board {
        grid-template-columns: repeat(6, 1fr);
        gap: 0.75rem;
        padding: 0.75rem;
    }
    
    .card-icon {
        font-size: 3rem;
    }
    
    .card-back-pattern {
        font-size: 2rem;
    }
    
    .game-footer {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .controls-guide {
        gap: 0.5rem;
        padding: 1rem;
    }
    
    .instruction-icon {
        font-size: 1.5rem;
    }
    
    .control-item {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .overlay-content {
        padding: 1.25rem;
        width: 95%;
    }
    
    .game-overlay {
        padding: 0.5rem;
    }
    
    .game-stage-container {
        padding: 1rem 0.5rem;
        min-height: 500px;
    }
    
    .memory-board {
        grid-template-columns: repeat(6, 1fr);
        gap: 0.5rem;
        padding: 0.5rem;
    }
    
    .card-icon {
        font-size: 2rem;
    }
    
    .overlay-title {
        font-size: 1.5rem;
    }
    
    .overlay-subtitle {
        font-size: 1rem;
    }
    
    .play-button {
        font-size: 1rem;
        padding: 0.875rem 2rem;
    }
    
    .round-stats {
        padding: 1rem;
    }
    
    .stat-row {
        font-size: 0.95rem;
        padding: 0.5rem 0;
    }
}
