:root {
  --bg: #f6f2ec;
  --bg-alt: #f0ebe3;
  --card: #ffffff;
  --text: #182025;
  --muted: #5c6770;
  --accent: #ef6c44;
  --accent-dark: #cc5132;
  --accent-soft: rgba(239, 108, 68, 0.12);
  --teal: #2a7564;
  --teal-soft: rgba(42, 117, 100, 0.12);
  --border: rgba(24, 32, 37, 0.12);
  --shadow: 0 20px 50px rgba(24, 32, 37, 0.12);
  --radius: 20px;
  --card-radius: 16px;
  --card-border: rgba(0, 0, 0, 0.08);
  --card-bg: rgba(255, 255, 255, 0.72);
  --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  --text-strong: rgba(20, 20, 20, 0.92);
  --text-muted: rgba(20, 20, 20, 0.6);
}

body[data-theme="dark"] {
  --bg: #0f1215;
  --bg-alt: #151a1f;
  --card: #1b2128;
  --text: #f3f5f7;
  --muted: #a5b0bb;
  --accent: #ef6c44;
  --accent-dark: #f08b6f;
  --accent-soft: rgba(239, 108, 68, 0.2);
  --teal: #5dc2ae;
  --teal-soft: rgba(93, 194, 174, 0.2);
  --border: rgba(243, 245, 247, 0.12);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-bg: rgba(27, 33, 40, 0.72);
  --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --text-strong: rgba(243, 245, 247, 0.95);
  --text-muted: rgba(243, 245, 247, 0.65);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

h1,
h2,
h3 {
  font-family: "Fraunces", serif;
  margin: 0;
}

p {
  margin: 0;
  color: var(--muted);
}

button,
input,
select {
  font-family: inherit;
}

.background {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}

.glow {
  position: absolute;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  opacity: 0.4;
  filter: blur(0px);
}

.glow-one {
  background: radial-gradient(circle, #ffe2c8 0%, rgba(255, 226, 200, 0) 70%);
  top: -120px;
  left: -80px;
}

.glow-two {
  background: radial-gradient(circle, rgba(95, 200, 180, 0.5) 0%, rgba(95, 200, 180, 0) 70%);
  bottom: -140px;
  right: -120px;
}

.grid {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(24, 32, 37, 0.08) 1px, transparent 1px);
  background-size: 36px 36px;
  opacity: 0.35;
  mix-blend-mode: multiply;
}

body[data-theme="dark"] .grid {
  background-image: radial-gradient(rgba(243, 245, 247, 0.08) 1px, transparent 1px);
}

.site-header {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 24px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 80px;
  display: grid;
  gap: 28px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.selection-card {
  display: grid;
  gap: 20px;
}

.selection-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: end;
}

.player-field {
  display: grid;
  gap: 8px;
  position: relative;
}

.player-field label {
  font-weight: 600;
}

.input-shell {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
}

.input-shell input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 1rem;
  color: var(--text);
}

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
}

.typeahead {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow: auto;
  display: none;
  z-index: 10;
}

.typeahead.is-open {
  display: block;
}

.typeahead button {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}

.typeahead button:hover,
.typeahead button.is-active {
  background: var(--accent-soft);
}

.swap-btn {
  border-radius: 999px;
  padding: 10px 16px;
  border: 1px dashed var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--muted);
}

.selection-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(239, 108, 68, 0.3);
}

.ghost {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  color: var(--text);
}

.status {
  margin-left: auto;
  font-size: 0.95rem;
}

.recent {
  display: grid;
  gap: 8px;
}

.recent-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.recent-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.recent-list button {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.9rem;
}

.stage-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.tabs {
  display: inline-flex;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  padding: 4px;
  gap: 4px;
}

.tab {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}

.tab.is-active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

.stage-meta {
  font-size: 0.95rem;
  color: var(--muted);
}

.summary-section {
  display: grid;
  gap: 16px;
}

.summary-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.record {
  background: var(--bg-alt);
  border-radius: 18px;
  padding: 12px 18px;
  min-width: 180px;
  text-align: center;
  border: 1px solid var(--border);
}

.summary-grid {
  display: block;
}

.h2h-scoreboard {
  display: grid;
  gap: 18px;
  --score-a: rgba(42, 117, 100, 0.42);
  --score-b: rgba(239, 108, 68, 0.42);
}

body[data-theme="dark"] .h2h-scoreboard {
  --score-a: rgba(93, 194, 174, 0.48);
  --score-b: rgba(239, 108, 68, 0.48);
}

.scoreboard-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
}

.scoreboard-player {
  font-weight: 700;
  font-size: 1.1rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scoreboard-player--a {
  color: var(--teal);
  text-align: left;
}

.scoreboard-player--b {
  color: var(--accent);
  text-align: right;
}

.scoreboard-title {
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  text-align: center;
}

.score-rows {
  display: grid;
  gap: 10px;
}

.score-row {
  position: relative;
  --left: 0;
  --right: 0;
  display: grid;
  grid-template-columns: minmax(72px, 110px) 1fr minmax(72px, 110px);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  overflow: hidden;
}

.score-row.skeleton .score-label,
.score-row.skeleton .score-value {
  background: transparent;
  border-color: transparent;
}

.score-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  opacity: 0.9;
  z-index: 0;
}

