/* ══════════════════════════════════════════════════════════
   Map/AR feature — ported from ECCsailing (eccsailing.html).
   All rendered inside #maar-root, a fixed overlay that sits
   BELOW the ECC-App header. Opened via the header "Map/AR"
   button; the "Sail" button closes it (hideMapAR()).
   Namespaces (.poi-*, .camera-*, #setup-*, #ar-canvas, etc.)
   are unique to Map/AR — verified non-colliding with Swimscapes.
══════════════════════════════════════════════════════════ */
#maar-root {
  position: fixed; left: 0; right: 0; top: 0; bottom: 0;
  z-index: 300; display: none; background: #0d1f2d; overflow: hidden;
}
#maar-root #map { width: 100%; height: 100%; }

    /* ── CAMERA ELEMENTS ────────────────────────────────── */
    #camera-feed {
      display: none; position: absolute; inset: 0;
      width: 100%; height: 100%; object-fit: cover;
    }
    #camera-overlay {
      display: none; position: absolute; inset: 0;
      pointer-events: none; overflow: hidden;
    }
    .camera-poi {
      position: absolute; transform: translateX(-50%) translateY(-60%);
      text-align: center; pointer-events: auto;
    }
    .camera-poi .poi-img-wrap { box-shadow: 0 0 12px rgba(0,0,0,0.7); }
    .camera-brg {
      display: inline-block; margin-top: 2px;
      background: rgba(10,24,38,0.85); border: 1px solid #2e86c1;
      border-radius: 3px; padding: 1px 6px; font-size: 10px; color: #7fb3d3;
      white-space: nowrap;
    }

    /* ── HEADING NUDGE BAR ───────────────────────────────── */
    #heading-nudge {
      display: none; position: absolute; bottom: 22px; left: 8px; right: 8px;
      z-index: 850; background: rgba(10,24,38,0.88);
      border: 1px solid #1e4d72; border-radius: 8px;
      padding: 6px 10px; flex-direction: column; gap: 4px;
    }
    #heading-nudge.visible { display: flex; }
    #nudge-label { font-size: 11px; color: #85c1e9; white-space: nowrap; min-width: 70px; }
    #nudge-slider { flex: 1; accent-color: #2e86c1; }
    #nudge-reset {
      background: none; border: 1px solid #2e86c1; border-radius: 4px;
      color: #5dade2; font-size: 14px; padding: 2px 6px; cursor: pointer;
    }

    /* ── VERTICAL CAMERA SLIDERS (HoE left, Opacity right) ── */
    .cam-vslider {
      display: none; position: absolute; z-index: 860;
      flex-direction: column; align-items: center; gap: 6px;
      background: rgba(10,24,38,0.82); border: 1px solid #1e4d72;
      border-radius: 10px; padding: 10px 6px; pointer-events: auto;
    }
    .cam-vslider.visible { display: flex; }
    #hoe-control     { left: 6px;  top: 50%; transform: translateY(-50%); }
    #opacity-control { right: 6px; top: 50%; transform: translateY(-50%); }
    .cam-vslider .vval { font-size: 12px; font-weight: 700; color: #85c1e9; white-space: nowrap; }
    .cam-vslider .vcap { font-size: 11px; color: #7fb3d3; white-space: nowrap; }
    .vrange-wrap { height: 180px; width: 28px; display: flex; align-items: center; justify-content: center; }
    .vrange {
      -webkit-appearance: none; appearance: none;
      width: 170px; height: 6px; border-radius: 3px;
      transform: rotate(-90deg); background: rgba(255,255,255,0.25);
    }
    .vrange::-webkit-slider-thumb {
      -webkit-appearance: none; appearance: none;
      width: 22px; height: 22px; border-radius: 50%;
      background: #d6eaf8; border: 2px solid #1e4d72; cursor: pointer;
    }
    .vrange::-moz-range-thumb {
      width: 22px; height: 22px; border-radius: 50%;
      background: #d6eaf8; border: 2px solid #1e4d72; cursor: pointer;
    }
    .zoombtn {
      background: none; border: 1px solid #27ae60; border-radius: 4px;
      color: #27ae60; font-size: 13px; padding: 1px 7px; cursor: pointer;
    }

    /* ── STATUS BAR — floats over map bottom ────────────── */
    #status-bar {
      position: absolute; bottom: 0; left: 0; right: 0; z-index: 800;
      background: rgba(10,24,38,0.82);
      padding: 3px 12px; font-size: 11px; color: #5d8aa8;
      text-align: center; pointer-events: none;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }

    /* ── NORTH INDICATOR ────────────────────────────────── */
    #north-indicator {
      position: absolute; top: 54px; right: 10px; z-index: 900;
      width: 36px; height: 36px; background: rgba(10,24,38,0.85);
      border: 1px solid #2e86c1; border-radius: 50%;
      display: none; align-items: center; justify-content: center;
      font-size: 13px; font-weight: 700; user-select: none;
    }
    #north-inner { display: block; transition: transform 0.3s; }

    /* ── OVERLAY PANELS (fullscreen) ────────────────────── */
    .overlay-panel {
      position: absolute; inset: 0; z-index: 1200;  /* above Leaflet controls (~800) */
      background: #080c12; display: none;
      flex-direction: column; overflow: hidden;
    }
    .overlay-panel.visible { display: flex; }

    .panel-header {
      display: flex; align-items: center; gap: 10px;
      padding: 12px 14px 10px; background: #081218;
      border-bottom: 1px solid #1e3a4f; flex-shrink: 0;
    }
    .panel-header h2 { font-size: 17px; font-weight: 700; flex: 1; color: #d6eaf8; }
    .panel-close {
      background: none; border: none; color: #5dade2; font-size: 24px;
      cursor: pointer; padding: 2px 6px; line-height: 1; -webkit-appearance: none;
    }
    .panel-body { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; min-height: 0; background: #080c12; }

    /* ── EXPLAIN PANEL ──────────────────────────────────── */
    #explain-text { font-size: 15px; line-height: 1.65; color: #b3d1ea; }
    #explain-text a { color: #5dade2; }
    #explain-text ul { margin: 6px 0 6px 18px; }
    #explain-text p { margin: 0 0 10px; }

    /* ── SETUP PANEL ────────────────────────────────────── */
    #setup-map-wrap { position: relative; height: 46vh; min-height: 260px; margin: 0 -16px 14px; }

    /* ── LOCATION 3-WAY TOGGLE ──────────────────────────── */
    .loc-toggle { display: inline-flex; border: 1px solid #2e86c1; border-radius: 8px; overflow: hidden; }
    .loc-btn {
      padding: 7px 14px; background: #11324b; color: #9dc4e0; border: none;
      border-right: 1px solid #1e4d72; font-size: 13px; font-weight: 600; cursor: pointer;
      -webkit-appearance: none;
    }
    .loc-btn:last-child { border-right: none; }
    .loc-btn.active { background: #1a5276; color: #fff; }
    #setup-map { width: 100%; height: 100%; }

    .section-label {
      font-size: 12px; color: #5d8aa8; text-transform: uppercase;
      letter-spacing: 0.5px; margin-bottom: 8px; margin-top: 16px;
    }
    .setup-btn {
      display: block; width: 100%; padding: 13px 14px; margin-bottom: 8px;
      background: #112233; border: 1px solid #1e4d72; border-radius: 8px;
      color: #d6eaf8; font-size: 15px; text-align: left; cursor: pointer;
      -webkit-appearance: none; transition: background 0.12s;
    }
    .setup-btn:active { background: #1a4a6e; }
    .setup-btn.chosen { background: #1a5276; border-color: #2e86c1; }
    .setup-btn.done-btn { background: #1a5276; border-color: #2e86c1; text-align: center; font-weight: 600; }

    #gps-status { font-size: 13px; color: #5d8aa8; min-height: 18px; margin-bottom: 8px; }

    /* compass cal */
    #compass-cal { display: none; margin-top: 12px; }
    #compass-btn-allow {
      display: block; width: 100%; padding: 12px; margin-bottom: 12px;
      background: #1e4d72; border: 1px solid #2e86c1; border-radius: 8px;
      color: #d6eaf8; font-size: 14px; text-align: center; cursor: pointer;
      -webkit-appearance: none;
    }
    .compass-ring-wrap { text-align: center; margin-bottom: 8px; }
    .compass-ring {
      display: inline-block; width: 80px; height: 80px;
      border: 2px solid #2e86c1; border-radius: 50%; position: relative;
    }
    #compass-needle {
      width: 3px; height: 38px; background: linear-gradient(to top, #555, #e74c3c);
      position: absolute; left: 50%; top: 50%;
      transform-origin: 50% 100%;
      transform: translateX(-50%) translateY(-100%) rotate(0deg);
      transition: transform 0.15s;
    }
    #heading-readout { font-size: 13px; color: #85c1e9; text-align: center; margin-bottom: 10px; }

    /* confirm overlay — sits above the full setup panel (above Leaflet controls) */
    #confirm-overlay {
      display: none; position: absolute; inset: 0; z-index: 1500;
      background: rgba(0,0,0,0.75); align-items: center; justify-content: center;
    }
    #confirm-overlay.visible { display: flex; }
    .confirm-box {
      background: #0d1f2d; border: 1px solid #2e86c1; border-radius: 10px;
      padding: 20px; max-width: 260px; text-align: center;
    }
    .confirm-box p { margin-bottom: 14px; font-size: 14px; color: #d6eaf8; line-height: 1.4; }
    #confirm-coords { display: block; font-size: 12px; color: #85c1e9; margin-top: 4px; }
    .confirm-row { display: flex; gap: 10px; justify-content: center; }
    .btn-yes { padding: 10px 22px; background: #2e86c1; border: none; border-radius: 6px; color: #fff; font-size: 14px; cursor: pointer; }
    .btn-no  { padding: 10px 22px; background: #1a2634; border: 1px solid #2e86c1; border-radius: 6px; color: #fff; font-size: 14px; cursor: pointer; }

    /* AR mode toggle */
    .mode-row { display: flex; gap: 8px; margin-bottom: 8px; }
    .mode-btn {
      flex: 1; padding: 11px 4px; border: 1px solid #1e4d72; border-radius: 7px;
      background: #112233; color: #aab7c4; font-size: 13px; text-align: center;
      cursor: pointer; -webkit-appearance: none;
    }
    .mode-btn.active { background: #1a5276; border-color: #2e86c1; color: #d6eaf8; }

    /* ── POI MARKERS ────────────────────────────────────── */
    .poi-marker { text-align: center; }
    .poi-card {
      display: inline-flex; flex-direction: column; align-items: center;
      cursor: pointer; transition: opacity 0.2s;
    }
    .poi-card.flip-up { flex-direction: column-reverse; }
    .poi-img-group { display: inline-flex; flex-direction: column; align-items: center; }
    .poi-name {
      border-radius: 4px 4px 0 0; padding: 2px 6px; margin-bottom: 0;
      font-size: 11px; font-weight: 600; color: #d6eaf8;
      background: rgba(10,24,38,0.88); border: 1px solid #1e4d72; border-bottom: none;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
      box-sizing: border-box;
    }
    .poi-img-wrap {
      border: 2px solid #2e86c1; border-radius: 6px; overflow: hidden;
      background: #1a2634; box-shadow: 0 2px 8px rgba(0,0,0,0.6);
      transition: width 0.2s, height 0.2s, border-color 0.15s;
      flex-shrink: 0;
    }
    .poi-img-wrap img { display: block; width: 100%; height: 100%; object-fit: cover; }
    .poi-placeholder {
      width: 100%; height: 100%; display: flex; align-items: center;
      justify-content: center;
    }
    .poi-text {
      background: rgba(10,24,38,0.88); border: 1px solid #1e4d72;
      border-radius: 4px; padding: 4px 6px;
      font-size: 11px; color: #b3d1ea; line-height: 1.4;
      max-height: 80px; overflow-y: auto;
      box-sizing: border-box; -webkit-overflow-scrolling: touch;
      transition: width 0.2s, max-height 0.3s;
      text-align: left; word-break: break-word;
    }
    /* Placeholder (collapsed): show one truncated line, no scroll */
    .poi-text.poi-text-collapsed {
      max-height: 2em; overflow: hidden;
      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    }
    .poi-card.expanded .poi-text { font-size: 12px; max-height: 200px; overflow-y: auto; }

    /* ── BEARING LABEL ──────────────────────────────────── */
    .brg-label {
      display: inline-block;
      background: rgba(10,24,38,0.82); border: 1px solid #1e4d72;
      border-radius: 3px; padding: 1px 5px; font-size: 10px; color: #7fb3d3;
      white-space: nowrap; pointer-events: none;
    }

    /* ── USER MARKERS ───────────────────────────────────── */
    .user-dot-wrap { display: flex; align-items: center; justify-content: center; }
    .user-dot {
      width: 16px; height: 16px; background: #2e86c1; border: 3px solid #fff;
      border-radius: 50%; box-shadow: 0 0 0 0 rgba(46,134,193,0.4);
      animation: gpspulse 2s infinite;
    }
    @keyframes gpspulse {
      0%   { box-shadow: 0 0 0 0   rgba(46,134,193,0.5); }
      70%  { box-shadow: 0 0 0 14px rgba(46,134,193,0);   }
      100% { box-shadow: 0 0 0 0   rgba(46,134,193,0);    }
    }

    /* ── POI DETAIL PANEL ───────────────────────────────── */
    #poi-detail {
      position: absolute; left: 0; right: 0; bottom: -100%; z-index: 700;
      background: #0d1f2d; border-top: 2px solid #2e86c1;
      border-radius: 16px 16px 0 0; padding: 18px 16px 24px;
      transition: bottom 0.28s ease; max-height: 62vh; overflow-y: auto;
      -webkit-overflow-scrolling: touch;
    }
    #poi-detail.open { bottom: 0; }
    #poi-detail-close {
      position: absolute; top: 12px; right: 14px;
      background: none; border: none; color: #5dade2;
      font-size: 26px; cursor: pointer; line-height: 1; padding: 2px 6px;
    }
    #poi-detail-title { font-size: 18px; font-weight: 700; padding-right: 36px; margin-bottom: 6px; color: #d6eaf8; }
    #poi-detail-meta  { font-size: 12px; color: #5d8aa8; margin-bottom: 10px; }
    #poi-detail-img   { width: 100%; max-height: 170px; object-fit: cover; border-radius: 8px; margin-bottom: 10px; display: none; }
    #poi-detail-desc  { font-size: 14px; color: #aab7c4; line-height: 1.55; margin-bottom: 14px; }
    #poi-detail-link  {
      display: inline-block; padding: 10px 22px;
      background: #2e86c1; border-radius: 7px;
      color: #fff; text-decoration: none; font-size: 14px; font-weight: 600;
    }

    #note-banner {
      display: none; position: absolute; left: 8px; right: 8px; top: 8px; z-index: 1150;
      align-items: center; gap: 8px; padding: 8px 10px;
      background: rgba(12,24,38,0.95); border: 1px solid #38bdf8; border-radius: 8px;
      color: #d6eaf8; font-size: 13px;
    }
    #note-banner button {
      margin-left: auto; padding: 5px 10px; background: #1a4a6e; border: 1px solid #2e86c1;
      border-radius: 6px; color: #d6eaf8; font-size: 12px; cursor: pointer;
    }
    #note-form {
      display: none; position: fixed; inset: 0; z-index: 1450;
      background: rgba(0,0,0,0.78); align-items: center; justify-content: center; padding: 16px;
    }
    #note-form .nf-card {
      width: 100%; max-width: 340px; background: #0f2236; border: 1px solid #2e86c1;
      border-radius: 12px; padding: 16px; color: #e2e8f0;
    }
    #note-form h3 { font-size: 16px; color: #38bdf8; margin-bottom: 10px; }
    #note-form .nf-coords { font-size: 12px; color: #85c1e9; margin-bottom: 10px; }
    #note-form textarea, #note-form input[type=text] {
      width: 100%; background: #11243a; border: 1px solid #1e4d72; border-radius: 8px;
      color: #fff; font-size: 14px; padding: 9px; margin-bottom: 10px; -webkit-appearance: none;
    }
    #note-form textarea { min-height: 70px; resize: vertical; }
    #note-form .nf-photo-btn, #note-form .nf-save, #note-form .nf-cancel {
      padding: 10px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
      border: 1px solid #2e86c1; -webkit-appearance: none;
    }
    #note-form .nf-photo-btn { width: 100%; background: #1a4a6e; color: #d6eaf8; margin-bottom: 10px; display: block; }
    #note-form #nf-thumb { max-width: 100%; border-radius: 8px; margin-bottom: 10px; display: none; }
    #note-form .nf-row { display: flex; gap: 8px; }
    #note-form .nf-save { flex: 1; background: #1a5276; color: #fff; }
    #note-form .nf-cancel { flex: 1; background: #3a1a1a; color: #f5b7b1; border-color: #c0392b; }
    #note-form #nf-status { font-size: 12px; color: #85c1e9; margin-top: 8px; min-height: 16px; }

