/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #e8ecf1;
}

/* ── Full-screen satellite map ────────────────────────────── */
#map {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 0;
}

/* ── Overlay panels ───────────────────────────────────────── */
.panel {
  position: fixed;
  z-index: 1000;
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px 20px;
  color: #e8ecf1;
  pointer-events: auto;
}

/* ── Weather panel (top-left) ─────────────────────────────── */
#weather-panel {
  top: 16px;
  left: 16px;
  min-width: 240px;
  max-width: 300px;
}

/* ── AB Wind Call panel (top-right) ───────────────────────── */
#ab-panel {
  top: 16px;
  right: 16px;
  text-align: center;
  min-width: 160px;
  border: 1px solid rgba(96, 165, 250, 0.25);
}

#ab-avg-panel {
  top: 260px;
  right: 16px;
  text-align: center;
  min-width: 160px;
  border: 1px solid rgba(74, 222, 128, 0.25);
}

.ab-header-avg {
  color: #4ade80 !important;
  border-bottom-color: rgba(74, 222, 128, 0.2) !important;
}

.ab-header {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #60a5fa;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(96, 165, 250, 0.2);
  padding-bottom: 6px;
}

.ab-clock-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}

.ab-clock-value {
  font-size: 3rem;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}

.ab-clock-label {
  font-size: 1rem;
  color: #8892a4;
  font-weight: 500;
}

.ab-speed-row {
  margin-top: 4px;
}

.ab-speed-row span:first-child {
  font-size: 1.8rem;
  font-weight: 700;
  color: #e8ecf1;
}

.ab-speed-unit {
  font-size: 0.8rem;
  color: #8892a4;
  margin-left: 3px;
}

/* Wind 1 / Wind 2 side-by-side */
.ab-winds {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-top: 6px;
}

.ab-wind-col {
  flex: 1;
  text-align: center;
}

.ab-wind-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #8892a4;
  margin-bottom: 2px;
}

.ab-wind-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: #e8ecf1;
  line-height: 1.1;
}

.ab-wind-gust {
  color: #f87171;
}

.ab-wind-sub {
  font-size: 0.55rem;
  color: #555e6e;
  margin-top: 1px;
}

.ab-wind-divider {
  width: 1px;
  height: 36px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0 4px;
}

.ab-component {
  margin-top: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #facc15;
  letter-spacing: 0.05em;
}

.ab-dof {
  margin-top: 8px;
  font-size: 0.65rem;
  color: #555e6e;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 6px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 8px;
}

#station-name {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.muted {
  font-size: 0.72rem;
  color: #8892a4;
}

/* ── Readings grid ────────────────────────────────────────── */
.readings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
}

.reading-group { display: flex; flex-direction: column; gap: 2px; }
.reading-group.wide { grid-column: 1 / -1; }

.reading-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8892a4;
}

.reading-value {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
}

.reading-sub {
  font-size: 0.72rem;
  color: #8892a4;
}

.unit {
  font-size: 0.7rem;
  font-weight: 400;
  color: #8892a4;
  margin-left: 2px;
}

/* ── Pressure trend arrows ────────────────────────────────── */
.trend { font-size: 0.8rem; margin-left: 4px; }
.trend.rising   { color: #4ade80; }
.trend.falling  { color: #f87171; }
.trend.steady   { color: #8892a4; }

/* ── Wind arrow overlay (locked to station on map) ────────── */
.wind-marker {
  background: none !important;
  border: none !important;
}

#wind-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

#wind-arrow-container {
  width: 180px;
  height: 180px;
}

#wind-arrow-svg {
  width: 100%;
  height: 100%;
}

#arrow-group {
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

#wind-speed-label {
  margin-top: -10px;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

#overlay-speed {
  font-size: 2.5rem;
  font-weight: 800;
  color: #fff;
}

.overlay-unit {
  font-size: 1rem;
  font-weight: 400;
  color: #ccc;
  margin-left: 4px;
}

