/* Base */
:root {
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
}
body {
    background: #000;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: all 0.3s ease;
}

/* Light Theme Support */
body.light-theme {
    background: #d4d4d4; /* Darker grey, less blinding */
    color: #181818;
}

body.light-theme .glass-panel,
body.light-theme .glass-btn,
body.light-theme .bottom-nav,
body.light-theme .creation-modal {
    background: rgba(240, 240, 240, 0.95); /* Slightly off-white */
    border-color: rgba(0, 0, 0, 0.15);
    color: #000;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
body.light-theme .glass-btn:active {
    background: rgba(220, 220, 220, 1);
}

body.light-theme .creation-card {
    background: #f5f5f5;
    color: #000;
    border-top: 1px solid rgba(0,0,0,0.1);
}
body.light-theme .settings-card {
    background: #f5f5f5;
    color: #000;
}

/* Force dark icons in light mode */
body.light-theme .glass-btn i, 
body.light-theme .glass-panel i,
body.light-theme .settings-card i,
body.light-theme .bottom-nav i,
body.light-theme button i {
    color: #222 !important;
}
/* Exceptions */
body.light-theme .create-btn i { color: #fff !important; }
body.light-theme .confirm-btn i { color: #fff !important; }

body.light-theme .text-white {
    color: #000 !important;
}
body.light-theme .text-gray-400 {
    color: #555 !important;
}
body.light-theme .zenly-input {
    background: #fff;
    border-color: #ccc;
    color: #000;
}
body.light-theme .zenly-input::placeholder {
    color: #888;
}

/* Map Style Buttons in Light Mode */
body.light-theme .map-style-btn {
    background: #e5e5e5;
    color: #333;
    border: 2px solid transparent;
}
body.light-theme .map-style-btn.active {
    background: #fff;
    color: #000;
    border-color: #000;
}

/* Tabs in Light Mode */
body.light-theme .tab-btn {
    color: #666;
}
body.light-theme .tab-btn.active {
    color: #000;
}
body.light-theme .tab-btn.active::after {
    background: #000;
}

/* Profile & Settings tweaks */
body.light-theme .bg-white\/5 {
    background: rgba(0,0,0,0.05);
    border-color: rgba(0,0,0,0.1);
}
body.light-theme .bg-white\/10 {
    background: rgba(0,0,0,0.1);
}
body.light-theme .bg-white\/20 {
    background: rgba(0,0,0,0.2);
}

/* --- UI COMPONENTS --- */
.bottom-nav-container {
    position: absolute;
    bottom: max(20px, var(--safe-area-bottom));
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 1000;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.bottom-nav-container.hidden-nav { transform: translateY(150%); opacity: 0; pointer-events: none !important; }

.bottom-nav {
    pointer-events: auto;
    background: rgba(20, 20, 20, 0.9);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 8px 24px;
    display: flex;
    align-items: center;
    gap: 40px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.top-bar-container {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    left: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    transition: opacity 0.3s;
}
.top-bar-container.hidden-top { opacity: 0; pointer-events: none !important; }

.glass-btn {
    pointer-events: auto;
    background: rgba(20, 20, 20, 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.create-btn-wrapper { position: relative; top: -25px; }
.create-btn {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #6C38FF, #9D50FF);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(6deg);
    border: 4px solid #000;
    box-shadow: 0 8px 20px rgba(108, 56, 255, 0.4);
    transition: transform 0.2s;
}
.create-btn:active { transform: rotate(0deg) scale(0.95); }

/* --- MAP MARKERS FIX --- */
.marker-container {
    background: transparent;
    will-change: transform;
    width: 48px !important;
    height: 48px !important;
    display: block;
    transition: opacity 0.3s;
    z-index: 1000 !important; /* Иконки поверх линий */
    overflow: visible !important;
}

/* ZOOM SCALING LOGIC */
/* Base transition for smooth scaling */
.marker-container > div {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: center center;
}

/* Low Zoom (City/Country view) - Tiny dots */
#map.zoom-low .marker-container > div {
    transform: scale(0.4);
}
#map.zoom-low .marker-container .badge-icon {
    opacity: 0; /* Hide small badges to reduce clutter */
}
#map.zoom-low .cluster-badge {
    transform: scale(1.5); /* Make counter readable */
}

/* Mid Zoom (District view) - Medium icons */
#map.zoom-mid .marker-container > div {
    transform: scale(0.7);
}

/* High Zoom (Street view) - Full size */
#map.zoom-high .marker-container > div {
    transform: scale(1);
}

/* Ultra Zoom (Very close) - 1.3x */
#map.zoom-ultra .marker-container > div {
    transform: scale(1.3);
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.5));
}

/* Max Zoom (Directly overhead) - 1.6x */
#map.zoom-max .marker-container > div {
    transform: scale(1.6);
    filter: drop-shadow(0 15px 30px rgba(0,0,0,0.6));
    z-index: 5000; /* Ensure top */
}

/* Mega Zoom (19+) - 2.0x */
#map.zoom-mega .marker-container > div {
    transform: scale(2.0);
    filter: drop-shadow(0 20px 40px rgba(0,0,0,0.7));
    z-index: 6000;
}

