/* ==================================================================
 * PDF 웹 뷰어 디자인 스타일시트 (Mobile Landscape Side Controls)
 * ==================================================================
 */

:root {
    --primary-bg: #f0f0f0;
    --secondary-bg: #ffffff;
    --text-color: #333333;
    --accent-color: #007bff;
    --border-color: #dddddd;
    --header-height: 50px;
    --footer-height: 50px;
    --shadow-color: rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Malgun Gothic', '맑은 고딕', sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-color);
    overflow: hidden;
}

#canvas {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

/* 상단바 */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    height: var(--header-height);
    background-color: var(--secondary-bg);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    text-decoration: none;
}
.icon-btn:hover {
    color: var(--accent-color);
}

/* 확대/축소 버튼 그룹 */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 0.1rem 0.2rem;
}
.zoom-controls .icon-btn {
    font-size: 1.2rem;
    font-weight: bold;
    width: 28px;
    height: 28px;
    line-height: 28px;
    text-align: center;
}

/* 목차 사이드바 */
.toc-sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 300px;
    height: 100%;
    background-color: var(--secondary-bg);
    box-shadow: 2px 0 5px var(--shadow-color);
    transition: left 0.3s ease-in-out;
    padding: 1rem;
    overflow-y: auto;
    z-index: 1000;
}
.toc-sidebar.active {
    left: 0;
}

#toc-title {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

#toc-list {
    list-style: none;
}
#toc-list li a {
    display: block;
    padding: 0.75rem 0.5rem;
    text-decoration: none;
    color: var(--text-color);
    border-radius: 4px;
}
#toc-list li a:hover {
    background-color: var(--primary-bg);
    color: var(--accent-color);
}

/* 메인 뷰어 & 2페이지 컨테이너 */
.magazine-viewport {
    flex-grow: 1;
    display: flex;
    align-items: center; 
    justify-content: flex-start;
    padding: 1rem;
    overflow: auto;
    flex-direction: column;
    /* 하단 여백: 기본적으로 플로팅 버튼 고려하여 추가 */
    padding-bottom: 80px; 
}

#page-spread-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0; 
    flex-direction: row !important;
    margin: 0 auto;
    width: fit-content; 
}

#pdf-canvas-left,
#pdf-canvas-right {
    width: auto;
    box-shadow: 0 4px 15px var(--shadow-color);
    display: block;
}

/* 하단 페이지 컨트롤 (기본 PC 스타일) */
.page-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--footer-height);
    background-color: var(--secondary-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    padding: 0.5rem;
    flex-wrap: wrap;
}

.control-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background-color: white;
    border-radius: 4px;
    cursor: pointer;
}
.control-btn:hover {
    background-color: var(--primary-bg);
}
.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-number-input {
    width: 60px;
    padding: 0.5rem;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* 로딩 및 에러 메시지 */
.loading-spinner, .error-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    color: #666;
    z-index: 10;
}
.error-message {
    color: #d9534f;
    text-align: center;
    line-height: 1.6;
    width: 80%;
}
.loading-spinner::after {
    content: '';
    display: block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =======================================================
 * 반응형 1: 모바일 세로 (하단 플로팅 바)
 * =======================================================
 */
@media (max-width: 768px) and (orientation: portrait) {
    .page-controls {
        position: fixed;
        bottom: 1.5rem;
        left: 50%;
        transform: translateX(-50%);
        width: auto;
        min-height: auto;
        z-index: 100;
        background-color: rgba(30, 30, 30, 0.85);
        backdrop-filter: blur(5px);
        -webkit-backdrop-filter: blur(5px);
        border-top: none;
        border-radius: 50px;
        padding: 0.5rem 1rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        flex-wrap: nowrap;
        gap: 0.5rem;
    }
    .page-controls .control-btn {
        background: transparent;
        border: none;
        color: white;
        padding: 0.5rem;
        font-size: 0.9rem;
    }
    .page-controls .page-number-input {
        background: rgba(255, 255, 255, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.3);
        color: white;
        border-radius: 10px;
        width: 50px;
    }
    .control-btn[aria-label="첫 페이지"],
    .control-btn[aria-label="마지막 페이지"] { 
        display: none; 
    }
    .zoom-controls { display: flex; }
}

/* =======================================================
 * 반응형 2: 모바일 가로 (양옆 화살표 버튼) - [수정됨]
 * =======================================================
 */
@media (max-width: 900px) and (orientation: landscape) {
    /* 1. 메인 뷰어 하단 여백 제거 (버튼이 옆으로 가서 공간 확보 불필요) */
    .magazine-viewport {
        padding-bottom: 1rem; 
    }

    /* 2. 하단 컨트롤 바 컨테이너 숨김 (배경, 입력창 등 제거하여 화면 확보) */
    .page-controls {
        position: static;
        background: transparent;
        box-shadow: none;
        padding: 0;
        min-height: 0;
        height: 0;
        border: none;
        overflow: visible; /* 자식 요소(버튼)는 보여야 함 */
    }

    /* 3. 불필요한 컨트롤 숨김 */
    .control-btn[aria-label="첫 페이지"],
    .control-btn[aria-label="마지막 페이지"],
    .page-number-input {
        display: none;
    }

    /* 4. 이전/다음 버튼을 화면 양옆 중앙에 고정 (반투명 원형) */
    .control-btn[aria-label="이전 페이지"],
    .control-btn[aria-label="다음 페이지"] {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        z-index: 200;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background-color: rgba(0, 0, 0, 0.6); /* 반투명 검정 */
        color: white;
        border: 1px solid rgba(255, 255, 255, 0.3);
        padding: 0;
        font-size: 0; /* '이전', '다음' 텍스트 숨김 */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 5. 버튼 내부 화살표 아이콘 */
    .control-btn[aria-label="이전 페이지"]::before {
        content: '‹'; /* 왼쪽 화살표 */
        font-size: 2rem;
        line-height: 1;
        padding-bottom: 4px; /* 높이 미세 조정 */
        padding-right: 2px;
    }
    .control-btn[aria-label="다음 페이지"]::before {
        content: '›'; /* 오른쪽 화살표 */
        font-size: 2rem;
        line-height: 1;
        padding-bottom: 4px;
        padding-left: 2px;
    }

    /* 6. 위치 지정 */
    .control-btn[aria-label="이전 페이지"] {
        left: 1rem;
    }
    .control-btn[aria-label="다음 페이지"] {
        right: 1rem;
    }
}