/* ==========================================================================
   Chem Interactions — Pro Dark Theme + Motion
   - Keeps your existing design tokens/components
   - Adds: reveal-stagger, mouse tilt, magnetic buttons, hero parallax
   - Respects prefers-reduced-motion
   ========================================================================== */

/* ------------------------------
   Design Tokens (yours, kept)
---------------------------------*/
:root {
  --bg: #0b1220;
  --ink: #e9eef7;
  --ink-dim: #9fb3d1;
  --panel: #0f1626;
  --card: hsl(221 41% 12%);
  --brd: rgba(255,255,255,.08);
  --brd-2: rgba(255,255,255,.12);
  --shadow: rgba(0,0,0,.35);
  --primary: #5b8cff;
  --accent-2: #22c55e;
  --accent-3: #f59e0b;
  --ring: rgba(91, 140, 255, .45);

  /* Motion additions */
  --tilt-persp: 800px;
  --tilt-max: 6deg;
  --hover-lift: 6px;
  --anim-fast: .18s;
  --anim-med: .28s;

   --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
            "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
            "Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
   --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas,
            "Liberation Mono", monospace;
}

/* ------------------------------
   Base
---------------------------------*/
html { scroll-behavior: smooth;  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-sans);}
::selection { background: color-mix(in oklab, var(--primary) 40%, transparent); color: white; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: .5rem; }

h1,h2,h3 { letter-spacing: -0.01em; }
/* ------------------------------
   Glassy sticky navbar
---------------------------------*/
.navbar, .bg-dark {
  background: rgba(10,15,28,.82) !important;
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid rgba(255,255,255,.06);
  box-shadow: 0 10px 30px rgba(2,6,23,.12);
}

/* ------------------------------
   Hero / gradients
---------------------------------*/
.bg-gradient {
  background:
    radial-gradient(1200px 600px at 12% -10%, color-mix(in oklab, var(--primary) 30%, transparent) 0%, transparent 60%),
    radial-gradient(900px 600px at 90% 10%, color-mix(in oklab, var(--accent-3) 25%, transparent) 0%, transparent 60%),
    radial-gradient(1200px 700px at 60% -30%, color-mix(in oklab, var(--accent-2) 22%, transparent) 0%, transparent 70%),
    linear-gradient(135deg, #14213d, #1f2a48);
}
.hero-card { background: rgba(255,255,255,.06); border: 1px solid var(--brd); box-shadow: 0 20px 60px rgba(2,6,23,.22); }

/* ------------------------------
   Cards & Feature blocks
---------------------------------*/
.card {
  background: var(--card);
  border: 1px solid var(--brd);
  color: white;
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
  will-change: transform;
}
.card:hover { transform: translateY(-4px); box-shadow: 0 18px 40px rgba(2,6,23,.26); border-color: var(--brd-2); }

.feature-card {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--brd);
  border-radius: 16px;
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
  will-change: transform;
}
.feature-card:hover { transform: translateY(-2px); border-color: var(--brd-2); box-shadow: 0 10px 30px var(--shadow); }

/* ------------------------------
   Tables
---------------------------------*/
.table { --bs-table-bg: transparent; color: var(--ink); }
.table thead th { color: var(--ink-dim); }
.table tbody tr td, .table thead th { border-color: var(--brd) !important; color: white; }

