/* The Spotify listening dashboard (spotify.html). Builds on the tokens in style.css. */

:root {
  /* Categorical slots, fixed order (validated on --surface: adjacent CVD ΔE ≥ 9.1). */
  --s1: #2456d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --s-other: #c9c2b6;          /* everyone outside the colored top 8 */

  /* Sequential blue, light -> dark (magnitude). */
  --q0: #efe9df;               /* zero / no listening */
  --q1: #cde2fb; --q2: #9ec5f4; --q3: #5598e7; --q4: #2456d6; --q5: #184f95; --q6: #0d366b;

  --grid: #ebe6dd;
  --axis: #cfc8bc;
  --axis-ink: #8a8578;
}

.dash-page { padding-block: clamp(2rem, 6vw, 4rem) clamp(2rem, 5vw, 3.5rem); }

.dash-intro h1 {
  font: 600 clamp(2.25rem, 6vw, 3.5rem)/1.05 var(--serif);
  letter-spacing: -0.02em;
}
.dash-intro .bio { max-width: 42rem; margin-top: 1rem; }

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

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

/* ---------- Dashboard controls (section tabs + time period) ---------- */
/* One card, a label column on the left, and the same pill style in both rows, so the
   first button of each row starts at the same point. */
.controls {
  margin-top: 1.75rem;
  border-block: 1px solid var(--line);
}
.control-row {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem 1rem;
  padding-block: 0.65rem;
}
.control-row + .control-row { border-top: 1px solid var(--line); }
.control-label {
  font: 600 0.72rem/1.4 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.tabs, .presets { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tabs button, .presets button {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.tabs button { font: 500 0.925rem/1 var(--sans); }
.presets button { font: 500 0.85rem/1 var(--sans); font-variant-numeric: tabular-nums; padding-block: 0.42rem; }
.tabs button:hover, .presets button:hover { color: var(--ink); border-color: var(--axis); }
.tabs button[aria-selected="true"], .presets button[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
}
@media (max-width: 640px) {
  .control-row { grid-template-columns: 1fr; }
}

.panel { padding-top: 1.5rem; outline: none; }
.panel.loading { opacity: 0.55; transition: opacity 0.2s; }
.panel-error { color: #a3341f; }

/* ---------- Layout ---------- */
.stack { display: grid; gap: 1rem; }
.row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); }
.row-3 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }

.dcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem 1.35rem;
  min-width: 0;
}
.dcard-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.25rem 1rem; }
.dcard h2 { font: 600 1.2rem/1.3 var(--serif); color: var(--ink); }
.dcard .sub { color: var(--muted); font-size: 0.9rem; margin-top: 0.3rem; max-width: 46rem; }
.dcard-body { margin-top: 1rem; }

.chart { position: relative; overflow-x: auto; overflow-y: hidden; }
.chart svg { display: block; }
.chart svg text { font-family: var(--sans); font-size: 11px; fill: var(--axis-ink); }
.chart .tick line { stroke: var(--grid); }
.chart .domain { stroke: var(--axis); }

/* ---------- Stat tiles ---------- */
.tiles { display: grid; gap: 1.25rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10.5rem), 1fr)); }
/* A tab's stats share one card, ruled into cells: the 1px gaps show the card's line color.
   The grid is fixed (4 columns, 2 on phones) and the headline stat takes two cells only
   when that fills every row, so no row ends early and leaves a stray line. */
