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

body {
    font-family: 'Bronto', sans-serif;
    min-height: 100vh;
    overflow: inherit !important;
}


header {
    position: absolute;
    display: flex;
    width: 100%;
    justify-content: flex-end;
}

/* Enhanced Preloader Styles */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
    overflow: hidden;
}

.preloader.hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

/* Floating particles background */
.particles {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.particle {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    animation: float 6s infinite ease-in-out;
    backdrop-filter: blur(2px);
}

.particle:nth-child(1) {
    width: 20px;
    height: 20px;
    left: 10%;
    animation-delay: 0s;
}

.particle:nth-child(2) {
    width: 30px;
    height: 30px;
    left: 20%;
    animation-delay: 1s;
}

.particle:nth-child(3) {
    width: 15px;
    height: 15px;
    left: 30%;
    animation-delay: 2s;
}

.particle:nth-child(4) {
    width: 25px;
    height: 25px;
    left: 40%;
    animation-delay: 0.5s;
}

.particle:nth-child(5) {
    width: 18px;
    height: 18px;
    left: 50%;
    animation-delay: 1.5s;
}

.particle:nth-child(6) {
    width: 22px;
    height: 22px;
    left: 60%;
    animation-delay: 2.5s;
}

.particle:nth-child(7) {
    width: 28px;
    height: 28px;
    left: 70%;
    animation-delay: 3s;
}

.particle:nth-child(8) {
    width: 16px;
    height: 16px;
    left: 80%;
    animation-delay: 3.5s;
}

.particle:nth-child(9) {
    width: 24px;
    height: 24px;
    left: 90%;
    animation-delay: 4s;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    50% {
        transform: translateY(-10vh) rotate(180deg);
        opacity: 0.8;
    }
}

.video-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: -1;
}

/* Memory cards animation loader */
.memory-loader {
    display: flex;
    gap: 15px;
    margin-bottom: 50px;
    perspective: 1000px;
}

.loader-card {
    width: 60px;
    height: 60px;
    position: relative;
    transform-style: preserve-3d;
    animation: cardFlip 2s infinite ease-in-out;
}

.loader-card:nth-child(2) {
    animation-delay: 0.2s;
}

.loader-card:nth-child(3) {
    animation-delay: 0.4s;
}

.loader-card:nth-child(4) {
    animation-delay: 0.6s;
}

.loader-card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.loader-card-back {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    font-weight: 700;
}

.loader-card-back::before {
    content: '?';
    font-size: 28px;
    opacity: 0.8;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.loader-card-front {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    transform: rotateY(180deg);
    color: #333;
    font-weight: 700;
    overflow: hidden;
}

@keyframes cardFlip {

    0%,
    20% {
        transform: rotateY(0deg) scale(1);
    }

    50% {
        transform: rotateY(180deg) scale(1.1);
    }

    80%,
    100% {
        transform: rotateY(360deg) scale(1);
    }
}

/* Enhanced spinner */
.spinner-container {
    position: relative;
    margin-bottom: 40px;
}

.spinner {
    width: 80px;
    height: 80px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid #ffd700;
    border-right: 4px solid #ff6b6b;
    border-radius: 50%;
    animation: spin 1.5s linear infinite;
    position: relative;
}

.spinner::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    border: 2px solid rgba(255, 255, 255, 0.05);
    border-top: 2px solid rgba(255, 215, 0, 0.3);
    border-radius: 50%;
    animation: spin 2s linear infinite reverse;
}

.spinner-glow {
    position: absolute;
    top: -15px;
    left: -15px;
    right: -15px;
    bottom: -15px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.1) 0%, transparent 70%);
    animation: glow 2s ease-in-out infinite alternate;
}

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

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

