/* =========================================================================
   ADD BOOKS SHEET
   ========================================================================= */
.add-scrim { position: fixed; inset: 0; z-index: 55; background: rgba(var(--shadow), .3); opacity: 0; pointer-events: none; transition: opacity .35s; }
.add-scrim.on { opacity: 1; pointer-events: auto; }
.add-sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 56; width: min(640px, 100%); max-height: 92vh; overflow-y: auto;
  transform: translate(-50%, 104%); transition: transform .5s var(--ease-paper);
  background: var(--card); border-radius: 30px 30px 0 0; padding: 10px 26px calc(var(--safe-b) + 26px);
  box-shadow: 0 -20px 60px -24px rgba(var(--shadow), .6);
}
.add-sheet::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background-image: var(--tooth); background-size: 256px; mix-blend-mode: overlay; opacity: var(--tooth-o); pointer-events: none; }
.add-sheet.open { transform: translate(-50%, 0); }
.add-sheet > * { position: relative; z-index: 1; }
.add-head { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; margin: 4px 0 18px; }
.add-head h2 { font-family: var(--display); font-weight: 500; font-size: 28px; margin: 0 0 6px; letter-spacing: -.01em; }
.add-head p { margin: 0; color: var(--ink-2); line-height: 1.5; font-size: 15px; }
.add-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.add-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 18px; border-radius: 22px; text-align: left;
  background: var(--chip); transition: transform .25s var(--spring);
}
.add-tile:active { transform: scale(.96); }
.add-tile:first-child { background: var(--accent); color: var(--accent-ink); }
.add-tile:first-child small { color: inherit; opacity: .8; }
.add-ico { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--btn); color: var(--ink); margin-bottom: 8px; box-shadow: 0 6px 14px -8px rgba(var(--shadow), .6); }
.add-tile b { font-size: 16.5px; font-weight: 800; }
.add-tile small { font-size: 13px; color: var(--ink-3); font-weight: 600; }
.add-how { margin-top: 18px; padding: 16px 18px; border-radius: 20px; background: color-mix(in srgb, var(--chip) 60%, transparent); }
.add-how h3 { margin: 0 0 10px; font-size: 14px; font-weight: 800; letter-spacing: .02em; color: var(--ink-2); }
.add-how ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.add-how li { display: flex; gap: 10px; align-items: baseline; font-size: 14.5px; line-height: 1.45; color: var(--ink-2); }
.add-how li span { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-2); color: #2f2b22; font-size: 12px; font-weight: 800; transform: translateY(-1px); }
.add-how b { color: var(--ink); }
.add-row { display: grid; grid-template-columns: 70px 1fr; gap: 12px; align-items: center; margin-top: 16px; }
.add-row > label { font-size: 13px; font-weight: 800; color: var(--ink-3); }
.add-formats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.add-formats span { font-size: 12px; font-weight: 800; letter-spacing: .04em; padding: 5px 10px; border-radius: 999px; background: var(--chip); color: var(--ink-2); }
.add-note { font-size: 12.5px; color: var(--ink-3); line-height: 1.5; margin: 14px 0 0; }

/* =========================================================================
   IMPORT TRAY
   ========================================================================= */
