/* =======================================
   CSS VARIABLES & PRESETS
   ======================================= */
:root {
    --bg-base: #f0f2f5;
    --bg-card: rgba(255, 255, 255, 0.85);
    --text-main: #1e293b;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #e2e8f0;
    --secondary-hover: #cbd5e1;
    --danger: #ef4444;
    --success: #10b981;
    --border: rgba(0, 0, 0, 0.1);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Outfit', sans-serif;
    --transition: 0.2s ease;
}

.theme-dark {
    --bg-base: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.85);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --secondary: #334155;
    --secondary-hover: #475569;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
}

/* =======================================
   RESET & BASE 
   ======================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-body);
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition);
}

/* Background Shapes for modern feel */
.bg-shapes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
}

.shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
}

.shape-1 {
    width: 500px;
    height: 500px;
    background: var(--primary);
    top: -100px;
    left: -100px;
}

.shape-2 {
    width: 400px;
    height: 400px;
    background: #8b5cf6;
    bottom: -50px;
    right: -100px;
}

/* =======================================
   UTILITY CLASSES 
   ======================================= */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--text-main);
}

.btn-secondary:not(:disabled):hover {
    background: var(--secondary-hover);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-text:hover {
    color: var(--text-main);
}

.btn-block {
    width: 100%;
}

.error-msg {
    color: var(--danger);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    text-align: center;
}

/* =======================================
   LAYOUT 
   ======================================= */
.app-wrapper {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* =======================================
   AUTH VIEW 
   ======================================= */
#auth-view {
    max-width: 400px;
    margin: 4rem auto;
    padding: 2rem;
    text-align: center;
}

.logo {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.logo span {
    color: var(--primary);
}

.auth-form {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    text-align: left;
    gap: 0.25rem;
}

.input-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.input-group input {
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-main);
    outline: none;
    transition: border-color var(--transition);
}

.theme-dark .input-group input {
    background: rgba(255, 255, 255, 0.05);
}

.input-group input:focus {
    border-color: var(--primary);
}

.auth-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.auth-actions button {
    flex: 1;
}

/* =======================================
   GAME VIEW 
   ======================================= */
.top-bar {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.branding {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.username {
    font-weight: 600;
}

.sync-indicator {
    text-align: right;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-saved {
    color: var(--success);
}

.status-saving {
    color: var(--text-muted);
    font-style: italic;
}

.status-error {
    color: var(--danger);
}

.game-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .game-layout {
        grid-template-columns: 1fr 1fr;
    }
}

/* Clicker Panel */
.clicker-panel {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 400px;
    position: relative;
    overflow: hidden;
}

.stats-display {
    margin-bottom: 2rem;
}

.stat-main .value {
    font-size: 3rem;
    font-weight: 700;
    display: block;
    line-height: 1;
    color: var(--primary);
}

.stat-main .label {
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-sub {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.main-click-btn {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border: none;
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4), inset 0 5px 15px rgba(255, 255, 255, 0.3);
    cursor: pointer;
    position: relative;
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    /* prevent double-tap zoom on mobile */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.main-click-btn:active {
    transform: scale(0.95);
    box-shadow: 0 5px 15px rgba(99, 102, 241, 0.4), inset 0 2px 5px rgba(255, 255, 255, 0.3);
}

.main-click-btn .btn-content {
    color: white;
    font-size: 2rem;
    font-weight: 700;
    pointer-events: none;
}

.level-info {
    margin-top: 2rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Tabs Panel */
.tabs-panel {
    display: flex;
    flex-direction: column;
    min-height: 400px;
}

.tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 1rem 0.5rem;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    padding: 1.5rem;
    flex-grow: 1;
    overflow-y: auto;
    max-height: 400px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* Upgrades List */
.upgrade-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.upgrade-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.upgrade-item:hover:not(:disabled) {
    border-color: var(--primary);
    transform: translateX(4px);
}

.upgrade-item:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    filter: grayscale(1);
}

.up-info h4 {
    color: var(--text-main);
    font-size: 1.1rem;
}

.up-info p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.25rem 0;
}

.up-info .owned {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
}

.up-action {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.price {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
}

.buy-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    padding: 0.2rem 0.5rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 4px;
    margin-top: 0.25rem;
}

/* Prestige */
.prestige-info {
    text-align: center;
    padding: 1rem;
}

.prestige-info h3 {
    font-size: 2rem;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.prestige-req {
    margin: 2rem 0;
    font-weight: 600;
    color: var(--text-muted);
}

/* Leaderboard */
.leaderboard-list {
    list-style: none;
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.leaderboard-list li {
    padding: 0.75rem 1rem;
    background: var(--bg-base);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.lb-rank {
    font-weight: bold;
    width: 30px;
    color: var(--primary);
}

.lb-name {
    flex-grow: 1;
    font-weight: 500;
}

.lb-points {
    font-family: monospace;
}

.lb-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem !important;
    background: transparent !important;
}

/* Chat UI */
.chat-container {
    margin-top: 1.5rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    height: 300px;
}

.chat-container h4 {
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.theme-dark .chat-messages {
    background: rgba(255, 255, 255, 0.02);
}

.chat-msg {
    font-size: 0.85rem;
    background: var(--bg-card);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    word-break: break-word;
}

.chat-msg span.chat-user {
    font-weight: bold;
    color: var(--primary);
    margin-right: 0.3rem;
}

.chat-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.chat-input-wrapper input {
    flex-grow: 1;
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
}

.chat-input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Achievements */
.achievements-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.achievement-card {
    background: var(--bg-base);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    opacity: 0.5;
    filter: grayscale(1);
    transition: all var(--transition);
}

.achievement-card.unlocked {
    opacity: 1;
    filter: grayscale(0);
    border-style: solid;
    border-color: var(--success);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.ach-title {
    font-weight: bold;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.ach-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Settings */
.setting-item {
    display: flex;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

/* =======================================
   ANIMATIONS & EFFECTS
   ======================================= */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Particle effect for clicking */
.particle {
    position: absolute;
    pointer-events: none;
    animation: floatUp 0.8s ease-out forwards;
    font-weight: bold;
    color: var(--primary);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

@keyframes floatUp {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translateY(-100px) scale(1.5);
        opacity: 0;
    }
}

/* Golden Coin Event */
.golden-coin {
    position: fixed;
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, #fcd34d 0%, #d97706 100%);
    border: 4px solid #fef3c7;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    color: #fff;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.8), inset 0 0 10px rgba(255, 255, 255, 0.5);
    animation: spin 2s linear infinite;
    transition: left 8s linear;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.golden-coin:hover {
    transform: scale(1.1);
    box-shadow: 0 0 30px rgba(251, 191, 36, 1), inset 0 0 15px rgba(255, 255, 255, 0.8);
}

@keyframes spin {
    0% {
        transform: rotateY(0deg);
    }

    100% {
        transform: rotateY(360deg);
    }
}

/* Toast System */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 9999;
}

.toast {
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-left: 4px solid var(--primary);
    border-radius: 4px;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease-out;
    transition: opacity 0.3s ease;
}

.toast-error {
    border-left-color: var(--danger);
}

.toast-success {
    border-left-color: var(--success);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Reduces motion if requested by OS */
@media (prefers-reduced-motion: reduce) {

    *,
    ::before,
    ::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}