:root {
    --fb-bg1: #2b3444;
    --fb-bg2: #12161f;
    --fb-bar: rgba(18, 22, 31, .82);
    --fb-line: rgba(255, 255, 255, .10);
    --fb-text: #eef1f6;
    --fb-muted: #9aa3b2;
    --fb-accent: #ff9f43;
    --fb-flip-ms: 1100ms;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--fb-bg2);
    color: var(--fb-text);
    font-family: 'Anuphan', system-ui, sans-serif;
}

.fb-app {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background:
        radial-gradient(ellipse at 50% 38%, var(--fb-bg1) 0%, #1b212d 55%, var(--fb-bg2) 100%);
}

/* ---------- top bar ---------- */
.fb-top {
    flex: 0 0 52px;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background: var(--fb-bar);
    border-bottom: 1px solid var(--fb-line);
    backdrop-filter: blur(10px);
    z-index: 30;
}
.fb-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--fb-text);
    text-decoration: none;
    flex: 0 0 auto;
}
.fb-brand-mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    display: grid; place-items: center;
    font-weight: 700;
    background: linear-gradient(135deg, #1d4f91, #3a7bd5);
}
.fb-brand-text { font-size: 14px; font-weight: 600; }
.fb-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 15px;
    font-weight: 500;
    color: var(--fb-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fb-top-actions { display: flex; gap: 6px; flex: 0 0 auto; }

/* ---------- buttons ---------- */
.fb-btn {
    width: 36px; height: 36px;
    display: inline-grid;
    place-items: center;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--fb-text);
    cursor: pointer;
    transition: background .15s, color .15s;
    text-decoration: none;
}
.fb-btn svg { width: 19px; height: 19px; }
.fb-btn:hover { background: rgba(255, 255, 255, .1); }
.fb-btn.is-active { color: var(--fb-accent); background: rgba(255, 159, 67, .12); }
.fb-btn:disabled { opacity: .35; cursor: default; background: transparent; }

/* ---------- stage ---------- */
.fb-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
.fb-viewport {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
}
.fb-viewport.is-zoomed { cursor: grab; }
.fb-viewport.is-panning { cursor: grabbing; }
.fb-pan {
    transform-origin: 50% 50%;
    transition: transform .35s ease;
}
.fb-pan.no-anim { transition: none; }

.fb-book {
    position: relative;
    perspective: 2600px;
    transition: transform .6s cubic-bezier(.4, .1, .2, 1), opacity .3s;
    opacity: 0;
}
.fb-book.is-ready { opacity: 1; }
.fb-book.no-anim, .fb-book.no-anim .fb-leaf { transition: none !important; }

/* page stacks give thickness + drop shadow */
.fb-stack {
    position: absolute;
    top: 0;
    height: 100%;
    background: #fdfdfb;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .35);
    transition: opacity .3s;
}
.fb-stack-left  { left: 0; border-radius: 3px 0 0 3px; }
.fb-stack-right { border-radius: 0 3px 3px 0; }
.fb-stack-left::before, .fb-stack-right::before {
    content: "";
    position: absolute;
    top: 3px; bottom: 3px;
    width: 4px;
    background: repeating-linear-gradient(90deg, #d9d9d4 0 1px, #f7f7f3 1px 2px);
}
.fb-stack-left::before  { left: -4px; border-radius: 2px 0 0 2px; }
.fb-stack-right::before { right: -4px; border-radius: 0 2px 2px 0; }
.fb-stack.is-empty { opacity: 0; }

/* ---------- leaves ---------- */
.fb-leaf {
    position: absolute;
    top: 0;
    height: 100%;
    transform-origin: 0 50%;
    transform-style: preserve-3d;
    transition: transform var(--fb-flip-ms) cubic-bezier(.4, .05, .2, 1);
    cursor: pointer;
}
.fb-leaf.is-flipped { transform: rotateY(-180deg); }
.fb-leaf.is-dragging { transition: none; }

.fb-face {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #fff;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.fb-face.back { transform: rotateY(180deg); }
.fb-face canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    opacity: .74;
}
.fb-face .fb-ph {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #b8bec8;
    font-size: 13px;
    background: #f6f7f9;
}

/* spine gutter shading */
.fb-face::after {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    width: 12%;
    pointer-events: none;
    z-index: 2;
}
.fb-face.front::after { left: 0;  background: linear-gradient(90deg, rgba(0,0,0,.22), rgba(0,0,0,.06) 35%, transparent); }
.fb-face.back::after  { right: 0; background: linear-gradient(270deg, rgba(0,0,0,.22), rgba(0,0,0,.06) 35%, transparent); }
.fb-face.is-cover::after { display: none; }

/* moving light / shadow while turning */
.fb-shade {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
}
.fb-face.front .fb-shade { background: linear-gradient(90deg, rgba(0,0,0,.35), rgba(0,0,0,0) 70%); }
.fb-face.back  .fb-shade { background: linear-gradient(270deg, rgba(255,255,255,.0), rgba(0,0,0,.28)); }

/* ---------- side nav arrows ---------- */
.fb-side-nav {
    position: absolute;
    top: 50%;
    z-index: 20;
    width: 46px; height: 76px;
    margin-top: -38px;
    border: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, .06);
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background .2s, opacity .2s;
}
.fb-side-nav svg { width: 28px; height: 28px; }
.fb-side-nav:hover { background: rgba(255, 255, 255, .16); }
.fb-side-nav:disabled { opacity: 0; pointer-events: none; }
.fb-side-prev { left: 14px; }
.fb-side-next { right: 14px; }

