:root {
  --bg: #0b1120;
  --panel: #0f172a;
  --panel-2: #131c31;
  --line: #1e293b;
  --line-2: #2a3650;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --dim: #64748b;
  --accent: #f97316;
  --gain: #4ade80;
  --chip-active-bg: #f8fafc;
  --chip-active-fg: #0b1120;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

/* Header */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.hero h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.hero .star { color: var(--accent); }
.hero .sub { margin: 6px 0 0; color: var(--muted); }

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

.locale {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.locale button {
  border: 0;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
}
.locale button + button { border-left: 1px solid var(--line); }
.locale button[aria-pressed='true'] { background: var(--panel-2); color: var(--text); }
.locale button:not([aria-pressed='true']):hover { color: var(--text); }

.mode {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
}
.mode button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 7px;
  white-space: nowrap;
  cursor: pointer;
}
.mode button[aria-selected='true'] { background: var(--chip-active-bg); color: var(--chip-active-fg); }
.mode button:not([aria-selected='true']):hover { color: var(--text); }

.period {
  display: inline-flex;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.period button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
}
.period button[aria-selected='true'] { background: var(--accent); color: #fff; }
.period button:not([aria-selected='true']):hover { color: var(--text); }

/* Chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.chips-sub { gap: 8px; }
.chip {
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 9px 20px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.chips-sub .chip { font-size: 14px; padding: 6px 14px; color: var(--muted); }
.chip:hover { border-color: var(--dim); }
.chip[aria-pressed='true'] {
  background: var(--chip-active-bg);
  color: var(--chip-active-fg);
  border-color: var(--chip-active-bg);
}
.chip .count {
  margin-left: 6px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin: 10px 0 16px;
}
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  min-width: 340px;
}
.search:focus-within { border-color: var(--dim); }
.search svg { width: 16px; height: 16px; fill: none; stroke: var(--dim); stroke-width: 2; }
.search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 10px 0;
}

/* Board */
.board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.list { list-style: none; margin: 0; padding: 0; }

.row {
  display: grid;
  grid-template-columns: 72px minmax(220px, 1.05fr) 2fr 120px 64px;
  align-items: center;
  gap: 16px;
  padding: 18px 28px;
  border-top: 1px solid var(--line);
}
.row.head {
  border-top: 0;
  padding-top: 14px;
  padding-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.list .row:hover { background: var(--panel-2); }
.right { text-align: right; white-space: nowrap; }

.rank {
  color: var(--accent);
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.repo { display: flex; align-items: center; gap: 16px; min-width: 0; }
.repo img {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  flex: none;
  background: var(--line);
  object-fit: cover;
}
.repo .names { min-width: 0; }
.repo .title {
  display: block;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.repo a.title:hover { color: var(--accent); }
.repo .slug {
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.desc { min-width: 0; }
.desc p {
  margin: 0;
  color: #cbd5e1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--dim);
}
.meta .lang::before {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--lang, var(--dim));
}

.stars {
  text-align: right;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stars .s { color: var(--accent); margin-right: 6px; }
.stars.gain { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; }
.stars .up { color: var(--gain); }
.stars .total { font-size: 13px; font-weight: 500; color: var(--muted); }
.stars .total .s { margin-right: 4px; }

.save {
  justify-self: end;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all .15s;
}
.save:hover { border-color: var(--accent); color: var(--accent); }
.save[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: #fff; }

.empty { margin: 0; padding: 48px 24px; text-align: center; color: var(--muted); }

.skeleton .bar {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--line) 0%, var(--line-2) 50%, var(--line) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.foot {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-top: 20px;
  font-size: 13px;
  color: var(--dim);
}

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Tablet */
@media (max-width: 960px) {
  .row { grid-template-columns: 52px minmax(180px, 1fr) 1.4fr 100px 52px; padding: 16px 18px; }
  .rank { font-size: 20px; }
  .repo img { width: 44px; height: 44px; }
  .repo .title { font-size: 16px; }
}

/* Phone */
@media (max-width: 720px) {
  .page { padding: 20px 16px 36px; }
  .hero h1 { font-size: 22px; }
  .controls { width: 100%; gap: 10px; }
  .mode { flex: 1; }
  .mode button { flex: 1; padding: 8px 10px; }
  .period { flex: 1 1 100%; }
  .period button { flex: 1; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; font-size: 14px; padding: 7px 14px; }
  .search { min-width: 0; width: 100%; }
  .row.head { display: none; }
  .row {
    grid-template-columns: 34px minmax(0, 1fr) auto 40px;
    grid-template-areas:
      'rank repo stars save'
      '. desc desc desc';
    gap: 8px 10px;
    padding: 14px;
  }
  .rank { grid-area: rank; font-size: 17px; }
  .repo { grid-area: repo; gap: 10px; }
  .repo img { width: 36px; height: 36px; border-radius: 9px; }
  .repo .title { font-size: 15px; }
  .repo .slug { font-size: 11.5px; }
  .desc { grid-area: desc; font-size: 14px; }
  .stars { grid-area: stars; font-size: 14px; }
  .stars .s { margin-right: 3px; }
  .stars .total { font-size: 12px; }
  .save { grid-area: save; width: 36px; height: 36px; font-size: 18px; }
}
