:root {
  --bg: #FAF8F3;
  --text: #1a1a1a;
  --red: #8B1A1A;
  --border: #ddd8d0;
  --muted: #666;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
}

a {
  color: var(--red);
}

a:hover {
  color: #6b1414;
}

.button-link {
  display: inline-block;
  border: 1px solid var(--red);
  background: var(--red);
  color: #fff;
  padding: 8px 14px;
  text-decoration: none;
}

.button-link:hover {
  background: #6b1414;
  color: #fff;
}

/* ---- Header ---- */

header {
  border-bottom: 1px solid var(--border);
  padding: 18px 20px 14px;
}

.header-inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px 32px;
  flex-wrap: wrap;
}

.site-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  font-weight: normal;
  white-space: nowrap;
}

.site-title a {
  color: var(--red);
  text-decoration: none;
  display: block;
  line-height: 0;
}

.site-logo {
  height: 52px;
  width: auto;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  align-items: center;
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  padding: 2px 4px;
  margin-left: auto;
}

nav a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

nav a:hover {
  color: var(--red);
}

nav a.active {
  border-bottom: 1.5px solid var(--text);
}

/* ---- Main ---- */

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 20px 72px;
}

/* ---- Notice ---- */

.notice {
  border-left: 3px solid var(--red);
  background: #fff9ee;
  padding: 10px 14px;
  margin-bottom: 36px;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ---- Headings ---- */

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.9rem;
  font-weight: normal;
  color: var(--red);
  margin-bottom: 28px;
}

h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: normal;
  color: var(--red);
  margin: 44px 0 14px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 22px 0 8px;
}

/* ---- Text ---- */

p {
  margin-bottom: 14px;
}

ul, ol {
  margin: 10px 0 14px 22px;
}

li {
  margin-bottom: 5px;
}

/* ---- Definition lists (used for fees, hours) ---- */

dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 20px;
  margin-bottom: 14px;
}

dt {
  font-weight: 500;
}

dd {
  margin: 0;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-bottom: 14px;
}

th {
  text-align: left;
  font-weight: 600;
  padding: 7px 14px 7px 0;
  border-bottom: 2px solid var(--border);
}

td {
  padding: 8px 14px 8px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Two-column layout ---- */

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: start;
}

/* ---- Archive browser ---- */

#archive-loading {
  color: var(--muted);
  font-size: 0.9rem;
}

#archive details {
  margin-bottom: 3px;
}

#archive > details {
  margin-bottom: 14px;
}

#archive summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  list-style: none;
  user-select: none;
}

#archive summary::-webkit-details-marker {
  display: none;
}

#archive summary::before {
  content: "+";
  display: inline-block;
  width: 14px;
  color: var(--muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

#archive details[open] > summary::before {
  content: "-";
}

#archive > details > summary {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  color: var(--red);
}

#archive > details > details > summary {
  font-size: 0.95rem;
  margin-left: 18px;
}

#archive ul {
  list-style: none;
  margin: 4px 0 10px 50px;
  padding: 0;
}

#archive li {
  margin-bottom: 3px;
}

#archive a {
  font-size: 0.9rem;
  text-decoration: none;
}

#archive a:hover {
  text-decoration: underline;
}

.archive-session > summary {
  font-size: 0.9rem;
}

.session-detail-body {
  margin: 4px 0 18px 22px;
}

.session-raw-link {
  display: inline-block;
  margin: 2px 0 10px;
  font-size: 0.8rem !important;
}

.session-loading,
.session-unavailable {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.session-group {
  margin: 0 0 18px;
}

.session-group h3 {
  margin: 4px 0 5px;
  font-size: 0.92rem;
}

.session-group-table {
  font-size: 0.82rem;
  margin-bottom: 8px;
}

.session-group-table th,
.session-group-table td {
  padding: 4px 12px 4px 0;
}

.session-group-table th:nth-child(n+2),
.session-group-table td:nth-child(n+2) {
  text-align: right;
}

.group-winner-row td {
  font-weight: bold;
}

.group-winner-trophy {
  font-weight: normal;
}

/* ---- Archive filters ---- */

.archive-filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 18px 0 10px;
  padding: 14px;
  background: #fff9ee;
  border: 1px solid var(--border);
}

.archive-filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.archive-filter-label {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 52px;
  flex-shrink: 0;
}

