/* ==========================================================================
   EDroutes – Karte: HUD, Systemdetails, Steuerung
   Cockpit-Instrument-Look; Farben, Schriften und Formen stehen in tokens.css
   (dort auch die Eckmarken --frame).
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; overscroll-behavior: none; }

#edmap {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

#ed3dmap {
  font-family: var(--font);
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
  touch-action: none;
}

#ed3dmap canvas { display: block; outline: none; }

a { -webkit-user-select: none; user-select: none; }

/* Sichtbarer Tastaturfokus */
#ed3dmap a:focus-visible,
#ed3dmap input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ==========================================================================
   Gemeinsame Panel-Optik (HUD + Systemdetails)
   ========================================================================== */

#hud,
#systemDetails {
  position: absolute;
  z-index: 999;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  background: var(--frame), var(--panel);
  background-origin: border-box;
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  backdrop-filter: blur(14px) saturate(130%);
  border: 1px solid var(--line);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.25) transparent;
}

#hud::-webkit-scrollbar,
#systemDetails::-webkit-scrollbar,
#systemDetails > div::-webkit-scrollbar { width: 6px; }
#hud::-webkit-scrollbar-thumb,
#systemDetails::-webkit-scrollbar-thumb,
#systemDetails > div::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.25);
  border-radius: 3px;
}

/* ==========================================================================
   HUD (Filter / Infos) – Desktop: linke Seitenleiste
   ========================================================================== */

#hud {
  top: calc(var(--gap) + var(--safe-t));
  left: calc(var(--gap) + var(--safe-l));
  bottom: auto;
  max-height: calc(100% - 2 * var(--gap) - var(--safe-t) - var(--safe-b));
  width: var(--hud-w);
  height: auto;
  padding: 18px 18px 22px;
  border-radius: var(--radius);
  transition: width 0.35s ease, transform 0.35s ease, opacity 0.25s ease;
}

#hud.enlarge {
  width: min(1100px, calc(100% - 2 * var(--gap) - var(--safe-l) - var(--safe-r)));
  background: var(--frame), var(--panel-sheet);
  background-origin: border-box;
}

#hud.collapsed {
  transform: translateX(calc(-100% - var(--gap) - var(--safe-l)));
  opacity: 0;
  pointer-events: none;
}

#hud > div { margin-bottom: 18px; clear: both; }

#hud h2,
#systemDetails h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  padding: 0;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
}
#hud h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }

#hud #infos h2,
#systemDetails > h2 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #fff;
  margin: 0 0 12px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
#hud #infos h2::after { display: none; }

#hud p { margin: 0 0 4px; }
#hud #distsol { font-family: var(--display); font-variant-numeric: tabular-nums; color: var(--cyan); font-weight: 600; }

#hud input { font: inherit; }
#hud input[type=text] {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
#hud input[type=range] { width: 100%; margin: 6px 0; padding: 0; accent-color: var(--accent); }

