/* ============================================================================
   CanopyFlow — Student Pattern Planner
   Presentation layer, rebuilt as a single coherent Apple-HIG design system.

   Architecture
     1.  Design tokens        — semantic --ui-* palette (light / dark / auto)
     2.  Base & typography
     3.  Map chrome           — MapLibre, markers, route overlays
     4.  Inspector shell      — controls column, nav, sheet, drawer handle
     5.  Cards & controls     — panels, buttons, inputs, switches, sliders
     6.  Wind section         — instruments, readout, tier grid
     7.  Pattern / Canopy / Brief sections
     8.  Floating map chrome  — DZ / recenter / GPS / more, menus, legend
     9.  Overlays             — DZ picker, modals, welcome, terms, focus, toast
     10. Layout breakpoints   — ≤699 compact · 700–1099 medium · ≥1100 expanded
     11. Accessibility media  — reduced motion / transparency / forced colors

   Contracts enforced by tests/theme-css.test.mjs and tests/ui-shell.test.mjs:
     · glass (backdrop-filter) only on the floating chrome whitelist
     · every letter-spacing declaration is exactly 0
     · 44px minimum touch targets
     · exact sheet snap heights (112px / 54dvh / 100dvh − 72px)
     · exact breakpoint set (699 / 700–1099 / 1100 / 1600)
   ========================================================================== */

/* ============================== 1. TOKENS ================================ */

:root {
  color-scheme: light;

  /* Surfaces & labels — iOS system palette */
  --ui-background: #f2f2f7;
  --ui-surface-base: #ffffff;
  --ui-surface-elevated: #ffffff;
  --ui-label-primary: #1d1d1f;
  --ui-label-secondary: #6e6e73;
  --ui-label-tertiary: #aeaeb2;
  --ui-separator: rgba(60, 60, 67, 0.14);
  --ui-separator-strong: rgba(60, 60, 67, 0.24);

  /* Tint & semantics */
  --ui-accent: #007aff;
  --ui-action: #0066cc;          /* solid fills that carry white text (AA) */
  --ui-danger: #ff3b30;
  --ui-danger-action: #c5221f;   /* solid destructive fill (AA on white)   */
  --ui-warning: #ff9500;
  --ui-success: #34c759;

  /* Fills (translucent grays that work on any surface) */
  --ui-fill: rgba(120, 120, 128, 0.10);
  --ui-fill-strong: rgba(120, 120, 128, 0.18);
  --ui-accent-fill: rgba(0, 122, 255, 0.12);
  --ui-danger-fill: rgba(255, 59, 48, 0.12);
  --ui-warning-fill: rgba(255, 149, 0, 0.14);

  /* Materials */
  --ui-glass: rgba(249, 249, 251, 0.72);
  --ui-overlay: rgba(0, 0, 0, 0.45);
  --ui-focus-ring: rgba(0, 122, 255, 0.48);

  /* Instrument dials (compass / windsock wells) */
  --dial-face: #ffffff;
  --dial-well: rgba(120, 120, 128, 0.08);
  --dial-ring: rgba(60, 60, 67, 0.12);
  --dial-tick: rgba(60, 60, 67, 0.28);
  --dial-label: #6e6e73;

  /* Geometry */
  --radius-xs: 8px;
  --radius-sm: 11px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;

  /* Elevation — layered key + ambient shadows */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 14px rgba(0, 0, 0, 0.07);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.07), 0 12px 32px rgba(0, 0, 0, 0.12);
  --shadow-3: 0 8px 20px rgba(0, 0, 0, 0.13), 0 28px 68px rgba(0, 0, 0, 0.18);

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-fast: 150ms;
  --dur-med: 280ms;
  --dur-slow: 420ms;

  /* Compatibility aliases — inline styles and JS-injected markup use these */
  --bg: var(--ui-background);
  --panel: var(--ui-surface-base);
  --panel-border: var(--ui-separator);
  --text: var(--ui-label-primary);
  --muted: var(--ui-label-secondary);
  --accent: var(--ui-accent);
  --accent-dark: var(--ui-action);
  --green: #248a3d;
  --red: var(--ui-danger);
  --ring: var(--ui-focus-ring);
}

:root[data-theme="light"] {
  color-scheme: light;
  --ui-background: #f2f2f7;
  --ui-surface-base: #ffffff;
  --ui-surface-elevated: #ffffff;
  --ui-label-primary: #1d1d1f;
  --ui-label-secondary: #6e6e73;
  --ui-label-tertiary: #aeaeb2;
  --ui-separator: rgba(60, 60, 67, 0.14);
  --ui-separator-strong: rgba(60, 60, 67, 0.24);
  --ui-accent: #007aff;
  --ui-action: #0066cc;
  --ui-danger: #ff3b30;
  --ui-danger-action: #c5221f;
  --ui-warning: #ff9500;
  --ui-success: #34c759;
  --ui-fill: rgba(120, 120, 128, 0.10);
  --ui-fill-strong: rgba(120, 120, 128, 0.18);
  --ui-accent-fill: rgba(0, 122, 255, 0.12);
  --ui-danger-fill: rgba(255, 59, 48, 0.12);
  --ui-warning-fill: rgba(255, 149, 0, 0.14);
  --ui-glass: rgba(249, 249, 251, 0.72);
  --ui-overlay: rgba(0, 0, 0, 0.45);
  --ui-focus-ring: rgba(0, 122, 255, 0.48);
  --dial-face: #ffffff;
  --dial-well: rgba(120, 120, 128, 0.08);
  --dial-ring: rgba(60, 60, 67, 0.12);
  --dial-tick: rgba(60, 60, 67, 0.28);
  --dial-label: #6e6e73;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 14px rgba(0, 0, 0, 0.07);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.07), 0 12px 32px rgba(0, 0, 0, 0.12);
  --shadow-3: 0 8px 20px rgba(0, 0, 0, 0.13), 0 28px 68px rgba(0, 0, 0, 0.18);
  --green: #248a3d;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ui-background: #000000;
  --ui-surface-base: #1c1c1e;
  --ui-surface-elevated: #2c2c2e;
  --ui-label-primary: #f5f5f7;
  --ui-label-secondary: #98989d;
  --ui-label-tertiary: #636366;
  --ui-separator: rgba(84, 84, 88, 0.55);
  --ui-separator-strong: rgba(84, 84, 88, 0.80);
  --ui-accent: #0a84ff;
  --ui-action: #0066cc;
  --ui-danger: #ff453a;
  --ui-danger-action: #c5221f;
  --ui-warning: #ff9f0a;
  --ui-success: #30d158;
  --ui-fill: rgba(120, 120, 128, 0.22);
  --ui-fill-strong: rgba(120, 120, 128, 0.34);
  --ui-accent-fill: rgba(10, 132, 255, 0.22);
  --ui-danger-fill: rgba(255, 69, 58, 0.22);
  --ui-warning-fill: rgba(255, 159, 10, 0.22);
  --ui-glass: rgba(24, 24, 26, 0.68);
  --ui-overlay: rgba(0, 0, 0, 0.62);
  --ui-focus-ring: rgba(10, 132, 255, 0.58);
  --dial-face: #2c2c2e;
  --dial-well: rgba(120, 120, 128, 0.16);
  --dial-ring: rgba(255, 255, 255, 0.10);
  --dial-tick: rgba(235, 235, 245, 0.28);
  --dial-label: #98989d;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.30), 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.35), 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 8px 20px rgba(0, 0, 0, 0.45), 0 28px 68px rgba(0, 0, 0, 0.60);
  --green: #30d158;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --ui-background: #000000;
    --ui-surface-base: #1c1c1e;
    --ui-surface-elevated: #2c2c2e;
    --ui-label-primary: #f5f5f7;
    --ui-label-secondary: #98989d;
    --ui-label-tertiary: #636366;
    --ui-separator: rgba(84, 84, 88, 0.55);
    --ui-separator-strong: rgba(84, 84, 88, 0.80);
    --ui-accent: #0a84ff;
    --ui-action: #0066cc;
    --ui-danger: #ff453a;
    --ui-danger-action: #c5221f;
    --ui-warning: #ff9f0a;
    --ui-success: #30d158;
    --ui-fill: rgba(120, 120, 128, 0.22);
    --ui-fill-strong: rgba(120, 120, 128, 0.34);
    --ui-accent-fill: rgba(10, 132, 255, 0.22);
    --ui-danger-fill: rgba(255, 69, 58, 0.22);
    --ui-warning-fill: rgba(255, 159, 10, 0.22);
    --ui-glass: rgba(24, 24, 26, 0.68);
    --ui-overlay: rgba(0, 0, 0, 0.62);
    --ui-focus-ring: rgba(10, 132, 255, 0.58);
    --dial-face: #2c2c2e;
    --dial-well: rgba(120, 120, 128, 0.16);
    --dial-ring: rgba(255, 255, 255, 0.10);
    --dial-tick: rgba(235, 235, 245, 0.28);
    --dial-label: #98989d;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.30), 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.35), 0 12px 32px rgba(0, 0, 0, 0.45);
    --shadow-3: 0 8px 20px rgba(0, 0, 0, 0.45), 0 28px 68px rgba(0, 0, 0, 0.60);
    --green: #30d158;
  }
}

