/* ==========================================================================
   Molecular Planet — deep-space laboratory instrument panel
   Palette is deliberately locked to the values already baked into the
   Three.js scene (sceneSetup.js / planet.js) so the DOM chrome and the
   WebGL content read as one instrument, not a page laid over a demo.
   ========================================================================== */

:root {
  --bg-void: #090c11;
  --panel-bg: rgba(14, 19, 27, 0.66);
  --panel-bg-strong: rgba(14, 19, 27, 0.86);
  --panel-border: rgba(198, 214, 219, 0.14);
  --panel-border-strong: rgba(198, 214, 219, 0.24);

  --teal: #4dd9c4;
  --teal-soft: rgba(77, 217, 196, 0.4);
  --teal-faint: rgba(77, 217, 196, 0.14);

  --amber: #e8a94d;
  --amber-soft: rgba(232, 169, 77, 0.4);
  --amber-faint: rgba(232, 169, 77, 0.14);

  --text-bright: #eaf3f2;
  --text-muted: #93a3ac;
  --text-faint: #5f6e78;

  --font-ui: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', monospace;

  --radius-panel: 20px;
  --radius-button: 12px;
  --blur: 20px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-void);
  color: var(--text-bright);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
}

.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;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}

/* ---- WebGL surface ------------------------------------------------- */

.scene-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---- shared glass surface -------------------------------------------- */

.glass {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-panel);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

/* ---- icon buttons ------------------------------------------------- */

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  color: var(--text-muted);
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.icon-button:hover {
  color: var(--teal);
  border-color: var(--teal-soft);
}

/* ---- top HUD bar ------------------------------------------------- */

.hud-top {
  position: fixed;
  top: 20px;
  left: 20px;
  right: 20px;
  z-index: 30;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.hud-top > * {
  pointer-events: auto;
}

.wordmark {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  line-height: 1.35;
}

.wordmark-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.wordmark-subtitle {
  font-size: 11.5px;
  color: var(--text-faint);
  font-weight: 400;
}

/* ---- legend / gesture guide ------------------------------------------ */

.legend-panel {
  position: fixed;
  top: 74px;
  left: 20px;
  z-index: 29;
  width: min(320px, calc(100vw - 40px));
  padding: 18px 18px 14px;
  transform-origin: top left;
  transition: opacity 0.28s var(--ease), transform 0.28s var(--ease), visibility 0.28s;
}

.legend-panel.collapsed {
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  visibility: hidden;
  pointer-events: none;
}

.legend-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--teal);
  letter-spacing: 0.01em;
}

.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.legend-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.legend-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--teal-faint);
  color: var(--teal);
  margin-top: 1px;
}

.legend-text {
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-muted);
}

.legend-text strong {
  color: var(--text-bright);
  font-weight: 600;
}

/* ---- mode badge (bottom HUD status line) ------------------------------ */

.mode-badge {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 28;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 10px 16px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}

.mode-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: color 0.3s var(--ease);
}

.mode-icon svg {
  display: block;
}

.mode-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.3s var(--ease);
  white-space: nowrap;
}

.mode-badge[data-mode="idle"] {
  border-color: var(--panel-border);
}

.mode-badge[data-mode="zoom"] .mode-icon,
.mode-badge[data-mode="zoom"] .mode-label,
.mode-badge[data-mode="rotate"] .mode-icon,
.mode-badge[data-mode="rotate"] .mode-label,
.mode-badge[data-mode="pan"] .mode-icon,
.mode-badge[data-mode="pan"] .mode-label {
  color: var(--teal);
}
.mode-badge[data-mode="zoom"],
.mode-badge[data-mode="rotate"],
.mode-badge[data-mode="pan"] {
  border-color: var(--teal-soft);
  box-shadow: 0 0 24px -8px var(--teal-soft);
}

