/* ─── Cup26 design system ─────────────────────────────────────────── */
:root {
  --bg: #081120;
  --bg-elev: #0e1c33;
  --bg-elev2: #14263f;
  --line: #1d3354;
  --line-soft: #16294a;
  --text: #e8eef7;
  --text-dim: #93a5bf;
  --text-faint: #5f7393;
  --accent: #2dd4bf;
  --accent-2: #34d399;
  --accent-grad: linear-gradient(90deg, #2dd4bf, #34d399);
  --live: #f87171;
  --gold: #fbbf24;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 28px rgba(2, 8, 20, 0.55);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(45, 212, 191, 0.07), transparent 60%),
    radial-gradient(900px 420px at -10% 0%, rgba(52, 153, 211, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ─── Header ──────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(8, 17, 32, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
  padding-top: env(safe-area-inset-top);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { border-radius: 9px; flex: none; }
.brand-text h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0.2px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-text p { margin: 0; font-size: 11px; color: var(--text-faint); white-space: nowrap; }

.tz-switch {
  display: flex;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.tz-switch button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.tz-switch button.active {
  background: var(--accent-grad);
  color: #06281f;
}

.tabs {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  gap: 4px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 14.5px;
  font-weight: 600;
  padding: 10px 14px 12px;
  position: relative;
}
.tab.active { color: var(--text); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent-grad);
}

/* ─── Layout ──────────────────────────────────────────────────────── */
main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 14px 16px 28px; }
.view[hidden] { display: none; }

/* ─── Toolbar ─────────────────────────────────────────────────────── */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.chip-row { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  transition: all 0.15s;
}
.chip.active { background: var(--accent-grad); border-color: transparent; color: #06281f; }
.chip[data-filter="live"].has-live:not(.active) { border-color: var(--live); color: var(--live); }

.search-row { display: flex; gap: 8px; }
#team-search {
  flex: 1;
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  padding: 9px 13px;
  outline: none;
}
#team-search:focus { border-color: var(--accent); }
#team-search::placeholder { color: var(--text-faint); }
#group-filter {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  padding: 9px 10px;
  max-width: 175px;
  outline: none;
}

/* ─── Match list ──────────────────────────────────────────────────── */
.day-header {
  position: sticky;
  top: calc(101px + env(safe-area-inset-top));
  z-index: 10;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-dim);
  background: rgba(8, 17, 32, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 10px 4px 8px;
  margin: 10px 0 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.day-header .day-count { font-weight: 500; color: var(--text-faint); text-transform: none; letter-spacing: 0; }

.match-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 10px; }

.match-card {
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  transition: border-color 0.15s, transform 0.1s;
  cursor: pointer;
}
.match-card:hover { border-color: var(--line); transform: translateY(-1px); }
.match-card.is-live { border-color: rgba(248, 113, 113, 0.55); box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.25); }

.mc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--text-faint); }
.mc-stage { font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--text-dim); }
.mc-status { font-weight: 700; }
.mc-status.live { color: var(--live); animation: pulse 1.6s ease-in-out infinite; }
.mc-status.ft { color: var(--text-dim); }
@keyframes pulse { 50% { opacity: 0.45; } }

