/* ==========================================================================
   GAME STYLE & VARIABLE SYSTEM (DEEP SPACE INDIGO & NEON CYAN THEME)
   ========================================================================== */
:root {
    --color-bg-deep: #070412;
    --color-card-bg: rgba(22, 18, 46, 0.65);
    --color-border: rgba(0, 242, 254, 0.12);
    --color-text-main: #f0ebfc;
    --color-text-muted: #9ba1c6;
    
    /* Neon Accents */
    --accent-cyan: 185, 100%, 50%;   /* #00f2fe */
    --accent-purple: 268, 80%, 65%; /* #a25cfa */
    --accent-gold: 42, 100%, 60%;    /* #ffa502 */
    --accent-green: 145, 80%, 55%;  /* #2ed573 */
    --accent-pink: 335, 100%, 65%;   /* #ff416c */
    
    /* Shadows & Transitions */
    --shadow-neon: 0 0 15px hsla(var(--accent-cyan), 0.3);
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    --transition-smooth: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Noto Sans SC', 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--color-bg-deep);
    color: var(--color-text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    overflow-x: hidden;
    position: relative;
    padding: 20px;
}

/* ==========================================================================
   PARALLAX STARRY BACKGROUND
   ========================================================================== */
.stars-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(circle at center, #11092b 0%, #030107 100%);
}

/* Simulated small stars using dynamic box-shadows */
.stars {
    position: absolute;
    width: 1px;
    height: 1px;
    background: transparent;
    border-radius: 50%;
}

.stars-small {
    box-shadow: 
        120px 450px #fff, 340px 120px #fff, 890px 432px #fff, 1200px 890px rgba(255,255,255,0.7),
        450px 760px #fff, 900px 120px rgba(255,255,255,0.8), 120px 980px #fff, 670px 320px #fff,
        1500px 340px #fff, 1340px 650px #fff, 780px 890px rgba(255,255,255,0.5), 1120px 210px #fff,
        250px 310px #fff, 860px 670px #fff, 540px 920px rgba(255,255,255,0.6), 1430px 120px #fff;
    width: 1px;
    height: 1px;
    animation: twinkle 4s infinite alternate;
}

.stars-medium {
    box-shadow: 
        300px 500px hsla(var(--accent-cyan), 0.5), 700px 200px hsla(var(--accent-purple), 0.6), 
        1100px 600px hsla(var(--accent-pink), 0.5), 400px 800px hsla(var(--accent-cyan), 0.7), 
        950px 300px hsla(var(--accent-purple), 0.5), 150px 700px hsla(var(--accent-pink), 0.4),
        1300px 150px hsla(var(--accent-cyan), 0.6), 800px 900px hsla(var(--accent-purple), 0.7);
    width: 2.5px;
    height: 2.5px;
    animation: twinkle 6s infinite alternate-reverse;
}

.stars-large {
    box-shadow: 
        200px 200px hsla(var(--accent-cyan), 0.4), 850px 700px hsla(var(--accent-purple), 0.4),
        1250px 450px hsla(var(--accent-gold), 0.35), 600px 400px hsla(var(--accent-pink), 0.35);
    width: 4px;
    height: 4px;
    filter: blur(1px);
    animation: twinkle 8s infinite alternate 1s;
}

@keyframes twinkle {
    0% { opacity: 0.3; transform: translateY(0); }
    100% { opacity: 1; transform: translateY(-10px); }
}

/* ==========================================================================
   APP SHELL CONTAINER & GLASS CARDS
   ========================================================================== */
.game-container {
    width: 100%;
    max-width: 620px;
    margin-top: 4vh;
    margin-bottom: 4vh;
    z-index: 10;
}

.panel {
    background: var(--color-card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--color-border);
    border-radius: 28px;
    padding: 36px 44px;
    box-shadow: var(--shadow-glass);
    display: none;
    opacity: 0;
    transform: scale(0.96);
}

.panel.active {
    display: flex;
    flex-direction: column;
    animation: zoomInShow 0.55s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

/* ==========================================================================
   1. WELCOME SCREEN
   ========================================================================== */
.logo-area {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.logo-svg {
    width: 72px;
    height: 72px;
    color: hsl(var(--accent-cyan));
    filter: drop-shadow(0 0 12px hsla(var(--accent-cyan), 0.5));
}

.game-title {
    font-size: 2.5rem;
    font-weight: 800;
    text-align: center;
    background: linear-gradient(135deg, #ffffff 30%, hsla(var(--accent-cyan), 0.9) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 6px;
    letter-spacing: 2px;
}

.game-subtitle {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    color: var(--color-text-muted);
    text-align: center;
    margin-bottom: 32px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.intro-box {
    font-size: 0.98rem;
    line-height: 1.8;
    color: var(--color-text-main);
    background: rgba(255, 255, 255, 0.03);
    border-left: 3px solid hsl(var(--accent-cyan));
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 36px;
    text-align: justify;
}

.intro-box p {
    margin-bottom: 10px;
}

.intro-box p:last-child {
    margin-bottom: 0;
}

/* Buttons Styling */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 36px;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 16px;
    border: none;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, hsl(var(--accent-purple)) 0%, hsl(var(--accent-cyan)) 100%);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(162, 92, 250, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(162, 92, 250, 0.5), 0 0 10px hsla(var(--accent-cyan), 0.35);
}

.btn-glow {
    position: relative;
    overflow: hidden;
}

.btn-glow::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.18) 0%, transparent 60%);
    transform: scale(0);
    transition: transform 0.6s ease-out;
}

.btn-glow:hover::after {
    transform: scale(1);
}

.btn-outline {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: hsla(var(--accent-cyan), 0.4);
    transform: translateY(-2px);
}

.btn-icon {
    transition: transform 0.3s ease;
}

.btn:hover .btn-icon {
    transform: translateX(4px);
}

/* ==========================================================================
   2. GAME BOARD SCREEN
   ========================================================================== */
.board-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--color-border);
    padding: 14px 24px;
    border-radius: 18px;
    margin-bottom: 24px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: #ffffff;
}

