/* MagFlip engine v1 — reader styles. One file for every issue. */
.mf, .mf * { box-sizing: border-box; }
.mf {
  --mf-accent: #d6a419;
  --mf-bg: #15171b;
  --mf-panel: #1d2026;
  --mf-ink: #e8eaee;
  --mf-muted: #9aa3b2;
  --mf-top: 52px;
  --mf-bar: 56px;
  position: fixed; inset: 0; display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% 40%, #23262d 0%, var(--mf-bg) 70%);
  color: var(--mf-ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden; user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.mf[data-inline] { position: relative; height: 100%; }
.mf button { font: inherit; color: inherit; }
.mf svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* ---- top bar ---- */
.mf-top { height: var(--mf-top); flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: rgba(0,0,0,.35); border-bottom: 1px solid rgba(255,255,255,.06); z-index: 6; }
/* Brand slot: the logo fits inside the top bar (52px, 46px on phones) */
.mf-brand { flex: 0 0 auto; display: flex; align-items: center; height: 100%; }
.mf-brand img { height: 34px; max-height: calc(var(--mf-top) - 12px); width: auto; display: block; }
.mf-brand-link { display: flex; align-items: center; height: 100%; padding: 0 4px; border-radius: 8px; opacity: .95; transition: background .15s, opacity .15s; }
.mf-brand-link:hover { background: rgba(255,255,255,.1); opacity: 1; }
.mf-brand-link:focus-visible { outline: 2px solid var(--mf-accent); outline-offset: 2px; }
.mf-title { flex: 1 1 auto; min-width: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mf-actions { display: flex; gap: 2px; }

/* ---- buttons ---- */
.mf-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; opacity: .85; transition: background .15s, opacity .15s; }
.mf-btn:hover { background: rgba(255,255,255,.1); opacity: 1; }
.mf-btn:focus-visible { outline: 2px solid var(--mf-accent); outline-offset: 2px; }
.mf-btn[disabled] { opacity: .25; cursor: default; background: transparent; }
.mf-btn.mf-on { color: var(--mf-accent); opacity: 1; }

/* ---- stage + book ---- */
.mf-stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 18px 56px; }
.mf-book { position: relative; perspective: 2600px; transform-style: preserve-3d; filter: drop-shadow(0 18px 40px rgba(0,0,0,.55)); }
.mf-page { position: absolute; top: 0; height: 100%; width: 100%; background: #fff; overflow: hidden; }
.mf[data-mode="spread"] .mf-page { width: 50%; }
.mf[data-mode="spread"] .mf-left { left: 0; border-radius: 3px 0 0 3px; }
.mf[data-mode="spread"] .mf-right { left: 50%; border-radius: 0 3px 3px 0; }
.mf[data-mode="single"] .mf-page { left: 0; border-radius: 3px; }
.mf-page.mf-blank { background: transparent; }
.mf-page img { display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
/* faint spine shading on spreads */
.mf[data-mode="spread"] .mf-left::after, .mf[data-mode="spread"] .mf-right::after { content: ""; position: absolute; top: 0; bottom: 0; width: 6%; pointer-events: none; }
.mf[data-mode="spread"] .mf-left::after { right: 0; background: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,.16)); }
.mf[data-mode="spread"] .mf-right::after { left: 0; background: linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,.16)); }

/* link hotspots */
.mf-links { position: absolute; inset: 0; }
.mf-link { position: absolute; display: block; border: 0; padding: 0; margin: 0; background: transparent; border-radius: 3px; cursor: pointer; transition: background .15s, box-shadow .15s; }
.mf-link:hover, .mf-link:focus-visible { background: color-mix(in srgb, var(--mf-accent) 22%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--mf-accent) 65%, transparent); outline: 0; }
.mf-hint-links .mf-link { background: color-mix(in srgb, var(--mf-accent) 18%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--mf-accent) 60%, transparent); }

