/* ═══════════════════════════════════════════
   DESIGN TOKENS — nautical instrument palette
   Dark: deep ocean + amber instruments + cyan heading
   Light: fog-white + navy + amber accents
═══════════════════════════════════════════ */
:root {
  /* ── Palette ── */
  --bg:        #0a1628;
  --bg2:       #0f1e38;
  --bg3:       #162444;
  --surface:   #1a2d50;
  --border:    #2a4070;
  --text:      #e8eef8;
  --text2:     #8fa8cc;
  --accent:    #f59e0b;
  --accent2:   #00d4ff;
  --on-accent: #000;   /* text/glyph colour that sits ON an --accent fill (light mode flips to #fff) */
  --pill-bg:   rgba(10,22,40,0.62); /* over-map glass: tide cards + wind/AIS/warn/orient/trip pills */
  --pill-fg:   #eaf1fb;             /* fixed light text on that glass — same in both themes */
  --danger:    #ef4444;
  --success:   #10b981;
  --warn:      #f97316;
  --kpi-bg:    rgba(15,30,56,0.92);
  --shadow:    0 4px 24px rgba(0,0,0,0.5);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.35);
  /* ── Shape ── */
  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 5px;
  /* ── Typography ── */
  --font-mono: 'Courier New', monospace;
  --font-main: system-ui, -apple-system, sans-serif;
  /* ── Touch targets ── */
  --touch:     72px;
  /* Bottom row: 6 buttons + 5 inner gaps + 2×12px margins must fit 100vw */
  --btn:       clamp(44px, calc((100vw - 24px) / 6.8), 72px);
  --btn-gap:   clamp(6px,  calc((100vw - 24px - 6 * var(--btn)) / 5), 12px);
}
[data-theme="light"] {
  --bg:        #e8eef8;
  --bg2:       #d8e4f0;
  --bg3:       #c8d8e8;
  --surface:   #f0f4fc;
  --border:    #b0c4de;
  --text:      #0a1628;
  --text2:     #3a5478;
  --accent:    #1a2d50;
  --accent2:   #0284c7;
  --on-accent: #fff;   /* white text/glyph on the navy accent fill (buttons, badges, active states) */
  --pill-bg:   rgba(6,16,32,0.55);  /* light mode: semi-transparent glass to soften contrast (was 0.86). A55 taste-dial — raise if white pill text washes out over pale sea. */
  --kpi-bg:    rgba(240,244,252,0.95);
  --shadow:    0 4px 24px rgba(0,0,50,0.18);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: var(--font-main); background: var(--bg); color: var(--text); }

/* ─── MAP CANVAS ─── */
#map-canvas {
  position: fixed; top: var(--hdr); left: 0; right: 0; bottom: 0;
  width: 100%; height: calc(100% - var(--hdr));
  touch-action: none;
  cursor: crosshair;
}
/* Radar sits on its own canvas — no touch events, floats above map */
#radar-canvas {
  position: fixed;
  top: calc(var(--hdr) + 10px); right: 10px;
  width: 116px; height: 116px; /* internal buffer is DPR-scaled (Stage 40) for crispness */
  z-index: 101; pointer-events: none;
  opacity: 0.88;
}

/* ─── FIXED HEADER ─── */
/* Header height (portrait: temp/GPS/hamburger stack; landscape: single KPI row) */
:root { --hdr: 84px; --hdr-col: 52px; }

#top-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--hdr);
  background: var(--kpi-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex; flex-direction: row;   /* single flex row — left column + cards column */
  z-index: 200;
  padding: 0;
}

/* ─── LEFT COLUMN (landscape only): hamburger, vertically centred ─── */
#hdr-left-col {
  width: var(--hdr-col); flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
}
#header-menu-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  border: none;
  background: transparent; color: var(--text);
  cursor: pointer; font-size: 20px;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}
#header-menu-btn:active { background: var(--bg3); }
/* Stage 22: hamburger relocated into the first KPI card in portrait (under GPS). */
#kpi-card-menu {
  display: none;                 /* portrait-only; shown in the portrait media query */
  align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text);
  cursor: pointer; padding: 0; margin-top: 7px;
  -webkit-tap-highlight-color: transparent;
}
#kpi-card-menu:active { opacity: 0.6; }

/* ─── KPI COLUMN: single row of 3 cards ─── */
#kpi-col {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.kpi-row {
  display: flex; align-items: stretch; flex: 1;
  border-bottom: 1px solid var(--border);
  min-height: 0;
}
.kpi-row:last-child { border-bottom: none; }

