/* stats.css — "Stats" tab: tournament-to-date hero, overview cards and the
   goals-by-stage chart. Reuses the global tokens and the .stat-card pattern.
   Repeated tiles use a flat translucent fill (no backdrop-filter) per the
   project's perf rule; blur is reserved for the few large .glass surfaces. */

/* --------------------------------------------------------- hero "pulse" */

.stats-hero {
  padding: clamp(1.4rem, 4vw, 2.4rem);
  text-align: center;
}

.stats-hero .hero-label {
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}

.stats-hero-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
}

.stats-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 1rem 0.6rem;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
}

.stats-tile-value {
  font-size: clamp(1.5rem, 4.5vw, 2.1rem);
  font-weight: 700;
  color: var(--accent-gold-soft);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stats-tile-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

/* -------------------------------------------------------- verdict hero */
/* post-tournament hero: champion + podium above the count-up tiles */

.stats-verdict {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.3rem;
}

.stats-verdict .hero-label { margin-bottom: 0.1rem; }

.verdict-champion {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}

.verdict-trophy {
  font-size: 2.4rem;
  line-height: 1;
}

.verdict-flag {
  border-radius: 4px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  outline: 2px solid var(--accent-gold);
}

.verdict-name {
  font-size: clamp(1.6rem, 5vw, 2.5rem);
  font-weight: 800;
  line-height: 1.05;
  color: var(--accent-gold-soft);
}

.verdict-crown {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent-gold);
}

.verdict-podium {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.8rem 1.5rem;
}

.verdict-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
  min-width: 84px;
}

.verdict-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.verdict-place-name {
  font-size: 0.92rem;
  font-weight: 600;
}

.verdict-place-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.stats-verdict .stats-hero-tiles { width: 100%; }

/* ----------------------------------------------------------- overview */

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

.stats-overview-grid .stat-value {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
}

.stat-sub {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-secondary);
}

/* ------------------------------------------------- goals-by-stage chart */

.stats-chart {
  display: grid;
  gap: 0.85rem;
  padding: 1.25rem 1.4rem;
}

.chart-row {
  display: grid;
  grid-template-columns: clamp(86px, 22vw, 150px) 1fr auto;
  align-items: center;
  gap: 0.8rem;
}

.chart-bar-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.chart-track {
  height: 14px;
  background: var(--glass-bg-strong);
  border-radius: 999px;
  overflow: hidden;
}

.chart-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-gold));
  transform-origin: left center;
  animation: stats-bar-grow 0.6s ease both;
}

@keyframes stats-bar-grow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.chart-bar-val {
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 1.5ch;
  text-align: right;
}

/* ------------------------------------------------- team statistics */

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

.leader-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.1rem 1rem;
  text-align: center;
  position: relative; /* anchor for the full-height side click areas */
}

.leader-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent-gold);
  font-weight: 600;
}

.leader-team {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.leader-name {
  font-size: 1rem;
  font-weight: 600;
}

.leader-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold-soft);
}

/* tied-leader carousel: arrows pinned to the card edges (so they never shift
   with the team-name width), dots/counter below */
.leader-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  /* keep the team clear of the full-height side click areas */
  padding-inline: 2.75rem;
}

/* each arrow is a full-height strip down the card side: clicking anywhere on the
   lateral navigates. The chevron glyph stays small, centered in the strip (≈ the
   team row, since the card's vertical centre sits on it). */
.leader-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  opacity: 0.5;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, opacity 0.15s ease;
}

.leader-prev { left: 0; }
.leader-next { right: 0; }

.leader-nav:hover,
.leader-nav:focus-visible {
  opacity: 1;
  color: var(--accent-gold);
}

.leader-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-top: -0.15rem; /* tuck the smaller dots closer to the value */
}

.leader-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--glass-border);
  transition: background 0.2s ease, transform 0.2s ease;
}

.leader-dot.active {
  background: var(--accent-gold);
  transform: scale(1.25);
}

.leader-counter {
  font-size: 0.68rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .leader-dot { transition: none; }
}

/* horizontal scroll on narrow screens; rank + team columns stay frozen */
.stats-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  -webkit-overflow-scrolling: touch;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--glass-bg);
}

.stats-table th,
.stats-table td {
  padding: 0.6rem 0.7rem;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stats-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--glass-border);
  font-weight: 600;
  color: var(--text-secondary);
}

