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

/* Prevent text selection on game elements */
.game-container {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none; /* Prevent callout on long-press */
    touch-action: manipulation; /* Better touch handling */
}

/* Allow text selection only in input fields */
input, textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    color: #333;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    background: #667eea;
    background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    background-size: cover;
    background-position: center;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 40% 60%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Removed floating background animation to prevent flicker */

.page-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    z-index: 1;
}

.game-container {
    max-width: 800px;
    width: 100%;
    padding: 20px;
    margin: 0 auto;
    position: relative;
    z-index: 10;
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

.game-wrapper {
    position: relative;
    width: 100%;
}

.sound-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.3s ease;
    z-index: 100;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

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

.sound-toggle.muted {
    opacity: 0.5;
}

header {
    text-align: center;
    margin-bottom: 20px;
    color: white;
}

h1 {
    font-size: 2.5em;
    font-weight: 700;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.tagline {
    font-size: 1em;
    opacity: 0.9;
    margin-bottom: 10px;
}

.game-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.stat-item {
    background: rgba(255, 255, 255, 0.9);
    padding: 15px 25px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    text-align: center;
    position: relative;
}

.stat-label {
    display: block;
    font-size: 0.8em;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 1.5em;
    font-weight: 600;
    color: #764ba2;
}

.difficulty-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.diff-btn {
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid transparent;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #666;
}

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

.diff-btn.active {
    background: white;
    color: #764ba2;
    border-color: #764ba2;
    font-weight: 600;
}

.game-board {
    display: none; /* Hidden by default */
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
    max-width: 600px;
    margin: 0 auto 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.card {
    aspect-ratio: 1;
    cursor: pointer;
    perspective: 1000px;
    -webkit-perspective: 1000px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

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

.card:hover .card-inner {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Mobile touch feedback */
@media (hover: none) and (pointer: coarse) {
    .card:active {
        transform: scale(0.95);
    }
    
    .card:active .card-inner {
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    }
    
    /* Disable hover effects on mobile */
    .card:hover {
        transform: none;
    }
    
    .category-card:active {
        transform: scale(0.98) translateZ(0);
        background: rgba(255, 255, 255, 1);
    }
    
    .category-card:hover {
        transform: translateZ(0);
    }
    
    .control-btn:hover,
    .btn-primary:hover,
    .btn-secondary:hover {
        transform: none;
    }
    
    /* Better button touch states */
    .btn-primary:active,
    .btn-secondary:active,
    .control-btn:active,
    .leaderboard-btn:active,
    .achievements-btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    transition: transform 0.6s, box-shadow 0.3s;
    transform: rotateY(0deg);
}

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

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.card-front {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
    transform: rotateY(0deg);
}

.card-front::before {
    content: '?';
    position: absolute;
    font-size: 3em;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.1);
    transform: rotate(-15deg);
    animation: pulse 2s ease-in-out infinite;
}

.card-front::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, 
        transparent 30%, 
        rgba(255, 255, 255, 0.1) 50%, 
        transparent 70%);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 0.1; transform: rotate(-15deg) scale(1); }
    50% { opacity: 0.2; transform: rotate(-15deg) scale(1.1); }
}

.card-pattern {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5em;
    color: rgba(255, 255, 255, 0.3);
    font-weight: bold;
}

.card-back {
    transform: rotateY(180deg);
    padding: 15px;
    text-align: center;
}

.card-back.question {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    color: #333;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.card-back.answer {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.card-content {
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.3;
    position: relative;
    z-index: 10;
}

.card.matched {
    animation: matchDisappear 0.6s ease forwards;
}

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

@keyframes matchDisappear {
    0% { 
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
    50% { 
        transform: scale(1.2) rotate(10deg);
        opacity: 1;
    }
    100% { 
        transform: scale(0) rotate(360deg);
        opacity: 0;
    }
}

.score-popup {
    position: fixed;
    font-size: 2em;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    pointer-events: none;
    z-index: 1000;
    animation: scoreFloat 1.5s ease-out forwards;
    transform: translate(-50%, 0);
}

@keyframes scoreFloat {
    0% {
        transform: translate(-50%, 0);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -100px);
        opacity: 0;
    }
}

.celebration-particle {
    position: fixed;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 999;
    animation: particleBurst 1s ease-out forwards;
}

@keyframes particleBurst {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0);
        opacity: 0;
    }
}

.timer-stat {
    overflow: hidden;
}

.timer-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, #4CAF50, #45a049);
    border-radius: 0 0 15px 15px;
    transition: width 1s linear, background 0.3s ease;
    width: 100%;
}