.stack > .tiles {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.stack > .tiles .tile { background: var(--surface); padding: 1.1rem 1.35rem; }
.stack > .tiles .tile-hero { grid-column: auto; }
.stack > .tiles .tile-hero .tile-value { font-size: clamp(2rem, 3.6vw, 2.5rem); white-space: nowrap; }
.stack > .tiles .tile-hero:nth-last-child(4n + 3) { grid-column: span 2; } /* 3, 7, 11… stats */
.stack > .tiles .tile-hero:nth-last-child(4n + 3) .tile-value { font-size: clamp(2.5rem, 6vw, 3.25rem); }
.tile-label { color: var(--muted); font-size: 0.85rem; }
.tile-value { font: 600 1.65rem/1.15 var(--sans); color: var(--ink); margin-top: 0.3rem; letter-spacing: -0.01em; }
.tile-note { color: var(--muted); font-size: 0.8rem; margin-top: 0.25rem; }
.tile.tile-hero { grid-column: span 2; }
.tile.tile-hero .tile-value { font-size: clamp(2.5rem, 6vw, 3.25rem); }
@media (max-width: 480px) { .tile.tile-hero { grid-column: auto; } }
@media (max-width: 720px) {
  .stack > .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stack > .tiles .tile { padding: 1rem; }
  /* The headline gets its own row; a last stat that would sit alone fills its row. */
  .stack > .tiles .tile-hero, .stack > .tiles .tile-hero:nth-last-child(4n + 3) { grid-column: 1 / -1; }
  .stack > .tiles .tile-hero .tile-value { font-size: 2.5rem; }
  .stack > .tiles .tile:last-child:nth-child(even) { grid-column: 1 / -1; }
}

/* ---------- Ranked lists ---------- */
.rank { display: grid; gap: 0.55rem; counter-reset: rank; }
.rank li {
  display: grid;
  grid-template-columns: 1.4rem 2.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
}
.rank li.no-art { grid-template-columns: 1.4rem minmax(0, 1fr) auto; }
.rank-n { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; text-align: right; }
.art {
  width: 2.5rem; height: 2.5rem; border-radius: 6px; object-fit: cover;
  background: var(--q0);
}
.art-link { display: block; border-radius: 6px; }
.rank-text { min-width: 0; }
.rank-title, .rank-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-title { color: var(--ink); font-size: 0.95rem; font-weight: 500; }
.rank-title a { color: inherit; text-decoration: none; }
.rank-title a:hover { color: var(--accent); text-decoration: underline; }
.rank-sub { color: var(--muted); font-size: 0.82rem; }
.rank-bar { height: 4px; margin-top: 0.3rem; border-radius: 2px; background: var(--s1); }
.rank-val { color: var(--ink); font-size: 0.875rem; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.rank-val small { display: block; color: var(--muted); font-weight: 400; font-size: 0.75rem; }

/* ---------- Legends ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; margin-bottom: 0.75rem; font-size: 0.85rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { width: 0.7rem; height: 0.7rem; border-radius: 3px; flex: none; }
.swatch.line { height: 2px; width: 0.9rem; border-radius: 1px; }
.scale-legend { display: flex; align-items: center; gap: 0.3rem; font-size: 0.78rem; color: var(--muted); margin-top: 0.75rem; flex-wrap: wrap; }
.scale-legend .swatch { width: 0.85rem; height: 0.85rem; }
.scale-legend span + .swatch { margin-left: 0.35rem; }

/* ---------- Tooltip ---------- */
.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  max-width: 18rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.6rem 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}
.tip-title { color: var(--ink); font-weight: 600; margin-bottom: 0.2rem; }
.tip-row { display: flex; align-items: center; gap: 0.45rem; }
.tip-row strong { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.tip-row .swatch.line { width: 0.75rem; }

/* ---------- Mini sparkline rows (always in rotation) ---------- */
.spark-list { display: grid; gap: 0.5rem; }
.spark-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto 4.2rem; align-items: center; gap: 0.75rem; }
.spark-list .rank-title { font-size: 0.9rem; }
.spark-list .rank-val { font-size: 0.82rem; }
.spark-list.multi { grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); gap: 0.5rem 2.5rem; }

