:root {
    --brand: #C8102E;
    --brand-dark: #9B0E24;
    --brand-light: #E8334D;
    --navy: #002B5C;
    --gold: #D4A843;
    --bg: #FAFAF8;
    --fg: #1A1A1A;
    --muted-bg: #F3F2EF;
    --muted-fg: #6B6B6B;
    --border: #E5E3DE;
    --card: #FFFFFF;
    --success: #2D8A4E;
    --danger: #C8102E;
    --warning: #D4A843;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.08);
    --radius-sm: 4px;
    --radius-md: 6px;
    --transition: all 0.15s ease-out;
    --font-display: "Inter", "Noto Sans SC", -apple-system, sans-serif;
    --font-body: "Inter", "Noto Sans SC", -apple-system, "Helvetica Neue", sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", "Menlo", monospace;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-wrap: pretty;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--fg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }
@media (min-width: 768px) { .container { padding: 0 32px; } }

/* ─── Header ─── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.header-content { display: flex; align-items: center; justify-content: space-between; height: 56px; }

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
    color: var(--fg);
}

.logo-icon {
    background: var(--brand);
    padding: 2px 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.nav-desktop { display: none; gap: 2px; }
@media (min-width: 768px) { .nav-desktop { display: flex; } }

.nav-link {
    padding: 6px 14px;
    font-weight: 500;
    font-size: 0.88rem;
    color: var(--muted-fg);
    transition: var(--transition);
}

.nav-link:hover { color: var(--fg); }
.nav-link.active { color: var(--brand); font-weight: 600; }

/* ─── Lang Toggle ─── */
.header-right { display: flex; align-items: center; gap: 8px; }
.lang-toggle {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 8px;
    border: 1px solid var(--border);
    background: none;
    cursor: pointer;
    color: var(--muted-fg);
    letter-spacing: 0.04em;
    transition: var(--transition);
}
.lang-toggle:hover { color: var(--brand); border-color: var(--brand); }

/* ─── Mobile ─── */
.menu-toggle { display: flex; flex-direction: column; gap: 5px; padding: 8px; background: none; border: none; cursor: pointer; }
.menu-toggle span { display: block; width: 20px; height: 1.5px; background: var(--fg); transition: var(--transition); }
@media (min-width: 768px) { .menu-toggle { display: none; } }

.mobile-menu { display: none; position: fixed; top: 56px; left: 0; right: 0; bottom: 0; background: var(--card); z-index: 99; padding: 20px; }
.mobile-menu.active { display: block; }
.mobile-nav { display: flex; flex-direction: column; gap: 4px; }
.mobile-nav-link { padding: 14px 16px; font-weight: 500; color: var(--muted-fg); transition: var(--transition); }
.mobile-nav-link:hover { color: var(--brand); }

/* ─── Main ─── */
.main { flex: 1; }

/* ─── Hero ─── */
.hero {
    background: var(--navy);
    color: white;
    padding: 56px 0 64px;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--brand);
}

.hero-title {
    font-family: var(--font-display);
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 12px;
    line-height: 1.15;
}

.hero-subtitle {
    font-size: 1rem;
    opacity: 0.55;
    margin-bottom: 28px;
    max-width: 480px;
}

.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

@media (min-width: 768px) {
    .hero { padding: 80px 0 88px; }
    .hero-title { font-size: 3rem; }
    .hero-subtitle { font-size: 1.05rem; }
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 22px;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-dark); }

.btn-secondary { background: rgba(255,255,255,0.08); color: white; border: 1px solid rgba(255,255,255,0.15); }
.btn-secondary:hover { background: rgba(255,255,255,0.12); }

.btn-text { background: none; color: var(--brand); padding: 6px 14px; font-size: 0.85rem; font-weight: 600; }
.btn-text:hover { opacity: 0.7; }

/* ─── Sections ─── */
.section { padding: 48px 0; }

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

.section-title {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-indicator {
    width: 8px;
    height: 8px;
    background: var(--brand);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ─── Stats ─── */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 768px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
    background: var(--card);
    padding: 20px;
    border: 1px solid var(--border);
    text-align: center;
    transition: var(--transition);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--brand);
    letter-spacing: -0.02em;
    margin-bottom: 2px;
}

.stat-label {
    color: var(--muted-fg);
    font-size: 0.78rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font-mono);
}

