/* Riffle viewer. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: #1f2933;
  background: #2b2f36;
  overflow: hidden;
}
.cfb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cfb-seo { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: normal; border: 0; }
.cfb-noscript { padding: 24px; color: #fff; }

.cfb {
  --cfb-bg: #2b2f36;
  --cfb-bar: #16191d;
  --cfb-fg: #e9edf1;
  --cfb-accent: #f8991c;
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  background: var(--cfb-bg);
  color: var(--cfb-fg);
}

/* Top bar */
.cfb-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 14px; background: var(--cfb-bar);
  padding-top: max(8px, env(safe-area-inset-top));
}
.cfb-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cfb-top-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Buttons */
.cfb-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; height: 40px; padding: 0 8px;
  border: 0; border-radius: 8px; background: transparent; color: inherit;
  font: inherit; font-size: 22px; line-height: 1; cursor: pointer; text-decoration: none;
}
.cfb-btn:hover { background: rgba(255,255,255,.1); }
.cfb-btn:focus-visible, .cfb-arrow:focus-visible, .cfb-pager input:focus-visible { outline: 2px solid var(--cfb-accent); outline-offset: 2px; }
.cfb-btn[disabled] { opacity: .35; cursor: default; }
.cfb-btn svg, .cfb-arrow svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* Stage */
.cfb-stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; }
.cfb-book-wrap { position: relative; transition: transform .45s ease; }
.cfb-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 5;
  width: 48px; height: 72px; border: 0; border-radius: 10px;
  background: rgba(0,0,0,.35); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.cfb-arrow:hover { background: rgba(0,0,0,.6); }
.cfb-arrow-prev { left: 10px; }
.cfb-arrow-next { right: 10px; }
.cfb-arrow[disabled] { opacity: 0; pointer-events: none; }

