:root {
    --ebook-bg-dark: #363636;
    --ebook-accent: #00a2ff;
    --ebook-icon-color: #5d5d5d;
    --ebook-tooltip-bg: rgba(0, 0, 0, 0.8);
}

#ebook-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    margin: 0 auto;
    background: #f0f0f0;
    text-align: center;
    -webkit-overflow-scrolling: touch;
}

/* 상단 옵션 바 */
.ebook-options {
    display: flex;
    justify-content: center;
    flex-shrink: 0;
    padding: 20px;
    gap: 10px;
    background-color: #fff;
    z-index: 1;
    /* ★ 모바일: 버튼 터치 허용 */
    touch-action: auto;
}

.ebook-controls button {
    padding: 8px;
    cursor: pointer;
    color: #fff;
    border: none;
    border-radius: 35px;
}

#page-label-btn {
    display: flex;
    justify-content: center;
    background: #33333366;
}

#page-input {
    width: 50px;
    text-align: center;
}

#flipbook-viewport {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
    margin: 0 auto;
    transform-origin: center top;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    /* ★ 모바일 터치 드래그: 브라우저 기본 스크롤/줌 차단 → turn.js에 이벤트 전달 */
    touch-action: none;
    -webkit-touch-callout: none;
}
#flipbook-viewport.grabbing {
    cursor: grabbing;
}
#flipbook-viewport.zoomed-in {
    display: block;
}
/* === 로딩 오버레이 (초기 접속 시 깜빡임 방지) === */
.ebook-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    transition: opacity 0.4s ease;
}
.ebook-loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}
.ebook-loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #ddd;
    border-top-color: #999;
    border-radius: 50%;
    animation: ebook-spin 0.8s linear infinite;
}
@keyframes ebook-spin {
    to { transform: rotate(360deg); }
}
.ebook-loading-percent {
    margin-top: 12px;
    font-size: 13px;
    color: #999;
    font-family: 'NanumSquare', sans-serif;
}

/* 플립북 화면 정중앙 */
#flipbook {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    margin: 0 !important;
}

/* ★ v6: 페이지 기본 스타일
 * width/height는 turn.js가 turn('size') 호출 시 인라인으로 설정
 * CSS에서는 폴백값만 제공
 */
#flipbook .page {
    width: 500px;
    height: 700px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-color: #ffffff !important;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
    /* 로드 전: 약간 투명 */
    opacity: 0.88;
    transition: opacity 0.3s ease;
    /* ★ 모바일: 페이지 위 터치를 turn.js로 전달 */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 썸네일 로드됨 → 살짝 밝아짐 */
#flipbook .page.thumb-loaded {
    opacity: 0.94;
}

/* ★ 원본 로드 완료 → 완전 불투명, 선명 */
#flipbook .page.loaded {
    opacity: 1;
}

/* 썸네일 그리드 내 이미지 */
.thumb-item img {
    width: 100%;
    height: auto;
    aspect-ratio: 1/1.4;
    object-fit: cover;
    display: block;
}

/* 책갈피 스타일 */
.ebook-tabs {
    position: absolute;
    display: none;
    z-index: 10;
    transition: all 0.3s ease;
}

.tab-item {
    position: absolute;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 35px;
    padding: 7px 2px;
    color: #fff;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    border-radius: 5px 0 0 5px;
    transition: width 0.3s ease, transform 0.2s ease, left 0.25s ease;
    overflow: visible;
    box-sizing: border-box;
}
.tab-item .tab-label {
    display: inline-block;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform-origin: center center;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    pointer-events: none;
}

.tab-item.left-side {
    transform: translateX(-100%) translateX(1px) !important;
    border-radius: 5px 0 0 5px;
    writing-mode: vertical-rl;
}
.tab-item.left-side:hover {
    width: 60px;
    z-index: 1;
}
.tab-item.right-side {
    transform: translateX(0);
    border-radius: 0 5px 5px 0;
}
.tab-item.right-side:hover {
    width: 60px;
    z-index: 1;
}

