/*
  Content library (library.js). Every class is prefixed lib-.
  Colours and fonts come from the shell's :root custom properties, with fallbacks.
*/

.lib {
  container-type: inline-size;
  container-name: lib;
  min-width: 0;
  color: var(--ink, #f2f4ee);
  font-family: var(--sans, 'DM Sans', system-ui, sans-serif);
  font-size: 16px;
  line-height: 1.5;
  text-align: left;
  -webkit-text-size-adjust: 100%;
  animation: lib-in .32s ease-out both;
}

.lib *,
.lib *::before,
.lib *::after { box-sizing: border-box; }

.lib ul { list-style: none; margin: 0; padding: 0; }
.lib p, .lib h3 { margin: 0; }

@keyframes lib-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.lib-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- toolbar ---------- */

.lib-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
}

.lib-search {
  position: relative;
  flex: 1 1 260px;
  max-width: 420px;
  min-width: 0;
}

.lib-input {
  display: block;
  width: 100%;
  height: 46px;
  margin: 0;
  padding: 0 14px 0 42px;
  color: var(--ink, #f2f4ee);
  font: inherit;
  font-size: 16px;
  background-color: var(--surface, #10252d);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23b4c2c2' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.6-3.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px 50%;
  border: 1px solid var(--line, rgba(200, 228, 228, .16));
  border-radius: var(--r, 10px);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s ease, background-color .15s ease;
}

.lib-input::placeholder { color: var(--faint, #8499a0); opacity: 1; }
.lib-input:hover { background-color: var(--surface-2, #16313a); }
.lib-input:focus-visible {
  outline: 2px solid var(--accent, #b9a3ff);
  outline-offset: 2px;
  border-color: var(--accent, #b9a3ff);
}

.lib-count {
  flex: 0 0 auto;
  color: var(--muted, #b4c2c2);
  font-family: var(--mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 14px;
  letter-spacing: .04em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

/* ---------- chips ---------- */

.lib-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  margin-top: 16px;
}

.lib-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.lib-chips-label {
  margin-right: 2px;
  color: var(--faint, #8499a0);
  font-family: var(--mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.lib-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  padding: 0 16px;
  color: var(--ink, #f2f4ee);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  background: transparent;
  border: 1px solid var(--line, rgba(200, 228, 228, .16));
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.lib-chip:hover {
  background: var(--surface-2, #16313a);
  border-color: var(--accent, #b9a3ff);
}

.lib-chip:focus-visible {
  outline: 2px solid var(--accent, #b9a3ff);
  outline-offset: 2px;
}

.lib-chip[aria-pressed="true"] {
  color: #06222a;
  background: var(--accent, #b9a3ff);
  border-color: var(--accent, #b9a3ff);
}

.lib-chip-count {
  color: var(--faint, #8499a0);
  font-family: var(--mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.lib-chip[aria-pressed="true"] .lib-chip-count { color: #1d4a50; }

/* ---------- results ---------- */

.lib-results { margin-top: 28px; }

.lib-group {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 14px;
  color: var(--muted, #b4c2c2);
  font-family: var(--mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.lib-group::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: var(--line, rgba(200, 228, 228, .16));
}

.lib-grid + .lib-group,
.lib-list + .lib-group { margin-top: 36px; }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
  gap: 16px;
}

.lib-grid--featured {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}

.lib-cell { display: flex; min-width: 0; }

/* ---------- shared card parts ---------- */

.lib-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-family: var(--mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.lib-type { color: var(--accent, #b9a3ff); }
.lib-date { color: var(--muted, #b4c2c2); font-variant-numeric: tabular-nums; }

.lib-badge {
  padding: 2px 8px;
  color: #2a1503;
  font-weight: 600;
  background: var(--warm, #f0a868);
  border-radius: 999px;
}

.lib-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--warm, #f0a868);
}

.lib-flag::before {
  content: "";
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
}

.lib-title {
  color: var(--ink, #f2f4ee);
  font-family: var(--display, 'Bricolage Grotesque', system-ui, sans-serif);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.015em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.lib-desc {
  color: var(--muted, #b4c2c2);
  font-size: 15.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.lib-tags {
  color: var(--faint, #8499a0);
  font-family: var(--mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 12px;
  letter-spacing: .02em;
  overflow-wrap: anywhere;
}

.lib-source {
  min-width: 0;
  color: var(--muted, #b4c2c2);
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.lib-go {
  flex: 0 0 auto;
  color: var(--accent, #b9a3ff);
  font-size: 18px;
  line-height: 1;
  transition: transform .18s ease;
}

.lib-media {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--surface-2, #16313a);
}

.lib-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .3s ease;
}

.lib-media--play::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 38px;
  height: 38px;
  background-color: rgba(6, 24, 30, .82);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f2f4ee'%3E%3Cpath d='M9 6.5v11l9-5.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 20px 20px;
  border: 1px solid rgba(242, 244, 238, .35);
  border-radius: 50%;
}

/* ---------- card (grid) ---------- */

.lib-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  background: var(--surface, #10252d);
  border: 1px solid var(--line, rgba(200, 228, 228, .16));
  border-radius: var(--r, 10px);
  transition: background-color .18s ease, border-color .18s ease, transform .18s ease;
}

.lib-card-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 20px;
}

.lib-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line, rgba(200, 228, 228, .16));
}

a.lib-card:hover {
  background: var(--surface-2, #16313a);
  border-color: var(--accent, #b9a3ff);
  transform: translateY(-2px);
}

a.lib-card:hover .lib-title,
a.lib-row:hover .lib-title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }

a.lib-card:hover .lib-go,
a.lib-row:hover .lib-go { transform: translate(2px, -2px); }

a.lib-card:hover .lib-img { transform: scale(1.03); }

a.lib-card:focus-visible,
a.lib-row:focus-visible {
  outline: 2px solid var(--accent, #b9a3ff);
  outline-offset: 2px;
}

a.lib-card:focus-visible { background: var(--surface-2, #16313a); }

.lib-card--featured { border-color: rgba(185, 163, 255, .34); }
.lib-card--featured .lib-card-body { gap: 12px; padding: 24px; }
.lib-card--featured .lib-title { font-size: 28px; line-height: 1.12; }
.lib-card--featured .lib-desc { max-width: 62ch; font-size: 16px; color: var(--ink, #f2f4ee); }
.lib-card--upcoming { border-color: var(--warm, #f0a868); }

/* ---------- row (list: podcast, writing) ---------- */

.lib-list {
  overflow: hidden;
  background: var(--surface, #10252d);
  border: 1px solid var(--line, rgba(200, 228, 228, .16));
  border-radius: var(--r, 10px);
}

.lib-list .lib-cell { display: block; }
.lib-list .lib-cell + .lib-cell { border-top: 1px solid var(--line, rgba(200, 228, 228, .16)); }

.lib-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "meta go"
    "body body"
    "media media";
  gap: 8px 16px;
  padding: 18px 16px;
  color: inherit;
  text-decoration: none;
  transition: background-color .18s ease;
}

.lib-row > .lib-meta { grid-area: meta; align-self: center; }
.lib-row > .lib-row-body { grid-area: body; }
.lib-row > .lib-media { grid-area: media; width: min(100%, 260px); margin-top: 6px; border-radius: 6px; }
.lib-row > .lib-go { grid-area: go; align-self: center; }

.lib-row-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.lib-row .lib-source { color: var(--faint, #8499a0); font-size: 13.5px; }

a.lib-row:hover,
a.lib-row:focus-visible { background: var(--surface-2, #16313a); }
a.lib-row:focus-visible { outline-offset: -2px; }

/* Episode list: the guest line carries as much weight as the title. */
.lib--podcast .lib-row .lib-desc { color: var(--ink, #f2f4ee); font-size: 16px; }

/* Reading list: a comfortable measure. */
.lib--writing .lib-row .lib-desc { max-width: 68ch; }

/* ---------- empty state ---------- */

.lib-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 32px 24px;
  background: var(--surface, #10252d);
  border: 1px dashed var(--line, rgba(200, 228, 228, .16));
  border-radius: var(--r, 10px);
}

.lib-empty-title {
  font-family: var(--display, 'Bricolage Grotesque', system-ui, sans-serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
}

.lib-empty-text { color: var(--muted, #b4c2c2); font-size: 15.5px; }
.lib-empty-btn { margin-top: 6px; }

/* ---------- wider containers ---------- */

@container lib (min-width: 680px) {
  .lib-row {
    grid-template-columns: 124px minmax(0, 1fr) auto auto;
    grid-template-areas: "meta body media go";
    gap: 0 24px;
    padding: 22px 24px;
  }

  .lib-row > .lib-meta {
    flex-direction: column;
    align-items: flex-start;
    align-self: start;
    gap: 4px;
    padding-top: 5px;
  }

  .lib-row > .lib-meta .lib-date { order: -1; color: var(--ink, #f2f4ee); }
  .lib-row > .lib-media { width: 176px; margin-top: 0; align-self: center; }
  .lib-row .lib-title { font-size: 24px; }
}

@container lib (min-width: 900px) {
  .lib-grid { gap: 20px; }
  .lib-card--featured .lib-title { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .lib { animation: none; }
  .lib-card,
  .lib-row,
  .lib-chip,
  .lib-input,
  .lib-img,
  .lib-go { transition: none; }
  a.lib-card:hover,
  a.lib-card:hover .lib-img,
  a.lib-card:hover .lib-go,
  a.lib-row:hover .lib-go { transform: none; }
}

.lib-group-note {
  margin: 8px 0 16px;
  color: var(--muted, #b3bec6);
  font-size: 14px;
  line-height: 1.5;
}
