/* ============================================================================
   Nowcast Engine — "Will it rain on ME" storm-motion radar
   Client-side optical-flow nowcaster layered over the existing Leaflet radar.
   Apple Liquid Glass aesthetic, matches the tinyblue weather design system.
   Feature slug: nowcast-engine-will-it-rain-on-me-storm-
   ============================================================================ */

:root {
  --nc-future-tint: #38bdf8;
  --nc-observed: #1474e6;
  --nc-arrow: #38e0d6;
  --nc-warn: #f97316;
  --nc-good: #34d399;
}

/* ---- Launch button injected into the radar HUD ------------------------- */
.nc-launch {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 640;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px 9px 13px;
  border: 1px solid var(--wx-glass-edge, rgba(255, 255, 255, .22));
  border-radius: 999px;
  background: var(--wx-glass-strong, rgba(20, 24, 40, .82));
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  color: var(--ink, #fff);
  font: 600 13px/1 system-ui, -apple-system, "SF Pro Text", sans-serif;
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: 0 8px 30px var(--wx-glass-shadow, rgba(0, 0, 0, .45)),
    inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .35s cubic-bezier(.22, 1, .36, 1), box-shadow .35s ease, background .35s ease;
}
.nc-launch:hover {
  transform: translateX(-50%) translateY(-1px) scale(1.02);
  box-shadow: 0 14px 42px var(--wx-glass-shadow, rgba(0, 0, 0, .5)),
    inset 0 1px 0 rgba(255, 255, 255, .35);
}
.nc-launch:active { transform: translateX(-50%) scale(.98); }
.nc-launch:focus-visible { outline: 2px solid var(--nc-future-tint); outline-offset: 3px; }
.nc-launch .nc-launch-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--nc-good);
  box-shadow: 0 0 0 0 color-mix(in oklab, var(--nc-good) 70%, transparent);
  animation: nc-pulse-dot 2.4s ease-out infinite;
}
.nc-launch[data-state="armed"] .nc-launch-dot { background: var(--nc-future-tint); }
.nc-launch[data-state="error"] .nc-launch-dot { background: var(--nc-warn); animation: none; }
@keyframes nc-pulse-dot {
  0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--nc-future-tint) 60%, transparent); }
  70% { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.nc-launch .nc-launch-glyph {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---- SVG overlay for storm-motion arrow & future field ----------------- */
.nc-overlay {
  position: absolute;
  inset: 0;
  z-index: 615;          /* above radar canvas (radarPane ~420), below HUD chips */
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity .5s ease;
}
.nc-overlay.is-on { opacity: 1; }

.nc-overlay-future {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  mix-blend-mode: screen;
}
:root[data-theme="light"] .nc-overlay-future { mix-blend-mode: multiply; }

.nc-overlay-svg { position: absolute; inset: 0; width: 100%; height: 100%; }

.nc-arrow-path {
  stroke: var(--nc-arrow);
  stroke-width: 4;
  stroke-linecap: round;
  fill: none;
  filter: drop-shadow(0 0 6px color-mix(in oklab, var(--nc-arrow) 70%, transparent));
}
.nc-arrow-head { fill: var(--nc-arrow); filter: drop-shadow(0 0 6px color-mix(in oklab, var(--nc-arrow) 70%, transparent)); }
.nc-arrow-sweep {
  stroke: #fff;
  stroke-width: 4;
  stroke-linecap: round;
  fill: none;
  opacity: .85;
  stroke-dasharray: 14 220;
  animation: nc-sweep 2.6s linear infinite;
}
@keyframes nc-sweep { to { stroke-dashoffset: -234; } }

.nc-track-line {
  stroke: color-mix(in oklab, var(--nc-future-tint) 80%, transparent);
  stroke-width: 2;
  stroke-dasharray: 5 7;
  fill: none;
  opacity: .7;
}

/* ---- The user-pin countdown tooltip (Liquid Glass) --------------------- */
.nc-countdown {
  position: absolute;
  z-index: 650;
  transform: translate(-50%, calc(-100% - 18px));
  min-width: 184px;
  max-width: 230px;
  padding: 13px 15px 14px;
  border: 1px solid var(--wx-glass-edge, rgba(255, 255, 255, .22));
  border-radius: 18px;
  background: var(--wx-glass-strong, rgba(16, 20, 34, .86));
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  backdrop-filter: blur(26px) saturate(180%);
  box-shadow: 0 18px 50px var(--wx-glass-shadow, rgba(0, 0, 0, .5)),
    inset 0 1px 0 rgba(255, 255, 255, .22);
  color: var(--ink, #fff);
  pointer-events: none;
  opacity: 0;
  transition: opacity .45s ease, transform .45s cubic-bezier(.22, 1, .36, 1);
}
.nc-countdown.is-on { opacity: 1; }
.nc-countdown::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 14px; height: 14px;
  transform: translateX(-50%) rotate(45deg);
  background: inherit;
  border-right: 1px solid var(--wx-glass-edge, rgba(255, 255, 255, .22));
  border-bottom: 1px solid var(--wx-glass-edge, rgba(255, 255, 255, .22));
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  backdrop-filter: blur(26px) saturate(180%);
}
.nc-countdown-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 9px;
}
.nc-ring {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    conic-gradient(var(--nc-future-tint) calc(var(--nc-progress, 0) * 1%), transparent 0),
    radial-gradient(circle, var(--wx-glass) 60%, transparent 62%);
  position: relative;
}
.nc-ring::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--wx-glass-strong, rgba(16, 20, 34, .92));
}
.nc-ring-icon {
  position: relative;
  width: 17px; height: 17px;
  stroke: var(--nc-future-tint);
  fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.nc-countdown[data-verdict="dry"] .nc-ring-icon { stroke: var(--nc-good); }
.nc-countdown[data-verdict="raining"] .nc-ring-icon,
.nc-countdown[data-verdict="incoming"] .nc-ring-icon { stroke: var(--nc-future-tint); }
.nc-countdown-headline {
  font: 700 15px/1.15 system-ui, -apple-system, sans-serif;
  letter-spacing: -.01em;
}
.nc-countdown-sub {
  font: 500 11px/1.3 system-ui, -apple-system, sans-serif;
  color: var(--ink-mute, rgba(255, 255, 255, .65));
  margin-top: 1px;
}
.nc-countdown-rows {
  display: grid;
  gap: 5px;
  padding-top: 9px;
  margin-top: 2px;
  border-top: 1px solid var(--rule, rgba(255, 255, 255, .1));
}
.nc-countdown-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font: 500 11.5px/1.2 system-ui, -apple-system, sans-serif;
}
.nc-countdown-row span:first-child { color: var(--ink-mute, rgba(255, 255, 255, .6)); }
.nc-countdown-row span:last-child { font-weight: 650; font-variant-numeric: tabular-nums; }
.nc-countdown-pin {
  position: absolute;
  z-index: 648;
  width: 16px; height: 16px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, var(--nc-future-tint) 30%, transparent 72%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s ease;
}
.nc-countdown-pin.is-on { opacity: 1; }
.nc-countdown-pin::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in oklab, var(--nc-future-tint) 70%, transparent);
  animation: nc-ping 2.2s ease-out infinite;
}
@keyframes nc-ping {
  0% { transform: scale(.5); opacity: .9; }
  100% { transform: scale(1.9); opacity: 0; }
}

