/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap');

:root {
    --primary-color: #10b981;
    --bg-overlay: rgba(255, 255, 255, 0.85);
    --bg-body: #e5e7eb;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --card-bg: rgba(255, 255, 255, 0.6);
    --divider-bg: rgba(0, 0, 0, 0.1);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 16px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
    --bg-overlay: rgba(17, 24, 39, 0.9);
    --bg-body: #030712;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --card-bg: rgba(255, 255, 255, 0.05);
    --divider-bg: rgba(255, 255, 255, 0.1);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    background-color: var(--bg-body);
    color: var(--text-primary);
    transition: background-color 0.3s ease;
}

#map {
    height: 100%;
    width: 100%;
    z-index: 1;
}

/* UI Overlay */
.ui-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: var(--bg-overlay);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 340px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s ease;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

/* Scrollbar for the overlay */
.ui-overlay::-webkit-scrollbar {
    width: 4px;
}

.ui-overlay::-webkit-scrollbar-thumb {
    background: var(--divider-bg);
    border-radius: 10px;
}

.ui-overlay.hidden {
    transform: translateX(-380px);
    opacity: 0;
    pointer-events: none;
}

.toggle-ui-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background: var(--bg-overlay);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    display: none;
    align-items: center;
    justify-content: center;
}

.toggle-ui-btn.visible {
    display: flex;
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1rem;
}

.brand h1 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

.brand-icon {
    width: 28px;
    height: 28px;
    background: var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 16px;
}

/* User Controls - Larger for Touch */
.user-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 1.25rem;
}

.user-select {
    flex: 1;
    height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--divider-bg);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 18px;
}

.add-user-btn {
    width: 44px;
    height: 44px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Stats Card */
.stats-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1rem;
    display: grid;
    grid-template-columns: 1fr 1px 1fr;
    gap: 10px;
    margin-bottom: 1.25rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-divider {
    background: var(--divider-bg);
    height: 100%;
}

.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 700;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Controls Section */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--divider-bg);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Knowledge Levels - Better Touch Targets */
.level-picker {
    display: flex;
    gap: 8px;
}

.level-btn {
    flex: 1;
    height: 40px;
    border-radius: 10px;
    border: 2px solid transparent;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
    transition: all 0.2s;
}

.level-btn.active {
    border-color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.level-1 {
    background-color: #34d399;
}

.level-2 {
    background-color: #10b981;
}

.level-3 {
    background-color: #059669;
}

/* Switch Toggle - Mobile Sized */
.switch {
    width: 50px;
    height: 28px;
    display: inline-block;
    position: relative;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 30px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:checked+.slider.eraser {
    background-color: #ef4444;
}

input:checked+.slider:before {
    transform: translateX(22px);
}

/* Close/Hide Button */
.close-panel-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--divider-bg);
    border: none;
    color: var(--text-primary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Toast Notification - Mobile Optimized */
.toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    width: auto;
    max-width: 90vw;
}

.toast {
    background: #1f2937;
    color: white;
    padding: 12px 20px;
    border-radius: 30px;
    font-size: 0.9rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

/* Mobile Adjustments (Smartphones) */
@media (max-width: 600px) {
    .ui-overlay {
        top: auto;
        left: 0;
        bottom: 0;
        width: 100%;
        border-radius: 24px 24px 0 0;
        max-height: 70vh;
        padding-bottom: calc(1.5rem + var(--safe-area-bottom));
        transform: translateY(0);
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .ui-overlay.hidden {
        transform: translateY(100%);
        opacity: 1;
        /* Keep opacity for slide effect */
    }

    .toggle-ui-btn {
        top: auto;
        bottom: 20px;
        left: 20px;
    }

    /* Move leaflet attribution to not cover the button */
    .leaflet-bottom.leaflet-left {
        margin-bottom: 80px;
    }

    .leaflet-control-zoom {
        display: none;
        /* Hide zoom on small mobile to clear UI */
    }
}

/* Tablet Adjustments */
@media (min-width: 601px) and (max-width: 1024px) {
    .ui-overlay {
        width: 300px;
    }
}

/* Leaflet Bar Overrides */
.leaflet-bar a {
    background: var(--bg-overlay) !important;
    backdrop-filter: blur(8px) !important;
    color: var(--text-primary) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}