/* library.css - Puzzle Library page (library.html) + landing library strip
   (index.html #libraryStrip). PhotoPieces v2.0, Builder F.
   Loaded on BOTH pages (see COMMON.md / index.html <head>). Uses the shared
   design tokens from styles.css (--bg, --primary, --accent, --space-*, ...);
   this file does not redefine them. */

/* ---------- Shared chip pill (category chips, surprise toggle, strip links) --- */

.library-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.library-chip svg { width: 16px; height: 16px; flex: none; }
.library-chip:hover { border-color: var(--primary); color: var(--primary); }
button.library-chip[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ---------- Library page: hero ---------- */

.library-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-8);
}
.library-hero { text-align: center; margin-bottom: var(--space-5); }
.library-hero h1 {
  font-size: clamp(1.6rem, 4.5vw, 2.3rem);
  margin: var(--space-4) 0 var(--space-2);
}
.library-hero-line {
  color: var(--ink-muted);
  font-size: 1.05rem;
  margin: 0;
}
.library-hero-count {
  display: inline-block;
  margin: var(--space-2) 0 0;
  padding: 2px 12px;
  background: #FDEEE6;
  color: var(--primary);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
}

/* ---------- Library page: controls ---------- */

.library-controls { margin-bottom: var(--space-4); }
.library-chip-row {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-1) 0 var(--space-2);
  scrollbar-width: thin;
}
.library-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-2);
}
.library-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;
}
.library-ages-select {
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.9rem;
  cursor: pointer;
}
.library-search-field {
  position: relative;
  flex: 1 1 220px;
  min-width: 180px;
}
.library-search-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--ink-muted);
  pointer-events: none;
}
.library-search-field input {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-7);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
}
.library-search-field input::placeholder { color: var(--ink-muted); }

