:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --accent: #4f6ef7;
  --accent2: #7c3aed;
  --gold: #f59e0b;
  --silver: #94a3b8;
  --bronze: #b45309;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --live: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: 72px; /* space for bottom nav */
}

/* ── Header ── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.app-header h1 span {
  color: var(--accent);
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.last-updated-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.last-updated {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.refresh-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

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

.refresh-btn svg {
  width: 13px;
  height: 13px;
}

.refresh-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

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

/* ── Language toggle ── */
.lang-toggle {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.lang-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

.lang-btn.lang-active {
  background: var(--accent);
  color: #fff;
}

/* ── Main content ── */
main {
  flex: 1;
  padding: 12px 12px 0;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 4px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: color 0.15s;
  min-width: 0;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.nav-btn.active {
  color: var(--accent);
}

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

.nav-btn.participant-tab {
  max-width: 120px;
  overflow: hidden;
}

.nav-btn .nav-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Views ── */
.view {
  display: none;
  animation: fadeIn 0.15s ease;
}

.view.active {
  display: block;
}

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

/* ── Section title ── */
.section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 16px 0 8px;
}

/* ── Standings table ── */
.standings-table {
  width: 100%;
  border-collapse: collapse;
}

.standings-table th {
  text-align: left;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.standings-table th.num { width: 32px; text-align: center; }
.standings-table th.pts,
.standings-table th.cor,
.standings-table th.exct { width: 44px; text-align: center; }

.standings-row {
  cursor: pointer;
  transition: background 0.1s;
}

.standings-row:hover {
  background: var(--surface2);
}

.standings-row td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.standings-row td.rank {
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  width: 32px;
}

.standings-row td.pts {
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
}

.standings-row td.cor,
.standings-row td.exct {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.rank-1 { color: var(--gold); }
.rank-2 { color: var(--silver); }
.rank-3 { color: var(--bronze); }

.medal {
  font-size: 1rem;
}

/* ── Group score cards ── */
.group-section {
  margin-bottom: 16px;
}

.group-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 0 6px;
}

.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.match-team {
  font-size: 0.85rem;
  font-weight: 600;
}

.match-team.home {
  text-align: right;
}

.match-team.away {
  text-align: left;
}

.match-center {
  text-align: center;
  min-width: 64px;
}

.match-score {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.match-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge-live {
  background: var(--live);
  color: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}

.badge-ht {
  background: var(--yellow);
  color: #000;
}

.badge-ft {
  background: var(--surface2);
  color: var(--text-muted);
}

.badge-sched {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

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

/* ── Participant drill-down ── */
.back-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  transition: background 0.15s;
}

.back-btn:hover { background: var(--surface2); }

.participant-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.participant-header .p-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.participant-header .p-stats {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.p-sep {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  margin: 2px 4px;
}

.p-op .val {
  color: var(--text-muted);
  font-weight: 400;
}

.p-stat-rank {
  margin-left: auto;
}

.p-stat {
  text-align: center;
}

.p-stat .val {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.p-stat .lbl {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.drill-table {
  width: 100%;
  border-collapse: collapse;
}

.drill-table th {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.drill-table td {
  padding: 7px 3px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  text-align: center;
  vertical-align: middle;
}

/* Flag cells */
.drill-table .td-flag {
  width: 1.5rem;
  padding: 7px 2px;
  text-align: center;
}
.drill-table .td-flag .fi {
  width: 1.2em;
  height: 0.9em;
  display: inline-block;
  background-size: cover;
  vertical-align: middle;
}

/* Team name cells */
.drill-table .td-team {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drill-table .td-home { text-align: right; padding-right: 4px; }
.drill-table .td-away { text-align: left;  padding-left: 4px; }

/* Group badge inline under team name */
.drill-table .td-grp {
  display: block;
  font-size: 0.6rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* Predicted score and dash */
.drill-table .td-score {
  font-size: 0.88rem;
  width: 1.2rem;
  text-align: center;
  padding: 7px 2px;
}
.drill-table .score-win  { font-weight: 700; }
.drill-table .score-loss { font-weight: 400; color: var(--text-muted); }
.drill-table .td-dash {
  color: var(--text-muted);
  text-align: center;
  padding: 7px 1px;
  font-size: 0.8rem;
}

/* Result indicator column */
.drill-table .td-indicator {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  width: 2rem;
  padding: 7px 4px;
}

/* Section divider between played and upcoming */
.drill-table .section-divider td {
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface2);
  padding: 5px 8px;
  border-top: 2px solid var(--border);
}

.pts-0 { color: var(--text-muted); }
.pts-1 { color: var(--yellow); font-weight: 700; }
.pts-2 { color: var(--green); font-weight: 700; }

/* Prediction indicator colours */
.pts-outcome { color: #4ade80; font-weight: 700; }
.pts-exact   { color: var(--green); font-weight: 700; }
.pts-miss    { color: var(--red); font-weight: 700; }

.row-pending td { color: var(--text-muted); }

/* ── Loading / error states ── */
.loading-msg, .error-msg {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.error-msg {
  color: var(--red);
}

/* ── Skeleton shimmer ── */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Live Now section ── */
#live-now-section,
#upcoming-section {
  margin-bottom: 4px;
}

.section-header {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 14px 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.live-header {
  color: var(--live);
}

.live-dot {
  width: 7px;
  height: 7px;
  background: var(--live);
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse 1.4s ease-in-out infinite;
}

.live-match-card {
  background: var(--surface);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-left: 3px solid var(--live);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
}

.lm-teams {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.lm-team-home {
  display: flex;
  align-items: center;
  gap: 5px;
}

.lm-team-away {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-direction: row-reverse;
}

.lm-score {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  white-space: nowrap;
}

.lm-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Upcoming section ── */
.upcoming-divider {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 3px 8px;
  background: var(--surface2);
  border-radius: 4px;
  display: inline-block;
  margin: 8px 0 5px;
}

.upcoming-divider:first-child {
  margin-top: 0;
}

.upcoming-match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 5px;
}

.um-teams {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.um-home {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.um-home span:last-child,
.um-away span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.um-away {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  justify-content: flex-end;
  flex-direction: row-reverse;
}

.um-vs {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
  flex-shrink: 0;
  padding: 0 2px;
}

.um-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.um-time {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Venue tag (shared) ── */
.venue-tag {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.venue-tag .fi {
  width: 1.1em;
  height: 0.8em;
  display: inline-block;
  background-size: cover;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Flags in live/upcoming rows ── */
.live-match-card .fi,
.upcoming-match-card .fi {
  width: 1.2em;
  height: 0.9em;
  display: inline-block;
  background-size: cover;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Responsive adjustments ── */
@media (max-width: 380px) {
  .match-team { font-size: 0.78rem; }
  .standings-row td { padding: 9px 6px; font-size: 0.85rem; }
}
