:root {
  color-scheme: dark;
  --bg: #05010f;
  --bg-spot-a: rgba(60, 16, 123, 0.55);
  --bg-spot-b: rgba(0, 166, 255, 0.35);
  --bg-spot-paused-a: rgba(255, 118, 183, 0.35);
  --bg-spot-paused-b: rgba(74, 255, 198, 0.35);
  --panel-bg: rgba(10, 8, 28, 0.72);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-shadow: 0 30px 90px rgba(8, 3, 26, 0.55);
  --text: #f6f7ff;
  --muted: rgba(232, 236, 255, 0.68);
  --accent: #7497ff;
  --accent-strong: #61f5ff;
  --chip-size: 48px;
  --font-body: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  --hud-blur: saturate(150%) blur(18px);
  --panel-blur: saturate(160%) blur(22px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% -10%, var(--bg-spot-a), transparent 40%),
    radial-gradient(circle at 90% 10%, var(--bg-spot-b), transparent 55%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background 400ms ease;
}

body[data-paused="true"] {
  background:
    radial-gradient(circle at 15% 5%, var(--bg-spot-paused-a), transparent 55%),
    radial-gradient(
      circle at 80% 20%,
      var(--bg-spot-paused-b),
      transparent 50%
    ),
    var(--bg);
}

.noscript {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 0, 8, 0.9);
  z-index: 10;
  font-size: 1.1rem;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  cursor: crosshair;
}

.hud {
  position: fixed;
  top: 1.75rem;
  left: 1.75rem;
  backdrop-filter: var(--hud-blur);
  background: rgba(14, 6, 35, 0.5);
  padding: 1.2rem 1.5rem;
  border-radius: 1.4rem;
  max-width: min(460px, 80vw);
  box-shadow: 0 18px 40px rgba(5, 2, 18, 0.45);
  border: 1px solid rgba(132, 129, 255, 0.2);
  z-index: 4;
}

.hud h1 {
  margin: 0 0 0.2rem;
  font-size: clamp(1.4rem, 2vw + 0.6rem, 2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.hud .tagline {
  margin: 0;
  font-weight: 500;
  color: var(--muted);
  font-size: clamp(0.9rem, 1vw + 0.6rem, 1rem);
}

.tips {
  margin-top: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: rgba(225, 230, 255, 0.65);
}

.tips span {
  background: rgba(137, 133, 255, 0.12);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.control-panel {
  position: fixed;
  top: 1.75rem;
  right: 1.75rem;
  width: clamp(280px, 22vw + 120px, 360px);
  max-height: calc(100vh - 3.5rem);
  overflow: hidden auto;
  padding: 1.6rem;
  border-radius: 1.6rem;
  background: var(--panel-bg);
  backdrop-filter: var(--panel-blur);
  border: 1px solid var(--panel-border);
  box-shadow: var(--panel-shadow);
  display: grid;
  gap: 1.6rem;
  z-index: 5;
  transition:
    transform 320ms ease,
    opacity 220ms ease;
}

body[data-panel-open="false"] .control-panel {
  transform: translateY(-6px) translateX(420px);
  opacity: 0;
  pointer-events: none;
}

.control-panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.control-section {
  display: grid;
  gap: 0.9rem;
}

.control-section header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.control-section h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(222, 226, 255, 0.8);
}

.control-section p {
  margin: 0;
  font-size: 0.8rem;
  color: rgba(223, 227, 255, 0.52);
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 0.75rem;
}

.palette-chip {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 1.1rem;
  border: 1px solid transparent;
  background: linear-gradient(
    135deg,
    var(--c0) 0%,
    var(--c1) 33%,
    var(--c2) 66%,
    var(--c3) 100%
  );
  box-shadow: 0 12px 24px rgba(6, 2, 20, 0.35);
  cursor: pointer;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease;
}

.palette-chip::after {
  content: attr(data-label);
  position: absolute;
  inset: auto 0 -1.35rem 0;
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: rgba(233, 236, 255, 0.75);
}

.palette-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.palette-chip:hover,
.palette-chip:focus-visible {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 18px 36px rgba(6, 2, 20, 0.45);
}

.palette-chip[aria-pressed="true"] {
  border-color: rgba(255, 255, 255, 0.7);
  box-shadow: 0 20px 40px rgba(5, 2, 22, 0.48);
}

.slider-group {
  display: grid;
  gap: 0.6rem;
}

.slider {
  display: grid;
  gap: 0.35rem;
}

.slider label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 20px rgba(0, 186, 255, 0.35);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 20px rgba(0, 186, 255, 0.35);
  cursor: pointer;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.action-row button {
  flex: 1;
  min-width: 120px;
}

.action-hint {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  color: rgba(223, 227, 255, 0.6);
  letter-spacing: 0.04em;
}

button {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.7rem 1.1rem;
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(
    135deg,
    rgba(109, 137, 255, 0.24),
    rgba(72, 255, 222, 0.18)
  );
  color: var(--text);
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 18px 32px rgba(8, 2, 24, 0.35);
  background: linear-gradient(
    135deg,
    rgba(109, 137, 255, 0.38),
    rgba(72, 255, 222, 0.32)
  );
}

button:active {
  transform: translateY(0);
}

.panel-footer {
  display: grid;
  gap: 0.55rem;
  font-size: 0.78rem;
  color: rgba(214, 218, 255, 0.55);
  line-height: 1.4;
}

.panel-footer kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.12rem 0.45rem;
  border-radius: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(123, 132, 255, 0.14);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: rgba(233, 236, 255, 0.75);
}

.panel-footer a {
  color: var(--accent-strong);
  text-decoration: none;
}

.panel-footer a:hover {
  text-decoration: underline;
}

.panel-toggle {
  position: fixed;
  bottom: 1.15rem;
  right: 1.15rem;
  width: 56px;
  height: 56px;
  border-radius: 999px;
  font-size: 1.35rem;
  display: grid;
  place-items: center;
  z-index: 6;
  background: linear-gradient(
    135deg,
    rgba(109, 137, 255, 0.38),
    rgba(72, 255, 222, 0.38)
  );
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 18px 40px rgba(7, 4, 26, 0.5);
}

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

.panel-toggle {
  display: none;
}

body[data-panel-open="false"] .panel-toggle {
  transform: rotate(-90deg);
}

@media (max-width: 960px) {
  .hud {
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    max-width: min(540px, calc(100vw - 3rem));
  }

  .tips {
    justify-content: center;
  }

  .control-panel {
    bottom: 5.5rem;
    right: 1.15rem;
    left: 1.15rem;
    top: auto;
    max-height: 55vh;
    transform-origin: bottom center;
  }

  body[data-panel-open="false"] .control-panel {
    transform: translateY(24px) scale(0.97);
  }

  .panel-toggle {
    display: grid;
  }
}

@media (max-width: 600px) {
  .hud {
    top: 1.1rem;
    padding: 1rem 1.1rem;
    border-radius: 1.2rem;
  }

  .tips {
    font-size: 0.75rem;
  }

  .control-panel {
    padding: 1.2rem;
    border-radius: 1.35rem;
    gap: 1.2rem;
  }

  .palette-grid {
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .control-panel,
  .palette-chip,
  button {
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }
}

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