/* =============================================================================
   Тирлист игроков. Стили глобальные: доска рендерит перетаскиваемые элементы
   через MudDropContainer (часть — вне DOM-скоупа компонента), а диалог редактора
   портируется MudBlazor вне дерева компонента.
   ============================================================================= */

/* ---------- Страница ---------- */
.tierlist-page-root {
    width: 100%;
}

.tierlist-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px 12px 48px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* В режиме доски ужимаем поля страницы — освобождаем максимум высоты под тиры и лоток. */
.tierlist-page:has(.tierlist-board-view) {
    padding: 8px 12px 20px;
    gap: 12px;
}

.tierlist-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 16px;
    color: #98a0c4;
}

.tierlist-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    padding: 24px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background:
        radial-gradient(120% 90% at 100% 0%, rgba(122, 92, 255, 0.16) 0%, transparent 55%),
        radial-gradient(110% 90% at 0% 0%, rgba(74, 140, 255, 0.14) 0%, transparent 50%),
        linear-gradient(165deg, rgba(43, 45, 62, 0.6) 0%, rgba(19, 20, 30, 0.7) 100%);
}

.tierlist-hero__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, #4a8cff 0%, #b45cff 100%);
    color: #fff;
}

.tierlist-hero__title {
    font-weight: 800;
}

.tierlist-hero__subtitle {
    color: #aab2d5;
    max-width: 620px;
}

