:root {
  --bg: #12141a;
  --surface: #1b1e27;
  --border: #2a2e3a;
  --text: #e6e8ee;
  --muted: #8b92a5;
  --accent: #6ee7b7;
  --error: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

.nav {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.nav-brand { font-weight: 700; color: var(--text); }
.nav-links a { margin-left: 1.25rem; color: var(--muted); }
.nav-links a:hover { color: var(--text); }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.nav-toggle-bar {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 720px) {
  .nav-toggle { display: flex; }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1.5rem 1rem;
    z-index: 10;
  }

  .nav-links.open { display: flex; }
  .nav-links a { margin-left: 0; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
  .nav-links a:last-child { border-bottom: none; }
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

h1 { margin-top: 0; }

.stat-cards {
  display: flex;
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.875rem; }

.listen-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

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

.listen-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.track-title { display: block; font-weight: 600; color: var(--text); }
.track-title:hover { color: var(--accent); }
.track-artist { display: block; font-size: 0.85rem; }
.muted { color: var(--muted); }
.count { color: var(--muted); font-size: 0.85rem; margin-left: 0.4rem; }

.filter-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-form input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.checkbox-label input { accent-color: var(--accent); }

button, .filter-form button {
  background: var(--accent);
  color: #0b0d12;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }

.login-card {
  max-width: 360px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
}

.login-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }
.login-form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.875rem; color: var(--muted); }
.login-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.7rem;
  border-radius: 6px;
}

.error { color: var(--error); }
.notice { color: var(--accent); }

.period-selector { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; }
.period-link {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
}
.period-link.active { background: var(--accent); color: #0b0d12; border-color: var(--accent); }

.stats-loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.stats-loading-indicator[hidden] { display: none; }
.stats-loading-indicator::before {
  content: "";
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: stats-spin 0.7s linear infinite;
}
@keyframes stats-spin { to { transform: rotate(360deg); } }

.top-lists.is-loading { opacity: 0.5; pointer-events: none; transition: opacity 0.15s; }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.top-lists {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.top-list ol { padding-left: 1.2rem; }
.top-list li { margin-bottom: 0.4rem; }

.trend-lists { grid-template-columns: 1fr 1fr; align-items: start; }
.trend-list { list-style: none; padding-left: 0; max-height: 70vh; overflow-y: auto; }
.trend-list li { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }
.trend-item-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem; min-width: 0; }
.trend-month { flex-basis: 100%; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.see-all { display: inline-block; margin-top: 0.5rem; font-size: 0.85rem; color: var(--accent); }

.stats-list-full { padding-left: 1.6rem; }
.stats-list-full li { margin-bottom: 0.5rem; }

.top-list-cover { padding-left: 1.6rem; }
.top-list-cover li { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }
.top-list-cover-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem; min-width: 0; }

.entity-header {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  margin-bottom: 2rem;
}

.cover-art {
  display: block;
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface);
}

/* The 120px default is sized for the mobile entity-header (track/album/
   artist banner) - on wider screens there's room to show it bigger without
   it dominating the layout. Scoped to .entity-header specifically so it
   doesn't affect the small listen-row thumbnails or the album grid, which
   already size themselves independently. */
@media (min-width: 641px) {
  .entity-header .cover-art {
    width: 180px;
    height: 180px;
  }
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.album-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--text);
}

.album-card .cover-art { width: 100%; height: auto; aspect-ratio: 1; }
.album-title { font-weight: 600; font-size: 0.9rem; }

#heatmap, #track-heatmap, #artist-heatmap {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
}

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--border);
}

@media (max-width: 720px) {
  .charts-grid, .top-lists { grid-template-columns: 1fr; }
}

.manage-section { margin-bottom: 2.5rem; }

[data-split-credits-form] { display: flex; flex-direction: column; gap: 0.6rem; max-width: 420px; }
[data-split-credits-form] label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
[data-split-credits-form] input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
}
[data-credit-rows] { display: flex; flex-direction: column; gap: 0.4rem; }
.credit-row { display: flex; gap: 0.4rem; align-items: center; }
.credit-row input { flex: 1; }
.credit-row button { padding: 0.3rem 0.6rem; }

.manage-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.search-results { list-style: none; padding: 0; margin: 0.75rem 0 0; }

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.4rem;
}

.result-row.selected { border-color: var(--accent); }