.timer-stat.warning .timer-progress {
    background: linear-gradient(90deg, #ff9800, #f57c00);
}

.timer-stat.critical .timer-progress {
    background: linear-gradient(90deg, #f44336, #d32f2f);
    animation: pulse-bar 0.5s ease-in-out infinite;
}

@keyframes pulse-bar {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.timer-stat.warning .stat-value {
    color: #ff9800 !important;
    font-weight: bold;
}

.timer-stat.critical {
    animation: shake 0.5s infinite;
}

.timer-stat.critical .stat-value {
    font-weight: bold;
    font-size: 1.8em;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.time-bonus-popup {
    position: fixed;
    font-size: 2em;
    font-weight: bold;
    color: #4CAF50;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    pointer-events: none;
    z-index: 1000;
    animation: timeBonusFloat 1.5s ease-out forwards;
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 40px;
    border-radius: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.time-penalty-popup {
    position: fixed;
    font-size: 2.2em;
    font-weight: bold;
    color: #ff0000;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 1000;
    animation: penaltyShake 1.5s ease-out forwards;
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 40px;
    border-radius: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

@keyframes timeBonusFloat {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -80px) scale(0.8);
    }
}

@keyframes penaltyShake {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translate(calc(-50% - 10px), -50%) scale(1.1);
    }
    20%, 40%, 60%, 80% {
        transform: translate(calc(-50% + 10px), -50%) scale(1.1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

@keyframes wrongMatchPulse {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

.penalty-flash {
    animation: redFlash 0.5s ease-out;
}

@keyframes redFlash {
    0%, 100% {
        color: inherit;
    }
    50% {
        color: #ff0000 !important;
        transform: scale(1.2);
    }
}

.game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.game-over-modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.4s ease;
}

.game-over-content {
    position: relative;
    background: #ffffff;
    border-radius: 24px;
    padding: 48px 40px 40px;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: slideUpScale 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.game-over-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #667eea, #764ba2);
    animation: shimmerBar 3s ease-in-out infinite;
}

@keyframes shimmerBar {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes slideUpScale {
    from {
        transform: translateY(40px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.game-over-header {
    text-align: center;
    margin-bottom: 32px;
    position: relative;
    padding-bottom: 24px;
    border-bottom: 1px solid #e5e7eb;
}

.game-over-title {
    color: #111827;
    font-size: 2.25em;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.025em;
    line-height: 1.1;
}

.level-reached {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 16px;
    background: #f3f4f6;
    border-radius: 100px;
    font-size: 0.875em;
}

.level-label {
    color: #6b7280;
    font-size: 0.875em;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.level-number {
    color: #111827;
    font-size: 1.125em;
    font-weight: 700;
}

.game-over-score-display {
    text-align: center;
    margin-bottom: 32px;
    padding: 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px;
    position: relative;
    overflow: hidden;
    animation: scoreReveal 0.8s ease-out 0.3s backwards;
}

@keyframes scoreReveal {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.game-over-score-display::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: scorePulse 3s ease-in-out infinite;
}

@keyframes scorePulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

.score-main {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    margin-bottom: 0;
}

.score-value {
    font-size: 3.5em;
    font-weight: 800;
    color: #ffffff;
    line-height: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.score-label {
    font-size: 1.125em;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.new-high-score {
    position: absolute;
    top: -12px;
    right: -12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fbbf24;
    padding: 8px 16px;
    border-radius: 100px;
    font-size: 0.875em;
    font-weight: 600;
    color: #78350f;
    margin: 0;
    animation: highScorePulse 2s ease-in-out infinite;
    box-shadow: 0 4px 6px -1px rgba(251, 191, 36, 0.4);
    transform: rotate(12deg);
}

.new-high-score.hidden {
    display: none;
}

.high-score-icon {
    font-size: 1.3em;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

@keyframes highScorePulse {
    0%, 100% { 
        transform: rotate(12deg) scale(1);
    }
    50% { 
        transform: rotate(12deg) scale(1.05);
    }
}

.game-over-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 32px;
}

.stat-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: all 0.2s ease;
}

.stat-card:hover {
    background: #f3f4f6;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.stat-icon {
    font-size: 1.75em;
    margin-bottom: 4px;
}

.stat-number {
    font-size: 1.75em;
    font-weight: 700;
    color: #111827;
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 0.75em;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.high-score-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.category-selection {
    text-align: center;
    padding: 20px;
    display: block !important;
    position: relative;
    width: 100%;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-y: visible;
    padding-bottom: 100px;
}

.category-selection.hidden {
    display: none !important;
}

.menu-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
    z-index: 10;
    position: relative;
    flex-wrap: wrap;
}

/* Mode Selection */
.mode-selection {
    text-align: center;
    padding: 40px 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.mode-selection.hidden {
    display: none !important;
}

.mode-selection h2 {
    color: white;
    font-size: 3.5em;
    margin-bottom: 15px;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.3);
    font-weight: 800;
    letter-spacing: -1px;
}

.mode-subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.3em;
    margin-bottom: 50px;
    font-weight: 300;
}

.mode-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

@media (max-width: 768px) {
    .mode-options {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

.mode-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    padding: 40px 30px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    border: 2px solid transparent;
}

.mode-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(118, 75, 162, 0.1), transparent);
    transform: rotate(45deg);
    transition: all 0.6s;
    opacity: 0;
}

.mode-card:hover::before {
    animation: shimmer 0.6s ease;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); opacity: 1; }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); opacity: 0; }
}

/* Entrance animations for mode cards */
.mode-card {
    animation: modeCardEntrance 0.6s ease-out backwards;
}

.mode-card:nth-child(1) { animation-delay: 0.1s; }
.mode-card:nth-child(2) { animation-delay: 0.2s; }
.mode-card:nth-child(3) { animation-delay: 0.3s; }
.mode-card:nth-child(4) { animation-delay: 0.4s; }

@keyframes modeCardEntrance {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.mode-selection h2 {
    animation: titleEntrance 0.8s ease-out;
}

.mode-subtitle {
    animation: subtitleEntrance 0.8s ease-out 0.2s backwards;
}

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

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

.mode-card:hover {
    transform: translateY(-12px) scale(1.03);
    box-shadow: 0 20px 40px rgba(118, 75, 162, 0.3);
    background: white;
    border-color: #764ba2;
}

.mode-card[data-mode="classic"] {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(102, 126, 234, 0.1));
}

.mode-card[data-mode="speed"] {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 99, 71, 0.1));
}

.mode-card[data-mode="memory"] {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(46, 213, 115, 0.1));
}

.mode-card[data-mode="perfect"] {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(231, 76, 60, 0.1));
}

.mode-icon {
    font-size: 3em;
    margin-bottom: 15px;
    display: block;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
}

.mode-card h3 {
    color: #2c3e50;
    font-size: 1.8em;
    margin-bottom: 12px;
    font-weight: 700;
}

.mode-card p {
    color: #546e7a;
    font-size: 1em;
    line-height: 1.4;
    margin-bottom: 20px;
}

.mode-difficulty {
    display: inline-block;
    background: rgba(118, 75, 162, 0.1);
    color: #764ba2;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Game footer */
.game-footer {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9em;
    text-align: center;
    display: flex;
    gap: 20px;
    align-items: center;
}

.footer-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-link:hover {
    color: white;
}

.footer-separator {
    color: rgba(255, 255, 255, 0.4);
}

/* Stats button on main menu */
.menu-stats-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    color: rgba(255, 255, 255, 0.4);
    border: none;
    padding: 5px;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0.5;
}

.menu-stats-btn:hover {
    opacity: 0.8;
    color: rgba(255, 255, 255, 0.7);
    transform: scale(1.1);
}

/* Combo Display */
.combo-display {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #FFD700, #FFA500);
    padding: 15px 40px;
    border-radius: 30px;
    box-shadow: 0 10px 30px rgba(255, 165, 0, 0.5);
    z-index: 100;
}

.combo-display.hidden {
    display: none;
}

.combo-text {
    font-size: 1.2em;
    font-weight: bold;
    color: white;
    margin-right: 10px;
}

.combo-count {
    font-size: 2em;
    font-weight: bold;
    color: white;
}

.combo-animation {
    animation: comboPulse 0.5s ease;
}

@keyframes comboPulse {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.2); }
}