/* ─── KPI BAR (inside header) ─── */
#kpi-bar {
  flex: 1; display: flex; align-items: stretch; flex-direction: column;
  pointer-events: none;
  min-width: 0;
}
.kpi {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  border-right: 1px solid var(--border);
  padding: 3px 2px 2px;
  pointer-events: all;
  cursor: pointer;
  transition: background .15s;
  user-select: none; text-align: center;
  overflow: hidden;
}
.kpi:last-child { border-right: none; }
.kpi:active { background: var(--bg3); }
.kpi-label {
  font-size: clamp(7px, 1.8vw, 10px); font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text2);
  white-space: nowrap; line-height: 1.2;
}
/* Titles removed — value now fills the card. Fluid size maximised to the card width
   with a few px of breathing room; the widest content is Time ("23:59", 5 mono chars).
   Verify on the A55 in the gate — one-line tuning knob if it clips or under-fills. */
.kpi-value {
  font-family: var(--font-mono);
  font-size: clamp(22px, 8.4vw, 38px); font-weight: 700;
  color: var(--accent); line-height: 1.05;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
#kpi-clock { font-weight: 800; }
/* Row 2 cards: same count so same sizing; wind value compacted by JS */
.kpi.kpi-r2 .kpi-value {
  color: var(--accent);
  font-size: clamp(10px, 2.9vw, 19px);
}
/* Sub-line under a header value: SOG unit ("kts") / COG cardinal ("NE"). With the
   titles gone this line is the card's identifier, so it shows in BOTH orientations. */
.kpi-sub {
  font-family: var(--font-mono);
  font-size: clamp(9px, 2.5vw, 13px); font-weight: 700;
  color: var(--text2); line-height: 1.15;
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
/* Units hidden by default — kept in DOM so JS update logic still works. (The trip
   Dist unit still uses this; only the header SOG unit was reclassed to .kpi-sub.) */
.kpi-unit { display: none; }

/* Portrait (default): value stacked over its sub-line.
   Landscape: lay them out inline so SOG reads "5.2 kts" and COG "045° NE" on one line. */
@media (orientation: landscape) {
  .kpi-row .kpi { flex-direction: row; align-items: center; gap: 4px; }
  .kpi-row .kpi .kpi-sub { font-size: 13px; }
}

/* Clock-card extras (temperature + GPS) are portrait-only; hidden by default so
   landscape uses the pills instead. */
.kpi-clock-extra { display: none; }

/* Portrait-only header proportions (Stage 9): the clock card is halved and narrowed
   with temperature stacked beneath it; SOG/COG take the freed width at a larger size.
   The two value clamps below are the on-device tuning knobs if anything clips. */
@media (orientation: portrait) {
  .kpi-row .kpi:first-child { flex: 0.6; }               /* narrower clock card */
  #kpi-clock { display: none; }                          /* Stage 22: clock moved to the tide NOW card */
  .kpi-row .kpi .kpi-sub { font-size: clamp(11px, 4.2vw, 19px); }  /* Stage 9: temp/GPS/units match the clock */
  .kpi-row .kpi:nth-child(2) .kpi-value,
  .kpi-row .kpi:nth-child(3) .kpi-value {
    font-size: clamp(24px, 10vw, 44px);                  /* SOG/COG grow into the freed width */
  }
  .kpi-clock-extra { display: none; }                   /* Stage C: temp + GPS move to the right-column pills; first card is hamburger-only, like landscape */
  #hdr-left-col { display: none; }                       /* Stage 22: no left column in portrait -> 3 columns */
  #kpi-card-menu { display: flex; }                     /* Stage 22: hamburger below GPS in the first card */
  .civ-label::after { content: ':'; }                   /* Stage 24: portrait pills read "AIS: 2" / "WARN: 0" */
}

/* ─── ZOOM BUTTONS — bottom left, side by side ─── */
#zoom-btns {
  display: contents;
}
.zoom-btn {
  position: fixed; bottom: 20px;
  width: var(--btn); height: var(--btn);
  background: var(--kpi-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: clamp(20px, 5vw, 28px); line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
  transition: border-color .15s, background .15s;
  user-select: none; -webkit-tap-highlight-color: transparent;
  z-index: 100;
}
.zoom-btn:active { border-color: var(--accent); background: var(--surface); }
/* Right-aligned pair, bottom-right (portrait + large landscape). Plus at far right. */
#zoom-btn-in  { right: 12px; }
#zoom-btn-out { right: calc(12px + var(--btn) + var(--btn-gap)); }

/* ─── HAMBURGER: now lives inside #top-header as #header-menu-btn ─── */

/* ─── ORIENT/ANCHOR/WEATHER buttons removed from bottom row — now in menu ─── */
/* orient-btn is now a visible compass pill inside #pill-row: portrait it stacks under
   the AIS pill (right side); landscape it detaches to bottom-left. */
/* Stage B: orient is now a square map button, same --btn size as zoom/recentre. It holds
   the LEFT slot of a fixed, centred orient+recentre pair (recentre takes the right slot
   and only appears when panned — its slot is reserved, so orient never shifts). */
#orient-btn {
  position: fixed; bottom: 20px; z-index: 100;
  left: calc(50% - var(--btn) - var(--btn-gap)/2);
  width: var(--btn); height: var(--btn);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  pointer-events: auto; cursor: pointer;
  background: var(--kpi-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  backdrop-filter: blur(8px);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
#orient-btn:active { border-color: var(--accent); background: var(--surface); }
#orient-btn .compass-svg { width: 22px; height: 22px; }
.orient-label { font-family: var(--font-mono); font-size: 10px; font-weight: 700; line-height: 1; }
#weather-btn {
  display: none; /* moved to menu */
}
#anchor-btn {
  transition: color .2s, border-color .2s;
  display: none; /* moved to menu */
}
#anchor-btn.active { color: var(--accent); border-color: var(--accent); }
#anchor-btn.alarming { color: var(--danger); border-color: var(--danger); animation: pulse-red 1s infinite; }
@keyframes pulse-red { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.6); } 50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); } }

