/* ─── RESET & BASE ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red: #E9292F;
  --red-dark: #c41e24;
  --yellow: #FFD602;
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #8e8e93;
  --border: #e5e5ea;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ─── HEADER ──────────────────────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(160deg, var(--red) 0%, var(--red-dark) 100%);
  color: white;
  padding: 16px 16px 12px;
  padding-top: max(16px, env(safe-area-inset-top));
}

.header-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
.team-switcher {
  display: flex;
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 3px;
  margin-left: auto;
  gap: 2px;
}
.team-btn {
  background: none; border: none;
  color: rgba(255,255,255,0.75);
  font-size: 13px; font-weight: 600;
  padding: 5px 14px; border-radius: 16px;
  cursor: pointer; transition: all .15s;
}
.team-btn.active {
  background: white;
  color: var(--red);
}
.header-install-btn {
  background: none; border: none;
  font-size: 22px; cursor: pointer;
  padding: 4px; opacity: 0.75;
  line-height: 1;
}

.header-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-sub {
  font-size: 13px;
  opacity: 0.85;
  margin-top: 2px;
}

.header-club-logo {
  display: block;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: contain;
  background: white;
  padding: 4px;
  flex-shrink: 0;
}

/* Sponsor banner */
.sponsor-bar {
  background: white;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

.sponsor-label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  font-weight: 600;
}

.sponsor-slot {
  height: 32px;
  min-width: 80px;
  background: var(--bg);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  flex-shrink: 0;
}

.sponsor-slot img { height: 100%; object-fit: contain; padding: 4px; }

/* ─── NAVIGATION ─────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 1;
  min-width: 70px;
  padding: 13px 8px;
  text-align: center;
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color .2s, border-color .2s;
  white-space: nowrap;
}
.tab-btn.active { border-bottom-color: var(--red); color: var(--red); }

/* ─── VIEWS ──────────────────────────────────────────────────────────────── */
.view { display: none; padding: 12px 12px calc(80px + var(--safe-bottom)); min-height: 60vh; }
.view.active { display: block; }

/* ─── MATCH CARD ──────────────────────────────────────────────────────────── */
.match-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.match-card--live { border-left: 3px solid var(--red); }

.match-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.match-teams {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0;
}

.team { flex: 1; text-align: center; }

.team-abbr {
  width: 44px; height: 44px;
  background: var(--bg);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: var(--red);
  margin: 0 auto 6px;
}

.team-name { font-size: 13px; font-weight: 500; }

.score {
  font-size: 30px;
  font-weight: 700;
  padding: 0 12px;
  letter-spacing: -1px;
}
.score--upcoming { font-size: 18px; color: var(--text-secondary); font-weight: 400; }

.match-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
  flex-wrap: wrap;
  gap: 6px;
}