.tab-item[data-index="1"] { top: 1px; }
.tab-item[data-index="2"] { top: 42px; }
.tab-item[data-index="3"] { top: 94px; }
.tab-item[data-index="4"] { top: 137px; }
.tab-item[data-index="5"] { top: 189px; }
.tab-item[data-index="6"] { top: 232px; }
.tab-item[data-index="7"] { top: 285px; }
.tab-item[data-index="8"] { top: 328px; }
.tab-item[data-index="9"] { top: 380px; }
.tab-item[data-index="10"] { top: 434px; }
.tab-item[data-index="11"] { top: 489px; }
.tab-item[data-index="12"] { top: 541px; }

.tab-item:hover { width: 45px; transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1); }

/* 사이드 내비게이션 */
.side-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.07);
    border: none;
    color: #fff;
    font-size: 30px;
    padding: 20px 10px;
    cursor: pointer;
    z-index: 100;
    transition: background 0.3s;
    display: flex;
    align-items: center;
}
.side-nav:hover { background: rgba(0,0,0,0.3); }
.side-nav.prev { left: 10px; border-radius: 0 10px 10px 0; }
.side-nav.next { right: 10px; border-radius: 10px 0 0 10px; }

/* 로딩 표시 */
.page .loader {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #999;
}

/* 하단 컨트롤 */
.ebook-controls {
    position: absolute;
    bottom: 0;
    /* ★ iOS/Android safe area 대응 — 브라우저 하단 툴바에 가리지 않도록 */
    bottom: env(safe-area-inset-bottom, 0px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    flex-shrink: 0;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 100;
    touch-action: auto;
}
.btn-group.zoom-ctrl {
    display: flex;
    align-items: center;
	gap: 10px;
}
.btn-group.navigate {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 30px;
    padding: 5px 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.btn {
    position: relative;
    font-size: 1.2rem;
    color: var(--ebook-icon-color);
    transition: color 0.2s;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 5px;
}
.btn:hover { color: var(--ebook-accent); }

.btn .tooltip {
    visibility: hidden;
    position: absolute;
/*     top: 110%; */
	bottom: -350%;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--ebook-tooltip-bg);
    color: #fff;
    text-align: center;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10;
}
.btn:hover .tooltip {
    visibility: visible;
    opacity: 1;
}

.btn svg { width: 24px; height: 24px; fill: #5d5d5d; }
.btn:disabled svg { fill: #7b7b7b; }

.btn-pagelabel {
    margin: 0 15px;
    font-size: 14px;
    font-weight: bold;
    min-width: 80px;
}

.input-page {
    width: 50px;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* 확대 시 — transform 패닝 사용 */
#ebook-container.is-zoomed {
    overflow: hidden !important;
    cursor: grab;
}

#ebook-container.is-zoomed:active {
    cursor: grabbing;
}
#flipbook-viewport.zoomed-in {
    cursor: grab;
    overflow: hidden;
    display: block;
    margin: 0 auto;
    transition: none;
}
#flipbook-viewport.zoomed-in:active {
    cursor: grabbing;
}
#ebook-container::-webkit-scrollbar {
    display: none;
}

/* 모바일 대응 */
@media screen and (max-width: 1000px) {
    #flipbook-viewport, #flipbook {
        width: 100%;
        aspect-ratio: 10 / 7;
    }
}


