:root {
    --bg: #eceef1;
    --toolbar-bg: #ffffff;
    --panel-bg: #ffffff;
    --border: #e0e2e6;
    --arrow-bg: rgba(0, 0, 0, .08);
    --arrow-bg-hover: rgba(0, 0, 0, .18);
    --hover: rgba(0, 0, 0, .06);
    --fg: #26262b;
    --muted: #6b6b73;
    --toolbar-h: 48px;
    --accent: #4c8bf5;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
    overflow: hidden;
}

/* ── 상단 툴바 ── */
.toolbar {
    height: var(--toolbar-h);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 40;
}

.tool-btn {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--fg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}

.tool-btn:hover { background: var(--hover); }
.tool-btn.active { background: var(--accent); color: #fff; }

/* ── 무대 ── */
.stage {
    position: relative;
    height: calc(100% - var(--toolbar-h));
}

/* ── 래퍼: 화면 중앙 정렬(centerBook이 표지 보정 시 transform 갱신) ── */
.book-wrap {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: transform .3s ease;
}

/* ── 플립북(turn.js가 크기 제어) ── */
.flip-book {
    margin: 0 !important;   /* turn.js가 넣는 마진 무시(래퍼 중앙정렬 유지) */
}

/* ── 챕터 탭(양면일 때만 좌/우 가장자리) ── */
.chapter-tabs {
    position: absolute;
    top: 0;
    height: 100%;
    width: 30px;
    display: flex;
    flex-direction: column;
    z-index: 15;
    isolation: isolate;   /* 탭 애니메이션이 책 레이어 재래스터화 유발 방지 */
}

.chapter-tabs[hidden] { display: none; }
.chapter-tabs--right { left: 100%; }   /* 책 오른쪽 바깥 */
.chapter-tabs--left { right: 100%; }    /* 책 왼쪽 바깥 */

.chapter-tab {
    position: absolute;   /* 인덱스 슬롯 위치 고정(top/height는 JS에서 지정) */
    left: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    writing-mode: vertical-rl;
    letter-spacing: 1px;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    transition: transform .15s ease, filter .12s;
    will-change: transform;   /* 탭을 독립 레이어로 → hover 시 부모(책) 재래스터화 억제 */
}

/* 마우스 오버: 바깥으로 슬라이드 + 확대(참조 사이트 방식) */
.chapter-tab:hover {
    filter: brightness(1.1);
    z-index: 2;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

.chapter-tabs--right .chapter-tab {
    border-radius: 0 6px 6px 0;
    transform-origin: left center;
}
.chapter-tabs--right .chapter-tab:hover { transform: scale(1.18); }

.chapter-tabs--left .chapter-tab {
    border-radius: 6px 0 0 6px;
    transform-origin: right center;
}
.chapter-tabs--left .chapter-tab:hover { transform: scale(1.18); }

.flip-book .page {
    background: #fff;
    box-shadow: none !important;  /* turn.js가 넣는 페이지 그림자 제거(가운데 줄 방지) */
}

.flip-book .page img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
    -webkit-user-drag: none;
    user-select: none;
}

/* 위치 기반 링크 영역(핫스팟) */
.link-area {
    position: absolute;
    display: block;
    z-index: 6;
    cursor: pointer;
    background: rgba(76, 139, 245, .35);
    border: 1px solid rgba(76, 139, 245, .9);
    border-radius: 4px;
}

.link-area:hover { background: rgba(76, 139, 245, .5); }

/* linkAreaView:false → 투명(안 보임) */
.link-area--plain { background: transparent; border: none; }
.link-area--plain:hover { background: transparent; }

/* ── 링크 좌표 편집 모드 ── */
.edit-rubber {
    position: absolute;
    border: 2px dashed #e0574f;
    background: rgba(224, 87, 79, .2);
    z-index: 30;
    pointer-events: none;
}

.edit-readout {
    position: fixed;
    left: 50%;
    top: calc(var(--toolbar-h) + 8px);
    transform: translateX(-50%);
    background: #111;
    color: #fff;
    font-size: 12px;
    font-family: Consolas, monospace;
    padding: 8px 14px;
    border-radius: 8px;
    z-index: 100;
    max-width: 92vw;
    white-space: nowrap;
    overflow: auto;
}

/* ── 좌우 화살표 ── */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--arrow-bg);
    color: var(--fg);
    font-size: 34px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    transition: background .15s, opacity .15s;
    -webkit-tap-highlight-color: transparent;
}