.archive-filter-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.archive-filter-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  padding: 4px 10px;
  line-height: 1.4;
}

.archive-filter-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

.archive-filter-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.archive-player-search {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: 5px 8px;
  width: min(100%, 280px);
}

.archive-player-search:focus {
  border-color: var(--red);
  outline: 2px solid rgba(139, 26, 26, 0.12);
  outline-offset: 1px;
}

.archive-count {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 10px;
  min-height: 1.2em;
}

.archive-filtered-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.archive-filtered-list > li {
  margin-bottom: 3px;
}

.archive-no-results {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 0;
}

/* ---- Player profile ---- */

.profile-back {
  margin-bottom: 20px;
  font-size: 0.875rem;
}

.profile-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0;
}

.profile-meta strong {
  color: var(--text);
  font-size: 1rem;
}

.rating-chart-full {
  width: 100%;
  max-width: 640px;
  height: 120px;
  display: block;
  margin-top: 8px;
}

.rating-chart-full text {
  fill: var(--muted);
  font: 9px system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

.profile-bottom-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr);
  gap: 40px;
  align-items: start;
}

.profile-sessions-table,
.profile-h2h-table {
  font-size: 0.85rem;
}

.profile-sessions-table td:nth-child(n+2),
.profile-sessions-table th:nth-child(n+2),
.profile-h2h-table td:nth-child(n+2),
.profile-h2h-table th:nth-child(n+2) {
  text-align: right;
}

.profile-adj[data-sign="pos"] { color: #2a6a2a; }
.profile-adj[data-sign="neg"] { color: #8B1A1A; }

/* ---- Leaderboard ---- */

#leaderboard-status {
  color: var(--muted);
  font-size: 0.9rem;
}

.leaderboard-tools {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
}

.leaderboard-tools[hidden] {
  display: none;
}

.leaderboard-search {
  width: min(100%, 320px);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 9px;
}

.leaderboard-search:focus {
  border-color: var(--red);
  outline: 2px solid rgba(139, 26, 26, 0.12);
  outline-offset: 1px;
}

.leaderboard-count,
.leaderboard-empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.leaderboard-empty {
  text-align: left !important;
  padding: 18px 0;
}

.leaderboard-table {
  margin-top: 18px;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 8px 12px 8px 0;
}

.leaderboard-table th:nth-child(1),
.leaderboard-table td:nth-child(1),
.leaderboard-table th:nth-child(3),
.leaderboard-table td:nth-child(3),
.leaderboard-table th:nth-child(5),
.leaderboard-table td:nth-child(5),
.leaderboard-table th:nth-child(6),
.leaderboard-table td:nth-child(6) {
  text-align: right;
}

.player-row {
  cursor: pointer;
}

.player-row:hover,
.player-row.expanded {
  background: #fff9ee;
}

.leaderboard-table td:nth-child(2) {
  white-space: nowrap;
}

.vs-button,
.small-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.75rem;
  line-height: 1;
}

.vs-button {
  margin-left: 8px;
  padding: 3px 5px;
}

.small-button {
  padding: 5px 8px;
}

.vs-button:hover,
.small-button:hover,
.vs-button.active {
  border-color: var(--red);
  color: var(--red);
}

.sparkline {
  width: 80px;
  height: 20px;
  display: inline-block;
  vertical-align: middle;
}

.rating-chart {
  width: 100%;
  max-width: 420px;
  height: 96px;
  display: block;
}

