:root {
    --bg-main: #0c0e14;
    --bg-card: #151821;
    --bg-card-hover: #1e222e;
    --bg-surface: #252a38;
    --border-color: #262c3c;
    --border-hover: #3d465f;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-gold: #f59e0b;
    --accent-amber: #d97706;
    --accent-yellow: #fbbf24;
    --accent-glow: rgba(245, 158, 11, 0.35);
    --success: #10b981;
    --danger: #ef4444;
    --font-stack: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    --bottom-nav-height: 4rem;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-stack);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* Header */
.app-header {
    background-color: rgba(21, 24, 33, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 0.75rem;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.brand-badge {
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-amber));
    color: #0f1117;
    font-weight: 800;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #ffffff;
    white-space: nowrap;
}

.header-hud {
    display: none;
    align-items: center;
    gap: 0.35rem;
    background-color: rgba(255, 255, 255, 0.04);
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.header-hud .hud-item {
    font-weight: 600;
    color: var(--accent-yellow);
}

.header-hud .hud-cps {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-icon {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
}

.btn-icon:hover {
    background-color: var(--bg-card-hover);
    border-color: var(--border-hover);
    color: #ffffff;
}

.btn-icon:active {
    transform: scale(0.92);
}

.btn-icon-danger {
    background-color: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.btn-icon-danger:hover {
    background-color: rgba(239, 68, 68, 0.25);
    border-color: var(--danger);
    color: #ffffff;
}

/* Toast Container */
.toast-container {
    position: fixed;
    top: 4.5rem;
    right: 1.25rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    max-width: 90vw;
}

.toast {
    background-color: rgba(30, 34, 46, 0.95);
    backdrop-filter: blur(8px);
    border-left: 4px solid var(--accent-gold);
    color: #ffffff;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    font-size: 0.85rem;
    animation: toastSlide 0.25s ease-out forwards;
    pointer-events: auto;
    word-break: break-word;
}

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

/* Main Layout */
.game-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 1rem;
    gap: 1.25rem;
    max-width: 1560px;
    margin: 0 auto;
    width: 100%;
}

/* Panel Containers */
.panel {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.panel-header {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.85rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.panel-header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.panel-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-count {
    background-color: var(--accent-gold);
    color: #0f1117;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
}

/* Panel 1: Cookie Center */
.panel-cookie {
    align-items: center;
    text-align: center;
    justify-content: center;
    padding: 1.5rem 1rem;
}

.cookie-counters {
    margin-bottom: 1.5rem;
    width: 100%;
}

.cookie-number {
    font-size: 2.75rem;
    font-weight: 900;
    color: var(--accent-yellow);
    line-height: 1.1;
    text-shadow: 0 0 25px var(--accent-glow);
    font-variant-numeric: tabular-nums;
    word-break: break-all;
}

.cookie-label {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-top: 0.25rem;
}

.rate-badge-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 0.75rem;
}

.rate-badge {
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.3rem 0.85rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.rate-badge strong {
    color: #ffffff;
    font-variant-numeric: tabular-nums;
}

/* Interactive Cookie */
.cookie-stage {
    position: relative;
    width: 250px;
    height: 250px;
    max-width: 80vw;
    max-height: 80vw;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.5rem auto 1.5rem auto;
    touch-action: manipulation;
}

.cookie-halo {
    position: absolute;
    width: 280px;
    height: 280px;
    max-width: 88vw;
    max-height: 88vw;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-glow) 0%, rgba(0, 0, 0, 0) 70%);
    animation: haloPulse 3.5s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes haloPulse {
    0% { transform: scale(0.94); opacity: 0.4; }
    100% { transform: scale(1.06); opacity: 0.9; }
}

.cookie-btn {
    background: none;
    border: none;
    cursor: pointer;
    width: 220px;
    height: 220px;
    max-width: 72vw;
    max-height: 72vw;
    padding: 0;
    border-radius: 50%;
    outline: none;
    transition: transform 0.06s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    z-index: 2;
    touch-action: manipulation;
}

.cookie-btn:active {
    transform: scale(0.91);
}

.cookie-btn.tap-animate {
    animation: cookiePop 0.12s ease-out;
}

@keyframes cookiePop {
    0% { transform: scale(0.90); }
    50% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

/* Particle Crumb Layer */
.particle-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
    z-index: 15;
}

.crumb-particle {
    position: absolute;
    background-color: #b46a20;
    border-radius: 50%;
    pointer-events: none;
    animation: crumbBurst 0.65s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes crumbBurst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0.2) rotate(var(--rot));
    }
}

/* Floating Click Numbers */
.floating-text {
    position: absolute;
    color: #ffffff;
    font-weight: 800;
    font-size: 1.2rem;
    pointer-events: none;
    animation: floatUpNumber 0.75s ease-out forwards;
    z-index: 20;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.85);
    font-variant-numeric: tabular-nums;
}

@keyframes floatUpNumber {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.85);
    }
    50% {
        transform: translate(-50%, -100%) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -160%) scale(1);
    }
}

/* Golden Cookie Drop */
.golden-cookie {
    position: absolute;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle, #fef08a 0%, #eab308 60%, #ca8a04 100%);
    border: 2px solid #ffffff;
    box-shadow: 0 0 30px #facc15;
    cursor: pointer;
    z-index: 80;
    touch-action: manipulation;
    animation: goldenSparkle 1.2s infinite alternate ease-in-out;
}

@keyframes goldenSparkle {
    0% { transform: scale(1) rotate(0deg); filter: brightness(1); }
    100% { transform: scale(1.18) rotate(20deg); filter: brightness(1.35); }
}

