:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f8f4ff;
  background: #141126;
  color-scheme: dark;
  font-synthesis: none;
  --space: #141126;
  --space-deep: #0c0a17;
  --panel: rgba(28, 23, 49, .92);
  --panel-solid: #211b38;
  --line: rgba(224, 216, 255, .2);
  --muted: #c7bfd8;
  --pink: #ffb8d2;
  --blue: #aee2ff;
  --yellow: #ffe493;
  --mint: #b9f1d6;
  --lilac: #d9c5ff;
}

* { box-sizing: border-box; }

html,
body { min-height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--space);
  color: #f8f4ff;
}

button,
a { font: inherit; -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
.universe:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.space-app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 560px;
  overflow: hidden;
  background: var(--space);
}

.space-topbar {
  position: absolute;
  z-index: 30;
  top: 0;
  left: 0;
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 15px 10px;
  pointer-events: none;
}

.space-brand,
.space-exit,
.catalog-status { pointer-events: auto; }

.space-brand {
  padding: 7px 9px;
  color: #2b2342;
  background: var(--yellow);
  border: 1px solid #ffeeba;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .1em;
  text-decoration: none;
}

.space-top-actions {
  display: flex;
  gap: 7px;
  align-items: center;
}

.catalog-status {
  padding: 6px 8px;
  color: #162c39;
  background: var(--blue);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.space-exit {
  padding: 7px 9px;
  color: #f8f4ff;
  background: rgba(33, 27, 56, .9);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.space-stage { height: 100%; }

.space-heading {
  position: absolute;
  z-index: 10;
  top: calc(68px + env(safe-area-inset-top));
  left: 16px;
  max-width: min(65vw, 340px);
  pointer-events: none;
}

.space-heading > span {
  color: var(--pink);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .18em;
}

.space-heading h1 {
  margin: 2px 0 2px;
  color: #fff;
  font-size: clamp(24px, 6vw, 38px);
  line-height: 1.1;
}

.space-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
}

.axis-legend {
  position: absolute;
  z-index: 12;
  top: calc(132px + env(safe-area-inset-top));
  right: 12px;
  display: grid;
  gap: 5px;
  width: min(54vw, 270px);
  pointer-events: none;
}

.axis-chip {
  display: grid;
  grid-template-columns: 18px 1fr auto 1fr;
  gap: 5px;
  align-items: center;
  padding: 6px 8px;
  color: #f8f4ff;
  background: rgba(20, 17, 38, .78);
  border: 1px solid var(--line);
  border-radius: 9px;
  backdrop-filter: blur(8px);
  font-size: 8px;
  text-align: center;
}

.axis-chip b {
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  color: #241c37;
  border-radius: 5px;
  font-size: 10px;
}

.axis-chip i { color: var(--muted); font-style: normal; }
.axis-x b { background: var(--pink); }
.axis-y b { background: var(--blue); }
.axis-z b { background: var(--yellow); }

.universe {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.universe.dragging { cursor: grabbing; }

#spaceCanvas,
.node-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.node-layer { pointer-events: none; }

.space-node {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  width: 64px;
  height: 80px;
  overflow: visible;
  padding: 0;
  place-items: center;
  color: #241c37;
  background: var(--node-color, var(--pink));
  border: 2px solid rgba(255, 255, 255, .72);
  border-radius: 14px;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .06), 0 0 24px var(--node-glow, rgba(255, 184, 210, .45));
  cursor: pointer;
  opacity: 0;
  pointer-events: auto;
  transform-origin: center;
  will-change: transform, opacity;
}

.space-node:hover,
.space-node:focus-visible,
.space-node.selected {
  border-color: #fff;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, .17), 0 0 38px var(--node-glow, rgba(255, 184, 210, .65));
}

.space-node img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 11px;
}

.node-symbol {
  display: grid;
  width: 43px;
  height: 43px;
  place-items: center;
  background: rgba(255, 255, 255, .72);
  border-radius: 50%;
  font-size: 18px;
  font-weight: 900;
}

.node-caption {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  width: 128px;
  overflow: hidden;
  padding: 5px 7px;
  color: #fff;
  background: rgba(13, 10, 24, .88);
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 7px;
  font-size: 8px;
  font-weight: 700;
  line-height: 1.35;
  opacity: 0;
  text-align: center;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
}

.space-node:hover .node-caption,
.space-node:focus-visible .node-caption,
.space-node.selected .node-caption { opacity: 1; }