/* ==================== 1b. HUD SCOPE — smoked-glass chrome ================= */
/* Everything that floats over the map imagery is aviation-HUD chrome: always
   smoked glass with light-on-dark labels, in BOTH appearances (like Apple
   Maps' satellite controls or the Camera app). Content-reading surfaces
   (welcome, terms, DZ picker, alert dialogs) keep following the theme.
   Implemented by re-scoping the semantic tokens — component rules keep
   referencing the same var() names, so the theme contract stays intact. */
.controls-column,
.dz-picker,
.banners,
.pattern-legend,
.more-menu,
.focus-overlay,
.windy-panel,
.info,
.toast,
.app-update-notice,
.wind-chip,
.home-btn,
.locate-btn,
.recenter-btn,
.map-mode-btn,
.map-north-btn,
.more-menu-btn {
  color-scheme: dark;
  --ui-surface-base: rgba(255, 255, 255, 0.05);
  --ui-surface-elevated: rgba(34, 36, 44, 0.96);
  --ui-label-primary: #f5f5f7;
  --ui-label-secondary: rgba(235, 235, 245, 0.62);
  --ui-label-tertiary: rgba(235, 235, 245, 0.34);
  --ui-separator: rgba(255, 255, 255, 0.13);
  --ui-separator-strong: rgba(255, 255, 255, 0.24);
  --ui-accent: #0a84ff;
  --ui-accent-fill: rgba(10, 132, 255, 0.32);
  --ui-danger: #ff6961;
  --ui-danger-fill: rgba(255, 105, 97, 0.26);
  --ui-warning: #ffd60a;
  --ui-warning-fill: rgba(255, 214, 10, 0.20);
  --ui-success: #30d158;
  --ui-fill: rgba(255, 255, 255, 0.10);
  --ui-fill-strong: rgba(255, 255, 255, 0.20);
  --ui-glass: rgba(16, 18, 25, 0.60);
  --ui-focus-ring: rgba(10, 132, 255, 0.70);
  --dial-face: transparent;
  --dial-well: transparent;
  --dial-ring: rgba(255, 255, 255, 0.22);
  --dial-tick: rgba(255, 255, 255, 0.38);
  --dial-label: rgba(235, 235, 245, 0.66);
}

/* ============================ 2. BASE ===================================== */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ui-background);
  color: var(--ui-label-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
input, select, textarea { font-family: inherit; }

/* Touch targets — 44pt HIG minimum */
button,
[role="button"] { min-height: 44px; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select { min-height: 44px; }

/* Press feedback — subtle scale, the iOS "squish" */
button:active { transform: scale(0.97); }
button { transition: background var(--dur-fast) ease, color var(--dur-fast) ease,
  border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease,
  opacity var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out); }

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
.drawer-handle:focus-visible {
  outline: 3px solid var(--ui-focus-ring);
  outline-offset: 2px;
}

.hidden { display: none !important; }

/* Numeric data never jitters */
.wind-readout, .wind-spd, .status-item, .brief-grid dd, .canopy-diagnostics,
.speed-slider-readout, .sheet-peek-summary, .focus-title .alt, .wingload-line b,
.canopy-readout, .update-date {
  font-variant-numeric: tabular-nums;
}

/* ============================ 3. MAP CHROME =============================== */

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #0b0e13; /* satellite imagery backdrop — identical in both themes */
}
#map img, #map canvas { filter: none; }
.maplibregl-map { background: #0b0e13; outline: none; }

.maplibregl-ctrl-attrib {
  background: rgba(0, 0, 0, 0.45) !important;
  color: rgba(255, 255, 255, 0.55) !important;
  font-size: 9px !important;
  padding: 1px 6px !important;
  border-radius: 6px 0 0 0;
}
.maplibregl-ctrl-attrib a { color: rgba(255, 255, 255, 0.70) !important; }

.landing-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: grab;
}
.landing-icon:active { cursor: grabbing; }
body[data-map-mode="3d"] .landing-icon { display: none; }

/* Waypoint altitude labels — white with heavy shadow so they read on terrain */
.wp-label {
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  text-align: center;
  text-shadow:
    0 0 3px rgba(0, 0, 0, 0.95),
    0 1px 3px rgba(0, 0, 0, 0.95),
    0 0 8px rgba(0, 0, 0, 0.55);
}
.wp-label.focused {
  color: #ffd60a;
  text-shadow:
    0 0 3px rgba(0, 0, 0, 0.95),
    0 1px 3px rgba(0, 0, 0, 0.95),
    0 0 10px rgba(255, 214, 10, 0.55);
}
.wp-label { width: 92px; height: 34px; pointer-events: none; }
body[data-map-mode="3d"] .wp-label,
body[data-map-mode="3d"] .leg-arrow {
  visibility: hidden;
  opacity: 0;
}

.leg-arrow { width: 26px; height: 26px; pointer-events: none; }
.leg-arrow svg { width: 100%; height: 100%; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)); }

/* Route hit path is editable only in 2D; 3D gestures always manipulate the camera. */
body[data-map-mode="2d"][data-interaction="edit"] #map { cursor: crosshair; }
body[data-map-mode="3d"] #map { cursor: grab; }
body[data-map-mode="3d"] #map .maplibregl-canvas:active { cursor: grabbing; }
#map canvas.dragging { cursor: grabbing !important; }

/* User location puck — blue dot with halo and heading cone */
.user-puck { pointer-events: none; position: relative; }
.user-halo {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 72px; height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(0, 122, 255, 0.28) 0%,
    rgba(0, 122, 255, 0.18) 45%,
    rgba(0, 122, 255, 0) 72%);
  animation: user-halo-pulse 2.5s ease-in-out infinite;
}
@keyframes user-halo-pulse {
  0%, 100% { opacity: 0.55; transform: translate(-50%, -50%) scale(1); }
  50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.08); }
}
.user-heading {
  position: absolute;
  top: 50%; left: 50%;
  width: 0; height: 0;
  transform-origin: 50% 50%;
  transform: translate(-50%, -50%) rotate(var(--user-heading, 0deg));
  transition: transform 0.2s ease-out;
}
.user-heading::before {
  content: "";
  position: absolute;
  left: -55px; top: -90px;
  width: 110px; height: 90px;
  background: radial-gradient(ellipse 80% 100% at 50% 100%,
    rgba(0, 122, 255, 0.85) 0%,
    rgba(0, 122, 255, 0.45) 40%,
    rgba(0, 122, 255, 0.18) 70%,
    rgba(0, 122, 255, 0) 100%);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}
.user-puck.no-heading .user-heading { display: none; }
.user-ring {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.user-dot { width: 14px; height: 14px; border-radius: 50%; background: #007aff; }

/* ======================== 4. INSPECTOR SHELL ============================== */

.controls-column {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  width: 340px;
  max-height: calc(100dvh - 32px);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(28, 31, 40, 0.90), rgba(14, 16, 22, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-xl);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), var(--shadow-3);
}
.controls-column.dragging { transition: none !important; }

/* Drag grabber — hidden on expanded desktop, shown on medium & compact */
.drawer-handle {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 20px 4px;
  background: transparent;
  border: none;
  cursor: grab;
  width: 100%;
  flex: 0 0 auto;
  touch-action: none; /* the handle owns the sheet drag gesture */
}
.drawer-handle:active { cursor: grabbing; transform: none; }
.drawer-handle-grip {
  width: 36px;
  height: 5px;
  border-radius: 999px;
  background: var(--ui-fill-strong);
  display: block;
  transition: background var(--dur-fast) ease;
}
.drawer-handle:hover .drawer-handle-grip { background: var(--ui-label-tertiary); }
.drawer-handle-lbl { display: none; }

/* Stack header — Apple-Maps search-bar form for choosing the dropzone */
.stack-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--ui-separator);
}
.stack-dz {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  text-align: left;
}
.stack-dz:hover { background: var(--ui-fill-strong); }
.stack-dz-pin {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--ui-label-secondary);
  stroke-width: 2;
}
.stack-dz-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15.5px;
  font-weight: 600;
}

