: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, #11131a);
  --hint: var(--tg-theme-hint-color, #7d8290);
  --link: var(--tg-theme-link-color, #2b6cd6);
  --accent: var(--tg-theme-button-color, #1f4fd1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-header-bg-color, var(--card));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--hint) 12%, transparent);
  --danger: var(--tg-theme-destructive-text-color, #d93a3a);

  --pts-3: #1f9d55;
  --pts-2: #1b8fa8;
  --pts-1: #c88a12;
  --pts-0: var(--hint);

  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@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);
    --link: var(--tg-theme-link-color, #6ea2ff);
    --accent: var(--tg-theme-button-color, #3d6ef0);
    --pts-3: #3ccf7a;
    --pts-2: #37b8d4;
    --pts-1: #e8b23c;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Шапка */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--header);
  border-bottom: 1px solid var(--sep);
}
.topbar__title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__logo {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text);
  font-size: 18px;
}
.topbar__name { font-weight: 700; font-size: 16px; }
.topbar__sub { color: var(--hint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__score { text-align: right; }
.topbar__points { display: block; font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.topbar__points::after { content: " очк."; font-size: 12px; font-weight: 500; color: var(--hint); }
.topbar__place { display: block; color: var(--hint); font-size: 12px; }

/* Основной контент */
.view { padding: 12px 16px calc(84px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }

.section-title {
  margin: 18px 4px 8px;
  font-size: 13px; font-weight: 600; letter-spacing: .02em;
  color: var(--hint); text-transform: uppercase;
}
.section-title:first-child { margin-top: 4px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.empty { text-align: center; color: var(--hint); padding: 48px 16px; }
.empty__icon { font-size: 36px; margin-bottom: 8px; }

/* Фильтры-чипы */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 0; border-radius: 999px;
  padding: 7px 14px;
  background: var(--card); color: var(--text);
  font-size: 14px; white-space: nowrap;
}
.chip.is-active { background: var(--accent); color: var(--accent-text); }

/* Карточка матча */
.match__meta { display: flex; justify-content: space-between; gap: 8px; color: var(--hint); font-size: 12px; margin-bottom: 10px; }
.match__row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.team { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; min-width: 0; }
.team__badge {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  font-weight: 700; font-size: 14px; color: #fff;
}
.team__name { font-weight: 600; font-size: 14px; line-height: 1.2; overflow-wrap: anywhere; }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper__col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stepper__btn {
  width: 34px; height: 28px; border: 0; border-radius: 8px;
  background: var(--soft); font-size: 18px; line-height: 1;
}
.stepper__btn:active { transform: scale(.94); }
.stepper__val {
  width: 40px; height: 44px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums;
  background: var(--soft);
}
.stepper__val.is-empty { color: var(--hint); font-weight: 500; }
.stepper__sep { font-size: 22px; font-weight: 700; color: var(--hint); }

.match__actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; min-height: 36px; }
.match__status { font-size: 13px; color: var(--hint); }
.match__status.is-saved { color: var(--pts-3); }

.btn {
  border: 0; border-radius: 10px;
  padding: 9px 16px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 600; font-size: 14px;
}
.btn:disabled { opacity: .45; }
.btn--ghost { background: var(--soft); color: var(--text); }
.btn--block { width: 100%; padding: 12px; }
.btn--danger { background: transparent; color: var(--danger); }

/* Результаты */
.score { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; min-width: 76px; }
.score--live { color: var(--danger); font-size: 14px; font-weight: 700; }
.result__foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--hint); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 4px 10px;
  font-size: 13px; font-weight: 600;
  background: var(--soft); color: var(--text);
}
.pts { border-radius: 999px; padding: 2px 8px; color: #fff; font-weight: 700; font-size: 12px; }
.pts-3 { background: var(--pts-3); }
.pts-2 { background: var(--pts-2); }
.pts-1 { background: var(--pts-1); }
.pts-0 { background: var(--pts-0); }

/* Таблица */
.lb { padding: 4px 0; }
.lb__row {
  display: grid; grid-template-columns: 36px 1fr auto auto; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--sep);
}
.lb__row:first-child { border-top: 0; }
.lb__row.is-me { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.lb__place { font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.lb__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.lb__exact { color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; }
.lb__pts { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 32px; text-align: right; }
.lb__legend { color: var(--hint); font-size: 12px; margin: 4px 4px 0; }

/* Профиль */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.stat__val { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat__label { color: var(--hint); font-size: 12px; }

.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.list__item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 13px 14px;
  border: 0; border-top: 1px solid var(--sep);
  background: transparent; text-align: left;
}
.list__item:first-child { border-top: 0; }
.list__label { min-width: 0; }
.list__title, .list__sub { display: block; }
.list__title { font-weight: 500; }
.list__sub { color: var(--hint); font-size: 13px; }
.list__value { color: var(--hint); flex: none; text-align: right; }
.list__value strong { color: var(--text); }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--soft); transition: background .2s; pointer-events: none; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

.rules { white-space: pre-line; color: var(--text); font-size: 14px; }

/* Нижняя панель */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: var(--header);
  border-top: 1px solid var(--sep);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: transparent; padding: 4px 0;
  color: var(--hint); font-size: 11px; font-weight: 500;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--accent); }

/* Нижний лист */
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s; }
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 85vh; overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + var(--safe-bottom));
  animation: up .22s ease-out;
  max-width: 640px; margin: 0 auto;
}
.sheet__handle { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 12px; }
.sheet__title { font-size: 17px; font-weight: 700; margin: 0 0 4px; }
.sheet__sub { color: var(--hint); font-size: 13px; margin: 0 0 12px; }

.field {
  width: 100%; padding: 12px 14px; margin-bottom: 10px;
  border: 1px solid var(--sep); border-radius: 10px;
  background: var(--card); outline: none;
}
.field:focus { border-color: var(--accent); }

.team-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.team-option {
  display: flex; align-items: center; gap: 8px;
  padding: 10px; border: 2px solid transparent; border-radius: 12px;
  background: var(--card); text-align: left; font-size: 14px;
}
.team-option .team__badge { width: 28px; height: 28px; font-size: 11px; flex: none; }
.team-option.is-active { border-color: var(--accent); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + var(--safe-bottom)); z-index: 20;
  margin: 0 auto; max-width: 420px;
  padding: 12px 16px; border-radius: 12px;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg);
  font-size: 14px; text-align: center;
  animation: up .2s ease-out;
}

.skeleton { height: 128px; border-radius: var(--radius); margin-bottom: 10px; background: var(--card); position: relative; overflow: hidden; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--soft), transparent);
  animation: shimmer 1.2s infinite;
}

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
