/* ===========================================================
   GLOBAL
   =========================================================== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0a1c2b;
}

.page { position: fixed; inset: 0; opacity: 0; pointer-events: none;
        transition: opacity .55s ease, transform .55s ease; }
.page.active { opacity: 1; pointer-events: auto; }
.hidden { display: none !important; }

/* ===========================================================
   PAGE 1 — MAP
   =========================================================== */
#map { position: absolute; inset: 0; background: #0c2740; z-index: 1; }

/* Nautical depth / paper tone over the tiles */
.leaflet-container { background: #0c2740; }

/* Deep-ocean gradient + bathymetric vignette baked over the map */
#map::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 400;
  background:
    radial-gradient(120% 90% at 50% 45%, rgba(10,40,66,0) 55%, rgba(4,18,30,0.55) 100%),
    linear-gradient(180deg, rgba(8,30,50,0.10), rgba(4,16,28,0.20));
  mix-blend-mode: multiply;
}

/* Shimmering water sheen */
#water-shimmer {
  position: absolute; inset: 0; z-index: 405; pointer-events: none;
  background:
    repeating-linear-gradient(115deg,
      rgba(255,255,255,0.00) 0px,
      rgba(255,255,255,0.05) 2px,
      rgba(255,255,255,0.00) 6px,
      rgba(255,255,255,0.00) 22px);
  mix-blend-mode: screen;
  opacity: .5;
  animation: shimmer 14s linear infinite;
}
@keyframes shimmer {
  0%   { background-position: 0 0; }
  100% { background-position: 600px 240px; }
}

/* Static north reference (bottom-left) */
#compass-rose {
  position: absolute; left: 14px; bottom: 14px;
  width: 66px; height: 66px; z-index: 500; pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.5));
}
@media (max-width: 600px){ #compass-rose { width: 52px; height: 52px; } }

/* Live cursor read-out (inside the instrument panel) */
#coord-readout {
  font: 700 14px/1.2 "SFMono-Regular", Menlo, Consolas, monospace;
  letter-spacing: .5px; color: #eaf2f8;
}

/* Scale (inside the instrument panel) — label, bar and reading on one row */
.np-scale { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.np-scale .np-lab {
  flex: 0 0 auto; font: 600 10px/1 "Segoe UI", sans-serif; letter-spacing: .6px;
  text-transform: uppercase; color: #7fa3bb;
}
#nautical-scale { flex: 1 1 auto; min-width: 46px; }
.scale-bar {
  height: 8px; border: 2px solid rgba(180,210,230,.7); border-top: none;
  background:
    repeating-linear-gradient(90deg, rgba(200,220,235,.8) 0, rgba(200,220,235,.8) 50%,
      rgba(0,0,0,.3) 50%, rgba(0,0,0,.3) 100%);
  background-size: 50% 100%;
}
#scale-label {
  flex: 0 0 auto; white-space: nowrap; color: #cfe3ef;
  font: 700 11px/1 "SFMono-Regular", Menlo, Consolas, monospace;
}

/* Live-traffic indicator (bottom-left). Visible only when real AIS is live. */
#live-badge {
  position: absolute; left: 88px; bottom: 22px; z-index: 500; pointer-events: none;
  font-size: 20px; line-height: 1;
  opacity: 0; transition: opacity .4s ease;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.6));
}
#live-badge.on { opacity: 1; }

/* Blinking sea marks (lighthouses / buoys) */
.seamark { position: relative; }
.seamark .glow {
  position: absolute; left: 50%; top: 50%; width: 26px; height: 26px;
  transform: translate(-50%,-50%); border-radius: 50%;
}
.seamark .core {
  position: absolute; left: 50%; top: 50%; width: 8px; height: 8px;
  transform: translate(-50%,-50%); border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255,255,255,.5);
}
.seamark.lighthouse .glow { background: radial-gradient(circle, rgba(255,90,60,.85), rgba(255,90,60,0) 70%);
  animation: blink 2.4s ease-in-out infinite; }