/* ─── RECORD BTN — bottom-center, same row as zoom buttons ─── */
#record-btn {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  height: var(--btn); padding: 0 20px;
  background: var(--bg3); border: 2px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 13px; font-weight: 700; letter-spacing: .08em;
  cursor: pointer; z-index: 100;
  display: flex; align-items: center; gap: 8px;
  backdrop-filter: blur(8px);
  -webkit-tap-highlight-color: transparent;
  transition: border-color .2s, background .2s;
}
#record-btn.recording { border-color: var(--danger); color: var(--danger); }
/* Portrait: START/STOP sits bottom-left (was centred). Landscape keeps it centred. */
@media (orientation: portrait) {
  #record-btn { left: 12px; transform: none; }
}
#record-btn .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text2); transition: background .2s; }
#record-btn.recording .rec-dot { background: var(--danger); animation: blink 1.2s infinite; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:.3; } }
/* Light mode: Start/Stop button goes white to match the zoom buttons (both read --kpi-bg).
   Scoped to light only — dark mode keeps its --bg3 fill. */
[data-theme="light"] #record-btn { background: var(--kpi-bg); }

/* ─── MODALS ─── */
.modal-backdrop {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,10,.78);
  z-index: 500; display: none; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; animation: backdrop-in .18s ease forwards; }
@keyframes backdrop-in { from { opacity:0; } to { opacity:1; } }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 600px;
  max-height: 90vh; overflow-y: auto;
  padding: 0 20px 36px;
  margin-top: auto; /* push to bottom in normal flow (not via flex align) so sticky header works on Android WebView */
  transform: translateY(100%); transition: transform .28s cubic-bezier(.32,0,.18,1);
  -webkit-overflow-scrolling: touch;
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal.center-modal {
  border-radius: var(--radius); max-width: 440px;
  margin: auto; transform: scale(.92); transition: transform .22s ease;
}
.modal-backdrop.open .modal.center-modal { transform: scale(1); }

/* Modal header — sticky so X stays visible when content scrolls.
   MUST be a direct child of .modal (the scroll container) — same as Settings modal. */
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  position: sticky; top: 0; z-index: 2;
  background: var(--bg2);
}
/* Scrollable body — passthrough (no longer used) */
.modal-title { font-size: 18px; font-weight: 800; color: var(--text); letter-spacing: -.01em; }
.modal-close {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
  font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.modal-close:active { background: var(--surface); color: var(--text); }

/* Section header inside modals — replaces ad-hoc inline divs */
.section-head {
  font-size: 10px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text2);
  padding-bottom: 8px; margin-bottom: 10px; margin-top: 20px;
  border-bottom: 1px solid var(--border);
}
.section-head:first-child { margin-top: 4px; }

/* Modal action bar — full-width button row at bottom of forms */
.modal-actions {
  display: flex; gap: 10px; margin-top: 20px;
}
.modal-actions .btn { flex: 1; }

