/* Projects listing — bone ground, white row cards, mono meta. */

.library-wrap {
  max-width: calc(var(--rail) + 2 * var(--rail-x));
  margin: 0 auto;
  padding: 56px var(--rail-x) 96px;
}

/* =============== Contribution heatmap (top of page) =============== */
.library-heatmap { margin: 0 0 32px; }
.heatmap-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.heatmap-title {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
  margin: 0 0 18px;
}
.heatmap-title b { font-weight: 500; color: var(--ink); }
/* Wrap the SVG so it can scroll horizontally on narrow viewports
   without breaking the card layout. */
.heatmap-grid { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.heatmap-grid svg { display: block; }
.heatmap-cell[data-level="0"] { fill: var(--heat-l0); }
.heatmap-cell[data-level="1"] { fill: var(--heat-l1); }
.heatmap-cell[data-level="2"] { fill: var(--heat-l2); }
.heatmap-cell[data-level="3"] { fill: var(--heat-l3); }
.heatmap-cell[data-level="4"] { fill: var(--heat-l4); }
.heatmap-cell[data-future="1"] { fill: transparent; }
.heatmap-month, .heatmap-dow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  fill: var(--fg-dim);
}
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 12px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
}
.heatmap-legend-swatch { width: 11px; height: 11px; border-radius: 2px; }
.heatmap-tooltip {
  position: fixed;
  transform: translate(-50%, -100%);
  background: var(--ink);
  color: var(--bone);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.7rem;
  padding: 6px 10px;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 50;
  opacity: 0;
  transition: opacity 80ms ease-out;
}
.heatmap-tooltip[data-visible="1"] { opacity: 1; }

/* Placeholder card rendered server-side so frame one of /projects
   already has the heatmap's footprint. heatmap.js replaces it. */
.heatmap-card--placeholder .heatmap-title { color: var(--fg-dim); }
.heatmap-card--placeholder .heatmap-grid {
  /* Match the rendered SVG's height (MONTH_LABEL_H + GRID_H = 18 + 95
     = 113px) so swapping the card in doesn't bump layout. */
  height: 113px;
  background:
    linear-gradient(
      90deg,
      rgba(10, 10, 10, 0.04),
      rgba(10, 10, 10, 0.08),
      rgba(10, 10, 10, 0.04)
    );
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: heatmap-shimmer 1.4s ease-in-out infinite;
}
@keyframes heatmap-shimmer {
  0%   { background-position:  100% 0; }
  100% { background-position: -100% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .heatmap-card--placeholder .heatmap-grid { animation: none; }
}

/* Active cell — the day currently in ?day=YYYY-MM-DD. The ink
   ring shows up against any L0–L4 fill so users can locate
   their selection at a glance. */
.heatmap-cell[data-active="1"] {
  stroke: var(--ink);
  stroke-width: 1.5;
}
.heatmap-cell[data-clickable="1"]:hover {
  stroke: var(--ink);
  stroke-width: 1;
}

/* Day-filter chip — sits between the heatmap card and the
   list-controls strip, only visible when ?day= is set. */
.library-day-chip-slot { margin: 0 0 16px; }
.lib-day-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.72rem;
  color: var(--ink);
}
.lib-day-chip-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  font-size: 0.65rem;
}
.lib-day-chip strong { font-weight: 600; }
.lib-day-chip-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--fg-dim);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.lib-day-chip-clear:hover {
  background: var(--bone);
  color: var(--ink);
}