.seamark.lighthouse .core { background: #ff5a3c; }
.seamark.buoy-g .glow { background: radial-gradient(circle, rgba(60,255,140,.8), rgba(60,255,140,0) 70%);
  animation: blink 3.2s ease-in-out infinite; }
.seamark.buoy-g .core { background: #2fe07a; }
.seamark.buoy-r .glow { background: radial-gradient(circle, rgba(255,70,70,.8), rgba(255,70,70,0) 70%);
  animation: blink 4s ease-in-out infinite; }
.seamark.buoy-r .core { background: #ff4646; }
@keyframes blink {
  0%, 100% { opacity: .15; } 8% { opacity: 1; } 22% { opacity: .15; }
}

/* Real aids to navigation (live OSM seamarks) — colour & period come from the
   data via CSS variables, so each light blinks with its true characteristic. */
.seamark.live { cursor: pointer; }
.seamark.live .glow {
  background: radial-gradient(circle, var(--glow, rgba(255,235,170,.9)), transparent 70%);
  animation: blink var(--blinkdur, 4s) ease-in-out infinite;
}
.seamark.live .core { background: var(--core, #ffe9a8); }
.seamark.live.unlit .glow { animation: none; opacity: .22; }   /* unlit buoy/beacon */

/* Moving vessels (fake AIS traffic) */
.vessel { position: relative; width: 22px; height: 22px; }
.vessel-rot {
  width: 22px; height: 22px;
  transform-origin: 50% 50%;
  transition: transform .25s ease-out;   /* smooth turning */
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5));
}
.vessel-label {
  position: absolute; left: 26px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; font: 600 9px/1.15 "Segoe UI", sans-serif;
  color: #eaf2f8; text-shadow: 0 1px 3px rgba(0,0,0,.9);
  border-left: 2px solid var(--vc); padding-left: 4px;
  opacity: .9; pointer-events: none;
}
.vessel-label b { font-weight: 700; color: var(--vc); }
@media (max-width: 600px){ .vessel-label { display: none; } }

/* AIS popup */
.ais-popup .leaflet-popup-content-wrapper {
  background: rgba(16,34,52,.96); color: #eaf2f8;
  border: 1px solid rgba(150,190,215,.3); border-radius: 8px;
}
.ais-popup .leaflet-popup-tip { background: rgba(16,34,52,.96); }
.ais-popup .leaflet-popup-content { margin: 10px 12px; }
.ais { font: 500 12px/1.5 "Segoe UI", sans-serif; min-width: 168px; }
.ais-name { font-weight: 700; font-size: 13px; letter-spacing: .5px;
  margin-bottom: 5px; color: #9fd3ff; }
.ais-row { display: flex; justify-content: space-between; gap: 14px; }
.ais-row span { opacity: .6; }

/* Leaflet controls toned to chart */
.leaflet-control-attribution { background: rgba(8,28,46,.55) !important; color: #cfe0ec !important; }
.leaflet-control-attribution a { color: #9fc6e0 !important; }
.leaflet-bar a { background: #123a59; color: #eaf2f8; border-color: #0a2336; }
.leaflet-bar a:hover { background: #1a4d74; }

/* go-to search shake on bad input (the field itself is styled in the top bar) */
@keyframes nudge {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* ===========================================================
   ECDIS-STYLE CHROME — top command bar + instrument panel
   =========================================================== */
/* push Leaflet's own controls clear of the top command bar */
.leaflet-top { top: 54px; }
@media (max-width: 600px){ .leaflet-top { top: 50px; } }
.leaflet-bar { border: none !important; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.leaflet-control-layers {
  background: rgba(8,26,42,.92) !important; color: #eaf2f8;
  border: 1px solid rgba(150,190,215,.28) !important;
  border-radius: 9px !important; box-shadow: 0 6px 18px rgba(0,0,0,.45) !important;
  font: 500 12px/1.6 "Segoe UI", sans-serif;
}
.leaflet-control-layers-expanded { padding: 9px 13px 9px 11px; }
.leaflet-control-layers-toggle { background-color: #0e2c44; }
.leaflet-control-layers label { color: #dce9f2; }
.leaflet-control-layers-separator { border-color: rgba(150,190,215,.2); }

/* ---- top command bar ---- */
#top-bar {
  position: absolute; top: 0; left: 0; right: 0; height: 48px; z-index: 700;
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: linear-gradient(180deg, rgba(6,18,30,.97), rgba(6,18,30,.88));
  border-bottom: 1px solid rgba(150,190,215,.22);
  box-shadow: 0 2px 12px rgba(0,0,0,.4); backdrop-filter: blur(7px);
}
.tb-brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.tb-name { font: 700 14px/1 Georgia, serif; letter-spacing: 3px; color: #eaf2f8; }
.tb-tag {
  font: 700 9px/1 "Segoe UI", sans-serif; letter-spacing: 1.5px; color: #06121e;
  background: #9fd3ff; border-radius: 3px; padding: 3px 5px;
}

/* go-to search field — recenter the chart on a typed position */
#goto-coord {
  display: flex; align-items: center; gap: 8px; flex: 0 1 280px;
  height: 33px; padding: 0 12px; border-radius: 9px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(150,190,215,.24);
  transition: border-color .15s, background .15s;
}
#goto-coord:focus-within { border-color: #3aa0d6; background: rgba(255,255,255,.1); }
#goto-coord svg { opacity: .85; flex: 0 0 auto; }
#goto-input {
  width: 100%; border: none; background: transparent; outline: none; color: #eaf2f8;
  letter-spacing: .3px; font: 500 12.5px/1 "SFMono-Regular", Menlo, Consolas, monospace;
}
#goto-input::placeholder { color: rgba(190,212,228,.5); }
#goto-coord.nudge { animation: nudge .4s cubic-bezier(.36,.07,.19,.97); }

/* tool buttons */
#nav-tools { display: flex; gap: 6px; margin-left: auto; flex: 0 0 auto; }
#nav-tools button {
  display: inline-flex; align-items: center; gap: 6px;
  font: 600 11.5px/1 "Segoe UI", sans-serif; letter-spacing: .3px;
  color: #dce9f2; background: rgba(255,255,255,.05);
  border: 1px solid rgba(150,190,215,.22); border-radius: 8px;
  height: 33px; padding: 0 13px; cursor: pointer; transition: background .15s, border-color .15s;
}
#nav-tools button svg { opacity: .85; }
#nav-tools button:hover { background: rgba(26,77,116,.55); }
#nav-tools button.on { background: #1a4d74; border-color: #9fd3ff; color: #fff; }
#nav-tools button.on svg { opacity: 1; }

/* ---- right instrument panel ---- */
#nav-panel {
  position: absolute; top: 60px; right: 12px; z-index: 600; width: 238px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: calc(100% - 132px); overflow-y: auto;
  pointer-events: none;                /* gaps pass clicks through to the chart */
}
#nav-panel > * { pointer-events: auto; }

/* mobile bottom sheet — hidden on desktop, populated/shown on phones */
#sheet { display: none; }
.np-block {
  position: relative; background: rgba(8,26,42,.9); color: #eaf2f8;
  border: 1px solid rgba(150,190,215,.26); border-radius: 11px;
  box-shadow: 0 6px 18px rgba(0,0,0,.42); backdrop-filter: blur(5px);
  padding: 12px 14px; font: 500 12px/1.5 "Segoe UI", sans-serif;
}
.np-h {
  font: 700 10px/1.2 "Segoe UI", sans-serif; letter-spacing: 1.3px;
  text-transform: uppercase; color: #7fa3bb;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid rgba(150,190,215,.18);
}

#pg-legs { max-height: 150px; overflow-y: auto; margin-bottom: 4px; }
.pg-leg, .pg-row, .fx-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 3px 0;
}
.pg-leg { font: 500 11.5px/1.65 "SFMono-Regular", Menlo, Consolas, monospace; }
.pg-leg span, .fx-row span, .pg-row span { color: #7fa3bb; font-size: 11px; flex: 0 0 auto; }
.pg-leg b { color: #ffd24a; font-weight: 700; }
.pg-leg i { font-style: normal; color: #cfe3ef; }
.pg-row { border-top: 1px solid rgba(150,190,215,.12); margin-top: 1px; padding-top: 7px; }
.pg-row b { font: 700 12.5px/1 "SFMono-Regular", Menlo, Consolas, monospace; color: #eaf2f8; }
.pg-hint { color: #7fa3bb; font-size: 11px; padding: 4px 0; }
.pg-speed { gap: 6px; }
#pg-sog {
  width: 58px; text-align: right; color: #eaf2f8; background: rgba(255,255,255,.06);
  border: 1px solid rgba(150,190,215,.3); border-radius: 5px; padding: 4px 7px; margin-left: auto;
  font: 600 12px/1 "SFMono-Regular", Menlo, Consolas, monospace;
}
.fx-row code {
  font: 600 11.5px/1.5 "SFMono-Regular", Menlo, Consolas, monospace; color: #cfe3ef; text-align: right;
}
#fix-close {
  position: absolute; top: 9px; right: 10px; width: 20px; height: 20px;
  background: transparent; border: none; color: #9fc6e0; cursor: pointer; font-size: 17px; line-height: 1;
}
#fx-copy {
  margin-top: 10px; width: 100%; font: 600 11px/1 "Segoe UI", sans-serif; letter-spacing: .4px;
  color: #eaf2f8; background: rgba(26,77,116,.7); border: 1px solid rgba(150,190,215,.3);
  border-radius: 6px; padding: 8px; cursor: pointer;
}
#fx-copy:hover { background: #1a4d74; }

/* ===========================================================
   PHONE LAYOUT — clean map + pull-up bottom sheet
   =========================================================== */
@media (max-width: 600px){
  /* top bar: brand + search only (tools move into the sheet) */
  #top-bar { gap: 8px; padding: 0 10px; }
  .tb-name { font-size: 12px; letter-spacing: 2px; }
  .tb-tag { display: none; }
  #goto-coord { flex: 1 1 auto; }

  /* declutter the chart corners */
  #compass-rose { display: none; }
  #live-badge { left: auto; right: 12px; bottom: 96px; }
  .leaflet-control-attribution { font-size: 9px !important; }

  /* the desktop right panel is emptied into the sheet → hide it */
  #nav-panel { display: none; }

  /* ---- the sheet ---- */
  #sheet {
    display: block; position: absolute; left: 0; right: 0; bottom: 0; z-index: 680;
    background: linear-gradient(180deg, rgba(8,26,42,.97), rgba(6,18,30,.98));
    border-top: 1px solid rgba(150,190,215,.25); border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 26px rgba(0,0,0,.55); backdrop-filter: blur(9px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #sheet-handle {
    display: block; width: 100%; background: transparent; border: none;
    padding: 9px 0 6px; cursor: pointer;
  }
  #sheet-handle span {
    display: block; width: 40px; height: 4px; border-radius: 2px;
    background: rgba(180,210,230,.5); margin: 0 auto;
  }
  #sheet-peek { padding: 0 16px 13px; }
  #sheet-body { max-height: 0; overflow: hidden; transition: max-height .3s ease; }
  #sheet.open #sheet-body {
    max-height: 64vh; overflow-y: auto; padding: 2px 12px 12px;
    -webkit-overflow-scrolling: touch;
  }

  /* tool buttons inside the sheet — full-width, with labels */
  #sheet-body #nav-tools { display: flex; gap: 9px; margin: 4px 0 12px; }
  #sheet-body #nav-tools button { flex: 1 1 0; justify-content: center; height: 44px; }
  #sheet-body #nav-tools button span { display: inline; }

  /* passage / fix cards fill the sheet width */
  #sheet-body .np-block {
    width: 100%; margin-bottom: 10px; box-shadow: none;
    background: rgba(255,255,255,.04); border-color: rgba(150,190,215,.18);
  }
  #sheet-body .np-block:last-child { margin-bottom: 2px; }

  /* the position line is the peek — one compact, chrome-less row */
  #nav-readout {
    display: flex; align-items: center; gap: 14px; padding: 2px;
    background: transparent; border: none; box-shadow: none;
  }
  #nav-readout .np-h { display: none; }
  #nav-readout #coord-readout { font-size: 13px; }
  #nav-readout .np-scale { margin-top: 0; flex: 1 1 auto; }
}

/* route waypoint pins + leg labels */
.wpt span {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: #ffd24a; color: #102a3a; border: 2px solid #08161f;
  font: 700 11px/1 "Segoe UI", sans-serif; box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.leaflet-tooltip.leg-tip {
  background: rgba(8,28,46,.85); color: #ffd24a; border: 1px solid rgba(255,210,74,.4);
  border-radius: 4px; font: 700 10px/1 "SFMono-Regular", Menlo, monospace;
  padding: 3px 5px; box-shadow: none; white-space: nowrap;
}
.leaflet-tooltip.leg-tip::before { display: none; }

/* ---- weather overlays (wind arrows + wave chips) ---- */
.wind-arrow { position: absolute; left: 0; top: 0; width: 38px; height: 38px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.7)); }
.met-kn { position: absolute; left: 38px; top: 12px; white-space: nowrap;
  font: 700 10px/1 "SFMono-Regular", Menlo, monospace; text-shadow: 0 1px 2px #000; }
.wave-chip { display: inline-block; padding: 2px 6px; border-radius: 9px;
  border: 1px solid; background: rgba(6,18,30,.7);
  font: 700 10px/1 "SFMono-Regular", Menlo, monospace; text-shadow: 0 1px 2px #000; }

/* ---- ARPA collision-avoidance ---- */
#nav-tools button.alarm { animation: arpaPulse 1s ease-in-out infinite;
  border-color: #ff5a5a !important; color: #fff; }
@keyframes arpaPulse {
  0%, 100% { background: rgba(255,90,90,.25); }
  50% { background: rgba(255,90,90,.7); }
}
.own-ship { width: 16px; height: 16px; border-radius: 50%;
  background: #6fe3ff; border: 2px solid #06121e;
  box-shadow: 0 0 0 3px rgba(111,227,255,.35), 0 1px 3px rgba(0,0,0,.6); }
.arpa-src { font-size: 11px; color: #9fc6e0; margin-bottom: 8px; }
.arpa-set { display: flex; gap: 10px; margin-bottom: 10px; }
.arpa-set label { flex: 1 1 0; font-size: 11px; color: #7fa3bb;
  display: flex; align-items: center; gap: 5px; }
.arpa-set input { width: 100%; min-width: 0; text-align: right; color: #eaf2f8;
  background: rgba(255,255,255,.06); border: 1px solid rgba(150,190,215,.3);
  border-radius: 5px; padding: 4px 6px;
  font: 600 12px/1 "SFMono-Regular", Menlo, Consolas, monospace; }
.arpa-cols { display: flex; justify-content: space-between; gap: 8px;
  font: 600 9.5px/1 "Segoe UI", sans-serif; letter-spacing: .5px;
  text-transform: uppercase; color: #5e7e95; padding-bottom: 4px;
  border-bottom: 1px solid rgba(150,190,215,.14); }
.arpa-cols span:nth-child(2), .arpa-cols span:nth-child(3) { flex: 0 0 56px; text-align: right; }
#arpa-list { max-height: 150px; overflow-y: auto; }
.arpa-row { display: flex; align-items: center; gap: 8px; padding: 4px 0;
  font: 500 11.5px/1.3 "SFMono-Regular", Menlo, Consolas, monospace;
  border-bottom: 1px solid rgba(120,160,185,.08); }
.arpa-row span { flex: 1 1 auto; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; color: #d7e7f2; }
.arpa-row b { flex: 0 0 56px; text-align: right; color: #cfe3ef; font-weight: 700; }
.arpa-row i { flex: 0 0 56px; text-align: right; font-style: normal; color: #9fc6e0; }
.arpa-row.danger span, .arpa-row.danger b, .arpa-row.danger i { color: #ff7a7a; }
.arpa-row.danger b { font-weight: 800; }
.arpa-note { margin-top: 8px; font-size: 10px; color: #5e7e95; }

/* transient on-chart status message (radar load, etc.) */
#chart-msg {
  position: absolute; top: 62px; left: 50%; transform: translate(-50%, -8px);
  z-index: 650; max-width: 80%; text-align: center;
  background: rgba(8,26,42,.94); color: #eaf2f8;
  border: 1px solid rgba(150,190,215,.3); border-radius: 18px;
  padding: 9px 17px; font: 500 12px/1.4 "Segoe UI", sans-serif;
  box-shadow: 0 6px 18px rgba(0,0,0,.45); backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease;
}
#chart-msg.on { opacity: 1; transform: translate(-50%, 0); }
