:root {
  --bg: #f5f5f7;
  --surface: #fff;
  --surface-alt: #ebebed;
  --border: #d2d2d7;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --link: #0066cc;
  --green: #1a8f3a;
  --red: #ff3b30;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius: 8px;
  --card-bg: var(--surface);
  --hover: var(--surface-alt);
  --chart-line: #1a3a5c;
  --chart-bg: var(--surface);
  --chart-width: 345px;
  --chart-height: 535px;
  --chart-aspect-w: 800;
  --chart-aspect-h: 400;
  /* Shared form sizing (every input / select / textarea / primary button) */
  --form-py: 0.4rem;
  --form-px: 0.65rem;
  --form-font: 0.9rem;
  --form-min-h: 2.35rem;
  --header-nav-max-width: 1400px;
  --main-max-width: 1200px;
  --header-bar-bg: #1c1c1e;
  --header-bar-border: #3a3a3c;
  --header-bar-text: #f5f5f7;
  --header-bar-muted: #a1a1a6;
  --header-bar-input-bg: #2c2c2e;
  --header-bar-input-border: #48484a;
}

/* -------- Global form controls (SPA + Tools + any page using this CSS) -------- */
input[type="text"],
input[type="search"],
input[type="url"],
input[type="email"],
input[type="tel"],
input[type="number"],
select,
textarea {
  font-family: inherit;
  font-size: var(--form-font);
  line-height: 1.35;
  padding: var(--form-py) var(--form-px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  min-height: var(--form-min-h);
  box-sizing: border-box;
}

textarea {
  min-height: 6.5rem;
  resize: vertical;
  padding: 0.5rem 0.75rem;
}

input[type="checkbox"],
input[type="radio"] {
  min-height: auto;
  width: auto;
  height: auto;
  padding: 0;
  vertical-align: middle;
  accent-color: var(--accent);
}

input[type="text"]::placeholder,
input[type="search"]::placeholder,
textarea::placeholder {
  color: var(--muted);
}

button {
  min-height: var(--form-min-h);
  padding: var(--form-py) 0.9rem;
  box-sizing: border-box;
}

.db-banner {
  background: #fef3c7;
  color: #92400e;
  padding: 0.5rem 1.5rem;
  text-align: center;
  font-size: 0.9rem;
}

.db-banner code {
  background: rgba(0, 0, 0, 0.06);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 18px;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: var(--header-bar-bg);
  border-bottom: 1px solid var(--header-bar-border);
  padding: 1rem 0;
}

.header .container-inner {
  max-width: var(--header-nav-max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.header h1 a {
  color: var(--header-bar-text);
  text-decoration: none;
}

.header h1 a:hover {
  color: #7eb8ff;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}

.controls label {
  font-size: 0.9rem;
  color: var(--muted);
}

.header .controls label {
  color: var(--header-bar-muted);
}

.controls label.toggle-inactive {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.controls select {
  margin-left: 0.25rem;
}

/* Dark bar: selects + search sit on dark background */
.header .controls select {
  background: var(--header-bar-input-bg);
  border: 1px solid var(--header-bar-input-border);
  color: var(--header-bar-text);
  border-radius: var(--radius);
}

.header .controls select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 145, 255, 0.35);
  outline: none;
}

.header .controls input[type="checkbox"] {
  accent-color: var(--accent);
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 320px;
  max-width: 100%;
}

/* Header search: keep dropdown same width as field (no mega-wide panel) */
.header .controls .search-wrap {
  width: 320px;
  max-width: min(320px, calc(100vw - 2rem));
}

.header .controls .search-wrap .search-results {
  min-width: 0;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}

.search-wrap input::placeholder {
  color: var(--muted);
}

.search-wrap label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.header .search-wrap {
  position: relative;
}

/* Magnifying glass icon inside the search field */
.header .search-wrap::before {
  content: "";
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.8)" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>') center/contain no-repeat;
  pointer-events: none;
  z-index: 1;
}

.header .search-wrap input {
  background: rgba(255, 255, 255, 0.18);
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  color: var(--header-bar-text);
  padding-left: 2.2rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.header .search-wrap input::placeholder {
  color: rgba(255, 255, 255, 0.65);
}

.header .search-wrap input:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.24);
  box-shadow: 0 0 0 2px rgba(0, 145, 255, 0.45), 0 1px 4px rgba(0, 0, 0, 0.35);
  outline: none;
}

.header .search-wrap label {
  color: var(--header-bar-muted);
}

#view-compare .search-wrap input {
  width: 26rem;
  min-width: 20rem;
  max-width: 100%;
}

#view-compare-players .search-wrap input {
  width: 22rem;
  min-width: 18rem;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow-y: auto;
  z-index: 9999;
}

