:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --border-color: #334155;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --table-stripe: #1e293b;
    --table-hover: #273548;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.season {
    color: var(--accent-color);
    font-size: 0.8em;
    background: rgba(59, 130, 246, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
    vertical-align: middle;
}

.actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.last-updated {
    font-size: 12px;
    color: var(--text-secondary);
}

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 10px 20px;
    cursor: pointer;
    font-size: 16px;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-color);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Standings Table */
.standings-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

@media (max-width: 1024px) {
    .standings-container {
        grid-template-columns: 1fr;
    }
}

.conference-section {
    display: flex;
    flex-direction: column;
}

.conference-section h2 {
    margin-bottom: 15px;
    font-size: 18px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    height: 27px;
}

.table-wrapper {
    background-color: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

th {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 10px 8px;
    text-align: center;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    white-space: nowrap;
}

th:nth-child(1) {
    width: 40px;
}

th:nth-child(2) {
    width: 140px;
    text-align: left;
}

th:nth-child(3) {
    width: 35px;
}

th:nth-child(4) {
    width: 35px;
}

th:nth-child(5) {
    width: 45px;
}

th:nth-child(6) {
    width: 40px;
}

th:nth-child(7) {
    width: 50px;
}

th:nth-child(8) {
    width: 45px;
}

th:nth-child(9) {
    width: 50px;
}

td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

td:nth-child(1) {
    width: 40px;
}

td:nth-child(2) {
    width: 140px;
    text-align: left;
    font-weight: 500;
    color: var(--text-primary);
}

td:nth-child(3) {
    width: 35px;
}

td:nth-child(4) {
    width: 35px;
}

td:nth-child(5) {
    width: 45px;
}

td:nth-child(6) {
    width: 40px;
}

td:nth-child(7) {
    width: 50px;
}

td:nth-child(8) {
    width: 45px;
}

td:nth-child(9) {
    width: 50px;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background-color: var(--table-hover);
}

.play-in-line {
    border-bottom: 2px solid var(--text-secondary) !important;
}

/* Games List */
.games-controls {
    margin-bottom: 20px;
}

.search-input {
    width: 100%;
    max-width: 300px;
    padding: 10px 15px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: white;
    font-size: 14px;
}

.games-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.game-card {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 15px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.game-date {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 8px;
    line-height: 1.4;
}

.game-scores {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.team {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.team-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 5px;
    text-align: center;
}

.score {
    font-size: 24px;
    font-weight: 700;
}

.score.winner {
    color: var(--success-color);
}

.score.loser {
    color: var(--text-secondary);
    opacity: 0.7;
}

.vs {
    color: var(--text-secondary);
    font-size: 12px;
    margin: 0 10px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--text-secondary);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* My Teams Feature */
.myteams-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.team-selector-section,
.schedule-section {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 0;
    /* Padding moved to inner elements */
    border: 1px solid var(--border-color);
}

.section-header {
    padding: 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header h2 {
    margin: 0;
    font-size: 18px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.section-header:hover {
    background-color: var(--table-hover);
}

.toggle-icon {
    font-size: 12px;
    transition: transform 0.2s;
    color: var(--text-secondary);
    margin-left: auto;
}

.team-selector-section.expanded .toggle-icon {
    transform: rotate(180deg);
}

.section-content {
    padding: 0 20px 20px 20px;
    border-top: 1px solid var(--border-color);
}

.section-content.hidden {
    display: none;
}

/* Specific to schedule section which isn't collapsible in the same way */
.schedule-section {
    padding: 20px;
}

.schedule-section h2 {
    margin-bottom: 20px;
    font-size: 18px;
    color: var(--text-primary);
}

.section-desc {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 15px;
    margin-top: 15px;
}

.team-search-box {
    margin-bottom: 15px;
}

.team-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.team-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.team-checkbox:hover {
    border-color: var(--accent-color);
    background-color: rgba(59, 130, 246, 0.05);
}

.team-checkbox.checked {
    border-color: var(--accent-color);
    background-color: rgba(59, 130, 246, 0.1);
}

.team-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.team-checkbox .team-abbr {
    font-weight: 600;
    color: var(--accent-color);
    min-width: 35px;
}

.team-checkbox .team-fullname {
    color: var(--text-primary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selected-count {
    font-size: 14px;
    color: var(--accent-color);
    font-weight: 400;
}

.schedule-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.empty-state {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px 20px;
    font-size: 14px;
}

/* Collapsible Team Schedule Card */
.schedule-card {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.schedule-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.schedule-card-header:hover {
    background-color: var(--table-hover);
}

.schedule-card-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.schedule-card-title .team-abbr {
    font-weight: 700;
    color: var(--accent-color);
    font-size: 16px;
}

.schedule-card-title .team-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 14px;
}

.schedule-card-title .game-count {
    background-color: var(--accent-color);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.collapse-icon {
    color: var(--text-secondary);
    font-size: 12px;
    transition: transform 0.2s;
}

.schedule-card.expanded .collapse-icon {
    transform: rotate(180deg);
}

.schedule-card-body {
    display: none;
    border-top: 1px solid var(--border-color);
    padding: 10px 15px;
}

.schedule-card.expanded .schedule-card-body {
    display: block;
}

.upcoming-game {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    gap: 15px;
}

.upcoming-game:last-child {
    border-bottom: none;
}

.game-datetime {
    min-width: 120px;
    font-size: 12px;
    color: var(--text-secondary);
}

.game-datetime .date {
    font-weight: 600;
    color: var(--text-primary);
}

.game-datetime .time {
    font-size: 11px;
}

.game-matchup {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.game-matchup .location-indicator {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.location-indicator.home {
    background-color: rgba(16, 185, 129, 0.15);
    color: var(--success-color);
}

.location-indicator.away {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
}

.game-matchup .opponent {
    font-weight: 500;
    color: var(--text-primary);
}

.game-matchup .vs-text {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Conference Labels in Team Grid */
.conference-label {
    grid-column: 1 / -1;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 10px 0 5px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 5px;
}

.conference-label:first-child {
    padding-top: 0;
}

/* Opponent Defense Stats */
.opponent-defense {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-left: auto;
}

.defense-rank {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: 600;
}

.defense-pa {
    background-color: rgba(148, 163, 184, 0.15);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: 500;
}
/* ==================== 球員數據頁籤 ==================== */
/* 獨立區塊佈局（不能用 .standings-container 的雙欄 grid） */
.players-container {
    display: block;
}

.players-container .table-wrapper {
    overflow-x: auto;
    max-width: 100%;
}

/* 31 欄寬表：解除全域 table-layout:fixed 與 td 截斷 */
#playersTable {
    table-layout: auto;
    width: max-content;
    min-width: 100%;
}

#playersTable th,
#playersTable td {
    overflow: visible;
    text-overflow: clip;
    max-width: none;
    width: auto;   /* 蓋掉全域 th/td:nth-child 的固定欄寬 */
    padding: 8px 10px;
}

.players-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 8px;
}

#playersTable th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

#playersTable th.sortable:hover {
    text-decoration: underline;
}

#playersTable th.sort-asc::after { content: ' ▲'; font-size: 0.7em; }
#playersTable th.sort-desc::after { content: ' ▼'; font-size: 0.7em; }

#playersTable td { white-space: nowrap; }

td.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: #888;
}

.view-toggle {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    padding: 4px;
}

.view-btn {
    border: none;
    background: transparent;
    color: #aab;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}

.view-btn:hover { color: #fff; }

.view-btn.active {
    background: #2563eb;
    color: #fff;
}

/* 季前名單表：同樣要解除全域 table-layout:fixed 與 td 截斷 */
#preseasonTable {
    table-layout: auto;
    width: max-content;
    min-width: 100%;
}

#preseasonTable th,
#preseasonTable td {
    overflow: visible;
    text-overflow: clip;
    max-width: none;
    width: auto;
    white-space: nowrap;
    padding: 8px 10px;
}

/* 數據欄靠右，讀起來成列 */
#preseasonTable td:nth-child(n+3),
#preseasonTable th:nth-child(n+3) {
    text-align: right;
}

/* ===== 季前名單 ===== */
.preseason-games {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.pre-game {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 6px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13px;
    white-space: nowrap;
}

.pre-game:hover {
    border-color: var(--accent-color);
}

.pre-date {
    color: var(--text-secondary);
    font-size: 12px;
}

/* ===== 板上新聞 ===== */
.news-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.news-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 14px;
}

.news-head {
    display: flex;
    gap: 8px;
    align-items: baseline;
    flex-wrap: wrap;
}

.news-tag {
    flex: none;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--border-color);
    color: var(--text-primary);
}

.tag-新聞 { background: #1d4ed8; }
.tag-情報 { background: #047857; }
.tag-外絮 { background: #7c3aed; }
.tag-花邊 { background: #b45309; }

.news-title {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
}

.news-title:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

.news-sub {
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 4px;
}

.news-excerpt {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 8px;
    white-space: pre-wrap;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

@media (max-width: 600px) {
    .pre-game { font-size: 12px; }
}

/* ===== 選秀排名 ===== */
#draftTable {
    table-layout: auto;
    width: max-content;
    min-width: 100%;
}
#draftTable th,
#draftTable td {
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    padding: 6px 10px;
}
#draftTable input[type="checkbox"] { width: 22px; height: 22px; cursor: pointer; }
#draftTable tr.taken td { text-decoration: line-through; opacity: 0.4; }
#draftTable tr.taken td:first-child { text-decoration: none; opacity: 1; }
#draftTable tr.excluded td { color: #888; }
#draftTable tr.next td { background: rgba(255, 196, 0, 0.18); font-weight: 600; }
#draftTable td.draft-note { white-space: normal; min-width: 180px; font-size: 0.85em; }
.draft-opt { display: inline-flex; align-items: center; gap: 4px; font-size: 0.9em; }
.draft-next {
    display: flex; flex-wrap: wrap; gap: 8px 20px;
    margin: 8px 0; padding: 10px 14px; border-radius: 8px;
    background: rgba(255, 196, 0, 0.12); font-size: 1.05em;
}
.draft-count { opacity: 0.7; }
#draft .players-controls { flex-wrap: wrap; gap: 8px 14px; }
#draft .draft-opt, #draftReset { white-space: nowrap; }
#draftMeta { white-space: nowrap; }
