/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #F3E2CE;
    color: #233A42;
    height: 100vh;
    width: 100vw;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
}

/* Game container */
.game-container {
    width: 100%;
    height: 100%;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    max-width: none;
}

/* Header styles */
.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: rgba(35, 58, 66, 0.1);
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(35, 58, 66, 0.3);
    flex-shrink: 0;
    position: relative;
}

.logo-container {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    flex-direction: column;
}

.header-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.player-display {
    color: #233A42;
    font-size: 0.8rem;
    font-weight: bold;
    margin-top: 3px;
    text-shadow: 0 0 5px rgba(35, 58, 66, 0.6);
}

.stats {
    display: flex;
    gap: 20px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-label {
    font-size: 10px;
    color: #233A42;
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 16px;
    font-weight: bold;
    color: #233A42;
    text-shadow: 0 0 8px rgba(35, 58, 66, 0.6);
}

.controls {
    display: flex;
    gap: 15px;
}

.control-btn {
    background: rgba(35, 58, 66, 0.2);
    border: 1px solid #233A42;
    border-radius: 6px;
    color: #233A42;
    font-size: 18px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: rgba(35, 58, 66, 0.3);
    box-shadow: 0 0 15px rgba(35, 58, 66, 0.4);
    transform: translateY(-2px);
}

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

/* Game board */
.game-board {
    width: 100%;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 3px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    border: none;
    width: 98vw;
    max-width: 98vw;
    height: 82vh;
    margin: 0 auto;
    transform: translate(-2px, 0px);
    justify-self: center;
    align-self: center;
}

/* Card styles */
.card {
    position: relative;
    aspect-ratio: 2/3;
    cursor: pointer;
    perspective: 1000px;
    border-radius: 8px;
    transition: transform 0.2s ease;
}

.card:hover {
    transform: scale(1.05);
}

.card:focus {
    outline: 1px solid #233A42;
    outline-offset: 0px;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    border-radius: 8px;
}

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(24px, 8vw, 48px);
    border: none;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    min-height: 60px;
    min-width: 60px;
    overflow: hidden;
}

.card-back {
    color: #233A42;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-front {
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
    transform: rotateY(180deg);
    border-color: #233A42;
    box-shadow: 0 0 20px rgba(35, 58, 66, 0.4);
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    display: block;
}

.card.matched .card-front {
    border-color: #32cd32;
    box-shadow: 0 0 25px rgba(50, 205, 50, 0.6);
}

.card.matched .card-image {
    filter: brightness(0.6);
}

