/* One surface, quiet type, no decorative cards. */
:root {
  color-scheme: light;
  --ink: #202020;
  --ink-soft: #737373;
  --border: #e8e8e8;
  --surface-muted: #fafafa;
  --radius-sm: 0;
}
html {
  scrollbar-gutter: stable;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: #fff;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
.container {
  max-width: 960px;
  margin: 72px auto;
  padding: 0 28px;
}
h1 {
  margin: 0 0 28px;
  font-size: 23px;
  font-weight: 500;
  letter-spacing: -0.6px;
}
button,
input {
  font: inherit;
}
button {
  cursor: pointer;
}
button:disabled {
  opacity: 0.5;
  cursor: wait;
}
:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
}
#apiForm {
  display: block;
}
.form-group {
  margin-bottom: 20px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}
input {
  min-width: 0;
  border: 0;
  border-bottom: 1px solid #ccc;
  background: #fff;
  border-radius: 0;
  padding: 12px 0;
  color: inherit;
}
input::placeholder {
  color: var(--ink-soft);
}
#tournamentUrl {
  width: 100%;
  padding: 12px;
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  font-size: 14px;
}
#submitBtn {
  width: 100%;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 12px 24px;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
}
#submitBtn:hover {
  background: #444;
}
.loading,
.error {
  display: none;
  margin: 16px 0;
  font-size: 13px;
}
.loading {
  color: var(--ink-soft);
}
.error {
  color: #a12b2b;
}
.error.show {
  display: block;
}
.results {
  display: none;
  margin-top: 40px;
}
.results.show {
  display: block;
}
.tournament-info {
  margin-bottom: 24px;
}
.tournament-info h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
}
.tournament-info dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 0;
  font-size: 0.875rem;
}
.tournament-info dt {
  color: var(--ink-soft);
}
.tournament-info dd {
  margin: 0;
}
.mobile-rank-shift {
  display: none;
}
#standingsTable th:nth-child(3),
#standingsTable td:nth-child(3) {
  text-align: left;
}
.standings-legend {
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}
.view-switch {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}
.results-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 20px;
}
.rating-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 24px;
}
#searchInput {
  width: 220px;
  padding: 7px 0;
  border-color: var(--border);
}
#ratingSwitch {
  display: inline-flex;
  gap: 16px;
  flex-shrink: 0;
}
.rating-switch-btn {
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--ink-soft);
  border-bottom: 1px solid transparent;
}
.rating-switch-btn.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
.table-wrapper,
.games-table-wrapper {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
th,
td {
  padding: 13px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
th {
  font-weight: 400;
  color: var(--ink-soft);
  white-space: nowrap;
}
th:first-child,
td:first-child {
  width: 40px;
  text-align: left;
  padding-left: 0;
  color: var(--ink-soft);
}
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}
th:last-child,
td:last-child {
  padding-right: 0;
}
tbody tr:hover {
  background: var(--surface-muted);
}
.sort-button,
.player-name-button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: inherit;
}
.player-name-button {
  font-weight: 500;
}
.player-name-button:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.sortable.active {
  color: var(--ink);
}
.rating-change,
.result-badge {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.positive {
  color: #1f6b3b;
}
.negative {
  color: #a12b2b;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  padding: 24px;
  background: rgb(0 0 0 / 0.22);
  align-items: center;
  justify-content: center;
}
.modal-overlay.show {
  display: flex;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 720px;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 0;
}
.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.modal-close {
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 26px;
  padding: 4px 8px;
  flex-shrink: 0;
}
.modal-body {
  padding: 20px 28px 28px;
  overflow-y: auto;
}
.player-meta {
  margin: 0 0 12px;
  color: var(--ink-soft);
  font-size: 14px;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  align-items: end;
  margin: 8px 0 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.detail-item {
  min-width: 0;
}
.detail-item + .detail-item {
  padding-left: 20px;
  border-left: 1px solid var(--border);
}
.detail-label {
  font-size: 12px;
  color: var(--ink-soft);
}
.detail-value {
  margin-top: 4px;
  line-height: 1.25;
  letter-spacing: -0.5px;
  white-space: nowrap;
  font-size: 24px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.detail-score .detail-value {
  font-size: 28px;
}
.detail-score-total {
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
}
.games-list {
  margin-top: 24px;
}
.games-list h4 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 400;
}
.games-table {
  table-layout: fixed;
  font-size: 12px;
}
.games-table th,
.games-table td {
  padding: 10px 8px;
}
.games-table td {
  vertical-align: middle;
}
.games-table .desktop-game-rating,
.games-table .desktop-game-color,
.games-table .game-result-cell {
  width: 72px;
  text-align: center;
}
.games-table .game-change-cell {
  width: 84px;
  text-align: right;
}
.games-table th:first-child,
.games-table td:first-child {
  padding-left: 0;
}
.games-table th:last-child,
.games-table td:last-child {
  padding-right: 0;
}
.opponent-name-cell {
  min-width: 120px;
}
.mobile-game-color,
.mobile-opponent-rating {
  display: none;
}
.game-result,
.game-color {
  display: flex;
  min-height: 1.5em;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: inherit;
}
.piece-color {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  flex-shrink: 0;
}
.piece-color.white {
  background: #fff;
}
.piece-color.black {
  background: var(--ink);
}
@media (max-width: 600px) {
  .container {
    margin: 32px auto;
    padding: 0 18px;
  }
  h1 {
    margin-bottom: 20px;
  }
  .results {
    margin-top: 28px;
  }
  #searchInput {
    width: 160px;
  }
  th,
  td {
    padding: 12px 8px;
    font-size: 12px;
  }
  .modal-overlay {
    padding: 12px;
  }
  .modal {
    max-height: 90dvh;
  }
  .modal-header {
    padding: 18px 18px 0;
  }
  .modal-body {
    padding: 16px 18px 20px;
  }
  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 20px;
  }
  .detail-item + .detail-item {
    padding-left: 0;
    border-left: 0;
  }
  .detail-item:nth-child(even) {
    padding-left: 20px;
    border-left: 1px solid var(--border);
  }
  #resultsTable {
    table-layout: fixed;
  }
  #resultsTable .column-gameCount,
  #resultsTable .column-performance {
    display: none;
  }
  #resultsTable th:first-child,
  #resultsTable td:first-child {
    width: 28px;
  }
  #resultsTable th.column-rating {
    width: 46px;
  }
  #resultsTable th.column-ratingChange {
    width: 64px;
  }
  #resultsTable td,
  #resultsTable th {
    padding: 12px 4px;
  }
  #resultsTable td:first-child,
  #resultsTable th:first-child {
    padding-left: 0;
  }
  #resultsTable td:last-child,
  #resultsTable th:last-child {
    padding-right: 0;
  }
  #resultsTable .player-name-button {
    display: block;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  #standingsTable .column-start {
    display: none;
  }
  /* Name first, then rank; both stay in view while the other columns scroll.
     Rows are flex boxes so `order` can move the name ahead of the rank. */
  #standingsTable {
    display: block;
    width: max-content;
    min-width: 100%;
  }
  #standingsTable thead,
  #standingsTable tbody {
    display: block;
  }
  #standingsTable tr {
    display: flex;
  }
  #standingsTable th,
  #standingsTable td {
    flex: none;
    width: 52px;
  }
  #standingsTable th:nth-child(3),
  #standingsTable td:nth-child(3),
  #standingsTable th:nth-child(2),
  #standingsTable td:nth-child(2) {
    position: sticky;
    z-index: 1;
    background: #fff;
    white-space: nowrap;
  }
  #standingsTable th:nth-child(3),
  #standingsTable td:nth-child(3) {
    order: -1;
    left: 0;
    width: 140px;
  }
  #standingsTable th:nth-child(2),
  #standingsTable td:nth-child(2) {
    left: 140px;
    width: 64px;
    color: var(--ink);
    box-shadow: 1px 0 0 var(--border);
  }
  .mobile-rank-shift {
    display: inline;
    margin-left: 6px;
    font-size: 11px;
  }
  /* Column headers stay visible while scrolling. The results table fits the screen,
     so the page itself scrolls; the standings table scrolls sideways, so it scrolls
     vertically inside its own box. */
  #resultsView .table-wrapper {
    overflow: visible;
  }
  #standingsView .table-wrapper {
    max-height: 75dvh;
    overflow: auto;
  }
  #resultsTable thead,
  #standingsTable thead {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  #resultsTable th,
  #standingsTable th {
    background: #fff;
  }
  #standingsTable .player-name-button {
    display: block;
    max-width: 7.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #resultsTable th.column-tournamentPoints {
    width: 40px;
  }
  .games-table {
    table-layout: fixed;
  }
  .games-table .desktop-game-rating,
  .games-table .desktop-game-color {
    display: none;
  }
  .games-table th,
  .games-table td {
    padding: 10px 4px;
  }
  .games-table th:first-child,
  .games-table td:first-child {
    width: 28px;
  }
  .games-table .game-result-cell {
    width: 66px;
    white-space: nowrap;
  }
  .games-table .game-change-cell {
    width: 64px;
    white-space: nowrap;
  }
  .games-table .opponent-name-cell {
    min-width: 0;
  }
  .opponent-line {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }
  .mobile-game-color {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
  }
  .mobile-game-color .piece-color {
    width: 8px;
    height: 8px;
  }
  .opponent-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-opponent-rating {
    display: block;
    margin-top: 3px;
    color: var(--ink-soft);
    font-size: 11px;
  }
}

.player-k-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 16px 0;
  font-size: 12px;
}
.player-k-control select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid #d4d4d8;
  background: #fff;
  color: var(--ink);
}
.player-k-control span {
  color: var(--ink-soft);
}

.opponent-button,
.modal-back {
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
}
.opponent-button:hover,
.modal-back:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.opponent-button {
  max-width: 100%;
}
.modal-back {
  margin-bottom: 16px;
  color: var(--ink-soft);
  font-size: 12px;
}
