:root {
  --map-bg: #050609;
  --map-ink: #fff8e8;
  --map-muted: #9fb0bc;
  --map-soft: rgba(255, 255, 255, 0.08);
  --map-line: rgba(255, 255, 255, 0.15);
  --map-gold: #f4c75b;
  --map-cyan: #65e8ff;
  --map-mint: #6ff2c7;
  --map-rose: #ff6d8a;
  --map-violet: #a88cff;
  --map-panel: rgba(6, 9, 13, 0.74);
  --map-panel-strong: rgba(7, 11, 17, 0.92);
  --map-shadow: 0 28px 90px rgba(0, 0, 0, 0.42);
  --map-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--map-bg);
  color: var(--map-ink);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--map-ink);
  background:
    linear-gradient(180deg, rgba(4, 5, 8, 0.92), rgba(3, 4, 7, 0.98)),
    radial-gradient(circle at 20% 8%, rgba(101, 232, 255, 0.12), transparent 32%),
    radial-gradient(circle at 78% 2%, rgba(244, 199, 91, 0.12), transparent 28%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

body.map-grabbing,
body.map-grabbing * {
  cursor: grabbing !important;
  user-select: none;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.system-map-page {
  min-height: 100vh;
  position: relative;
  isolation: isolate;
}

#constellationMount {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  opacity: 0.55;
}

.map-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 80;
  width: 100%;
  height: 4px;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, var(--map-gold), var(--map-cyan), var(--map-rose));
  box-shadow: 0 0 26px rgba(101, 232, 255, 0.42);
}

.map-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(620px, 1fr) auto;
  padding: 16px;
  gap: 12px;
}

.map-topbar,
.map-statusbar {
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--map-line);
  border-radius: 8px;
  background: rgba(5, 7, 10, 0.72);
  box-shadow: var(--map-shadow);
  backdrop-filter: blur(18px);
}

.map-topbar {
  min-height: 74px;
  padding: 10px 12px;
}

.map-statusbar {
  min-height: 48px;
  padding: 10px 12px;
  color: var(--map-muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.map-brand {
  display: flex;
  align-items: center;
  min-width: 220px;
  gap: 12px;
  text-decoration: none;
}

.map-brand img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  filter: drop-shadow(0 0 18px rgba(244, 199, 91, 0.34));
}

.map-brand strong {
  display: block;
  font-size: clamp(1.06rem, 2vw, 1.45rem);
  line-height: 1.05;
}

.map-brand span,
.map-kicker,
.drawer-kicker {
  display: block;
  color: var(--map-gold);
  font-size: 0.68rem;
  font-weight: 950;
  letter-spacing: 0.16em;
  line-height: 1.2;
  text-transform: uppercase;
}

.map-tools {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
}

.map-search {
  min-width: 0;
  height: 46px;
  border: 1px solid var(--map-line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--map-ink);
  outline: none;
  background: rgba(255, 255, 255, 0.06);
}

.map-search:focus {
  border-color: rgba(101, 232, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(101, 232, 255, 0.12);
}

.segment-row,
.zoom-row,
.drawer-actions,
.route-list,
.related-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.segment,
.icon-btn,
.route-link,
.map-cta {
  min-height: 38px;
  border: 1px solid var(--map-line);
  border-radius: 8px;
  color: var(--map-ink);
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0;
  cursor: pointer;
  transition: transform 180ms var(--map-ease), border-color 180ms var(--map-ease), background 180ms var(--map-ease);
}

.segment {
  padding: 0 10px;
}

.segment.is-active,
.map-cta.primary {
  border-color: transparent;
  color: #08100f;
  background: linear-gradient(90deg, var(--map-gold), var(--map-cyan));
}

.icon-btn {
  width: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.segment:hover,
.icon-btn:hover,
.route-link:hover,
.map-cta:hover {
  transform: translateY(-2px);
  border-color: rgba(244, 199, 91, 0.72);
}

.map-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  white-space: nowrap;
}

.zoom-label {
  width: 58px;
  color: var(--map-muted);
  text-align: center;
  font-size: 0.76rem;
  font-weight: 950;
}

.map-board {
  position: relative;
  min-height: 620px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(244, 199, 91, 0.08), transparent 26%),
    rgba(4, 7, 10, 0.6);
  background-size: 44px 44px, 44px 44px, auto, auto;
  box-shadow: var(--map-shadow), inset 0 0 90px rgba(101, 232, 255, 0.05);
  touch-action: none;
}

.map-board::before {
  content: "";
  position: absolute;
  inset: 10%;
  border: 1px solid rgba(244, 199, 91, 0.18);
  border-radius: 50%;
  transform: rotate(-9deg);
  pointer-events: none;
}

.map-board::after {
  content: "";
  position: absolute;
  inset: 20% 28%;
  border: 1px solid rgba(101, 232, 255, 0.18);
  border-radius: 50%;
  transform: rotate(18deg);
  pointer-events: none;
}

.edge-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.edge-line {
  stroke: rgba(101, 232, 255, 0.28);
  stroke-width: 1.8;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px rgba(101, 232, 255, 0.24));
}

.edge-line.is-active {
  stroke: rgba(244, 199, 91, 0.78);
  stroke-width: 2.6;
}

.core-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  width: clamp(220px, 22vw, 390px);
  max-height: clamp(220px, 22vw, 390px);
  object-fit: contain;
  transform: translate(-50%, -50%);
  filter:
    drop-shadow(0 0 20px rgba(244, 199, 91, 0.32))
    drop-shadow(0 0 42px rgba(101, 232, 255, 0.18));
  pointer-events: none;
  user-select: none;
}