/* ══════════════════════════════════════════════════════════
   POI HOVER PANEL — centred full-screen-ish overlay.
   On expand (hover / long-press) the POI card breaks out of its
   in-place camera/map position and becomes a centred top-layer
   panel (~75% viewport) so its full ~100-word explanation is
   readable and never clips off-screen behind other POIs.
   !important beats the inline px sizes set by makePOICardHtml /
   updatePOICardDOM.
══════════════════════════════════════════════════════════ */
/* Fixed, non-transformed layer that flex-centres the expanded card.
   The card is REPARENTED here on expand (updatePOICardDOM) so it escapes
   the transformed .camera-poi / Leaflet marker ancestors that would
   otherwise trap position:fixed. */
#poi-hover-layer {
  position: fixed; inset: 0; z-index: 2000;
  display: none; align-items: center; justify-content: center;
  pointer-events: none;
}
#poi-hover-layer.active { display: flex; pointer-events: auto; }

.poi-card.expanded {
  flex-direction: column !important;      /* beat .flip-up column-reverse */
  align-items: center !important;
  width: 75vw !important; max-width: 75vw !important;
  min-height: 80vh !important; max-height: 92vh !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  background: rgba(10,24,38,0.97);
  border: 2px solid #2e86c1; border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 10px 50px rgba(0,0,0,0.85);
  opacity: 1 !important;
  pointer-events: auto !important;
}
.poi-card.expanded .poi-img-group { align-items: center; }
.poi-card.expanded .poi-name {
  width: auto !important; max-width: 100% !important;
  font-size: 22px !important; white-space: normal !important;
  text-align: center; padding: 6px 10px; margin-bottom: 0;
}
.poi-card.expanded .poi-img-wrap {
  width: min(46vw, 280px) !important; height: min(46vw, 280px) !important;
}
.poi-card.expanded .poi-img-wrap img,
.poi-card.expanded .poi-img-wrap .poi-placeholder {
  width: 100% !important; height: 100% !important;
}
.poi-card.expanded .poi-text {
  width: 100% !important; max-height: none !important;
  flex: 1 1 auto !important;
  overflow: visible !important;
  font-size: 17px !important; line-height: 1.6 !important;
  padding: 12px 14px; margin-top: 10px;
  text-align: left; word-break: break-word;
}

/* POI cards: stop iOS showing the image save/preview callout on tap, and route
   every tap to the card itself (not the <img>) so the two-stage select is reliable. */
.poi-card, .poi-card * {
  -webkit-touch-callout: none;
  -webkit-user-select: none; user-select: none;
  -webkit-user-drag: none;
}
.poi-card .poi-img-wrap img { pointer-events: none; }