/* ---- Future timeline segment (grows the existing scrubber) ------------- */
.nc-future-rail {
  position: absolute;
  z-index: 630;
  left: 14px;
  right: 14px;
  bottom: 56px;
  height: 30px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid var(--wx-glass-edge, rgba(255, 255, 255, .2));
  background: var(--wx-glass, rgba(20, 24, 40, .7));
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  box-shadow: 0 10px 30px var(--wx-glass-shadow, rgba(0, 0, 0, .4));
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .45s ease, transform .45s cubic-bezier(.22, 1, .36, 1);
  pointer-events: none;
}
.nc-future-rail.is-on { opacity: 1; transform: translateY(0); pointer-events: auto; }
.nc-future-rail .nc-rail-label {
  font: 600 11px/1 system-ui, -apple-system, sans-serif;
  color: var(--ink-mute, rgba(255, 255, 255, .65));
  white-space: nowrap;
}
.nc-future-rail .nc-rail-now {
  flex: 0 0 auto;
  font: 700 11px/1 system-ui, -apple-system, sans-serif;
  color: var(--nc-observed);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.nc-rail-track {
  position: relative;
  flex: 1 1 auto;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    color-mix(in oklab, var(--nc-observed) 55%, transparent) 0 50%,
    color-mix(in oklab, var(--nc-future-tint) 45%, transparent) 50% 100%);
  overflow: visible;
}
.nc-rail-track::before {
  content: "";
  position: absolute;
  left: 50%; top: -3px; bottom: -3px;
  width: 2px;
  background: var(--ink, #fff);
  opacity: .55;
}
.nc-rail-track::after {
  content: "";
  position: absolute;
  left: 50%; right: 0; top: 0; bottom: 0;
  border-radius: 999px;
  border: 1px dashed color-mix(in oklab, var(--nc-future-tint) 80%, transparent);
  border-left: none;
}
.nc-rail-thumb {
  position: absolute;
  top: 50%;
  width: 16px; height: 16px;
  margin-left: -8px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--nc-future-tint));
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .6);
  cursor: grab;
  touch-action: none;
}
.nc-rail-thumb:active { cursor: grabbing; }
.nc-future-rail .nc-rail-readout {
  flex: 0 0 auto;
  min-width: 58px;
  text-align: right;
  font: 700 12px/1 system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
  color: var(--nc-future-tint);
}

