:root {
  --bg: #0c1220;
  --bg-card: #141c2e;
  --bg-elevated: #1a2438;
  --border: #2a3650;
  --text: #e8edf5;
  --text-muted: #8b9bb8;
  --accent: #00a651;
  --accent-gold: #f5c518;
  --accent-blue: #3b82f6;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: 'DM Sans', system-ui, sans-serif;
}

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

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(0, 166, 81, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(59, 130, 246, 0.08) 0%, transparent 50%);
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  background: rgba(20, 28, 46, 0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header.compact { padding: 0.75rem 0; }

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

.brand { display: flex; align-items: center; gap: 1rem; }
.brand-icon { font-size: 2rem; }
.brand h1 { margin: 0; font-size: 1.35rem; font-weight: 700; }
.subtitle { margin: 0.15rem 0 0; color: var(--text-muted); font-size: 0.85rem; }

.header-actions { display: flex; align-items: center; gap: 1rem; }
.meta-text { color: var(--text-muted); font-size: 0.8rem; }

.back-link { color: var(--text); font-weight: 500; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #008040);
  color: #fff;
}

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

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.82rem; }

.btn-icon { display: inline-block; transition: transform 0.5s; }
.btn.loading .btn-icon { animation: spin 1s linear infinite; }

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

.tabs {
  display: flex;
  gap: 0.25rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem 0;
  overflow-x: auto;
}

.tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 1rem;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-gold); border-bottom-color: var(--accent-gold); }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.panel { display: none; }
.panel.active { display: block; }

.panel-title { font-size: 1.2rem; margin: 0 0 1rem; font-weight: 600; }
.panel-title .meta-text { font-size: 0.85rem; font-weight: 400; }
.day-heading {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-gold);
  margin: 1.25rem 0 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
.day-heading:first-child { margin-top: 0; }
.section-subtitle { font-size: 1rem; margin: 2rem 0 1rem; color: var(--text-muted); }