.tierlist-hero__premium {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* ---------- Список карточек ---------- */
.tierlist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.tierlist-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(165deg, rgba(43, 45, 62, 0.75) 0%, rgba(23, 24, 34, 0.85) 100%);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.tierlist-card:hover {
    transform: translateY(-2px);
    border-color: rgba(138, 92, 255, 0.5);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.tierlist-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.tierlist-card__name {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tierlist-card__desc {
    color: #aab2d5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tierlist-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    color: #98a0c4;
    font-size: 0.85rem;
}

.tierlist-card__stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tierlist-card__stat .mud-icon-root {
    font-size: 1rem;
}

/* Кнопки-действия карточки (по образцу pairwise-poll-card__actions). */
.tierlist-card__actions {
    display: flex;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.tierlist-card__actions .mud-button-root {
    border-radius: 12px;
    text-transform: none;
    font-weight: 700;
}

/* Основная кнопка (Участвовать/Моя расстановка) занимает всё свободное место в строке. */
.tierlist-card__primary {
    flex: 1 1 auto;
    min-width: 0;
}

/* Контейнер иконки+текста внутри кнопки MudBlazor — разрешаем сжатие, чтобы длинный текст мог обрезаться многоточием. */
.tierlist-card__primary .mud-button-label {
    min-width: 0;
}

/* Текст кнопки: одна строка, при крайней нехватке места — аккуратное многоточие вместо вылезания за границу. */
.tierlist-card__btn-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Компактная квадратная кнопка «Рейтинг» (иконка) справа: не растягивается, ровняется по высоте с основной. */
.tierlist-card__rating-btn {
    flex: 0 0 auto;
    border-radius: 12px;
}

/* ---------- Просмотр доски ---------- */
.tierlist-board-view {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tierlist-board-view__header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tierlist-board-view__title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.tierlist-board-view__name {
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tierlist-board-view__desc {
    color: #aab2d5;
    font-size: 0.8rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tierlist-board-view__login-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(255, 193, 7, 0.08);
    border: 1px solid rgba(255, 193, 7, 0.2);
    color: #e6c37a;
}

/* ---------- Доска тиров ---------- */
.tierlist-board {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tierlist-board__tiers {
    display: flex;
    flex-direction: column;
    gap: 3px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.tierlist-row {
    display: flex;
    align-items: stretch;
    min-height: 78px;
    background: rgba(15, 16, 24, 0.6);
}

.tierlist-row__label {
    flex: 0 0 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    font-weight: 800;
    font-size: 1.25rem;
    color: #1a1a1a;
    text-align: center;
    word-break: break-word;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}

.tierlist-row__zone {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    padding: 8px;
    min-height: 78px;
}

/* Активный тир под курсором при перетаскивании — яркая подсветка зоны и всей строки, включая плашку. */
.tierlist-row--drop {
    background: rgba(138, 92, 255, 0.14);
}

.tierlist-row--drop .tierlist-row__zone {
    background: rgba(138, 92, 255, 0.2);
    outline: 2px solid rgba(168, 130, 255, 0.9);
    outline-offset: -3px;
}

.tierlist-row--drop .tierlist-row__label {
    filter: brightness(1.12);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
}

/* ---------- Лоток нераспределённых ---------- */
.tierlist-tray {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-radius: 12px;
    border: 1px dashed rgba(255, 255, 255, 0.14);
    background: rgba(20, 22, 32, 0.5);
}

.tierlist-tray__title {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #98a0c4;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tierlist-tray__zone {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    min-height: 92px;
    padding: 4px;
}

.tierlist-tray--drop .tierlist-tray__zone {
    background: rgba(138, 92, 255, 0.18);
    outline: 2px solid rgba(168, 130, 255, 0.85);
    outline-offset: -3px;
    border-radius: 8px;
}

/* ---------- Фишка игрока ---------- */
.tierlist-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    width: 64px;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    /* Тач-перетаскивание: не даём странице скроллиться при захвате чипа пальцем. */
    touch-action: none;
}

.tierlist-chip:active {
    cursor: grabbing;
}

/* Пока чип «в руке» — приглушаем оригинал на доске. */
.tierlist-chip--dragging {
    opacity: 0.35;
}

.tierlist-chip--dragging .tierlist-chip__avatar {
    border-color: rgba(168, 130, 255, 0.9);
}

/* «Призрак» — клон чипа, летящий за курсором/пальцем. */
.tierlist-chip--ghost {
    opacity: 0.9;
    transform-origin: top left;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
}

.tierlist-chip--ghost .tierlist-chip__avatar {
    border-color: rgba(168, 130, 255, 0.95);
}

/* Во время перетаскивания глушим выделение текста по всей странице. */
body.tierlist-dragging-active {
    user-select: none;
    -webkit-user-select: none;
    cursor: grabbing;
}

.tierlist-chip__avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #3a3d54 0%, #23233a 100%);
    border: 2px solid rgba(255, 255, 255, 0.14);
}

.tierlist-chip__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tierlist-chip__initial {
    font-weight: 700;
    color: #cfd4ec;
}

.tierlist-chip__name {
    max-width: 64px;
    font-size: 0.72rem;
    line-height: 1.1;
    text-align: center;
    color: #dfe3f5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tierlist-board__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

/* Индикатор автосохранения (вместо кнопки «Сохранить»). */
.tierlist-board__autosave {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: #98a0c4;
    transition: color 0.2s ease;
}

.tierlist-board__autosave .mud-icon-root,
.tierlist-board__autosave .mud-progress-circular {
    font-size: 18px !important;
    width: 16px;
    height: 16px;
}

.tierlist-board__autosave--saving {
    color: #9db8ff;
}

.tierlist-board__autosave--saved {
    color: #7fdca0;
}

.tierlist-board__autosave--error {
    color: #ff8b8b;
}

/* ---------- Диалог редактора ---------- */
.mud-dialog.tierlist-editor-dialog {
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(165deg, rgba(43, 45, 62, 0.98) 0%, rgba(19, 20, 30, 0.99) 100%);
}

.tierlist-editor-dialog .mud-dialog-title {
    padding: 18px 22px 6px;
    font-weight: 800;
    color: #f4f5fc;
}

.tierlist-editor-dialog__content {
    padding: 6px 22px 16px;
}

.tierlist-editor-dialog__root {
    padding: 4px 2px;
}

.tierlist-editor-dialog__section-title {
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    font-size: 12px;
    color: #9db8ff;
    margin-top: 6px;
}

.tierlist-editor-dialog__hint {
    font-size: 0.8rem;
    color: #838eab;
}

.tierlist-editor-dialog__field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tierlist-editor-dialog__field .tierlist-editor-dialog__hint {
    padding-left: 2px;
}

.tierlist-editor-dialog__tiers {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tierlist-editor-dialog__tier-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tierlist-editor-dialog__tier-color {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}

.tierlist-editor-dialog__tier-label {
    flex: 1;
}

.tierlist-editor-dialog__custom-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
    max-height: 40vh;
    overflow-y: auto;
    padding: 6px 2px;
}

.tierlist-editor-dialog__custom-chip {
    position: relative;
    width: 72px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tierlist-editor-dialog__custom-remove.mud-button-root {
    position: absolute;
    top: -6px;
    right: 2px;
    z-index: 2;
    padding: 2px;
    background: rgba(20, 20, 30, 0.85);
}

.tierlist-editor-dialog__custom-remove.mud-button-root:hover {
    background: rgba(60, 60, 80, 0.95);
}

.tierlist-editor-dialog__custom-remove .mud-icon-root {
    font-size: 0.95rem;
}

.tierlist-editor-dialog__actions {
    padding: 10px 20px 16px;
    gap: 10px;
    justify-content: space-between;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* Мобилки: диалог редактора на весь экран с минимумом отступов по бокам. */
@media (max-width: 600px) {
    .mud-dialog-container:has(> .tierlist-editor-dialog) {
        padding: 0;
    }

    .mud-dialog.tierlist-editor-dialog {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
    }

    .tierlist-editor-dialog__content {
        padding: 6px 12px 14px;
    }

    .tierlist-row__label {
        flex-basis: 56px;
        font-size: 1.05rem;
    }
}

/* ---------- Народный рейтинг ---------- */
.tierlist-board-view__recompute {
    display: flex;
    justify-content: flex-end;
}

/* Компактный список: [место+аватар+имя] · [карта голосов над полосой] · [консенсус+балл]. */
.tlr {
    --tlr-grid: minmax(150px, 230px) 1fr 104px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tlr__meta {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #98a0c4;
    font-size: 0.85rem;
    margin-bottom: 2px;
}

/* Шапка списка: подпись «Игрок», буквы тиров над колонкой карты, «Балл». */
.tlr__head {
    display: grid;
    grid-template-columns: var(--tlr-grid);
    gap: 18px;
    align-items: center;
    padding: 0 16px 6px;
    color: #7d8399;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.tlr__head-map {
    display: grid;
    gap: 5px;
}

.tlr__head-map span {
    text-align: center;
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 0;
    text-transform: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.tlr__head-end {
    text-align: right;
}

.tlr__row {
    display: grid;
    grid-template-columns: var(--tlr-grid);
    gap: 18px;
    align-items: center;
    padding: 10px 16px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(165deg, rgba(43, 45, 62, 0.55) 0%, rgba(23, 24, 34, 0.7) 100%);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tlr__row:hover {
    border-color: rgba(138, 92, 255, 0.4);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
}

.tlr__row--top {
    border-color: rgba(230, 195, 122, 0.4);
}

/* --- колонка 1: место + аватар + имя --- */
.tlr__id {
    display: grid;
    grid-template-columns: 20px 40px 1fr;
    gap: 10px;
    align-items: center;
    min-width: 0;
}

.tlr__rank {
    font-weight: 800;
    font-size: 0.95rem;
    color: #7d8399;
    text-align: center;
}

.tlr__row--top .tlr__rank {
    color: #e6c37a;
}

.tlr__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #3a3d54 0%, #23233a 100%);
    border: 2px solid rgba(255, 255, 255, 0.12);
}

.tlr__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tlr__initial {
    font-weight: 700;
    color: #cfd4ec;
    font-size: 0.9rem;
}

.tlr__who {
    min-width: 0;
}

.tlr__name {
    font-weight: 700;
    font-size: 0.9rem;
    color: #dfe3f5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tlr__sub {
    font-size: 0.68rem;
    color: #7d8399;
    margin-top: 1px;
}

/* --- колонка 2: тепловая карта над полосой --- */
.tlr__mid {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.tlr__map {
    display: grid;
    gap: 5px;
}

.tlr__cell {
    height: 26px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    color: #000000;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    transition: transform 0.12s ease;
}

.tlr__cell--mode {
    outline: 2px solid rgba(0, 0, 0, 0.85);
    outline-offset: -2px;
}

.tlr__cell:hover {
    transform: scale(1.1);
}

.tlr__bar {
    position: relative;
}

.tlr__track {
    height: 9px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.tlr__fill {
    height: 100%;
    border-radius: 6px;
}

.tlr__pool {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 2px;
    background: rgba(255, 255, 255, 0.4);
}

/* --- колонка 3: консенсус + балл --- */
.tlr__end {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.tlr__cbadge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #7d8399;
}

.tlr__cbadge b {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-weight: 800;
    font-size: 0.8rem;
    color: #1a1a1a;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}

.tlr__score {
    font-weight: 800;
    font-size: 1.5rem;
    line-height: 1;
    color: #f4f5fc;
}

.tlr__score small {
    font-weight: 400;
    font-size: 0.62rem;
    color: #7d8399;
}

/* --- нераспределённые --- */
.tlr__limit-note {
    display: inline-flex;
    align-items: center;
    align-self: center;
    gap: 6px;
    margin-top: 4px;
    color: #98a0c4;
    font-size: 0.85rem;
}

.tlr__limit-note .mud-icon-root {
    font-size: 16px !important;
}

.tlr__tray {
    margin-top: 6px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px dashed rgba(255, 255, 255, 0.14);
    background: rgba(20, 22, 32, 0.5);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.tlr__tray-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #98a0c4;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tlr__tray-name {
    color: #aab2d5;
    font-size: 0.82rem;
}

/* Кнопка перехода к своей расстановке под лотком. */
.tlr__footer {
    display: flex;
    justify-content: center;
    padding-top: 8px;
}

.tlr__footer .mud-button-root {
    border-radius: 12px;
    text-transform: none;
    font-weight: 700;
}

/* Узкий экран: колонки складываем в строки, шапку прячем. */
@media (max-width: 640px) {
    .tlr__head {
        display: none;
    }

    .tlr__row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .tlr__end {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}
