/* library.css — the library page, the upload tray, the drop overlay, and the
   notebook. Layout only; every colour and size comes from tokens.css. */

/* ------------------------------------------------------------------ header */
.lib-head { display: flex; align-items: center; gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap; }
.lib-titlerow { display: contents; }
.lib-head h1 { order: 1; font-size: var(--fs-2xl); }
.lib-count { order: 2; font-weight: 700; font-size: var(--fs-sm); margin-top: 6px; }
.lib-search { order: 3; margin-left: auto; flex: 1 1 220px; max-width: 520px; }
.lib-search .input { border-radius: var(--r-pill); background: var(--surface-2); }
.lib-add { order: 4; }
.lib-head:has(.lib-search[hidden]) .lib-add { margin-left: auto; }
.lib-head .lib-add { margin-bottom: var(--press-depth); }

@media (max-width: 760px) {
  .lib-head { gap: var(--s3); }
  .lib-count { flex: 1; }
  .lib-search { order: 5; flex: 1 1 100%; max-width: none; margin-left: 0; }
  .hide-sm { display: none; }
}

/* ------------------------------------------------------------------ continue */
.lib-continue { margin-bottom: var(--s3); }
.lib-continue .section-head { margin-bottom: var(--s3); }
.cont-row {
  display: grid; grid-auto-flow: column;
  grid-auto-columns: minmax(300px, 380px);
  gap: var(--s4);
  overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  padding: 4px 4px var(--s3);
  margin: -4px -4px 0;
}
.cont-card {
  scroll-snap-align: start;
  display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: var(--s4);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.cont-cover { display: block; border-radius: var(--cover-r); align-self: start; }
.cont-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cont-title { font-family: var(--font-brand); font-weight: 600; font-size: var(--fs-lg); line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cont-author { color: var(--text-2); font-size: var(--fs-sm); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cont-progress { margin-top: auto; padding-top: 4px; }
.cont-progress .bar > i { background: var(--sun); }
.cont-where { font-size: var(--fs-xs); font-weight: 800; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cont-actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: 4px; }
@media (max-width: 760px) {
  .cont-row { grid-auto-columns: 86%; }
  .cont-card { grid-template-columns: 88px minmax(0, 1fr); padding: var(--s3); gap: var(--s3); }
}

/* ------------------------------------------------------------------ toolbar */
.lib-toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--s3);
  margin: 0 calc(var(--gutter) * -1) var(--s5);
  padding: var(--s3) var(--gutter);
  padding-top: calc(var(--s3) + var(--safe-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px) saturate(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  border-bottom: 1px solid transparent;
}
.lib-chips { display: flex; gap: var(--s2); overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; padding: 2px; }
/* When the chips run past the edge, they fade out instead of being cut. */
.lib-chips.is-overflowing { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); padding-right: 40px; }
.lib-chips::-webkit-scrollbar { display: none; }
.lib-chips .chip { flex: none; }
.lib-tools { display: flex; align-items: center; gap: var(--s2); flex: none; }
.lib-sort { gap: 6px; }
.lib-viewseg button { min-height: 32px; padding: 0 var(--s3); }
@media (max-width: 760px) {
  .lib-toolbar { flex-wrap: wrap; row-gap: var(--s2); }
  .lib-chips { flex: 1 1 100%; }
  .lib-tools { margin-left: auto; }
  .lib-viewseg button span { display: none; }
}

/* ------------------------------------------------------------------ grid */
.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--s6) var(--s5);
  align-items: start;
}
@media (min-width: 1700px) { .lib-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
@media (max-width: 760px) { .lib-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s5) var(--s3); } }

