/* ============================================================
   Inkshelf — quality-of-life additions: offline downloads, NEW badges,
   pull-to-refresh, offline banner, back-to-top, broken-page placeholder,
   chapter actions. Tokens only (base.css) so every data-scheme / data-style applies.
   ============================================================ */

/* ---------- long / unicode titles never break layouts ---------- */
.detail-page .dp-hero-title,
.quick-title,
.sheet-title,
.list-row-title,
.card-title,
.empty-title { overflow-wrap: anywhere; }
.detail-page .dp-hero-title { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.sheet-title { padding-left: 24px; padding-right: 24px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list-row-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- cover badges: NEW chapters / downloaded ---------- */
.cover .qol-new {
  position: absolute; right: 6px; top: 6px; z-index: 2;
  padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; line-height: 18px;
  color: var(--accent-contrast); background: var(--pink);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--pink) 45%, transparent);
}
.cover .qol-saved {
  position: absolute; right: 6px; bottom: 6px; z-index: 2;
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  color: var(--accent-light);
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  box-shadow: 0 0 0 1px var(--glass-border), var(--glass-shadow);
}
.cover .qol-saved .icon { width: 15px; height: 15px; }

/* ---------- offline banner ---------- */
.qol-offline {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  padding: 6px 6px 6px 14px; border-radius: 999px;
  font-size: 13.5px; color: var(--text); white-space: nowrap;
  border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
}
.qol-offline-text { overflow: hidden; text-overflow: ellipsis; }
.qol-offline-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--orange); box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 25%, transparent); }
.qol-offline-retry {
  flex-shrink: 0; height: 30px; padding: 0 14px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; color: var(--accent-contrast); background: var(--accent);
}
.qol-offline.is-busy .qol-offline-retry { opacity: .6; pointer-events: none; }
body[data-route="manga"] .qol-offline { bottom: calc(var(--dp-bar-h, 64px) + var(--safe-b) + 14px); }

/* ---------- back to top ---------- */
.qol-top {
  position: fixed; z-index: 60; right: 16px;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  color: var(--accent-light);
  border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
  animation: qol-pop .2s ease-out;
}
.qol-top:active { transform: scale(.92); }
.qol-top-icon { transform: rotate(90deg); width: 22px; height: 22px; }
body[data-route="manga"] .qol-top { bottom: calc(var(--dp-bar-h, 64px) + var(--safe-b) + 14px); }
body:has(.qol-offline:not([hidden])) .qol-top { bottom: calc(var(--tabbar-h) + var(--safe-b) + 64px); }
body[data-route="manga"]:has(.qol-offline:not([hidden])) .qol-top { bottom: calc(var(--dp-bar-h, 64px) + var(--safe-b) + 64px); }
@keyframes qol-pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- pull to refresh ---------- */
.qol-ptr {
  position: fixed; z-index: 45; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 56px);
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  transform: translate(-50%, -80px); opacity: 0; pointer-events: none;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), opacity .2s;
}
.qol-ptr.is-pulling { opacity: 1; transition: none; }
.qol-ptr.is-busy { opacity: 1; transform: translate(-50%, 8px); }
.qol-ptr-spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--surface-2); border-top-color: var(--accent);
  transform: rotate(calc(var(--ptr, 0) * 300deg));
}
.qol-ptr.is-ready .qol-ptr-spin { border-color: var(--accent-soft); border-top-color: var(--accent); }
.qol-ptr.is-busy .qol-ptr-spin { animation: spin .8s linear infinite; }

/* ---------- series page: download button with a progress ring ---------- */
.qol-dl-btn { position: relative; }
.qol-dl-btn.is-saved { color: var(--accent-light); }
.qol-dl-btn.is-running::after {
  content: ""; position: absolute; inset: 3px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(var(--accent-light) calc(var(--p, 0) * 1%), color-mix(in srgb, var(--accent-light) 18%, transparent) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
}
.qol-dl-btn.is-running .icon { transform: scale(.72); }

.qol-dl-sheet { padding: 4px 2px 6px; }
.qol-dl-status { text-align: center; color: var(--text-2); font-size: 15px; margin: 2px 8px 14px; }
.qol-progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 0 6px 18px; }
.qol-progress > i {
  display: block; height: 100%; border-radius: inherit; background: var(--accent);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--accent-contrast) 35%, transparent);
  transition: width .25s ease;
}
.qol-dl-footer { display: flex; gap: 14px; width: 100%; }

/* chapter rows */
.detail-page .qol-ch-dl { color: var(--muted); flex-shrink: 0; position: relative; }
.detail-page .qol-ch-dl .icon { width: 21px; height: 21px; }
.detail-page .qol-ch-dl.is-saved { color: var(--accent-light); }
.detail-page .qol-ch-dl.is-saved::before {
  content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--accent-soft); z-index: -1;
}
.detail-page .qol-ch-dl.is-queued { color: var(--accent-light); opacity: .55; }
.detail-page .qol-ch-dl.is-running { color: var(--accent-light); }
.detail-page .qol-ch-dl.is-running .icon { animation: qol-bob 1s ease-in-out infinite; }
@keyframes qol-bob { 50% { transform: translateY(3px); } }
.detail-page .qol-ch-empty { color: var(--orange); }

/* removed-from-library note */
.qol-notice {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 14px 0 4px; padding: 12px 14px; border-radius: var(--radius);
  font-size: 14px; color: var(--text-2);
  background: color-mix(in srgb, var(--orange) 12%, var(--glass-bg));
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid color-mix(in srgb, var(--orange) 30%, transparent);
}
.qol-notice .icon { color: var(--orange); width: 20px; height: 20px; margin-top: 1px; }

/* ---------- reader: page wrapper + broken-page placeholder ---------- */
.reader-strip .qol-page { position: relative; }
.qol-broken {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: min(280px, calc(100% - 32px)); padding: 16px 18px; border-radius: var(--radius-lg);
  text-align: center; font-size: 14px; color: var(--text);
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
}
.reader-paged .qol-broken { position: fixed; }
.qol-broken-retry { background: var(--accent); color: var(--accent-contrast); border-radius: 999px; min-width: 96px; }
.qol-reader-empty { min-height: 100vh; }

/* ---------- Lite: no blur, no decorative motion ---------- */
html[data-style="lite"] .qol-top,
html[data-style="lite"] .qol-ptr-spin { animation: none; }
html[data-style="lite"] .cover .qol-saved,
html[data-style="lite"] .qol-broken,
html[data-style="lite"] .qol-notice,
html[data-style="lite"] .qol-ptr { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--glass-strong); }
@media (prefers-reduced-motion: reduce) {
  .qol-top, .detail-page .qol-ch-dl.is-running .icon { animation: none; }
}