/* === TOC === */
.tableofcontent_form {
    position: fixed;
    top: 10px;
    left: 0;
    width: 320px;
    max-width: 85%;
    height: calc(100vh - 20px);
    background: #363636;
    color: #fff;
    z-index: 1200;
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
    border-right: 1px solid rgba(255,255,255,0.04);
    overflow: auto;
    transform: translateX(-110%);
    transition: transform 320ms ease, opacity 320ms ease;
    padding: 12px;
    box-sizing: border-box;
    /* ★ 목차 내부 스크롤 허용 */
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
}
.tableofcontent_form.active {
    transform: translateX(0);
}
.tableofcontent_form .form_title {
    display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
    font-size: 18px; font-weight: 600;
}
.tableofcontent_form .form_title i {
    font-size: 18px; margin-right: 8px;
}
.tableofcontent_form .close {
    position: absolute; right: 12px; top: 12px; cursor: pointer; width: 22px; height: 22px;
    font-size: 24px; color: #ccc; transition: transform 0.2s;
}
.tableofcontent_form .close:hover {
    color: #fff; transform: rotate(90deg);
}
.tableofcontent_form .stage { margin-top: 10px; }
.tableofcontent_form .item { padding: 12px 8px; cursor: pointer; border-radius: 2px; }
.tableofcontent_form .item:hover { background: rgba(255,255,255,0.03); }
.tableofcontent_form .item .description { margin: 0; font-size: 16px; }


/* === Thumbnail overlay === */
.thumbnail-overlay { position: fixed; inset: 0; z-index: 1500; display: none; }
.thumbnail-overlay .thumb-overlay-bg {
    position: absolute; inset: 0; background: rgba(0,0,0,0.7); cursor: pointer;
}
.thumbnail-overlay .thumb-panel {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
    width: 55%; max-width: 1200px; min-width: 220px; max-height: 60vh; overflow: auto;
    background: rgba(255,255,255,0.02); padding: 18px; box-sizing: border-box;
    border-radius: 6px; box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    -ms-overflow-style: none;
    scrollbar-width: none;
    /* ★ 썸네일 패널 스크롤 허용 */
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
}
.thumb-panel::-webkit-scrollbar { display: none; }
.thumb-close { position: absolute; right: 12px; top: 8px; background: transparent; border: none; font-size: 28px; color: #fff; cursor: pointer; }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 25px; padding: 45px 20px; }
.thumb-item { background: #fff; border-radius: 4px; overflow: hidden; cursor: pointer; text-align: center; transition: transform 0.2s ease; }
.thumb-item:hover { transform: translateY(-5px); }
.thumb-item .thumb-inner { display: flex; width: 100%; justify-content: center; background: #eee; aspect-ratio: 1.4 / 1; }
.thumb-inner:not(.is-pair) {
    aspect-ratio: 0.7 / 1;
    width: 50%;
    margin: 0 auto;
}
.thumb-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-img-wrap {
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.thumb-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.thumb-label { padding: 6px 0; font-size: 13px; background: #f6f6f6; }
.thumb-loader { padding: 6px; font-size: 12px; color: #666; }
.thumb-fail { padding: 10px; color: #999; }
.thumb-footer { color: #fff; }

/* === 확대 상태 토스트 알림 === */
.zoom-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.75);
    color: #fff;
    padding: 10px 22px;
    border-radius: 20px;
    font-size: 13px;
    font-family: 'NanumSquare', sans-serif;
    white-space: nowrap;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.zoom-toast.show { opacity: 1; }

/* 반응형 */
@media (max-width: 900px) {
	.btn-group.zoom-ctrl {gap: 5px;}
    .tableofcontent_form { width: 76%; }
    .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 15px; }
    .ebook-tabs { display: none !important; }
    .side-nav { font-size: 20px; padding: 15px 5px; }

    /* #flipbook .page {-webkit-backface-visibility: hidden; backface-visibility: hidden;} */

    /* ★ v6.1: 모바일 하단 컨트롤 여유 공간 추가 */
    .ebook-controls {
        bottom: 5px;
        padding-bottom: calc(15px + env(safe-area-inset-bottom, 5px));
    }
}

@media screen and (min-width: 1921px) {}
@media screen and (min-width: 1024px) and (max-width: 1920px) {}
@media screen and (min-width: 1501px) and (max-width: 1920px) {}
@media screen and (min-width: 1025px) and (max-width: 1500px) {}
@media screen and (min-width: 768px) and (max-width: 1024px) {}
@media screen and (max-width: 768px) {}
