/* Цвета берутся из темы Telegram; вне Telegram — из запасных значений ниже. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #7b8190);
  --accent: var(--tg-theme-button-color, #e8590c);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #e8590c);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --win: #1f9d55;
  --loss: #d64545;
  --win-bg: color-mix(in srgb, #1f9d55 14%, transparent);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-secondary-bg-color, #0f1115);
    --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1a1d24));
    --text: var(--tg-theme-text-color, #eef0f4);
    --hint: var(--tg-theme-hint-color, #8a90a0);
    --win: #3fcf7f;
    --loss: #ff6b6b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] { --win: #3fcf7f; --loss: #ff6b6b; color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- верхняя панель и вкладки ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.league-switch {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  background: none; border: 0; padding: 4px 0; font-weight: 700; font-size: 17px;
}
.league-switch span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--hint); font-size: 12px; }
.badge {
  margin-left: auto; flex-shrink: 0;
  font-size: 12px; color: var(--hint); background: var(--card);
  padding: 3px 10px; border-radius: 99px;
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; padding: 7px 0 8px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 11px; color: var(--hint);
}
.tabs .ic { font-size: 19px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.tabs button.active .ic { filter: none; opacity: 1; }

/* ---------- содержимое ---------- */
.view { padding: 12px 16px 16px; max-width: 720px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; }
.hint { color: var(--hint); font-size: 13px; }
.muted { color: var(--hint); }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 8px; }
.empty { text-align: center; color: var(--hint); padding: 28px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.btn.block { width: 100%; }
.btn.secondary { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--link); }
.btn.ghost { background: transparent; color: var(--link); padding: 6px 8px; }
.btn.danger { background: color-mix(in srgb, var(--loss) 14%, transparent); color: var(--loss); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: default; }

input[type=text], input[type=number], input[type=date], input[type=search], select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 6px; border-radius: 8px; font-size: 14px; color: var(--hint); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 99px;
  padding: 5px 11px; font-size: 13px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ---------- списки ---------- */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item.tap { cursor: pointer; }
.item.tap:active { background: var(--bg); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 12px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank { width: 26px; text-align: right; color: var(--hint); font-size: 13px; flex-shrink: 0; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--bg); color: var(--hint); white-space: nowrap; }
.tag.accent { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--link); }
.statline { font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; }
.statline b { color: var(--text); font-weight: 600; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 6px; text-align: right; border-top: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--hint); font-weight: 500; border-top: 0; }
th:first-child, td:first-child { text-align: left; }
td.name { text-align: left; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
tr.mine td { font-weight: 700; }

/* ---------- матчап ---------- */
.score { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; text-align: center; }
.score .team { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.score .big { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score .big .sep { color: var(--hint); font-weight: 400; margin: 0 4px; }
.cats td { text-align: center; }
.cats td:first-child, .cats td:last-child { width: 38%; }
.cats td.k { color: var(--hint); font-size: 12px; }
.cats td.w { color: var(--win); font-weight: 700; background: var(--win-bg); border-radius: 6px; }
.w-text { color: var(--win); } .l-text { color: var(--loss); }
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }

/* ---------- драфт ---------- */
.clock { text-align: center; }
.clock .timer { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.clock.me { background: color-mix(in srgb, var(--accent) 14%, var(--card)); }
.clock.urgent .timer { color: var(--loss); }

/* ---------- нижний лист ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 6px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat-grid div { background: var(--card); border-radius: 10px; padding: 8px 4px; text-align: center; }
.stat-grid b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat-grid span { font-size: 11px; color: var(--hint); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  background: #222; color: #fff; padding: 11px 14px; border-radius: 12px; text-align: center;
  max-width: 480px; margin: 0 auto; font-size: 14px;
}
.toast.ok { background: var(--win); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- здоровье игроков ---------- */
.inj { display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .02em; padding: 1px 5px; border-radius: 5px; vertical-align: 1px; }
.inj.out { background: color-mix(in srgb, var(--loss) 18%, transparent); color: var(--loss); }
.inj.doubtful { background: color-mix(in srgb, #e8590c 18%, transparent); color: #e8590c; }
.inj.q { background: color-mix(in srgb, #d4a106 22%, transparent); color: #b08500; }
.inj.ok { background: var(--win-bg); color: var(--win); }
.banner { background: color-mix(in srgb, var(--loss) 9%, var(--card)); font-size: 14px; }
label.check { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 10px; font-size: 14px; cursor: pointer; }
label.check input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--accent); flex-shrink: 0; }

/* ---------- фото игроков ---------- */
.ava {
  position: relative; flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%; overflow: hidden;
  background: color-mix(in srgb, var(--accent) 16%, var(--bg));
  display: inline-flex; align-items: center; justify-content: center;
}
.ava::before { content: attr(data-i); font-size: 14px; font-weight: 700; color: var(--link); }
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 8%; background: var(--bg); }
.ava.sm { width: 34px; height: 34px; }
.ava.sm::before { font-size: 12px; }
.ava.lg { width: 72px; height: 72px; }
.ava.lg::before { font-size: 22px; }
.player-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.player-head h2 { margin-bottom: 8px; }

/* ---------- поиск и фильтры ---------- */
.toolbar {
  position: sticky; top: 49px; z-index: 3; background: var(--bg);
  margin: -12px -16px 6px; padding: 10px 16px 8px; border-bottom: 1px solid var(--line);
}
.toolbar .row { margin-bottom: 8px; }
.toolbar .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.toolbar .chips::-webkit-scrollbar { display: none; }
.toolbar .chip { white-space: nowrap; flex-shrink: 0; }
#pb-filter { flex-shrink: 0; padding: 10px 12px; }
.pb-total { margin: 2px 2px 6px; }
.sortval { display: inline-block; margin-right: 6px; font-size: 12px; color: var(--link); }
.sortval b { font-weight: 700; }

/* кнопка «Взять» есть всегда, видна только когда можно выбирать — строки не меняют высоту */
.pb-list .pick-btn { visibility: hidden; }
.pb-list.can-pick .pick-btn { visibility: visible; }
.pick-btn .lbl-other { display: none; }
.pb-list.pick-other .pick-btn .lbl-mine { display: none; }
.pb-list.pick-other .pick-btn .lbl-other { display: inline; }

/* ---------- часы драфта: закреплены и не меняют высоту ---------- */
.clock { position: sticky; top: 49px; z-index: 4; padding: 10px 14px; box-shadow: 0 4px 12px rgba(0,0,0,.06); }
.clock .clock-top { display: flex; align-items: center; justify-content: center; position: relative; min-height: 24px; }
.clock #ck-sound { position: absolute; right: -6px; top: -4px; font-size: 16px; }
.clock .who { font-weight: 700; margin: 2px 0; min-height: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock .timer { font-size: 30px; line-height: 1.15; }
/* на драфте закреплены часы — панель поиска под ними обычная */
#draft-body .toolbar { position: static; margin-top: 0; }
