* { box-sizing: border-box; }

:root {
  --bg: #0e1530;
  --bg2: #131c3f;
  --panel: #1a2450;
  --panel2: #212d63;
  --ink: #eef2ff;
  --muted: #9aa6d4;
  --accent: #7c8cff;
  --line: #2b376e;
}

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

.hidden { display: none !important; }

/* Кнопка домой */
#homeBtn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: rgba(26, 36, 80, 0.85);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  backdrop-filter: blur(4px);
}
#homeBtn:hover { background: var(--panel2); }

/* ---------- Стартовое меню ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(120% 120% at 50% 0%, #20306a, var(--bg));
  z-index: 40;
  padding: 20px;
}
.panel {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 26px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
}
.panel h1 { margin: 0 0 10px; font-size: 26px; }
.panel p { color: var(--muted); line-height: 1.5; margin: 8px 0 18px; }
.panel label { display: block; margin-bottom: 8px; font-size: 15px; }
.panel input[type="range"] { width: 100%; accent-color: var(--accent); }

.preview-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 16px 0 4px;
  min-height: 40px;
}
.preview-row img { width: 34px; height: 34px; }

#startBtn {
  margin-top: 18px;
  width: 100%;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  color: #0e1530;
  background: linear-gradient(180deg, #aab6ff, var(--accent));
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
#startBtn:hover { filter: brightness(1.06); }
.hint { font-size: 12.5px; margin-top: 16px !important; }

/* ---------- Основной экран ---------- */
#app {
  display: flex;
  height: 100%;
  width: 100%;
}

#sidebar {
  width: 30%;
  min-width: 240px;
  max-width: 460px;
  height: 100%;
  background: var(--bg2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 12px 60px;
  border-bottom: 1px solid var(--line);
}
.sidebar-head h2 { margin: 0; font-size: 16px; }
#restartBtn {
  width: 32px;
  height: 32px;
  font-size: 17px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
#restartBtn:hover { background: var(--panel2); }

#cards {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 10px;
  transition: opacity .3s;
}
.card.extinct { opacity: 0.38; }

.card-head { display: flex; align-items: center; gap: 8px; }
.card-head .avatar { width: 32px; height: 32px; flex: none; }
.card-head .title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.card-head .name { font-weight: 700; font-size: 14px; }
.card-head .count { font-size: 12px; color: var(--muted); }
.card-head .count b { color: #9be39b; }

.attrs {
  display: flex;
  gap: 6px;
  margin: 7px 0 6px;
  font-size: 11.5px;
  color: var(--muted);
}
.attrs span {
  background: var(--panel2);
  border-radius: 6px;
  padding: 2px 7px;
  white-space: nowrap;
}

.rel-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.rel-row .lbl {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  width: 78px;
  flex: none;
}
.rel-row.fears .lbl { color: #ff9d9d; }
.rel-row.beats .lbl { color: #9be39b; }
.icons { display: flex; flex-wrap: wrap; gap: 3px; }
.icons img { width: 17px; height: 17px; }
.icons .none { font-size: 11px; color: var(--muted); }

/* ---------- Сцена / карта ---------- */
#stage {
  flex: 1;
  position: relative;
  background:
    radial-gradient(80% 80% at 30% 20%, #16204a, #0b1126);
  overflow: hidden;
}
#canvas { display: block; width: 100%; height: 100%; }

#speedCtrl {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  background: rgba(16, 22, 48, 0.78);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(4px);
  z-index: 10;
}
.speed-top, .speed-bot { font-size: 15px; }
#speedCtrl input[type="range"] {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 8px;
  height: 160px;
  accent-color: var(--accent);
}
#speedVal {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#hud {
  position: absolute;
  top: 12px;
  right: 14px;
  background: rgba(16, 22, 48, 0.78);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 11px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  z-index: 10;
}

@media (max-width: 640px) {
  #sidebar { min-width: 180px; }
  .rel-row .lbl { width: 56px; }
}