/* ─── FORMS ─── */
label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text2); margin-bottom: 4px; margin-top: 14px; }
input, textarea, select {
  width: 100%; padding: 12px 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 16px; font-family: var(--font-main);
  outline: none; transition: border-color .2s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent2); }
select option { background: var(--bg2); }
textarea { resize: vertical; min-height: 80px; }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--touch); padding: 0 20px;
  border-radius: var(--radius-sm); border: none;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { opacity: .8; transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-secondary { background: var(--bg3); border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { height: 38px; padding: 0 14px; font-size: 13px; }
.btn-full { width: 100%; }

/* ─── MENU DRAWER ─── */
#menu-drawer {
  position: fixed; top: 0; left: -288px; width: 288px; height: 100%;
  background: var(--bg2); border-right: 1px solid var(--border);
  z-index: 600; transition: left .28s cubic-bezier(.32,0,.18,1);
  overflow-y: auto; padding: 0 0 24px;
  /* scrollbar */
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
#menu-drawer.open { left: 0; }
#menu-overlay { position: fixed; top:0; left:0; width:100%; height:100%; z-index: 599; display: none; }
#menu-overlay.open { display: block; }
.menu-header {
  min-height: var(--hdr);
  padding: 16px 20px 14px;
  background: linear-gradient(180deg, var(--bg3) 0%, var(--bg2) 100%);
  border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.menu-header-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.menu-header h2 { font-size: 22px; font-weight: 900; color: var(--accent); letter-spacing: .04em; }
.menu-close-btn {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 50%;
  width: 40px; height: 40px; font-size: 18px; color: var(--text2);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s; flex-shrink: 0;
}
.menu-close-btn:active { background: var(--surface); color: var(--text); }
.menu-header p { font-size: 11px; color: var(--text2); margin-top: 2px; line-height: 1.4; }
.menu-tagline { font-size: 10px; color: var(--text2); opacity: 0.6; font-style: italic; }
.menu-version-badge {
  display: inline-flex; align-items: center;
  background: var(--accent); color: var(--on-accent); border-radius: 10px;
  padding: 1px 7px; font-size: 10px; font-weight: 800; letter-spacing: .04em;
  margin-left: 8px; vertical-align: middle;
}
.menu-divider {
  height: 1px; background: var(--border); margin: 4px 0; opacity: 0.5;
}
.menu-section-label {
  font-size: 9px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text2);
  padding: 8px 20px 4px; opacity: 0.65;
}
.menu-item {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 20px; cursor: pointer; color: var(--text);
  font-size: 15px; font-weight: 600; transition: background .12s;
  -webkit-tap-highlight-color: transparent; position: relative;
}
.menu-item:active { background: var(--bg3); }
.menu-item .mi-icon { font-size: 20px; width: 26px; text-align: center; flex-shrink: 0; }
.menu-item .mi-badge {
  margin-left: auto; font-size: 10px; color: var(--text2); font-weight: 700;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 2px 8px;
}
.menu-install-row { cursor: default; }
.menu-install-row .install-pills { margin-left: auto; display: flex; gap: 16px; }
.install-pill {
  font-size: 13px; font-weight: 700; color: var(--accent);
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px 16px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.install-pill:active { background: var(--accent); color: var(--on-accent); }
@keyframes flash-hi { 0%,100% { background: transparent; } 50% { background: var(--accent); color: var(--on-accent); } }
.flash-hi { animation: flash-hi 0.5s ease-in-out 5; border-radius: 4px; padding: 0 3px; }

/* ─── LIST ITEMS (trips, markers, logbook) ─── */
.trip-item, .marker-item, .log-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 15px; margin-bottom: 8px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.trip-item:active, .marker-item:active, .log-item:active {
  border-color: var(--accent2); background: var(--surface);
}
.item-title { font-size: 15px; font-weight: 700; color: var(--text); }
.item-meta { font-size: 12px; color: var(--text2); margin-top: 4px; line-height: 1.5; }
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
.route-strip {
  background: var(--surface2, rgba(0,212,255,0.06));
  border: 1px solid rgba(0,212,255,0.35);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.route-strip-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.route-strip-list { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 8px; }
.route-chip {
  font-size: 12px;
  color: var(--text2);
  background: rgba(0,212,255,0.10);
  border-radius: 6px;
  padding: 2px 7px;
}
.route-chip.active { color: var(--text); background: rgba(0,212,255,0.28); font-weight: 700; }

/* ─── ICON PICKER ─── */
.icon-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 8px;
}
.icon-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 24px; background: var(--bg3); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: border-color .15s;
}
.icon-cell.selected { border-color: var(--accent); background: var(--surface); }
.icon-cell:active { border-color: var(--accent2); }

/* ─── WEATHER PANEL ─── */
.wx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.wx-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; text-align: center; min-height: 96px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.wx-icon { font-size: 32px; }
.wx-val { font-family: var(--font-mono); font-size: 22px; font-weight: 700; color: var(--accent2); margin: 4px 0; }
.wx-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: .08em; }
.tide-bar { height: 6px; background: var(--bg3); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.tide-fill { height: 100%; background: var(--accent2); border-radius: 3px; transition: width .5s; }

/* ─── KPI POPUP ─── */
.kpi-popup {
  position: fixed; z-index: 800;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 210px; box-shadow: var(--shadow);
}

.kpi-popup-row { display: flex; justify-content: space-between; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--border); }
.kpi-popup-row:last-child { border-bottom: none; }
.kpi-popup-label { font-size: 12px; color: var(--text2); }
.kpi-popup-val { font-family: var(--font-mono); font-size: 18px; color: var(--accent); font-weight: 700; }
#kpi-popup[data-kpi="speed"] .kpi-popup-label,
#kpi-popup[data-kpi="cog"] .kpi-popup-label { font-size: 18px; }
#kpi-gps.gps-nofix { animation: blink 1.2s infinite; }

/* ─── TOAST ─── */

/* ─── ANCHOR MODAL ─── */
.radius-display {
  font-family: var(--font-mono); font-size: 48px; font-weight: 900;
  color: var(--accent); text-align: center; margin: 16px 0;
}
.radius-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ─── LOGBOOK ─── */
.log-type-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.log-tab { height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; }
.log-tab.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* ─── UNITS GRID ─── */
.units-grid { display: grid; gap: 4px; }
.unit-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.unit-row:last-child { border-bottom: none; }
.unit-name { font-size: 14px; font-weight: 600; }
.unit-options { display: flex; gap: 6px; }
.unit-opt { height: 34px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 13px; cursor: pointer; transition: all .15s; }
.unit-opt.selected { background: var(--accent2); color: #000; border-color: var(--accent2); }
/* Light mode: lift contrast — firm dark text on unselected, navy+white on selected (matches buttons). */
[data-theme="light"] .unit-opt { color: var(--text); }
[data-theme="light"] .unit-opt.selected { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.ais-slider-row, .ais-dual-row { flex-direction: column; align-items: stretch; gap: 8px; }
/* Stage 18: dual-thumb radius slider (0 -> Discovery Radius). Base track = blue discovery
   zone; danger (red) and warning (orange) segments overlay from the left. */
.dual-slider {
  position: relative; height: 20px; width: 100%;
  margin: 26px 0 6px; border-radius: 10px;
  background: rgba(56,200,255,0.20); touch-action: none;
}
.dseg-danger, .dseg-warn { position: absolute; top: 0; bottom: 0; }
.dseg-danger { left: 0; width: 0; background: rgba(239,68,68,0.55); border-radius: 10px 0 0 10px; }
.dseg-warn { background: rgba(245,158,11,0.55); }
.dthumb {
  position: absolute; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.5);
  touch-action: none; cursor: grab;
}
.dthumb-danger { background: #ef4444; z-index: 4; }
.dthumb-warn { background: #f59e0b; z-index: 3; }
.dlbl {
  position: absolute; top: -22px; transform: translateX(-50%);
  font-size: 12px; font-weight: 700; white-space: nowrap; pointer-events: none;
}
.dlbl-danger { color: #ef4444; }
.dlbl-warn { color: #f59e0b; }
/* Stage 16: radar master OFF hides the radar + point-of-sail pill (one "radar group"); in
   portrait the wind/AIS/warn/orient stack climbs up into the radar's slot. */
body.radar-off #radar-canvas { display: none; }
body.radar-off #sail-status  { display: none !important; }
@media (orientation: portrait) {
  body.radar-off #wind-widget { top: calc(var(--hdr) + 10px); }
  body.radar-off #pill-row    { top: calc(var(--hdr) + 10px + 50px); }
}

/* ── Settings accordion + standardised rows (v4.38) ── */
.settings-section > .section-head {
  cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--text); margin-top: 18px;
}
.settings-section:first-of-type > .section-head { margin-top: 4px; }
.settings-section > .section-head::after { content: '▾'; font-size: 11px; color: var(--text2); font-weight: 400; }
.settings-section.collapsed > .section-head::after { content: '▸'; }
.settings-section.collapsed > .section-body { display: none; }
.settings-section:not(.collapsed) > .section-head { color: var(--accent); }  /* expanded title highlighted */
.setting-sub { display: block; font-size: 10px; color: var(--text2); font-weight: 400; margin-top: 1px; }
.overlay-block { border-left: 2px solid var(--border); padding-left: 10px; margin: 4px 0; }
.unit-row.child-row { padding-left: 16px; border-left: 2px solid var(--border); }
.overlay-block .unit-row:last-child { border-bottom: none; }
.setting-select { width: auto; padding: 8px 12px; font-size: 14px; }
.wb-input { width: 78px; padding: 8px 10px; font-size: 14px; text-align: center; }
.key-row { flex-direction: column; align-items: flex-start; gap: 6px; }
.key-input-row { display: flex; gap: 8px; width: 100%; }
.key-input { flex: 1; font-size: 13px; font-family: var(--font-mono); padding: 8px 10px; border-radius: var(--radius-xs); border: 1px solid var(--border); background: var(--bg2); color: var(--text); }
.setting-note { font-size: 11px; color: var(--text2); }
.about-topic { font-weight: 700; font-size: 13px; color: var(--text); margin-top: 14px; }
.about-topic:first-child { margin-top: 0; }
.about-text { font-size: 12.5px; color: var(--text2); line-height: 1.6; margin-top: 3px; }
.unit-preset-row { display: flex; gap: 8px; margin-bottom: 12px; }
.unit-preset-row .btn { flex: 1; }

/* ─── COMPASS ROSE (orient btn) ─── */
.compass-svg { width: 26px; height: 26px; }

/* anchor circle drawn directly on main map canvas */

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── CHART CONTAINER ─── */
.chart-container { position: relative; height: 160px; margin-top: 12px; }

/* ─── SPARKLINE (SOG popup inline canvas) ─── */
.sparkline-wrap { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.sparkline-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 4px; }
#sog-sparkline { display: block; width: 100%; height: 48px; border-radius: var(--radius-xs); }

/* ─── WIND FRESHNESS DOT ─── */
.wind-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-left: 3px; vertical-align: middle; flex-shrink: 0;
  transition: background-color .5s;
}
.wind-dot.fresh  { background: var(--success); }
.wind-dot.aging  { background: var(--accent); }
.wind-dot.stale  { background: var(--danger); }

/* ─── KPI POPUP ─── */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 20px; font-size: 14px; font-weight: 600; z-index: 900;
  opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* GPS indicator removed from map — kept hidden for JS compat */
#gps-indicator { display: none; }

/* ─── POSITION MARKER ─── */
.boat-marker { position: absolute; transform: translate(-50%,-50%); pointer-events: none; z-index: 60; }

/* ─── SEPARATOR ─── */
.sep { height: 1px; background: var(--border); margin: 12px 0; }

/* Screen wake lock icon */
#wake-icon { font-size: 16px; margin-left: auto; }

/* tab content */
.tab-content { display: none; }
.tab-content.active { display: block; }

.empty-state { text-align: center; padding: 32px; color: var(--text2); }
.empty-state .es-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* coord display */
.coord-display { font-family: var(--font-mono); font-size: 13px; color: var(--accent2); background: var(--bg3); padding: 8px 10px; border-radius: var(--radius-sm); margin-top: 6px; }

/* planning section */
.plan-card { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 10px; }
.plan-card h4 { font-size: 13px; color: var(--text2); text-transform: uppercase; letter-spacing:.08em; margin-bottom: 8px; }
.plan-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.plan-ok { color: var(--success); }
.plan-warn { color: var(--warn); }
.plan-bad { color: var(--danger); }

/* ─── RESPONSIVE ─── */
@media (max-width: 380px) {
  /* Keep padding tight on narrow phones; the .kpi-value clamp handles the size. */
  .kpi { padding: 2px 4px; min-width: 0; }
}

/* ─── RE-CENTRE BUTTON ─── */
#recentre-btn {
  position: fixed; bottom: calc(20px + var(--btn) + 12px); right: 12px;
  width: var(--btn); height: var(--btn);
  background: var(--accent); border: none;
  border-radius: var(--radius-sm); color: var(--on-accent);
  font-size: 22px; cursor: pointer; z-index: 100;
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 12px rgba(245,158,11,0.5);
}
/* Stage 25: portrait recentre defined AFTER the base rule so it wins on `bottom`.
   Bottom-centre, same row as START (left) and the zoom pair (right). */
@media (orientation: portrait) {
  #recentre-btn { bottom: 20px; left: calc(50% + var(--btn-gap)/2); right: auto; transform: none; }
}

/* ─── GPS INFO POPUP ─── */
#gps-popup {
  position: fixed; top: calc(var(--hdr) + 8px + 32px + 6px); left: 50%; transform: translateX(-50%);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  min-width: 220px; box-shadow: var(--shadow);
  z-index: 800; display: none;
}
#gps-popup .gps-row { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--border); gap: 12px; }
#gps-popup .gps-row:last-child { border-bottom: none; }
#gps-popup .gps-label { color: var(--text2); font-size: 12px; }
#gps-popup .gps-val { font-family: var(--font-mono); font-size: 18px; color: var(--accent2); font-weight: 700; }
#gps-popup .gps-val-sm { font-family: var(--font-mono); font-size: 13px; color: var(--accent2); font-weight: 700; }
/* ─── TIDE HUD OVERLAY — 3 tide cards ─── */
#tide-hud {
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s;
}
#tide-hud.visible { opacity: 1; }
#tide-hud-cards {
  display: flex;
  gap: 6px;
}
.thud-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 72px;
  padding: 5px 3px 5px;
  border-radius: 8px;
  background: var(--pill-bg);
}
/* Row 2 (middle): tide TIME — white, bigger */
.thud-time {
  font-family: 'Courier New', monospace;
  font-size: 20px;
  font-weight: 900;
  color: rgba(255,255,255,0.85);
  line-height: 1.05;
  letter-spacing: -.01em;
}
.thud-current .thud-time {
  color: #ffffff;
  text-shadow: 0 0 12px rgba(245,158,11,0.5);
}
.thud-clock { display: block; }
.thud-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #ffffff;
  margin-top: 2px;
}
.thud-current .thud-label {
  color: #f59e0b;
}

