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

body {
    font-family: Arial, sans-serif;
    background-image: url('images/bg2.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: env(safe-area-inset-top, 10px);
    padding-bottom: env(safe-area-inset-bottom, 10px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    margin: 0;
}

html {
    height: -webkit-fill-available;
}

.container {
    width: 100%;
    max-width: 800px;
    padding: 10px;
    padding-bottom: 20px;
}

/* Add a semi-transparent overlay to ensure text readability */
.game-info, header, .game-board {
    position: relative;
    z-index: 1;
}

/* Ensure text is readable against the background */
.timer, .moves {
    background-color: rgba(0, 0, 0, 0.7);
    padding: 5px 15px;
    border-radius: 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    color: white;
}

header {
    text-align: center;
    margin-bottom: 15px;
}

.game-info {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 10px;
    font-size: 1.1rem;
    flex-wrap: nowrap;
}

#shuffle-btn, #play-again {
    background-color: rgba(52, 152, 219, 0.9);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1rem;
    margin: 10px;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

#shuffle-btn:hover, #play-again:hover {
    background-color: rgba(41, 128, 185, 0.95);
    transform: translateY(-2px);
}

#shuffle-btn:active, #play-again:active {
    transform: translateY(0);
}

#difficulty {
    padding: 8px;
    font-size: 1rem;
    border-radius: 5px;
    margin: 10px;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 0 auto;
    max-width: 450px;
    padding: 10px;
    position: relative;
    z-index: 1;
}

.card {
    aspect-ratio: 1/1;
    background-color: #2c3e50;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    position: relative;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

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

.card.matched {
    pointer-events: none;
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    color: white;
    border-radius: 8px;
    pointer-events: none;
}

.card-front {
    background-color: #3498db;
    transform: rotateY(180deg);
    padding: 10px;
}

.card-front img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.card-back {
    background-color: #2c3e50;
    background-image: url('images/cardface.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transform: scale(0.7);
    opacity: 0;
    transition: all 0.3s ease-in-out;
    margin: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 20px);
    position: relative;
    z-index: 10000;
}

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

.modal-content h2 {
    color: #2c3e50;
    font-size: 2.5rem;
    margin-bottom: 20px;
}

.win-message {
    font-size: 1.2rem;
    color: #34495e;
    margin-bottom: 25px;
}

.stats {
    background-color: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin: 20px 0;
}

.stats p {
    margin: 10px 0;
    color: #2c3e50;
    font-size: 1.1rem;
}

.restart-btn {
    background-color: #27ae60;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    margin-top: 15px;
}

.restart-btn:hover {
    background-color: #219a52;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.3);
}

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

/* Responsive Design */
@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    .game-board {
        gap: 8px;
    }

    .game-info {
        flex-direction: column;
        gap: 10px;
    }

    h1 {
        font-size: 1.5rem;
    }
}

/* Touch Device Optimizations */
@media (hover: none) {
    .card:hover {
        transform: none;
    }

    #shuffle-btn:active, #play-again:active {
        background-color: #2980b9;
    }
}

/* Add new styles for countdown */
.countdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    color: white;
    font-size: 5rem;
    font-weight: bold;
}

/* Hide moves counter */
.moves {
    display: none;
}

/* Enhanced timer styling */
.timer {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.9) 100%);
    padding: 10px 25px;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 1px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transform: translateY(0);
    transition: all 0.3s ease;
}

.timer:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#time {
    font-family: 'Courier New', monospace;
    font-weight: bold;
}

/* Update game info container for centered single timer */
.game-info {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
    padding: 5px;
}

/* Update warning state for timer */
.timer.warning {
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.9) 0%, rgba(192, 57, 43, 0.95) 100%);
    animation: pulseWarning 1s infinite;
}

@keyframes pulseWarning {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 4px 20px rgba(231, 76, 60, 0.5);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
    }
}

/* Mobile optimizations for timer */
@media (max-width: 768px) {
    body {
        padding-top: env(safe-area-inset-top, 5px);
    }

    .container {
        padding: 8px;
    }

    .game-board {
        gap: 8px;
        margin: 0 auto;
        max-width: 100%;
    }

    .card {
        min-height: 80px;
    }

    .game-info {
        gap: 15px;
        margin-bottom: 8px;
        font-size: 1rem;
        padding-top: env(safe-area-inset-top, 0);
    }

    #shuffle-btn {
        padding: 8px 16px;
        margin: 5px;
    }

    body {
        touch-action: manipulation;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    /* Full screen modal adjustments */
    .modal-content {
        margin: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 20px);
    }

    /* Ensure timer and moves are always readable */
    .timer, .moves {
        background-color: rgba(0, 0, 0, 0.7);
        padding: 5px 15px;
        border-radius: 20px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        color: white;
        backdrop-filter: blur(5px);
        -webkit-backdrop-filter: blur(5px);
    }

    .timer {
        font-size: 1.2rem;
        padding: 8px 20px;
    }

    .game-logo {
        max-width: 120px;
        background-color: white;
        padding: 5px;
        border-radius: 4px;
    }
}

@media (display-mode: fullscreen) {
    body {
        padding: 0;
    }
}

.game-board.idle {
    animation: floatEffect 3s ease-in-out infinite;
    filter: brightness(0.9);
}

.game-board.idle .card {
    transform: scale(0.95);
    transition: transform 0.8s ease-in-out;
}

.game-board.idle .card:nth-child(odd) {
    animation: tiltLeft 4s ease-in-out infinite;
}

.game-board.idle .card:nth-child(even) {
    animation: tiltRight 4s ease-in-out infinite;
}

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

@keyframes tiltLeft {
    0%, 100% {
        transform: rotate(-2deg);
    }
    50% {
        transform: rotate(2deg);
    }
}

@keyframes tiltRight {
    0%, 100% {
        transform: rotate(2deg);
    }
    50% {
        transform: rotate(-2deg);
    }
}

.logo-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
    padding: 10px;
}

.game-logo {
    max-width: 150px;
    height: auto;
    opacity: 0.9;
    transition: opacity 0.3s ease;
    background-color: white;
    padding: 5px;
    border-radius: 4px;
}

.game-logo:hover {
    opacity: 1;
} 