/* Section tab bar — Find-My-style paging pinned to the panel bottom:
   icon over label, the active tab simply tints accent blue. */
.section-tabbar {
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
  padding: 5px 10px 7px;
  border-top: 1px solid var(--ui-separator);
}
.control-nav-item {
  flex: 1 1 0;
  min-width: 0;
  min-height: 50px;
  padding: 5px 4px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ui-label-secondary);
  font-size: 10.5px;
  font-weight: 600;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}
.control-nav-item svg {
  width: 23px;
  height: 23px;
  display: block;
  flex: 0 0 auto;
  stroke-width: 1.8;
}
.control-nav-item:hover { color: var(--ui-label-primary); }
.control-nav-item.active { color: var(--ui-accent); }

/* Scrollable content region */
.panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--ui-fill-strong) transparent;
}

/* Section pages — exactly one visible, switched by the bottom tab bar */
.control-section {
  display: grid;
  gap: 0;
  padding: 0 0 6px;
}
.control-section[hidden] { display: none !important; }
.control-section.active {
  animation: page-in var(--dur-med) var(--ease-out);
}
@keyframes page-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Peek summary — glanceable wind line, visible only in compact peek state */
.sheet-peek-summary {
  display: none;
  align-items: baseline;
  justify-content: center;
  flex-wrap: nowrap;
  overflow: hidden;
  padding: 2px 20px 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ui-label-primary);
  white-space: nowrap;
}
.sheet-peek-summary .sep { color: var(--ui-label-tertiary); margin: 0 7px; font-weight: 400; }
.sheet-peek-summary .tag { color: var(--ui-accent); font-weight: 750; }
.sheet-peek-summary .peek-age { color: var(--ui-label-secondary); font-weight: 450; font-size: 13px; }
.sheet-peek-summary:has(.peek-age:empty) .peek-age-sep { display: none; }

/* ======================== 6. CARDS & CONTROLS ============================= */

/* Panels dissolve into one continuous glass sheet, grouped by hairlines */
.panel {
  position: relative;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 16px 18px;
  box-shadow: none;
}
.control-section .panel + .panel { border-top: 1px solid var(--ui-separator); }
.control-section .panel,
.control-section .top-row > .panel {
  position: relative !important;
  inset: auto !important;
  width: 100% !important;
}
/* Hero-first: Current Wind leads the feed, the tier setter follows */
.top-row { display: flex; flex-direction: column; gap: 0; }
.top-row > .panel.wind { order: 1; border-top: 0; }
.top-row > .panel.speed-tier { order: 2; border-top: 1px solid var(--ui-separator); }

.panel .title {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  color: var(--ui-label-tertiary);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
}

/* --- Filled / tinted / plain buttons ------------------------------------- */
.btn-primary {
  background: var(--ui-action);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 650;
  width: 100%;
}
.btn-primary:hover { background: color-mix(in srgb, var(--ui-action) 88%, black); }

/* --- Text inputs ---------------------------------------------------------- */
.canopy-field input,
.pattern-altitude-field input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ui-separator);
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  font-size: 16px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease,
    background var(--dur-fast) ease;
}
.canopy-field input:focus,
.pattern-altitude-field input:focus {
  border-color: var(--ui-accent);
  background: var(--ui-surface-base);
  box-shadow: 0 0 0 3px var(--ui-accent-fill);
}
.pattern-altitude-field input { text-align: center; }
.canopy-field input::-webkit-outer-spin-button,
.canopy-field input::-webkit-inner-spin-button { margin: 0; }

/* --- iOS switch ------------------------------------------------------------ */
.pattern-switch {
  appearance: none;
  -webkit-appearance: none;
  width: 50px;
  min-width: 50px;
  height: 30px;
  min-height: 30px;
  border-radius: 999px;
  background: var(--ui-fill-strong);
  border: none;
  position: relative;
  flex: 0 0 auto;
  cursor: pointer;
  transition: background var(--dur-med) ease;
  margin: 0;
}
.pattern-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
  transition: transform var(--dur-med) var(--ease-spring);
}
.pattern-switch:checked { background: var(--ui-success); }
.pattern-switch:checked::after { transform: translateX(20px); }

/* --- Option row (label + switch) ------------------------------------------ */
.pattern-option {
  margin-top: 8px;
  min-height: 44px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ui-label-primary);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

/* ========================= 7. WIND SECTION ================================ */

/* Card grid: title / instruments / readout+action / source */
.panel.wind {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto auto;
  gap: 0 10px;
  align-content: start;
}
.panel.wind .title        { grid-column: 1 / -1; grid-row: 1; }
.panel.wind .wind-visuals { grid-column: 1 / -1; grid-row: 2; }
.panel.wind .wind-readout { grid-column: 1; grid-row: 3; }
.panel.wind .wind-actions { grid-column: 2; grid-row: 3; align-self: end; justify-self: end; }
.panel.wind .wind-source  { grid-column: 1 / -1; grid-row: 4; }

/* Instrument wells */
.wind-visuals {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: stretch;
  margin: 0 0 12px;
}
/* Bare instruments — no boxed wells, they float straight on the glass */
.windsock-box {
  order: 1;
  flex: 1 1 auto;
  min-width: 0;
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  background: none;
  border: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
}
.windsock-svg { max-width: 100%; height: 100%; width: auto; transition: opacity var(--dur-med) ease; }

.compass {
  order: 2;
  width: 112px;
  height: 112px;
  flex: none;
  padding: 2px;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.compass:active { cursor: grabbing; }
/* The wind needle glows like a HUD element */
#compass-arrow { filter: drop-shadow(0 0 6px rgba(255, 45, 45, 0.55)); }

/* Readout — FROM · big cardinal · pill, numbers underneath */
.wind-readout {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-width: 0;
}
.wind-dir { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.wind-dir .from-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-label-secondary);
  text-transform: uppercase;
  margin: 0 0 4px;
}
.wind-dir .cardinal-row { display: flex; align-items: center; gap: 10px; }
.wind-dir .cardinal {
  font-size: 64px;
  font-weight: 300;
  line-height: 1;
  color: var(--ui-label-primary);
}
.wind-spd {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  font-size: 14px;
  color: var(--ui-label-secondary);
  margin-top: 10px;
}
.wind-spd .wind-nums { white-space: nowrap; flex-shrink: 0; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 750;
  line-height: 1.4;
}
.pill-live   { background: var(--ui-accent-fill); color: var(--ui-accent); }
.pill-manual { background: var(--ui-danger-fill); color: var(--ui-danger); }

.tier-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  background: var(--ui-accent-fill);
  color: var(--ui-accent);
  white-space: nowrap;
}

.wind-source {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--ui-separator);
  font-size: 11px;
  color: var(--ui-label-secondary);
  line-height: 1.5;
  min-width: 0;
}

/* Refresh — tinted icon button */
.wind-actions { display: flex; gap: 6px; }
.wind-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--ui-accent-fill);
  color: var(--ui-accent);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.wind-actions button:hover { background: var(--ui-fill-strong); color: var(--ui-accent); }
.wind-actions button svg { width: 16px; height: 16px; flex: 0 0 auto; }
/* Manual toggle stays retired — the compass drag and tier buttons cover it */
.panel.wind #toggle-override { display: none !important; }

/* --- Wind Setting: tier grid + slider -------------------------------------- */
.speed-tier { display: flex; flex-direction: column; }
.speed-tier-body { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }

