/* Dark sports-app look: near-black page, charcoal cards, periwinkle accent, green home / purple away. */
:root {
  --page: #0b0d0e;
  --bar: #15191c;
  --card: #1a1f22;
  --card-2: #222829;
  --field: #101416;
  --line: #2c3337;
  --text: #f2f4f5;
  --muted: #9aa3a8;
  --faint: #6b7479;
  --accent: #7c86ff;
  --accent-ink: #0e1240;
  --accent-soft: rgb(124 134 255 / 0.14);
  --home: #49c45e;
  --away: #7c86ff;
  --good: #49c45e;
  --good-bg: rgb(73 196 94 / 0.14);
  --bad: #ff6b6b;
  --bad-bg: rgb(255 107 107 / 0.13);
  --meh: #f2c14e;
  --meh-bg: rgb(242 193 78 / 0.13);
  --radius: 18px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* The page hides things with the hidden attribute; don't let display rules undo that. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 12px 24px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- App bar ---------- */

.appbar {
  background: var(--bar);
  border-bottom: 1px solid var(--line);
}

.appbar-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--text);
  font-size: 1.05rem;
}


/* ---------- Match header ---------- */

.match-card {
  background: var(--card);
  border-radius: 0 0 var(--radius) var(--radius);
  margin: 0 -12px;
  padding: 14px 16px 12px;
}

@media (min-width: 700px) {
  .match-card {
    margin: 12px 0 0;
    border-radius: var(--radius);
  }
}

.pickers {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
  margin-bottom: 12px;
}

.pickers select {
  margin-top: 0;
  min-height: 40px;
  font-size: 0.9rem;
}

.match-header {
  text-align: center;
  padding: 4px 0 6px;
}

.mh-date {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--field);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.mh-teams {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
}

.mh-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.mh-name {
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.mh-centre {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 10px;
  min-width: 90px;
}

.mh-time {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.mh-sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 4px;
}

.crest {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 3px rgb(255 255 255 / 0.12);
  background: var(--card-2);
  flex: none;
}

.crest.small {
  width: 26px;
  height: 26px;
  font-size: 0.62rem;
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / 0.12);
}

.source {
  margin-top: 12px;
}

.edit-teams {
  margin-top: 10px;
  font-size: 0.88rem;
}

.edit-teams summary {
  cursor: pointer;
  color: var(--accent);
  text-align: center;
  padding: 4px 0;
  list-style: none;
}

.edit-teams summary::-webkit-details-marker {
  display: none;
}

.edit-teams[open] summary {
  margin-bottom: 8px;
}

#auto-msg {
  text-align: center;
}

#auto-msg:empty {
  display: none;
}

/* ---------- Tab bar ---------- */

.main-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--page);
  border-bottom: 1px solid var(--line);
  margin: 0 -12px 12px;
}

.main-tabs button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--faint);
  font-weight: 700;
  font-size: 0.98rem;
  min-height: 50px;
  border-bottom: 3px solid transparent;
}

.main-tabs button[aria-selected='true'] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Cards ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 12px;
}

h2 {
  font-size: 1.12rem;
  font-weight: 700;
  margin: 0 0 14px;
  text-align: center;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 10px;
}

.hint.centre {
  text-align: center;
}

.note {
  font-size: 0.85rem;
  margin: 8px 0 0;
  color: var(--muted);
}

.note.error {
  color: var(--bad);
}

.foot {
  color: var(--faint);
  font-size: 0.78rem;
  margin: 18px 4px 40px;
  text-align: center;
}

/* ---------- Form controls ---------- */

.row {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.row.two {
  grid-template-columns: 1fr 1fr;
}

.row.three {
  grid-template-columns: 1fr 1fr 1fr;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.opt {
  font-size: 0.72rem;
  color: var(--faint);
}

input,
select,
button {
  font: inherit;
  color: var(--text);
}

input,
select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background-color: var(--field);
  min-height: 44px;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

input::placeholder {
  color: var(--faint);
}

input:focus,
select:focus,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* No spinner arrows on number boxes; they crowd small screens. */
input[type='number'] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

button {
  cursor: pointer;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card-2);
  min-height: 44px;
  padding: 0 14px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 0.88rem;
}

/* Segmented toggles (odds / expected goals, home / away team) */
.tabs,
.team-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--field);
  border-radius: 999px;
  padding: 4px;
  margin: 0 auto 14px;
  max-width: 360px;
}

