/* ═══════════════════════════════════════════════
   Golf Tournament Win Probability – Stylesheet
   ═══════════════════════════════════════════════ */

:root {
    --chart-panel-height: 420px;
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-navbar: #1a1a2e;
    --color-navbar-accent: #16213e;
    --color-accent: #2d6a4f;
    --color-accent-light: #40916c;
    --color-text: #1e1e1e;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
    --radius: 10px;
}

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

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-main);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Navbar ─────────────────────────────────── */

#navbar {
    background: var(--color-navbar);
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 72px;
    padding: 0;
    box-sizing: border-box;
}

.nav-brand {
    display: flex;
    align-items: center;
    align-self: stretch;
    height: 100%;
    gap: 12px;
    min-width: 0;
    padding: 0;
    margin: 0;
}

.nav-logo {
    flex-shrink: 0;
    height: 100%;
    width: auto;
    max-width: 130px;
    object-fit: contain;
    object-position: left center;
    display: block;
}

.nav-title-main {
    color: #ffffff;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-subtitle {
    color: rgba(255,255,255,0.55);
    font-size: 0.75rem;
    margin-left: 14px;
    font-weight: 400;
}

.nav-round {
    color: var(--color-accent-light);
    font-size: 0.9rem;
    font-weight: 600;
    background: rgba(45,106,79,0.18);
    padding: 4px 14px;
    border-radius: 20px;
    white-space: nowrap;
}

/* ── Page wrapper ───────────────────────────── */

.page-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px 60px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ── Cards ──────────────────────────────────── */

.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.chart-card-header {
    justify-content: space-between;
}

/* ── Chart section ──────────────────────────── */

.chart-panels {
    position: relative;
}

.chart-panel[hidden] {
    display: none;
}

/* Same vertical slot for by-hole and by-time so the leaderboard does not shift when switching tabs. */
.chart-card .chart-panel {
    height: var(--chart-panel-height);
    overflow: hidden;
    box-sizing: border-box;
}

/* Non-scrolling frame: legend is positioned here so it never moves with the chart. */
.chart-time-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.chart-scroll-wrap {
    height: 100%;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    border-top: 1px solid transparent;
    scrollbar-gutter: stable;
}

/* Centered on viewport; single row like Chart.js legend (scroll on tiny screens if needed). */
.chart-time-legend-overlay {
    position: absolute;
    left: 50%;
    top: 12px;
    transform: translateX(-50%);
    z-index: 10;
    width: max-content;
    max-width: calc(100% - 16px);
    pointer-events: none;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.chart-time-legend-overlay::-webkit-scrollbar {
    height: 0;
}

/* Mirrors Chart.js default legend (by-hole): font/spacing set in JS from chartMobileLayout(). */
.chart-time-legend-overlay-inner {
    pointer-events: auto;
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    width: max-content;
    margin: 0 auto;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    color: #666;
}

.chart-time-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 400;
    color: inherit;
    cursor: pointer;
    line-height: 1;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.chart-time-legend-item:hover {
    background: transparent;
}

.chart-time-legend-item:focus-visible {
    outline: none;
}

.chart-time-legend-item--hidden {
    opacity: 0.45;
}

.chart-time-legend-item--hidden .chart-time-legend-label {
    text-decoration: line-through;
}

.chart-time-legend-swatch {
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: none;
}

.chart-time-inner {
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-width: 100%;
    height: 100%;
    min-height: 0;
}

/* Sticky strip: chart + y-axis stay in the scrollport; spacer carries horizontal scroll width. */
.chart-time-viewport-sticky {
    position: sticky;
    left: 0;
    z-index: 2;
    flex-shrink: 0;
    align-self: stretch;
    min-width: 0;
    min-height: 0;
    height: 100%;
    box-sizing: border-box;
    background: var(--color-surface);
    box-shadow: 4px 0 12px -4px rgba(0, 0, 0, 0.12);
}

.chart-time-scroll-spacer {
    flex: 0 0 auto;
    align-self: stretch;
    min-height: 100%;
    pointer-events: none;
}

.chart-wrap--time {
    height: 100%;
    min-height: 0;
    min-width: 0;
    width: 100%;
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.chart-controls label {
    font-weight: 500;
}

.chart-controls select {
    font-family: var(--font-main);
    font-size: 0.85rem;
    padding: 4px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.chart-controls select:focus {
    border-color: var(--color-accent);
}

/* ── Leaderboard / Rankings tabs ─────────────── */

.leaderboard-card-header {
    justify-content: flex-start;
}

.section-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    padding: 2px;
    background: #eef0f3;
    border-radius: 8px;
}

.section-tab {
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.section-tab:hover {
    color: var(--color-text);
    background: rgba(255, 255, 255, 0.5);
}

.section-tab.section-tab--active {
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
}

.section-tab:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.leaderboard-panels {
    position: relative;
}

.leaderboard-panel[hidden] {
    display: none;
}

/* ── Pairwise tab ───────────────────────────── */

.pairwise-panel-inner {
    padding: 16px 24px 24px;
    max-width: 48rem;
}

.pairwise-intro {
    font-size: 0.88rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    margin-bottom: 20px;
}

.pairwise-intro strong {
    color: var(--color-text);
    font-weight: 600;
}

.pairwise-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px 20px;
    margin-bottom: 20px;
}

.pairwise-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    flex: 1 1 200px;
}

.pairwise-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.pairwise-select {
    font-family: var(--font-main);
    font-size: 0.9rem;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
    max-width: 100%;
}

.pairwise-select:focus {
    border-color: var(--color-accent);
}

.pairwise-vs {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-muted);
    padding-bottom: 10px;
    flex-shrink: 0;
}