.squircle {
    width: 48px;
    height: 48px;
    border-radius: 18px;
    background-color: #222;
    background-size: cover;
    background-position: center;
    border: 2.5px solid white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    position: relative;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cluster-container {
    width: 48px !important;
    height: 48px !important;
    z-index: 1000 !important;
}
.cluster-stack {
    position: relative;
    width: 100%;
    height: 100%;
}
.cluster-item {
    position: absolute;
    width: 48px;
    height: 48px;
    border-radius: 18px;
    border: 2px solid white;
    background-size: cover;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    transition: transform 0.3s;
}
.cluster-item:nth-child(1) { transform: translate(0, 0) rotate(0deg); z-index: 3; }
.cluster-item:nth-child(2) { transform: translate(4px, -4px) rotate(5deg); z-index: 2; filter: brightness(0.8); }
.cluster-item:nth-child(3) { transform: translate(8px, -8px) rotate(10deg); z-index: 1; filter: brightness(0.6); }

.cluster-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #9D50FF;
    color: white;
    font-weight: bold;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 10px;
    border: 2px solid white;
    z-index: 10;
}

.system-event .squircle {
    border-color: #8A2BE2; /* Purple for recommendations */
    box-shadow: 0 0 15px rgba(138, 43, 226, 0.4);
}
@keyframes pulse-border {
    0% { box-shadow: 0 0 0 0 rgba(138, 43, 226, 0.6); }
    50% { box-shadow: 0 0 0 6px rgba(138, 43, 226, 0); }
    100% { box-shadow: 0 0 0 0 rgba(138, 43, 226, 0); }
}

.badge-icon {
    width: 20px;
    height: 20px;
    position: absolute;
    bottom: -6px;
    right: -6px;
    border-radius: 50%;
    border: 2px solid white;
    background-size: cover;
    background-color: #444;
}

.css-pin {
    width: 40px;
    height: 40px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin-top: -20px;
    pointer-events: none;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.css-pin.active { opacity: 1; }
.pin-head {
    width: 30px;
    height: 30px;
    background: #9D50FF;
    border: 3px solid white;
    border-radius: 50% 50% 0 50%;
    transform: rotate(45deg);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    margin-bottom: 8px;
    position: relative;
}
.pin-head::after {
    content: '';
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.pin-shadow { width: 10px; height: 4px; background: rgba(0,0,0,0.5); border-radius: 50%; filter: blur(2px); }

/* MODAL & CARD */
.creation-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
.creation-modal.active { pointer-events: auto; opacity: 1; }
.creation-modal.active #modal-bg { opacity: 1; }

#modal-bg {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    transition: opacity 0.3s;
    opacity: 0;
}

.creation-card {
    background: #181818;
    border-radius: 32px 32px 0 0;
    padding: 24px;
    padding-bottom: max(32px, var(--safe-area-bottom));
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 3001;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.creation-modal.active .creation-card { transform: translateY(0); }

.creation-modal.location-mode { pointer-events: none; }
.creation-modal.location-mode #modal-bg { opacity: 0; }
.creation-modal.location-mode .creation-card {
    background: transparent;
    border: none;
    pointer-events: none;
    padding: 16px;
    box-shadow: none;
    overflow: visible;
}
.creation-modal.location-mode .creation-card button.confirm-btn {
    pointer-events: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.location-search-wrapper {
    position: fixed;
    top: -100px;
    left: 16px;
    right: 16px;
    z-index: 3005;
    transition: top 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
}
.location-search-wrapper.active { top: max(16px, var(--safe-area-top)); }

.zenly-input {
    width: 100%;
    background: #2a2a2a;
    border: 1px solid rgba(255,255,255,0.1);
    color: white;
    padding: 16px;
    border-radius: 16px;
    font-size: 16px;
    margin-bottom: 16px;
    outline: none;
}
.step-content { display: none; }
.step-content.active { display: block; animation: fadeUp 0.3s; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

#file-input { display: none; }
.upload-btn {
    border: 2px dashed #444;
    border-radius: 16px;
    height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #888;
    cursor: pointer;
    margin-bottom: 16px;
    background-size: cover;
    background-position: center;
    transition: background-color 0.2s;
    position: relative;
    overflow: hidden;
}
.upload-btn-overlay {
    background: rgba(0,0,0,0.5);
    width: 100%;
    height: 100%;
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* SPIDER OVERLAY & CARD */
#spider-overlay-bg {
    background: radial-gradient(circle at center, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.8) 100%);
    pointer-events: none;
}
#spider-overlay-bg.active { opacity: 1; }

/* Darken ONLY tiles - NO BLUR */
#map.spider-mode .leaflet-tile-pane {
    /* filter: brightness(0.4) grayscale(0.8); */ /* Darkening disabled per user request */
    transition: filter 0.5s ease;
}
/* Убеждаемся, что маркеры яркие и четкие */
#map.spider-mode .leaflet-marker-pane {
    filter: none !important;
    opacity: 1 !important;
    z-index: 2000 !important;
}

/* Event card - Floating at top-center */
#event-card-overlay {
    position: fixed;
    top: 8%;
    left: 0;
    right: 0;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none !important; /* Critical: Allow clicks through to map */
}
#event-card-overlay.active {
    visibility: visible;
    opacity: 1;
}
#event-card-content {
    pointer-events: auto !important; /* Catch clicks on the card itself */
}
#event-card-content {
    pointer-events: auto;
    background: rgba(20, 20, 20, 0.98);
    width: 90%;
    max-width: 350px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 24px;
    padding: 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

