/* Theme Variables - Default (Dark Blue Theme) */
:root {
    --bg-gradient-start: #0a0f1e;
    --bg-gradient-end: #0c1222;
    --card-bg: rgba(15, 23, 42, 0.7);
    --card-bg-hover: rgba(15, 23, 42, 0.9);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --winner-color: #fbbf24;
    --table-header-bg: rgba(0, 0, 0, 0.3);
    --mana-bg: rgba(0, 0, 0, 0.3);
    --button-gradient-start: #3b82f6;
    --button-gradient-end: #2563eb;
    --danger-bg: rgba(239, 68, 68, 0.2);
    --danger-border: rgba(239, 68, 68, 0.5);
    --success-bg: rgba(34, 197, 94, 0.2);
    --success-border: rgba(34, 197, 94, 0.5);
    --warning-bg: rgba(251, 191, 36, 0.1);
    --error-color: #f87171;
    --warning-color: #fbbf24;
    --loading-color: #94a3b8;
    --position-1: #ffd966;
    --position-2: #c0c0c0;
    --position-3: #cd7f32;
    --position-4: #6c91b0;
}

/* Light Theme - White Background */
body.light-theme {
    --bg-gradient-start: #f5f5f5;
    --bg-gradient-end: #ffffff;
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-bg-hover: rgba(255, 255, 255, 1);
    --border-color: rgba(0, 0, 0, 0.1);
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --accent-blue: #2563eb;
    --accent-cyan: #0891b2;
    --winner-color: #d97706;
    --table-header-bg: rgba(0, 0, 0, 0.05);
    --mana-bg: rgba(0, 0, 0, 0.05);
    --button-gradient-start: #2563eb;
    --button-gradient-end: #1d4ed8;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --danger-border: rgba(239, 68, 68, 0.3);
    --success-bg: rgba(34, 197, 94, 0.1);
    --success-border: rgba(34, 197, 94, 0.3);
    --warning-bg: rgba(251, 191, 36, 0.08);
    --error-color: #dc2626;
    --warning-color: #d97706;
    --loading-color: #9ca3af;
    --position-1: #b45309;
    --position-2: #4b5563;
    --position-3: #b45309;
    --position-4: #3b82f6;
}


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

body {
    font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    padding: 2rem;
    color: var(--text-primary);
    transition: background 0.3s ease;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
}

/* File Upload Section */
.upload-section {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 1rem;
    padding: 1rem 1.5rem;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.file-label {
    background: linear-gradient(135deg, var(--button-gradient-start), var(--button-gradient-end));
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: transform 0.2s, box-shadow 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
}

.file-label:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.file-label input {
    display: none;
}

.file-info {
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: color 0.3s ease;
}

.clear-btn {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s;
    color: var(--text-primary);
}

.clear-btn:hover {
    background: rgba(239, 68, 68, 0.3);
}

/* Date Input Styling */
.date-input {
    background: var(--mana-bg);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    width: 180px;
    transition: all 0.2s;
    color-scheme: dark;
}

body.light-theme .date-input {
    color-scheme: light;
}

.date-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.date-input::placeholder {
    color: var(--text-secondary);
}

/* Header Section with Logo - Fixed Dark Background */
.header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
}

.logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.75rem;
}

