:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1f1a14;
  --muted: #6d6458;
  --accent: #0f5c4c;
  --accent-soft: #d8ebe4;
  --gold: #b8860b;
  --gold-soft: #f6ecd0;
  --border: #ddd4c6;
  --shadow: 0 12px 30px rgba(31, 26, 20, 0.08);
  --radius: 16px;
  --font-serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-serif);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #efe4cf 0, transparent 35%),
    radial-gradient(circle at bottom right, #dce9e4 0, transparent 30%),
    var(--bg);
  line-height: 1.5;
}

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

.container {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: rgba(255, 253, 248, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 0;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  color: var(--muted);
}

h1 {
  margin: 0.15rem 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

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

.home-link {
  flex-shrink: 0;
  align-self: center;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
}

.home-link:hover {
  background: var(--accent-soft);
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font: inherit;
  cursor: pointer;
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.stat-card strong {
  display: block;
  font-size: 1.8rem;
  line-height: 1.1;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.search-field {
  flex: 1 1 240px;
}

.search-field input,
.sort-field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.7rem 1rem;
  font: inherit;
  background: var(--surface);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  cursor: pointer;
}

.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.sort-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding-bottom: 3rem;
}

.team-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.team-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(31, 26, 20, 0.12);
}

.team-card.finalist {
  border-color: #d8b24d;
  background: linear-gradient(180deg, var(--gold-soft), var(--surface) 45%);
}

.team-card-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: start;
}

.team-card-header h2.team-name,
.team-name {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.team-rank {
  margin: 0.35rem 0 0;
  font-family: var(--font-serif);
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #ece7de;
  color: var(--muted);
}

.badge-finalist {
  background: var(--gold-soft);
  color: #7a5a00;
}

.team-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 1rem 0;
}

.metric {
  background: #f7f3ec;
  border-radius: 12px;
  padding: 0.55rem;
  text-align: center;
}

.metric span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.metric strong {
  font-size: 1rem;
}

.player-preview {
  list-style: none;
  margin: 0;
  padding: 0;
}

.player-preview li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0;
  border-top: 1px solid #eee7db;
  font-size: 0.92rem;
}

.player-preview-link {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-preview .rating,
.rating-pair {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 0 4rem;
}

.hidden {
  display: none;
}

.modal {
  border: 0;
  padding: 0;
  width: min(960px, calc(100% - 2rem));
  background: transparent;
}

.modal::backdrop {
  background: rgba(20, 16, 12, 0.45);
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  max-height: 85vh;
  overflow: auto;
}

.modal-close {
  float: right;
  border: 0;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.modal h2 {
  margin-top: 0;
}

.players-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.players-table th,
.players-table td {
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid #eee7db;
  text-align: left;
}

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

.players-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

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

.ratingviewer-link {
  margin-left: 0.35rem;
  text-decoration: none;
  font-size: 0.85rem;
}

.games-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin-top: 0.75rem;
}

.games-table th,
.games-table td {
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid #eee7db;
  text-align: left;
}

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

.games-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.game-result {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
}

.game-result::before {
  content: "●";
  font-size: 0.75rem;
}

.game-result-win {
  color: #1f7a3f;
}

.game-result-loss {
  color: #c0392b;
}

.game-result-draw {
  color: var(--muted);
  font-weight: 500;
}

.color-cell {
  text-align: center;
}

.color-box {
  display: inline-block;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 3px;
  border: 1px solid #8a8175;
  vertical-align: middle;
}

.color-box-white {
  background: #fff;
  box-shadow: inset 0 0 0 1px #e8e2d8;
}

.color-box-black {
  background: #1a1a1a;
  border-color: #1a1a1a;
}

.player-links {
  margin: 0.35rem 0 0;
}

.player-links a {
  font-weight: 600;
}

.games-empty,
.modal-hint {
  margin-top: 0.75rem;
}

.modal-section-title {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
}

.team-matches-table td.match-meta {
  vertical-align: top;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0 2rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .home-link {
    align-self: flex-start;
  }

  .team-metrics {
    grid-template-columns: 1fr 1fr;
  }
}
