:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --muted: #64748b;
  --micro: #8bc34a;
  --animal: #2196f3;
  --human: #e53935;
  --empty: #f1f5f9;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #1e3a8a 0%, var(--bg) 55%) fixed;
  color: #0f172a;
  min-height: 100vh;
}

.page {
  max-width: 1020px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.hero {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.hero h1 { margin: 0 0 6px; font-size: 28px; }
.subtitle { margin: 0; color: var(--muted); max-width: 420px; }

.score-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  min-width: 110px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
}
.card.highlight { background: #fffbeb; border-color: #fde68a; }
.card-label { font-size: 12px; color: var(--muted); }
.card-value { font-size: 24px; font-weight: 800; }

.layout {
  display: grid;
  grid-template-columns: 1.4fr .9fr;
  gap: 16px;
  margin-top: 16px;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

.game-panel, .side-panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.status {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  min-height: 42px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  aspect-ratio: 1 / 1;
}

.cell {
  border: none;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 6px;
  color: inherit;
}
.cell svg {
  width: 68%;
  height: 68%;
  max-width: 40px;
  max-height: 40px;
  display: block;
}
.cell-tag {
  position: absolute;
  right: 6px;
  bottom: 4px;
  font-size: 11px;
  font-weight: 800;
  opacity: .75;
  line-height: 1;
}
.cell.empty { background: var(--empty); }
.cell.empty:hover { filter: brightness(.94); transform: scale(1.03); }
.cell.micro { background: var(--micro); color: #1a2e05; }
.cell.animal { background: var(--animal); color: white; }
.cell.human { background: var(--human); color: white; }
.cell.pop { animation: pop .35s ease; }
@keyframes pop {
  0% { transform: scale(.7); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.cell:disabled { cursor: default; }

.controls { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn {
  border: 1px solid #cbd5e1;
  background: white;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn.primary { background: #0f172a; color: white; border-color: #0f172a; }
.btn.small { margin-top: 8px; width: 100%; }
.side-panel .controls .btn.small { width: auto; flex: 1; margin-top: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.save-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.save-row label { font-size: 14px; color: var(--muted); white-space: nowrap; }
.save-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  font-size: 16px;
}

.hint { color: var(--muted); font-size: 13px; }
.howto { margin-top: 8px; font-size: 14px; }
.howto code { background: #f1f5f9; padding: 1px 6px; border-radius: 6px; }
.port-note { color: var(--muted); font-size: 13px; }

.panel-title { margin: 0 0 4px; font-size: 17px; }

.tabs { display: flex; gap: 8px; }
.tab {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  cursor: pointer;
  font-weight: 700;
}
.tab.active { background: #0f172a; color: white; border-color: #0f172a; }

.notice {
  margin-top: 10px;
  font-size: 13px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  padding: 8px 10px;
  border-radius: 10px;
  color: #92400e;
}
.hidden { display: none; }

.leaderboard { padding-left: 22px; margin: 12px 0; }
.leaderboard li {
  padding: 6px 4px;
  border-bottom: 1px dashed #e2e8f0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.leaderboard .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .pts { font-weight: 800; }

.legend { display: grid; gap: 6px; margin-top: 12px; font-size: 14px; }
.legend-row { display: flex; align-items: center; gap: 4px; }
.evo-chain { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.chip {
  display: inline-flex;
  width: 30px; height: 30px;
  align-items: center; justify-content: center;
  border-radius: 8px;
  margin-right: 6px;
  padding: 3px;
}
.chip svg { width: 100%; height: 100%; display: block; }
.chip.micro { background: var(--micro); color: #1a2e05; }
.chip.animal { background: var(--animal); color: white; }
.chip.human { background: var(--human); color: white; }

footer { color: #cbd5e1; text-align: center; margin-top: 14px; font-size: 13px; }