.stats-table tbody tr {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.stats-table tbody tr:hover {
  background: var(--glass-bg-strong);
}

.col-rank {
  text-align: center;
  color: var(--text-secondary);
  width: 2.5rem;
}

.col-team {
  text-align: left;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* freeze rank + team to the left while metric columns scroll under them */
.stats-table .col-rank,
.stats-table .col-team {
  position: sticky;
  background: var(--bg-secondary);
  z-index: 1;
}

.stats-table .col-rank { left: 0; }
.stats-table .col-team { left: 2.5rem; }

.stats-table tbody .col-rank,
.stats-table tbody .col-team {
  background: var(--bg-primary);
}

.stats-table tbody tr:hover .col-rank,
.stats-table tbody tr:hover .col-team {
  background: var(--bg-secondary);
}

/* favorite-team row highlight (gold) — after the hover rules so it persists */
.stats-table tbody tr.row-fav td { background: rgba(212, 175, 55, 0.12); }
.stats-table tbody tr.row-fav .col-rank,
.stats-table tbody tr.row-fav .col-team { background: var(--bg-secondary); }
.stats-table tbody tr.row-fav .col-rank { box-shadow: inset 3px 0 0 var(--accent-gold); }

/* ------------------------------------------------------ team records */

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

.record-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.1rem 1rem;
  text-align: center;
  width: 100%;
}

button.record-card { cursor: pointer; transition: border-color 0.2s, background-color 0.2s; }
button.record-card:hover { border-color: var(--accent-gold); background: var(--glass-bg-strong); }

.record-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent-gold);
  font-weight: 600;
}

.record-main { display: flex; align-items: center; gap: 0.6rem; }

.record-score {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold-soft);
}

.record-teams { font-size: 0.85rem; color: var(--text-secondary); }
.record-vs { opacity: 0.55; }

.champ-path {
  display: grid;
  gap: 0.35rem;
  padding: 1.1rem 1.2rem;
  margin-bottom: 1.25rem;
}

.champ-path .record-label { margin-bottom: 0.3rem; }

.champ-path-row {
  display: grid;
  grid-template-columns: 1fr auto 1.4fr;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
}

.champ-path-row.clickable { cursor: pointer; }
.champ-path-row.clickable:hover { background: var(--glass-bg-strong); }

.champ-path-phase { font-size: 0.82rem; color: var(--text-secondary); text-align: left; }
.champ-path-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.champ-path-opp { display: flex; align-items: center; gap: 0.4rem; justify-content: flex-end; font-size: 0.88rem; }

/* -------------------------------------------------- format-48 debuts band */

.stats-subhead {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 1.5rem 0 0.8rem;
}

.debut-band {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem 1.25rem;
  padding: 1.4rem 1.5rem;
}

.debut-fact {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  text-align: center;
}

.debut-value {
  font-size: clamp(1.6rem, 4.5vw, 2.2rem);
  font-weight: 800;
  line-height: 1.05;
  color: var(--accent-gold-soft);
  font-variant-numeric: tabular-nums;
}

.debut-value-sm { font-size: clamp(1rem, 3vw, 1.3rem); }

.debut-label {
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--text-secondary);
}

/* ---------------------------------------------------- team comparator */

.cmp-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.cmp-select { flex: 1 1 0; min-width: 0; max-width: 16rem; }

.cmp-vs {
  flex: 0 0 auto;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.cmp-panel {
  display: grid;
  gap: 0.7rem;
  padding: 1.3rem 1.4rem;
}

.cmp-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.4rem;
  font-weight: 700;
}

.cmp-team { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.cmp-team span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-team-b { flex-direction: row; text-align: right; }

.cmp-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr minmax(56px, auto) 1fr 2.2rem;
  align-items: center;
  gap: 0.5rem;
}

.cmp-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.cmp-val.a { text-align: right; }
.cmp-val.b { text-align: left; }
.cmp-val.lead { color: var(--accent-gold-soft); }

.cmp-track {
  height: 12px;
  background: var(--glass-bg-strong);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}

.cmp-track.a { justify-content: flex-end; }
.cmp-track.b { justify-content: flex-start; }

.cmp-bar {
  height: 100%;
  border-radius: 999px;
  animation: cmp-grow 0.5s ease both;
}

.cmp-bar.a {
  background: linear-gradient(90deg, var(--accent-gold-soft), var(--accent-gold));
  transform-origin: right center;
}