.tabs button,
.team-toggle button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  min-height: 36px;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

.tabs button[aria-selected='true'],
.team-toggle button[aria-selected='true'] {
  background: var(--text);
  color: var(--page);
}

.advanced {
  margin-top: 6px;
  font-size: 0.88rem;
}

.advanced summary {
  cursor: pointer;
  color: var(--accent);
  padding: 4px 0;
}

.advanced label {
  margin-top: 8px;
}

.advanced .hint {
  margin-top: 6px;
}

/* ---------- Bet builder ---------- */

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.summary > div,
.ms-goals > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--field);
  border-radius: 12px;
  padding: 8px 10px;
}

.k {
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.v {
  font-weight: 700;
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
}

.add-leg {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.add-leg select {
  margin-top: 0;
}

.legs {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.legs li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  margin-top: 6px;
  background: var(--field);
  border-radius: 12px;
}

.legs .p {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.legs .p small {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 400;
}

.legs .remove {
  min-height: 32px;
  width: 32px;
  padding: 0;
  color: var(--muted);
  border-radius: 50%;
  background: var(--card-2);
}

.headline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  text-align: center;
}

.headline > div {
  background: var(--field);
  border-radius: 14px;
  padding: 12px 8px;
}

.big {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

#corr {
  text-align: center;
}

.bookie {
  margin-top: 14px;
}

.verdict {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
}

.verdict strong {
  display: block;
  font-size: 1.02rem;
}

.verdict.good {
  background: var(--good-bg);
  color: var(--good);
}

.verdict.bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.verdict.meh {
  background: var(--meh-bg);
  color: var(--meh);
}

/* ---------- Who will win ---------- */

.pills {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--field);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pill.picked {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #fff;
}

.pill-x {
  color: var(--muted);
  font-weight: 700;
}

.winner .pick {
  margin-top: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
}

.winner .conf {
  margin-top: 6px;
  font-size: 0.84rem;
  color: var(--muted);
  text-align: center;
}

#ms-winner-empty {
  text-align: center;
}

.conf-badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.conf-high,
.conf-good {
  background: var(--good-bg);
  color: var(--good);
}

.conf-medium {
  background: var(--meh-bg);
  color: var(--meh);
}

.conf-low,
.conf-tossup {
  background: var(--bad-bg);
  color: var(--bad);
}

/* ---------- Goals ---------- */

.ms-goals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ms-goals .k {
  white-space: normal;
  overflow: visible;
}

.ms-scores {
  margin: 12px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
}

.ms-scores strong {
  color: var(--text);
}

/* ---------- Stats comparison ---------- */

.cmp-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.cmp-legend .home {
  color: var(--home);
}

.cmp-legend .away {
  color: var(--away);
}

.cmp-row {
  padding: 10px 0;
}

.cmp-top {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
}

.cmp-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
}

.cmp-val.away {
  text-align: right;
}

.cmp-label {
  text-align: center;
  font-size: 0.9rem;
}

.cmp-label small {
  display: block;
  color: var(--faint);
  font-size: 0.72rem;
}

.cmp-bars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.cmp-track {
  height: 7px;
  border-radius: 4px;
  background: var(--card-2);
  overflow: hidden;
  display: flex;
}

.cmp-track.home {
  justify-content: flex-end;
}

.cmp-track i {
  display: block;
  height: 100%;
  border-radius: 4px;
}

.cmp-track.home i {
  background: var(--home);
}

.cmp-track.away i {
  background: var(--away);
}

/* ---------- Tables ---------- */

.table-scroll {
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
}

.stat-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.stat-table th,
.stat-table td {
  text-align: right;
  padding: 9px 5px;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}

.stat-table th:first-child,
.stat-table td:first-child {
  text-align: left;
}

.stat-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.76rem;
  border-top: 0;
}

.stat-table .sub {
  display: block;
  color: var(--faint);
  font-size: 0.72rem;
  font-weight: 400;
}

.stat-table.players {
  min-width: 520px;
}

.stat-table.players th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.stat-table.players th.sorted {
  color: var(--accent);
}

.stat-table.players tbody tr.player {
  cursor: pointer;
}

.stat-table.players td:first-child {
  white-space: nowrap;
  font-weight: 600;
}

.stat-table.players tr.detail td {
  text-align: left;
  white-space: normal;
  font-size: 0.84rem;
  color: var(--muted);
  background: var(--field);
  border-top: 0;
}