.pairwise-results {
    min-height: 5rem;
}

.pairwise-results-wrap {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.pairwise-snapshot {
    background: #fafbfc;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}

.pairwise-snapshot-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

.pairwise-snapshot-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

.pairwise-snapshot-col {
    min-width: 0;
}

.pairwise-snapshot-head {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.pairwise-snapshot-photo-wrap {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background: #e8eaed;
    border: 1px solid var(--color-border);
}

.pairwise-snapshot-photo {
    display: block;
    width: 80px;
    height: 80px;
    object-fit: cover;
}

.pairwise-snapshot-photo-fallback {
    width: 80px;
    height: 80px;
    background: linear-gradient(145deg, #e2e5e9 0%, #eef0f3 100%);
}

.pairwise-snapshot-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.25;
    min-width: 0;
}

.pairwise-snapshot-dl {
    margin: 12px 0 0;
    padding: 0;
}

.pairwise-snapshot-row {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    font-size: 0.82rem;
    padding: 5px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.pairwise-snapshot-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.pairwise-snapshot-dl dt {
    margin: 0;
    font-weight: 500;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.pairwise-snapshot-dl dd {
    margin: 0;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--color-text);
    text-align: right;
}

@media (max-width: 520px) {
    .pairwise-snapshot-cols {
        grid-template-columns: 1fr;
    }
}

.pairwise-results-placeholder {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin: 0;
}

.pairwise-results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 520px) {
    .pairwise-results-grid {
        grid-template-columns: 1fr;
    }
}

.pairwise-result-card {
    background: #fafbfc;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}

.pairwise-result-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.pairwise-result-value {
    font-size: 1.65rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--color-accent);
    letter-spacing: -0.02em;
}

.pairwise-result-sub {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 6px;
    line-height: 1.4;
}

.chart-wrap {
    position: relative;
    box-sizing: border-box;
    height: 100%;
    min-height: 0;
    padding: 16px 20px 12px;
}

/* ── Leaderboard table ──────────────────────── */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

#leaderboard,
#rankings {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
    font-size: 0.88rem;
}

#leaderboard thead th,
#rankings thead th {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    padding: 10px 14px;
    text-align: left;
    border-bottom: 2px solid var(--color-border);
    user-select: none;
}

#leaderboard thead th.col-pos,
#rankings thead th.col-pos {
    text-align: center;
}

#leaderboard thead th.col-prob {
    text-align: right;
}

#leaderboard thead th.col-score {
    text-align: right;
}

#rankings thead th.col-rating {
    text-align: right;
}

#leaderboard tbody tr,
#rankings tbody tr {
    transition: background-color 0.12s;
}

#leaderboard tbody tr:hover,
#rankings tbody tr:hover {
    background-color: rgba(45,106,79,0.06);
}

#leaderboard tbody tr:nth-child(even),
#rankings tbody tr:nth-child(even) {
    background-color: #fafbfc;
}

#leaderboard tbody tr:nth-child(even):hover,
#rankings tbody tr:nth-child(even):hover {
    background-color: rgba(45,106,79,0.08);
}

#leaderboard tbody td,
#rankings tbody td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.col-pos {
    width: 48px;
    text-align: center;
    font-weight: 700;
    color: var(--color-text-muted);
}

.col-flag {
    width: 40px;
    text-align: center;
    padding-left: 8px !important;
    padding-right: 8px !important;
}

.leaderboard-flag {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 3px;
    vertical-align: middle;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

#leaderboard thead th.col-flag,
#rankings thead th.col-flag {
    width: 40px;
    padding: 10px 4px;
}

.leaderboard-row,
.rankings-row {
    cursor: default;
}

#rankings .col-rating {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* Player row hover card */
.player-hover-card {
    position: fixed;
    z-index: 2000;
    width: max-content;
    max-width: min(460px, calc(100vw - 24px));
    min-width: 280px;
    padding: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    pointer-events: auto;
}

