:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --border-light: #f3f4f6;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --success: #059669;
    --success-light: #10b981;
    --danger: #dc2626;
    --danger-light: #ef4444;
    --warning: #d97706;
    --warning-light: #f59e0b;
}

[data-theme="dark"] {
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-card: #374151;
    --bg-card-hover: #4b5563;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --border-color: #4b5563;
    --border-light: #6b7280;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --success: #10b981;
    --success-light: #34d399;
    --danger: #ef4444;
    --danger-light: #f87171;
    --warning: #f59e0b;
    --warning-light: #fbbf24;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: all 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* MARK: Header */
.header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--bg-card);
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.league-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.league-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
}

.theme-toggle:hover {
    background: var(--bg-card-hover);
    transform: scale(1.05);
}

/* MARK: Controls */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.week-selector {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.week-selector:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* MARK: Tab Navigation */
.tab-nav {
    display: flex;
    background: var(--bg-secondary);
    border-radius: 0.75rem;
    padding: 0.25rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.tab-button {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-radius: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab-button.active {
    background: var(--bg-card);
    color: var(--primary-color);
    box-shadow: var(--shadow);
}

.tab-button:hover:not(.active) {
    color: var(--text-primary);
}

/* MARK: Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

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

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* MARK: Cards */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

.stat-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.card-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* MARK: Chart Container */
.chart-container {
    position: relative;
    height: 300px;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    padding: 1rem;
    margin: 1rem 0;
}

.chart-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-style: italic;
}

/* MARK: Standings */
.standings-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.team-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

.team-row:hover {
    background: var(--bg-card-hover);
    transform: translateX(2px);
}

.team-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.team-rank {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    color: white;
    background: var(--text-muted);
}

.rank-1 { background: linear-gradient(135deg, #fbbf24, #f59e0b); }
.rank-2 { background: linear-gradient(135deg, #e5e7eb, #d1d5db); color: #374151; }
.rank-3 { background: linear-gradient(135deg, #fbbf24, #92400e); }
.rank-playoff { background: var(--success-light); }

.team-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.team-stats {
    text-align: right;
    font-size: 0.875rem;
}

/* MARK: Player Lists */
.player-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

.player-item:hover {
    background: var(--bg-card-hover);
}

.player-info h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.player-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.player-points {
    font-weight: 700;
    color: var(--text-primary);
}

/* MARK: Stat Values */
.stat-value {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-light);
}

.stat-value:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
}

.stat-number {
    display: block;  
    text-align: right;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-number.positive { color: var(--success-light); }
.stat-number.negative { color: var(--danger-light); }
.stat-number.neutral { color: var(--warning-light); }

/* MARK: Accolades */
.accolades-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.accolade-card {
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid;
    transition: all 0.3s ease;
}

.accolade-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.accolade-best {
    border-color: var(--success-light);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.05));
}

.accolade-worst {
    border-color: var(--danger-light);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.05));
}

.accolade-lucky {
    border-color: var(--warning-light);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(217, 119, 6, 0.05));
}

/* MARK: Loading & Error States */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50vh;
    flex-direction: column;
    gap: 1rem;
}

.spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin: 1rem 0;
    text-align: center;
    color: var(--danger-light);
    font-weight: 600;
}

/* MARK: Responsive Design - Mobile First */
@media (min-width: 640px) {
    .container {
        padding: 1.5rem;
    }
    
    .league-title {
        font-size: 2rem;
    }
    
    .header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .container {
        padding: 2rem;
    }
    
    .league-title {
        font-size: 2.5rem;
    }
    
    .card-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .tab-nav {
        justify-content: center;
    }
    
    .tab-button {
        flex: none;
        min-width: 120px;
    }
}

@media (min-width: 1024px) {
    .chart-container {
        height: 400px;
    }
}

/* MARK: Collapsible Sections */
.collapsible {
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    overflow: hidden;
}

.collapsible-header {
    background: var(--bg-secondary);
    padding: 1rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    transition: background 0.3s ease;
}

.collapsible-header:hover {
    background: var(--bg-card-hover);
}

.collapsible-content {
    padding: 1rem;
    background: var(--bg-card);
    display: none;
}

.collapsible.open .collapsible-content {
    display: block;
}

.collapsible-arrow {
    transition: transform 0.3s ease;
}

.collapsible.open .collapsible-arrow {
    transform: rotate(180deg);
}

.chart-container {
    width: 100%;
    height: 550px;
    position: relative;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.stat-card .chart-container {
    margin: 0;
}

.stat-card:has(.chart-container) {
    grid-column: 1 / -1;
    width: 100%;
}

#teamRankingsChart, #leagueChart {
    width: 100% !important;
    height: 100% !important;
}

.team-legend {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 16px;
  padding: 10px 16px;
  border-top: 1px solid #e5e7eb;
  background-color: transparent;
  font-size: 12px;
  color: --text-primary;
  scroll-snap-type: x mandatory;
}

.team-legend-item {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  white-space: nowrap;
  scroll-snap-align: start;
}

.team-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}