/* Combo reward popup */
.combo-reward-popup {
    position: fixed;
    font-size: 1.4em;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(135deg, #667eea, #764ba2);
    padding: 15px 30px;
    border-radius: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 1001;
    animation: rewardSlideIn 0.5s ease-out;
    pointer-events: none;
}

@keyframes rewardSlideIn {
    0% { 
        opacity: 0;
        transform: translateX(-50%) translateY(20px) scale(0.8);
    }
    100% { 
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

/* Hint glow effect */
.card.hint-glow {
    animation: hintGlow 2s ease-in-out;
}

.card.hint-glow .card-inner {
    box-shadow: 0 0 30px #FFD700, 0 0 60px #FFD700;
}

@keyframes hintGlow {
    0%, 100% { 
        transform: scale(1);
        filter: brightness(1);
    }
    50% { 
        transform: scale(1.05);
        filter: brightness(1.3);
    }
}

/* Combo meter */
.combo-meter {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
    z-index: 100;
    transition: opacity 0.3s ease;
}

.combo-meter.hidden {
    opacity: 0;
}

.combo-meter-fill {
    height: 100%;
    background: linear-gradient(90deg, #FFD700, #FFA500);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px #FFD700;
}

/* Fire mode effects */
.fire-mode {
    position: relative;
}

.fire-mode::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    background: radial-gradient(circle, transparent 30%, rgba(255, 69, 0, 0.1) 70%);
    animation: fireGlow 1s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes fireGlow {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

/* Shield effect */
.shield-active::after {
    content: '🛡️';
    position: absolute;
    top: -20px;
    right: -20px;
    font-size: 2em;
    animation: shieldPulse 2s ease-in-out;
}

@keyframes shieldPulse {
    0% { opacity: 0; transform: scale(0); }
    20% { opacity: 1; transform: scale(1.2); }
    80% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0); }
}

/* Timer glow effects */
.timer-bonus-glow {
    animation: timerGlow 0.5s ease-out;
}

@keyframes timerGlow {
    0% { box-shadow: 0 0 0 rgba(76, 175, 80, 0); }
    50% { box-shadow: 0 0 20px rgba(76, 175, 80, 0.8); }
    100% { box-shadow: 0 0 0 rgba(76, 175, 80, 0); }
}

/* Score pulse effect */
.score-pulse {
    animation: scorePulse 0.5s ease-out;
}

@keyframes scorePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); color: #FFD700; }
    100% { transform: scale(1); }
}

/* Fire particles */
.fire-particle {
    position: fixed;
    width: 10px;
    height: 10px;
    background: radial-gradient(circle, #FF4500, #FF6347);
    border-radius: 50%;
    pointer-events: none;
    z-index: 999;
    animation: fireParticle 2s ease-out forwards;
}

@keyframes fireParticle {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) scale(0);
    }
}

