:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --panel: #ffffff;
  --control: #ffffff;
  --panel-strong: #0b2e63;
  --text: #172033;
  --muted: #667085;
  --line: #d8e0ec;
  --accent: #2474d6;
  --accent-2: #61a5fa;
  --gold: #d4a017;
  --soft: #eaf2ff;
  --soft-strong: #e2edff;
  --table-head: #f7faff;
  --stat-bg: #fbfdff;
  --shadow: 0 16px 40px rgba(24, 52, 94, 0.11);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07111f;
  --panel: #0c1828;
  --control: #12233a;
  --panel-strong: #06101d;
  --text: #edf5ff;
  --muted: #93a8c2;
  --line: #20344f;
  --accent: #60a5fa;
  --accent-2: #38bdf8;
  --gold: #f5c451;
  --soft: #10243d;
  --soft-strong: #142d4f;
  --table-head: #081525;
  --stat-bg: #091827;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(16px, 4vw, 56px);
  background: var(--panel-strong);
  color: #f8fbf7;
}

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

.app-header h1 {
  margin: 4px 0 0;
  font-size: clamp(28px, 5vw, 52px);
  line-height: 1;
  letter-spacing: 0;
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.top-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  padding: 4px 10px;
  color: #d8e9ff;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.top-nav a[aria-current="page"] {
  background: rgba(96, 165, 250, 0.18);
  color: #ffffff;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-header .eyebrow {
  color: #9ec5ff;
}

.header-stat {
  display: grid;
  gap: 2px;
  min-width: 116px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  text-align: right;
}

.header-stat span {
  font-size: 30px;
  font-weight: 850;
}

.header-stat small {
  color: #c6dcff;
  font-size: 12px;
}

main {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 32px) 48px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(140px, 190px) minmax(140px, 190px) minmax(130px, 170px);
  gap: 12px;
  margin-bottom: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

input,
select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--control);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 116, 214, 0.18);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.league-summary,
.source-card,
.rankings-shell,
.club-panel article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.league-summary {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.league-summary strong {
  font-size: 18px;
}

.league-summary span {
  color: var(--muted);
  font-size: 13px;
}

.source-shell {
  margin-bottom: 18px;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding-top: 12px;
}

.source-card {
  display: grid;
  align-content: space-between;
  gap: 16px;
  min-height: 154px;
  padding: 16px;
}

.source-card h3 {
  margin: 4px 0 8px;
  font-size: 18px;
}

.source-card a {
  color: var(--accent);
  font-size: 13px;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.source-notes {
  display: grid;
  gap: 5px;
  margin: 12px 0 0;
  padding-left: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.meter {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: var(--soft);
}

.meter i {
  display: block;
  height: 100%;
  background: var(--accent);
}

.rankings-shell {
  overflow: hidden;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2,
.dialog-header h2 {
  margin: 2px 0 0;
  font-size: 22px;
  letter-spacing: 0;
}

.ghost-button,
.icon-button,
.theme-toggle {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.ghost-button {
  min-width: 94px;
  height: 38px;
}

.icon-button {
  width: 36px;
  height: 36px;
  font-size: 22px;
  line-height: 1;
}

.theme-toggle {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.theme-toggle span {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #f6c84f;
  box-shadow: 0 0 0 3px rgba(246, 200, 79, 0.16);
  transition: transform 0.18s ease, background 0.18s ease;
}

[data-theme="dark"] .theme-toggle span {
  transform: translateX(20px);
  background: #dce7ff;
  box-shadow: inset -5px -2px 0 #8797bc;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: var(--table-head);
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.is-selected {
  background: var(--soft-strong);
}

.rank {
  font-weight: 850;
}

.club-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 230px;
}

.club-crest {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 900;
}

.club-crest.sm {
  width: 34px;
  height: 34px;
}

.club-crest.lg {
  width: 54px;
  height: 54px;
}

.club-crest img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0;
  background: transparent;
}

.club-crest b {
  display: none;
  font-size: 11px;
}

.club-crest.lg b {
  font-size: 15px;
}

.club-crest[data-fallback="true"] b,
.club-crest:empty b {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.club-name {
  display: grid;
  gap: 3px;
}

.club-name strong {
  font-size: 15px;
}

.club-name span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.icon-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px 3px 4px;
  background: var(--soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.icon-badge.cup {
  background: rgba(245, 196, 81, 0.16);
  color: var(--gold);
}

.icon-badge.cup.qualifying-entry {
  background: rgba(96, 165, 250, 0.14);
  color: var(--accent);
}

.icon-badge.honor {
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent-2);
}

.competition-mark {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-size: 8px;
  font-weight: 950;
  line-height: 1;
}

.competition-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
}

.competition-mark b {
  display: none;
}

.competition-mark[data-fallback="true"] {
  width: auto;
  min-width: 28px;
  border: 1px solid currentColor;
  padding: 0 5px;
  border-radius: 6px;
  background: transparent;
}

.competition-mark[data-fallback="true"] b {
  display: inline;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.cup {
  background: rgba(245, 196, 81, 0.16);
  color: var(--gold);
}

.badge.cup.qualifying-entry {
  background: rgba(96, 165, 250, 0.14);
  color: var(--accent);
}

.badge.honor {
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent-2);
}

.info-dot {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-left: 5px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 10px;
  line-height: 1;
  outline: none;
}

.tooltip {
  position: absolute;
  z-index: 5;
  right: 0;
  bottom: calc(100% + 8px);
  display: none;
  width: max-content;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
  white-space: normal;
}

.info-dot:hover .tooltip,
.info-dot:focus .tooltip {
  display: block;
}

.number {
  text-align: right;
}

.coefficient {
  color: var(--accent);
  font-size: 22px;
  font-weight: 900;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.pagination-actions {
  display: flex;
  gap: 8px;
}

.pagination-actions .ghost-button {
  min-width: 72px;
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.club-panel {
  margin-top: 18px;
}

.club-panel article {
  padding: 18px;
}

.club-detail-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--stat-bg);
}

.detail-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-title h2 {
  margin: 0;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.detail-section-label {
  margin-top: 18px;
}

.profile-info-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.profile-info {
  min-height: 66px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--stat-bg);
}

.profile-info span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.profile-info strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  line-height: 1.25;
}

.formula-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.formula-list li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

dialog {
  width: min(680px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.24);
}

.club-dialog {
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 32px);
  overflow: auto;
}

.club-dialog #clubPanel article {
  border: 0;
  padding: 30px;
  box-shadow: none;
}

.close-floating {
  position: sticky;
  z-index: 2;
  top: 12px;
  float: right;
  margin: 12px 12px 0 0;
}

dialog::backdrop {
  background: rgba(8, 20, 15, 0.45);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

#formulaContent {
  padding: 18px;
}

@media (max-width: 780px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-stat {
    text-align: left;
  }

  .header-actions {
    justify-content: space-between;
  }

  .toolbar,
  .summary-grid,
  .source-grid,
  .club-detail-grid,
  .stat-grid,
  .profile-info-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .ghost-button {
    width: 100%;
  }

  .pagination-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-actions .ghost-button {
    width: auto;
  }
}
