/* 01. Design tokens */
:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --muted-2: #98a2b3;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --accent: #0f766e;
  --accent-strong: #0b5d56;
  --accent-soft: #e7f5f2;
  --warn: #a15c07;
  --warn-soft: #fff7e8;
  --gold: #a15c07;
  --silver: #71717a;
  --bronze: #8a5a16;
  --radius: 8px;
  --page-x: clamp(10px, 2vw, 28px);
  --page-max: 1520px;
  --controls-height: 62px;
}

/* 02. Base styles */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP",
    "Microsoft YaHei", sans-serif;
  line-height: 1.45;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

/* 03. Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  gap: 16px;
  padding: 10px var(--page-x);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  flex: 0 0 auto;
  max-width: min(42vw, 420px);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.3;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout {
  width: min(var(--page-max), calc(100% - (var(--page-x) * 2)));
  margin: 0 auto 40px;
}

/* 04. Sticky controls */
.controls {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-areas: "range view niche search snapshot";
  grid-template-columns: auto auto auto minmax(240px, 1fr) minmax(180px, 230px);
  gap: 10px;
  align-items: center;
  margin: 0 calc(var(--page-x) * -1) 10px;
  padding: 10px var(--page-x);
  border-bottom: 1px solid rgba(228, 231, 236, 0.9);
  background: rgba(245, 247, 250, 0.92);
  backdrop-filter: blur(14px);
}

.control-strip {
  display: contents;
}

.range-mode {
  grid-area: range;
}

.view-mode {
  grid-area: view;
}

.niche-toggle {
  grid-area: niche;
}

.search-field {
  grid-area: search;
  width: 100%;
}

.snapshot-field {
  grid-area: snapshot;
  width: 100%;
}

/* 05. Segmented controls */
.segmented {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  padding: 3px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #eef2f6;
  scrollbar-width: none;
}

.segmented::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  letter-spacing: 0;
  white-space: nowrap;
}

.tab:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.68);
}

.tab.active,
.tab[aria-pressed="true"] {
  border-color: rgba(15, 118, 110, 0.28);
  background: var(--accent);
  color: #ffffff;
}

/* 06. Inputs */
.field {
  min-width: 0;
}

select,
input {
  width: 100%;
  min-height: 40px;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
}

select {
  text-overflow: ellipsis;
}

input::placeholder {
  color: var(--muted-2);
}

.niche-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  min-width: max-content;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.niche-toggle:hover {
  color: var(--ink);
  background: var(--panel);
}

.niche-toggle input {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.niche-toggle:has(input:checked) {
  border-color: rgba(161, 92, 7, 0.28);
  background: var(--warn-soft);
  color: var(--warn);
}

.niche-summary,
.niche-badge {
  border-color: rgba(161, 92, 7, 0.28);
  background: var(--warn-soft);
  color: var(--warn);
}

.niche-toggle:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 07. Summary metrics */
.summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  overflow: visible;
}

.summary-title {
  flex: 0 0 auto;
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
}

.summary-chip,
.summary-note {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-weight: 650;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
}