/* Edge flash animation */
@keyframes edgeFlash {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}


/* Achievements */
.achievements-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.achievements-modal.hidden {
    display: none !important;
}

.achievements-modal .modal-content {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.achievements-list {
    max-height: 500px;
    overflow-y: auto;
    padding-right: 10px;
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.achievement-section-title {
    grid-column: 1 / -1;
    color: #764ba2;
    font-size: 1.5em;
    margin: 30px 0 15px;
    padding-top: 20px;
    border-top: 2px solid #eee;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 15px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.achievement-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.achievement-item.unlocked {
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    border-color: #4CAF50;
}

.achievement-item.locked {
    opacity: 0.6;
    filter: grayscale(0.8);
    background: #f0f0f0;
}

.achievement-icon {
    font-size: 2.5em;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.1));
}

.achievement-info {
    flex: 1;
}

.achievement-item h4 {
    margin: 0;
    color: #333;
    font-size: 1.1em;
    font-weight: 600;
}

.achievement-item p {
    margin: 5px 0 0 0;
    color: #666;
    font-size: 0.9em;
    line-height: 1.3;
}

.achievement-progress {
    text-align: center;
    padding: 20px;
    background: #f8f8f8;
    border-radius: 15px;
    margin-top: 20px;
}

.achievement-progress h3 {
    color: #764ba2;
    margin-bottom: 15px;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    transition: width 0.5s ease;
    box-shadow: 0 2px 8px rgba(118, 75, 162, 0.3);
}

.close-btn {
    background: #764ba2;
    color: white;
    border: none;
    padding: 10px 30px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px;
    touch-action: manipulation;
}

.close-btn:hover {
    transform: scale(1.05);
}

/* Achievement Popup */
.achievement-popup {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 1001;
    animation: slideInRight 0.5s ease;
}

