:root {
  --bg: #f5f2ec;
  --panel: #ffffff;
  --ink: #1c1e21;
  --ink-soft: #565a63;
  --ink-mute: #8a8f99;
  --line: #e3ddd0;
  --line-soft: #efe9dc;
  --accent: #c65545;
  --accent-2: #3ea6a1;
  --hi: #fff6d9;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.05);
  --radius: 10px;
  --radius-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --panel: #1a1d24;
    --ink: #ecedf0;
    --ink-soft: #a8adb8;
    --ink-mute: #6a6f7a;
    --line: #262a33;
    --line-soft: #1f232b;
    --hi: #3a2b0d;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; }
.brand h1 {
  margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
}
.brand .sub {
  margin: 2px 0 0 0; font-size: 12px; color: var(--ink-soft);
}
.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ctrl {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em;
}
.ctrl select {
  font: inherit; font-size: 13px; text-transform: none;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 5px 8px; min-width: 150px;
}
.ctrl input[type="range"] { width: 160px; }
.ctrl output { font-family: 'JetBrains Mono', monospace; color: var(--ink); text-transform: none; }
.ctrl.toggle {
  flex-direction: row; align-items: center; gap: 6px;
  text-transform: none; letter-spacing: normal; font-size: 13px; color: var(--ink);
}

/* Layout */
.layout {
  display: grid; grid-template-columns: 1fr 360px;
  min-height: 0; flex: 1;
  height: calc(100vh - 68px);
}
body.has-profile .layout { height: calc(100vh - 68px - 300px - var(--rwy-h, 0px)); }
body:not(.has-profile) .layout { height: calc(100vh - 68px - var(--rwy-h, 0px)); }
@media (max-width: 900px) {
  body.has-profile .layout,
  body:not(.has-profile) .layout { height: auto; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { max-height: 45vh; }
}

/* Map */
.mapwrap { position: relative; min-height: 400px; }
#map { position: absolute; inset: 0; background: var(--line-soft); }
.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; font-size: 12px;
  box-shadow: var(--shadow); min-width: 158px;
}
.legend-title { margin: 0 0 6px 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.legend div { display: flex; align-items: center; gap: 8px; padding: 2px 0; color: var(--ink); }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend-sep { border-top: 1px solid var(--line); margin: 6px 0 4px 0; padding: 0 !important; height: 0; }

/* Side */
.side {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 14px 16px 6px 16px; border-bottom: 1px solid var(--line); }
.side-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.side-head p { margin: 4px 0 8px 0; font-size: 12px; color: var(--ink-soft); }
.tblwrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; }
thead { position: sticky; top: 0; background: var(--panel); z-index: 2; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-soft); font-weight: 500; cursor: pointer; user-select: none;
}
th.num, td.num { text-align: right; font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
th:hover { color: var(--ink); }
tr.row { cursor: pointer; }
tr.row:hover td { background: var(--line-soft); }
tr.row.active td { background: var(--hi); }
tr.row.dim td { opacity: 0.32; }
tr.grp td {
  background: linear-gradient(90deg, rgba(62,166,161,0.10), transparent 60%);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line-soft);
}
tr.row.in-10nm td:first-child { border-left: 2px solid #3ea6a1; }

/* Place markers (populated areas within 10 NM) */
.place-label {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #312e81;
  font-size: 10px;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  white-space: nowrap;
}
.place-label::before { display: none; } /* remove leaflet tooltip arrow */
.place-label .pl-pop {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  background: rgba(99, 102, 241, 0.14);
  color: #4338ca;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  vertical-align: baseline;
}
.place-label-city .pl-pop, .place-label-town .pl-pop {
  font-size: 10.5px;
  background: rgba(67, 56, 202, 0.16);
}
@media (prefers-color-scheme: dark) {
  .place-label .pl-pop { background: rgba(129,140,248,0.20); color: #c7d2fe; }
}
.place-label-city { font-size: 12.5px; font-weight: 700; color: #1e1b4b; background: rgba(255,255,255,0.95); border-color: #4338ca; padding: 2px 7px; }
.place-label-town { font-size: 11.5px; font-weight: 600; color: #1e1b4b; background: rgba(255,255,255,0.92); border-color: #4f46e5; }
@media (prefers-color-scheme: dark) {
  .place-label { background: rgba(18,20,26,0.85); color: #c7d2fe; border-color: rgba(129,140,248,0.35); }
  .place-label-city, .place-label-town { color: #e0e7ff; background: rgba(18,20,26,0.92); }
}
.pop-title.place { color: #4338ca; }
.pop-title.place .eng { color: var(--ink-mute); font-weight: 400; font-size: 11px; }
.ring-badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #0f6a67;
  background: rgba(62,166,161,0.14);
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: 1px;
}
tr.dim td { opacity: 0.35; }
.pill {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 8px; vertical-align: middle;
}
.sub-range { font-size: 11px; color: var(--ink-mute); display: block; margin-top: 1px; }

.foot { padding: 10px 16px 14px 16px; border-top: 1px solid var(--line); font-size: 11px; color: var(--ink-soft); }
.foot p { margin: 4px 0; }
.foot a { color: var(--accent-2); text-decoration: none; }
.foot a:hover { text-decoration: underline; }
.src { line-height: 1.5; }

/* Elevation profile */
.profile {
  background: var(--panel);
  border-top: 1px solid var(--line);
  height: 300px;
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.profile[hidden] { display: none; }
.profile-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 10px 18px 4px 18px; gap: 16px;
  border-bottom: 1px solid var(--line-soft);
}
.profile-title-wrap h2 { margin: 0; font-size: 14px; font-weight: 600; }
.profile-title-wrap p { margin: 3px 0 0 0; font-size: 12px; color: var(--ink-soft); }
.profile-actions { display: flex; align-items: center; gap: 12px; }
.pstat {
  font-family: 'JetBrains Mono', monospace; font-size: 11.5px;
  color: var(--ink-soft); white-space: pre; text-align: right; line-height: 1.4;
}
.pstat b { color: var(--ink); }
#profileClose {
  background: transparent; border: 1px solid var(--line);
  color: var(--ink-soft); width: 26px; height: 26px; border-radius: 50%;
  cursor: pointer; font-size: 16px; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
#profileClose:hover { color: var(--ink); border-color: var(--ink-mute); }
.profile-chart {
  position: relative; flex: 1; padding: 4px 12px 10px 12px; min-height: 0;
}
.profile-chart canvas { width: 100% !important; height: 100% !important; }

/* Runway wind component panel */
:root { --rwy-h: 180px; }
.rwy {
  background: var(--panel);
  border-top: 1px solid var(--line);
  min-height: 180px;
  flex-shrink: 0;
}
body.rwy-collapsed { --rwy-h: 42px; }
body.rwy-collapsed .rwy-body { display: none; }
.rwy-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 8px 18px; gap: 12px; border-bottom: 1px solid var(--line-soft);
}
.rwy-head h2 { margin: 0; font-size: 13.5px; font-weight: 600; }
.rwy-head .sub { margin: 2px 0 0 0; font-size: 11.5px; color: var(--ink-soft); font-family: 'JetBrains Mono', monospace; }
#rwyToggle {
  background: transparent; border: 1px solid var(--line);
  color: var(--ink-soft); width: 26px; height: 26px; border-radius: 5px;
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0;
}
#rwyToggle:hover { color: var(--ink); border-color: var(--ink-mute); }

.rwy-body {
  display: grid; grid-template-columns: minmax(420px, 1fr) auto;
  gap: 20px; padding: 10px 18px 14px 18px; align-items: center;
}
@media (max-width: 900px) { .rwy-body { grid-template-columns: 1fr; } }

.rwy-controls {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px 16px;
  align-items: end;
}
.rwy-controls .field { display: flex; flex-direction: column; gap: 4px; }
.rwy-controls .field-btn { align-self: end; }
.rwy-controls label {
  font-size: 10.5px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-mute);
}
.rwy-btns { display: inline-flex; gap: 4px; }
.rwy-btns button {
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
  padding: 5px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
}
.rwy-btns button.active {
  background: var(--accent-2); color: #0d1015; border-color: var(--accent-2);
  font-weight: 700;
}
.wind-inputs {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 12.5px;
  color: var(--ink-soft);
}
.wind-inputs input {
  background: rgba(255,255,255,0.04); border: 1px solid var(--line);
  color: var(--ink); font: inherit; font-family: 'JetBrains Mono', monospace;
  width: 62px; padding: 5px 6px; border-radius: 5px; text-align: right;
}
.wind-inputs input:focus { outline: none; border-color: var(--accent-2); }
.wind-inputs .lbl-sm { font-size: 10.5px; color: var(--ink-mute); text-transform: uppercase; }

#windFromScenario {
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
  padding: 6px 10px; border-radius: 6px; font-size: 11.5px; cursor: pointer;
  white-space: nowrap;
}
#windFromScenario:hover:not(:disabled) { color: var(--ink); border-color: var(--ink-mute); }
#windFromScenario:disabled { opacity: 0.45; cursor: not-allowed; }

.rwy-out {
  display: flex; align-items: center; gap: 16px;
}
.rwy-nums {
  display: grid; grid-template-columns: auto auto; gap: 4px 14px;
  font-family: 'JetBrains Mono', monospace; font-size: 12.5px;
  color: var(--ink-soft); align-content: center;
}
.rwy-nums .k { color: var(--ink-mute); text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.05em; align-self: center; }
.rwy-nums .v { color: var(--ink); font-weight: 600; text-align: right; }
.rwy-nums .v .side { color: var(--ink-mute); font-weight: 400; margin-left: 3px; font-size: 11px; }
.rwy-status {
  grid-column: 1 / -1; margin-top: 6px;
  padding: 5px 10px; border-radius: 5px; text-align: center;
  font-family: 'Inter', sans-serif; font-weight: 600; font-size: 12px;
  letter-spacing: 0.04em;
}
.rwy-status.green { background: rgba(62,166,132,0.18); color: #6dd6a8; border: 1px solid rgba(62,166,132,0.4); }
.rwy-status.amber { background: rgba(255,180,84,0.18); color: #ffb454; border: 1px solid rgba(255,180,84,0.4); }
.rwy-status.red   { background: rgba(198,85,69,0.22);  color: #ff8570; border: 1px solid rgba(198,85,69,0.5); }

/* Elevation cursor marker on map */
.elev-cursor {
  width: 12px; height: 12px; border-radius: 50%;
  background: #c65545; border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.25);
}

/* Scenario radio group */
.scenario {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 10px; border-radius: 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
}
.scenario .scenario-lbl {
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-mute); margin-right: 4px;
}
.scenario label {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--ink-soft); cursor: pointer;
  padding: 2px 6px; border-radius: 5px;
}
.scenario label:hover { color: var(--ink); }
.scenario input[type="radio"] { accent-color: var(--accent-2); margin: 0; }
.scenario input:checked + span { color: var(--ink); font-weight: 600; }

/* Scenario overlay visibility */
.legend div.sc-only, .sc-only { display: none !important; }
body.scenario-active .legend div.sc-only,
body.scenario-active .sc-only { display: flex !important; }
body.scenario-sw .legend div.lenti-row,
body.scenario-sw .legend div.rotor-row { display: none !important; }
body.scenario-n .legend div.cb-row { display: none !important; }

.cloud-ico {
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
  pointer-events: none;
  transform-origin: center;
  animation: cloud-drift 8s ease-in-out infinite alternate;
}
@keyframes cloud-drift {
  from { transform: translate(0, 0); }
  to   { transform: translate(3px, -2px); }
}
.cloud-ico.cb { animation-duration: 6s; }

.wind-arrow {
  pointer-events: none;
  opacity: 0.85;
}
.wind-arrow path {
  stroke: #3a6f8a;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wind-arrow .head { fill: #3a6f8a; stroke: none; }

.sw-badge {
  position: absolute;
  top: 12px; left: 60px; z-index: 500;
  background: rgba(20,22,28,0.82);
  color: #f2ede0;
  padding: 7px 11px; border-radius: 8px;
  font-size: 11.5px; line-height: 1.35;
  border: 1px solid rgba(255,255,255,0.15);
  max-width: 290px;
  pointer-events: none;
  display: none;
}
body.scenario-active .sw-badge { display: block; }
.sw-badge b { color: #ffb570; }
.sw-badge .sub { color: #b8bcc8; font-size: 10.5px; margin-top: 3px; display: block; }

.lenti-ico {
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
  pointer-events: none;
  animation: cloud-drift 10s ease-in-out infinite alternate;
}
.rotor-ico {
  pointer-events: none;
  animation: rotor-spin 5s linear infinite;
  transform-origin: center;
}
@keyframes rotor-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.sw-ico { display: inline-flex; margin-right: 4px; vertical-align: middle; }

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--panel); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 10px 12px; font-size: 12.5px; line-height: 1.5; }
.leaflet-popup-content b { color: var(--ink); }
.pop-title { font-size: 13.5px; font-weight: 600; margin-bottom: 3px; }
.pop-sub { color: var(--ink-soft); font-size: 11.5px; margin-bottom: 6px; }
.pop-row { display: flex; justify-content: space-between; gap: 12px; }
.pop-row span:last-child { font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }

/* Peak markers */
.peak-marker {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
}
.peak-marker svg { filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.35)); }
.airport-marker svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4)); }

/* Scale control tweak */
.leaflet-control-scale-line { background: rgba(255,255,255,0.85); color: #333; }