.stat-table.players tr.detail p {
  margin: 4px 0;
}

.status-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--meh-bg);
  color: var(--meh);
}

.status-badge.out {
  background: var(--bad-bg);
  color: var(--bad);
}

.pl-foot {
  margin-top: 10px;
}

.ms-note {
  margin: 4px 4px 14px;
  text-align: center;
}

.stat-table.upcoming tbody tr {
  cursor: pointer;
}

.stat-table.upcoming tbody tr.current td {
  background: var(--accent-soft);
}

.stat-table.upcoming td:nth-child(2) {
  text-align: left;
  white-space: normal;
  font-weight: 600;
}

.stat-table.upcoming td:first-child {
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.8rem;
}

/* ---------- Track record ---------- */

.record summary {
  cursor: pointer;
  list-style: none;
}

.record summary::-webkit-details-marker {
  display: none;
}

.record summary h2 {
  margin: 0;
}

.record summary h2::after {
  content: ' ▾';
  color: var(--muted);
  font-size: 0.85rem;
}

.record[open] summary h2 {
  margin-bottom: 12px;
}

.record h3 {
  font-size: 0.92rem;
  margin: 16px 0 0;
}

.record .stat-table td.good {
  color: var(--good);
  font-weight: 700;
}

.record .stat-table td.bad {
  color: var(--bad);
}

.record-download {
  margin: 14px 0 0;
  font-size: 0.88rem;
  text-align: center;
}

.record-download a {
  color: var(--accent);
  font-weight: 700;
}

@media (max-width: 400px) {
  .row.three {
    gap: 6px;
  }

  .big {
    font-size: 1.65rem;
  }

  .crest {
    width: 48px;
    height: 48px;
  }

  .mh-time {
    font-size: 1.6rem;
  }
}

/* ---------- Logos ---------- */

.crest.logo {
  background: transparent;
  box-shadow: none;
}

.crest.logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.team-line {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.5;
}

.team-line .crest.small {
  width: 20px;
  height: 20px;
  font-size: 0.5rem;
}

/* ---------- Match strip (top bar, wide screens) ---------- */

.strip {
  display: none;
}

/* ---------- Layout: phone = one column; prediction comes before the tabs ---------- */

.layout {
  display: flex;
  flex-direction: column;
}

.side-top .card:first-child {
  margin-top: 12px;
}

/* ---------- Layout: desktop ---------- */

@media (min-width: 1000px) {
  .appbar-inner,
  main.layout {
    max-width: 1240px;
  }

  .appbar-inner {
    padding: 14px 20px;
  }

  .strip:not([hidden]) {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 20px 12px;
    scrollbar-width: thin;
  }

  .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    font-size: 0.82rem;
    font-weight: 600;
  }

  .chip.current {
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  .chip .crest.small {
    width: 20px;
    height: 20px;
    font-size: 0.5rem;
  }

  .chip-time {
    color: var(--muted);
  }

  .chip-dash {
    color: var(--faint);
  }

  .chip-pct {
    color: var(--accent);
    margin-left: 2px;
  }

  main.layout {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    grid-template-areas:
      'header header'
      'sidetop panel'
      'sidebottom panel'
      'foot foot';
    grid-template-rows: auto auto 1fr auto;
    column-gap: 16px;
    padding: 16px 20px 24px;
    align-items: start;
  }

  .match-card {
    grid-area: header;
    margin: 0 0 16px;
    border-radius: var(--radius);
    padding: 18px 24px 16px;
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    grid-template-areas:
      'auto header source'
      'auto header msg'
      'edit header .';
    align-items: start;
    column-gap: 20px;
  }

  .match-card #auto {
    grid-area: auto;
  }

  .match-card .pickers {
    grid-template-columns: 1fr;
    margin: 0;
  }

  .match-card .match-header {
    grid-area: header;
  }

  .match-card .source {
    grid-area: source;
    margin: 0;
  }

  .match-card #auto-msg {
    grid-area: msg;
    text-align: left;
  }

  .match-card .edit-teams {
    grid-area: edit;
  }

  .match-card .edit-teams summary {
    text-align: left;
  }

  .crest {
    width: 72px;
    height: 72px;
    font-size: 1.3rem;
  }

  .mh-name {
    font-size: 1.15rem;
  }

  .mh-time {
    font-size: 2.4rem;
  }

  .side-top {
    grid-area: sidetop;
  }

  .side-top .card:first-child {
    margin-top: 0;
  }

  .side-bottom {
    grid-area: sidebottom;
  }

  .foot {
    grid-area: foot;
  }

  /* The right-hand panel: one big card with the tab bar on top, sections inside. */
  .panel {
    grid-area: panel;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
  }

  .panel .main-tabs {
    position: static;
    margin: 0;
    background: transparent;
  }

  .panel .card {
    background: transparent;
    border-radius: 0;
    margin: 0;
    padding: 18px 22px;
  }

  #view-builder:not([hidden]),
  #view-stats:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  #view-builder > .card:first-child {
    grid-row: span 2;
    border-right: 1px solid var(--line);
  }

  #view-builder > .card + .card {
    border-bottom: 1px solid var(--line);
  }

  #view-stats > .card {
    border-bottom: 1px solid var(--line);
  }

  /* Goals and over/under on the left, the stats comparison down the right. */
  #view-stats > [aria-labelledby='goals-h'],
  #view-stats > #ms-lines-card {
    grid-column: 1;
    border-right: 1px solid var(--line);
  }

  #view-stats > [aria-labelledby='stats-h'] {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  #players-card,
  #view-stats > .ms-note {
    grid-column: 1 / -1;
  }

  #players-card .table-scroll {
    margin: 0;
    padding: 0;
  }

  .stat-table.players {
    min-width: 0;
  }
}