@keyframes glow {
    0% {
        opacity: 0.5;
        transform: scale(1);
    }

    100% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* Enhanced text animations */
.preloader-text {
    color: white;
    font-size: clamp(24px, 5vw, 42px);
    font-weight: 700;
    text-align: center;
    opacity: 0;
    animation: textReveal 1s ease-out 0.5s forwards;
    position: relative;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    background: linear-gradient(45deg, #fff, #ffd700, #fff);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: textReveal 1s ease-out 0.5s forwards, shimmer 3s ease-in-out infinite;
}

.preloader-subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 16px;
    font-weight: 300;
    margin-top: 20px;
    opacity: 0;
    animation: slideUpFade 1s ease-out 1s forwards;
    text-align: center;
    letter-spacing: 0.5px;
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: 30px;
    overflow: hidden;
    opacity: 0;
    animation: slideUpFade 1s ease-out 1.5s forwards;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #ffd700, #ff6b6b, #4facfe);
    background-size: 200% 100%;
    border-radius: 2px;
    animation: loadProgress 2s ease-out forwards, gradientMove 2s ease-in-out infinite;
    width: 0%;
}

@keyframes textReveal {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.8);
        filter: blur(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0px);
    }
}

@keyframes shimmer {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes loadProgress {
    from {
        width: 0%;
    }

    to {
        width: 100%;
    }
}

@keyframes gradientMove {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

/* Pulsing dots */
.loading-dots {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    opacity: 0;
    animation: slideUpFade 1s ease-out 2s forwards;
}

.dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite both;
}

.dot:nth-child(2) {
    animation-delay: 0.16s;
}

.dot:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes dotPulse {

    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Game Container */
.game-container {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px;
    opacity: 0;
    transform: translateY(30px) scale(0.95);
    transition: all 1s cubic-bezier(0.23, 1, 0.320, 1);
}

.game-container.loaded {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 15px;
    color: white;
}

.title {
    display: flex;
    justify-content: center;
    font-size: clamp(1.5rem, 5vw, 4rem);
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    background: linear-gradient(45deg, #fff, #e0e7ff);
    -webkit-background-clip: text;
    background-clip: text;
}

.subtitle {
    font-size: 18px;
    font-weight: 300;
    opacity: 0.9;
    margin-top: 30px;
}

/* Stats and Controls */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(39, 39, 39, 0.315);
    padding: 20px;
    border-radius: 20px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-wrap: wrap;
    gap: 15px;
}

.stats {
    display: flex;
    gap: 30px;
    color: white;
    font-weight: 600;
}

.stat {
    text-align: center;
}



.stat-value {
    font-size: 24px;
    display: block;
    color: #ffd700;
}

.stat-value#time {
    width: 55px;
}

.stat-label {
    font-size: 12px;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button {
    cursor: pointer;
}

button.option-btn,
button.modal-btn {
    display: block;
    width: 100%;
    padding: 12px 14px;
    margin-top: 10px;
    border-radius: 50px;
    background-color: #f0f0f0;
    color: #35819e;
    border-radius: 1rem;
    border: 4px solid #add8e6;
    box-shadow: inset 5px 5px 10px rgba(255, 255, 255, 0.7), inset -5px -5px 10px rgba(0, 0, 0, 0.15), 0 6px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.25s ease-in-out;
    outline: none;
    -webkit-border-radius: 50px;
    -moz-border-radius: 50px;
    -ms-border-radius: 50px;
    -o-border-radius: 50px;
    font-family: "Bronto", sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
}

.control-buttons {
    display: flex;
    color: #fff;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}





/* Difficulty Selector */
.difficulty-selector {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    padding: 15px;
    border-radius: 20px;
    margin-bottom: 15px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

.difficulty-title {
    color: white;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
}

.difficulty-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.difficulty-btn {
    padding: 10px 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    color: white;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.difficulty-btn.active {
    background: rgba(255, 255, 255, 0.2);
    border-color: #ffd700;
    color: #ffd700;
}

.difficulty-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

/* Game Board */
.game-board {
    display: grid;
    gap: 15px;
    justify-content: center;
    margin: 0 auto;
    perspective: 1000px;
}

.game-board.grid-4-4 {
    grid-template-columns: repeat(4, 1fr);
    max-width: 400px;
}

.game-board.grid-5-5 {
    grid-template-columns: repeat(5, 1fr);
    max-width: 500px;
}

.game-board.grid-6-4 {
    grid-template-columns: repeat(6, 1fr);
    max-width: 500px;
}

.game-board.grid-6-6 {
    grid-template-columns: repeat(6, 1fr);
    max-width: 600px;
}


/* Easy Grid */
.game-board.grid-4-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Intermediate Grid (5 columns) */
.game-board.grid-5-4 {
    grid-template-columns: repeat(5, 1fr);
    /* 5 columns, 4 rows of cards */
}

/* Hard Grid (6 columns) */
.game-board.grid-6-5 {
    grid-template-columns: repeat(6, 1fr);
    /* 6 columns, 5 rows of cards */
}

/* Card Styles */
.card {
    aspect-ratio: 1;
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s;
}

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

.card.matched {
    animation: matchGlow 0.8s ease-out;
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.card-back {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    font-weight: 700;
}

.card-back::before {
    content: '?';
    font-size: clamp(2rem, 4vw, 3rem);
    opacity: 0.7;
}

.card-front {
    background: linear-gradient(135deg, #d2f2ff 0%, #d2f2ff 100%);
    transform: rotateY(180deg);
    color: #333;
    overflow: hidden;
}

.card-face.card-front img {
    width: 100%;
}

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

.card.flipped:hover {
    transform: rotateY(180deg) translateY(-5px) scale(1.05);
}

@keyframes matchGlow {

    0%,
    100% {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    }

    50% {
        box-shadow: 0 0 40px rgba(255, 215, 0, 0.8), 0 0 80px rgba(255, 215, 0, 0.4);
    }
}

/* Win Modal */
.win-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s ease;
}

.win-modal.show {
    opacity: 1;
    pointer-events: all;
}

.win-content {
    background: linear-gradient(135deg, #002f5c 0%, rgb(0 146 176) 100%);
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    color: white;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
    transform: scale(0.8);
    transition: transform 0.4s ease;
    max-width: 400px;
    width: 90%;
}

.win-modal.show .win-content {
    transform: scale(1);
}

.win-title {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(45deg, #ffd700, #ffed4e);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.win-stats {
    margin: 30px 0;
    display: flex;
    justify-content: space-around;
}

.win-stat {
    text-align: center;
}

.win-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #ffd700;
}

.win-stat-label {
    font-size: 14px;
    opacity: 0.8;
    margin-top: 5px;
}

#time {
    width: 30%;
}

/* Sound Toggle */
.sound-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 20px;
}

.sound-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}


/* Generic Modal Box */
/* Modal styles */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
}

.modal.show {
    display: flex;
    /* Use flexbox to center */
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fefefe;
    padding: 20px 30px;
    border: 1px solid #888;
    width: 80%;
    max-width: 400px;
    text-align: center;
    border-radius: 10px;
    position: relative;
}

.modal-content h2 {
    color: #002f5c;
    font-size: 1.4rem;
    font-weight: 600;
}

.close-btn {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover {
    color: black;
}

.difficulty-options button:hover {
    opacity: .8;
}

.difficulty-options button.active {
    color: #35819e;
    background-color: rgb(255, 238, 0);
    box-shadow: inset 5px 5px 10px rgba(255, 196, 0, 0.7), inset -5px -5px 10px rgba(0, 0, 0, 0.15), 0 6px 12px rgba(0, 0, 0, 0.1);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    background: rgba(0, 0, 0, 0.75);
}

button.btn-secondary {
    background: none;
    border: none;
    box-shadow: none;
}

/* Responsive Design */
@media (min-width: 1031px) {
    .card {
        min-width: 80px;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .controls {
        flex-direction: column;
        text-align: center;
    }

    .control-buttons {
        flex-direction: row;
    }

    header {
        position: relative;
        justify-content: center;
        margin-bottom: 10px;
    }

    .stats {
        justify-content: center;
    }

    .game-board {
        gap: 10px;
        padding: 0 10px;
    }

    .card-face {
        font-size: 1.5rem;
    }

    .difficulty-buttons {
        gap: 10px;
    }

    .difficulty-btn {
        padding: 8px 16px;
        font-size: 14px;
    }

    .memory-loader {
        gap: 10px;
    }

    .loader-card {
        width: 50px;
        height: 50px;
    }

    .loader-card-face {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .game-container {
        padding: 0;
        margin: 0 10px;
    }

    .controls {
        padding: 15px;
    }

    .game-board {
        gap: 8px;
    }

    .card-face {
        font-size: 1.2rem;
    }

    .memory-loader {
        gap: 8px;
    }

    .loader-card {
        width: 40px;
        height: 40px;
    }
}