:root {
  --lev-red: #E32219;
  --good: #1c8c3e;
  --meh:  #d68f00;
  --bad:  #b8211a;
  --bg:   #fafafa;
  --fg:   #1a1a1a;
  --muted: #666;
  --line: #ddd;
  --cl: #1f4ea5;
  --el: #f48a00;
  --ecl: #2da564;
  --none: #999;
}
* { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  padding: 0;
  line-height: 1.5;
}
header {
  background: white;
  border-bottom: 3px solid var(--lev-red);
  padding: 1.5rem 2rem 1rem;
}
.header-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}
.header-titles { flex: 1 1 auto; min-width: 0; }
.club-crest {
  height: 52px;
  width: auto;
  flex-shrink: 0;
}
header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--lev-red);
  line-height: 1.15;
}
.header-question {
  margin: 0.15rem 0 0;
  font-size: 0.95rem;
  color: var(--fg);
  line-height: 1.35;
}
.header-question .inline-logo {
  height: 1.1em;
  width: auto;
  vertical-align: -0.2em;
  margin: 0 0.1em;
}

/* Bucket-row leader: a fixed-width slot so text aligns regardless of icon */
.bucket-leader {
  display: inline-flex;
  width: 22px;
  height: 1em;
  align-items: center;
  justify-content: center;
  margin-right: 0.5rem;
  vertical-align: middle;
}
.bucket-leader img {
  max-height: 16px;
  max-width: 18px;
  width: auto;
  height: auto;
}
.meta {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.meta code { font-family: ui-monospace, "Cascadia Code", "SF Mono", monospace; }
.cache-age { font-size: 0.85rem; color: var(--muted); }
.cache-age.stale { color: var(--bad); font-weight: 600; }
.meta button {
  background: var(--lev-red);
  color: white;
  border: 0;
  padding: 0.3rem 0.8rem;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 0.6rem;
}
main {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem;
}
section { margin-bottom: 2.5rem; }
section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.3rem;
  margin: 0 0 1rem;
}
.muted { color: var(--muted); font-size: 0.85rem; }

/* Hero big number */
.hero { text-align: center; padding: 2rem 0; }
.big-number {
  font-size: 4.5rem;
  font-weight: 300;
  line-height: 1;
  letter-spacing: -2px;
}
.big-number.good { color: var(--good); }
.big-number.meh  { color: var(--meh); }
.big-number.bad  { color: var(--bad); }
.big-label {
  font-size: 0.95rem;
  color: var(--muted);
  letter-spacing: 0;
  margin-top: 0.5rem;
}