.library-header { margin-bottom: 24px; }
.library-header h1 { margin: 0 0 6px; font-size: 1.75rem; color: var(--ink); }
.library-header .subtitle {
  margin: 0;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.library-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.lib-search { flex: 1 1 280px; min-width: 240px; display: block; }
.lib-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 14px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-family: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.lib-search input:focus {
  border-color: var(--ink);
}

.lib-filters {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.lib-filter {
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.lib-filter:hover          { color: var(--ink); }
.lib-filter--active        { background: var(--ink); color: var(--chartreuse); }

.library-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lib-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: border-color 120ms ease, transform 120ms ease;
}
.lib-row:hover {
  border-color: var(--ink);
  transform: translateY(-1px);
}

.lib-row-main { min-width: 0; flex: 1; }
.lib-row-title {
  display: flex; align-items: center; gap: 10px; margin-bottom: 2px;
}
.lib-row-title strong {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-row-creator { color: var(--fg-dim); font-size: 0.88rem; }
/* Legacy single-line meta — kept for the placeholder row which
   still uses the old .lib-row-meta slot. */
.lib-row-meta {
  margin-top: 4px;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
/* New pill strip — BPM · host · time-sig · filename · date.
   One line on desktop, wraps naturally on narrow. */
.lib-row-pills {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.lib-row-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  background: var(--bone);
  color: var(--fg-dim);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.4;
}
.lib-row:hover .lib-row-pill { color: var(--ink); }

.lib-row-side {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* "Just added" chartreuse badge — persistent, not a pulse.
   Shown in the side column when .lib-row has .lib-row--new. */
.lib-row-just-added {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  background: var(--chartreuse);
  color: var(--ink);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  line-height: 1;
}
.lib-row:not(.lib-row--new) .lib-row-just-added { display: none; }

.lib-role {
  display: inline-block;
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-radius: 4px;
  line-height: 1;
}
.lib-role--owner  { background: var(--chartreuse); color: var(--ink); }
.lib-role--collab { background: transparent; color: var(--fg-dim); border: 1px solid var(--border-strong); }

.lib-empty {
  color: var(--fg-dim);
  text-align: center;
  padding: 48px 16px;
  font-size: 0.95rem;
  margin: 0;
}
.lib-empty--err { color: var(--danger); }

/* First-time empty state (no tracks ever) — aspirational
   framing + dual CTAs to web sign / plugin install. */
.lib-empty--first {
  text-align: center;
  padding: 80px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.lib-empty-head {
  margin: 0;
  font-size: clamp(1.25rem, 2.5vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.lib-empty-sub {
  margin: 0;
  max-width: 48ch;
  color: var(--fg-dim);
  font-size: 1rem;
  line-height: 1.55;
}
.lib-empty-ctas {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.library-paging {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
}
.lib-page-indicator {
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

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

/* New-row state — subtle chartreuse tint holds for ~28s, then
   fades out over the final 2s. Paired with the persistent
   "Just added" badge rendered by library.js so the new bounce
   is clearly visible, not a blink-and-miss. */
@keyframes lib-row-new {
  0%, 93%  { background-color: rgba(212, 224, 48, 0.16); }
  100%     { background-color: var(--surface); }
}
.lib-row--new {
  animation: lib-row-new 30s ease-out forwards;
}
/* Reduced-motion: skip the fade, show a static tint for the
   full duration — CSS can't remove the class after 30s without
   JS, so accept that the tint stays until next render. */
@media (prefers-reduced-motion: reduce) {
  .lib-row--new {
    animation: none;
    background-color: rgba(212, 224, 48, 0.16);
  }
}

@keyframes lib-placeholder-shimmer {
  0%   { opacity: 0.55; }
  50%  { opacity: 0.95; }
  100% { opacity: 0.55; }
}
.lib-row--placeholder {
  animation: lib-placeholder-shimmer 1.4s ease-in-out infinite;
  pointer-events: none;
  background: rgba(212, 224, 48, 0.12);
  border-style: dashed;
}
.lib-row--placeholder .lib-row-meta { font-style: italic; }

/* =============== Responsive =============== */
@media (max-width: 720px) {
  .library-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .lib-filters {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .lib-filter { white-space: nowrap; }
  .lib-row {
    padding: 14px 16px;
    gap: 10px;
  }
  .lib-row-side { align-self: flex-start; }
}

@media (max-width: 480px) {
  .library-header h1 { font-size: 1.5rem; }
  .lib-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .lib-row-title strong {
    white-space: normal;          /* allow wrap, we have room now */
  }
  .library-paging { gap: 8px; }
  .library-paging .secondary-button { min-height: 44px; padding: 10px 14px; }
}