/* Koordinaten-Kacheln */
.coords {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 8px 0 12px;
  padding: 0;
  border: 0;
  font-family: var(--mono);
}
.coords::after { display: none; }
.coords > span {
  display: block;
  float: none;
  width: auto;
  min-width: 0;
  padding: 8px 4px;
  font-size: 0.92rem;
  line-height: 1.1;
  text-align: center;
  color: #fff;
  background: var(--raised);
  border: 1px solid var(--line);
  border-top: 2px solid var(--accent-line);
  border-radius: var(--radius-sm);
  box-shadow: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.coords > span::before {
  display: block;
  margin-bottom: 3px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.coords > span:nth-child(1)::before { content: "X"; }
.coords > span:nth-child(2)::before { content: "Y"; }
.coords > span:nth-child(3)::before { content: "Z"; }

/* ==========================================================================
   Filter- und Routenlisten
   ========================================================================== */

.check {
  display: inline-block;
  float: none;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-right: 10px;
  line-height: 1;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.25), 0 0 10px currentColor;
  vertical-align: -2px;
  transition: opacity 0.2s, box-shadow 0.2s;
}
.check::after { content: none; }

.map_filter,
.map_link {
  display: flex;
  align-items: center;
  margin: 0 0 4px;
  padding: 9px 10px;
  min-height: 40px;
  cursor: pointer;
  color: var(--text);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.map_filter:hover,
.map_link:hover {
  color: #fff;
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.map_filter.disabled { color: var(--muted); }
.map_filter.disabled .check {
  background: #2a2f3a !important;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1);
}

.show_childs {
  display: inline-block;
  margin-top: 6px;
  padding: 6px 2px;
  color: var(--cyan);
  cursor: pointer;
  text-decoration: none;
}
.show_childs:hover { text-decoration: underline; }

.map_filter.hidden { display: none; }
.open .map_filter.hidden { display: flex; }

#hud.enlarge #filters > div.open { columns: 240px; column-gap: 12px; }
#hud.enlarge .map_filter { width: 100%; max-width: none; break-inside: avoid; clear: both; }

/* ==========================================================================
   Systemdetails (Desktop: rechtes/linkes Panel, Popup-Variante mittig)
   ========================================================================== */

#systemDetails {
  top: calc(var(--gap) + var(--safe-t));
  left: calc(var(--gap) + var(--safe-l));
  bottom: auto;
  max-height: calc(100% - 2 * var(--gap) - var(--safe-t) - var(--safe-b));
  width: var(--hud-w);
  height: auto;
  padding: 20px 18px 0;
  border-radius: var(--radius);
  display: flex;             /* inline display:none (JS) überschreibt dies im Ruhezustand */
  flex-direction: column;
}

#systemDetails.popup-detail {
  top: 50%; left: 50%; bottom: auto;
  width: min(720px, calc(100% - 2 * var(--gap)));
  height: min(80%, 640px);
  transform: translate(-50%, -50%);
  border: 1px solid var(--line-strong);
}

#systemDetails img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }

/* Systemname + Copy-Button in einer Zeile */
#systemDetails > h2 {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
#systemName { flex: 1; min-width: 0; }

#systemDetails .copy { position: relative; flex: none; }

#systemDetails .copy-button {
  display: grid;
  place-items: center;
  min-inline-size: 28px;
  min-block-size: 28px;
  padding: 0;
  cursor: pointer;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
#systemDetails .copy-button:hover {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
}
#systemDetails .copy-button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
#systemDetails .copy-button .icon {
  grid-area: 1 / 1;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#systemDetails .copy-button .icon-check { opacity: 0; }
#systemDetails .copy-button[data-copied] { color: var(--cyan); border-color: var(--cyan); }
#systemDetails .copy-button[data-copied] .icon-copy { opacity: 0; }
#systemDetails .copy-button[data-copied] .icon-check { opacity: 1; }
#systemDetails .copy-button[data-failed] { color: #ff6b6b; border-color: #ff6b6b; }

/* Bestätigung: zugleich Live-Region; per opacity ein-/ausblenden (bleibt im Accessibility-Tree) */
#systemDetails .copy .tip {
  position: absolute;
  inset-block-start: calc(100% + 6px);
  inset-inline-end: 0;
  z-index: 1;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.3;
  white-space: nowrap;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
#systemDetails .copy .tip:not(:empty) { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  #systemDetails .copy-button,
  #systemDetails .copy .tip { transition: opacity 0.15s; }
}

#systemDetails > div {
  max-height: none;
  overflow: visible;
  color: #cfd6e2;
}
#systemDetails > div:not(.coords):not(#nav) {
  font-size: 0.95rem;
  line-height: 1.65;
}

/* Links zu EDSM, Inara und Spansh */
#systemDetails > .ext-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
#systemDetails .ext-links a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  color: var(--cyan);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: background 0.15s, border-color 0.15s;
}
#systemDetails .ext-links a:hover { background: rgba(63, 216, 230, 0.12); border-color: var(--cyan); }
#systemDetails .ext-links a:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

