/* ──────────────────────────────────────────  RESET + TOKENS  ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

:root {
  --bg-0:   #07090f;
  --bg-1:   #0c1018;
  --bg-2:   #131826;
  --bg-3:   #1a2235;
  --panel:  #0f1320;
  --panel-2:#141a2b;
  --border: #1f2940;
  --border-2: #2a3656;

  --fg-0:   #e7ecf5;
  --fg-1:   #b6bfd1;
  --fg-2:   #818ba3;
  --fg-3:   #5a647c;

  --accent-A: #fbbf24;       /* A — gold (cautious / low-entropy) */
  --accent-B: #14b8a6;       /* B — teal (curious / high-entropy) */
  --accent-1: #7dd3fc;       /* cyan */
  --accent-2: #f0abfc;       /* magenta */
  --accent-3: #fde68a;       /* yellow */
  --good:     #34d399;
  --bad:      #f87171;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 10px 40px -20px rgba(0,0,0,0.6);

  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

html, body {
  background: radial-gradient(circle at 20% -10%, #131c34 0%, var(--bg-0) 55%) fixed;
  color: var(--fg-0);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-1); text-decoration: none; }
a:hover { color: var(--accent-2); }

h1, h2, h3 { letter-spacing: -0.02em; margin: 0; }
h1 { font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1.1; }
h2 { font-size: clamp(1.5rem, 2.4vw, 2rem); }
h3 { font-size: 1.05rem; }

main { max-width: 1400px; margin: 0 auto; padding: 0 24px 100px; }

/* ──────────────────────────────────────────  TOPBAR  ────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 32px;
  background: rgba(7, 9, 15, 0.6);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--bg-2); border-radius: 10px;
  border: 1px solid var(--border-2);
}
.brand-title { font-weight: 600; font-size: 0.95rem; }
.brand-sub   { font-size: 0.78rem; color: var(--fg-2); font-family: var(--mono); }
.topbar-right { display: flex; gap: 18px; align-items: center; }
.topnav { display: flex; gap: 22px; align-items: center; }
.topnav a { color: var(--fg-1); font-size: 0.9rem; }
.topnav a:hover { color: var(--fg-0); }

.audio-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  margin-left: 4px;
  padding: 0;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--fg-2);
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}
.audio-toggle:hover { color: var(--fg-0); border-color: var(--accent-1); }
.audio-toggle.audio-on { color: var(--accent-3); border-color: var(--accent-3); background: rgba(253, 230, 138, 0.08); }
.audio-toggle.audio-phase { box-shadow: 0 0 18px rgba(253, 230, 138, 0.6); }

/* Phase-transition celebration on the mean-reward chart card */
@keyframes phasePulseBorder {
  0%, 100% { border-color: var(--border); box-shadow: none; }
  50%      { border-color: var(--accent-3); box-shadow: 0 0 22px -4px rgba(253, 230, 138, 0.45); }
}
@keyframes phasePulseOpacity {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.72; }
}
.chart-card.phase-active {
  animation: phasePulseBorder 2.4s ease-in-out infinite;
}
.chart-card.phase-active .chart-title {
  animation: phasePulseOpacity 2.4s ease-in-out infinite;
  color: var(--accent-3);
}
.phase-banner {
  position: fixed; bottom: 22px; right: 22px; z-index: 50;
  background: linear-gradient(135deg, rgba(253, 230, 138, 0.18), rgba(240, 171, 252, 0.18));
  border: 1px solid var(--accent-3);
  color: var(--fg-0);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.88rem;
  box-shadow: 0 18px 50px -20px rgba(253, 230, 138, 0.45);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 400ms ease, transform 400ms ease;
  pointer-events: none;
  max-width: 320px;
}
.phase-banner.visible { opacity: 1; transform: translateY(0); }
.phase-banner .mono { font-family: var(--mono); color: var(--accent-3); }

