/* ── Court Energy Design System ── */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@700;800&family=Inter:wght@400;500;600&display=swap');

:root {
    --brand:       #4A7C59;   /* Victory Green */
    --brand-dark:  #3A6249;
    --brand-light: #E8F4EE;
    --action:      #B85C38;   /* Terracotta */
    --action-dark: #9A4A2C;
    --action-light:#FAF0EB;
    --bg:          #FFFFFF;
    --surface:     #F3F4F6;
    --surface-alt: #E9EAEC;
    --text:        #1F2937;
    --text-muted:  #6B7280;
    --text-light:  #9CA3AF;
    --border:      #E5E7EB;
    --shadow-sm:   0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:   0 4px 6px -1px rgba(0,0,0,0.10), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg:   0 10px 15px -3px rgba(0,0,0,0.10), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius-sm:   8px;
    --radius-md:   12px;
    --radius-lg:   16px;
    --radius-pill: 999px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--surface);
    color: var(--text);
    min-height: 100vh;
}

h1, h2, h3, h4 {
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
}

/* ─────────────────────────────────────────── */
/* App Shell                                  */
/* ─────────────────────────────────────────── */
.app-container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 0 24px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ─────────────────────────────────────────── */
/* Top Navigation Bar                         */
/* ─────────────────────────────────────────── */
.topbar {
    background: var(--brand);
    border-radius: 0;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    margin: 0 -24px 0;           /* bleed to edges of padded container */
    width: calc(100% + 48px);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
    gap: 16px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 4px;
}

.back-link {
    display: flex;
    align-items: center;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    padding: 4px 6px 4px 2px;
    border-radius: 6px;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}
.back-link:hover {
    color: #FFFFFF;
    background: rgba(255,255,255,0.12);
}

.logo {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.3rem;
    font-weight: 800;
    color: #FFFFFF !important;
    cursor: pointer;
    letter-spacing: 0.2px;
    white-space: nowrap;
    transition: opacity 0.2s;
    text-shadow: 0 1px 6px rgba(0,0,0,0.45);
}
.logo:hover { opacity: 0.85; }

/* Force topbar to always be brand color regardless of glass-panel */
nav.topbar {
    background: var(--brand) !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
}

.topbar-center {
    display: flex;
    gap: 4px;
    background: rgba(0,0,0,0.18);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.nav-btn {
    padding: 7px 18px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.75);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 0.88rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.nav-btn.active {
    background: #FFFFFF;
    color: var(--brand);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.nav-btn:hover:not(.active) {
    color: #FFFFFF;
    background: rgba(255,255,255,0.12);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-group {
    display: flex;
    background: rgba(0,0,0,0.18);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}

.toggle-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.75);
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 0.82rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.toggle-btn.active {
    background: #FFFFFF;
    color: var(--brand);
    box-shadow: 0 2px 6px rgba(0,0,0,0.20);
}
.toggle-btn:hover:not(.active) {
    color: #FFFFFF;
    background: rgba(255,255,255,0.12);
}

/* ─────────────────────────────────────────── */
/* Page Visibility                            */
/* ─────────────────────────────────────────── */
.page { display: none; flex-direction: column; gap: 20px; padding-top: 24px; }
.page.active { display: flex; }

/* ─────────────────────────────────────────── */
/* Panel / Card Base                          */
/* ─────────────────────────────────────────── */
.glass-panel {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

/* ─────────────────────────────────────────── */
/* Controls Bar (Era Slider)                  */
/* ─────────────────────────────────────────── */
.controls-bar {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}

.era-control {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 260px;
}

.era-control label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 130px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

#era-label {
    color: var(--brand);
    font-weight: 700;
}

.limit-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.limit-control label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* Limit buttons live inside a light surface toggle-group */
.controls-bar .toggle-group {
    background: var(--surface);
    border: 1px solid var(--border);
}

.controls-bar .toggle-btn {
    color: var(--text-muted);
}
.controls-bar .toggle-btn.active {
    background: var(--brand);
    color: #FFFFFF;
    box-shadow: 0 2px 6px rgba(37,99,235,0.35);
}
.controls-bar .toggle-btn:hover:not(.active) {
    color: var(--brand);
    background: var(--brand-light);
}

.limit-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}
.limit-btn.active {
    background: var(--brand);
    color: white;
}

.toggle-group.mini .limit-btn {
    padding: 4px 12px;
    font-size: 0.8rem;
    min-width: 40px;
}

/* Dual Range Slider */
.dual-range-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dual-range {
    position: relative;
    height: 36px;
}

.dual-range .track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 5px;
    transform: translateY(-50%);
    border-radius: 3px;
    background: var(--surface-alt);
    pointer-events: none;
}

.dual-range .track-fill {
    position: absolute;
    top: 50%;
    height: 5px;
    transform: translateY(-50%);
    border-radius: 3px;
    background: var(--brand);
    pointer-events: none;
    transition: left 0.05s, right 0.05s;
}

.dual-range input[type="range"] {
    position: absolute;
    width: 100%;
    top: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    height: 36px;
    margin: 0;
}

.dual-range input[type="range"]::-webkit-slider-runnable-track {
    height: 0;
    background: transparent;
}