.player-hover-card[hidden] {
    display: none !important;
}

.player-hover-card__inner {
    display: flex;
    gap: 14px;
    padding: 14px 16px;
    align-items: flex-start;
}

.player-hover-card__photo {
    flex-shrink: 0;
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    background: #eef0f2;
}

.player-hover-card__photo[hidden] {
    display: none;
}

.player-hover-card__text {
    flex: 1;
    min-width: 220px;
    font-size: 0.88rem;
    line-height: 1.45;
}

.player-hover-card__name {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 6px;
    color: var(--color-text);
}

.player-hover-card__country {
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.player-hover-card__country::before {
    content: "Country: ";
    font-weight: 600;
    color: var(--color-text);
}

.player-hover-card__tee {
    color: var(--color-text-muted);
    margin-bottom: 10px;
}

.player-hover-card__rating {
    color: var(--color-text-muted);
    margin-bottom: 4px;
    white-space: nowrap;
}

.player-hover-card__rank {
    color: var(--color-text-muted);
    margin-bottom: 10px;
}

@media (max-width: 420px) {
    .player-hover-card__rating {
        white-space: normal;
    }
}

.player-hover-card__rating[hidden],
.player-hover-card__rank[hidden] {
    display: none !important;
}

.player-hover-card__link {
    display: inline-block;
    color: var(--color-accent);
    font-weight: 600;
    text-decoration: none;
}

.player-hover-card__link:hover {
    text-decoration: underline;
}

.col-name {
    font-weight: 600;
    min-width: 140px;
}

.col-score {
    font-weight: 700;
    min-width: 60px;
    text-align: right;
}

.col-thru, .col-rd {
    color: var(--color-text-muted);
    min-width: 50px;
}

.col-prob {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-width: 68px;
    border-radius: 4px;
}

.col-win {
    font-size: 0.92rem;
}

/* ── Loading overlay ────────────────────────── */

#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(244,245,247,0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 500;
    gap: 16px;
    transition: opacity 0.3s;
}

#loading-overlay p {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    font-weight: 500;
}

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

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

/* ── Responsive: Tablet ─────────────────────── */

@media (max-width: 768px) {
    html { font-size: 14px; }

    :root {
        --chart-panel-height: 320px;
    }

    .nav-inner {
        height: 64px;
    }

    .nav-logo {
        max-width: 64px;
    }

    .nav-title-main { font-size: 1.1rem; }

    .nav-subtitle { display: block; margin-left: 0; margin-top: 1px; font-size: 0.68rem; }

    .nav-title { display: flex; flex-direction: column; }

    .page-wrap { padding: 16px 12px 40px; gap: 16px; }

    .card-header { padding: 12px 16px; }

    .chart-wrap { padding: 12px 10px 8px; }

    #leaderboard thead th,
    #leaderboard tbody td,
    #rankings thead th,
    #rankings tbody td {
        padding: 7px 6px;
    }

    .leaderboard-flag {
        width: 22px;
        height: 22px;
    }

    .col-flag {
        width: 34px;
        padding-left: 4px !important;
        padding-right: 4px !important;
    }

    #leaderboard thead th.col-flag,
    #rankings thead th.col-flag {
        width: 34px;
        padding: 7px 4px;
    }
}

/* ── Responsive: Phone ──────────────────────── */

@media (max-width: 480px) {
    html { font-size: 13px; }

    :root {
        --chart-panel-height: 260px;
    }

    #navbar { padding: 0 12px; }

    .nav-inner {
        height: 56px;
    }

    .nav-logo {
        max-width: 56px;
    }

    .nav-title-main { font-size: 1rem; }

    .nav-round { font-size: 0.78rem; padding: 3px 10px; }

    .chart-wrap { padding: 8px 4px 4px; }

    .card-header h2 { font-size: 1rem; }

    #leaderboard,
    #rankings {
        font-size: 0.82rem;
    }

    #leaderboard thead th,
    #rankings thead th {
        font-size: 0.7rem;
        padding: 6px 4px;
    }

    #leaderboard tbody td,
    #rankings tbody td {
        padding: 6px 4px;
    }

    .leaderboard-flag {
        width: 18px;
        height: 18px;
    }

    .col-flag {
        width: 28px;
        padding-left: 2px !important;
        padding-right: 2px !important;
    }

    #leaderboard thead th.col-flag,
    #rankings thead th.col-flag {
        width: 28px;
        padding: 6px 2px;
    }

    .col-name { min-width: 110px; }
    .col-prob { min-width: 54px; }
}

/* ── Responsive: Small phone ────────────────── */

@media (max-width: 360px) {
    :root {
        --chart-panel-height: 220px;
    }

    .col-extra {
        display: none;
    }

    .nav-subtitle { display: none; }
}