/* ─── LEFT STACK: tide HUD + trip widget ─── */
#left-stack {
  position: fixed;
  top: calc(var(--hdr) + 8px);
  left: 12px;
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}

/* ─── TRIP WIDGET — Trip / Dist / Dest, styled like tide cards ─── */
#trip-hud {
  display: flex; gap: 6px; pointer-events: none;
  align-self: flex-start;                    /* pill hugs its own content, not stretched to the stack */
  background: var(--pill-bg);           /* same dimmed pill as #gps-widget */
  border-radius: 6px; padding: 4px 6px;
}
/* The widget shares the .trip-item class with the modal list items (line ~394),
   which carry an opaque var(--bg3) fill + border. Strip those here so the three
   items are transparent and only the pill above shows — matching the GPS widget. */
#trip-hud .trip-item {
  background: transparent; border: none; border-radius: 0; margin-bottom: 0;
}
#trip-hud .trip-item {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  width: 72px; padding: 5px 3px;
}
.trip-title {
  font-size: 11px; font-weight: 800; letter-spacing: .04em;
  text-transform: uppercase; color: #ffffff;
}
.trip-val {
  font-family: 'Courier New', monospace;
  font-size: 20px; font-weight: 900;
  color: rgba(255,255,255,0.85); line-height: 1.05;
}