.tier-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.speed-btn {
  min-height: 52px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.25;
}
.speed-btn .range {
  font-size: 10px;
  color: var(--ui-label-secondary);
  font-weight: 450;
  margin-top: 2px;
}
.speed-btn:hover { background: var(--ui-fill-strong); }
.speed-btn.active {
  background: rgba(255, 255, 255, 0.94);
  color: #16181d;
  border-color: transparent;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.speed-btn.active .range { color: rgba(22, 24, 29, 0.60); }

/* Slider row */
.speed-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px 0;
}
.speed-slider-end {
  font-size: 11px;
  color: var(--ui-label-tertiary);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  flex: 0 0 auto;
}
.speed-slider-readout {
  font-size: 12px;
  font-weight: 700;
  color: var(--ui-accent);
  line-height: 1;
  white-space: nowrap;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.speed-slider-readout small { font-size: 9px; font-weight: 500; color: var(--ui-label-secondary); }
.speed-slider-readout #slider-kt {
  display: inline-block;
  min-width: 2.4em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"].speed-slider {
  --slider-pct: 0%;
  --slider-fill: var(--ui-accent);
  --slider-fill-soft: var(--ui-accent-fill);
  --slider-empty: var(--ui-fill-strong);
  flex: 1 1 auto;
  min-width: 0;
  height: 28px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: ew-resize;
  -webkit-appearance: none;
  appearance: none;
  touch-action: pan-x;
  pointer-events: auto;
  accent-color: var(--ui-accent);
}
input[type="range"].speed-slider::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(to right,
    var(--slider-fill) 0%,
    var(--slider-fill) var(--slider-pct),
    var(--slider-empty) var(--slider-pct),
    var(--slider-empty) 100%);
}
input[type="range"].speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8.5px;
  border-radius: 50%;
  background: #ffffff;
  border: 0.5px solid rgba(0, 0, 0, 0.04);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18), 0 1px 2px rgba(0, 0, 0, 0.20);
  cursor: ew-resize;
}
input[type="range"].speed-slider::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  border: none;
  background: var(--slider-empty);
}
input[type="range"].speed-slider::-moz-range-progress {
  height: 5px;
  border-radius: 3px;
  background: var(--slider-fill);
}
input[type="range"].speed-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: none;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18), 0 1px 2px rgba(0, 0, 0, 0.20);
  cursor: ew-resize;
}

/* ================== 7. PATTERN / CANOPY / BRIEF SECTIONS ================== */

.pattern-buttons { display: flex; gap: 8px; }
.pattern-btn {
  flex: 1;
  min-height: 52px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1.25;
}
.pattern-btn:hover { background: var(--ui-fill-strong); }
.pattern-btn.active {
  background: rgba(255, 255, 255, 0.94);
  color: #16181d;
  border-color: transparent;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.pattern-btn .ind {
  width: 20px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.pattern-btn .ind svg { width: 100%; height: 100%; }
/* Tailwind conflict — the active side goes solid red */
.pattern.tailwind-conflict .pattern-btn.active {
  background: var(--ui-danger-action);
  border-color: var(--ui-danger-action);
  color: #ffffff;
}

/* Altitude inputs */
.alt-step-panel { display: flex; flex-direction: column; }
.pattern-altitude-inputs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.pattern-altitude-field { display: flex; flex-direction: column; gap: 6px; }
.pattern-altitude-field label {
  color: var(--ui-label-secondary);
  font-size: 11px;
  font-weight: 600;
}

/* Canopy card */
.canopy-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}
.canopy-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.canopy-field label {
  font-size: 11px;
  color: var(--ui-label-secondary);
  font-weight: 600;
  text-transform: uppercase;
}
.wingload-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--ui-separator);
  color: var(--ui-label-secondary);
  font-size: 13px;
}
.wingload-line b {
  color: var(--ui-label-primary);
  font-size: 20px;
  font-weight: 750;
}
.wingload-line small { color: var(--ui-label-secondary); font-size: 11px; }
.wingload-note {
  margin-top: 4px;
  font-size: 11px;
  color: var(--ui-label-secondary);
  line-height: 1.45;
}

.canopy-diagnostics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 14px;
  margin-top: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--ui-separator);
  border-bottom: 1px solid var(--ui-separator);
}
.canopy-diagnostics > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  color: var(--ui-label-secondary);
  font-size: 11px;
}
.canopy-diagnostics > div:last-child { grid-column: 1 / -1; }
.canopy-diagnostics b {
  color: var(--ui-label-primary);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.canopy-readout {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--ui-label-secondary);
}
.canopy-readout b { color: var(--ui-label-primary); font-weight: 650; }
.canopy-readout .models { font-size: 11px; margin-top: 2px; }

/* Brief summary */
.brief-grid { display: grid; gap: 0; margin: 0; }
.brief-grid > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--ui-separator);
}
.brief-grid > div:last-of-type { border-bottom: none; }
.brief-grid dt { color: var(--ui-label-secondary); font-size: 12px; }
.brief-grid dd {
  margin: 0;
  color: var(--ui-label-primary);
  font-size: 13px;
  font-weight: 650;
  text-align: right;
}
.brief-alert {
  margin-top: 8px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
  color: var(--ui-label-secondary);
  font-size: 12px;
  line-height: 1.45;
}
.brief-alert.has-alert {
  background: var(--ui-warning-fill);
  color: var(--ui-label-primary);
  border-left: 3px solid var(--ui-warning);
}

/* Appearance — segmented control */
.appearance-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  margin-top: 12px;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
}
.appearance-control button {
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ui-label-secondary);
  font-size: 12px;
  font-weight: 600;
}
.appearance-control button:hover { color: var(--ui-label-primary); }
.appearance-control button[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.94);
  color: #16181d;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.creator-entry {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 58px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  text-align: left;
  transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease,
    transform var(--dur-fast) var(--ease-out);
}
.creator-entry:hover {
  background: var(--ui-fill-strong);
  border-color: var(--ui-separator-strong);
}
.creator-entry:active { transform: scale(0.99); }
.creator-entry-avatar,
.creator-avatar {
  display: block;
  flex: none;
  border-radius: 50%;
  background: #0a78c8;
  object-fit: cover;
  object-position: center;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ui-separator-strong) 72%, transparent);
}
.creator-entry-avatar {
  width: 36px;
  height: 36px;
}
.creator-entry-copy,
.creator-link-copy {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}
.creator-entry-copy strong,
.creator-link-copy strong {
  color: var(--ui-label-primary);
  font-size: 13px;
  font-weight: 700;
}
.creator-entry-copy small,
.creator-link-copy small {
  overflow: hidden;
  color: var(--ui-label-secondary);
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.creator-entry-arrow {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--ui-label-tertiary);
}

/* Share — plain container inside the Brief section */
.panel.actions {
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
}

/* ===================== 9. FLOATING MAP CHROME ============================= */

:root { --sheet-h: 54dvh; }

