:root {
  color-scheme: dark;
  font-family: "Space Grotesk", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --bg-gradient-start: #0f172a;
  --bg-gradient-end: #1e293b;
  --accent: #facc15;
  --panel-bg: rgba(15, 23, 42, 0.85);
  --panel-border: rgba(148, 163, 184, 0.35);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body,
html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 20% 20%, #1f2937, transparent 55%),
    radial-gradient(circle at 80% 0%, rgba(56, 189, 248, 0.25), transparent 60%),
    linear-gradient(160deg, var(--bg-gradient-start), var(--bg-gradient-end));
  color: #e2e8f0;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  background: rgba(15, 23, 42, 0.65);
  padding: 1rem 2rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  backdrop-filter: blur(8px);
  z-index: 10;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.5);
}

.overlay h1 {
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.overlay p {
  font-size: 0.9rem;
  opacity: 0.8;
}

.control-panel {
  position: absolute;
  top: 2rem;
  left: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.1rem 1.25rem;
  min-width: 240px;
  max-width: min(320px, 24vw);
  background: rgba(15, 23, 42, 0.78);
  border-radius: 1.25rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(10px);
  z-index: 12;
  transition: opacity 200ms ease, transform 220ms ease;
}

.control-panel.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px);
}

.control-panel h2 {
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.85);
}

.cluster-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: min(40vh, 360px);
  overflow-y: auto;
  padding-right: 0.2rem;
}

.cluster-button,
.ghost-button {
  border: none;
  cursor: pointer;
  border-radius: 0.85rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background 160ms ease, transform 160ms ease, color 160ms ease;
}

.cluster-button {
  background: rgba(30, 41, 59, 0.72);
  color: rgba(226, 232, 240, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.cluster-button:hover {
  background: rgba(59, 130, 246, 0.2);
  color: #f8fafc;
  transform: translateY(-1px);
}

.cluster-button.active {
  background: rgba(59, 130, 246, 0.28);
  border-color: rgba(148, 163, 184, 0.45);
  color: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.45);
}

.cluster-button.is-hovered:not(.active) {
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(148, 163, 184, 0.4);
  color: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(191, 219, 254, 0.4);
}

.cluster-dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 999px;
  background: var(--dot-color, rgba(255, 255, 255, 0.8));
  box-shadow: 0 0 8px var(--dot-color, rgba(255, 255, 255, 0.6));
  flex-shrink: 0;
}

.ghost-button {
  justify-content: center;
  color: rgba(226, 232, 240, 0.8);
  background: rgba(30, 41, 59, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.ghost-button:hover {
  background: rgba(15, 23, 42, 0.65);
  color: #f8fafc;
}

.ghost-button.is-hidden {
  display: none;
}

#reset-focus {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#canvas-container {
  width: 100%;
  height: 100%;
}

#sparkle-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 8;
  mix-blend-mode: screen;
}

.sparkle {
  position: absolute;
  width: var(--sparkle-size, 10px);
  height: var(--sparkle-size, 10px);
  border-radius: 999px;
  pointer-events: none;
  background:
    radial-gradient(
      circle at 30% 30%,
      rgba(255, 255, 255, 0.95) 0%,
      rgba(255, 255, 255, 0.22) 38%,
      rgba(255, 255, 255, 0) 68%
    ),
    radial-gradient(
      circle at 70% 70%,
      rgba(255, 255, 255, 0.7) 0%,
      rgba(255, 255, 255, 0.1) 46%,
      rgba(255, 255, 255, 0) 72%
    ),
    radial-gradient(
      circle,
      var(--sparkle-color, rgba(250, 204, 21, 0.95)) 0%,
      var(--sparkle-accent, rgba(255, 255, 255, 0.8)) 55%,
      rgba(15, 23, 42, 0) 100%
    );
  box-shadow:
    0 0 calc(var(--sparkle-size, 10px) * 0.55)
      var(--sparkle-color, rgba(250, 204, 21, 0.45)),
    0 0 calc(var(--sparkle-size, 10px) * 0.4)
      var(--sparkle-accent, rgba(224, 231, 255, 0.55));
  mix-blend-mode: screen;
  filter: saturate(135%) brightness(1.05)
    drop-shadow(0 0 5px rgba(255, 255, 255, 0.45));
  transform: translate(-50%, -50%) rotate(var(--sparkle-rotation, 0deg)) scale(0.25);
  opacity: 0;
  animation:
    sparkle-trail 0.65s ease-out forwards,
    sparkle-flicker 0.65s ease-in-out forwards;
}

