/* Modern, addictive design with smooth animations */
:root {
    --primary: #ff4500;
    --secondary: #ff8c00;
    --success: #4caf50;
    --bg-light: #f0f8ff;
    --bg-dark: #121212;
    --card-bg: #7fffd4;
    --text-dark: #000;
    --text-light: #fff;
    --shadow: rgba(0, 0, 0, 0.2);
    --glow: rgba(255, 69, 0, 0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-dark);
    transition: all 0.3s ease;
    overflow-x: hidden;
}

/* Header Styles */
header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    box-shadow: 0 4px 20px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    max-width: 1200px;
    margin: 0 auto;
}

nav h1 {
    font-size: 2.5em;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
    animation: pulse 2s infinite;
}

.extreme {
    font-size: 0.6em;
    vertical-align: super;
    animation: glow 1.5s ease-in-out infinite alternate;
}

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

@keyframes glow {
    from { text-shadow: 0 0 10px var(--glow); }
    to { text-shadow: 0 0 20px var(--glow), 0 0 30px var(--glow); }
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-right a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s;
}

.nav-right a:hover {
    color: var(--secondary);
    transform: translateY(-2px);
}

#theme-toggle {
    background: none;
    border: none;
    font-size: 1.8em;
    cursor: pointer;
    transition: transform 0.3s;
}

#theme-toggle:hover {
    transform: rotate(180deg);
}

/* Main Content */
main {
    padding: 30px 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.stat-item {
    background: rgba(255, 255, 255, 0.9);
    padding: 15px 25px;
    border-radius: 20px;
    box-shadow: 0 4px 15px var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
    transition: transform 0.3s;
}

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

.stat-label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--primary);
}

.score-pop {
    animation: scorePop 0.3s ease;
}

@keyframes scorePop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.combo-active {
    color: var(--secondary) !important;
    animation: comboGlow 0.5s ease;
}

@keyframes comboGlow {
    0% { transform: scale(1); text-shadow: none; }
    50% { transform: scale(1.2); text-shadow: 0 0 20px var(--glow); }
    100% { transform: scale(1); text-shadow: 0 0 10px var(--glow); }
}

/* Progress Bar */
.progress-container {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    height: 30px;
    margin: 20px auto;
    max-width: 600px;
    overflow: hidden;
    position: relative;
}

