:root {
    /* Primary Colors - Light Theme (Default) */
    --primary-bg: #fdf6e3;
    --secondary-bg: #fffbf0;
    --cookie-color: #d2691e;
    --cookie-dark: #8b4513;
    --accent: #ff8c00;
    --accent-hover: #e07b00;
    --text-main: #5d4037;
    --text-light: #8d6e63;
    --panel-bg: #ffffff;
    --border-color: #efebe9;
    --success: #66bb6a;
    --danger: #ef5350;
    --disabled: #e0e0e0;

    /* Fonts */
    --font-heading: 'Fredoka', sans-serif;
    --font-body: 'Nunito', sans-serif;
}

/* Dark Theme Variables */
body.dark-mode {
    --primary-bg: #2d2420;
    --secondary-bg: #251e1b;
    --panel-bg: #352b26;
    --border-color: #4a3e38;
    --text-main: #e8dcd8;
    --text-light: #bcaaa4;
    --disabled: #5d4037;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    background-color: var(--primary-bg);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

#game-app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

@media (min-width: 768px) {
    #game-app {
        flex-direction: row;
    }
}

/* Common UI */
button {
    cursor: pointer;
    font-family: var(--font-heading);
    border: none;
    outline: none;
    transition: transform 0.1s, background-color 0.2s;
}

button:active {
    transform: scale(0.95);
}

.primary-btn {
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 1.2rem;
    box-shadow: 0 4px 0 var(--cookie-dark);
}

.full-width {
    width: 100%;
}

/* Header & Controls */
.header-stats {
    text-align: center;
    width: 100%;
    margin-bottom: 20px;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: var(--text-light);
    font-weight: 700;
    position: relative;
    z-index: 50;
    /* Ensure controls are above other elements */
}

.controls {
    display: flex;
    gap: 10px;
}

.controls button {
    background: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    padding: 0;
    /* Fix alignment */
    line-height: 1;
    cursor: pointer;
    /* Explicit cursor */
    z-index: 51;
    /* Explicit z-index */
}

.score-container h1 {
    font-family: var(--font-heading);
    font-size: 3rem;
    margin: 0;
    color: var(--text-main);
}

#cps-display {
    margin-top: 5px;
    font-weight: 700;
    color: var(--accent);
    background: rgba(255, 140, 0, 0.15);
    /* Slightly more visible */
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
}

/* Big Cookie */
#click-zone {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--primary-bg);
    position: relative;
    padding: 20px;
    transition: background-color 0.3s;
}

.cookie-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex: 1;
}

#big-cookie {
    width: 250px;
    height: 250px;
    background: url('https://em-content.zobj.net/source/microsoft-teams/363/cookie_1f36a.png') no-repeat center center / contain;
    background-color: transparent;
    border-radius: 50%;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.2));
    transition: transform 0.05s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
}

#big-cookie:active {
    transform: scale(0.92);
}

/* Right Panel */
#shop-zone {
    flex: 1;
    background: var(--panel-bg);
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s, border-color 0.3s;
}

@media (min-width: 768px) {
    #shop-zone {
        max-width: 450px;
        border-left: 2px solid var(--border-color);
    }
}

.shop-nav {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    background: var(--secondary-bg);
}

.tab-btn {
    flex: 1;
    padding: 15px;
    background: transparent;
    color: var(--text-light);
    font-weight: 700;
    border-bottom: 4px solid transparent;
}

.tab-btn.active {
    background: var(--panel-bg);
    color: var(--cookie-color);
    border-bottom-color: var(--cookie-color);
}

.shop-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: none;
}

.shop-content.active {
    display: block;
}

/* Styles for Building/Upgrades Items */
.building-item,
.upgrade-item {
    display: flex;
    align-items: center;
    background: var(--panel-bg);
    /* Use panel bg or lighten/darken? */
    border: 2px solid var(--border-color);
    margin-bottom: 8px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

/* In dark mode, items should be slightly lighter than BG or same with border */
body.dark-mode .building-item,
body.dark-mode .upgrade-item {
    background: rgba(255, 255, 255, 0.05);
}

.building-item:hover,
.upgrade-item:hover {
    border-color: var(--accent);
    transform: translateX(4px);
}

.building-item.disabled,
.upgrade-item.disabled {
    opacity: 0.6;
    filter: grayscale(1);
    cursor: not-allowed;
    background: rgba(0, 0, 0, 0.05);
}

.b-icon {
    font-size: 2rem;
    margin-right: 15px;
    width: 40px;
    text-align: center;
}

.b-info {
    flex: 1;
}

.b-name {
    font-weight: 800;
    color: var(--text-main);
    font-family: var(--font-heading);
}

.b-cost {
    color: var(--accent);
    font-weight: 700;
}

.b-count {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--disabled);
    margin-left: 10px;
}

