:root {
    --fl-bg: #1a1d23;
    --fl-bg-2: #23272f;
    --fl-text: #e8eaed;
    --fl-muted: #9aa0a6;
    --fl-accent: #ff6d00;
    --fl-low: #ffeb3b;
    --fl-med: #ff9800;
    --fl-high: #f44336;
    --fl-old: #ffcc80;          /* light orange — fires 12-24 h old */
    --fl-archive: #ffffff;      /* white — fires 24-72 h old (archive) */
    --fl-red-1: #d32f2f;        /* navbar gradient */
    --fl-red-2: #8e0000;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--fl-bg);
    color: var(--fl-text);
}

body {
    display: flex;
    flex-direction: column;
}

/* ---- Top bar ---- */
#topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;            /* let status drop below logo on narrow screens */
    gap: 4px 12px;
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--fl-red-1) 0%, var(--fl-red-2) 100%);
    border-bottom: 1px solid #5c0000;
    box-shadow: 0 2px 8px rgba(211, 47, 47, 0.35);
    z-index: 1000;
    min-height: 56px;
}

#logo { height: 34px; }
#logo-link { line-height: 0; }

#status {
    display: flex;
    align-items: center;
    gap: 24px;
    text-align: right;
    min-width: 0;          /* allow it to shrink instead of overflowing */
    margin-left: auto;     /* keep it pinned right even when topbar wraps */
}

#clock #fl-hour { font-weight: 700; font-size: 1.15rem; }
#clock #fl-date { font-size: 0.8rem; color: rgba(255, 255, 255, 0.75); }

#acq-info #fl-fire-count { font-weight: 700; color: #fff; font-size: 1rem; }
#acq-info #fl-acq-time { font-size: 0.8rem; color: rgba(255, 255, 255, 0.75); }
#acq-info #fl-acq-source { font-size: 0.75rem; color: rgba(255, 255, 255, 0.65); }
#acq-info #fl-wind-ref { font-size: 0.72rem; color: rgba(255, 255, 255, 0.8); font-weight: 600; }

/* ---- Map ---- */
#map {
    flex: 1;
    background: #e8e8e0;
    z-index: 1;
}

/* ---- MapLibre popups (fires, contour, wind) ---- */
.maplibregl-popup.fl-popup .maplibregl-popup-content {
    background: var(--fl-bg-2);
    color: var(--fl-text);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.85rem;
    line-height: 1.5;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.maplibregl-popup.fl-popup .maplibregl-popup-content b { color: var(--fl-accent); }
.maplibregl-popup.fl-popup .maplibregl-popup-close-button {
    color: var(--fl-muted);
    font-size: 1rem;
    padding: 0 6px;
}
.maplibregl-popup.fl-popup .maplibregl-popup-close-button:hover {
    color: var(--fl-text);
    background: transparent;
}
.maplibregl-popup.fl-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--fl-bg-2); }
.maplibregl-popup.fl-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--fl-bg-2); }
.maplibregl-popup.fl-popup.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--fl-bg-2); }
.maplibregl-popup.fl-popup.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--fl-bg-2); }
.maplibregl-popup.fl-popup.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip { border-top-color: var(--fl-bg-2); }
.maplibregl-popup.fl-popup.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--fl-bg-2); }
.maplibregl-popup.fl-popup.maplibregl-popup-anchor-top-left .maplibregl-popup-tip { border-bottom-color: var(--fl-bg-2); }
.maplibregl-popup.fl-popup.maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--fl-bg-2); }

.popup-table td { padding: 1px 8px 1px 0; }
.popup-table td:first-child { color: var(--fl-muted); }

/* Wind arrow hover tooltip (mini popup, no close button) */
.maplibregl-popup.fl-wind-tooltip .maplibregl-popup-content {
    background: var(--fl-bg-2);
    color: var(--fl-text);
    border: 1px solid #000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.75rem;
    line-height: 1.4;
    white-space: nowrap;
}
.maplibregl-popup.fl-wind-tooltip .maplibregl-popup-content b { color: var(--fl-accent); }
.maplibregl-popup.fl-wind-tooltip.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--fl-bg-2); }
.maplibregl-popup.fl-wind-tooltip.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--fl-bg-2); }
.maplibregl-popup.fl-wind-tooltip.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--fl-bg-2); }
.maplibregl-popup.fl-wind-tooltip.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--fl-bg-2); }

/* ---- Footer / timeline ---- */
#timeline-bar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 16px;
    background: var(--fl-bg-2);
    border-top: 1px solid #000;
    z-index: 1000;
    flex-wrap: wrap;
}

