:root {
    --red: #D81E44;
    --dark-red: #A51834;
    --black: #121212;
    --dark-gray: #1E1E1E;
    --gold: #D4AF37;
    --light-gold: #F0E68C;
    --green: #4CAF50;
    --orange: #FF9800;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Microsoft YaHei', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
}

#section-eight-decks.active {
    min-height: 100vh;
    padding: 30px 20px;
    max-width: 1920px;
    margin: 0 auto;
    overflow-x: hidden;
    position: relative;
}

.back-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    background: linear-gradient(135deg, var(--red), var(--dark-red));
    color: var(--light-gold);
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    z-index: 999;
}

.back-btn:hover {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 0 10px rgba(216, 30, 68, 0.6);
}

/* ── 右上角按钮：历届卡组 ─────────────────────────────── */

.old-decks-trigger {
    position: absolute;
    top: 24px;
    right: 24px;
    background: linear-gradient(135deg, var(--dark-gray), var(--black));
    color: var(--light-gold);
    border: 1px solid rgba(216, 30, 68, 0.5);
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    z-index: 100;
}

.old-decks-trigger:hover {
    background: linear-gradient(135deg, var(--red), var(--dark-red));
    box-shadow: 0 0 12px rgba(216, 30, 68, 0.5);
    transform: scale(1.05);
}

/* ── 页面标题 ──────────────────────────────────────────── */

.page-title {
    text-align: center;
    color: var(--light-gold);
    font-size: 2rem;
    margin-bottom: 10px;
    text-shadow: 0 0 5px var(--light-gold);
    width: 100%;
    margin: 0 auto 10px;
}

.red-line {
    width: 80%;
    height: 2px;
    background: var(--red);
    margin: 0 auto 30px;
}

/* ── 比赛信息头 ────────────────────────────────────────── */

.tournament-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.tournament-header #tourneyName {
    color: #fff;
    font-size: 1.4rem;
    font-weight: bold;
}

.badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
}

.rule-badge {
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold);
    border: 1px solid var(--gold);
}

.status-badge {
    border: 1px solid;
}

.status-ready {
    background: rgba(255, 152, 0, 0.15);
    color: var(--orange);
    border-color: var(--orange);
}

.status-running {
    background: rgba(76, 175, 80, 0.15);
    color: var(--green);
    border-color: var(--green);
    animation: pulse 2s infinite;
}

.status-finished {
    background: rgba(158, 158, 158, 0.15);
    color: #9e9e9e;
    border-color: #9e9e9e;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ── 主体容器 ──────────────────────────────────────────── */

.tournament-main {
    max-width: 1400px;
    margin: 0 auto;
    width: 95%;
}

.loading-hint {
    text-align: center;
    color: #888;
    padding: 40px;
    font-size: 1rem;
}

/* ── 排名表 ────────────────────────────────────────────── */

.section-title {
    color: var(--gold);
    font-size: 1.2rem;
    margin: 28px 0 14px;
    text-align: center;
}

.ranking-wrap {
    overflow-x: auto;
    margin-bottom: 8px;
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    background: linear-gradient(135deg, var(--dark-gray), var(--black));
    border: 1px solid rgba(216, 30, 68, 0.3);
    border-radius: 12px;
    overflow: hidden;
}

.ranking-table th {
    background: linear-gradient(135deg, var(--red), var(--dark-red));
    color: var(--light-gold);
    padding: 10px 8px;
    font-size: 13px;
    text-align: center;
}

.ranking-table td {
    padding: 8px;
    text-align: center;
    color: #ccc;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 13px;
}

.ranking-table tr.rank-top {
    background: rgba(212, 175, 55, 0.06);
}

.ranking-table tr.rank-top td {
    color: #fff;
    font-weight: bold;
}

.rank-col {
    font-size: 16px;
    width: 40px;
}

/* ── 瑞士轮 ────────────────────────────────────────────── */

.swiss-section {
    margin-top: 8px;
}

.round-selector {
    text-align: center;
    margin-bottom: 16px;
}
.round-selector select {
    background: linear-gradient(135deg, var(--dark-gray), var(--black));
    color: var(--light-gold);
    border: 1px solid var(--red);
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    outline: none;
}
.round-selector select:hover {
    border-color: var(--gold);
}

.round-group {
    margin-bottom: 20px;
}

.round-title {
    color: var(--light-gold);
    font-size: 1rem;
    margin-bottom: 10px;
    padding-left: 8px;
    border-left: 3px solid var(--red);
}

.match-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.match-list .match-card {
    width: 100%;
    max-width: 500px;
}

/* ── 对局卡片 ──────────────────────────────────────────── */

.match-card {
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, var(--dark-gray), var(--black));
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 8px 10px;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    transition: 0.3s;
    overflow: hidden;
}

