/* Pilot Tools — lightweight moving map, waypoints, flight recording. Themed to
   match Competition Tools / Crew Tools (GitHub-dark palette, #1f6feb accent) —
   most of this file is intentionally identical to crew.clearabovecamera.com's
   style.css so the two apps read as one family. */
:root {
  --bg:      #0d1117;
  --panel:   #161b22;        /* sheet surface            */
  --elev:    #1c2330;        /* cards / rows             */
  --elev-2:  #232c3a;        /* hover / pressed          */
  --text:    #e6edf3;
  --text-2:  #9fb4c8;        /* muted                    */
  --text-3:  #6e7b8a;        /* dim / units              */
  --line:    #30363d;
  --accent:  #1f6feb;        /* Competition Tools blue    */
  --accent-h: #388bfd;
  --accent-ink: #ffffff;
  --self:    #2b83ff;        /* my-location dot (blue) */
  --edge:    #0d1117;        /* marker outline on the map */
  --radius:  14px;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:      #f3f5f8;
    --panel:   #ffffff;
    --elev:    #eef1f6;
    --elev-2:  #e3e8ef;
    --text:    #15202b;
    --text-2:  #4c586a;
    --text-3:  #6c7787;
    --line:    #d7dce3;
    --accent-h: #175cd3;
    --edge:    #f3f5f8;
    --shadow:  0 10px 30px rgba(15, 23, 32, .18);
  }
  .chip, .round { background: rgba(255, 255, 255, .82); }
  .leaflet-bar a { background: rgba(255, 255, 255, .9) !important; }
  .leaflet-control-attribution { background: rgba(255, 255, 255, .75) !important; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); color: var(--text); background: var(--bg);
  overflow: hidden; overscroll-behavior: none;
  -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1;
}
#map { position: absolute; inset: 0; z-index: 0; background: #090c10; }

.top-scrim {
  position: absolute; z-index: 400; top: 0; left: 0; right: 0; height: 130px;
  background: linear-gradient(180deg, rgba(0, 0, 0, .5), transparent);
  pointer-events: none;
}

/* ============================== top controls ============================== */
#top {
  position: absolute; z-index: 500;
  top: calc(12px + var(--safe-t)); left: 12px; right: 12px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  pointer-events: none;
}
#top .chip, #top .round { pointer-events: auto; }
.chips { display: flex; gap: 8px; overflow: hidden; }
.chip {
  border: 0; cursor: pointer; white-space: nowrap;
  font-family: var(--font); font-weight: 600; font-size: 13px;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(22, 27, 34, .8); color: var(--text-2);
  border: 1px solid var(--line); backdrop-filter: blur(14px);
}
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.round {
  display: grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 50%; cursor: pointer;
  background: rgba(22, 27, 34, .8); color: var(--text);
  border: 1px solid var(--line); backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
.round svg { width: 21px; height: 21px; }
.round:active { background: var(--elev-2); }
.tools { display: flex; flex-direction: column; gap: 8px; }
.round.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* transient warning/info toast, bottom-centred above the peek sheet */
.toast {
  position: absolute; z-index: 600; left: 50%; transform: translateX(-50%);
  bottom: calc(104px + var(--safe-b)); max-width: calc(100% - 32px);
  background: #b45309; color: #fff; font-weight: 600; font-size: 13px;
  padding: 9px 16px; border-radius: 12px; box-shadow: var(--shadow);
  text-align: center; line-height: 1.35; pointer-events: none;
}
.toast[hidden] { display: none; }
.toast.ok { background: var(--accent); }

/* ================================ scrim ================================ */
#scrim {
  position: fixed; inset: 0; z-index: 900; background: rgba(0, 0, 0, .55);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .3s ease, visibility .3s;
}
#scrim.show { opacity: 1; visibility: visible; pointer-events: auto; }