.home-btn, .locate-btn, .recenter-btn, .map-mode-btn, .map-north-btn, .more-menu-btn {
  display: inline-flex;
  position: absolute;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--ui-separator);
  background: var(--ui-glass);
  color: var(--ui-label-primary);
  box-shadow: var(--shadow-1);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  cursor: pointer;
  z-index: 450;
  transition: bottom var(--dur-med) var(--ease-spring),
    background var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
}
.home-btn:hover, .locate-btn:hover, .recenter-btn:hover,
.map-mode-btn:hover, .map-north-btn:hover, .more-menu-btn:hover {
  background: var(--ui-surface-elevated);
}
.home-btn svg, .locate-btn svg, .recenter-btn svg,
.map-mode-btn svg, .map-north-btn svg, .more-menu-btn svg {
  width: 19px;
  height: 19px;
  display: block;
}
/* The DZ pill is retired — the stack header carries the dropzone entry now */
.home-btn { display: none !important; }
/* Recenter + GPS fuse into one Apple-Maps-style vertical pill; ⋯ floats above */
.recenter-btn { bottom: 16px; border-radius: 0 0 22px 22px; }
.locate-btn   { bottom: 59px; border-radius: 22px 22px 0 0; }
.more-menu-btn { bottom: 115px; z-index: 550; }
.map-mode-btn { bottom: 171px; font-size: 12px; font-weight: 750; }
.map-north-btn {
  --map-bearing: 0;
  bottom: 227px;
  flex-direction: column;
  gap: 0;
  font-size: 8px;
  font-weight: 800;
}
.map-north-btn svg {
  transform: rotate(calc(var(--map-bearing) * -1deg));
  transition: transform var(--dur-fast) var(--ease-out);
}
.locate-btn.active { color: #ffffff; background: var(--ui-action); border-color: var(--ui-action); }

/* DZ pill — wider, carries a label */
.home-btn {
  width: auto;
  min-width: 128px;
  padding: 0 16px 0 13px;
  border-radius: 999px;
  gap: 7px;
}
.home-btn .home-btn-label {
  color: var(--ui-label-primary);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  pointer-events: none;
}

/* Wind chip — weather-style glance pinned to the top-left map corner */
.wind-chip {
  --tier-color: #10b981;
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 440;
  display: inline-flex;
  align-items: center;
  gap: 0;
  min-height: 40px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--ui-separator);
  background: var(--ui-glass);
  color: var(--ui-label-primary);
  font-size: 12.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  overflow: hidden;
}
.wind-chip:hover { background: var(--ui-surface-elevated); }
.wind-chip-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 5px 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
}
.wind-chip-main:hover { background: var(--ui-fill); }
.wind-chip-main svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  stroke-width: 2;
  color: var(--tier-color);
}
.wind-chip[data-tier="none"]   { --tier-color: #3b82f6; }
.wind-chip[data-tier="light"]  { --tier-color: #10b981; }
.wind-chip[data-tier="medium"] { --tier-color: #eab308; }
.wind-chip[data-tier="strong"] {
  --tier-color: #ff453a;
  border-color: rgba(255, 69, 58, 0.55);
  background: rgba(80, 16, 12, 0.72);
}

/* More menu — iOS popover */
.more-menu {
  display: none;
  position: absolute;
  right: 66px;
  top: auto;
  bottom: 115px; /* align to the ⋯ button bottom and expand upward */
  z-index: 551;
  min-width: 216px;
  padding: 5px;
  border-radius: var(--radius-md);
  background: var(--ui-surface-elevated);
  border: 1px solid var(--ui-separator);
  box-shadow: var(--shadow-3);
  transition: bottom var(--dur-med) var(--ease-spring);
}
.more-menu.open { display: block; animation: menu-in var(--dur-fast) var(--ease-out); }
@keyframes menu-in {
  from { opacity: 0; transform: translateX(6px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
.more-menu .menu-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  padding: 8px 11px;
  border-radius: 9px;
  background: transparent;
  border: none;
  color: var(--ui-label-primary);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
}
.more-menu .menu-item + .menu-item { margin-top: 1px; }
.more-menu .menu-item:hover, .more-menu .menu-item:active { background: var(--ui-fill); }
.more-menu .menu-item .menu-icon {
  width: 17px;
  height: 17px;
  display: block;
  flex-shrink: 0;
  color: var(--ui-accent);
}
.more-menu .menu-item .menu-handle {
  color: var(--ui-label-secondary);
  font-size: 12px;
  margin-left: auto;
}

/* Left-hand mode — mirror the floating stack */
body.left-handed .home-btn,
body.left-handed .recenter-btn,
body.left-handed .locate-btn,
body.left-handed .map-mode-btn,
body.left-handed .map-north-btn,
body.left-handed .more-menu-btn { right: auto; left: 16px; }
body.left-handed .more-menu {
  right: auto;
  left: 66px;
  animation-name: menu-in-left;
}
@keyframes menu-in-left {
  from { opacity: 0; transform: translateX(-6px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* Legend — bottom-right glass chip */
.pattern-legend {
  position: absolute;
  right: 68px;
  bottom: 171px;
  z-index: 410;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--ui-glass);
  border: 1px solid var(--ui-separator);
  color: var(--ui-label-primary);
  font-size: 11px;
  font-weight: 600;
  box-shadow: var(--shadow-1);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  pointer-events: none;
}
.pattern-legend span { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.legend-line {
  width: 26px;
  height: 0;
  border-top: 3px solid var(--ui-accent);
  border-radius: 999px;
  display: inline-block;
}
.legend-line.solid { border-top-color: #10b981; }
body:has(.speed-btn[data-tier="none"].active)   .legend-line.solid { border-top-color: #3b82f6; }
body:has(.speed-btn[data-tier="light"].active)  .legend-line.solid { border-top-color: #10b981; }
body:has(.speed-btn[data-tier="medium"].active) .legend-line.solid { border-top-color: #eab308; }
body:has(.speed-btn[data-tier="strong"].active) .legend-line.solid { border-top-color: #cc0000; }
.legend-line.dashed { border-top-color: #9aa3b2; border-top-style: dashed; }

/* Retired chrome — kept in the DOM contract, permanently hidden */
.windy-toggle { display: none !important; }
.north-indicator { display: none !important; }
.feedback-badge { display: none !important; }

/* ========================== 10. OVERLAYS ================================== */

/* --- DZ picker — Spotlight-style centered glass search --------------------- */
.dz-picker {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(6, 8, 12, 0.55);
  color: var(--ui-label-primary);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: max(9dvh, env(safe-area-inset-top, 0)) 20px 24px;
}
.dz-picker.open { display: flex; animation: dz-in var(--dur-fast) var(--ease-out); }
@keyframes dz-in { from { opacity: 0; } to { opacity: 1; } }
.dz-panel {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(700px, 84dvh);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(30, 33, 42, 0.97), rgba(15, 17, 23, 0.97));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-xl);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), var(--shadow-3);
  animation: dz-panel-in var(--dur-med) var(--ease-spring);
}
@keyframes dz-panel-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.dz-picker-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: transparent;
  border-bottom: 1px solid var(--ui-separator);
}
.dz-picker-back {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--ui-fill);
  border: none;
  color: var(--ui-label-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.dz-picker-back:hover { background: var(--ui-fill-strong); color: var(--ui-label-primary); }
.dz-picker-back svg { width: 18px; height: 18px; }
.dz-picker-search {
  flex: 1;
  height: 46px;
  padding: 0 16px;
  background: var(--ui-fill);
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-sm);
  color: var(--ui-label-primary);
  font-size: 17px;
  outline: none;
  caret-color: var(--ui-accent);
  -webkit-appearance: none;
  appearance: none;
}
.dz-picker-search:focus {
  border-color: var(--ui-accent);
  background: var(--ui-fill-strong);
  box-shadow: 0 0 0 2px var(--ui-focus-ring);
}
.dz-picker-search::placeholder { color: var(--ui-label-tertiary); }
.dz-picker-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 10px 14px;
  scrollbar-color: var(--ui-separator-strong) transparent;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.dz-picker-list::-webkit-scrollbar { width: 10px; }
.dz-picker-list::-webkit-scrollbar-track { background: transparent; }
.dz-picker-list::-webkit-scrollbar-thumb {
  min-height: 48px;
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--ui-separator-strong);
  background-clip: padding-box;
}
.dz-section-label {
  padding: 18px 4px 7px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--ui-label-secondary);
  font-weight: 650;
}
.dz-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  width: 100%;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  margin-bottom: 2px;
  color: var(--ui-label-primary);
  font: inherit;
  text-align: left;
  transition: background var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
  user-select: none;
  -webkit-user-select: none;
}
.dz-item:hover { background: var(--ui-fill); }
.dz-item:active { background: var(--ui-fill-strong); transform: scale(0.995); }
.dz-item:focus-visible {
  outline: 3px solid var(--ui-focus-ring);
  outline-offset: -2px;
}
.dz-item.is-current { background: var(--ui-accent-fill); }
.dz-item.is-current::after {
  content: "✓";
  flex: none;
  color: var(--ui-accent);
  font-size: 16px;
  font-weight: 750;
}
.dz-item-icon {
  width: 40px;
  height: 40px;
  flex: none;
  background: var(--ui-accent-fill);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-accent);
}
.dz-item-icon svg { width: 20px; height: 20px; }
.dz-item.is-current .dz-item-icon {
  background: var(--ui-accent);
  color: #ffffff;
}
.dz-item-text { flex: 1; min-width: 0; }
.dz-item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--ui-label-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dz-item-loc {
  font-size: 12.5px;
  color: var(--ui-label-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dz-empty {
  padding: 64px 24px;
  text-align: center;
  color: var(--ui-label-secondary);
  font-size: 14px;
  line-height: 1.6;
}

/* --- Alert / language modals ------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--ui-overlay);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--ui-surface-elevated);
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-lg);
  padding: 24px 24px 20px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-3);
  animation: modal-in var(--dur-fast) var(--ease-out);
  color: var(--ui-label-primary);
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ui-danger-fill);
  color: var(--ui-danger);
  font-size: 0;
  line-height: 1;
}
.modal-icon::before {
  content: "!";
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid currentColor;
  font-size: 15px;
  font-weight: 800;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 12px;
}
.modal-body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ui-label-primary);
  margin-bottom: 20px;
}
.modal-body b { color: var(--ui-danger); font-weight: 700; }
.modal-body .dim { color: var(--ui-label-secondary); }
.modal-actions { display: flex; gap: 8px; }
.modal-actions button {
  flex: 1;
  min-height: 44px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 650;
  border: none;
}
.modal-actions .btn-cancel { background: var(--ui-fill); color: var(--ui-label-primary); }
.modal-actions .btn-warn { background: var(--ui-danger-action); color: #ffffff; }
.modal-actions .btn-warn:hover { background: color-mix(in srgb, var(--ui-danger-action) 86%, black); }

/* About the creator — quiet, theme-native identity card. */
.creator-modal-card { max-width: 390px; }
.creator-avatar {
  width: 76px;
  height: 76px;
  margin: 0 auto 12px;
  box-shadow: 0 10px 24px rgba(0, 102, 204, 0.24),
    0 0 0 1px color-mix(in srgb, var(--ui-separator-strong) 78%, transparent);
}
.creator-name { margin-bottom: 3px; }
.creator-role,
.creator-intro {
  margin: 0;
  text-align: center;
}
.creator-role {
  color: var(--ui-accent);
  font-size: 12px;
  font-weight: 700;
}
.creator-intro {
  margin-top: 7px;
  color: var(--ui-label-secondary);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.creator-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 17px 0 14px;
}
.creator-link {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 58px;
  padding: 9px 11px;
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  text-decoration: none;
  transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease,
    transform var(--dur-fast) var(--ease-out);
}
.creator-link:hover {
  background: var(--ui-fill-strong);
  border-color: var(--ui-separator-strong);
}
.creator-link:active { transform: scale(0.99); }
.creator-link-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  overflow: hidden;
  border-radius: 11px;
  color: #ffffff;
}
.creator-platform-icon {
  width: 21px;
  height: 21px;
  fill: currentColor;
}
.creator-link-mark--douyin {
  background: #050505;
}
.creator-link-mark--douyin .creator-platform-icon {
  width: 23px;
  height: 23px;
}
.creator-link-mark--xiaohongshu {
  background: #ff2442;
}
.creator-link-mark--xiaohongshu .creator-platform-icon {
  width: 25px;
  height: 25px;
}
.creator-link-mark--instagram {
  background: radial-gradient(circle at 31% 107%, #ffd600 0 18%, #ff7a00 34%, #ff0169 58%, #d300c5 76%, #7638fa 100%);
}
.creator-link > svg {
  width: 17px;
  height: 17px;
  flex: none;
  color: var(--ui-label-tertiary);
}
/* Language options */
.lang-options { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 14px; }
.lang-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 15px;
  background: var(--ui-fill);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--ui-label-primary);
  font-size: 15px;
  text-align: left;
}
.lang-option:hover { background: var(--ui-fill-strong); }
.lang-option.active {
  background: var(--ui-accent-fill);
  border-color: var(--ui-accent);
}
.lang-option-check { color: var(--ui-accent); font-weight: 750; font-size: 16px; }

/* --- Welcome (disclaimer) modal --------------------------------------------- */
.disclaimer-modal {
  position: fixed;
  inset: 0;
  background: var(--ui-overlay);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.disclaimer-modal.hidden { display: none; }
.disclaimer-box {
  position: relative;
  background: var(--ui-surface-elevated);
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-xl);
  padding: 28px 24px 20px;
  max-width: 440px;
  width: 100%;
  max-height: 94dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-3);
  animation: disc-in var(--dur-med) var(--ease-out);
  text-align: center;
  color: var(--ui-label-primary);
}
@keyframes disc-in {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.welcome-lang-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  min-height: 34px;
  background: var(--ui-fill);
  border: 1px solid var(--ui-separator);
  color: var(--ui-label-secondary);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  z-index: 1;
}
.welcome-lang-toggle:hover { background: var(--ui-fill-strong); color: var(--ui-label-primary); }

.welcome-icon {
  width: 82px;
  height: 82px;
  margin: 4px auto 14px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: linear-gradient(155deg, #2f9bff 0%, var(--ui-action) 78%);
  border: none;
  box-shadow: 0 12px 28px rgba(0, 102, 204, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.welcome-mark { width: 50px; height: 50px; display: block; }
.welcome-mark path, .welcome-mark circle { stroke: #ffffff; vector-effect: non-scaling-stroke; }

.welcome-title {
  font-size: 23px;
  font-weight: 750;
  margin: 0 0 4px;
  line-height: 1.22;
  color: var(--ui-label-primary);
}
.welcome-subtitle { font-size: 14px; color: var(--ui-label-secondary); margin: 0 0 6px; }
.welcome-version-line {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0 0 12px;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--ui-accent-fill);
  color: var(--ui-accent);
  font-size: 12px;
  font-weight: 650;
}
.welcome-author-version { font-weight: 500; user-select: text; }
.welcome-tagline {
  font-size: 17px;
  font-weight: 700;
  margin: 4px 0 8px;
  color: var(--ui-label-primary);
}
.welcome-intro {
  font-size: 14px;
  line-height: 1.5;
  color: var(--ui-label-primary);
  margin: 0 0 14px;
}
.welcome-intro em, .welcome-subtitle em, .welcome-card em {
  color: var(--ui-accent);
  font-style: normal;
  font-weight: 650;
}
.welcome-card {
  background: var(--ui-fill);
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-md);
  padding: 4px 16px;
  text-align: left;
  margin: 0 0 14px;
}
.welcome-card p {
  font-size: 13px;
  line-height: 1.5;
  color: var(--ui-label-primary);
  margin: 0;
  padding: 11px 0;
}
.welcome-card p + p { border-top: 1px solid var(--ui-separator); }

.welcome-link-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin: 0 auto 14px;
}
.welcome-link-sep { color: var(--ui-separator); font-size: 12px; user-select: none; }
.welcome-terms-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  font-size: 12.5px;
  color: var(--ui-accent);
  text-decoration: none;
  padding: 4px 7px;
  border-radius: 7px;
  background: none;
  border: none;
}
.welcome-terms-link:hover { background: var(--ui-accent-fill); }

.disclaimer-actions { display: flex; gap: 8px; margin-top: 2px; }
.disclaimer-actions button {
  border-radius: var(--radius-md);
  border: none;
  padding: 12px 14px;
}
.disclaimer-actions .btn-decline {
  flex: 0 0 30%;
  background: var(--ui-fill);
  color: var(--ui-label-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  font-size: 14px;
  font-weight: 650;
}
.disclaimer-actions .btn-decline small {
  font-size: 11px;
  font-weight: 450;
  margin-top: 3px;
  color: var(--ui-label-tertiary);
}
.disclaimer-actions .btn-decline:hover { background: var(--ui-fill-strong); color: var(--ui-label-primary); }
.disclaimer-actions .btn-accept {
  flex: 1;
  background: var(--ui-action);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1.2;
  box-shadow: 0 6px 18px rgba(0, 102, 204, 0.35);
}
.disclaimer-actions .btn-accept:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ui-action) 88%, black);
}
.disclaimer-actions .btn-accept:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}
.accept-main, .accept-sub, .accept-cta, .accept-legal { color: #ffffff; }
.accept-main { font-size: 15px; font-weight: 750; }
.accept-sub  { font-size: 10.5px; font-weight: 450; opacity: 0.8; margin-top: 1px; }
.accept-cta  { font-size: 15px; font-weight: 750; margin-top: 2px; }
.btn-accept.counting-down .accept-main,
.btn-accept.counting-down .accept-sub { display: none; }

/* --- Terms / usage / updates sheets ------------------------------------------ */
.terms-modal {
  position: fixed;
  inset: 0;
  background: var(--ui-overlay);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.terms-modal.hidden { display: none; }
.terms-box {
  background: var(--ui-surface-elevated);
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  max-width: 560px;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-3);
  color: var(--ui-label-primary);
  animation: modal-in var(--dur-fast) var(--ease-out);
}
.terms-box h2 { font-size: 19px; font-weight: 750; margin: 0 0 14px; }
.terms-body { font-size: 13.5px; line-height: 1.65; color: var(--ui-label-primary); }
.terms-body p { margin: 0 0 12px; }
.terms-body strong { color: var(--ui-danger); font-weight: 650; }
.terms-body.usage-body strong,
.terms-body.update-body strong { color: var(--ui-accent); }
.terms-body ul { list-style: none; padding: 0; margin: 8px 0 14px; }
.terms-body li { padding: 5px 0 5px 18px; position: relative; }
.terms-body li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 13px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--ui-accent);
}
.update-current-version {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 12px;
  margin: 2px 0 12px;
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  font-size: 13px;
  font-weight: 700;
}
.update-version-card {
  padding: 13px 15px;
  margin: 10px 0;
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-md);
  background: var(--ui-accent-fill);
}
.update-version-card h3 {
  margin: 0 0 8px;
  color: var(--ui-label-primary);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}
