/*
 * Bui — "precision instrument, Delft ink."
 *
 * Glassy instrument chrome floating over a full-screen map. Bricolage
 * Grotesque carries the voice; Spline Sans Mono carries the numbers.
 * Mobile gets floating cards; desktop gets a full-height instrument rail.
 */

:root {
  --font-display: "Bricolage Grotesque", system-ui, -apple-system, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --glass: rgba(251, 252, 254, 0.78);
  --glass-strong: rgba(255, 255, 255, 0.94);
  --bg-solid: #ffffff;
  --field: rgba(20, 29, 54, 0.05);
  --edge: rgba(255, 255, 255, 0.65);
  --ink: #141d36;
  --ink-dim: #5d6880;
  --line: rgba(20, 29, 54, 0.08);
  --accent: #2b50e0;
  --accent-ink: #1d3bb8;
  --accent-soft: rgba(43, 80, 224, 0.11);
  --amber: #c47b06;
  --amber-soft: rgba(224, 138, 0, 0.13);
  --rain-1: #62d3f7;
  --rain-2: #3f6cf0;
  --rain-3: #8b5cf6;
  --radius: 22px;
  --shadow: 0 16px 44px rgba(10, 16, 38, 0.16), 0 2px 8px rgba(10, 16, 38, 0.07);
  --shadow-pop: 0 24px 60px rgba(10, 16, 38, 0.22), 0 3px 10px rgba(10, 16, 38, 0.1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --split: 74%; /* radar/model boundary on the scrubber, set from JS */
  --rail-w: 424px; /* desktop rail width; JS derives map padding from this */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --glass: rgba(14, 19, 35, 0.78);
    --glass-strong: rgba(18, 24, 43, 0.96);
    --bg-solid: #111729;
    --field: rgba(231, 236, 248, 0.07);
    --edge: rgba(231, 236, 248, 0.09);
    --ink: #e7ecf8;
    --ink-dim: #92a0bf;
    --line: rgba(231, 236, 248, 0.09);
    --accent: #8fadff;
    --accent-ink: #b3c5ff;
    --accent-soft: rgba(143, 173, 255, 0.13);
    --amber: #f0b35a;
    --amber-soft: rgba(240, 179, 90, 0.13);
    --shadow: 0 16px 44px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-pop: 0 24px 60px rgba(0, 0, 0, 0.6), 0 3px 10px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-display);
  color: var(--ink);
  background: #0c1124;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

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

/* a soft vignette gives the map atmosphere without touching its data */
#map::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 40%, transparent 64%, rgba(10, 16, 38, 0.14));
}
@media (prefers-color-scheme: dark) {
  #map::after {
    background: radial-gradient(120% 90% at 50% 40%, transparent 60%, rgba(2, 5, 16, 0.42));
  }
}

/* ------------------------------------------------------------- entrance -- */

.topbar, .sheet { opacity: 0; }
body.ready .topbar { animation: drop-in 0.7s var(--ease-out) 0.05s forwards; }
body.ready .sheet { animation: rise-in 0.7s var(--ease-out) 0.14s forwards; }

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: none; }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(22px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------- splash -- */

#splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  background:
    radial-gradient(90% 70% at 50% 30%, #16204a 0%, #0c1124 70%);
  color: #e7ecf8;
  transition: opacity 0.45s ease, visibility 0.45s;
}
#splash.hide { opacity: 0; visibility: hidden; }
#splash svg {
  width: 64px;
  height: 64px;
  filter: drop-shadow(0 6px 24px rgba(98, 211, 247, 0.35));
  animation: drip 1.6s var(--ease-out) infinite;
}
@keyframes drip {
  0% { transform: translateY(-6px) scale(1, 0.96); }
  45% { transform: translateY(2px) scale(0.97, 1.04); }
  70% { transform: translateY(0) scale(1.02, 0.98); }
  100% { transform: translateY(-6px) scale(1, 0.96); }
}
.splash-word {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.splash-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: #8fa3d4;
}

/* ----------------------------------------------------------- panel rail -- */

.panel { display: contents; }
.panel-foot { display: none; }

/* -------------------------------------------------------------- top bar -- */

.topbar {
  position: fixed;
  top: calc(10px + var(--sat));
  left: 12px;
  right: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px 9px 11px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow);
  font-weight: 800;
  letter-spacing: 0.2px;
  font-size: 18px;
  user-select: none;
}
.brand svg { display: block; }

.search { position: relative; flex: 1; min-width: 0; }

.search-ico {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-dim);
  pointer-events: none;
}

