/* ============================================================
   Recital — catalogue: controls, cards, viewer
   ============================================================ */

/* ---- sticky control bar ---- */
.controls {
  position: sticky; top: 0; z-index: 20;
  background: rgba(247, 243, 234, 0.92);
  backdrop-filter: saturate(140%) blur(6px);
  border-bottom: 1px solid var(--rule);
}
.controls__inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0.7rem 1.25rem;
  display: flex; flex-wrap: wrap; gap: 0.7rem 1rem; align-items: center;
}
.search-field {
  position: relative; flex: 1 1 240px; min-width: 200px;
}
.search-field__icon {
  position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%);
  color: var(--ink-faint); font-size: 1.2rem; pointer-events: none;
}
.search-field input {
  width: 100%; font-family: var(--font-ui); font-size: 0.98rem;
  padding: 0.55rem 0.7rem 0.55rem 2.2rem;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--paper-2); color: var(--ink);
}
.search-field input::placeholder { color: var(--ink-faint); }

.tier-filter {
  display: flex; flex-wrap: wrap; gap: 0.35rem;
}
.chip {
  font-family: var(--font-ui); font-size: 0.8rem; font-weight: 500;
  padding: 0.4rem 0.75rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--rule); background: var(--paper-2); color: var(--ink-soft);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent-2); }
.chip[aria-pressed="true"] {
  background: var(--ink); color: var(--paper-2); border-color: var(--ink);
}
.chip--all[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }

.filter-divider {
  align-self: stretch; width: 1px; background: var(--rule); margin: 0.1rem 0.1rem;
}
.source-filter { display: flex; flex-wrap: wrap; gap: 0.35rem; }
/* source chips read as a distinct group: gold accent when active */
.chip--source[aria-pressed="true"] {
  background: var(--accent-2); border-color: var(--accent-2); color: #221a08;
}
.chip--featured { display: inline-flex; align-items: center; gap: 0.3em; }
.chip--featured span { color: var(--accent-2); }
.chip--featured[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper-2); }
.chip--featured[aria-pressed="true"] span { color: #f3d27a; }

/* sort / group control */
.sort-control {
  display: inline-flex; align-items: center; gap: 0.4em;
  font-family: var(--font-ui); font-size: 0.78rem; color: var(--ink-faint);
}
.sort-control select {
  font-family: var(--font-ui); font-size: 0.82rem; padding: 0.4rem 0.5rem;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--paper-2); color: var(--ink); cursor: pointer;
}

/* section headers when the list is grouped */
.group-header {
  grid-column: 1 / -1; list-style: none;
  display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap;
  margin: 1.1rem 0 0.2rem; padding: 0 0.2rem 0.45rem;
  border-bottom: 1px solid var(--rule);
}
.group-header:first-child { margin-top: 0; }
.group-header[hidden] { display: none; }
.group-header__label { font-size: 1.35rem; font-weight: 600; color: var(--ink); }
.group-header__count { font-family: var(--font-ui); font-size: 0.72rem; color: var(--ink-faint); letter-spacing: 0.02em; }

