* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
    color: #333;
}

.fb-app {
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
    overflow: hidden;
}

.fb-loading {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #000;
    color: #fff;
    font-size: 14px;
}

.fb-loading-spinner {
    width: 40px;
    height: 40px;
    margin-bottom: 16px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: fb-spin 0.8s linear infinite;
}

@keyframes fb-spin {
    to { transform: rotate(360deg); }
}

.fb-viewport {
    position: absolute;
    inset: 0;
    padding: 20px 60px 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: transform 0.2s ease;
    transform-origin: center center;
}

.fb-viewport.is-hidden {
    visibility: hidden;
    opacity: 0;
}

.fb-flipbook-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    /* 평소에는 잘라낸다. 넘김 애니메이션 중에 지면이 컨테이너를 잠깐 벗어나는데
       여기서 overflow:auto 로 두면 페이지를 넘길 때마다 스크롤바가 깜빡인다. */
    overflow: hidden;
}

/* 확대했을 때만 스크롤을 받는다. 책을 실제로 크게 그리므로(setZoom) 넘치는 만큼은
   여기서 스크롤되어야 좌우 화살표·툴바는 제자리에 두고 가장자리까지 볼 수 있다. */
.fb-flipbook-wrap.is-zoomed {
    overflow: auto;
}

#flipbook {
    /* margin:auto 로 가운데를 잡는다. justify-content:center 로 잡으면 책이 컨테이너보다
       클 때 시작쪽 넘침이 스크롤로 닿지 않는다(auto 마진은 남는 공간이 없으면 0이 된다). */
    margin: auto;
    /* JS 가 PDF 실제 비율로 계산한 px 크기를 그대로 유지한다.
       flex 자식이라 기본값(flex-shrink:1)이면 컨테이너가 줄일 수 있어 비율이 깨진다. */
    flex: 0 0 auto;
}

#flipbook .page {
    background: #fff;
    overflow: hidden;
}

#flipbook .page img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
}

/* 아직 그려지지 않은 지면. 흰 종이 위에 작은 스피너만 둔다 */
#flipbook .page.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid rgba(0, 0, 0, 0.12);
    border-top-color: rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    animation: fb-spin 0.8s linear infinite;
}

.fb-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    width: 48px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.85);
    font-size: 36px;
    line-height: 1;
    border: none;
    background: transparent;
    transition: color 0.2s, opacity 0.2s;
}

.fb-nav:hover {
    color: #fff;
}

.fb-nav.is-disabled {
    opacity: 0.25;
    cursor: default;
    pointer-events: none;
}

.fb-nav-prev { left: 8px; }
.fb-nav-next { right: 8px; }

.fb-toolbar {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.fb-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: none;
    background: transparent;
    color: #444;
    font-size: 13px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
}

.fb-btn:hover {
    background: #f0f0f0;
}

.fb-btn.is-disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.fb-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.fb-page-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 70px;
}

.fb-page-input {
    width: 36px;
    height: 28px;
    padding: 0 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
    font-size: 13px;
}

.fb-page-label {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
}

.fb-divider {
    width: 1px;
    height: 24px;
    margin: 0 4px;
    background: #e0e0e0;
}

.fb-more-wrap {
    position: relative;
}

.fb-more-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    padding: 6px 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.fb-more-menu.is-open {
    display: block;
}

.fb-more-menu .fb-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 0 14px;
    gap: 8px;
}

.fb-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 40;
    width: 260px;
    background: #fff;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.3);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
}

.fb-panel.is-open {
    transform: translateX(0);
}

.fb-panel-right {
    right: 0;
    left: auto;
    transform: translateX(100%);
}

.fb-panel-right.is-open {
    transform: translateX(0);
}

.fb-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #eee;
    font-size: 14px;
    font-weight: 600;
}

.fb-panel-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    color: #666;
}

.fb-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.fb-thumb-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.fb-thumb-item {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    transition: border-color 0.15s;
}

.fb-thumb-item:hover,
.fb-thumb-item.is-active {
    border-color: #333;
}

.fb-thumb-item img {
    display: block;
    width: 100%;
    height: auto;
}

/* 끝내 못 그린 지면. 스피너를 계속 돌리면 사용자는 영원히 기다린다 */
#flipbook .page.is-failed::after {
    content: '이 페이지를 불러오지 못했습니다';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    padding: 0 12px;
    text-align: center;
    font-size: 12px;
    line-height: 1.5;
    color: #999;
}

/* 백그라운드 로딩이 아직 닿지 않은 썸네일 자리 */
.fb-thumb-item.is-loading img,
.fb-thumb-item.is-failed img {
    height: 130px;
    background: #f0f0f0;
}

.fb-thumb-item.is-failed img {
    background: #f7ecec;
}

.fb-thumb-num {
    display: block;
    padding: 4px 0;
    font-size: 11px;
    text-align: center;
    color: #666;
}

.fb-search-input-wrap {
    padding: 0 0 12px;
}

.fb-search-input {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.fb-search-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fb-search-item {
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1.5;
}

.fb-search-item:hover {
    background: #f8f8f8;
}

.fb-search-item strong {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    color: #333;
}

.fb-search-empty {
    padding: 20px 0;
    text-align: center;
    color: #999;
    font-size: 13px;
}

.fb-toast {
    position: fixed;
    left: 50%;
    bottom: 80px;
    transform: translateX(-50%);
    z-index: 200;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 13px;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.fb-toast.is-show {
    opacity: 1;
}

.fb-noscript {
    position: absolute;
    inset: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #111;
    color: #fff;
    text-align: center;
}

.fb-noscript a {
    margin-top: 16px;
    color: #6eb5ff;
}

.fb-error {
    position: absolute;
    inset: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #111;
    color: #fff;
    text-align: center;
    font-size: 15px;
    line-height: 1.6;
}

@media (max-width: 768px) {
    .fb-viewport {
        padding: 10px 40px 76px;
    }

    .fb-nav {
        width: 36px;
        height: 60px;
        font-size: 28px;
    }

    .fb-toolbar {
        max-width: calc(100% - 16px);
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .fb-panel {
        width: 85%;
        max-width: 320px;
    }
}

@media print {
    .fb-toolbar,
    .fb-nav,
    .fb-panel,
    .fb-loading,
    .fb-toast {
        display: none !important;
    }

    .fb-viewport {
        position: static;
        padding: 0;
        transform: none !important;
    }

    #flipbook .page {
        page-break-after: always;
    }
}
