:root {
  /* brand accents — identical in both themes */
  --blue: #77a8f3;
  --violet: #8f7ceb;
  --magenta: #c62dd9;
  --gradient: linear-gradient(135deg, #77a8f3 0%, #8f7ceb 45%, #c62dd9 100%);
  --font: 'Manrope', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* light theme — default surface */
  --bg: #ffffff;
  --soft: #f6f7ff;
  --text: #131826;
  --muted: #5e6475;
  --line: #e6e8f2;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-active: rgba(255, 255, 255, 0.98);
  --panel-border: rgba(230, 232, 242, 0.9);
  --grid-line: rgba(143, 124, 235, 0.045);
  --frame-line: rgba(230, 232, 242, 0.7);
  --scene-bg:
    radial-gradient(ellipse 65% 50% at 50% 50%, rgba(143, 124, 235, 0.05) 0%, transparent 70%),
    radial-gradient(ellipse 30% 25% at 50% 50%, rgba(198, 45, 217, 0.06) 0%, transparent 60%),
    linear-gradient(135deg, #fbfcff 0%, #f6f7ff 50%, #faf6ff 100%);
  --shadow: 0 12px 36px rgba(55, 63, 110, 0.08);
  --shadow-active: 0 22px 60px rgba(143, 124, 235, 0.20), 0 0 0 1px rgba(143, 124, 235, 0.1);
  color-scheme: light;
}

/* dark theme — follows system preference unless overridden by the toggle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0a0a10;
    --soft: #12121c;
    --text: #f1f2fa;
    --muted: #9a9fb5;
    --line: rgba(255, 255, 255, 0.09);
    --panel: rgba(24, 24, 36, 0.72);
    --panel-active: rgba(32, 32, 46, 0.94);
    --panel-border: rgba(255, 255, 255, 0.14);
    --grid-line: rgba(143, 124, 235, 0.09);
    --frame-line: rgba(255, 255, 255, 0.10);
    --scene-bg:
      radial-gradient(ellipse 65% 50% at 50% 50%, rgba(143, 124, 235, 0.16) 0%, transparent 70%),
      radial-gradient(ellipse 30% 25% at 50% 50%, rgba(198, 45, 217, 0.13) 0%, transparent 60%),
      linear-gradient(135deg, #0a0a10 0%, #0d0d16 50%, #100e17 100%);
    --shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
    --shadow-active: 0 22px 60px rgba(143, 124, 235, 0.35), 0 0 0 1px rgba(143, 124, 235, 0.25);
    color-scheme: dark;
  }
}

/* dark theme — manual override via the toggle (persisted in localStorage) */
:root[data-theme="dark"] {
  --bg: #0a0a10;
  --soft: #12121c;
  --text: #f1f2fa;
  --muted: #9a9fb5;
  --line: rgba(255, 255, 255, 0.09);
  --panel: rgba(24, 24, 36, 0.72);
  --panel-active: rgba(32, 32, 46, 0.94);
  --panel-border: rgba(255, 255, 255, 0.14);
  --grid-line: rgba(143, 124, 235, 0.09);
  --frame-line: rgba(255, 255, 255, 0.10);
  --scene-bg:
    radial-gradient(ellipse 65% 50% at 50% 50%, rgba(143, 124, 235, 0.16) 0%, transparent 70%),
    radial-gradient(ellipse 30% 25% at 50% 50%, rgba(198, 45, 217, 0.13) 0%, transparent 60%),
    linear-gradient(135deg, #0a0a10 0%, #0d0d16 50%, #100e17 100%);
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  --shadow-active: 0 22px 60px rgba(143, 124, 235, 0.35), 0 0 0 1px rgba(143, 124, 235, 0.25);
  color-scheme: dark;
}

/* light theme — manual override forces light even if the system is dark */
:root[data-theme="light"] {
  --bg: #ffffff;
  --soft: #f6f7ff;
  --text: #131826;
  --muted: #5e6475;
  --line: #e6e8f2;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-active: rgba(255, 255, 255, 0.98);
  --panel-border: rgba(230, 232, 242, 0.9);
  --grid-line: rgba(143, 124, 235, 0.045);
  --frame-line: rgba(230, 232, 242, 0.7);
  --scene-bg:
    radial-gradient(ellipse 65% 50% at 50% 50%, rgba(143, 124, 235, 0.05) 0%, transparent 70%),
    radial-gradient(ellipse 30% 25% at 50% 50%, rgba(198, 45, 217, 0.06) 0%, transparent 60%),
    linear-gradient(135deg, #fbfcff 0%, #f6f7ff 50%, #faf6ff 100%);
  --shadow: 0 12px 36px rgba(55, 63, 110, 0.08);
  --shadow-active: 0 22px 60px rgba(143, 124, 235, 0.20), 0 0 0 1px rgba(143, 124, 235, 0.1);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .35s ease, color .35s ease;
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

/* Visually hidden, but accessible to screen readers and SEO crawlers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.node:focus-visible {
  outline: 3px solid rgba(119, 168, 243, .45);
  outline-offset: 4px;
}

.scene {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  isolation: isolate;
  background: var(--scene-bg);
  transition: background .35s ease;
}

.scene::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 56px 56px;
  -webkit-mask-image: radial-gradient(circle at 50% 50%, #000 25%, transparent 78%);
          mask-image: radial-gradient(circle at 50% 50%, #000 25%, transparent 78%);
  pointer-events: none;
  z-index: 0;
  transition: background-image .35s ease;
}

.scene::after {
  content: "";
  position: absolute;
  inset: 22px;
  border: 1px solid var(--frame-line);
  border-radius: 28px;
  pointer-events: none;
  z-index: 9;
  transition: border-color .35s ease;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#bg { z-index: 1; }
#mid { z-index: 2; }
#core { z-index: 4; }

/* ---------- TOP BAR ---------- */
.top-bar {
  position: absolute;
  top: 38px;
  left: 56px;
  right: 56px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  background-image: url('../assets/logo/vm-logo.png');
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  filter: drop-shadow(0 6px 14px rgba(143, 124, 235, 0.30));
}

.brand-status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

.brand-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.18);
  animation: livePulse 2s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.18); }
  50%      { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0.06); }
}