#legend {
    flex: 1;
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 0.78rem;
    color: var(--fl-muted);
    white-space: nowrap;
}

.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-note { font-style: italic; opacity: 0.7; }

.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot-low  { background: var(--fl-low); }
.dot-med  { background: var(--fl-med); }
.dot-high { background: var(--fl-high); }
.dot-old  { background: var(--fl-old); }
.dot-archive { background: var(--fl-archive); border: 1px solid #5f6368; box-sizing: border-box; }
.dot-contour { background: rgba(183,28,28,0.18); border: 1.5px solid #b71c1c; box-sizing: border-box; }
.legend-group { font-weight: 600; color: var(--fl-text); }
.legend-sep { opacity: 0.4; }

#view-toggle { display: flex; gap: 0; }

.toggle {
    background: transparent;
    border: 1px solid var(--fl-muted);
    color: var(--fl-muted);
    padding: 5px 14px;
    font-size: 0.78rem;
    cursor: pointer;
}
.toggle:first-child { border-radius: 6px 0 0 6px; }
.toggle:last-child  { border-radius: 0 6px 6px 0; border-left: none; }
.toggle.active {
    background: var(--fl-accent);
    border-color: var(--fl-accent);
    color: #fff;
    font-weight: 600;
}

/* Wind toggle (independent overlay, not part of the points/heat group) */
.wind-toggle {
    border-radius: 6px;
    margin-left: 6px;
}
.wind-toggle.active {
    background: #1565c0;
    border-color: #1565c0;
    color: #fff;
}

/* Archive toggle (24–72 h old fires, off by default) */
.archive-toggle {
    border-radius: 6px;
    margin-left: 10px;
}
.archive-toggle.active {
    background: #ffffff;
    border-color: #ffffff;
    color: #1a1d23;
    font-weight: 600;
}

/* Fire contour toggle (on by default) */
.contour-toggle {
    border-radius: 6px;
    margin-left: 6px;
}
.contour-toggle.active {
    background: #b71c1c;
    border-color: #b71c1c;
    color: #fff;
    font-weight: 600;
}

/* Wind model selector (ECMWF / AROME) */
#wind-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}
.model-toggle { display: flex; gap: 0; }
.model-btn {
    font-size: 0.72rem;
    padding: 5px 10px;
}
.model-btn.active {
    background: #37474f;
    border-color: #37474f;
    color: #fff;
}

/* Info button + modal */
.info-btn {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    font-style: italic;
    font-family: 'Segoe UI', Georgia, serif;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.info-btn:hover {
    background: var(--fl-accent);
    border-color: var(--fl-accent);
    color: #fff;
}
.info-btn:active { transform: scale(0.92); }

/* Header variant sits on the red navbar — ensure good contrast. */
#btn-info-header { margin-left: 4px; }

.info-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.info-modal[hidden] { display: none; }
.info-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(2px);
}
.info-modal-card {
    position: relative;
    background: var(--fl-bg-2);
    color: var(--fl-text);
    border: 1px solid #000;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    max-width: 560px;
    width: 100%;
    max-height: 86vh;
    overflow-y: auto;
    padding: 20px 24px 22px;
}
.info-close {
    position: absolute;
    top: 12px; right: 14px;
    background: transparent;
    border: none;
    color: var(--fl-muted);
    font-size: 1.1rem;
    cursor: pointer;
}
.info-close:hover { color: var(--fl-text); }
.info-modal-card h2 { margin: 0 0 8px; font-size: 1.25rem; }
.info-modal-card .info-intro { margin: 0 0 16px; color: var(--fl-muted); font-size: 0.88rem; }
.info-modal-card h3 { margin: 16px 0 6px; font-size: 1rem; color: var(--fl-accent); }
.info-modal-card ul { margin: 4px 0 8px; padding-left: 20px; }
.info-modal-card li { margin: 3px 0; font-size: 0.85rem; line-height: 1.45; }
.info-modal-card ul ul { margin: 2px 0; }
.info-note { color: var(--fl-muted); font-size: 0.8rem; font-style: italic; }
.info-modal-card a { color: #8ab4f8; }
.info-footer { margin: 16px 0 0; color: var(--fl-muted); font-size: 0.75rem; border-top: 1px solid #000; padding-top: 10px; }

/* Wind arrow overlay canvas — floats above the map canvas (z-index 1, below
   the z-index-2 MapLibre controls) and lets clicks fall through to the map;
   arrows are hit-tested in JS. */
.fl-wind-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
}

/* ---- Wind forecast timeline slider ---- */
.wind-timeline {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 8px 20px;
    background: var(--fl-bg-2);
    border-top: 1px solid #000;
    z-index: 1000;
}
.wind-timeline[hidden] { display: none; }

.wind-play-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: none;
    background: #1565c0;
    color: #fff;
    font-size: 0.85rem;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
}
.wind-play-btn:hover { background: #1976d2; }
.wind-play-btn:active { transform: scale(0.92); }
.wind-play-btn.playing { background: var(--fl-accent); }

#wind-slider-container {
    flex: 1;
    padding: 0 6px;
}

/* noUiSlider customisation for the dark theme */
#wind-slider {
    height: 8px;
}
#wind-slider .noUi-connects {
    background: #37474f;
    border-radius: 4px;
}
#wind-slider .noUi-connect {
    background: #1565c0;
}
#wind-slider .noUi-handle {
    width: 50px;
    height: 30px;
    border-radius: 6px;
    background: #1565c0;
    border: 1px solid #0d47a1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    cursor: ew-resize;
    top: -11px;
    right: -25px;
}
#wind-slider .noUi-handle::before,
#wind-slider .noUi-handle::after { display: none; }
#wind-slider .noUi-touch-area {
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    text-align: center;
    line-height: 30px;
    font-family: 'Segoe UI', sans-serif;
}
#wind-slider .noUi-tooltip { display: none; }
#wind-slider .noUi-pips {
    color: var(--fl-muted);
    font-size: 0.7rem;
    height: fit-content;
}
#wind-slider .noUi-marker { height: 4px; }
#wind-slider .noUi-marker-large { height: 7px; }
#wind-slider .noUi-value-horizontal {
    transform: translate(-50%, 12px);
}