/* Close Button for Event Card */
#card-close-btn {
    display: flex; /* Ensure it's visible via CSS if JS adds it */
}

/* System Event Colors */
.system-event .squircle {
    border-color: #8A2BE2; /* Purple for recommendations */
    box-shadow: 0 0 15px rgba(138, 43, 226, 0.4);
}
.system-event.gold .squircle {
    border-color: #FFD700 !important; /* Gold for ADs */
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
    animation: pulse-border-gold 3s infinite;
}

@keyframes pulse-border-gold {
    0% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.6); }
    50% { box-shadow: 0 0 0 6px rgba(255, 215, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
}

/* Кнопка закрытия (крестик) - скрыта, управление тапами/свайпом */
#close-spider-btn {
    display: none !important;
}

/* SETTINGS MODAL */
.settings-modal {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
.settings-modal.active { pointer-events: auto; opacity: 1; }

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

.settings-card {
    background: #181818;
    border-radius: 32px 32px 0 0;
    padding: 24px;
    padding-bottom: max(32px, var(--safe-area-bottom));
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 5001;
    border-top: 1px solid rgba(255,255,255,0.1);
    position: relative;
}
.settings-modal.active .settings-card { transform: translateY(0); }

.settings-tabs {
    display: flex;
    gap: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 24px;
}
.tab-btn {
    padding: 12px 16px;
    color: #888;
    font-weight: bold;
    position: relative;
    transition: color 0.2s;
    text-align: center;
    min-width: 80px;
}
.tab-btn.active { color: white; }
.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: white;
    border-radius: 2px;
}

.tab-content { display: none; animation: fadeUp 0.3s; }
.tab-content.active { display: block; }

.map-style-btn {
    background: #2a2a2a;
    border-radius: 16px;
    padding: 8px;
    border: 2px solid transparent;
    text-align: center;
    font-size: 12px;
    color: #aaa;
    transition: all 0.2s;
}
.map-style-btn.active {
    border-color: #9D50FF;
    background: #333;
    color: white;
}

/* Theme Toggle Fixes */
.theme-btn.active i {
    color: white !important; /* Always white in active state regardless of theme */
}
.theme-btn.active {
    border-color: #9D50FF;
}
/* Moon Icon visible in Light Theme selector */
body.light-theme #theme-dark i {
    color: white !important;
}

/* Chat Room Transition */
.safe-pb {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.translate-x-full { transform: translateX(100%); }
.translate-y-full { transform: translateY(100%); }

/* Chat Room Overlay - Override to ensure it sits on top */
#chat-room-overlay {
    position: fixed;
    inset: 0;
    z-index: 6000; /* Higher than modals */
    background: #181818;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease-out;
}

/* Animations */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.animate-fade-in { animation: fade-in 0.3s ease-out; }
.cursor-zoom-out { cursor: zoom-out; }

/* Filters */
#map-filters button.active {
    background: #9D50FF;
    color: white;
    border-color: transparent;
}
body.light-theme #map-filters button.glass-btn {
    background: #fff;
    color: #333;
    border: 1px solid #ddd;
}
body.light-theme #map-filters button.active {
    background: #000;
    color: #fff;
    border-color: #000;
}

/* Chat Messages Container - Fix for Overlap */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: calc(160px + env(safe-area-inset-bottom)) !important; /* Ensure enough space for input area */
    display: flex;
    flex-direction: column;
    user-select: text !important;
    -webkit-user-select: text !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent; 
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2); 
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4); 
}

/* Chat Input Area - Fixed at bottom */
#chat-input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: #181818;
    display: flex;
    gap: 8px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    align-items: center;
    z-index: 20;
}
#chat-messages * {
    user-select: text !important;
    -webkit-user-select: text !important;
}
#chat-messages a {
    pointer-events: auto !important;
    z-index: 10;
    position: relative;
}

/* Gold Pin (Ad) */
.marker-pin.gold .pin-head {
    background: #FFD700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}
.system-event.gold .squircle {
    border-color: #FFD700;
    animation: pulse-border-gold 3s infinite;
}
@keyframes pulse-border-gold {
    0% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.6); }
    50% { box-shadow: 0 0 0 6px rgba(255, 215, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
}

/* Cluster Font */
.marker-cluster div {
    font-family: 'Inter', -apple-system, sans-serif !important;
    font-weight: 700 !important;
    font-size: 14px !important; 
}

/* Image Placeholder */
.event-image-empty {
    width: 100%;
    height: 100%;
    background: #2a2a2a;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}
