@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #070a10;
  --panel: #0e131c;
  --panel2: #121826;
  --line: #1c2532;
  --line2: #283344;
  --dim: #5a6878;
  --dim2: #8593a3;
  --text: #c4ccd6;
  --bright: #eef2f6;
  --phys: #d9a441;
  --part: #9b8cf0;
  --reac: #e8503a;
  --cool: #4ad6c8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--ink);
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: 0 0 80px;
}

.mono { font-family: 'IBM Plex Mono', monospace; }

/* ---- header ---- */
header {
  padding: 46px 32px 30px;
  border-bottom: 1px solid var(--line);
  max-width: 1560px;
  margin: 0 auto;
}
.eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 16px;
}
h1 {
  font-size: clamp(26px, 4vw, 48px);
  font-weight: 700;
  line-height: 1.03;
  letter-spacing: -.02em;
  color: var(--bright);
  max-width: 20ch;
}
h1 em { font-style: normal; color: var(--cool); }
.lede {
  margin-top: 18px;
  max-width: 64ch;
  font-size: 15px;
  line-height: 1.6;
  color: var(--dim);
}

/* ---- filter bar ---- */
.controls {
  max-width: 1560px;
  margin: 22px auto 0;
  padding: 0 32px;
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}
.filt {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: .05em;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  padding: 7px 14px;
  border-radius: 2px;
  cursor: pointer;
  transition: .18s;
}
.filt:hover { border-color: var(--dim); color: var(--text); }
.filt.on { background: var(--text); color: var(--ink); border-color: var(--text); }

/* ---- groups / grid ---- */
.group {
  max-width: 1560px;
  margin: 34px auto 0;
  padding: 0 32px;
}
.group-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 16px;
}
.group-head h2 { font-size: 20px; font-weight: 600; letter-spacing: -.01em; color: var(--bright); }
.group-head .tag {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 2px;
  border: 1px solid var(--line);
}
.group-head .ln { flex: 1; height: 1px; background: var(--line); }
.group-head .desc { font-size: 12.5px; color: var(--dim); max-width: 40ch; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

/* ---- card ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .2s, transform .2s;
  cursor: pointer;
}
.card:hover { border-color: var(--line2); transform: translateY(-2px); }
.cw { position: relative; aspect-ratio: 1/1; background: #04070c; }
canvas { display: block; width: 100%; height: 100%; }
.badge {
  position: absolute;
  top: 9px;
  left: 9px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: .13em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 2px;
  background: rgba(4,7,12,.8);
  backdrop-filter: blur(4px);
}
.open-hint {
  position: absolute;
  bottom: 9px;
  right: 9px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: .1em;
  color: var(--dim2);
  background: rgba(4,7,12,.7);
  padding: 3px 8px;
  border-radius: 2px;
  opacity: 0;
  transition: .2s;
}
.card:hover .open-hint { opacity: 1; }
.c-physarum  { color: var(--phys); }
.c-particle  { color: var(--part); }
.c-reaction  { color: var(--reac); }
.c-attractor { color: var(--cool); }

.meta { padding: 15px 17px 17px; }
.meta h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--bright);
  letter-spacing: -.01em;
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.meta h3 .idx { font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: var(--dim); font-weight: 400; }
.kind { font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: var(--dim); margin: 5px 0 9px; letter-spacing: .03em; }
.desc { font-size: 12.5px; line-height: 1.5; color: var(--text); }

/* ---- overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4,6,11,.86);
  backdrop-filter: blur(10px);
  display: none;
  opacity: 0;
  transition: opacity .25s;
}
.overlay.show { display: flex; opacity: 1; }
.sheet {
  margin: auto;
  width: min(1180px, 94vw);
  max-height: 92vh;
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  transform: translateY(12px);
  transition: transform .25s;
}
.overlay.show .sheet { transform: translateY(0); }
.sheet-view {
  flex: 1.15;
  min-width: 0;
  background: #04070c;
  position: relative;
  display: flex;
  flex-direction: column;
}
.sheet-canvas-wrap { flex: 1; position: relative; min-height: 0; }
#ov-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.view-foot {
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--panel);
}
.sheet-info {
  flex: 1;
  min-width: 0;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  max-width: 440px;
}
.info-head { padding: 22px 24px 16px; border-bottom: 1px solid var(--line); }
.info-head .badge2 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: .13em;
  text-transform: uppercase;
  display: inline-block;
  margin-bottom: 11px;
}
.info-head h2 { font-size: 23px; font-weight: 700; color: var(--bright); letter-spacing: -.02em; line-height: 1.08; }
.info-head .formula {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--dim2);
  margin-top: 9px;
  line-height: 1.5;
  word-break: break-word;
}
#ov-switcher { margin-top: 12px; }
.algo-sel {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line2);
  border-radius: 5px;
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  padding: 5px 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235a6878'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 22px;
}
.algo-sel:hover { border-color: var(--dim2); color: var(--bright); }
.algo-sel optgroup { color: var(--dim2); font-size: 10px; }
.algo-sel option { color: var(--text); background: var(--panel); }

.info-body { padding: 18px 24px 24px; overflow-y: auto; flex: 1; }
.info-body h4 {
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 18px 0 9px;
}
.info-body h4:first-child { margin-top: 0; }
.info-body p { font-size: 13.5px; line-height: 1.62; color: var(--text); margin-bottom: 11px; }

/* ---- tunable cards ---- */
.tune {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px 13px;
  margin-bottom: 9px;
  background: var(--panel2);
}
.tune-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
.tune-name { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--cool); letter-spacing: .04em; }
.tune-val { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--bright); }
.tune input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: var(--line2);
  border-radius: 2px;
  outline: none;
  margin: 3px 0 7px;
}
.tune input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--cool);
  cursor: pointer;
  border: 2px solid var(--ink);
}
.tune input[type=range]::-moz-range-thumb {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--cool);
  cursor: pointer;
  border: 2px solid var(--ink);
}
.tune-note { font-size: 11.5px; line-height: 1.5; color: var(--dim2); }
.tune-note b { color: var(--text); font-weight: 500; }

