:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e7eaf3;
  --text: #1a1f36;
  --muted: #6b7393;
  --accent: #2f6bff;
  --live: #ff3d6e;
  --green: #16a34a;
  --amber: #f59e0b;
  --shadow: 0 1px 3px rgba(26, 31, 54, 0.06), 0 8px 24px rgba(26, 31, 54, 0.05);
  --shadow-hover: 0 4px 12px rgba(26, 31, 54, 0.08), 0 16px 40px rgba(26, 31, 54, 0.08);
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-mark {
  font-size: 24px;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-accent { color: var(--accent); }

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: white;
  background: var(--accent);
  border: none;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

#refresh-btn:hover { filter: brightness(1.08); }
#refresh-btn:active { transform: scale(0.96); }

#refresh-btn.loading svg {
  animation: spin 0.7s linear infinite;
}

#refresh-btn:disabled { opacity: 0.7; cursor: default; }

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.tabs {
  position: sticky;
  top: 65px;
  z-index: 9;
  max-width: 880px;
  margin: 0 auto;
  padding: 14px 20px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.tab-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  background: var(--live);
  color: white;
}

.tab.active .tab-count { background: rgba(255, 255, 255, 0.25); }

.tab-panel { display: none; animation: rise 0.35s ease both; }
.tab-panel.active { display: block; }

.sub-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 22px 0 12px;
}
.sub-head:first-child { margin-top: 0; }
.live-head { color: var(--live); }
.live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 1.4s infinite;
}

.match-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  animation: rise 0.4s ease both;
  cursor: pointer;
}

.match-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.match-card.live {
  border-color: rgba(255, 61, 110, 0.35);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.stage-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  padding: 3px 9px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 61, 110, 0.1);
  color: var(--live);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 6px;
}

.live-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 1.4s infinite;
}

.team-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.team-name {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 15px;
}

.crest {
  width: 22px;
  height: 22px;
  object-fit: contain;
  border-radius: 3px;
}

.team-score {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}

.team-row.winner .team-score { color: var(--green); }
.team-row.winner .team-name { color: var(--text); }

.scorers {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 3px 0 0 31px;
  font-size: 11px;
  color: var(--muted);
}

/* --- Standings tables --- */
.standings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.group-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.group-table h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 14px;
}
.group-table table { width: 100%; border-collapse: collapse; }
.group-table th {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  padding: 4px 3px;
}
.group-table td {
  font-size: 13px;
  text-align: center;
  padding: 5px 3px;
  border-top: 1px solid var(--border);
}
.group-table td.pos { color: var(--muted); width: 18px; }
.group-table td.t {
  text-align: left;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
}
.group-table td.t img { width: 18px; height: 18px; object-fit: contain; }
.group-table td.pts { font-weight: 700; color: var(--accent); }

.group-results {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.group-results-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.mini-result {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  padding: 5px 0;
  cursor: pointer;
  border-radius: 8px;
}
.mini-result:hover { background: var(--bg); }
.mini-result .mr-team {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.mini-result .mr-team.away { flex-direction: row-reverse; text-align: right; }
.mini-result img { width: 16px; height: 16px; object-fit: contain; }
.mini-result .mr-score {
  font-family: var(--font-display);
  font-weight: 700;
  min-width: 42px;
  text-align: center;
}
.mr-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mr-win { color: var(--green); }

/* --- Match detail modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  background: rgba(15, 20, 40, 0.5);
  backdrop-filter: blur(4px);
  overflow-y: auto;
}
.modal.open { display: flex; animation: fade 0.2s ease; }
.modal-card {
  background: var(--surface);
  border-radius: 18px;
  max-width: 560px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow-hover);
  position: relative;
  animation: rise 0.25s ease both;
}
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  border: none;
  background: var(--bg);
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.modal-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
}
.modal-team img { width: 44px; height: 44px; object-fit: contain; }
.modal-score {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
}
.modal-sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}
.modal-info {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 10px;
  background: var(--bg);
  border-radius: 10px;
  margin-bottom: 16px;
}
.modal-card h3 {
  font-family: var(--font-display);
  font-size: 14px;
  margin: 18px 0 10px;
}
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.tl-clock { color: var(--muted); min-width: 34px; font-weight: 600; }
.tl-icon { min-width: 18px; }
.lineups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.lineup-team { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.lineups ul { list-style: none; margin: 0; padding: 0; }
.lineups li { font-size: 12px; color: var(--muted); padding: 3px 0; }
.modal-loading { text-align: center; color: var(--muted); padding: 30px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card-time {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 14px;
  padding: 18px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 20px;
}

@media (max-width: 520px) {
  .header-inner { padding: 14px 16px; }
  main { padding: 22px 16px 48px; }
  .match-list {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .brand h1 { font-size: 18px; }
  .section-head h2 { font-size: 16px; }
  .match-card { padding: 16px; border-radius: 14px; }
  .team-name { font-size: 14px; }
  .team-score { font-size: 18px; }
  .standings-grid { grid-template-columns: 1fr; }
  .modal-card { padding: 18px; }
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 61, 110, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(255, 61, 110, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 61, 110, 0); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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