/* Bucket bar */
.bar {
  display: flex;
  height: 28px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--line);
  margin-bottom: 0.8rem;
}
.bar .seg { display: block; height: 100%; }
.seg.cl  { background: var(--cl);  }
.seg.el  { background: var(--el);  }
.seg.ecl { background: var(--ecl); }
.seg.none{ background: var(--none); }
.bucket-table { width: 100%; border-collapse: collapse; }
.bucket-table td { padding: 0.3rem 0; font-size: 0.95rem; }
.bucket-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.key {
  display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 0.5rem; vertical-align: middle;
}
.key.cl  { background: var(--cl); }
.key.el  { background: var(--el); }
.key.ecl { background: var(--ecl); }
.key.none{ background: var(--none); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th { text-align: left; border-bottom: 2px solid var(--line); padding: 0.4rem 0.5rem; font-weight: 600; }
tbody td { padding: 0.3rem 0.5rem; border-bottom: 1px solid #eee; }
tr.leverkusen { background: rgba(227, 34, 25, 0.08); font-weight: 600; }

.ranks-table td:first-child { width: 40px; text-align: center; font-variant-numeric: tabular-nums; }
.ranks-table td:nth-child(2) { width: 80px; font-variant-numeric: tabular-nums; }
.rank-bar { display: inline-block; height: 14px; background: var(--lev-red); border-radius: 2px; }

.market-derived td:first-child { width: 50%; }
.market-derived td:nth-child(2) { width: 80px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.market-derived td.src { color: var(--muted); font-size: 0.8rem; }

.src-tag {
  font-family: ui-monospace, "Cascadia Code", "SF Mono", monospace;
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: #eee;
}
.src-tag.odds_api_hda  { background: #cfe6cf; color: #1c5d1c; }
.src-tag.pinnacle_cs   { background: #cfd9eb; color: #1d3a6e; }
.src-tag.missing       { background: #f3c8c6; color: #7d1813; }

/* Decomposition table */
#decomp-table { width: 100%; border-collapse: collapse; }
#decomp-table thead th {
  font-size: 0.85rem;
  border-bottom: 2px solid var(--line);
  padding: 0.4rem 0.5rem;
  text-align: right;
}
#decomp-table thead th:first-child { text-align: center; width: 50px; }
#decomp-table tbody td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid #eee;
  font-variant-numeric: tabular-nums;
}
#decomp-table tbody td.num { text-align: right; font-family: ui-monospace, "Cascadia Code", monospace; font-size: 0.85rem; }
#decomp-table tbody td:first-child { text-align: center; font-weight: 600; }
#decomp-table tbody td.cl    { color: var(--cl); }
#decomp-table tbody td.el    { color: var(--el); }
#decomp-table tbody td.ecl   { color: var(--ecl); }
#decomp-table tbody td.none  { color: var(--none); }
#decomp-table tbody td.contrib { background: rgba(31, 78, 165, 0.06); font-weight: 600; }
#decomp-table .short-label { display: none; }
#decomp-table tr.total td { border-top: 2px solid var(--line); padding-top: 0.5rem; background: #f3f3f3; }

/* Tabs */
nav.tabs {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.7rem;
  border-bottom: 1px solid var(--line);
}
nav.tabs a, nav.tabs button.tab-button {
  padding: 0.5rem 1rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
  border: 0;
  background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-family: inherit;
}
nav.tabs a:hover, nav.tabs button.tab-button:hover { color: var(--fg); }
nav.tabs a.active, nav.tabs button.tab-button.active {
  color: var(--lev-red);
  border-bottom-color: var(--lev-red);
  font-weight: 600;
}

.tab-pane h2 {
  font-size: 1.05rem;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.3rem;
  margin: 2rem 0 0.8rem;
}
.tab-pane h2:first-child { margin-top: 0.5rem; }

/* Loading screens */
.loading {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--muted);
}

/* Sim status indicator */
.sim-status { font-size: 0.85rem; }

/* Dev refresh button */
.dev-button {
  background: white;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.3rem 0.7rem;
  border-radius: 3px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-left: 0.6rem;
}
.dev-button:hover { color: var(--fg); border-color: var(--fg); }

/* What-if tab */
.lead { font-size: 0.95rem; color: var(--fg); margin-bottom: 1rem; }
.whatif-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin: 0.8rem 0 1rem;
}
.whatif-actions button {
  background: white;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.4rem 0.9rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}
.whatif-actions button:hover { color: var(--fg); border-color: var(--fg); }
.delta-banner {
  background: #f3f3f3;
  border-radius: 4px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.delta-banner .delta-up { color: var(--good); font-weight: 600; }
.delta-banner .delta-down { color: var(--bad); font-weight: 600; }

/* Per-fixture score widgets */
.fix-cell {
  white-space: nowrap;
  font-size: 0.85rem;
}
/* Tap-only goal stepper: −  N  +. Cycles "–" → 0 → 1 … → 9 (and back). */
.score-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  vertical-align: middle;
}
.score-stepper .step-down,
.score-stepper .step-up {
  background: transparent;
  border: 0;
  width: 26px;
  height: 30px;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.score-stepper .step-down:hover,
.score-stepper .step-up:hover { color: var(--lev-red); }
.score-stepper .step-down:active,
.score-stepper .step-up:active { background: rgba(227, 34, 25, 0.08); }
.score-stepper .score-val {
  display: inline-block;
  min-width: 14px;
  text-align: center;
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.score-sep { margin: 0 0.15rem; color: var(--muted); font-weight: 600; }
.score-stepper.played .score-val { color: var(--lev-red); }
.score-stepper.played .step-down,
.score-stepper.played .step-up {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}
.leg-played-badge {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--lev-red);
  background: rgba(227, 34, 25, 0.08);
  padding: 0.05rem 0.35rem;
  border-radius: 2px;
  margin-right: 0.3rem;
}

/* UEFA tie row: leg-1 + leg-2 stepper rows + advance dropdown stacked. */
.uefa-fix-cell { white-space: nowrap; }
.uefa-fix-cell .leg-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.3rem;
}
.uefa-fix-cell .leg-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  flex: 0 0 22px;
}
.uefa-fix-cell .sf-select { display: block; margin-top: 0.3rem; max-width: 100%; }
.leg-stepper-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.leg-stepper-cell .team-tag {
  font-size: 0.6rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
}
.uefa-cond {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
.uefa-cond strong { color: var(--fg); }
.row-clear {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  cursor: pointer;
  font-size: 0.75rem;
  margin-left: 0.3rem;
}
.row-clear:hover {
  background: var(--lev-red);
  color: white;
  border-color: var(--lev-red);
}
.fix-cell select {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 0.85rem;
  font-family: inherit;
  max-width: 240px;
}
.when { font-size: 0.78rem; color: var(--muted); }

/* FAQ */
.faq {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.6rem 0.9rem;
  margin: 0.5rem 0;
  background: white;
}
.faq summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.1rem 0;
  color: var(--lev-red);
}
.faq summary:hover { text-decoration: underline; }
.faq[open] summary { margin-bottom: 0.4rem; }
.faq p { margin: 0.5rem 0 0; font-size: 0.9rem; line-height: 1.55; }

/* What-if section dividers + Lev-row highlight */
tr.section-divider td {
  background: #f3f3f3;
  padding: 0.5rem 0.5rem;
  border-top: 2px solid var(--lev-red);
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}
tr.section-divider td strong { color: var(--lev-red); }
tr.lev-row { background: rgba(227, 34, 25, 0.06); }
.hda-hint {
  font-size: 0.72rem;
  font-family: ui-monospace, monospace;
  color: var(--muted);
  margin-top: 0.15rem;
}
.note { background: #fafafa; border-left: 3px solid var(--cl); padding: 0.55rem 0.8rem; font-size: 0.85rem; line-height: 1.5; margin: 0.5rem 0 1rem; }
.note.muted { color: var(--fg); }

/* Story sentence under the hero */
.story {
  text-align: center;
  font-size: 0.95rem;
  color: var(--fg);
  margin: -0.5rem auto 1.5rem;
  max-width: 640px;
}

/* Recent-form strip */
.form-strip {
  display: flex;
  gap: 0.4rem;
  margin: 0.5rem 0 1rem;
}
.form-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.95rem;
  font-family: ui-monospace, monospace;
  color: white;
  cursor: help;
}
.form-W { background: var(--good); }
.form-D { background: var(--meh); }
.form-L { background: var(--bad); }

/* Lev-remaining table */
#lev-remaining-table .hda-cell {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}
.venue-home { color: var(--good); font-size: 0.78rem; font-weight: 600; }
.venue-away { color: var(--meh); font-size: 0.78rem; font-weight: 600; }

/* Markets table on How-it-works tab */
#markets-table td:nth-child(2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  width: 80px;
}
#markets-table td.src { color: var(--muted); font-size: 0.78rem; }