.library-result-count {
  margin: var(--space-3) 0 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

/* ---------- Library page: grid + cards ---------- */

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4);
}
.library-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.library-card:hover,
.library-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}
.library-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--border);
}
.library-thumb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3);
  text-align: center;
  color: rgba(255, 255, 255, 0.95);
  background: linear-gradient(135deg, #D9D2C4, #C7BFAE);
}
.library-thumb-icon {
  width: 32px;
  height: 32px;
  opacity: 0.9;
}
.library-thumb-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.25;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.library-thumb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.library-thumb-img.is-loaded { opacity: 1; }
.library-badge-surprise {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}
.library-card-body {
  padding: var(--space-3) var(--space-4) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1;
}
.library-card-title {
  margin: 0;
  font-size: 1.02rem;
  font-family: var(--font-display);
  color: var(--ink);
}
.library-card-cat {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
}
.library-age-pills {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: var(--space-2) 0 0;
  padding: 0;
}
.library-age-pill {
  background: #E7F5F2;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

/* Per-category fallback gradients: original palette, no brand colours. */
.library-thumb[data-cat="space"] .library-thumb-fallback { background: linear-gradient(135deg, #262A52, #4A4F9E); }
.library-thumb[data-cat="rocket"] .library-thumb-fallback { background: linear-gradient(135deg, #B6431F, #E8622C); }
.library-thumb[data-cat="underwater"] .library-thumb-fallback { background: linear-gradient(135deg, #0D5C68, #2E9E8F); }
.library-thumb[data-cat="cars"] .library-thumb-fallback { background: linear-gradient(135deg, #2B2B2F, #6B1F22); }
.library-thumb[data-cat="cartoon"] .library-thumb-fallback { background: linear-gradient(135deg, #C2417A, #F2A33F); }
.library-thumb[data-cat="animals"] .library-thumb-fallback { background: linear-gradient(135deg, #4C6B2E, #8A9E3F); }
.library-thumb[data-cat="nature"] .library-thumb-fallback { background: linear-gradient(135deg, #3F7D4A, #D9A441); }
.library-thumb[data-cat="futuristic"] .library-thumb-fallback { background: linear-gradient(135deg, #1F4E6B, #2E9E8F); }
.library-thumb[data-cat="landscape"] .library-thumb-fallback { background: linear-gradient(135deg, #8A4B2A, #5B8FC4); }

/* ---------- Library page: empty state + honesty note ---------- */

.library-empty {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--ink-muted);
}
.library-empty p { margin: 0 0 var(--space-4); }

.library-note {
  margin: var(--space-7) auto 0;
  max-width: 640px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

/* ---------- Landing library strip (#libraryStrip) ---------- */

.library-strip { margin: var(--space-7) 0; }
.library-strip-heading {
  font-size: 1.3rem;
  text-align: center;
  margin: 0 0 var(--space-3);
}
.library-strip-chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-2);
  scrollbar-width: thin;
  justify-content: flex-start;
}
.library-strip-row {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  padding: var(--space-2) 0 var(--space-3);
  scroll-snap-type: x proximity;
  scrollbar-width: thin;                      /* a slim bar, not the chunky desktop one */
  scrollbar-color: #CFC7B8 transparent;
}
.library-strip-card {
  flex: none;
  width: 160px;
  scroll-snap-align: start;
}
.library-strip-card-body {
  padding: var(--space-2) var(--space-3) var(--space-3);
}
.library-strip-card .library-card-title { font-size: 0.9rem; }
.library-strip-seeall {
  display: block;
  text-align: center;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  margin-top: var(--space-2);
}
.library-strip-seeall:hover { color: var(--primary); }

@media (min-width: 720px) {
  .library-strip-card { width: 190px; }
  /* Room to spare: show every category instead of a sideways-scrolling row */
  .library-chip-row,
  .library-strip-chips { flex-wrap: wrap; overflow-x: visible; }
  .library-strip-chips { justify-content: center; }
}

/* ---------- v2.1: newest pictures (fresh.js) - landing strip + library page --- */

.library-new { margin-bottom: var(--space-6); }
.library-new--page { margin: 0 0 var(--space-5); }
.library-new-heading { color: var(--ink); }
.library-new-row { padding-top: var(--space-2); }
/* Last card in a capped row: plain text card that opens the rest */
.library-new-more {
  align-items: center;
  justify-content: center;
  min-height: 150px;
  padding: var(--space-3);
  text-align: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--accent);
  background: #E7F5F2;
  border: 1px dashed var(--accent);
  cursor: pointer;
}
.library-new-more:hover { color: var(--primary); border-color: var(--primary); }
/* "New" (unplayed, added in the last 7 days) - top-left, opposite Surprise-worthy */
.pp-badge-new {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}
/* Played tick: neutral, quiet - a record, not a score */
.pp-badge-played {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  color: #5B6168;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}
.library-finished {
  margin: var(--space-2) 0 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}
.library-chip-new-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex: none;
}
button.library-chip[aria-pressed="true"] .library-chip-new-dot { background: #fff; }

/* ---------- Small screens (320px baseline, no horizontal page scroll) --- */

@media (max-width: 480px) {
  .library-filter-row { flex-direction: column; align-items: stretch; }
  .library-search-field { flex: none; }
  .library-ages-select { width: 100%; }
}

/* Phones: two compact cards per row (one-per-row made a very long page) */
@media (max-width: 560px) {
  .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .library-grid .library-card-body { padding: var(--space-2) var(--space-3) var(--space-3); }
  .library-grid .library-card-title { font-size: 0.92rem; overflow-wrap: anywhere; }
  .library-grid .library-card-cat { font-size: 0.78rem; }
  .library-grid .library-age-pills { gap: 3px; margin-top: var(--space-1); }
  .library-grid .library-age-pill { font-size: 0.66rem; padding: 1px 6px; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .library-card { transition: none; }
  .library-card:hover, .library-card:focus-visible { transform: none; }
  .library-thumb-img { transition: none; }
}
