:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --border: #e0e0da;
  --text: #1c1c1a;
  --muted: #6c6c66;
  --accent: #7a2e5c;
  --accent-soft: #f4e8ef;
  --win: #1f7a4d;
  --loss: #a33b3b;
  --live: #c2410c;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1e1e23;
    --surface-2: #26262c;
    --border: #33333c;
    --text: #ececea;
    --muted: #9a9a95;
    --accent: #e08cba;
    --accent-soft: #33222d;
    --win: #58c68e;
    --loss: #e08585;
    --live: #fb923c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.1rem; }
h2 { font-size: 0.95rem; }

.topbar {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar__meta { color: var(--muted); font-size: 0.8rem; margin-left: auto; }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.panel__head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.panel__controls { margin-left: auto; display: flex; align-items: center; gap: 0.35rem; }

/* ------------------------------------------------------------------ picker */

.picker__label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.picker__input-wrap { position: relative; }

input[type="search"], input[type="date"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input[type="date"] { width: auto; padding: 0.35rem 0.5rem; font-size: 0.85rem; }
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.suggestions {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
  max-height: 300px;
  overflow-y: auto;
  z-index: 30;
}
.suggestions li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
}
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--accent-soft); }
.suggestions .rank { color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.suggestions .country { margin-left: auto; color: var(--muted); font-size: 0.75rem; }
.suggestions__more {
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
  padding-top: 0.5rem;
  color: var(--accent);
  font-size: 0.82rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; margin: 0.7rem 0 0; padding: 0; }
.chips:empty { margin: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.35rem 0.25rem 0.6rem;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
}
.chip button {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.2rem;
}
.chip button:hover { color: var(--loss); }

button.ghost {
  font: inherit;
  padding: 0.3rem 0.55rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}
button.ghost:hover { border-color: var(--accent); }
button.ghost[disabled] { opacity: 0.5; cursor: default; }

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

.scroll-x { overflow-x: auto; }

table.compare {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
table.compare th, table.compare td {
  text-align: right;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.compare th[scope="row"] {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}
table.compare thead th { text-align: right; vertical-align: bottom; }
table.compare tr.section th {
  padding-top: 1.1rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  border-bottom-color: transparent;
}
table.compare tbody tr:hover td { background: var(--surface-2); }

.player-head { display: flex; flex-direction: column; align-items: flex-end; gap: 0.1rem; }
.player-head__name { font-weight: 600; }
.player-head__sub { font-size: 0.75rem; color: var(--muted); font-weight: 400; }
.big { font-size: 1.02rem; font-weight: 600; }
.muted { color: var(--muted); }
.pos { color: var(--win); }
.neg { color: var(--loss); }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.needs-history {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.8rem;
  margin-top: 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
}
.needs-history .muted { flex: 1 1 12rem; }

/* --------------------------------------------------------------- slam grid */

.slam-grids { display: flex; flex-direction: column; gap: 1.1rem; margin-top: 1.2rem; }
.slam-grid h3 { font-size: 0.85rem; margin-bottom: 0.45rem; }
table.slams { border-collapse: collapse; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
table.slams th, table.slams td {
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  text-align: center;
  white-space: nowrap;
}
table.slams th { color: var(--muted); font-weight: 500; }
table.slams th.year { text-align: right; }
td.res { font-family: var(--mono); font-size: 0.78rem; }
td.res[data-r="W"] { background: var(--accent); color: #fff; font-weight: 700; }
td.res[data-r="F"] { background: var(--accent-soft); font-weight: 600; }
td.res[data-r="S"], td.res[data-r="Q"] { font-weight: 600; }
td.res[data-r="-"], td.res[data-r="QUAL"] { color: var(--muted); }

/* ----------------------------------------------------------------- matches */

.match-list { display: flex; flex-direction: column; gap: 0.4rem; }
.match {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.3rem 0.8rem;
  padding: 0.55rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.match--tappable { cursor: pointer; }
.match--tappable:hover { border-color: var(--accent); background: var(--accent-soft); }
.match--tappable:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.match__event {
  grid-column: 1 / -1;
  font-size: 0.72rem;
  color: var(--muted);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.match__state { text-transform: uppercase; letter-spacing: 0.05em; }
.match__state--in { color: var(--live); font-weight: 700; }
.match__side { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.match__side--won { font-weight: 650; }
.match__side--lost { color: var(--muted); }
.match__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match__rank { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.match__score { font-family: var(--mono); font-size: 0.82rem; text-align: right; }
.match__add {
  border: 0; background: none; padding: 0 0.15rem; cursor: pointer;
  color: var(--accent); font-size: 0.95rem; line-height: 1;
}
.match__add[disabled] { color: var(--muted); cursor: default; }

@media (max-width: 640px) {
  main { padding: 0.8rem; }
  .panel { padding: 0.8rem; }
}
