/* ═══════════════════════════════════════════════════════════
   FoxPlace — Global Styles
   Premium dark UI with glassmorphism
   ═══════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #0a0a1a;
    --bg-glass: rgba(15, 15, 35, 0.82);
    --bg-glass-hover: rgba(25, 25, 55, 0.9);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #e8e8f0;
    --text-secondary: rgba(200, 200, 220, 0.65);
    --text-muted: rgba(160, 160, 180, 0.45);
    --accent: #6c5ce7;
    --accent-glow: rgba(108, 92, 231, 0.35);
    --accent-bright: #a29bfe;
    --success: #00b894;
    --warning: #fdcb6e;
    --danger: #e17055;
    --paint-btn: #00cec9;
    --paint-btn-glow: rgba(0, 206, 201, 0.4);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 64px rgba(0,0,0,0.5);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
    --bg-primary: #f0f0f5;
    --bg-glass: rgba(245, 245, 250, 0.82);
    --bg-glass-hover: rgba(255, 255, 255, 0.9);
    --border-glass: rgba(0, 0, 0, 0.08);
    --border-glass-hover: rgba(0, 0, 0, 0.15);
    --text-primary: #1a1a2a;
    --text-secondary: rgba(40, 40, 60, 0.65);
    --text-muted: rgba(80, 80, 100, 0.45);
    --accent: #5f3dc4;
    --accent-glow: rgba(95, 61, 196, 0.25);
    --accent-bright: #6c5ce7;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }

/* ── Map ───────────────────────────────────────────────── */
#map {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: #0a0a1a;
}

/* Base map tiles only - not the pixel canvases */
.leaflet-tile-pane img.leaflet-tile { 
    filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(1.1) saturate(1.3);
    transition: filter var(--transition);
}
[data-theme="light"] .leaflet-tile-pane img.leaflet-tile {
    filter: brightness(1.0) contrast(1.0) saturate(1.1);
}
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
    background: var(--bg-glass) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
    backdrop-filter: blur(12px);
    border-radius: var(--radius-sm) 0 0 0 !important;
    border: 1px solid var(--border-glass) !important;
    border-right: none !important;
    border-bottom: none !important;
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }

/* ── Pixel Cursor ──────────────────────────────────────── */
#pixel-cursor {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    border: 2px solid rgba(255,255,255,0.85);
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(108, 92, 231, 0.5), inset 0 0 4px rgba(255,255,255,0.15);
    transition: opacity 0.1s ease;
}

[data-theme="light"] #pixel-cursor {
    border-color: rgba(0, 0, 0, 0.85);
    box-shadow: 0 0 8px rgba(108, 92, 231, 0.4), inset 0 0 4px rgba(0,0,0,0.15);
}

/* ── Toolbar ───────────────────────────────────────────── */
#toolbar {
    position: fixed;
    top: 16px;
    left: 16px;
    width: 260px;
    z-index: 2000;
    background: var(--bg-glass);
    backdrop-filter: blur(24px) saturate(1.3);
    -webkit-backdrop-filter: blur(24px) saturate(1.3);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,0.03) inset;
    overflow: hidden;
    transition: transform var(--transition), opacity var(--transition);
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
}

#toolbar.collapsed #toolbar-body { display: none; }
#toolbar.collapsed { border-radius: var(--radius-md); }

#toolbar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-glass);
    cursor: pointer;
    user-select: none;
}

#toolbar.collapsed #toolbar-header { border-bottom: none; }

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon { font-size: 22px; }

.logo-text {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent-bright), var(--paint-btn));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#toolbar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: var(--transition);
    display: flex;
    align-items: center;
}
#toolbar-toggle:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }
#toolbar.collapsed #toolbar-toggle svg { transform: rotate(180deg); }
#toolbar-toggle svg { transition: transform var(--transition); }

#toolbar-body {
    padding: 4px 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

#toolbar-body::-webkit-scrollbar { width: 4px; }
#toolbar-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* ── Toolbar Sections ──────────────────────────────────── */
.toolbar-section {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-glass);
}
.toolbar-section:last-child { border-bottom: none; }

.section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* ── Balance ───────────────────────────────────────────── */
#pixel-balance {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 10px;
}

#balance-amount {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -1px;
    background: linear-gradient(135deg, #a29bfe, #6c5ce7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    transition: transform 0.2s ease;
}

#balance-amount.bump {
    animation: balanceBump 0.4s ease;
}

@keyframes balanceBump {
    0% { transform: scale(1); }
    40% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.balance-unit {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

#income-timer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.timer-bar-bg {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 4px;
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-bright));
    border-radius: 4px;
    transition: width 0.3s linear;
}