#nav {
  position: sticky;
  bottom: 0;
  margin: auto -18px 0;
  width: auto;
  display: flex;
  gap: 8px;
  padding: 14px 18px 16px;
  background: linear-gradient(to top, var(--panel-solid) 60%, rgba(10,13,18,0));
  text-align: center;
}
#nav > a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-height: 46px;
  margin: 0;
  padding: 0;
  cursor: pointer;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: none;
  transition: background 0.15s, border-color 0.15s;
}
#nav > a:hover,
#nav > a:active { background: var(--accent-soft); border-color: var(--accent); }
#nav > a:nth-child(2) { flex: 0 0 30%; }

/* ==========================================================================
   Steuerung oben rechts (2D/3D, Info, Optionen, Fullscreen)
   ========================================================================== */

#controls {
  position: absolute;
  top: calc(var(--gap) + var(--safe-t));
  right: calc(var(--gap) + var(--safe-r));
  z-index: 999;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 2 * var(--gap));
}

#controls a { cursor: pointer; }

#controls > a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  margin: 0;
  padding: 0 12px;
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--muted);
  text-decoration: none;
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
#controls > a:hover { color: #fff; border-color: var(--line-strong); }
#controls > a.selected {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
  box-shadow: inset 0 -2px 0 var(--accent);
}
#controls > a svg { width: 18px; height: 18px; display: block; }
#controls > a#tog-fullscreen { width: auto; }

/* Optionen-Dropdown */
#options {
  position: absolute;
  top: 46px;
  right: 0;
  width: max-content;
  min-width: 190px;
  margin: 0;
  padding: 8px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,0.65);
  clear: both;
}
#options a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  margin: 0;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: left;
  border-radius: var(--radius-sm);
}
#options a.loading { opacity: 0.6; cursor: progress; }
#options a:hover { background: rgba(255,255,255,0.06); }
#options a.active { color: var(--text); }
#options a::before {
  content: "";
  display: block;
  flex: 0 0 auto;
  width: 18px; height: 18px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: transparent;
}
#options a.active::before {
  content: "✓";
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  color: #000;
  background: var(--accent);
  border-color: var(--accent);
}

/* Filter-Knopf in der Leiste: sieht aus wie «Routen» (#controls > a, eingefärbt = .selected) */
#hudToggle { padding: 0 14px; }

/* Schliessen-Icon direkt im Widget links; die Zeile hat keine Höhe und bleibt beim Scrollen oben stehen */
#hud > .hud-close-row {
  position: sticky;
  top: -6px;
  z-index: 2;
  height: 0;
  margin: 0;
  overflow: visible;
}
.hud-close {
  position: absolute;
  top: -10px;
  right: -8px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.hud-close:hover { color: #fff; border-color: var(--line-strong); }
.hud-close:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* Fullscreen */
.map-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 999 !important;
}

/* ==========================================================================
   Ladeanzeige
   ========================================================================== */

#loader {
  position: absolute;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(ellipse at center, #0c1118 0%, #05070a 75%);
  color: var(--accent) !important;
  font-family: var(--font) !important;
  letter-spacing: 0.08em;
}
#loader #loadInfos { min-height: 1.5em; }
#loader #loadTimer { min-height: 1em; opacity: 0.7; }
#loader svg {
  margin: 18px auto 0;
  width: min(160px, 40vw);
  height: auto;
  aspect-ratio: 1;
}
#loader path { fill: var(--accent); stroke: #000; stroke-width: 0; opacity: 0; }