/* ─── WIND / GPS OVERLAY WIDGETS (right side, over dimmed background) ─── */
#wind-widget {
  position: fixed; right: 10px; width: 116px;
  z-index: 101; pointer-events: none; color: var(--pill-fg);
  background: var(--pill-bg); border-radius: 6px;
  padding: 4px 6px; text-align: center;
  top: calc(var(--hdr) + 10px + 116px + 4px + 44px);
}
/* Temp / GPS / AIS pill row. Portrait: right side, stacked under the wind widget.
   temp + GPS are hidden here (they live in the clock card), so only AIS shows. */
#pill-row {
  position: fixed; z-index: 101; pointer-events: none;
  right: 10px; width: 116px; top: calc(var(--hdr) + 10px + 116px + 4px + 44px); /* Stage C: column sits just below the radar + sail-status */
  display: flex; flex-direction: column; gap: 6px; align-items: stretch;
}
#gps-widget, #ais-widget, #warn-widget {
  background: var(--pill-bg); border-radius: 6px;
  padding: 4px 6px; text-align: center; white-space: nowrap;
}
#gps-widget { display: none; }   /* portrait: these live in the clock card */
#ais-widget { display: none; }                 /* JS shows it when the AIS toggle is on */
#warn-widget { display: none; pointer-events: auto; cursor: pointer; }  /* JS shows it when the Marine-warnings toggle is on; tappable → opens Weather & Sea modal */
.wind-row {
  display: flex; align-items: center; justify-content: center;
  gap: 5px; line-height: 1.3; white-space: nowrap;
}
.wind-primary   { font-family: var(--font-mono); font-size: 16px; font-weight: 700; }
#gps-widget, #ais-widget, #warn-widget { font-family: var(--font-mono); font-size: 13px; font-weight: 700; color: #ffffff; }
/* Centre the AIS + warnings pills in the column (portrait #pill-row is align-items:flex-end;
   this overrides for these two, matching how #orient-btn centres itself). Harmless in
   landscape, where #pill-row already centres. */