.search input {
  width: 100%;
  border: 1px solid var(--edge);
  outline: none;
  padding: 10px 16px 10px 36px;
  border-radius: 999px;
  font-size: 16px; /* ≥16px so iOS doesn't zoom on focus */
  font-family: inherit;
  color: var(--ink);
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease;
}
.search input::placeholder { color: var(--ink-dim); }
.search input:focus {
  box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft);
}
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 16px;
  background: var(--glass-strong);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  z-index: 30;
  animation: results-in 0.18s var(--ease-out);
}
@keyframes results-in {
  from { opacity: 0; transform: translateY(-4px); }
}
.search-results li {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.search-results li span:first-child {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.search-results li .type {
  flex: none;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.search-results li:hover,
.search-results li.active { background: var(--accent-soft); }

.iconbtn {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.15s var(--ease-out);
}
.iconbtn:active { transform: scale(0.9); }
.iconbtn.busy svg { animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- bottom sheet -- */

.sheet {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(10px + var(--sab));
  z-index: 20;
  padding: 16px 16px 14px;
  border-radius: var(--radius);
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow-pop);
}

.sheet-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

/* animated status glyph: sun / cloud / rain */
.glyph {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  transition: background 0.4s ease, color 0.4s ease;
}
.glyph svg { width: 30px; height: 30px; display: none; overflow: visible; }
.glyph[data-status="dry"] { background: var(--amber-soft); color: var(--amber); }
.glyph[data-status="dry"] .g-sun { display: block; }
.glyph[data-status="later"] .g-cloud { display: block; }
.glyph[data-status="rain"] .g-rain { display: block; }
.glyph[data-status="loading"] { color: var(--ink-dim); }
.glyph[data-status="loading"] .g-cloud { display: block; opacity: 0.45; }
.glyph[data-status="nodata"] { background: var(--field); color: var(--ink-dim); }
.glyph[data-status="nodata"] .g-cloud { display: block; }
.glyph[data-status="nodata"] .drop { display: none; }

.g-sun .rays {
  transform-box: fill-box;
  transform-origin: center;
  animation: spin 40s linear infinite;
}
.g-rain .drop, .g-cloud .drop {
  animation: fall 1.4s ease-in infinite;
}
.g-rain .drop:nth-child(2) { animation-delay: 0.45s; }
.g-rain .drop:nth-child(3) { animation-delay: 0.9s; }
.g-cloud .drop { animation-duration: 3.2s; }
.g-cloud .drop:nth-child(2) { animation-delay: 1.6s; }
@keyframes fall {
  0% { transform: translateY(-3px); opacity: 0; }
  35% { opacity: 1; }
  100% { transform: translateY(6px); opacity: 0; }
}

.loc { min-width: 0; }
.loc h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.loc p {
  margin: 3px 0 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-dim);
}

.now-chip {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
#frame-time {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 23px;
  letter-spacing: -0.5px;
  line-height: 1;
}
.frame-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-dim);
  white-space: nowrap;
}
.kind {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 2.5px 9px;
  border-radius: 999px;
  margin-top: 2px;
}
.kind.radar { background: var(--accent-soft); color: var(--accent-ink); }
.kind.model { background: var(--amber-soft); color: var(--amber); }

/* ---------------------------------------------------------------- chart -- */

.chart-wrap { position: relative; height: 124px; }
#chart {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.chart-empty {
  position: absolute;
  inset: 0 0 14px;
  border-radius: 10px;
  pointer-events: none;
  overflow: hidden;
  background:
    repeating-linear-gradient(90deg, var(--line) 0 22px, transparent 22px 34px);
  opacity: 0.5;
  mask-image: linear-gradient(180deg, transparent 10%, #000 95%);
  -webkit-mask-image: linear-gradient(180deg, transparent 10%, #000 95%);
}
.chart-empty::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, var(--glass-strong) 50%, transparent 80%);
  animation: shimmer 1.6s ease infinite;
}
@keyframes shimmer {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

/* the skeleton stops promising progress when the forecast fetch failed */
.chart-empty.failed {
  display: grid;
  place-items: center;
  background: none;
  opacity: 0.8;
  mask-image: none;
  -webkit-mask-image: none;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.chart-empty.failed::after { display: none; }

/* chart svg internals */
#chart .tick { stroke: var(--line); stroke-width: 1; }
#chart .axis { stroke: var(--line); stroke-width: 1.5; }
#chart .ticklabel {
  fill: var(--ink-dim);
  font-size: 9.5px;
  text-anchor: middle;
  font-family: var(--font-mono);
}
#chart .rainline {
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linejoin: round;
  fill: none;
  opacity: 0.95;
}
#chart .boundary {
  stroke: var(--ink-dim);
  stroke-width: 1;
  stroke-dasharray: 2 4;
  stroke-linecap: round;
  opacity: 0.55;
}
#chart .seglabel,
#chart .ymaxlabel,
#chart .nowlabel {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
#chart .seglabel { fill: var(--amber); }
#chart .ymaxlabel { fill: var(--ink-dim); }
#chart .nowlabel { fill: var(--accent); text-anchor: middle; }
#chart .nowline {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 1.5 3.5;
  stroke-linecap: round;
  opacity: 0.7;
}
#chart .drylabel {
  fill: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  text-anchor: middle;
  opacity: 0.7;
}
#chart .playline { stroke: var(--ink); stroke-width: 1.3; opacity: 0.65; }
#chart .playdot {
  fill: var(--accent);
  stroke: var(--bg-solid);
  stroke-width: 2;
}
#chart .playglow { fill: var(--accent); opacity: 0.18; }