/* ─── Cards ─── */
.matches-grid, .news-grid, .tournaments-grid { display: grid; gap: 12px; }
@media (min-width: 768px) {
    .matches-grid { grid-template-columns: repeat(2, 1fr); }
    .news-grid { grid-template-columns: repeat(3, 1fr); }
    .tournaments-grid { grid-template-columns: repeat(2, 1fr); }
}

.match-card {
    background: var(--card);
    padding: 16px;
    border: 1px solid var(--border);
    transition: var(--transition);
}

.match-card:hover { border-color: var(--brand); }
.match-live { border-left: 3px solid var(--brand); }

.match-header { display: flex; justify-content: space-between; margin-bottom: 14px; font-size: 0.8rem; }

.match-type {
    color: var(--brand);
    font-weight: 600;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.match-round { color: var(--muted-fg); }

.match-players { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.player { flex: 1; text-align: center; }
.player-name { font-weight: 600; font-size: 0.95rem; display: block; margin-bottom: 3px; }
.player-country { font-size: 0.8rem; color: var(--muted-fg); }

.match-score {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--navy);
    min-width: 70px;
    text-align: center;
}

.match-footer { margin-top: 14px; text-align: center; }
.live-badge { color: var(--brand); font-weight: 600; font-size: 0.8rem; }

/* ─── News ─── */
.news-card { background: var(--card); overflow: hidden; border: 1px solid var(--border); transition: var(--transition); }
.news-card:hover { box-shadow: var(--shadow-md); }
.news-image { aspect-ratio: 16/9; overflow: hidden; }
.news-image img { width: 100%; height: 100%; object-fit: cover; transition: var(--transition); }
.news-card:hover .news-image img { transform: scale(1.03); }
.news-content { padding: 16px; }
.news-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 8px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.news-summary { font-size: 0.85rem; color: var(--muted-fg); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ─── Tournament Card ─── */
.tournament-card { background: var(--card); padding: 16px; border: 1px solid var(--border); transition: var(--transition); }
.tournament-card:hover { border-color: var(--brand); }
.tournament-card.tournament-active { border-color: var(--brand); }

.tournament-link { display: flex; align-items: center; gap: 14px; }
.tournament-flag { font-size: 1.5rem; }
.tournament-info { flex: 1; }
.tournament-name { font-family: var(--font-display); font-size: 0.95rem; font-weight: 600; margin-bottom: 4px; }
.tournament-meta { font-size: 0.82rem; color: var(--muted-fg); display: flex; gap: 10px; }

.tournament-status {
    font-size: 0.72rem;
    font-family: var(--font-mono);
    font-weight: 600;
    padding: 3px 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.status-upcoming { background: var(--muted-bg); color: var(--muted-fg); }
.status-ongoing { background: rgba(200,16,46,0.08); color: var(--brand); }
.status-completed { background: var(--muted-bg); color: var(--muted-fg); }

/* ─── Rankings ─── */
.rankings-tabs { display: flex; gap: 2px; margin-bottom: 20px; overflow-x: auto; padding-bottom: 8px; }

.tab-btn {
    padding: 7px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
    color: var(--muted-fg);
    letter-spacing: 0.02em;
}

.tab-btn:hover { color: var(--fg); }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

.rankings-table-wrapper { background: var(--card); overflow: hidden; border: 1px solid var(--border); }
.rankings-table { width: 100%; border-collapse: collapse; }
.rankings-table th, .rankings-table td { padding: 14px 16px; text-align: left; }

.rankings-table th {
    background: var(--muted-bg);
    font-weight: 600;
    font-size: 0.72rem;
    color: var(--muted-fg);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font-mono);
}

.rankings-table td { border-top: 1px solid var(--border); }

.rank-cell { display: flex; align-items: center; gap: 8px; }
.rank-number { font-family: var(--font-mono); font-weight: 700; font-size: 1rem; }
.rank-up { color: var(--success); font-size: 0.7rem; font-weight: 600; }
.rank-down { color: var(--brand); font-size: 0.7rem; font-weight: 600; }
.rank-same { color: var(--muted-fg); font-size: 0.7rem; }
.player-cell { font-weight: 500; }
.country-cell { color: var(--muted-fg); font-size: 0.9rem; }
.points-cell { font-family: var(--font-mono); font-weight: 600; color: var(--navy); font-size: 0.9rem; }

/* ─── Loading ─── */
.loading-state { text-align: center; padding: 48px; color: var(--muted-fg); }
.loading-cell { text-align: center; padding: 48px; }

.loading-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 14px;
}

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

.empty-state { text-align: center; padding: 48px; color: var(--muted-fg); }
.empty-cell { text-align: center; padding: 24px; color: var(--muted-fg); }

/* ─── Footer ─── */
.footer {
    background: var(--navy);
    color: rgba(255,255,255,0.5);
    padding: 40px 0;
    margin-top: auto;
}

.footer-content { text-align: center; }

.footer-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    color: white;
    margin-bottom: 8px;
}