.btn-icon-only {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    transition: var(--transition-smooth);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-only:hover {
    color: hsl(var(--accent-cyan));
    background: rgba(0, 242, 254, 0.08);
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   GRID CARD CONTAINER & 3D CARDS
   ========================================================================== */
.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 30px;
}

.card {
    aspect-ratio: 1;
    perspective: 1000px;
    cursor: pointer;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.175, 0.885, 0.32, 1.25);
}

/* Flip state */
.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    transition: var(--transition-smooth);
}

/* Card Back (Face Down) */
.card-back {
    background: radial-gradient(circle at center, #1b1542 0%, #0c0822 100%);
    box-shadow: inset 0 0 10px rgba(0, 242, 254, 0.15);
}

.card-back::after {
    content: '?';
    font-family: 'Outfit', sans-serif;
    font-size: 1.8rem;
    font-weight: 600;
    color: rgba(0, 242, 254, 0.3);
    text-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
    transition: var(--transition-smooth);
}

.card:hover .card-back {
    border-color: hsla(var(--accent-cyan), 0.4);
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.25), inset 0 0 12px rgba(0, 242, 254, 0.2);
}

.card:hover .card-back::after {
    color: hsl(var(--accent-cyan));
    transform: scale(1.1);
    text-shadow: 0 0 15px hsla(var(--accent-cyan), 0.5);
}

/* Card Front (Revealed Symbol) */
.card-front {
    background: rgba(255, 255, 255, 0.03);
    transform: rotateY(180deg);
    font-size: 2.2rem;
    box-shadow: var(--shadow-glass);
}

/* Matched Card State (Pulsing Glow) */
.card.matched .card-front {
    background: rgba(46, 213, 115, 0.08);
    border-color: hsla(var(--accent-green), 0.5);
    box-shadow: 0 0 20px rgba(46, 213, 115, 0.25);
    animation: matchPulse 0.6s ease-in-out;
}

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

/* Bottom Actions */
.board-footer {
    display: flex;
    gap: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 24px;
}

.board-footer .btn {
    flex: 1;
}

/* ==========================================================================
   3. WIN MODAL DIALOG
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 3, 15, 0.85);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: radial-gradient(circle at top, #231942 0%, #0d0922 100%);
    border: 1px solid rgba(162, 92, 250, 0.3);
    border-radius: 28px;
    padding: 40px;
    width: 90%;
    max-width: 440px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(162, 92, 250, 0.2);
    text-align: center;
    transform: translateY(30px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.win-icon {
    font-size: 3.5rem;
    margin-bottom: 18px;
    filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.5));
    animation: floatTrophy 2s infinite ease-in-out;
}

@keyframes floatTrophy {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(4deg); }
}

.modal-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: #ffffff;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.modal-desc {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

.summary-box {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 18px;
    padding: 16px 20px;
    margin-bottom: 28px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
}

.sum-label {
    color: var(--color-text-muted);
}

.sum-val {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: #ffffff;
}

.ranking-text {
    font-size: 1.15rem;
    color: hsl(var(--accent-gold)) !important;
    text-shadow: 0 0 10px rgba(255, 165, 0, 0.4);
}

.modal-actions {
    display: flex;
    gap: 16px;
}

.modal-actions .btn {
    flex: 1;
}

/* ==========================================================================
   APP FOOTER
   ========================================================================== */
.app-footer {
    text-align: center;
    margin-top: 4vh;
    padding: 12px;
    z-index: 10;
}

.app-footer p {
    font-size: 0.8rem;
    color: rgba(155, 161, 198, 0.25);
    letter-spacing: 0.5px;
}

/* ==========================================================================
   RESPONSIVE DESIGN MEDIA QUERIES
   ========================================================================== */
@media (max-width: 500px) {
    body {
        padding: 12px;
    }
    
    .game-container {
        margin-top: 2vh;
        margin-bottom: 2vh;
    }

    .panel {
        padding: 24px 20px;
        border-radius: 20px;
    }
    
    .game-title {
        font-size: 2rem;
    }
    
    .game-subtitle {
        font-size: 0.95rem;
        margin-bottom: 20px;
    }
    
    .board-header {
        padding: 10px 16px;
        margin-bottom: 16px;
    }
    
    .grid-container {
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .card-front, .card-back {
        border-radius: 12px;
    }
    
    .card-front {
        font-size: 1.8rem;
    }
    
    .card-back::after {
        font-size: 1.4rem;
    }
    
    .board-footer {
        flex-direction: column;
        gap: 12px;
        padding-top: 16px;
    }
    
    .modal-content {
        padding: 30px 20px;
    }
}

/* Floating Back Home Button */
.back-home-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 1000;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.back-home-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(6, 182, 212, 0.25);
}

.home-icon-svg {
    width: 20px;
    height: 20px;
}

@media (max-width: 768px) {
    .back-home-btn {
        top: 12px;
        left: 12px;
        width: 38px;
        height: 38px;
    }
    .home-icon-svg {
        width: 18px;
        height: 18px;
    }
}