/* ---- "Will it rain on me" verdict badge (top of radar) ----------------- */
.nc-verdict {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  z-index: 635;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--wx-glass-edge, rgba(255, 255, 255, .2));
  background: var(--wx-glass-strong, rgba(16, 20, 34, .85));
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  box-shadow: 0 10px 32px var(--wx-glass-shadow, rgba(0, 0, 0, .42));
  color: var(--ink, #fff);
  font: 650 13px/1 system-ui, -apple-system, sans-serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s ease, transform .5s cubic-bezier(.22, 1, .36, 1);
  max-width: min(92vw, 460px);
  text-align: center;
}
.nc-verdict.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }
.nc-verdict .nc-verdict-icon {
  width: 16px; height: 16px;
  flex: 0 0 auto;
  stroke: var(--nc-future-tint); fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.nc-verdict[data-verdict="dry"] .nc-verdict-icon { stroke: var(--nc-good); }
.nc-verdict[data-verdict="raining"] .nc-verdict-icon { stroke: var(--nc-warn); }

/* ---- Reduced motion: kill sweeps & pings, keep static vector ----------- */
@media (prefers-reduced-motion: reduce) {
  .nc-arrow-sweep { animation: none; opacity: 0; }
  .nc-launch .nc-launch-dot { animation: none; }
  .nc-countdown-pin::after { animation: none; }
  .nc-overlay, .nc-countdown, .nc-future-rail, .nc-verdict, .nc-launch {
    transition: opacity .01s linear;
  }
}

/* ---- Small screens ----------------------------------------------------- */
@media (max-width: 560px) {
  .nc-launch { top: 10px; padding: 8px 13px 8px 11px; font-size: 12px; }
  .nc-verdict { top: 50px; font-size: 12px; padding: 7px 12px; }
  .nc-future-rail { bottom: 50px; }
  .nc-countdown { min-width: 168px; }
}