/* the turning leaf */
.mf-leaf { position: absolute; top: 0; width: 50%; height: 100%; transform-style: preserve-3d; transition: transform .7s cubic-bezier(.38,.08,.22,1); z-index: 5; will-change: transform; }
.mf-leaf-fwd { left: 50%; transform-origin: left center; transform: rotateY(0deg); }
.mf-leaf-fwd.mf-turning { transform: rotateY(-180deg); }
.mf-leaf-back { left: 0; transform-origin: right center; transform: rotateY(0deg); }
.mf-leaf-back.mf-turning { transform: rotateY(180deg); }
.mf-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; background: #fff; }
.mf-face .mf-page { width: 100% !important; left: 0 !important; border-radius: 0; }
.mf-face .mf-page::after { display: none; }
.mf-face-back { transform: rotateY(180deg); }
.mf-face::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .7s; background: linear-gradient(to right, rgba(0,0,0,.28), rgba(0,0,0,0) 45%); }
.mf-leaf-fwd .mf-face-front::before { background: linear-gradient(to left, rgba(0,0,0,0) 55%, rgba(0,0,0,.28)); }
.mf-leaf.mf-turning .mf-face::before { opacity: 1; }

/* single-page slide */
.mf[data-mode="single"] .mf-page { transition: transform .32s ease, opacity .32s ease; }
.mf-enter-right { transform: translateX(6%); opacity: 0; }
.mf-enter-left { transform: translateX(-6%); opacity: 0; }
.mf-exit-left { transform: translateX(-6%) !important; opacity: 0 !important; }
.mf-exit-right { transform: translateX(6%) !important; opacity: 0 !important; }

/* edge arrows */
.mf-edge { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border-radius: 12px; z-index: 4; }
.mf-edge-prev { left: 8px; }
.mf-edge-next { right: 8px; }