.wind-time-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--fl-text);
    min-width: 90px;
    text-align: right;
    flex-shrink: 0;
}

/* Wind speed colour swatches (footer legend) */
.wind-scale { gap: 4px; align-items: flex-start; }
.ws-col { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ws-col > span:first-child {
    width: 14px; height: 4px; border-radius: 2px; display: inline-block;
}
.ws-num { font-size: 0.6rem; opacity: 0.6; line-height: 1; }
.ws-calm   { background: #9aa0a6; }
.ws-blue   { background: #8ab4f8; }
.ws-cyan   { background: #4fc3f7; }
.ws-yellow { background: #ffd54f; }
.ws-orange { background: #ffb300; }
.ws-red    { background: #ff7043; }
.wind-scale-label { margin-left: 4px; font-style: italic; opacity: 0.75; }

/* Fire marker pulse for very intense fires */
@keyframes fl-pulse {
    0%   { opacity: 0.9; }
    50%  { opacity: 0.5; }
    100% { opacity: 0.9; }
}

/* MapLibre user-geolocation control — recolour the "active/locked" states to
   the app's blue instead of MapLibre's default accent. */
.maplibregl-ctrl-group button.maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-active,
.maplibregl-ctrl-group button.maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-active:hover {
    background: #1565c0;
}
.maplibregl-ctrl-group button.maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-background,
.maplibregl-ctrl-group button.maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-background:hover {
    background: #90caf9;
}

/* Custom share (permalink) control — inline SVG icon centred in the 29×29
   MapLibre control button */
.maplibregl-ctrl-group button.fl-share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Keep the full (non-compact) attribution readable on the light basemap */
.maplibregl-ctrl-attrib a { color: rgba(0, 0, 0, 0.75); }

@media (max-width: 700px) {
    #legend { display: none; }
    #status { gap: 12px; }
    /* Compact navbar so the wide logo + right-side status fit on narrow
       Android viewports (logo SVG is 625x84 → very wide at full size). */
    #topbar { padding: 6px 10px; min-height: 48px; gap: 2px 10px; }
    #logo { height: 26px; }
    #clock #fl-hour { font-size: 0.95rem; }
    #clock #fl-date { font-size: 0.7rem; }
    #acq-info #fl-fire-count { font-size: 0.85rem; }
    #acq-info #fl-acq-time { font-size: 0.7rem; }
    #acq-info #fl-acq-source { font-size: 0.66rem; }
    #acq-info #fl-wind-ref { font-size: 0.66rem; }
}

@media (max-width: 420px) {
    /* Very narrow phones: drop secondary acquisition lines to keep the
       top-right block from breaking the navbar layout. */
    #acq-info #fl-acq-source,
    #acq-info #fl-wind-ref { display: none; }
    #status { gap: 10px; }
    #logo { height: 22px; }
    #clock #fl-hour { font-size: 0.88rem; }
    #acq-info #fl-fire-count { font-size: 0.8rem; }
}