/* Dark scrollbars everywhere. */
* {
  scrollbar-color: var(--line) transparent;
}

.pick-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  justify-content: flex-end;
  margin-bottom: 3px;
}

.pick-line .crest.small {
  width: 20px;
  height: 20px;
  font-size: 0.5rem;
}

.stat-table.upcoming td:last-child {
  text-align: right;
}

.stat-table.upcoming td:last-child .conf-badge {
  display: block;
  width: fit-content;
  margin-left: auto;
}

/* ---------- Live scores ---------- */

.mh-sub.live,
.sub.live,
.chip-time.live {
  color: #ff5b5b;
  font-weight: 700;
}

.stat-table.upcoming .score {
  display: block;
  color: var(--text);
  font-size: 0.95rem;
}

.live-verdict {
  margin-top: 10px;
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 8px 10px;
  border-radius: 12px;
}

.live-verdict.good {
  background: var(--good-bg);
  color: var(--good);
}

.live-verdict.bad {
  background: var(--bad-bg);
  color: var(--bad);
}

/* ---------- Page links in the top bar ---------- */

.appnav {
  display: flex;
  gap: 4px;
}

.appnav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 7px 12px;
  border-radius: 999px;
}

.appnav a[aria-current='page'] {
  color: var(--text);
  background: var(--card-2);
}

.appnav a:hover {
  color: var(--text);
}

/* ---------- Track record page ---------- */

.record-page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 12px 24px;
}

.record-hero {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}

.record-hero h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.kpi {
  background: var(--field);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}

.kpi-v {
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kpi-v.small {
  font-size: 1.15rem;
  padding-top: 8px;
}

#record-msg:empty {
  display: none;
}

.record-grid .stat-table td.good {
  color: var(--good);
  font-weight: 700;
}

.record-grid .stat-table td.bad {
  color: var(--bad);
}

.record-grid .team-line .crest.small {
  width: 20px;
  height: 20px;
  font-size: 0.5rem;
}

@media (min-width: 1000px) {
  .record-page {
    padding: 20px;
  }

  .kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .record-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    align-items: start;
  }

  .record-grid .card {
    margin: 0;
  }

  .record-grid .card.wide {
    grid-column: 1 / -1;
  }
}

/* Track record tables: team names left-aligned; wide tables scroll sideways on phones. */
.record-grid .stat-table td:has(.team-line) {
  text-align: left;
}

@media (min-width: 640px) {
  .record-grid #recent-out .stat-table,
  .record-grid #waiting-out .stat-table,
  .record-grid #markets-out .stat-table {
    min-width: 540px;
  }
}

.record-grid .stat-table td:first-child {
  white-space: nowrap;
}