.loading, .error-banner, .refresh-status {
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.loading { background: var(--bg-card); text-align: center; color: var(--text-muted); }
.error-banner { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--danger); color: #fca5a5; }
.refresh-status { background: rgba(0, 166, 81, 0.12); border: 1px solid var(--accent); color: #86efac; }
.hidden { display: none !important; }

.filter-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.filter-row label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.filter-row input, .filter-row select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  font-family: inherit;
}

.match-list { display: flex; flex-direction: column; gap: 0.75rem; }

.match-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.match-card.finished { border-left: 3px solid var(--accent); }
.match-card.scheduled { border-left: 3px solid var(--accent-blue); }

.match-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.match-meta .stage-badge {
  background: var(--bg-elevated);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  color: var(--accent-gold);
}

.match-body {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}

.team-side {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.team-side.away { flex-direction: row-reverse; text-align: right; }

.team-flag { width: 32px; height: 22px; object-fit: cover; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.team-flag.placeholder { background: var(--bg-elevated); }

.team-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
}

.team-name:hover { color: var(--accent-gold); }

.score-block { text-align: center; min-width: 80px; }
.score { font-size: 1.6rem; font-weight: 700; letter-spacing: 0.05em; }
.score.vs { font-size: 1rem; color: var(--text-muted); font-weight: 500; }

.goals-list {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  line-height: 1.4;
}

.match-details {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

.venue-line {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.venue-flag {
  width: 20px;
  height: 14px;
  object-fit: cover;
  border-radius: 2px;
  vertical-align: middle;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.nat-flag {
  width: 20px;
  height: 14px;
  object-fit: cover;
  border-radius: 2px;
  vertical-align: -2px;
  margin-right: 0.15rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.referee-line {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.2rem;
}

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

.group-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.group-header {
  background: var(--bg-elevated);
  padding: 0.6rem 1rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent-gold);
}

.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.standings-table th, .standings-table td {
  padding: 0.45rem 0.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.standings-table th:first-child, .standings-table td:first-child { text-align: left; padding-left: 0.75rem; }

.standings-table tr:hover { background: rgba(255,255,255,0.03); }

.standings-team {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.standings-team img { width: 20px; height: 14px; object-fit: cover; border-radius: 1px; }

.knockout-bracket {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.bracket-flow {
  display: flex;
  gap: 1.5rem;
  min-width: max-content;
}

.bracket-col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 160px;
}

.bracket-col h4 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bracket-slot {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.bracket-slot.highlight { color: var(--text); border-color: var(--accent); }

.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.site-footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* Team page */
.team-page { padding-top: 1rem; }

.team-hero {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.team-flag-wrap {
  flex-shrink: 0;
  width: 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  background: var(--bg-elevated);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.team-flag-lg {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
}

.team-hero h1 { margin: 0; font-size: 1.75rem; }
.coach-info {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.2rem;
}
.coach-source { font-size: 0.78rem; color: var(--text-muted); }

.team-section { margin-bottom: 2rem; }
.team-section h2 { font-size: 1.1rem; margin-bottom: 1rem; }

.table-wrap {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.squad-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  background: var(--bg-card);
}

.squad-table thead th {
  background: var(--bg-elevated);
  padding: 0.65rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

.squad-sticky-head {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--team-sticky-top, 53px);
  z-index: 90;
  background: rgba(26, 36, 56, 0.98);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}

.squad-sticky-head.hidden { display: none; }

.squad-sticky-head-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  overflow: visible;
  will-change: transform;
}

.squad-table-head-clone {
  margin: 0;
  table-layout: fixed;
}

.squad-table-head-clone th {
  border-bottom: none;
}

.squad-table td {
  padding: 0.55rem 0.75rem;
  border-top: 1px solid var(--border);
}

.squad-table tr:hover { background: rgba(255,255,255,0.03); }

.pos-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.pos-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.squad-row.pos-gk { background: rgba(234, 179, 8, 0.07); }
.squad-row.pos-df { background: rgba(59, 130, 246, 0.07); }
.squad-row.pos-mf { background: rgba(0, 166, 81, 0.07); }
.squad-row.pos-fw { background: rgba(239, 68, 68, 0.07); }

.squad-row.pos-gk { box-shadow: inset 3px 0 0 #eab308; }
.squad-row.pos-df { box-shadow: inset 3px 0 0 #3b82f6; }
.squad-row.pos-mf { box-shadow: inset 3px 0 0 #00a651; }
.squad-row.pos-fw { box-shadow: inset 3px 0 0 #ef4444; }

.pos-badge.pos-gk { background: rgba(234, 179, 8, 0.2); color: #fde047; }
.pos-badge.pos-df { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.pos-badge.pos-mf { background: rgba(0, 166, 81, 0.2); color: #86efac; }
.pos-badge.pos-fw { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.pos-badge.pos-other { background: rgba(139, 155, 184, 0.2); color: var(--text-muted); }

.squad-row:hover { filter: brightness(1.08); }

.player-name { cursor: help; position: relative; font-weight: 500; }
.player-name-zh { color: var(--text-muted); font-size: 0.88em; margin-left: 0.4em; font-weight: 400; }
.player-name.captain::after { content: ' (C)'; color: var(--accent-gold); font-size: 0.75rem; }
.player-name.vice-captain::after { content: ' (VC)'; color: var(--text-muted); font-size: 0.75rem; }

.club-cell { display: flex; align-items: center; gap: 0.4rem; }
.club-flag { width: 18px; height: 12px; object-fit: cover; border-radius: 1px; }

.player-popup {
  position: fixed;
  z-index: 1000;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  box-shadow: var(--shadow);
  pointer-events: none;
  max-width: 200px;
}

.player-popup img {
  width: 180px;
  height: auto;
  border-radius: 6px;
  display: block;
}

.player-popup p {
  margin: 0.4rem 0 0;
  font-size: 0.82rem;
  text-align: center;
  font-weight: 500;
}

/* Statistics tab */
.stats-page { display: flex; flex-direction: column; gap: 1.5rem; }

.stats-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent-gold);
  line-height: 1.1;
}

.stat-label { font-size: 0.85rem; font-weight: 600; }
.stat-sub { font-size: 0.75rem; color: var(--text-muted); }

.stats-wiki-note {
  margin: 0;
  padding: 0.75rem 1rem;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

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

.stats-block-full { width: 100%; }

.stats-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  min-width: 0;
}

.stats-block-title {
  margin: 0 0 0.85rem;
  font-size: 1rem;
  font-weight: 600;
}

.stats-subtitle {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stats-table-wrap { overflow-x: auto; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stats-table th,
.stats-table td {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.stats-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stats-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }

.stats-table .rank-col { width: 2rem; color: var(--text-muted); white-space: nowrap; }
.stats-table .num-col { text-align: center; white-space: nowrap; }
.stats-table .min-col { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }
.stats-table .group-col { text-align: center; color: var(--text-muted); white-space: nowrap; width: 2.5rem; }

.stats-table .stats-team-col {
  white-space: nowrap;
  min-width: 8rem;
  max-width: 11rem;
}

.stats-team-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  vertical-align: middle;
}

.stats-team-inline .team-flag {
  flex-shrink: 0;
  width: 22px;
  height: 16px;
  object-fit: cover;
  border-radius: 2px;
}

.stats-team-inline .team-name {
  white-space: nowrap;
  font-size: 0.85rem;
}

.stats-table-scorers .stats-team-col { min-width: 9rem; }
.stats-table-standings .stats-team-col { min-width: 7.5rem; max-width: 10rem; }
.stats-table-standings { font-size: 0.8rem; }

.stats-match-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  overflow-x: auto;
}

.stats-match-team {
  flex: 0 0 auto;
  min-width: 0;
}

.stats-match-row .stats-team-inline .team-name { font-size: 0.8rem; }

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 1rem !important;
}

.stats-highlights {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.stats-match-list,
.stats-bar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.stats-score {
  font-weight: 700;
  color: var(--accent-gold);
  padding: 0 0.25rem;
}

.stats-bar-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.stats-bar-list strong { color: var(--accent); }

@media (max-width: 640px) {
  .stats-highlights { grid-template-columns: 1fr; }
  .stats-grid,
  .stats-grid-pair { grid-template-columns: 1fr; }
  .match-body { grid-template-columns: 1fr; text-align: center; }
  .team-side, .team-side.away { flex-direction: column; text-align: center; }
  .brand h1 { font-size: 1.1rem; }
}
