:root {
    --primary: #00BCD4;
    --accent: #FF5722;
    --fatal: #E53935;
    --injury: #FB8C00;
    --pedestrian: #8E24AA;
    --bicycle: #43A047;
    --impaired: #D81B60;
    --bg-dark: #0D1117;
    --bg-card: rgba(22, 27, 34, 0.95);
    --text: #E6EDF3;
    --text-muted: #7D8590;
    --border: rgba(48, 54, 61, 0.8);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
}

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

/* Stats Panel (centered on screen) */
.stats-panel {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 100;
}

.stat-item {
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--border);
    backdrop-filter: blur(15px);
    padding: 6px 10px;
    border-radius: 8px;
    text-align: center;
    transition: transform 0.3s ease;
}

.stat-item.top {
    top: 0; left: 50%;
    transform: translateX(-50%) translateY(-100%);
    margin-top: -20px;
}

.stat-item.bottom {
    bottom: 0; left: 50%;
    transform: translateX(-50%) translateY(100%);
    margin-bottom: -20px;
}

.stat-item.left {
    top: 50%; left: 0;
    transform: translateY(-50%) translateX(-100%);
    margin-left: -20px;
}

.stat-item.right {
    top: 50%; right: 0;
    transform: translateY(-50%) translateX(100%);
    margin-right: -20px;
}

.stat-item .value {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-item.top .value {
    font-size: 22px;
    background: linear-gradient(135deg, var(--primary), #4DD0E1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-item .label {
    font-size: 8px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-item.top { color: var(--primary); }
.stat-item.fatal .value { color: var(--fatal); }
.stat-item.injury .value { color: var(--injury); }
.stat-item.ped .value { color: var(--pedestrian); }

/* Top Bar */
.top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
    backdrop-filter: blur(20px);
}

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

.logo-icon {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.logo-text {
    font-size: 16px;
    font-weight: 600;
}

.logo-text span { color: var(--primary); }

/* Year Selector */
.year-selector {
    display: flex;
    gap: 4px;
}

.year-btn {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.year-btn:hover {
    border-color: var(--primary);
    color: var(--text);
}

.year-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--bg-dark);
}

.year-btn:not(.active) {
    opacity: 0.5;
}

/* Data Note */
.data-note {
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 11px;
    color: #FFC107;
    margin-bottom: 12px;
}

/* Story Tabs */
.story-tabs {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.3);
    padding: 3px;
    border-radius: 8px;
}

.story-tab {
    padding: 6px 14px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.story-tab:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.story-tab.active {
    background: var(--primary);
    color: var(--bg-dark);
}

/* Side Panel */
.side-panel {
    position: fixed;
    top: 76px; right: 20px;
    width: 300px;
    max-height: calc(100vh - 96px);
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    z-index: 500;
    overflow: hidden;
    backdrop-filter: blur(20px);
}

.panel-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
}

.panel-content {
    padding: 16px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
}

/* Story Styles */
.story-insight {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    margin-bottom: 16px;
}

.insight-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.insight-title {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.insight-value {
    font-size: 20px;
    font-weight: 700;
    margin-top: 2px;
}

.chart-box {
    height: 160px;
    margin-bottom: 16px;
}

.chart-box > div {
    width: 100%;
    height: 100%;
}

.story-detail {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.detail-title {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.detail-row:last-child { border-bottom: none; }

.detail-value {
    font-weight: 600;
}

.detail-value small {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 10px;
}

.mini-bar {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin: 0 10px;
    overflow: hidden;
}

.mini-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s;
}

/* Safety Grid */
.safety-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.safety-card {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    padding: 10px 6px;
    text-align: center;
}

.safety-value {
    font-size: 18px;
    font-weight: 700;
}

.safety-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 2px;
}

/* Day Grid */
.day-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.day-cell {
    background: rgba(0, 188, 212, calc(var(--intensity) * 0.3));
    border-radius: 6px;
    padding: 8px 4px;
    text-align: center;
    border: 1px solid rgba(0, 188, 212, calc(var(--intensity) * 0.5));
}

.day-cell.peak {
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(0, 188, 212, 0.3);
}

.day-name {
    font-size: 9px;
    color: var(--text-muted);
}

.day-value {
    font-size: 12px;
    font-weight: 600;
    margin-top: 2px;
}

/* Controls */
.controls-panel {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    z-index: 500;
    backdrop-filter: blur(20px);
}

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

.control-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.radius-slider {
    width: 100px;
    height: 4px;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.radius-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

.radius-value {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    min-width: 45px;
}

.toggle-btn {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.toggle-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--bg-dark);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 12px;
    opacity: 0;
    transition: all 0.3s;
    z-index: 2000;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Loading */
.loading {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s;
}

.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
    margin-top: 16px;
    color: var(--text-muted);
    font-size: 13px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Info tip */
.info-tip {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--text-muted);
    z-index: 400;
}

@media (max-width: 900px) {
    .side-panel { width: 260px; right: 10px; }
    .year-selector { display: none; }
}
