* { box-sizing: border-box; }

:root {
    /* Тёмная тема, как на скриншоте */
    --bg:        #111122;
    --bg-2:      #333B44;
    --surface:   #333B44;
    --surface-2: #666B77;
    --border:    #1a1f25;        /* почти чёрный — даёт чёткое разделение плашек */
    --text:      #e8eaee;
    --muted:     #8d97a4;
    --primary:   #4ea5ff;
    --primary-hover: #338bea;

    /* Цвета ячеек ставок */
    --cell-loss:    #f3a8a8;     /* красный — 0 баллов */
    --cell-win1:    #f5e189;     /* жёлтый — исход (1) */
    --cell-win2:    #f1b876;     /* оранжевый — разница (2) */
    --cell-win3:    #9fdb98;     /* зелёный — точный (3) */
    --cell-win4:    #a3d4ee;     /* голубой — точный+проход (4) */
    --cell-pending: #d6d8de;     /* светло-серый — нет результата */
    --cell-hit:     #9fdb98;

    --header-h: 48px;
    --radius: 8px;
    --cell-size: 44px;       /* размер квадрата ячейки ставки (десктоп) */
    --label-w: 260px;        /* ширина левой колонки таблицы (десктоп) */
    --radius-sm: 6px;
    --shadow: 0 1px 0 rgba(0,0,0,.2);
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

/* ========= AUTH ========= */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); }
.auth-shell { width: 100%; max-width: 380px; }
.auth-title { text-align: center; margin: 0 0 24px; font-size: 22px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 24px;
}
.auth-card h2 { margin: 0 0 16px; font-size: 20px; color: var(--text); }
.auth-error {
    background: #4a2222;
    border: 1px solid #803838;
    color: #fbd5d5;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 13px;
}
.auth-field { display: block; margin-bottom: 14px; }
.auth-field > span { display: block; font-weight: 500; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.auth-field > input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: var(--bg-2);
    color: var(--text);
}
.auth-field > input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(78,165,255,.18);
}
.auth-submit {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
}
.auth-submit:hover { background: var(--primary-hover); }
.auth-hint { margin: 14px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

/* ========= HEADER ========= */
.site-header {
    position: sticky; top: 0; z-index: 50;
    height: var(--header-h);
    background: #222A33;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 14px; gap: 12px;
}

/* === Кастомный селект турниров === */
.tournament-switch {
    position: relative;
    min-width: 0;
    max-width: 70%;
}
.tournament-switch-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    max-width: 100%;
    transition: background .1s linear, border-color .1s linear;
}
.tournament-switch-toggle:hover { background: #424952; }
.tournament-switch.is-open .tournament-switch-toggle { background: #424952; border-color: #8389A0; }
.tournament-switch-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}
.tournament-switch-caret {
    width: 10px;
    height: 6px;
    flex: 0 0 auto;
    color: var(--muted);
    transition: transform .15s ease;
}
.tournament-switch.is-open .tournament-switch-caret { transform: rotate(180deg); }

.tournament-switch-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    margin: 0; padding: 4px;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,.45);
    min-width: 100%;
    max-height: 320px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}
.tournament-switch.is-open .tournament-switch-menu { display: block; }
.tournament-switch-option {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.tournament-switch-option:hover { background: var(--bg-2); }
.tournament-switch-option.is-active {
    background: #8389A0;
    color: #ffffff;
    font-weight: 700;
}

/* === Пользовательское меню === */
.site-user-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.site-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    transition: background .1s linear, border-color .1s linear;
}
.site-user:hover { background: #424952; }
.site-user-wrap.is-open .site-user { background: #424952; border-color: #8389A0; }
.site-user img, .site-user .stub {
    width: 28px; height: 28px; border-radius: 50%;
    object-fit: cover;
    background: #1b2128;
    color: var(--muted);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 12px;
}
.site-user-name { font-weight: 600; font-size: 13px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-user-caret {
    width: 10px; height: 6px;
    flex: 0 0 auto;
    color: var(--muted);
    transition: transform .15s ease;
    margin-left: 2px;
}
.site-user-wrap.is-open .site-user-caret { transform: rotate(180deg); }

.site-user-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    margin: 0; padding: 4px;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,.45);
    min-width: 160px;
    z-index: 100;
    display: none;
}
.site-user-wrap.is-open .site-user-menu { display: block; }
.site-user-menu-item {
    display: block;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}
.site-user-menu-item:hover { background: var(--bg-2); }

/* ========= 3 ОБЛАСТИ ========= */
.areas-wrap { position: relative; overflow: hidden; width: 100%; }
.areas-scroll {
    display: flex;
    flex-wrap: nowrap;
    width: calc(var(--n, 1) * 100%);
    transition: transform .25s ease;
    will-change: transform;
}
/* Скрытие скроллбара уже не нужно, но оставим на случай переноса */
.areas-scroll::-webkit-scrollbar { display: none; }

.area {
    flex: 0 0 calc(100% / var(--n, 1));
    width: calc(100% / var(--n, 1));
    padding: 8px 4px 64px;
    min-height: calc(100vh - var(--header-h) - 40px);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
}
.area > * { width: 100%; max-width: 1100px; }
.area > .calc-wrap, .area > .lb-table-wrap { align-self: stretch; max-width: 100%; }
.area-title { margin: 0 0 8px; font-size: 14px; font-weight: 600; }

.site-tabs {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 60;
    background: #222A33;
    border-top: 1px solid var(--border);
    height: 56px;
    padding: 0;
}
.site-tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--muted);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    box-shadow: inset 0 0 0 0 transparent;
    transition: color .12s linear, background .12s linear, box-shadow .12s linear;
}
.site-tab:hover { color: var(--text); background: rgba(255,255,255,.04); }
.site-tab.active {
    color: #ffffff;
    box-shadow: inset 0 3px 0 #8389A0;
}
.site-tab-icon {
    width: 22px; height: 22px;
    display: block;
}
.site-tab-label {
    line-height: 1;
}

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty h2 { margin: 0 0 8px; color: var(--text); }

/* ========= ТАБЛИЦА РАСЧЁТОВ ========= */
.calc-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    background: transparent;
    width: 100%;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}
.calc-table {
    border-collapse: separate;
    border-spacing: 2px;
    font-size: 11px;
    margin: 0 auto;
    width: max-content;
    max-width: none;
}
.calc-table th, .calc-table td {
    padding: 0 3px;
    height: var(--cell-size);
    min-height: var(--cell-size);
    text-align: center;
    white-space: nowrap;
    background: var(--surface);
    border-radius: var(--radius-sm);
    color: var(--text);
}
/* Строка матча может быть выше — там команды столбиком */
.calc-table tr.match-row td { height: auto; }
.calc-table tr.match-row td.col-label { min-height: 38px; }

/* Левый столбец */
.calc-table .col-label {
    text-align: left;
    /* Базовая желаемая ширина — var(--label-w).
       Если игроков мало, расширяем col-label так, чтобы вся таблица была
       минимум 540px шириной: расчёт берёт 540px минус площадь, занимаемая
       ячейками игроков (cell-size + 2px border-spacing на каждую). */
    width: max(
        var(--label-w, 260px),
        calc(540px - var(--players-count, 0) * (var(--cell-size) + 2px))
    );
    min-width: var(--label-w, 260px);
    max-width: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    padding: 0 6px;
    box-sizing: border-box;
}
.calc-table tr.match-row td.col-label {
    white-space: normal;
    overflow: visible;
    padding: 3px 6px;
}
.calc-table thead .col-label { background: transparent; }

.calc-table .col-result {
    font-weight: 700;
    color: var(--text);
    padding-left: 6px;
}

/* Шапка */
.calc-table thead th {
    background: transparent;
    font-weight: 700;
    color: var(--text);
    font-size: 12px;
    letter-spacing: .02em;
    padding: 6px 8px;
}
.calc-table thead th.player {
    background: var(--bg-2);
    border-radius: var(--radius-sm);
    width: var(--cell-size);
    min-width: var(--cell-size);
    max-width: var(--cell-size);
    color: var(--text);
    word-break: break-word;
    white-space: normal;
    font-size: 10px;
    line-height: 1.1;
    padding: 3px 2px;
    overflow: hidden;
}

/* Строки: итоги и разделы */
.calc-table tr.totals td {
    background: var(--surface);
    font-weight: 700;
    font-size: 12px;
}
.calc-table tr.totals .col-label {
    background: var(--surface);
    font-size: 11px;
}