.lib-card {
  display: flex; flex-direction: column; gap: 8px;
  /* content-visibility clips painting to the card's box, so the card carries
     its own margin of room for the focus ring around the cover. */
  --ring-room: 8px;
  padding: var(--ring-room); margin: calc(var(--ring-room) * -1);
  color: var(--text); text-decoration: none;
  border-radius: var(--r-sm);
  content-visibility: auto;
  contain-intrinsic-size: auto 320px;
  -webkit-touch-callout: none;
}
.lib-card:focus-visible { outline: none; }
.lib-card:focus-visible .cover { outline: 3px solid var(--focus); outline-offset: 4px; }
.lib-card-cover { position: relative; }
.lib-card-title { font-weight: 800; font-size: .93rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.lib-card-author { font-size: .82rem; font-weight: 700; color: var(--text-3); margin-top: -4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) {
  .lib-card-title { font-size: .84rem; }
  .lib-card-author { font-size: .75rem; }
}

.lib-badges { position: absolute; top: 6px; right: 6px; z-index: 4; display: flex; flex-direction: column; gap: 4px; }
.lib-badge {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid var(--outline);
  box-shadow: 0 1px 3px rgba(52, 28, 13, .25);
}
.lib-badge .icon { width: 14px; height: 14px; stroke-width: 2.6; }
.lib-badge-audio { background: var(--sun); color: var(--sb-ink); }
.lib-badge-wait { background: var(--raise); color: var(--brand-deep); }
.lib-badge-done { background: var(--ok); color: var(--raise); }
.lib-review {
  position: absolute; bottom: 12px; right: 6px; z-index: 4;
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--raise); color: var(--accent-deep); border: 1.5px solid var(--accent);
}
.lib-review .icon { width: 13px; height: 13px; }
.lib-row-title .lib-review { position: static; display: inline-grid; margin-left: 6px; vertical-align: middle; width: 20px; height: 20px; }
.lib-seriesno {
  position: absolute; left: 10%; top: 8px; z-index: 4;
  padding: 2px 8px; border-radius: var(--r-pill);
  background: var(--sb-ink); color: var(--sb-paper);
  font-size: 11px; font-weight: 800;
}

.lib-group { margin-bottom: var(--s6); }
.lib-group-title { font-size: var(--fs-lg); margin-bottom: var(--s4); padding-bottom: var(--s2); border-bottom: 1px solid var(--line); }

/* ------------------------------------------------------------------ list */
.lib-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.lib-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 2.2fr) minmax(0, 1.2fr) 150px 90px 110px;
  align-items: center; gap: var(--s4);
  padding: 10px var(--s4);
  border-bottom: 1px solid var(--line);
  color: var(--text); text-decoration: none;
  content-visibility: auto; contain-intrinsic-size: auto 88px;
}
.lib-row:last-child { border-bottom: 0; }
.lib-row:hover { background: var(--bg); }
.lib-row:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: 0; }
.lib-row .cover { box-shadow: 0 1px 3px rgba(52, 28, 13, .2); }
.lib-row-title { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-row-author { font-size: var(--fs-sm); color: var(--text-3); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-row-series { font-size: var(--fs-sm); color: var(--text-2); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-row-progress { font-size: var(--fs-sm); font-weight: 700; }
.lib-row-bar { display: flex; align-items: center; gap: var(--s2); }
.lib-row-bar .bar { flex: 1; }
.lib-row-bar .bar > i { background: var(--sun); }
.lib-row-meta { display: flex; gap: 4px; justify-content: flex-end; }
.lib-row-added { font-size: var(--fs-xs); font-weight: 700; text-align: right; }
@media (max-width: 1100px) { .lib-row { grid-template-columns: 44px minmax(0, 2fr) 140px 80px; } .lib-row-series, .lib-row-added { display: none; } }
@media (max-width: 760px) {
  .lib-row { grid-template-columns: 40px minmax(0, 1fr) 76px; gap: var(--s3); padding: 8px var(--s3); }
  .lib-row-meta { display: none; }
  .lib-row-bar .bar { display: none; }
  .lib-row-progress { text-align: right; }
}

/* ------------------------------------------------------------------ empty and no results */
.lib-none { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s3); padding: var(--s7) var(--s4); color: var(--text-2); }
.lib-none > .icon { color: var(--text-3); }
.lib-none h2 { color: var(--text); }
.lib-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s4); padding: var(--s6) var(--s4) var(--s7); max-width: 640px; margin: 0 auto; }
.lib-empty-bear { width: 150px; }
.lib-empty h2 { font-size: var(--fs-2xl); }
.lib-dropzone {
  display: flex; flex-direction: column; align-items: center; gap: var(--s2);
  width: 100%; padding: var(--s6) var(--s5);
  border: 2.5px dashed var(--line-2); border-radius: var(--r-xl);
  background: var(--surface-2); color: var(--text);
  font-size: var(--fs-lg);
}
.lib-dropzone:hover, .lib-dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.lib-dropzone .icon-lg { width: 42px; height: 42px; color: var(--accent-deep); }
.lib-formats { font-size: var(--fs-sm); color: var(--text-2); max-width: 520px; }

.sk-line { height: 12px; margin-top: 4px; }
.sk-short { width: 60%; }