.top-right {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  pointer-events: none;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease, transform 0.2s ease;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: rgba(143, 124, 235, 0.45);
  transform: scale(1.08);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

/* base (no data-theme attribute yet) reads as light — sun shown */
.theme-toggle .i-moon { display: none; }
.theme-toggle .i-sun { display: block; }

:root[data-theme="dark"] .theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .i-sun { display: none; }
  :root:not([data-theme]) .theme-toggle .i-moon { display: block; }
}

/* ---------- NODES (orbiting capsules) ---------- */
.nodes {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.node {
  --pull-x: 0px;
  --pull-y: 0px;
  --drift-x: 0px;
  --drift-y: 0px;
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform:
    translate(-50%, -50%)
    translate(var(--pull-x), var(--pull-y))
    translate(var(--drift-x), var(--drift-y));
  display: inline-flex;
  align-items: center;
  gap: 11px;
  padding: 10px 18px 10px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition:
    background 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease,
    color 0.3s ease,
    scale 0.4s cubic-bezier(0.34, 1.4, 0.64, 1),
    transform 1.4s cubic-bezier(0.4, 0, 0.4, 1);
  will-change: transform;
}

.node-dot {
  position: relative;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--gradient);
  box-shadow: 0 0 0 4px rgba(143, 124, 235, 0.10);
  transition: box-shadow 0.3s ease;
  flex-shrink: 0;
}

.node-dot::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: inherit;
  filter: blur(6px);
  opacity: 0.55;
  z-index: -1;
}

.node:hover,
.node.is-active {
  background: var(--panel-active);
  border-color: rgba(143, 124, 235, 0.45);
  box-shadow: var(--shadow-active);
  scale: 1.08;
}

.node:hover .node-dot,
.node.is-active .node-dot {
  box-shadow:
    0 0 0 6px rgba(143, 124, 235, 0.16),
    0 0 22px rgba(198, 45, 217, 0.55);
}

/* ---------- NODE TOOLTIP ----------
   Desktop: shown on hover / keyboard focus, pure CSS.
   Touch: no real hover, so app.js toggles .tip-shown on the first tap
   (which also suppresses that tap's navigation) — a second tap follows
   the link through. Content comes from data-tip so each pill only
   states its text once. */