.search-results li {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.search-results li>span:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

.search-results li>span:first-child em {
  color: var(--muted);
  font-style: normal;
  margin-left: 0.45rem;
}

.search-results li:last-child {
  border-bottom: none;
}

.search-results li:hover {
  background: var(--surface-alt);
}

.search-results .rating {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.search-results li.fed-all-item {
  color: var(--muted);
  font-style: italic;
  border-bottom: 1px solid var(--border);
}

/* Player page: slim chrome — no filter bar */
body.page-player .header .container-inner {
  min-height: 0;
}

.player-page-context {
  padding: 0.4rem 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

body.page-player .nav {
  border-top: none;
}

.nav {
  padding: 0.5rem 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav .container-inner {
  max-width: var(--header-nav-max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* nav-links: transparent wrapper on wide screens, collapsible on mobile */
.nav-links {
  display: contents;
  /* children flow directly into the flex container */
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.nav a:hover {
  color: var(--accent);
  background: var(--surface-alt);
}

.nav a.active {
  color: var(--accent);
  font-weight: 600;
  background: rgba(0, 113, 227, 0.07);
}

/* Hamburger toggle button — hidden by default */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  min-height: auto;
  padding: 0.35rem 0.45rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  border-radius: var(--radius);
  margin-left: auto;
}

.nav-toggle:hover {
  background: var(--surface-alt);
  color: var(--text);
}

#main {
  flex: 1;
  padding: 1.5rem;
  max-width: var(--main-max-width);
  width: 100%;
  margin: 0 auto;
}

/* -------- Stats hub (new page) -------- */
body.page-stats-hub #main {
  max-width: var(--header-nav-max-width);
}

.stats-hub {
  display: grid;
  gap: 1rem;
}

.stats-hub-allgrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}
.stats-hub-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0.85rem;
}
.stats-hub-col-title {
  font-weight: 900;
  color: var(--text);
  margin: 0 0 0.65rem 0;
  padding: 0.6rem 0.75rem;
  border-radius: 12px;
  min-height: 3.1rem; /* keep headers aligned even if they wrap */
  display: flex;
  align-items: center;
}
.stats-hub-list {
  display: grid;
  gap: 0;
}
.stats-hub-section-links {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.stats-hub-section-title {
  display: block;
  width: 100%;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text);
  margin: 0.85rem 0 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  line-height: 1.4;
}
.stats-hub-col .stats-hub-section:first-child .stats-hub-section-title {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.stats-hub-link {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0.55rem 0.4rem;
  border-radius: 10px;
  cursor: pointer;
  border-top: 1px solid rgba(0,0,0,0.06); /* divider per stat */
  white-space: normal;
  line-height: 1.35;
}
.stats-hub-col .stats-hub-section:first-child .stats-hub-section-links .stats-hub-link:first-child {
  border-top: 0;
}
.stats-hub-section:not(:first-child) .stats-hub-section-links .stats-hub-link:first-child {
  border-top: 0;
}
.stats-hub-link:hover { background: var(--surface-alt); }
.stats-hub-link.is-active { background: rgba(0,113,227,0.10); }

.stats-hub-note { margin-top: 0.35rem; font-size: 0.95rem; }
.stats-hub-filters { display:flex; flex-wrap:wrap; gap:0.75rem; align-items:flex-end; margin-top:0.75rem; }

/* Full main width like /stats — avoid .table-wrap.table-list { width: fit-content } shrinking charts. */
body.page-stats-hub .stats-hub-panel.table-wrap {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: visible;
}
.stats-hub-panel-inner {
  padding: 0.85rem 1rem 1rem;
}

/* Stronger than display:flex on control rows — non-active Player Stats slices stay fully hidden in the hub. */
body.page-stats-hub #view-player-stats > .stats-hub-slice-hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .stats-hub-allgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .stats-hub-allgrid { grid-template-columns: 1fr; }
}

.view h2 {
  margin-top: 0;
  font-size: 1.25rem;
  color: var(--text);
}

.view h2:not(.player-name):not(.home-section-title):not(.country-detail-title) {
  padding-left: 0.7rem;
  border-left: 3px solid var(--accent);
  margin-bottom: 1.1rem;
}

.list-rank-note {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

.view h3 {
  font-size: 1rem;
  margin: 1rem 0 0.5rem;
}

.view p {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Home (front page) */
.view-home .home-intro {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.view-home .home-type-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0;
}

.view-home .home-type-toggle>label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.view-home .home-list-date {
  margin-left: 0.5rem;
  font-size: 0.9rem;
}

.view-home .home-top-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 920px) {
  .view-home .home-top-grid {
    grid-template-columns: 1fr;
  }
}

/* ---- Player stats: 2-column table grid (e.g. revoked titles) ---- */
.player-stats-two-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 920px) {
  .player-stats-two-grid {
    grid-template-columns: 1fr;
  }
}

.player-stats-two-grid-title {
  padding: 0.55rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 70%, var(--bg));
}

.view-home .home-top-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.view-home .home-top-block h3,
.view-home .home-top-block h4 {
  margin: 0;
  padding: 0.55rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #fff;
  background: var(--accent);
  border-bottom: none;
}

.view-home .home-block-link {
  margin: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}

.view-home .home-block-link a {
  color: var(--accent);
  text-decoration: none;
}

.view-home .home-block-link a:hover {
  text-decoration: underline;
}

.view-home .home-table-wrap {
  overflow-x: auto;
}

.view-home .home-top-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.view-home .home-top-table th {
  text-align: left;
  padding: 0.4rem 0.75rem;
  background-color: var(--surface-alt);
  font-weight: 600;
}

.view-home .home-table-wrap th:not(:last-child) {
  background-image: linear-gradient(to bottom, transparent 20%, var(--border) 20%, var(--border) 80%, transparent 80%);
  background-size: 1px 100%;
  background-position: right center;
  background-repeat: no-repeat;
}

.view-home .home-top-table th.num {
  text-align: center;
}

.view-home .home-top-table td {
  padding: 0.35rem 0.75rem;
  border-top: 1px solid var(--border);
}

.view-home .home-top-table td.num {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.view-home .home-top-table .player-link {
  color: var(--accent);
  text-decoration: none;
}

.view-home .home-top-table .player-link:hover {
  text-decoration: underline;
}

.view-home .home-top-table tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.025);
}

.view-home .home-top-table tbody tr:nth-child(even):hover td {
  background: var(--surface-alt);
}

.view-home .home-links {
  margin-bottom: 1.5rem;
}

.view-home .home-link {
  color: var(--accent);
}

.view-home .home-meta-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.5rem;
  align-items: start;
}

.view-home .home-title-counts {
  width: 250px;
}

@media (max-width: 640px) {
  .view-home .home-meta-row {
    grid-template-columns: 1fr;
  }

  .view-home .home-title-counts {
    width: 100%;
  }
}

.view-home .home-title-counts h3,
.view-home .home-countries h3 {
  margin-top: 0;
  font-size: 1rem;
}