/* ──────────────────────────────────────────  HERO  ────────────────────────────────────────── */
.hero {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 48px;
  align-items: center;
  padding: 60px 0 80px;
}
.hero-left .kicker {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  color: var(--accent-1);
  margin-bottom: 18px;
}
.hero-left h1 { margin-bottom: 18px; }
.hero-left .grad {
  background: linear-gradient(90deg, var(--accent-A), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lede {
  color: var(--fg-1);
  font-size: 1.05rem;
  max-width: 580px;
}
.lede em { color: var(--accent-3); font-style: normal; }

.hero-cta { display: flex; gap: 12px; margin-top: 26px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid var(--border-2);
  background: var(--bg-2);
  color: var(--fg-0);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: 120ms ease;
  font-family: inherit;
}
.btn:hover { background: var(--bg-3); border-color: var(--accent-1); color: var(--fg-0); }
.btn-primary {
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
  border-color: #f59e0b;
  color: #1b1305;
  font-weight: 600;
}
.btn-primary:hover { color: #1b1305; transform: translateY(-1px); box-shadow: 0 12px 30px -10px rgba(245, 158, 11, 0.4); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.hero-meta {
  display: flex; gap: 24px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.hero-meta > div { display: flex; flex-direction: column; }
.hero-meta .big { font-size: 1.25rem; font-weight: 600; color: var(--fg-0); }
.hero-meta .lbl { font-size: 0.72rem; color: var(--fg-2); font-family: var(--mono); }

.hero-right { position: relative; }
.three-host {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: radial-gradient(ellipse at 50% 50%, #18243f 0%, #0b1020 65%, transparent 95%);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}
.three-host-mini { aspect-ratio: 1 / 1; max-width: 320px; margin: 0 auto; }
.three-host canvas { display: block; width: 100%; height: 100%; }
.three-placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--fg-3);
  font-family: var(--mono);
  font-size: 0.78rem;
  pointer-events: none;
  text-align: center;
  padding: 16px;
}

.hero-caption {
  position: absolute; bottom: 18px; left: 18px;
  background: rgba(15, 19, 32, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 12px 16px;
}
.caption-title { font-weight: 600; }
.caption-mono { font-family: var(--mono); font-size: 0.82rem; color: var(--fg-2); margin-top: 2px; }

/* ──────────────────────────────────────────  SECTION  ────────────────────────────────────────── */
.section-head {
  text-align: center;
  margin: 60px 0 32px;
}
.section-head h2 { margin-bottom: 8px; }
.section-head p { color: var(--fg-2); margin: 0; }

/* ──────────────────────────────────────────  TRAIN GRID  ────────────────────────────────────────── */
.train-section { padding: 20px 0 60px; }
.train-grid {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 20px;
  align-items: stretch;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-head .legend { display: flex; gap: 14px; font-size: 0.7rem; }
.panel-head .legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; margin-right: 4px; }
.dot-A { background: var(--accent-A); }
.dot-B { background: var(--accent-B); }
.panel-body { padding: 18px; flex: 1; display: flex; flex-direction: column; gap: 14px; }

/* form fields */
.field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.field-label { font-size: 0.78rem; color: var(--fg-1); }
.field select,
.field input[type="text"] {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  color: var(--fg-0);
  padding: 9px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--fg-2) 50%),
    linear-gradient(135deg, var(--fg-2) 50%, transparent 50%);
  background-position: right 14px top 16px, right 9px top 16px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.field input[type="range"] { width: 100%; accent-color: var(--accent-A); }
.field-value {
  position: absolute; right: 0; top: 0;
  font-family: var(--mono); font-size: 0.8rem; color: var(--accent-1);
}
.field-help { font-size: 0.78rem; color: var(--fg-2); margin-top: -8px; }

.field-checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.field-checkbox input[type="checkbox"] {
  appearance: none;
  width: 16px; height: 16px;
  border: 1px solid var(--border-2);
  background: var(--bg-2);
  border-radius: 4px;
  cursor: pointer;
  transition: 120ms ease;
  position: relative;
  flex-shrink: 0;
}
.field-checkbox input[type="checkbox"]:hover { border-color: var(--accent-1); }
.field-checkbox input[type="checkbox"]:checked {
  background: var(--accent-A);
  border-color: var(--accent-A);
}
.field-checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 0px;
  width: 5px; height: 9px;
  border: solid #1b1305;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.field-checkbox .field-label { font-size: 0.85rem; color: var(--fg-0); }

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

.btn-preset {
  margin-top: 4px;
  padding: 8px 12px;
  background: transparent;
  border: 1px dashed var(--border-2);
  border-radius: 8px;
  color: var(--fg-2);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: 140ms ease;
}
.btn-preset:hover {
  border-color: var(--accent-3);
  color: var(--accent-3);
  background: rgba(253, 230, 138, 0.04);
}

.status {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0 0;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--fg-1);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-3);
  flex-shrink: 0;
  transition: background 200ms ease;
}
.status-dot.status-running { background: var(--good); box-shadow: 0 0 14px var(--good); animation: pulse 1.2s ease-in-out infinite; }
.status-dot.status-error   { background: var(--bad); }
.status-dot.status-done    { background: var(--accent-1); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* metrics */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}
.metric {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.metric-label { font-size: 0.7rem; color: var(--fg-2); margin-bottom: 4px; }
.metric-value { font-family: var(--mono); font-size: 1.05rem; color: var(--fg-0); }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1;
}
.chart-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}
.chart-title { font-size: 0.78rem; color: var(--fg-1); margin-bottom: 6px; }
.chart-card canvas { flex: 1; max-height: 220px; }