.update-version-card ul { margin-bottom: 0; }
.update-version-card li { padding-top: 4px; padding-bottom: 4px; }
.update-date {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 10px;
  margin-bottom: 8px;
  border-radius: 999px;
  background: var(--ui-accent-fill);
  color: var(--ui-accent);
  font-size: 12px;
  font-weight: 700;
}
.usage-note {
  color: var(--ui-label-secondary);
  font-size: 12.5px;
  border-top: 1px solid var(--ui-separator);
  padding-top: 12px;
  margin-top: 12px;
}
.terms-close {
  display: block;
  position: sticky;
  bottom: 0;
  width: 100%;
  min-height: 44px;
  padding: 12px 16px;
  margin-top: 16px;
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 650;
}
#updates-modal .terms-box { display: flex; flex-direction: column; overflow: hidden; }
#updates-modal .update-body { min-height: 0; overflow-y: auto; padding-right: 4px; }
#updates-modal .terms-close { position: static; flex: 0 0 auto; }

/* Secondary action hovers share the semantic strong fill */
.focus-btn:hover,
.modal-actions .btn-cancel:hover,
.dz-picker-back:hover,
.terms-close:hover { background: var(--ui-fill-strong); }

/* --- Declined screen ---------------------------------------------------------- */
.declined-screen {
  position: fixed;
  inset: 0;
  background: var(--ui-background);
  color: var(--ui-label-secondary);
  z-index: 9998;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  font-size: 15px;
  line-height: 1.6;
}
.declined-screen.show { display: flex; }
.declined-screen .inner { max-width: 420px; }
.declined-screen b {
  color: var(--ui-label-primary);
  font-size: 19px;
  display: block;
  margin-bottom: 10px;
}
.declined-reopen-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  margin-top: 28px;
  padding: 14px 20px;
  background: var(--ui-fill);
  border: 1.5px solid var(--ui-accent);
  border-radius: var(--radius-md);
}
.declined-reopen-btn:hover { background: var(--ui-accent-fill); }
.reopen-main { font-size: 16px; font-weight: 700; color: var(--ui-accent); }
.reopen-sub { font-size: 12.5px; font-weight: 450; color: var(--ui-label-secondary); }