.view-home .home-title-counts-wrap {
  max-width: 20rem;
}

.view-home .home-title-counts-table {
  width: 100%;
  font-size: 0.9rem;
}

.view-home .home-title-counts-table th,
.view-home .home-title-counts-table td {
  padding: 0.45rem 0.75rem;
}

.view-home .home-title-counts-table tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.025);
}

.view-home .home-title-counts-table tbody tr:nth-child(even):hover td {
  background: var(--surface-alt);
}

.view-home .home-countries-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 520px) {
  .view-home .home-countries-grid {
    grid-template-columns: 1fr;
  }
}

.view-home .home-country-block {
  min-width: 0;
}

.view-home .home-country-block h4 {
  font-size: 0.95rem;
}

.view-home .home-country-block .home-top-table th,
.view-home .home-country-block .home-top-table td {
  padding: 0.35rem 0.75rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-list-info {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}

.table-export-row {
  margin: 0.65rem 0 0;
}

.table-export-row .table-export-csv + .table-export-csv {
  margin-left: 0.5rem;
}

.table-wrap.table-list {
  width: fit-content;
  max-width: 100%;
}

.table-wrap.table-list table {
  width: auto;
}

.table-wrap.table-list th.sortable {
  cursor: pointer;
  user-select: none;
}

.table-wrap.table-list th.sortable:hover {
  color: var(--accent);
}

.table-wrap.table-list th.sort-asc::after {
  content: " \25b2";
  font-size: 0.65em;
  opacity: 0.8;
}

.table-wrap.table-list th.sort-desc::after {
  content: " \25bc";
  font-size: 0.65em;
  opacity: 0.8;
}

/* Lists overview: full-width table like Top players (not shrink-wrapped). */
#view-lists .table-wrap.table-list {
  width: 100%;
  max-width: 100%;
}

#view-lists .table-wrap.table-list table {
  width: 100%;
}

#listsTable th:first-child,
#listsTable td:first-child {
  min-width: 5rem;
  white-space: nowrap;
}

.search-page-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 1rem;
  margin-bottom: 0.65rem;
}

.search-page-query-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.search-page-input {
  min-width: min(100%, 18rem);
  padding: 0.45rem 0.65rem;
  font-size: var(--form-font);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.country-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  padding: 0.8rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

@media (max-width: 600px) {
  .country-stats-grid {
    gap: 0.35rem;
  }

  .stat-card {
    padding: 0.35rem 0.55rem;
    min-width: 2.8rem;
  }

  .stat-card-highlight {
    min-width: 3.8rem;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .stat-card-highlight .stat-value {
    font-size: 1.05rem;
  }
}

.input-button-row .input-and-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
  flex-wrap: wrap;
}

.input-button-row .input-and-btn input {
  flex: 1;
  min-width: 12rem;
}

.input-button-row .input-and-btn .search-results {
  left: 0;
  min-width: 100%;
}

.stats-country-fed-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.player-stats-title-age-controls,
.player-stats-milestone-controls,
.player-stats-decline-controls,
.player-stats-improvers-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

/* Gap between top-N select and open/women toggle */
.player-stats-title-age-controls .top-filter-group+.seg-toggle,
.player-stats-milestone-controls .top-filter-group+.seg-toggle {
  margin-left: 0.75rem;
}

/* Stats chart control rows: flex with gap so Top select and Open/Women have breathing room */
#view-stats p:has(> label + .seg-toggle),
#view-player-stats p:has(> label + .seg-toggle) {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.stats-country-fed-row label {
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats-country-fed-row .search-wrap {
  width: 14rem;
  flex-shrink: 1;
}

.country-input-wrap {
  position: relative;
}

.country-input-wrap input {
  min-width: 10rem;
  width: 16rem;
  max-width: 100%;
}

.autocomplete-wrap {
  position: relative;
  display: inline-block;
  vertical-align: middle;
}

.autocomplete-wrap label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.autocomplete-wrap input {
  display: block;
  min-width: 10rem;
  width: 16rem;
  max-width: 100%;
}

#view-compare .autocomplete-wrap input {
  width: 26rem;
  min-width: 20rem;
  max-width: 100%;
}

#view-compare-players .autocomplete-wrap input {
  width: 22rem;
  min-width: 18rem;
}

#compareTable td.fed-cell,
#compareTable th:first-child {
  min-width: 14rem;
  max-width: 28rem;
}

#compareTable td.fed-cell {
  font-weight: 600;
}

.country-women {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

#compareTable th:first-child,
#compareTable td:first-child {
  width: 2.5rem;
  min-width: 2rem;
  max-width: 3rem;
  text-align: right;
}

.info-box {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  margin-bottom: 0.75rem;
  display: inline-block;
  font-size: 0.95rem;
}

/* ── Country detail section ── */
.compare-country-detail {
  margin-top: 1.5rem;
}

/* Header: back button + country name */
.country-detail-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.country-detail-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.country-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--link);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow);
  transition: background 0.12s, border-color 0.12s;
}

.country-back-btn:hover {
  background: var(--surface-alt);
  border-color: var(--accent);
}

.country-detail-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
}

.country-list-badge {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.country-list-badge strong {
  color: var(--text);
  font-weight: 600;
}

.country-list-badge .badge-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
}

/* Stats card grid */
.country-stats-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  padding: 0.45rem 0.8rem;
  min-width: 3.2rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.stat-card-highlight {
  background: linear-gradient(150deg, var(--surface) 0%, var(--surface-alt) 100%);
  min-width: 4.5rem;
}

.stat-card-sep {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  margin: 0 0.15rem;
  border-radius: 1px;
  flex-shrink: 0;
}

.stat-label {
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1;
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.1;
}

.stat-card-highlight .stat-value {
  font-size: 1.2rem;
}

/* Keep col sizing */
#compareCountryTable .col-world-rank,
#compareCountryTable .col-women-rank {
  min-width: 3.5rem;
}

