* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d1a;
  --surface: #13131f;
  --surface2: #1a1a2e;
  --border: #2a2a3d;
  --text: #e8e8f0;
  --muted: #6b6b82;
  --accent: #3b82f6;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --white: #ffffff;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 560px;
  margin: 0 auto;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-logo {
  height: 68px;
  width: auto;
  flex-shrink: 0;
  /* The source art's visual weight (the gold "CA") sits in the upper
     ~70% of the image, with a thin flag bar below - pure bounding-box
     centering against the two-line wordmark left the letters floating
     visibly above the title. This nudges it down to match by eye. */
  margin-top: 7px;
}
/* At 68px the logo's width starts crowding "Calcio Americano" onto two
   lines on ~360px-wide phones (common Android sizes) - scale down below
   that so the wordmark always fits on one line. */
@media (max-width: 400px) {
  .header-logo {
    height: 56px;
    margin-top: 6px;
  }
}
.header-text {
  display: flex;
  flex-direction: column;
  margin-top: -4px;
}
.logo-main {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--white);
}
.logo-sub {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
}
.tournament-tag {
  font-size: 11px;
  font-weight: 700;
  background: var(--accent);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

/* Tabs */
.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 12px 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  letter-spacing: 0.03em;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Page wrapper */
.page { display: none; }
.page.active { display: block; }

/* Content wrapper */
.content {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

/* Section label */
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 10px;
  margin-top: 20px;
}
.section-label:first-child { margin-top: 0; }

/* Toolbar (sort toggle etc) */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}
.toolbar-label { font-size: 11px; color: var(--muted); }
.toggle-group { display: flex; gap: 6px; }
.toggle-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.toggle-btn.active { color: var(--white); border-color: var(--accent); background: rgba(59,130,246,0.12); }

/* Matchday prev/next navigation */
.matchday-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.md-arrow {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
}
.md-arrow:hover:not(:disabled) { color: var(--white); border-color: var(--accent); }
.md-arrow:disabled { opacity: 0.35; cursor: default; }
.md-nav-center { text-align: center; }
.md-nav-round { font-size: 14px; font-weight: 800; color: var(--white); letter-spacing: 0.02em; }
.md-nav-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Match card */
.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s;
}
.match-card:hover { border-color: #3a3a5c; }
.match-card.expanded { border-color: var(--accent); }

.match-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.match-teams {
  flex: 1;
  min-width: 0;
}
.teams-row {
  font-size: 15px;
  font-weight: 700;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.match-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

/* Right side of the card header: result chip (played matches only) sits to
   the left of the signal badge. */
.match-header-right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Result chip - only on played matches: did the first half finish level? */
.result-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 4px 7px;
  border-radius: 5px;
}
.result-chip.hit  { background: rgba(34,197,94,0.15); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.result-chip.miss { background: rgba(239,68,68,0.12); color: var(--red);   border: 1px solid rgba(239,68,68,0.25); }
.result-chip-icon { font-size: 11px; line-height: 1; }

.signal-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 5px 9px;
  border-radius: 5px;
  text-align: center;
}
.badge-strong  { background: rgba(34,197,94,0.15);  color: var(--green);  border: 1px solid rgba(34,197,94,0.3); }
.badge-moderate{ background: rgba(245,158,11,0.15); color: var(--yellow); border: 1px solid rgba(245,158,11,0.3); }
.badge-weak    { background: rgba(239,68,68,0.12);  color: var(--red);    border: 1px solid rgba(239,68,68,0.25); }
.badge-none    { background: rgba(107,107,130,0.1); color: var(--muted);  border: 1px solid var(--border); }

.signal-count {
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  display: block;
}
.signal-label {
  display: block;
  font-size: 9px;
  margin-top: 1px;
}

/* Article preview CTA - lives inside the expanded match detail, first
   section, so it's discovered together with the signal data rather than
   competing with it as a separate top-level link */
.article-cta {
  margin-top: 14px;
  cursor: pointer;
  background: rgba(59,130,246,0.08);
  border: 1px solid rgba(59,130,246,0.25);
  border-radius: 8px;
  padding: 10px 12px;
  transition: background 0.15s;
}
.article-cta:hover { background: rgba(59,130,246,0.14); }
.article-cta-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}
.article-cta-excerpt {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}
.article-cta-arrow {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent);
}

/* Collapsed-card hint that an article exists - same accent+arrow language
   as .article-cta, scaled down to a plain line since it's not itself a
   separate click target (the whole card is already clickable). Hidden
   once expanded, where the full CTA above takes over. */
.preview-hint {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-top: 4px;
}
.preview-hint-arrow { font-weight: 800; }
.match-card.expanded .preview-hint { display: none; }

/* Article view (swaps in over the This Matchday fixture list) */
.article-view { padding-bottom: 4px; }
.article-back {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  margin-bottom: 14px;
}
.article-back:hover { text-decoration: underline; }
.article-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--white);
}
.article-body {
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}
.article-body p { margin-bottom: 12px; }
.article-body p:last-child { margin-bottom: 0; }