.calc-table tr.section-header td {
    background: var(--surface-2);
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    font-size: 11px;
}
.calc-table tr.section-header td.col-label::after {
    content: '▾';
    margin-left: 6px;
    display: inline-block;
    transition: transform .15s;
    color: var(--muted);
}
.calc-table tr.section-header.collapsed td.col-label::after { transform: rotate(-90deg); }
.calc-table tr.section-header td.points-cell {
    background: var(--surface-2);
    font-weight: 700;
    font-size: 12px;
}

/* Особый стиль строк бонусов: левая колонка как пилюля с метой */
.calc-table tr.bonus-row .col-label {
    background: var(--surface);
}

/* Левый блок матча: статус | команды | счёт */
.match-cell-wrap {
    /* Контейнер запросов: меряет ширину этой обёртки в td.col-label.
       От него зависит, какой режим показа использует .match-cell внутри. */
    container-type: inline-size;
    container-name: matchcell;
    width: 100%;
}
.match-cell {
    display: grid;
    grid-template-rows: 1fr 1fr;
    column-gap: 8px;
    row-gap: 0;
    align-items: center;
    cursor: default;
    line-height: 1.1;
    width: 100%;
    box-sizing: border-box;
}
.match-cell .status-col {
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: center;
    text-align: center;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.15;
    user-select: none;
}
.match-cell .status-col .ms-finished {
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    font-size: 10px;
}
.match-cell .status-col .ms-cancelled { color: var(--muted); font-weight: 600; font-size: 10px; text-transform: uppercase; }
.match-cell .status-col .ms-live {
    display: inline-block;
    color: #ff5757;
    font-weight: 800;
    font-size: 11px;
    letter-spacing: .03em;
    animation: live-pulse 1.6s ease-in-out infinite;
}
.match-cell .status-col .ms-time {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.2;
}
.match-cell .status-col .ms-time-d { font-size: 10px; color: var(--muted); }
.match-cell .status-col .ms-time-t { font-size: 10px; color: var(--muted); }

.match-cell.no-status {
    grid-template-columns: minmax(0, 1fr) auto;
}
.match-cell.no-status .row { grid-column: 1; }
.match-cell.no-status .score { grid-column: 2; }

.match-cell .row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
    height: 20px;
}
.match-cell .row.row-home { grid-row: 1; }
.match-cell .row.row-away { grid-row: 2; }
.match-cell .flag { font-size: 14px; line-height: 1; flex: 0 0 auto; }
.match-cell .team {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 10.5px;
    line-height: 1.1;
}
.match-cell .team.winner { font-weight: 800; }
.match-cell .score {
    grid-column: 3;
    grid-row: 1 / span 2;
    font-weight: 800;
    font-size: 13px;
    color: var(--text);
    padding: 2px 8px;
    background: #1b2128;
    border-radius: var(--radius-sm);
    align-self: center;
    white-space: nowrap;
    line-height: 1.1;
    min-width: 36px;
    text-align: center;
}
.match-cell .score.score-empty {
    background: transparent;
    visibility: hidden;
    min-width: 28px;
}
.match-cell .score .winner-digit { color: var(--text); font-weight: 900; }
.match-cell .score .pen-suffix { color: var(--muted); font-size: 9px; }
.match-cell .score .pass-mark {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
    font-weight: 900;
}
/* Тултип со счётом по периодам — через CSS, мгновенный, работает и на тапе */
.match-cell .score.has-detail {
    position: relative;
    cursor: help;
}
.match-cell .score.has-detail::after {
    content: attr(data-detail);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1a1d23;
    color: #f4f6fa;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,.45);
    transition: opacity .08s linear;
}
.match-cell .score.has-detail::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 1px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1a1d23;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    z-index: 100;
    transition: opacity .08s linear;
}
.match-cell .score.has-detail:hover::after,
.match-cell .score.has-detail:hover::before,
.match-cell .score.has-detail:focus::after,
.match-cell .score.has-detail:focus::before {
    opacity: 1;
    visibility: visible;
}
.match-cell .live-score {
    color: #ff5757;
    font-weight: 900;
    animation: live-pulse 1.6s ease-in-out infinite;
}

/* Левая колонка простого/призового бонуса */
.bonus-label {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px 6px;
    font-size: 11px;
    line-height: 1.15;
}
.bonus-label .bonus-title {
    color: var(--muted);
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .03em;
    flex: 0 0 auto;
    max-width: 100%;
}
.bonus-label .bonus-flag { font-size: 14px; line-height: 1; flex: 0 0 auto; }
.bonus-label .bonus-team {
    font-weight: 700;
    color: var(--text);
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
}
.bonus-label .bonus-empty { color: var(--muted); font-style: italic; font-weight: 500; }

/* Призовые места: флаг+страна прижаты к правому краю */
.bonus-label--placement { flex-wrap: wrap; }
.bonus-label--placement .bonus-result {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: 0 1 auto;
    min-width: 0;
    word-break: break-word;
}
.bonus-label--placement .bonus-result .bonus-team { word-break: break-word; }

/* Ячейки ставок */
/* Ячейка ставки: td — прозрачный контейнер, квадрат рисует .bc-in */
.bet-cell {
    width: var(--cell-size);
    min-width: var(--cell-size);
    max-width: var(--cell-size);
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none;
    vertical-align: middle;
}
.bet-cell .bc-in {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: var(--cell-size);
    height: var(--cell-size);
    margin: 0 auto;
    box-sizing: border-box;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 13px;
    line-height: 1.05;
    color: #1a1d23;
    background: var(--surface);
    white-space: normal;
    word-break: break-word;
    overflow: hidden;
    padding: 2px;
}
/* Бонусные ячейки с текстом могут подрастать по высоте */
.bet-cell.bonus-cell .bc-in {
    /* Та же высота, что у обычных ячеек ставок — длинный текст переносится внутри */
    height: var(--cell-size);
}
/* Цвета — теперь на внутреннем блоке */
.bet-cell.none .bc-in    { background: var(--cell-pending); opacity: .6; }
.bet-cell.pending .bc-in { background: var(--cell-pending); }
.bet-cell.loss .bc-in    { background: var(--cell-loss); }
.bet-cell.win1 .bc-in    { background: var(--cell-win1); }
.bet-cell.win2 .bc-in    { background: var(--cell-win2); }
.bet-cell.win3 .bc-in    { background: var(--cell-win3); }
.bet-cell.win4 .bc-in    { background: var(--cell-win4); }
.bet-cell.hit .bc-in     { background: var(--cell-hit); }
.bet-cell.exact .bc-in   { background: var(--cell-win3); }
.bet-cell.partial .bc-in { background: var(--cell-win1); }
/* Пустая ячейка (нет ставки) — нейтральный фон */
.bet-cell:not(.none):not(.pending):not(.loss):not(.win1):not(.win2):not(.win3):not(.win4):not(.hit):not(.exact):not(.partial) .bc-in {
    background: var(--surface);
    color: var(--text);
}

.bet-cell .pass-mark {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
    font-weight: 900;
}

@keyframes live-pulse { 0%,100%{opacity:1} 50%{opacity:.55} }

tr.is-hidden { display: none; }