/* --- Waypoint focus card -------------------------------------------------------- */
.focus-overlay {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ui-surface-elevated);
  border: 1px solid var(--ui-separator);
  border-radius: var(--radius-md);
  padding: 14px 20px 12px;
  min-width: 340px;
  max-width: 440px;
  z-index: 600;
  box-shadow: var(--shadow-3);
  text-align: center;
  color: var(--ui-label-primary);
}
.focus-overlay.hidden { display: none; }
.focus-title {
  font-size: 10px;
  color: var(--ui-label-secondary);
  text-transform: uppercase;
  margin-bottom: 4px;
  font-weight: 650;
}
.focus-title .alt { color: var(--ui-accent); font-weight: 750; font-size: 15px; }
.focus-sub { font-size: 13px; color: var(--ui-label-primary); margin-bottom: 12px; line-height: 1.45; }
.focus-sub b { color: var(--ui-accent); font-weight: 700; }
.focus-nav { display: flex; gap: 6px; justify-content: center; }
.focus-btn {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--ui-fill);
  color: var(--ui-label-primary);
  font-size: 12.5px;
  font-weight: 600;
  border: none;
}
.focus-btn:disabled { opacity: 0.35; cursor: default; }
.focus-btn.close { background: var(--ui-action); color: #ffffff; }
.focus-btn.close:hover { background: color-mix(in srgb, var(--ui-action) 88%, black); }

/* --- Windy panel ------------------------------------------------------------------ */
.windy-panel {
  position: fixed;
  top: 76px;
  right: 16px;
  z-index: 460;
  width: 360px;
  height: 280px;
  padding: 0;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--ui-surface-elevated);
  border: 1px solid var(--ui-separator);
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + 24px));
  visibility: hidden;
  pointer-events: none;
  transition: transform var(--dur-med) var(--ease-spring), visibility 0s linear var(--dur-med);
}
.windy-panel.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition: transform var(--dur-med) var(--ease-spring), visibility 0s linear 0s;
}
.windy-panel .hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 8px 9px 14px;
  font-size: 11px;
  color: var(--ui-label-secondary);
  text-transform: uppercase;
  font-weight: 650;
  border-bottom: 1px solid var(--ui-separator);
}
.windy-panel .hdr button {
  background: none;
  border: none;
  color: var(--ui-label-secondary);
  font-size: 18px;
  line-height: 1;
  min-height: 32px;
  padding: 0 10px;
}
.windy-panel .hdr button:hover { color: var(--ui-label-primary); }
.windy-panel iframe { flex: 1; width: 100%; border: none; }

/* --- Warning banners ----------------------------------------------------------------- */
.banners {
  position: absolute;
  top: 16px;
  right: 16px;
  left: auto;
  z-index: 490; /* below the sheet/sidebar so a full sheet is never blocked */
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
  max-width: min(440px, calc(100vw - 32px));
}
.warning-banner {
  position: relative;
  overflow: hidden;
  background: var(--ui-surface-elevated);
  color: var(--ui-label-primary);
  padding: 10px 14px 10px 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ui-separator);
  border-left: 4px solid var(--ui-danger);
  font-size: 12px;
  font-weight: 550;
  max-width: 100%;
  text-align: left;
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  line-height: 1.45;
  animation: banner-in var(--dur-med) var(--ease-out);
}
@keyframes banner-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.warning-banner::before {
  content: "!";
  position: absolute;
  top: 10px;
  left: 12px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ui-danger-fill);
  color: var(--ui-danger);
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
}
.warning-banner b { font-weight: 750; color: var(--ui-danger); }
.warning-banner.amber { border-left-color: var(--ui-warning); }
.warning-banner.amber::before { background: var(--ui-warning-fill); color: var(--ui-warning); }
.warning-banner.amber b { color: var(--ui-label-primary); }
.warning-banner .rule-link {
  color: var(--ui-accent);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.warning-banner.hidden { display: none; }

.banner-collapse-toggle {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 4px 8px;
  border: 0;
  border-left: 1px solid var(--ui-separator);
  border-radius: 0 999px 999px 0;
  background: transparent;
  color: var(--ui-accent);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1;
}
.banner-collapse-toggle.hidden { display: none; }
.banner-collapse-toggle:hover { background: var(--ui-fill); }
.banner-collapse-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.banner-collapse-dot {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ui-warning);
  color: #ffffff;
  font-size: 11px;
  font-weight: 850;
}
.banner-collapse-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--ui-accent-fill);
  color: var(--ui-accent);
  font-size: 10.5px;
  font-weight: 800;
}
.banners.collapsed { max-width: max-content; }
.banners.collapsed .warning-banner:not(.hidden) { display: none; }

/* --- Hint, footer line, toast --------------------------------------------------------- */
.info {
  position: absolute;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  font-size: 12px;
  color: var(--ui-label-secondary);
  background: var(--ui-surface-elevated);
  border: 1px solid var(--ui-separator);
  border-radius: 999px;
  box-shadow: var(--shadow-1);
  z-index: 430;
  pointer-events: none;
  max-width: 420px;
  text-align: center;
}
.disclaimer {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  z-index: 400;
  pointer-events: none;
  white-space: nowrap;
}
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--ui-surface-elevated);
  color: var(--ui-label-primary);
  border: 1px solid var(--ui-separator);
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 12000;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--dur-fast) var(--ease-out), opacity var(--dur-fast) ease;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.app-update-notice {
  position: fixed;
  top: max(20px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--ui-separator);
  border-radius: 999px;
  background: var(--ui-surface-elevated);
  color: var(--ui-label-primary);
  box-shadow: var(--shadow-2);
  z-index: 9000;
}
.app-update-notice[hidden] { display: none; }
.app-update-message {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}
.app-update-refresh {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--ui-action);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.app-update-refresh:hover { background: color-mix(in srgb, var(--ui-action) 88%, black); }
.app-update-refresh:focus-visible {
  outline: 3px solid var(--ui-focus-ring);
  outline-offset: 2px;
}

/* ====================== 11. LAYOUT BREAKPOINTS ============================ */

