:root {
  --bg: #0a0c10;
  --panel: #12161d;
  --panel-2: #171d26;
  --line: #232b37;
  --text: #e8edf4;
  --muted: #8a97a8;
  --accent: #4ade80;
  --accent-dim: #1c3a2a;
  --danger: #f87171;
  --warn: #fbbf24;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 12px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 'Space Grotesk', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-weight: 700; }

.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* --- шапка --- */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 12px 0 0;
  background: linear-gradient(var(--bg) 82%, transparent);
}

.top-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.top-row h1 { font-size: 20px; letter-spacing: -0.02em; }

.level {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--accent);
}

.xpbar {
  height: 4px;
  margin: 8px 0;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.xpbar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .4s ease;
}

.debt {
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid var(--warn);
  border-radius: 10px;
  background: #2a220c;
  color: var(--warn);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 6px;
  padding-bottom: 10px;
  overflow-x: auto;
}

.tab {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

/* --- общие блоки --- */

.card {
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.spread { display: flex; justify-content: space-between; gap: 8px; }
.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }

.btn {
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.btn:active { transform: scale(.98); }
.btn.primary { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }

.chip {
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
}

.chip.ok { border-color: var(--accent); color: var(--accent); }
.chip.bad { border-color: var(--danger); color: var(--danger); }
.chip.warn { border-color: var(--warn); color: var(--warn); }

/* --- парные сравнения --- */

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pick {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.pick.win { border-color: var(--accent); background: var(--accent-dim); }
.pick.lose { border-color: var(--line); opacity: .6; }

.pick img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  object-fit: cover;
  background: var(--panel-2);
}

.pick-name { font-weight: 700; font-size: 14px; line-height: 1.2; }
.pick-desc {
  font-size: 11px;
  color: var(--muted);
  max-height: 92px;
  overflow: hidden;
}

.vs {
  margin: 10px 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

/* --- карточка игры --- */

.game-head { display: flex; gap: 10px; }

.game-head img {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--panel-2);
  flex: none;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.stat {
  padding: 8px 6px;
  border-radius: 10px;
  background: var(--panel-2);
  text-align: center;
}

.stat b { display: block; font-family: 'JetBrains Mono', monospace; font-size: 15px; }
.stat span { font-size: 10px; color: var(--muted); }

/* --- формы --- */

label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }

input[type=text], input[type=number], input[type=date], textarea, select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

textarea { min-height: 68px; resize: vertical; }

input[type=range] { width: 100%; accent-color: var(--accent); }

.seg { display: flex; gap: 6px; }

.seg button {
  flex: 1;
  padding: 9px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.seg button.on { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }

.slider-val {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
  font-size: 13px;
}

/* --- график --- */

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

.legend { display: flex; gap: 12px; margin-top: 6px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 2px; margin-right: 4px; vertical-align: middle; }

/* --- шторка --- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(0, 0, 0, .6);
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  max-height: 92vh;
  padding: 8px 12px calc(20px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--line);
  background: var(--bg);
  overflow-y: auto;
}

.sheet-grip {
  width: 36px;
  height: 4px;
  margin: 4px auto 12px;
  border-radius: 2px;
  background: var(--line);
}

/* --- служебное --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
}

.empty { padding: 32px 12px; text-align: center; color: var(--muted); }