/* ---- driver row ---- */
.drive-row { display: flex; gap: 7px; align-items: center; margin: 2px 0 8px; }
.drive-sel {
  flex: 1;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: .04em;
  background: var(--ink);
  color: var(--dim2);
  border: 1px solid var(--line2);
  border-radius: 3px;
  padding: 5px 7px;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%);
  background-position: calc(100% - 14px) 9px, calc(100% - 9px) 9px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.drive-sel:hover { border-color: var(--dim2); color: var(--text); }
.drive-sel.active { border-color: var(--cool); color: var(--cool); }
.tune.driven input[type=range] { opacity: .55; }
.tune.driven input[type=range]::-webkit-slider-thumb {
  background: var(--cool);
  box-shadow: 0 0 0 3px rgba(74,214,200,.18);
}
.pulse { position: relative; }
.pulse::after {
  content: '';
  position: absolute;
  top: 50%; right: 9px;
  transform: translateY(-50%);
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--cool);
  box-shadow: 0 0 6px var(--cool);
  animation: blip 1.2s ease-in-out infinite;
}
@keyframes blip { 0%,100%{opacity:.3} 50%{opacity:1} }

/* ---- dual-thumb range ---- */
.range-row {
  display: none;
  align-items: center;
  gap: 8px;
  margin: 6px 0 2px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  color: var(--dim);
  letter-spacing: .04em;
}
.tune.driven .range-row { display: flex; }
.dual { position: relative; flex: 1; height: 16px; }
.dual input[type=range] {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 16px;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.dual input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--cool);
  cursor: pointer;
  border: 2px solid var(--ink);
}
.dual input[type=range]::-moz-range-thumb {
  pointer-events: auto;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--cool);
  cursor: pointer;
  border: 2px solid var(--ink);
}
.dual .track { position: absolute; top: 7px; left: 0; width: 100%; height: 2px; background: var(--line2); border-radius: 2px; }
.dual .fill { position: absolute; top: 7px; height: 2px; background: var(--cool); border-radius: 2px; opacity: .5; }
.range-row .rv { min-width: 30px; color: var(--cool); }

/* ---- global drive console ---- */
.drive-console {
  border: 1px solid var(--line2);
  border-radius: 5px;
  padding: 13px 14px;
  margin-bottom: 16px;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
}
.dc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 11px; }
.dc-head .t {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--cool);
}
.dc-mini { display: flex; gap: 10px; align-items: center; }
.dc-mini canvas {
  width: 54px; height: 54px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #04070c;
}
.dc-mini .lab { font-family: 'IBM Plex Mono', monospace; font-size: 9px; color: var(--dim); line-height: 1.5; }
.dc-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9.5px;
  letter-spacing: .05em;
  color: var(--dim);
  text-transform: uppercase;
}
.dc-row input[type=range] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 2px;
  background: var(--line2);
  border-radius: 2px;
  outline: none;
}
.dc-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--cool);
  cursor: pointer;
  border: 2px solid var(--ink);
}
.dc-row input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--cool);
  cursor: pointer;
  border: 2px solid var(--ink);
}
.dc-row .v { min-width: 34px; text-align: right; color: var(--text); }