.table-modern { --bs-table-bg: transparent; color: var(--ink); border-radius: .75rem; overflow: hidden; }
.table-modern thead th { background: #0e1524; position: sticky; top: 0; z-index: 1; color: #cfe0ff !important; border-bottom: 1px solid rgba(255,255,255,.1) !important; }
.table-modern tbody tr:nth-child(odd) td { background: rgba(255,255,255,.03); }
.table-modern tbody tr:hover td { background: rgba(91,140,255,.08); }

/* ------------------------------
   Forms
---------------------------------*/
.form-control, .form-select { background: var(--panel); color: var(--ink); border-color: var(--brd-2); }
.form-control::placeholder { color: #7b8aa3; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 .2rem var(--ring); }
.form-range::-webkit-slider-thumb { cursor: pointer; }

/* ------------------------------
   Buttons & Pills
---------------------------------*/
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-outline-secondary { color: var(--ink); border-color: rgba(255,255,255,.25); }
.btn-ghost { background: transparent; color: var(--ink-dim); border: 1px solid rgba(255,255,255,.15); }
.btn-ghost:hover { color: #fff; }
.pill { background:#102335; border:1px solid #1d3b5a; color:#cfe0ff; padding:.2rem .5rem; border-radius:999px; font-size:.85rem; }

/* ------------------------------
   Tabs
---------------------------------*/
.nav-tabs .nav-link { color: var(--ink-dim); }
.nav-tabs .nav-link.active { background: transparent; border-color: transparent transparent var(--primary); border-bottom: 2px solid var(--primary); color: var(--ink); }

/* ------------------------------
   Suggest (autocomplete)
---------------------------------*/
.suggest-wrap { position: relative; }
.suggest-panel { position: absolute; z-index: 1050; left: 0; right: 0; top: 100%; margin-top: .25rem; background: var(--panel); border: 1px solid var(--brd-2); border-radius: .75rem; box-shadow: 0 10px 30px var(--shadow); max-height: 280px; overflow: auto; display: none; opacity: 0; transform: translateY(6px); transition: opacity .18s ease, transform .18s ease; }
.suggest-panel.show { display: block; opacity: 1; transform: translateY(0); }
.suggest-item { padding: .55rem .75rem; cursor: pointer; display: flex; align-items: center; gap: .5rem; }
.suggest-item:hover, .suggest-item.active { background: rgba(91,140,255,.12); }
.suggest-item .tag { font-size: .75rem; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); padding: .1rem .4rem; border-radius: .5rem; color: var(--ink-dim); }

.card-header-slim { padding: .65rem .9rem; border-bottom: 1px solid var(--brd); }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; color: #fff; }

/* ------------------------------
   Badges & Network
---------------------------------*/
.badge-count { background: rgba(91,140,255,.15); border: 1px solid rgba(91,140,255,.35); color: #cfe0ff; padding: .25rem .5rem; border-radius: .5rem; }

.network-wrap { background: var(--panel); border: 1px solid var(--brd); border-radius: .75rem; height: 420px; }
.network-legend { display: flex; gap: .75rem; flex-wrap: wrap; }
.legend-dot { width: .85rem; height: .85rem; border-radius: 50%; display: inline-block; vertical-align: middle; margin-right: .35rem; }
.legend-ligand  { background: var(--primary); }
.legend-metal   { background: var(--accent-2); }
.legend-solvent { background: var(--accent-3); }

/* ------------------------------
   Modals & Viewer
---------------------------------*/
#infoModalBody { background-color: #2E2E2E; }
#infoModalTitle{ color: #e9eef7; }
.modal-header, .modal-footer { background-color:#5C5C5C; border-color: rgba(255,255,255,.08); }
#structureModal .modal-dialog { max-width: min(1200px, 96vw); }
#structureModal .modal-dialog.modal-dialog-scrollable .modal-body { max-height: 80vh; overflow-y: auto; background-color: black; }
#structureViewer { display: block; width: 100%; height: 65vh; min-height: 360px; }

/* ------------------------------
   Charts & Filters
---------------------------------*/
.chartjs-render-monitor { background: transparent; }
.chart-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:1rem; }
@media (max-width: 992px) { .chart-grid{ grid-template-columns:1fr; } }
.chart-card { background: #0b1520; border-radius: .75rem; padding: .75rem; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.chart-card h6 { margin: .25rem 0 .5rem; font-size: .95rem; color:#cfe0ff; }
.filter-row .col { min-width: 220px; }
.sticky-tools { position: sticky; top: .5rem; z-index: 5; }

/* ------------------------------
   Hero helper styles
---------------------------------*/
.hero {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(91,140,255,.25), transparent 60%),
    radial-gradient(900px 600px at 90% 10%, rgba(245,158,11,.18), transparent 60%),
    radial-gradient(1200px 700px at 60% -30%, rgba(34,197,94,.18), transparent 70%);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.hero .lead { color: rgba(255,255,255,.85); }
.section-title { letter-spacing: .2px; }
.text-dim { color: rgba(255,255,255,.72); }
.divider { border-top: 1px solid rgba(255,255,255,.08); }

/* ------------------------------
   Scroll progress
---------------------------------*/
body::before {
  content: ""; position: fixed; top: 0; left: 0; height: 3px; width: 0;
  z-index: 2000; background: linear-gradient(90deg, var(--primary), var(--accent-3));
  box-shadow: 0 0 18px rgba(91,140,255,.55);
}
@keyframes growX { to { width: 100%; } }
@supports (animation-timeline: scroll()) {
  body::before { animation: growX linear; animation-timeline: scroll(root block); animation-duration: auto; }
}

/* ------------------------------
   Reveal animations (scroll)
---------------------------------*/
@keyframes fade-up { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .6s ease, transform .6s ease; }
.reveal.show { opacity: 1; transform: none; }

/* If supported, use scroll-driven CSS animations */
@supports (animation-timeline: view()) {
  .reveal { opacity: 1; transform: none; animation: fade-up both ease-out; animation-timeline: view(block); animation-range: entry 15% cover 30%; }
}

/* Staggered reveal for rows/lists */
.reveal-stagger > * { opacity: 0; transform: translateY(14px); transition: opacity .5s ease, transform .5s ease; }
.reveal-stagger.show > * { opacity: 1; transform: none; }
.reveal-stagger.show > *:nth-child(1){ transition-delay: .02s; }
.reveal-stagger.show > *:nth-child(2){ transition-delay: .08s; }
.reveal-stagger.show > *:nth-child(3){ transition-delay: .14s; }
.reveal-stagger.show > *:nth-child(4){ transition-delay: .20s; }
.reveal-stagger.show > *:nth-child(5){ transition-delay: .26s; }
.reveal-stagger.show > *:nth-child(6){ transition-delay: .32s; }

/* ------------------------------
   Parallax-ish hero accents (fallback float)
---------------------------------*/
@keyframes floatY { from { transform: translateY(-4%); } to { transform: translateY(6%); } }
header.bg-gradient { position: relative; overflow: clip; }
header.bg-gradient::before, header.bg-gradient::after {
  content: ""; position: absolute; filter: blur(40px); border-radius: 50%; opacity: .45; pointer-events: none;
}
header.bg-gradient::before { width: 420px; height: 420px; left: -120px; top: -80px; background: radial-gradient(circle, var(--primary) 0%, transparent 60%); }
header.bg-gradient::after  { width: 360px; height: 360px; right: -100px; bottom: -80px; background: radial-gradient(circle, var(--accent-3) 0%, transparent 60%); }
header.bg-gradient::before, header.bg-gradient::after { animation: floatY 16s ease-in-out infinite alternate; }
@supports (animation-timeline: scroll()) {
  header.bg-gradient::before, header.bg-gradient::after { animation: floatY linear; animation-timeline: scroll(root block); animation-range: entry 0% exit 100%; }
}

/* ------------------------------
   Mouse Parallax layers (JS-controlled)
   Add .parallax wrapper and .parallax-layer elements in HTML for best effect.
---------------------------------*/
.parallax { position: relative; overflow: clip; }
.parallax-layer {
  position: absolute;
  pointer-events: none; will-change: transform;
  transform: translate3d(var(--px,0), var(--py,0), 0) scale(var(--scale,1));
  opacity: .5; filter: blur(30px);
  border-radius: 50%;
}
.parallax .blob-primary { background: radial-gradient(circle, var(--primary), transparent 60%); width: 420px; height: 420px; left: -120px; top: -80px; }
.parallax .blob-accent  { background: radial-gradient(circle, var(--accent-3), transparent 60%); width: 360px; height: 360px; right: -100px; bottom: -80px; }

/* ------------------------------
   Mouse Tilt utility
   Use .tilt .tilt-inner in HTML OR auto-apply to .card/.feature-card/.hero-card via JS
---------------------------------*/
.tilt { transform-style: preserve-3d; perspective: var(--tilt-persp); }
.tilt .tilt-inner { transform: rotateX(var(--rx, 0)) rotateY(var(--ry, 0)); transform-origin: center; transition: transform .15s ease; will-change: transform; }
.tilt [data-pop] { transform: translateZ(18px); }

/* ------------------------------
   Magnetic Buttons
---------------------------------*/
.magnet { position: relative; }
.magnet .magnet-inner {
  display:inline-flex; align-items:center; gap:.5rem;
  transform: translate3d(var(--mx,0), var(--my,0), 0);
  transition: transform .12s ease;
}

/* ------------------------------
   Local sticky nav (optional)
---------------------------------*/
.local-nav { position: sticky; top: 92px; background: rgba(255,255,255,.03); border: 1px solid var(--brd); border-radius: 14px; }
.local-nav a { color: rgba(255,255,255,.82); text-decoration: none; padding: .5rem .75rem; border-radius: 10px; display: block; }
.local-nav a.active, .local-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }

/* ------------------------------
   Scrollbar polish (webkit)
---------------------------------*/
*::-webkit-scrollbar { height: 10px; width: 10px; }
*::-webkit-scrollbar-track { background: rgba(255,255,255,.04); }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.28); }

/* ------------------------------
   Helpers
---------------------------------*/
.small a { color: var(--ink-dim); }
#ligand-help, #metal-help, #solvent-help, #entity-meta { color: white; }
.metric { font-variant-numeric: tabular-nums; }
#site-footer { scroll-margin-top: 80px; }

/* ------------------------------
   Accessibility: reduced motion
---------------------------------*/
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .tilt .tilt-inner, .magnet .magnet-inner, .parallax-layer { transform: none !important; }
  .reveal, .reveal-stagger > * { opacity: 1 !important; transform: none !important; }
}