.import-tray {
  position: fixed; right: 16px; bottom: calc(var(--safe-b) + 16px); z-index: 58; width: min(360px, calc(100vw - 32px));
  max-height: 46vh; display: flex; flex-direction: column;
  background: var(--card); border-radius: 22px; box-shadow: 0 2px 0 rgba(var(--shadow), .1), 0 24px 50px -20px rgba(var(--shadow), .7), 0 0 0 1px var(--rule);
  transform: translateY(calc(100% + 30px)); transition: transform .5s var(--spring); overflow: hidden;
}
.import-tray.on { transform: none; }
.import-tray header { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 8px 18px; font-size: 14px; }
.import-tray header button { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-3); }
.import-tray header svg { width: 18px; height: 18px; }
.import-tray ol { list-style: none; margin: 0; padding: 0 8px 10px; overflow-y: auto; }
.import-tray li { display: flex; gap: 12px; align-items: center; padding: 8px 10px; border-radius: 14px; animation: rise .35s var(--ease-paper) both; }
.tray-thumb { flex: none; width: 34px; height: 48px; border-radius: 2px 5px 5px 2px; background: var(--chip); display: grid; place-items: center; overflow: hidden; box-shadow: 0 4px 8px -4px rgba(var(--shadow), .5); }
.tray-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tray-thumb svg { width: 18px; height: 18px; stroke-width: 2.4; }
li.ok .tray-thumb svg { color: #4f7a5a; }
li.err .tray-thumb svg { color: var(--accent); }
li.skip { opacity: .65; }
.tray-text { min-width: 0; display: flex; flex-direction: column; }
.tray-text b { font-size: 14px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-text small { font-size: 12.5px; color: var(--ink-3); font-weight: 600; }
li.err .tray-text small { color: var(--accent); }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--rule); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   THE BINDERY — an open book riffles while your file becomes a Folio book
   ========================================================================= */
.bindery {
  position: fixed; inset: 0; z-index: 65; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: color-mix(in srgb, var(--desk) 92%, transparent);
  opacity: 0; pointer-events: none; transition: opacity .45s ease;
  --bw: clamp(120px, 17vw, 170px); --bh: calc(var(--bw) * 1.42);
}
.bindery::after { content: ""; position: absolute; inset: 0; background-image: var(--tooth); background-size: 256px; mix-blend-mode: overlay; opacity: var(--tooth-o); pointer-events: none; }
.bindery.on { opacity: 1; pointer-events: auto; }
.bind-stage { position: relative; perspective: 1500px; margin-bottom: 26px; }
.bind-book {
  position: relative; width: calc(var(--bw) * 2); height: var(--bh); transform-style: preserve-3d;
  transform: rotateX(22deg); transition: transform .9s var(--ease-paper);
  animation: bindIn .7s var(--spring) both;
}
@keyframes bindIn { from { transform: rotateX(22deg) translateY(30px) scale(.85); opacity: 0; } }
.bb-board { position: absolute; top: -6px; bottom: -6px; width: calc(var(--bw) + 6px); background: var(--bind, var(--accent)); border-radius: 6px; }
.bb-board::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background-image: var(--tooth); background-size: 256px; mix-blend-mode: overlay; opacity: .5; }
.bb-board-l { left: -6px; border-radius: 6px 2px 2px 6px; filter: brightness(.88); }
.bb-board-r { right: -6px; border-radius: 2px 6px 6px 2px; }
.bb-block, .bb-leaf i, .bb-inside {
  background-color: var(--page);
  background-image:
    linear-gradient(var(--page), var(--page)),
    repeating-linear-gradient(180deg, transparent 0 9px, color-mix(in srgb, var(--ink) 22%, transparent) 9px 11px);
  background-size: 100% 18%, 100% 100%;
  background-repeat: no-repeat, repeat;
  background-clip: border-box, content-box;
  padding: calc(var(--bh) * .1) calc(var(--bw) * .14);
}
.bb-block { position: absolute; top: 0; height: var(--bh); width: var(--bw); }
.bb-block-l { left: 0; box-shadow: inset -14px 0 18px -12px rgba(var(--shadow), .45), -2px 3px 0 color-mix(in srgb, var(--page), #000 12%), -3px 5px 0 color-mix(in srgb, var(--page), #000 18%); }
.bb-block-r { left: var(--bw); box-shadow: inset 14px 0 18px -12px rgba(var(--shadow), .45), 2px 3px 0 color-mix(in srgb, var(--page), #000 12%), 3px 5px 0 color-mix(in srgb, var(--page), #000 18%); }
/* the riffling leaves */
.bb-leaf {
  position: absolute; top: 0; left: var(--bw); width: var(--bw); height: var(--bh);
  transform-origin: 0 50%; transform-style: preserve-3d;
  animation: riffle 1.9s cubic-bezier(.45, .05, .3, 1) infinite; animation-delay: calc(var(--i) * .3s);
}
.bb-leaf i { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; padding: calc(var(--bh) * .1) calc(var(--bw) * .14); }
.bb-leaf i::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(var(--shadow), .25), transparent 30%, rgba(255,255,255,.12) 70%, rgba(var(--shadow), .12)); opacity: var(--shade, 0); }
.bb-leaf i:last-child { transform: rotateY(180deg); }
@keyframes riffle {
  0% { transform: rotateY(0deg); }
  10% { transform: rotateY(-8deg); }
  48% { transform: rotateY(-172deg); }
  55%, 100% { transform: rotateY(-180deg); }
}
.bindery.closing .bb-leaf { animation-play-state: paused; opacity: 0; transition: opacity .2s; }
/* the front cover: lies open on the left, then swings shut */
.bb-front {
  position: absolute; top: -6px; left: var(--bw); width: calc(var(--bw) + 6px); height: calc(var(--bh) + 12px);
  transform-origin: 0 50%; transform-style: preserve-3d; transform: rotateY(-180deg);
  transition: transform .8s cubic-bezier(.55, 0, .3, 1); opacity: 0;
}
.bb-cover, .bb-inside { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 2px 6px 6px 2px; overflow: hidden; }
.bb-cover { background: var(--bind, var(--accent)); box-shadow: 0 20px 40px -18px rgba(var(--shadow), .7); }
.bb-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bb-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,.28), rgba(255,255,255,.14) 3%, transparent 9%); }
.bb-inside { transform: rotateY(180deg); border-radius: 6px 2px 2px 6px; inset: 6px 6px 6px 0; }
.bindery.closing .bb-front { opacity: 1; transform: rotateY(0deg); }
.bindery.closing .bb-board-l, .bindery.closing .bb-block-l { opacity: 0; }
.bindery.closing .bind-book { transform: rotateX(8deg) translateX(calc(var(--bw) * -.5)); }
.bindery.done .bind-book { transform: rotateX(8deg) translateX(calc(var(--bw) * -.5)) translateY(60vh) scale(.4); transition: transform .65s cubic-bezier(.5, 0, .75, 0); }
.bind-shadow { position: absolute; left: 6%; right: 6%; bottom: -26px; height: 28px; background: radial-gradient(50% 50% at 50% 50%, rgba(var(--shadow), .35), transparent 70%); transition: opacity .5s; }
.bindery.done .bind-shadow { opacity: 0; }
.bind-status { font-family: var(--display); font-size: clamp(22px, 3vw, 28px); margin: 0; color: var(--ink); position: relative; z-index: 1; min-height: 1.3em; }
.bind-status.swap { animation: statusIn .4s var(--ease-paper); }
@keyframes statusIn { from { opacity: 0; transform: translateY(8px); } }
.bind-name { margin: 0; color: var(--ink-3); font-size: 14.5px; font-weight: 700; max-width: 80vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 1; }
.bind-dots { display: flex; gap: 6px; margin-top: 12px; position: relative; z-index: 1; }
.bind-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--rule); transition: background-color .3s; }
.bind-dots i.done { background: var(--accent); }
.bind-dots i.now { background: var(--accent-2); }