.footer-text { margin-bottom: 20px; font-size: 0.85rem; }
.footer-links { display: flex; justify-content: center; gap: 24px; margin-bottom: 20px; }
.footer-links a { transition: var(--transition); font-size: 0.85rem; }
.footer-links a:hover { color: white; }
.footer-copyright { font-size: 0.75rem; font-family: var(--font-mono); opacity: 0.4; }

/* ─── Overlay & Toast ─── */
.loading-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(250,250,248,0.92); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.loading-overlay.active { display: flex; }

.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 1001; display: flex; flex-direction: column; gap: 8px; }

.toast { background: var(--card); padding: 14px 20px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Page Header ─── */
.page-header {
    background: #eef2f7;
    color: var(--navy);
    padding: 36px 0;
    position: relative;
}

.page-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--brand);
}

.page-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.page-subtitle { color: rgba(0,43,92,0.5); font-size: 0.9rem; margin-top: 4px; }

/* ─── Filters ─── */
.filters { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

.filter-select {
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--card);
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--fg);
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    font-family: var(--font-body);
    font-size: 0.85rem;
}

/* ─── Pagination ─── */
.pagination { display: flex; justify-content: center; gap: 6px; margin-top: 28px; }

.page-btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    background: var(--card);
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    color: var(--muted-fg);
}

.page-btn:hover, .page-btn.active { background: var(--brand); color: white; border-color: var(--brand); }

/* ─── Detail ─── */
.detail-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 8px;
}

.detail-meta { color: rgba(255,255,255,0.55); display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.9rem; }

.detail-content { background: var(--card); padding: 28px; border: 1px solid var(--border); }

/* ─── Inverted Section ─── */
.section-inverted { background: var(--navy); color: white; padding: 48px 0; }
.section-inverted .section-title { color: white; }
.section-inverted .btn-text { color: rgba(255,255,255,0.6); }
.section-inverted .btn-text:hover { color: white; }
.section-inverted .stat-card { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }
.section-inverted .stat-value { color: white; }
.section-inverted .stat-label { color: rgba(255,255,255,0.5); }

/* ─── Players Grid ─── */
.players-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 768px) { .players-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .players-grid { grid-template-columns: repeat(4, 1fr); } }

/* ─── Tournament List ─── */
.tournaments-list { display: flex; flex-direction: column; gap: 8px; }
.tournament-list-item { }

/* ─── Matches List ─── */
.matches-list { display: flex; flex-direction: column; gap: 0; }

/* ─── Responsive ─── */
@media (max-width: 767px) {
    .rankings-table th, .rankings-table td { padding: 10px 8px; font-size: 0.85rem; }
    .match-players { flex-direction: column; gap: 10px; }
    .match-score { order: -1; }
    .detail-meta { font-size: 0.82rem; }
}