/* ---- bottom bar ---- */
.mf-bar { height: var(--mf-bar); flex: 0 0 auto; display: flex; align-items: center; justify-content: center; gap: 2px; padding: 0 8px; background: rgba(0,0,0,.35); border-top: 1px solid rgba(255,255,255,.06); z-index: 6; }
.mf-sep { width: 1px; height: 24px; background: rgba(255,255,255,.12); margin: 0 6px; }
.mf-pagebox { display: flex; align-items: center; gap: 6px; margin: 0 6px; }
.mf-pagebox input { width: 64px; height: 32px; text-align: center; border: 1px solid rgba(255,255,255,.18); border-radius: 8px; background: rgba(0,0,0,.3); color: var(--mf-ink); font: inherit; font-variant-numeric: tabular-nums; }
.mf-pagebox input:focus { outline: 2px solid var(--mf-accent); border-color: transparent; }
.mf-pagecount { color: var(--mf-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- thumbnails ---- */
.mf-thumbs { flex: 0 0 auto; height: 0; overflow: hidden; background: rgba(0,0,0,.45); transition: height .25s ease; }
.mf.mf-thumbs-open .mf-thumbs { height: 158px; border-top: 1px solid rgba(255,255,255,.06); }
.mf-thumbstrip { display: flex; gap: 10px; height: 158px; padding: 12px 14px; overflow-x: auto; overflow-y: hidden; scroll-behavior: smooth; }
.mf-thumb { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: transparent; cursor: pointer; padding: 0; color: var(--mf-muted); font-size: 11px; }
.mf-thumb img { height: 108px; width: auto; display: block; border-radius: 2px; box-shadow: 0 2px 8px rgba(0,0,0,.5); outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .15s, transform .15s; background: #fff; }
.mf-thumb:hover img { transform: translateY(-2px); }
.mf-thumb.mf-current img { outline-color: var(--mf-accent); }
.mf-thumb.mf-current { color: var(--mf-accent); }

/* ---- side panels ---- */
.mf-panel { position: absolute; top: var(--mf-top); bottom: 0; width: 340px; max-width: 88vw; background: var(--mf-panel); box-shadow: 0 0 40px rgba(0,0,0,.5); z-index: 8; display: flex; flex-direction: column; transition: transform .28s ease; }
.mf-panel-toc { left: 0; transform: translateX(-105%); }
.mf-panel-search { right: 0; transform: translateX(105%); }
.mf-panel.mf-open { transform: none; }
.mf-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 10px 16px; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,.07); }
.mf-panel-body { flex: 1 1 auto; overflow-y: auto; padding: 8px 0; }
.mf-toc-item { display: flex; gap: 12px; align-items: baseline; width: 100%; text-align: left; padding: 9px 16px; border: 0; background: transparent; cursor: pointer; line-height: 1.35; }
.mf-toc-item:hover { background: rgba(255,255,255,.06); }
.mf-toc-item .mf-toc-page { flex: 0 0 auto; min-width: 30px; text-align: right; color: var(--mf-accent); font-variant-numeric: tabular-nums; font-weight: 600; }
.mf-toc-item .mf-toc-title { flex: 1 1 auto; }
.mf-empty { padding: 20px 16px; color: var(--mf-muted); }
.mf-search-form { display: flex; gap: 6px; padding: 12px 16px; }
.mf-search-form input { flex: 1 1 auto; height: 38px; padding: 0 12px; border: 1px solid rgba(255,255,255,.18); border-radius: 9px; background: rgba(0,0,0,.3); color: var(--mf-ink); font: inherit; }
.mf-search-form input:focus { outline: 2px solid var(--mf-accent); border-color: transparent; }
.mf-search-count { padding: 0 16px 8px; color: var(--mf-muted); font-size: 12.5px; }
.mf-result { display: block; width: 100%; text-align: left; padding: 10px 16px; border: 0; background: transparent; cursor: pointer; border-top: 1px solid rgba(255,255,255,.05); }
.mf-result:hover { background: rgba(255,255,255,.06); }
.mf-result-page { display: block; color: var(--mf-accent); font-weight: 600; font-size: 12px; margin-bottom: 2px; }
.mf-result-snip { display: block; color: var(--mf-muted); font-size: 13px; line-height: 1.4; }
.mf-result-snip mark { background: color-mix(in srgb, var(--mf-accent) 35%, transparent); color: var(--mf-ink); border-radius: 2px; padding: 0 1px; }

/* ---- zoom overlay ---- */
.mf-zoom { position: absolute; inset: 0; z-index: 12; background: #0b0c0f; display: flex; flex-direction: column; }
.mf-zoom[hidden] { display: none; }
.mf-zoom-tools { flex: 0 0 auto; height: var(--mf-top); display: flex; align-items: center; justify-content: center; gap: 4px; background: rgba(0,0,0,.4); }
.mf-zoom-level { min-width: 52px; text-align: center; color: var(--mf-muted); font-variant-numeric: tabular-nums; }
.mf-zoom-scroll { flex: 1 1 auto; overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y; cursor: grab; }
.mf-zoom-scroll.mf-dragging { cursor: grabbing; }
.mf-zoom-inner { position: relative; margin: 0 auto; display: flex; }
.mf-zoom-inner .mf-page { position: relative; flex: 1 1 0; height: auto; width: auto; }
.mf-zoom-inner .mf-page img { height: auto; }

/* ---- misc ---- */
.mf-loader { position: absolute; inset: 0; display: grid; place-items: center; background: var(--mf-bg); z-index: 20; transition: opacity .3s; }
.mf-loader.mf-hide { opacity: 0; pointer-events: none; }
.mf-spinner { width: 42px; height: 42px; border-radius: 50%; border: 3px solid rgba(255,255,255,.12); border-top-color: var(--mf-accent); animation: mf-spin .9s linear infinite; }
@keyframes mf-spin { to { transform: rotate(360deg); } }
.mf-toast { position: absolute; left: 50%; bottom: calc(var(--mf-bar) + 16px); transform: translate(-50%, 10px); background: rgba(0,0,0,.85); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 30; }
.mf-toast.mf-show { opacity: 1; transform: translate(-50%, 0); }
.mf-error { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--mf-muted); z-index: 21; }

@media (prefers-reduced-motion: reduce) {
  .mf-leaf, .mf-panel, .mf-thumbs, .mf[data-mode="single"] .mf-page { transition: none !important; }
}
@media (max-width: 720px) {
  .mf { --mf-top: 46px; --mf-bar: 52px; }
  .mf-stage { padding: 10px 8px; }
  .mf-edge { display: none; }
  .mf-btn { width: 36px; height: 36px; }
  .mf-pagebox input { width: 54px; }
  .mf-hide-sm { display: none; }
  .mf.mf-thumbs-open .mf-thumbs { height: 122px; }
  .mf-thumbstrip { height: 122px; padding: 10px; }
  .mf-thumb img { height: 80px; }
}