/* ---------- loading ---------- */
.fb-loading {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    transition: opacity .4s;
}
.fb-loading.is-hidden { opacity: 0; pointer-events: none; }
.fb-loading.is-hidden .fb-loading-book span { animation: none; }
.fb-loading-book { position: relative; width: 64px; height: 44px; perspective: 300px; }
.fb-loading-book span {
    position: absolute;
    left: 50%; top: 0;
    width: 50%; height: 100%;
    background: #e9edf3;
    border-radius: 0 3px 3px 0;
    transform-origin: 0 50%;
    animation: fbLoadFlip 1.5s ease-in-out infinite;
}
.fb-loading-book span:nth-child(2) { animation-delay: .25s; background: #d4dbe5; }
.fb-loading-book span:nth-child(3) { animation-delay: .5s;  background: #c0c9d6; }
@keyframes fbLoadFlip { 0%, 15% { transform: rotateY(0); } 60%, 100% { transform: rotateY(-180deg); } }
.fb-loading-text { color: var(--fb-muted); font-size: 14px; }
.fb-progress { width: 220px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden; }
.fb-progress-bar { width: 0; height: 100%; background: var(--fb-accent); transition: width .2s; }
.fb-loading.is-error .fb-loading-book, .fb-loading.is-error .fb-progress { display: none; }
.fb-loading.is-error .fb-loading-text { color: #ffb4a8; }

/* ---------- thumbnails ---------- */
.fb-thumbs {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: 300px;
    max-width: 86vw;
    z-index: 26;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: rgba(18, 22, 31, .94);
    border-right: 1px solid var(--fb-line);
    backdrop-filter: blur(12px);
    transform: translateX(-105%);
    transition: transform .3s ease;
}
.fb-thumbs.is-open { transform: none; }
.fb-thumbs-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 10px 10px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--fb-line);
}
.fb-thumbs-head span { display: flex; align-items: center; gap: 8px; }
.fb-thumbs-head span svg { width: 16px; height: 16px; }
.fb-thumbs-grid {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 12px;
    align-content: start;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.2) transparent;
}
.fb-thumb {
    border: 0;
    padding: 0;
    background: none;
    color: var(--fb-muted);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    text-align: center;
}
.fb-thumb-img {
    position: relative;
    display: block;
    background: #e9ecf1;
    border-radius: 3px;
    overflow: hidden;
    outline: 2px solid transparent;
    outline-offset: 2px;
    transition: outline-color .15s, transform .15s;
    margin-bottom: 5px;
}
.fb-thumb-img canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.fb-thumb:hover .fb-thumb-img { transform: translateY(-2px); }
.fb-thumb.is-current { color: var(--fb-accent); }
.fb-thumb.is-current .fb-thumb-img { outline-color: var(--fb-accent); }

/* ---------- bottom bar ---------- */
.fb-bar {
    flex: 0 0 56px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    background: var(--fb-bar);
    border-top: 1px solid var(--fb-line);
    backdrop-filter: blur(10px);
    z-index: 30;
}
.fb-bar-group { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.fb-pageinfo {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 4px;
    font-size: 14px;
}
.fb-pageinfo input {
    width: 72px;
    height: 30px;
    border-radius: 7px;
    border: 1px solid var(--fb-line);
    background: rgba(255, 255, 255, .06);
    color: var(--fb-text);
    text-align: center;
    font: inherit;
    font-size: 14px;
}
.fb-pageinfo input:focus { outline: none; border-color: var(--fb-accent); }
.fb-pagetotal { color: var(--fb-muted); white-space: nowrap; }
.fb-pagetotal b { color: var(--fb-text); font-weight: 500; }
.fb-zoom-label { min-width: 44px; text-align: center; font-size: 13px; color: var(--fb-muted); }

.fb-slider {
    flex: 1 1 auto;
    min-width: 60px;
    height: 4px;
    appearance: none;
    -webkit-appearance: none;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--fb-accent) var(--fill, 0%), rgba(255,255,255,.15) var(--fill, 0%));
    cursor: pointer;
}
.fb-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.fb-slider::-moz-range-thumb {
    width: 16px; height: 16px;
    border: 0;
    border-radius: 50%;
    background: #fff;
}

/* ---------- small screens ---------- */
@media (max-width: 760px) {
    .fb-brand-text, #fbSound, .fb-zoom-label, #fbFirst, #fbLast { display: none; }
    .fb-top { gap: 10px; padding: 0 10px; }
    .fb-bar { gap: 6px; padding: 0 8px; flex-basis: 52px; }
    .fb-slider { display: none; }
    .fb-bar-nav { flex: 1 1 auto; justify-content: center; }
    .fb-side-nav { width: 34px; height: 60px; margin-top: -30px; background: rgba(0,0,0,.25); }
    .fb-side-prev { left: 4px; }
    .fb-side-next { right: 4px; }
}
