:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #111827;
  --muted: #5b6472;
  --line: #d8dde6;
  --line-strong: #b8c0cc;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --green: #0f766e;
  --amber: #a16207;
  --code-bg: #0d1117;
  --code-text: #c9d1d9;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 84px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 249, 0.94);
  backdrop-filter: blur(12px);
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 760;
  letter-spacing: 0;
}

.brand {
  display: flex;
  align-items: center;
  min-height: 42px;
}

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

.header-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-weight: 690;
  white-space: nowrap;
}

.header-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.tab {
  min-width: 104px;
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 680;
}

.tab.is-active {
  background: var(--text);
  color: #ffffff;
}

main {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px 28px 40px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  min-height: 76px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  font-size: 24px;
  line-height: 1.1;
}

.summary-panel {
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

.summary-heading h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 760;
  letter-spacing: 0;
}

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

.summary-scroll {
  overflow: auto;
}

.summary-table {
  min-width: 560px;
  box-shadow: none;
}

.summary-table th,
.summary-table td {
  padding: 9px 14px;
}

.summary-table th:last-child,
.summary-table td:last-child {
  text-align: right;
}

.controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 220px 220px;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.search-field,
.select-field {
  display: grid;
  gap: 6px;
}

.search-field span,
.select-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

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

input {
  padding: 0 13px;
}

select {
  padding: 0 36px 0 12px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.table-shell {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.table-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.pager {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.pager-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 680;
}

.pager-button:disabled {
  cursor: default;
  opacity: 0.42;
}

.table-scroll {
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fbfcfe;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

th button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: inherit;
  text-transform: inherit;
}

tbody tr:hover > td:not(.code-cell) {
  background: #f9fbff;
}

tbody tr.is-open > td:not(.code-cell) {
  background: #f7fafc;
}

.data-row {
  scroll-margin-top: 96px;
}

.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.title-cell {
  min-width: 300px;
  font-weight: 650;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #2f3a4a;
  font-size: 12px;
  font-weight: 720;
  white-space: nowrap;
}

.pill.high {
  background: #fff7ed;
  color: var(--amber);
}

.codebook-pill {
  background: #ecfeff;
  color: #155e75;
}

.tier-0000-1199-newbie {
  background: #e0f2fe;
  color: #075985;
}

.tier-1200-1399-pupil {
  background: #dcfce7;
  color: #166534;
}

.tier-1400-1599-specialist {
  background: #fef9c3;
  color: #854d0e;
}

.tier-1600-1899-expert {
  background: #ffedd5;
  color: #9a3412;
}

.tier-1900-2099-candidate-master {
  background: #fee2e2;
  color: #991b1b;
}

.tier-2100-2299-master {
  background: #fce7f3;
  color: #9d174d;
}

.tier-2300-2399-international-master {
  background: #ede9fe;
  color: #5b21b6;
}

.tier-2400-2599-grandmaster {
  background: #e0e7ff;
  color: #3730a3;
}

.tier-2600-2999-international-grandmaster {
  background: #ccfbf1;
  color: #115e59;
}

.tier-3000-3999-legendary-grandmaster {
  background: #f3e8ff;
  color: #6b21a8;
}

.tier-4000-plus-eponym {
  background: #111827;
  color: #ffffff;
}

.tier-unrated {
  background: #e5e7eb;
  color: #374151;
}

.pill.contest {
  color: #ffffff;
}

.contest-weekly.contest-tone-0 {
  background: #0f766e;
}

.contest-weekly.contest-tone-1 {
  background: #0d9488;
}

.contest-weekly.contest-tone-2 {
  background: #0891b2;
}

.contest-weekly.contest-tone-3 {
  background: #0369a1;
}

.contest-biweekly.contest-tone-0 {
  background: #7e22ce;
}

.contest-biweekly.contest-tone-1 {
  background: #9333ea;
}

.contest-biweekly.contest-tone-2 {
  background: #be185d;
}

.contest-biweekly.contest-tone-3 {
  background: #c2410c;
}

.action-row {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-weight: 690;
}

.button:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.code-cell {
  padding: 0;
  background: var(--code-bg);
}

.code-row:hover .code-cell {
  background: var(--code-bg);
}

.code-panel {
  display: grid;
  grid-template-rows: auto minmax(220px, 520px);
  max-height: 620px;
}

.code-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.code-toolbar .button {
  min-height: 28px;
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

pre {
  margin: 0;
  overflow: auto;
  padding: 16px;
  color: var(--code-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.code-comment {
  color: #8b949e;
}

.code-string {
  color: #a5d6ff;
}

.code-preprocessor {
  color: #d2a8ff;
}

.code-keyword {
  color: #ff7b72;
}

.code-number {
  color: #79c0ff;
}

.code-view-main {
  width: min(1280px, 100%);
}

.code-view-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
  padding: 16px 0;
}

.code-view-heading h2 {
  margin: 4px 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

.code-view-meta,
.code-view-heading p {
  margin: 0;
  color: var(--muted);
}

.code-view-heading p {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.code-view-actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.full-code-panel {
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--code-bg);
  grid-template-rows: auto 1fr;
  max-height: none;
}

.full-code-panel pre {
  min-height: 68vh;
}

.empty {
  padding: 42px 16px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 860px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .header-link {
    width: 100%;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
    min-width: 0;
  }

  main {
    padding: 16px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .table-meta {
    flex-direction: column;
    gap: 4px;
  }

  .code-view-heading {
    flex-direction: column;
  }

  .code-view-actions {
    width: 100%;
    justify-content: flex-start;
  }
}