/* ========= ОБЛАСТЬ ВВОДА СТАВОК ========= */
.flash { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 13px; }
.flash-ok    { background: #1f3d2d; border: 1px solid #2d6b4a; color: #b8f3cf; }
.flash-error { background: #4a2222; border: 1px solid #803838; color: #fbd5d5; }

.bets-meta {
    display: flex; flex-wrap: wrap; gap: 6px 14px;
    align-items: baseline;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}
.bets-meta strong { font-size: 15px; }
.bets-deadline { color: var(--muted); }

/* Плашка сообщений в форме ставок — шириной с форму */
.bets-msg {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-weight: 600;
    margin: 0 auto 8px;
    max-width: 540px;
    text-align: center;
    font-size: 13px;
    box-sizing: border-box;
}
.bets-msg-ok  { background: #1f3d2d; border: 1px solid #2d6b4a; color: #b8f3cf; }
.bets-msg-err { background: #4a2222; border: 1px solid #803838; color: #fbd5d5; }

/* Совместимость со старым именем */
.bets-confirmed-banner {
    padding: 12px 14px;
    background: #1f3d2d;
    border: 1px solid #2d6b4a;
    color: #b8f3cf;
    border-radius: var(--radius);
    font-weight: 600;
    margin: 0 auto 8px;
    max-width: 540px;
    text-align: center;
}

/* Когда форма уже подтверждена — скрываем actions и подсказку */
.bets-form.is-confirmed .bets-actions,
.bets-form.is-confirmed .bets-hint { display: none; }
.bets-form.is-confirmed input,
.bets-form.is-confirmed select,
.bets-form.is-confirmed button { opacity: .7; }

.bets-form { display: flex; flex-direction: column; gap: 4px; max-width: 540px; margin: 0 auto; }
.bets-section-title {
    margin: 8px 0 4px;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

/* Плашка-строка для бонусов и матчей в форме ставок */
.bet-line {
    display: grid;
    grid-template-columns: 1fr 24px 1fr;
    align-items: stretch;
    gap: 6px;
    background: transparent;
}
.bet-line > .side {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-height: 46px;
}
.bet-line > .side.left  { justify-content: flex-start; }
/* В solo-плашке: название слева не сжимается, инпут занимает всё остальное */
.bet-line > .side.right { justify-content: flex-start; }
.bet-line > .side .flag { font-size: 18px; line-height: 1; flex: 0 0 auto; }
.bet-line > .side .name {
    color: var(--muted);
    font-weight: 700;
    flex: 0 0 auto;
    text-transform: uppercase;
    letter-spacing: .03em;
    font-size: 12px;
}
.bet-line > .side input[type="text"],
.bet-line > .side input[type="number"] {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    background: transparent;
    color: var(--text);
    border: none;
    outline: none;
    font: inherit;
    font-weight: 600;
    text-align: right;
}
.bet-line > .side input[type="text"]::placeholder,
.bet-line > .side input[type="number"]::placeholder { color: var(--muted); opacity: .65; }
.bet-line > .side input:disabled { color: var(--muted); }

/* Обёртка флаг+инпут — прижата к правому краю.
   Внутри инпут шириной по своему содержимому (через JS size attr),
   так что флаг прилегает прямо к названию страны. */
.bet-line > .side .bonus-input-wrap {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
}
.bet-line > .side .bonus-input-wrap input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 40px;
    padding-left: 0;
    padding-right: 0;
    text-align: right;
}
/* Флажок перед инпутом призового места */
.bet-line > .side .bonus-input-flag {
    display: inline-block;
    width: 22px;
    height: 16px;
    flex: 0 0 auto;
    border-radius: 2px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
.bet-line > .side .bonus-input-flag.is-empty {
    background: var(--bg-2);
    border: 1px dashed var(--border);
    opacity: .5;
}
.bet-line > .colon {
    display: flex; align-items: center; justify-content: center;
    color: var(--text); font-weight: 700; font-size: 16px;
}

/* Простая «однотумбочная» плашка — для бомбардира, золота и т.п. */
.bet-line.solo {
    grid-template-columns: 1fr;
}
.bet-line.solo > .side {
    justify-content: space-between;
}

/* Плашка матча: команда — [счёт : счёт] — команда */
.bet-line.match {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 72px minmax(0, 1fr);
    gap: 3px;
    align-items: stretch;
}
.bet-line.match .mb-cell {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    height: 44px;
    display: flex;
    align-items: center;
    overflow: hidden;
}
.bet-line.match .mb-team {
    gap: 5px;
    padding: 2px 6px;
    min-width: 0;
    position: relative;       /* для полоски-индикатора */
    cursor: default;
}
.bet-line.match[data-playoff="1"] .mb-team { cursor: pointer; }
.bet-line.match[data-locked="1"] .mb-team { cursor: default; }
.bet-line.match .mb-home { justify-content: flex-start; }
.bet-line.match .mb-away { justify-content: flex-end; }

/* Окраска всего блока команды по результату.
   Цвет задаётся классами is-win / is-loss / is-draw. */
.bet-line.match .mb-team {
    transition: background-color .12s ease;
}
.bet-line.match .mb-team.is-win  { background: var(--cell-win3); border-color: var(--cell-win3); }
.bet-line.match .mb-team.is-loss { background: var(--cell-loss); border-color: var(--cell-loss); }
.bet-line.match .mb-team.is-draw { background: var(--cell-win1); border-color: var(--cell-win1); }
/* На окрашенном блоке текст тёмный */
.bet-line.match .mb-team.is-win  .mb-name,
.bet-line.match .mb-team.is-loss .mb-name,
.bet-line.match .mb-team.is-draw .mb-name { color: #1a1d23; }

.bet-line.match .mb-name {
    color: var(--text);
    font-weight: 600;
    font-size: 13px;
    line-height: 1.1;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: normal;
    word-break: break-word;
    /* Ограничиваем 2 строки, без увеличения высоты */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.bet-line.match .mb-away .mb-name { text-align: right; }

/* Один блок со счётом: [input] : [input] */
.bet-line.match .mb-score-block {
    padding: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    overflow: hidden;
}
.bet-line.match .mb-score-block input {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    color: var(--text);
    border: none;
    outline: none;
    font: inherit;
    font-weight: 700;
    text-align: center;
    font-size: 15px;
    padding: 0;
    -moz-appearance: textfield;
    appearance: textfield;
}
.bet-line.match .mb-score-block input::-webkit-outer-spin-button,
.bet-line.match .mb-score-block input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.bet-line.match .mb-score-block input:disabled { color: var(--muted); }
.bet-line.match .mb-score-block .mb-colon {
    display: flex; align-items: center; justify-content: center;
    color: var(--text);
    font-weight: 700;
    font-size: 16px;
    padding: 0 2px;
    user-select: none;
}

.bet-line.match .pass-line {
    grid-column: 1 / -1;
    padding: 6px 10px;
    background: var(--bg-2);
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: 11px;
    display: flex; gap: 8px; align-items: center;
}
.bet-line.match .pass-line select {
    flex: 1; background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 4px 6px; font: inherit; font-size: 12px;
}

.bet-status-pill {
    font-size: 10px;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid var(--border);
    color: var(--muted);
    background: var(--bg-2);
    font-weight: 700;
    letter-spacing: 0.04em;
}

.bets-actions {
    display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap;
    align-items: center;
}
.bets-autosave {
    flex: 1 1 auto;
    color: var(--muted);
    font-size: 12px;
    min-width: 140px;
}
.bets-actions button {
    flex: 0 0 auto; min-width: 160px; padding: 12px 18px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 700; cursor: pointer; border: 1px solid var(--border);
    font-family: inherit;
}
.bets-actions button:disabled { opacity: .6; cursor: default; }
.btn-primary { background: #2d6b4a; color: #fff; border-color: #2d6b4a; }
.btn-primary:hover { background: #235638; border-color: #235638; }
.btn-secondary { background: var(--surface); color: var(--text); }
.btn-secondary:hover { background: var(--bg-2); }

.bets-hint { margin: 12px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ========= ТУРНИРНАЯ ТАБЛИЦА ========= */
.lb-table-wrap { overflow: visible; }
.lb-table {
    border-collapse: separate; border-spacing: 2px;
    margin: 0 auto;
    font-size: 12px;
    width: max-content;
    max-width: none;
}
.lb-table th, .lb-table td {
    padding: 0;
    vertical-align: middle;
    text-align: center;
    background: var(--surface);
    border-radius: var(--radius-sm);
    color: var(--text);
    /* Квадратные ячейки чисел и шапок */
    width: var(--cell-size);
    min-width: var(--cell-size);
    height: var(--cell-size);
    box-sizing: border-box;
    white-space: nowrap;
}
.lb-table th {
    background: #666B77;
    font-size: 9px;
    text-transform: none;
    color: #ffffff;
    font-weight: 700;
    letter-spacing: 0;
    /* Высокая шапка с переносом длинных названий */
    white-space: normal;
    word-break: break-word;
    line-height: 1.15;
    padding: 4px 3px;
    height: auto;
    vertical-align: middle;
}
.lb-table th.sort-th {
    cursor: pointer;
    user-select: none;
    position: relative;
}
.lb-table th.sort-th:hover { background: #7a8090; }
.lb-table th.sort-th.active {
    background: #8389A0 !important;
    color: #ffffff;
}
/* По умолчанию (десктоп) показываем полное название, короткое скрыто */
.lb-table th.sort-th .th-full  { display: inline; }
.lb-table th.sort-th .th-short { display: none; }
.lb-table td.place {
    font-weight: 700;
    /* Уже квадрат через общее правило */
}
.lb-table td.name {
    text-align: left;
    font-weight: 700;
    /* Базовая ширина для рейтинговой таблицы такая же логика, как в калькуляционной:
       при малом количестве тайбрейкеров колонка имени растягивается так,
       чтобы вся таблица была минимум 540px шириной. */
    width: max(
        86px,
        calc(540px - (var(--tb-count, 4) + 2) * (var(--cell-size) + 2px))
    );
    min-width: 86px;
    max-width: none;
    padding: 4px 8px;
    white-space: normal;
    word-break: break-word;
}
.lb-table th.name-th {
    text-align: left;
    width: max(
        86px,
        calc(540px - (var(--tb-count, 4) + 2) * (var(--cell-size) + 2px))
    );
    min-width: 86px;
    padding: 0 8px;
    background: transparent;
}
.lb-table th.place-th {
    background: transparent;
}
.lb-table .name-cell {
    display: flex; align-items: center; gap: 6px;
}
.lb-table .name-cell img.avatar,
.lb-table .name-cell .stub {
    width: 22px; height: 22px; border-radius: 50%;
    object-fit: cover; background: #1b2128;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--muted); font-weight: 700; font-size: 10px;
    flex: 0 0 auto;
}
.lb-table td.total {
    background: #ffffff;
    color: #1a1d23;
    font-weight: 800;
    font-size: 13px;
}
.lb-table th.total-th {
    background: #666B77;
    color: #ffffff;
}

/* Обёртка таблицы и панели сегментов рейтинга: ширина по таблице, центрирование */
.lb-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
}
.lb-block .lb-table-wrap {
    /* Таблица — по своей ширине, центрируется через align-items родителя */
    width: auto;
    max-width: 100%;
}
.lb-block .lb-table { margin: 0; }
/* Кнопка «График набора очков» под таблицей рейтинга и блок с canvas */
.lb-chart-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin: 8px 0 0;
    padding: 8px 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background .12s linear, border-color .12s linear;
    box-sizing: border-box;
}
.lb-chart-toggle:hover { background: #424952; }
.lb-chart-toggle.is-open { background: #424952; border-color: #8389A0; color: #ffffff; }
.lb-chart-toggle svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--muted); }
.lb-chart-toggle.is-open svg { color: #ffffff; }
.lb-chart-toggle-label { line-height: 1; }

/* Модальное окно графика — поверх всего, на весь экран */
.lb-chart-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}
.lb-chart-modal[hidden] { display: none; }
.lb-chart-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.65);
    backdrop-filter: blur(2px);
}
.lb-chart-modal-window {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px rgba(0,0,0,.6);
    display: flex;
    flex-direction: column;
    padding: 16px 16px 12px;
    box-sizing: border-box;
}
.lb-chart-modal-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    padding-right: 40px;
    line-height: 1.2;
}
.lb-chart-modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    transition: color .1s linear, background .1s linear;
    z-index: 2;
}
.lb-chart-modal-close:hover { color: var(--text); background: rgba(255,255,255,.08); }
.lb-chart-modal-close svg { width: 20px; height: 20px; }
.lb-chart-canvas-wrap {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
}
/* Блокировка прокрутки фоновой страницы при открытой модалке */
body.lb-chart-open { overflow: hidden; }

@media (max-width: 560px) {
    .lb-chart-modal { padding: 8px; }
    .lb-chart-modal-window { padding: 12px 10px 10px; }
    .lb-chart-modal-title { font-size: 13px; padding-right: 36px; }
}

/* Переключатели сегментов рейтинга — под таблицей. Ширина =100% lb-block,
   которая на маленьких экранах может оказаться больше ширины таблицы —
   тогда таблица центрируется относительно панели (align-items: center). */
.lb-segments {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px;
    margin: 8px 0 0;
    width: 100%;
    box-sizing: border-box;
}
.lb-seg {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .1s linear, border-color .1s linear;
    flex: 1 1 auto;
    text-align: center;
    box-sizing: border-box;
    min-width: 0;
}
.lb-seg:hover { background: #424952; }
.lb-seg.active {
    background: #8389A0;
    border-color: #8389A0;
    color: #ffffff;
}

/* ========= ФЛАГИ-КАРТИНКИ ========= */
.flag-img {
    display: inline-block;
    width: 17px;
    height: 12px;
    object-fit: cover;
    border-radius: 2px;
    background: transparent;
    flex: 0 0 auto;
    vertical-align: middle;
}
/* Клубный логотип — 1:1, без обрезки (логотипы обычно круглые/прямоугольные эмблемы) */
.flag-img--club {
    width: 14px;
    height: 14px;
    object-fit: contain;
    border-radius: 0;
}
.flag-img-empty {
    background: transparent;
    border: 1px dashed var(--bg-2);
    opacity: .25;
}

/* ========= КАСТОМНЫЙ АВТОКОМПЛИТ ========= */
.autocomplete-dropdown {
    position: absolute;
    z-index: 1000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
    box-shadow: 0 8px 24px rgba(0,0,0,.45);
    max-height: 240px;
    overflow-y: auto;
    width: max-content;
    max-width: 90vw;
    font-size: inherit;
}
.autocomplete-dropdown .ac-item {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text);
    font-size: inherit;
    text-align: right;
    line-height: 1.3;
}
.autocomplete-dropdown .ac-item:hover,
.autocomplete-dropdown .ac-item.active {
    background: var(--bg-2);
}
.autocomplete-dropdown .ac-item .ac-flag {
    width: 22px; height: 16px; border-radius: 2px;
    object-fit: cover; flex: 0 0 auto;
}
.autocomplete-dropdown .ac-item .ac-flag-empty {
    background: var(--bg-2);
    border: 1px dashed var(--border);
    opacity: .5;
}
.autocomplete-dropdown .ac-item .ac-text { flex: 0 0 auto; }
.autocomplete-dropdown .ac-item mark {
    background: rgba(78,165,255,.25);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

/* ========= МОДАЛКА «ИНФО О МАТЧЕ» ========= */
.match-info-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 1100;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.match-info-overlay .match-info-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 26px;
    min-width: 280px; max-width: 90vw;
    color: var(--text);
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.match-info-overlay .close {
    position: absolute; top: 8px; right: 12px;
    background: transparent; border: none; color: var(--muted);
    font-size: 22px; cursor: pointer; line-height: 1;
}
.match-info-overlay .close:hover { color: var(--text); }
.match-info-overlay h3 { margin: 0 0 8px; font-size: 16px; }
.match-info-overlay .time { font-size: 22px; font-weight: 700; }
.match-info-overlay .sub  { color: var(--muted); margin-top: 6px; font-size: 13px; }

/* ========= АДАПТИВНОСТЬ ========= */

/* Базовое поведение match-cell — КОМПАКТНЫЙ режим (узкая обёртка):
   коды стран, без даты, 2 колонки. @container правила ниже разворачивают. */
.match-cell {
    grid-template-columns: minmax(0,1fr) auto;
}
.match-cell .status-col { display: none; }
.match-cell .row { grid-column: 1; }
.match-cell .score { grid-column: 2; }
.match-cell .team { display: none; }
.match-cell .team-code {
    display: inline;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .02em;
}
.match-cell .team-code.winner { font-weight: 900; }
.match-cell.no-status {
    grid-template-columns: minmax(0,1fr) auto;
}
.match-cell.no-status .row { grid-column: 1; }
.match-cell.no-status .score { grid-column: 2; }

/* Средняя обёртка (≥160px) — полные имена команд, ещё без даты */
@container matchcell (min-width: 160px) {
    .match-cell .team { display: inline; }
    .match-cell .team-code { display: none; }
}

/* Широкая обёртка (≥220px) — полные имена + дата/время слева */
@container matchcell (min-width: 220px) {
    .match-cell {
        grid-template-columns: 56px minmax(0, 1fr) auto;
    }
    .match-cell .status-col { display: block; grid-column: 1; }
    .match-cell .row { grid-column: 2; }
    .match-cell .score { grid-column: 3; }
    .match-cell.no-status {
        grid-template-columns: minmax(0, 1fr) auto;
    }
    .match-cell.no-status .status-col { display: none; }
    .match-cell.no-status .row { grid-column: 1; }
    .match-cell.no-status .score { grid-column: 2; }
}

/* «Закрепляем» левую колонку при горизонтальной прокрутке */
.calc-wrap { overflow-x: auto; position: relative; }
.calc-table .col-label {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
    box-shadow: 4px 0 6px -4px rgba(0,0,0,.5);
}
.calc-table thead .col-label { background: var(--bg); }
.calc-table tr.totals .col-label { background: var(--surface); }
.calc-table tr.section-header .col-label { background: var(--surface-2); }

/* Узкие экраны (телефоны) */
@media (max-width: 560px) {
    body { font-size: 12px; }
    :root { --cell-size: 34px; --label-w: 110px; }

    /* Хедер: компактнее, имя скрываем — оставляем аватар + стрелочка */
    .site-header { padding: 0 10px; gap: 8px; }
    .site-user-name { display: none; }
    .tournament-switch-toggle { font-size: 12px; padding: 6px 10px; }

    /* На мобильном — компактнее размеры; режим показа рулится container queries */
    .match-cell { row-gap: 0; }
    .match-cell .row { height: 16px; }
    .match-cell .score { font-size: 11px; min-width: 28px; padding: 2px 5px; }
    .match-cell .team-code { font-size: 10px; }

    /* Левый блок матча — компактнее по высоте, чтобы не тянуть ячейки */
    .calc-table tr.match-row td.col-label { min-height: 0; padding: 1px 4px; }

    /* Лейбл первой колонки таблицы — компактные паддинги, минимум var(--label-w).
       На мобильном «540-минимум» отключаем — растягивание делает width:100% таблицы. */
    .calc-table .col-label {
        padding: 0 3px;
        width: auto;
        min-width: var(--label-w, 110px);
    }
    .calc-table {
        font-size: 10px;
        width: 100%;
        min-width: 100%;
    }
    .calc-table thead th.player { font-size: 8px; }
    .bet-cell .bc-in { font-size: 11px; }
    .bet-cell.bonus-cell .bc-in { font-size: 10px; }
    /* Ячейка тянется по высоте строки (для строк матчей, что выше ячейки) */
    .calc-table tr.match-row .bet-cell { height: 100%; }
    .calc-table tr.match-row .bet-cell .bc-in {
        height: 100%;
        min-height: var(--cell-size);
    }
    .calc-table .col-result { font-size: 10px; }

    /* Турнирная таблица */
    .lb-table {
        font-size: 10px;
        width: 100%;
    }
    .lb-block { width: 100%; }
    .lb-block .lb-table-wrap { width: 100%; }
    .lb-table th {
        font-size: 11px;
        white-space: nowrap;
        word-break: normal;
    }
    .lb-table th.sort-th .th-full  { display: none; }
    .lb-table th.sort-th .th-short { display: inline; font-weight: 700; }
    /* CSS-тултип для th: тап/hover показывает полное название */
    .lb-table th.sort-th {
        position: relative;
    }
    .lb-table th.sort-th::after {
        content: attr(data-full);
        position: absolute;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        margin-top: 4px;
        background: #1a1d23;
        color: #f4f6fa;
        padding: 4px 8px;
        border-radius: 6px;
        font-size: 10px;
        font-weight: 600;
        white-space: nowrap;
        pointer-events: none;
        opacity: 0;
        visibility: hidden;
        z-index: 100;
        text-transform: none;
        box-shadow: 0 4px 12px rgba(0,0,0,.45);
        transition: opacity .1s linear;
    }
    .lb-table th.sort-th:hover::after,
    .lb-table th.sort-th:focus::after {
        opacity: 1;
        visibility: visible;
    }
    .lb-table td.name { min-width: 70px; padding: 2px 6px; }
    .lb-table th.name-th { min-width: 70px; padding: 0 6px; }
    .lb-table .name-cell { gap: 4px; }
    .lb-table .name-cell img.avatar,
    .lb-table .name-cell .stub { width: 18px; height: 18px; font-size: 9px; }
    .lb-table td.total { font-size: 11px; }

    /* Форма ставок */
    .bet-line.match {
        grid-template-columns: minmax(0,1fr) 56px minmax(0,1fr);
        gap: 2px;
    }
    .bet-line.match .mb-cell { height: 36px; }
    /* Имена стран в форме ставок — крупнее на мобильном */
    .bet-line.match .mb-name { font-size: 12px; }
    .bet-line.match .mb-score-block input { font-size: 14px; }
    /* Флаги в форме ставок — крупнее, чем в таблице (в таблице остаются 17×12) */
    .bet-line.match .flag-img { width: 22px; height: 16px; }
    .bet-line.match .flag-img--club { width: 20px; height: 20px; }
    /* Бонусные плашки — той же высоты, что плашки матчей */
    .bet-line > .side { min-height: 36px; padding: 4px 8px; gap: 6px; font-size: 12px; }
    .bet-line > .side .flag { font-size: 16px; }
    .bet-line > .side .flag-img { width: 22px; height: 16px; }
    .bet-line > .side .flag-img--club { width: 20px; height: 20px; }
    .bet-line > .side input[type="text"],
    .bet-line > .side input[type="number"] { font-size: 12px; }
}

/* Большой экран — крупнее */
@media (min-width: 1100px) {
    body { font-size: 14px; }
    :root { --cell-size: 48px; --label-w: 300px; }
    .calc-table { font-size: 12px; }
    .lb-table { font-size: 12px; }
    .bet-cell .bc-in { font-size: 13px; }
}

/* ========================================================== */
/* СТРАНИЦА ПРОФИЛЯ (/account.php)                            */
/* ========================================================== */

/* Шапка-«мини» страницы профиля: кнопка назад + заголовок */
.site-header .site-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--text);
    padding: 6px 10px 6px 6px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    transition: background .1s linear;
}
.site-header .site-back:hover { background: rgba(255,255,255,.06); }
.site-header .site-back svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--muted); }
.site-header .site-header-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}
.site-header .site-header-spacer { width: 80px; }

.account-page {
    max-width: 540px;
    margin: 16px auto;
    padding: 0 14px 40px;
}

.account-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Аватар-блок */
.account-avatar-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    background: var(--surface);
    border-radius: var(--radius);
}
.account-avatar-current {
    width: 72px; height: 72px;
    border-radius: 50%;
    overflow: hidden;
    background: #1b2128;
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
}
.account-avatar-current img {
    width: 100%; height: 100%; object-fit: cover;
}
.account-avatar-current .stub {
    font-size: 28px; font-weight: 800;
    color: var(--muted);
}
.account-avatar-actions {
    display: flex; flex-direction: column; gap: 6px;
    min-width: 0;
}
.account-avatar-upload {
    display: inline-flex;
    align-items: center;
    padding: 7px 12px;
    background: var(--bg-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    width: max-content;
    transition: background .1s linear;
}
.account-avatar-upload:hover { background: #424952; }
.account-avatar-upload input[type="file"] {
    /* Скрываем системный input, оставляем кликабельным label */
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0;
    overflow: hidden;
}

/* Поля формы */
.account-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.account-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.account-hint {
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    text-transform: none;
    letter-spacing: 0;
}
.account-label .account-hint { margin-left: 4px; }

.account-form input[type="text"],
.account-form input[type="password"],
.account-form select.account-select {
    width: 100%;
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    box-sizing: border-box;
}
.account-form input:focus,
.account-form select:focus {
    outline: none;
    border-color: #8389A0;
    background: #424952;
}

/* Префикс «@» для Telegram */
.account-input-prefix {
    display: flex;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.account-input-prefix:focus-within { border-color: #8389A0; }
.account-input-prefix .account-prefix {
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    color: var(--muted);
    font-weight: 700;
    font-size: 14px;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
}
.account-input-prefix input {
    flex: 1 1 auto;
    border: none !important;
    background: transparent !important;
    padding: 9px 12px;
}

/* Поле пароля с кнопкой-«глаз» */
.account-password-wrap {
    position: relative;
}
.account-password-wrap input {
    padding-right: 42px;
}
.account-password-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px; height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    transition: color .1s linear, background .1s linear;
}
.account-password-toggle:hover { color: var(--text); background: rgba(255,255,255,.06); }
.account-password-toggle svg { width: 18px; height: 18px; }
.account-password-toggle .icon-eye-off { display: none; }
.account-password-toggle.is-visible .icon-eye { display: none; }
.account-password-toggle.is-visible .icon-eye-off { display: block; }

/* Кнопка «Сохранить» */
.account-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}
.btn-primary {
    padding: 10px 22px;
    background: #8389A0;
    color: #ffffff;
    border: 1px solid #8389A0;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background .1s linear;
}
.btn-primary:hover { background: #9aa0b6; border-color: #9aa0b6; }

/* Flash-сообщения */
.account-page .flash {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 14px;
}
.account-page .flash-ok    { background: rgba(159, 219, 152, .15); color: #b6f0c6; }
.account-page .flash-error { background: rgba(243, 168, 168, .15); color: #f3a8a8; }

@media (max-width: 560px) {
    .site-header .site-back span { display: none; }
    .site-header .site-header-spacer { width: 32px; }
    .account-page { padding: 0 10px 30px; }
    .account-avatar-current { width: 60px; height: 60px; }
    .account-avatar-current .stub { font-size: 24px; }
}

/* ========================================================== */
/* Кликабельные имена/аватарки игроков (выглядят как обычный текст) */
/* ========================================================== */
.player-link,
.name-cell-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}
.player-link:hover,
.name-cell-link:hover { color: inherit; }
.name-cell-link {
    display: block; /* td.name отдаст всю ширину под клик */
}

/* ========================================================== */
/* СТРАНИЦА СТАТИСТИКИ /stats.php                            */
/* ========================================================== */
.stats-page {
    max-width: 900px;
    margin: 16px auto;
    padding: 0 14px 40px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.stats-user-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: var(--surface);
    border-radius: var(--radius);
}
.stats-user-avatar {
    width: 56px; height: 56px;
    border-radius: 50%;
    overflow: hidden;
    background: #1b2128;
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
}
.stats-user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.stats-user-avatar .stub {
    font-size: 22px; font-weight: 800; color: var(--muted);
}
.stats-user-name { font-size: 17px; font-weight: 800; color: var(--text); }
.stats-user-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1 1 auto;
}

/* Список наград справа в шапке */
.stats-user-awards-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;
    text-align: right;
    flex: 0 0 auto;
    max-width: 50%;
}
.stats-award-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text);
    line-height: 1.2;
}
.stats-award-emoji {
    font-size: 16px;
    line-height: 1;
    flex: 0 0 auto;
}
.stats-award-tname {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 560px) {
    .stats-user-head { flex-wrap: wrap; }
    .stats-user-awards-list {
        max-width: 100%;
        width: 100%;
        align-items: flex-start;
        text-align: left;
        margin-top: 6px;
    }
}