.summary-range {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.history-chip {
  color: var(--warn);
  background: var(--warn-soft);
}

.summary-note {
  margin-left: auto;
  color: var(--ink);
}

/* 08. Shared content containers */
.content-shell {
  min-width: 0;
}

.content-shell[aria-busy="true"] {
  cursor: progress;
}

.rank-panel,
.song-index {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

/* 09. Ranking rows */
.rank-header,
.rank-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 64px;
  column-gap: 12px;
  align-items: center;
}

.rank-header {
  min-height: 32px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.rank-header span:last-child {
  text-align: right;
}

.rank-row {
  grid-template-areas:
    "rank content count"
    ". drawer drawer";
  min-height: 62px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  border-left: 2px solid transparent;
  background: var(--panel);
  content-visibility: auto;
  contain-intrinsic-size: auto 62px;
  transition:
    background-color 140ms ease,
    border-color 140ms ease;
}

.rank-row:last-child,
.index-row:last-child {
  border-bottom: 0;
}

.rank-row:hover,
.index-row:hover {
  background: #f8fafc;
}

.rank-row.is-expanded,
.index-row.is-expanded {
  content-visibility: visible;
  contain-intrinsic-size: auto;
}

.rank-top-1 {
  border-left-color: rgba(161, 92, 7, 0.7);
}

.rank-top-2 {
  border-left-color: rgba(113, 113, 122, 0.48);
}

.rank-top-3 {
  border-left-color: rgba(138, 90, 22, 0.48);
}

.rank-number {
  grid-area: rank;
  min-width: 0;
  color: var(--muted);
  font-size: 17px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
}

.rank-top-1 .rank-number {
  color: var(--gold);
}

.rank-top-2 .rank-number {
  color: var(--silver);
}

.rank-top-3 .rank-number {
  color: var(--bronze);
}

.rank-content {
  grid-area: content;
  display: grid;
  gap: 3px;
  min-width: 0;
}

.rank-title {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 15.5px;
  font-weight: 780;
  letter-spacing: 0;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.song-badge {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.2;
  vertical-align: 1px;
  white-space: nowrap;
}

.rank-subline {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 620;
  line-height: 1.3;
  white-space: nowrap;
}

.rank-subline span:not(.meta-separator):not(.source-preview-separator),
.source-preview-list,
.source-link-inline {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-separator {
  flex: 0 0 auto;
  color: var(--muted-2);
}

.artist-missing {
  flex: 0 0 auto;
  max-width: max-content;
  border-radius: 6px;
  padding: 1px 6px;
  background: var(--warn-soft);
  color: var(--warn);
}

.source-link-inline {
  display: inline-block;
  flex: 0 1 auto;
  max-width: min(260px, 34vw);
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.source-preview-list {
  display: inline-flex;
  flex: 0 1 auto;
  align-items: center;
  gap: 4px;
  max-width: min(430px, 42vw);
}

.source-preview-list .source-link-inline {
  flex: 0 1 auto;
  max-width: 100%;
}

.source-preview-separator {
  flex: 0 0 auto;
  color: var(--muted-2);
  font-weight: 650;
}

.source-link-inline:hover,
.source-link:hover,
.video-title:hover,
.song-list a:hover {
  color: var(--accent-strong);
}

.rank-count {
  grid-area: count;
  justify-self: end;
  min-width: 52px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #f2f4f7;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.rank-count.is-strong {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.rank-expand {
  flex: 0 0 auto;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 7px;
  background: #ffffff;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.35;
  white-space: nowrap;
}

.rank-expand:hover,
.is-expanded .rank-expand {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* 10. Pagination */
.pagination-row {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 2px;
}

.pagination-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.pagination-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  justify-content: flex-end;
}

.pagination-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
}

.pagination-status,
.pagination-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.pagination-ellipsis {
  min-width: 20px;
  color: var(--muted);
}

.pagination-button:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.pagination-button.is-current {
  border-color: rgba(15, 118, 110, 0.28);
  background: var(--accent);
  color: #ffffff;
}

.pagination-button:disabled {
  cursor: default;
  opacity: 0.52;
}

/* 11. Source drawer */
.source-drawer {
  grid-area: drawer;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 6px 12px;
  width: 100%;
  margin-top: 8px;
  padding: 9px 0 0;
  border-top: 1px dashed var(--line);
}

.source-drawer[hidden] {
  display: none;
}

.source-link {
  display: grid;
  grid-template-columns: 62px minmax(88px, 0.55fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
  border-radius: 6px;
  padding: 5px 6px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 650;
  text-decoration: none;
}

.source-link:hover {
  background: #f2f4f7;
}

.time {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  white-space: nowrap;
}

.source-name,
.source-video {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-video {
  color: var(--muted-2);
}

/* 12. Song index */
.song-index {
  display: block;
  background: transparent;
  border: 0;
}

.index-nav {
  position: sticky;
  top: calc(var(--controls-height) + 8px);
  z-index: 10;
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  padding: 8px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  scrollbar-width: none;
}

.index-nav::-webkit-scrollbar {
  display: none;
}

.index-nav a {
  flex: 0 0 auto;
  min-width: 34px;
  border-radius: 6px;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  text-align: center;
  text-decoration: none;
}

.index-nav a:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.index-section {
  overflow: hidden;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  content-visibility: auto;
  contain-intrinsic-size: auto 360px;
  scroll-margin-top: calc(var(--controls-height) + 56px);
}

.index-heading {
  margin: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0;
}

.index-list {
  display: grid;
}

.index-row {
  display: grid;
  grid-template-areas:
    "content count"
    "drawer drawer";
  grid-template-columns: minmax(0, 1fr) 64px;
  min-height: 58px;
  align-items: center;
  column-gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  content-visibility: auto;
  contain-intrinsic-size: auto 58px;
  transition: background-color 140ms ease;
}

/* 13. Video grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: start;
  gap: 12px;
}

.video-card {
  display: grid;
  align-self: start;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  content-visibility: auto;
  contain-intrinsic-size: auto 230px;
  transition:
    border-color 140ms ease,
    background-color 140ms ease;
}

.video-card:hover {
  border-color: var(--line-strong);
  background: #fcfcfd;
}

.thumb-link {
  display: block;
  overflow: hidden;
  background: #111827;
  aspect-ratio: 16 / 9;
}

.thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-body {
  display: grid;
  gap: 9px;
  min-width: 0;
  padding: 10px;
}

.video-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  min-width: 0;
}

.video-title-wrap {
  min-width: 0;
}

.video-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  text-decoration: none;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.video-meta {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-count {
  border-radius: 999px;
  padding: 3px 7px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.song-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 19px;
}

.song-list li {
  min-width: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}

.song-list a {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-weight: 650;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-artist {
  color: var(--muted);
}

.video-more {
  justify-self: start;
  border: 0;
  border-radius: 6px;
  padding: 3px 0;
  background: transparent;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 850;
}

/* 14. Empty states and toast */
.empty-state {
  display: block;
}

.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 34px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  text-align: center;
}

.empty p {
  margin: 0;
  font-weight: 700;
}

.clear-search {
  min-height: 34px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--accent);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

.back-to-top {
  position: fixed;
  right: 18px;
  bottom: 76px;
  z-index: 45;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(17, 24, 39, 0.16);
  font-size: 20px;
  font-weight: 850;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 140ms ease,
    transform 140ms ease,
    background-color 140ms ease;
}

.back-to-top:hover {
  background: var(--accent-strong);
}

.back-to-top.is-visible,
.back-to-top[data-visible="true"],
.back-to-top[aria-hidden="false"] {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top[hidden] {
  display: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.toast[hidden] {
  display: none;
}

/* 15. Responsive breakpoints */
@media (max-width: 1280px) {
  .controls {
    grid-template-columns: auto minmax(0, 1fr) auto minmax(220px, 1.1fr) minmax(180px, 220px);
  }

  .video-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .controls {
    grid-template-areas:
      "range view niche snapshot"
      "search search search search";
    grid-template-columns: auto minmax(0, 1fr) auto minmax(170px, 220px);
  }

  .rank-header {
    display: none;
  }

  .rank-row {
    grid-template-columns: 42px minmax(0, 1fr) 56px;
  }

  .source-drawer {
    grid-template-columns: 1fr;
  }

  .video-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 920px) {
  .rank-header {
    display: grid;
  }

  .rank-row {
    grid-template-columns: 48px minmax(0, 1fr) 64px;
  }
}

@media (max-width: 620px) {
  :root {
    --page-x: 8px;
  }

  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .layout {
    margin-bottom: 84px;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 58px;
    align-items: start;
    gap: 4px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .brand {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  h1 {
    overflow: hidden;
    font-size: 18px;
    text-overflow: ellipsis;
  }

  .brand p {
    display: none;
  }

  .status {
    justify-self: start;
    min-width: 0;
    max-width: 100%;
    font-size: 10.5px;
    line-height: 1.25;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .controls {
    grid-template-areas:
      "search"
      "strip";
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    overflow: hidden;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .control-strip {
    grid-area: strip;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .control-strip::-webkit-scrollbar {
    display: none;
  }

  .range-mode,
  .view-mode,
  .niche-toggle {
    flex: 0 0 auto;
  }

  .snapshot-field {
    flex: 0 0 172px;
    width: 172px;
  }

  select,
  input {
    min-height: 36px;
    font-size: 13px;
  }

  .tab {
    min-height: 32px;
    padding: 0 10px;
    font-size: 13px;
  }

  .niche-toggle {
    min-height: 32px;
    padding: 0 9px;
    font-size: 12.5px;
  }

  .summary {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    grid-template-rows: minmax(26px, auto);
    align-items: center;
    min-height: 34px;
    max-height: 42px;
    margin-bottom: 8px;
    gap: 5px 6px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    padding-bottom: 2px;
    font-size: 12.5px;
    scrollbar-width: none;
  }

  .summary::-webkit-scrollbar {
    display: none;
  }

  .summary:has(.history-chip),
  .summary:has(.summary-note) {
    grid-template-rows: repeat(2, minmax(26px, auto));
    max-height: 60px;
    align-items: start;
  }

  .summary-title {
    max-width: min(52vw, 180px);
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .summary-chip,
  .summary-note {
    width: max-content;
    max-width: min(78vw, 260px);
    justify-content: flex-start;
    min-height: 26px;
    padding: 2px 6px;
    font-size: 12px;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .history-chip,
  .summary-note {
    grid-row: 2;
    margin-left: 0;
  }

  .rank-row {
    grid-template-areas:
      "rank content count"
      ". drawer drawer";
    grid-template-columns: 34px minmax(0, 1fr) 42px;
    min-height: 56px;
    column-gap: 6px;
    padding: 7px 8px;
    contain-intrinsic-size: auto 56px;
  }

  .rank-number {
    font-size: 14px;
  }

  .rank-title {
    font-size: 13.5px;
    -webkit-line-clamp: 2;
  }

  .song-badge {
    min-height: 16px;
    padding: 0 5px;
    font-size: 10.5px;
  }

  .rank-subline {
    gap: 5px;
    font-size: 11.5px;
  }

  .subline-primary,
  .artist-missing {
    max-width: 82px;
  }

  .source-link-inline {
    flex: 1 1 auto;
    max-width: none;
  }

  .source-preview-list {
    flex: 1 1 auto;
    max-width: none;
    min-width: 0;
    gap: 3px;
  }

  .source-preview-list .source-link-inline {
    flex: 1 1 auto;
    max-width: none;
    min-width: 0;
  }

  .subline-video-count {
    display: none;
  }

  .rank-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    min-width: 0;
    max-width: 42px;
    padding: 3px 4px;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.2;
    text-overflow: clip;
  }

  .rank-expand {
    flex: 0 0 auto;
    max-width: none;
    overflow: visible;
    padding: 1px 5px;
    font-size: 11.5px;
    text-overflow: clip;
  }

  .back-to-top {
    right: 10px;
    bottom: 72px;
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .source-link {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .source-video {
    grid-column: 2;
  }

  .index-row {
    grid-template-columns: minmax(0, 1fr);
    min-height: 54px;
    column-gap: 8px;
    padding: 7px 8px;
    contain-intrinsic-size: auto 54px;
  }

  .pagination-row {
    justify-content: flex-start;
    padding-top: 12px;
  }

  .pagination-note,
  .pagination-controls {
    flex: 1 1 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 480px) {
  .layout {
    margin-bottom: 84px;
  }

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

/* 16. Accessibility and reduced motion */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.34);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
