:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --border: #e5e7eb;
  --up: #15803d;
  --down: #b91c1c;
  --accent: #2563eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

header, main, footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}
.wide header, .wide main, .wide footer { max-width: 1240px; }

header { padding-top: 24px; }
.nav { display: flex; gap: 4px; margin-bottom: 14px; font-size: 0.9rem; }
.nav a { padding: 4px 12px; border-radius: 999px; color: var(--muted); }
.nav a:hover { text-decoration: none; background: #e9ecf1; }
.nav a[aria-current="page"] { background: var(--accent); color: #fff; }
h1 { margin: 0 0 4px; font-size: 1.6rem; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
h3 { margin: 0; font-size: 1.05rem; }
.sub { margin: 0 0 16px; }
.muted { color: var(--muted); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: 0.9em; }

.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
}
.link-button:hover { text-decoration: underline; }

/* toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 16px;
}
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search input {
  width: 100%;
  padding: 8px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.player-filters { align-items: flex-start; }
.filter-menus { display: flex; flex: 1 1 100%; gap: 8px; flex-wrap: wrap; }
.filter-menu { position: relative; }
.filter-menu summary, #directory-reset {
  padding: 7px 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.filter-menu summary { list-style: none; }
.filter-menu summary::-webkit-details-marker { display: none; }
.filter-menu summary::after { content: " ▾"; color: var(--muted); }
.filter-menu[open] summary { border-color: var(--accent); }
.filter-choices {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  max-height: 290px;
  overflow-y: auto;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.filter-choices label { display: flex; align-items: center; gap: 7px; padding: 3px 5px; white-space: nowrap; cursor: pointer; }
.filter-actions { display: flex; gap: 5px; padding-bottom: 5px; border-bottom: 1px solid var(--border); margin-bottom: 5px; }
.filter-actions button { border: 0; background: #eef2ff; border-radius: 4px; padding: 3px 9px; cursor: pointer; }
.player-icon { width: 18px; height: 18px; object-fit: contain; vertical-align: middle; margin-right: 4px; image-rendering: pixelated; }
.subpath-icon { width: 28px; height: 28px; object-fit: contain; vertical-align: middle; margin-right: 4px; image-rendering: pixelated; }
.mark-icon { width: 24px; height: 24px; object-fit: contain; vertical-align: middle; image-rendering: pixelated; }
.chart-controls { display: flex; flex-wrap: wrap; gap: 12px; }
.chart-controls select { padding: 6px 8px; font: inherit; }
#chart-note { margin-top: 0; }
.player-board { min-width: 1300px; }
.board-wrap:has(.player-board) { overflow-x: auto; }
.player-board th:first-child, .player-board td:first-child { position: sticky; left: 0; z-index: 2; background: var(--panel); }
.player-board thead th:first-child { z-index: 3; background: #f0f2f5; }
.player-board tr.tracked td:first-child { background: #eef2ff; }
.player-board td { vertical-align: middle; }
.player-board .path-rank { white-space: nowrap; }
.path-rank .player-icon { margin: 0 0 0 3px; }
.player-board th button { white-space: nowrap; }
.toolbar select {
  padding: 7px 10px;
  font: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.suggestions {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  max-height: 320px;
  overflow-y: auto;
}
.suggestions button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.suggestions button:hover, .suggestions button:focus { background: #eef2ff; outline: none; }
.suggestions .rank { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.suggestions .empty { padding: 6px 10px; color: var(--muted); }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle:has(input:disabled) { opacity: 0.45; cursor: default; }
.segmented {
  display: inline-flex;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}
.segmented label {
  padding: 6px 12px;
  cursor: pointer;
  user-select: none;
}
.segmented label + label { border-left: 1px solid var(--border); }
.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented label:has(input:checked) { background: var(--accent); color: #fff; }

/* panels & cards */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  padding: 14px 16px;
}
.card .remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.card .remove:hover { background: #f1f5f9; color: var(--down); }
.card h3 { padding-right: 28px; }
.card .title { font-weight: normal; color: var(--muted); }
.card .rank { font-size: 2.2rem; font-weight: 700; line-height: 1.1; margin: 6px 0 2px; }
.card .rank small { font-size: 0.95rem; font-weight: 600; margin-left: 6px; }
.card .rank .rank-label { font-weight: 500; }
.card .rank-sub { margin: 0 0 4px; color: var(--text); }
.card .rank-sub .delta { font-size: 0.85rem; margin-left: 4px; }
.card .real { margin: 0 0 6px; }
.card .real strong { font-size: 1.1rem; }
.card .real details { display: inline; }
.card .real summary { cursor: pointer; display: inline; color: var(--accent); }
.card .real summary::-webkit-details-marker { display: none; }
.card .real ul { margin: 6px 0 0; padding-left: 18px; font-size: 0.9rem; }
.card .gap { font-size: 1.05rem; margin: 4px 0; }
.card .gap strong { font-size: 1.25rem; }
.card .stats { font-size: 0.85rem; color: var(--muted); margin: 0; }
.card.absent { border-left-style: dashed; }

.up { color: var(--up); }
.down { color: var(--down); }

.chart-wrap { position: relative; height: 420px; }
.chart-heading { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chart-heading h2 { margin: 0; }
.rankings-chart { height: 360px; }
.rankings-chart canvas[hidden] { display: none !important; }

/* history table */
.table-wrap { overflow-x: auto; }
.table-wrap table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.table-wrap th, .table-wrap td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.table-wrap th:first-child, .table-wrap td:first-child { text-align: left; }
.table-wrap thead th { background: #f0f2f5; position: sticky; top: 0; }
.table-wrap thead tr:first-child th { border-bottom: none; text-align: center; }
.table-wrap thead tr:first-child th:first-child { text-align: left; }
.table-wrap thead .group { border-left: 1px solid var(--border); }
.table-wrap tbody td.group { border-left: 1px solid var(--border); }
.table-wrap tbody tr:hover { background: #f8fafc; }
.table-wrap td .target { color: var(--muted); font-size: 0.85rem; margin-left: 6px; }
.table-wrap td .delta { font-size: 0.85rem; margin-left: 4px; }
.table-wrap td .uncertain { color: var(--muted); font-size: 0.85rem; }
.table-footer { margin: 10px 0 0; text-align: center; }

/* "to pass" mini table inside cards */
.card .next-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 6px;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}
.card .next-table th {
  padding: 2px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}
.card .next-table td { padding: 3px 6px; border-bottom: 1px solid #f1f5f9; }
.card .next-table tr:last-child td { border-bottom: none; }
.card .next-table .num { text-align: right; white-space: nowrap; }
.card .next-table td:first-child { width: 3.5em; }
.card .next-table tbody tr:first-child td { font-size: 1rem; }
.card .next-table strong { font-size: 1.1rem; }

footer { padding: 8px 16px 32px; font-size: 0.85rem; }
footer p { margin: 0 0 8px; }

/* rankings page */
.board-panel { padding: 0 0 8px; }
.board-wrap { overflow: visible; } /* lets the header stick to the viewport */
@media (max-width: 1000px) {
  .board-wrap { overflow-x: auto; }
}
.board { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.board th, .board td { padding: 5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
.board th:first-child, .board td:first-child { padding-left: 14px; }
.board th:last-child, .board td:last-child { padding-right: 14px; }
.board .num { text-align: right; }
.board .stale-stat { color: var(--muted); }
.board thead th { position: sticky; top: 0; background: #f0f2f5; z-index: 1; }
.board thead tr th:first-child { border-top-left-radius: 10px; }
.board thead tr th:last-child { border-top-right-radius: 10px; }
.board thead th.sortable button {
  all: unset;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.board thead th.sortable button:hover { color: var(--accent); }
.board thead th.active button { color: var(--accent); }
.board .arrow { font-size: 0.7em; margin-left: 4px; }
.board tbody tr:hover td { background: #f8fafc; }
.board tbody tr.tracked td { background: #eef2ff; }
.board td.player { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.board td.strong { font-weight: 600; }
.board td.status { text-align: center; }
.board td .target { color: var(--muted); font-size: 0.85rem; margin-left: 6px; }
.board td .delta { font-size: 0.8rem; margin-left: 4px; }
.board td .uncertain { color: var(--muted); font-size: 0.85rem; }
.board .chart-link { font-size: 0.75rem; color: var(--muted); margin-left: 4px; }
.board tr:hover .chart-link { color: var(--accent); }
#empty { padding: 16px; }

@media (max-width: 600px) {
  .chart-wrap { height: 320px; }
  .rankings-chart { height: 300px; }
  th, td { padding: 5px 6px; }
}
