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

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--surface-0);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-body);
  line-height: 1.5;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  padding: 1.25rem 1.5rem 1rem;
  padding-left: max(1.5rem, 7.5rem);
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline-strong);
}

.page-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-1);
}

.page-lede {
  margin: 0;
  max-width: 42rem;
  color: var(--text-2);
  font-size: var(--text-caption);
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-pill);
  background: var(--cat-utility-soft);
  border: 1px solid var(--cat-utility-hairline);
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  font-weight: 500;
  color: var(--cat-utility);
  white-space: nowrap;
}

.live-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-green) 45%, transparent);
  animation: pulse-dot 2s ease-out infinite;
}

@keyframes pulse-dot {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-green) 45%, transparent);
  }
  70% {
    box-shadow: 0 0 0 8px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot {
    animation: none;
  }
}

.page-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  padding: 1rem 1.15rem 1.15rem;
}

.panel-head {
  margin-bottom: 0.75rem;
}

.panel-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.panel h2 {
  margin: 0 0 0.15rem;
  font-family: var(--font-display);
  font-size: var(--text-h3);
  font-weight: 600;
  color: var(--text-1);
}

.panel-note {
  margin: 0;
  color: var(--text-3);
  font-size: var(--text-micro);
}

.live-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.5rem;
}

.live-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
}

.live-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-caption);
}

.live-item-name a {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.live-item-name a:hover {
  color: var(--accent-primary-hover);
}

.live-item-count {
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  font-weight: 600;
  color: var(--text-1);
}

.live-empty {
  color: var(--text-3);
  padding: 0.35rem 0;
  grid-column: 1 / -1;
  font-size: var(--text-caption);
}

.chart-wrap {
  position: relative;
  height: min(280px, 42vw);
  min-height: 200px;
}

.chart-status {
  margin: 0.75rem 0 0;
  color: var(--text-3);
  font-size: var(--text-caption);
}

.chart-status.is-error {
  color: var(--danger);
}

.app-select-label select {
  appearance: none;
  background: var(--surface-1)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236e6e6e' d='M1 1l5 5 5-5'/%3E%3C/svg%3E")
    no-repeat right 0.7rem center;
  color: var(--text-1);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  padding: 0.4rem 2rem 0.4rem 0.7rem;
  font-family: var(--font-ui);
  font-size: var(--text-caption);
  min-width: 11rem;
  max-width: 100%;
  cursor: pointer;
}

.app-select-label select:focus {
  outline: 2px solid var(--focus-ring-inner);
  outline-offset: 2px;
}

.range-toggle {
  display: inline-flex;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.range-btn {
  appearance: none;
  border: 0;
  background: var(--surface-1);
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: var(--text-micro);
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

.range-btn + .range-btn {
  border-left: 1px solid var(--hairline-strong);
}

.range-btn:hover {
  background: var(--surface-2);
}

.range-btn.is-active {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
}

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

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-caption);
}

.rank-table th,
.rank-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--hairline);
}

.rank-table th {
  color: var(--text-3);
  font-weight: 500;
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rank-table td:first-child,
.rank-table th:first-child {
  width: 2.5rem;
  color: var(--text-3);
  font-family: var(--font-mono);
}

.rank-table td:nth-child(3),
.rank-table td:nth-child(4),
.rank-table td:nth-child(5),
.rank-table th:nth-child(3),
.rank-table th:nth-child(4),
.rank-table th:nth-child(5) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: var(--text-micro);
}

.rank-table td a {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.rank-table td a:hover {
  color: var(--accent-primary-hover);
}

.rank-table tbody tr:hover td {
  background: var(--surface-2);
}

.footnotes {
  margin: 0.25rem 0 0;
  color: var(--text-3);
  font-size: var(--text-micro);
}

.footnotes a {
  color: var(--accent-primary);
}

@media (max-width: 640px) {
  .page-header {
    padding-left: max(1rem, 6.5rem);
    padding-right: 1rem;
  }

  .page-main {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .chart-wrap {
    height: 220px;
  }
}
