/* ============================================================
   CD Collection — construction-paper / retro-infographic styling
   ============================================================
   Layout: mobile-first, two covers across on a phone.
   The paper base + grain + hard offset shadows do the heavy lifting;
   each card's shadow gets tinted by JS with the cover's dominant color.
   ============================================================ */

:root {
  /* Warm paper base — reads as construction paper, not flat white */
  --paper:        #f5edd6;
  --paper-deep:   #ece0c2;
  --surface:      #fffaf0;                /* raised "card white" (cards, inputs, pills) */
  --ink:          #241c16;                /* near-black warm ink for type */
  --ink-soft:     #5b5142;

  /* Retro accent palette */
  --brick:   #c8452f;
  --mustard: #e0a51f;
  --teal:    #2f8f8a;
  --orange:  #d9711f;
  --forest:  #3e6b3a;

  /* Default card shadow tint (used until/if cover color is sampled) */
  --shadow-neutral: #3a3128;

  /* Type */
  --font-display: 'Anton', 'Arial Narrow', sans-serif;
  --font-body:    'Archivo', system-ui, -apple-system, sans-serif;
  --font-mono:    'Space Mono', 'Courier New', monospace;

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* Shared control height so the search box and shuffle button line up */
  --control-h: 3.25rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--paper);
  /* faint printed rule lines, like an almanac page */
  background-image:
    linear-gradient(0deg, rgba(58, 49, 40, 0.035) 1px, transparent 1px);
  background-size: 100% 2.2rem;
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color 0.6s var(--ease);
}

/* ---------- Paper grain overlay ---------- */
.grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  /* pervasive across the whole page, not just the placeholder covers */
  opacity: 0.19;
  mix-blend-mode: multiply;
}

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

/* ---------- Focus visibility (non-negotiable) ---------- */
:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* ============================================================
   Header + stats
   ============================================================ */
.site-header {
  padding: 1.5rem 1rem 0.5rem;
  max-width: 1200px;
  margin: 0 auto;
}
.header-inner {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.eyebrow {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.66rem;
  color: var(--ink-soft);
  margin: 0 0 0.35rem;
}
.site-title {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 12vw, 5rem);
  line-height: 0.9;
  letter-spacing: 0.01em;
  margin: 0;
  min-width: 0;   /* allow the title to wrap so the CD can stay to its right */
  color: var(--ink);
  text-transform: uppercase;
  /* layered cut-paper shadow: burnt orange stacked over brick */
  text-shadow: 3px 3px 0 var(--orange), 6px 6px 0 var(--brick);
}

/* Title + CSS-drawn CD sitting to its right */
.title-row {
  display: flex;
  align-items: center;
  gap: clamp(0.8rem, 2.5vw, 1.5rem);
  /* keep the CD beside the title; the title itself wraps when space is tight */
  flex-wrap: nowrap;
}

/* ---------- Flat icon-style compact disc ----------
   Bold, hard-edged concentric bands in the palette — matches the flat
   construction-paper language (no gradients, sheen, or spin). The whole shape
   is drawn with hard-stop radial bands and finished with the same hard offset
   shadow the cards use. */
.cd-logo {
  --cd-size: clamp(2.75rem, 9vw, 4.75rem);
  flex: 0 0 auto;
  width: var(--cd-size);
  height: var(--cd-size);
  border-radius: 50%;
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  background: radial-gradient(circle at 50% 50%,
    var(--paper)   0 14%,     /* spindle hole */
    var(--ink)     14% 20%,   /* hole rim */
    var(--paper)   20% 30%,   /* clear hub band */
    var(--ink)     30% 35%,   /* inner groove */
    var(--mustard) 35% 100%   /* flat disc face */
  );
}

/* Stats "data card" — looks like a printed index card, not a dashboard.
   Fills the full width of whatever space it's given. */
.stats-card {
  border: 2px solid var(--ink);
  background: var(--surface);
  padding: 0.75rem 0.9rem;
  box-shadow: 5px 5px 0 var(--ink);
  width: 100%;
}
.stats-total {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  border-bottom: 1.5px dashed var(--ink-soft);
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
}
.stats-figure {
  font-family: var(--font-display);
  font-size: 2.2rem;
  line-height: 1;
  color: var(--orange);
}
.stats-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.stats-genres {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.stats-genres li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}
.stats-genres .g-name { text-transform: uppercase; letter-spacing: 0.04em; }
.stats-genres .g-count { font-weight: 700; }
/* dotted leader between name and count, infographic style */
.stats-genres .g-dots {
  flex: 1;
  border-bottom: 2px dotted var(--paper-deep);
  transform: translateY(-0.15em);
}

@media (min-width: 720px) {
  .header-inner { flex-direction: row; align-items: flex-end; gap: 2rem; }
  .masthead { flex: 0 1 auto; }
  /* stats card grows to fill the room left beside the title */
  .stats-card { flex: 1 1 auto; }
}

/* ============================================================
   Controls: search + shuffle
   ============================================================ */
