:root {
  --bg: #ffffff;
  --bg-subtle: #f6f8fa;
  --bg-hover: #f3f6fa;
  --bg-selected: #eef5ff;
  --border: #d0d7de;
  --border-light: #e6ebf0;
  --text: #1f2328;
  --text-muted: #59636e;
  --accent: #0969da;
  --bar-fill: #d7e6fa;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

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

a:hover {
  text-decoration: underline;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Header */
.site-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

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

.site-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.site-header h1 strong {
  font-weight: 600;
}

.title-sub {
  color: var(--text-muted);
}

.repo-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.repo-link:hover {
  color: var(--text);
  text-decoration: none;
}

.github-icon {
  flex-shrink: 0;
}

/* Controls */
.controls {
  padding: 12px 14px 10px;
  margin-bottom: 14px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.controls-primary {
  display: grid;
  grid-template-columns: minmax(190px, 1.35fr) minmax(150px, 0.95fr) minmax(185px, 1fr) minmax(185px, 1.15fr);
  gap: 10px 14px;
  align-items: end;
}

.controls-primary:has(#kind-control[hidden]) {
  grid-template-columns: minmax(200px, 1.4fr) minmax(185px, 1fr) minmax(200px, 1.3fr);
}

.controls-secondary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--border-light);
}

.controls-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.slice-count {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.control-group > label,
.control-label-row > label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.control-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.control-kind[hidden],
.inline-control[hidden] {
  display: none;
}

.inline-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.inline-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

select,
input[type="search"] {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
}

select:focus,
input[type="search"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.year-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.year-inputs select {
  flex: 1 1 0;
  min-width: 68px;
}

.year-sep {
  color: var(--text-muted);
  flex-shrink: 0;
}

.year-presets {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.link-btn {
  padding: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--accent);
  text-decoration: underline;
}

.link-btn.active {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

/* Buttons */
.btn {
  height: 28px;
  padding: 0 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 3px;
}

.seg-btn {
  position: relative;
  height: 26px;
  padding: 0 9px;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.seg-btn:first-child {
  border-radius: 2px 0 0 2px;
}

.seg-btn:last-child {
  border-right: none;
  border-radius: 0 2px 2px 0;
}

.seg-btn:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

.seg-btn.active {
  background: var(--bg-subtle);
  color: var(--text);
  font-weight: 600;
}

.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 0;
  bottom: calc(100% + 7px);
  width: 240px;
  padding: 6px 8px;
  background: #1f2328;
  color: #ffffff;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  z-index: 20;
}

.has-tooltip:hover::after,
.has-tooltip:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

/* Trend section */
.trend-section {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

.trend-empty {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.trend-examples {
  display: inline;
}

.example-pkg {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 0;
  margin: 0 2px;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
}

.example-pkg:hover {
  text-decoration: underline;
}

.trend-active {
  padding: 12px 14px 10px;
}

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

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-subtle);
  font-size: 12px;
}

.legend-swatch {
  width: 10px;
  height: 3px;
  border-radius: 1px;
  flex-shrink: 0;
}

.legend-name {
  font-family: var(--font-mono);
  color: var(--text);
}

.legend-ctan {
  font-size: 11px;
  color: var(--text-muted);
}

.legend-remove {
  padding: 0 2px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.legend-remove:hover {
  color: var(--text);
}

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

.chart-wrap {
  position: relative;
  width: 100%;
}

.trend-svg {
  display: block;
  width: 100%;
  height: 240px;
  user-select: none;
}

.chart-tooltip {
  position: absolute;
  top: 8px;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 6px 9px;
  font-size: 12px;
  line-height: 1.4;
  min-width: 170px;
  z-index: 10;
}

.tooltip-year {
  font-weight: 600;
  margin-bottom: 3px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--border-light);
}

.tooltip-elig {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 4px;
}

.tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}

.tooltip-pkg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
}

.tooltip-val {
  white-space: nowrap;
}

.trend-note {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Table section */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

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

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

.loading-indicator {
  font-size: 12px;
  color: var(--text-muted);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.rankings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.rankings-table th,
.rankings-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.rankings-table thead th {
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-align: left;
  white-space: nowrap;
}

.rankings-table thead th.num,
.rankings-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rankings-table tbody tr {
  cursor: pointer;
}

.rankings-table tbody tr:hover {
  background: var(--bg-hover);
}

.rankings-table tbody tr.is-plotted {
  background: var(--bg-selected);
}

.rankings-table tbody tr:last-child td {
  border-bottom: none;
}

.sort-btn {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.sort-btn:hover {
  color: var(--text);
}

.sort-arrow {
  font-size: 10px;
  color: var(--text);
}

.col-rank {
  width: 64px;
  color: var(--text-muted);
}

.col-pkg {
  min-width: 220px;
}

.pkg-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pkg-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.plot-dot-inline {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pkg-name {
  font-family: var(--font-mono);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.pkg-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  opacity: 0;
}

.rankings-table tbody tr:hover .pkg-actions,
.rankings-table tbody tr:focus-within .pkg-actions {
  opacity: 1;
}

.chart-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--accent);
  white-space: nowrap;
}

.chart-hint-remove {
  color: var(--text-muted);
}

.ctan-link {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.ctan-link:hover {
  color: var(--accent);
}

.col-papers {
  width: 110px;
}

.col-pct {
  width: 150px;
}

.pct-cell {
  position: relative;
}

.pct-bar-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
}

.pct-bar-track {
  width: 64px;
  height: 7px;
  background: var(--bg-subtle);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.pct-bar-fill {
  height: 100%;
  background: var(--accent);
  opacity: 0.55;
}

.pct-text {
  min-width: 52px;
  text-align: right;
}

.col-updated {
  width: 92px;
  color: var(--text-muted);
}

.empty-cell {
  padding: 20px 12px !important;
  text-align: center;
  color: var(--text-muted);
  cursor: default;
}

.table-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.showing-count {
  font-size: 12px;
  color: var(--text-muted);
}

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

/* Footer */
.site-footer {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-muted);
}

.site-footer p {
  margin: 0;
  line-height: 1.55;
}

@media (max-width: 840px) {
  .controls-primary,
  .controls-primary:has(#kind-control[hidden]) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .pct-bar-track {
    display: none;
  }

  .pkg-actions {
    opacity: 0.75;
  }

  .trend-svg {
    height: 200px;
  }
}

@media (max-width: 520px) {
  .controls-primary,
  .controls-primary:has(#kind-control[hidden]) {
    grid-template-columns: 1fr;
  }
}
