:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #18202b;
  --ink-soft: #5b6573;
  --line: #e3e8ee;
  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 16px rgba(16, 24, 40, .06);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

#app { display: flex; height: 100vh; }

/* ---------- sidebar ---------- */
/* Single column: controls (compass + view) stay pinned at the top while the
 * ranking scrolls in its own region below (#tableScroll) — so spinning the
 * compass visibly re-sorts the table without it scrolling out of view. */
#sidebar {
  width: 420px; min-width: 420px;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 20px 24px;
  display: flex; flex-direction: column; gap: 12px;
}
#sidebar header h1 { font-size: 1.25rem; margin: 0 0 6px; letter-spacing: -.01em; }
#sidebar header .logo { filter: saturate(1.2); }
.tagline { margin: 0 0 10px; color: var(--ink-soft); font-size: .86rem; line-height: 1.45; }
.header-actions { display: flex; gap: 8px; }

h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em;
     color: var(--ink-soft); margin: 0 0 8px; font-weight: 600; }
h2 .hint { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: .74rem; opacity: .75; }
section { margin: 0; }
.caption { font-size: .76rem; color: var(--ink-soft); margin: 6px 0 0; line-height: 1.4; }

button { font: inherit; cursor: pointer; }
.ghost {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 10px; font-size: .8rem; color: var(--ink-soft);
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.ghost.small { padding: 2px 8px; font-size: .74rem; }
.ghost.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.presets { display: flex; gap: 8px; }
.chip {
  flex: 1; border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 8px 10px; font-size: .82rem; font-weight: 500;
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip.small { flex: none; padding: 3px 11px; font-size: .76rem; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- compass rose ---------- */
#rose { display: flex; justify-content: center; }
/* Tightened from 280px so the merged ranking gets room below the compass. */
#rose svg { max-width: 196px; width: 100%; }
#rose .sector-hit { cursor: pointer; }
#rose .sector-hit:hover .petal { opacity: .95; }
.rose-legend { display: flex; gap: 16px; justify-content: center; font-size: .74rem;
               color: var(--ink-soft); margin-top: 4px; }
.rose-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px;
                   margin-right: 5px; vertical-align: -1px; }
.rose-legend .summer { background: #f59e0b; }
.rose-legend .winter { background: #3b82f6; }
#roseCaption { text-align: center; min-height: 2.1em; }

/* ---------- segmented control ---------- */
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1; padding: 8px 6px; border: none; background: var(--panel);
  font-size: .84rem; font-weight: 500; display: flex; flex-direction: column;
  align-items: center; gap: 1px; color: var(--ink);
}
.seg button small { font-size: .72rem; color: var(--ink-soft); font-weight: 400; }
.seg button.on { background: var(--accent); color: #fff; }
.seg button.on small { color: rgba(255,255,255,.85); }

/* ---------- settings popover (units + opacity) ---------- */
#settingsPanel { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px;
                 padding: 10px 12px; display: flex; flex-direction: column; gap: 12px;
                 background: var(--panel); box-shadow: var(--shadow); }
#settingsPanel[hidden] { display: none; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-lbl { font-size: .8rem; color: var(--ink-soft); }
.seg.small { width: auto; flex: none; }
.seg.small button { flex: 0 0 auto; padding: 4px 12px; font-size: .78rem; }
.slider-label { font-size: .78rem; color: var(--ink-soft); flex: 1;
                display: flex; align-items: center; gap: 10px; }
.slider-label input { flex: 1; accent-color: var(--accent); }

/* ---------- on-map wind legend (fixed key) ---------- */
#mapLegend {
  position: absolute; left: 12px; bottom: 30px; z-index: 5;
  background: rgba(255,255,255,.92); backdrop-filter: blur(6px);
  border-radius: 10px; padding: 8px 11px; box-shadow: var(--shadow);
  pointer-events: none; width: 216px; max-width: 58%;
}
#mapLegend .legend-title { font-size: .72rem; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
#mapLegend canvas { width: 100%; height: 10px; border-radius: 3px; display: block; }
#mapLegend #legendLabels { display: flex; justify-content: space-between;
                           font-size: .66rem; color: var(--ink-soft); margin-top: 3px; }
#mapLegend .legend-note { font-size: .64rem; color: var(--ink-soft); margin-top: 6px;
                          display: flex; align-items: center; gap: 5px; line-height: 1.3; }
#mapLegend .legend-note i { width: 8px; height: 8px; border-radius: 50%; background: #15803d;
                            flex: none; display: inline-block; }

/* ---------- table ---------- */
/* The ranking fills the leftover panel height; its search + filters stay put
 * while only the rows scroll, and the column headers stick. */
#tableSection { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
#tableScroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
#suburbSearch {
  width: 100%; box-sizing: border-box; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  font: inherit; font-size: .82rem; color: var(--ink);
}
#suburbSearch:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
/* One scrollable row (instead of wrapping to ~3) so the ranking gets more
 * visible rows under the pinned compass. flex:none stops the flex column from
 * shrinking it to nothing (overflow-x:auto sets its min-height to 0). */
.filters { display: flex; gap: 6px; margin-bottom: 8px; flex: none; flex-wrap: nowrap;
           overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; }
