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

:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --primary: #1e5631;
    --primary-hover: #174425;
    --border: #e5e7eb;
    --header-bg: #1e5631;
    --header-text: #ffffff;
    --row-hover: #f0f7f2;
    --row-alt: #f8faf9;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

header h1 a {
    color: inherit;
    text-decoration: none;
}

header h1 a:hover {
    opacity: 0.85;
}

.controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

select {
    appearance: none;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--header-text);
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='white' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    min-width: 140px;
}

select:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 1px;
}

select option {
    color: var(--text);
    background: var(--surface);
}

.btn {
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background: #c8a951;
    color: #1a1a2e;
}

.btn-primary:hover:not(:disabled) {
    background: #b89941;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary.scraping {
    background: #e9d88b;
    cursor: wait;
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.stats-section {
    margin-bottom: 2rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.stats-section h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text);
    padding-left: 0.25rem;
}

.section-header h2 {
    margin-bottom: 0;
}

.source-select {
    appearance: none;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.35rem 1.75rem 0.35rem 0.6rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.source-select:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.table-wrapper {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    border: 1px solid var(--border);
}

.chart-wrapper {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 1rem 1rem 0.5rem;
    margin-top: 0.75rem;
    position: relative;
    max-height: 280px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    white-space: nowrap;
}

thead th {
    background: #f8f9fa;
    color: var(--text);
    font-weight: 600;
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    user-select: none;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

th.sortable {
    cursor: pointer;
}

th.sortable:hover {
    background: #eef0f2;
}

th.sort-asc::after {
    content: ' \25B2';
    font-size: 0.65rem;
    color: var(--primary);
}

th.sort-desc::after {
    content: ' \25BC';
    font-size: 0.65rem;
    color: var(--primary);
}

/* Rank column */
th[data-col="rank"],
td.rank-cell {
    width: 2.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Right-align numeric columns */
th[data-type="number"],
td.num {
    text-align: right;
}

tbody td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

tbody tr:nth-child(even) {
    background: var(--row-alt);
}

tbody tr:hover {
    background: var(--row-hover);
}

tbody td:first-child {
    font-weight: 600;
}

.player-name-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

.player-name-link:hover {
    text-decoration: underline;
    color: var(--primary);
}

/* Back link in header */
.back-link {
    color: var(--header-text);
    text-decoration: none;
    font-size: 0.85rem;
    opacity: 0.85;
}

.back-link:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Player info card */
.player-info-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}

.info-row {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.info-row:last-child {
    margin-bottom: 0;
}

.info-label {
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 0.35rem;
}

.edit-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--primary);
    border-radius: 4px;
    white-space: nowrap;
    transition: all 0.15s;
}

.edit-link:hover {
    background: var(--primary);
    color: white;
}

.team-badge {
    display: inline-block;
    background: var(--row-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.15rem 0.5rem;
    font-size: 0.8rem;
    margin-right: 0.35rem;
}

.pc-link {
    color: var(--primary);
    text-decoration: none;
    margin-right: 0.75rem;
    font-size: 0.85rem;
}

.pc-link:hover {
    text-decoration: underline;
}

td .pc-link {
    font-size: inherit;
    margin-right: 0;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}

/* Career row highlight */
.career-row {
    font-weight: 600;
    background: #f0f4f1 !important;
    border-top: 2px solid var(--border);
}

/* Loading states */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

.scrape-progress {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s ease;
    animation: indeterminate 1.5s ease-in-out infinite;
}

@keyframes indeterminate {
    0% { width: 0%; margin-left: 0; }
    50% { width: 40%; margin-left: 30%; }
    100% { width: 0%; margin-left: 100%; }
}

.progress-fill.determinate {
    animation: none;
}

#scrape-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.no-data {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.last-updated {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 1rem;
}

.hidden {
    display: none !important;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--text);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

.toast.error {
    background: #dc2626;
}

.toast.success {
    background: var(--primary);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    header {
        padding: 0.75rem 1rem;
    }

    .header-content {
        flex-direction: column;
        align-items: stretch;
    }

    header h1 {
        font-size: 1.2rem;
    }

    .controls {
        flex-direction: column;
    }

    select, .btn {
        width: 100%;
    }

    main {
        padding: 1rem;
    }

    table {
        font-size: 0.78rem;
    }

    thead th, tbody td {
        padding: 0.4rem 0.5rem;
    }
}
