:root {
  --bg: #17161a;
  --bg-soft: #1d1c21;
  --surface: #222127;
  --fg: #efeae1;
  --muted: #9a9287;
  --line: #322f38;
  --line-strong: #4a4453;

  --gold: #d4a44a;
  --gold-dim: #8f7333;
  --crimson: #9e2b32;

  --win: #7cb87c;
  --lose: #c86a63;

  --maxw: 900px;
  --radius: 2px;

  --serif: 'Georgia', 'Times New Roman', 'PT Serif', serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 10;
  padding: 8px 14px;
  background: var(--gold);
  color: #17161a;
  font-size: 14px;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
}

.site-head,
.main,
.site-foot {
  width: 100%;
  max-width: var(--maxw);
  padding: 0 20px;
  margin: 0 auto;
}

.site-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 26px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--gold);
}

.brand span {
  color: var(--muted);
  font-weight: 400;
}

.brand-tag {
  margin-left: 2px;
  padding: 1px 5px;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: 3px;
}

.nav {
  display: flex;
  gap: 22px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav a {
  color: var(--muted);
  padding-bottom: 3px;
  border-bottom: 1px solid transparent;
  white-space: nowrap;
}

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

.nav a.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 24px;
  padding-bottom: 56px;
}

.muted {
  color: var(--muted);
}

.loading {
  padding: 64px 0;
  color: var(--muted);
  font-size: 14px;
}

.empty-note {
  margin: 0;
  padding: 18px 0;
  color: var(--muted);
  font-size: 14px;
}

.leagues {
  display: flex;
  justify-content: center;
  gap: 0;
  margin: 4px 0 30px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.league-btn {
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 9px 20px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.league-btn:last-child {
  border-right: 0;
}

.league-btn:hover {
  color: var(--fg);
  background: var(--bg-soft);
}

.league-btn.active {
  background: var(--gold);
  color: #17161a;
  font-weight: 600;
}

.league-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.page-title {
  margin: 6px 0 6px;
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.page-sub {
  margin: 0 0 26px;
  font-size: 14px;
  color: var(--muted);
}

.section-title {
  margin: 30px 0 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold-dim);
}

.battle {
  width: 100%;
}

.battle-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 14px;
  width: 100%;
}

.versus {
  align-self: center;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--gold-dim);
  padding: 0 4px;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.card:hover:not(:disabled) {
  border-color: var(--gold);
  background: var(--surface);
}

.card:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.card:disabled {
  cursor: default;
}

.card.is-winner {
  border-color: var(--gold);
  background: var(--surface);
}

.card.is-loser {
  opacity: 0.45;
}

.photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface);
  border-radius: var(--radius);
  display: block;
}

.photo.is-empty {
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 30px;
  color: var(--gold-dim);
}

.card-name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
}

.card-meta {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.card-wrap {
  display: flex;
  flex-direction: column;
}

.card-wrap .card {
  flex: 1;
}

.card-awards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 6px;
  margin-top: 1px;
}

.award {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.01em;
  color: var(--muted);
  white-space: nowrap;
}

.award-icon {
  color: var(--gold-dim);
  font-size: 10px;
  line-height: 1;
}

.card:hover .award,
.card:focus-visible .award {
  border-color: var(--line-strong);
  color: var(--fg);
}

.card:hover .award-icon {
  color: var(--gold);
}