.stats-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px 14px 14px;
}
.stats-section-title {
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text);
}
.stats-section-hint {
    margin: 0 0 10px;
    font-size: 11px;
    color: var(--muted);
}
.stats-section-formula { opacity: .75; }

.stats-empty {
    padding: 12px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
    background: var(--bg-2);
    border-radius: var(--radius-sm);
}

/* === 1) Общая таблица === */
.stats-overall-wrap { overflow-x: auto; }
.stats-overall {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 4px;
    font-size: 12px;
}
.stats-overall th {
    background: #666B77;
    color: #ffffff;
    font-size: 9px;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
    padding: 6px 6px;
    text-align: center;
    white-space: nowrap;
}
.stats-overall th.stats-name-th { text-align: left; padding-left: 10px; background: transparent; color: var(--muted); }
.stats-overall th.stats-total-th { background: #666B77; }
.stats-overall td {
    background: var(--bg-2);
    padding: 6px 6px;
    vertical-align: middle;
}
.stats-overall td.stats-name { text-align: left; padding-left: 10px; }
.stats-overall td.stats-num { text-align: center; white-space: nowrap; }
.stats-overall td.stats-total-cell { font-weight: 800; color: var(--text); }

.stats-overall tr.is-viewed td {
    background: #8389A0;
    color: #ffffff;
}
.stats-overall tr.is-viewed td.stats-total-cell { color: #ffffff; }
.stats-overall tr.is-viewed .stats-name-link { color: #ffffff; }

.stats-name-cell {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.stats-overall .stats-avatar {
    width: 24px; height: 24px;
    border-radius: 50%;
    object-fit: cover;
    background: #1b2128;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--muted); font-weight: 700; font-size: 10px;
    flex: 0 0 auto;
}
.stats-name-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}
.stats-name-link:hover { color: #ffffff; }

/* === 2-5) Команды: сетка с двумя топ-таблицами в ряд === */
.stats-team-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
@media (max-width: 640px) {
    .stats-team-grid { grid-template-columns: 1fr; }
}
.stats-team-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 3px;
    font-size: 12px;
}
.stats-team-table td {
    background: var(--bg-2);
    padding: 6px 8px;
    vertical-align: middle;
}
.stats-team-cell { width: 100%; }
.stats-team-name {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
    font-weight: 600;
}
.stats-team-name .flag-img { width: 17px; height: 12px; }
.stats-team-name .flag-img--club { width: 14px; height: 14px; }
.stats-team-table .stats-num { text-align: right; white-space: nowrap; font-weight: 700; }
.stats-team-table .stats-num-muted { color: var(--muted); font-weight: 500; font-size: 11px; padding-left: 6px; }

/* === 6) Родственная душа === */
.stats-soulmate-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.stats-soulmate {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-2);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    transition: background .1s linear;
}
.stats-soulmate:hover { background: #424952; }
.stats-soulmate-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: #1b2128;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--muted); font-weight: 800; font-size: 16px;
    flex: 0 0 auto;
}
.stats-soulmate-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stats-soulmate-name { font-size: 14px; font-weight: 700; }
.stats-soulmate-num { font-size: 11px; color: var(--muted); }

/* Колонка номера места в общей таблице статистики */
.stats-overall th.stats-place-th {
    background: transparent;
    color: var(--muted);
    width: 28px;
    text-align: center;
}
.stats-overall td.stats-place {
    width: 28px;
    text-align: center;
    font-weight: 800;
    color: var(--muted);
}
.stats-overall tr.is-viewed td.stats-place { color: #ffffff; }

/* Сортируемые заголовки */
.stats-overall th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background .1s linear;
}
.stats-overall th.sortable:hover { background: #7a8090; }
.stats-overall th.sortable.active { background: #8389A0; }

/* ========================================================== */
/* Чекбокс в форме профиля                                    */
/* ========================================================== */
.account-checkbox-field { gap: 4px; }
.account-checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 6px 0;
}
.account-checkbox-row input[type="checkbox"] {
    width: 18px; height: 18px;
    flex: 0 0 auto;
    accent-color: #8389A0;
    cursor: pointer;
}
.account-checkbox-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
}

/* ========================================================== */
/* Кнопка «Чат» в табах-футере (как обычная ссылка)           */
/* ========================================================== */
.site-tab.site-tab-link {
    text-decoration: none;
    color: inherit;
}

/* ========================================================== */
/* СТРАНИЦА ЧАТА /chat                                        */
/* ========================================================== */
body.chat-body {
    /* фиксированный viewport, чтобы форма ввода прижалась к низу */
    background: var(--bg);
    margin: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.chat-shell {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 0;
    min-height: 0;
    /* Нужно для абсолютного позиционирования .chat-scroll-down */
    position: relative;
}

/* Круглая кнопка «к новым сообщениям»: появляется в правом нижнем углу
   списка, когда пользователь промотал чат вверх. С счётчиком новых
   сообщений в углу, если они есть. */
.chat-scroll-down {
    position: absolute;
    /* Над формой ввода (~ 64px высоты), но прижата к правому краю */
    right: 14px;
    bottom: 80px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0,0,0,.35);
    z-index: 5;
    transition: transform .15s ease, opacity .15s ease, background .15s ease;
    opacity: .92;
}
.chat-scroll-down:hover { opacity: 1; background: var(--bg-2); transform: scale(1.04); }
.chat-scroll-down:active { transform: scale(0.95); }
.chat-scroll-down[hidden] { display: none; }
.chat-scroll-down svg { display: block; }
/* Счётчик новых — небольшой бейдж сверху-справа кнопки */
.chat-scroll-down-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    padding: 0 6px;
    background: #4ea5ff;
    color: #fff;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    box-sizing: border-box;
    pointer-events: none;
    border: 2px solid var(--bg);
}
.chat-scroll-down-badge[hidden] { display: none; }
/* Когда видим reply-preview — поднимем кнопку чуть выше, чтобы не наезжала. */
.chat-reply-preview:not([hidden]) ~ .chat-form ~ .chat-scroll-down,
.chat-shell:has(.chat-reply-preview:not([hidden])) .chat-scroll-down {
    bottom: 124px;
}
.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg);
}
.chat-loading,
.chat-empty {
    margin: auto;
    color: var(--muted);
    font-size: 13px;
    padding: 30px 0;
}
.chat-date-sep {
    align-self: center;
    background: rgba(255,255,255,.05);
    color: var(--muted);
    font-size: 11px;
    padding: 3px 12px;
    border-radius: 999px;
    margin: 12px 0 6px;
}

