:root {
  --bg:       #06080f;
  --panel:    rgba(16, 19, 28, 0.78);
  --border:   rgba(155, 182, 234, 0.18);
  --text:     #e9eef7;
  --muted:    #9bb6ea;
  --dim:      #6e87b8;
  --accent:   #22d3ee;
  --warm:     #ffa276;
  --good:     #6ee7b7;
  --bad:      #f57b8a;
  --orbit-fg: rgba(155, 182, 234, 0.12);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background:
    radial-gradient(ellipse 100% 60% at 50% 0%, rgba(124,58,237,0.10), transparent 70%),
    var(--bg);
  color: var(--text); overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--muted); text-decoration: none; }
a:hover { color: #fff; }

/* ── Top bar ──────────────────────────────────────────────────── */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: 56px;
  padding: 0 20px;
  display: flex; align-items: center; gap: 14px;
  z-index: 50;
  background: linear-gradient(to bottom, rgba(6,8,15,0.92), transparent);
  backdrop-filter: blur(6px);
}
.brand { font-weight: 600; letter-spacing: 0.04em; color: var(--text); font-size: 17px; }
.brand-glyph { color: var(--warm); margin-right: 4px; }
.brand-sub { color: var(--dim); font-size: 13px; }
.burger {
  margin-left: auto;
  width: 36px; height: 36px; background: transparent; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
}
.burger span { display: block; width: 16px; height: 1.5px; background: var(--text); transition: transform 200ms, opacity 200ms; }
.burger.open span:nth-child(1) { transform: translateY(5px) rotate(45deg); }
.burger.open span:nth-child(2) { opacity: 0; }
.burger.open span:nth-child(3) { transform: translateY(-5px) rotate(-45deg); }
.nav-menu {
  position: fixed; top: 56px; right: 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px; min-width: 160px;
  display: flex; flex-direction: column; gap: 2px;
  opacity: 0; pointer-events: none; transform: translateY(-6px);
  transition: opacity 180ms, transform 180ms; backdrop-filter: blur(12px);
  z-index: 51;
}
.nav-menu.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.nav-menu a { padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.nav-menu a:hover { background: rgba(155, 182, 234, 0.08); color: #fff; }

/* ── Stage ────────────────────────────────────────────────────── */
.stage { position: fixed; inset: 0; }

/* Horizontal scroll of star-system cards. Each protein is its own
   complete world. */
.universe {
  position: absolute; inset: 60px 0 220px 0;
  display: flex; gap: 28px;
  align-items: center;
  padding: 24px 32px;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
}
.universe::-webkit-scrollbar { height: 6px; }
.universe::-webkit-scrollbar-thumb { background: rgba(155,182,234,0.2); border-radius: 3px; }

.universe-empty {
  margin: auto;
  max-width: 480px;
  text-align: center;
  color: var(--dim);
  font-size: 14px; line-height: 1.6;
}

/* One star-system card per recommended protein. */
.system {
  position: relative;
  flex: 0 0 auto;
  width: 360px; height: 440px;
  scroll-snap-align: center;
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 38%, rgba(124,58,237,0.18), rgba(6,8,15,0.92) 70%),
    rgba(16,19,28,0.5);
  border: 1px solid var(--border);
  box-shadow: 0 14px 40px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.03);
  overflow: hidden;
  cursor: pointer;
  transition: transform 240ms, box-shadow 240ms, border-color 240ms;
}
.system:hover {
  transform: translateY(-4px);
  border-color: rgba(34,211,238,0.4);
  box-shadow: 0 18px 60px rgba(0,0,0,0.5), 0 0 30px rgba(34,211,238,0.18);
}
.system.focused { transform: scale(1.02); border-color: var(--accent); }

.system-header {
  position: absolute; top: 12px; left: 16px; right: 16px;
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; z-index: 4;
}
.system-rank {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(34,211,238,0.12); border: 1px solid rgba(34,211,238,0.35);
  font-size: 11px; color: var(--accent); font-weight: 700;
}
.system-name { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; flex: 1; }
.system-uniprot { font-size: 11px; color: var(--dim); }

/* Central protein structure (the star) */
.system-center {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 220px; height: 220px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow:
    0 0 60px rgba(34,211,238,0.22),
    0 0 100px rgba(124,58,237,0.18),
    inset 0 0 0 1px rgba(155,182,234,0.10);
  background: radial-gradient(circle at 50% 40%, rgba(124,58,237,0.20), rgba(6,8,15,0.95) 70%);
  z-index: 3;
}
.system-center.empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--dim); text-align: center; padding: 0 20px;
}

/* Orbital ring containing compound molecules */
.system-orbits {
  position: absolute; top: 50%; left: 50%;
  width: 100%; height: 100%;
  transform: translate(-50%, -50%);
  animation: orbit-spin 40s linear infinite;
  z-index: 2;
  pointer-events: none;
}
.system-orbits::before {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 80%; height: 80%;
  border: 1px dashed var(--orbit-fg); border-radius: 50%;
  transform: translate(-50%, -50%);
}
@keyframes orbit-spin {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to   { transform: translate(-50%, -50%) rotate(360deg); }
}