/* ---------- Yearly leaderboard ---------- */
.board { display: grid; gap: 0.3rem 0.35rem; min-width: 46rem; align-items: stretch; }
.board-year { color: var(--ink); font-size: 0.85rem; font-weight: 600; padding: 0 0.45rem 0.25rem; }
.board .rank-n { align-self: center; }
.board-cell {
  display: flex; align-items: center; gap: 0.45rem; min-width: 0;
  padding: 0.35rem 0.45rem; border-radius: 8px; min-height: 2.75rem;
  background: var(--bg); font-size: 0.8rem; line-height: 1.25; color: var(--ink);
  outline: none; transition: opacity 0.15s, background-color 0.15s;
}
.board-name { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
.board-cell.filled { font-weight: 600; }
.board.dim .board-cell:not(.hot) { opacity: 0.3; }
.board-cell.hot:not(.filled) { background: var(--accent-soft); }
.board-cell.hot { box-shadow: 0 0 0 2px var(--ink); }
.board-cell:focus-visible { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Timeline rows (lifespans & comebacks) ---------- */
.tl { min-width: 46rem; }
.tl-axis, .tl-row { display: grid; grid-template-columns: 15rem minmax(0, 1fr); align-items: center; gap: 0.75rem; }
.tl-row { padding: 0.18rem 0; border-radius: 6px; }
.tl-row:hover, .tl-row:focus-visible { background: var(--bg); }
.tl-label { display: grid; grid-template-columns: 1.6rem minmax(0, 1fr); gap: 0.5rem; align-items: center; min-width: 0; }
.tl-label .art { width: 1.6rem; height: 1.6rem; border-radius: 4px; }
.tl-label .rank-title { font-size: 0.82rem; }
.tl-label .rank-sub { font-size: 0.74rem; }

/* ---------- Explore ---------- */
.search { position: relative; max-width: 28rem; }
.search input {
  width: 100%;
  font: 400 1rem/1.5 var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.6rem 1rem;
}
.search input:focus { outline: none; border-color: var(--accent); }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 0.3rem); z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 0.3rem; max-height: 18rem; overflow-y: auto;
}
.suggest button {
  display: flex; justify-content: space-between; gap: 1rem; width: 100%;
  font: 400 0.925rem/1.3 var(--sans); color: var(--ink); text-align: left;
  background: none; border: 0; border-radius: 8px; padding: 0.45rem 0.7rem; cursor: pointer;
}
.suggest button small { color: var(--muted); }
.suggest button:hover, .suggest button.active { background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.75rem; }
.chips button {
  font: 500 0.82rem/1.3 var(--sans); color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.35rem 0.8rem; cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.profile { display: grid; grid-template-columns: 8rem minmax(0, 1fr); gap: 1.25rem; align-items: center; }
.profile .art { width: 8rem; height: 8rem; border-radius: 10px; }
.art.round, .profile .art.round { border-radius: 50%; } /* artist photos, like Spotify */
.art-link:has(.round) { border-radius: 50%; }
.profile h2 { font: 600 clamp(1.5rem, 4vw, 2rem)/1.15 var(--serif); }
.profile .tiles { margin-top: 0.9rem; }
.profile .tile { border-top: 1px solid var(--line); padding-top: 0.6rem; } /* already inside a card */
.profile .tile-value { font-size: 1.2rem; }
@media (max-width: 560px) {
  .profile { grid-template-columns: 1fr; }
  .profile .art { width: 6rem; height: 6rem; }
}


/* ---------- Chart hover states ---------- */
.chart rect.cell:hover { stroke: var(--ink); stroke-width: 1.5; }
.chart rect.hit:hover { fill: rgb(27 29 34 / 0.04); }

/* "Show all" toggle under a shortened list */
.more-button {
  margin-top: 0.9rem;
  font: 500 0.85rem/1.3 var(--sans);
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
}
.more-button:hover { border-color: var(--accent); }

/* Layout rules like `display: grid` would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

/* Spotify attribution (required by Spotify's developer policy) */
.footer-credit { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
.footer-credit a { display: inline-flex; }
.footer-credit img { width: 80px; height: auto; display: block; }
