:root {
  --sea-950: #062c33;
  --sea-900: #0b3c43;
  --sea-800: #12535a;
  --sea-700: #176b70;
  --sea-accent: #0e8f7c;
  --sea-accent-soft: #d8f2eb;
  --surface: #f5f8f7;
  --ink: #102a2d;
  --muted: #5d7374;
  --border: #d5e1df;
  --speed-still: #9aa9aa;
  --speed-slow: #f1b94c;
  --speed-fast: #0e8f7c;
  --radius-lg: 14px;
  --radius-md: 8px;
  --radius-pill: 999px;
  --ar-space-1: 4px;
  --ar-space-2: 8px;
  --ar-space-3: 12px;
  --ar-space-4: 16px;
  --ar-space-5: 20px;
  --ar-space-6: 24px;
  --ar-space-8: 32px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-width: 320px;
  color: #eaf8f5;
  background: var(--sea-950);
  font-family: Arial, Helvetica, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--sea-accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- page shell ---------- */
.ar-view {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  width: 100vw;
  overflow: clip;
  background: radial-gradient(ellipse at 50% 20%, var(--sea-900), var(--sea-950) 70%);
}

.ar-camera { position: absolute; inset: 0; background: #04191d; }
.ar-camera-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ar-contrast-scrim {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to bottom, rgb(6 44 51 / 0.55) 0%, rgb(6 44 51 / 0) 18%, rgb(6 44 51 / 0) 72%, rgb(6 44 51 / 0.6) 100%);
}
@media (prefers-reduced-transparency: reduce) {
  .ar-contrast-scrim { background: rgb(6 44 51 / 0.35); }
}

.ar-overlay-layer { position: absolute; inset: 0; display: none; }
.ar-view--live .ar-overlay-layer,
.ar-view--empty .ar-overlay-layer,
.ar-view--calibrating .ar-overlay-layer,
.ar-view--loading-data .ar-overlay-layer { display: block; }

/* ---------- top bar ---------- */
.ar-topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: var(--ar-space-3);
  padding: max(env(safe-area-inset-top), 12px) 12px 8px;
  z-index: 30;
}
.ar-brand-lockup { display: flex; flex-direction: column; line-height: 1.15; text-decoration: none; color: #fff; }
.ar-brand-lockup b { font-size: 13px; font-weight: 700; }
.ar-brand-lockup span { font-size: 13px; font-weight: 400; color: rgb(234 248 245 / 0.75); }
.ar-heading-readout {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-pill);
  background: rgb(6 44 51 / 0.72); border: 1px solid rgb(255 255 255 / 0.16);
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: #eaf8f5;
}
.ar-heading-readout .ar-confidence-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--speed-slow); }
.ar-heading-readout[data-confidence="ready"] .ar-confidence-dot { background: var(--sea-accent); }
.ar-heading-readout[data-confidence="unstable"] .ar-confidence-dot { background: var(--speed-slow); }
.ar-exit-button {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgb(6 44 51 / 0.72); border: 1px solid rgb(255 255 255 / 0.16); color: #fff; font-size: 16px;
}
.ar-freshness {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: rgb(6 44 51 / 0.6); color: rgb(234 248 245 / 0.8);
  font-size: 12px; font-weight: 600; z-index: 29; white-space: nowrap;
}

/* ---------- horizon guide ---------- */
.ar-horizon-guide {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 1px; background: rgb(255 255 255 / 0.28);
  z-index: 5; pointer-events: none;
}
.ar-horizon-guide::before, .ar-horizon-guide::after {
  content: ""; position: absolute; top: -4px; width: 1px; height: 9px; background: rgb(255 255 255 / 0.4);
}
.ar-horizon-guide::before { left: 50%; } .ar-horizon-guide::after { left: 50%; display: none; }