.progress-bar {
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    height: 100%;
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 20px;
    box-shadow: 0 0 20px var(--glow);
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* Header fade animation */
header {
    transition: transform 0.5s ease, opacity 0.5s ease;
}

header.header-hidden {
    transform: translateY(-100%);
    opacity: 0;
}

/* Timer urgent state */
.timer-urgent {
    color: #ff0000 !important;
    animation: timerPulse 0.5s infinite;
}

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

/* Game Board Grid Layouts - Vertical orientation for mobile */
.game-board-4x2 {
    display: grid;
    grid-template-columns: repeat(4, 90px);
    gap: 15px;
    justify-content: center;
    margin: 30px auto;
    perspective: 1000px;
}

.game-board-4x3 {
    display: grid;
    grid-template-columns: repeat(4, 90px);
    gap: 15px;
    justify-content: center;
    margin: 30px auto;
    perspective: 1000px;
}

.game-board-4x4 {
    display: grid;
    grid-template-columns: repeat(4, 90px);
    gap: 15px;
    justify-content: center;
    margin: 30px auto;
    perspective: 1000px;
}

.game-board-4x5 {
    display: grid;
    grid-template-columns: repeat(4, 85px);
    gap: 12px;
    justify-content: center;
    margin: 30px auto;
}

.game-board-4x6 {
    display: grid;
    grid-template-columns: repeat(4, 80px);
    gap: 10px;
    justify-content: center;
    margin: 30px auto;
}

.game-board-4x5 .card {
    width: 85px;
    height: 85px;
}

.game-board-4x6 .card {
    width: 80px;
    height: 80px;
}

.card {
    width: 90px;
    height: 90px;
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.3s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.game-board-5x4 .card {
    width: 80px;
    height: 80px;
}

.game-board-6x4 .card {
    width: 70px;
    height: 70px;
}

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

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    pointer-events: none;
}

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

.card-front, .card-back {
    width: 100%;
    height: 100%;
    position: absolute;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5em;
    border-radius: 15px;
    box-shadow: 0 4px 15px var(--shadow);
    pointer-events: none;
}

.card-front {
    background: linear-gradient(145deg, #e0f7fa, #4dd0e1);
    color: #00838f;
    font-weight: bold;
}

.card-back {
    background: linear-gradient(145deg, #fff, #f5f5f5);
    transform: rotateY(180deg);
}

.card.matched {
    animation: matchPulse 0.6s ease;
}

.card.matched .card-back {
    background: linear-gradient(145deg, #c8e6c9, #4caf50);
    box-shadow: 0 0 30px rgba(76, 175, 80, 0.5);
}

@keyframes matchPulse {
    0% { transform: scale(1) rotateY(180deg); }
    50% { transform: scale(1.2) rotateY(180deg); }
    100% { transform: scale(1) rotateY(180deg); }
}

/* Candy Salad */
.salad-container {
    margin: 40px auto;
    text-align: center;
}

.salad-container h2 {
    font-size: 2em;
    margin-bottom: 20px;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

#candy-salad {
    background: rgba(255, 255, 255, 0.95);
    min-height: 80px;
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 8px 32px var(--shadow);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
    max-width: 600px;
    margin: 0 auto;
    border: 3px dashed var(--primary);
}

.candy-item {
    font-size: 2.5em;
    transition: all 0.3s;
}

.candy-drop {
    animation: candyDrop 0.5s ease;
}

@keyframes candyDrop {
    0% {
        transform: translateY(-100px) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: translateY(0) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: translateY(0) rotate(360deg);
    }
}

.candy-item:hover {
    transform: scale(1.2) rotate(10deg);
}

/* Particles */
.particle {
    position: fixed;
    width: 10px;
    height: 10px;
    background: var(--secondary);
    border-radius: 50%;
    pointer-events: none;
    animation: particleFly 1s ease-out forwards;
}

@keyframes particleFly {
    to {
        transform: translate(var(--dx), var(--dy));
        opacity: 0;
    }
}

/* Achievement Toast */
.achievement-toast {
    position: fixed;
    top: 100px;
    right: -400px;
    background: linear-gradient(145deg, #fff, #f5f5f5);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 8px 32px var(--shadow);
    display: flex;
    align-items: center;
    gap: 15px;
    transition: right 0.5s ease;
    z-index: 1000;
    max-width: 350px;
}

.achievement-toast.show {
    right: 20px;
}

.achievement-icon {
    font-size: 3em;
}

.achievement-title {
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 5px;
}

.achievement-name {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 3px;
}

.achievement-desc {
    font-size: 0.9em;
    color: #666;
}

/* Win Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    animation: modalPop 0.5s ease;
}

@keyframes modalPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.win-content h2 {
    font-size: 2.5em;
    margin-bottom: 20px;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.win-stats p {
    margin: 10px 0;
    font-size: 1.2em;
}

.star-rating {
    margin: 20px 0;
    font-size: 2.5em;
}

.star {
    color: #ddd;
    transition: all 0.3s;
}

.star-filled {
    color: gold;
    animation: starPop 0.5s ease;
}

@keyframes starPop {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px var(--glow);
}

.btn-secondary {
    background: #f0f0f0;
    color: var(--primary);
}

.btn-secondary:hover {
    background: #e0e0e0;
}

/* High Score Container */
.high-score-container {
    margin: 40px auto;
    max-width: 800px;
    text-align: center;
}

.high-score-container h3 {
    font-size: 2em;
    color: white;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
}

.stat-box {
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 4px 15px var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: transform 0.3s;
}

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

.stat-icon {
    font-size: 2em;
}

.stat-title {
    font-size: 0.9em;
    color: #666;
}

.stat-number {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--primary);
}

/* Total Games */
.total-games {
    text-align: center;
    font-size: 1.3em;
    color: white;
    margin-top: 30px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

/* Sound Toggle */
.sound-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 1.8em;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--shadow);
    transition: all 0.3s;
    z-index: 100;
}

.sound-toggle:hover {
    transform: scale(1.1);
}

.sound-toggle.sound-off {
    opacity: 0.6;
}

/* Theme Toggle Float (hidden on desktop) */
.theme-toggle-float {
    display: none;
}

/* Dark Mode */
body.dark-mode {
    background: linear-gradient(135deg, #232526 0%, #414345 100%);
}

body.dark-mode header {
    background: rgba(30, 30, 30, 0.95);
}

body.dark-mode .stat-item,
body.dark-mode .modal-content,
body.dark-mode #candy-salad,
body.dark-mode .stat-box,
body.dark-mode .achievement-toast {
    background: rgba(40, 40, 40, 0.95);
    color: white;
}

body.dark-mode .stat-label,
body.dark-mode .stat-title,
body.dark-mode .achievement-desc {
    color: #aaa;
}

body.dark-mode .card-front {
    background: linear-gradient(145deg, #424242, #616161);
    color: #e0e0e0;
}

body.dark-mode .sound-toggle,
body.dark-mode .theme-toggle-float {
    background: #333;
    color: white;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Maximize game board on mobile */
    body {
        padding-top: 60px; /* Space for header when visible */
    }
    
    /* Compact header for mobile */
    header {
        padding: 8px 10px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
    }
    
    header.header-hidden {
        transform: translateY(-100%);
    }
    
    nav {
        flex-direction: row;
        gap: 0;
    }
    
    nav h1 {
        font-size: 1.2em;
    }
    
    .nav-right {
        display: none; /* Hide navigation links on mobile during gameplay */
    }
    
    #theme-toggle {
        font-size: 1.4em;
        margin-left: auto;
        padding: 5px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 35px;
        height: 35px;
    }
    
    /* Minimize padding */
    main {
        padding: 10px 5px;
    }
    
    /* Compact stats bar */
    .stats-bar {
        gap: 8px;
        margin-bottom: 10px;
    }
    
    .stat-item {
        padding: 5px 10px;
        min-width: 60px;
        border-radius: 12px;
    }
    
    .stat-label {
        font-size: 0.7em;
        margin-bottom: 2px;
    }
    
    .stat-value {
        font-size: 1.2em;
    }
    
    /* Compact progress bar */
    .progress-container {
        height: 20px;
        margin: 10px auto;
    }
    
    .progress-text {
        font-size: 0.8em;
    }
    
    /* Maximize game board space - vertical layouts */
    .game-board-4x2 {
        grid-template-columns: repeat(4, calc((100vw - 60px) / 4));
        gap: 8px;
        margin: 15px auto;
    }
    
    .game-board-4x3 {
        grid-template-columns: repeat(4, calc((100vw - 60px) / 4));
        gap: 8px;
        margin: 15px auto;
    }
    
    .game-board-4x4 {
        grid-template-columns: repeat(4, calc((100vw - 60px) / 4));
        gap: 8px;
        margin: 15px auto;
    }
    
    .game-board-4x5 {
        grid-template-columns: repeat(4, calc((100vw - 50px) / 4));
        gap: 6px;
        margin: 10px auto;
    }
    
    .game-board-4x6 {
        grid-template-columns: repeat(4, calc((100vw - 40px) / 4));
        gap: 5px;
        margin: 10px auto;
    }
    
    .card {
        width: calc((100vw - 60px) / 4);
        height: calc((100vw - 60px) / 4);
        max-width: 85px;
        max-height: 85px;

    }
    
    .game-board-4x5 .card {
        width: calc((100vw - 50px) / 4);
        height: calc((100vw - 50px) / 4);
        max-width: 80px;
        max-height: 80px;
    }
    
    .game-board-4x6 .card {
        width: calc((100vw - 40px) / 4);
        height: calc((100vw - 40px) / 4);
        max-width: 75px;
        max-height: 75px;
    }
    
    .card-front, .card-back {
        font-size: 1.8em;
        border-radius: 10px;
    }
    
    /* Hide less important elements on mobile */
    .salad-container {
        margin: 20px auto;
    }
    
    .salad-container h2 {
        font-size: 1.2em;
        margin-bottom: 10px;
    }
    
    #candy-salad {
        min-height: 50px;
        padding: 10px;
        gap: 5px;
    }
    
    .candy-item {
        font-size: 1.8em;
    }
    
    /* Hide stats container on mobile to save space */
    .high-score-container {
        display: none;
    }
    
    /* Compact total games */
    .total-games {
        font-size: 0.9em;
        margin-top: 15px;
    }
    
    /* Smaller floating buttons on mobile */
    .sound-toggle {
        width: 45px;
        height: 45px;
        font-size: 1.4em;
        bottom: 10px;
        right: 10px;
    }
    
    /* Show theme toggle float on mobile */
    .theme-toggle-float {
        display: flex;
        position: fixed;
        bottom: 10px;
        right: 65px;
        background: white;
        border: none;
        border-radius: 50%;
        width: 45px;
        height: 45px;
        font-size: 1.4em;
        cursor: pointer;
        box-shadow: 0 4px 15px var(--shadow);
        transition: all 0.3s;
        z-index: 100;
        align-items: center;
        justify-content: center;
    }
    
    .theme-toggle-float:active {
        transform: scale(0.95);
    }
    
    /* Hide the header theme toggle on mobile */
    nav #theme-toggle {
        display: none;
    }
    
    /* Compact achievement toast */
    .achievement-toast {
        max-width: 280px;
        padding: 12px;
        top: 70px;
    }
    
    .achievement-icon {
        font-size: 2em;
    }
    
    .achievement-title {
        font-size: 0.8em;
    }
    
    .achievement-name {
        font-size: 1em;
    }
    
    .achievement-desc {
        font-size: 0.8em;
    }
    
    /* Compact modal */
    .modal-content {
        padding: 25px 15px;
        margin: 10px;
    }
    
    .win-content h2 {
        font-size: 1.8em;
        margin-bottom: 15px;
    }
    
    .win-stats p {
        font-size: 1em;
        margin: 5px 0;
    }
    
    .star-rating {
        font-size: 2em;
        margin: 15px 0;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 1em;
    }
}

/* Mobile touch fix */
@media (hover: none) and (pointer: coarse) {
    .card {
        touch-action: manipulation;
    }
}
@media (max-width: 400px) {
    nav h1 {
        font-size: 1em;
    }
    
    .extreme {
        display: none;
    }
    
    .stat-item {
        padding: 4px 8px;
    }
    
    .stat-label {
        font-size: 0.6em;
    }
    
    .stat-value {
        font-size: 1em;
    }
    
    /* Even smaller cards for tiny screens */
    .game-board-4x6 .card {
        max-width: 65px;
        max-height: 65px;
    }
}