:root {
    --bg-base: #fcfbf7;
    --bg-panel: rgba(255, 253, 248, 0.94);
    --bg-panel-solid: #fffdf9;
    --border-light: rgba(215, 195, 170, 0.5);
    --text-main: #1c2d27;
    --text-muted: #65756e;
    --accent: #e05a36;
    --accent-light: #f59e0b;
    --card-bg: #f4eee2;
    --shadow-soft: 0 8px 30px rgba(160, 120, 80, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%; margin: 0; padding: 0;
    overflow: hidden; touch-action: none;
    font-family: 'Outfit', -apple-system, sans-serif;
    background: var(--bg-base); color: var(--text-main);
}

#map { position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; z-index: 1; }

/* Shared Components */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-soft);
}

/* Smooth Shadow Rendering & Sub-Pixel Anti-Aliasing */
.leaflet-pane.leaflet-shadowPane-pane {
    filter: blur(0.5px) !important;
}
.leaflet-pane.leaflet-shadowPane-pane img,
.leaflet-pane.leaflet-shadowPane-pane canvas {
    image-rendering: auto !important;
    image-rendering: smooth !important;
}

/* Top Action Bar (Mobile Only) */
.top-action-bar {
    position: absolute; top: max(env(safe-area-inset-top, 12px), 12px); right: 12px;
    z-index: 1000; display: none;
}
.action-fab {
    background: var(--bg-panel); backdrop-filter: blur(12px); border: 1px solid var(--border-light);
    color: var(--accent); font-family: inherit; font-size: 13px; font-weight: 700;
    padding: 8px 14px; border-radius: 20px; box-shadow: 0 4px 15px rgba(160,120,80,0.2);
    cursor: pointer; display: flex; align-items: center; gap: 6px;
}

