:root {
  --bg: #0e1116;
  --panel: #1a1f2a;
  --panel-2: #232a37;
  --text: #e8eaed;
  --muted: #8a93a3;
  --accent: #7cf6c8;
  --warn: #f39c12;
  --danger: #e74c3c;
  --radius: 10px;
  --pad: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid #000;
}

header h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.5px;
}

header .ver {
  color: var(--muted);
  font-size: 12px;
  margin-left: 8px;
}

header .credit {
  font-size: 12px;
  color: var(--muted);
}
header .credit a { color: var(--accent); text-decoration: none; }

main {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 56px);
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; height: auto; }
}

.left-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.canvas-wrap {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  align-items: center;
}

#world {
  width: 100%;
  height: auto;
  max-width: 800px;
  background: #0a0d11;
  border-radius: 6px;
  display: block;
}

.controls {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 800px;
  margin-top: 10px;
  align-items: center;
  flex-wrap: wrap;
}

button.big {
  background: var(--accent);
  color: #0e1116;
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  min-width: 70px;
}
button.big:hover { filter: brightness(1.1); }
button.big:active { transform: translateY(1px); }

button.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #2e3645;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}
button.secondary:hover { background: #2c3445; }

.speed-pick {
  display: inline-flex;
  border: 1px solid #2e3645;
  border-radius: var(--radius);
  overflow: hidden;
}
.speed-pick button {
  background: var(--panel-2);
  color: var(--text);
  border: none;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}
.speed-pick button.active {
  background: var(--accent);
  color: #0e1116;
  font-weight: 700;
}

.day-counter {
  font-size: 16px;
  margin-left: auto;
  color: var(--muted);
}
.day-counter b { color: var(--text); font-size: 20px; padding: 0 4px; }

.graph-wrap {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--pad);
}
.graphs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.graph-cell { background: #0a0d11; border-radius: 6px; padding: 6px 8px 4px; }
.graph-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
.graph-cell canvas { width: 100%; height: 100px; display: block; }
.graph-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}
.graph-legend span.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.right-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}

.world-panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--pad);
}
.world-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.species-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--pad);
  border-left: 4px solid var(--accent);
}
.species-card.disabled { opacity: 0.45; }

.species-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.species-header input[type="checkbox"] { width: 18px; height: 18px; }
.species-header input[type="text"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #2e3645;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 16px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
}
.species-header input[type="color"] {
  background: transparent;
  border: 1px solid #2e3645;
  border-radius: 6px;
  width: 32px;
  height: 30px;
  padding: 0;
}

.trait-row {
  display: grid;
  grid-template-columns: 70px 1fr 44px;
  gap: 8px;
  align-items: center;
  margin: 4px 0;
  font-size: 13px;
}
.trait-row label { color: var(--muted); }
.trait-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.trait-row input[type="range"] { width: 100%; }

.world-check {
  font-size: 13px;
  margin: 4px 0;
}
.world-check label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  cursor: pointer;
}
.world-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.species-toggles {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}
.species-toggles label { display: flex; align-items: center; gap: 4px; cursor: pointer; }

.diet-row {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 8px;
  align-items: center;
  margin: 8px 0 2px;
  font-size: 13px;
}
.diet-row > label { color: var(--muted); }
.diet-pick {
  display: inline-flex;
  border: 1px solid #2e3645;
  border-radius: var(--radius);
  overflow: hidden;
}
.diet-pick button {
  flex: 1;
  background: var(--panel-2);
  color: var(--text);
  border: none;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
}
.diet-pick button:hover { background: #2c3445; }
.diet-pick button.active {
  background: var(--accent);
  color: #0e1116;
  font-weight: 700;
}

.energy-budget {
  margin-top: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel-2);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.energy-budget .eb-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.energy-budget .eb-val { font-weight: 600; }
.energy-budget .eb-val.good     { color: #7cf6c8; }
.energy-budget .eb-val.tight    { color: #f8c34a; }
.energy-budget .eb-val.critical { color: #ff7a7a; }

.right-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.share-row {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.share-row input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #2e3645;
  border-radius: 6px;
  padding: 6px;
  font-size: 12px;
  width: 100%;
  font-family: monospace;
}
.share-row .row { display: flex; gap: 6px; }
.share-row .row button { flex: 1; }

.help {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--pad);
  line-height: 1.5;
}
.help b { color: var(--text); }

.flash {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #0e1116;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.flash.show { opacity: 1; }
