/* Светлая тема под референс: тёплый серо-белый фон, белые карточки,
   цветные иконки нижней навигации. Цвета фиксированы намеренно, чтобы
   вид совпадал со скриншотом (тему Telegram можно подключить позже). */
:root {
  --bg:     #f5f6fa;
  --card:   #ffffff;
  --ink:    #1e1f23;
  --muted:  #6e7280;
  --track:  #ecedf5;   /* фон чипов и дорожек прогресса */
  --grid:   #e3e4ee;   /* сетка радара, линии-разделители */
  --avatar: #cdccdb;   /* фон аватара-заглушки */
  --hl:     #efedfb;   /* подсветка своей строки в рейтинге */
  --accent: #8b7cf6;                        /* основной цвет — одинаков в обеих темах */
  --accent-weak: rgba(139, 124, 246, .20);  /* полупрозрачная заливка радара */
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: 0 2px 14px rgba(0, 0, 0, .05);
  --radius: 20px;
}

/* Тёмная тема — переключается кнопкой в профиле (data-theme на <html>). */
:root[data-theme="dark"] {
  --bg:     #0f1117;
  --card:   #181b22;
  --ink:    #f2f3f5;
  --muted:  #a1a4b2;
  --track:  #262a33;
  --grid:   #2a2e38;
  --avatar: #2a2e38;
  --hl:     #232743;   /* фиолетовая подсветка своей строки */
  --l0:     #20242e;   /* пустая ячейка тепловой карты в тёмной теме */
  --shadow: 0 2px 14px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: 92px;               /* место под фиксированный таб-бар */
}
body.no-tabbar { padding-bottom: 0; } /* таб-бар скрыт (тест/результат) — низ свободен */

#view { padding: 14px 16px 0; max-width: 640px; margin: 0 auto; }