/* featured star badge on cards */
.badge--featured { background: var(--accent-2); color: #221a08; padding: 0.22rem 0.45rem; }

.controls__actions {
  display: flex; align-items: center; gap: 0.8rem; margin-left: auto;
}
.result-count {
  font-family: var(--font-ui); font-size: 0.8rem; color: var(--ink-faint);
  white-space: nowrap;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 0.45em;
  font-family: var(--font-ui); font-size: 0.85rem; font-weight: 500;
  padding: 0.5rem 0.85rem; border-radius: var(--radius-sm);
  border: 1px solid var(--ink); background: var(--ink); color: var(--paper-2);
  text-decoration: none; cursor: pointer; line-height: 1;
  transition: filter 0.12s ease, background 0.12s ease;
}
.btn:hover { filter: brightness(1.12); color: var(--paper-2); }
.btn--ghost {
  background: transparent; color: var(--ink); border-color: var(--rule);
}
.btn--ghost:hover { background: var(--paper-2); color: var(--ink); border-color: var(--accent-2); }
.btn--imslp { background: var(--accent); border-color: var(--accent); }
.btn--play { background: var(--accent-2); border-color: var(--accent-2); color: #221a08; }
.btn--play[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper-2); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---- catalogue grid ---- */
.catalog { max-width: var(--maxw); margin: 0 auto; padding: 1.6rem 1.25rem 0; }
.catalog:focus { outline: none; }
.piece-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 0.9rem;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .piece-grid { grid-template-columns: 1fr 1fr; align-items: start; }
  /* an open card spans the full width so the score has room */
  .card.is-open { grid-column: 1 / -1; }
}

/* ---- card ---- */
.card {
  background: var(--card); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: 0 1px 2px var(--shadow);
  overflow: hidden;
}
.card[hidden] { display: none; }
.piece { }
.piece__summary {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 0.9rem;
  align-items: center; padding: 0.9rem 1rem; cursor: pointer; list-style: none;
}
.piece__summary::-webkit-details-marker { display: none; }
.piece__summary:hover { background: #fbf7ee; }

.piece__thumb {
  width: 56px; height: 56px; border-radius: var(--radius-sm); overflow: hidden;
  background: linear-gradient(135deg, #efe7d6, #e2d6bd);
  display: grid; place-items: center; border: 1px solid var(--rule-2);
}
.piece__thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.piece__thumb .initials {
  font-family: var(--font-serif); font-weight: 600; font-size: 1.25rem; color: var(--accent);
}

.piece__head { min-width: 0; }
.piece__title { font-size: 1.22rem; font-weight: 600; }
.piece__composer {
  margin: 0.05rem 0 0; color: var(--ink-soft); font-size: 1rem;
}
.piece__composer .dates { color: var(--ink-faint); font-size: 0.9em; }
.piece__opus {
  margin: 0.1rem 0 0; font-family: var(--font-ui); font-size: 0.76rem;
  letter-spacing: 0.02em; color: var(--ink-faint);
}

.piece__badges {
  display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem;
  text-align: right;
}
.badge {
  font-family: var(--font-ui); font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.03em; padding: 0.22rem 0.5rem; border-radius: 999px;
  white-space: nowrap;
}
.badge--tier { color: #fff; }
.badge--easy               { background: #3f7d52; }
.badge--early-intermediate { background: #5b8a3c; }
.badge--intermediate       { background: #9a7b3f; }
.badge--late-intermediate  { background: #b56a32; }
.badge--advanced           { background: #8a3535; }
.badge--license {
  background: var(--rule-2); color: var(--ink-soft); border: 1px solid var(--rule);
}
.badge--linked { background: #ece3d2; color: var(--accent); border: 1px solid #d8c39a; }
.expand-hint {
  font-family: var(--font-ui); font-size: 0.72rem; color: var(--ink-faint);
  display: inline-flex; align-items: center; gap: 0.3em;
}
.expand-hint::after { content: "▾"; transition: transform 0.15s ease; }
.piece[open] .expand-hint::after { transform: rotate(180deg); }

/* ---- expanded body ---- */
.piece__body {
  border-top: 1px solid var(--rule-2); padding: 1rem;
  background: #fcf9f2;
}
.piece__notes {
  margin: 0 0 0.85rem; color: var(--ink-soft); font-size: 1.05rem; font-style: italic;
}
.toolbar {
  display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem;
}
.provenance {
  font-family: var(--font-ui); font-size: 0.78rem; color: var(--ink-faint);
  line-height: 1.5; margin-bottom: 0.85rem;
  display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem;
}
.provenance .prov-item { display: inline-flex; gap: 0.35em; align-items: baseline; }
.provenance .prov-label { color: var(--ink-faint); }
.provenance .prov-value { color: var(--ink-soft); }
.provenance a { color: var(--accent); }
.linked-note {
  background: #f4ecdc; border: 1px solid #e3d4b3; border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem; color: var(--ink-soft); font-style: normal;
}

/* ---- interactive player ---- */
.player {
  margin: 0 0 0.9rem; padding: 0.7rem 0.75rem 0.55rem;
  border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--paper-2);
}
.pl-transport { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.pl-play {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--accent); background: var(--accent); color: var(--paper-2);
  font-size: 1rem; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.pl-play:hover { filter: brightness(1.12); }
.player.is-loading .pl-play { background: var(--ink-faint); border-color: var(--ink-faint); cursor: progress; }
.pl-progress {
  flex: 1 1 140px; min-width: 110px; height: 9px; border-radius: 999px;
  background: var(--rule-2); position: relative; cursor: pointer;
}
.pl-progress__fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); }
.pl-time { font-family: var(--font-ui); font-size: 0.74rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pl-tempo-wrap { display: inline-flex; align-items: center; gap: 0.4em; font-family: var(--font-ui); font-size: 0.74rem; color: var(--ink-faint); }
.pl-tempo { width: 84px; accent-color: var(--accent); cursor: pointer; }
.pl-tempo-val { min-width: 2.6em; font-variant-numeric: tabular-nums; }
.pl-labels {
  font-family: var(--font-ui); font-size: 0.74rem; padding: 0.35rem 0.6rem;
  border: 1px solid var(--rule); border-radius: 999px; cursor: pointer;
  background: var(--paper-2); color: var(--ink-soft); white-space: nowrap;
}
.pl-labels[aria-pressed="true"] { background: var(--accent-2); border-color: var(--accent-2); color: #221a08; }

/* piano keyboard */
.keyboard {
  position: relative; height: 62px; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--rule); background: #2b2620; user-select: none;
}
.kb-white { display: flex; height: 100%; }
.kb-key--white {
  flex: 1 1 0; height: 100%; background: linear-gradient(#fffdf8, #f3eee2);
  border-right: 1px solid #cabfa6; border-radius: 0 0 3px 3px; cursor: pointer;
}
.kb-key--white:last-child { border-right: 0; }
.kb-black { position: absolute; inset: 0 0 auto 0; height: 62%; pointer-events: none; }
.kb-key--black {
  position: absolute; top: 0; height: 100%; transform: translateX(-50%);
  background: linear-gradient(#3a342b, #1d1a14); border-radius: 0 0 2px 2px;
  pointer-events: auto; cursor: pointer; box-shadow: 0 1px 1px rgba(0,0,0,0.4);
}
.kb-key--white.key--on { background: linear-gradient(var(--accent-2), #b08b34); }
.kb-key--black.key--on { background: linear-gradient(#a83d3d, var(--accent)); }

/* scrolling staff notation (looks like sheet music: light paper, ink notes) */
.pl-staff {
  display: block; width: 100%; height: 132px; margin-bottom: 0.5rem;
  background: #fdfaf3; border: 1px solid var(--rule); border-radius: 5px;
}

/* falling-note roll, sitting directly on top of the keyboard */
.pl-stage { margin-bottom: 0.5rem; }
.pl-roll {
  display: block; width: 100%; height: 122px;
  background: linear-gradient(#211c16, #2a2520);
  border: 1px solid var(--rule); border-bottom: 0; border-radius: 5px 5px 0 0;
}
.pl-stage .keyboard { border-top: 0; border-radius: 0 0 5px 5px; }

/* pedal indicator lamps */
.pl-pedals {
  display: flex; flex-wrap: wrap; gap: 0.9rem; margin-top: 0.1rem;
  font-family: var(--font-ui); font-size: 0.72rem; color: var(--ink-faint);
}
.pl-pedal { display: inline-flex; align-items: center; gap: 0.4em; }
.pl-pedal__dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--rule); border: 1px solid #cabfa6; transition: background 0.08s ease, box-shadow 0.08s ease;
}
.pl-pedal.is-on { color: var(--accent); }
.pl-pedal.is-on .pl-pedal__dot { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 6px rgba(124, 45, 45, 0.55); }

@media (max-width: 560px) { .keyboard { height: 48px; } .pl-roll { height: 92px; } .pl-staff { height: 104px; } .pl-time { width: 100%; } }
@media (prefers-reduced-motion: reduce) { .pl-pedal__dot { transition: none; } }

/* ---- PDF surface ---- */
.pdf-surface {
  position: relative; width: 100%; min-height: 220px;
  background: #efe9dd; border: 1px solid var(--rule); border-radius: var(--radius-sm);
  overflow: hidden;
}
.pdf-surface.is-iframe { height: min(82vh, 900px); }
.pdf-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.pdf-canvas-scroll {
  height: min(82vh, 900px); overflow-y: auto; padding: 0.6rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.6rem;
  background: #d9d2c4;
}
.pdf-canvas-scroll canvas {
  max-width: 100%; height: auto; box-shadow: 0 2px 8px rgba(0,0,0,0.25); background: #fff;
}
.pdf-status {
  font-family: var(--font-ui); font-size: 0.85rem; color: var(--ink-faint);
  padding: 1.4rem; text-align: center;
}
.pdf-status .spinner {
  display: inline-block; width: 18px; height: 18px; margin-right: 0.5em;
  border: 2px solid var(--rule); border-top-color: var(--accent);
  border-radius: 50%; vertical-align: -3px; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  font-family: var(--font-ui); text-align: center; color: var(--ink-faint);
  padding: 3rem 1rem; font-size: 1rem;
}

/* ---- print-only helper (hidden on screen) ---- */
.print-only { display: none; }

/* ---- responsive ---- */
@media (max-width: 560px) {
  body { font-size: 1.06rem; }
  .piece__summary { grid-template-columns: 44px 1fr; grid-template-areas: "thumb head" "badges badges"; }
  .piece__thumb { width: 44px; height: 44px; grid-area: thumb; }
  .piece__head { grid-area: head; }
  .piece__badges { grid-area: badges; flex-direction: row; align-items: center; justify-content: flex-start; flex-wrap: wrap; }
  .controls__actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .pdf-surface.is-iframe, .pdf-canvas-scroll { height: 70vh; }
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
      transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
