:root {
  --bg: #f7f5ef;
  --ink: #1a1a1a;
  --muted: #6b6358;
  --rule: #d9d3c3;
  --accent: #c0492b;
  --accent-soft: rgba(192, 73, 43, 0.12);
  --paper: #fffcf3;
  --serif: "Iowan Old Style", "Charter", "Georgia", "Cambria", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Arial, sans-serif;
  --t: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 64px 32px 80px;
}

.masthead {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 36px;
  margin-bottom: 48px;
}

.eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  margin-bottom: 18px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.eyebrow .updated {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--muted);
  opacity: 0.7;
}
.eyebrow .updated::before {
  content: "·";
  margin-right: 12px;
  opacity: 0.5;
}

h1 {
  font-family: var(--serif);
  font-size: 52px;
  line-height: 1.06;
  font-weight: 500;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
}

h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

h2 .dyn {
  font-size: 14px;
  font-family: var(--sans);
  color: var(--accent);
  font-style: normal;
  margin-left: 8px;
  font-weight: 400;
  letter-spacing: 0;
  vertical-align: middle;
}

.subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: var(--muted);
  margin: 0;
  max-width: 580px;
}

.lede {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 22px;
}

.numbers {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin-bottom: 64px;
}

.num {
  padding: 28px 12px;
  text-align: left;
  border-right: 1px solid var(--rule);
}
.num:last-child { border-right: none; }

.big {
  font-family: var(--serif);
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-top: 8px;
}

.block {
  margin-bottom: 64px;
}

.block.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 56px;
}

.insights {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 28px 36px;
  margin-top: 18px;
}

/* Collapsible section */
.collapsible-toggle {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: color .2s;
  outline: none;
}
.collapsible-toggle:hover { color: var(--accent); }
.collapsible-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 2px;
}
.collapsible-toggle .chevron {
  font-size: 18px;
  color: var(--muted);
  transition: transform .25s var(--t);
  display: inline-block;
}
.collapsible.collapsed .chevron { transform: rotate(-90deg); }

.collapsible-body {
  overflow: hidden;
  transition: max-height .35s var(--t), opacity .25s var(--t), margin-top .25s var(--t);
  max-height: 4000px;
  opacity: 1;
}
.collapsible.collapsed .collapsible-body {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

.insight {
  border-left: 2px solid var(--accent);
  padding: 4px 0 4px 18px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .6s var(--t), transform .6s var(--t);
}
.insight.in { opacity: 1; transform: none; }

.insight h3 {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 500;
  margin: 0 0 6px;
  letter-spacing: -0.005em;
}

.insight p {
  font-size: 15px;
  line-height: 1.55;
  margin: 0;
}

/* Filter bar */
.filterbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(247, 245, 239, 0.92);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin: 0 -32px 48px;
  padding: 14px 32px;
}

.fb-inner {
  max-width: 920px;
  margin: 0 auto;
  display: grid;
  gap: 8px;
}

.fb-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 16px;
  align-items: center;
}

.fb-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 12px;
  background: rgba(0,0,0,0.04);
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid transparent;
  color: var(--ink);
  transition: background .2s, color .2s, border-color .2s, transform .15s;
  font-family: var(--sans);
  user-select: none;
}
.chip:hover {
  background: rgba(0,0,0,0.08);
  transform: translateY(-1px);
}
.chip.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.chip.clear {
  background: transparent;
  color: var(--muted);
  border-color: var(--rule);
}
.chip.clear:hover { color: var(--accent); border-color: var(--accent); }

.chip.mode-chip.active {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}

.fb-status {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  font-family: var(--serif);
  min-height: 18px;
}

