* { 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;
    align-items: center;
    justify-content: center;
}

#flipbook {
    margin: 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;
}

.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;
}

.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;
    }
}