@keyframes hideshow { 0% {opacity:0} 10% {opacity:1} 100% {opacity:0} }
@keyframes inner    { 0% {opacity:0} 10% {opacity:1} 100% {opacity:0} }
.l1 { animation: hideshow 750ms linear infinite; }
.l2 { animation: inner 750ms linear infinite; }
.d19 { animation-delay: 750ms; }
.d18 { animation-delay: 710.52631579ms; }
.d17 { animation-delay: 671.05263158ms; }
.d16 { animation-delay: 631.57894737ms; }
.d15 { animation-delay: 592.10526316ms; }
.d14 { animation-delay: 552.63157895ms; }
.d13 { animation-delay: 513.15789474ms; }
.d12 { animation-delay: 473.68421053ms; }
.d11 { animation-delay: 434.21052632ms; }
.d10 { animation-delay: 394.73684211ms; }
.d9  { animation-delay: 355.26315789ms; }
.d8  { animation-delay: 315.78947368ms; }
.d7  { animation-delay: 276.31578947ms; }
.d6  { animation-delay: 236.84210526ms; }
.d5  { animation-delay: 197.36842105ms; }
.d4  { animation-delay: 157.89473684ms; }
.d3  { animation-delay: 118.42105263ms; }
.d2  { animation-delay: 78.94736842ms; }
.d1  { animation-delay: 39.47368421ms; }

/* ==========================================================================
   Tablet / Mobil: HUD und Details werden zu Bottom-Sheets
   ========================================================================== */

@media (max-width: 820px) {

  #hud,
  #systemDetails {
    top: auto;
    left: calc(var(--gap) + var(--safe-l));
    right: calc(var(--gap) + var(--safe-r));
    bottom: calc(var(--gap) + var(--safe-b));
    width: auto;
    max-height: 46vh;
    max-height: 46dvh;
    padding: 14px 14px 18px;
    border-radius: var(--radius);
    background: var(--frame), var(--panel-sheet);
    background-origin: border-box;
  }

  #hud.enlarge {
    width: auto;
    max-height: 70dvh;
  }
  #hud.enlarge #filters > div.open { columns: 1; }

  #hud.collapsed {
    transform: translateY(calc(100% + var(--gap) + var(--safe-b)));
  }

  /* Griff-Strich oben am Sheet */
  #hud::before {
    content: "";
    display: block;
    width: 38px; height: 4px;
    margin: -4px auto 12px;
    border-radius: 2px;
    background: var(--line-strong);
  }

  #hud #infos h2,
  #systemDetails > h2 { font-size: 1.05rem; }

  /* Systemdetails: Platz für Navigation reservieren */
  #systemDetails {
    max-height: 58dvh;
    padding-bottom: 0;
  }
  #systemDetails.popup-detail {
    top: auto; left: calc(var(--gap) + var(--safe-l)); bottom: calc(var(--gap) + var(--safe-b));
    width: auto; height: auto; max-height: 70dvh;
    transform: none;
  }
  #nav { margin: auto -14px 0; padding: 12px 14px 14px; }

  .map_filter, .map_link { min-height: 44px; }

  /* Steuerung kompakter */
  #controls > a { min-width: 44px; height: 44px; }
  #options { top: 50px; }

  .hud-close { width: 44px; height: 44px; top: -14px; right: -12px; }
}

/* Sehr schmale Geräte */
@media (max-width: 420px) {
  #controls > a { padding: 0 10px; }
  #controls > a#tog-fullscreen { font-size: 0; padding: 0 12px; }
  #controls > a#tog-fullscreen::before { content: "⛶"; font-size: 1.1rem; }
  .coords > span { font-size: 0.85rem; }
}

/* Querformat auf Handys: wenig Höhe -> HUD als schmale Seitenleiste */
@media (max-height: 480px) and (orientation: landscape) and (max-width: 950px) {
  #hud, #systemDetails {
    top: calc(var(--gap) + var(--safe-t) + 50px);
    bottom: calc(var(--gap) + var(--safe-b));
    left: calc(var(--gap) + var(--safe-l));
    right: auto;
    width: min(320px, 42vw);
    max-height: none;
  }
  #systemDetails { top: calc(var(--gap) + var(--safe-t)); }
  #hud::before { display: none; }
  #hud.collapsed { transform: translateX(calc(-100% - var(--gap) - var(--safe-l))); }
}

/* Reduzierte Bewegung respektieren */
@media (prefers-reduced-motion: reduce) {
  #hud, .check, .map_filter, #nav > a { transition: none; }
  .l1, .l2 { animation-duration: 2s; }
}