/* Thumbnail */
.thumb {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background-color: rgba(0,0,0,0.06);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  vertical-align: middle;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.thumb.round { border-radius: 50%; }
.thumb.sm { width: 22px; height: 22px; }
.thumb.lg { width: 56px; height: 56px; border-radius: 6px; }
.thumb.placeholder {
  background: linear-gradient(135deg, var(--rule), rgba(0,0,0,0.06));
}

/* Bar chart rows */
.bar-row {
  display: grid;
  grid-template-columns: 38px 1fr 60px;
  align-items: center;
  gap: 14px;
  padding: 7px 0;
  font-size: 14px;
  border-bottom: 1px dotted var(--rule);
  cursor: default;
  transition: background .2s;
}
.bar-row.no-thumb {
  grid-template-columns: 200px 1fr 60px;
}
.bar-row .bar-mid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-width: 0;
}
.bar-row:last-child { border-bottom: none; }
.bar-row.clickable { cursor: pointer; }
.bar-row.clickable:hover { background: var(--accent-soft); }

.bar-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}

.bar-track {
  background: rgba(0,0,0,0.04);
  height: 10px;
  position: relative;
  border-radius: 1px;
  overflow: hidden;
}

.bar-fill {
  background: var(--ink);
  height: 100%;
  border-radius: 1px;
  width: 0%;
  transition: width .8s var(--t);
}

.bar-row.alt .bar-fill { background: var(--accent); }

.bar-value {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}

.tracklist {
  list-style: none;
  counter-reset: t;
  padding: 0;
  margin: 0;
}

.tracklist li {
  counter-increment: t;
  padding: 10px 0;
  border-bottom: 1px dotted var(--rule);
  display: grid;
  grid-template-columns: 24px 38px 1fr auto;
  gap: 12px;
  align-items: center;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .4s var(--t), transform .4s var(--t);
}
.tracklist li.no-thumb {
  grid-template-columns: 24px 1fr auto;
}
.tracklist li.in { opacity: 1; transform: none; }
.tracklist.tight li { padding: 8px 0; }

.tracklist li::before {
  content: counter(t, decimal-leading-zero);
  font-family: var(--serif);
  font-size: 13px;
  color: var(--muted);
}

.tk-name {
  font-size: 14px;
  line-height: 1.4;
}

.tk-artist {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.tk-plays {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
}

/* Line chart */
.linechart svg {
  width: 100%;
  height: 220px;
  display: block;
}
.linechart .axis text {
  font-size: 10px;
  fill: var(--muted);
  font-family: var(--sans);
}
.linechart .grid line {
  stroke: var(--rule);
  stroke-dasharray: 2 3;
}
.linechart path.line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-dasharray: 4000;
  stroke-dashoffset: 4000;
  transition: stroke-dashoffset 1.4s var(--t);
}
.linechart.in path.line {
  stroke-dashoffset: 0;
}
.linechart path.area {
  fill: var(--accent-soft);
  stroke: none;
  opacity: 0;
  transition: opacity 1s var(--t) .6s;
}
.linechart.in path.area { opacity: 1; }

.linechart circle.peak {
  opacity: 0;
  transition: opacity .4s var(--t) 1.2s;
}
.linechart.in circle.peak { opacity: 1; }

.dotgrid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}

.dotcell {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: default;
}

.dotcell .dot {
  width: 100%;
  background: var(--ink);
  border-radius: 1px;
  margin-bottom: 8px;
  height: 4px;
  transition: height .8s var(--t);
}

.dotcell .num-small {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  margin-top: 4px;
  color: var(--muted);
}

.hourbars {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 3px;
  align-items: end;
  height: 120px;
  margin-top: 8px;
}

.hourbar {
  background: var(--ink);
  width: 100%;
  border-radius: 1px;
  min-height: 1px;
  height: 1%;
  transition: height .8s var(--t), background .2s;
  cursor: default;
}
.hourbar:hover { background: var(--accent); }

.hourlabels {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 3px;
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#evolution {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 6px 18px;
  align-items: baseline;
  font-size: 14px;
}

.evo-year {
  font-family: var(--serif);
  font-size: 16px;
  color: var(--ink);
  padding-top: 8px;
}

.evo-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--rule);
}