/* a new book drops onto the shelf */
.b3d.fresh .b3d-obj { animation: shelfDrop .95s cubic-bezier(.3, 1.35, .5, 1) both; }
@keyframes shelfDrop {
  0% { transform: translateZ(calc(var(--t) / -2)) translateY(-140px) rotateY(0deg) rotateZ(-6deg); opacity: 0; }
  40% { opacity: 1; }
  100% { transform: translateZ(calc(var(--t) / -2)) rotateY(26deg); }
}

/* =========================================================================
   FIND BOOKS — loading scene, labels, states
   ========================================================================= */
.disc-loading { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 18px 0 8px; }
.disc-loading p { margin: 0; font-family: var(--display); font-style: italic; font-size: 18px; color: var(--ink-2); }
/* a little book riffling its pages */
.mini-book { --w: 34px; --h: 46px; position: relative; width: calc(var(--w) * 2); height: var(--h); perspective: 400px; transform: rotateX(18deg); }
.mini-book i { position: absolute; top: 0; width: var(--w); height: var(--h); background: var(--page);
  background-image: repeating-linear-gradient(180deg, transparent 0 5px, color-mix(in srgb, var(--ink) 20%, transparent) 5px 6px);
  background-clip: content-box; padding: 7px 6px; box-shadow: 0 6px 12px -6px rgba(var(--shadow), .5); }
.mini-book .mb-l { left: 0; border-radius: 3px 0 0 3px; border-left: 3px solid var(--accent); }
.mini-book .mb-r { left: var(--w); border-radius: 0 3px 3px 0; border-right: 3px solid var(--accent); }
.mini-book .mb-leaf { left: var(--w); transform-origin: 0 50%; backface-visibility: visible; border-radius: 0 3px 3px 0;
  animation: riffle 1.5s cubic-bezier(.45, .05, .3, 1) infinite; animation-delay: calc(var(--i) * .25s); }
/* shimmering placeholder covers */
.disc-skel { display: flex; flex-direction: column; gap: 9px; animation: rise .4s var(--ease-paper) both; }
.disc-skel i { aspect-ratio: 2 / 3; border-radius: 4px 10px 10px 4px; }
.disc-skel b { height: 11px; border-radius: 6px; width: 85%; }
.disc-skel b + b { width: 55%; }
.disc-skel i, .disc-skel b {
  background: linear-gradient(100deg, var(--chip) 30%, color-mix(in srgb, var(--chip), #fff 35%) 50%, var(--chip) 70%);
  background-size: 300% 100%; animation: shimmer 1.4s ease-in-out infinite;
}
body[data-theme="night"] .disc-skel i, body[data-theme="night"] .disc-skel b { background-image: linear-gradient(100deg, var(--chip) 30%, color-mix(in srgb, var(--chip), #fff 8%) 50%, var(--chip) 70%); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.disc-item .cover { position: relative; }
.disc-tag { position: absolute; left: 8px; top: 8px; z-index: 4; font-size: 11px; font-weight: 800; letter-spacing: .04em; padding: 4px 9px; border-radius: 999px; background: var(--btn); color: var(--ink); box-shadow: 0 4px 10px -4px rgba(0,0,0,.4); }
.disc-tag.free { background: #24683f; color: #fff6e6; }
.disc-tag.borrow { background: #d9a52a; color: #2b2410; }
.disc-tag.lib { background: rgba(30, 28, 24, .72); color: #f3ead6; }
.disc-item .get.quiet { background: transparent; box-shadow: inset 0 0 0 1.5px var(--rule); color: var(--ink-2); }
.disc-item .get.busy { opacity: .75; }
.disc-callout { grid-column: 1 / -1; margin: 0 0 4px; padding: 14px 18px; border-radius: 16px; background: var(--card); color: var(--ink-2); font-size: 14.5px; line-height: 1.5; border-left: 4px solid #d9a52a; }
.disc-status { grid-column: 1 / -1; text-align: center; color: var(--ink-3); font-family: var(--display); font-style: italic; padding: 40px 0; font-size: 17px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.disc-retry { font-style: normal; }