.cfb-loader { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }
.cfb[data-state="loading"] .cfb-loader { display: flex; }
/* Riffle loader: the logo's pages riffle closed and fan open (hover to speed up). */
.cfb-rl { display: grid; justify-items: center; gap: 14px; color: rgba(255,255,255,.72); font: 600 14px/1.4 Inter, system-ui, sans-serif; }
.cfb-rl .rl-mark { width: 60px; height: 60px; overflow: visible; filter: drop-shadow(0 10px 24px rgba(242,98,15,.4)); cursor: progress; }
.cfb-rl .rl-tile { transform-box: view-box; transform-origin: 32px 32px; animation: rlBreath 2.4s ease-in-out infinite; }
.cfb-rl .rl-p { transform-box: view-box; transform-origin: 33px 49px; animation: rlRiffle 1.6s cubic-bezier(.65,0,.35,1) infinite; }
.cfb-rl .rl-p1 { --a: -28deg; animation-delay: .16s; }
.cfb-rl .rl-p2 { --a: -10deg; animation-delay: .08s; }
.cfb-rl .rl-p3 { --a: 10deg; }
.cfb-rl:hover .rl-p { animation-duration: .7s; }
@keyframes rlRiffle { 0%, 100% { transform: rotate(var(--a)); } 38%, 52% { transform: rotate(10deg) translateY(-1px); } 72% { transform: rotate(calc(var(--a) - 6deg)); } }
@keyframes rlBreath { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@media (prefers-reduced-motion: reduce) { .cfb-rl .rl-p, .cfb-rl .rl-tile { animation: none; } .cfb-rl .rl-p { transform: rotate(var(--a)); } }
@keyframes cfb-spin { to { transform: rotate(360deg); } }

/* Pages */
.cfb-page { background: #fff; overflow: hidden; }
.cfb-page-inner { position: relative; width: 100%; height: 100%; }
.cfb-page img.cfb-page-img { display: block; width: 100%; height: 100%; object-fit: fill; user-select: none; -webkit-user-drag: none; }
.cfb-page-num { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 10px; color: #8a96a3; pointer-events: none; }
.cfb-hotspot {
  position: absolute; display: block; z-index: 2;
  border-radius: 3px; background: rgba(248,153,28,0); transition: background .15s ease;
}
.cfb-hotspot:hover, .cfb-hotspot:focus-visible { background: rgba(248,153,28,.22); outline: 2px solid rgba(248,153,28,.8); }
.cfb-hotspot-video { background: rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; border: 0; cursor: pointer; padding: 0; }
.cfb-hotspot-video::after {
  content: ""; width: 0; height: 0; margin-left: 6px;
  border-style: solid; border-width: 16px 0 16px 26px; border-color: transparent transparent transparent #fff;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.5));
}

/* Bottom bar */
.cfb-bar {
  display: flex; align-items: center; justify-content: center; gap: 2px; flex-wrap: wrap;
  padding: 6px 10px; background: var(--cfb-bar);
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}
.cfb-sep { width: 1px; height: 24px; background: rgba(255,255,255,.18); margin: 0 6px; }
.cfb-pager { display: flex; align-items: center; gap: 6px; margin: 0 6px; font-size: 14px; }
.cfb-pager input {
  width: 64px; height: 32px; text-align: center; font: inherit;
  border: 1px solid rgba(255,255,255,.25); border-radius: 6px; background: rgba(255,255,255,.08); color: inherit;
}

/* Side panels */
.cfb-panel {
  position: absolute; top: 0; bottom: 0; right: 0; z-index: 20;
  width: min(360px, 100%); background: #fff; color: #1f2933;
  display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0,0,0,.3);
}
.cfb-panel[hidden] { display: none; }
.cfb-panel .cfb-btn:hover { background: #eef1f4; }
.cfb-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid #e4e8ec; }
.cfb-thumb-grid { overflow-y: auto; padding: 14px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.cfb-thumb { border: 2px solid transparent; border-radius: 6px; padding: 0; background: none; cursor: pointer; text-align: center; font: inherit; font-size: 12px; color: #52606d; }
.cfb-thumb img { display: block; width: 100%; height: auto; border-radius: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.2); margin-bottom: 4px; background: #eee; }
.cfb-thumb[aria-current="true"] { border-color: var(--cfb-accent); }
.cfb-search-form { padding: 12px 14px; }
.cfb-search-form input { width: 100%; height: 40px; padding: 0 12px; font: inherit; border: 1px solid #cbd2d9; border-radius: 8px; }
.cfb-results { list-style: none; margin: 0; padding: 0 14px 14px; overflow-y: auto; }
.cfb-results li { margin-bottom: 8px; }
.cfb-results button { width: 100%; text-align: left; padding: 10px 12px; border: 1px solid #e4e8ec; border-radius: 8px; background: #f8fafb; cursor: pointer; font: inherit; font-size: 13px; color: #323f4b; }
.cfb-results button:hover { border-color: var(--cfb-accent); }
.cfb-results b { display: block; color: #0b3c5d; margin-bottom: 3px; }
.cfb-results mark { background: #ffe3b3; color: inherit; }
.cfb-results .cfb-empty { color: #7b8794; font-size: 13px; }

/* Zoom */
.cfb-zoom { position: absolute; inset: 0; z-index: 30; background: rgba(16,18,22,.97); display: flex; flex-direction: column; }
.cfb-zoom[hidden] { display: none; }
.cfb-zoom-tools { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px; font-size: 14px; }
.cfb-zoom-scroll { flex: 1; overflow: auto; cursor: grab; touch-action: pan-x pan-y; }
.cfb-zoom-scroll.dragging { cursor: grabbing; }
.cfb-zoom-pages { display: flex; gap: 0; margin: 0 auto; width: max-content; padding: 12px; }
.cfb-zoom-pages img { display: block; user-select: none; -webkit-user-drag: none; background: #fff; }

/* Video */
.cfb-video { position: absolute; inset: 0; z-index: 40; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; padding: 16px; }
.cfb-video[hidden] { display: none; }
.cfb-video-box { position: relative; width: min(960px, 100%); }
.cfb-video-frame { position: relative; padding-top: 56.25%; background: #000; }
.cfb-video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.cfb-video-close { position: absolute; top: -46px; right: 0; color: #fff; }

/* Toast */
.cfb-toast {
  position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%) translateY(20px);
  background: #fff; color: #1f2933; padding: 8px 14px; border-radius: 8px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.cfb-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .cfb-btn { min-width: 34px; height: 38px; padding: 0 4px; }
  .cfb-top { padding-left: 10px; padding-right: 6px; }
  .cfb-title { font-size: 14px; }
  .cfb-arrow { width: 36px; height: 56px; }
  .cfb-arrow-prev { left: 4px; }
  .cfb-arrow-next { right: 4px; }
  .cfb-bar .cfb-btn[data-action="first"], .cfb-bar .cfb-btn[data-action="last"] { display: none; }
  .cfb-sep { margin: 0 2px; }
  .cfb-pager input { width: 52px; }
}

/* Progressive page loading: blurred thumbnail first, full page fades in over it. */
.cfb-page-inner { background: #fff center / 100% 100% no-repeat; }
.cfb-page-inner.cfb-loading::before { content: ""; position: absolute; inset: 0; background: inherit; filter: blur(6px); transform: scale(1.04); }
.cfb-page img.cfb-page-img { position: relative; opacity: 0; transition: opacity .25s ease; color: transparent; }
.cfb-page img.cfb-page-img.cfb-in { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .cfb-page img.cfb-page-img { transition: none; } }

/* "Made with Riffle" credit (owner can turn it off) */
.cfb-credit { flex-shrink: 0; margin-right: 8px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; color: rgba(255,255,255,.72); text-decoration: none; border: 1px solid rgba(255,255,255,.16); white-space: nowrap; transition: color .15s, border-color .15s; }
.cfb-credit:hover, .cfb-credit:focus-visible { color: #fff; border-color: rgba(255,255,255,.4); }
@media (max-width: 560px) { .cfb-credit { display: none; } }

/* Free-plan badge (can't be turned off) */
.cfb-wm { position: fixed; left: 12px; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 60; display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: rgba(11, 22, 36, .86); border: 1px solid rgba(255, 255, 255, .14); color: #fff; text-decoration: none; font: 500 12px/1.2 Inter, system-ui, -apple-system, sans-serif; box-shadow: 0 8px 24px rgba(0, 0, 0, .28); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); transition: transform .15s, background .15s; }
.cfb-wm:hover, .cfb-wm:focus-visible { background: rgba(11, 22, 36, .96); transform: translateY(-2px); }
.cfb-wm svg { width: 26px; height: 26px; flex-shrink: 0; }
.cfb-wm span { display: grid; }
.cfb-wm b { font-weight: 700; }
.cfb-wm small { font-size: 11px; color: #ffcf8a; }
@media print { .cfb-wm { display: none; } }
@media (max-width: 560px) { .cfb-wm { bottom: calc(100px + env(safe-area-inset-bottom)); left: 8px; padding: 4px 10px 4px 4px; } .cfb-wm svg { width: 22px; height: 22px; } }

/* Buttons the viewer turns off (e.g. download) must stay hidden. */
.cfb-btn[hidden], .cfb-top [hidden] { display: none !important; }

/* 1.6.6: share menu */
.cfb-top { position: relative; }
.cfb-share { position: absolute; top: calc(100% + 6px); right: 12px; z-index: 40; min-width: 220px; padding: 6px; border-radius: 12px; background: #fff; box-shadow: 0 18px 40px rgba(0,0,0,.35); display: flex; flex-direction: column; }
.cfb-share[hidden] { display: none; }
.cfb-share a, .cfb-share button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: #1f2933; font: 500 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; text-decoration: none; cursor: pointer; }
.cfb-share a:hover, .cfb-share button:hover, .cfb-share a:focus-visible, .cfb-share button:focus-visible { background: #fff3ea; color: #c2410c; outline: none; }
.cfb-share .cfb-share-report { margin-top: 4px; border-top: 1px solid #e4e7eb; border-radius: 0 0 8px 8px; color: #7b8794; font-size: 13px; }

/* 1.6.6: on phones the side arrows stay small and see-through so they don't cover the page; swipe and the bottom bar do the work. */
@media (max-width: 640px) {
  .cfb-arrow { width: 28px; height: 44px; background: rgba(0,0,0,.28); }
  .cfb-arrow svg { width: 18px; height: 18px; }
  .cfb-arrow-prev { left: 2px; }
  .cfb-arrow-next { right: 2px; }
}

/* 1.6.9: hover magnifier */
.cfb-lens { position: fixed; left: 0; top: 0; z-index: 55; width: 240px; height: 240px; border-radius: 50%; pointer-events: none; background-color: #fff; background-repeat: no-repeat; border: 3px solid rgba(255,255,255,.95); box-shadow: 0 0 0 1px rgba(0,0,0,.18), 0 18px 40px rgba(0,0,0,.45); opacity: 0; transition: opacity .15s ease; will-change: transform; }
.cfb-lens.on { opacity: 1; }
.cfb-btn[aria-pressed="false"].cfb-lens-btn { opacity: .55; }
.cfb-btn[aria-pressed="true"].cfb-lens-btn { color: var(--cfb-accent, #ffb03b); }
@media (hover: none), (pointer: coarse) { .cfb-lens, .cfb-lens-btn { display: none !important; } }
@media print { .cfb-lens { display: none; } }