/* A compound molecule orbiting. `--angle` + `--radius` per-instance */
.compound {
  position: absolute; top: 50%; left: 50%;
  width: 54px; height: 54px;
  transform-origin: center;
  transform:
    translate(-50%, -50%)
    rotate(var(--angle))
    translateY(calc(var(--radius) * -1))
    rotate(calc(var(--angle) * -1));
  pointer-events: auto;
}
.compound-body {
  width: 100%; height: 100%;
  animation: compound-counter 40s linear infinite;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
}
@keyframes compound-counter {
  from { transform: rotate(0deg); }
  to   { transform: rotate(-360deg); }
}
.compound-icon {
  width: 38px; height: 38px;
  background: rgba(16,19,28,0.85);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 12px rgba(34,211,238,0.25), inset 0 0 0 1px rgba(155,182,234,0.3);
  overflow: hidden;
}
.compound-icon img,
.compound-icon svg { width: 70%; height: 70%; filter: invert(1) brightness(1.4); opacity: 0.92; }
.compound-icon.atom {
  background: radial-gradient(circle at 38% 32%, #fff3d4, #b6925d 55%, #6d4d20);
  color: #1c1004;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  filter: none;
  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
}
.compound-label {
  font-size: 9.5px; color: var(--muted);
  letter-spacing: 0.04em; white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Footer with scores + rationale snippet */
.system-footer {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 12px 16px 14px;
  background: linear-gradient(to top, rgba(6,8,15,0.95), transparent);
  z-index: 4;
}
.system-scores { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.score-pill {
  background: rgba(34,211,238,0.12); border: 1px solid rgba(34,211,238,0.32);
  border-radius: 999px; padding: 2px 8px; font-size: 10.5px; color: var(--accent);
  letter-spacing: 0.02em;
}
.score-pill.warm { background: rgba(255,162,118,0.10); border-color: rgba(255,162,118,0.35); color: var(--warm); }
.score-pill.dim  { background: rgba(155,182,234,0.06); border-color: rgba(155,182,234,0.2); color: var(--muted); }
.system-rationale {
  font-size: 11.5px; color: var(--muted); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Input card ───────────────────────────────────────────────── */
.glass {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.45);
}
.input-card {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 24px;
  width: min(640px, calc(100vw - 32px));
  padding: 14px;
  z-index: 30;
}
.input-row { display: flex; gap: 10px; align-items: center; }
.input-row.controls { margin-top: 10px; flex-wrap: wrap; }
textarea {
  width: 100%; min-height: 60px; max-height: 140px; resize: vertical;
  background: rgba(12, 15, 23, 0.7); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px;
  font: inherit; font-size: 14px; line-height: 1.5;
}
textarea:focus { outline: none; border-color: rgba(34,211,238,0.55); }

.btn {
  border: 0; border-radius: 10px; padding: 9px 14px;
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: transform 120ms, box-shadow 200ms;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); color: #062028; box-shadow: 0 4px 18px rgba(34,211,238,0.35); }
.btn.ghost   { background: transparent; color: var(--accent); border: 1px solid rgba(34,211,238,0.4); }

#img-preview { display: none; height: 32px; width: 32px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
#img-preview.shown { display: inline-block; }

.status { font-size: 12px; color: var(--dim); flex: 1; min-width: 140px; text-align: right; }
.status.busy { color: var(--accent); }
.status.error { color: var(--bad); }

/* ── Detail panel ─────────────────────────────────────────────── */
.detail {
  position: absolute; right: 24px; top: 80px;
  width: min(340px, calc(100vw - 32px));
  padding: 18px 20px 20px;
  z-index: 40;
  transform: translateX(20px); opacity: 0;
  transition: opacity 220ms, transform 220ms;
  pointer-events: none;
}
.detail:not([hidden]) { opacity: 1; transform: translateX(0); pointer-events: auto; }
.detail h2 { margin: 0 0 6px; font-size: 18px; }
.detail-meta { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.detail-rationale { margin: 0 0 14px; font-size: 14px; line-height: 1.55; }
.detail-scores { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.detail-scores .pill {
  background: rgba(34,211,238,0.1); border: 1px solid rgba(34,211,238,0.3);
  border-radius: 999px; padding: 4px 10px; font-size: 11.5px; color: var(--accent);
}
.detail-scores .pill.warm { background: rgba(255,162,118,0.08); border-color: rgba(255,162,118,0.32); color: var(--warm); }
.detail-notes { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.detail-notes .concern { color: var(--warm); margin-top: 8px; }
.detail-close {
  position: absolute; top: 8px; right: 10px;
  width: 28px; height: 28px;
  background: transparent; border: 0; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer; border-radius: 6px;
}
.detail-close:hover { background: rgba(155,182,234,0.08); color: #fff; }

/* ── Debug ────────────────────────────────────────────────────── */
.debug {
  position: absolute; left: 16px; bottom: 16px;
  max-width: 280px; max-height: 240px; overflow: auto;
  padding: 8px 12px;
  font-size: 11px; color: var(--dim);
  z-index: 20;
}
.debug summary { cursor: pointer; }
.debug pre { color: var(--muted); font: 11px/1.4 ui-monospace, Menlo, monospace; margin: 6px 0 0; }

@media (max-width: 640px) {
  .brand-sub { display: none; }
  .system { width: 88vw; height: 60vh; }
  .system-center { width: 50vw; height: 50vw; max-width: 220px; max-height: 220px; }
  .detail { top: auto; bottom: 230px; right: 16px; left: 16px; width: auto; }
}