/* ---------- Track record: filters and charts ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 14px 0 0;
}

.seg {
  display: inline-flex;
  background: var(--field);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  flex-wrap: wrap;
}

.seg button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
}

.seg button[aria-checked='true'] {
  background: var(--text);
  color: var(--page);
}

.f-league select {
  margin-top: 0;
  min-height: 42px;
  min-width: 170px;
}

.chart-box {
  width: 100%;
  margin-top: 4px;
}

.chart-box.calib {
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

svg.chart {
  display: block;
  overflow: visible;
  --series-1: #3987e5;
}

svg.chart .grid {
  stroke: var(--line);
  stroke-width: 1;
}

svg.chart .baseline {
  stroke: #3b4549;
  stroke-width: 1;
}

svg.chart .axis {
  fill: var(--faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

svg.chart .axis.label {
  fill: var(--muted);
  font-size: 12px;
}

svg.chart .axis.faint {
  font-size: 10px;
}

svg.chart .ref-label {
  fill: var(--muted);
}

svg.chart .reference {
  stroke: var(--muted);
  stroke-width: 1.5;
  opacity: 0.7;
}

svg.chart .series-line {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

svg.chart .series-area {
  fill: var(--series-1);
  opacity: 0.1;
}

svg.chart .series-dot {
  fill: var(--series-1);
  stroke: var(--card);
  stroke-width: 2;
}

svg.chart .series-bar {
  fill: var(--series-1);
}

svg.chart .expected-tick {
  stroke: var(--text);
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.75;
}

svg.chart .value-label {
  fill: var(--text);
  font-size: 12px;
  font-weight: 700;
}

svg.chart .crosshair {
  stroke: var(--muted);
  stroke-width: 1;
}

svg.chart .hit {
  cursor: pointer;
  outline: none;
}

svg.chart .hit:hover .series-bar,
svg.chart .hit:focus .series-bar,
svg.chart .hit:hover .series-dot,
svg.chart .hit:focus .series-dot {
  filter: brightness(1.25);
}

.chart-tip {
  position: absolute;
  z-index: 50;
  pointer-events: none;
  background: #0f1315;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.82rem;
  color: var(--muted);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.4);
  max-width: 260px;
}

.chart-tip strong {
  color: var(--text);
}

.chart-tip .lead strong {
  font-size: 1rem;
}

.numbers {
  margin-top: 8px;
  font-size: 0.88rem;
}

.numbers summary {
  cursor: pointer;
  color: var(--accent);
}

.src-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--card-2);
  color: var(--muted);
}

.src-badge.pre {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- Sortable tables and table controls ---------- */

.stat-table.sortable th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.stat-table.sortable th[aria-sort='ascending'],
.stat-table.sortable th[aria-sort='descending'] {
  color: var(--accent);
}

.stat-table.sortable th[aria-sort='ascending']::after {
  content: ' ▲';
  font-size: 0.7em;
}

.stat-table.sortable th[aria-sort='descending']::after {
  content: ' ▼';
  font-size: 0.7em;
}

.stat-table.sortable th:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.table-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}

.table-controls input,
.table-controls select {
  margin-top: 0;
  min-height: 40px;
}

.tc-search {
  flex: 1 1 200px;
}

.tc-count select {
  min-width: 120px;
}

.seg.small button {
  min-height: 32px;
  padding: 0 12px;
}

/* ---------- Phones ---------- */

/* Never wider than the screen. */
html,
body {
  overflow-x: clip;
}

.mh-name {
  overflow-wrap: break-word;
  hyphens: auto;
}

.kpi .k {
  white-space: normal;
}

.stat-table.upcoming th:nth-child(2) {
  text-align: left;
}

/* Player names stay put while the stats scroll sideways. */
.stat-table.players tr:not(.detail) > :first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card);
}