/* ---------- Compact (phones): bottom sheet + tab bar ---------------------- */
@media (max-width: 699px) {
  .app-update-notice {
    top: max(64px, calc(env(safe-area-inset-top) + 56px));
    align-items: flex-start;
    border-radius: var(--radius-md);
  }
  .app-update-message { max-width: min(62vw, 260px); }

  body:has(.controls-column.sheet-peek) { --sheet-h: 76px; }
  body:has(.controls-column.sheet-half) { --sheet-h: 54dvh; }
  body:has(.controls-column.sheet-full) { --sheet-h: calc(100dvh - 72px); }

  .controls-column {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 100dvh;
    gap: 0;
    border: 0;
    border-top: 1px solid var(--ui-separator);
    border-radius: 30px 30px 0 0;
    box-shadow: 0 -12px 44px rgba(0, 0, 0, 0.28);
    overflow: hidden;
    touch-action: pan-y;
    transition: height var(--dur-med) var(--ease-spring);
    will-change: height;
  }
  .controls-column.sheet-peek { height: 76px; }
  .controls-column.sheet-half { height: 54dvh; }
  .controls-column.sheet-full { height: calc(100dvh - 72px); }

  /* Single top row: a slim grip hugs the sheet edge, the dropzone title sits
     right under it, and the whole header doubles as the drag surface. */
  .controls-column .drawer-handle {
    order: 1;
    display: inline-flex;
    flex: 0 0 16px;
    min-height: 16px;
    padding: 7px 20px 0;
    align-items: flex-start;
  }
  .stack-header { order: 2; padding: 0 12px 6px 8px; touch-action: none; }
  .panel-scroll { order: 3; flex: 1 1 auto; min-height: 0; overscroll-behavior-y: contain; }
  .section-tabbar { order: 4; padding-bottom: max(7px, env(safe-area-inset-bottom)); }

  /* Peek: grabber + dropzone title (with alert chip) — pull up for the rest */
  .controls-column.sheet-peek .control-section { display: none; }
  .controls-column.sheet-peek .panel-scroll { overflow: hidden; }
  .controls-column.sheet-peek .section-tabbar { display: none; }

  .banners {
    /* sits below the corner wind chip (top 10 + 36 chip + 10 gap) */
    top: max(56px, calc(env(safe-area-inset-top) + 56px));
    left: 14px;
    right: 66px;
    max-width: none;
    align-items: stretch;
    gap: 6px;
  }
  .banners .warning-banner { font-size: 11px; padding: 9px 11px 9px 37px; }
  .banners.collapsed { right: auto; max-width: calc(100vw - 80px); align-items: flex-start; }

  /* DZ search fills the phone screen edge-to-edge */
  .dz-picker { padding: 0; }
  .dz-panel {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
  }
  .dz-picker-header { padding-top: max(12px, env(safe-area-inset-top)); }
  .dz-picker-list { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

  /* Floating chrome rides the sheet edge; it fades away when the sheet is full */
  .home-btn, .recenter-btn, .locate-btn, .map-mode-btn, .map-north-btn, .more-menu-btn { right: 14px; }
  .home-btn, .recenter-btn, .locate-btn, .map-mode-btn, .map-north-btn, .more-menu-btn, .pattern-legend {
    transition: bottom var(--dur-med) var(--ease-spring), opacity var(--dur-fast) ease;
  }
  body:has(.controls-column.sheet-full) .home-btn,
  body:has(.controls-column.sheet-full) .recenter-btn,
  body:has(.controls-column.sheet-full) .locate-btn,
  body:has(.controls-column.sheet-full) .map-mode-btn,
  body:has(.controls-column.sheet-full) .map-north-btn,
  body:has(.controls-column.sheet-full) .more-menu-btn,
  body:has(.controls-column.sheet-full) .more-menu,
  body:has(.controls-column.sheet-full) .pattern-legend {
    opacity: 0;
    pointer-events: none;
  }
  .recenter-btn  { bottom: calc(var(--sheet-h) + 12px); }
  .locate-btn    { bottom: calc(var(--sheet-h) + 12px + 43px); }
  .more-menu-btn { bottom: calc(var(--sheet-h) + 12px + 43px + 56px); }
  .map-mode-btn  { bottom: calc(var(--sheet-h) + 12px + 43px + 112px); }
  .map-north-btn { bottom: calc(var(--sheet-h) + 12px + 43px + 168px); }
  .more-menu {
    top: auto;
    bottom: calc(var(--sheet-h) + 12px + 43px + 56px);
    right: 64px;
  }
  .wind-chip {
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    min-height: 36px;
    padding: 3px;
    font-size: 12px;
  }
  .wind-chip-main { min-height: 30px; padding: 4px 8px; }
  .banner-collapse-toggle { min-height: 30px; padding: 3px 7px; }
  body.left-handed .home-btn,
  body.left-handed .recenter-btn,
  body.left-handed .locate-btn,
  body.left-handed .map-mode-btn,
  body.left-handed .map-north-btn,
  body.left-handed .more-menu-btn { right: auto; left: 14px; }
  body.left-handed .more-menu { right: auto; left: 64px; }

  .pattern-legend {
    left: 12px;
    right: auto;
    bottom: calc(var(--sheet-h) + 12px);
    padding: 7px 9px;
    font-size: 10.5px;
    gap: 4px;
  }
  body.left-handed .pattern-legend { left: auto; right: 12px; }
  .legend-line { width: 22px; border-top-width: 2.5px; }

  .focus-overlay {
    bottom: calc(var(--sheet-h) + 12px);
    min-width: 0;
    width: calc(100vw - 24px);
    max-width: 440px;
  }

  .windy-panel {
    width: calc(100% - 28px);
    left: 14px;
    right: 14px;
    top: max(64px, calc(env(safe-area-inset-top) + 56px));
  }

  .toast { top: max(64px, calc(env(safe-area-inset-top) + 56px)); }
  .info { display: none; }
  .disclaimer { display: none; }
}

/* ---------- Medium (portrait tablets): bottom-left capsule stack ----------- */
@media (min-width: 700px) and (max-width: 1099px) {
  .controls-column {
    top: 72px;
    bottom: auto;
    left: 16px;
    display: flex;
    width: 352px;
    height: auto;
    max-height: calc(100dvh - 88px);
  }
  .wind-chip { left: 16px; }
  .info { display: none; }
  .drawer-handle { display: none; }
}

/* ---------- Expanded (desktop): bottom-left capsule stack ------------------- */
@media (min-width: 1100px) {
  .controls-column {
    top: 72px;
    right: auto;
    bottom: auto;
    left: 16px;
    display: flex;
    width: 380px;
    height: auto;
    max-height: calc(100dvh - 88px);
  }
  .wind-chip { left: 16px; }
  .drawer-handle { display: none; }
  .info { left: 50%; }
}

@media (min-width: 1600px) {
  .controls-column { width: 400px; }
}

/* ====================== 11. ACCESSIBILITY MEDIA =========================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .wind-chip,
  .pattern-legend,
  .home-btn,
  .locate-btn,
  .recenter-btn,
  .map-mode-btn,
  .map-north-btn,
  .more-menu-btn {
    background: var(--ui-surface-elevated);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  :root {
    --ui-separator: currentColor;
    --ui-focus-ring: var(--ui-accent);
  }
  button, input, select { border-width: 2px; }
}

@media (forced-colors: active) {
  :root { forced-color-adjust: auto; }
  .controls-column,
  .panel,
  .pattern-legend,
  .more-menu,
  .dz-picker,
  .modal,
  .disclaimer-box,
  .terms-box {
    border: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
    box-shadow: none;
  }
  button:focus-visible,
  input:focus-visible,
  select:focus-visible,
  a:focus-visible,
  [role="button"]:focus-visible { outline: 3px solid Highlight; }
}
#local-file-preview-notice {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  padding: 24px;
  color: var(--ui-text-primary, #f5f7fb);
  background: var(--ui-map-fallback, #0b0e13);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#local-file-preview-notice > div {
  width: min(520px, 100%);
  padding: 28px;
  border: 1px solid var(--ui-border-subtle, rgba(255, 255, 255, 0.14));
  border-radius: var(--ui-radius-xl, 20px);
  background: var(--ui-surface-solid, #171b23);
  box-shadow: var(--ui-shadow-raised, 0 24px 70px rgba(0, 0, 0, 0.38));
}

#local-file-preview-notice h1 {
  margin: 0 0 14px;
  font-size: 24px;
}

#local-file-preview-notice p {
  margin: 10px 0;
  color: var(--ui-text-secondary, #c7cbd4);
  line-height: 1.65;
}

#local-file-preview-notice code {
  color: var(--ui-text-primary, #fff);
  font-weight: 700;
}

#local-file-preview-notice a {
  display: inline-block;
  margin-top: 10px;
  padding: 11px 16px;
  border-radius: var(--ui-radius-control, 12px);
  color: #fff;
  background: var(--accent, #0a84ff);
  text-decoration: none;
  font-weight: 700;
}
