:root {
  --bg: #0b1017;
  --panel: rgba(17, 24, 35, 0.86);
  --panel-solid: #131b26;
  --border: rgba(255, 255, 255, 0.10);
  --text: #e8edf4;
  --muted: #8b9bb0;
  --accent: #38bdf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* Any rule setting `display` outranks the UA's [hidden] { display: none },
   so panels that lay themselves out with flex would never actually hide. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
}

#map { position: absolute; inset: 0; }

.panel {
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- top bar ---------- */
.topbar {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
}

.brand { display: flex; align-items: center; gap: 9px; flex: none; }

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.mark {
  display: flex;
  color: var(--accent);
  filter: drop-shadow(0 0 7px rgba(56, 189, 248, 0.45));
}

.search { position: relative; flex: 1; max-width: 420px; }

.search input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.30);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.search input:focus { border-color: var(--accent); }
.search input::placeholder { color: var(--muted); }

.results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.results li {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.results li:hover, .results li[aria-selected="true"] { background: rgba(56, 189, 248, 0.14); }
.results .mmsi { color: var(--muted); font-family: var(--mono); font-size: 12px; }

.stats { margin-left: auto; display: flex; align-items: center; gap: 12px; flex: none; }

.status { font-size: 12px; display: flex; align-items: center; gap: 6px; color: var(--muted); }

.status::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-state="live"] { color: var(--ok); }
.status[data-state="live"]::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status[data-state="connecting"]::before { background: var(--warn); animation: pulse 1.1s ease-in-out infinite; }
.status[data-state="offline"] { color: var(--err); }
.status[data-state="offline"]::before { background: var(--err); }

@keyframes pulse { 50% { opacity: 0.25; } }

.count { font-family: var(--mono); font-size: 13px; color: var(--text); }
.count::after { content: " ships"; color: var(--muted); font-family: var(--font); font-size: 12px; }

/* ---------- details ---------- */
.details {
  position: absolute;
  z-index: 5;
  top: 70px;
  right: 12px;
  width: 290px;
  padding: 16px;
  max-height: calc(100% - 130px);
  overflow-y: auto;
}

.details h2 { margin: 0 4px 2px 0; font-size: 17px; font-weight: 600; }
.subtitle { margin: 0 0 12px; color: var(--muted); font-size: 12px; }

.close {
  position: absolute;
  top: 10px; right: 10px;
  width: 24px; height: 24px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
}
.close:hover { color: var(--text); background: rgba(255, 255, 255, 0.07); }

.details dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; }
.details dt { color: var(--muted); font-size: 12px; }
.details dd { margin: 0; font-family: var(--mono); font-size: 12px; text-align: right; word-break: break-word; }

.source-note { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }

/* ---------- legend ---------- */
.legend {
  position: absolute;
  z-index: 5;
  bottom: 38px;
  left: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.legend .row { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.legend .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }

/* ---------- attribution ---------- */
.attrib {
  position: absolute;
  z-index: 5;
  bottom: 8px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--muted);
  pointer-events: none;
}
.attrib a { color: var(--muted); pointer-events: auto; }



@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .details { top: auto; bottom: 34px; right: 12px; left: 12px; width: auto; max-height: 52%; }
  .legend { display: none; }
  .attrib span:last-child { display: none; }

  /* On a phone the card is short, so the photo would fill it entirely and
     push the ship's name and particulars out of view. Identity first;
     the photo goes below the data it illustrates. */
  .details { display: flex; flex-direction: column; }
  #d-name { order: 1; }
  #d-type { order: 2; }
  #d-voyage { order: 3; }
  #d-fields { order: 4; }
  #d-photo { order: 5; margin: 14px 0 0; }
  #d-reference { order: 6; }
  .details .source-note { order: 7; }
}


/* ---------- icon button ---------- */
.icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.1); }
.icon-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }

/* ---------- settings ---------- */
.settings {
  position: absolute;
  z-index: 6;
  top: 62px;
  right: 12px;
  width: 260px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings h2 {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.settings .field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }

.settings select {
  padding: 7px 9px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  outline: none;
}
.settings select:focus { border-color: var(--accent); }

.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; flex: none; }
.toggle:hover { color: #fff; }

.settings .hint { margin: 2px 0 0; font-size: 11px; color: var(--muted); }

/* ---------- photo ---------- */
.photo { margin: 0 0 12px; }
.photo figcaption { margin-top: 5px; font-size: 10.5px; color: var(--muted); line-height: 1.4; }
.photo figcaption a { color: var(--muted); }

/* ---------- voyage ---------- */
.voyage {
  margin: 0 0 13px;
  padding: 10px 11px;
  background: rgba(56, 189, 248, 0.07);
  border: 1px solid rgba(56, 189, 248, 0.16);
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.leg { display: grid; grid-template-columns: 34px 1fr; gap: 3px 9px; align-items: baseline; }
.leg-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 600;
}
.leg-value { font-size: 12.5px; }
.leg-note { grid-column: 2; font-size: 10.5px; color: var(--muted); font-style: italic; }

/* ---------- search groups ---------- */
.results .group {
  padding: 7px 10px 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  cursor: default;
  pointer-events: none;
}
.results .group:hover { background: none; }

/* MapLibre's own controls, themed to match the panels. */
.maplibregl-ctrl-group {
  background: var(--panel) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
  backdrop-filter: blur(14px);
}
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--border) !important; }
.maplibregl-ctrl-group button span { filter: invert(1) brightness(1.6); }
.maplibregl-ctrl-scale {
  background: var(--panel) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}