#compareCountryTable.hide-women-rank .col-women-rank {
  display: none;
}

/* Legacy title-counts-box (used elsewhere) */
.title-counts-box {
  margin-bottom: 0.85rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  line-height: 1.5;
}

.title-counts-intro {
  display: inline;
  color: var(--muted);
  font-weight: 500;
  margin-right: 0.5rem;
  white-space: nowrap;
}

.title-counts-track {
  display: inline;
}

.title-count-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  margin: 0.15rem 0.1rem 0.15rem 0;
  padding: 0.12rem 0.5rem 0.12rem 0.4rem;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
  vertical-align: middle;
}

.title-count-code {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
}

.title-count-num {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-size: 0.95rem;
}

.title-count-sep {
  display: inline;
  color: var(--border);
  margin: 0 0.15rem;
  user-select: none;
  font-weight: 300;
}

.title-count-group-sep::before {
  content: "";
  display: inline-block;
  width: 1px;
  height: 0.9rem;
  margin: 0 0.5rem 0 0.35rem;
  background: var(--border);
  vertical-align: middle;
  opacity: 0.85;
}

.stats-unique-title {
  margin-top: 2.5rem;
  margin-bottom: 0.65rem;
}

.stats-country-unique-wrap .stats-country-row {
  cursor: pointer;
}

.stats-country-unique-wrap .stats-country-row:hover td {
  background: var(--surface-alt);
}

.stats-country-expand>td {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.stats-country-players-detail {
  margin: 0;
}

.stats-country-players-detail table {
  font-size: 0.85rem;
}

.stats-country-players-detail th {
  padding: 0.35rem 0.5rem;
}

.stats-country-players-detail td {
  padding: 0.35rem 0.5rem;
  background: var(--surface);
}

.stats-country-players-detail tbody tr:nth-child(even) td {
  background: var(--surface-alt);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background-color: var(--surface-alt);
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.table-wrap th:not(:last-child) {
  background-image: linear-gradient(to bottom, transparent 20%, var(--border) 20%, var(--border) 80%, transparent 80%);
  background-size: 1px 100%;
  background-position: right center;
  background-repeat: no-repeat;
}

tr:last-child td {
  border-bottom: none;
}

.table-wrap tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.025);
}

.table-wrap tbody tr:nth-child(even):hover td {
  background: var(--surface-alt);
}

tr:hover td {
  background: var(--surface-alt);
}

td.num,
th.num {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.rating {
  font-weight: 600;
}

.change-pos {
  color: var(--green);
}

.change-neg {
  color: var(--red);
}

.top-inactive-col {
  width: 1.5rem;
}

.top-inactive-flag {
  color: var(--muted);
  font-size: 0.75rem;
  font-style: italic;
}

a.player-link {
  color: var(--link);
  text-decoration: none;
}

a.player-link:hover {
  text-decoration: underline;
}

.table-wrap.table-list td a.player-link {
  font-weight: 600;
}

/* Federation flag image (flagcdn.com) */
img.fed-flag-img {
  width: 24px;
  height: 16px;
  border-radius: 2px;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 5px;
}

span.fed-flag-emoji {
  font-size: 1.1em;
  vertical-align: middle;
  line-height: 1;
  margin-right: 4px;
}

span.fed-nowrap {
  white-space: nowrap;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--form-font);
}

button:hover {
  background: var(--accent-hover);
}

button.link-button {
  background: none;
  color: var(--link);
  padding: 0.25rem 0;
  font-size: 0.95rem;
}

button.link-button:hover {
  text-decoration: underline;
}

button.btn-small {
  min-height: 2rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

button.btn-loading {
  opacity: 0.7;
  cursor: not-allowed;
}

button.btn-loading::after {
  content: " …";
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.2);
}

#view-player .player-name {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
  color: var(--text);
  line-height: 1.2;
}

#view-player h3 {
  font-size: 1.15rem;
  margin: 1.25rem 0 0.5rem;
  color: var(--text);
  font-weight: 600;
}

#view-player h4 {
  font-size: 1.1rem;
  margin: 1.5rem 0 0.5rem;
  color: var(--text);
  font-weight: 600;
}

/* Player chart / table filters: label column + control (aligned type scale) */
#view-player .player-chart-filters {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  font-size: 0.95rem;
}

.player-all-ratings-header {
  display: block;
  align-items: center;
  margin: 1.25rem 0 0.5rem;
}

.player-all-ratings-header h4 {
  margin: 0;
}

.player-table-type-toggle {
  display: flex;
}

/* Format row: hide checkboxes like radios so label + pill are one row (click label to toggle) */
#view-player .seg-toggle-check .seg-toggle-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  pointer-events: none;
}

#view-player .seg-toggle-check .seg-toggle-item {
  position: relative;
  display: flex;
  align-items: stretch;
}

#view-player .chart-filter-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

#view-player .chart-filter-label {
  flex: 0 0 auto;
  min-width: 7.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--muted);
}

#view-player .chart-filter-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

#view-player .chart-filter-control-wrap {
  align-items: center;
  gap: 0.65rem;
}

#view-player .chart-filter-period {
  gap: 0.45rem;
}

#view-player .chart-filter-to {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
}

#view-player .player-chart-filters select {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.25;
}

#view-player .player-chart-filters .seg-toggle-item span {
  font-size: 0.95rem;
  padding: 0.42rem 0.95rem;
}

#view-player .player-chart-x-hint {
  font-size: 0.85rem;
  line-height: 1.35;
}

.player-profile {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin: 0.85rem 0 1.75rem;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 1rem;
  overflow: hidden;
}

.player-profile>.profile-info-line,
.player-profile>.profile-prev-names-line {
  padding: 0.85rem 1.25rem;
}

.player-profile .profile-row {
  min-width: 0;
}

.player-profile .profile-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.2rem;
  display: block;
}

.player-profile .profile-value {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
}