/* Один пузырь = ряд с аватаром (слева для чужих) и пузырём */
.chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 6px 0 0;
    max-width: 100%;
}
.chat-msg.chat-msg-grouped { margin-top: 1px; }
.chat-msg-mine { justify-content: flex-end; }
.chat-msg-avatar,
.chat-msg-avatar-spacer {
    width: 28px; height: 28px;
    flex: 0 0 auto;
    border-radius: 50%;
    overflow: hidden;
    background: #1b2128;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--muted);
    font-weight: 800;
    font-size: 12px;
}
.chat-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-msg-avatar-spacer { background: transparent; }

.chat-bubble {
    max-width: 75%;
    background: var(--surface);
    color: var(--text);
    padding: 6px 10px 4px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: 1.35;
    font-size: 14px;
    position: relative;
}
.chat-msg-mine .chat-bubble {
    background: #3a5a8a;
    color: #ffffff;
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
}
.chat-bubble-name {
    font-size: 12px;
    font-weight: 700;
    color: #b8c2d6;
    margin-bottom: 2px;
}
.chat-bubble-text {
    white-space: pre-wrap;
}
.chat-bubble-text a {
    color: inherit;
    text-decoration: underline;
}
.chat-bubble-time {
    text-align: right;
    font-size: 10px;
    color: var(--muted);
    margin-top: 2px;
    user-select: none;
}
.chat-msg-mine .chat-bubble-time { color: rgba(255,255,255,.7); }