.mode-badge[data-mode="select"] .mode-icon,
.mode-badge[data-mode="select"] .mode-label,
.mode-badge[data-mode="explode"] .mode-icon,
.mode-badge[data-mode="explode"] .mode-label {
  color: var(--amber);
}
.mode-badge[data-mode="select"],
.mode-badge[data-mode="explode"] {
  border-color: var(--amber-soft);
  box-shadow: 0 0 24px -8px var(--amber-soft);
}

/* ---- molecule info panel --------------------------------------------- */

.molecule-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 32;
  width: min(340px, 88vw);
  height: 100%;
  padding: 26px 24px;
  background: var(--panel-bg-strong);
  border-inline-start: 1px solid var(--panel-border);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  transform: translateX(105%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.36s var(--ease), opacity 0.3s var(--ease);
  display: flex;
  flex-direction: column;
}

.molecule-panel.hidden {
  display: none;
}

.molecule-panel.visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.close-button {
  align-self: flex-start;
  margin-bottom: 18px;
}

.molecule-swatch {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  margin-bottom: 16px;
  box-shadow: 0 0 26px -4px currentColor;
}

.molecule-formula {
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--teal);
  letter-spacing: 0.02em;
}

.molecule-name {
  font-size: 19px;
  font-weight: 600;
  margin-top: 6px;
  margin-bottom: 14px;
}

.molecule-description {
  font-size: 13.5px;
  line-height: 1.9;
  color: var(--text-muted);
  margin: 0;
}

/* ---- webcam picture-in-picture ---------------------------------------- */

.pip {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 27;
  width: 208px;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  background: #000;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.pip-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0.82;
}

.pip-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- modal overlays (welcome / error) --------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, rgba(9, 12, 17, 0.55) 0%, rgba(9, 12, 17, 0.88) 100%);
  transition: opacity 0.35s var(--ease), visibility 0.35s;
}

.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-card {
  width: min(420px, 100%);
  padding: 40px 34px;
  text-align: center;
  background: var(--panel-bg-strong);
  border: 1px solid var(--panel-border-strong);
  border-radius: var(--radius-panel);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

.modal-eyebrow {
  margin: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--amber);
  text-transform: uppercase;
}

.modal-title {
  margin: 0 0 14px;
  font-size: 26px;
  font-weight: 700;
}

.modal-body {
  margin: 0 0 26px;
  font-size: 14px;
  line-height: 1.85;
  color: var(--text-muted);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 30px;
  border-radius: var(--radius-button);
  border: 1px solid var(--teal-soft);
  background: var(--teal-faint);
  color: var(--teal);
  font-size: 14.5px;
  font-weight: 600;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}

.primary-button:hover {
  background: rgba(77, 217, 196, 0.24);
}

.primary-button:active {
  transform: scale(0.97);
}

.spinner {
  width: 30px;
  height: 30px;
  margin: 4px auto 0;
  border-radius: 50%;
  border: 2.5px solid var(--panel-border-strong);
  border-top-color: var(--teal);
  animation: spin 0.85s linear infinite;
}

.status-text {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--text-faint);
  min-height: 1em;
}

.hidden {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- responsive ------------------------------------------------------- */

@media (max-width: 640px) {
  .wordmark-subtitle {
    display: none;
  }
  .legend-panel {
    left: 12px;
    right: 12px;
    width: auto;
  }
  .pip {
    width: 132px;
    bottom: 16px;
    right: 16px;
  }
  .mode-badge {
    bottom: 16px;
    padding: 8px 16px 8px 12px;
  }
  .mode-label {
    font-size: 12px;
  }
  .molecule-panel {
    width: 100%;
  }
  .modal-card {
    padding: 30px 22px;
  }
}

/* ---- reduced motion ---------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .legend-panel,
  .molecule-panel,
  .modal-overlay,
  .icon-button,
  .primary-button,
  .mode-badge,
  .mode-icon,
  .mode-label {
    transition-duration: 0.01ms !important;
  }
}
