/* KBO Baseball Analytics Dashboard - Premium Design */

/* ========== CSS Variables ========== */
:root {
    /* Colors */
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --secondary: #8b5cf6;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    /* Backgrounds */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.95);
    --bg-glass: rgba(15, 23, 42, 0.03);

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    /* Borders */
    --border-color: rgba(15, 23, 42, 0.08);
    --border-radius: 12px;
    --border-radius-lg: 16px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 8px 32px rgba(15, 23, 42, 0.12);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);
    --plot-bg: #ffffff;
    --plot-grid: rgba(15, 23, 42, 0.06);
    --plot-axes: rgba(15, 23, 42, 0.3);
    --plot-label: rgba(15, 23, 42, 0.55);
    --plot-stroke: rgba(15, 23, 42, 0.5);
    --plot-point-stroke: rgba(15, 23, 42, 0.4);

    /* Transitions */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========== Global Styles ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ========== Typography ========== */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 1rem;
}

h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.25rem;
}

/* ========== Container ========== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* ========== Header ========== */
.header {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    transition: var(--transition);
}

.logo:hover {
    color: var(--primary-light);
    transform: translateY(-2px);
}

.logo-icon {
    font-size: 1.5rem;
}

/* ========== Navigation ========== */
.nav {
    display: flex;
    gap: 1rem;
}

.nav-link {
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.nav-link::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.2), transparent);
    transition: var(--transition);
}

.nav-link:hover::before {
    left: 100%;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-glass);
}

.nav-link.active {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

/* ========== Cards ========== */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(59, 130, 246, 0.3);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    color: var(--text-secondary);
}

/* ========== Grid System ========== */
.grid {
    display: grid;
    gap: 2rem;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1024px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* ========== Stats Cards ========== */
.stat-card {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, var(--primary), var(--secondary));
}

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

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.stat-delta {
    font-size: 0.875rem;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stat-icon {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 3rem;
    opacity: 0.1;
}

/* ========== Buttons ========== */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

/* ========== Input Fields ========== */
.input-group {
    margin-bottom: 1.5rem;
}

.input-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-box {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box .input {
    padding-left: 3rem;
}

/* ========== Tables ========== */
.table-container {
    overflow-x: auto;
    border-radius: var(--border-radius-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    position: relative;
    max-height: 800px;
    /* Limit height if too many rows */
    overflow-y: auto;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table th,
.table td {
    padding: 1rem;
    white-space: nowrap;
}

/* Sticky First Column (Player Name) */
.table th:first-child,
.table td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
}

.table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-tertiary);
}

.table thead th:first-child {
    z-index: 11;
}

.table th {
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: none;
    font-size: 0.875rem;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border-color);
    transition: var(--transition);
}

.table th:hover {
    background: var(--bg-glass);
    color: var(--primary-light);
}

.table th small {
    margin-left: 4px;
    color: var(--primary);
}

.table td {
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.table tbody tr {
    transition: var(--transition);
}

.table tbody tr:hover {
    background: var(--bg-glass);
}

.table td a:hover {
    text-decoration: underline !important;
}

/* ========== Badges ========== */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
}

.badge-primary {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary-light);
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

/* ========== Loading ========== */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ========== Animations ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.6s ease-out;
}

/* ========== Player Card ========== */
.player-card {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 2rem;
    margin-bottom: 2rem;
}

.player-info-vertical {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.info-item:last-child {
    border-bottom: none;
}

.info-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.info-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.4;
}

.detailed-stats-container {
    grid-column: span 3;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    /* 패딩 약간 축소 */
    margin-top: 0.5rem;
    overflow: hidden;
    min-height: auto;
}

[class*="grid-"]>.detailed-stats-container {
    grid-column: span 1;
}

.grid-usage-movement {
    display: grid;
    grid-template-columns: 4fr 6fr;
    gap: 1.5rem;
    align-items: stretch;
    grid-column: span 3;
    width: 100%;
}

@media (max-width: 640px) {
    .grid-usage-movement {
        grid-template-columns: 1fr;
    }
}

.grid-usage-movement>.detailed-stats-container {
    grid-column: span 1;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.pitch-arsenal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

/* Section Header for Pitch Arsenal */
.section-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding: 0 0.5rem;
}