@media (max-width: 639px) {
  .appbar-inner {
    padding: 10px 12px;
    gap: 8px;
  }

  .brand {
    font-size: 1.1rem;
    white-space: nowrap;
  }

  .appnav a {
    white-space: nowrap;
    font-size: 0.85rem;
    padding: 7px 10px;
  }

  .summary,
  .ms-goals {
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  }

  .tabs button,
  .team-toggle button,
  .main-tabs button {
    white-space: nowrap;
  }

  /* Track record filters: full-width rows that never wrap inside a button. */
  .record-hero {
    padding: 16px;
  }

  .filters .seg,
  .filters .f-league {
    width: 100%;
  }

  .seg {
    flex-wrap: nowrap;
  }

  .seg button {
    flex: 1 1 auto;
    white-space: nowrap;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .tc-search {
    flex-basis: 100%;
  }

  .table-controls .seg {
    flex: 1 1 auto;
  }

  /* Stacked tables: the headings become sort buttons, each row a small card. */
  .stat-table.stack,
  .stat-table.stack thead,
  .stat-table.stack tbody {
    display: block;
    width: 100%;
  }

  .stat-table.stack thead tr {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0 10px;
  }

  .stat-table.stack th {
    text-align: left !important;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--field);
    font-size: 0.74rem;
  }

  .stat-table.stack th:empty {
    display: none;
  }

  .stat-table.stack tbody tr {
    display: grid;
    gap: 6px 10px;
    align-items: center;
    padding: 10px 0;
    border-top: 1px solid var(--line);
  }

  .stat-table.stack td {
    border: 0;
    padding: 0;
    min-width: 0;
    text-align: left;
    white-space: normal !important;
  }

  .stat-table.stack-waiting td:nth-child(n + 4)::before,
  .stat-table.stack-markets td:nth-child(n + 2)::before,
  .stat-table.stack-recent td:nth-child(4)::before {
    content: attr(data-label) ' ';
    color: var(--faint);
    font-size: 0.74rem;
    font-weight: 400;
  }

  .stat-table.stack-waiting td:nth-child(n + 4):not(:last-child)::before,
  .stat-table.stack-markets td:nth-child(n + 2)::before {
    display: block;
  }

  .table-controls .seg.small button {
    padding: 0 8px;
  }

  .tc-count select {
    min-width: 0;
    width: 104px;
  }

  /* Latest results: match and score; prediction and result; date and how it was saved. */
  .stat-table.stack-recent tbody tr {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      'match match score'
      'pred pred result'
      'date saved saved';
  }

  .stack-recent td:nth-child(1) {
    grid-area: date;
    color: var(--muted);
    font-size: 0.78rem;
  }

  .stack-recent td:nth-child(2) {
    grid-area: match;
    font-weight: 600;
  }

  .stack-recent td:nth-child(3) {
    grid-area: score;
    font-size: 1.05rem;
    font-weight: 800;
    text-align: right;
  }

  .stack-recent td:nth-child(4) {
    grid-area: pred;
  }

  .stack-recent td:nth-child(5) {
    grid-area: result;
    text-align: right;
  }

  .stack-recent td:nth-child(6) {
    grid-area: saved;
  }

  /* Waiting: kick-off and league; match; the three chances; the prediction. */
  .stat-table.stack-waiting tbody tr {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      'ko ko league'
      'match match match'
      'home draw away'
      'pred pred pred';
  }

  .stack-waiting td:nth-child(1) {
    grid-area: ko;
    color: var(--muted);
    font-size: 0.78rem;
  }

  .stack-waiting td:nth-child(2) {
    grid-area: league;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: right;
  }

  .stack-waiting td:nth-child(3) {
    grid-area: match;
    font-weight: 600;
  }

  .stack-waiting td:nth-child(4) {
    grid-area: home;
  }

  .stack-waiting td:nth-child(5) {
    grid-area: draw;
  }

  .stack-waiting td:nth-child(6) {
    grid-area: away;
  }

  .stack-waiting td:nth-child(7) {
    grid-area: pred;
    font-weight: 600;
  }

  /* By market: the name, then the numbers in two rows of three. */
  .stat-table.stack-markets tbody tr {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      'name name name'
      'said happened matches'
      'loss same same';
  }

  .stack-markets td:nth-child(1) {
    grid-area: name;
    font-weight: 700;
  }

  .stack-markets td:nth-child(2) {
    grid-area: matches;
  }

  .stack-markets td:nth-child(3) {
    grid-area: said;
  }

  .stack-markets td:nth-child(4) {
    grid-area: happened;
  }

  .stack-markets td:nth-child(5) {
    grid-area: loss;
  }

  .stack-markets td:nth-child(6) {
    grid-area: same;
  }
}

@media (max-width: 369px) {
  /* Very narrow phones: the logo alone, so the page links fit on one line. */
  .brand {
    font-size: 0;
    gap: 0;
  }

  .appnav a {
    padding: 7px 9px;
  }

  .mh-name {
    font-size: 0.9rem;
  }

  .mh-centre {
    min-width: 70px;
  }

  .tabs button,
  .team-toggle button {
    font-size: 0.84rem;
  }

  .cmp-top {
    grid-template-columns: 52px 1fr 52px;
  }
}