.card.wildcard .card-front {
    background: linear-gradient(135deg, #4a1a4a 0%, #5a2a5a 100%);
    border-color: #ff6ec7;
    box-shadow: 0 0 25px rgba(255, 110, 199, 0.6);
}

/* Game Footer */
.game-footer {
    width: 100%;
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.footer-image {
    width: 100%;
    height: auto;
    object-fit: contain;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.score-label {
    font-size: 11px;
    color: #233A42;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-size: 16px;
    font-weight: bold;
    color: #233A42;
    text-shadow: 0 0 8px rgba(35, 58, 66, 0.6);
}

/* Welcome Screen Styles */
.welcome-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: block;
}

.welcome-image-click {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
    display: block;
}

/* Name Input Modal */
.name-input-modal .modal-content {
    background: #f7ddc3;
    border: 2px solid #233A42;
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 0 50px rgba(35, 58, 66, 0.4);
}

.name-input-modal h3 {
    color: #000000;
}

.logo-section {
    margin-bottom: 30px;
}

.welcome-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    border-radius: 10px;
}

.game-title {
    color: #555555;
    font-size: 2.2rem;
    margin-bottom: 10px;
    text-shadow: 0 0 15px rgba(85, 85, 85, 0.6);
}

.game-subtitle {
    color: #233A42;
    font-size: 1.1rem;
    margin-bottom: 0;
}

.name-input-section {
    margin: 30px 0;
}

.name-label {
    display: block;
    color: #555555;
    font-size: 1.2rem;
    margin-bottom: 15px;
    font-weight: bold;
}

.name-input {
    width: 100%;
    max-width: 300px;
    padding: 12px 15px;
    font-size: 1.1rem;
    border: 2px solid #233A42;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: #000000;
    text-align: center;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.name-input:focus {
    outline: none;
    border-color: #4a7c8a;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 10px rgba(74, 124, 138, 0.3);
}

.name-input::placeholder {
    color: rgba(74, 74, 74, 0.7);
}

.start-game-btn {
    background: linear-gradient(145deg, #233A42, #4a7c8a);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.3rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(35, 58, 66, 0.3);
    font-weight: bold;
}

.start-game-btn:hover {
    background: linear-gradient(145deg, #4a7c8a, #6bb6cd);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(35, 58, 66, 0.4);
}

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

.start-game-btn:disabled {
    background: linear-gradient(145deg, #666, #888);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.game-instructions {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid rgba(35, 58, 66, 0.3);
}

.game-instructions h3 {
    color: #ffffff;
    font-size: 1.3rem;
    margin-bottom: 15px;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.game-instructions ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.game-instructions li {
    color: #233A42;
    font-size: 1rem;
    margin-bottom: 8px;
    padding: 5px 0;
}

.leaderboard-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid rgba(35, 58, 66, 0.3);
}

.leaderboard-section h3 {
    color: #4a4a4a;
    font-size: 1.3rem;
    margin-bottom: 15px;
    text-shadow: 0 0 10px rgba(74, 74, 74, 0.3);
}

.leaderboard-list {
    max-height: 200px;
    overflow-y: auto;
    background: rgba(35, 58, 66, 0.1);
    border-radius: 8px;
    padding: 10px;
}

.loading-text {
    color: #233A42;
    font-style: italic;
    text-align: center;
    margin: 0;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(35, 58, 66, 0.2);
    color: #000000;
    font-size: 0.9rem;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.player-rank {
    font-weight: bold;
    margin-right: 10px;
    color: #000000;
}

.player-info {
    flex: 1;
}

.player-stats {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* Game Over Modal Styles */
.game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}

.game-over-modal.show {
    display: flex;
    animation: modalFadeIn 0.3s ease;
}

.game-over-content {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    text-align: center;
    width: 100vw;
    height: 100vh;
    box-shadow: none;
    position: relative;
}

.game-over-image {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.game-over-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}


/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.name-input-modal {
    background-color: #f7ddc3;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.3s ease;
}

/* Win Modal specific styles */
.win-modal .modal-content {
    background: none;
    border: none;
    padding: 0;
    max-width: none;
    width: 100%;
    height: 100%;
    box-shadow: none;
}

/* Score Summary Modal */
.score-summary-modal .modal-content {
    background: #f7ddc3;
    border: 2px solid #233A42;
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 0 50px rgba(35, 58, 66, 0.4);
    text-align: center;
    cursor: pointer;
}

.score-summary-modal h2 {
    color: #555555;
    font-size: 2.2rem;
    margin-bottom: 30px;
    text-shadow: 0 0 15px rgba(85, 85, 85, 0.6);
}

.winner-info {
    margin: 30px 0;
}

.player-name {
    font-size: 1.8rem;
    font-weight: bold;
    color: #000000;
    margin-bottom: 20px;
}

.score-details {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    border: 1px solid rgba(35, 58, 66, 0.2);
}

.score-label {
    font-size: 1.2rem;
    color: #4a4a4a;
    font-weight: bold;
}

.score-value {
    font-size: 1.2rem;
    color: #000000;
    font-weight: bold;
}

.play-again-text {
    font-size: 1rem;
    color: #4a4a4a;
    margin-top: 30px;
    font-style: italic;
}

.win-image {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.win-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
    padding: 40px;
    border-radius: 20px;
    border: 2px solid #233A42;
    box-shadow: 0 0 50px rgba(35, 58, 66, 0.4);
    text-align: center;
    max-width: 400px;
    width: 90%;
    animation: modalSlideIn 0.3s ease;
}

.modal-content h2 {
    color: #555555;
    font-size: 28px;
    margin-bottom: 20px;
    text-shadow: 0 0 15px rgba(85, 85, 85, 0.6);
}

.win-stats p {
    font-size: 18px;
    margin-bottom: 20px;
    color: white;
}

.final-stats {
    display: flex;
    justify-content: space-around;
    margin: 20px 0;
    padding: 20px;
    background: rgba(35, 58, 66, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(35, 58, 66, 0.3);
}

.final-stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.final-stat-label {
    font-size: 12px;
    color: white;
    text-transform: uppercase;
}

.final-stat-value {
    font-size: 18px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
}

.new-record {
    background: #F3E2CE;
    color: #000;
    padding: 10px;
    border-radius: 8px;
    margin: 15px 0;
    font-weight: bold;
    animation: recordGlow 2s infinite alternate;
}

.play-again-btn {
    background: linear-gradient(45deg, #233A42, #4a6370);
    color: #F3E2CE;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
}

.play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(35, 58, 66, 0.4);
}

/* Instructions */
.instructions {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.9);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #233A42;
    max-width: 300px;
    font-size: 14px;
}

.instructions h3 {
    color: #233A42;
    margin-bottom: 10px;
}

.instructions ul {
    list-style-type: none;
    padding-left: 0;
}

.instructions li {
    margin-bottom: 5px;
    padding-left: 15px;
    position: relative;
}

.instructions li::before {
    content: '▸';
    color: #233A42;
    position: absolute;
    left: 0;
}

/* Animations */
@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes recordGlow {
    from {
        box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    }
    to {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    }
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
    
    .game-container {
        padding: 8px;
        gap: 8px;
    }
    
    .game-header {
        padding: 6px 12px;
    }
    
    .stats {
        gap: 15px;
    }
    
    .stat-label {
        font-size: 9px;
    }
    
    .stat-value {
        font-size: 14px;
    }
    
    .control-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    .grid {
        gap: 3px;
        padding: 4px;
        max-width: 98vw;
        height: 75vh;
    }
    
    
    .score-label {
        font-size: 9px;
    }
    
    .score-value {
        font-size: 14px;
    }
    
    .modal-content {
        padding: 30px 20px;
        margin: 10px;
    }
    
    .final-stats {
        flex-direction: column;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .game-container {
        padding: 5px;
        gap: 5px;
    }
    
    .game-header {
        padding: 4px 8px;
    }
    
    .stats {
        gap: 12px;
    }
    
    .stat-label {
        font-size: 8px;
    }
    
    .stat-value {
        font-size: 12px;
    }
    
    .control-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    .grid {
        gap: 2px;
        padding: 3px;
        max-width: 99vw;
        height: 78vh;
    }
    
    .card-face {
        font-size: clamp(20px, 10vw, 40px);
        border-radius: 6px;
    }
    
    
    .score-label {
        font-size: 8px;
    }
    
    .score-value {
        font-size: 12px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .card-face {
        border-width: 3px;
    }
    
    .card:focus {
        outline-width: 4px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .card-inner,
    .card,
    .control-btn,
    .play-again-btn {
        transition: none;
    }
    
    .modal.show {
        animation: none;
    }
    
    .modal-content {
        animation: none;
    }
}