.nav-arrow:hover { background: var(--arrow-bg-hover); }
.nav-arrow:disabled { opacity: .2; cursor: default; }
.nav-arrow span { margin-top: -4px; }
.nav-arrow--left { left: 18px; }
.nav-arrow--right { right: 18px; }

/* ── 페이지 표시 ── */
.pager {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    color: #fff;
    background: rgba(0, 0, 0, .55);
    padding: 6px 10px;
    border-radius: 26px;
    z-index: 20;
}

.pager-btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .12s;
}

.pager-btn:hover { background: rgba(255, 255, 255, .2); }
.pager-btn:disabled { opacity: .35; cursor: default; }

.pager-page {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 16px;
    font-weight: 600;
    padding: 0 6px;
}

.pager-input {
    width: 52px;
    height: 30px;
    text-align: center;
    border: none;
    border-radius: 6px;
    background: #fff;
    color: #222;
    font-size: 15px;
    font-weight: 600;
}
/* 숫자 입력 스피너 제거 */
.pager-input::-webkit-outer-spin-button,
.pager-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pager-input { -moz-appearance: textfield; }

/* ── 로딩 ── */
.loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .8);
    z-index: 30;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #6366f1;      /* indigo-500 (NM과 동일) */
    border-top-color: transparent;
    border-radius: 50%;
    animation: nm-spin .8s linear infinite;
}

.loading-text {
    margin: 12px 0 0;
    font-size: 14px;
    color: #555;
}

@keyframes nm-spin { to { transform: rotate(360deg); } }

/* 렌더 전(소스 없는) 페이지 이미지의 깨진 아이콘 숨김 */
.flip-book .page img:not([src]) { visibility: hidden; }

/* 모바일 */
@media (max-width: 640px) {
    .nav-arrow {
        width: 44px;
        height: 44px;
        font-size: 26px;
    }
    .nav-arrow--left { left: 8px; }
    .nav-arrow--right { right: 8px; }
}

/* ── 배경(패널 열릴 때) ── */
.backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 45;
}

/* ── 공통 패널 ── */
.panel {
    position: fixed;
    background: var(--panel-bg);
    color: var(--fg);
    z-index: 50;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(0, 0, 0, .3);
}

.panel[hidden] { display: none; }

.panel--left {
    top: 0;
    left: 0;
    width: 320px;
    max-width: 85vw;
    height: 100%;
}

.panel--full {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.panel__close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--fg);
    font-size: 16px;
    cursor: pointer;
}

.panel__close:hover { background: var(--hover); }

.panel__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 0;
}

/* ── 목차 ── */
.toc-list { padding: 6px 0; }

.toc-item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 16px;
    cursor: pointer;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.toc-item:hover {
    background: var(--hover);
    border-left-color: var(--accent);
}

.toc-item--lv2 { padding-left: 32px; font-size: 13px; color: var(--muted); }
.toc-item--lv3 { padding-left: 48px; font-size: 12.5px; color: var(--muted); }
.toc-item__page { color: var(--muted); flex: 0 0 auto; }

.toc-empty { padding: 20px 16px; color: var(--muted); font-size: 14px; }

/* ── 썸네일 ── */
.thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
    padding: 18px;
}

.thumb {
    cursor: pointer;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: #f5f6f8;
}

.thumb:hover { border-color: var(--accent); }
.thumb.current { border-color: var(--accent); }

.thumb img,
.thumb .thumb__ph {
    display: block;
    width: 100%;
    height: 180px;
    object-fit: contain;
    background: #fff;
}

.thumb .thumb__ph { background: #e6e7ea; }

.thumb__num {
    padding: 5px 0;
    font-size: 12px;
    color: var(--muted);
}

@media (max-width: 640px) {
    .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; padding: 12px; }
    .thumb img, .thumb .thumb__ph { height: 130px; }
}
