:root {
  --surface-0: #f5f4f1;
  --surface-1: #fcfcfb;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #85847f;
  --accent: #2a78d6;
  --sidebar-w: 360px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4;
  color: var(--text-primary); background: var(--surface-0);
}
#layout { display: flex; height: 100vh; }

/* ---------------- sidebar */
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  overflow-y: auto; padding: 18px 16px 40px;
  background: var(--surface-1); border-right: 1px solid var(--border);
}
#sidebar h1 { font-size: 21px; margin: 0 0 6px; line-height: 1.2; }
.blurb { color: var(--text-secondary); margin: 4px 0 8px; font-size: 15px; }
.sub { color: var(--text-muted); font-size: 12px; margin: 0 0 12px; }
.nav-comparison {
  width: 100%; text-align: left; font: inherit; font-weight: 600;
  padding: 10px 12px; margin-bottom: 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-0);
}
.nav-comparison.active { border-color: var(--text-primary); background: #fff; }

.card {
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
  padding: 10px 10px 6px; margin-bottom: 10px; cursor: pointer;
}
.card.active { border-color: var(--text-primary); box-shadow: 0 0 0 1px var(--text-primary); }
.card-head { display: flex; align-items: center; gap: 8px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 12px; }
.card-name { font-weight: 600; font-size: 16px; flex: 1; }
.tag {
  font-size: 11px; padding: 1px 6px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--text-secondary); white-space: nowrap;
}
.tag.cvfree { background: #f0efec; }
.card-meta { color: var(--text-secondary); font-size: 13px; margin: 3px 0 4px 20px; }
.lineage { display: block; width: 100%; }
.lineage .node { cursor: default; }
.lineage .node.clickable { cursor: pointer; }
.lineage .node.clickable:hover rect { stroke: var(--text-primary); stroke-width: 1.5; }
.lineage .node.current rect { stroke: var(--text-primary); stroke-width: 2.5; }
.lineage text { font-size: 9px; fill: var(--text-primary); pointer-events: none; }
.lineage .edge { stroke: #9a9994; fill: none; }

/* ---------------- main */
#main { flex: 1; overflow-y: auto; padding: 20px 26px 60px; }
#head h2 { font-size: 30px; margin: 0 0 4px; }
#blurb { font-size: 17px; max-width: 1100px; }
.fe-how { color: var(--text-secondary); font-size: 15px; margin: 2px 0 10px; max-width: 1100px; }
.fe-how:not(:empty)::before { content: "Free energy: "; font-weight: 600; color: var(--text-primary); }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 12px; }
.stat {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; min-width: 110px;
}
.stat b { display: block; font-size: 22px; font-weight: 600; }
.stat span { color: var(--text-secondary); font-size: 13px; }
.note { color: var(--text-secondary); font-style: italic; margin: 4px 0; }
.note:empty { display: none; }

.panel {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 16px;
}
.panel h3 { margin: 0 0 6px; font-size: 18px; }
.hint { color: var(--text-muted); font-weight: 400; font-size: 13px; }
.panel h3 .hint { margin-left: 6px; }

.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panels .panel { margin-bottom: 0; min-width: 0; }
.panels .panel.wide { grid-column: 1 / -1; }
.plot { width: 100%; height: 360px; }
.plot.tall { height: 470px; }

/* ---------------- trajectory */
#traj-chips { margin: 2px 0 8px; }
.chip-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 4px; }
.chip-row .row-label { color: var(--text-secondary); font-size: 13px; min-width: 90px; }
.chip {
  font: inherit; font-size: 13px; padding: 2px 9px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-0); color: var(--text-primary);
}
.chip.active { background: var(--text-primary); color: #fff; border-color: var(--text-primary); }
.traj-grid { display: grid; grid-template-columns: minmax(380px, 1fr) 1.25fr; gap: 14px; }
#viewer {
  position: relative; width: 100%; height: 420px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 8px; font-size: 14px; }
.controls button {
  font: inherit; font-size: 14px; padding: 4px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-0);
}
#play { min-width: 92px; font-weight: 600; }
#frame { flex: 1; min-width: 150px; }
.readout { font-variant-numeric: tabular-nums; color: var(--text-secondary); min-width: 150px; }
.slider input { vertical-align: middle; width: 110px; }
#frame-label { margin: 6px 0 0; min-height: 1.2em; font-size: 14px; color: var(--text-secondary); }

@media (max-width: 1300px) {
  .traj-grid { grid-template-columns: 1fr; }
  .panels { grid-template-columns: 1fr; }
}

/* intro page */
.intro-structs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.intro-struct { background: #fff; border: 1px solid #e3e2dd; border-radius: 10px; padding: 12px; }
.intro-struct h3 { margin: 0 0 4px; font-size: 17px; }
.intro-struct .meta { color: #52514e; font-size: 14px; }
.intro-viewer { position: relative; width: 100%; height: 320px; }
.intro-facts { background: #fff; border: 1px solid #e3e2dd; border-radius: 10px; padding: 14px 18px 14px 36px;
               font-size: 16px; line-height: 1.5; color: #0b0b0b; margin: 0 0 18px; }
.intro-facts li { margin: 6px 0; }
#sync-box h3 { font-size: 15px; margin: 10px 0 2px; color: #0b0b0b; }
.sync-plot { height: 240px; }

/* ensemble grid view */
.view-toggle { margin: 4px 0 8px; }
.view-toggle button { font-size: 14px; padding: 4px 12px; margin-right: 6px; border: 1px solid #c9c8c3; background: #fff; border-radius: 14px; cursor: pointer; }
.view-toggle button.active { background: #0b0b0b; color: #fff; border-color: #0b0b0b; }
#ens-grid { position: relative; width: 100%; }