.loading-card,
.space-error {
  position: absolute;
  z-index: 20;
  top: 50%;
  left: 50%;
  display: grid;
  min-width: 220px;
  padding: 22px;
  place-items: center;
  color: #fff;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  text-align: center;
  transform: translate(-50%, -50%);
}

.loading-card strong,
.space-error strong { margin-top: 12px; font-size: 12px; }

.loading-orbit {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, .16);
  border-top-color: var(--pink);
  border-right-color: var(--blue);
  border-radius: 50%;
  animation: orbit 1s linear infinite;
}

@keyframes orbit { to { transform: rotate(360deg); } }

.space-error button {
  margin-top: 14px;
  padding: 10px 14px;
  color: #241c37;
  background: var(--yellow);
  border: 0;
  border-radius: 10px;
  font-weight: 800;
}

.view-controls {
  position: absolute;
  z-index: 18;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 44px 44px auto;
  gap: 7px;
}

.view-controls button {
  min-height: 44px;
  padding: 0 12px;
  color: #f8f4ff;
  background: rgba(33, 27, 56, .9);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
  backdrop-filter: blur(8px);
}

.view-controls button:last-child { font-size: 10px; }

.space-help,
.source-note {
  position: absolute;
  z-index: 11;
  left: 12px;
  margin: 0;
  color: var(--muted);
  background: rgba(20, 17, 38, .72);
  border-radius: 7px;
  font-size: 8px;
  pointer-events: none;
}

.space-help {
  bottom: calc(26px + env(safe-area-inset-bottom));
  padding: 5px 7px;
}

.source-note {
  right: 12px;
  bottom: calc(50px + env(safe-area-inset-bottom));
  padding: 6px 8px;
  color: #efe9ff;
  border: 1px solid var(--line);
  line-height: 1.45;
}

.work-drawer {
  position: absolute;
  z-index: 40;
  right: 12px;
  bottom: 12px;
  display: grid;
  grid-template-columns: 112px 1fr;
  width: min(520px, calc(100vw - 24px));
  max-height: min(460px, calc(100dvh - 100px));
  overflow: auto;
  color: #f8f4ff;
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 20px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .46);
  opacity: 0;
  pointer-events: none;
  transform: translateY(calc(100% + 28px));
  transition: transform .24s ease, opacity .2s ease;
}

.work-drawer.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.drawer-close {
  position: absolute;
  z-index: 2;
  top: 8px;
  right: 8px;
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  color: #fff;
  background: rgba(12, 10, 23, .72);
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
}

.drawer-cover {
  display: grid;
  min-height: 100%;
  overflow: hidden;
  place-items: center;
  color: #2a213e;
  background: var(--pink);
  border-radius: 19px 0 0 19px;
  background-position: center;
  background-size: cover;
}

.drawer-cover span {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  background: rgba(255, 255, 255, .74);
  border-radius: 50%;
  font-size: 25px;
  font-weight: 900;
}

.drawer-content { padding: 18px 44px 18px 16px; }

.drawer-kicker {
  color: var(--blue);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .12em;
}

.drawer-content h2 {
  margin: 4px 0 3px;
  color: #fff;
  font-size: 17px;
  line-height: 1.35;
}

.drawer-circle {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 10px;
}

.drawer-tags { display: flex; gap: 5px; flex-wrap: wrap; }

.drawer-tags span {
  padding: 4px 7px;
  color: #211a35;
  background: var(--lilac);
  border-radius: 999px;
  font-size: 8px;
  font-weight: 800;
}

.axis-values {
  display: grid;
  gap: 7px;
  margin: 13px 0;
}

.axis-values > div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px;
  align-items: center;
}

.axis-values dt { color: var(--muted); font-size: 8px; }

.axis-values dd {
  position: relative;
  height: 16px;
  margin: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, .1);
  border-radius: 999px;
}

.axis-values i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--pink);
  border-radius: inherit;
}

.axis-values > div:nth-child(2) i { background: var(--blue); }
.axis-values > div:nth-child(3) i { background: var(--yellow); }

.axis-values dd span {
  position: absolute;
  z-index: 1;
  right: 6px;
  color: #fff;
  font-size: 8px;
  font-weight: 900;
  line-height: 16px;
  text-shadow: 0 1px 3px #000;
}