.site-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}
.controls {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  margin: 1rem 0 1.25rem;
  flex-wrap: wrap;
}
.search-wrap { flex: 1 1 12rem; display: flex; flex-direction: column; }
.search-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin-bottom: 0.25rem;
}
.search-input {
  font-family: var(--font-body);
  font-size: 1rem;
  height: var(--control-h);          /* shared height so shuffle matches */
  padding: 0 0.85rem;
  border: 2px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  width: 100%;
}
.search-input::placeholder { color: var(--ink-soft); opacity: 0.8; }
/* Recolor the native search clear (×) button to match the palette instead of
   the browser default blue. Replaces it with a brick-red masked glyph. */
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  height: 1.1em;
  width: 1.1em;
  cursor: pointer;
  background-color: var(--brick);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6l12 12M18 6L6 18' stroke='black' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6l12 12M18 6L6 18' stroke='black' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
/* Shared "press flush into the paper" treatment: the offset shadow collapses
   and the control shifts into where its shadow sat, ringed in orange, instead
   of stacking a focus outline on top of a still-present drop shadow (which read
   as two competing edges). Each control keeps its own translate distance so it
   travels exactly its own shadow offset — see the per-element rules below. */
.search-input:focus,
.detail-close:active,
.detail-close:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 0;
  box-shadow: none;
}
.search-input:focus { transform: translate(3px, 3px); }   /* 3px shadow */

.shuffle-btn {
  align-self: flex-end;
  height: var(--control-h);          /* exactly the same height as the input */
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 1.15rem;
  color: var(--surface);
  background: var(--orange);
  border: 2px solid var(--ink);
  padding: 0 1.3rem;
  box-shadow: 4px 4px 0 var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease), background-color 0.2s;
}
.shuffle-btn:hover { background: var(--brick); }
.shuffle-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.shuffle-icon {
  display: block;                /* flex item; block avoids inline baseline drift */
  width: 1.15em;
  height: 1.15em;
  flex: 0 0 auto;
}
/* While it picks: a quick card-riffle shake, not a spin. */
.shuffle-btn.is-shuffling .shuffle-icon { animation: shuffleRiffle 0.5s var(--ease); }
@keyframes shuffleRiffle {
  0%, 100% { transform: translateX(0) rotate(0); }
  20%      { transform: translateX(-2.5px) rotate(-9deg); }
  45%      { transform: translateX(2.5px)  rotate(9deg); }
  70%      { transform: translateX(-1.5px) rotate(-5deg); }
  88%      { transform: translateX(1px)    rotate(3deg); }
}

/* ============================================================
   Filter pills — horizontally scrolling rails
   ============================================================ */
.filters { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.25rem; }
.filter-group { display: flex; flex-direction: column; gap: 0.35rem; }
.filter-heading {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin: 0;
}
.pill-rail {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
  /* let thumbs flick sideways smoothly */
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  /* grab-to-drag affordance for mouse users (JS wires the actual scroll) */
  cursor: grab;
}
.pill-rail.is-dragging {
  cursor: grabbing;
  scroll-snap-type: none;   /* don't fight the drag */
  user-select: none;
}
.pill-rail.is-dragging .pill { cursor: grabbing; }
.pill {
  flex: 0 0 auto;
  scroll-snap-align: start;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  padding: 0.4rem 0.8rem;
  border: 2px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 0.1s var(--ease), box-shadow 0.1s var(--ease), background-color 0.15s;
}
.pill:hover { background: var(--mustard); }
.pill:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
/* Active state: filled + a leading check mark so meaning isn't color-only */
.pill[aria-pressed="true"] {
  background: var(--teal);
  color: var(--surface);
}
.pill[aria-pressed="true"]::before { content: "✓ "; }
.pill.pill-count { opacity: 0.55; font-weight: 400; }

/* ============================================================
   Results bar
   ============================================================ */
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
  min-height: 1.5rem;
  flex-wrap: wrap;   /* count drops above the tools on a narrow phone */
}
.results-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0;
}
/* Right-hand cluster: clear-filters (when shown) + the sort control. */
.results-tools {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-left: auto;   /* pin to the right even before the bar wraps */
}
.clear-filters {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: none;
  border: none;
  border-bottom: 2px solid var(--brick);
  color: var(--brick);
  cursor: pointer;
  padding: 0.1rem 0;
}

/* ---------- Sort dropdown ----------
   Same construction-paper language as the pills/inputs: hard 2px border, offset
   shadow, mono type. Native <select> restyled with a masked brick chevron. */