#ais-widget, #warn-widget { align-self: center; font-size: 16px; }
/* Stage 23: GPS/AIS/WARN share a <label><value> structure. Portrait keeps the inline
   pill look (⚠/AIS + value on one line); landscape lays them out as tide-style cards. */
#ais-widget.civ-on, #warn-widget.civ-on { display: flex; align-items: baseline; gap: 5px; }
#wind-card, #temp-card { display: none; pointer-events: auto; cursor: pointer; }   /* Stage 25: WIND/TEMP show in landscape only; Stage 36: tappable, opens Weather modal */
.civ-label, .civ-val { font-family: var(--font-mono); font-weight: 700; color: #ffffff; font-size: 16px; white-space: nowrap; }

/* Stage C: portrait right column = five uniform single-row pills (GPS/AIS/WARN/WIND/TEMP),
   same width, stacked evenly below the radar. Landscape keeps its own tide-card styling. */
@media (orientation: portrait) {
  #gps-widget, #wind-card, #temp-card { display: flex; }
  #gps-widget, #ais-widget.civ-on, #warn-widget.civ-on, #wind-card, #temp-card {
    flex-direction: row; align-items: baseline; justify-content: center; gap: 5px;
    align-self: stretch; width: auto;
    padding: 4px 6px; background: var(--pill-bg); border-radius: 6px;
  }
  #pill-row .civ-label, #pill-row .civ-val { font-size: 14px; }
  #wind-widget { display: none; }   /* retired: wind now shows via #wind-card */
}