.mc-teams { display: flex; flex-direction: column; gap: 7px; }
.mc-row { display: flex; align-items: center; gap: 10px; }
.mc-flag { font-size: 22px; line-height: 1; width: 26px; text-align: center; flex: none; }
.mc-name { font-size: 15.5px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-name.tbd { color: var(--text-faint); font-weight: 500; font-size: 14px; }
.mc-name.winner { color: var(--text); }
.mc-name.loser { color: var(--text-dim); }
.mc-score { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; width: 24px; text-align: right; flex: none; }
.mc-time {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  align-self: center;
  white-space: nowrap;
}
.mc-center { display: flex; align-items: center; gap: 12px; }
.mc-center .mc-teams { flex: 1; min-width: 0; }

.mc-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--line-soft);
  padding-top: 9px;
  font-size: 12px;
  color: var(--text-faint);
}
.mc-venue { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-tv { display: flex; gap: 5px; flex: none; }
.tv-badge {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 2.5px 7px;
  border-radius: 5px;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  white-space: nowrap;
}
.tv-badge.en { color: #7dd3fc; }
.tv-badge.es { color: #fda4af; }

.empty-state { text-align: center; color: var(--text-faint); padding: 56px 16px; font-size: 14.5px; }

/* ─── Groups ──────────────────────────────────────────────────────── */
.groups-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; }
.group-card { background: var(--bg-elev); border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; }
.group-card h3 {
  margin: 0;
  padding: 11px 14px;
  font-size: 13.5px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--bg-elev2);
  border-bottom: 1px solid var(--line-soft);
}
.group-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.group-table th {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  font-weight: 600;
  padding: 7px 6px;
  text-align: center;
}
.group-table th:first-child { text-align: left; padding-left: 14px; }
.group-table td { padding: 8px 6px; text-align: center; font-variant-numeric: tabular-nums; color: var(--text-dim); border-top: 1px solid var(--line-soft); }
.group-table td.team-cell { text-align: left; padding-left: 14px; color: var(--text); font-weight: 600; white-space: nowrap; }
.group-table td.pts { color: var(--text); font-weight: 800; }
.group-table tr.q1 td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.group-table tr.q3 td:first-child { box-shadow: inset 3px 0 0 var(--gold); }

/* ─── Bracket ─────────────────────────────────────────────────────── */
.bracket-scroll { overflow-x: auto; padding-bottom: 12px; -webkit-overflow-scrolling: touch; }
.bracket { display: flex; gap: 18px; min-width: max-content; padding: 6px 2px; }
.bracket-round { display: flex; flex-direction: column; gap: 10px; width: 215px; }
.bracket-round-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
  text-align: center;
  padding: 4px 0 6px;
  position: sticky;
  top: 0;
}
.bracket-round-matches { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }
.bracket-round-matches.center { justify-content: center; }
.bracket-round-matches.center .bracket-round-title { padding-top: 18px; }
.bk-match {
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.bk-match:hover { border-color: var(--line); }
.bk-match.final-match { border-color: rgba(251, 191, 36, 0.4); box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.18); }
.bk-meta { font-size: 10px; color: var(--text-faint); display: flex; justify-content: space-between; gap: 6px; }
.bk-team { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; }
.bk-team .mc-flag { font-size: 16px; width: 20px; }
.bk-team .bk-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bk-team.tbd .bk-name { color: var(--text-faint); font-weight: 500; font-size: 12px; }
.bk-team .bk-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.bk-team.winner .bk-name, .bk-team.winner .bk-score { color: var(--accent); }

/* ─── Modal ───────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal { align-items: center; } }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 8, 18, 0.72); }
.modal-card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
@media (min-width: 640px) { .modal-card { border-radius: 18px; } }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  border: 0;
  background: var(--bg-elev2);
  color: var(--text-dim);
  width: 30px; height: 30px;
  border-radius: 999px;
  font-size: 15px;
  line-height: 1;
}
.md-stage { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-faint); margin: 0 0 14px; }
.md-teams { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 6px 0 16px; }
.md-team { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.md-team .flag { font-size: 42px; line-height: 1; }
.md-team .name { font-size: 14.5px; font-weight: 700; }
.md-mid { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.md-mid.upcoming { font-size: 19px; color: var(--accent); }
.md-sub { text-align: center; color: var(--text-dim); font-size: 13px; margin: -8px 0 16px; }
.md-rows { display: flex; flex-direction: column; border-top: 1px solid var(--line-soft); }
.md-row { display: flex; justify-content: space-between; gap: 14px; padding: 10px 2px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; }
.md-row .k { color: var(--text-faint); flex: none; }
.md-row .v { color: var(--text); text-align: right; font-weight: 500; }

/* ─── Footer ──────────────────────────────────────────────────────── */
.app-footer {
  border-top: 1px solid var(--line-soft);
  color: var(--text-faint);
  font-size: 11.5px;
  text-align: center;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.dot-sep { opacity: 0.5; }
.fine-print { color: var(--text-faint); font-size: 12px; margin: 14px 2px 0; line-height: 1.5; }

/* ─── Small screens ───────────────────────────────────────────────── */
@media (max-width: 540px) {
  .brand-text p { display: none; }
  .match-cards { grid-template-columns: 1fr; }
  .day-header { top: calc(96px + env(safe-area-inset-top)); }
}