.dual-range input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--brand);
    border: 3px solid #FFFFFF;
    margin-top: -10px;
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 2px 6px rgba(37,99,235,0.4);
    transition: transform 0.15s;
    position: relative;
    z-index: 1;
}
.dual-range input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.dual-range input[type="range"]::-moz-range-track {
    height: 0;
    background: transparent;
    border: none;
}

.dual-range input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--brand);
    border: 3px solid #FFFFFF;
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 2px 6px rgba(37,99,235,0.4);
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-light);
    padding: 0 4px;
}

/* Apply Button */
.apply-btn {
    background: var(--brand);
    color: white;
    border: none;
    padding: 10px 22px;
    border-radius: 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    white-space: nowrap;
    box-shadow: 0 4px 10px rgba(37,99,235,0.30);
}
.apply-btn:hover {
    background: var(--brand-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(37,99,235,0.38);
}
.apply-btn:active { transform: translateY(0); }

/* ─────────────────────────────────────────── */
/* Leaderboard Table                          */
/* ─────────────────────────────────────────── */
.leaderboard-section {
    display: flex;
    flex-direction: column;
}

.leaderboard-section h3 {
    font-size: 1.15rem;
    color: var(--text);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 6px;
    margin-bottom: 20px;
}

.table-container {
    overflow-y: auto;
    max-height: calc(100vh - 300px);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.table-container::-webkit-scrollbar { width: 6px; }
.table-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface);
    padding: 12px 16px;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}

td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
    color: var(--text);
    background: var(--bg);
}

tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}
tbody tr:hover td {
    background: var(--brand-light);
}
tbody tr:last-child td { border-bottom: none; }

/* Rank column */
td:nth-child(1) {
    font-weight: 700;
    color: var(--text-light);
    width: 60px;
}
/* Player name */
td:nth-child(2) {
    font-weight: 600;
    color: var(--brand);
}
/* Peak ZTR */
td:nth-child(3) {
    font-weight: 700;
    color: var(--action);
}

/* ─────────────────────────────────────────── */
/* Player Evolution Page                      */
/* ─────────────────────────────────────────── */
.player-analysis {
    display: flex;
    flex-direction: column;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.header-row h3 {
    font-size: 1.1rem;
    color: var(--text);
}

.search-box {
    position: relative;
}

.search-box input {
    background: var(--surface);
    border: 1.5px solid var(--border);
    padding: 10px 16px;
    border-radius: 12px;
    color: var(--text);
    width: 320px;
    outline: none;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box input::placeholder { color: var(--text-light); }
.search-box input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.search-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 260px;
    overflow-y: auto;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    z-index: 10;
    box-shadow: var(--shadow-lg);
}
.search-dropdown.open { display: block; }

.search-dropdown-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    transition: background 0.12s;
}
.search-dropdown-item:hover {
    background: var(--brand-light);
    color: var(--brand);
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 20px 24px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}

.card-value {
    font-family: 'Montserrat', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}
.card-value.accent-green { color: var(--action); }

/* Chart area */
.chart-container {
    position: relative;
    height: 400px;
    width: 100%;
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 8px;
    border: 1px solid var(--border);
}

.chart-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
}
.chart-placeholder p {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-style: italic;
}
.chart-placeholder.hidden { display: none; }

/* ─────────────────────────────────────────── */
/* Comparison Page                            */
/* ─────────────────────────────────────────── */
.comparison-analysis {
    display: flex;
    flex-direction: column;
}

.comparison-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding: 14px 20px;
    background: var(--surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    gap: 20px;
    flex-wrap: wrap;
}

.player-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.player-tag {
    background: var(--brand-light);
    color: var(--brand);
    border: 1.5px solid rgba(37,99,235,0.25);
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: tagFadeIn 0.25s ease-out;
}

.player-tag .remove-btn {
    cursor: pointer;
    opacity: 0.5;
    font-size: 1.1rem;
    line-height: 1;
    margin-bottom: 1px;
    transition: opacity 0.15s, color 0.15s;
}
.player-tag .remove-btn:hover {
    opacity: 1;
    color: var(--action);
}

.view-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.view-toggle label {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* View-toggle buttons live in a light toggle-group */
.view-toggle .toggle-group {
    background: var(--bg);
    border: 1.5px solid var(--border);
}
.view-toggle .toggle-btn {
    color: var(--text-muted);
}
.view-toggle .toggle-btn.active {
    background: var(--brand);
    color: #FFFFFF;
    box-shadow: 0 2px 6px rgba(37,99,235,0.35);
}
.view-toggle .toggle-btn:hover:not(.active) {
    color: var(--brand);
    background: var(--brand-light);
}

.chart-container.large {
    height: 500px;
    margin-top: 20px;
}

/* ─────────────────────────────────────────── */
/* Animations                                 */
/* ─────────────────────────────────────────── */
@keyframes tagFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─────────────────────────────────────────── */
/* Responsive                                 */
/* ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-container { padding: 0 16px 32px; }
    .topbar { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 10px; width: calc(100% + 32px); margin: 0 -16px 0; }
    .topbar-center { order: 3; width: 100%; justify-content: center; }
    .summary-cards { grid-template-columns: 1fr; }
    .search-box input { width: 100%; }
    .era-control { flex-direction: column; align-items: flex-start; }
    .controls-bar { flex-direction: column; align-items: stretch; }
    .comparison-toolbar { flex-direction: column; align-items: flex-start; }
}