/* Landscape: wind widget moves to the LEFT of the radar (right-aligned);
   GPS moves to map-centre (between tides and radar). */
@media (orientation: landscape) {
  .modal.center-modal { max-width: 600px; }  /* match standard modals' width in landscape */
  :root { --hdr: 78px; }                       /* Stage 24: shorter header in landscape */
  #wind-widget { display: none; }              /* Stage 25: wind/temp move into cards in landscape */
  /* GPS / AIS / WARN as one centred row of tide-style cards, between the tide HUD and radar */
  #pill-row {
    right: 134px; left: 246px; width: auto; transform: none;   /* Stage 25: off-centre, clear of the tide HUD & radar */
    top: calc(var(--hdr) + 10px);
    flex-direction: row; gap: 6px; align-items: flex-start; justify-content: center;
  }
  #gps-widget, #wind-card, #temp-card { display: flex; }   /* always show in landscape (as cards) */
  #gps-widget,
  #ais-widget.civ-on,
  #warn-widget.civ-on,
  #wind-card,
  #temp-card {
    flex-direction: column; align-items: center; justify-content: center;
    width: 72px; padding: 5px 3px; gap: 0;
    border-radius: 8px; background: var(--pill-bg);
  }
  .civ-label { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
  .civ-val   { font-size: 17px; font-weight: 900; color: rgba(255,255,255,0.9); line-height: 1.05; }
  #record-btn { left: 12px; transform: none; right: auto; }   /* Stage B: START bottom-left, mirroring portrait; orient uses the base centred-pair slot */
  /* Landscape: centre the orient+recentre pair in the gap between START (left) and the zoom
     pair (right) to avoid mistaps. Recentre takes the centre-left slot, orient sits one button
     to its left, so the pair centres near the midpoint of the START->zoom gap. */
  #orient-btn   { left: calc(50% - 2 * var(--btn) - 3 * var(--btn-gap) / 2); }
  #recentre-btn { bottom: 20px; left: calc(50% - var(--btn) - var(--btn-gap)/2); right: auto; transform: none; }
}

/* Landscape short screens: radar drops to record-button level, so the zoom pair
   moves into the gap left of the radar to avoid overlap. */
@media (orientation: landscape) and (max-height: 480px) {
  #zoom-btn-in  { right: calc(10px + 116px + 12px); }
  #zoom-btn-out { right: calc(10px + 116px + 12px + var(--btn) + var(--btn-gap)); }
}