#rankTable { width: 100%; border-collapse: collapse; font-size: .8rem; }
#rankTable thead th { position: sticky; top: 0; z-index: 1; background: var(--panel); }
#rankTable th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft); padding: 4px 6px; border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none; white-space: nowrap;
}
#rankTable th.num, #rankTable td.num { text-align: right; }
#rankTable th.sorted::after { content: " ▼"; font-size: .6rem; }
#rankTable th.sorted.asc::after { content: " ▲"; }
#rankTable td { padding: 5px 6px; border-bottom: 1px solid #f0f2f5; }
#rankTable tbody tr { cursor: pointer; }
#rankTable tbody tr:hover { background: var(--accent-soft); }
.score-pill {
  display: inline-block; min-width: 26px; text-align: center;
  border-radius: 999px; color: #fff; font-weight: 700; font-size: .74rem;
  padding: 1px 6px; font-variant-numeric: tabular-nums;
}
#scoreInfoBtn {
  border: none; background: none; color: var(--accent); cursor: pointer;
  font-size: .8rem; padding: 0 0 0 3px; vertical-align: 1px;
}
#scorePopover {
  border: 1px solid var(--accent); background: var(--accent-soft);
  border-radius: 10px; padding: 10px 12px; margin: 8px 0;
  font-size: .78rem; line-height: 1.5; color: var(--ink);
}
#scorePopover p { margin: 6px 0 0; }
.sub-name { display: flex; align-items: center; gap: 6px; }
.sub-name .b { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sub-name .g { color: var(--ink-soft); font-size: .68rem; }
.sub-name .tags { font-size: .72rem; letter-spacing: -1px; }

footer { font-size: .68rem; color: var(--ink-soft); line-height: 1.5;
         border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- map ---------- */
#mapwrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

#particle-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 2;
}
.mapboxgl-popup { z-index: 5; }
.mapboxgl-ctrl-top-right, .mapboxgl-ctrl-bottom-right,
.mapboxgl-ctrl-bottom-left { z-index: 4; }

.mapboxgl-ctrl-group button.view-ctrl-btn {
  font-size: 11.5px; font-weight: 700; color: #333;
}
.mapboxgl-ctrl-group button.view-ctrl-btn.on {
  background: var(--accent); color: #fff;
}

#scenarioChip {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  background: rgba(255,255,255,.92); backdrop-filter: blur(6px);
  border-radius: 999px; padding: 7px 14px; font-size: .8rem; font-weight: 500;
  box-shadow: var(--shadow); pointer-events: none; max-width: 70%;
}
#scenarioChip .warn { color: #b45309; font-weight: 400; }
#scenarioChip .muted { color: var(--ink-soft); font-weight: 400; }

#probe {
  position: absolute; bottom: 132px; left: 12px; z-index: 5;
  background: rgba(24,32,43,.88); color: #fff; backdrop-filter: blur(4px);
  border-radius: 9px; padding: 7px 11px; font-size: .74rem; line-height: 1.5;
  pointer-events: none; font-variant-numeric: tabular-nums;
}

#loading {
  position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: rgba(244,246,249,.9); font-size: .9rem; color: var(--ink-soft);
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- popup ---------- */
.mapboxgl-popup-content { font-family: inherit; border-radius: 10px; padding: 12px 14px;
                          box-shadow: var(--shadow); min-width: 200px; }
.popup-title { font-weight: 600; font-size: .92rem; margin-bottom: 2px; }
.popup-sub { color: var(--ink-soft); font-size: .72rem; margin-bottom: 8px; }
.popup-badge { display: inline-block; border-radius: 999px; color: #fff; font-size: .7rem;
               font-weight: 600; padding: 2px 9px; margin-bottom: 8px; }
.popup-grid { display: grid; grid-template-columns: auto auto; gap: 2px 14px;
              font-size: .78rem; font-variant-numeric: tabular-nums; }
.popup-grid .k { color: var(--ink-soft); }
.popup-tags { margin-top: 8px; font-size: .74rem; color: var(--ink-soft); }

/* ---------- modal ---------- */
#aboutModal { position: fixed; inset: 0; z-index: 50; background: rgba(15,20,30,.45);
              display: flex; align-items: center; justify-content: center; padding: 20px; }
#aboutModal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 16px; max-width: 680px; max-height: 86vh;
              overflow-y: auto; padding: 28px 32px; position: relative; box-shadow: var(--shadow); }
.modal-card h2 { font-size: 1.15rem; color: var(--ink); text-transform: none; letter-spacing: 0; }
.modal-card h3 { font-size: .95rem; margin: 18px 0 6px; }
.modal-card p, .modal-card li { font-size: .85rem; line-height: 1.55; color: #2a3442; }
.modal-close { position: absolute; top: 14px; right: 14px; border: none; background: none;
               font-size: 1rem; color: var(--ink-soft); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #app { flex-direction: column-reverse; height: auto; }
  #sidebar { width: 100%; min-width: 0; border-right: none; border-top: 1px solid var(--line);
             overflow: visible; }
  #mapwrap { flex: none; height: 62vh; }
  #scenarioChip { font-size: .72rem; max-width: 86%; }
  /* Bound the ranking so the page doesn't become a 6-screen scroll of 82 rows;
     nothing sits below the table, so there's no scroll-trap. Headers stay sticky. */
  #tableSection { flex: none; }
  #tableScroll { max-height: 62vh; overflow-y: auto; min-height: 0; }
  #rose svg { max-width: 240px; }
}