.card-stats {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.cs-row {
  display: grid;
  grid-template-columns: 1fr 2.6em 2.6em 2.6em;
  gap: 8px;
  align-items: baseline;
}

.cs-label {
  text-align: left;
  letter-spacing: 0.02em;
}

.cs-total,
.cs-good,
.cs-bad {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cs-total {
  color: var(--fg);
}

.cs-good {
  color: color-mix(in srgb, var(--win) 65%, var(--muted));
}

.cs-bad {
  color: color-mix(in srgb, var(--lose) 55%, var(--muted));
}

.cs-head {
  font-size: 10px;
  letter-spacing: 0.04em;
  opacity: 0.5;
}

.cs-head .cs-total,
.cs-head .cs-good,
.cs-head .cs-bad {
  color: var(--muted);
}

.card-source {
  align-self: center;
  margin-top: 8px;
  padding: 2px 4px;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--muted);
  opacity: 0.55;
  border-bottom: 1px solid transparent;
}

.card-source:hover,
.card-source:focus-visible {
  color: var(--gold);
  opacity: 1;
  border-bottom-color: var(--gold-dim);
}

.card-rating {
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
}

.delta {
  font-weight: 700;
}

.delta.up {
  color: var(--win);
}

.delta.down {
  color: var(--lose);
}

.battle-actions {
  margin: 20px 0 0;
  display: flex;
  justify-content: center;
}

.battle-hint {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.battle-keys {
  margin: 10px 0 0;
  font-size: 12px;
  opacity: 0.7;
}

.card.is-placeholder {
  cursor: default;
  opacity: 0.35;
  min-height: 260px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  font-size: 14px;
  text-align: center;
}

.toast[hidden] {
  display: none;
}

.toast.is-warn {
  border-color: var(--gold-dim);
  color: var(--gold);
}

.toast.is-error {
  border-color: var(--lose);
  color: var(--lose);
}

.battle-note {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  opacity: 0.75;
}

.btn {
  font: inherit;
  font-size: 14px;
  padding: 8px 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.toolbar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
  width: 100%;
}

.input,
.select {
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: inherit;
}

.input {
  min-width: 220px;
}

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

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--gold);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  text-align: left;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--gold-dim);
  text-transform: uppercase;
  border-bottom-color: var(--line-strong);
}

tbody tr:hover {
  background: var(--bg-soft);
}

.col-num {
  text-align: right;
  width: 1%;
}

.rank {
  color: var(--muted);
  width: 1%;
  font-family: var(--serif);
}

tbody tr:nth-child(1) .rank,
tbody tr:nth-child(2) .rank,
tbody tr:nth-child(3) .rank {
  color: var(--gold);
}

.cell-name {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: normal;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface);
  flex: none;
}

.avatar.is-empty {
  display: grid;
  place-items: center;
  font-size: 12px;
  font-family: var(--serif);
  color: var(--gold-dim);
}

.name-link {
  border-bottom: 1px solid transparent;
}

tbody tr:hover .name-link,
a:hover > .name-link {
  border-bottom-color: var(--gold-dim);
}

.rating-val {
  font-weight: 700;
  color: var(--gold);
}

.uncalibrated {
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.calibration-note {
  max-width: 560px;
  margin: 0 auto 18px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--gold-dim);
  border-radius: var(--radius);
  background: var(--bg-soft);
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.calibration-note[hidden] {
  display: none;
}

.calibration-note a {
  color: var(--gold);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  font-size: 14px;
  color: var(--muted);
}

.stat-row {
  display: flex;
  justify-content: center;
  gap: 40px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.stat {
  min-width: 104px;
}

.stat-num {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  color: var(--gold);
  line-height: 1.2;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.league-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}

.league-card {
  padding: 16px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  text-align: center;
}

.league-card h3 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--fg);
}

.league-card .lead {
  font-size: 14px;
  color: var(--fg);
}

.league-card .lead-rating {
  color: var(--gold);
  font-weight: 700;
}

.league-card .counts {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.feed {
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
  font-size: 14px;
}

.feed li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.feed .beat {
  color: var(--muted);
  font-size: 13px;
}

.tag {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-dim);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 1px 6px;
}

.feed time {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.seo-block {
  width: 100%;
  margin-top: 34px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.seo-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  font-size: 14px;
}

.seo-list li {
  padding: 5px 0;
}

.seo-list a {
  border-bottom: 1px solid var(--line-strong);
}

.seo-list a:hover {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.prose {
  max-width: 620px;
  text-align: left;
}

.prose .page-title,
.prose .page-sub {
  text-align: center;
}

.prose p {
  margin: 0 0 14px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--fg);
}

.prose strong {
  color: var(--gold);
  font-weight: 600;
}

.prose a {
  color: var(--gold);
  border-bottom: 1px solid var(--gold-dim);
}

.prose .section-title {
  margin-top: 26px;
}

.prose-list {
  margin: 0 0 14px;
  padding-left: 20px;
  font-size: 15px;
  line-height: 1.65;
}

.prose-list li {
  margin: 5px 0;
}

.seasons-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  justify-content: center;
  margin: 0;
  font-size: 14px;
}