.flex-group {
    display: flex;
    align-items: center;
}

.gap-3 {
    gap: 0.75rem;
}

.view-mode-selector {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px;
    border-radius: 10px;
    gap: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.mode-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.mode-btn.active {
    background: var(--primary-color, #3b82f6);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.pitch-chart-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    transition: var(--transition);
}

.pitch-chart-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-5px);
}

.pitch-chart-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.pitch-canvas-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1.2;
    background: var(--plot-bg, #fff);
    border-radius: 8px;
    overflow: hidden;
}

.pitch-canvas {
    width: 100%;
    height: 100%;
}

/* Standard 테이블 전용 압축 스타일 */
.detailed-stats-container .table th,
.detailed-stats-container .table td {
    padding: 0.65rem 0.5rem;
    /* 셀 간격 축소 */
    font-size: 0.8rem;
    /* 폰트 크기 축소 */
}

.detailed-stats-container .table th {
    font-size: 0.75rem;
}

.mt-4 {
    margin-top: 1rem;
}

/* ========== Player Header Bar ========== */
.player-header-bar {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0 2rem 0 0;
    margin-bottom: 1.5rem;
    overflow: hidden;
    min-height: 100px;
    transition: background-color 0.5s ease, border-color 0.5s ease;
}

.header-bar-photo {
    flex-shrink: 0;
    width: 90px;
    height: 100px;
    overflow: hidden;
    margin-right: 1.25rem;
}

.header-bar-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-bar-main {
    flex-shrink: 0;
    margin-right: auto;
}

.header-bar-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-bar-number {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-muted);
}

.header-bar-team {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.header-bar-info-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
    margin-right: 2rem;
    text-align: right;
}

.header-bar-details {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.header-bar-dob {
    font-size: 0.85rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

.header-bar-divider {
    color: var(--text-muted);
    opacity: 0.4;
    margin: 0 0.25rem;
}

.header-bar-position {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

/* ========== News Section ========== */
.player-details-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
    align-items: stretch;
    /* 높이를 똑같이 맞춤 */
}

#player-card {
    height: 100%;
    overflow: hidden;
}

.player-card,
.stats-card,
.news-card {
    height: 100%;
    /* 부모 높이에 꽉 차게 */
    margin-bottom: 0;
    transition: background-color 0.5s ease, border-color 0.5s ease;
    min-height: 500px;
}

.stats-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    overflow-y: auto;
}

/* 팀 색상 적용 시 배경을 팀 고유 색상으로 선명하게 적용 */
.theme-applied {
    background-color: var(--team-color) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
}

.theme-applied .info-label {
    color: rgba(255, 255, 255, 0.7) !important;
    font-weight: 500;
}

.theme-applied .card-title,
.theme-applied .info-value,
.theme-applied .header-bar-name {
    color: #ffffff !important;
}

.theme-applied .header-bar-number,
.theme-applied .header-bar-team,
.theme-applied .header-bar-details,
.theme-applied .header-bar-dob {
    color: rgba(255, 255, 255, 0.8) !important;
}

.theme-applied .header-bar-divider {
    color: rgba(255, 255, 255, 0.3) !important;
}

.theme-applied .header-bar-position {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
}

/* 테마 적용 시 테이블 스타일 조정 */
.theme-applied .table-container,
.theme-applied .table th,
.theme-applied .table td {
    background: transparent !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: #ffffff !important;
}

.theme-applied .table thead th {
    background: rgba(0, 0, 0, 0.2) !important;
}

.theme-applied .table th:first-child,
.theme-applied .table td:first-child {
    background: rgba(0, 0, 0, 0.2) !important;
}

.theme-applied tr:hover {
    background: rgba(255, 255, 255, 0.05) !important;
}


.news-card {
    display: flex;
    flex-direction: column;
    min-height: 480px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
}

.news-list {
    overflow-y: auto;
    flex-grow: 1;
}

.news-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
}

.news-item:last-child {
    border-bottom: none;
}

.news-item:hover {
    background: var(--bg-glass);
    transform: translateX(5px);
}

