/* ─── Design Tokens ─── */
:root {
  --bg: #0b0e17;
  --bg-panel: rgba(15, 20, 35, 0.82);
  --text: #e2e8f0;
  --text-muted: #8b97b0;
  --accent: #64d2ff;
  --accent-dim: rgba(100, 210, 255, 0.18);
  --accent-hot: #ff6b9d;
  --border: rgba(100, 210, 255, 0.12);
  --radius: 12px;
  --blur: 18px;
}

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

html {
  color-scheme: dark;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

/* ─── Loading Overlay ─── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  color: var(--accent);
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: opacity 0.6s ease;
}
.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Glassmorphism Panel ─── */
.panel {
  position: fixed;
  background: var(--bg-panel);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  z-index: 10;
  color: var(--text);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.panel h2,
.panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

/* ─── Info Panel (top-left) ─── */
#info-panel {
  top: 20px;
  left: 20px;
  min-width: 200px;
  max-width: 300px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 13px;
}

.info-row .label {
  color: var(--text-muted);
}

.info-desc {
  margin: 10px 0 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-muted);
  max-width: 260px;
}

#info-panel select {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 12px;
  outline: none;
  max-width: 160px;
}

/* ─── Selection Panel (bottom-right) ─── */
.selection-panel {
  bottom: 20px;
  right: 20px;
  min-width: 200px;
}
.distance-row {
  color: var(--accent-hot);
  font-weight: 600;
  font-size: 14px;
  padding: 6px 0 2px;
}

/* ─── Controls Panel (bottom-left) ─── */
#controls-panel {
  bottom: 20px;
  left: 20px;
  min-width: 220px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}

.control-row label {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 12px;
}

.control-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  max-width: 110px;
}

.control-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.control-row select {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  outline: none;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-action {
  flex: 1;
  padding: 7px 0;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-action:hover {
  background: rgba(100, 210, 255, 0.28);
}
.btn-action:active {
  transform: scale(0.97);
}
.btn-accent {
  background: rgba(255, 107, 157, 0.15);
  color: var(--accent-hot);
  border-color: rgba(255, 107, 157, 0.2);
}
.btn-accent:hover {
  background: rgba(255, 107, 157, 0.28);
}

.btn-warn {
  background: rgba(255, 170, 50, 0.15);
  color: #ffaa32;
  border-color: rgba(255, 170, 50, 0.2);
}
.btn-warn:hover {
  background: rgba(255, 170, 50, 0.28);
}
.btn-info {
  background: rgba(100, 255, 218, 0.12);
  color: #64ffda;
  border-color: rgba(100, 255, 218, 0.2);
}
.btn-info:hover {
  background: rgba(100, 255, 218, 0.25);
}

.btn-small {
  width: 100%;
  margin-top: 6px;
  padding: 5px 0;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-small:hover {
  background: rgba(100, 210, 255, 0.28);
}

/* ─── Legend Panel (top-right) ─── */
#legend {
  top: 20px;
  right: 20px;
  min-width: 160px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 2px 0;
  color: var(--text-muted);
}

.legend-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 0;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
}

.swatch-carbon { background: #909090; }
.swatch-nitrogen { background: #3050f8; }
.swatch-oxygen { background: #ff0d0d; }
.swatch-hydrogen { background: #ffffff; }
.swatch-sulfur { background: #ffff30; }

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 5px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
  text-align: center;
  color: var(--accent);
}

/* ─── Tooltip ─── */
.tooltip {
  position: fixed;
  background: var(--bg-panel);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
}

.is-hidden {
  display: none;
}

/* ─── Toast notification ─── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 24px;
  font-size: 13px;
  color: var(--text);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── FPS Counter ─── */
.fps-badge {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  z-index: 10;
  font-variant-numeric: tabular-nums;
}

.home-link-wrap {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(11, 14, 23, 0.76);
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.home-link:hover,
.home-link:focus-visible {
  border-color: rgba(100, 210, 255, 0.32);
  color: var(--accent);
}

/* ─── Responsive ─── */
@media (max-width: 600px) {
  .panel {
    padding: 10px 14px;
  }
  #info-panel {
    top: 10px;
    left: 10px;
    right: 10px;
    min-width: auto;
  }
  #controls-panel {
    bottom: 10px;
    left: 10px;
    right: 10px;
    min-width: auto;
  }
  #legend {
    display: none;
  }
  .selection-panel {
    right: 10px;
    bottom: auto;
    top: 10px;
  }
}