.seasons-links a {
  color: var(--muted);
  border-bottom: 1px solid transparent;
}

.seasons-links a:hover {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.seasons-links .current {
  color: var(--gold);
  font-weight: 700;
}

.spark {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  color: var(--gold);
}

.profile {
  width: 100%;
  max-width: 620px;
}

.profile-photo {
  width: 180px;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 14px;
}

.profile dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0;
  margin: 20px 0 0;
  text-align: left;
  font-size: 14px;
}

.profile dt {
  padding: 8px 0;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.profile dd {
  margin: 0;
  padding: 8px 0;
  text-align: right;
  border-bottom: 1px solid var(--line);
}

.back-link {
  display: inline-block;
  margin-top: 22px;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--line-strong);
}

.back-link:hover {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.profile-nav {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}

.error {
  padding: 48px 0;
  color: var(--lose);
  font-size: 14px;
}

.site-foot {
  border-top: 1px solid var(--line);
  padding-top: 22px;
  padding-bottom: 34px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.foot-links {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.foot-links a,
.foot-links button {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  padding: 0 0 1px;
  cursor: pointer;
}

.foot-links a:hover,
.foot-links button:hover {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.site-foot p {
  margin: 4px 0;
}

.site-foot a.src {
  color: var(--muted);
  border-bottom: 1px solid var(--line-strong);
}

.site-foot a.src:hover {
  color: var(--gold);
}

.support-link {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}

.support-icon {
  color: var(--gold-dim);
  font-size: 11px;
  line-height: 1;
}

.foot-links .support-link:hover .support-icon,
.foot-links .support-link:focus-visible .support-icon {
  color: var(--gold);
}

.support-card {
  margin: 0 0 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--gold-dim);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.support-card p {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.support-card .support-btn {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border-color: var(--gold-dim);
  color: var(--fg);
  text-decoration: none;
}

.support-card .support-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--surface);
}

.support-card .support-btn:hover .support-icon {
  color: var(--gold);
}

.foot-panel {
  max-width: 620px;
  margin: 0 auto 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
}

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

.foot-panel h4 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 14px;
  color: var(--gold);
}

.foot-panel ul {
  margin: 0;
  padding-left: 18px;
}

.foot-panel li {
  margin: 3px 0;
}

.foot-panel code {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--gold);
}

.foot-panel a {
  color: var(--gold);
  border-bottom: 1px solid var(--gold-dim);
}

.foot-links button[aria-expanded='true'] {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

@media (max-width: 640px) {
  .battle-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .versus {
    padding: 2px 0;
  }

  .photo {
    aspect-ratio: 4 / 3;
  }

  .site-head {
    padding-top: 20px;
    justify-content: center;
  }

  .nav {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 18px;
    font-size: 12px;
    letter-spacing: 0.03em;
  }

  .league-cards {
    grid-template-columns: 1fr;
  }

  .stat-row {
    gap: 24px;
  }

  .leagues {
    width: 100%;
  }

  .league-btn {
    flex: 1;
    padding: 9px 8px;
    font-size: 12px;
    letter-spacing: 0.03em;
  }

  .page-title {
    font-size: 23px;
  }

  th,
  td {
    padding: 8px 4px;
  }

  th {
    white-space: normal;
    letter-spacing: 0.04em;
  }

  .rating-val .uncalibrated {
    font-size: 0;
  }

  .rating-val .uncalibrated::after {
    content: '—';
    font-size: 14px;
  }

  .col-extra {
    display: none;
  }

  [data-sort='winrate'] .col-winrate,
  [data-sort='games'] .col-games,
  [data-sort='correct'] .col-correct {
    display: table-cell;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