/* ------------------------------------------------------------------ drop overlay */
.drop-overlay {
  position: fixed; inset: 0; z-index: calc(var(--z-sheet) + 5);
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--sb-teal) 90%, transparent);
  backdrop-filter: blur(3px);
}
.drop-overlay * { pointer-events: none; }
.drop-card {
  display: flex; flex-direction: column; align-items: center; gap: var(--s3);
  padding: var(--s6) var(--s7);
  background: var(--sb-paper); color: var(--sb-ink);
  border: 3px solid var(--sb-ink); border-radius: var(--r-xl);
  box-shadow: 0 8px 0 var(--sb-ink);
  text-align: center;
}
.drop-card strong { font-family: var(--font-brand); font-size: var(--fs-2xl); font-weight: 600; }
.drop-card span { font-weight: 700; }
.drop-bear { width: 120px; }

/* ------------------------------------------------------------------ upload tray */
.up-tray {
  position: fixed; z-index: calc(var(--z-toast) - 1);
  right: var(--s5); bottom: calc(var(--s5) + var(--player-h, 0px));
  width: min(400px, calc(100vw - 32px));
  background: var(--raise);
  border: 2px solid var(--outline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.up-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s2) var(--s2) var(--s4); border-bottom: 1px solid var(--line); }
.up-icon { color: var(--accent-deep); display: grid; }
.up-title { flex: 1; font-weight: 800; font-size: var(--fs-sm); }
.up-list { list-style: none; margin: 0; padding: var(--s1) 0; max-height: min(50vh, 420px); overflow-y: auto; }
.up-tray.is-collapsed .up-list { display: none; }
.up-tray.is-collapsed .up-head { border-bottom: 0; }
.up-item { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3) var(--s2) var(--s4); }
.up-text { display: flex; flex-direction: column; min-width: 0; }
.up-name { font-weight: 800; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-status { font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); }
.up-item[data-status="failed"] .up-status { color: var(--danger); white-space: normal; }
.up-item[data-status="done"] .up-status { color: var(--ok); }
.up-actions { display: flex; align-items: center; gap: 2px; }
.up-ring {
  --p: 0;
  position: relative;
  width: 34px; height: 34px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1turn), var(--progress-track) 0);
  display: grid; place-items: center;
}
.up-ring::before { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: var(--raise); }
.up-ring-icon { position: relative; display: grid; place-items: center; }
.up-ring-icon .icon { width: 16px; height: 16px; stroke-width: 2.6; }
.up-item[data-status="done"] .up-ring { background: var(--ok); }
.up-item[data-status="done"] .up-ring-icon { color: var(--ok); }
.up-item[data-status="failed"] .up-ring { background: var(--danger); }
.up-item[data-status="failed"] .up-ring-icon { color: var(--danger); }
.up-item[data-status="duplicate"] .up-ring { background: var(--brand); }
.up-item[data-status="duplicate"] .up-ring-icon { color: var(--brand-deep); }
.up-item:is([data-status="queued"], [data-status="converting"], [data-status="reading"], [data-status="matching"]) .up-ring::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid transparent; border-top-color: var(--accent-deep);
  animation: sb-spin 1.1s linear infinite;
}
@media (max-width: 760px) {
  .up-tray { left: var(--s2); right: var(--s2); width: auto; bottom: calc(64px + var(--safe-bottom) + var(--s2) + var(--player-h, 0px)); }
}

/* ------------------------------------------------------------------ ten-foot library (TV / projector) */
.lib-tv .lib-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s7) var(--s6); }
.lib-tv .lib-card-title { font-size: 1.15rem; }
.lib-tv .lib-card-author { font-size: 1rem; }
.lib-tv .cont-row { grid-auto-columns: minmax(460px, 520px); }
.lib-tv .cont-card { grid-template-columns: 150px minmax(0, 1fr); font-size: 1.15rem; }
.lib-tv .lib-card { --ring-room: 26px; }
.lib-tv .lib-card:focus .cover, .lib-tv .lib-card.is-focused .cover { outline: 5px solid var(--sun); outline-offset: 5px; }
.lib-tv .lib-card:focus { outline: none; }
.lib-tv .lib-add, .lib-tv .lib-viewseg { display: none; }

/* ------------------------------------------------------------------ notebook */
.nb-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); margin-bottom: var(--s5); }
.nb-stat { padding: var(--s4) var(--s5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.nb-stat-value { font-family: var(--font-brand); font-weight: 600; font-size: var(--fs-2xl); line-height: 1.1; font-variant-numeric: tabular-nums; }
.nb-stat-label { font-size: var(--fs-sm); font-weight: 800; color: var(--text-3); }
.nb-stat-value .icon { width: .8em; height: .8em; color: var(--accent-deep); display: inline-block; vertical-align: -2px; margin-right: 4px; }
@media (max-width: 760px) { .nb-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); } .nb-stat { padding: var(--s3) var(--s4); } }