/* ------------------------------------------------------------- controls -- */

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 8px;
}

.iconbtn.play {
  width: 46px;
  height: 46px;
  border: none;
  background: linear-gradient(135deg, var(--rain-2), var(--rain-3));
  color: #fff;
  box-shadow: 0 8px 22px rgba(63, 108, 240, 0.45);
}
.iconbtn.play:active { transform: scale(0.88); }

#scrubber {
  /* one definition for both vendor-prefixed track pseudo-elements */
  --scrub-track: linear-gradient(
    90deg,
    var(--rain-1),
    var(--rain-2) calc(var(--split) * 0.6),
    var(--rain-3) calc(var(--split) - 1%),
    var(--amber-soft) var(--split),
    var(--amber-soft) 100%
  );
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 30px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  min-width: 0;
}
#scrubber::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--scrub-track);
  box-shadow: inset 0 0 0 1px var(--line);
}
#scrubber::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(10, 16, 38, 0.35);
  transition: transform 0.15s var(--ease-out);
}
#scrubber:active::-webkit-slider-thumb { transform: scale(1.25); }
#scrubber::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--scrub-track);
  box-shadow: inset 0 0 0 1px var(--line);
}
#scrubber::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
}

.legend {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.4px;
  color: var(--ink-dim);
}
.legend-bar {
  width: 52px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(98, 211, 247, 0.25), var(--rain-1), var(--rain-2), var(--rain-3));
}
@media (max-width: 374px) { .legend { display: none; } }

/* ---------------------------------------------------------------- toast -- */

.toast {
  position: fixed;
  top: calc(66px + var(--sat));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--edge);
  color: var(--ink);
  font-size: 13px;
  box-shadow: var(--shadow-pop);
  animation: toast-in 0.3s var(--ease-out);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
}

/* --------------------------------------------------------------- marker -- */

.pin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(43, 80, 224, 0.35), 0 2px 8px rgba(10, 16, 38, 0.4);
}
.pin::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(63, 108, 240, 0.5);
  animation: ping 1.8s ease-out infinite;
}
@keyframes ping {
  0% { transform: scale(0.5); opacity: 1; }
  80%, 100% { transform: scale(1.15); opacity: 0; }
}

/* ------------------------------------------------------ maplibre chrome -- */

.maplibregl-ctrl-top-right { top: calc(58px + var(--sat)); }
.maplibregl-ctrl-attrib { font-size: 10px; border-radius: 12px; }
@media (prefers-color-scheme: dark) {
  .maplibregl-ctrl-attrib { background: rgba(14, 19, 35, 0.7); color: var(--ink-dim); }
  .maplibregl-ctrl-attrib a { color: var(--ink-dim); }
}

/* ------------------------------------------------------- desktop layout -- */

@media (min-width: 920px) {
  .panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 16px;
    left: 16px;
    max-height: calc(100% - 32px);
    width: var(--rail-w);
    z-index: 20;
    padding: 18px;
    gap: 18px;
    border-radius: 26px;
    background: var(--glass);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid var(--edge);
    box-shadow: var(--shadow-pop);
    opacity: 0;
  }
  body.ready .panel { animation: rail-in 0.8s var(--ease-out) forwards; }
  @keyframes rail-in {
    from { opacity: 0; transform: translateX(-22px); }
    to { opacity: 1; transform: none; }
  }

  .topbar, .sheet {
    position: static;
    inset: auto;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .brand {
    background: none;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 0 4px 0 0;
  }
  .search input {
    background: var(--field);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    font-size: 14px;
  }
  .search input:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
  .iconbtn {
    background: var(--field);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .iconbtn.play {
    background: linear-gradient(135deg, var(--rain-2), var(--rain-3));
    box-shadow: 0 8px 22px rgba(63, 108, 240, 0.4);
  }

  .chart-wrap { height: 172px; }
  .loc h1 { font-size: 21px; }
  .loc p { font-size: 13.5px; }

  .panel-foot {
    display: block;
    margin-top: -4px;
    padding: 0 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.5px;
    color: var(--ink-dim);
  }
  .panel-foot a { color: inherit; text-decoration: none; border-bottom: 1px solid var(--line); }
  .panel-foot a:hover { color: var(--accent); }

  .maplibregl-ctrl-top-right { top: 10px; }
}

/* tall desktop: give the rail's forecast more presence */
@media (min-width: 920px) and (min-height: 900px) {
  .chart-wrap { height: 210px; }
}

/* --------------------------------------------------------------- motion -- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .topbar, .sheet, .panel { opacity: 1 !important; }
}
