:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #111827;
  --accent-soft: #e5e7eb;
  --radius-xl: 24px;
  --radius-md: 14px;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(209, 213, 219, 0.72), transparent 30%),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1;
  margin-bottom: 0;
  letter-spacing: -0.06em;
}

h2 {
  font-size: clamp(1.45rem, 2.4vw, 2.2rem);
  letter-spacing: -0.04em;
  margin-bottom: 10px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.lead {
  color: #374151;
  line-height: 1.8;
  max-width: 680px;
  margin-bottom: 0;
}

.nav-pills {
  display: flex;
  gap: 8px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.pill {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  cursor: pointer;
}

.pill.active {
  background: var(--accent);
  color: #fff;
}

.hero-card,
.section-block,
.about-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(229, 231, 235, 0.85);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.hero-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: center;
  padding: clamp(20px, 3.5vw, 34px);
  margin-bottom: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 104px);
  gap: 10px;
}

.stat {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.section-block {
  display: none;
  padding: clamp(14px, 2.2vw, 22px);
  margin-bottom: 16px;
}

.active-section {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 180px 160px;
  gap: 10px;
  margin-bottom: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 13px;
}

.search-box input,
.toolbar select {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  min-height: 44px;
}

.toolbar select {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 12px;
}

.library-table-wrap {
  overflow-x: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
}

.library-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
  background: #fff;
}

.library-table th {
  background: #e5e7eb;
  color: #111827;
  font-size: 0.82rem;
  text-align: left;
  padding: 12px;
  white-space: nowrap;
}

.library-table td {
  border-top: 1px solid var(--line);
  padding: 12px;
  vertical-align: middle;
  font-size: 0.92rem;
}

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

.library-table tbody tr:hover {
  background: #f9fafb;
}

.title-cell strong {
  display: block;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-cell small,
.artist-cell small {
  color: var(--muted);
  display: block;
  margin-top: 4px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bpm-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 7px 10px;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  min-width: 66px;
  justify-content: center;
  font-weight: 800;
}

.bpm-pill small {
  font-size: 0.68rem;
  opacity: 0.72;
  font-weight: 700;
}

.source-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.source-tag {
  display: inline-block;
  padding: 5px 8px;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  font-size: 0.76rem;
  max-width: 132px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
}

.log-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.loading,
.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px !important;
}

.section-heading p {
  color: var(--muted);
  line-height: 1.8;
}

.playlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.playlist-card {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}

.playlist-card h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.playlist-card p {
  color: var(--muted);
  margin-bottom: 12px;
}

.playlist-song-list {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 0.9rem;
}

.about-card {
  padding: clamp(18px, 3vw, 28px);
}

.about-card p,
.about-card li {
  color: #374151;
  line-height: 1.8;
}

.detail-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  width: min(420px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
  padding: 24px;
  transform: translateX(calc(100% + 36px));
  transition: transform 0.22s ease;
  z-index: 20;
}

.detail-panel.open {
  transform: translateX(0);
}

.close-button {
  position: absolute;
  right: 14px;
  top: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  cursor: pointer;
  font-size: 1.2rem;
}

.detail-title {
  padding-right: 36px;
}

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0;
}

.detail-meta div {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
}

.detail-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  margin-bottom: 4px;
}

.log-list {
  display: grid;
  gap: 8px;
}

.log-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: var(--surface-soft);
}

.log-item strong {
  display: inline-block;
  margin-right: 8px;
}

.log-item small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.ad-slot {
  border: 1px dashed #cbd5e1;
  border-radius: 20px;
  background: rgba(255,255,255,0.62);
  color: var(--muted);
  min-height: 72px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 4px;
  padding: 14px;
}

.ad-slot small {
  display: block;
}

code {
  background: #f3f4f6;
  padding: 2px 5px;
  border-radius: 6px;
}

@media (max-width: 820px) {
  .topbar,
  .hero-card {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .topbar {
    display: grid;
  }

  .nav-pills {
    overflow-x: auto;
    justify-content: flex-start;
  }

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

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

  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 14px;
  }
}
/* テーブル見出し固定 */
.table-wrap,
.table-wrapper,
.table-scroll,
.library-table-wrap {
  max-height: calc(100vh - 260px);
  overflow: auto;
  position: relative;
}

table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(18, 24, 38, 0.96);
  backdrop-filter: blur(10px);
}

/* クリック式ヘッダー */
.th-sort {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
}

.th-sort:hover {
  opacity: 0.8;
}

.sort-mark {
  font-size: 0.75em;
  opacity: 0.75;
}

/* アーティスト列は1行省略 */
.artist-cell {
  max-width: min(34vw, 360px);
}

.artist-line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bpm-search-control {
  min-width: min(100%, 360px);
}

.control-label {
  display: block;
  font-size: 0.78rem;
  opacity: 0.72;
  margin-bottom: 8px;
}

.bpm-target-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bpm-target-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.bpm-target-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.1);
}

.bpm-target-button.active {
  border-color: rgba(120, 180, 255, 0.7);
  background: rgba(120, 180, 255, 0.18);
}

.bpm-target-button strong {
  font-size: 0.86rem;
}

.bpm-target-button span {
  font-size: 0.78rem;
  opacity: 0.78;
}

.bpm-range-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.bpm-range-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  opacity: 0.9;
}

#bpmToleranceInput {
  width: 64px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  padding: 6px 8px;
}

.mini-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

.bpm-filter-status {
  margin: 8px 0 0;
  font-size: 0.78rem;
  opacity: 0.7;
}

@media (max-width: 640px) {
  .library-table {
    min-width: 560px;
    table-layout: fixed;
  }

  .library-table th,
  .library-table td {
    padding: 10px 8px;
    font-size: 0.84rem;
  }

  .library-table th:nth-child(1),
  .library-table td:nth-child(1) {
    width: 160px;
  }

  .library-table th:nth-child(2),
  .library-table td:nth-child(2) {
    width: 110px;
  }

  .library-table th:nth-child(3),
  .library-table td:nth-child(3) {
    width: 82px;
  }

  .library-table th:nth-child(4),
  .library-table td:nth-child(4) {
    width: 54px;
  }

  .library-table th:nth-child(5),
  .library-table td:nth-child(5) {
    width: 110px;
  }

  .library-table th:nth-child(6),
  .library-table td:nth-child(6) {
    width: 70px;
  }

  .title-cell strong,
  .title-cell small,
  .artist-line {
    max-width: 100%;
  }

  .bpm-pill {
    min-width: 58px;
    padding: 6px 8px;
  }
}