.mtg-logo {
    max-width: 150px;
    height: auto;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.week-badge {
    display: inline-block;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    padding: 0.5rem 1.5rem;
    border-radius: 100px;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1rem;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    color: white;
}

h1 {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ffffff, #9ca3af);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 0.5rem;
}

.info-container {
    display: flex;
    justify-content: center;
    gap: 2rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.player-count {
    font-size: 1rem;
    font-weight: 700;
    display: inline-block;
    background: rgba(59, 130, 246, 0.25);
    padding: 0.35rem 1.25rem;
    border-radius: 100px;
    backdrop-filter: blur(5px);
    color: #ffffff;
    border: 1px solid rgba(59, 130, 246, 0.5);
}

.tournament-date {
    font-size: 0.85rem;
    display: inline-block;
    background: rgba(255, 255, 255, 0.08);
    padding: 0.25rem 1rem;
    border-radius: 100px;
    backdrop-filter: blur(5px);
    color: #94a3b8;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Dark Header Background - Stays dark in both themes */
.header {
    background: linear-gradient(135deg, #0a0f1e 0%, #0c1222 100%);
    border-radius: 1.5rem;
    padding: 1.5rem 1rem;
    margin-bottom: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Table Styles */
.results-table {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 1.5rem;
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    margin-bottom: 3rem;
    transition: background 0.3s ease, border-color 0.3s ease;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1.25rem 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    background: var(--table-header-bg);
    border-bottom: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

td {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-weight: 500;
    vertical-align: middle;
}

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

tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.position-cell {
    font-weight: 600;
    font-size: 0.9rem;
    width: 70px;
    min-width: 70px;
    white-space: nowrap;
    opacity: 0.8;
}

.position-1 { color: var(--position-1); }
.position-2 { color: var(--position-2); }
.position-3 { color: var(--position-3); }
.position-4 { color: var(--position-4); }

/* Desktop View - Deck name - No truncation */
.player-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.deck-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
    transition: color 0.3s ease;
}

/* Winner emphasis - Desktop */
.player-name.winner {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--winner-color);
    text-shadow: 0 0 4px rgba(251, 191, 36, 0.3);
    position: relative;
    display: table-cell;
    vertical-align: middle;
}

.player-name.winner::before {
    content: "👑 ";
    font-size: 1rem;
    display: inline-block;
    margin-right: 0.25rem;
}

.medal {
    display: inline-block;
    margin-right: 0.3rem;
    font-size: 0.9rem;
    vertical-align: middle;
}

.position-text {
    display: inline-block;
    vertical-align: middle;
}

/* Card Art Column - Desktop (120x80) */
.card-art-cell {
    width: 120px;
    text-align: center;
    padding: 0.5rem;
}

.card-art-img {
    width: 120px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--mana-bg);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-art-img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-color: var(--accent-blue);
}

/* Mana Symbols */
.mana-symbols {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: wrap;
}

.mana-symbol {
    width: 24px;
    height: 24px;
    display: inline-block;
}

.loading {
    text-align: center;
    padding: 3rem;
    color: var(--loading-color);
}

.error {
    text-align: center;
    padding: 2rem;
    color: var(--error-color);
    background: rgba(248, 113, 113, 0.1);
    border-radius: 1rem;
}

.warning {
    text-align: center;
    padding: 0.75rem;
    color: var(--warning-color);
    background: var(--warning-bg);
    border-radius: 0.5rem;
    margin: 0.5rem;
    font-size: 0.85rem;
}

.status-msg {
    text-align: center;
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.screenshot-spacer {
    height: 2rem;
}

/* View Toggle Buttons */
.view-toggle-btn {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s;
    color: white;
}

.view-toggle-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

/* Theme Toggle Button */
.theme-toggle-btn {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s;
    color: white;
}

.theme-toggle-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(107, 114, 128, 0.4);
}

body.dark-theme .theme-toggle-btn {
    background: linear-gradient(135deg, #374151, #1f2937);
}

/* ============================================
   MOBILE VIEW - 9:16 RATIO OPTIMIZED
   ============================================ */
.mobile-container {
    max-width: 400px;
    margin: 0 auto;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 0 1px var(--border-color);
    transition: background 0.3s ease;
}

/* Mobile Header - Fixed Dark Background */
.mobile-header {
    text-align: center;
    padding: 2.5rem 1rem 0.75rem 1rem;
    background: linear-gradient(135deg, #0a0f1e 0%, #0c1222 100%);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 10;
    border-radius: 0 0 1rem 1rem;
    margin-bottom: 0.5rem;
}

.back-to-desktop-btn {
    position: absolute;
    left: 1rem;
    top: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.4rem 0.7rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 1rem;
    color: #94a3b8;
    transition: all 0.2s;
    z-index: 20;
    line-height: 1;
}

.back-to-desktop-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}


.mobile-logo-container {
    margin-bottom: 0.5rem;
    margin-top: 1.25rem;
    padding: 0.25rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mobile-logos-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.mobile-bzgc-logo {
    max-width: 60px;
    height: auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.mobile-mtg-logo {
    max-width: 80px;
    height: auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.mobile-week-badge {
    display: inline-block;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    padding: 0.25rem 1rem;
    border-radius: 100px;
    font-weight: 700;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
    color: white;
}

.mobile-title {
    font-size: 1rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ffffff, #9ca3af);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 0.5rem;
}

.mobile-info {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    font-size: 0.65rem;
    margin-bottom: 0.25rem;
}

.mobile-player-count {
    background: rgba(59, 130, 246, 0.25);
    padding: 0.2rem 0.7rem;
    border-radius: 100px;
    color: white;
    font-weight: 600;
    border: 1px solid rgba(59, 130, 246, 0.5);
}

.mobile-date {
    background: rgba(255, 255, 255, 0.08);
    padding: 0.2rem 0.7rem;
    border-radius: 100px;
    color: #94a3b8;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Mobile Cards */
.mobile-cards {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.player-card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 0.75rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

/* Mobile Card Art */
.mobile-card-art {
    flex-shrink: 0;
    width: 80px;
    height: 53px;
    margin-right: 0.75rem;
}

.mobile-card-art-img {
    width: 80px;
    height: 53px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--mana-bg);
}

/* Mobile Position Badge */
.card-position {
    font-weight: 600;
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
    border-radius: 100px;
    background: rgba(0, 0, 0, 0.3);
    min-width: 45px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.8;
}

.card-position .medal {
    font-size: 0.7rem;
    margin-right: 0.2rem;
}

.card-position-1 { color: var(--position-1); background: rgba(180, 83, 9, 0.1); }
.card-position-2 { color: var(--position-2); background: rgba(75, 85, 99, 0.1); }
.card-position-3 { color: var(--position-3); background: rgba(180, 83, 9, 0.1); }
.card-position-4 { color: var(--position-4); background: rgba(59, 130, 246, 0.1); }

/* Mobile Rank - Position number + record */
.mobile-rank {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 35px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.7;
    gap: 0.15rem;
}

.mobile-rank-number {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--text-primary);
    line-height: 1;
}

.mobile-rank-record {
    font-size: 0.55rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    line-height: 1;
}

/* Winner rank styling */
.player-card:first-child .mobile-rank {
    opacity: 1;
}
.player-card:first-child .mobile-rank-number {
    color: var(--winner-color);
}

.card-content {
    flex: 1;
    min-width: 0;
}

.card-deck {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
    margin-bottom: 0.25rem;
    transition: color 0.3s ease;
}

.card-player {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.3s ease;
}

.card-player.winner {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--winner-color);
    text-shadow: 0 0 2px rgba(251, 191, 36, 0.2);
}

.card-player.winner::before {
    content: "👑 ";
    font-size: 0.7rem;
    display: inline-block;
    margin-right: 0.15rem;
}

.card-colors {
    display: flex;
    gap: 0.2rem;
    align-items: center;
    flex-shrink: 0;
}

.card-colors .mana-symbol {
    width: 18px;
    height: 18px;
}

.mobile-footer {
    padding: 0.75rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    background: var(--card-bg);
    transition: all 0.3s ease;
}

.mobile-status {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* Color Distribution Chart */
.chart-container {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 1.5rem;
    padding: 1.25rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.chart-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    margin: 0;
    transition: color 0.3s ease;
}

.chart-filters {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.25rem;
    border-radius: 0.75rem;
}

.chart-filter-btn {
    background: transparent;
    border: none;
    padding: 0.4rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.chart-filter-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.chart-filter-btn.active {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.chart-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    min-height: 320px;
    width: 100%;
}

#colorChart {
    max-width: 100%;
    max-height: 320px;
    width: auto;
    height: auto;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }
    
    th, td {
        padding: 0.75rem 0.5rem;
    }
    
    .position-cell {
        width: 70px;
        font-size: 0.9rem;
    }
    
    .mana-symbol {
        width: 20px;
        height: 20px;
    }
    
    .upload-section {
        flex-direction: column;
        align-items: stretch;
    }
    
    .file-label {
        justify-content: center;
    }
    
    .info-container {
        gap: 1rem;
    }
    
    .mtg-logo {
        max-width: 150px;
    }
    
    .date-input {
        width: 140px;
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }
    
    .chart-header {
        flex-direction: column;
        text-align: center;
    }
    
    .chart-filters {
        justify-content: center;
    }
    
    .chart-container {
        padding: 1rem;
        max-width: 100%;
    }
    
    .chart-wrapper {
        min-height: 280px;
    }
    
    #colorChart {
        max-height: 280px;
    }
    
    .legend-item {
        font-size: 0.7rem;
        gap: 0.35rem;
    }
}

@media (max-width: 480px) {
    .mobile-card-art {
        width: 70px;
        height: 47px;
        margin-right: 0.6rem;
    }
    
    .mobile-card-art-img {
        width: 70px;
        height: 47px;
    }
}