.page-title { font-size: 32px; font-weight: 800; margin: 6px 4px 18px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.muted { color: var(--muted); font-size: 15px; }

/* ── Шапка профиля ─────────────────────────────────────────────────── */
.pf-head { display: flex; align-items: center; gap: 18px; }
.pf-avatar {
  width: 92px; height: 92px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  background: var(--avatar); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 700;
}
.pf-name     { font-size: 24px; font-weight: 800; line-height: 1.15; }
.pf-nick     { color: var(--muted); font-size: 15px; margin-top: 4px; }
.pf-username { color: var(--muted); font-size: 16px; margin-top: 4px; }
.pf-joined   { color: var(--muted); font-size: 15px; margin-top: 8px; }

/* ── Сетка статистики (3 ряда × 2) ─────────────────────────────────── */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 24px 12px; padding: 24px 18px; }
.stat        { text-align: center; }
.stat-label  { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.stat-value  { font-size: 24px; font-weight: 800; }

/* ── Пустая вкладка ────────────────────────────────────────────────── */
.empty { text-align: center; color: var(--muted); padding: 70px 20px; }
.empty svg { width: 56px; height: 56px; opacity: .9; margin-bottom: 16px; }
.empty .t  { font-size: 18px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }

/* ── Нижняя навигация ──────────────────────────────────────────────── */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around; align-items: center;
  background: var(--bg);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--grid);
}
.tab {
  border: none; background: transparent; cursor: pointer; color: var(--muted);
  width: 46px; height: 46px; border-radius: 14px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.tab svg { width: 26px; height: 26px; }
.tab.active { background: var(--card); box-shadow: var(--shadow); color: var(--accent); }

/* ── Статистика ────────────────────────────────────────────────────── */
/* уровни тепловой карты: пусто → насыщенно */
:root { --l0: #e6e7f0; --l1: #d8d3f8; --l2: #b7adf3; --l3: #9585ee; --l4: #7360e6; }

/* аккордеон */
.acc-head { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.acc-title { font-size: 19px; font-weight: 800; }
.acc-chevron { font-size: 24px; color: var(--muted); line-height: 1; transition: transform .2s ease; }
.acc.open .acc-chevron { transform: rotate(90deg); }
.acc-body { display: none; padding-top: 16px; }
.acc.open .acc-body { display: block; }

/* тепловая карта активности */
.hm { display: flex; gap: 10px; overflow-x: auto; }
.hm-days { display: flex; flex-direction: column; gap: 4px; padding-top: 20px; flex-shrink: 0; }
.hm-day-label { height: 20px; line-height: 20px; font-size: 12px; color: var(--muted); }
.hm-months { display: flex; gap: 4px; height: 20px; }
.hm-month { width: 20px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: visible; }
.hm-cols { display: flex; gap: 4px; }
.hm-col { display: flex; flex-direction: column; gap: 4px; }
.hm-cell { width: 20px; height: 20px; border-radius: 6px; }
.hm-legend { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.hm-legend i { width: 14px; height: 14px; border-radius: 4px; }

/* чипы выбора предмета */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { border: none; border-radius: 999px; padding: 9px 16px; font-size: 15px; font-weight: 600; background: var(--track); color: var(--ink); cursor: pointer; }
.chip.active { background: var(--accent); color: #fff; }

/* радар точности по темам */
.radar { width: 100%; max-width: 320px; display: block; margin: 0 auto 8px; }

/* список тем с прогресс-барами */
.tlist { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.trow-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; margin-bottom: 5px; }
.trow-name { font-weight: 600; }
.trow-pct { font-weight: 800; color: var(--accent); }
.tbar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.tbar > i { display: block; height: 100%; background: var(--accent); }
.trow-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* сводные карточки 2×2 */
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sum-card { margin-bottom: 0; padding: 16px; }
.sum-label { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.sum-value { font-size: 26px; font-weight: 800; }
.sum-value.good { color: var(--success); }
.sum-value.warn { color: var(--warning); }
.sum-sub { font-size: 12px; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .3px; }

/* сетка радара — тонируется темой */
.radar .rgrid { stroke: var(--grid); stroke-width: 1; fill: none; }
/* подписи тем на радаре — цвет по теме */
.radar .rlabel { fill: var(--ink); }

/* кнопка переключения темы в профиле */
.theme-toggle {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: none; cursor: pointer;
  font-family: inherit; font-size: 16px; font-weight: 600;
  color: var(--ink); background: var(--card);
}

/* ── О боте ─────────────────────────────────────────────────────────── */
.ab-lead { font-size: 16px; line-height: 1.5; }
.ab-info { padding: 6px 18px; }
.ab-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 12px 0; }
.ab-row + .ab-row { border-top: 1px solid var(--grid); }
.ab-key { color: var(--muted); font-size: 15px; }
.ab-val { font-weight: 700; text-align: right; }
.ab-primary { background: var(--accent); color: #fff; }
.donate-opt { text-align: center; }

/* инструкция (онбординг) */
.ob-lead { color: var(--muted); font-size: 15px; margin: -6px 4px 16px; line-height: 1.5; }
.ob-card { padding: 16px 18px; }
.ob-h { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.ob-row { font-size: 15px; line-height: 1.5; margin-bottom: 10px; }
.ob-row:last-child { margin-bottom: 0; }

/* ── Главная: тест / соревнование ──────────────────────────────────── */
.big-btn {
  display: block; width: 100%; text-align: left; cursor: pointer;
  border: none; border-radius: var(--radius); padding: 20px; margin-bottom: 14px;
  background: var(--accent); color: #fff; font-family: inherit; font-size: 16px;
}
.big-btn.ghost { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.big-btn:disabled { opacity: .45; cursor: default; }
.big-btn-title { display: block; font-size: 20px; font-weight: 800; }
.big-btn-sub   { display: block; font-size: 14px; opacity: .9; margin-top: 4px; }
.big-btn.ghost .big-btn-sub { color: var(--muted); opacity: 1; }

/* списки выбора предмета/темы */
.pick-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.list-btn {
  width: 100%; text-align: left; border: none; border-radius: 14px; padding: 16px;
  font-size: 16px; background: var(--card); color: var(--ink); cursor: pointer;
  box-shadow: var(--shadow); font-family: inherit;
}
.list-btn.back { text-align: center; background: transparent; box-shadow: none; color: var(--muted); }

/* экран вопроса */
.q-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.q-meta { color: var(--muted); font-size: 14px; }
.q-timer { font-weight: 800; font-size: 18px; color: var(--accent); min-width: 30px; text-align: right; }
.q-progress { height: 5px; border-radius: 3px; background: var(--track); overflow: hidden; margin-bottom: 16px; }
.q-progress > i { display: block; height: 100%; width: 100%; background: var(--accent); transition: width 1s linear; }
.q-img { width: 100%; border-radius: 14px; margin-bottom: 12px; }
.q-text { font-size: 19px; font-weight: 700; margin-bottom: 14px; }
.q-opts { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.q-opt {
  width: 100%; text-align: left; border: 2px solid transparent; border-radius: 14px;
  padding: 15px; font-size: 16px; background: var(--card); color: var(--ink);
  cursor: pointer; box-shadow: var(--shadow); font-family: inherit;
}
.q-opt.sel { border-color: var(--accent); }

/* экран результата */
.result-screen { display: flex; flex-direction: column; min-height: calc(100vh - 14px); min-height: calc(100dvh - 14px); }
.q-result { text-align: center; margin: 34px 0 20px; }
.result-big { font-size: 46px; font-weight: 800; }
.result-line { color: var(--muted); font-size: 15px; margin-top: 6px; }
.result-verdict { font-size: 18px; font-weight: 700; margin-top: 12px; }
/* «На главную» прижата к низу экрана (как «Покинуть тест») */
.result-foot { margin-top: auto; padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }

/* форма «Сообщить об ошибке» */
.fb-input {
  width: 100%; min-height: 130px; resize: vertical;
  border-radius: 14px; padding: 14px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--grid); background: var(--card); color: var(--ink);
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.fb-error { color: #d03b3b; font-size: 14px; margin-bottom: 10px; }

/* поле смены ника */
.nick-input {
  width: 100%; border-radius: 14px; padding: 14px; font-size: 16px;
  font-family: inherit; border: 1px solid var(--grid);
  background: var(--card); color: var(--ink); box-shadow: var(--shadow);
  margin-bottom: 12px;
}

/* ── Рейтинг ───────────────────────────────────────────────────────── */
/* переключатель месяца */
.seg { display: flex; gap: 8px; margin-bottom: 14px; }
.seg-btn { flex: 1; border: none; border-radius: 12px; padding: 11px; font-size: 15px; font-weight: 600; background: var(--track); color: var(--ink); cursor: pointer; }
.seg-btn.active { background: var(--accent); color: #fff; }

/* карточка «моё место» (тёплый градиент под референс) */
.lb-card { border-radius: var(--radius); padding: 18px; margin-bottom: 16px; color: #fff;
  background: linear-gradient(135deg, #9a8bf7, #6f5fe1); box-shadow: var(--shadow); }
.lb-card-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.lb-league { font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-badge { background: rgba(255,255,255,.22); border-radius: 10px; padding: 6px 11px; font-size: 14px; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
.lb-me { display: flex; justify-content: space-between; align-items: center; background: rgba(255,255,255,.18); border-radius: 12px; padding: 12px 14px; font-size: 17px; font-weight: 700; }

/* список игроков */
.lb-list { padding: 4px 0; }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--grid); }
.lb-row:last-child { border-bottom: none; }
.lb-row.me { background: var(--hl); }
.lb-rank { width: 30px; text-align: center; font-weight: 700; color: var(--muted); font-size: 16px; flex-shrink: 0; }
.lb-rank.medal { font-size: 22px; line-height: 30px; }
.lb-av { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; flex-shrink: 0; }
.lb-name { flex: 1; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-val { font-weight: 800; font-size: 17px; text-align: right; }
.lb-sub { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
