/* ---------- RESET & BASE ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    background: radial-gradient(ellipse at 50% 0%, #1a0a2e, #0d0a1a 70%);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* ---------- PRELOADER ---------- */
#preloader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #0d0a1a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

#preloader.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-ring {
    width: 70px;
    height: 70px;
    border: 6px solid rgba(255, 255, 255, 0.05);
    border-top: 6px solid #f7c948;
    border-right: 6px solid #f59e3a;
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.6, 0.0, 0.4, 1.0) infinite;
    box-shadow: 0 0 40px rgba(245, 158, 58, 0.1);
}

.loader-text {
    color: rgba(255, 255, 255, 0.3);
    margin-top: 24px;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 2px;
    animation: pulseText 1.5s ease-in-out infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

@keyframes pulseText {

    0%,
    100% {
        opacity: 0.3;
    }

    50% {
        opacity: 0.8;
    }
}

/* ---------- TUTORIAL / HOW TO PLAY ---------- */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

.tutorial-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.tutorial-modal {
    background: radial-gradient(ellipse at 50% 0%, #2a1a3e, #150d22);
    border-radius: 48px;
    padding: 40px 44px 36px;
    max-width: 440px;
    width: 90%;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.8);
    transform: scale(0.95) translateY(20px);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tutorial-overlay.active .tutorial-modal {
    transform: scale(1) translateY(0);
}

.tutorial-modal .big-icon {
    font-size: 56px;
    display: block;
    margin-bottom: 8px;
}

.tutorial-modal h2 {
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 16px;
}

.tutorial-modal ul {
    list-style: none;
    text-align: left;
    margin: 16px 0 28px;
    padding: 0;
}

.tutorial-modal ul li {
    color: rgba(255, 255, 255, 0.75);
    font-size: 16px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    gap: 12px;
}

.tutorial-modal ul li:last-child {
    border-bottom: none;
}

.tutorial-modal ul li .emoji {
    font-size: 22px;
    width: 32px;
    text-align: center;
}

.tutorial-modal .btn-primary {
    padding: 14px 40px;
    border: none;
    border-radius: 40px;
    background: linear-gradient(135deg, #f7c948, #f59e3a);
    color: #1a0a2e;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 10px 30px rgba(255, 204, 0, 0.4), 0 5px 0 #b8860b;
    width: 100%;
}

.tutorial-modal .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(245, 158, 58, 0.5);
}

.tutorial-modal .btn-primary:active {
    transform: scale(0.97);
}

/* ---------- GAME WRAPPER ---------- */
.game-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 560px;
    padding: 16px 20px 24px;
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(12px);
    border-radius: 48px 48px 32px 32px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.game-wrapper.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---------- HEADER ---------- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px 12px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.title {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, #f7c948, #f59e3a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
    text-shadow: 0 0 30px rgba(245, 158, 58, 0.2);
}

.title small {
    font-size: 12px;
    font-weight: 400;
    background: none;
    -webkit-text-fill-color: rgba(255, 255, 255, 0.35);
    margin-left: 4px;
}

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

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: 500;
}

.stat-item .icon {
    font-size: 16px;
}

.stat-item .value {
    color: #fff;
    font-weight: 700;
    min-width: 22px;
    text-align: center;
}

/* ---------- TIMER BAR ---------- */
.timer-wrap {
    margin-top: 12px;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.timer-fill {
    height: 100%;
    width: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, #f7c948, #f59e3a);
    transition: width 0.4s linear, background 0.4s ease;
}

.timer-fill.warning {
    background: linear-gradient(90deg, #ffb347, #ff6b6b);
}

.timer-fill.danger {
    background: linear-gradient(90deg, #ff6b6b, #ee5a24);
    animation: pulseTimer 0.6s ease-in-out infinite alternate;
}

@keyframes pulseTimer {
    0% {
        opacity: 0.6;
        box-shadow: 0 0 10px rgba(255, 0, 0, 0.2);
    }

    100% {
        opacity: 1;
        box-shadow: 0 0 20px rgba(255, 0, 0, 0.4);
    }
}

/* ---------- BOARD ---------- */
.board-wrap {
    perspective: 800px;
    margin: 18px 0 14px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.4);
}

.board {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    transform: rotateX(2deg) rotateY(-1deg);
    transition: transform 0.3s ease;
}

/* ---------- CARD ---------- */
.card {
    aspect-ratio: 1/1;
    background: radial-gradient(circle at 20% 25%, #2a1a3e, #1a0e2a);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 3px solid transparent;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);

    /* 1. REMOVE OR DELETE THESE TWO LINES: */
    /* transform: scale(0); */
    /* opacity: 0; */

    position: relative;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);

    /* 2. CHANGE 'forwards' TO 'backwards' ON THIS LINE: */
    animation: cardPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

.card::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 60%);
    pointer-events: none;
}

/* Update this specific block in your <style> tag */
.card.selected {
    transform: translateY(-8px) scale(1.06) !important;
    /* Added !important to override hover */
    border-color: #f7c948 !important;
    /* Force border color */
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 0 30px rgba(247, 201, 72, 0.3) !important;
    animation: glowPulse 0.8s ease-in-out infinite alternate;
    z-index: 2;
}

@keyframes cardPop {
    0% {
        transform: scale(0) rotate(-10deg);
        opacity: 0;
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.card:hover:not(.matched):not(.disabled) {
    transform: translateY(-3px) scale(1.02);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 20px rgba(247, 201, 72, 0.05);
}

/* SELECTED state: golden border + zoom */
.card.selected {
    transform: translateY(-8px) scale(1.06);
    border-color: #f7c948;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 0 30px rgba(247, 201, 72, 0.3);
    animation: glowPulse 0.8s ease-in-out infinite alternate;
    z-index: 2;
}

@keyframes glowPulse {
    0% {
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 0 20px rgba(247, 201, 72, 0.15);
    }

    100% {
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 0 40px rgba(247, 201, 72, 0.4);
    }
}

/* WRONG state: red border, shake, but stays visible */
.card.wrong {
    border-color: #ff6b6b !important;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.4) !important;
    animation: shake 0.4s ease forwards;
}

@keyframes shake {

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

    20% {
        transform: translateX(-8px);
    }

    40% {
        transform: translateX(8px);
    }

    60% {
        transform: translateX(-6px);
    }

    80% {
        transform: translateX(6px);
    }
}

/* MATCHED: hides after a pop */
.card.matched {
    animation: matchHide 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    pointer-events: none;
    border-color: #4ade80;
}

@keyframes matchHide {
    0% {
        transform: scale(1.1);
        opacity: 1;
        border-color: #4ade80;
        box-shadow: 0 0 30px rgba(74, 222, 128, 0.4);
    }

    60% {
        transform: scale(1.2);
        opacity: 0.8;
    }

    100% {
        transform: scale(0);
        opacity: 0;
    }
}

/* Hint glow */
.card.hint {
    animation: hintGlow 0.6s ease-in-out 3;
    border-color: #60a5fa;
    box-shadow: 0 0 40px rgba(96, 165, 250, 0.4);
}

@keyframes hintGlow {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
        box-shadow: 0 0 60px rgba(96, 165, 250, 0.6);
    }
}

/* Hidden (only for matched cards) */
.card.hidden {
    visibility: hidden;
    pointer-events: none;
    animation: none;
    transform: scale(0);
    opacity: 0;
}

/* burst effect on match */
.card.match-burst::before {
    content: '✦';
    position: absolute;
    font-size: 40px;
    color: #4ade80;
    opacity: 0;
    pointer-events: none;
    animation: burst 0.6s ease-out forwards;
}

@keyframes burst {
    0% {
        transform: scale(0.5) translate(0, 0);
        opacity: 1;
    }

    100% {
        transform: scale(2) translate(10px, -20px);
        opacity: 0;
    }
}

/* ---------- BOOSTERS ---------- */
.boosters {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 12px;
    flex-wrap: wrap;
}

.booster-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    border-radius: 40px;
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(8px);
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.booster-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.booster-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.booster-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

.booster-btn .emoji {
    font-size: 18px;
}

.booster-btn .count {
    background: rgba(247, 201, 72, 0.15);
    color: #f7c948;
    padding: 0 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}

/* ---------- OVERLAY / MODAL ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

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

.modal {
    background: radial-gradient(ellipse at 50% 0%, #2a1a3e, #150d22);
    border-radius: 40px;
    padding: 40px 44px 36px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.8);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal .big-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 12px;
}

.modal h2 {
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 6px;
}

.modal p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 16px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal .highlight {
    color: #f7c948;
    font-weight: 700;
}

.modal .btn-primary {
    padding: 14px 40px;
    border: none;
    border-radius: 40px;
    background: linear-gradient(135deg, #f7c948, #f59e3a);
    color: #1a0a2e;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 8px 24px rgba(245, 158, 58, 0.3);
}

.modal .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(245, 158, 58, 0.4);
}

.modal .btn-primary:active {
    transform: scale(0.96);
}

.modal .btn-secondary {
    margin-top: 12px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.5);
    padding: 10px 28px;
    border-radius: 40px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.04);
    color: #fff;
}

.modal .stats-row {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin: 14px 0 20px;
}

.modal .stats-row .item {
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
}

.modal .stats-row .item .num {
    display: block;
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    margin-top: 2px;
}

/* ---------- BACKGROUND PARTICLES ---------- */
.bg-particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-particles span {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    animation: floatParticle linear infinite;
}

@keyframes floatParticle {
    0% {
        transform: translateY(100vh) scale(0);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        transform: translateY(-10vh) scale(1);
        opacity: 0;
    }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 520px) {
    .game-wrapper {
        padding: 12px 12px 18px;
        border-radius: 32px 32px 24px 24px;
        max-width: 100%;
        margin: 8px;
    }

    .title {
        font-size: 16px;
    }

    .title small {
        font-size: 10px;
    }

    .stats {
        gap: 10px;
    }

    .stat-item {
        font-size: 12px;
    }

    .stat-item .icon {
        font-size: 13px;
    }

    .board {
        gap: 5px;
    }

    .card {
        font-size: 24px;
        border-radius: 12px;
    }

    .card::after {
        border-radius: 10px;
    }

    .board-wrap {
        padding: 5px;
        border-radius: 16px;
    }

    .booster-btn {
        padding: 8px 14px;
        font-size: 12px;
        gap: 5px;
    }

    .booster-btn .emoji {
        font-size: 15px;
    }

    .modal {
        padding: 28px 20px 28px;
    }

    .modal .big-icon {
        font-size: 48px;
    }

    .modal h2 {
        font-size: 22px;
    }

    .modal .btn-primary {
        padding: 12px 30px;
        font-size: 16px;
    }

    .modal .stats-row {
        gap: 20px;
    }

    .modal .stats-row .item .num {
        font-size: 20px;
    }

    .tutorial-modal {
        padding: 28px 20px;
    }

    .tutorial-modal ul li {
        font-size: 14px;
    }
}

@media (max-width: 400px) {
    .card {
        font-size: 18px;
        border-radius: 10px;
    }

    .board {
        gap: 4px;
    }

    .booster-btn {
        padding: 6px 10px;
        font-size: 10px;
    }

    .booster-btn .emoji {
        font-size: 13px;
    }

    .stats {
        gap: 6px;
    }

    .stat-item {
        font-size: 10px;
    }

    .stat-item .icon {
        font-size: 11px;
    }
}

/* scrollbar hide */
::-webkit-scrollbar {
    display: none;
}