.news-thumb {
    width: 80px;
    height: 60px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.news-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.news-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    /* Standard */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

/* ========== Utility Classes ========== */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.hidden {
    display: none;
}

/* ========== Pitch Usage ========== */
.usage-container {
    padding: 1rem;
    max-width: 100%;
    margin: 0;
    height: 400px;
    overflow-y: auto;
}

.usage-header {
    display: grid;
    grid-template-columns: 1fr 120px 1fr;
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 0.75rem 0;
    border-bottom: 1.5px solid var(--border-color);
    margin-bottom: 1rem;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    /* Matches var(--bg-secondary) */
    z-index: 10;
}

.usage-label-l {
    text-align: right;
    padding-right: 2rem;
}

.usage-label-r {
    text-align: left;
    padding-left: 2rem;
}

.usage-row {
    display: grid;
    grid-template-columns: 1fr 120px 1fr;
    align-items: center;
    margin-bottom: 0.75rem;
}

.usage-left {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.4rem;
}

.usage-right {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.4rem;
}

.usage-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.usage-pct {
    font-size: 0.95rem;
    color: var(--text-muted);
    width: 45px;
    font-variant-numeric: tabular-nums;
}

.usage-left .usage-pct {
    text-align: right;
}

.usage-right .usage-pct {
    text-align: left;
}

.usage-bar-total {
    flex-grow: 1;
    max-width: 150px;
    height: 14px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 7px;
    overflow: hidden;
    position: relative;
}

.usage-bar-fill {
    height: 100%;
    border-radius: 7px;
    background: var(--pitch-color, #94a3b8);
    transition: width 0.6s ease-out;
}

.usage-left .usage-bar-fill {
    float: right;
}

.pitch-abb-circle {
    width: 28px;
    height: 28px;
    background: var(--pitch-color, #94a3b8);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.usage-total-pct {
    font-size: 0.95rem;
    font-weight: 600;
    min-width: 40px;
}

/* Pitch type colors (Standardized) */
.pitch-FF {
    --pitch-color: #D22D49;
}

.pitch-SL {
    --pitch-color: #EEE716;
}

.pitch-CH {
    --pitch-color: #1DBE3A;
}

.pitch-CU {
    --pitch-color: #00D1ED;
}

.pitch-SI {
    --pitch-color: #FE9D00;
}

.pitch-ST {
    --pitch-color: #DDB33A;
}

.pitch-FC {
    --pitch-color: #933F2C;
}

.pitch-FS {
    --pitch-color: #3BACAC;
}

.pitch-SV {
    --pitch-color: #93AFD4;
}

.pitch-KN {
    --pitch-color: #3C44CD;
}

/* ========== Movement Profile ========== */
.movement-container {
    padding: 0.5rem;
    height: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#movement-canvas {
    max-width: 100%;
    max-height: 100%;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
}

/* ========== Metric Selector ========== */
.pill-checkbox {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    user-select: none;
    white-space: nowrap;
}

.pill-checkbox:hover {
    background: #f8fafc;
    border-color: var(--primary);
    color: var(--primary);
}

.pill-checkbox:has(input:checked) {
    background: rgba(var(--primary-rgb, 37, 99, 235), 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.pill-checkbox input[type="checkbox"] {
    accent-color: var(--primary);
    cursor: pointer;
    margin-right: 0.4rem;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    .nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    .player-card {
        grid-template-columns: 1fr;
    }

    .player-image {
        width: 100%;
        max-width: 200px;
        margin: 0 auto;
    }
}
/* ========== Dark Theme (data-theme="dark") ========== */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: rgba(30, 41, 59, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
    --plot-bg: #000;
    --plot-grid: rgba(255, 255, 255, 0.05);
    --plot-axes: rgba(255, 255, 255, 0.4);
    --plot-label: rgba(255, 255, 255, 0.6);
    --plot-stroke: #cbd5e1;
    --plot-point-stroke: #ffffff;
}

[data-theme="dark"] body {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

/* light/dark 공통: hardcoded 색이 너무 강한 경우 fallback */
.theme-toggle:hover {
    transform: translateY(-1px);
}

/* ===================== KBO 경기 일정/결과 ===================== */
.schedule-section {
    margin-bottom: 2.5rem;
}

.schedule-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.schedule-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.date-nav-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

.date-label {
    min-width: 140px;
    text-align: center;
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text-primary);
}

.today-btn {
    margin-left: 0.25rem;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--primary);
    background: transparent;
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.today-btn:hover {
    background: var(--primary);
    color: #fff;
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.game-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
}

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

.game-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.85rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.game-card-top .stadium {
    font-weight: 600;
    color: var(--text-secondary);
}

.game-card-body {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 0.75rem;
}

.team {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}

.team-emblem {
    width: 46px;
    height: 46px;
    object-fit: contain;
}

.team-emblem-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.team-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.team.win .team-name {
    color: var(--primary);
}

.game-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    min-width: 64px;
}

.game-score {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
    font-weight: 700;
}

.score {
    font-size: 1.6rem;
    color: var(--text-secondary);
    line-height: 1;
}

.score.win {
    color: var(--text-primary);
}

.score-sep {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.game-vs {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.status-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    white-space: nowrap;
}

.status-badge.before {
    background: rgba(59, 130, 246, 0.14);
    color: #3b82f6;
}

.status-badge.final {
    background: rgba(100, 116, 139, 0.18);
    color: var(--text-muted);
}

.status-badge.live {
    background: rgba(239, 68, 68, 0.16);
    color: #ef4444;
}

.status-badge.cancel {
    background: rgba(100, 116, 139, 0.18);
    color: var(--text-muted);
}

.game-card.live {
    border-color: rgba(239, 68, 68, 0.5);
}

.game-card.cancel {
    opacity: 0.6;
}

.game-card-foot {
    padding: 0.45rem 0.85rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    text-align: center;
}

/* 일정 헤더 좌측 그룹(제목 + 1군/퓨처스 토글) */
.schedule-bar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* 퓨처스 디비전 라벨(북부/남부) */
.team-div {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

/* 교류전 배지 */
.series-badge.exhibition {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    background: rgba(246, 181, 0, 0.16);
    color: #c8881a;
}

/* ===== 투수 정보 (예정=선발 / 진행=현재 마운드 / 종료=승·패·세이브) ===== */
.game-pitchers {
    padding: 0.45rem 0.85rem 0.55rem;
    font-size: 0.78rem;
    border-top: 1px dashed var(--border-color);
}

/* 예정·진행: 좌(원정) — 라벨 — 우(홈) 3분할로 위쪽 팀 배치와 정렬 */
.game-pitchers.before,
.game-pitchers.live {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.5rem;
}

.game-pitchers .pp {
    color: var(--text-secondary);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-pitchers .pp.away { text-align: right; }
.game-pitchers .pp.home { text-align: left; }

.game-pitchers .pp-label {
    font-size: 0.66rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    white-space: nowrap;
}

.game-pitchers.before .pp-label {
    background: rgba(59, 130, 246, 0.14);
    color: #3b82f6;
}

.game-pitchers.live .pp-label {
    background: rgba(239, 68, 68, 0.16);
    color: #ef4444;
}

/* 종료: 승·패·세이브 칩 (가운데 정렬, 세이브는 있을 때만) */
.game-pitchers.final {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.3rem 0.7rem;
}

.pdec {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.pdec-tag {
    font-size: 0.64rem;
    font-weight: 700;
    width: 1.05rem;
    height: 1.05rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    flex-shrink: 0;
}

.pdec-tag.win  { background: #16a34a; }
.pdec-tag.lose { background: #64748b; }
.pdec-tag.save { background: #f59e0b; }

/* 선수 이름 딥링크(개인 순위·경기 투수 -> 선수 분석). 매칭된 이름만 링크, 미매칭은 일반 텍스트 */
.player-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}
.player-link:hover,
.player-link:focus-visible {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}
/* 개인 순위 이름 링크: .lr-name(flex:1·말줄임) 레이아웃·기본색 유지 */
a.lr-name.player-link {
    color: var(--text-primary);
    display: block;
}
a.lr-name.player-link:hover,
a.lr-name.player-link:focus-visible {
    color: var(--primary);
}

.schedule-msg {
    grid-column: 1 / -1;
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border: 1px dashed var(--border-color);
    border-radius: var(--border-radius);
}

.schedule-msg.error {
    color: #ef4444;
}

.schedule-note {
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
}

/* ===================== 퀵 링크 ===================== */
.quicklink-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.85rem;
}

.quicklink-card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.quicklink-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.ql-icon {
    font-size: 1.4rem;
}

.ql-title {
    font-weight: 700;
    color: var(--text-primary);
}

.ql-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

@media (max-width: 480px) {
    .game-card-body {
        padding: 0.85rem 0.5rem;
    }
    .team-emblem {
        width: 38px;
        height: 38px;
    }
    .score {
        font-size: 1.35rem;
    }
}

/* ===================== KBO Dia Gothic (공식 폰트, self-host) ===================== */
@font-face {
    font-family: 'KBO Dia Gothic';
    src: url('../assets/fonts/KBO-Dia-Gothic_light.woff') format('woff');
    font-weight: 300;
    font-display: swap;
}
@font-face {
    font-family: 'KBO Dia Gothic';
    src: url('../assets/fonts/KBO-Dia-Gothic_medium.woff') format('woff');
    font-weight: 400 500;
    font-display: swap;
}
@font-face {
    font-family: 'KBO Dia Gothic';
    src: url('../assets/fonts/KBO-Dia-Gothic_bold.woff') format('woff');
    font-weight: 600 700;
    font-display: swap;
}

body, button, input, select, textarea,
h1, h2, h3, h4, h5, h6,
.logo, .nav-link, .card-title, .team-name, .stat-value, .stat-label {
    font-family: 'KBO Dia Gothic', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===================== Material Symbols ===================== */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
    line-height: 1;
    user-select: none;
}

h2 .material-symbols-outlined,
.schedule-title .material-symbols-outlined {
    font-size: 1.1em;
    vertical-align: -4px;
    color: var(--primary);
}

.date-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.date-nav-btn .material-symbols-outlined {
    font-size: 1.4rem;
}

.ql-icon.material-symbols-outlined {
    font-size: 1.7rem;
    color: var(--primary);
}

.stat-icon .material-symbols-outlined {
    font-size: inherit;
}

.foot-icon {
    font-size: 1em;
    vertical-align: -3px;
}

/* ===================== 팀 순위 (KBO 공식) ===================== */
.standings-section {
    margin-bottom: 2.5rem;
}

.standings-wrap {
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    /* 박스를 채워 본문 행이 남는 높이를 흡수 → 범례 아래 빈 공간 제거 (헤더는 자연 높이 유지) */
    display: flex;
    flex-direction: column;
}

.standings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    flex: 1 1 auto;
}

.standings-table th,
.standings-table td {
    padding: 0.6rem 0.5rem;
    text-align: center;
    white-space: nowrap;
}

.standings-table thead th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    /* 개인 순위 카드 타이틀 밑줄과 동일한 높이로 맞춤 (leaders-wrap padding 1rem 보정) */
    padding-top: 0.83rem;
    border-bottom: 1px solid var(--border-color);
}

.standings-table tbody tr {
    border-bottom: 1px solid var(--border-color);
}

.standings-table tbody tr:last-child {
    border-bottom: none;
}

.standings-table tbody tr:hover {
    background: var(--bg-glass);
}

.standings-table .team-col {
    text-align: left;
}

.standings-table .team-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.standings-table .rank-emblem {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.standings-table .pct {
    font-weight: 700;
    color: var(--text-primary);
}

.standings-table .rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.25rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* KBO 가을야구(포스트시즌) 진출 구분 — 순위 행 좌측 색상 바 */
.standings-table tbody tr.seed-ks  td:first-child { box-shadow: inset 4px 0 0 #f59e0b; }
.standings-table tbody tr.seed-po  td:first-child { box-shadow: inset 4px 0 0 #3b82f6; }
.standings-table tbody tr.seed-spo td:first-child { box-shadow: inset 4px 0 0 #22c55e; }
.standings-table tbody tr.seed-wc  td:first-child { box-shadow: inset 4px 0 0 #a855f7; }

.standings-table .streak-w { color: #059669; font-weight: 600; }
.standings-table .streak-l { color: #dc2626; font-weight: 600; }

/* 팀 순위 가을야구 진출 범례 (박스 안, 표 아래 1×4 한 줄) */
.standings-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.45rem 0.5rem;
    padding: 0.8rem 0.85rem 0.9rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.74rem;
    color: var(--text-secondary);
}
.standings-legend .sl-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}
.standings-legend .sl-dot {
    flex: none;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}
.standings-legend .sl-dot.sl-ks  { background: #f59e0b; }
.standings-legend .sl-dot.sl-po  { background: #3b82f6; }
.standings-legend .sl-dot.sl-spo { background: #22c55e; }
.standings-legend .sl-dot.sl-wc  { background: #a855f7; }

/* ===================== 순위 2단 레이아웃 (팀 순위 + 개인 순위) ===================== */
.rank-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: stretch;
    margin-bottom: 2.5rem;
}

/* 좌우 헤더 바 높이를 통일 → 두 표의 상단 시작 위치 정렬 (탭 알약이 우측 바를 더 높이는 문제 해결) */
.rank-row .schedule-bar {
    min-height: 2.5rem;
    margin-bottom: 1rem;
}

/* 출처 문구: 박스 바로 아래 정렬 (빈 줄 없이) */
.rank-row .schedule-note {
    min-height: 0;
    margin-top: 0.75rem;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
}

/* 좌우 컬럼 동일 높이: 가운데 박스가 늘어나고 개인순위 행은 분산 */
.rank-col-team,
.rank-col-players {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.rank-col-team .standings-wrap,
.rank-col-players .leaders-wrap {
    flex: 1 1 auto;
}

.leaders-wrap {
    display: flex;
    flex-direction: column;
}

.leaders-grid {
    flex: 1 1 auto;
}

.leader-card {
    display: flex;
    flex-direction: column;
}

.leader-list {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

@media (max-width: 900px) {
    .rank-row {
        grid-template-columns: 1fr;
    }
}

/* ===== 개인 순위 ===== */
.leaders-tabs {
    display: inline-flex;
    gap: 0.25rem;
    background: var(--bg-glass);
    padding: 0.2rem;
    border-radius: 999px;
}

.leaders-tab {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.35rem 0.95rem;
    border-radius: 999px;
    cursor: pointer;
    transition: var(--transition);
}

.leaders-tab.active {
    background: var(--primary);
    color: #fff;
}

.leaders-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
}

.leaders-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, 1fr);
    grid-auto-flow: column;
    gap: 0.5rem 1.25rem;
}

/* 좁은 화면: 6개 지표를 1열로 세로 나열 */
@media (max-width: 540px) {
    .leaders-grid {
        grid-auto-flow: row;
        grid-template-columns: 1fr;
        grid-template-rows: none;
    }
}

.leader-card-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    padding-bottom: 0.4rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-color);
}

.leader-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.lr-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.32rem 0;
    font-size: 0.85rem;
}

.lr-rank {
    flex: none;
    width: 1.1rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.lr-emblem {
    flex: none;
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.lr-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
    font-weight: 500;
}

.lr-val {
    flex: none;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.lr-empty {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    padding: 0.5rem;
}

/* ===================== 반응형 내비게이션 (햄버거) ===================== */
/* 햄버거 버튼: 데스크톱·no-JS에서는 숨김, 모바일(.nav-js)에서만 노출 */
.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-glass);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.nav-toggle:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

.nav-toggle .material-symbols-outlined {
    font-size: 1.6rem;
}

@media (max-width: 768px) {
    /* JS 활성 시: nav를 햄버거 드롭다운으로 접음
       (no-JS는 위쪽 기존 768px 블록의 줄바꿈 nav가 폴백으로 유지됨) */
    .nav-js .header-content {
        flex-direction: row;
        gap: 0.5rem;
    }

    .nav-js .nav-toggle {
        display: inline-flex;
    }

    .nav-js .nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
        padding: 0.6rem 1.25rem 1rem;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        border-bottom: 1px solid var(--border-color);
        box-shadow: var(--shadow-lg);
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-0.5rem);
        transition: max-height 0.3s ease, opacity 0.2s ease, transform 0.2s ease, visibility 0.3s;
    }

    .nav-js .nav.open {
        max-height: 80vh;
        overflow-y: auto;
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    .nav-js .nav .nav-link {
        width: 100%;
        padding: 0.85rem 1rem;
        border-radius: var(--border-radius);
    }

    /* theme-toggle.js 가 nav 안에 주입하는 다크모드 버튼: 드롭다운에서 전체폭 */
    .nav-js .nav .theme-toggle {
        width: 100%;
        margin-left: 0 !important;
        margin-top: 0.35rem;
        justify-content: center;
    }
}
