:root {
  --bg-0: #07131f;
  --bg-1: #0c1f30;
  --ink: #e8f2f8;
  --muted: #8aa3b5;
  --line: rgba(140, 190, 210, 0.18);
  --cyan: #35d0c5;
  --amber: #f0b429;
  --rose: #ff6b6b;
  --panel: rgba(10, 28, 42, 0.78);
  --radius: 18px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Sora", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(53, 208, 197, 0.16), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(240, 180, 41, 0.12), transparent 50%),
    linear-gradient(165deg, var(--bg-0), var(--bg-1) 55%, #081722);
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(120, 180, 200, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 180, 200, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 85%);
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  width: 40vw;
  height: 40vw;
  top: 20%;
  left: 30%;
  background: radial-gradient(circle, rgba(53, 208, 197, 0.08), transparent 70%);
  filter: blur(40px);
  animation: drift 14s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}

@keyframes drift {
  from {
    transform: translate(-8%, -4%) scale(1);
  }
  to {
    transform: translate(10%, 8%) scale(1.15);
  }
}

.topbar,
.layout,
.footer {
  position: relative;
  z-index: 1;
}

.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0.75rem;
  display: grid;
  gap: 1rem;
}

.brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
}

.brand-mark {
  width: 14px;
  height: 42px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--amber), var(--cyan));
  box-shadow: 0 0 24px rgba(53, 208, 197, 0.45);
  animation: breathe 2.8s ease-in-out infinite;
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.7;
    transform: scaleY(0.92);
  }
  50% {
    opacity: 1;
    transform: scaleY(1);
  }
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
}

h1 {
  margin: 0.15rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 3.4vw, 2.35rem);
  font-weight: 700;
  line-height: 1.15;
}

.lead {
  margin: 0;
  max-width: 52ch;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.98rem;
}

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem 1.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.9fr);
  gap: 1.1rem;
  align-items: start;
}

.stage-frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: linear-gradient(180deg, rgba(8, 24, 36, 0.9), rgba(6, 18, 28, 0.95));
  box-shadow: var(--shadow);
  overflow: hidden;
}

#bondCanvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pulse-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px;
  border: 2px solid var(--amber);
  border-radius: 50%;
  animation: pulseOut 0.7s ease-out forwards;
}

@keyframes pulseOut {
  to {
    transform: scale(18);
    opacity: 0;
  }
}

.hint {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.panel {
  display: grid;
  gap: 1rem;
}

.meter-card,
.legend-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(10px);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow);
}

.meter-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.meter-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(53, 208, 197, 0.35);
  background: rgba(53, 208, 197, 0.1);
  color: var(--cyan);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.energy-readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.energy-readout .label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.energy-readout strong {
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-variant-numeric: tabular-nums;
}

.energy-readout .unit {
  margin-left: 0.25rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.progress-wrap {
  margin-bottom: 1rem;
}

.progress-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--amber));
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 18px rgba(240, 180, 41, 0.35);
}

.progress-threshold {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.55);
  transform: translateX(-1px);
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.actions {
  display: grid;
  gap: 0.55rem;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:not(:disabled):hover {
  transform: translateY(-1px);
}

.btn:not(:disabled):active {
  transform: translateY(1px) scale(0.99);
}

.btn.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  color: #102018;
  background: linear-gradient(135deg, var(--amber), #ffd978);
}

.btn.primary.flash {
  animation: btnFlash 0.45s ease;
}

@keyframes btnFlash {
  0% {
    filter: brightness(1);
  }
  40% {
    filter: brightness(1.35);
  }
  100% {
    filter: brightness(1);
  }
}

.btn.ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

.btn-icon {
  font-style: normal;
}

.status {
  margin: 0.9rem 0 0;
  min-height: 2.8em;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.status.alert {
  color: #ffd4a8;
}

.status.success {
  color: #9af0d8;
}

.legend-card h3 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.legend-list li {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.legend-list li:hover,
.legend-list li.active {
  border-color: rgba(53, 208, 197, 0.4);
  background: rgba(53, 208, 197, 0.08);
}

.legend-list li.broken {
  opacity: 0.55;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

.legend-meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.legend-meta strong {
  font-size: 0.9rem;
}

.legend-meta span {
  color: var(--muted);
  font-size: 0.72rem;
}

.legend-energy {
  font-variant-numeric: tabular-nums;
  color: var(--amber);
  font-size: 0.82rem;
  font-weight: 600;
}

.footnote {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.45;
}

.footer {
  max-width: 1180px;
  margin: 0 auto 1.25rem;
  padding: 0 1.25rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel {
    order: 2;
  }

  .stage {
    order: 1;
  }
}

@media (max-width: 560px) {
  .topbar,
  .layout,
  .footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .energy-readout {
    grid-template-columns: 1fr;
  }

  .meter-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .footer {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
