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

:root {
  --bg: #0a0b0f;
  --bg-mid: #0f1118;
  --string: rgba(200, 220, 255, 0.4);
  --string-dim: rgba(160, 190, 255, 0.15);
  --node: rgba(255, 248, 230, 0.7);
  --cursor: #7ec8e3;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-slow: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

/* Cosmic background */
.bg-base {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 0;
}

.bg-shift {
  position: fixed;
  inset: -50%;
  z-index: 0;
  background:
    radial-gradient(ellipse 90% 70% at 30% 20%, rgba(30, 40, 70, 0.5) 0%, transparent 50%),
    radial-gradient(ellipse 80% 90% at 70% 80%, rgba(25, 35, 55, 0.4) 0%, transparent 50%),
    radial-gradient(ellipse 100% 100% at 50% 50%, rgba(20, 28, 45, 0.3) 0%, transparent 60%);
  animation: bgShift 20s var(--ease-out-slow) infinite alternate;
}

@keyframes bgShift {
  0% { transform: translate(-2%, -2%) scale(0.98); opacity: 0.8; }
  100% { transform: translate(3%, 3%) scale(1.05); opacity: 1; }
}

/* Cursor glow — soft, cosmic */
.cursor-glow {
  position: fixed;
  width:  min(85vmax, 640px);
  height: min(85vmax, 640px);
  left: 0;
  top: 0;
  margin-left: calc(-1 * min(42.5vmax, 320px));
  margin-top:  calc(-1 * min(42.5vmax, 320px));
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(100, 140, 180, 0.12) 0%,
    rgba(60, 90, 130, 0.05) 40%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.5s var(--ease-out);
}

.cursor-glow.ready {
  opacity: 1;
}

body.cursor-custom {
  cursor: none;
}

body.cursor-custom a {
  cursor: none;
}

.cursor-dot {
  position: fixed;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cursor);
  box-shadow: 0 0 12px rgba(126, 200, 227, 0.6);
  pointer-events: none;
  z-index: 9998;
  transform: translate(-50%, -50%);
  transition: transform 0.1s var(--ease-out);
}

.viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  z-index: 2;
}

.viewport.grabbing {
  cursor: grabbing;
}

.world {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: 0 0;
  will-change: transform;
  width: 0;
  height: 0;
}

/* —— Strings SVG: centered in world —— */
.strings-svg {
  position: absolute;
  left: -500px;
  top: -500px;
  width: 1000px;
  height: 1000px;
  overflow: visible;
}

.string {
  stroke: var(--string);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  animation: stringFlow 8s linear infinite;
  filter: url(#glow);
}

.string--1 { animation-duration: 10s; animation-delay: 0s; stroke: url(#strGrad1); }
.string--2 { animation-duration: 12s; animation-delay: -2s; stroke: var(--string-dim); }
.string--3 { animation-duration: 9s;  animation-delay: -1s; stroke: url(#strGrad2); }
.string--4 { animation-duration: 14s; animation-delay: -3s; stroke: var(--string-dim); }
.string--5 { animation-duration: 11s; animation-delay: -0.5s; stroke: url(#strGrad1); }
.string--6 { animation-duration: 13s; animation-delay: -4s; stroke: var(--string-dim); }
.string--7 { animation-duration: 10s; animation-delay: -2.5s; stroke: url(#strGrad2); }
.string--8 { animation-duration: 6s;  animation-delay: -1.5s; stroke: var(--string-dim); stroke-width: 1; }

@keyframes stringFlow {
  0%   { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -1; }
}

/* Nodes: particles at intersections */
.node {
  fill: var(--node);
  filter: drop-shadow(0 0 4px rgba(255, 248, 230, 0.4));
  animation: nodePulse 3s var(--ease-in-out) infinite alternate;
  transform-origin: center;
  transform-box: fill-box;
}

.node--1 { animation-delay: 0s; }
.node--2 { animation-delay: 0.4s; }
.node--3 { animation-delay: 0.8s; }
.node--4 { animation-delay: 0.2s; }
.node--5 { animation-delay: 0.6s; }

@keyframes nodePulse {
  0% { opacity: 0.5; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1.1); }
}

@media (max-width: 600px) {
  .cursor-dot {
    display: none;
  }
  body.cursor-custom {
    cursor: auto;
  }
  body.cursor-custom a {
    cursor: pointer;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bg-shift {
    animation: none;
    opacity: 0.9;
  }
  .cursor-glow {
    display: none;
  }
  .string {
    animation: none;
    stroke-dasharray: none;
    stroke-dashoffset: 0;
  }
  .node {
    animation: none;
    opacity: 0.8;
  }
  .viewport {
    cursor: default;
  }
  .world {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) !important;
  }
}