/* ── Rating cards ─────────────────────────────────────────────────── */
.profile-ratings-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
}

@media (max-width: 500px) {
  .profile-ratings-grid {
    grid-template-columns: 1fr;
  }
}

.profile-rating-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  padding: 1rem 1.1rem 0.85rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.profile-rating-card:last-child {
  border-right: none;
}

.profile-rating-card.prc-empty {
  opacity: 0.45;
}

.prc-type {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

a.prc-rating,
.prc-rating {
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

a.prc-rating:hover {
  color: var(--accent-hover);
  text-decoration: none;
}

.prc-rating-empty {
  color: var(--muted);
}

.prc-date {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  margin-top: -0.15rem;
}

.prc-ranks {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-top: 0.15rem;
}

.prc-ranks-row {
  display: flex;
  flex-direction: row;
  align-items: baseline;
}

.prc-ranks-row-women {
  margin-top: 0.05rem;
}

.prc-rank {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  padding: 0 0.55rem;
}

.prc-ranks-row .prc-rank:first-child {
  padding-left: 0;
}

.prc-ranks-row .prc-rank+.prc-rank {
  border-left: 1px solid var(--border);
}

.prc-rank-n {
  font-size: 0.92rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.prc-rank-l {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.prc-peak {
  margin-top: auto;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  flex-wrap: wrap;
  justify-content: center;
}

.prc-peak-sep {
  color: var(--border);
  font-weight: 400;
  font-size: 0.75rem;
}

.prc-peak-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.prc-peak-rating {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.prc-peak-date {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
  display: inline;
  text-decoration: none;
}

.prc-peak-date:hover {
  text-decoration: underline;
}

.prc-peak-pos {
  margin-top: 0.1rem;
}

/* Vertical divider between open-title and women-title sections in title history */
.profile-title-hist-divider {
  display: inline-block;
  width: 1px;
  background: var(--border);
  height: 1.2em;
  margin: 0 0.6rem;
  vertical-align: middle;
}

/* Inline list date links (player stats tables, profile cards) */
.list-link {
  color: var(--accent);
  text-decoration: none;
}

.list-link:hover {
  text-decoration: underline;
}

.prc-status {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.profile-info-line {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 2.5rem;
  align-items: flex-start;
  font-size: 0.92rem;
  border-top: 1px solid var(--border);
}

.profile-info-line .profile-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
  margin-right: 0.3rem;
}

.profile-info-line .profile-meta-item {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.08rem;
  vertical-align: top;
}

.profile-info-line .profile-meta-item .profile-label {
  display: block;
  margin-bottom: 0;
}

.profile-info-line .profile-meta-sub {
  display: block;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.25;
}

.profile-prev-names-line {
  font-size: 0.88rem;
  color: var(--muted);
}

.profile-prev-names-line .profile-label {
  font-size: 0.8rem;
  font-weight: 500;
}

.profile-prev-name {
  white-space: nowrap;
}

.profile-prev-period {
  font-size: 0.8em;
  color: var(--muted);
  font-weight: 400;
}

.profile-fide-link {
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}

.profile-fide-link:hover {
  text-decoration: underline;
  color: var(--accent);
}

/* Title history row */
.profile-title-hist-line {
  align-items: baseline;
  gap: 0.4rem 0.75rem;
  flex-wrap: wrap;
}

.profile-title-hist-line>.profile-label {
  white-space: nowrap;
  flex-shrink: 0;
}

.profile-title-hist-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1.25rem;
}

.profile-title-hist-group-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.profile-title-hist-item {
  display: inline-flex;
  gap: 0.3rem;
  align-items: baseline;
  white-space: nowrap;
}

.profile-title-hist-code {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
}

.profile-title-hist-date {
  font-size: 0.82rem;
  color: var(--muted);
}

.chart-types-wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
  flex-wrap: wrap;
}

.chart-types-wrap label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.chart-types-wrap .chart-types-label {
  color: var(--muted);
}

.profile-type-link {
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.profile-type-link:hover {
  text-decoration: underline;
}

.chart-period {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.chart-period label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.chart-period select {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

.table-wrap.player-ratings-wrap {
  overflow-x: auto;
  width: fit-content;
}

.player-ratings-wrap table {
  font-size: 1rem;
  width: auto;
  table-layout: auto;
}

/* List column (date) needs enough width for yyyy-mm */
.player-ratings-wrap th:first-child,
.player-ratings-wrap td:first-child {
  min-width: 5.5em;
  width: 6em;
}

.player-ratings-wrap th,
.player-ratings-wrap td {
  padding: 0.5rem 0.6rem;
}

.player-ratings-wrap th {
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.player-ratings-wrap th:hover {
  color: var(--accent);
}

.player-ratings-wrap th.sort-asc::after {
  content: " \25b2";
  font-size: 0.6em;
  opacity: 0.8;
}

.player-ratings-wrap th.sort-desc::after {
  content: " \25bc";
  font-size: 0.6em;
  opacity: 0.8;
}

/* Constrain numeric columns to avoid Change being wider than Games */
.player-ratings-table th[data-sort="change"],
.player-ratings-table td:nth-child(7),
.player-ratings-table th[data-sort="games"],
.player-ratings-table td:nth-child(8) {
  width: 5rem;
}

.player-ratings-table.hide-women th.col-women,
.player-ratings-table.hide-women td.col-women {
  display: none;
}

.player-ratings-table.hide-women-national th.col-women-national,
.player-ratings-table.hide-women-national td.col-women-national {
  display: none;
}

.player-ratings-table.hide-status th.col-status,
.player-ratings-table.hide-status td.col-status {
  display: none;
}

.player-ratings-table.hide-country th.col-country,
.player-ratings-table.hide-country td.col-country {
  display: none;
}

.history-chart {
  margin-top: 0.5rem;
  padding: 1.25rem;
  background: var(--chart-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: visible;
  box-shadow: var(--shadow);
  width: 100%;
  min-width: var(--chart-width);
  box-sizing: border-box;
  /* Legend + export sit below SVG — do not aspect-ratio the whole box or they overlap the plot */
  display: flex;
  flex-direction: column;
  gap: 0;
}

.stats-chart {
  margin-bottom: 2.5rem;
}

.stats-filters {
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

/* Rating Stats: panel cards separate each block */
#view-stats .stats-panel {
  margin-bottom: 1.5rem;
  padding: 1rem 1.15rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#view-stats .stats-panel h3 {
  margin: 0 0 0.75rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--surface-alt);
  font-size: 1.05rem;
}

#view-stats .stats-panel .stats-chart:last-child {
  margin-bottom: 0;
}

.stats-women-pct-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: center;
  margin-bottom: 0.35rem;
}

.stats-panel-note {
  font-size: 0.88rem;
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.stats-avg-metric-picker {
  margin: 0 0 0.65rem;
}

.stats-chart-loading {
  margin: 1.25rem 0;
  min-height: 3.5rem;
  display: flex;
  align-items: center;
}

.stats-inline-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: 0.35rem;
}

/* Player Stats: same vertical rhythm as Rating Stats */
#view-player-stats h3 {
  margin-top: 2.5rem;
  margin-bottom: 0.65rem;
}

#view-player-stats h3:first-of-type {
  margin-top: 0.75rem;
}

.history-chart-inner {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
}

.chart-tooltip {
  position: absolute;
  background: var(--text);
  color: var(--bg);
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
}

/* Space between x-axis labels (inside SVG) and series legend below */
.history-chart-inner .chart-legend {
  margin-top: 1.15rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.player-chart-x-hint {
  margin-left: 0;
}

.history-chart-inner>.history-svg {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: var(--chart-aspect-w) / var(--chart-aspect-h);
  min-height: 220px;
}

.history-svg {
  display: block;
}

/* Default stroke for single-series charts; multi-series sets inline style to override */
.history-svg polyline:not([style*="stroke"]) {
  stroke: var(--chart-line);
}

.chart-legend {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
  padding: 0.35rem 0 0;
  line-height: 1.45;
  flex-wrap: wrap;
  display: flex;
  align-items: center;
  gap: 0.5rem 1rem;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-legend .legend-line {
  display: inline-block;
  width: 1.5rem;
  height: 3px;
  background: var(--chart-line);
  border-radius: 2px;
  flex-shrink: 0;
}

.chart-legend .legend-swatch {
  display: inline-block;
  width: 1rem;
  height: 0.65rem;
  background: var(--chart-line);
  border-radius: 2px;
  flex-shrink: 0;
}

.chart-legend--gender .chart-legend-swatch {
  display: inline-block;
  width: 1rem;
  height: 0.65rem;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 0.2rem;
}

.home-juniors-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
}

.home-junior-class-select {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  cursor: pointer;
  outline: none;
  margin-left: 0.3rem;
}

.history-svg .chart-tick {
  font-size: 11px;
  fill: var(--muted);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.history-svg .chart-title {
  font-size: 14px;
  font-weight: 600;
  fill: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.history-svg .chart-axis-label {
  font-size: 10px;
  fill: var(--muted);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.compare-players-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  min-height: 1.5rem;
}

.compare-players-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.15rem 0.2rem 0.65rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
}

.compare-players-chip-text {
  line-height: 1.3;
}

.compare-players-chip .compare-players-remove {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.compare-players-chip .compare-players-remove:hover {
  background: rgba(0, 0, 0, 0.12);
  color: var(--text);
}

.compare-players-chip .compare-players-remove-svg {
  display: block;
}

.chart-export-bar {
  margin: 0;
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
  clear: both;
  width: 100%;
}

.chart-export-bar .link-button {
  margin-right: 0.25rem;
}

/* Match .history-chart horizontal inset so table CSV rows align with chart Download: JPG · CSV */
.table-wrap>.chart-export-bar.chart-export-bar--table {
  padding-left: 1.25rem;
  padding-right: 1.25rem;
  box-sizing: border-box;
}

/* Player page: export row is last in #playerHistoryChart — extra separation from summary below */
#playerHistoryChart {
  padding-bottom: 1rem;
}

.compare-players-mode {
  margin-bottom: 0.75rem;
}

.compare-players-mode>label {
  margin-right: 1rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.compare-players-mode .seg-toggle-item {
  margin-right: 0;
}

.compare-players-filters {
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.compare-players-filters .compare-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.compare-players-filters .compare-filter-group label {
  margin-right: 0.25rem;
  color: var(--muted);
}

.compare-players-filters input[type="number"] {
  width: 4.5rem;
  min-width: 4.5rem;
}

.top-filters {
  display: flex;
  align-items: center;
  gap: 0.75rem 0;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.top-filters .top-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  padding: 0.2rem 1.1rem;
}

.top-filters .top-filter-group+.top-filter-group {
  border-left: 1px solid var(--border);
}

.top-filters .top-filter-group label {
  margin: 0 0.1rem 0 0;
  cursor: pointer;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.top-filters .top-filter-group:first-child {
  padding-left: 0.25rem;
}

.top-filters select,
.top-filters input[type="text"],
.top-filters input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  padding: 0.35rem 0.6rem;
}

.top-filters select:focus,
.top-filters input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 145, 255, 0.18);
  outline: none;
}

.top-fed-wrap {
  position: relative;
  display: inline-block;
}

.top-fed-wrap input {
  width: 11rem;
  max-width: 100%;
}

.top-filters select.top-filters-select,
.top-filters .top-filters-select {
  min-width: 6rem;
}

.top-filters input.top-filters-num,
.top-filters .top-filters-num {
  width: 5rem;
  min-width: 5rem;
  min-height: var(--form-min-h);
}

.gains-losses-filters .top-filter-group>label:first-of-type:not(:has(input)) {
  color: var(--muted);
  margin-right: 0;
}

.gains-losses-filters .top-filter-group:last-child {
  border-left: none;
  padding-left: 0.35rem;
}

.title-holders-title-select {
  min-width: 12rem !important;
}

#titlesTable td.title-new-col {
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

#compareCountryTable td.country-fed-since-col {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.btn-titles-show {
  padding: var(--form-py) 1rem;
  border: 1px solid transparent;
}

.btn-titles-show:hover {
  background: var(--accent-hover);
}

.btn-titles-past {
  padding: var(--form-py) 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-left: 0.4rem;
}

.btn-titles-past:hover {
  background: var(--hover);
}

.btn-titles-past.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#view-titles .top-fed-wrap input {
  width: 14rem;
}

.top-birth-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.top-birth-filter label {
  margin-right: 0.2rem;
}

.top-birth-filter input[type="number"] {
  width: 4.25rem;
  min-width: 4.25rem;
}

.top-birth-sep {
  color: var(--muted);
  font-weight: 500;
  margin: 0 0.1rem;
}

.top-birth-hint {
  font-size: 0.8rem;
  margin-left: 0.15rem;
}

.footer {
  padding: 1rem 1.5rem 1.35rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

.footer p {
  margin: 0.35rem 0;
}

.footer-developer {
  font-size: 0.8rem;
}

.footer a {
  color: var(--link);
}

.footer a:hover {
  text-decoration: underline;
}

.api-doc-main {
  padding: 1rem 1rem 2rem;
}

.api-doc-main h2 {
  margin-top: 0;
}

.api-doc-main h3 {
  margin-top: 1.5rem;
}

.api-doc-main h4.api-subh4 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.api-tools-fields td:first-child {
  white-space: nowrap;
}

.api-tools-endpoints td code {
  word-break: break-word;
}

/* API call builder (api.html) */
.api-builder {
  margin: 1rem 0 1.25rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.api-builder h4 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.api-builder-recipe {
  margin-bottom: 1rem;
}

.api-builder-recipe label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.api-builder-recipe select {
  width: 100%;
  max-width: 28rem;
  padding: 0.45rem 0.5rem;
  font-size: 0.95rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.api-builder-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.65rem 1rem;
  margin-bottom: 0.85rem;
}

.api-builder-fields .api-bf {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.api-builder-fields .api-bf label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.api-builder-fields .api-bf input,
.api-builder-fields .api-bf select {
  padding: 0.4rem 0.5rem;
  font-size: 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
}

.api-builder-fields .api-bf-full {
  grid-column: 1 / -1;
}

.api-builder-fields .api-bf-full textarea {
  min-height: 4rem;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
}

.api-builder-mode-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: -0.35rem 0 0.5rem;
  line-height: 1.35;
  max-width: 40rem;
}

.api-builder-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 0.5rem;
}

.api-builder-actions button {
  padding: 0.45rem 0.85rem;
  font-size: 0.88rem;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.api-builder-actions .btn-api-try-primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}

.api-builder-actions .btn-api-try-primary:hover {
  background: var(--accent-hover);
}

.api-builder-curl {
  margin-top: 0.65rem;
  font-size: 0.75rem;
}

.api-builder-curl pre {
  margin: 0.35rem 0 0;
  padding: 0.5rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.api-doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0.75rem 0;
}

.api-doc-table th,
.api-doc-table td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.api-doc-table th {
  color: var(--muted);
  font-weight: 600;
}

.api-doc-table code {
  font-size: 0.82em;
  word-break: break-all;
}

.api-doc-clickable tbody tr[data-api-path]:hover {
  background: var(--surface-alt);
}

.api-row-flash {
  background: rgba(0, 113, 227, 0.08) !important;
  transition: background 0.15s;
}

.api-try {
  margin: 1.5rem 0 2rem;
  padding: 1.25rem 1.25rem 1.5rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.api-try-lead {
  margin-top: 0.35rem;
  margin-bottom: 1rem;
}

.api-try-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}

.api-try-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  flex: 1;
  min-width: 12rem;
}

.api-try-label span {
  font-weight: 600;
  color: var(--text);
}

.api-try-input {
  width: 100%;
  padding: var(--form-py) var(--form-px);
  font-size: var(--form-font);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: ui-monospace, monospace;
}

.api-try-query {
  flex: 1.5;
  min-width: 16rem;
}

.btn-api-try {
  padding: var(--form-py) 1.1rem;
  font-size: var(--form-font);
  font-weight: 600;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

.btn-api-try:hover {
  background: var(--accent-hover);
}

.api-try-url {
  margin: 0.75rem 0 0.25rem;
  font-size: 0.8rem;
  word-break: break-all;
}

.api-try-url code {
  font-size: inherit;
  background: transparent;
}

.api-try-meta {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.api-try-out {
  margin: 0;
  max-height: min(70vh, 28rem);
  overflow: auto;
  padding: 1rem;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.45;
  border: 1px solid var(--border);
}

.api-try-out code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  background: transparent;
  color: inherit;
}

.api-try-examples {
  margin: 0.85rem 0 0;
  font-size: 0.85rem;
}

.api-try-examples .link-button {
  margin-right: 0.35rem;
}

/* -------- Segmented toggle (Standard / Rapid / Blitz) -------- */
.seg-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.seg-toggle-item {
  position: relative;
  cursor: pointer;
  line-height: 1;
}

.seg-toggle-item input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.seg-toggle-item span {
  display: block;
  padding: 0.38rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}

.seg-toggle-item:last-child span {
  border-right: none;
}

.seg-toggle-item input[type="radio"]:checked+span,
.seg-toggle-item input[type="checkbox"]:checked+span {
  background: var(--accent);
  color: #fff;
}

.seg-toggle-item:hover span {
  background: var(--surface-alt);
  color: var(--text);
}

.seg-toggle-item input[type="radio"]:checked+span:hover,
.seg-toggle-item input[type="checkbox"]:checked+span:hover {
  background: var(--accent-hover);
}

/* -------- Home section header row (title + toggle on same line) -------- */
.home-section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.home-section-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

/* -------- Home intro block -------- */
.home-intro-block {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.view-home .home-intro {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* -------- Home grid footer (below the 4 cards) -------- */
.home-grid-footer {
  margin-top: -0.5rem;
  margin-bottom: 1.75rem;
  font-size: 0.85rem;
}

.home-grid-footer a {
  color: var(--accent);
  text-decoration: none;
}

.home-grid-footer a:hover {
  text-decoration: underline;
}

/* -------- Empty state cells -------- */
.empty-state-cell {
  padding: 1.5rem 0.75rem !important;
  text-align: center !important;
  font-size: 0.9rem;
  color: var(--muted) !important;
}

/* -------- View filter bar (context-sensitive, below nav) -------- */
.view-filter-bar {
  display: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

body[data-view="lists"] .view-filter-bar,
body[data-view="top"] .view-filter-bar,
body[data-view="gains-losses"] .view-filter-bar,
body[data-view="compare"] .view-filter-bar,
body[data-view="titles"] .view-filter-bar {
  display: block;
}

/* Lists doesn't need the List date selector (it IS the list browser) */
body[data-view="lists"] .vfb-list {
  display: none;
}

.vfb-inner {
  max-width: var(--header-nav-max-width);
  margin: 0 auto;
  padding: 0 2.3rem;
  display: flex;
  align-items: stretch;
  gap: 0;
  flex-wrap: wrap;
}

.vfb-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: default;
  padding: 0.5rem 1.1rem;
}

.vfb-item:first-child {
  padding-left: 0.25rem;
}

.vfb-item+.vfb-item {
  border-left: 1px solid var(--border);
}

.vfb-item> :first-child:not(select):not(input) {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
}

.vfb-item select {
  margin-left: 0.1rem;
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

.vfb-item select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 145, 255, 0.2);
  outline: none;
}

.vfb-item input[type="checkbox"] {
  accent-color: var(--accent);
}

.vfb-inactive {
  cursor: pointer;
}

/* Show + Inactive are hidden by default; shown only on views that need them */
.view-filter-bar .vfb-show,
.view-filter-bar .vfb-inactive {
  display: none;
}

body[data-view="top"] .vfb-show,
body[data-view="top"] .vfb-inactive,
body[data-view="gains-losses"] .vfb-show,
body[data-view="gains-losses"] .vfb-inactive,
body[data-view="titles"] .vfb-show,
body[data-view="titles"] .vfb-inactive {
  display: inline-flex;
}

.player-stats-birthday-controls,
.player-stats-milestone-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.player-stats-birthday-controls label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.milestone-threshold-input {
  width: 6rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
}

/* ================================================================
   RESPONSIVE — mobile-first improvements
   ================================================================ */

/* ---- Hamburger nav (≤ 760px) ---- */
@media (max-width: 760px) {
  .nav-toggle {
    display: flex;
    align-items: center;
  }

  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    margin-top: 0.25rem;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links a {
    padding: 0.55rem 0.75rem;
    font-size: 0.95rem;
  }

  .nav .container-inner {
    flex-wrap: wrap;
  }
}

/* ---- Header: stack on very small screens ---- */
@media (max-width: 520px) {
  .header .container-inner {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .header h1 {
    font-size: 1.2rem;
  }

  .header .controls {
    margin-left: 0;
    width: 100%;
  }

  .header .controls .search-wrap {
    width: 100%;
    max-width: 100%;
  }

  .header .search-wrap input {
    width: 100%;
  }

  .nav .container-inner {
    padding: 0.25rem 1rem;
  }
}

/* ---- Main content padding ---- */
@media (max-width: 640px) {
  #main {
    padding: 1rem;
  }

  .vfb-inner {
    padding: 0.5rem 1rem;
    gap: 0.75rem;
  }
}

/* ---- Font scale ---- */
@media (max-width: 480px) {
  html {
    font-size: 16px;
  }
}

/* ---- Tables: smaller padding on mobile ---- */
@media (max-width: 640px) {

  th,
  td {
    padding: 0.4rem 0.55rem;
  }

  .table-wrap {
    border-radius: 6px;
  }

  .view h2 {
    font-size: 1.1rem;
  }

  .view h2:not(.player-name):not(.home-section-title) {
    padding-left: 0.55rem;
  }
}

/* ---- Player profile ---- */
@media (max-width: 480px) {
  .player-profile {
    padding: 1rem 1.1rem;
    gap: 0.75rem 1.25rem;
  }

  #view-player .player-name {
    font-size: 1.4rem;
  }

  #view-player .chart-filter-label {
    min-width: 5.5rem;
    font-size: 0.9rem;
  }

  #view-player .chart-filter-row-table-type {
    padding-left: calc(5.5rem + 0.65rem);
  }
}

/* ---- Chart: no enforced min-width on mobile ---- */
@media (max-width: 600px) {
  .history-chart {
    min-width: 0;
  }

  :root {
    --chart-width: 0px;
  }
}

/* ---- Filters / controls bars ---- */
@media (max-width: 640px) {
  .stats-filters {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
    font-size: 0.85rem;
  }

  .country-controls {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }
}

/* ---- Compare/search inputs ---- */
@media (max-width: 600px) {

  #view-compare .search-wrap input,
  #view-compare .autocomplete-wrap input,
  #view-compare-players .search-wrap input,
  #view-compare-players .autocomplete-wrap input {
    width: 100%;
    min-width: 0;
  }
}

/* ---- Home page top grid already collapses at 920px ---- */
/* ---- Home page meta row already collapses at 640px ---- */
/* ---- Home countries grid already collapses at 520px ---- */