.cmp-bar.b {
  background: linear-gradient(90deg, var(--accent-blue), #5aa9f0);
  transform-origin: left center;
}

@keyframes cmp-grow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.cmp-label {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

@media (prefers-reduced-motion: reduce) {
  .cmp-bar { animation: none; }
}

.col-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0;
  color: inherit;
  font: inherit;
  font-weight: 600;
}

.col-sort:hover {
  color: var(--text-primary);
}

.stats-table th.sorted,
.stats-table td.sorted {
  color: var(--accent-gold-soft);
}

.sort-arrow {
  font-size: 0.7rem;
}

.row-idle td {
  color: var(--text-secondary);
  opacity: 0.7;
}

.stats-pagination {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

.page-btn {
  min-width: 2.2rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}

.page-btn:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: var(--accent-gold);
}

.page-btn.active {
  color: var(--bg-primary);
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-soft));
  border-color: transparent;
  font-weight: 600;
}

.page-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------- header tooltips + key */

.has-tip { cursor: help; }
.col-sort.has-tip { cursor: pointer; }

.app-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 220px;
  padding: 0.45rem 0.65rem;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 400;
  line-height: 1.4;
  text-align: center;
  text-transform: none;
  letter-spacing: normal;
  pointer-events: none;
}

.app-tooltip[hidden] { display: none; }

/* abbreviation key — hidden on desktop (tooltips cover it), shown on mobile */
.stats-legend { display: none; }

.legend-pair b {
  color: var(--text-primary);
  font-weight: 600;
}

@media (max-width: 600px) {
  .stats-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.9rem;
    margin: 0.9rem 0 0;
    padding: 0.8rem 1rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    font-size: 0.76rem;
    color: var(--text-secondary);
    line-height: 1.5;
  }
}

/* --------------------------------------------------------------- misc */

.stats-more {
  margin-top: 1.5rem;
  text-align: center;
}

.stats-link {
  padding: 0.55rem 1.2rem;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}

.stats-link:hover {
  color: var(--text-primary);
  border-color: var(--accent-gold);
  background: var(--glass-bg-strong);
}

/* -------------------------------------------------- sub-nav (scrollspy) */

/* sticks just below the variable-height sticky header (--header-h is kept live
   by app.js trackHeaderHeight). NOT a tablist — it's a <nav> of in-page anchors
   whose clicks are intercepted, so the top tablist's arrow keys never conflict. */
.stats-subnav {
  position: sticky;
  top: var(--header-h, 64px);
  z-index: 20;
  margin: 1.4rem 0;
  padding: 0.4rem;
  overflow: hidden; /* clip the inner track to the rounded pill */
  background: rgba(8, 20, 33, 0.88);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
}

/* the scrolling chip track — the edge-fade mask goes here, not on the pill, so
   the pill's background + rounded ends stay crisp while only chips fade out. */
.stats-subnav-track {
  position: relative;
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.stats-subnav-track::-webkit-scrollbar { display: none; }

/* edge fades — toggled by JS only on a side that still has chips to scroll to */
.stats-subnav.fade-right .stats-subnav-track {
  -webkit-mask-image: linear-gradient(to left, transparent 0, #000 28px);
  mask-image: linear-gradient(to left, transparent 0, #000 28px);
}

.stats-subnav.fade-left .stats-subnav-track {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 28px);
  mask-image: linear-gradient(to right, transparent 0, #000 28px);
}

.stats-subnav.fade-left.fade-right .stats-subnav-track {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
}

.stats-subnav-chip {
  flex: 0 0 auto;
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.2s, background-color 0.2s;
}

.stats-subnav-chip:hover { color: var(--text-primary); }

.stats-subnav-chip.active {
  color: var(--bg-primary);
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-soft));
}

/* offset scroll targets so the sticky header + sub-nav never cover a heading */
.stats-section {
  scroll-margin-top: calc(var(--header-h, 64px) + 3.75rem);
}

.stats-section + .stats-section { margin-top: 2.5rem; }
.stats-section:focus { outline: none; }
/* section spacing is owned by the wrapper, not the first heading inside it */
.stats-section > .section-title:first-child { margin-top: 0; }

/* flag monogram fallback (graceful degradation §0.3) — never a broken-img icon */
.flag-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: 3px;
  color: var(--text-secondary);
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  vertical-align: middle;
  overflow: hidden;
}

/* ---------------------------------------------------------- responsive */

@media (max-width: 600px) {
  .stats-hero-tiles {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chart-bar { animation: none; }
}