.match-card.finished .match-player.right.winner {
    background: rgba(212, 175, 55, 0.1);
    border-radius: 6px;
    padding: 2px 6px;
}
.match-card.finished .match-player.right.winner .player-name {
    color: var(--gold);
    font-weight: bold;
}

.match-card.live {
    border-color: var(--green);
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.3);
}

.match-player {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.match-player.left {
    justify-content: flex-end;
}

.match-player.right {
    justify-content: flex-start;
}

.match-player.winner .player-name {
    color: var(--gold);
    font-weight: bold;
}

.player-name {
    color: #ddd;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

.player-score {
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.match-vs {
    color: #666;
    font-size: 11px;
    font-weight: bold;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── 淘汰赛对阵树 ──────────────────────────────────────── */

.bracket-tree {
    display: flex;
    overflow-x: auto;
    padding: 20px 0 30px;
    justify-content: center;
    max-width: 100%;
}

.bracket-layer {
    display: flex;
    flex-direction: column;
    width: 210px;
    flex-shrink: 0;
}

.bracket-layer-title {
    color: var(--gold);
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 8px;
    white-space: nowrap;
}

.bracket-layer-slots {
    position: relative;
}

.bracket-slot {
    position: absolute;
    left: 0;
    right: 6px;
    height: 100px;
    display: flex;
    align-items: center;
}

.bracket-slot .match-card {
    flex: 1;
    min-width: 0;
}

.bracket-subtitle {
    color: var(--light-gold);
    font-size: 1rem;
    margin-bottom: 8px;
    text-align: center;
}

.bracket-note {
    color: #888;
    font-size: 13px;
    margin-top: 4px;
    text-align: center;
}


/* 旧版简单对阵（兜底 fallback） */
.bracket-view {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    padding-bottom: 16px;
}
.bracket-round {
    display: flex;
    flex-direction: column;
    gap: 12px;
    justify-content: center;
    min-width: 200px;
}
.bracket-round-title {
    color: var(--gold);
    font-size: 13px;
    text-align: center;
}
.bracket-matches {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── 历届卡组弹窗 ──────────────────────────────────────── */

.old-decks-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: none;
    backdrop-filter: blur(4px);
}

.old-decks-overlay.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.old-decks-modal {
    background: linear-gradient(135deg, #1a1a1a, var(--black));
    border: 2px solid var(--red);
    border-radius: 20px;
    width: 95vw;
    max-width: 1600px;
    height: 90vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
    box-shadow: 0 16px 64px rgba(0, 0, 0, 0.6);
}

.old-decks-close {
    position: sticky;
    top: 0;
    float: right;
    background: linear-gradient(135deg, var(--red), var(--dark-red));
    color: var(--light-gold);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    z-index: 10;
    transition: 0.3s;
}

.old-decks-close:hover {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(216, 30, 68, 0.6);
}

.old-decks-modal h2 {
    color: var(--gold);
    text-align: center;
    margin-bottom: 20px;
    font-size: 1.4rem;
}

.old-decks-body {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.old-filter-panel {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
}

.old-container {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
    gap: 8px;
}

/* ── 保留的卡组卡片样式（在 modal 中复用） ──────────────── */

.filter-panel {
    width: 270px;
    background: linear-gradient(135deg, var(--dark-gray), var(--black));
    border: 1px solid rgba(216, 30, 68, 0.3);
    border-radius: 20px;
    padding: 20px;
    position: sticky;
    top: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    align-self: flex-start;
}

.filter-panel h3, .filter-popup h3 {
    color: var(--gold);
    margin-bottom: 12px;
    border-bottom: 2px solid var(--red);
    padding-bottom: 6px;
    font-size: 1rem;
    text-align: center;
}

.folder-btn {
    width: 100%;
    padding: 10px;
    margin: 6px 0;
    background: linear-gradient(135deg, var(--red), var(--dark-red));
    color: var(--light-gold);
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    font-size: 14px;
    text-align: center;
}

.folder-btn:hover {
    transform: scale(1.03);
    box-shadow: 0 0 8px rgba(216, 30, 68, 0.5);
}

.deck {
    background: linear-gradient(135deg, var(--dark-gray), var(--black));
    border-radius: 12px;
    padding: 8px;
    border: 1px solid var(--red);
    width: 100%;
    box-sizing: border-box;
    max-width: 700px;
    margin: 0 auto;
}

.deck h3 {
    font-size: 0.9rem;
    color: var(--light-gold);
    text-align: center;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 5px;
}

.deck-sep {
    height: 1px;
    background: var(--red);
    margin: 4px 0;
}

.deck-section {
    margin-bottom: 6px;
}

.section-label {
    color: var(--gold);
    font-weight: bold;
    margin-bottom: 3px;
    font-size: 0.8rem;
    text-align: center;
}

.cards {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
    border: 1px solid #444;
    padding: 4px;
    border-radius: 4px;
    min-height: 30px;
    width: 100%;
    margin: 0 auto;
}

.card-img {
    width: 100%;
    aspect-ratio: 42/61;
    object-fit: cover;
    border-radius: 2px;
    border: 1px solid #666;
}

.empty-tip {
    grid-column: 1/-1;
    text-align: center;
    color: #ccc;
    padding: 4px;
    font-size: 0.7rem;
}

/* ── 移动端浮动筛选按钮 ────────────────────────────────── */

.filter-float-btn {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--red), var(--dark-red));
    color: var(--light-gold);
    border: none;
    font-size: 18px;
    line-height: 36px;
    text-align: center;
    cursor: pointer;
    transition: 0.3s;
    z-index: 2001;
    box-shadow: 0 3px 12px rgba(216, 30, 68, 0.6);
    display: none;
}

.filter-float-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(216, 30, 68, 0.8);
}

.filter-mask {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2500;
    display: none;
    backdrop-filter: blur(2px);
}

.filter-popup {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 400px;
    background: linear-gradient(135deg, var(--dark-gray), var(--black));
    border: 1px solid rgba(216, 30, 68, 0.5);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 3000;
    display: none;
    max-height: 80vh;
    overflow-y: auto;
}

.filter-close-btn {
    position: absolute;
    top: 15px; right: 15px;
    background: transparent;
    border: none;
    color: var(--light-gold);
    font-size: 20px;
    cursor: pointer;
}

.filter-mask.show,
.filter-popup.show {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -45%); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}

/* ================================================================
   响应式
   ================================================================ */

@media (max-width: 1200px) {
    .bracket-tree {
        justify-content: flex-start;
    }
    .bracket-layer {
        width: 180px;
    }
    .bracket-slot {
        height: 90px;
    }
    .player-name {
        max-width: 70px;
        font-size: 11px;
    }
    .player-score {
        font-size: 13px;
    }
    .match-card {
        padding: 6px 8px;
        gap: 4px;
    }
    .match-vs {
        font-size: 10px;
    }
    .bracket-view { gap: 10px; }
    .bracket-round { min-width: 160px; }
}

@media (max-width: 768px) {
    #section-eight-decks.active {
        padding: 20px 10px;
    }

    .page-title {
        font-size: 1.6rem;
    }

    .back-btn {
        left: 12px; top: 60px;
        transform: none;
        margin-left: 0;
        padding: 8px 16px;
        font-size: 0.9rem;
    }

    .old-decks-trigger {
        position: fixed;
        top: 60px;
        right: 12px;
        padding: 8px 12px;
        font-size: 12px;
        z-index: 998;
    }

    .tournament-header {
        flex-direction: column;
        gap: 8px;
    }

    .tournament-header #tourneyName {
        font-size: 1.1rem;
    }

    /* 对阵树移动端：变成纵向列表，不移除屏幕 */
    .bracket-tree {
        display: block;
        overflow-x: visible;
        padding: 10px 0 16px;
    }
    .bracket-layer {
        width: 100%;
        margin-bottom: 12px;
    }
    .bracket-layer-title {
        font-size: 13px;
        margin-bottom: 6px;
    }
    .bracket-layer-slots {
        height: auto !important;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .bracket-slot {
        position: static !important;
        height: auto !important;
        width: 100%;
    }
    .bracket-conn-col {
        display: none;
    }

    .match-card {
        width: 100%;
        padding: 8px 10px;
        gap: 6px;
    }
    .match-player { gap: 4px; }
    .player-name { max-width: none; flex: 1; }
    .player-score { font-size: 14px; min-width: 16px; }
    .match-vs { font-size: 10px; }
    .match-card.finished .match-player.right.winner {
        padding: 3px 8px;
    }

    /* Fallback 对阵移动端 */
    .bracket-view { flex-direction: column; gap: 8px; }
    .bracket-round { min-width: auto; }

    .ranking-table th, .ranking-table td {
        padding: 6px 4px;
        font-size: 11px;
    }

    /* Modal 内响应式 */
    .old-decks-body {
        flex-direction: column;
    }

    .old-filter-panel {
        width: 100%;
        position: static;
    }

    .old-container {
        grid-template-columns: 1fr;
        width: 100%;
    }

        .filter-panel { display: none; }
    .filter-float-btn { display: block; }

    .deck { max-width: 100%; padding: 6px; }
    .cards { gap: 1px; padding: 3px; }
}

@media (max-width: 480px) {
    .cards {
        grid-template-columns: repeat(8, 1fr);
    }
    .old-decks-modal {
        width: 98vw;
        padding: 12px;
    }
    .match-vs { font-size: 10px; }
    .player-score { font-size: 14px; }
    .player-name { max-width: 60px; font-size: 11px; }
}