.evo-pill {
  font-size: 12px;
  background: rgba(0,0,0,0.04);
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.evo-pill:hover { background: var(--accent-soft); color: var(--accent); }
.evo-pill.first {
  background: var(--ink);
  color: var(--paper);
}
.evo-pill.first:hover { background: var(--accent); color: var(--paper); }

/* Heatmap */
.heatmap {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 6px;
  font-family: var(--sans);
}

.heatmap .dow-labels {
  display: grid;
  grid-auto-rows: 14px;
  gap: 2px;
  font-size: 10px;
  color: var(--muted);
  align-content: start;
  padding-top: 16px;
}

.heatmap .grid-area {
  overflow-x: auto;
  padding-bottom: 4px;
}

.heatmap .grid-inner {
  display: grid;
  grid-template-rows: 12px repeat(7, 14px);
  grid-auto-flow: column;
  grid-auto-columns: 14px;
  gap: 2px;
}

.heatmap .month-label {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.heatmap .cell {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  background: rgba(0,0,0,0.04);
  cursor: default;
  transition: transform .15s;
}
.heatmap .cell.empty { visibility: hidden; }
.heatmap .cell:hover { transform: scale(1.4); outline: 1px solid var(--ink); }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--sans);
}
.heatmap-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}

/* Genre grid */
.genre-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 24px;
}

.gtile {
  border-top: 2px solid var(--accent);
  padding: 14px 0 4px;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: center;
}
.gtile-text { min-width: 0; }

.gtile-genre {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin-bottom: 8px;
}

.gtile-name {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.2;
  margin-bottom: 4px;
}

.gtile-meta {
  font-size: 13px;
  color: var(--muted);
}

/* Concentration meter */
.meter { margin-top: 8px; }

.meter-track {
  background: rgba(0,0,0,0.04);
  height: 14px;
  border-radius: 1px;
  position: relative;
  overflow: hidden;
}

.meter-fill {
  background: linear-gradient(90deg, var(--ink), var(--accent));
  height: 100%;
  width: 0%;
  transition: width 1s var(--t);
  border-radius: 1px;
}

.meter-readout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 16px;
  font-size: 14px;
}

/* Tooltip */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 3px;
  opacity: 0;
  transform: translate(-50%, -120%);
  transition: opacity .12s;
  z-index: 100;
  white-space: nowrap;
  font-family: var(--sans);
}
.tooltip.show { opacity: 1; }

footer {
  border-top: 1px solid var(--rule);
  padding-top: 28px;
  margin-top: 24px;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  font-family: var(--serif);
}

@media (max-width: 720px) {
  main { padding: 40px 20px 60px; }
  h1 { font-size: 36px; }
  .numbers { grid-template-columns: repeat(3, 1fr); }
  .num { border-bottom: 1px solid var(--rule); }
  .num:nth-child(3) { border-right: none; }
  .num:nth-child(n+4) { border-bottom: none; }
  .insights, .block.split, .genre-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 130px 1fr 50px; }
  .meter-readout { grid-template-columns: 1fr; gap: 8px; }
  .filterbar { margin-left: -20px; margin-right: -20px; padding: 12px 20px; }
}

/* Auth gate */
body.locked { overflow: hidden; }
body.locked main { visibility: hidden; }

#auth-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity .35s var(--t);
}
#auth-gate.hidden {
  opacity: 0;
  pointer-events: none;
}

.auth-card {
  width: min(360px, 92vw);
  display: grid;
  gap: 14px;
  padding: 36px 32px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
  transform: translateY(0);
}

.auth-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-align: center;
}

.auth-title {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
  margin: 0 0 4px;
  text-align: center;
  letter-spacing: -0.01em;
}

#auth-input {
  font-family: var(--sans);
  font-size: 16px;
  padding: 10px 14px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-submit {
  font-family: var(--sans);
  font-size: 14px;
  padding: 10px 14px;
  border: none;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background .15s;
}
.auth-submit:hover { background: var(--accent); }

.auth-error {
  font-size: 13px;
  font-style: italic;
  color: var(--accent);
  font-family: var(--serif);
  text-align: center;
  min-height: 18px;
}

@keyframes auth-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.auth-card.shake { animation: auth-shake .35s ease-out; }

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