/* ---------- marker field ---------- */
.ar-marker-field { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
.ar-marker {
  position: absolute; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto; background: none; border: 0; padding: 0;
  transition: transform 0.25s ease-out, opacity 0.16s ease-out;
}
.ar-marker-label {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 8px 5px; border-radius: var(--radius-md);
  background: rgb(6 44 51 / 0.78); border: 1px solid rgb(255 255 255 / 0.18);
  min-width: 44px; max-width: 108px;
}
.ar-vessel-glyph { width: 14px; height: 14px; position: relative; margin-bottom: 1px; }
.ar-vessel-glyph i { position: absolute; inset: 0; display: block; box-shadow: 0 2px 5px rgb(0 0 0 / 0.3); }
.ar-marker--triangle .ar-vessel-glyph i { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 14px solid var(--glyph-color, var(--sea-accent)); background: transparent; box-shadow: none; }
.ar-marker--circle .ar-vessel-glyph i { border-radius: 50%; border: 2px solid #fff; background: var(--glyph-color, var(--sea-accent)); }
.ar-marker--square .ar-vessel-glyph i { border-radius: 2px; border: 2px solid #fff; background: var(--glyph-color, var(--sea-accent)); }
.ar-marker--diamond .ar-vessel-glyph i { border-radius: 2px; border: 2px solid #fff; background: var(--glyph-color, var(--sea-accent)); transform: rotate(45deg); }
.ar-marker--dot .ar-vessel-glyph i { border-radius: 50%; border: 2px solid #fff; background: var(--glyph-color, var(--sea-accent)); inset: 2px; }
.ar-marker--stopped { --glyph-color: var(--speed-still); }
.ar-marker--slow { --glyph-color: var(--speed-slow); }
.ar-marker--fast { --glyph-color: var(--speed-fast); }
.ar-marker-name { font-size: 11px; font-weight: 700; line-height: 1.2; color: #fff; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ar-marker-distance { font-size: 10px; font-weight: 600; color: rgb(234 248 245 / 0.7); font-variant-numeric: tabular-nums; }
.ar-marker--selected .ar-marker-label { outline: 2px solid var(--sea-accent-soft); background: rgb(6 44 51 / 0.92); }
.ar-marker--closest .ar-marker-label::before {
  content: "Closest"; position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  font-size: 9px; font-weight: 700; letter-spacing: 0.02em; color: var(--sea-950);
  background: var(--sea-accent-soft); padding: 1px 6px; border-radius: var(--radius-pill); white-space: nowrap;
}
.ar-marker--label-hidden .ar-marker-name, .ar-marker--label-hidden .ar-marker-distance { display: none; }
.ar-marker--label-hidden .ar-marker-label { padding: 6px; min-width: 26px; }
.ar-marker-trajectory { position: absolute; top: 50%; left: 50%; width: 2px; transform-origin: top center; background: linear-gradient(to bottom, var(--glyph-color, var(--sea-accent)), transparent); opacity: 0.55; pointer-events: none; z-index: 9; }

/* ---------- edge indicators ---------- */
.ar-edge-indicator {
  position: absolute; top: 50%; width: 48px; height: 48px; margin-top: -24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: var(--radius-md); background: rgb(6 44 51 / 0.78); border: 1px solid rgb(255 255 255 / 0.16);
  color: #fff; pointer-events: auto; z-index: 20;
}
.ar-edge-indicator--left { left: 16px; }
.ar-edge-indicator--right { right: 16px; }
.ar-edge-indicator .ar-edge-chevron { font-size: 12px; line-height: 1; color: rgb(234 248 245 / 0.85); }
.ar-edge-indicator .ar-edge-distance { font-size: 9px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ar-edge-overflow {
  position: absolute; top: 50%; width: 36px; height: 36px; margin-top: -18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: rgb(6 44 51 / 0.78); border: 1px solid rgb(255 255 255 / 0.16);
  color: #fff; font-size: 11px; font-weight: 700; z-index: 20;
}
.ar-edge-overflow--left { left: 20px; } .ar-edge-overflow--right { right: 20px; }

/* ---------- radar ---------- */
.ar-radar {
  position: absolute; top: 64px; right: 12px; width: 104px; height: 104px; border-radius: 50%;
  background: rgb(6 44 51 / 0.8); border: 1px solid rgb(255 255 255 / 0.18); z-index: 25;
  display: none;
}
.ar-view--radar-on .ar-radar { display: block; }
.ar-radar-ring { position: absolute; border: 1px solid rgb(255 255 255 / 0.16); border-radius: 50%; }
.ar-radar-facing-wedge {
  position: absolute; top: 50%; left: 50%; width: 0; height: 0;
  border-left: 9px solid transparent; border-right: 9px solid transparent; border-bottom: 34px solid rgb(216 242 235 / 0.22);
  transform-origin: bottom center; margin: -34px 0 0 -9px;
}
.ar-radar-vessel { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--glyph-color, var(--sea-accent)); margin: -2.5px 0 0 -2.5px; }
.ar-radar-toggle {
  position: absolute; height: 40px; min-width: 40px; padding: 0 12px; border-radius: var(--radius-pill);
  background: rgb(6 44 51 / 0.78); border: 1px solid rgb(255 255 255 / 0.18); color: #fff;
  font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: 6px; z-index: 26; pointer-events: auto;
}

/* ---------- insight stack ---------- */
.ar-insight-stack { position: absolute; left: 12px; bottom: 148px; display: flex; flex-direction: column; gap: 8px; z-index: 22; max-width: 62vw; }
.ar-insight-card {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; border-radius: var(--radius-md);
  background: rgb(6 44 51 / 0.78); border: 1px solid rgb(255 255 255 / 0.16); color: #fff;
  pointer-events: auto; text-align: left;
}
.ar-insight-card strong { display: block; font-size: 13px; font-weight: 700; line-height: 1.2; max-width: 44vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ar-insight-card span { display: block; font-size: 10px; font-weight: 600; color: rgb(234 248 245 / 0.68); text-transform: none; }

/* ---------- filter bar ---------- */
.ar-filter-bar {
  position: absolute; left: 0; right: 0; bottom: 92px; z-index: 22;
  display: flex; gap: 8px; padding: 0 12px; overflow-x: auto; scroll-snap-type: x proximity;
  -ms-overflow-style: none; scrollbar-width: none;
}
.ar-filter-bar::-webkit-scrollbar { display: none; }
.ar-filter-chip {
  flex: 0 0 auto; scroll-snap-align: start; min-height: 40px; padding: 0 16px; border-radius: var(--radius-pill);
  background: rgb(6 44 51 / 0.72); border: 1px solid rgb(255 255 255 / 0.18); color: #fff;
  font-size: 14px; font-weight: 600;
}
.ar-filter-chip--active { background: var(--sea-accent); border-color: var(--sea-accent); color: var(--sea-950); }

/* ---------- bottom controls ---------- */
.ar-bottom-controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 22;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
}
.ar-control-button {
  height: 44px; padding: 0 16px; border-radius: var(--radius-pill);
  background: rgb(6 44 51 / 0.78); border: 1px solid rgb(255 255 255 / 0.18); color: #fff;
  font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px;
}

/* ---------- state panels (intro / permission / unsupported / loading / empty / calibration / error) ---------- */
.ar-state-panel { position: absolute; inset: 0; z-index: 40; display: none; overflow-y: auto; }
.ar-view--intro .ar-intro,
.ar-view--requesting .ar-intro,
.ar-view--denied .ar-permission-state,
.ar-view--unsupported .ar-unsupported-state,
.ar-view--data-error .ar-data-error { display: block; }

.ar-intro, .ar-permission-state, .ar-unsupported-state, .ar-data-error {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: var(--ar-space-6);
  padding: max(env(safe-area-inset-top), 24px) 24px max(env(safe-area-inset-bottom), 24px);
  background: linear-gradient(160deg, var(--sea-900), var(--sea-950) 70%);
}
.ar-eyebrow { font-size: 13px; font-weight: 700; color: var(--sea-accent-soft); }
.ar-state-panel h1 { margin: 0; font-size: 30px; line-height: 34px; font-weight: 700; color: #fff; max-width: 22ch; }
.ar-state-panel h2 { margin: 0; font-size: 22px; line-height: 27px; font-weight: 700; color: #fff; }
.ar-state-panel p { margin: 0; font-size: 16px; line-height: 23px; color: rgb(234 248 245 / 0.82); max-width: 40ch; }
.ar-requirement-list { display: flex; flex-direction: column; gap: 14px; margin: 4px 0 0; padding: 0; list-style: none; }
.ar-requirement-list li { display: flex; align-items: center; gap: 12px; font-size: 14px; color: rgb(234 248 245 / 0.85); }
.ar-requirement-list i { width: 36px; height: 36px; flex-shrink: 0; border-radius: var(--radius-md); background: rgb(216 242 235 / 0.12); display: flex; align-items: center; justify-content: center; color: var(--sea-accent-soft); font-size: 15px; }
.ar-requirement-list b { color: #fff; }
.ar-primary-cta {
  height: 52px; padding: 0 24px; border-radius: var(--radius-pill); border: 0;
  background: var(--sea-accent-soft); color: var(--sea-950); font-size: 16px; font-weight: 700;
  white-space: nowrap; align-self: flex-start;
}
.ar-primary-cta:active { transform: translateY(1px) scale(0.98); }
.ar-primary-cta[disabled] { opacity: 0.6; }
.ar-secondary-link { font-size: 14px; font-weight: 600; color: var(--sea-accent-soft); text-decoration: underline; align-self: flex-start; background: none; border: 0; padding: 0; }
.ar-fine-print { font-size: 12px; line-height: 16px; color: rgb(234 248 245 / 0.55); max-width: 40ch; }
.ar-permission-actions, .ar-error-actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- calibration prompt ---------- */
.ar-calibration-prompt {
  position: absolute; left: 16px; right: 16px; bottom: 96px; z-index: 45; display: none;
  padding: var(--ar-space-5); border-radius: var(--radius-lg);
  background: rgb(6 44 51 / 0.94); border: 1px solid rgb(255 255 255 / 0.18); color: #fff;
}
.ar-view--calibrating .ar-calibration-prompt { display: block; }
.ar-calibration-glyph { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--sea-accent-soft); display: flex; align-items: center; justify-content: center; margin-bottom: 10px; font-size: 16px; }
.ar-calibration-prompt h2 { font-size: 18px; margin: 0 0 6px; }
.ar-calibration-prompt p { font-size: 14px; line-height: 20px; color: rgb(234 248 245 / 0.8); margin: 0 0 14px; max-width: 44ch; }
.ar-calibration-actions { display: flex; gap: 12px; }
.ar-calibration-actions button { height: 40px; padding: 0 16px; border-radius: var(--radius-pill); font-size: 13px; font-weight: 700; border: 1px solid rgb(255 255 255 / 0.3); background: transparent; color: #fff; }
.ar-calibration-actions button:first-child { background: var(--sea-accent-soft); color: var(--sea-950); border-color: transparent; }

/* ---------- loading + empty states (float over live camera) ---------- */
.ar-loading-state, .ar-empty-state {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 15;
  width: min(260px, 72vw); padding: var(--ar-space-5); border-radius: var(--radius-lg);
  background: rgb(6 44 51 / 0.82); border: 1px solid rgb(255 255 255 / 0.16); color: #fff; text-align: center;
  display: none;
}
.ar-view--loading-data .ar-loading-state { display: block; }
.ar-view--empty .ar-empty-state { display: block; }
.ar-loading-state strong, .ar-empty-state strong { display: block; font-size: 16px; margin-bottom: 6px; }
.ar-empty-state p { margin: 0; font-size: 13px; line-height: 18px; color: rgb(234 248 245 / 0.75); }
.ar-loading-skeleton { height: 8px; border-radius: 4px; margin: 8px auto 0; background: var(--sea-800); }
.ar-loading-skeleton:nth-child(1) { width: 70%; }
.ar-loading-skeleton:nth-child(2) { width: 92%; }
.ar-loading-skeleton:nth-child(3) { width: 55%; }

/* ---------- vessel detail sheet ---------- */
.ar-sheet-scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); z-index: 49; opacity: 0; pointer-events: none; transition: opacity 0.16s ease-out; }
.ar-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 62dvh; overflow-y: auto; border-radius: 14px 14px 0 0;
  background: var(--surface); color: var(--ink);
  padding: 8px 20px max(20px, env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 0.22s ease-out;
}
.ar-sheet-scrim.is-open { opacity: 1; pointer-events: auto; }
.ar-sheet.is-open { transform: translateY(0); }
.ar-sheet-handle { width: 36px; height: 4px; border-radius: var(--radius-pill); background: var(--border); margin: 8px auto 12px; }
.ar-sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.ar-sheet-title { display: flex; align-items: center; gap: 10px; }
.ar-sheet-title h2 { margin: 0; font-size: 22px; line-height: 27px; font-weight: 700; }
.ar-sheet-subtitle { margin: 2px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.ar-sheet-close { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-size: 16px; flex-shrink: 0; }
.ar-sheet-readout { font-size: 18px; font-weight: 700; color: var(--sea-700); margin: 0 0 10px; font-variant-numeric: tabular-nums; }
.ar-sheet-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0 0 14px; padding: 0; }
.ar-sheet-facts dt { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; color: var(--muted); margin: 0; }
.ar-sheet-facts dd { font-size: 14px; font-weight: 600; color: var(--ink); margin: 2px 0 0; }
.ar-sheet-section-label { font-size: 12px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; }
.ar-sheet-movements { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; padding: 0; list-style: none; }
.ar-sheet-movements li { font-size: 13px; line-height: 18px; color: var(--ink); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.ar-sheet-movements li span { display: block; color: var(--muted); font-size: 11px; }
.ar-sheet-record-link {
  display: block; width: 100%; height: 48px; border-radius: var(--radius-pill); border: 1px solid var(--sea-700);
  background: transparent; color: var(--sea-700); font-size: 14px; font-weight: 700; text-align: center; line-height: 46px; text-decoration: none;
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .ar-marker, .ar-sheet, .ar-sheet-scrim, .ar-primary-cta, .ar-calibration-glyph { transition-duration: 0.08s !important; animation: none !important; }
}

/* ---------- landscape ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  .ar-horizon-guide { top: 48%; }
  .ar-insight-stack { bottom: 90px; left: 12px; max-width: 46vw; }
  .ar-filter-bar { bottom: 12px; left: 12px; right: auto; max-width: 40vw; flex-wrap: wrap; }
  .ar-bottom-controls { left: auto; right: 12px; bottom: 12px; width: auto; flex-direction: column; align-items: flex-end; }
  .ar-sheet { top: 0; bottom: 0; left: auto; right: 0; width: min(420px, 42vw); max-height: none; border-radius: 14px 0 0 14px; transform: translateX(100%); }
  .ar-sheet.is-open { transform: translateX(0); }
}

@media (min-width: 720px) {
  .ar-intro, .ar-permission-state, .ar-unsupported-state, .ar-data-error { max-width: 480px; margin: 0 auto; }
}