.sparkle::before {
  content: "";
  position: absolute;
  inset: 24%;
  border-radius: inherit;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.9) 0%,
    rgba(255, 255, 255, 0.04) 40%,
    rgba(255, 255, 255, 0) 70%
  );
  filter: blur(0.4px);
}

.sparkle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--sparkle-size, 10px) * 1.2);
  height: calc(var(--sparkle-size, 10px) * 1.2);
  background:
    linear-gradient(
      to right,
      rgba(255, 255, 255, 0) 0%,
      var(--sparkle-accent, rgba(255, 255, 255, 0.9)) 50%,
      rgba(255, 255, 255, 0) 100%
    ) center / 100% 26% no-repeat,
    linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0) 0%,
      var(--sparkle-accent, rgba(255, 255, 255, 0.9)) 50%,
      rgba(255, 255, 255, 0) 100%
    ) center / 26% 100% no-repeat;
  transform: translate(-50%, -50%) rotate(var(--sparkle-rotation, 0deg));
  opacity: 0.78;
  filter: blur(0.35px);
  mix-blend-mode: screen;
  animation: sparkle-rays 0.6s ease-out forwards;
}

@keyframes sparkle-trail {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--sparkle-rotation, 0deg))
      scale(0.25);
  }
  40% {
    opacity: 1;
    transform: translate(-50%, -50%)
      rotate(calc(var(--sparkle-rotation, 0deg) + 10deg)) scale(0.9);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%)
      rotate(calc(var(--sparkle-rotation, 0deg) + 22deg)) scale(1.35);
  }
}

@keyframes sparkle-flicker {
  0% {
    filter: saturate(120%) brightness(1.2);
  }
  50% {
    filter: saturate(160%) brightness(1.4);
  }
  100% {
    filter: saturate(115%) brightness(1.1);
  }
}

@keyframes sparkle-rays {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.35);
  }
  35% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.2);
  }
}

.tooltip {
  position: fixed;
  pointer-events: none;
  max-width: 360px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--panel-border);
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.4;
  z-index: 20;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.6);
}

.tooltip.hidden {
  opacity: 0;
  visibility: hidden;
}

.tooltip.visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 120ms ease-out;
}

.info-panel {
  position: absolute;
  bottom: 2rem;
  right: 2rem;
  width: min(420px, 90vw);
  padding: 1.2rem 1.4rem;
  border-radius: 1.2rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 45px rgba(2, 6, 23, 0.45);
  backdrop-filter: blur(12px);
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.info-panel.hidden {
  display: none;
}

#close-info {
  align-self: flex-end;
  border: none;
  background: rgba(148, 163, 184, 0.25);
  color: #e2e8f0;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  transition: background 120ms ease;
}

#close-info:hover {
  background: rgba(250, 204, 21, 0.35);
}

#info-title {
  font-size: 1.1rem;
  font-weight: 600;
}

#info-content {
  white-space: pre-line;
  font-size: 0.9rem;
  line-height: 1.5;
}

#info-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

#info-link:hover {
  text-decoration: underline;
}

#info-link.hidden {
  display: none;
}

@media (max-width: 768px) {
  .overlay {
    top: 1rem;
    width: 90vw;
    padding: 0.75rem 1.25rem;
  }

  .overlay h1 {
    font-size: 1.2rem;
  }

  .overlay p {
    font-size: 0.8rem;
  }

  .control-panel {
    top: auto;
    bottom: 1rem;
    left: 50%;
    transform: translate(-50%, 0);
    width: min(90vw, 420px);
    max-width: none;
  }

  .control-panel.is-hidden {
    transform: translate(-50%, 12px);
  }

  .cluster-buttons {
    max-height: 40vh;
  }

  .info-panel {
    bottom: 1rem;
    right: 1rem;
  }
}