/* ============================== bottom sheet ============================== */
.sheet {
  position: fixed; z-index: 1000; left: 0; right: 0; bottom: 0;
  height: min(80vh, 600px);
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0; box-shadow: 0 -8px 36px rgba(0, 0, 0, .55);
  transform: translateY(calc(min(80vh, 600px) - var(--peek-h, 84px)));
  transition: transform .34s cubic-bezier(.32, .72, 0, 1); will-change: transform;
}
.sheet.expanded { transform: translateY(0); }
.peek {
  display: block; width: 100%; border: 0; cursor: pointer; text-align: left;
  background: transparent; color: inherit; padding: 0 16px; height: var(--peek-h, 84px);
}
.grip { display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--elev-2); margin: 8px auto 0; }
.peek-row { display: flex; align-items: center; gap: 12px; height: 64px; }
.peek-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; background: var(--text-3); transition: background .3s; }
.peek-dot.live { background: var(--accent); }
.peek-dot.stale { background: #d8973c; }
.peek-main { flex: 1; min-width: 0; }
.peek-name { display: block; font-weight: 700; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peek-sub { display: block; font-weight: 500; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.peek-stat { display: flex; align-items: baseline; gap: 11px; font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
.peek-stat i { font-style: normal; font-weight: 600; font-size: 11px; color: var(--text-3); margin-left: 2px; }
.peek-chev { width: 22px; height: 22px; color: var(--text-3); flex: none; transition: transform .34s ease; }
.sheet.expanded .peek-chev { transform: rotate(180deg); }
.sheet-body {
  height: calc(min(80vh, 600px) - var(--peek-h, 84px));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(24px + var(--safe-b));
}

/* telemetry */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); background: var(--elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 4px; margin: 6px 0 18px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat .sv { font-weight: 700; font-size: 21px; letter-spacing: -.02em; line-height: 1; }
.stat .sv.up { color: var(--accent-h); }
.stat .sv.down { color: #d8973c; }
.stat .sl { font-weight: 500; font-size: 11px; color: var(--text-3); }
.stat .sl i { font-style: normal; }

/* nav row */
.navrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; text-decoration: none; color: inherit; background: var(--elev); border: 1px solid rgba(31, 111, 235, .4); border-radius: var(--radius); padding: 13px 15px; margin-bottom: 18px; cursor: pointer; }
.navrow[hidden] { display: none; }
.navrow .eyebrow { display: block; font-weight: 600; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--accent-h); }
.navrow-name { display: block; font-weight: 700; font-size: 15px; margin-top: 2px; }
.navrow-go { font-weight: 700; font-size: 13px; color: var(--accent-h); white-space: nowrap; }

/* section heads */
.sec-head { display: flex; align-items: center; gap: 9px; margin: 6px 2px 10px; }
.sec-head h2 { font-weight: 700; font-size: 18px; letter-spacing: -.01em; margin: 0; }
.count { font-weight: 700; font-size: 12px; color: var(--text-2); background: var(--elev-2); border-radius: 999px; padding: 2px 9px; }
.mini-add { margin-left: auto; border: 0; cursor: pointer; background: var(--elev-2); color: var(--accent-h); font-family: var(--font); font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 999px; }
.mini-add:active { background: var(--line); }

/* generic list (waypoints, imported files) */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 13px; width: 100%; border: 0; background: transparent; cursor: pointer; text-align: left; color: inherit; padding: 9px 8px; border-radius: 10px; }
.row:active { background: var(--elev); }
.row .dot { width: 16px; height: 16px; border-radius: 50%; flex: none; border: 2px solid rgba(255, 255, 255, .22); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; font-weight: 500; font-size: 13px; color: var(--text-2); margin-top: 1px; }
.row-dir { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 50%; color: var(--text-2); text-decoration: none; border: 0; background: transparent; cursor: pointer; }
.row-dir:active { background: var(--elev-2); color: var(--text); }
.row-dir svg { width: 20px; height: 20px; }
.empty { color: var(--text-3); font-size: 14px; font-weight: 500; padding: 4px 8px 14px; }
.empty.in-card { padding: 2px; margin: 0; }

/* card (recording) */
.card { background: var(--elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; margin-bottom: 18px; }
.rec-status { font-weight: 700; font-size: 15px; margin: 0 0 12px; }
.rec-status.on { color: var(--accent-h); }
.rec-actions { display: flex; gap: 10px; }
.rec-btn { margin-top: 0; }
.rec-btn[hidden] { display: none; }

/* Watch Me Fly task-sheet paste box + result line */
.wmf-text {
  width: 100%; font-family: var(--font); font-weight: 500; font-size: 14px;
  line-height: 1.5; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  resize: vertical; min-height: 84px;
}
.wmf-text:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, .25); }
.wmf-text::placeholder { color: var(--text-3); font-weight: 500; }
.wmf-add { margin-top: 10px; }
.hidden-wmf { display: none; }
#wmf-result.ok { color: var(--accent-h); font-weight: 600; }

.btn-accent { display: block; text-align: center; text-decoration: none; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; padding: 12px; border-radius: 999px; }
.btn-accent:active { background: var(--accent-h); }

/* ================================ overlay ================================ */
.overlay { position: fixed; inset: 0; z-index: 2000; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; background: var(--bg); }
.overlay[hidden], .overlay.hidden { display: none; }
.boot { width: 100%; max-width: 340px; margin: 0 auto; min-height: 100%; padding: 28px 24px calc(28px + var(--safe-b)); display: flex; flex-direction: column; justify-content: center; text-align: center; }
.boot .mark { width: 60px; height: 60px; border-radius: 14px; object-fit: cover; align-self: center; }
.boot h1 { font-weight: 800; font-size: 34px; letter-spacing: -.02em; margin: 16px 0 4px; }
.boot .lede { color: var(--text-2); font-size: 15px; margin: 0 0 28px; }
.cta { width: 100%; margin-top: 12px; border: 0; cursor: pointer; font-family: var(--font); font-weight: 700; font-size: 16px; padding: 15px; border-radius: 999px; color: #fff; background: var(--accent); }
.cta:active { background: var(--accent-h); }
.ghost { width: 100%; box-sizing: border-box; margin-top: 10px; border: 1px solid var(--line); background: transparent; color: var(--text); font-family: var(--font); font-weight: 700; font-size: 16px; padding: 15px; border-radius: 999px; cursor: pointer; }
.ghost:active { background: var(--elev); }
.err { color: #ff7b72; min-height: 1.1em; margin: 12px 0 0; font-size: 13.5px; font-weight: 500; }
.hint { color: var(--text-3); font-size: 12.5px; margin: 10px 0 0; line-height: 1.5; }

/* settings sheet */
.set-card { text-align: left; }
.set-h { font-weight: 800; font-size: 26px; letter-spacing: -.01em; margin: 0 0 13px; text-align: center; }
.set-card .field { margin: 10px 0 6px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 11px 0; }
.set-row .field { margin: 0; }
.seg2 { display: flex; gap: 4px; background: var(--elev); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg2 button { border: 0; background: transparent; cursor: pointer; color: var(--text-2); font-family: var(--font); font-weight: 600; font-size: 13px; padding: 7px 12px; border-radius: 7px; }
.seg2 button.on { background: var(--accent); color: #fff; }
.seg2.wide { width: 100%; justify-content: space-between; }
/* waypoint colour swatches in the editor */
.seg2.wide .swatch { flex: 1; height: 34px; border: 0; border-radius: 7px; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
.seg2.wide .swatch.on { outline: 2px solid #fff; outline-offset: 1px; }
#wpedit-name, #wpedit-coord, #wpedit-ring { width: 100%; font-family: var(--font); font-weight: 600; font-size: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
#wpedit-name:focus, #wpedit-coord:focus, #wpedit-ring:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, .25); }
#wpedit-name::placeholder, #wpedit-coord::placeholder, #wpedit-ring::placeholder { color: var(--text-3); font-weight: 500; }
#wpedit-ring { -moz-appearance: textfield; }
#wpedit-ring::-webkit-outer-spin-button, #wpedit-ring::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#set-id { width: 100%; font-family: var(--font); font-weight: 600; font-size: 17px; text-align: center; letter-spacing: .04em; padding: 15px; border-radius: 12px; border: 1px solid var(--line); background: var(--elev); color: var(--text); }
#set-id::placeholder { color: var(--text-3); letter-spacing: 0; text-transform: none; font-weight: 500; }
#set-id:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, .25); }
.dim-id { color: var(--text-3); font-weight: 500; font-size: 11px; letter-spacing: 0; text-transform: none; }
.set-ver { text-align: center; color: var(--text-3); font-size: 11px; font-weight: 500; letter-spacing: .04em; margin: 10px 0 2px; opacity: .7; }

/* simple prompt overlay (name a waypoint / imported layer) */
.prompt-card { background: var(--elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: 100%; max-width: 320px; margin: auto; }
.prompt-card h2 { margin: 0 0 12px; font-size: 18px; }
.prompt-card input { width: 100%; font-family: var(--font); font-weight: 600; font-size: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); margin-bottom: 12px; }
.prompt-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, .25); }
.prompt-actions { display: flex; gap: 10px; }
.prompt-actions .cta, .prompt-actions .ghost { margin-top: 0; flex: 1; }
#prompt-overlay { display: flex; align-items: center; justify-content: center; padding: 20px; }

/* ================================ markers ================================ */
.mk svg { display: block; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .55)); }
.dotpin { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--edge); box-shadow: 0 2px 6px rgba(0, 0, 0, .45); font-weight: 800; font-size: 12px; line-height: 1; }
.self { display: grid; place-items: center; }
.self i { width: 15px; height: 15px; border-radius: 50%; background: var(--self); border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35), 0 1px 4px rgba(0, 0, 0, .5); }
.self.stale i { background: var(--text-3); }
/* chase-crew location marker — a smaller teal dot, distinct from your own blue */
.mk.self.crew i { width: 13px; height: 13px; background: #22c1c3; border-width: 2.5px; }

/* ================================ popups ================================ */
.leaflet-popup-content-wrapper { background: var(--elev); color: var(--text); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
.leaflet-popup-tip { background: var(--elev); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 13px 15px; font-family: var(--font); min-width: 190px; }
.pop-eyebrow { font-weight: 700; font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--text-3); margin-bottom: 3px; }
.leaflet-popup-content h3 { font-weight: 700; font-size: 16px; margin: 0 0 9px; }
.leaflet-popup-content p { margin: 0 0 9px; font-size: 13px; color: var(--text-2); }
a.dir-btn { display: flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; background: var(--accent); color: #fff; font-weight: 700; font-size: 14px; padding: 10px; border-radius: 9px; }
a.dir-btn:active { background: var(--accent-h); }
.leaflet-popup-close-button { width: 44px !important; height: 44px !important; font: 700 24px/44px var(--font) !important; color: var(--text-2) !important; padding: 0 !important; right: 3px; top: 3px; text-align: center; z-index: 3; background: var(--elev-2); border-radius: 11px; }
.leaflet-popup-close-button:hover, .leaflet-popup-close-button:active { color: var(--text) !important; background: var(--line); }
.pop-eyebrow, .leaflet-popup-content h3 { padding-right: 42px; }

.leaflet-bar a { background: rgba(22, 27, 34, .85) !important; color: var(--text) !important; border-color: var(--line) !important; }
.leaflet-top.leaflet-left { margin-top: 66px; }
.leaflet-control-attribution { background: rgba(13, 17, 23, .7) !important; color: var(--text-3) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--text-3) !important; }

/* waypoint / imported-layer name label beside its dot */
.wp-tip { background: rgba(13, 17, 23, .82); color: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; font-weight: 600; font-size: 11px; white-space: nowrap; box-shadow: none; }
.wp-tip::before { display: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .sheet, .peek-chev { transition: none; } }