/* Mobile Quick Stats Box */
.mobile-quick-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    width: 100%;
    max-width: 360px;
    margin-top: 0.5rem;
}

.quick-stat-box {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.quick-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.quick-stat-value {
    font-size: 1.05rem;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Panel 2: Shop & Controls */
.buy-multiplier-group {
    display: flex;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.btn-multiplier {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.3rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
}

.btn-multiplier.active {
    background-color: var(--accent-gold);
    color: #0f1117;
}

.shop-filter-tabs {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
}

.shop-filter-btn {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.4rem 0.85rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
    touch-action: manipulation;
}

.shop-filter-btn.active {
    background-color: rgba(245, 158, 11, 0.15);
    border-color: var(--accent-gold);
    color: var(--accent-yellow);
}

.shop-sub-section {
    margin-bottom: 1.25rem;
}

.shop-sub-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.6rem;
}

/* Upgrades Grid */
.upgrades-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
}

.upgrade-card {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
    position: relative;
}

.upgrade-card:hover:not(:disabled) {
    background-color: var(--bg-card-hover);
    border-color: var(--accent-gold);
    transform: translateY(-2px);
}

.upgrade-card:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.upgrade-card.purchased {
    opacity: 0.4;
    border-color: var(--success);
    background-color: rgba(16, 185, 129, 0.05);
    cursor: default;
}

.upgrade-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: #ffffff;
}

.upgrade-desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.2;
}

.upgrade-price {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--accent-gold);
    margin-top: auto;
    font-variant-numeric: tabular-nums;
}

/* Buildings List */
.buildings-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.building-card {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
    touch-action: manipulation;
}

.building-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background-color: var(--accent-gold);
    transition: width 0.3s ease;
    opacity: 0.6;
}

.building-card:hover:not(.cannot-afford) {
    background-color: var(--bg-card-hover);
    border-color: var(--accent-gold);
    transform: translateX(3px);
}

.building-card.cannot-afford {
    opacity: 0.55;
    cursor: not-allowed;
}

.building-icon-wrapper {
    width: 42px;
    height: 42px;
    min-width: 42px;
    background-color: var(--bg-surface);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-yellow);
    border: 1px solid var(--border-color);
}

.building-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.building-header-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.building-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.building-level-badge {
    background-color: rgba(245, 158, 11, 0.15);
    color: var(--accent-yellow);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    white-space: nowrap;
}

.building-cps-stat {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.building-buy-action {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.2rem;
    min-width: 80px;
}

.building-cost-pill {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    transition: all 0.15s ease;
}

.building-card:not(.cannot-afford) .building-cost-pill {
    background-color: rgba(245, 158, 11, 0.2);
    border-color: var(--accent-gold);
    color: var(--accent-yellow);
}

/* Panel 3: Stats & Achievements */
.stats-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-card-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stat-card-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: #ffffff;
    font-variant-numeric: tabular-nums;
}

.achievements-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.achievements-heading {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.achievements-counter {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-yellow);
}

.progress-bar-container {
    height: 6px;
    background-color: var(--bg-surface);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-amber), var(--accent-yellow));
    transition: width 0.3s ease;
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
}

.achievement-card {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    opacity: 0.4;
    transition: all 0.2s ease;
}

.achievement-card.unlocked {
    opacity: 1;
    background-color: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.35);
}

.achievement-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #ffffff;
}

.achievement-card.unlocked .achievement-title {
    color: var(--accent-yellow);
}

.achievement-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.2;
}

/* Mobile Bottom Navigation Bar */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--bottom-nav-height);
    background-color: rgba(21, 24, 33, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-color);
    z-index: 150;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-nav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
    height: 100%;
    touch-action: manipulation;
    transition: all 0.15s ease;
}

.mobile-nav-btn svg {
    transition: transform 0.15s ease;
}

.mobile-nav-btn.active {
    color: var(--accent-gold);
}

.mobile-nav-btn.active svg {
    transform: translateY(-2px);
}

.nav-icon-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-badge {
    position: absolute;
    top: -5px;
    right: -8px;
    background-color: var(--accent-gold);
    color: #0f1117;
    font-size: 0.6rem;
    font-weight: 800;
    padding: 0.05rem 0.35rem;
    border-radius: 10px;
    display: none;
}

.nav-badge.visible {
    display: block;
}

/* Footer */
.app-footer {
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: auto;
}

/* RESPONSIVE BREAKPOINTS */

/* Mobile view (< 1024px) */
@media (max-width: 1023px) {
    .header-hud {
        display: flex;
    }

    .brand-title {
        font-size: 1rem;
    }

    .mobile-nav {
        display: flex;
    }

    .game-container {
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 1rem);
    }

    .app-footer {
        display: none;
    }

    /* Tab Switch Logic on Mobile */
    .panel {
        display: none;
    }

    .panel.active {
        display: flex;
    }
}

/* Desktop view (>= 1024px) */
@media (min-width: 1024px) {
    .game-container {
        display: grid;
        grid-template-columns: 1fr 1.25fr 1fr;
        gap: 1.25rem;
        padding: 1.5rem;
    }

    .panel {
        display: flex !important;
        height: calc(100vh - 6.5rem);
        overflow-y: auto;
    }

    .panel::-webkit-scrollbar {
        width: 6px;
    }

    .panel::-webkit-scrollbar-track {
        background: transparent;
    }

    .panel::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 4px;
    }

    .panel::-webkit-scrollbar-thumb:hover {
        background: var(--border-hover);
    }

    .panel-cookie {
        order: 1;
    }

    .panel-shop {
        order: 2;
    }

    .panel-stats {
        order: 3;
    }

    .mobile-quick-stats {
        display: none;
    }
}
