/* =====================================================================
   GLOBAL & RESET
   ===================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: #fafaf9;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

/* =====================================================================
   UI HEADER & TOOLTIP
   ===================================================================== */
.ui-header {
  position: fixed;
  top: 1.5rem;
  left: 1.5rem;
  z-index: 30;
  pointer-events: none;
}

.ui-header__title {
  font-size: 1.5rem;
  font-weight: 900;
  color: #1c1917;
  letter-spacing: -0.025em;
}

.ui-header__desc {
  font-size: 0.75rem;
  color: #57534e;
  margin-top: 0.25rem;
  max-width: 24rem;
  line-height: 1.625;
}

.speed-badge {
  font-weight: 800;
  color: #065f46;
  background-color: #ecfdf5;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  border: 1px solid #a7f3d0;
}

#ball-tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #e7e5e4;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  border-radius: 0.75rem;
  padding: 0.75rem;
  z-index: 40;
  max-width: 20rem;
  backdrop-filter: blur(4px);
  transition: opacity 0.2s;
}

.tooltip-title {
  font-weight: 700;
  color: #292524;
  font-size: 0.875rem;
}

.tooltip-latin {
  font-size: 0.75rem;
  color: #78716c;
  font-style: italic;
  margin-top: 0.125rem;
}

.tooltip-cat {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  border-width: 1px;
  border-style: solid;
  margin-top: 0.5rem;
  display: inline-block;
}

.tooltip-cat--flag    { color: #1d4ed8; background: #eff6ff; border-color: #dbeafe; }
.tooltip-cat--amazon  { color: #b45309; background: #fffbeb; border-color: #fef3c7; }
.tooltip-cat--atlantic{ color: #be123c; background: #fff1f2; border-color: #ffe4e6; }
.tooltip-cat--welsh   { color: #047857; background: #ecfdf5; border-color: #d1fae5; }

.hidden { display: none !important; }

/* =====================================================================
   CANVAS & SVG LAYERS
   ===================================================================== */
#canvas-bg { z-index: 1; }
#interactive-map { z-index: 10; pointer-events: none; }

/* SVG Connection Layer */
#svg-connections {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  overflow: visible;
}

.connection-line {
  stroke: #94a3b8 !important;
  stroke-width: 2.5px !important;
  stroke-linecap: round;
  fill: none !important;
  stroke-dasharray: 6 6;
  animation: dash-flow 25s linear infinite;
}

.connection-line--thick {
  stroke: #64748b !important;
  stroke-width: 4px !important;
  stroke-linecap: round;
  fill: none !important;
  stroke-dasharray: 8 6;
  animation: dash-flow 20s linear infinite;
}

@keyframes dash-flow {
  to { stroke-dashoffset: -100; }
}}

@keyframes dash-flow {
  to { stroke-dashoffset: -100; }
}

/* =====================================================================
   TWO-LAYER TRANSFORM NODE ARCHITECTURE
   ===================================================================== */
/* Layer 1: JS-only translate coordinates */
.node {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform: translate3d(0, 0, 0);
  will-change: transform;
}

/* Layer 2: CSS-only centering, state scale & active styling */
.node__body {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%) scale(var(--node-scale, 1));
  transition: opacity 0.28s ease, transform 0.38s cubic-bezier(0.34, 1.45, 0.64, 1);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-drag: none;
  cursor: grab;
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
  margin: 0;
  border: 0;
  font: inherit;
  color: inherit;
  background: none;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.node__body:active { cursor: grabbing; }
.node__body:focus-visible { outline: 3px solid #0284c7; outline-offset: 5px; }

.node.is-collapsed .node__body {
  --node-scale: 0.25;
  opacity: 0;
  pointer-events: none;
}

.node.is-dragging .node__body {
  transition: none;
}

/* =====================================================================
   ROOT GLASS SPHERES
   ===================================================================== */
.sphere {
  border-radius: 50%;
  position: relative;
  box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.18), inset 0 -8px 15px rgba(0, 0, 0, 0.15);
}

.sphere::after,
.chip::after {
  content: '';
  position: absolute;
  top: 8%;
  left: 8%;
  width: 38%;
  height: 20%;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0) 100%);
  border-radius: 50%;
  transform: rotate(-35deg);
  pointer-events: none;
}

.sphere--lg { width: 8rem; height: 8rem; }
.sphere--md { width: 7rem; height: 7rem; }

@media (min-width: 768px) {
  .sphere--lg { width: 9rem; height: 9rem; }
  .sphere--md { width: 8rem; height: 8rem; }
}

.theme-perma {
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #fda4af 30%, #be123c 85%, #1e1b4b 100%);
  border: 3px solid #be123c;
}

.theme-natphil {
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #fef08a 35%, #eab308 80%, #ea580c 100%);
  border: 3px solid #eab308;
}

.theme-natforest {
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #a7f3d0 35%, #15803d 80%, #166534 100%);
  border: 3px solid #15803d;
}

.sphere__glyph {
  font-size: 2.5rem;
  font-weight: 900;
  color: #ffffff;
  line-height: 1;
}

.sphere__label {
  font-size: 0.625rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 0.25rem;
  line-height: 1.15;
}

.sphere__icon {
  width: 1.5rem;
  height: 1.5rem;
  margin-bottom: 0.25rem;
}

/* =====================================================================
   SUBFOLDER CHILD CHIPS
   ===================================================================== */
.chip {
  width: 4.8rem;
  height: 4.8rem;
  border-radius: 50%;
  border: 2px solid;
  font-size: 0.75rem;
  font-weight: 900;
  box-shadow: 0 8px 20px -3px rgba(0, 0, 0, 0.15), inset 0 -4px 8px rgba(0, 0, 0, 0.12);
  line-height: 1.1;
  padding: 0 0.3rem;
}

.chip--rose      { background: #fecdd3; border-color: #f43f5e; color: #4c0519; }
.chip--indigo    { background: #c7d2fe; border-color: #6366f1; color: #1e1b4b; }
.chip--amber     { background: #fef3c7; border-color: #f59e0b; color: #451a03; }
.chip--orange    { background: #ffedd5; border-color: #f97316; color: #431407; }
.chip--amberdeep { background: #fde68a; border-color: #d97706; color: #451a03; }
.chip--emerald   { background: #d1fae5; border-color: #10b981; color: #022c22; }
.chip--teal      { background: #ccfbf1; border-color: #14b8a6; color: #042f2e; }
.chip--emerdeep  { background: #a7f3d0; border-color: #059669; color: #022c22; }

@media (prefers-reduced-motion: reduce) {
  .connection-line { animation: none; }
  .node__body { transition-duration: 0.01ms; }
}