/* Expanded detail */
.match-detail {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}
.match-card.expanded .match-detail { display: block; }

.detail-section {
  margin-top: 14px;
}
.detail-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Signal checklist */
.signal-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.signal-row:last-child { border-bottom: none; }
.signal-icon {
  font-size: 14px;
  font-weight: 800;
  width: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}
.signal-icon.pass { color: var(--green); }
.signal-icon.fail { color: var(--red); }
.signal-icon.na   { color: var(--muted); }
.signal-text { flex: 1; }
.signal-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.signal-detail {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.signal-detail-sub { opacity: 0.7; margin-top: 1px; }

/* Teams tab — standings-style table */
.standings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
}
.standings-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px 7px;
  font-size: 12px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
.standings-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0 0 10px 10px;
}
.standings-table {
  border-collapse: collapse;
  width: 100%;
}
.standings-table th, .standings-table td {
  padding: 7px 8px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.standings-table th {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface2);
  padding: 6px 8px;
}
.standings-table td:first-child, .standings-table th:first-child { text-align: left; }
.standings-table tbody tr:last-child td { border-bottom: none; }
.standings-table tbody tr.is-signal td:first-child { color: var(--green); font-weight: 700; }

/* HT-Draw Profile table - long headers ("All-Time Avg 1st Goal Scored")
   were forced onto one line by the shared nowrap rule above, making the
   table far wider than it needed to be. Let headers wrap onto a few
   lines within a capped width instead, and center data under them
   (right-align reads best for single-line numeric columns, but fights
   a wrapped, centered header). Team name stays left-aligned via the
   existing :first-child rule. */
.profile-table th {
  white-space: normal;
  text-align: center;
  line-height: 1.3;
}
.profile-table th:not(:first-child) { max-width: 92px; }
.profile-table td { text-align: center; }
.profile-table td:first-child, .profile-table th:first-child { text-align: left; }

/* Frozen columns - keep team identity visible while the stat columns scroll */
.standings-table.freeze-1 th:first-child,
.standings-table.freeze-1 td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
}
.standings-table.freeze-1 td:first-child { background: var(--surface); }
.standings-table.freeze-1 th:first-child { background: var(--surface2); z-index: 2; }

.standings-table.freeze-2 th:first-child,
.standings-table.freeze-2 td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 34px;
}
.standings-table.freeze-2 th:nth-child(2),
.standings-table.freeze-2 td:nth-child(2) {
  position: sticky;
  left: 34px;
  z-index: 1;
}
.standings-table.freeze-2 td:first-child,
.standings-table.freeze-2 td:nth-child(2) { background: var(--surface); }
.standings-table.freeze-2 th:first-child,
.standings-table.freeze-2 th:nth-child(2) { background: var(--surface2); z-index: 2; }
/* faint edge so it's visually obvious content continues under the frozen columns */
.standings-table.freeze-1 td:first-child,
.standings-table.freeze-1 th:first-child,
.standings-table.freeze-2 td:nth-child(2),
.standings-table.freeze-2 th:nth-child(2) {
  box-shadow: 2px 0 4px rgba(0,0,0,0.35);
}

/* Stat colors */
.sc-green { color: var(--green); }
.sc-yellow { color: var(--yellow); }
.sc-muted  { color: var(--muted); }

/* About / Research prose cards */
.about-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
}
.about-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 8px;
}
.about-body {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}
.about-body strong { color: var(--text); }

/* Disclaimer */
.disclaimer {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 20px 16px;
  line-height: 1.6;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
  font-size: 13px;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Charts (Research tab) ───────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
}
.chart-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 2px;
}
.chart-subtitle {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 12px;
}
.chart-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
}
.legend-line { width: 12px; height: 2px; border-radius: 1px; }
.chart-svg-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-svg-wrap svg { display: block; }
.chart-svg text { font-family: inherit; }
.chart-bar-group:hover .chart-bar { opacity: 0.85; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: #05050c;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 11px;
  color: var(--white);
  white-space: nowrap;
  transform: translate(-50%, -100%);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.1s;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-label { color: var(--muted); margin-right: 6px; }
.chart-pos { position: relative; }

.data-table-toggle {
  margin-top: 10px;
}
.data-table-toggle summary {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  cursor: pointer;
  text-transform: uppercase;
  user-select: none;
}
.data-table-toggle summary:hover { color: var(--text); }
.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-top: 8px;
}
.mini-table th, .mini-table td {
  padding: 5px 6px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.mini-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.mini-table th:first-child, .mini-table td:first-child { text-align: left; }

.finding-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.finding-row:last-child { border-bottom: none; }
.finding-name { font-size: 12px; color: var(--text); flex: 1; }
.finding-value { font-size: 12px; font-weight: 700; color: var(--white); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.finding-note { font-size: 10px; color: var(--muted); }