.achievement-popup.hidden {
    display: none;
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

/* Spectacular Achievement Celebration */
.achievement-celebration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.achievement-celebration.show {
    opacity: 1;
}

.achievement-celebration.hide {
    opacity: 0;
}

.achievement-burst {
    position: absolute;
    width: 600px;
    height: 600px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.starburst-ray {
    position: absolute;
    width: 2px;
    height: 300px;
    background: linear-gradient(to bottom, transparent, #FFD700, transparent);
    top: 50%;
    left: 50%;
    transform-origin: center top;
    animation: starburstExpand 1s ease-out;
}

@keyframes starburstExpand {
    0% {
        height: 0;
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        height: 300px;
        opacity: 0;
    }
}

.achievement-content-large {
    position: relative;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 3px solid #FFD700;
    border-radius: 30px;
    padding: 60px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 100px rgba(255, 215, 0, 0.5);
    animation: achievementBounce 0.8s ease-out;
    max-width: 500px;
}

@keyframes achievementBounce {
    0% {
        transform: scale(0) rotate(180deg);
    }
    50% {
        transform: scale(1.2) rotate(10deg);
    }
    75% {
        transform: scale(0.9) rotate(-5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

.achievement-unlock-text {
    color: #FFD700;
    font-size: 1.2em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 20px;
    animation: glowText 2s ease-in-out infinite;
}

@keyframes glowText {
    0%, 100% {
        text-shadow: 0 0 10px #FFD700, 0 0 20px #FFD700;
    }
    50% {
        text-shadow: 0 0 20px #FFD700, 0 0 40px #FFD700, 0 0 60px #FFD700;
    }
}

.achievement-icon-large {
    font-size: 5em;
    margin-bottom: 20px;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.5));
    animation: iconFloat 3s ease-in-out infinite;
}

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

.achievement-name-large {
    color: #fff;
    font-size: 2.5em;
    margin: 0 0 10px;
    font-weight: 800;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.achievement-desc-large {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.3em;
    margin: 0;
}

.achievement-particles {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    overflow: hidden;
    pointer-events: none;
}

.achievement-particle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    animation: particleFloat 4s ease-out infinite;
}

@keyframes particleFloat {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(-100vh) rotate(720deg);
        opacity: 0;
    }
}

.achievement-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.achievement-text h3 {
    margin: 0;
    color: #333;
}

.achievement-text p {
    margin: 5px 0 0 0;
    color: #666;
    font-size: 0.9em;
}

/* Special card effects */
.card.revealed {
    box-shadow: 0 0 30px #FFD700 !important;
    animation: revealPulse 2s ease;
}

@keyframes revealPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Preview mode styling */
.card.preview-mode .card-inner {
    box-shadow: 0 0 20px rgba(118, 75, 162, 0.6);
}

.card.preview-mode {
    pointer-events: none;
}

/* Category selection animation styling */
.category-selection:not(.hidden) {
    animation: fadeIn 0.5s ease-out;
    padding-top: 60px;
    position: relative;
    z-index: 100;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.category-selection h2 {
    color: white;
    font-size: 3em;
    margin-bottom: 20px;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.3);
    line-height: 1.3;
    font-weight: 800;
    animation: titleEntrance 0.8s ease-out;
}

.category-options {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    padding-bottom: 40px;
}

.category-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    padding: 40px 35px;
    width: 250px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    border: 2px solid transparent;
    animation: categoryCardEntrance 0.6s ease-out backwards;
    z-index: 10;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.category-card:nth-child(1) { animation-delay: 0.1s; }
.category-card:nth-child(2) { animation-delay: 0.2s; }
.category-card:nth-child(3) { animation-delay: 0.3s; }

@keyframes categoryCardEntrance {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: linear-gradient(90deg, #667eea, #764ba2);
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}

.category-card:hover::before {
    transform: translateX(0);
}

.category-card:hover {
    transform: translateY(-12px) scale(1.03) translateZ(0);
    box-shadow: 0 20px 40px rgba(118, 75, 162, 0.3);
    background: white;
    border-color: #764ba2;
}

.category-card h3 {
    color: #2c3e50;
    font-size: 1.6em;
    margin-bottom: 12px;
    font-weight: 700;
}

.category-card p {
    color: #546e7a;
    font-size: 1em;
    margin-bottom: 20px;
    line-height: 1.4;
}

.category-icon {
    font-size: 2.5em;
    margin-bottom: 15px;
    display: block;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.1));
}


.game-controls {
    display: none; /* Hidden by default, shown when game starts */
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.control-btn {
    background: white;
    color: #764ba2;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    min-height: 44px;
    touch-action: manipulation;
}

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

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

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.hint-btn {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: white;
}

.hint-btn:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(255, 165, 0, 0.4);
}

.win-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.win-modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.5s ease;
}

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

.modal-content h2 {
    color: #764ba2;
    font-size: 2.5em;
    margin-bottom: 20px;
}

.win-stats {
    margin-bottom: 30px;
}

.win-stats p {
    font-size: 1.2em;
    color: #666;
    margin-bottom: 20px;
}

.final-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
}

.final-stats div {
    font-size: 1.1em;
    color: #333;
}

.final-stats span {
    font-weight: 600;
    color: #764ba2;
}

.stars {
    font-size: 2em;
    color: #ffd700;
    margin-bottom: 20px;
}

.play-again-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    border-radius: 30px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px;
    touch-action: manipulation;
}

.play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(118, 75, 162, 0.4);
}