#timer-text {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 60px;
    text-align: right;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-glass {
    background: rgba(255,255,255,0.06);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
    width: 100%;
}
.btn-glass:hover {
    background: rgba(255,255,255,0.1);
    border-color: var(--border-glass-hover);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #5f3dc4);
    color: white;
    box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-paint {
    background: linear-gradient(135deg, var(--paint-btn), #00b894);
    color: #0a0a1a;
    font-size: 15px;
    font-weight: 700;
    padding: 14px 28px;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 24px var(--paint-btn-glow), 0 0 0 1px rgba(255,255,255,0.1) inset;
    animation: paintBtnPulse 2s ease-in-out infinite;
}
.btn-paint:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 8px 32px var(--paint-btn-glow);
}

@keyframes paintBtnPulse {
    0%, 100% { box-shadow: 0 4px 24px var(--paint-btn-glow); }
    50% { box-shadow: 0 4px 32px rgba(0, 206, 201, 0.6); }
}

.btn-cancel {
    background: rgba(255,255,255,0.08);
    color: var(--text-secondary);
    padding: 14px 16px;
    border-radius: var(--radius-md);
    font-size: 16px;
}
.btn-cancel:hover { background: rgba(225, 112, 85, 0.2); color: var(--danger); }

/* ── Paint Actions ─────────────────────────────────────── */
#paint-actions {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    gap: 10px;
    align-items: center;
    animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Color Palette ─────────────────────────────────────── */
#color-palette {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
    margin-bottom: 10px;
}

.color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}
.color-swatch:hover {
    transform: scale(1.2);
    z-index: 1;
    box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}
.color-swatch.active {
    border-color: white;
    box-shadow: 0 0 0 2px var(--accent), 0 2px 12px rgba(0,0,0,0.4);
    transform: scale(1.15);
}

#custom-color-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

#color-input {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: none;
    padding: 0;
}
#color-input::-webkit-color-swatch-wrapper { padding: 0; }
#color-input::-webkit-color-swatch { border: 1px solid var(--border-glass); border-radius: 6px; }

#color-hex {
    font-size: 12px;
    font-weight: 500;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-secondary);
}

/* ── Info ───────────────────────────────────────────────── */
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
}

.info-label {
    font-size: 12px;
    color: var(--text-muted);
}

.info-value {
    font-size: 12px;
    font-weight: 500;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-secondary);
}

/* ── Controls ──────────────────────────────────────────── */
.control-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

kbd {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    font-size: 10px;
    font-family: var(--font);
    font-weight: 600;
    color: var(--text-primary);
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border-glass);
    border-radius: 5px;
}

.mobile-only { display: none; }
@media (pointer: coarse) {
    .desktop-only { display: none; }
    .mobile-only { display: flex; }
}

/* ── Zoom Hint ─────────────────────────────────────────── */
#zoom-hint {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1500;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    padding: 12px 22px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-md);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Sync Status ───────────────────────────────────────── */
#sync-status {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 2000;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-glass);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
}

.sync-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--warning);
    box-shadow: 0 0 6px var(--warning);
}
.sync-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

/* ── Modal ─────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: var(--bg-glass);
    backdrop-filter: blur(24px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 90%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-content h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

.modal-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 18px;
    line-height: 1.5;
}

.modal-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 18px;
    outline: none;
    transition: border-color var(--transition);
}
.modal-input:focus { border-color: var(--accent); }

.modal-actions {
    display: flex;
    gap: 10px;
}
.modal-actions .btn { flex: 1; }

.modal-note {
    margin-top: 14px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

/* ── Toasts ────────────────────────────────────────────── */
#toasts {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 6000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 14px 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 300px;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.error { border-left: 3px solid var(--danger); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 640px) {
    #toolbar {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 55vh;
    }

    #toolbar.collapsed {
        border-radius: var(--radius-md) var(--radius-md) 0 0;
    }

    #toolbar-header {
        padding: 12px 20px;
    }

    #toolbar.collapsed #toolbar-toggle svg { transform: rotate(0deg); }
    #toolbar:not(.collapsed) #toolbar-toggle svg { transform: rotate(180deg); }

    #paint-actions {
        bottom: auto;
        top: 16px;
    }

    #zoom-hint {
        bottom: auto;
        top: 16px;
    }

    #sync-status {
        bottom: auto;
        top: 16px;
        left: 16px;
        right: auto;
    }

    #toasts {
        top: auto;
        bottom: 80px;
        right: 16px;
        left: 16px;
    }
    .toast { max-width: 100%; }
}
