* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #9fb4d0;
  font: 12px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Segoe UI, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app { position: fixed; inset: 0; }

#view {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* we handle all gestures ourselves */
  cursor: grab;
}
#view:active { cursor: grabbing; }

.hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: auto auto;
  gap: 1px 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(12, 16, 22, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #e8eef6;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  font-size: 11px;
}
.hud .k { color: #8fa4bd; }
.hud .v { text-align: right; }

.toast {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(90vw, 460px);
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(150, 32, 32, 0.94);
  color: #fff;
  z-index: 10;
}
.toast.warn { background: rgba(150, 104, 24, 0.94); }

.attribution {
  position: absolute;
  right: max(6px, env(safe-area-inset-right));
  bottom: max(6px, env(safe-area-inset-bottom));
  max-width: 70vw;
  padding: 3px 7px;
  border-radius: 5px;
  background: rgba(12, 16, 22, 0.5);
  color: #cfdaea;
  font-size: 10px;
  text-align: right;
  pointer-events: none;
}

/* States what this build actually is, so a missing feature reads as "not built
   yet" rather than "broken". */
.phase {
  position: absolute;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 16, 22, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #dce6f2;
  text-align: center;
  pointer-events: none;
}
.phase b { color: #8fc7ff; font-weight: 600; }

/* The HUD is a development readout; on a phone it should stay out of the way
   of the thing it is reporting on. */
@media (max-width: 500px) {
  .hud { font-size: 10px; padding: 5px 8px; gap: 0 6px; opacity: 0.85; }
  .attribution { font-size: 9px; max-width: 60vw; }
  /* Stack the two bottom labels instead of letting them collide. The
     attribution wraps to two lines at this width (44px measured), so the phase
     banner needs to clear that, not a nominal single line. */
  .phase {
    font-size: 10px;
    padding: 5px 10px;
    bottom: calc(max(6px, env(safe-area-inset-bottom)) + 52px);
  }
  .attribution {
    max-width: 94vw;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    text-align: center;
  }
}

/* Viewer controls. Collapsed to a single button by default so the map stays
   the subject; the panel is bottom-left so it never fights the HUD. */
.controls {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  font: 12px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e8eef6;
}
.controls-toggle {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 0;
  background: rgba(12, 16, 22, 0.62);
  color: #e8eef6;
  font-size: 16px;
  cursor: pointer;
}
.controls-body {
  display: none;
  margin-top: 8px;
  padding: 12px;
  width: 216px;
  border-radius: 10px;
  background: rgba(12, 16, 22, 0.72);
  backdrop-filter: blur(6px);
}
.controls-body.open { display: block; }
.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.controls-row + .controls-row { margin-top: 12px; }
.controls-label { opacity: 0.75; }
.controls-value { font-variant-numeric: tabular-nums; }
.controls-seg { display: flex; gap: 4px; }
.controls-seg button {
  border: 0;
  border-radius: 6px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.10);
  color: #e8eef6;
  cursor: pointer;
  font: inherit;
}
.controls-seg button.on { background: #3b82f6; }
/* On/off switch, styled like the segmented buttons so the panel reads as one
   set of controls rather than a collection of widgets. */
.controls-switch {
  border: 0;
  border-radius: 6px;
  padding: 4px 10px;
  min-width: 40px;
  background: rgba(255, 255, 255, 0.10);
  color: #e8eef6;
  cursor: pointer;
  font: inherit;
}
.controls-switch.on { background: #3b82f6; }
.controls-note { opacity: 0.55; font-size: 11px; margin-bottom: 2px; }
.controls input[type="range"] {
  width: 100%;
  margin: 2px 0;
  accent-color: #3b82f6;
}

/* Forecast scrubber: play/pause beside the time slider. */
.controls-time {
  display: flex;
  align-items: center;
  gap: 8px;
}
.controls-time button {
  flex: 0 0 auto;
  width: 26px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.10);
  color: #e8eef6;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.controls-time input[type="range"] { flex: 1 1 auto; margin: 0; }

/* Compass: top-right, fades out entirely when the view is already north-up. */
.compass {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  width: 42px;
  height: 42px;
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: rgba(12, 16, 22, 0.62);
  cursor: pointer;
  transition: opacity 0.25s;
}
.compass-ring { fill: none; stroke: rgba(232, 238, 246, 0.25); stroke-width: 1.5; }
.compass-n { fill: #e2564a; }
.compass-s { fill: rgba(232, 238, 246, 0.75); }

/* Speed legend: bottom-right, above the attribution. */
.legend {
  position: absolute;
  right: 12px;
  bottom: 44px;
  z-index: 5;
  width: 168px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(12, 16, 22, 0.62);
  color: #e8eef6;
  font: 11px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.legend-bar { height: 8px; border-radius: 4px; }
.legend-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.legend-unit { opacity: 0.55; margin-top: 2px; }

/* On a phone the legend has to clear the stacked bottom labels, or it lands on
   top of them: the phase banner and the two-line attribution together occupy
   the bottom ~100 px at 390 px wide, while the desktop offset is 44 px.
   This block must come AFTER the base .legend rule — an identical-specificity
   override inside the earlier media query silently loses to it, which is how
   the overlap survived a first fix. */
@media (max-width: 500px) {
  .legend {
    width: 132px;
    padding: 6px 8px;
    font-size: 10px;
    bottom: calc(max(6px, env(safe-area-inset-bottom)) + 100px);
  }
}

/* Preset places: a wrapping row of small buttons. */
.controls-places {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.controls-places button {
  border: 0;
  border-radius: 6px;
  padding: 4px 7px;
  background: rgba(255, 255, 255, 0.10);
  color: #e8eef6;
  cursor: pointer;
  font: inherit;
}
.controls-places button:hover { background: rgba(255, 255, 255, 0.18); }

/* Wind profile panel: opens on a click, top-left under the HUD. */
.profile {
  position: absolute;
  left: 12px;
  /* Below the HUD, which grew when it gained the atmospheric-state line.
     Measured: the HUD reaches ~215 px at its tallest, so 228 clears it with a
     margin rather than by coincidence. */
  top: 228px;
  z-index: 6;
  width: 500px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(12, 16, 22, 0.78);
  backdrop-filter: blur(6px);
  color: #e8eef6;
  font: 11px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.profile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.profile-close {
  border: 0;
  background: transparent;
  color: #e8eef6;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}
.profile-line { fill: none; stroke: #6ee7d0; stroke-width: 2; }
.profile-barb { stroke: rgba(232, 238, 246, 0.65); stroke-width: 1.2; }
.profile-grid { stroke: rgba(232, 238, 246, 0.14); stroke-width: 1; }
.profile-tick { fill: rgba(232, 238, 246, 0.5); font-size: 9px; }
.profile-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  opacity: 0.75;
}

/* The flight-planning panel: 18 hours across the top, the selected hour's
   numbers and wind profile below. Both visible at once because they answer
   different questions — when to fly, and what the air is doing. */
.pf-timeline {
  display: flex;
  gap: 1px;
  margin: 6px 0 8px;
}
.tl-col {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 3px 0 2px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.tl-col:hover { background: rgba(255, 255, 255, 0.07); }
.tl-col.on { background: rgba(59, 130, 246, 0.30); }
/* Thermal strength as a bar, so the shape of the day reads at a glance. */
.tl-bar {
  width: 7px;
  border-radius: 2px 2px 0 0;
  background: linear-gradient(to top, #f59e0b, #fcd34d);
  align-self: flex-end;
}
/* Flyability as a dot under it: the verdict, separate from the strength,
   because a strong day can still be unflyable. */
.tl-dot { width: 6px; height: 6px; border-radius: 50%; }
.tl-dot.good { background: #4ade80; }
.tl-dot.fair { background: #fcd34d; }
.tl-dot.poor { background: #fb923c; }
.tl-dot.no   { background: rgba(232, 238, 246, 0.22); }
.tl-hr { font-size: 9px; opacity: 0.6; font-variant-numeric: tabular-nums; }

.pf-body { display: flex; gap: 10px; align-items: flex-start; }
.pf-facts { flex: 0 0 190px; }
.pf-plot { flex: 1 1 auto; }
.pf-hour { font-size: 13px; font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.pf-verdict { display: flex; align-items: baseline; gap: 6px; }
.pf-stars { letter-spacing: 1px; }
.pf-label { font-size: 11px; font-weight: 600; }
.pf-verdict.good .pf-stars, .pf-verdict.good .pf-label { color: #4ade80; }
.pf-verdict.fair .pf-stars, .pf-verdict.fair .pf-label { color: #fcd34d; }
.pf-verdict.poor .pf-stars, .pf-verdict.poor .pf-label { color: #fb923c; }
/* The reason the verdict came out that way. Never hidden: a call a pilot
   cannot audit is a call they should not trust. */
.pf-reason { opacity: 0.7; font-size: 10px; margin: 2px 0 6px; }
.pf-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1px 8px;
  font-variant-numeric: tabular-nums;
}
.pf-grid dt { opacity: 0.55; }
.pf-grid dd { margin: 0; }
.pf-axis { font-size: 9px; opacity: 0.5; text-align: center; margin-top: 2px; }
.pf-ceiling { stroke: #4ade80; stroke-width: 1; stroke-dasharray: 3 3; }
.pf-ceiling-t { fill: #4ade80; font-size: 9px; opacity: 0.9; }
.pf-note {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(232, 238, 246, 0.12);
  font-size: 9px;
  opacity: 0.5;
}

/* On a phone the panel becomes a bottom sheet. At 500 px wide it cannot sit
   beside anything, and a fixed top offset would push the profile off-screen
   the moment the timeline is stacked above it. */
@media (max-width: 560px) {
  .profile {
    left: 6px;
    right: 6px;
    top: auto;
    bottom: max(6px, env(safe-area-inset-bottom));
    width: auto;
    max-height: 62vh;
    overflow-y: auto;
  }
  .pf-body { flex-direction: column; }
  .pf-facts { flex: 1 1 auto; }
  .pf-plot { width: 100%; }
  /* Cap the plot's height instead of letting it scale with the sheet's width.
     width:100%/height:auto on a 232x176 viewBox makes it ~280 px tall on a
     390 px phone, which pushed the 10 m label off the bottom of the sheet. */
  .pf-plot svg { width: 100%; height: 150px; }
  .tl-hr { font-size: 8px; }
  /* A bottom sheet owns the bottom of the screen while it is open. Leaving the
     legend, the controls button and the attribution underneath it means three
     overlapping layers on a 390 px phone — measured, not guessed. They come
     back when the sheet closes. */
  body:has(.profile[style*="block"]) .legend,
  body:has(.profile[style*="block"]) .attribution,
  body:has(.profile[style*="block"]) .phase { display: none; }
  /* The controls button moves out of the sheet's way rather than sitting on
     top of the plot — it is still reachable, just above the sheet. */
  body:has(.profile[style*="block"]) .controls {
    z-index: 7;
    bottom: auto;
    top: max(8px, env(safe-area-inset-top));
    left: auto;
    right: 12px;
  }
}

.controls-locate {
  width: 100%;
  margin-bottom: 4px;
  border: 0;
  border-radius: 6px;
  padding: 5px 7px;
  background: rgba(255, 255, 255, 0.10);
  color: #e8eef6;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.controls-locate:hover { background: rgba(255, 255, 255, 0.18); }