/* current exploring */
.panel-current-body { gap: 16px; }
.current-meta { font-size: 0.88rem; }
.current-label { font-size: 0.72rem; color: var(--fg-2); margin-bottom: 4px; }
.current-smiles {
  font-family: var(--mono);
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
  font-size: 0.82rem;
  min-height: 38px;
}
.current-stats { display: flex; justify-content: space-between; margin-top: 10px; font-family: var(--mono); }
.current-stats .lbl { color: var(--fg-2); }
.hint { margin-top: 12px; font-size: 0.78rem; color: var(--fg-2); line-height: 1.4; }

/* ──────────────────────────────────────────  MOLECULES GRID  ────────────────────────────────────────── */
.molecules-section { padding: 20px 0 60px; }
.mol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.mol-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  transition: transform 180ms ease, border-color 180ms ease;
  animation: cardIn 320ms ease both;
}
.mol-card:hover { transform: translateY(-2px); border-color: var(--accent-1); }
.mol-card .mol-svg {
  background: #ffffff;
  border-radius: 6px;
  aspect-ratio: 1 / 1;
  display: grid; place-items: center;
  overflow: hidden;
}
.mol-card .mol-svg svg { width: 100%; height: 100%; }
.mol-card .mol-score {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 0.85rem;
  display: flex; justify-content: space-between;
}
.mol-card .mol-score .num { color: var(--accent-3); }
.mol-card .mol-smiles {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--fg-2);
  word-break: break-all;
  line-height: 1.3;
}
.mol-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--fg-2);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ──────────────────────────────────────────  ALGORITHM  ────────────────────────────────────────── */
.algo-section { padding: 40px 0 80px; }
.algo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}
.algo-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 24px;
  position: relative;
}
.algo-card h3 { margin-bottom: 8px; }
.algo-card p { color: var(--fg-1); font-size: 0.92rem; margin: 0; }
.algo-card em { color: var(--accent-3); font-style: normal; }
.algo-num {
  position: absolute; top: 16px; right: 18px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--fg-3);
}
.algo-details {
  margin-top: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.algo-details summary {
  padding: 16px 22px;
  cursor: pointer;
  color: var(--fg-1);
  font-weight: 500;
  list-style: none;
}
.algo-details summary::marker, .algo-details summary::-webkit-details-marker { display: none; }
.algo-details summary::before {
  content: '+ ';
  color: var(--accent-1);
  font-family: var(--mono);
}
.algo-details[open] summary::before { content: '− '; }
.algo-details .details-body { padding: 0 22px 22px; color: var(--fg-1); }
.algo-details ul { padding-left: 20px; }
.algo-details li { margin-bottom: 6px; }
.algo-details code { background: var(--bg-2); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); font-size: 0.85em; }

/* ──────────────────────────────────────────  FOOTER  ────────────────────────────────────────── */
.footer {
  display: flex; justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 24px;
  padding: 30px 32px 20px;
  font-size: 0.78rem;
  color: var(--fg-3);
  border-top: 1px solid var(--border);
  margin-top: 60px;
  font-family: var(--mono);
}
.footer a { color: var(--fg-2); text-decoration: underline; text-decoration-color: var(--border-2); text-underline-offset: 2px; }
.footer a:hover { color: var(--accent-1); }
.attribution { flex-basis: 100%; color: var(--fg-3); }

.icon-link {
  display: inline-flex; align-items: center; gap: 5px;
  text-decoration: none !important;
  padding: 1px 2px;
}
.icon-link svg { transition: transform 200ms ease; }
.icon-link:hover svg { transform: scale(1.1); }

/* ──────────────────────────────────────────  RESPONSIVE  ────────────────────────────────────────── */
@media (max-width: 1200px) {
  .train-grid { grid-template-columns: 260px 1fr; }
  .panel-current { grid-column: 1 / -1; }
  .three-host-mini { max-width: 240px; }
}
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 32px; padding: 32px 0 50px; }
  .train-grid { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .metrics-row { grid-template-columns: repeat(3, 1fr); }
  .topnav { display: none; }
  /* .topbar-right still flexes so the audio toggle stays visible even when topnav is hidden */
  main { padding: 0 16px 60px; }
  .footer { flex-direction: column; gap: 6px; padding: 24px 16px; }
}