.sort-wrap { display: flex; align-items: center; gap: 0.4rem; }
.sort-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}
.sort-select {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink);
  background-color: var(--surface);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
  /* room on the right for the chevron */
  padding: 0.35rem 1.9rem 0.35rem 0.6rem;
  -webkit-appearance: none;
  appearance: none;
  /* brick chevron, drawn as a masked SVG so it inherits the palette */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 9l7 7 7-7' fill='none' stroke='%23c8452f' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 0.9rem;
  transition: transform 0.1s var(--ease), box-shadow 0.1s var(--ease);
}
.sort-select:hover { background-color: var(--mustard); }
/* Press flush into the paper on focus, matching the search field / close btn. */
.sort-select:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 0;
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ============================================================
   The grid
   ============================================================ */
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);   /* two across on a phone */
  gap: 1.1rem;
}
@media (min-width: 560px)  { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px)  { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1080px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.grid-item { min-width: 0; }

/* Card is a real button so it's keyboard-operable end to end */
.card {
  --card-shadow: var(--shadow-neutral);
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 2px solid var(--ink);
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  /* hard offset shadow, tinted by the cover's dominant color */
  box-shadow: 6px 6px 0 var(--card-shadow);
  transition: transform 0.14s var(--ease), box-shadow 0.14s var(--ease);
  /* fade/slide-in on load */
  opacity: 0;
  transform: translateY(14px);
}
.card.is-in { opacity: 1; transform: translateY(0); }
.card:hover { transform: translateY(-3px); box-shadow: 8px 10px 0 var(--card-shadow); }
.card:active { transform: translateY(1px) scale(0.99); box-shadow: 3px 3px 0 var(--card-shadow); }

.card-cover-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-bottom: 2px solid var(--ink);
  background: var(--paper-deep);
}
.card-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Archive accession tag: the catalog number, sitting on the cover corner */
.card-number {
  position: absolute;
  top: 0;
  left: 0;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  background: var(--mustard);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-top: 0;
  border-left: 0;
  padding: 0.15rem 0.45rem;
}
.card-body { padding: 0.5rem 0.6rem 0.65rem; display: flex; flex-direction: column; gap: 0.1rem; }
.card-artist {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.15;
  /* clamp to two lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-year {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--ink-soft);
  margin-top: 0.1rem;
}

/* Briefly pulse the card the shuffle landed on */
.card.is-shuffled { animation: shuffleLand 0.9s var(--ease); }
@keyframes shuffleLand {
  0%   { box-shadow: 6px 6px 0 var(--card-shadow); }
  25%  { box-shadow: 0 0 0 6px var(--mustard), 10px 10px 0 var(--card-shadow); }
  100% { box-shadow: 6px 6px 0 var(--card-shadow); }
}

/* ============================================================
   Detail dialog
   ============================================================ */
.detail {
  border: 3px solid var(--ink);
  padding: 0;
  max-width: min(560px, 92vw);
  width: 100%;
  /* keep the whole card (cover + body) reachable on short viewports */
  max-height: 90vh;
  overflow-y: auto;
  background: var(--detail-bg, var(--surface));
  color: var(--ink);
  box-shadow: 10px 10px 0 var(--ink);
}
.detail::backdrop { background: rgba(36, 28, 22, 0.55); }
/* Lock background scrolling while the dialog is open. showModal() traps focus
   but doesn't stop the page behind the backdrop from scrolling on wheel/touch;
   JS toggles this class on open/close. */
body.modal-open { overflow: hidden; }
.detail-inner { position: relative; }
.detail-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: 1rem;
  width: 2rem; height: 2rem;
  background: var(--surface);
  border: 2px solid var(--ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}
/* Same press-flush treatment as the search field (shared rule above); the
   dialog auto-focuses this button on open, so this is the state seen first. */
.detail-close:active,
.detail-close:focus-visible { transform: translate(2px, 2px); }   /* 2px shadow */
.detail-cover {
  aspect-ratio: 1 / 1;
  border-bottom: 3px solid var(--ink);
  overflow: hidden;
  background: var(--paper-deep);
}
.detail-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-body {
  padding: 1rem 1.15rem 1.4rem;
  /* transparent so the dialog's own opaque, cover-tinted background shows —
     no bleed-through from the page behind. */
  background: transparent;
}
.detail-number {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 0.25rem;
}
.detail-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  line-height: 0.95;
  text-transform: uppercase;
  margin: 0 0 0.15rem;
}
.detail-artist {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  margin: 0 0 0.9rem;
  color: var(--ink);
}
.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;          /* label sits on the value's baseline */
  gap: 0.45rem 0.9rem;
  margin: 0 0 0.9rem;
  font-size: 0.95rem;
  border-top: 1.5px dashed var(--ink-soft);
  border-bottom: 1.5px dashed var(--ink-soft);
  padding: 0.7rem 0;
}
.detail-meta dt {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.detail-meta dd { margin: 0; font-weight: 600; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }
.detail-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  background: var(--surface);
  border: 2px solid var(--ink);
}
.detail-notes {
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.detail-notes:empty { display: none; }

/* ============================================================
   States + footer
   ============================================================ */
.state-msg {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-align: center;
  padding: 2.5rem 1rem;
}
.state-msg.is-error { color: var(--brick); font-weight: 700; }
.state-msg[hidden] { display: none; }

.site-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-soft);
  border-top: 2px solid var(--ink);
}
.site-footer p { margin: 0; }

/* ============================================================
   Reduced motion: drop slides/staggers/spins to simple fades
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .card { transition: opacity 0.2s ease; transform: none; }
  .card.is-in { transform: none; }
  .card:hover, .card:active { transform: none; }
  .shuffle-btn.is-shuffling .shuffle-icon { animation: none; }
  .card.is-shuffled { animation: none; outline: 4px solid var(--mustard); outline-offset: 3px; }
  body { transition: none; }
}