.result-row button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.result-row button:hover { color: var(--text); }

.merge-confirm {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
}

.merge-confirm button { margin-right: 0.5rem; margin-top: 0.5rem; }

[data-suggestions] { list-style: none; padding: 0; }

[data-suggestions] li {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem;
  margin-bottom: 0.5rem;
}

[data-suggestions] button {
  margin-right: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

.cover-art-wrap { position: relative; display: inline-block; }

.cover-art-frame { position: relative; display: block; background: var(--surface); border-radius: 8px; }

.cover-cell { width: 44px; }

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

.cover-art-sm .cover-art-frame { border-radius: 4px; }
.cover-art-sm .cover-art { width: 36px; height: 36px; border-radius: 4px; cursor: pointer; }

.cover-art-edit {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
  font-size: 0.7rem;
}

/* On the small (table-row) size, the edit controls would blow out the row
   width, so they're hidden by default and only pop open on tap/click of
   the thumbnail (see public/js/cover-edit.js), positioned absolutely so
   they don't affect table layout even while open. */
.cover-art-sm .cover-art-edit {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  flex-direction: column;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem;
  margin-top: 0.25rem;
  white-space: nowrap;
}

.cover-art-sm .cover-art-edit.open { display: flex; }

.cover-art-status {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(11, 13, 18, 0.55);
  border-radius: inherit;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  pointer-events: none;
}

.cover-art-wrap.uploading .cover-art-status,
.cover-art-wrap.upload-done .cover-art-status,
.cover-art-wrap.upload-failed .cover-art-status {
  display: flex;
}

.cover-art-wrap.upload-failed .cover-art-status { background: rgba(248, 113, 113, 0.6); }

.cover-art-wrap.uploading .cover-art-edit,
.cover-art-wrap.upload-done .cover-art-edit {
  pointer-events: none;
  opacity: 0.6;
}

.cover-art-status .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: cover-art-spin 0.7s linear infinite;
}

@keyframes cover-art-spin {
  to { transform: rotate(360deg); }
}

.cover-art-error {
  color: var(--error);
  font-size: 0.7rem;
  align-self: center;
}

.listened-at-short { display: none; }

/* Below this width, the listen table becomes a card list: thumbnail on the
   left (spanning both text rows), title top-right, artist below it, listen
   time pinned to the bottom-right corner of the row. The album column is
   dropped - there isn't room for it and it's one tap away via the artist
   page. The time is positioned out of grid flow (position: absolute)
   rather than given its own grid column - a dedicated column would reserve
   its full text width on EVERY row (grid column tracks are shared across
   all rows), squeezing the title/artist column even on rows where no time
   text needs that space, which is what made titles wrap early before. */
@media (max-width: 640px) {
  .listen-table, .listen-table tbody { display: block; width: 100%; }
  .listen-table thead { display: none; }

  .listen-table tr {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 0.75rem;
    row-gap: 0.15rem;
    padding: 0.65rem 3.75rem 0.65rem 0;
    border-bottom: 1px solid var(--border);
  }

  .listen-table td { display: contents; }

  .listen-table .cover-cell .cover-art-wrap {
    grid-column: 1;
    grid-row: 1 / 3;
    align-self: center;
  }

  /* Fixed, clipped box regardless of the image's load state, so a missing
     cover (placeholder or a broken fallback) can never grow taller than
     the thumbnail itself. */
  .cover-art-sm.cover-art-wrap { flex-shrink: 0; }
  .cover-art-sm .cover-art-frame {
    width: 56px;
    height: 56px;
    overflow: hidden;
    border-radius: 6px;
  }
  .cover-art-sm .cover-art {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
  }

  .listen-table .track-title { grid-column: 2; grid-row: 1; align-self: end; }
  .listen-table .track-artist { grid-column: 2; grid-row: 2; align-self: start; }

  .listen-table .album-cell,
  .listen-table .album-cell * { display: none; }

  .listen-table .listened-at { display: contents; }
  .listen-table .listened-at-full { display: none; }
  .listen-table .listened-at-short {
    display: block;
    position: absolute;
    right: 0;
    bottom: 0.65rem;
    font-size: 0.7rem;
    color: var(--muted);
    white-space: nowrap;
  }
}

.cover-art-edit label,
.cover-art-edit button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
  cursor: pointer;
}

.cover-art-edit label:hover,
.cover-art-edit button:hover { color: var(--text); }