.play-again-btn.secondary {
    background: white;
    color: #764ba2;
    border: 2px solid #764ba2;
}

.play-again-btn.secondary:hover {
    background: #f8f9fa;
    box-shadow: 0 10px 30px rgba(118, 75, 162, 0.2);
}

/* High score name input */
.high-score-name-input {
    margin: 24px 0;
    padding: 20px;
    background: #f9fafb;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
}

.high-score-name-input.hidden {
    display: none;
}

.name-input-label {
    margin-bottom: 12px;
    color: #4b5563;
    font-size: 0.875em;
    text-align: center;
    font-weight: 500;
}

.name-input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

#playerNameInput {
    flex: 1;
    padding: 12px 16px;
    font-size: 1em;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: white;
    color: #111827;
    transition: all 0.2s ease;
}

#playerNameInput::placeholder {
    color: #9ca3af;
}

#playerNameInput:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 0 3px rgba(118, 75, 162, 0.1);
}

.save-name-btn {
    background: #764ba2;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.875em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.save-name-btn:hover {
    background: #6b5b95;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Game over action buttons */
.game-over-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 8px;
}

.btn-primary, .btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    border-radius: 12px;
    font-size: 0.9375em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    text-decoration: none;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    filter: brightness(1.05);
}

.btn-secondary {
    background: white;
    color: #374151;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover {
    background: #f9fafb;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-color: #d1d5db;
}

.btn-icon {
    font-size: 1.125em;
}

/* Button ripple effect */
.btn-primary::after, .btn-secondary::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-primary:active::after, .btn-secondary:active::after {
    width: 300px;
    height: 300px;
}

/* Game mode selector */
.game-mode-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    z-index: 10;
}

.mode-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 150px;
    font-weight: 600;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.mode-btn.active {
    background: white;
    color: #764ba2;
    border-color: white;
}

/* Menu buttons */
.leaderboard-btn, .achievements-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0;
    display: inline-block;
    pointer-events: auto;
    position: relative;
    z-index: 100;
    white-space: nowrap;
}

.leaderboard-btn:hover, .achievements-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* Leaderboard modal */
.leaderboard-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.leaderboard-modal.hidden {
    display: none !important;
}

