/* Colors come from the style family (ADR 0039): web/src/theme.ts sets the --ui-* properties on
   <html> for the chosen style and the visitor's scheme. The fallbacks below are the default
   style (siemens) so the page reads right before the script runs, light or dark. `:host` gives
   the same defaults inside the SDK's shadow root, which has no theme script (ADR 0040). */
:root,
:host {
  color-scheme: light dark;
  --ui-surface: #f3f3f0;
  --ui-card: #fff;
  --ui-text: #000028;
  --ui-muted: #4c4c68;
  --ui-border: transparent;
  --ui-shadow: 0 1px 4px rgb(0 0 40 / 25%);
  --ui-primary: #007993;
  --ui-primary-2: #007993;
  --ui-primary-hover: #005159;
  --ui-on-primary: #fff;
  --ui-link: #007993;
  --ui-hover: #ebf7f8;
  --ui-focus: #1491eb;
  --ui-pin: #009999;
  --ui-pin-core: #fff;
  --ui-pin-label: #007373;
  --ui-attr-bg: rgb(255 255 255 / 85%);
  --ui-attr-text: #000028;
  --ui-attr-link: #007993;
  --ui-ctrl-bg: #fff;
  --ui-ctrl-icon: #000028;
}

/* No flash of a light page for dark-mode visitors on the default colorScheme=auto. */
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --ui-surface: #000028;
    --ui-card: #00183b;
    --ui-text: #fff;
    --ui-muted: #ccccd4;
  }
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--ui-surface);
  color: var(--ui-text);
}

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

/* space=stars (ADR 0050): NASA SVS Deep Star Maps 2020 (public domain) behind the globe. The
   image is only fetched while the class is set; its opacity follows the zoom (web/src/space.ts). */
#map.map-space::before {
  content: "";
  position: absolute;
  inset: 0;
  background: #00000e url("./stars.webp") center / cover no-repeat;
  opacity: var(--map-space-opacity, 1);
  pointer-events: none;
}

/* An author `display` (like .status's flex) beats the UA [hidden] rule; without this the
   hidden full-size status overlay sits on top of the map and swallows every pointer event. */
[hidden] {
  display: none !important;
}

.status {
  position: absolute;
  inset: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  font-size: 0.95rem;
  color: var(--ui-muted);
}

.notice {
  position: absolute;
  bottom: 2.25rem;
  left: 0.5rem;
  right: 0.5rem;
  z-index: 3;
  margin: 0;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  color: var(--ui-text);
  background: var(--ui-card);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 20%);
}

/* Map controls follow the scheme. MapLibre draws its icons as dark SVG backgrounds; on a dark
   control they are inverted. */
.maplibregl-ctrl-group {
  background: var(--ui-ctrl-bg);
}

.maplibregl-ctrl-group:not(:empty) {
  box-shadow: 0 0 0 1px var(--ui-border), 0 0 0 2px rgb(0 0 0 / 10%);
}

.maplibregl-ctrl-group button + button {
  border-top-color: var(--ui-muted);
}

:root[data-scheme="dark"] .maplibregl-ctrl-icon,
:root[data-scheme="dark"] .maplibregl-ctrl-attrib-button {
  filter: invert(1);
}

:root[data-style="bold"][data-scheme="light"] .maplibregl-ctrl-icon {
  filter: none;
}

.maplibregl-ctrl button:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 2px;
}

/* The canvas fills the frame, so an outline around it would be clipped. Draw the ring inside
   the frame on top of the map instead, on a band of the card color, visible on the street map
   and on imagery (WCAG 2.4.7, 2.4.11; ADR 0031). */
.maplibregl-canvas:focus-visible {
  outline: none;
}

.maplibregl-map:has(.maplibregl-canvas:focus-visible)::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  border: 3px solid var(--ui-focus);
  box-shadow: inset 0 0 0 2px var(--ui-card);
  pointer-events: none;
}

/* Text only assistive technology reads: the map description (ADR 0031). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.maplibregl-ctrl-attrib {
  font-size: 0.7rem;
}

.maplibregl-ctrl.maplibregl-ctrl-attrib,
.maplibregl-ctrl-attrib.maplibregl-compact-show {
  color: var(--ui-attr-text);
  background: var(--ui-attr-bg);
}

.maplibregl-ctrl-attrib a {
  color: var(--ui-attr-link);
}

/* Siemens pin: the SVG tip sits on the point (anchor bottom). The drawing takes the scheme's
   pin colors; the SVG attributes are the fallback. */
.sie-pin {
  line-height: 0;
  cursor: default;
}

.sie-pin path,
.map-poster-pin path {
  fill: var(--ui-pin);
  stroke: var(--ui-pin-core);
}

.sie-pin circle,
.map-poster-pin circle {
  fill: var(--ui-pin-core);
}

/* Static poster over the map until the first interaction (ADR 0028). The images and the pin sit
   at the pixels MapLibre will draw them at, so the swap does not move anything. */
.map-poster-root.maplibregl-map {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

.map-poster {
  position: absolute;
  inset: 0;
  cursor: grab;
}

.map-poster:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: -3px;
}

.map-poster-image {
  position: absolute;
  top: 0;
  display: block;
  user-select: none;
  pointer-events: none;
}

.map-poster-pin {
  position: absolute;
  top: 0;
  left: 0;
  line-height: 0;
  pointer-events: none;
}