/* ---- buttons ---- */
.btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  letter-spacing: .06em;
  background: transparent;
  border: 1px solid var(--line2);
  color: var(--dim2);
  padding: 8px 13px;
  border-radius: 3px;
  cursor: pointer;
  transition: .15s;
  text-transform: uppercase;
}
.btn:hover { border-color: var(--dim2); color: var(--text); }
.btn.hot { border-color: var(--reac); color: var(--reac); }
.btn.hot:hover { background: var(--reac); color: var(--ink); }
.dc-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9.5px;
  letter-spacing: .06em;
  background: transparent;
  border: 1px solid var(--line2);
  color: var(--dim2);
  padding: 5px 9px;
  border-radius: 3px;
  cursor: pointer;
  text-transform: uppercase;
}
.dc-btn:hover { border-color: var(--dim2); color: var(--text); }
.dc-btn.on { background: var(--cool); color: var(--ink); border-color: var(--cool); }

/* ---- algorithm-specific action bar (meta.actions) ---- */
.action-bar {
  border: 1px solid var(--line2);
  border-radius: 5px;
  padding: 13px 14px;
  margin-bottom: 16px;
  background: var(--panel2);
}
.action-bar-head {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--phys);
  margin-bottom: 10px;
}
.action-row { display: flex; gap: 7px; flex-wrap: wrap; }
.action-btn { flex: 1; min-width: 72px; padding: 8px 9px; }
.action-btn.held { background: var(--phys); color: var(--ink); border-color: var(--phys); }

/* ---- live readout HUD (meta.readout) ---- */
.readout {
  position: absolute;
  inset: 0;
  z-index: 3;
  font-family: 'IBM Plex Mono', monospace;
  pointer-events: none;
}
.ro-lines {
  position: absolute;
  top: 14px; left: 14px;
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--dim2);
  text-shadow: 0 0 6px #000;
}
.ro-lbl { color: var(--dim2); letter-spacing: .1em; }
.ro-val { color: var(--phys); }
.ro-matrix {
  position: absolute;
  bottom: 14px; left: 14px;
  display: flex;
  gap: 24px;
}
.ro-col { font-size: 9.5px; line-height: 1.5; color: var(--dim2); text-shadow: 0 0 6px #000; }
.ro-col-k { color: var(--bright); letter-spacing: .12em; display: block; margin-bottom: 2px; }
.ro-n { display: block; color: var(--phys); font-variant-numeric: tabular-nums; }
.ro-phase {
  position: absolute;
  bottom: 14px; right: 14px;
  text-align: right;
  font-size: 9.5px;
  color: var(--dim2);
  text-shadow: 0 0 6px #000;
  letter-spacing: .1em;
}
#ov-readout-toggle.on { border-color: var(--phys); color: var(--phys); }

/* ---- snapshot ---- */
.snap-bar { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.snap-count { font-family: 'IBM Plex Mono', monospace; font-size: 9.5px; color: var(--dim); letter-spacing: .05em; }
.snap-count b { color: var(--cool); }
.snap-list { max-height: 96px; overflow-y: auto; margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.snap-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  color: var(--dim2);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 4px 8px;
}
.snap-item .x { cursor: pointer; color: var(--dim); padding: 0 2px; }
.snap-item .x:hover { color: var(--reac); }

/* ---- close + paint hint ---- */
.close-x {
  position: absolute;
  top: 14px; right: 14px;
  z-index: 5;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line2);
  background: rgba(4,7,12,.7);
  color: var(--dim2);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  transition: .15s;
}
.close-x:hover { border-color: var(--text); color: var(--text); }
.hint-paint {
  position: absolute;
  top: 14px; left: 14px;
  z-index: 4;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: .06em;
  color: var(--dim2);
  background: rgba(4,7,12,.7);
  padding: 5px 10px;
  border-radius: 3px;
  pointer-events: none;
}

/* ---- footer ---- */
footer {
  max-width: 1560px;
  margin: 54px auto 0;
  padding: 0 32px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--dim);
  line-height: 1.7;
}

/* ---- responsive ---- */
@media (max-width: 820px) {
  .sheet { flex-direction: column; max-height: 94vh; }
  .sheet-info { max-width: none; border-left: none; border-top: 1px solid var(--line); }
  .sheet-view { min-height: 46vh; }
}