#wind-dir-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: #ccc;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ── Wind color coding (arrow changes color by speed) ───── */
.wind-calm      line, .wind-calm      polygon { stroke: #4ade80; fill: #4ade80; }
.wind-light     line, .wind-light     polygon { stroke: #a3e635; fill: #a3e635; }
.wind-moderate  line, .wind-moderate  polygon { stroke: #facc15; fill: #facc15; }
.wind-fresh     line, .wind-fresh     polygon { stroke: #fb923c; fill: #fb923c; }
.wind-strong    line, .wind-strong    polygon { stroke: #f87171; fill: #f87171; }
.wind-gale      line, .wind-gale      polygon { stroke: #ef4444; fill: #ef4444; }

/* ── 20-min History panel (bottom) ────────────────────────── */
#history-panel {
  bottom: 16px;
  left: 16px;
  right: 16px;
  padding: 12px 16px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.history-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8892a4;
}

.history-stats {
  font-size: 0.72rem;
  color: #8892a4;
}

.hist-value {
  font-weight: 700;
  color: #e8ecf1;
  font-size: 0.82rem;
}

/* ── Timeline with per-minute wind entries ────────────────── */
#history-timeline {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  justify-content: center;
}
#history-timeline::-webkit-scrollbar { display: none; }

.hist-entry {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 48px;
  padding: 4px 2px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.hist-entry.latest {
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.3);
}

.hist-entry-time {
  font-size: 0.55rem;
  color: #555e6e;
  margin-bottom: 2px;
}

.hist-entry-arrow {
  width: 28px;
  height: 28px;
  margin-bottom: 1px;
}

.hist-entry-arrow svg {
  width: 100%;
  height: 100%;
}

.hist-entry-speed {
  font-size: 0.82rem;
  font-weight: 700;
  color: #e8ecf1;
  line-height: 1;
}

.hist-entry-gust {
  font-size: 0.6rem;
  color: #f87171;
  line-height: 1;
  margin-top: 1px;
}

.hist-entry-dir {
  font-size: 0.55rem;
  color: #8892a4;
  margin-top: 1px;
}

.hist-entry-clock {
  font-size: 0.55rem;
  color: #facc15;
  font-weight: 600;
  margin-top: 1px;
}

.hist-entry-empty {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 90px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.05);
  color: #333;
  font-size: 0.6rem;
}

/* ── Speed-based arrow colors in history ──────────────────── */
.arrow-calm     { color: #4ade80; }
.arrow-light    { color: #a3e635; }
.arrow-moderate { color: #facc15; }
.arrow-fresh    { color: #fb923c; }
.arrow-strong   { color: #f87171; }
.arrow-gale     { color: #ef4444; }

/* ── Tablet tweaks ────────────────────────────────────────── */
@media (max-width: 820px) {
  #weather-panel {
    top: 8px;
    left: 8px;
    min-width: 200px;
    max-width: 260px;
    padding: 12px 14px;
  }

  .reading-value { font-size: 1.1rem; }

  #wind-arrow-container { width: 150px; height: 150px; }
  #overlay-speed { font-size: 2rem; }

  #history-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 10px 12px;
  }

  .hist-entry { min-width: 42px; }
  .hist-entry-arrow { width: 24px; height: 24px; }
}

/* ── Mobile phone layout ──────────────────────────────────── */
@media (max-width: 480px) {

  /* ── Weather panel: thin strip across top ───────────────── */
  #weather-panel {
    top: 4px;
    left: 4px;
    right: 4px;
    max-width: none;
    min-width: 0;
    padding: 6px 10px;
    border-radius: 8px;
  }

  .panel-header {
    margin-bottom: 4px;
    padding-bottom: 3px;
  }

  #station-name { font-size: 0.75rem; }
  .muted { font-size: 0.6rem; }

  .readings {
    grid-template-columns: repeat(5, 1fr);
    gap: 2px 6px;
  }

  /* Wind reading spans 1 col on mobile like everything else */
  .reading-group.wide { grid-column: span 1; }
  .reading-group { gap: 0; }
  .reading-label { font-size: 0.48rem; }
  .reading-value { font-size: 0.78rem; line-height: 1.1; }
  .reading-sub { font-size: 0.5rem; display: none; }
  .unit { font-size: 0.48rem; }

  /* ── AB panels: ultra-compact, side-by-side at bottom ──── */
  #ab-panel,
  #ab-avg-panel {
    top: auto;
    right: auto;
    left: auto;
    position: fixed;
    min-width: 0;
    padding: 5px 4px 4px;
    border-radius: 8px;
  }

  #ab-panel {
    bottom: 96px;
    left: 4px;
    right: calc(50% + 2px);
  }

  #ab-avg-panel {
    bottom: 96px;
    left: calc(50% + 2px);
    right: 4px;
  }

  .ab-header {
    font-size: 0.42rem;
    letter-spacing: 0.06em;
    margin-bottom: 2px;
    padding-bottom: 2px;
  }

  .ab-clock-row { gap: 3px; }

  .ab-clock-value {
    font-size: 1.4rem;
  }

  .ab-clock-label {
    font-size: 0.55rem;
  }

  .ab-winds {
    margin-top: 2px;
  }

  .ab-wind-label { font-size: 0.42rem; }
  .ab-wind-value { font-size: 0.85rem; }
  .ab-wind-sub { font-size: 0.38rem; }

  .ab-wind-divider {
    height: 18px;
    margin: 0 2px;
  }

  .ab-component {
    font-size: 0.55rem;
    margin-top: 2px;
  }

  /* Hide DOF line on mobile — not needed at a glance */
  .ab-dof {
    display: none;
  }

  /* ── Wind arrow overlay: smaller on mobile ──────────────── */
  #wind-arrow-container { width: 100px; height: 100px; }
  #overlay-speed { font-size: 1.4rem; }
  .overlay-unit { font-size: 0.6rem; }
  #wind-dir-text { font-size: 0.75rem; }
  #wind-speed-label { margin-top: -4px; }

  /* ── History panel: thin strip at very bottom ──────────── */
  #history-panel {
    left: 4px;
    right: 4px;
    bottom: 4px;
    padding: 4px 6px;
    max-height: 88px;
    overflow-y: auto;
    border-radius: 8px;
  }

  .history-header { margin-bottom: 3px; }
  .history-title { font-size: 0.52rem; }
  .history-stats { font-size: 0.48rem; }
  .hist-value { font-size: 0.58rem; }

  .hist-entry {
    min-width: 30px;
    padding: 2px 1px;
    border-radius: 4px;
  }

  .hist-entry-arrow { width: 16px; height: 16px; }
  .hist-entry-speed { font-size: 0.58rem; }
  .hist-entry-gust { font-size: 0.42rem; }
  .hist-entry-dir { font-size: 0.4rem; }
  .hist-entry-clock { font-size: 0.4rem; }
  .hist-entry-time { font-size: 0.4rem; }

  .hist-entry-empty {
    min-width: 30px;
    height: 55px;
    font-size: 0.42rem;
  }

  /* ── Leaflet controls: hidden on phone ─────────────────── */
  .leaflet-control-zoom {
    display: none;
  }
}

/* ── Hide Leaflet attribution on tablet ───────────────────── */
.leaflet-control-attribution {
  font-size: 8px !important;
  opacity: 0.5;
}

/* ── Main page quick nav links ───────────────────────────── */
.main-nav-links {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  gap: 8px;
}

.main-nav-link {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: rgba(10, 14, 23, 0.85);
  color: #60a5fa;
  font-size: 12px;
  text-decoration: none;
}

.main-nav-select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: rgba(10, 14, 23, 0.85);
  color: #60a5fa;
  font-size: 12px;
}

.main-nav-select-label {
  color: #60a5fa;
}

.main-nav-select {
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: rgba(15, 20, 32, 0.95);
  color: #e8ecf1;
  border-radius: 6px;
  font-size: 12px;
  padding: 2px 6px;
}

/* ── BLE button in nav ── */
.ble-nav-btn {
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: rgba(15, 20, 32, 0.95);
  cursor: pointer;
  font-size: 12px;
}
.ble-nav-btn.connected {
  border-color: rgba(74, 222, 128, 0.5);
  color: #4ade80;
}
.ble-nav-btn.disconnected {
  border-color: rgba(248, 113, 113, 0.4);
}

/* ── BLE status banner ── */
#ble-banner {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  background: rgba(15, 20, 32, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(74, 222, 128, 0.3);
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 0.72rem;
  color: #4ade80;
  display: none;
  gap: 6px;
  align-items: center;
}
#ble-banner.show { display: flex; }
#ble-banner .ble-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  animation: ble-pulse 1.5s infinite;
}
@keyframes ble-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
