:root {
  --bg: #0f1419;
  --panel: #19212b;
  --panel-2: #222c38;
  --ink: #e6edf3;
  --muted: #8b98a5;
  --accent: #4cc2ff;
  --male: #5aa9ff;
  --female: #ff7eb6;
  --food: #6ee7a8;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid #2a3543;
}
header h1 { margin: 0; font-size: 22px; letter-spacing: 1px; }
.tagline { color: var(--muted); font-size: 13px; }
.auth { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.auth .user { color: var(--muted); font-size: 13px; }

main { display: flex; min-height: calc(100vh - 56px); }

aside#sidebar {
  width: 320px;
  padding: 16px;
  background: var(--panel);
  border-right: 1px solid #2a3543;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0 0 10px; }

.sim-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sim-list li {
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.sim-list li:hover { border-color: var(--accent); }
.sim-list li.active { border-color: var(--accent); background: #26384a; }
.sim-list .name { font-weight: 600; }
.sim-list .sub { color: var(--muted); font-size: 12px; }

.create-form { display: flex; flex-direction: column; gap: 8px; }
.create-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }

input, button {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid #33414f;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
}
button { cursor: pointer; background: #2b3b4d; }
button:hover { border-color: var(--accent); }
button.danger { background: #3a2326; }
button.danger:hover { border-color: var(--danger); }

#stage { flex: 1; padding: 18px; }
.empty { color: var(--muted); display: grid; place-items: center; height: 100%; font-size: 16px; }
.hidden { display: none; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.toolbar .spacer { flex: 1; }
.meta { color: var(--muted); font-size: 13px; }

canvas#world {
  background: #0b0f14;
  border: 1px solid #2a3543;
  border-radius: 10px;
  image-rendering: pixelated;
  width: 600px;
  height: 600px;
}

.readouts { display: flex; gap: 24px; margin-top: 14px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(120px, 1fr)); gap: 8px; }
.stat-grid .cell { background: var(--panel); padding: 8px 10px; border-radius: 8px; }
.stat-grid .cell .k { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.stat-grid .cell .v { font-size: 20px; font-weight: 700; }

.genes h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.genes h3:not(:first-child) { margin-top: 14px; }
#geneBars { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.bar { display: grid; grid-template-columns: 90px 1fr 44px; align-items: center; gap: 8px; font-size: 12px; }
.bar .track { background: var(--panel-2); border-radius: 4px; height: 10px; overflow: hidden; }
.bar .fill { background: linear-gradient(90deg, #4cc2ff, #6ee7a8); height: 100%; }
canvas#chart { background: var(--panel); border-radius: 8px; }

/* ---- legend --------------------------------------------------------------- */
.world-wrap { position: relative; width: 600px; max-width: 100%; }
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}
.legend-title { text-transform: uppercase; letter-spacing: 1px; font-size: 11px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); }
.legend-hint { color: var(--muted); font-style: italic; }
.legend .dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; }
.legend .dot.male { background: var(--male); }
.legend .dot.female { background: var(--female); }
.legend .dot.preg { background: var(--female); box-shadow: 0 0 0 2px var(--accent-gold, #ffd166); }
.legend .dot.food { background: var(--food); border-radius: 2px; width: 9px; height: 9px; }
.legend .dot.water { background: rgba(56,140,255,0.6); }
.legend .dot.age-young { width: 7px; height: 7px; background: var(--muted); }
.legend .dot.age-old { width: 13px; height: 13px; background: var(--muted); }
.legend .dot.energy-poor { background: var(--male); opacity: 0.35; }
.legend .dot.energy-rich { background: var(--male); opacity: 1; }

/* ---- tooltip -------------------------------------------------------------- */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(12, 16, 22, 0.95);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink);
  white-space: nowrap;
  z-index: 5;
}

/* ---- distribution charts -------------------------------------------------- */
.distributions { display: flex; gap: 24px; margin-top: 16px; flex-wrap: wrap; }
.dist h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.dist-sub { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }
.dist canvas { background: var(--panel); border-radius: 8px; display: block; }

/* ---- event log ------------------------------------------------------------ */
.events h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.event-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
}
.event-log li { padding: 3px 6px; background: var(--panel); border-radius: 5px; border-left: 3px solid var(--muted); }
.event-log .ev-tick { color: var(--muted); }
.event-log .ev-sim { color: var(--ink); font-weight: 600; }
.event-log .ev-arrow { color: var(--muted); }
.event-log li.ev-birth { border-left-color: var(--food); }
.event-log li.ev-preg { border-left-color: var(--accent); }
.event-log li.ev-death { border-left-color: var(--danger); }

/* ---- params + explore panels --------------------------------------------- */
.param-fields { display: flex; flex-direction: column; gap: 8px; }
.param-fields.readonly { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.param-fields label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.param-fields input:disabled { opacity: 0.55; cursor: not-allowed; }

.params-panel, .browse-panel { margin-top: 18px; }
.params-panel h3, .browse-panel h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }

.browse-hint { color: var(--muted); font-size: 13px; font-style: italic; }
.browse { display: flex; gap: 16px; flex-wrap: wrap; }
.browse-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  font-size: 12px;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.browse-list li {
  padding: 6px 9px;
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}
.browse-list li:hover { border-color: var(--accent); }
.browse-list li.sel { border-color: var(--accent); background: #26384a; }
.sim-detail {
  flex: 1;
  min-width: 220px;
  background: var(--panel);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  align-self: flex-start;
}
.sim-detail .muted { color: var(--muted); }
.sim-detail .detail-head { font-weight: 700; margin-bottom: 8px; }
.sim-detail .detail-sub { margin: 10px 0 6px; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 1px; }
.sim-detail .kv { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; border-bottom: 1px solid #202a36; }
.sim-detail .kv span:first-child { color: var(--muted); }
