:root {
  --bg: #0f1720;
  --bg-card: #182433;
  --bg-card-2: #202f42;
  --border: #2c3d52;
  --text: #eef3f8;
  --text-dim: #93a4b8;
  --accent: #3ddc97;
  --accent-2: #4d9fff;
  --red: #ff6767;
  --amber: #ffb347;
  --team-a: #5b9dff;
  --team-b: #7d9bc4;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: 80px; }

a { color: var(--accent-2); }

h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }

p { margin: 0.3em 0; }

.container { max-width: 720px; margin: 0 auto; padding: 12px 14px 40px; }

/* Растягиваем на весь экран даже при коротком/пустом контенте вкладки —
   иначе под коротким содержимым остаётся пустая область без DOM-элемента,
   и свайп там не улавливается (не с чем сработать closest() в обработчике). */
.portrait-view { min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(15,23,32,0.92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar .title { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { color: var(--text-dim); font-size: 0.8rem; margin-top: 4px; }

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

.card-2 { background: var(--bg-card-2); }

.grid { display: grid; gap: 10px; margin-top: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }

label { display: block; font-size: 0.82rem; color: var(--text-dim); margin: 10px 0 4px; }
label:first-child { margin-top: 0; }

input, select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0c141c;
  color: var(--text);
  font-size: 1rem;
  box-sizing: border-box;
  height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent-2); }
input[type="date"] { line-height: 1.2; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 18px;
  border-radius: 12px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-card-2);
  color: var(--text);
  border: 1px solid var(--border);
  transition: transform 0.05s ease;
  width: 100%;
  gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #06251a; border-color: var(--accent); }
.btn-accent { background: var(--accent-2); color: #04182e; border-color: var(--accent-2); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn-ghost { background: transparent; }
.btn-sm { width: auto; padding: 8px 12px; font-size: 0.85rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { width: auto; flex: 1; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.tabs { display: flex; gap: 20px; overflow-x: auto; padding: 8px 0 20px; }
.tab {
  flex: none; padding: 6px 0 12px; background: none; border: none;
  color: var(--text-dim); font-size: 1rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  position: relative;
}
.tab.active { color: var(--text); font-weight: 800; }
.tab.active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 2px; height: 3px; border-radius: 3px;
  background: #7c6fee;
}

.badge {
  display: inline-block; vertical-align: middle; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700;
  background: var(--bg-card-2); color: var(--text-dim); border: 1px solid var(--border);
  text-transform: none;
}
/* Статусы уровня турнира без точки (например "Квалификация") — приглушённо,
   нейтральным цветом. */
.badge-live { background: var(--bg-card-2); color: var(--text); border-color: var(--border); }
/* "Идёт" — раунд/матч в процессе, с пульсирующей точкой — тёплая жёлтая пилюля. */
.badge-live:has(.live-dot) { background: #ffe066; color: #3d2e00; border-color: #ffe066; }
/* Точка ".live-dot" смещает текст вправо внутри пилюли — уравновешиваем
   таким же невидимым отступом справа, чтобы слово выглядело по центру. */
.badge-live:has(.live-dot)::after { content: ''; display: inline-block; vertical-align: middle; width: 8px; margin-left: 6px; }
.badge-done { background: transparent; color: var(--text); border-color: var(--text-dim); }
.badge-amber { background: var(--amber); color: #331e00; border-color: var(--amber); }

.score-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.score-row input { text-align: center; font-size: 1.2rem; font-weight: 700; width: 64px; flex: none; }
.score-row .colon { color: var(--text-dim); font-weight: 700; }
.score-row .btn { flex: 1; }

.sub-toggle-row { margin-top: 8px; }
.sub-picker { margin-top: 8px; padding: 10px; border-radius: 10px; background: #0c141c; border: 1px solid var(--border); }
.sub-picker label { margin-top: 8px; }
.sub-picker label:first-child { margin-top: 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: center; }

.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg-card-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.list-row:last-child { margin-bottom: 0; }
.list-row .name { font-weight: 600; }
.list-row .meta { color: var(--text-dim); font-size: 0.8rem; }

.muted { color: var(--text-dim); }
.center { text-align: center; }
.small { font-size: 0.82rem; }
.error { color: var(--red); font-size: 0.88rem; margin-top: 6px; }
.success { color: var(--accent); font-size: 0.88rem; margin-top: 6px; }

.metrics-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  background: #0c141c; border-radius: 10px; padding: 6px 10px; margin-top: 8px;
}
.metric { display: flex; align-items: baseline; gap: 6px; padding: 2px 0; }
.metric .v { font-size: 1.15rem; font-weight: 800; }
.metric .l { font-size: 0.72rem; color: var(--text-dim); }

.link-box { display: flex; gap: 6px; align-items: center; background: #0c141c; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 0.85rem; overflow: hidden; }
.link-box input { border: none; background: transparent; padding: 0; flex: 1; font-size: 0.85rem; }

.empty { text-align: center; padding: 30px 10px; color: var(--text-dim); }

.live-dot { display: inline-block; vertical-align: middle; width: 8px; height: 8px; border-radius: 50%; background: #3d2e00; margin-right: 6px; box-shadow: 0 0 0 0 rgba(61,43,0,0.6); animation: pulse 2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61,43,0,0.45); }
  70% { box-shadow: 0 0 0 8px rgba(61,43,0,0); }
  100% { box-shadow: 0 0 0 0 rgba(61,43,0,0); }
}

.bracket { display: flex; flex-direction: column; gap: 10px; }

/* Карточка матча — цветные имена без фоновых "таблеток" (синий/оранжевый по
   командам, победитель зелёным), крупный счёт по центру. Используется и в
   портретных вкладках (Сейчас играют / История / Сетка), и в альбомной
   раскладке — единое цветовое оформление, разный только масштаб. */
.lm-court {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.lm-court-header { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-bottom: 8px; position: relative; }
.lm-court-label {
  font-weight: 800; font-size: 0.92rem;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em;
  position: absolute; left: 50%; transform: translateX(-50%);
}
.lm-row { display: flex; align-items: center; gap: 10px; }
.lm-team { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lm-team.right { align-items: flex-end; text-align: right; }
.lm-team .lm-name {
  font-weight: 800; font-size: 1.1rem; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.lm-team.team-a .lm-name { color: var(--team-a); }
.lm-team.team-b .lm-name { color: var(--team-b); }
.lm-score {
  position: relative; flex: none; font-weight: 900; color: var(--text);
  font-size: 2.1rem; letter-spacing: 0.01em; text-align: center; min-width: 1.4em;
}
/* "VS" внутри .lm-score — заметно мельче самого счёта, чтобы отличаться от
   цифр по значимости. (Не путать с .lm-vs — тот же "vs", но в компактных
   карточках предстоящих матчей, отдельный контекст.) */
.lm-score-vs { font-size: 0.68em; }
/* Победитель — трофей рядом со счётом/VS (с той стороны, с которой выиграла
   команда), сам счёт победителя подсвечен золотистым — имена игроков цвет не меняют.
   Трофей позиционируется абсолютно относительно .lm-score, чтобы сам счёт/VS
   всегда оставался по центру и не смещался при появлении трофея. */
.lm-score-win { color: #e0b23c; }
.lm-trophy {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 0.45em; white-space: nowrap;
}
.lm-trophy.left { right: 100%; margin-right: 5px; }
.lm-trophy.right { left: 100%; margin-left: 5px; }

.lm-compact { padding: 10px 12px; border-radius: 14px; margin-bottom: 10px; }
.lm-compact:last-child { margin-bottom: 0; }
.lm-compact .lm-court-header { margin-bottom: 6px; }
.lm-compact .lm-court-label { font-size: 0.76rem; }
.lm-row.compact { gap: 8px; }
.lm-row.compact .lm-name { font-size: 0.92rem; }
.lm-vs { flex: none; font-size: 0.72rem; color: var(--text-dim); font-weight: 700; }

/* Подсветка топ-3 в рейтинге (золото/серебро/бронза) — общая для портретной
   вкладки "Рейтинг" и альбомной колонки рейтинга. */
.ld-rank { font-weight: 800; color: var(--text-dim); width: 1.6em; }
tr.ld-top1 { background: rgba(255, 179, 71, 0.14); }
tr.ld-top1 .ld-rank { color: #ffb347; }
tr.ld-top2 { background: rgba(255, 255, 255, 0.06); }
tr.ld-top2 .ld-rank { color: #d9dee5; }
tr.ld-top3 { background: rgba(255, 179, 71, 0.05); }
tr.ld-top3 .ld-rank { color: #c98a4b; }

/* Альбомная раскладка для трансляции (телефон боком или ТВ):
   рейтинг слева, текущие+прошедшие матчи по центру, предстоящие справа —
   всё на одном экране, без вкладок. По умолчанию скрыта, портретная — видна. */
.landscape-dashboard { display: none; }

@media (orientation: landscape) {
  body:has(.landscape-dashboard) { padding-bottom: 0; }
  .portrait-view { display: none; }

  .landscape-dashboard {
    display: grid;
    grid-template-columns: minmax(160px, 1.1fr) minmax(0, 1.8fr) minmax(0, 1.1fr);
    grid-template-rows: auto 1fr;
    gap: 8px;
    height: 100vh;
    box-sizing: border-box;
    padding: 14px;
  }

  .ld-topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
  }
  .ld-topbar .title { font-weight: 800; font-size: clamp(1.1rem, 1.8vw, 1.6rem); }

  .ld-col {
    overflow-y: auto;
    min-height: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 14px;
  }
  .ld-col h3 {
    margin: 0 0 10px;
    font-size: clamp(0.78rem, 1vw, 0.95rem);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    font-weight: 800;
  }
  .ld-col h4 {
    margin: 16px 0 8px;
    font-size: clamp(0.68rem, 0.9vw, 0.8rem);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    font-weight: 700;
  }

  /* Рейтинг — крупнее, шире (топ-3 подсвечены общим правилом выше) */
  .ld-col-rating table { font-size: clamp(0.85rem, 1.15vw, 1.05rem); width: 100%; }
  .ld-col-rating th, .ld-col-rating td { padding: 9px 6px; }
  .ld-col-rating tr:not(.ld-top1):not(.ld-top2):not(.ld-top3) td:first-child { padding-left: 6px; }

  /* Текущие матчи — одна колонка на всю ширину, крупнее чем в портретной вкладке. */
  .ld-current-grid { display: flex; flex-direction: column; gap: 14px; }
  .ld-current-grid .lm-court { margin-bottom: 0; }

  .lm-court-label { font-size: clamp(0.8rem, 1.1vw, 1.05rem); }
  .lm-team .lm-name { font-size: clamp(0.8rem, 1.8vw, 1.9rem); }
  .lm-score { font-size: clamp(1rem, 2.8vw, 3.3rem); }

  /* Предстоящие — тот же язык компактнее. */
  .lm-compact .lm-court-label { font-size: clamp(0.7rem, 0.85vw, 0.82rem); }
  .lm-row.compact .lm-name { font-size: clamp(0.7rem, 1.05vw, 1rem); }

  /* Прошедшие — блок на раунд, внутри по корту, самый мелкий масштаб. */
  .ld-past { display: flex; flex-direction: column; gap: 16px; }
  .pm-round-title {
    display: flex; align-items: center; gap: 8px;
    font-size: clamp(0.72rem, 0.9vw, 0.85rem); text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-dim); font-weight: 800; margin-bottom: 8px; padding-bottom: 5px; border-bottom: 1px solid var(--border);
  }
  .pm-court { background: var(--bg-card-2); border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; }
  .pm-court-title {
    position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 6px;
    font-size: 0.68rem; font-weight: 700; color: var(--text-dim); margin-bottom: 4px;
  }
  .pm-court-label { position: absolute; left: 50%; transform: translateX(-50%); }
  /* Бейджи в блоке прошедших игр — мельче, в той же пропорции, что и текст
     здесь мельче текста текущих матчей. */
  .pm-round-title .badge, .pm-court-title .badge { font-size: 0.62rem; padding: 1px 6px; }
  .pm-row { display: flex; align-items: center; gap: 10px; }
  .pm-team { flex: 1; min-width: 0; font-size: 0.82rem; font-weight: 700; line-height: 1.35; }
  .pm-team.right { text-align: right; }
  .pm-team div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pm-team.team-a { color: var(--team-a); }
  .pm-team.team-b { color: var(--team-b); }
  .pm-score {
    position: relative; flex: none; font-size: 1.05rem; font-weight: 900; color: var(--text);
    min-width: 56px; text-align: center;
  }
}