/* Time Controls */
.time-controls-container {
    position: absolute; z-index: 1000;
    display: flex; flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.time-banner-compact {
    display: flex; align-items: center; justify-content: space-between;
    background: #f4eee2; border: 1px solid #e6dac8;
    padding: 6px 10px; border-radius: 12px; margin-bottom: 8px;
}
.brand-pill { display: flex; align-items: center; gap: 5px; }
.brand-pill .title { font-size: 13px; font-weight: 700; color: #1c2d27; }
.time-right-group { display: flex; align-items: center; gap: 8px; }
.time-main { font-size: 26px; font-weight: 800; color: var(--text-main); font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; }
.offset-badge { font-size: 12px; font-weight: 600; color: #65756e; background: #e2d7c3; padding: 2px 6px; border-radius: 8px; }
.jump-now-btn { background: var(--accent); color: white; border: none; padding: 5px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; cursor: pointer; display: none; box-shadow: 0 2px 4px rgba(201, 73, 39, 0.3); transition: transform 0.1s; }
.jump-now-btn:active { transform: scale(0.95); }
.time-right-group.not-now .jump-now-btn { display: block; }
.time-right-group.not-now .offset-badge { display: block; }
.time-right-group:not(.not-now) .offset-badge { display: none; }

.date-pills-row { display: flex; gap: 6px; margin-bottom: 8px; }
.date-chip { flex: 1 1 0; text-align: center; background: #f4eee2; border: 1px solid #e2d7c3; color: #65756e; font-size: 11px; font-weight: 600; padding: 5px 6px; border-radius: 16px; cursor: pointer; white-space: nowrap; }
.date-chip.active { background: var(--accent); color: #ffffff; border-color: #c94927; font-weight: 700; }

.slider-wrapper { margin-bottom: 8px; }
input[type=range] { width: 100%; -webkit-appearance: none; background: #e6dac8; height: 8px; border-radius: 4px; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); border: 2px solid #ffffff; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.15); }

.preset-row { display: flex; gap: 6px; margin-bottom: 8px; }
.preset-chip { flex: 1 1 0; text-align: center; background: #f4eee2; border: 1px solid #e2d7c3; color: #65756e; font-size: 11px; font-weight: 600; padding: 5px 8px; border-radius: 16px; cursor: pointer; }
.preset-chip:active { background: var(--accent); color: #ffffff; }

.controls-grid { display: grid; grid-template-columns: 42px 42px 1fr 42px 42px; gap: 6px; margin-bottom: 4px; }
.btn { background: #ede6d8; border: 1px solid #d6c8b4; color: var(--text-main); font-family: inherit; font-size: 14px; font-weight: 600; border-radius: 10px; min-height: 42px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.btn-primary { background: var(--accent); border-color: #c94927; color: #ffffff; font-weight: 700; }

/* Leaderboard */
.leaderboard-container {
    position: absolute; z-index: 2000; display: flex; flex-direction: column;
    background: var(--bg-panel-solid); transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.lm-header { padding: 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e2d7c3; background: #f5eedf; }
.lm-title { font-size: 15pt; font-weight: 800; color: #1c2d27; display: flex; align-items: center; gap: 8px; }
.lm-close { display: none; background: rgba(0,0,0,0.06); border: none; color: #1c2d27; border-radius: 50%; width: 34px; height: 34px; font-size: 16px; cursor: pointer; }

.lb-tabs { display: flex; gap: 6px; padding: 8px 16px; background: #f5eedf; border-bottom: 1px solid #e2d7c3; }
.lb-tab { flex: 1; border: 1px solid #e2d7c3; background: #f4eee2; padding: 8px 4px; border-radius: 12px; font-size: 11px; font-weight: 600; color: var(--text-muted); cursor: pointer; text-align: center; }
.lb-tab.active { background: var(--accent); color: #ffffff; border-color: #c94927; font-weight: 700; }

.leaderboard-list { flex-grow: 1; overflow-y: auto; padding: 16px; }
.lb-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; margin-bottom: 8px; background: #f4eee2; border-radius: 12px; cursor: pointer; border: 1px solid #e6dac8; }
.lb-rank { font-weight: 800; font-size: 14pt; color: #8c7d6b; width: 28px; }
.lb-details { flex-grow: 1; margin-left: 8px; }
.lb-name { font-weight: 700; font-size: 11pt; color: var(--text-main); }
.lb-sun { font-size: 9.5pt; color: var(--accent); font-weight: 600; margin-top: 2px; }
.lb-badge { padding: 3px 8px; border-radius: 10px; font-size: 9pt; font-weight: 700; }

/* Venue Details */
.venue-details-container {
    position: absolute; z-index: 2000; background: var(--bg-panel);
    backdrop-filter: blur(16px); border: 1px solid var(--border-light);
    display: flex; flex-direction: column; gap: 12px; padding: 20px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: var(--shadow-soft);
}
.vd-drag-handle { display: none; width: 36px; height: 4px; background: rgba(0,0,0,0.2); border-radius: 2px; margin: -10px auto 8px auto; }
.vs-header { display: flex; justify-content: space-between; align-items: flex-start; }
.vs-title { font-size: 16pt; font-weight: 800; color: #1c2d27; line-height: 1.1; margin-bottom: 4px; }
.vs-subtitle { font-size: 10pt; color: var(--text-muted); }
.vs-close { background: rgba(0,0,0,0.06); border: none; color: #1c2d27; border-radius: 50%; width: 32px; height: 32px; font-size: 16px; cursor: pointer; }

.timeline-container { margin-top: 8px; }
.timeline-title { font-size: 9pt; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; }
.timeline-bar { display: flex; height: 22px; width: 100%; background: #e8ded0; border-radius: 10px; overflow: hidden; border: 1px solid #d8caa8; position: relative; }
.timeline-segment { height: 100%; }
.timeline-labels { display: flex; justify-content: space-between; font-size: 8.5pt; color: #786b5e; margin-top: 4px; }
.timeline-cursor { position: absolute; top: -2px; bottom: -2px; width: 3px; background: #1c2d27; border-radius: 2px; box-shadow: 0 0 6px #1c2d27; z-index: 2; transition: left 0.1s; }

/* Settings Overlay */
.settings-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(28, 45, 39, 0.35); backdrop-filter: blur(6px);
    z-index: 2500; opacity: 0; pointer-events: none; transition: opacity 0.25s ease;
}
.settings-overlay.open { opacity: 1; pointer-events: auto; }
.settings-card {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: var(--bg-panel-solid); border-top: 1px solid var(--border-light);
    border-radius: 20px 20px 0 0; padding: 20px; box-shadow: var(--shadow-soft);
}
.settings-title { font-size: 16px; font-weight: 700; color: #1c2d27; margin-bottom: 16px; display: flex; justify-content: space-between; }
.setting-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.setting-label { font-size: 13px; font-weight: 600; color: #3c4c45; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-switch { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #d6c8b4; transition: .2s; border-radius: 24px; }
.slider-switch:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .2s; border-radius: 50%; }
input:checked + .slider-switch { background-color: var(--accent); }
input:checked + .slider-switch:before { transform: translateX(20px); }

/* --- RESPONSIVE LAYOUTS --- */

/* DESKTOP (min-width: 769px) */
@media (min-width: 769px) {
    .time-controls-container {
        top: 20px; right: 20px; width: 320px;
        background: var(--bg-panel); backdrop-filter: blur(20px);
        border: 1px solid var(--border-light); border-radius: 16px;
        padding: 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    }
    .time-controls-container .sheet-drag-handle { display: none; }

    .leaderboard-container {
        top: 20px; left: 20px; bottom: 40px; width: 340px;
        border-radius: 16px; border: 1px solid var(--border-light);
        box-shadow: 5px 5px 25px rgba(0,0,0,0.3);
    }
    .lm-header { padding-top: 16px; } /* Reset safe area */

    .venue-details-container {
        top: 20px; right: -420px; width: 380px; bottom: auto;
        border-radius: 16px; box-shadow: -5px 5px 25px rgba(0,0,0,0.3);
    }
    .venue-details-container.open { right: 360px; } /* Slide in next to time controls */

    .settings-card {
        top: 50%; left: 50%; bottom: auto; right: auto;
        transform: translate(-50%, -50%);
        width: 400px; border-radius: 16px; border: 1px solid var(--border-light);
    }
}

/* MOBILE (max-width: 768px) */
@media (max-width: 768px) {
    .top-action-bar { display: flex; }

    .time-controls-container {
        bottom: 0; left: 0; right: 0;
        background: var(--bg-panel); border-top: 1px solid var(--border-light);
        border-radius: 20px 20px 0 0; padding: 8px 14px calc(env(safe-area-inset-bottom, 8px) + 8px) 14px;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    }
    .sheet-drag-handle {
        width: 36px; height: 4px; background: rgba(255, 255, 255, 0.3);
        border-radius: 2px; margin: 0 auto 8px auto;
    }

    .leaderboard-container {
        top: 100%; left: 0; right: 0; bottom: 0; width: 100%;
    }
    .leaderboard-container.open { top: 0; }
    .lm-header { padding-top: max(env(safe-area-inset-top, 16px), 16px); }
    .lm-close { display: block; }
    .leaderboard-list { padding-bottom: 40px; }

    .venue-details-container {
        bottom: -100%; left: 0; right: 0; top: auto;
        border-radius: 20px 20px 0 0; border-top: 1px solid var(--border-light);
    }
    .venue-details-container.open { bottom: 0; }
    .vd-drag-handle { display: block; }

    @keyframes active-venue-pulse {
        0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(224, 90, 54, 0.6); }
        50% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(224, 90, 54, 0); }
        100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(224, 90, 54, 0.6); }
    }
    .place-icon.active-place-marker > div {
        animation: active-venue-pulse 2.4s infinite ease-in-out !important;
        border-color: #ffffff !important;
        z-index: 1000 !important;
    }

    .settings-card {
        padding: 22px 20px calc(env(safe-area-inset-bottom, 16px) + 16px) 20px !important;
        border-radius: 24px 24px 0 0 !important;
    }
    .settings-title {
        font-size: 18px !important;
        margin-bottom: 20px !important;
    }
    .setting-label {
        font-size: 15px !important;
    }
    .setting-row {
        margin-bottom: 18px !important;
        min-height: 44px !important;
    }
    .preset-chip, .date-pill {
        padding: 10px 14px !important;
        font-size: 14px !important;
        border-radius: 12px !important;
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    #mapProviderSelect {
        padding: 10px 12px !important;
        font-size: 15px !important;
        border-radius: 10px !important;
        min-height: 44px !important;
    }
}
.night-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(4, 11, 30, 0.65);
    pointer-events: none; z-index: 400;
    opacity: 0; transition: opacity 0.8s ease;
}
.night-overlay.active { opacity: 1; }

/* User Location Marker */
.user-location-marker {
    position: relative;
    width: 20px;
    height: 20px;
}
.user-location-dot {
    width: 14px;
    height: 14px;
    background-color: #2563eb;
    border: 2.5px solid #ffffff;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.6);
    z-index: 2;
}
.user-location-pulse {
    width: 32px;
    height: 32px;
    background-color: rgba(37, 99, 235, 0.35);
    border-radius: 50%;
    position: absolute;
    top: -6px;
    left: -6px;
    animation: user-pulse 2s infinite ease-out;
    z-index: 1;
    pointer-events: none;
}
@keyframes user-pulse {
    0% { transform: scale(0.5); opacity: 0.8; }
    70% { transform: scale(1.5); opacity: 0.0; }
    100% { transform: scale(1.5); opacity: 0.0; }
}