.nb-chart { padding: var(--s4) var(--s5) var(--s3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: var(--s6); }
.nb-chart-head { display: flex; align-items: baseline; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }
.nb-chart-head h2 { font-size: var(--fs-lg); margin-right: auto; }
.nb-key { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 800; color: var(--text-2); }
.nb-key i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.nb-key-read i { background: var(--accent); }
.nb-key-listen i { background: var(--brand); }
.nb-bars { display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); align-items: end; gap: 3px; height: 120px; }
.nb-bar { display: flex; flex-direction: column-reverse; height: 100%; justify-content: flex-start; border-radius: 4px 4px 0 0; }
.nb-bar > i { display: block; width: 100%; }
.nb-bar > i.r { background: var(--accent); border-radius: 0 0 2px 2px; }
.nb-bar > i.l { background: var(--brand); border-radius: 3px 3px 0 0; }
.nb-bar > i.r:last-child { border-radius: 3px 3px 2px 2px; }
.nb-bar.is-empty::after { content: ''; display: block; height: 3px; border-radius: 2px; background: var(--progress-track); }
.nb-axis { display: flex; justify-content: space-between; font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); margin-top: 6px; }

.nb-tools { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s5); flex-wrap: wrap; }
.nb-tools .input-wrap { flex: 1 1 280px; max-width: 460px; }
.nb-colors { display: flex; gap: var(--s2); flex-wrap: wrap; }
.nb-swatch { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--outline); display: inline-block; }
.hl-yellow { --hl: var(--sun); }
.hl-orange { --hl: var(--accent); }
.hl-teal { --hl: var(--brand); }
.hl-pink { --hl: color-mix(in srgb, var(--danger) 45%, var(--raise)); }
.hl-green { --hl: var(--ok); }
.hl-underline { --hl: var(--text-2); }
.nb-swatch { background: var(--hl); }

.nb-book { margin-bottom: var(--s6); }
.nb-book-head { display: flex; align-items: center; gap: var(--s4); margin-bottom: var(--s3); }
.nb-book-head .cover { width: 48px; flex: none; }
.nb-book-head h2 { font-size: var(--fs-lg); }
.nb-book-head .sub { font-size: var(--fs-sm); color: var(--text-3); font-weight: 700; }
.nb-list { display: flex; flex-direction: column; gap: var(--s3); }
.nb-item {
  position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s3);
  padding: var(--s4) var(--s4) var(--s4) calc(var(--s4) + 6px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.nb-item::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 5px; border-radius: 0 4px 4px 0; background: var(--hl); }
.nb-quote { font-family: var(--font-serif); font-size: 1.02rem; line-height: 1.55; color: var(--text); text-decoration: none; display: block; }
.nb-quote:hover { text-decoration: underline; text-decoration-color: var(--hl); text-decoration-thickness: 2px; }
.nb-note { margin-top: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r-sm); background: var(--bg); font-weight: 600; font-size: var(--fs-sm); white-space: pre-wrap; }
.nb-meta { margin-top: var(--s2); font-size: var(--fs-xs); font-weight: 800; color: var(--text-3); }
.nb-item-actions { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

/* ------------------------------------------------------------------ tiny covers */
/* A generated cover shown very small keeps only its title, set small, so a
   word never breaks letter by letter. */
:is(.lib-row-cover, .nb-book-head, .st-trash-cover, .fx-cover) .cover-gen { padding: 12% 8% 8% 14%; }
:is(.lib-row-cover, .nb-book-head, .st-trash-cover, .fx-cover) .cover-gen .gt { font-size: 7px; line-height: 1.1; overflow-wrap: normal; word-break: normal; hyphens: auto; }
:is(.lib-row-cover, .nb-book-head, .st-trash-cover, .fx-cover) .cover-gen :is(.ga, .gb) { display: none; }
@media (max-width: 760px) {
  .lib-card .cover-gen .gt { font-size: 11px; overflow-wrap: normal; hyphens: auto; }
  .lib-card .cover-gen .ga { font-size: 9px; }
}

/* ---- Split into separate books (library/collections.js) */
.cx { display: flex; flex-direction: column; gap: var(--s4); }
.cx-looking { display: flex; align-items: center; gap: var(--s3); font-weight: 700; }
.cx-looking p { margin: 0; }
.cx-none { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s2); padding: var(--s4) 0; color: var(--text-2); }
.cx-none .icon { color: var(--accent-deep); }
.cx-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.cx-row { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.cx-num { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-deep); font-family: var(--font-brand); font-weight: 600; }
.cx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.cx-title { font-weight: 800; }
.cx-sub { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; font-size: var(--fs-sm); }
.cx-sub .badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-actions { justify-content: flex-end; }