/* Mobile breakpoint */
@media (max-width: 640px) {
  header { padding: 1rem 0.9rem 0.6rem; }
  header h1 { font-size: 1.15rem; }
  .header-question { font-size: 0.85rem; }
  .club-crest { height: 44px; }
  .header-row { gap: 0.6rem; }
  main { padding: 1rem 0.8rem 3rem; }
  nav.tabs button.tab-button, nav.tabs a {
    padding: 0.5rem 0.6rem;
    font-size: 0.9rem;
    flex: 1;
    text-align: center;
  }
  .meta { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
  .big-number { font-size: 3.5rem; }
  table { font-size: 0.85rem; }
  thead th, tbody td { padding: 0.3rem 0.3rem; }
  /* Larger tap targets on mobile (per Apple HIG ≥ 44px) */
  .score-stepper .step-down,
  .score-stepper .step-up { width: 36px; height: 40px; font-size: 1.2rem; }
  .score-stepper .score-val { min-width: 18px; font-size: 1rem; }
  .fix-cell select { font-size: 0.85rem; max-width: 100%; }
  .ranks-table td:first-child { width: 30px; }
  .ranks-table td:nth-child(2) { width: 60px; }
  .rank-bar { height: 12px; }
  #decomp-table { font-size: 0.75rem; table-layout: fixed; }
  #decomp-table thead th { font-size: 0.7rem; padding: 0.3rem 0.2rem; word-break: break-word; }
  #decomp-table tbody td { padding: 0.25rem 0.2rem; }
  #decomp-table tbody td.num { font-size: 0.72rem; }
  /* Hide a couple of low-value columns on mobile to keep decomp readable */
  #decomp-table thead th:nth-child(4),
  #decomp-table thead th:nth-child(5),
  #decomp-table thead th:nth-child(6),
  #decomp-table tbody td:nth-child(4),
  #decomp-table tbody td:nth-child(5),
  #decomp-table tbody td:nth-child(6) { display: none; }
  /* Shorter Contribution label on mobile — full label leaks past 376px viewport */
  #decomp-table thead th:nth-child(7) .full-label { display: none; }
  #decomp-table thead th:nth-child(7) .short-label { display: inline; }
  #markets-table td.src { display: none; }
  footer { padding: 1rem 0.8rem; }
}

/* Matches table */
.matches-table {
  font-size: 0.85rem;
}
.matches-table td.odds {
  font-family: ui-monospace, "Cascadia Code", "SF Mono", monospace;
  font-size: 0.8rem;
}
.matches-table td.src { color: var(--muted); font-size: 0.78rem; }
.matches-table td.result {
  font-family: ui-monospace, monospace;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.matches-table td.decisive { color: var(--muted); font-size: 0.78rem; }
.matches-table tr.played {
  background: rgba(28, 140, 62, 0.06);
}
.matches-table td.when { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.matches-table td.odds-src .odds { font-family: ui-monospace, monospace; font-size: 0.78rem; }
.matches-table td.odds-src .src { color: var(--muted); font-size: 0.72rem; }
.matches-table td.fix-cell {
  white-space: nowrap;
  font-size: 0.85rem;
}
.matches-table td.fix-cell input.score-input {
  width: 38px;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  text-align: center;
}
.matches-table td.fix-cell .fix-hint {
  font-size: 0.7rem;
  color: var(--meh);
  margin-top: 0.2rem;
  max-width: 220px;
  white-space: normal;
  line-height: 1.2;
}
.matches-table td.fix-cell button.row-clear {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  cursor: pointer;
  font-size: 0.75rem;
  margin-left: 0.3rem;
}
.matches-table td.fix-cell button.row-clear:hover {
  background: var(--lev-red);
  color: white;
  border-color: var(--lev-red);
}
.matches-table td.fix-cell select {
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 0.8rem;
  max-width: 220px;
}
.form-actions {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  margin: 1rem 0;
}
.form-actions button.primary {
  background: var(--lev-red);
  color: white;
  border: 0;
  padding: 0.5rem 1.1rem;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.form-actions button.secondary {
  background: white;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.5rem 0.9rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.85rem;
}
.form-actions button.secondary:hover { color: var(--fg); border-color: var(--fg); }
.form-actions .delta-up   { color: var(--good); font-weight: 600; }
.form-actions .delta-down { color: var(--bad);  font-weight: 600; }
.comp-tag {
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  background: #eee;
  color: #333;
  font-weight: 600;
  white-space: nowrap;
}
.comp-tag.bundesliga { background: #fde7c9; color: #a35200; }
.comp-tag.dfb-pokal  { background: #ffd0d0; color: #7d1813; }
.comp-tag.uefa-cl    { background: #cfd9eb; color: #1d3a6e; }
.comp-tag.uefa-el    { background: #fbe4b9; color: #7a4500; }
.comp-tag.uefa-ecl   { background: #cfe6cf; color: #1c5d1c; }

.poly-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.poly-comp h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  color: var(--lev-red);
}

footer {
  border-top: 1px solid var(--line);
  background: white;
  padding: 1rem 2rem;
  text-align: center;
}