.drawer-actions { display: flex; gap: 7px; flex-wrap: wrap; }

.drawer-actions button,
.drawer-actions a {
  padding: 9px 11px;
  color: #241c37;
  background: var(--yellow);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-size: 9px;
  font-weight: 900;
  text-decoration: none;
}

.drawer-actions a { color: #183449; background: var(--blue); }

.space-age {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  padding: 18px;
  place-items: center;
  background: rgba(10, 8, 20, .92);
}

.space-age-card {
  width: min(100%, 380px);
  padding: 24px;
  color: #2d2637;
  background: #fffaf7;
  border: 2px solid #ffb8d2;
  border-radius: 20px;
}

.space-age-card > span {
  color: #7d294c;
  font-size: 10px;
  font-weight: 900;
}

.space-age-card h2 { margin: 6px 0 9px; font-size: 23px; }
.space-age-card p { margin: 0 0 15px; color: #655c6a; font-size: 12px; line-height: 1.65; }

.space-age-card button,
.space-age-card a {
  display: block;
  width: 100%;
  padding: 12px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.space-age-card button { color: #fff; background: #773153; border: 0; cursor: pointer; }
.space-age-card a { margin-top: 8px; color: #245c78; background: #def2ff; text-decoration: none; }

@media (max-width: 640px) {
  .space-heading {
    top: calc(68px + env(safe-area-inset-top));
    max-width: calc(100vw - 32px);
  }

  .space-heading h1 { font-size: 27px; }

  .space-heading p {
    max-width: calc(100vw - 32px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .axis-legend {
    top: calc(142px + env(safe-area-inset-top));
    left: 12px;
    right: 12px;
    width: auto;
    gap: 4px;
  }

  .axis-chip {
    grid-template-columns: 22px 1fr auto 1fr;
    min-height: 31px;
    padding: 5px 8px;
    background: rgba(20, 17, 38, .96);
    backdrop-filter: none;
    font-size: 9px;
  }

  .axis-chip b {
    width: 22px;
    height: 22px;
  }

  .universe {
    top: calc(252px + env(safe-area-inset-top));
    right: 0;
    bottom: calc(176px + env(safe-area-inset-bottom));
    left: 0;
    border-top: 1px solid rgba(224, 216, 255, .08);
    border-bottom: 1px solid rgba(224, 216, 255, .08);
  }

  .space-node { width: 48px; height: 60px; border-radius: 11px; }
  .node-symbol { width: 34px; height: 34px; font-size: 15px; }
  .space-node img { border-radius: 9px; }

  .view-controls {
    bottom: calc(119px + env(safe-area-inset-bottom));
  }

  .source-note {
    bottom: calc(54px + env(safe-area-inset-bottom));
    padding: 7px 9px;
    background: rgba(20, 17, 38, .96);
  }

  .space-help {
    right: 12px;
    bottom: calc(26px + env(safe-area-inset-bottom));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .work-drawer {
    right: 8px;
    bottom: 8px;
    grid-template-columns: 86px 1fr;
    width: calc(100vw - 16px);
  }

  .drawer-content { padding: 15px 40px 15px 12px; }
  .drawer-content h2 { font-size: 14px; }
  .axis-values > div { grid-template-columns: 82px 1fr; }
}

@media (max-width: 380px) {
  .catalog-status { display: none; }
  .space-heading { top: calc(62px + env(safe-area-inset-top)); }
  .space-heading h1 { font-size: 25px; }
  .axis-legend { top: calc(132px + env(safe-area-inset-top)); }
  .universe { top: calc(240px + env(safe-area-inset-top)); }
  .space-help { max-width: none; line-height: 1.4; }
}

@media (max-height: 700px) and (max-width: 640px) {
  .space-heading { top: calc(60px + env(safe-area-inset-top)); }
  .space-heading h1 { font-size: 23px; }
  .space-heading p { display: none; }
  .axis-legend { top: calc(116px + env(safe-area-inset-top)); }
  .axis-chip { min-height: 28px; padding-block: 3px; }
  .universe {
    top: calc(218px + env(safe-area-inset-top));
    bottom: calc(160px + env(safe-area-inset-bottom));
  }
  .view-controls { bottom: calc(106px + env(safe-area-inset-bottom)); }
  .source-note { bottom: calc(48px + env(safe-area-inset-bottom)); }
  .space-help { bottom: calc(22px + env(safe-area-inset-bottom)); }
}

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