.leaderboard-tabs {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.tab-btn {
    background: #f0f0f0;
    border: none;
    padding: 10px 30px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-btn.active {
    background: #764ba2;
    color: white;
}

.leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: #f8f8f8;
    margin-bottom: 10px;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.leaderboard-item:hover {
    transform: translateX(5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.leaderboard-rank {
    font-size: 1.5em;
    font-weight: bold;
    color: #764ba2;
    width: 40px;
}

.leaderboard-name {
    flex: 1;
    margin-left: 20px;
    font-weight: 600;
}

.leaderboard-score {
    font-size: 1.2em;
    color: #667eea;
    font-weight: bold;
}

/* Two Player Stats */
.two-player-stats {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    margin: 15px 0;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.two-player-stats.hidden {
    display: none !important;
}

.player-stat {
    background: rgba(255, 255, 255, 0.9);
    padding: 15px 25px;
    border-radius: 15px;
    text-align: center;
    position: relative;
    transition: all 0.3s ease;
    opacity: 0.6;
    transform: scale(0.95);
}

.player-stat.active {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    background: white;
}

.player-name {
    display: block;
    font-size: 1.2em;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
}

.player-score {
    display: block;
    font-size: 2em;
    font-weight: 800;
    color: #764ba2;
    line-height: 1;
}

.player-turn-indicator {
    position: absolute;
    bottom: -22px;
    left: 50%;
    transform: translateX(-50%);
    background: #4CAF50;
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s ease;
    white-space: nowrap;
}

.player-stat.active .player-turn-indicator {
    opacity: 1;
}

.vs-divider {
    font-size: 1.5em;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    pointer-events: none;
}

.loading-overlay.hidden {
    display: none !important;
}

/* Ensure loading overlay is truly hidden */
#loadingOverlay.hidden {
    display: none !important;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

/* Force category selection to be visible when shown */
.category-selection:not(.hidden) {
    display: block !important;
}

.loader {
    width: 60px;
    height: 60px;
    position: relative;
}

.loader-inner {
    width: 100%;
    height: 100%;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Two Player Modal */
.two-player-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.two-player-results {
    background: white;
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    max-width: 600px;
    width: 90%;
}

.two-player-results h2 {
    color: #764ba2;
    font-size: 2.5em;
    margin-bottom: 30px;
}

.two-player-final-scores {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 40px;
    margin-bottom: 40px;
}

.final-player-score {
    background: #f9fafb;
    padding: 30px;
    border-radius: 20px;
    transition: all 0.3s ease;
}

.final-player-score.winner {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 10px 30px rgba(118, 75, 162, 0.3);
}

.player-label {
    display: block;
    font-size: 1.1em;
    margin-bottom: 10px;
    font-weight: 600;
}

.player-final-score {
    display: block;
    font-size: 3em;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 5px;
}

.pairs-label {
    font-size: 0.9em;
    opacity: 0.7;
}

.vs-final {
    font-size: 1.5em;
    font-weight: bold;
    color: #764ba2;
}

.two-player-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* Notification animations */
@keyframes slideDown {
    from { transform: translate(-50%, -100px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

@keyframes slideUp {
    from { transform: translate(-50%, 0); opacity: 1; }
    to { transform: translate(-50%, -100px); opacity: 0; }
}

/* Custom viewport height property */
:root {
    --vh: 1vh;
}

/* Mobile optimizations for small screens */
@media (max-width: 600px) {
    body {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .page-wrapper {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .game-container {
        padding: 10px;
        width: 100%;
        max-width: 100%;
        min-height: 100vh;
        position: relative;
    }
    
    h1 {
        font-size: 1.8em;
        margin-bottom: 5px;
    }
    
    .tagline {
        font-size: 1em;
    }
    
    .sound-toggle {
        top: 10px;
        right: 10px;
        width: 35px;
        height: 35px;
        font-size: 1em;
    }
    
    .game-stats {
        gap: 10px;
        margin-bottom: 15px;
        flex-wrap: wrap;
    }
    
    .stat-item {
        padding: 10px 14px;
        font-size: 0.9em;
        flex: 1;
        min-width: 70px;
        min-height: 44px; /* Better touch target */
    }
    
    .stat-label {
        font-size: 0.7em;
    }
    
    .stat-value {
        font-size: 1.2em;
    }
    
    .game-board {
        gap: 8px;
        padding: 10px;
        max-width: 100%;
    }
    
    .card {
        touch-action: manipulation; /* Prevents double-tap zoom */
        min-height: 60px; /* Ensure minimum touch target size */
    }
    
    .card-content {
        font-size: 0.75em;
        padding: 5px;
    }
    
    .card-front::before {
        font-size: 2em;
    }
    
    .diff-btn {
        font-size: 0.8em;
        padding: 8px 15px;
    }
    
    /* Game over modal mobile adjustments */
    .game-over-modal {
        padding: 10px;
    }
    
    .game-over-content {
        padding: 32px 24px 24px;
        max-width: 100%;
        border-radius: 20px;
    }
    
    .game-over-title {
        font-size: 1.75em;
    }
    
    .score-value {
        font-size: 2.5em;
    }
    
    .game-over-score-display {
        padding: 20px;
        margin-bottom: 24px;
    }
    
    .game-over-stats-grid {
        gap: 8px;
    }
    
    .stat-card {
        padding: 16px 12px;
    }
    
    .stat-icon {
        font-size: 1.5em;
    }
    
    .stat-number {
        font-size: 1.375em;
    }
    
    .btn-primary, .btn-secondary {
        padding: 12px 20px;
        font-size: 0.875em;
        border-radius: 10px;
    }
    
    .game-over-actions {
        gap: 8px;
    }
    
    .game-over-actions button {
        flex: 1;
        min-width: 0;
    }
    
    .new-high-score {
        font-size: 0.75em;
        padding: 6px 12px;
        top: -10px;
        right: -10px;
    }
    
    .high-score-name-input {
        padding: 16px;
        margin: 20px 0;
    }
    
    #playerNameInput {
        padding: 10px 14px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .save-name-btn {
        padding: 10px 20px;
    }
    
    /* Modal optimizations */
    .modal-content {
        padding: 20px;
        margin: 10px;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Achievement popup mobile */
    .achievement-popup {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: calc(100% - 20px);
        font-size: 0.9em;
    }
    
    /* Combo display mobile */
    .combo-display {
        top: 60px;
        padding: 10px 20px;
        font-size: 0.9em;
    }
    
    .combo-text {
        font-size: 1em;
    }
    
    .combo-count {
        font-size: 1.5em;
    }
    
    /* Timer warning adjustments */
    .timer-stat.critical .stat-value {
        font-size: 1.4em;
    }
    
    /* Win modal adjustments */
    .win-stats {
        margin-bottom: 20px;
    }
    
    .final-stats {
        flex-direction: column;
        gap: 10px;
    }
    
    /* Category selection mobile */
    .category-selection {
        padding: 20px 10px;
        padding-top: env(safe-area-inset-top, 20px);
        padding-bottom: 100px;
        min-height: 100vh;
        min-height: -webkit-fill-available;
        display: block !important;
        overflow-y: visible;
        position: relative;
    }
    
    .category-selection h2 {
        font-size: 2em;
        line-height: 1.2;
        margin-bottom: 15px;
        padding: 0 10px;
    }
    
    /* Achievements grid mobile */
    .achievements-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .achievement-item {
        padding: 15px;
        gap: 10px;
    }
    
    .achievement-icon {
        font-size: 2em;
    }
    
    /* Leaderboard mobile */
    .leaderboard-item {
        padding: 10px;
        font-size: 0.9em;
    }
    
    .leaderboard-rank {
        font-size: 1.2em;
        width: 30px;
    }
    
    .leaderboard-name {
        margin-left: 10px;
    }
    
    .leaderboard-score {
        font-size: 1em;
    }
    
    /* Two-player mode mobile */
    .two-player-stats {
        flex-direction: row;
        gap: 10px;
        padding: 10px;
        margin: 10px 0;
    }
    
    .player-stat {
        flex: 1;
        padding: 12px 10px;
    }
    
    .player-name {
        font-size: 0.9em;
    }
    
    .player-score {
        font-size: 1.5em;
    }
    
    .vs-divider {
        font-size: 1em;
        align-self: center;
    }
    
    body.two-player-mode .game-board {
        gap: 8px;
        padding: 10px;
    }
    
    .game-mode-selector {
        flex-direction: column;
        gap: 10px;
    }
    
    .mode-btn {
        width: 100%;
        max-width: 300px;
    }
    
    .two-player-final-scores {
        flex-direction: column;
        gap: 20px;
    }
    
    .final-player-score {
        width: 100%;
        max-width: 200px;
    }
}

/* Two-player mode adjustments */
body.two-player-mode .game-stats {
    display: none; /* Hide single player stats in two-player mode */
}

body.two-player-mode .game-board {
    display: grid !important; /* Ensure grid display */
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    max-width: 600px;
    margin: 0 auto 30px;
    padding: 20px;
}

/* Extra small devices */
@media (max-width: 400px) {
    h1 {
        font-size: 1.5em;
    }
    
    .game-board {
        gap: 6px;
        padding: 8px;
    }
    
    .card-content {
        font-size: 0.65em;
    }
    
    .stat-item {
        padding: 8px 10px;
        min-width: 60px;
        min-height: 40px;
    }
    
    .category-card {
        padding: 25px 20px;
        min-height: 120px;
    }
    
    .category-icon {
        font-size: 1.8em;
    }
    
    .sound-toggle {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 900px) {
    .category-options {
        flex-wrap: wrap;
        justify-content: center;
        max-width: 100%;
        padding: 0 20px;
    }
    
    .category-card {
        width: 200px;
        padding: 30px 25px;
    }
}

@media (max-width: 768px) {
    .category-selection {
        padding-top: 20px;
    }
    
    .category-selection h2 {
        font-size: 2.2em;
        margin-bottom: 15px;
    }
    
    .category-options {
        gap: 15px;
        flex-direction: column;
        align-items: center;
        padding: 10px;
        margin-bottom: 30px;
    }
    
    .category-card {
        width: 100%;
        max-width: 300px;
        padding: 25px 20px;
    }
    
    .category-card h3 {
        font-size: 1.4em;
    }
    
    .category-icon {
        font-size: 2em;
    }
    
    /* Menu buttons on mobile */
    .menu-buttons {
        flex-direction: row;
        width: 100%;
        max-width: 100%;
        margin: 0 auto 20px;
        gap: 10px;
        padding: 0 10px;
    }
    
    .leaderboard-btn, .achievements-btn {
        flex: 1;
        margin: 0;
        min-height: 44px;
        font-size: 0.9em;
        padding: 10px 15px;
    }
    
    /* Game mode selector mobile */
    .game-mode-selector {
        margin: 15px auto;
        width: 100%;
        max-width: 100%;
        padding: 0 10px;
    }
}

/* Preview countdown overlay */
.preview-countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 30px 50px;
    border-radius: 20px;
    text-align: center;
    z-index: 100;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

.preview-text {
    font-size: 1.5em;
    font-weight: 600;
    margin-bottom: 15px;
    color: #FFD700;
}

.preview-timer {
    font-size: 3em;
    font-weight: 800;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

@media (max-width: 600px) {
    .preview-countdown {
        padding: 20px 30px;
    }
    
    .preview-text {
        font-size: 1.2em;
    }
    
    .preview-timer {
        font-size: 2.5em;
    }
}