.rating-chart text {
  fill: var(--muted);
  font: 9px system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

.player-detail {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(240px, 1fr);
  gap: 28px;
  padding: 14px 0 18px;
}

.player-detail h3,
.comparison-grid h3 {
  margin-top: 0;
}

.head-to-head-table {
  font-size: 0.82rem;
  margin-bottom: 0;
}

.comparison-panel {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  margin: 0 0 22px;
}

.comparison-panel[hidden] {
  display: none;
}

.comparison-panel h2 {
  border-bottom: 0;
  margin: 0;
  padding: 0;
}

.comparison-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

/* ---- Photos ---- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 24px;
}

.photo-grid img {
  width: 100%;
  height: 210px;
  object-fit: cover;
  display: block;
}

/* ---- Rules page ---- */

.rule-block {
  margin-bottom: 16px;
  padding-left: 0;
}

.correction {
  background: #f7f4ef;
  border-left: 3px solid var(--border);
  padding: 10px 14px;
  margin-bottom: 12px;
}

.correction p:last-child {
  margin-bottom: 0;
}

/* ---- Footer ---- */

footer {
  border-top: 1px solid var(--border);
  padding: 22px 20px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---- Responsive ---- */

@media (max-width: 640px) {
  h1 {
    font-size: 1.5rem;
  }

  .two-col {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .nav-toggle {
    display: block;
  }

  nav a {
    display: none;
    width: 100%;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
  }

  nav.nav-open {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
    padding-top: 8px;
  }

  nav.nav-open a {
    display: block;
  }

  .header-inner {
    align-items: center;
    justify-content: space-between;
  }

  .session-detail-body {
    margin-left: 18px;
  }

  .leaderboard-table {
    font-size: 0.82rem;
  }

  .leaderboard-tools {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .leaderboard-search {
    width: 100%;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding-right: 8px;
  }

  /* Rankings table: hide Trend and Sessions columns */
  .leaderboard-table:not(.improved-table) th:nth-child(4),
  .leaderboard-table:not(.improved-table) td:nth-child(4),
  .leaderboard-table:not(.improved-table) th:nth-child(5),
  .leaderboard-table:not(.improved-table) td:nth-child(5) {
    display: none;
  }

  /* Improved table: hide Was and Sessions columns */
  .improved-table th:nth-child(4),
  .improved-table td:nth-child(4),
  .improved-table th:nth-child(6),
  .improved-table td:nth-child(6) {
    display: none;
  }

  .vs-button {
    display: none;
  }

  .player-detail,
  .comparison-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  dl {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }

  dt {
    margin-top: 8px;
  }

  .profile-bottom-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .archive-filters {
    padding: 10px;
    gap: 8px;
  }

  .archive-player-search {
    width: 100%;
  }
}

.data-status {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.latest-results-date {
  font-family: system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  font-weight: normal;
  color: var(--muted);
  margin-left: 0.5rem;
}

.latest-results-groups {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px 40px;
  margin: 16px 0;
}

@media (min-width: 641px) {
  .latest-results-groups {
    grid-template-columns: 1fr 1fr;
  }
}

.latest-results-link {
  font-size: 0.9rem;
  margin-top: 8px;
}

/* Leaderboard tabs */
.leaderboard-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.leaderboard-tab {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text);
}

.leaderboard-tab.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

/* Most Improved panel */
.improved-period-btns {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.improved-pos { color: #2a6a2a; font-weight: 600; }
.improved-neg { color: var(--red); font-weight: 600; }

/* Rank change on player profile */
.rank-change {
  font-size: 0.8em;
  font-weight: normal;
  margin-left: 4px;
}

/* Profile session expand */
.profile-session-row {
  cursor: pointer;
}

.profile-session-row:hover td {
  background: #f3f0e8;
}

.profile-session-row .session-chevron {
  font-size: 0.65rem;
  color: var(--muted);
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s;
}

.profile-session-row.expanded .session-chevron {
  transform: rotate(90deg);
}

.profile-session-detail-row td {
  padding: 6px 8px 12px 16px;
  background: #f7f5ef;
}

.profile-match-table {
  font-size: 0.82rem;
  border-collapse: collapse;
  min-width: 240px;
}

.profile-match-table td {
  padding: 3px 12px 3px 0;
}

.match-win  { color: #2a6a2a; font-weight: 600; }
.match-loss { color: var(--red); font-weight: 600; }

.rank-change[data-dir="up"]   { color: #2a6a2a; }
.rank-change[data-dir="down"] { color: var(--red); }

/* Hall of Fame */
.hof-section {
  margin-bottom: 40px;
}

.hof-table {
  width: 100%;
  max-width: 560px;
}

.hof-table td:first-child {
  color: var(--muted);
  width: 2rem;
}

tr.hof-gold td:nth-child(2) a,
tr.hof-gold td:nth-child(2) {
  font-weight: 700;
}

/* ---- Player profile percentile + show more ---- */

.profile-percentile {
  font-size: 0.8em;
  color: var(--muted);
  font-weight: normal;
}

.show-more-sessions {
  margin-top: 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}

.show-more-sessions:hover {
  border-color: #999;
  color: var(--text);
}
