/* Тема Telegram -> CSS-переменные, с фоллбэками для тёмной темы */
:root {
  --bg: var(--tg-theme-bg-color, #212121);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8a8a8a);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --accent-hover: var(--tg-theme-link-color, #62bcf9);
  --panel: var(--tg-theme-secondary-bg-color, #181818);
  --danger: #e8503a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 12px 14px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

#auth-warning {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
}

header { margin: 4px 0 12px; }

#user-line { font-size: 20px; font-weight: 700; }

#league-line {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 13px;
  color: var(--hint);
}
#league-line:empty { display: none; }

/* ---------- табы ---------- */

#tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.tab-btn {
  padding: 9px 2px;
  border: 0;
  border-radius: 10px;
  background: var(--panel);
  color: var(--hint);
  font-size: 14px;
  font-weight: 600;
}
.tab-btn.active { background: var(--accent); color: var(--accent-text); }

/* ---------- таблица статистики ---------- */

#stat-wrap { margin-top: 14px; overflow-x: auto; }

#stat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

#stat-table th, #stat-table td {
  padding: 7px 9px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 35%, transparent);
}

#stat-table th {
  color: var(--hint);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#stat-table th:first-child, #stat-table td:first-child {
  text-align: left;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#stat-table tr.me-row td { color: var(--accent-hover); font-weight: 700; }

#stat-empty {
  padding: 24px 0;
  text-align: center;
  color: var(--hint);
  font-size: 15px;
}

.chips.wrap { flex-wrap: wrap; max-height: 96px; overflow-y: auto; }

/* ---------- лиги ---------- */

#league-list { display: flex; flex-direction: column; gap: 10px; }

.league-card {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
}

.league-card.me-card { outline: 2px solid var(--accent); }

.league-line1 { font-size: 15px; }

.league-line1 .leag { color: var(--hint); }

.league-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.league-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  vertical-align: -4px;
  flex: none;
}

.league-next { display: inline-flex; align-items: center; gap: 3px; }

.league-pill-icon {
  width: 14px;
  height: 14px;
  object-fit: contain;
  flex: none;
}

.league-bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  /* rgba вместо color-mix: последний не поддерживается старыми WebView Telegram */
  background: rgba(127, 127, 127, 0.25);
  overflow: hidden;
}

.league-bar .fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  min-width: 3px;
}

.league-left { margin-top: 6px; color: var(--hint); font-size: 13px; }

#league-empty { padding: 24px 0; text-align: center; color: var(--hint); font-size: 15px; }

/* ---------- экран записи ---------- */

.ex-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-btn {
  width: 52px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
}
.icon-btn:active { background: var(--accent); }

#ex-name, #c-ex-name { font-size: 17px; font-weight: 600; }

#today-hint { margin: 6px 0 0; color: var(--hint); font-size: 13px; text-align: center; }

#reps-display {
  margin: 22px 0 2px;
  text-align: center;
  font-size: 72px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-height: 88px;
}

#reps-hint {
  text-align: center;
  color: var(--hint);
  font-size: 14px;
  margin-bottom: 18px;
}

#keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

#keypad button {
  height: 56px;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 24px;
  font-weight: 600;
}
#keypad button:active { background: var(--accent); color: var(--accent-text); }

button.primary {
  display: block;
  width: 100%;
  padding: 15px 0;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 17px;
  font-weight: 700;
}
button.primary:disabled { opacity: 0.45; }

button.ghost {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 11px 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--hint);
  font-size: 14px;
}
button.ghost:active { color: var(--danger); }

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

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 12px 0 4px;
}

.chips button {
  padding: 7px 13px;
  border: 0;
  border-radius: 999px;
  background: var(--panel);
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
}

.chips button.active { background: var(--accent); color: var(--accent-text); }

.chips .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

#chart-wrap {
  position: relative;
  margin-top: 14px;
  height: 260px;
}

#chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint);
  font-size: 15px;
}

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 88%;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid rgba(128, 128, 128, 0.35);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 10;
}