/* ─── H2H Modal ─── */
.h2h-modal-overlay { display: none; position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; }
.h2h-modal-overlay.active { display: flex; }
.h2h-modal { background: var(--card); border-radius: var(--radius-md); width: 90%; max-width: 520px; max-height: 80vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.h2h-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.h2h-modal-title { font-weight: 700; font-size: 0.95rem; color: var(--navy); }
.h2h-modal-close { background: none; border: none; font-size: 1.4rem; color: var(--muted-fg); cursor: pointer; padding: 0 4px; line-height: 1; }
.h2h-modal-close:hover { color: var(--brand); }
.h2h-modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.h2h-loading { text-align: center; padding: 24px 0; }
.h2h-empty { text-align: center; color: var(--muted-fg); padding: 24px 0; }
.h2h-summary { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; margin-bottom: 12px; border-bottom: 2px solid var(--border); }
.h2h-player { text-align: center; flex: 1; }
.h2h-pname { font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }
.h2h-pwins { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; }
.h2h-p1 .h2h-pwins { color: var(--brand); }
.h2h-p2 .h2h-pwins { color: var(--navy); }
.h2h-vs { font-size: 0.75rem; color: var(--muted-fg); padding: 0 8px; white-space: nowrap; }
.h2h-match-list { display: flex; flex-direction: column; gap: 6px; }
.h2h-match-row { padding: 8px 0; border-bottom: 1px solid var(--border); }
.h2h-match-info { display: flex; gap: 8px; margin-bottom: 4px; font-size: 0.72rem; color: var(--muted-fg); }
.h2h-match-tournament { font-weight: 500; }
.h2h-match-score { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.h2h-side1 { flex: 1; text-align: right; font-weight: 500; }
.h2h-side2 { flex: 1; font-weight: 500; }
.h2h-score-val { font-family: var(--font-mono); font-weight: 700; color: var(--brand); white-space: nowrap; }
.h2h-win { font-weight: 700; color: var(--brand); }
.h2h-link { display: inline-block; font-size: 0.68rem; font-family: var(--font-mono); color: var(--navy); cursor: pointer; padding: 1px 4px; border-radius: 2px; transition: var(--transition); text-decoration: none; }
.h2h-link:hover { background: rgba(0,43,92,0.08); }
.h2h-source { font-size: 0.68rem; color: var(--muted-fg); text-align: center; margin-bottom: 8px; font-family: var(--font-mono); }
.tournaments-section-title { font-size: 0.92rem; font-weight: 700; color: var(--navy); margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--border); }
.tournaments-history-toggle { cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: space-between; color: var(--muted-fg); }
.tournaments-history-toggle:hover { color: var(--brand); }
.toggle-arrow { font-size: 0.72rem; }
.player-detail-header { display: flex; align-items: center; gap: 20px; }
.player-avatar-large { width: 100px; height: 100px; border-radius: 50%; overflow: hidden; background: var(--muted-bg); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.player-avatar-large img { width: 100%; height: 100%; object-fit: cover; }
.avatar-placeholder { font-size: 2.5rem; font-weight: 700; color: var(--navy); }
.player-detail-info { flex: 1; }
.detail-title { font-size: 1.4rem; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.detail-meta { display: flex; gap: 12px; font-size: 0.85rem; color: var(--muted-fg); margin-bottom: 12px; }
.detail-stats-row { display: flex; gap: 20px; }
.mini-stat { text-align: center; }
.mini-stat-val { font-family: var(--font-mono); font-size: 1.2rem; font-weight: 700; color: var(--navy); }
.mini-stat-label { font-size: 0.7rem; color: var(--muted-fg); }
.tmt-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 16px; margin-bottom: 8px; }
.tmt-card-header { display: flex; align-items: center; gap: 10px; }
.tmt-logo { width: 28px; height: 28px; object-fit: contain; }
.tmt-card-name { font-weight: 600; font-size: 0.88rem; color: var(--navy); }
.tmt-card-meta { font-size: 0.72rem; color: var(--muted-fg); }
.tmt-card-draws { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.draw-stat { display: flex; align-items: center; gap: 6px; background: var(--muted-bg); padding: 3px 8px; border-radius: 4px; font-size: 0.75rem; }
.draw-name { font-weight: 500; }
.draw-record { font-family: var(--font-mono); color: var(--brand); font-weight: 600; }
.match-row { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.match-row.is-win { border-left: 3px solid var(--success); }
.match-row.is-loss { border-left: 3px solid var(--danger); }
.match-row-left { width: 140px; flex-shrink: 0; }
.match-row-tmt { font-weight: 500; font-size: 0.78rem; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.match-row-round { font-size: 0.68rem; color: var(--muted-fg); }
.match-row-center { flex: 1; display: flex; align-items: center; gap: 8px; }
.match-row-center span:first-child { flex: 1; text-align: right; }
.match-row-center span:last-child { flex: 1; }
.match-row-score { font-family: var(--font-mono); font-weight: 700; color: var(--brand); white-space: nowrap; }
.match-row-right { display: flex; align-items: center; gap: 6px; width: 60px; justify-content: flex-end; }
.match-duration { font-size: 0.7rem; color: var(--muted-fg); font-family: var(--font-mono); }
.winner { font-weight: 700; color: var(--success); }
.result-w { font-weight: 700; color: var(--success); font-family: var(--font-mono); }
.result-l { font-weight: 700; color: var(--danger); font-family: var(--font-mono); }