@media (max-width: 720px) {
  .settings { top: auto; bottom: 34px; left: 12px; right: 12px; width: auto; }
}

/* Visible to screen readers and crawlers, not on screen. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  position: absolute;
  z-index: 10;
  inset: 70px 12px auto 12px;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 24px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.55;
}
.noscript h2 { margin-top: 0; font-size: 18px; }
.noscript p { color: var(--muted); }

.toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  padding: 10px 16px;
  max-width: min(420px, calc(100% - 32px));
  font-size: 12.5px;
  text-align: center;
}

.legend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 0;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  cursor: pointer;
}
.legend-head:hover { color: var(--text); }
.legend-head .chev { transition: transform 0.18s ease; }
.legend-head.collapsed .chev { transform: rotate(-90deg); }

.legend-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }

.reference {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.reference h3 {
  margin: 0 0 9px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.reference dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; }
.reference dt { color: var(--muted); font-size: 12px; }
.reference dd { margin: 0; font-size: 12px; text-align: right; word-break: break-word; }

.article-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}
.article-link:hover { text-decoration: underline; }
.ref-note { margin: 8px 0 0; font-size: 10.5px; color: var(--muted); }

.locate-btn { display: grid; place-items: center; color: var(--text); }
.locate-btn.locating { opacity: 0.5; }
.locate-btn.locating svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ship photo, with a stable placeholder ---------- */
.photo-frame {
  position: relative;
  aspect-ratio: 8 / 5;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

/* The placeholder holds the space so the card never reflows when a photo
   arrives — and stays put for the many ships that have no photo at all. */
.photo-placeholder {
  width: 100%;
  height: 100%;
  color: var(--muted);
}

.photo-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: photo-in 0.25s ease;
}

@keyframes photo-in { from { opacity: 0; } to { opacity: 1; } }

/* Not-reported values stay in place, visibly muted. */
.absent { color: var(--muted); opacity: 0.65; font-style: italic; }
.details dd.absent { font-style: normal; }
.no-entry { margin: 0; font-size: 11.5px; line-height: 1.4; }

/* Server-rendered vessel content: visible until the map takes over, and the
   only thing a non-JS client or a crawler sees. */
.ssr {
  position: absolute;
  z-index: 4;
  inset: 70px 12px auto 12px;
  max-width: 680px;
  margin: 0 auto;
  padding: 22px 26px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.55;
  max-height: calc(100% - 110px);
  overflow-y: auto;
}
.ssr h1 { margin: 0 0 6px; font-size: 22px; }
.ssr-lede { margin: 0 0 16px; color: var(--muted); }
.ssr table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ssr caption { text-align: left; color: var(--muted); font-size: 11px; padding-bottom: 8px; }
.ssr th { text-align: left; font-weight: 500; color: var(--muted); padding: 5px 12px 5px 0; }
.ssr td { text-align: right; font-family: var(--mono); font-size: 12px; }
.ssr figure { margin: 16px 0 0; }
.ssr figure img { max-width: 100%; border-radius: 8px; }
.ssr figcaption { font-size: 11px; color: var(--muted); margin-top: 5px; }
.ssr a { color: var(--accent); }

.flag { cursor: default; }


/* Map controls stack above the legend in the bottom-left corner. The legend
   sits 38px up and changes height when collapsed, so track it. */
.maplibregl-ctrl-bottom-left {
  bottom: calc(var(--legend-h, 40px) + 48px);
  left: 0;
}

@media (max-width: 720px) {
  /* The legend is hidden on narrow screens, so the controls drop back down. */
  .maplibregl-ctrl-bottom-left { bottom: 34px; }
}

.photo-caveat { color: var(--muted); }

.results .empty {
  padding: 10px;
  cursor: default;
  display: block;
}
.results .empty:hover { background: none; }
.results .empty-hint {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}

/* Distance from the viewer, shown only when they are on screen themselves. */
.distance {
  margin: 14px 0 0;
  padding-top: 11px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.distance .distance-value { font-family: var(--mono); color: var(--accent); }
.distance .distance-label { color: var(--muted); font-size: 11.5px; }

/* ---------- range control ---------- */
.slider-field span { display: flex; justify-content: space-between; align-items: baseline; }
.slider-field output { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.slider-field input[type="range"] {
  width: 100%;
  height: 18px;
  margin: 0;
  background: none;
  accent-color: var(--accent);
  cursor: pointer;
}
