/* 기본 스타일 및 CSS 변수 */
:root {
    --primary-bg: #2c3e50;
    --primary-text: #ffffff;
    --secondary-bg: #34495e;
    --secondary-text: #ffffff;
    --accent-color: #3498db;
    --accent-hover: #2980b9;
    --disabled-bg: #7f8c8d;
    --body-bg: #f5f5f5;
    --container-bg: #fff;
    --border-color: #bdc3c7;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --spinner-color: #3498db;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--body-bg);
    height: 100vh;
    overflow: hidden;
}

/* 메인 레이아웃 */
.viewer-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: var(--container-bg);
}

.viewer-main {
    flex: 1;
    overflow: auto;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 상단 컨트롤 바 */
.control-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: var(--primary-bg);
    color: var(--primary-text);
    box-shadow: 0 2px 4px var(--shadow-color);
    flex-shrink: 0;
}

/* 파일 입력 */
.file-input-container {
    position: relative;
}

#epub-file {
    display: none;
}

.file-input-label {
    display: inline-block;
    padding: 8px 16px;
    background-color: var(--accent-color);
    color: var(--primary-text);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.file-input-label:hover {
    background-color: var(--accent-hover);
}

/* 네비게이션 & 줌 컨트롤 */
.navigation-controls, .zoom-controls, .export-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-btn {
    padding: 8px 16px;
    background-color: var(--secondary-bg);
    color: var(--secondary-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.nav-btn:hover:not(:disabled) {
    background-color: var(--primary-bg);
}

.nav-btn:disabled {
    background-color: var(--disabled-bg);
    cursor: not-allowed;
}

.page-info, .zoom-level {
    font-weight: 500;
    min-width: 120px;
    text-align: center;
}

.zoom-level {
    min-width: 50px;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    background-color: var(--secondary-bg);
    color: var(--secondary-text);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: background-color 0.3s;
}

.zoom-btn:hover {
    background-color: var(--primary-bg);
}

/* Export 컨트롤 */
.pages-input {
    padding: 8px 12px;
    width: 120px;
    background-color: var(--container-bg);
    color: var(--primary-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

.pages-input:focus {
    border-color: var(--accent-color);
}

.pages-input::placeholder {
    color: var(--disabled-bg);
}

.export-btn {
    padding: 8px 16px;
    background-color: var(--accent-color);
    color: var(--primary-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.export-btn:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

.export-btn:disabled {
    background-color: var(--disabled-bg);
    cursor: not-allowed;
    opacity: 0.6;
}

/* 뷰어 영역 */
.epub-viewer {
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: var(--container-bg);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

.epub-viewer iframe {
    border: none;
    background: transparent;
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 100%;
}

/* 하단 상태 바 */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background-color: #ecf0f1;
    border-top: 1px solid var(--border-color);
    font-size: 14px;
    flex-shrink: 0;
}

.book-title {
    font-weight: 500;
    color: var(--primary-bg);
}

.loading-status {
    color: var(--disabled-bg);
}

/* 로딩 오버레이 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    flex-direction: column;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--spinner-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--primary-text);
    font-size: 18px;
    font-weight: 500;
}

/* 스크롤바 */
.epub-viewer::-webkit-scrollbar {
    width: 8px;
}

.epub-viewer::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.epub-viewer::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.epub-viewer::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 기능 버튼들 */
.feature-controls {
    display: flex;
    gap: 8px;
    margin-left: 20px;
}

.feature-controls button {
    background: #f5f5f5;
    border: 1px solid #ddd;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s;
}

.feature-controls button:hover {
    background: #e0e0e0;
}

/* 다이얼로그, 팝업, 메뉴 */
.toc-dialog,
.search-dialog,
.memo-dialog,
.settings-dialog {
    position: fixed;
    z-index: 10001;
    background: var(--container-bg);
    border-radius: 8px;
    box-shadow: 0 4px 16px var(--shadow-color);
}

.text-selection-menu {
    position: fixed;
    z-index: 10000;
    background: #333;
    color: white;
    padding: 8px;
    border-radius: 4px;
    display: flex;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.text-selection-menu button {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 12px;
}

.text-selection-menu button:hover {
    background: var(--accent-hover);
}

/* 하이라이트 */
.highlight, .search-highlight {
    background-color: #ffeb3b;
    padding: 1px 2px;
    border-radius: 2px;
    font-weight: bold;
}

/* 캔버스 및 챕터 네비게이션 툴바 */
.canvas-toolbar,
.chapter-navigation {
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background: var(--container-bg);
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px var(--shadow-color);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.canvas-toolbar button,
.chapter-navigation button {
    width: 40px;
    height: 40px;
    border: 1px solid #ddd;
    background: var(--container-bg);
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

.canvas-toolbar button:hover,
.chapter-navigation button:hover {
    background: #f0f0f0;
}

/* 기타 UI 요소 */
.toc-item {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

.toc-item:hover {
    background: #f5f5f5;
}

.progress-bar, .chapter-info, .toast-message {
    position: fixed;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 10000;
}

.progress-bar { bottom: 20px; left: 50%; transform: translateX(-50%); }
.chapter-info { top: 20px; left: 50%; transform: translateX(-50%); }
.toast-message { top: 20px; right: 20px; opacity: 0; transition: opacity 0.3s; }

/* 테마 스타일 */
.theme-light {
    --theme-bg: #ffffff;
    --theme-text: #333333;
}

.theme-dark {
    --theme-bg: #1a1a1a;
    --theme-text: #ffffff;
}

.theme-sepia {
    --theme-bg: #f4f1e8;
    --theme-text: #5c4b37;
}

.theme-night {
    --theme-bg: #0a0a0a;
    --theme-text: #e0e0e0;
}

/* 뷰 모드 */
.view-single .epub-viewer { max-width: 800px; margin: 0 auto; }
.view-double .epub-viewer { max-width: 1200px; margin: 0 auto; }
.view-continuous .epub-viewer { max-width: none; margin: 0; }

/* 반응형 디자인 */
@media (max-width: 768px) {
    .control-bar {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }

    .navigation-controls { order: 2; }
    .zoom-controls { order: 3; }
    .file-input-container { order: 1; }

    .epub-viewer { padding: 10px; }

    .feature-controls {
        margin-left: 10px;
        gap: 4px;
    }

    .feature-controls button {
        padding: 6px 8px;
        font-size: 14px;
    }

    .canvas-toolbar,
    .chapter-navigation {
        right: 10px;
        padding: 8px;
    }

    .canvas-toolbar button,
    .chapter-navigation button {
        width: 35px;
        height: 35px;
        font-size: 14px;
    }
}