/* Форма ввода */
.chat-form {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) 10px;
    background: #222A33;
    border-top: 1px solid var(--border);
}
.chat-form textarea {
    flex: 1 1 auto;
    resize: none;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 9px 14px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.35;
    min-height: 38px;
    max-height: 140px;
    outline: none;
    box-sizing: border-box;
}
.chat-form textarea:focus { border-color: #8389A0; }
.chat-send {
    flex: 0 0 auto;
    width: 40px; height: 40px;
    border: none;
    background: #3a5a8a;
    color: #ffffff;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .1s linear, transform .05s linear;
}
.chat-send:hover { background: #4a6ea0; }
.chat-send:active { transform: scale(.95); }
.chat-send:disabled { opacity: .5; cursor: default; }
.chat-send svg { width: 20px; height: 20px; }

@media (max-width: 560px) {
    .chat-bubble { max-width: 85%; font-size: 14px; }
    .chat-messages { padding: 8px 8px 6px; }
}

/* ========================================================== */
/* Чат как встроенная секция в .areas-scroll                  */
/* ========================================================== */
.area--chat {
    padding: 0 !important;
    /* ВАЖНО: align-self: flex-start отменяет stretch flex-родителя
       (align-items: stretch у .areas-scroll по умолчанию), и тогда
       .area--chat не тянется до высоты самой высокой соседней секции
       (calc/leaderboard могут быть длинными), а живёт по своему height. */
    align-self: flex-start !important;
    /* Дефолтная высота — на случай, если JS ещё не успел проставить
       свою. После загрузки sizeChatArea() прописывает точную высоту
       через style="height:...px" (inline без !important — этот CSS
       НЕ должен иметь !important, иначе не перебьётся, и при скрытии
       .site-tabs внизу останется пустота). */
    height: calc(100vh - var(--header-h) - 56px);
    height: calc(100dvh - var(--header-h) - 56px);
    min-height: 0 !important;
    overflow: hidden;
    background: var(--bg);
}
.area--chat .chat-shell {
    width: 100%;
    max-width: 720px;
    height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: transparent;
}
.area--chat .chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    background: transparent;
    scrollbar-width: thin;
    scrollbar-color: #555 transparent;
}
.area--chat .chat-messages::-webkit-scrollbar       { width: 6px; }
.area--chat .chat-messages::-webkit-scrollbar-track { background: transparent; }
.area--chat .chat-messages::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}
.area--chat .chat-messages::-webkit-scrollbar-thumb:hover { background: #777; }

.area--chat .chat-form {
    flex: 0 0 auto;
    background: transparent;
    border-top: none;
}

/* Стилизуем скроллбар textarea — тонкий тёмный, скрывается на одной строке */
.chat-form textarea {
    scrollbar-width: thin;
    scrollbar-color: #555 transparent;
}
.chat-form textarea::-webkit-scrollbar       { width: 6px; }
.chat-form textarea::-webkit-scrollbar-track { background: transparent; }
.chat-form textarea::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}
.chat-form textarea::-webkit-scrollbar-thumb:hover { background: #777; }

/* Badge непрочитанных в кнопке-табе чата (поверх иконки, без сдвига лейбла) */
.site-tab { position: relative; }
.chat-unread-badge {
    position: absolute;
    top: 4px;
    /* Смещаем чуть правее центра иконки, чтобы был хорошо виден */
    left: calc(50% + 6px);
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    padding: 0 4px;
    background: #e44a4a;
    color: #ffffff;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    text-align: center;
    box-sizing: border-box;
    pointer-events: none;
    z-index: 2;
}
.chat-unread-badge[hidden] { display: none; }
/* Если среди непрочитанных есть ответ пользователю — другой цвет и тонкая
   пульсация, чтобы он не пропустил обращение к нему. */
.chat-unread-badge.has-mention {
    background: #4ea5ff;
    animation: chat-mention-pulse 1.8s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(78,165,255,.6);
}
@keyframes chat-mention-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(78,165,255,.5); }
    50%      { box-shadow: 0 0 0 6px rgba(78,165,255,0); }
}

