:root {
  --ink: rgba(10, 14, 22, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f7fb;
  --muted: #b7c3d4;
  --accent: #3ec2ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
  font-family: "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b1018; color: var(--text); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#map { position: absolute; inset: 0; }
#particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}
#progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  width: 40%;
  z-index: 8;
  background: linear-gradient(90deg, transparent, var(--accent), #fff);
  animation: slide 1s ease-in-out infinite;
}
#progress[hidden] { display: none; }
@keyframes slide { 50% { transform: translateX(160%); } }

#hover {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  background: rgba(8, 12, 18, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}

header, .layers, #legend, #picker, #route-panel, #timeline, #status {
  z-index: 5;
}
header {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  pointer-events: none;
}
header > * { pointer-events: auto; }

.brand, .header-actions button, .layers button, #legend, #picker, #route-panel, #timeline, #model-pill {
  background: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  border-radius: 14px;
  padding: 8px 12px 8px 8px;
}
.brand strong { display: block; letter-spacing: 0.08em; font-size: 15px; }
.brand small { color: var(--muted); letter-spacing: 0.04em; }
.mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.35), transparent 40%),
    linear-gradient(160deg, #1c4f86, #123);
  position: relative;
}
.mark::before, .mark::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  height: 2px;
  border-radius: 2px;
  background: #9ee7ff;
}
.mark::before { top: 13px; transform: rotate(-8deg); }
.mark::after { top: 20px; background: #f0c14a; transform: rotate(8deg); }

#search { position: relative; flex: 1; max-width: 560px; margin: 0 auto; }
#q {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
#results {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  max-height: 280px;
  overflow: auto;
}
#results button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 8px;
  color: var(--text);
}
#results button:hover, #results button[aria-selected="true"] { background: rgba(255, 255, 255, 0.08); }
#results[hidden] { display: none; }

.header-actions { display: flex; gap: 8px; }
.header-actions button, .route-actions button, .modes button, .layers button, #btn-unit, #play, #model-pill {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  padding: 10px 12px;
}
.header-actions button { background: var(--ink); box-shadow: var(--shadow); }
#btn-route[aria-pressed="true"], .layers button.on, .modes button.on, .route-actions .primary {
  background: #145f86;
  border-color: #3ec2ff;
}

.layers {
  position: absolute;
  top: 74px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.layers button { min-width: 74px; background: var(--ink); }

#legend {
  position: absolute;
  top: 168px;
  right: 12px;
  bottom: 92px;
  width: 86px;
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  min-height: 180px;
}
#legend-title { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.legend-body { flex: 1; display: flex; gap: 4px; min-height: 0; margin: 6px 0; }
#legend-ticks { position: relative; flex: 1; }
#legend-ticks span {
  position: absolute;
  right: 0;
  transform: translateY(50%);
  font-size: 11px;
  color: var(--muted);
}
#legend-bar { width: 14px; border-radius: 7px; }
#btn-unit { width: 100%; padding: 6px; }

#picker, #route-panel {
  position: absolute;
  top: 74px;
  left: 12px;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100vh - 170px);
  overflow: auto;
  border-radius: 16px;
  padding: 14px;
}
#picker-close, #route-close {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
}
#picker-name { padding-right: 24px; color: var(--muted); font-size: 13px; }
.picker-main { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
#picker-arrow {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background:
    linear-gradient(#fff, #fff) center 10px / 3px 18px no-repeat,
    linear-gradient(135deg, transparent 50%, #fff 50% 60%, transparent 60%) center 8px / 12px 12px no-repeat,
    rgba(255, 255, 255, 0.04);
}
.speed-row { display: flex; align-items: baseline; gap: 6px; }
#picker-speed { font-size: 42px; font-weight: 650; letter-spacing: -0.03em; }
#picker-bft, #picker-dir, .gust-row, .fine, #route-hint { color: var(--muted); }
.gust-row { margin: 8px 0; }
.fine { font-size: 12px; margin: 8px 0 0; }
#picker-chart, #route-chart { width: 100%; height: auto; display: block; margin-top: 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.2); }

.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; font-size: 18px; }
.modes, .route-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.modes button, .route-actions button { background: rgba(255, 255, 255, 0.04); }
.route-fields { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; margin-top: 10px; }
.route-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.route-fields input {
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 8px;
}
#route-hint { font-size: 13px; }
#waypoints { margin: 8px 0 0; padding-left: 22px; }
#waypoints li { margin: 4px 0; }
#waypoints button { border: 0; background: transparent; color: #ff8d8d; }
#route-summary { margin-top: 10px; }
#route-table { overflow: auto; margin-top: 8px; }
#route-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
#route-table th, #route-table td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
#route-table th:first-child, #route-table td:first-child { text-align: left; }
.tail { color: #8ee6a2; }
.head { color: #ff9b7a; }
.pin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #145f86;
  border: 2px solid #fff;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.place-pin {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #f4f7fb;
  border: 3px solid #49b6ff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.45);
}
.wind-arrow {
  width: 18px;
  height: 18px;
  background:
    linear-gradient(#fff, #fff) center 1px / 2px 8px no-repeat,
    linear-gradient(135deg, transparent 50%, #fff 50% 64%, transparent 64%) center 0 / 9px 9px no-repeat;
  filter: drop-shadow(0 0 2px #000);
}
.gps-fix {
  width: 0;
  height: 0;
  overflow: visible;
  pointer-events: none;
}
.gps-arrow {
  position: absolute;
  left: -8px;
  bottom: 0;
  width: 16px;
  height: 20px;
  transform-origin: 50% 100%;
  background:
    linear-gradient(#14324f, #14324f) center bottom / 3px 11px no-repeat,
    linear-gradient(135deg, transparent 46%, #14324f 46% 58%, transparent 58%) center top / 16px 12px no-repeat;
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 2px #fff);
}
.gps-arrow.still {
  left: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #14324f;
  border: 2px solid #fff;
  filter: none;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}
.gps-readout {
  position: absolute;
  left: 14px;
  top: -14px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 12, 18, 0.88);
  font-size: 12px;
  white-space: nowrap;
}
.gps-readout:empty { display: none; }

#timeline {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-radius: 16px;
  padding: 8px 10px;
}
#play {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  color: #111;
  border: 0;
  font-size: 16px;
  flex: none;
}
.track { position: relative; flex: 1; min-width: 0; padding-top: 16px; }
#days { position: relative; height: 14px; }
#days span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
#scrub { width: 100%; accent-color: #fff; }
#readout { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
#readout strong { color: var(--text); font-size: 14px; }
#model-pill { padding: 8px 10px; border-radius: 12px; letter-spacing: 0.08em; font-size: 12px; }
#status {
  position: absolute;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%);
  background: rgba(120, 24, 24, 0.92);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}
#status:empty { display: none; }

.maplibregl-ctrl-bottom-left { bottom: 84px; left: 8px; }
.maplibregl-ctrl-bottom-right { bottom: 84px; right: 108px; }
.maplibregl-ctrl-attrib { font-size: 11px; background: rgba(10, 14, 22, 0.7) !important; }

@media (hover: none) { #hover { display: none !important; } }

@media (max-width: 760px) {
  header { flex-wrap: wrap; }
  #search { order: 3; max-width: none; flex-basis: 100%; }
  #legend { top: auto; bottom: 92px; height: 150px; width: 72px; }
  .layers { top: auto; bottom: 252px; }
  #picker, #route-panel {
    top: auto;
    bottom: 92px;
    max-height: 48vh;
  }
  .route-fields { grid-template-columns: 1fr; }
  #model-pill { display: none; }
  #days span:nth-child(odd) { display: none; }
}
