/* 25곡 티어 정렬 모드 — 탭 기반(held-and-place) 배치 UI.
   토큰/컴포넌트는 tokens.css·components.css에 의존. worldcup 전용 확장. */

.tier-mode {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 12px 14px 20px;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
}

.tier-head { text-align: center; }
.tier-title { margin: 0 0 4px; font-size: 1.1rem; }
.tier-hint {
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
    min-height: 2.4em;
}
.tier-hint b { color: var(--text-primary); }

/* ---- 작업 영역 ----
   25곡 모드는 예전 그대로 한 줄 흐름(display: contents)으로 두고,
   50곡(.tier-mode-wide)에서만 티어 영역 / 곡 영역을 독립 스크롤 패널로 쪼갠다. */
.tier-workspace,
.tier-lanes-pane { display: contents; }

/* ---- 티어 레인 ---- */
.tier-lanes { display: flex; flex-direction: column; gap: 8px; }

.tier-lane {
    display: flex;
    align-items: stretch;
    gap: 8px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 6px;
    background: var(--bg-secondary);
    transition: border-color .14s, background .14s;
}
.tier-lane.drop-ready {
    border-color: var(--accent-primary, #C96442);
    background: color-mix(in srgb, var(--accent-primary, #C96442) 8%, var(--bg-secondary));
}

.tier-label {
    flex: none;
    width: 44px;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-weight: 800;
    font-size: 1.15rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .1s, filter .1s;
}
.tier-lane.drop-ready .tier-label { transform: scale(1.05); filter: brightness(1.1); }
.tier-label:active { transform: scale(0.95); }
.tier-lane[data-tier="S"] .tier-label { background: #e0607a; }
.tier-lane[data-tier="A"] .tier-label { background: #ef9a4a; }
.tier-lane[data-tier="B"] .tier-label { background: #d7b56d; }
.tier-lane[data-tier="C"] .tier-label { background: #57b982; }
.tier-lane[data-tier="D"] .tier-label { background: #7c8cff; }
.tier-lane[data-tier="E"] .tier-label { background: #6f7aa8; }
.tier-lane[data-tier="F"] .tier-label { background: #8a8f9c; }

.tier-lane-slots {
    flex: 1;
    min-height: 56px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    gap: 5px;
    align-content: start;
}

/* ---- 미배치 풀 ---- */
.tier-pool-block {
    border: 1px dashed var(--border-light);
    border-radius: 12px;
    padding: 8px;
}
.tier-pool-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding: 0 2px;
}
.tier-pool-count {
    background: var(--bg-tertiary);
    border-radius: 999px;
    padding: 1px 9px;
    font-weight: 700;
    color: var(--text-primary);
}
.tier-pool {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

/* ============================================================
   50곡 라운드(FAST ELO 풀 토너먼트) — 티어 / 곡 2단 분리 레이아웃
   곡이 티어 아래로 길게 깔려 스크롤 왕복이 생기는 문제를 없앤다.
   데스크톱: 좌 티어 · 우 곡 목록, 각각 독립 스크롤.
   모바일  : 위 티어(스크롤) · 아래 곡 트레이(고정 높이) — 아래 미디어쿼리.
   ============================================================ */
.tier-mode-wide {
    max-width: 1180px;
    /* .match-area(flex column)를 꽉 채워야 내부 패널이 각자 스크롤할 수 있다 */
    flex: 1;
    min-height: 0;
}
.tier-mode-wide .tier-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 302px;
    gap: 12px;
    flex: 1;
    min-height: 0;
}
.tier-mode-wide .tier-lanes-pane {
    display: block;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
}
.tier-mode-wide .tier-pool-block {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden; /* 스크롤은 내부 .tier-pool 담당 — 헤더는 항상 보이게 */
}
.tier-mode-wide .tier-pool-head {
    flex: none;
    margin-bottom: 6px;
}
/* 카드 배치는 grid 대신 고정폭 flex 랩으로.
   패널에 확정 높이가 생기면 auto 행 높이와 카드의 aspect-ratio 사이에 순환이 생겨
   행 간격이 카드 높이의 절반으로 잡히고 카드가 서로 겹쳐 그려진다(2026-07 실측).
   폭을 고정하면 높이가 aspect-ratio로 결정되어 그 순환이 사라진다. */
.tier-mode-wide .tier-pool,
.tier-mode-wide .tier-lane-slots {
    display: flex;
    flex-wrap: wrap;
    align-content: start;
}
.tier-mode-wide .tier-pool > .tier-card,
.tier-mode-wide .tier-lane-slots > .tier-card {
    flex: 0 0 auto;
}
.tier-mode-wide .tier-pool {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 2px;
}
.tier-mode-wide .tier-pool > .tier-card { width: 66px; }
.tier-mode-wide .tier-lane-slots > .tier-card { width: 48px; }

/* 미배치가 빈 상태(현재 순위대로 미리 채워 시작한 라운드)에선 곡 영역을 접고
   티어가 화면 전체를 쓴다. 곡이 풀로 돌아올 일이 없어 빈 칸만 남기 때문. */
.tier-mode-wide.tier-pool-empty .tier-pool-block { display: none; }
.tier-mode-wide.tier-pool-empty .tier-workspace { grid-template-columns: minmax(0, 1fr); }

/* ---- 곡 카드 (풀·레인 공통) ---- */
.tier-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-tertiary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    transition: transform .1s, box-shadow .1s, outline-color .1s;
    outline: 2px solid transparent;
    outline-offset: -2px;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.tier-card:active { transform: scale(0.94); }
.tier-card.held {
    outline-color: var(--accent-primary, #C96442);
    transform: scale(1.06);
    box-shadow: 0 4px 14px rgba(0,0,0,0.28);
    z-index: 3;
}
.tier-card.long-pressing {
    outline-color: var(--accent-primary, #C96442);
    transform: scale(0.94);
    filter: brightness(0.72);
    transition: transform .5s linear, filter .5s linear, outline-color .12s;
}
.tier-card.long-pressed {
    outline-color: var(--accent-primary, #C96442);
    transform: scale(0.92);
}
.tier-card::after {
    content: '';
    position: absolute;
    inset: 50% auto auto 50%;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    background: rgba(0, 0, 0, 0.72);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.65);
    transition: opacity .12s, transform .12s;
    pointer-events: none;
    z-index: 4;
}
.tier-card.long-pressing::after,
.tier-card.long-pressed::after {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}
.tier-card:focus-visible {
    outline-color: var(--accent-primary, #C96442);
}
.tier-card-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.tier-card-title {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: 6px 4px 3px;
    font-size: 0.6rem;
    line-height: 1.1;
    color: #fff;
    background: linear-gradient(to top, rgba(0,0,0,0.82), rgba(0,0,0,0));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tier-actions {
    display: flex;
    gap: 10px;
    /* 일반 흐름에 두어 카드 목록의 끝에서만 보이게 한다. */
    padding: 10px 0 4px;
    background: linear-gradient(to top, var(--bg-primary) 70%, transparent);
}
.tier-actions .btn { flex: 1; }
#tierSubmitBtn { flex: 2; }

/* ---- 모바일 ---- */
@media (max-width: 768px) {
    .match-area > .tier-mode {
        flex: 1;
        min-height: 0;
        max-height: 100%;
        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        padding: 8px 8px calc(16px + env(safe-area-inset-bottom));
        gap: 10px;
    }
    .tier-actions {
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }
    .tier-label { width: 38px; font-size: 1rem; }
    .tier-lane-slots { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); }
    .tier-card-title { font-size: 0.55rem; }
}
/* 모바일 50곡: 티어는 위에서 스크롤, 곡 목록은 하단 고정 트레이 */
@media (max-width: 768px) {
    .match-area > .tier-mode-wide {
        /* 바깥 한 덩어리 스크롤을 끄고 패널 단위 스크롤로 넘긴다 */
        overflow: hidden;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
    .match-area > .tier-mode-wide { gap: 8px; }
    .tier-mode-wide .tier-title { font-size: 0.95rem; margin-bottom: 1px; }
    .tier-mode-wide .tier-hint { min-height: 0; font-size: 0.72rem; line-height: 1.3; }
    /* 좁은 화면에선 6개 레인을 한눈에 넣는 게 우선 — 부가 안내는 감춘다 */
    .tier-mode-wide .tier-hint-extra { display: none; }
    /* 레인 압축: 집은 채로 S~F를 스크롤 없이 고를 수 있게 */
    .tier-mode-wide .tier-lanes { gap: 5px; }
    .tier-mode-wide .tier-lane { padding: 4px; gap: 6px; }
    .tier-mode-wide .tier-lane-slots { min-height: 44px; }
    .tier-mode-wide .tier-label { width: 34px; font-size: 0.95rem; }
    .tier-mode-wide .tier-workspace {
        display: flex;
        flex-direction: column;
        gap: 8px;
        flex: 1;
        min-height: 0;
    }
    .tier-mode-wide .tier-lanes-pane {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding-right: 2px;
    }
    .tier-mode-wide .tier-pool-block {
        flex: none;
        max-height: 24vh;
        padding: 6px;
    }
    .tier-mode-wide .tier-pool > .tier-card { width: 60px; }
    .tier-mode-wide .tier-lane-slots > .tier-card { width: 42px; }
    .tier-mode-wide .tier-actions { padding-top: 8px; padding-bottom: 4px; }
}
@media (max-width: 480px) {
    .tier-pool { gap: 5px; }
    .tier-lane-slots { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
    .tier-mode-wide .tier-pool > .tier-card { width: 54px; }
    .tier-mode-wide .tier-lane-slots > .tier-card { width: 40px; }
}
