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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    padding: 8px;
}

.game-container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 12px;
    max-width: 950px;
    width: 95%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    margin: 0 auto;
}

/* ===== HEADER - COMPACT & NEVER WRAPS ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 15px;
    margin-bottom: 12px;
    flex-wrap: nowrap;
    gap: 8px;
    min-height: 42px;
    overflow: hidden;
}

.stats {
    display: flex;
    gap: 12px;
    white-space: nowrap;
    font-size: 1.05em;
    font-weight: bold;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-item i {
    font-size: 1.35em;
}

#cookie-count {
    color: #ffd700;
    font-size: 1.4em;
}

/* Header buttons container */
.header-buttons {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

/* Button Base Styles */
.btn {
    border: none;
    border-radius: 50px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ultra-compact buttons */
.btn-sound, .btn-toggle {
    background: rgba(255, 255, 255, 0.2);
    color: #ffd700;
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    font-size: 0.85em;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

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

.btn-sound.muted {
    color: #ff6b6b;
    opacity: 0.7;
}

.btn-toggle.flat {
    color: #7fff00;
}

.btn-prestige {
    background: linear-gradient(135deg, #ffd700 0%, #ff8c00 100%);
    color: #333;
    padding: 4px 8px;
    font-size: 0.75em;
    box-shadow: 0 2px 6px rgba(255, 215, 0, 0.4);
    min-width: 70px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-prestige:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(255, 215, 0, 0.6);
}

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

/* ===== MAIN GAME AREA - SIDE-BY-SIDE ON DESKTOP ===== */
.main-game {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

/* Cookie Area */
.cookie-area {
    flex: 1;
    min-width: 300px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 28px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    height: 340px;
}

.cookie-area:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.02);
}

.cookie-container {
    position: relative;
    width: 200px;    /* FIXED SIZE - NEVER CHANGES */
    height: 200px;   /* FIXED SIZE - NEVER CHANGES */
    display: flex;
    justify-content: center;
    align-items: center;
}

.cookie {
    position: relative;
    z-index: 10;
}

.cookie i {
    color: #ffd700;
    font-size: 5.5rem;
    animation: pulse 2s infinite;
}

/* REALISTIC COOKIE STYLING */
.custom-cookie {
    width: 130px;
    height: 130px;
    animation: cookiePulse 2.2s ease-in-out infinite;
    transform-origin: center;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.cookie-area:hover .custom-cookie {
    filter: url(#cookieGlow) brightness(1.05);
    transform: scale(1.04);
}

.cookie-area:active .custom-cookie {
    transform: scale(0.92) rotate(2deg);
}

@keyframes cookiePulse {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.06) rotate(1deg); filter: url(#cookieGlow) brightness(1.15); }
}

/* Custom SVG Cookie Styling */
.custom-cookie {
    width: 120px;
    height: 120px;
    animation: pulse 2s infinite;
    transition: all 0.2s ease;
}

.cookie-area:hover .custom-cookie {
    filter: url(#glow) brightness(1.1);
    transform: scale(1.03);
}

.cookie-area:active .custom-cookie {
    transform: scale(0.95);
}

/* Enhanced pulse animation for SVG */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        filter: url(#glow);
    }
    50% {
        transform: scale(1.07);
        filter: url(#glow) brightness(1.2);
    }
}

.cookie-area:active .cookie i {
    transform: scale(0.9);
}

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

/* ===== ROTATION LAYERS - PERFECT CENTERING ===== */
.rotation-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;    /* MUST MATCH cookie-container */
    height: 200px;   /* MUST MATCH cookie-container */
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: center center;
}

.layer-1 { animation: rotate-clockwise 20s linear infinite; }
.layer-2 { animation: rotate-counter 25s linear infinite; }
.layer-3 { animation: rotate-clockwise 30s linear infinite; }
.layer-4 { animation: rotate-counter 35s linear infinite; }
.layer-5 { animation: rotate-clockwise 40s linear infinite; }
.layer-6 { animation: rotate-counter 45s linear infinite; }
.layer-7 { animation: rotate-clockwise 50s linear infinite; }
.layer-8 { animation: rotate-counter 55s linear infinite; }

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

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

/* Emoji indicators */
.upgrade-indicator {
    position: absolute;
    font-size: 1.6rem;
    text-shadow: 0 2px 6px rgba(0,0,0,0.5);
    pointer-events: none;
}

.layer-1 .upgrade-indicator { color: #4CAF50; }
.layer-2 .upgrade-indicator { color: #FF5722; }
.layer-3 .upgrade-indicator { color: #8BC34A; }
.layer-4 .upgrade-indicator { color: #9E9E9E; }
.layer-5 .upgrade-indicator { color: #3F51B5; }
.layer-6 .upgrade-indicator { color: #FF9800; }
.layer-7 .upgrade-indicator { color: #9C27B0; }
.layer-8 .upgrade-indicator { color: #3F51B5; }

.cookie-area:hover .upgrade-indicator {
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.8);
}

/* Floating Cookies Animation */
.floating-cookies {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.floating-cookie {
    position: absolute;
    color: #ffd700;
    font-size: 1.4em;
    animation: float-up 1.5s ease-out forwards;
    opacity: 0;
}

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

/* ===== UPGRADES PANEL ===== */
.upgrades-panel {
    flex: 1;
    min-width: 300px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 20px 15px;
    max-height: 340px;
    overflow-y: auto;
}

.upgrades-panel h2 {
    margin-bottom: 12px;
    text-align: center;
    font-size: 1.4em;
    color: #ffd700;
    font-weight: bold;
}

.upgrade-item {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid transparent;
    position: relative;
}

.upgrade-item:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(3px);
}

.upgrade-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    font-weight: bold;
}

.upgrade-name {
    font-size: 1em;
    color: #ffd700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.upgrade-level {
    background: rgba(255, 215, 0, 0.3);
    padding: 2px 6px;
    border-radius: 15px;
    font-size: 0.8em;
    font-weight: bold;
}

.upgrade-desc {
    font-size: 0.85em;
    margin-bottom: 4px;
    color: #ddd;
    line-height: 1.3;
}

.upgrade-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
}

.upgrade-cps { color: #7fff00; display: flex; align-items: center; gap: 3px; }
.upgrade-cost { color: #ff6b6b; font-weight: bold; display: flex; align-items: center; gap: 3px; }

.upgrade-item.affordable {
    background: rgba(100, 255, 100, 0.15) !important;
    border-left: 4px solid #55cc55 !important;
    box-shadow: 0 0 10px rgba(100, 255, 100, 0.3) !important;
}

.upgrade-item.affordable:hover:not(.disabled) {
    background: rgba(100, 255, 100, 0.25) !important;
    transform: translateX(4px);
}

.upgrade-item.affordable .upgrade-cost {
    color: #55cc55 !important;
    font-weight: bold;
}

.upgrade-item.disabled {
    opacity: 0.6;
    cursor: not-allowed !important;
}

.upgrade-item.disabled:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.1) !important;
}

.ad-slot::before {
    content: "Advertisement";
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 0.75em;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: bold;
}

/* ===== FOOTER ===== */
.footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    flex-wrap: wrap;
}

.btn-save {
    background: linear-gradient(135deg, #00c853 0%, #009624 100%);
    color: white;
    box-shadow: 0 3px 10px rgba(0, 200, 83, 0.4);
    min-width: 100px;
    padding: 8px 16px;
    font-size: 0.88em;
}

.btn-save:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(0, 200, 83, 0.6);
}

.btn-load {
    background: linear-gradient(135deg, #2196f3 0%, #1565c0 100%);
    color: white;
    box-shadow: 0 3px 10px rgba(33, 150, 243, 0.4);
    min-width: 100px;
    padding: 8px 16px;
    font-size: 0.88em;
}

.btn-load:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(33, 150, 243, 0.6);
}

#save-status {
    margin: 0 8px;
    font-size: 0.85em;
    color: #7fff00;
    min-width: 100px;
    text-align: center;
    font-weight: bold;
}

/* Legal Links in Footer */
.legal-links {
    margin-top: 15px;
    text-align: center;
    font-size: 0.8em;
    color: #ccc;
}

.legal-links a {
    color: #7fff00;
    text-decoration: none;
    margin: 0 5px;
}

.legal-links a:hover {
    text-decoration: underline;
}

/* Scrollbar Styling */
.upgrades-panel::-webkit-scrollbar { width: 5px; }
.upgrades-panel::-webkit-scrollbar-track { background: transparent; border-radius: 10px; }
.upgrades-panel::-webkit-scrollbar-thumb { background: rgba(255, 215, 0, 0.5); border-radius: 10px; }
.upgrades-panel::-webkit-scrollbar-thumb:hover { background: rgba(255, 215, 0, 0.8); }

/* ===== DESKTOP: FORCE SIDE-BY-SIDE + FIX SCROLLBAR ===== */
@media (min-width: 900px) {
    .main-game {
        flex-wrap: nowrap;
    }
    
    .cookie-area, .upgrades-panel {
        min-width: 320px;
    }
    
    /* CRITICAL: Fix scrollbar by matching exact heights */
    .upgrades-panel {
        height: 340px; /* Match cookie area height */
        max-height: none; /* Override max-height */
        padding: 15px; /* Reduced padding */
    }
    
    .upgrade-item {
        padding: 9px; /* Tighter spacing */
        margin-bottom: 9px;
    }
    
    .upgrades-panel h2 {
        margin-bottom: 10px; /* Reduced margin */
    }
    
    /* Cleaner scrollbar */
    .upgrades-panel::-webkit-scrollbar-track {
        background: transparent;
    }
}

/* ===== MOBILE FIXES (768px and below) ===== */
@media (max-width: 899px) {
    .main-game {
        flex-direction: column;
    }
    
    .cookie-area, .upgrades-panel {
        min-width: 100% !important;
        width: 100%;
    }
    
    .header {
        padding: 6px;
        min-height: 40px;
    }
    
    .stats {
        font-size: 0.95em;
        gap: 10px;
    }
    
    .stat-item i { font-size: 1.25em; }
    #cookie-count { font-size: 1.25em; }
    
    .btn-sound, .btn-toggle {
        width: 26px;
        height: 26px;
        font-size: 0.8em;
    }
    
    .btn-prestige {
        min-width: 65px;
        padding: 3px 6px;
        font-size: 0.7em;
    }
    
    .cookie-area {
        height: 280px;
        padding: 15px;
    }
    
    .upgrades-panel {
        max-height: 280px;
        padding: 14px;
    }
    
    .upgrades-panel h2 { font-size: 1.3em; }
    .upgrade-item { padding: 9px; margin-bottom: 9px; }
    .upgrade-name { font-size: 0.95em; }
    .upgrade-desc { font-size: 0.82em; }
    .upgrade-stats { font-size: 0.78em; }
    
    .footer {
        gap: 10px;
        padding: 10px;
    }
    
    .btn-save, .btn-load {
        min-width: 90px;
        padding: 7px 14px;
        font-size: 0.85em;
    }
    
    #save-status {
        min-width: 90px;
        font-size: 0.82em;
    }
    
    .ad-slot {
        min-height: 250px;
        margin: 12px 0;
        padding: 10px;
    }
}

/* iPhone SE / 13 Mini (375px) */
@media (max-width: 375px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 8px;
        min-height: auto;
    }
    
    .header-buttons {
        width: 100%;
        justify-content: center;
        margin-top: 4px;
        flex-wrap: wrap;
    }
    
    .btn-prestige {
        min-width: 60px;
        padding: 3px 5px;
        font-size: 0.68em;
    }
    
    .btn-sound, .btn-toggle {
        width: 24px;
        height: 24px;
        font-size: 0.75em;
    }
    
    .cookie-area {
        height: 260px;
        padding: 12px;
    }
    
    .upgrades-panel {
        max-height: 250px;
        padding: 12px;
    }
    
    .upgrades-panel h2 { font-size: 1.25em; }
    
    .footer {
        flex-direction: column;
        gap: 8px;
        padding: 10px;
    }
    
    .btn-save, .btn-load {
        width: 100%;
        max-width: 180px;
        min-width: auto;
        padding: 10px;
        font-size: 0.9em;
    }
    
    #save-status {
        width: 100%;
        min-width: auto;
        padding: 4px 0;
        font-size: 0.82em;
    }
    
    /* Hide ad on very small screens */
    .ad-slot {
        display: none;
    }
}

/* Hide empty ad container during local testing */
#container-49e8f7d787ee9f43ebf2867f83ece867:empty {
    display: none;
}

/* iOS smooth scrolling */
@supports (-webkit-overflow-scrolling: touch) {
    .game-container, .upgrades-panel {
        -webkit-overflow-scrolling: touch;
    }
}
/* ===== FIXED AD SLOT - FULL WIDTH BELOW CONTENT ===== */
.ad-slot {
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Prevent vertical centering of tall ads */
    margin: 20px 0;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 18px;
    padding: 20px 15px;
    position: relative;
    width: 100%;
    min-height: auto; /* CRITICAL: Let ad determine height */
    box-sizing: border-box;
    border: 1px solid rgba(255, 215, 0, 0.2);
}

.ad-slot::before {
    content: "Advertisement";
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 0.78em;
    color: rgba(255, 255, 255, 0.65);
    background: rgba(0, 0, 0, 0.25);
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: bold;
    letter-spacing: 0.5px;
    z-index: 10;
    backdrop-filter: blur(4px);
}

/* Target Adsterra container specifically */
#container-49e8f7d787ee9f43ebf2867f83ece867 {
    width: 100% !important;
    height: auto !important;
    min-height: 280px; /* Minimum space for ad content */
    max-width: 728px; /* Prevent oversizing on wide screens */
    margin: 0 auto; /* Center the ad content */
}

/* Clean up ad internals */
#container-49e8f7d787ee9f43ebf2867f83ece867 * {
    box-sizing: border-box !important;
}

/* Mobile optimization */
@media (max-width: 768px) {
    .ad-slot {
        padding: 18px 12px;
        margin: 18px 0;
        border-radius: 16px;
    }
    
    #container-49e8f7d787ee9f43ebf2867f83ece867 {
        min-height: 250px;
    }
}

/* Hide empty container during local testing */
#container-49e8f7d787ee9f43ebf2867f83ece867:empty {
    display: none;
}