.match-arena { font-size: 12px; color: var(--text-secondary); }
.match-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── BADGES ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge--live { background: var(--red); color: white; animation: pulse 2s infinite; }
.badge--upcoming { background: #e5e5ea; color: var(--text-secondary); }
.badge--win { background: #d1fae5; color: #065f46; }
.badge--loss { background: #fee2e2; color: #991b1b; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.6} }

/* ─── LINK BUTTON ────────────────────────────────────────────────────────── */
.link-btn {
  background: none; border: none; cursor: pointer;
  color: var(--red); font-size: 13px; font-weight: 600;
  padding: 0; text-decoration: none;
}

/* ─── PLAYER CARD ────────────────────────────────────────────────────────── */
.player-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
  position: relative;
  transition: box-shadow .2s;
}
.player-card:active { box-shadow: 0 2px 8px rgba(0,0,0,.15); }

.player-photo {
  width: 46px; height: 46px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  flex-shrink: 0;
  margin-right: 12px;
  display: flex; align-items: center; justify-content: center;
}
.player-photo img { width: 100%; height: 100%; object-fit: cover; }
.player-initials { color: white; font-weight: 700; font-size: 16px; display: flex; align-items: center; justify-content: center; }

.player-info { flex: 1; min-width: 0; }
.player-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-position { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.player-number { font-weight: 700; font-size: 20px; color: var(--red); margin-left: 8px; min-width: 28px; text-align: right; }

.squad-check {
  position: absolute; top: 8px; right: 36px;
  width: 20px; height: 20px;
  background: var(--yellow); color: #333;
  border-radius: 50%; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ─── FILTER BUTTONS ─────────────────────────────────────────────────────── */
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-btn {
  padding: 7px 14px; border-radius: 20px;
  border: 1.5px solid var(--border); background: white;
  font-size: 13px; font-weight: 500; cursor: pointer;
  color: var(--text-secondary); transition: all .2s;
}
.filter-btn.active { background: var(--red); border-color: var(--red); color: white; }

/* ─── TABLE ──────────────────────────────────────────────────────────────── */
.table-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  margin-bottom: 10px;
}

.table-card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-card th { background: var(--bg); padding: 8px 6px; text-align: center; font-weight: 600; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; }
.table-card td { padding: 10px 6px; text-align: center; border-top: 1px solid var(--border); }
.table-card .team-cell { text-align: left; padding-left: 10px; font-weight: 500; }
.table-card .pos-cell { color: var(--text-secondary); font-size: 12px; }
.table-card .pts-cell { color: var(--text); }
.table-card .diff-cell { color: var(--text-secondary); }
.table-card tr.our-team { background: #fff5f5; }
.table-card tr.our-team .team-cell { color: var(--red); }

.form-row {
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--text-secondary);
  border-top: 1px solid var(--border);
}
.form-badges { display: flex; gap: 4px; }
.form-badge {
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.form-badge--win { background: #d1fae5; color: #065f46; }
.form-badge--loss { background: #fee2e2; color: #991b1b; }

/* ─── STATISTICS ─────────────────────────────────────────────────────────── */
.sort-row { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.sort-btn {
  padding: 6px 12px; border-radius: 16px;
  border: 1.5px solid var(--border); background: white;
  font-size: 12px; font-weight: 500; cursor: pointer; color: var(--text-secondary);
}
.sort-btn.active { background: var(--red); border-color: var(--red); color: white; }

.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th { padding: 8px 6px; text-align: center; font-weight: 600; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; background: var(--bg); }
.stats-table td { padding: 10px 6px; text-align: center; border-top: 1px solid var(--border); }
.stats-table .player-cell { text-align: left; padding-left: 10px; }
.stats-table .stats-name { display: block; font-weight: 600; }
.stats-table .stats-pos { font-size: 11px; color: var(--text-secondary); }
.stats-table .highlight-col { font-weight: 700; color: var(--red); }

/* ─── FANS / NEWS ────────────────────────────────────────────────────────── */
.section-title { font-size: 17px; font-weight: 700; margin-bottom: 10px; }

.news-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  display: flex;
}
.news-image { width: 90px; min-height: 90px; background: var(--bg); flex-shrink: 0; overflow: hidden; }
.news-image img { width: 100%; height: 100%; object-fit: cover; }
.news-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 28px; }
.news-body { padding: 12px; flex: 1; min-width: 0; }
.news-date { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; }
.news-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; line-height: 1.3; }
.news-excerpt { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.gallery-item {
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 4/3;
  background: var(--bg);
  cursor: pointer;
}
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.action-btn {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--red); color: white;
  padding: 14px 16px; border-radius: var(--radius);
  border: none; width: 100%; cursor: pointer;
  font-size: 15px; font-weight: 600; margin-bottom: 10px;
}

/* ─── DETAIL VIEWS ────────────────────────────────────────────────────────── */
.detail-header {
  display: flex; align-items: center; gap: 12px;
  background: white; padding: 14px;
  border-radius: var(--radius); margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.back-btn {
  background: none; border: none; cursor: pointer;
  color: var(--red); font-size: 15px; font-weight: 600; padding: 0;
}

.detail-title { font-size: 16px; font-weight: 700; }
.detail-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

.section-card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.section-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }

.player-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.player-row:last-child { border-bottom: none; }
.jersey { width: 28px; font-weight: 700; color: var(--red); font-size: 13px; }
.player-row-name { flex: 1; font-weight: 500; font-size: 14px; }
.player-row-pos { font-size: 12px; color: var(--text-secondary); }

.event-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.event-row:last-child { border-bottom: none; }
.event-time { width: 40px; font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.event-icon { font-size: 16px; }
.event-desc { flex: 1; font-size: 13px; }
.event-assist { color: var(--text-secondary); font-size: 12px; }
.event-score { font-weight: 700; font-size: 14px; }

/* Player profile */
.profile-photo-wrap {
  width: 90px; height: 90px; border-radius: 50%;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.profile-photo-wrap img { width: 100%; height: 100%; object-fit: cover; }
#profile-initials { color: white; font-size: 32px; font-weight: 700; display: none; }

.info-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.info-row:last-child { border-bottom: none; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat-box { background: var(--bg); border-radius: 10px; padding: 12px 8px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 700; color: var(--red); }
.stat-lbl { font-size: 11px; color: var(--text-secondary); margin-top: 3px; }

/* ─── INSTALL BANNER ─────────────────────────────────────────────────────── */
/* ─── INSTALL MODAL ──────────────────────────────────────────────────────── */
.install-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 300;
  padding-bottom: calc(var(--safe-bottom) + 8px);
}
.install-modal.hidden { display: none; }
.install-modal-box {
  background: white;
  border-radius: 20px 20px 16px 16px;
  padding: 24px 22px 28px;
  width: 100%; max-width: 440px;
  position: relative;
  box-shadow: 0 -4px 30px rgba(0,0,0,.2);
}
.install-modal-close {
  position: absolute; top: 14px; right: 16px;
  background: var(--bg); border: none;
  border-radius: 50%; width: 28px; height: 28px;
  font-size: 14px; cursor: pointer; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
}
.install-modal-icon { font-size: 32px; margin-bottom: 8px; }
.install-modal-box h3 { margin: 0 0 8px; font-size: 18px; }
.install-modal-box p { margin: 0; font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.install-steps {
  margin: 10px 0 0; padding-left: 20px;
  font-size: 14px; color: var(--text-secondary); line-height: 1.9;
}
.install-steps strong { color: var(--text); }
.share-icon-ios {
  display: inline-block;
  background: #007AFF; color: white;
  border-radius: 6px; padding: 1px 6px;
  font-size: 13px; vertical-align: middle;
  font-style: normal;
}
.install-modal-btn {
  margin-top: 16px; width: 100%;
  background: var(--red); color: white;
  border: none; border-radius: 12px;
  padding: 13px; font-size: 15px; font-weight: 700;
  cursor: pointer;
}

/* ─── FOOTER SPONSORS ────────────────────────────────────────────────────── */
.sponsor-footer {
  background: white; padding: 16px;
  border-radius: var(--radius); margin-top: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.sponsor-footer-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; text-align: center; margin-bottom: 10px; font-weight: 600; letter-spacing: 0.5px; }
.sponsor-footer-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sponsor-footer-slot { height: 44px; background: var(--bg); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--text-secondary); font-weight: 600; }
.sponsor-footer-slot img { height: 100%; object-fit: contain; padding: 6px; }
.app-install-footer { text-align: center; margin-top: 12px; }
.app-install-link {
  background: none; border: none;
  font-size: 12px; color: var(--text-secondary);
  cursor: pointer; padding: 4px 8px;
  text-decoration: underline; text-underline-offset: 3px;
  opacity: 0.7;
}

/* ─── LOADING / ERROR ────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.loading-overlay.hidden { display: none; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--red); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner { background: #fee2e2; color: #991b1b; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 10px; }
.error-banner.hidden { display: none; }

.empty-state { color: var(--text-secondary); font-size: 14px; padding: 20px 0; text-align: center; }