.score-fill--a {
  left: 0;
  width: calc(var(--left) * 100%);
  background: var(--score-a);
}

.score-fill--b {
  right: 0;
  width: calc(var(--right) * 100%);
  background: var(--score-b);
}

.score-value {
  position: relative;
  z-index: 1;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-value--a {
  color: var(--teal);
  text-align: left;
}

.score-value--b {
  color: var(--accent);
  text-align: right;
}

.score-value.is-lead {
  font-weight: 800;
  font-size: 1.15rem;
}

.score-label {
  position: relative;
  z-index: 1;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  padding: 0 6px;
}

.score-note {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 2px;
  z-index: 1;
}

.scoreboard-highlights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.highlight-column {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
}

.highlight-column-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
}

.highlight-column--a .highlight-column-title {
  color: var(--teal);
}

.highlight-column--b .highlight-column-title {
  color: var(--accent);
}

.highlight {
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  background: var(--card);
  display: grid;
  gap: 4px;
  border-left: 3px solid var(--teal);
}

.highlight--b {
  border-left-color: var(--accent);
}

.highlight-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.highlight-score {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.highlight-meta {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.highlight-tour {
  font-size: 0.8rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 720px) {
  .scoreboard-head {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .scoreboard-player--a,
  .scoreboard-player--b {
    text-align: center;
  }

  .scoreboard-title {
    justify-self: center;
  }

  .score-row {
    grid-template-columns: minmax(60px, 90px) 1fr minmax(60px, 90px);
  }
}

.viz-card {
  padding: 20px;
}

.viz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.viz-block {
  background: var(--bg-alt);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

.viz-title {
  font-weight: 600;
}

.viz-title:not(.with-info) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viz-title.with-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.viz-title-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.info-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.75rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.info-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  max-width: 320px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 0.75rem;
  line-height: 1.3;
  color: var(--text);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 5;
  white-space: normal;
}

.info-wrap:hover .info-tooltip,
.info-wrap:focus-within .info-tooltip,
.info-wrap.is-open .info-tooltip {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.form-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  overflow-x: auto;
  padding: 4px 4px 6px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chip {
  width: clamp(22px, 2.6vw, 28px);
  min-width: 22px;
  height: clamp(22px, 2.6vw, 28px);
  padding: 0;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.chip.win {
  background: rgba(42, 117, 100, 0.2);
  color: var(--teal);
  border-color: rgba(42, 117, 100, 0.3);
}

.chip.loss {
  background: rgba(239, 108, 68, 0.2);
  color: var(--accent);
  border-color: rgba(239, 108, 68, 0.3);
}

.chip.draw {
  background: rgba(100, 120, 140, 0.2);
  color: var(--muted);
  border-color: rgba(100, 120, 140, 0.3);
}

.chart {
  min-height: 180px;
  display: grid;
  gap: 8px;
  align-content: start;
  color: var(--muted);
  position: relative;
}

.chart svg {
  width: 100%;
  height: 170px;
}

.chart-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 0.75rem;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.1s ease;
  z-index: 2;
  max-width: 220px;
}

.chart-tooltip.is-visible {
  opacity: 1;
}

.chart-tooltip .tooltip-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.chart-tooltip .tooltip-row {
  color: var(--muted);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.legend-dot.a {
  background: var(--teal);
}

.legend-dot.b {
  background: var(--accent);
}

.chart-note {
  font-size: 0.75rem;
  color: var(--muted);
}

.filters-card {
  padding: 20px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.filter {
  display: grid;
  gap: 8px;
}

.filter label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.filter select,
.filter input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--text);
}

.toggle-group {
  display: grid;
  gap: 8px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.matches-card {
  display: grid;
  gap: 16px;
}

.matches-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

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

#matches-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

#matches-table th,
#matches-table td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

#matches-table th {
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
  color: var(--muted);
  font-weight: 600;
}

.match-score {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(24, 32, 37, 0.08);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.winner {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.winner.a {
  background: rgba(42, 117, 100, 0.2);
  color: var(--teal);
}

.winner.b {
  background: rgba(239, 108, 68, 0.2);
  color: var(--accent);
}

.winner.d {
  background: rgba(120, 130, 140, 0.2);
  color: var(--muted);
}

.expand-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
}

.detail-row td {
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.empty-state {
  text-align: center;
  padding: 40px 24px;
}

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

.site-footer {
  text-align: center;
  padding: 30px 20px 50px;
  color: var(--muted);
}

.skeleton {
  position: relative;
  color: transparent !important;
  background: linear-gradient(90deg, rgba(120, 130, 140, 0.1) 0%, rgba(120, 130, 140, 0.25) 50%, rgba(120, 130, 140, 0.1) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton::after {
  content: "";
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@media (max-width: 900px) {
  .selection-grid {
    grid-template-columns: 1fr;
  }

  .swap-btn {
    justify-self: start;
  }

  .status {
    margin-left: 0;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 600px) {
  .container {
    padding-bottom: 60px;
  }

  .record {
    width: 100%;
  }

  .matches-header {
    align-items: flex-start;
  }
}