/* ========================================================== */
/* Вложения в сообщениях                                       */
/* ========================================================== */
.chat-bubble-attachment-image {
    max-width: 100%;
    max-height: 280px;
    border-radius: 10px;
    cursor: zoom-in;
    display: block;
    margin: 2px 0;
}
.chat-bubble-attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    margin: 2px 0;
    background: rgba(255,255,255,.07);
    color: inherit;
    border-radius: 8px;
    text-decoration: none;
    max-width: 260px;
}
.chat-msg-mine .chat-bubble-attachment-file { background: rgba(255,255,255,.18); }
.chat-bubble-attachment-file .file-icon {
    flex: 0 0 auto;
    width: 26px; height: 26px;
    color: currentColor;
    opacity: .85;
}
.chat-bubble-attachment-file .file-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: 12px;
    line-height: 1.25;
}
.chat-bubble-attachment-file .file-name {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-bubble-attachment-file .file-size {
    opacity: .7;
    font-size: 11px;
}

/* Кнопка-скрепка для прикрепления файла */
.chat-attach-btn {
    flex: 0 0 auto;
    width: 40px; height: 40px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color .1s linear;
    padding: 0;
}
.chat-attach-btn:hover { color: var(--text); }
.chat-attach-btn svg { width: 22px; height: 22px; }
.chat-attach-input { display: none; }

/* Превью прикреплённого файла перед отправкой */
.chat-attach-preview {
    flex: 0 0 auto;
    display: none;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,.08);
    padding: 6px 10px 6px 10px;
    border-radius: 18px;
    max-width: 200px;
    overflow: hidden;
    color: var(--text);
    font-size: 12px;
}
.chat-attach-preview.is-active { display: inline-flex; }
.chat-attach-preview img {
    width: 28px; height: 28px;
    object-fit: cover;
    border-radius: 4px;
    flex: 0 0 auto;
}
.chat-attach-preview .name {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-attach-preview .remove {
    flex: 0 0 auto;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
}
.chat-attach-preview .remove:hover { color: var(--text); }

/* Модалка для просмотра изображений */
.chat-image-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.92);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: zoom-out;
}
.chat-image-modal.is-active { display: flex; }
.chat-image-modal img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: default;
    border-radius: 6px;
    box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.chat-image-modal-close {
    position: absolute;
    top: 14px; right: 14px;
    background: rgba(255,255,255,.12);
    border: none;
    color: #fff;
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-image-modal-close:hover { background: rgba(255,255,255,.2); }

/* ========================================================== */
/* Чат: pinned bar, reply preview, quote, ctx-menu            */
/* ========================================================== */
.chat-pinned-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .1s linear;
}
.chat-pinned-bar:hover { background: #3c434d; }
.chat-pinned-bar[hidden] { display: none; }
.chat-pinned-icon {
    flex: 0 0 auto;
    width: 18px; height: 18px;
    color: #8389A0;
}
.chat-pinned-icon svg { width: 100%; height: 100%; }
.chat-pinned-text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}
.chat-pinned-title {
    font-size: 11px;
    font-weight: 700;
    color: #8389A0;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.chat-pinned-preview {
    font-size: 13px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-pinned-counter {
    flex: 0 0 auto;
    font-size: 11px;
    color: var(--muted);
    background: rgba(255,255,255,.08);
    padding: 2px 8px;
    border-radius: 999px;
}

/* Reply preview над формой */
.chat-reply-preview {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.chat-reply-preview[hidden] { display: none; }
.chat-reply-bar {
    flex: 0 0 auto;
    width: 3px;
    height: 32px;
    background: #8389A0;
    border-radius: 2px;
}
.chat-reply-meta {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}
.chat-reply-name {
    font-size: 12px;
    font-weight: 700;
    color: #8389A0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-reply-text {
    font-size: 13px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-reply-close {
    flex: 0 0 auto;
    width: 28px; height: 28px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    border-radius: 50%;
}
.chat-reply-close:hover {
    background: rgba(255,255,255,.08);
    color: var(--text);
}

/* Цитата внутри пузыря */
.chat-quote {
    background: rgba(255,255,255,.08);
    border-left: 3px solid #8389A0;
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
    cursor: pointer;
    max-width: 100%;
    overflow: hidden;
    transition: background .1s linear;
}
.chat-quote:hover { background: rgba(255,255,255,.14); }
.chat-msg-mine .chat-quote { border-left-color: #ffffff; background: rgba(255,255,255,.18); }
.chat-quote-name {
    font-size: 11px;
    font-weight: 700;
    color: #8389A0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-msg-mine .chat-quote-name { color: #ffffff; }
.chat-quote-text {
    font-size: 12px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Иконка пина в углу пузыря */
.chat-pin-icon {
    width: 11px;
    height: 11px;
    vertical-align: -1px;
    margin-right: 3px;
    opacity: .75;
}

/* Удалённое сообщение */
.chat-bubble-deleted {
    color: var(--muted);
    font-style: italic;
}
.chat-msg-deleted .chat-bubble {
    background: rgba(255,255,255,.04);
}
.chat-msg-mine.chat-msg-deleted .chat-bubble {
    background: rgba(255,255,255,.06);
    color: var(--muted);
}

/* Подсветка при scroll-to */
.chat-msg-flash .chat-bubble {
    box-shadow: 0 0 0 3px rgba(131,137,160,.6);
    transition: box-shadow .8s ease-out;
}

/* Контекстное меню */
.chat-ctx-menu {
    position: fixed;
    z-index: 250;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    display: none;
    min-width: 160px;
}
.chat-ctx-menu.is-active { display: block; }
.chat-ctx-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 9px 14px;
    text-align: left;
    font-size: 14px;
    border-radius: 6px;
    cursor: pointer;
}
.chat-ctx-item:hover { background: rgba(255,255,255,.08); }
.chat-ctx-item.is-danger { color: #e44a4a; }
.chat-ctx-item.is-danger:hover { background: rgba(228,74,74,.15); }
.chat-ctx-icon {
    flex: 0 0 16px;
    width: 16px; height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
    opacity: .8;
}
.chat-ctx-icon svg { width: 16px; height: 16px; display: block; }
.chat-ctx-label { flex: 1 1 auto; }

/* Подсветка строки текущего пользователя в таблице рейтинга */
.lb-table tr.is-me td {
    background: #5a626f;
}
.lb-table tr.is-me td.total {
    /* Total изначально светлая (белая) — для своей строки чуть приглушаем */
    background: #d6d6d6;
}

/* Когда активна вкладка «Чат»: блокируем прокрутку всей страницы.
   Скролл идёт только внутри .chat-messages. Без этого на мобильных при
   свайпе вверх обнажается пустое пространство снизу .area--chat или
   pinned-bar заезжает под хедер. */
html.chat-mode,
body.chat-mode {
    overflow: hidden !important;
    /* overscroll-behavior: none — отключает «оттягивание» страницы вниз/вверх,
       характерное для мобильных, которое обнажает пустое пространство, если
       контент короче viewport. */
    overscroll-behavior: none;
    /* Высота равна visible viewport (sizeChatArea ставит её через CSS-var
       --vvh из JS). Это особенно важно при открытой клавиатуре: visualViewport
       уменьшается, body должен ужаться вслед за ним. */
    height: var(--vvh, 100dvh) !important;
    max-height: var(--vvh, 100dvh) !important;
}
body.chat-mode {
    position: fixed !important;
    width: 100% !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* На узких экранах (мобильные) у LIVE-матча скрываем статус-колонку:
   места в колонке мало, а красный пульсирующий счёт сам по себе достаточный
   сигнал «идёт». На широких всё помещается — оставляем колонку как есть. */
@media (max-width: 719px) {
    .match-cell.is-live .status-col { display: none; }
    .match-cell.is-live { grid-template-columns: minmax(0, 1fr) auto; }
    .match-cell.is-live .row { grid-column: 1; }
    .match-cell.is-live .score { grid-column: 2; }
}

/* Клавиатура открыта (на мобильных при фокусе в textarea чата):
   скрываем нижний футер-табы, чтобы он не «прыгал» с клавиатурой
   и не закрывал содержимое чата. */
@media (max-width: 768px) {
    body.keyboard-open .site-tabs { display: none !important; }
    /* В режиме чата на мобильных скрываем хедер — освобождаем место для
       сообщений. При выходе из чата (переключение на другую вкладку
       турнира) класс снимается, хедер возвращается. */
    body.chat-mode .site-header { display: none !important; }
}

/* Свайп влево по сообщению чата → быстрый ответ.
   Иконка ↩ плавает справа от сообщения, растёт и подсвечивается
   при приближении к порогу активации. */
.chat-swipe-reply-icon {
    position: fixed;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 2px 10px rgba(0,0,0,.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--muted);
    pointer-events: none;
    z-index: 50;
    transform-origin: center center;
    transition: opacity .12s ease, transform .12s ease, color .12s ease, background .12s ease;
    user-select: none;
}
.chat-swipe-reply-icon.is-armed {
    color: #fff;
    background: var(--primary);
    box-shadow: 0 2px 14px rgba(78,165,255,.45);
}
/* На время свайпа отключаем эффект ховера на пузыре — он мешает анимации. */
.chat-msg { will-change: transform; }

/* Запрет выделения текста на интерактивных элементах чата и табах.
   Это не текстовый контент для копирования (для копирования сообщений
   есть пункт меню «Копировать»), а тапаемые кнопки/баббл — выделение
   только мешает (приветствует пунктирную рамку Android, синий блик iOS). */
.site-tabs,
.site-tabs *,
.chat-msg,
.chat-msg *,
.chat-ctx-menu,
.chat-ctx-menu *,
.chat-pinned-bar,
.chat-pinned-bar *,
.chat-scroll-down,
.chat-scroll-down * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* === Режим выделения сообщений === */
.chat-select-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    color: var(--text);
    min-height: 56px;
    box-sizing: border-box;
}
.chat-select-bar[hidden] { display: none; }
/* Когда режим выделения активен — прячем форму ввода. */
body.chat-selection-mode .chat-form { display: none !important; }
body.chat-selection-mode .chat-reply-preview { display: none !important; }
.chat-select-cancel {
    flex: 0 0 auto;
    width: 36px; height: 36px;
    border: none; background: transparent;
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .12s ease;
}
.chat-select-cancel:hover { background: rgba(255,255,255,.08); }
.chat-select-counter {
    flex: 1 1 auto;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}
.chat-select-actions {
    display: flex; gap: 4px;
}
.chat-select-act {
    width: 36px; height: 36px;
    border: none; background: transparent;
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .12s ease, color .12s ease;
}
.chat-select-act:hover { background: rgba(255,255,255,.08); }
.chat-select-act.is-danger { color: #e44a4a; }
.chat-select-act.is-danger:hover { background: rgba(228,74,74,.15); }
.chat-select-act[hidden] { display: none; }
/* Подсветка выделенных сообщений */
.chat-msg.is-selected .chat-msg-bubble,
.chat-msg.is-selected > * {
    /* Используем box-shadow вместо background, чтобы сохранить градиент. */
}
.chat-msg.is-selected {
    background: rgba(78,165,255,.18);
    border-radius: 8px;
    transition: background .12s ease;
}

/* @-mention autocomplete popup */
.chat-mention-popup {
    position: fixed;
    z-index: 50;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0,0,0,.4);
    overflow: hidden;
    max-height: 260px;
    overflow-y: auto;
    padding: 4px 0;
}
.chat-mention-popup[hidden] { display: none; }
.chat-mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text);
    font-size: 14px;
}
.chat-mention-item.is-active,
.chat-mention-item:hover {
    background: rgba(78,165,255,.18);
}
.chat-mention-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--bg-2, #2a2f3a);
    color: var(--muted);
    flex: 0 0 28px;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}
.chat-mention-avatar img {
    width: 100%; height: 100%;
    object-fit: cover; display: block;
}
.chat-mention-name {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Подсветка @-упоминаний в тексте сообщения */
.chat-mention {
    color: #4ea5ff;
    font-weight: 600;
    background: rgba(78,165,255,.10);
    padding: 0 3px;
    border-radius: 3px;
}
.chat-mention-all {
    color: #fbbf24;
    background: rgba(251,191,36,.12);
}
