:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #07090d;
  color: #e6edf5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  height: 100vh;
}

.world {
  position: relative;
  min-width: 0;
  min-height: 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 0;
  padding: 22px;
  border-left: 1px solid #253142;
  background: #10151c;
  overflow-y: auto;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin: 0 0 12px;
  color: #eef5ff;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

p {
  margin: 10px 0 0;
  color: #aeb9c8;
  font-size: 14px;
  line-height: 1.45;
}

.stats dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  margin: 0 0 18px;
}

.biot-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: min(310px, calc(100% - 16px));
  padding: 12px;
  border: 1px solid rgba(142, 167, 204, 0.38);
  border-radius: 7px;
  background: rgba(12, 18, 27, 0.9);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(8px);
  pointer-events: none;
  overflow: hidden;
  will-change: transform;
}

.biot-tooltip[hidden] {
  display: none;
}

.tooltip-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.tooltip-head h2 {
  margin: 0 0 3px;
}

.tooltip-head span {
  color: #9aa8ba;
  font-size: 12px;
}

.tooltip-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 4px;
}

.tooltip-status b {
  border: 1px solid #38475b;
  border-radius: 999px;
  padding: 3px 7px;
  color: #dce7f5;
  font-size: 11px;
  font-weight: 600;
}

.tooltip-status b.stable { border-color: rgba(126, 231, 135, 0.45); color: #9df2a4; }
.tooltip-status b.injured { border-color: rgba(255, 211, 107, 0.5); color: #ffd36b; }
.tooltip-status b.sick { border-color: rgba(255, 77, 255, 0.5); color: #ff9cff; }
.tooltip-status b.seed { border-color: rgba(244, 247, 255, 0.5); color: #f4f7ff; }

.tooltip-chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.tooltip-chips span,
.lineage-strip span {
  min-width: 0;
  border: 1px solid rgba(71, 88, 114, 0.72);
  border-radius: 5px;
  padding: 6px;
  background: rgba(24, 34, 48, 0.78);
  color: #aeb9c8;
  font-size: 11px;
}

.tooltip-chips b,
.lineage-strip b {
  display: block;
  margin-bottom: 2px;
  color: #eef5ff;
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lineage-strip {
  display: grid;
  grid-template-columns: 1fr 1.35fr 0.8fr;
  gap: 6px;
  margin-bottom: 10px;
}

.kin-cell i {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  color: #aeb9c8;
  font-style: normal;
}

.kin-cell strong {
  color: #eef5ff;
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.relation-key {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 10px;
  color: #b8c5d4;
  font-size: 12px;
}

.relation-key span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.relation-key i {
  width: 18px;
  height: 3px;
  border-radius: 999px;
}

.relation-key .parent { background: #ffd36b; }
.relation-key .child { background: #7ee787; }
.relation-key .sibling { background: repeating-linear-gradient(90deg, #8fb3ff 0 5px, transparent 5px 9px); }

.role-mix {
  display: grid;
  gap: 5px;
}

.role-mix span {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 8px;
  row-gap: 3px;
  align-items: center;
  color: #aeb9c8;
  font-size: 11px;
}

.role-mix i {
  grid-column: 1 / -1;
  display: block;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--c) var(--w), rgba(39, 50, 65, 0.86) var(--w));
}

.role-mix b {
  font-weight: 500;
  color: #d9e4f2;
}

.role-mix em {
  color: #aeb9c8;
  font-style: normal;
  font-variant-numeric: tabular-nums;
}

dt {
  color: #9aa8ba;
}

dd {
  margin: 0;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.bars {
  display: grid;
  gap: 10px;
}

.bars.compact {
  gap: 8px;
}

.bar {
  display: grid;
  gap: 5px;
  color: #aeb9c8;
  font-size: 12px;
}

.bar i {
  display: block;
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--c) var(--w), #273241 var(--w));
}

.mini-charts {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.histogram {
  display: grid;
  gap: 6px;
}

.histogram span {
  color: #aeb9c8;
  font-size: 12px;
}

.histogram div {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(4px, 1fr));
  align-items: end;
  gap: 2px;
  height: 38px;
  padding-block: 2px;
}

.histogram i {
  display: block;
  height: var(--h);
  min-height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--c);
  opacity: 0.86;
}

.controls {
  display: grid;
  gap: 17px;
}

label {
  display: grid;
  gap: 8px;
  color: #cad5e3;
  font-size: 13px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: #58d8ff;
}

input[type="range"] {
  width: 100%;
  accent-color: #58d8ff;
}

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button {
  min-height: 38px;
  border: 1px solid #38475b;
  border-radius: 6px;
  background: #1a2330;
  color: #eef5ff;
  font: inherit;
  cursor: pointer;
}

button:hover {
  background: #223044;
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  color: #b8c5d4;
  font-size: 13px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.leaf {
  width: 20px;
  height: 3px;
  border-radius: 999px;
}

.green { background: #40d463; }
.red { background: #ff4b4b; }
.blue { background: #4c78ff; }
.cyan { background: #58d8ff; }
.white { background: #f4f7ff; }

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 62vh) auto;
    height: auto;
    min-height: 100vh;
  }

  .panel {
    border-left: 0;
    border-top: 1px solid #253142;
  }
}
