/* ============================================================
   Library polish (shelf grid, tiles, saga strip, hero extras)
   and the book page sheet (js/bookpage.js).
   ============================================================ */

/* ---------- the shelf: six across on a desk, three on a tablet, two on a phone (no lone last tile) ---------- */
.grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 40px 22px; }
@media (max-width: 1040px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 40px 28px; } }
@media (max-width: 560px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 16px; } }

.tile { position: relative; }
.tile-link { display: block; position: relative; border-radius: 8px; -webkit-touch-callout: none; }
.tile-link:focus-visible { outline-offset: 4px; border-radius: 10px; }
.tile-badge {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px 3px 6px; border-radius: 999px;
  font: 600 11px/1.3 var(--ui); color: #FBF3E4; letter-spacing: .01em;
  background: rgba(22, 15, 12, .58);
  -webkit-backdrop-filter: blur(8px) saturate(1.4); backdrop-filter: blur(8px) saturate(1.4);
  box-shadow: 0 2px 10px -2px rgba(0, 0, 0, .35);
}
.tile-badge svg { width: 12px; height: 12px; color: #EBC77A; }

.tile-prog { height: 3px; margin-top: 12px; border-radius: 3px; background: color-mix(in oklab, var(--line) 85%, transparent); }
.tile-prog i { border-radius: inherit; background: linear-gradient(90deg, var(--crimson), color-mix(in oklab, var(--crimson) 55%, var(--gold))); }
.tile-prog.is-done i { background: var(--gold); }
.tile-prog.is-empty { background: color-mix(in oklab, var(--line) 50%, transparent); }

.tile-meta { width: 100%; align-items: flex-start; text-align: left; padding: 10px 0 0; border-radius: 6px; cursor: pointer; }
div.tile-meta { cursor: default; }
.tile-title { display: inline-flex; align-items: center; gap: 1px; max-width: 100%; }
.tile-title > span { overflow: hidden; text-overflow: ellipsis; text-decoration: underline 1px transparent; text-underline-offset: 3px; transition: text-decoration-color .2s; }
.tile-title svg { width: 15px; height: 15px; flex: none; color: var(--ink-3); opacity: 0; transform: translateX(-3px); transition: opacity .2s, transform .3s var(--ease-out, var(--ease)); }
button.tile-meta:hover .tile-title > span { text-decoration-color: color-mix(in oklab, var(--ink) 35%, transparent); }
button.tile-meta:hover .tile-title svg, button.tile-meta:focus-visible .tile-title svg { opacity: 1; transform: none; }
@media (hover: none) { .tile-title svg { opacity: .55; transform: none; } }
.tile-sub { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; font-variant-numeric: tabular-nums; }
.tile-state { font-weight: 600; color: var(--ink-2); }
.tile-state::before { content: "·"; margin-right: 6px; color: var(--ink-3); font-weight: 400; }
.tile-state.is-done { color: var(--gold); }
.tile-state.is-next { color: var(--crimson); }
.tile-eds { display: flex; align-items: flex-start; gap: 5px; margin-top: 7px; font-size: 12px; font-weight: 600; line-height: 1.4; color: var(--gold); }
.tile-eds svg { width: 13px; height: 13px; flex: none; margin-top: 2px; stroke-width: 2; }
.tile-eds .dot { color: var(--ink-3); font-weight: 400; }
.tile-eds .is-pending { color: var(--ink-3); font-weight: 500; }
.tile-eds.is-plain { color: var(--ink-2); }

/* ---------- saga strip ---------- */
.shelf-head { align-items: center; }
.saga { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.saga-strip { display: flex; gap: 4px; width: clamp(150px, 20vw, 240px); margin: 0; padding: 0; list-style: none; }
.saga-strip li { position: relative; flex: 1 1 0; height: 6px; border-radius: 3px; overflow: hidden; background: color-mix(in oklab, var(--line) 90%, transparent); }
.saga-strip li i { position: absolute; inset: 0; border-radius: inherit; transform-origin: left; transform: scaleX(var(--p, 0)); background: var(--crimson); }
.saga-strip li.is-done i { background: var(--gold); }
.saga-cap { font-size: 13px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.saga-all { color: var(--ink-3); }
.saga-strip.is-anim li i { animation: saga-fill .9s var(--ease-out, ease-out) both; animation-delay: calc(var(--d, 0) * 1ms + 200ms); }
@keyframes saga-fill { from { transform: scaleX(0); } }
:root[data-motion="still"] .saga-strip li i { animation: none; }
@media (prefers-reduced-motion: reduce) { .saga-strip li i { animation: none; } }

/* ---------- hero extras ---------- */
.hero-done {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 14px;
  padding: 4px 12px 4px 8px; border-radius: 999px;
  font-size: 13px; color: var(--ink-2); background: color-mix(in oklab, var(--gold) 15%, transparent);
}
.hero-done svg { width: 14px; height: 14px; color: var(--gold); }
.hero-done i { font-family: var(--serif); }
.hero-more svg { width: 18px; height: 18px; }

/* ---------- the book page ---------- */
.modal-book { padding-top: max(5vh, 20px); }
.modal-book .modal-card { width: min(940px, 100%); height: min(86vh, 820px); max-height: none; overflow: hidden; }
.bp-scroll { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); height: 100%; min-height: 0; }
.bp-main { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 20px; }

.bp-head { position: relative; isolation: isolate; display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 22px; align-items: end; padding: 34px 28px 20px; }
.bp-bd { position: absolute; z-index: -1; inset: 0; overflow: hidden; pointer-events: none; }
.bp-bd-img { position: absolute; inset: -20%; width: 140%; height: 140%; max-width: none; object-fit: cover; filter: blur(46px) saturate(1.5); opacity: .5; }
.bp-bd i { position: absolute; inset: 0; background:
  radial-gradient(90% 80% at 15% 0%, rgba(var(--c1, 178, 38, 46), var(--glow-a, .25)), transparent 70%),
  linear-gradient(to bottom, transparent 35%, var(--surface) 100%); }
:root[data-theme="light"] .bp-bd-img, :root[data-theme="sepia"] .bp-bd-img, :root[data-theme="parchment"] .bp-bd-img { opacity: .38; }
.bp-x { position: absolute; top: 12px; right: 12px; z-index: 2; background: color-mix(in oklab, var(--surface) 70%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.bp-cover img, .bp-cover .art { width: 128px; height: 128px; border-radius: 9px; object-fit: cover; box-shadow: 0 2px 6px rgba(var(--shade), .2), 0 18px 40px -14px rgba(var(--shade), .6); }
.bp-id { min-width: 0; }
.bp-kicker { margin: 0 0 4px; font-size: 12.5px; font-weight: 600; color: var(--crimson); }
.bp-title { margin: 0; font: 400 clamp(30px, 3.4vw, 40px)/1 var(--serif); font-variation-settings: "opsz" 60; letter-spacing: -0.02em; text-wrap: balance; }
.bp-author { margin: 6px 0 0; color: var(--ink-2); font-size: 14px; }
.bp-prog { margin-top: 14px; }
.bp-here { margin: 0 0 8px; font: italic 400 16px/1.3 var(--serif); color: var(--ink); }
.bp-here.bp-new { color: var(--ink-3); margin: 0; }
.bp-bar { height: 4px; border-radius: 4px; background: color-mix(in oklab, var(--line) 90%, transparent); overflow: hidden; }
.bp-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--crimson), var(--gold)); }
.bp-pct { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 8px 0 0; font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bp-pct b { color: var(--ink); font-weight: 650; }
.bp-done { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px 12px 4px 8px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--gold); background: color-mix(in oklab, var(--gold) 15%, transparent); }
.bp-done svg { width: 15px; height: 15px; }

.bp-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 28px 18px; }
.bp-act-sep { flex-basis: 100%; height: 0; }
.btn-ghost { height: 36px; padding: 0 12px 0 10px; font-size: 14px; gap: 6px; color: var(--ink-2); background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.btn-ghost svg { width: 16px; height: 16px; }
.btn-ghost:hover { color: var(--ink); background: var(--bg-2); }
.btn-ghost[aria-expanded="true"] { color: var(--crimson); background: var(--pill); box-shadow: none; }

.bp-confirm { margin: -4px 28px 18px; padding: 14px 16px; border-radius: 12px; font-size: 14px; line-height: 1.5; color: var(--ink-2); background: color-mix(in oklab, var(--crimson) 8%, var(--bg-2)); }
.bp-confirm p { margin: 0; }
.bp-confirm b { color: var(--ink); font-weight: 600; }
.bp-confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.bp-facts { margin: 0 28px; border-top: 1px solid var(--line); }
.bp-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.bp-row:last-child { border-bottom: 0; }
.bp-row dt { padding-top: 1px; font-size: 12.5px; font-weight: 600; color: var(--ink-3); }
.bp-row dd { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.bp-eds { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.bp-ed, .bp-fact { display: inline-flex; align-items: center; gap: 6px; }
.bp-ed svg { width: 15px; height: 15px; color: var(--gold); flex: none; }
.bp-fact svg { width: 15px; height: 15px; color: var(--ink-3); flex: none; }
.bp-ed b, .bp-fact b { color: var(--ink); font-weight: 600; }
.bp-ed.is-yours b { color: var(--crimson); }
.bp-ed.is-yours::after { content: "your place"; margin-left: 2px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; color: var(--crimson); background: var(--pill); }
.bp-ed.is-pending { color: var(--ink-3); }
.bp-soft { color: var(--ink-3); }

.bp-next { padding: 16px 28px 4px; }
.bp-next-card { display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 14px 10px 10px; border-radius: 14px; text-align: left; background: var(--bg-2); transition: background-color .2s, transform .15s var(--ease); }
.bp-next-card:hover { background: color-mix(in oklab, var(--bg-2) 80%, var(--ink) 7%); }
.bp-next-card:active { transform: scale(.99); }
.bp-next-card img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex: none; }
.bp-next-card > span { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bp-next-k { font-size: 12px; font-weight: 600; color: var(--crimson); }
.bp-next-t { font: 500 19px/1.2 var(--serif); }
.bp-next-card > svg { width: 34px; height: 34px; padding: 9px; border-radius: 50%; color: #FFF7F4; background: var(--crimson); flex: none; }

.bp-chs { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: color-mix(in oklab, var(--bg) 35%, var(--surface)); }
.bp-chs-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 22px 64px 12px 24px; }
.bp-chs-head h3 { margin: 0; font: 500 20px/1.2 var(--serif); font-variation-settings: "opsz" 32; }
.bp-chs-n { font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bp-list { flex: 1; min-height: 0; margin: 0; padding: 0 12px 24px; list-style: none; overflow-y: auto; overscroll-behavior: contain; }
.bp-part { padding: 16px 12px 6px; font-size: 11.5px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--gold); }
.bp-part:first-child { padding-top: 4px; }
.bp-ch { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; text-align: left; transition: background-color .15s; }
.bp-ch:hover { background: var(--bg-2); }
.bp-ch-t { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.bp-ch-n { flex: none; min-width: 1.7em; font: 600 12px/1 var(--ui); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bp-ch-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 400 16px/1.35 var(--serif); }
.bp-ch.is-done .bp-ch-name { color: var(--ink-2); }
.bp-ch.is-current { background: color-mix(in oklab, var(--crimson) 10%, transparent); }
.bp-ch.is-current .bp-ch-name { color: var(--crimson); font-weight: 500; }
.bp-ch-d { flex: none; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bp-ch-here { margin-right: 8px; font-weight: 650; color: var(--crimson); }
.bp-wait { display: grid; place-items: center; padding: 32px 12px; color: var(--ink-3); font-size: 14px; }
.bp-wait .loading { position: static; min-height: 0; padding: 0; }

:root[data-motion="still"] .modal-book .modal-card { transition: opacity .15s ease; transform: none; }

/* ---------- phones: a full-height sheet, one column ---------- */
@media (max-width: 720px), (pointer: coarse) and (max-height: 500px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 16px; }
  .shelf-head { gap: 12px 24px; }
  .saga { width: 100%; margin-left: 0; }
  .saga-strip { flex: 1; width: auto; }
  .hero-more { width: 44px; padding: 0; justify-content: center; }
  .hero-more span { display: none; }

  .modal-book { padding: 0; }
  .modal-book .modal-card {
    position: absolute; left: 0; right: 0; bottom: 0;
    top: calc(env(safe-area-inset-top) + 10px);
    width: 100%; height: auto; max-height: none;
    border-radius: 22px 22px 0 0;
    transform: translateY(100%); opacity: 1;
    transition: transform .45s var(--spring, var(--ease-out));
  }
  .modal-book.in .modal-card { transform: none; }
  .modal-book .sheet-grab { position: absolute; z-index: 3; top: 0; left: 50%; margin: 8px 0 0 -19px; background: color-mix(in oklab, var(--ink) 25%, transparent); }
  .bp-scroll { display: block; overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(env(safe-area-inset-bottom) + 24px); }
  .bp-main { overflow: visible; padding-bottom: 8px; }
  .bp-head { grid-template-columns: 96px minmax(0, 1fr); gap: 16px; padding: 34px 20px 16px; }
  .bp-cover img, .bp-cover .art { width: 96px; height: 96px; }
  .bp-title { font-size: 30px; }
  .bp-x { width: 44px; height: 44px; top: 14px; right: 12px; }
  .bp-actions { padding: 4px 20px 16px; }
  .bp-actions .btn-primary { flex: 1 1 auto; justify-content: center; }
  .btn-ghost { height: 40px; }
  .bp-confirm { margin: -4px 20px 16px; }
  .bp-facts { margin: 0 20px; }
  .bp-row { grid-template-columns: 84px minmax(0, 1fr); }
  .bp-next { padding: 14px 20px 4px; }
  .bp-chs { border-left: 0; border-top: 1px solid var(--line); margin-top: 12px; background: none; }
  .bp-chs-head { padding: 18px 20px 8px; }
  .bp-list { overflow: visible; padding: 0 8px; }
  .bp-ch { min-height: 50px; }
  .bp-ch-name { font-size: 17px; }
}