/* Place card. It is a MapLibre control, so pointer events on it never reach the map and the map
   keeps every gesture outside its box. */
.place-card {
  box-sizing: border-box;
  max-width: min(320px, calc(100vw - 64px));
  margin: 10px 0 0 10px !important;
  padding: 12px 14px;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ui-text);
  background: var(--ui-card);
  /* The scheme's border as an inset ring: it adds no size, so card and pin layout stay put. */
  box-shadow: var(--ui-shadow), inset 0 0 0 2px var(--ui-border);
}

.pc-title {
  margin: 0 0 2px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.pc-detail {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ui-muted);
  overflow-wrap: anywhere;
}

/* Directions mode: distance and travel time, as on Google's card. */
.pc-summary {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ui-link);
}

/* Directions mode: lettered stops (A origin, B, C waypoints); the destination is the pin. */
.sie-stop {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-sizing: border-box;
  border: 3px solid var(--ui-pin);
  background: var(--ui-card);
  color: var(--ui-text);
  font: 700 12px/20px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-align: center;
  box-shadow: 0 1px 3px rgb(0 0 40 / 30%);
}

.pc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.pc-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  font: 700 14px Arial, Helvetica, sans-serif;
  border: 1px solid var(--ui-link);
  border-radius: 0;
  cursor: pointer;
  text-decoration: none;
}

/* The primary action: Interactive Blue with white on light (5.1:1), the Bold Dynamic Petrol
   gradient with Deep Blue on dark (WCAG 1.4.3; tested in test/styles.test.ts). */
.maplibregl-ctrl .pc-btn.pc-primary {
  width: auto;
  height: 34px;
  color: var(--ui-on-primary);
  background: linear-gradient(90deg, var(--ui-primary), var(--ui-primary-2));
  border-color: transparent;
}

.maplibregl-ctrl .pc-btn.pc-primary:hover {
  background: var(--ui-primary-hover);
}

.pc-btn.pc-secondary {
  color: var(--ui-link);
  background: transparent;
}

.pc-btn.pc-secondary:hover {
  background: var(--ui-hover);
}

.pc-menu {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--ui-muted);
}

.pc-menu-title {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ui-muted);
}

.pc-menu ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pc-route {
  display: block;
  padding: 8px 4px;
  font-size: 14px;
  color: var(--ui-text);
  text-decoration: none;
}

.pc-route:hover {
  background: var(--ui-hover);
}

.pc-btn:focus-visible,
.pc-route:focus-visible,
.pc-result:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 2px;
}

.pc-category {
  margin: 0 0 2px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ui-link);
  overflow-wrap: anywhere;
}

/* Search results: numbered like the pins, the selected one marked. Scrolls inside the card so
   it never covers the whole frame. */
.pc-results {
  margin: 10px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--ui-muted);
  max-height: 40vh;
  overflow-y: auto;
  list-style: none;
  counter-reset: result;
}

.pc-results li {
  counter-increment: result;
}

.maplibregl-ctrl .pc-result {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  height: auto;
  padding: 6px 4px 6px 30px;
  position: relative;
  font: 14px Arial, Helvetica, sans-serif;
  text-align: left;
  color: var(--ui-text);
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

.pc-result::before {
  content: counter(result);
  position: absolute;
  left: 4px;
  top: 7px;
  width: 18px;
  height: 18px;
  font: 700 11px/18px Arial, Helvetica, sans-serif;
  text-align: center;
  color: var(--ui-on-primary);
  background: var(--ui-primary);
  border-radius: 50%;
}

.maplibregl-ctrl .pc-result:hover {
  background: var(--ui-hover);
}

.maplibregl-ctrl .pc-result[aria-current="true"] {
  background: var(--ui-hover);
  box-shadow: inset 3px 0 0 var(--ui-pin);
}

.pc-result-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.pc-result-category {
  font-size: 12px;
  color: var(--ui-muted);
}

/* Search result pins carry their number; the selected one is drawn larger and on top. */
.sie-pin-label {
  position: absolute;
  top: 10px;
  left: 0;
  width: 36px;
  font: 700 12px/15px Arial, Helvetica, sans-serif;
  text-align: center;
  color: var(--ui-pin-label);
  pointer-events: none;
}

/* The pin is the marker element itself (absolutely positioned by MapLibre), so the label's
   absolute position is relative to it. */
.sie-pin.sie-result {
  cursor: pointer;
}

.maplibregl-marker.is-selected {
  z-index: 2;
}

/* Scale the drawing, not the marker: MapLibre positions the marker with its own transform. */
.sie-pin.sie-result.is-selected svg {
  transform: scale(1.2);
  transform-origin: 50% 100%;
}

.sie-pin.sie-result:focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 2px;
}

/* Narrow frames (phones, side columns): one line of address, card spans the width left of
   the zoom buttons. */
@media (max-width: 480px) {
  .place-card {
    width: calc(100vw - 64px);
    max-width: none;
    margin: 8px 0 0 8px !important;
    padding: 10px 12px;
  }

  .pc-detail {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .pc-results {
    max-height: 22vh;
  }

  .pc-btn {
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
  }

  /* Both actions must fit on one row in a 358 px frame, or the card hides the pin. */
  .pc-btn svg:last-child {
    display: none;
  }
}
