:root {
    --panel-bg: rgba(15, 23, 42, 0.88);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #38bdf8;
    --font-main: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: #0f172a;
    color: var(--text-primary);
    font-family: var(--font-main);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

#map { position: absolute; inset: 0; }
/* Grey basemap so the station colors stand out */
.leaflet-tile-pane { filter: grayscale(1) contrast(0.9) brightness(0.7); }

.panel {
    position: absolute;
    z-index: 1000;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

/* Title */
.map-title {
    top: 16px;
    left: 56px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
}
.map-title h1 { font-size: 1.05rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.map-logo { font-size: 1.3rem; }
.panel-link {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    margin-left: 0.5rem;
    white-space: nowrap;
}
.panel-link:hover { text-decoration: underline; }

/* Legend */
.legend {
    top: 16px;
    right: 16px;
    padding: 0.6rem 0.9rem;
    font-size: 0.8rem;
}
.legend summary { cursor: pointer; font-weight: 600; color: var(--text-secondary); }
.layer-toggles {
    display: grid;
    gap: 0.3rem;
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--panel-border);
    font-weight: 600;
}
.layer-toggles label { display: flex; align-items: center; gap: 0.45rem; cursor: pointer; }
.layer-toggles input { accent-color: var(--accent-color); margin: 0; }
.legend ul { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; gap: 0.3rem; }
.legend li { display: flex; align-items: center; gap: 0.5rem; }
.legend li:last-child { margin-top: 0.5rem; }
.swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid #94a3b8;
    flex-shrink: 0;
}

.legend .swatch { width: 16px; height: 16px; }

.swatch-x {
    width: 16px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: #94a3b8;
    flex-shrink: 0;
}

/* Timeline */
.timeline {
    left: 16px;
    right: 16px;
    bottom: 20px;
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.9rem;
}
.tl-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--panel-border);
    color: var(--text-primary);
    border-radius: 10px;
    height: 40px;
    min-width: 40px;
    padding: 0 0.7rem;
    font: 600 0.95rem var(--font-main);
    cursor: pointer;
    flex-shrink: 0;
}
.tl-btn:hover { background: rgba(255, 255, 255, 0.16); }
.tl-btn.active { background: var(--accent-color); color: #0f172a; border-color: var(--accent-color); }
.tl-speed { min-width: 48px; font-variant-numeric: tabular-nums; }
.tl-main { flex: 1; min-width: 0; }
/* Centered over the tape, so it sits right above the playhead */
.tl-label {
    position: relative;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
    font-variant-numeric: tabular-nums;
}
.tl-loading {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.78rem;
}
.tl-tape {
    position: relative;
    height: 68px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    overflow: hidden;
    touch-action: none;  /* we handle horizontal drags ourselves */
    cursor: grab;
    outline: none;
    user-select: none;
}
.tl-tape:active { cursor: grabbing; }
.tl-tape:focus-visible { box-shadow: 0 0 0 2px var(--accent-color); }
.tl-tape canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.tl-playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    margin-left: -1px;
    background: #fff;
    box-shadow: 0 0 6px rgba(56, 189, 248, 0.8);
    pointer-events: none;
}
.tl-playhead::before {
    content: "";
    position: absolute;
    top: 0;
    left: -5px;
    border: 6px solid transparent;
    border-top-color: #fff;
}

/* Station hover label (Leaflet tooltip) */
.leaflet-tooltip.station-hover {
    font-family: var(--font-main);
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
}

/* Station card (Leaflet popup; width set by the popup's min/maxWidth in map.js) */
.station-tip .leaflet-popup-content-wrapper,
.station-tip .leaflet-popup-tip {
    background: #f8fafc;
    color: #0f172a;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.station-tip .leaflet-popup-content-wrapper {
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 0;
}
.station-tip .leaflet-popup-content {
    margin: 0.55rem 0.7rem;
    font-family: var(--font-main);
    line-height: 1.3;
}
.tip-name { font-weight: 700; font-size: 0.9rem; margin-bottom: 0.2rem; padding-right: 1.2rem; /* clear the × */ }
.tip-now { display: flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; margin-bottom: 0.4rem; }
.tip-now .swatch { border-color: #475569; }
.tip-when { color: #64748b; margin-left: auto; }
.tip-chart { display: block; background: #e2e8f0; border-radius: 4px; }
.tip-empty {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e2e8f0;
    border-radius: 4px;
    color: #64748b;
    font-size: 0.8rem;
}
.tip-foot { display: flex; justify-content: space-between; color: #64748b; font-size: 0.72rem; margin-top: 0.3rem; }
.station-tip .tip-foot a { color: #0284c7; font-weight: 600; text-decoration: none; }
.station-tip .tip-foot a:hover { text-decoration: underline; }

.toast {
    position: absolute;
    z-index: 1100;
    left: 50%;
    bottom: 120px;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    background: #7f1d1d;
    color: #fff;
    padding: 0.6rem 1rem;
    border-radius: 10px;
    font-size: 0.85rem;
}

@media (max-width: 640px) {
    .tl-label { font-size: 1rem; }
    .tl-loading { display: none; }  /* no room beside the centered time */
    .map-title { left: 16px; right: 16px; top: 12px; padding: 0.5rem 0.8rem; }
    .map-title h1 { font-size: 0.95rem; }
    .panel-link { margin-left: auto; }
    .leaflet-top.leaflet-left { top: 64px; }
    .legend { top: auto; right: 16px; bottom: 120px; }
    .legend { padding: 0.4rem 0.7rem; }
    .timeline { bottom: 12px; gap: 0.4rem; padding: 0.6rem; }
}