.node::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 14px);
  transform: translate(-50%, 4px);
  width: max-content;
  max-width: 220px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--panel-active);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-active);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  line-height: 1.45;
  white-space: normal;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
}

.node:hover::after,
.node:focus-visible::after,
.node.tip-shown::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* VM GEO sits at the very top of the ring — flip its tooltip below the
   pill so it doesn't get pushed past the top edge. */
.node[data-id="geo"]::after {
  bottom: auto;
  top: calc(100% + 14px);
  transform: translate(-50%, -4px);
}

.node[data-id="geo"]:hover::after,
.node[data-id="geo"]:focus-visible::after,
.node[data-id="geo"].tip-shown::after {
  transform: translate(-50%, 0);
}

@media (max-width: 680px) {
  .node::after { max-width: 170px; font-size: 11.5px; padding: 8px 12px; }
}

/* node positions on a circle around center */
.node[data-id="geo"]      { --x: 50%; --y: 19%; }
.node[data-id="ads"]      { --x: 78%; --y: 30%; }
.node[data-id="tour"]     { --x: 87%; --y: 58%; }
.node[data-id="web"]      { --x: 72%; --y: 82%; }
.node[data-id="analytics"] { --x: 28%; --y: 82%; }
.node[data-id="creative"] { --x: 13%; --y: 58%; }
.node[data-id="media"]    { --x: 22%; --y: 30%; }

/* ---------- BOTTOM BAR ---------- */
.bottom-bar {
  position: absolute;
  bottom: 38px;
  left: 56px;
  right: 56px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  opacity: 0.7;
  pointer-events: none;
}

/* ---------- PRIVACY NOTE (small print) ---------- */
.privacy-note {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  margin: 0;
  max-width: 90%;
  font-size: 9px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  color: var(--muted);
  opacity: 0.4;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

@media (max-width: 680px) {
  .privacy-note {
    bottom: calc(4px + env(safe-area-inset-bottom, 0px));
    font-size: 7.5px;
    white-space: normal;
  }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 980px) {
  .top-bar, .bottom-bar { left: 28px; right: 28px; }
  .scene::after { inset: 14px; border-radius: 22px; }

  .node[data-id="geo"]      { --x: 50%; --y: 20%; }
  .node[data-id="ads"]      { --x: 76%; --y: 33%; }
  .node[data-id="tour"]     { --x: 80%; --y: 62%; }
  .node[data-id="web"]      { --x: 70%; --y: 84%; }
  .node[data-id="analytics"] { --x: 30%; --y: 84%; }
  .node[data-id="creative"] { --x: 16%; --y: 62%; }
  .node[data-id="media"]    { --x: 20%; --y: 33%; }
}

@media (max-width: 680px) {
  .top-bar {
    top: calc(22px + env(safe-area-inset-top, 0px));
    left: 18px;
    right: 18px;
  }
  .bottom-bar {
    bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    left: 18px;
    right: 18px;
    font-size: 9px;
    letter-spacing: 0.14em;
  }
  .brand-text { display: none; }
  .top-right { gap: 10px; }
  /* icon-only status on phones — the full "Live ecosystem" label doesn't
     fit next to the theme toggle without crowding or overflowing */
  .brand-status-label { display: none; }
  .theme-toggle { width: 30px; height: 30px; }
  .theme-toggle svg { width: 14px; height: 14px; }
  .scene::after { inset: 8px; border-radius: 16px; }

  .node { padding: 7px 12px 7px 9px; font-size: 11px; gap: 8px; }
  .node-dot { width: 9px; height: 9px; }

  /* Fallback ring for the first paint before js/app.js runs (or if it
     fails) — layoutNodes() immediately overrides these via inline style,
     computed from the real sphere radius so it never overlaps it. */
  .node[data-id="geo"]      { --x: 50%; --y: 24%; }
  .node[data-id="ads"]      { --x: 72%; --y: 36%; }
  .node[data-id="tour"]     { --x: 74%; --y: 60%; }
  .node[data-id="web"]      { --x: 65%; --y: 76%; }
  .node[data-id="analytics"] { --x: 35%; --y: 76%; }
  .node[data-id="creative"] { --x: 20%; --y: 60%; }
  .node[data-id="media"]    { --x: 22%; --y: 36%; }
}

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