.upgrade-item {
    flex-direction: column;
    align-items: flex-start;
}

.u-info {
    width: 100%;
}

.u-name {
    font-weight: 700;
    font-family: var(--font-heading);
    margin-bottom: 4px;
    color: var(--text-main);
}

.u-desc {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 8px;
    line-height: 1.2;
}

.u-cost {
    font-weight: bold;
    color: var(--accent);
    font-size: 0.9rem;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--panel-bg);
    padding: 25px;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    /* Prevent modal from growing too tall */
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    font-family: var(--font-heading);
}

.close-btn {
    background: none;
    font-size: 2rem;
    padding: 0;
    line-height: 1;
    color: var(--text-light);
}

.close-btn:hover {
    color: var(--danger);
}

/* Help Guide Styles */
.help-content {
    max-width: 500px;
}

.scrollable-y {
    overflow-y: auto;
    padding-right: 5px;
    /* Space for scrollbar */
}

.guide-section {
    margin-bottom: 25px;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 15px;
}

.guide-section:last-of-type {
    border-bottom: none;
}

.guide-section h3 {
    margin: 0 0 10px 0;
    font-family: var(--font-heading);
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 10px;
}

.guide-section p {
    margin: 0 0 10px 0;
    color: var(--text-light);
    font-size: 0.95rem;
    line-height: 1.5;
}

.guide-section ul {
    margin: 0;
    padding-left: 20px;
    color: var(--text-light);
    text-align: left;
}

.guide-section li {
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.guide-step {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    text-align: left;
}

.step-icon {
    font-size: 2rem;
    margin-right: 15px;
    min-width: 40px;
    text-align: center;
}

.step-text h3 {
    margin: 0 0 5px 0;
    font-family: var(--font-heading);
    color: var(--accent);
}

.step-text p {
    margin: 0;
    color: var(--text-light);
    font-size: 0.9rem;
}

/* Settings */
.setting-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    font-weight: 700;
    color: var(--text-main);
}

.action-btn {
    width: 100%;
    padding: 12px;
    background: var(--text-light);
    color: white;
    border-radius: 8px;
    margin-top: 10px;
}

.danger-btn {
    width: 100%;
    padding: 12px;
    background: var(--danger);
    color: white;
    border-radius: 8px;
    margin-top: 10px;
}

/* Toasts / Floating */
.floating-number {
    position: absolute;
    pointer-events: none;
    color: var(--text-main);
    font-weight: 800;
    font-size: 1.5rem;
    animation: floatUp 1s ease-out forwards;
    z-index: 20;
    text-shadow: 0 0 2px var(--primary-bg);
    /* Better than stroke for theme adapt */
}

@keyframes floatUp {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translateY(-100px) scale(1.2);
        opacity: 0;
    }
}

.toast {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-main);
    color: var(--primary-bg);
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 700;
    opacity: 0;
    animation: fadeInOut 4s forwards;
    width: max-content;
    max-width: 90%;
    z-index: 100;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

#overlay-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-align: center;
}

#overlay-content {
    background: var(--cookie-color);
    padding: 40px;
    border-radius: 30px;
    box-shadow: 0 0 50px rgba(255, 140, 0, 0.5);
    animation: bounceIn 0.5s;
    max-width: 90%;
}

@keyframes bounceIn {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }

    50% {
        transform: scale(1.05);
    }

    70% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#overlay-content h2 {
    font-size: 2.5rem;
    margin: 0 0 20px 0;
    font-family: var(--font-heading);
}

#overlay-content p {
    font-size: 1.2rem;
    margin-bottom: 30px;
}

.empty-state {
    text-align: center;
    color: var(--text-light);
    padding: 40px 20px;
    font-style: italic;
}

.hidden {
    display: none !important;
}