:root {
    --bg: #0c111b;
    --panel: #121a27;
    --panel-2: #182235;
    --text: #f4f6f8;
    --muted: #9aa7b7;
    --line: rgba(255,255,255,.1);
    --accent: #f1b23c;
    --accent-ink: #16110a;
    --danger: #ff7474;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { color: inherit; }

.library-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 64px 0 80px; }
.hero { margin-bottom: 34px; }
.eyebrow { color: var(--accent); font-size: 12px; letter-spacing: .16em; font-weight: 800; }
.hero h1 { font-size: clamp(36px, 6vw, 72px); letter-spacing: -.04em; margin: 10px 0 12px; }
.hero p { color: var(--muted); margin: 0; font-size: 17px; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 22px; }
.book-card { border: 1px solid var(--line); border-radius: 22px; overflow: hidden; background: var(--panel); }
.book-cover { display: block; aspect-ratio: 4 / 5.35; background: #202b3d; overflow: hidden; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; display:block; }
.cover-placeholder { width:100%; height:100%; display:grid; place-items:center; background: radial-gradient(circle at 30% 20%, #2f405b, #111827 65%); }
.cover-placeholder span { font-size: 48px; font-weight: 900; letter-spacing: -.06em; opacity: .18; }
.book-meta { padding: 18px; }
.book-meta h2 { margin:0 0 8px; font-size: 19px; }
.book-meta p { color: var(--muted); min-height: 42px; margin:0 0 16px; line-height:1.5; font-size:14px; }
.primary-btn { display:inline-flex; min-height:42px; align-items:center; justify-content:center; background: var(--accent); color: var(--accent-ink); font-weight:800; border-radius: 12px; padding: 0 15px; }
.is-missing .book-cover { opacity:.45; }
.missing-note { color: var(--danger); font-size: 13px; overflow-wrap:anywhere; }
.alert { border:1px solid rgba(255,116,116,.4); background:rgba(255,116,116,.08); color:#ffd1d1; padding:14px 16px; border-radius:14px; margin-bottom:20px; }

.viewer-page { height: 100dvh; overflow: hidden; }
.viewer-header { height: 64px; display:flex; align-items:center; gap:12px; padding: 0 14px; border-bottom:1px solid var(--line); background:rgba(12,17,27,.92); backdrop-filter: blur(14px); position:relative; z-index:30; }
.viewer-title-wrap { min-width:0; flex:1; }
.viewer-title { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; font-weight:800; }
.viewer-subtitle { color:var(--muted); font-size:12px; margin-top:2px; }
.header-actions { display:flex; gap:8px; }
.icon-button, .control-btn { border:1px solid var(--line); background:var(--panel); border-radius:12px; min-width:42px; height:42px; display:inline-grid; place-items:center; cursor:pointer; }
.icon-button:hover, .control-btn:hover { background:var(--panel-2); }
.icon-button.small { min-width:34px; height:34px; }
.viewer-shell { height: calc(100dvh - 64px); display:grid; grid-template-rows: 1fr 62px; position:relative; }
.stage { min-height:0; overflow:auto; display:grid; place-items:center; padding:20px; position:relative; }
.book { transform-origin:center center; transition: transform .18s ease; }
.page { background:#fff; overflow:hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.page canvas { width:100%; height:100%; object-fit:contain; display:block; background:#fff; }
.loading-card { position:absolute; inset:auto; z-index:10; display:flex; align-items:center; gap:12px; color:var(--muted); background:var(--panel); border:1px solid var(--line); padding:12px 16px; border-radius:14px; }
.spinner { width:18px; height:18px; border:2px solid rgba(255,255,255,.18); border-top-color:var(--accent); border-radius:50%; animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
.viewer-controls { border-top:1px solid var(--line); background:rgba(12,17,27,.96); display:flex; align-items:center; justify-content:center; gap:8px; padding:9px 12px; z-index:25; }
.control-btn { font-size:24px; }
.control-btn.compact { min-width:36px; height:36px; font-size:20px; }
.page-jump { height:38px; border:1px solid var(--line); background:var(--panel); border-radius:12px; display:flex; align-items:center; gap:6px; padding:0 11px; color:var(--muted); }
.page-jump input { width:45px; border:0; outline:0; background:transparent; color:var(--text); text-align:right; appearance:textfield; }
.page-jump input::-webkit-inner-spin-button { appearance:none; }
.divider { width:1px; height:28px; background:var(--line); margin:0 3px; }
.zoom-label { width:48px; text-align:center; font-size:12px; color:var(--muted); }
.thumb-panel { position:absolute; top:0; bottom:62px; left:0; width:min(320px, 85vw); z-index:40; background:rgba(18,26,39,.98); border-right:1px solid var(--line); transform:translateX(-101%); transition:transform .22s ease; display:flex; flex-direction:column; box-shadow: 20px 0 50px rgba(0,0,0,.35); }
.thumb-panel.open { transform:translateX(0); }
.thumb-panel-head { height:54px; flex:none; display:flex; align-items:center; justify-content:space-between; padding:0 12px 0 16px; border-bottom:1px solid var(--line); }
.thumb-list { padding:12px; overflow:auto; display:grid; grid-template-columns:repeat(2,1fr); gap:10px; }
.thumb-item { border:1px solid var(--line); border-radius:10px; overflow:hidden; background:#fff; cursor:pointer; position:relative; }
.thumb-item canvas { width:100%; display:block; }
.thumb-item span { position:absolute; bottom:5px; right:5px; background:rgba(0,0,0,.72); color:#fff; padding:2px 6px; border-radius:6px; font-size:11px; }
.thumb-item.active { outline:2px solid var(--accent); outline-offset:1px; }

@media (max-width: 700px) {
    .viewer-header { height:58px; }
    .viewer-shell { height:calc(100dvh - 58px); grid-template-rows:1fr 58px; }
    .stage { padding:10px 6px; }
    .viewer-controls { padding:7px 8px; }
    .zoom-label { display:none; }
    .divider { margin:0; }
    .icon-button { min-width:38px; height:38px; }
    .control-btn { min-width:40px; height:40px; }
    .viewer-title { font-size:14px; }
    .thumb-panel { bottom:58px; }
}

/* ===== V2.1: headerless viewer + iframe embed ===== */
.viewer-page { height: 100dvh; overflow: hidden; }
.viewer-page .viewer-header { display: none !important; }
.viewer-shell { height: 100dvh; grid-template-rows: 1fr 62px; }
.thumb-panel { top: 0; bottom: 62px; }

/* Khi nhúng vào website chính, flipbook chiếm đúng khung iframe */
.embed-mode,
.embed-mode .viewer-shell { width: 100%; height: 100dvh; }
.embed-mode .stage { padding-top: 8px; }

@media (max-width: 700px) {
    .viewer-shell { height: 100dvh; grid-template-rows: 1fr 58px; }
    .thumb-panel { bottom: 58px; }
    .viewer-controls { gap: 6px; }
    .viewer-controls .divider:nth-of-type(2) { display: none; }
}
\n\n/* ===== V2.2: fit toàn bộ trang ở mức zoom 100% ===== */
.stage {
    overflow: auto;
    padding: 14px 18px;
    align-content: center;
    justify-content: center;
}
.book {
    max-width: none;
    max-height: none;
    flex: none;
}

@media (max-width: 700px) {
    .stage { padding: 8px; }
}