.core-pulse {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: clamp(300px, 34vw, 620px);
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(244, 199, 91, 0.22);
  box-shadow: inset 0 0 70px rgba(101, 232, 255, 0.08), 0 0 80px rgba(244, 199, 91, 0.1);
  pointer-events: none;
  animation: mapPulse 5.8s var(--map-ease) infinite;
}

.node-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
}

.system-node {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  gap: 3px;
  width: clamp(122px, 12vw, 174px);
  min-height: 70px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 10px;
  color: var(--map-ink);
  background: rgba(8, 12, 17, 0.84);
  box-shadow: 0 20px 58px rgba(0, 0, 0, 0.34), inset 0 0 22px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px);
  transform-origin: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.system-node:active {
  cursor: grabbing;
}

.system-node.is-hidden {
  opacity: 0.08;
  pointer-events: none;
}

.system-node.is-active {
  border-color: rgba(244, 199, 91, 0.86);
  background: rgba(18, 15, 8, 0.94);
  box-shadow: 0 24px 68px rgba(0, 0, 0, 0.44), 0 0 34px rgba(244, 199, 91, 0.22);
}

.system-node .node-type {
  color: var(--node-color, var(--map-cyan));
  font-size: 0.62rem;
  font-weight: 950;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.system-node strong {
  overflow-wrap: anywhere;
  font-size: clamp(0.78rem, 1.1vw, 0.94rem);
  line-height: 1.08;
}

.system-node small {
  color: var(--map-muted);
  font-size: 0.68rem;
  line-height: 1.25;
}

.system-node .node-dot {
  position: absolute;
  right: 9px;
  top: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--node-color, var(--map-cyan));
  box-shadow: 0 0 16px var(--node-color, var(--map-cyan));
}

.drawer {
  position: absolute;
  z-index: 12;
  right: 16px;
  top: 16px;
  bottom: 16px;
  width: min(380px, calc(100% - 32px));
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 16px;
  background: var(--map-panel-strong);
  box-shadow: var(--map-shadow);
  backdrop-filter: blur(20px);
  overflow: auto;
}

.drawer h1,
.drawer h2,
.drawer h3,
.drawer p {
  margin: 0;
}

.drawer h1 {
  font-size: clamp(1.7rem, 3vw, 2.8rem);
  line-height: 0.98;
}

.drawer p {
  color: #dce7ec;
  line-height: 1.56;
}

.drawer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.drawer-chip,
.related-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--map-muted);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.7rem;
  font-weight: 900;
}

.drawer-main {
  display: grid;
  gap: 14px;
  align-content: start;
  overflow: auto;
  padding-right: 4px;
}

.route-link {
  width: 100%;
  justify-content: space-between;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
}

.route-link span {
  color: var(--map-muted);
  font-size: 0.68rem;
}

.route-list {
  display: grid;
}

.related-chip {
  cursor: pointer;
}

.map-help {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 9;
  max-width: min(420px, calc(100% - 32px));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--map-muted);
  background: rgba(5, 7, 10, 0.74);
  box-shadow: 0 20px 54px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
  font-size: 0.78rem;
  line-height: 1.4;
}

.map-help strong {
  color: var(--map-ink);
}

.quick-dock {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  max-width: min(560px, calc(100% - 430px));
  gap: 8px;
}

.quick-dock .map-cta {
  background: rgba(6, 9, 13, 0.72);
  backdrop-filter: blur(12px);
}

.map-statusbar strong {
  color: var(--map-ink);
}

.map-footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes mapPulse {
  0%,
  100% {
    opacity: 0.42;
    transform: translate(-50%, -50%) scale(0.94);
  }

  50% {
    opacity: 0.78;
    transform: translate(-50%, -50%) scale(1.03);
  }
}

@media (max-width: 1120px) {
  .map-shell {
    grid-template-rows: auto minmax(700px, 1fr) auto;
  }

  .map-topbar {
    display: grid;
    align-items: stretch;
  }

  .map-brand {
    min-width: 0;
  }

  .map-tools {
    grid-template-columns: 1fr;
  }

  .segment-row,
  .zoom-row {
    justify-content: flex-start;
  }

  .quick-dock {
    max-width: calc(100% - 32px);
  }

  .drawer {
    top: auto;
    left: 16px;
    width: auto;
    height: min(42vh, 380px);
  }

  .map-help {
    display: none;
  }
}

@media (max-width: 640px) {
  .map-shell {
    padding: 10px;
    grid-template-rows: auto minmax(720px, 1fr) auto;
  }

  .map-topbar,
  .map-statusbar,
  .map-board,
  .drawer {
    border-radius: 8px;
  }

  .map-brand img {
    width: 46px;
    height: 46px;
  }

  .segment-row {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .segment {
    flex: 0 0 auto;
  }

  .core-logo {
    width: clamp(178px, 58vw, 260px);
    max-height: clamp(178px, 58vw, 260px);
  }

  .system-node {
    width: 124px;
    min-height: 66px;
    padding: 9px;
  }

  .drawer {
    left: 10px;
    right: 10px;
    bottom: 10px;
    height: min(38vh, 340px);
    padding: 14px;
  }

  .quick-dock {
    left: 10px;
    right: 10px;
    top: 10px;
    max-width: none;
  }

  .map-statusbar {
    display: grid;
    gap: 8px;
  }

  .map-footer-links {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }

  #constellationMount {
    opacity: 0.22;
  }
}
