/* -------------------------------------------------------------------------- */
/* CSS Variables & Global Reset                                               */
/* -------------------------------------------------------------------------- */
:root {
    --color-bg: #fbfbfb;
    --color-surface: #ffffff;
    --color-text-main: #2b2b2b;
    --color-text-muted: #868686;
    --color-text-light: #c2c2c2;
    --color-border: #f0f0f0;
    --color-primary: #1c1c1c;
    --color-primary-hover: #000000;
    --color-primary-text: #ffffff;
    --color-accent: #f7f5f2; /* 차분하고 은은한 베이지 톤 */
    
    --color-header-bg: rgba(251, 251, 251, 0.85);
    --color-toolbar-bg: rgba(255, 255, 255, 0.95);
    --color-overlay-bg: rgba(251, 251, 251, 0.85);
    
    --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.08);
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 24px;
    
    --transition-fast: 0.2s ease;
    --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
    --color-bg: #121212;
    --color-surface: #1e1e1e;
    --color-text-main: #e0e0e0;
    --color-text-muted: #a0a0a0;
    --color-text-light: #666666;
    --color-border: #333333;
    --color-primary: #ffffff;
    --color-primary-hover: #e0e0e0;
    --color-primary-text: #1c1c1c;
    --color-accent: #2c2c2c;
    
    --color-header-bg: rgba(18, 18, 18, 0.85);
    --color-toolbar-bg: rgba(30, 30, 30, 0.95);
    --color-overlay-bg: rgba(18, 18, 18, 0.85);
}

[data-theme="dark"] .rank-1 {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, rgba(245, 158, 11, 0.05) 100%);
    border-color: rgba(253, 230, 138, 0.2);
}
[data-theme="dark"] .rank-2 {
    background: linear-gradient(135deg, rgba(156, 163, 175, 0.15) 0%, rgba(156, 163, 175, 0.05) 100%);
    border-color: rgba(229, 231, 235, 0.2);
}
[data-theme="dark"] .rank-3 {
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.15) 0%, rgba(217, 119, 6, 0.05) 100%);
    border-color: rgba(254, 215, 170, 0.2);
}

[data-theme="fairy"] {
    --color-bg: #fef9f4; /* 웜 화이트 베이스 */
    --color-surface: #ffffff;
    --color-text-main: #3d3b40;
    --color-text-muted: #79767c;
    --color-text-light: #b5b1b8;
    --color-border: #f4dce0; /* 부드러운 로즈쿼츠 느낌 테두리 */
    --color-primary: #ff7b89; /* 톡톡 튀는 베리 핑크 */
    --color-primary-hover: #e66a77;
    --color-primary-text: #ffffff;
    --color-accent: #e3f2fd; /* 경쾌하고 맑은 스카이블루 */
    
    --color-header-bg: rgba(254, 249, 244, 0.85);
    --color-toolbar-bg: rgba(255, 255, 255, 0.95);
    --color-overlay-bg: rgba(254, 249, 244, 0.85);
    
    /* 예술적인 분위기의 컬러 섀도우 */
    --shadow-sm: 0 4px 16px rgba(255, 123, 137, 0.08);
    --shadow-md: 0 10px 30px rgba(255, 123, 137, 0.12);
    --shadow-lg: 0 20px 50px rgba(255, 123, 137, 0.15);
}

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

body {
    background-color: var(--color-bg);
    color: var(--color-text-main);
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
    line-height: 1.7;
    letter-spacing: -0.02em; /* 미세한 자간 조절로 가독성 향상 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* -------------------------------------------------------------------------- */
/* Typography                                                                 */
/* -------------------------------------------------------------------------- */
.font-sans {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
}

.font-serif {
    font-family: 'Noto Serif KR', 'Nanum Myeongjo', serif;
}

.font-round {
    font-family: 'NanumSquareRound', sans-serif;
}

.font-maru {
    font-family: 'MaruBuri', serif;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 400;
    line-height: 1.4;
    color: var(--color-primary);
    letter-spacing: -0.03em;
}

/* -------------------------------------------------------------------------- */
/* Utilities & Animations                                                     */
/* -------------------------------------------------------------------------- */
.hidden {
    display: none !important;
}

.mobile-only {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(12px); }
}

.view-section {
    animation: fadeIn var(--transition-smooth);
}

/* -------------------------------------------------------------------------- */
/* Buttons & Inputs                                                           */
/* -------------------------------------------------------------------------- */
button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.btn-primary {
    background-color: var(--color-primary);
    color: var(--color-primary-text);
    padding: 0.7rem 1.6rem;
    border-radius: 30px;
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.btn-primary:hover {
    background-color: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn-outline {
    background-color: var(--color-surface);
    color: var(--color-primary);
    border: 1px solid var(--color-border);
    padding: 0.7rem 1.6rem;
    border-radius: 30px;
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
}

.btn-outline:hover {
    border-color: #d0d0d0;
    background-color: var(--color-bg);
}

.btn-text {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
}

.btn-text:hover {
    color: var(--color-primary);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    padding: 0.5rem;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    color: var(--color-primary);
    background-color: var(--color-accent);
}

.admin-hidden-menu {
    display: none !important;
}

.full-width {
    width: 100%;
}

.form-group {
    margin-bottom: 2rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.input-text, .input-textarea {
    width: 100%;
    padding: 1rem 1.2rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 1.05rem;
    background-color: var(--color-bg);
    color: var(--color-text-main);
    transition: all var(--transition-fast);
    line-height: 1.6;
}

.input-text::placeholder, .input-textarea::placeholder {
    color: var(--color-text-muted);
}

.input-text:focus, .input-textarea:focus {
    outline: none;
    border-color: var(--color-text-muted);
    background-color: var(--color-surface);
    box-shadow: 0 0 0 4px rgba(0,0,0,0.05);
}

/* -------------------------------------------------------------------------- */
/* Global Header                                                              */
/* -------------------------------------------------------------------------- */
#ranking-period-filters::-webkit-scrollbar,
#ranking-category-filters::-webkit-scrollbar {
    display: none;
}

.app-header {
    background-color: var(--color-header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    width: 100%;
    margin: 0 auto;
    padding: 1.2rem 3rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    letter-spacing: 0;
    color: var(--color-primary);
    font-weight: 600;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 2rem;
}

#admin-nav-links {
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

#admin-nav-links::-webkit-scrollbar {
    display: none;
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--color-border);
    background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

/* -------------------------------------------------------------------------- */
/* Profile Dropdown                                                           */
/* -------------------------------------------------------------------------- */
.profile-dropdown-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.profile-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.8rem;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    width: 220px;
    z-index: 200;
    overflow: hidden;
    animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.dropdown-header {
    padding: 1.2rem;
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-accent);
}

.dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.9rem 1.2rem;
    font-size: 0.95rem;
    color: var(--color-text-main);
    background: none;
    border: none;
    cursor: pointer;
    transition: background-color var(--transition-fast);
    font-weight: 500;
}

.dropdown-item:hover {
    background-color: var(--color-bg);
    color: var(--color-primary);
}

/* -------------------------------------------------------------------------- */
/* Toggle Switch                                                              */
/* -------------------------------------------------------------------------- */
.toggle-switch input:checked + .toggle-slider {
    background-color: var(--color-primary);
}
.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 1px var(--color-primary);
}
.toggle-switch input:checked + .toggle-slider:before {
    left: calc(100% - 3px);
    transform: translateX(-100%);
}
.toggle-slider:before {
    position: absolute;
    content: "";
    height: calc(100% - 6px);
    aspect-ratio: 1;
    left: 3px;
    top: 3px;
    background-color: var(--color-primary-text);
    transition: 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

/* -------------------------------------------------------------------------- */
/* Main Layout & Home View                                                    */
/* -------------------------------------------------------------------------- */
#app-root {
    min-height: calc(100vh - 75px);
}

.home-container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 5rem 2.5rem;
}

.home-header {
    text-align: center;
    margin-bottom: 5rem;
}

.section-title {
    font-size: 2.4rem;
    margin-bottom: 0.8rem;
    color: var(--color-primary);
}

.section-subtitle {
    color: var(--color-text-muted);
    font-size: 1.05rem;
    font-weight: 300;
}

/* -------------------------------------------------------------------------- */
/* Ranking Styles                                                             */
/* -------------------------------------------------------------------------- */
.ranking-item {
    display: flex;
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    gap: 1.5rem;
    transition: all var(--transition-fast);
    cursor: pointer;
    position: relative;
}

.ranking-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
    border-color: #d0d0d0;
}

.ranking-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-muted);
    min-width: 40px;
    text-align: center;
}

.rank-1 {
    background: linear-gradient(135deg, #fffbee 0%, #fff7e6 100%);
    border-color: #fde68a;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.15);
}
.rank-1 .ranking-number {
    color: #f59e0b;
    font-size: 2rem;
    text-shadow: 1px 1px 0px rgba(0,0,0,0.1);
}
.rank-1::before {
    content: "👑";
    position: absolute;
    top: 50%;
    left: 8px;
    transform: translateY(-20px) rotate(-15deg);
    font-size: 1.5rem;
}

.rank-2 {
    background: linear-gradient(135deg, #f8fafc 0%, #f3f4f6 100%);
    border-color: #e5e7eb;
    box-shadow: 0 4px 15px rgba(156, 163, 175, 0.15);
}
.rank-2 .ranking-number {
    color: #9ca3af;
    font-size: 1.8rem;
}

.rank-3 {
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
    border-color: #fed7aa;
    box-shadow: 0 4px 15px rgba(217, 119, 6, 0.1);
}
.rank-3 .ranking-number {
    color: #d97706;
    font-size: 1.6rem;
}

.ranking-cover {
    width: 60px;
    height: 80px;
    background: var(--color-accent);
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.ranking-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ranking-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    margin-bottom: 0.2rem;
    line-height: 1.3;
}

.ranking-meta {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    display: flex;
    gap: 0.8rem;
    align-items: center;
}

.ranking-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-main);
}

/* -------------------------------------------------------------------------- */
/* Book Grid & Cards                                                          */
/* -------------------------------------------------------------------------- */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2.5rem;
}

.book-card {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-smooth);
    display: flex;
    flex-direction: column;
    min-height: 360px;
    box-shadow: var(--shadow-sm);
}

.book-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
    border-color: #e5e5e5;
}

.book-card-cover {
    height: 160px;
    background-color: var(--color-accent);
    /* 부드러운 그라데이션 커버 */
    background-image: linear-gradient(to top, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%);
    opacity: 0.8;
    transition: opacity var(--transition-fast);
}

.book-card:hover .book-card-cover {
    opacity: 1;
}

.book-card-content {
    padding: 2.2rem 1.8rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.book-card-content h3 {
    font-size: 1.35rem;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.book-summary {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-status {
    margin-top: 1.5rem;
    font-size: 0.75rem;
    color: var(--color-text-light);
    font-weight: 600;
    letter-spacing: 0.05em;
}

.create-card {
    background-color: transparent;
    border: 1px dashed #dcdcdc;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 3rem 2rem;
    box-shadow: none;
}

.create-card:hover {
    border-color: var(--color-text-muted);
    background-color: var(--color-surface);
    box-shadow: var(--shadow-md);
    transform: translateY(-4px);
}

.create-icon {
    font-size: 2.5rem;
    color: var(--color-text-light);
    margin-bottom: 1.2rem;
    font-weight: 200;
    transition: color var(--transition-fast);
}

.create-card:hover .create-icon {
    color: var(--color-primary);
}

.create-card h3 {
    margin-bottom: 0.8rem;
    font-size: 1.2rem;
}

.create-card p {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* -------------------------------------------------------------------------- */
/* Editor View Layout                                                         */
/* -------------------------------------------------------------------------- */
.editor-layout {
    display: flex;
    height: calc(100vh - 75px);
}

.editor-sidebar {
    width: 280px;
    background-color: var(--color-bg);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    padding: 2.5rem 2rem;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.sidebar-title {
    font-size: 1.2rem;
    margin-bottom: 0;
    color: var(--color-primary);
    line-height: 1.4;
    transition: color var(--transition-fast);
}

.sidebar-title:hover {
    color: #666;
}

.mobile-sidebar-close, .mobile-sidebar-toggle {
    display: none;
}

.mobile-sidebar-overlay {
    display: none;
}

.sidebar-divider {
    height: 1px;
    background-color: var(--color-border);
    margin-bottom: 2rem;
}

.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.toc-item {
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.chapter-title-span {
    flex: 1;
    word-break: keep-all;
    white-space: normal;
    line-height: 1.4;
}

.btn-delete-chapter {
    color: var(--color-text-light);
    font-size: 1.2rem;
    line-height: 1;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    opacity: 0;
    transition: all var(--transition-fast);
}

.btn-delete-chapter:hover {
    background-color: rgba(255, 0, 0, 0.1);
    color: #ff4d4d;
}

.toc-item:hover .btn-delete-chapter {
    opacity: 1;
}

@media (max-width: 768px) {
    .btn-delete-chapter {
        opacity: 1;
    }
}

.toc-item:hover {
    background-color: var(--color-surface);
    color: var(--color-text-main);
    box-shadow: var(--shadow-sm);
}

.toc-item.active {
    background-color: var(--color-accent);
    color: var(--color-primary);
    font-weight: 600;
}

.highlight-ai-modified {
    background-color: rgba(99, 102, 241, 0.08) !important;
    color: #4f46e5 !important;
    border-left: 3px solid #6366f1;
    font-weight: 500;
}

.highlight-ai-modified.active {
    background-color: rgba(99, 102, 241, 0.15) !important;
    font-weight: 600;
}

.toc-item.drag-over {
    border-top: 2px solid var(--color-primary);
}

.toc-item.dragging {
    opacity: 0.5;
    background-color: var(--color-border);
}

.new-chapter {
    margin-top: 1.5rem;
    color: var(--color-text-light);
    border: 1px dashed var(--color-border);
    text-align: center;
    background-color: transparent;
}

.new-chapter:hover {
    border-color: #c0c0c0;
    color: var(--color-text-main);
}

/* -------------------------------------------------------------------------- */
/* Main Editor Area                                                           */
/* -------------------------------------------------------------------------- */
.editor-bottom-nav {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    gap: 0.6rem;
    z-index: 50;
}

.btn-editor-nav {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    color: var(--color-primary);
    transition: all var(--transition-fast);
}

.btn-editor-nav:hover {
    background: var(--color-surface);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.btn-editor-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

@media (max-width: 768px) {
    .editor-bottom-nav {
        bottom: 1.5rem;
        right: 1.2rem;
    }
    .btn-editor-nav {
        width: 48px;
        height: 48px;
    }
}

.editor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--color-surface);
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 4rem;
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-toolbar-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(8px);
}

#view-preview .editor-toolbar {
    background-color: transparent !important;
    backdrop-filter: none !important;
    border: none !important;
    box-shadow: none !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease !important;
}

#view-preview .editor-toolbar.hide-toolbar {
    transform: translateY(-100%) !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#view-preview .toolbar-left,
#view-preview .current-section-label {
    /* 텍스트가 그림에 묻히지 않도록 부드러운 흰색 후광 효과 추가 */
    text-shadow: 0 0 10px rgba(255,255,255,0.8), 0 2px 5px rgba(255,255,255,0.5);
}

.toolbar-left {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-right: 1.5rem;
}

.current-section-label {
    font-size: 1.35rem;
    color: var(--color-primary);
    font-weight: 400;
    white-space: nowrap;
}

.complexity-badge {
    background-color: var(--color-accent);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    color: var(--color-text-muted) !important;
    font-size: 0.75rem !important;
    font-weight: 500;
}

.toolbar-right {
    display: flex;
    gap: 0.8rem;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.toolbar-right::-webkit-scrollbar {
    display: none;
}

.toolbar-right .btn-primary, 
.toolbar-right .btn-outline {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.editor-content-area {
    max-width: 760px; /* 글쓰기에 가장 편안한 너비 */
    width: 100%;
    margin: 0 auto;
    padding: 5rem 2rem 8rem 2rem;
    flex: 1;
}

/* -------------------------------------------------------------------------- */
/* Content Blocks & Editable Elements                                         */
/* -------------------------------------------------------------------------- */
.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 0 !important; /* editable-text의 min-height 충돌 방지 */
    max-height: calc(1.15rem * 1.85 * 3) !important; /* 3줄 높이를 초과하여 글자가 반토막 나는 현상 차단 */
}

.btn-read-more {
    display: block;
    margin: 0.8rem auto 0 auto;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    text-align: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 0.3rem 1rem;
    transition: all var(--transition-fast);
}

.btn-read-more:hover {
    background: var(--color-bg);
    color: var(--color-primary);
    border-color: #d0d0d0;
}

.content-block-container {
    margin-bottom: 4rem;
    position: relative;
}

.content-block-container:last-child {
    margin-bottom: 1rem; /* 마지막 요소의 과도한 하단 여백 제거 */
}

.block-label {
    font-size: 0.85rem;
    color: var(--color-text-light);
    letter-spacing: 0.05em;
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.content-block {
    position: relative;
}

/* 읽기 편안한 에디터 타이포그래피 */
.editable-text {
    font-size: 1.15rem; /* 글씨를 큼직하게 */
    line-height: 1.85; /* 넉넉한 행간 */
    color: var(--color-text-main);
    outline: none;
    min-height: 150px;
    padding: 0;
    white-space: pre-wrap;
    word-break: break-all;
    text-align: justify;
    transition: color var(--transition-fast);
}

.editable-text:focus {
    color: var(--color-primary);
}

.editable-text[contenteditable="true"]:empty:before {
    content: "여기에 글을 작성하세요...";
    color: var(--color-text-light);
    pointer-events: none;
    display: block; 
}

/* Floating AI Button (글쓰기 방해 금지, 호버시 등장) */
.btn-floating-edit {
    position: absolute;
    bottom: -45px;
    right: 0;
    background-color: var(--color-surface);
    backdrop-filter: blur(4px);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 0.85rem;
    padding: 0.5rem 1.2rem;
    border-radius: 20px;
    box-shadow: var(--shadow-sm);
    opacity: 0; /* 평소엔 숨김 */
    transform: translateY(10px);
    transition: all var(--transition-smooth);
    z-index: 5;
}

.content-block:hover .btn-floating-edit,
.editable-text:focus ~ .btn-floating-edit {
    opacity: 0.6;
    transform: translateY(0);
}

.btn-floating-edit:hover {
    opacity: 1 !important;
    color: var(--color-primary);
    border-color: #d0d0d0;
    box-shadow: var(--shadow-md);
    background-color: var(--color-surface);
}

/* -------------------------------------------------------------------------- */
/* Chatbot Panel                                                              */
/* -------------------------------------------------------------------------- */
.typing-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 4px 6px;
    height: 24px;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--color-text-muted);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.chatbot-panel {
    position: fixed;
    bottom: 90px;
    right: 2rem;
    width: 360px;
    height: 500px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 99;
    overflow: hidden;
    transition: all var(--transition-smooth);
    transform-origin: bottom right;
}

.chatbot-panel.hidden {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
    pointer-events: none;
    display: flex !important; /* Transition을 위해 display: none 무효화 */
}

.chatbot-header {
    padding: 1rem 1.2rem;
    background: var(--color-accent);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    background: var(--color-bg);
}

.chat-message {
    max-width: 85%;
    display: flex;
    flex-direction: column;
}

.chat-message.user-message {
    align-self: flex-end;
}

.chat-message.ai-message {
    align-self: flex-start;
}

.message-content {
    padding: 0.8rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}

.user-message .message-content {
    background: var(--color-primary);
    color: var(--color-primary-text);
    border-bottom-right-radius: 4px;
}

.ai-message .message-content {
    background: var(--color-surface);
    color: var(--color-text-main);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.chatbot-input-area {
    padding: 1rem;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 0.5rem;
}

.chatbot-btn {
    background-color: var(--color-primary);
    color: var(--color-primary-text);
    border-color: var(--color-primary);
}
.chatbot-btn:hover {
    background-color: var(--color-primary-hover);
    color: var(--color-primary-text);
}

@media (max-width: 768px) {
    .chatbot-panel {
        top: 0;
        left: 0;
        bottom: auto; /* 키보드 대응을 위해 bottom auto 설정 */
        right: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        border-radius: 0;
        z-index: 2000;
    }
    
    .chatbot-input-area input {
        font-size: 16px !important; /* iOS 인풋 포커스 시 자동 확대 방지 */
    }
}

.msg-action-btns {
    display: flex;
    gap: 0.5rem;
    margin-top: 6px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    transform: translateY(-4px);
}
.chat-message.active-actions .msg-action-btns,
.chat-message:hover .msg-action-btns {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.btn-msg-action {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.btn-msg-action:hover {
    background: var(--color-border);
    color: var(--color-text-main);
}

/* -------------------------------------------------------------------------- */
/* Modals & Overlays                                                          */
/* -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-overlay-bg, rgba(0, 0, 0, 0.25)) !important; 
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: 3rem 0;
    z-index: 1000;
    backdrop-filter: blur(6px);
    transition: opacity var(--transition-fast);
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background-color: var(--color-surface);
    padding: 3.5rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 540px;
    position: relative;
    margin: auto;
    box-shadow: var(--shadow-lg);
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(255,255,255,0.2);
}

#modal-create-book .modal-content {
    max-height: 85vh;
    overflow-y: auto;
}
#modal-create-book .modal-content::-webkit-scrollbar {
    width: 6px;
}
#modal-create-book .modal-content::-webkit-scrollbar-thumb {
    background-color: var(--color-border);
    border-radius: 4px;
}

.modal-content.small-modal {
    max-width: 440px;
    padding: 3rem;
}

.btn-close-modal {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    font-size: 1.8rem;
    color: var(--color-text-light);
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.btn-close-modal:hover {
    color: var(--color-text-main);
    background-color: var(--color-bg);
}

.modal-title {
    font-size: 1.8rem;
    margin-bottom: 0.8rem;
    color: var(--color-primary);
}

.modal-desc {
    color: var(--color-text-muted);
    font-size: 1rem;
    margin-bottom: 2.5rem;
    line-height: 1.6;
}

.modal-actions {
    margin-top: 1.5rem;
}

.settings-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.5rem;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.settings-tabs::-webkit-scrollbar {
    display: none;
}

.settings-tab-btn {
    font-size: 1rem;
    color: var(--color-text-muted);
    font-weight: 500;
    padding: 0.5rem 0.5rem;
    position: relative;
    flex-shrink: 0;
}

.settings-tab-btn.active {
    color: var(--color-primary);
    font-weight: 600;
}

.settings-tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -0.6rem;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--color-primary);
}

.settings-tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.settings-tab-content.active {
    display: block;
}

.admin-list {
    list-style: none;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.admin-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

.admin-list-item:last-child {
    border-bottom: none;
}

.admin-list-item span {
    font-weight: 500;
}

.admin-list-actions {
    display: flex;
    gap: 0.5rem;
}

.admin-list-actions button {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

.admin-list-actions button:hover {
    background-color: var(--color-bg);
}

/* -------------------------------------------------------------------------- */
/* Loading Spinner                                                            */
/* -------------------------------------------------------------------------- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-overlay-bg, rgba(251, 251, 251, 0.9));
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
}

.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.5s ease;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-text-main); /* 좀 더 차분한 스피너 색상 */
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
    margin-bottom: 2rem;
}

.loading-text {
    color: var(--color-text-main);
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

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

/* -------------------------------------------------------------------------- */
/* Responsive Adjustments                                                     */
/* -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    #app-root {
        min-height: auto; /* 모바일 하단 무한 스크롤 버그 방지 */
    }
    
    .header-container {
        padding: 1rem 1.2rem;
        gap: 0.5rem;
    }
    
    .logo {
        font-size: 1.2rem;
        flex-shrink: 0;
    }
    
    .nav-links {
        gap: 0.8rem;
        flex: 1;
        justify-content: flex-end;
        overflow: visible;
        min-width: 0;
    }
    
    #admin-nav-links {
        gap: 0.8rem !important;
        flex: 1;
        min-width: 0;
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    
    #dynamic-nav-links {
        gap: 0.8rem !important;
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        min-width: 0;
    }
    
    #dynamic-nav-links::-webkit-scrollbar {
        display: none;
    }

    /* 모바일 어드민 화면 필터 폼 및 라벨 깨짐(세로 늘어짐) 방지 */
    .settings-container div[style*="height: 36px"] {
        height: auto !important;
        flex-wrap: wrap !important;
        gap: 0.8rem !important;
        padding-top: 0.5rem;
    }
    
    .settings-container button[style*="height: 100%"] {
        height: 36px !important;
    }

    .settings-container label {
        white-space: nowrap !important;
    }
    
    .profile-dropdown-wrapper {
        flex-shrink: 0;
    }

    .admin-table-container table {
        min-width: max-content;
    }

    .admin-table-container th, 
    .admin-table-container td {
        white-space: nowrap;
    }

    .mobile-sidebar-close, .mobile-sidebar-toggle {
        display: flex;
    }

    .editor-layout {
        display: block; /* 모바일에서 flex 팽창으로 인한 여백 붕괴 해결 */
        height: auto;
        min-height: auto;
        background-color: var(--color-surface);
    }
    
    .editor-main {
        display: block; /* 모바일에서 flex 해제 */
        overflow-y: visible;
        height: auto;
        background-color: var(--color-surface);
    }

    #view-editor {
        background-color: var(--color-surface);
        min-height: auto;
    }
    
    .editor-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        max-height: 100vh;
        z-index: 1001;
        background-color: var(--color-surface);
        border-right: 1px solid var(--color-border);
        border-bottom: none;
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        padding: 1.5rem 1.2rem;
        box-shadow: var(--shadow-lg);
    }

    .editor-sidebar.open {
        transform: translateX(0);
        left: 0;
    }
    
    .mobile-sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0,0,0,0.4);
        z-index: 1000;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-sidebar-overlay.show {
        display: block;
        opacity: 1;
    }
    
    .editor-content-area {
        padding: 1.5rem 1rem 8rem 1rem; /* 네비게이션 버튼 가림 방지 및 iOS 가상키보드 대비 여유 확보 */
    }
    
    .editor-toolbar {
        padding: 0.8rem 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
        position: sticky;
        top: 59px; /* 모바일 헤더 높이에 맞춰 툴바 고정 */
        z-index: 90;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05); /* 스크롤 시 구분을 위한 미세한 그림자 */
    }

    .toolbar-left {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: nowrap;
        gap: 0.3rem;
        align-items: center;
    }
    
    #view-preview .toolbar-left {
        flex-wrap: nowrap;
        width: auto;
        flex: 1;
        overflow: hidden;
    }

    .current-section-label {
        font-size: 1.1rem;
        white-space: normal;
        word-break: keep-all;
        line-height: 1.3;
        flex: 1;
    }

    .complexity-badge {
        margin-left: 0 !important;
        font-size: 0.7rem !important;
    }

    .toolbar-right {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: nowrap;
        gap: 0.5rem;
        overflow-x: auto; /* 한 줄 가로 스크롤 활성화 */
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* 파이어폭스 스크롤바 숨김 */
        padding-bottom: 2px; /* 가로 스크롤 시 그림자 짤림 방지 */
    }
    
    .toolbar-right::-webkit-scrollbar {
        display: none; /* 크롬, 사파리 스크롤바 숨김 */
    }

    .toolbar-right .btn-primary, 
    .toolbar-right .btn-outline {
        padding: 0.45rem 0.9rem;
        font-size: 0.85rem;
        flex-shrink: 0; /* 버튼이 찌그러지지 않도록 크기 고정 */
    }
    
    .home-container {
        padding: 2rem 1.2rem;
    }
    
    #ranking-period-filters,
    #ranking-category-filters {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    #ranking-period-filters::-webkit-scrollbar,
    #ranking-category-filters::-webkit-scrollbar {
        display: none;
    }
    #ranking-period-filters .btn-outline,
    #ranking-category-filters .btn-outline {
        flex-shrink: 0;
    }
    
    .modal-overlay {
        padding: 1.5rem 0;
    }

    .modal-content {
        padding: 2rem 1.2rem;
    }
}

/* -------------------------------------------------------------------------- */
/* Book Reader (Preview) Mode                                                 */
/* -------------------------------------------------------------------------- */
:root {
    --viewer-bg: #fdfcf9;
    --viewer-text: #2a2a2a;
    --viewer-font: 'Noto Serif KR', 'Nanum Myeongjo', serif;
    --viewer-font-size: 1.08rem;
    --viewer-font-weight: 500;
    --viewer-line-height: 2.1;
    --viewer-letter-spacing: -0.04em;
    --viewer-text-shadow: 0px 3px 8px rgba(0,0,0,0.6);
    --viewer-binding: linear-gradient(to right, transparent 49.2%, rgba(0,0,0,0.02) 49.8%, rgba(0,0,0,0.06) 50%, rgba(0,0,0,0.02) 50.2%, transparent 50.8%);
}

.book-reader-wrapper {
    width: 100%;
    max-width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

.book-reader-container {
    background-color: var(--viewer-bg);
    width: 100vw;
    height: 100vh;
    box-shadow: none;
    border-radius: 0;
    overflow: hidden;
    position: relative;
    background-image: none; /* 1페이지 꽉참 구조를 위해 바인딩 제거 */
    transition: background-color 0.3s ease;
}

.book-reader-content {
    display: flex;
    flex-direction: row;
    height: 100%;
    margin: 0;
    padding: 0;
    font-size: var(--viewer-font-size);
    line-height: var(--viewer-line-height);
    letter-spacing: var(--viewer-letter-spacing);
    color: var(--viewer-text);
    font-family: var(--viewer-font);
    font-weight: 400;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    word-break: break-all;
    text-align: justify;
    scroll-behavior: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.book-reader-content::-webkit-scrollbar {
    display: none;
}
.book-reader-content {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.book-reader-content h2, .book-reader-content h3 {
    break-after: avoid;
    column-break-after: avoid;
    margin-top: 0;
    margin-bottom: 2rem;
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--viewer-text);
    letter-spacing: -0.05em;
}

.book-reader-content p {
    margin-bottom: 1.2em;
    text-indent: 0;
}

.book-reader-content section.preview-chapter {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
}

.chapter-bg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

.chapter-text-box {
    position: absolute;
    top: 10%;
    left: 5%;
    width: 45%;
    min-width: 300px;
    max-height: 80%;
    background: transparent;
    padding: 2.5rem;
    z-index: 10;
    cursor: move;
    border: 2px solid transparent;
    transition: border-color 0.2s;
    display: flex;
    flex-direction: column;
}
.chapter-text-content {
    flex: 1;
    overflow-y: auto;
    /* 스크롤바 숨기기 옵션 */
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.chapter-text-content::-webkit-scrollbar {
    display: none;
}

.chapter-text-box h2,
.chapter-text-box p {
    -webkit-text-stroke-width: var(--viewer-text-stroke, 1.5px);
    -webkit-text-stroke-color: var(--viewer-bg);
    paint-order: stroke fill;
    text-shadow: var(--viewer-text-shadow, 0px 3px 8px rgba(0,0,0,0.6));
    font-weight: var(--viewer-font-weight, 500);
    transition: text-shadow 0.2s ease, -webkit-text-stroke 0.2s ease, font-weight 0.2s ease, color 0.2s ease;
}

.chapter-text-box:hover {
    border-color: rgba(0,0,0,0.1);
}

.chapter-text-box .resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 24px;
    height: 24px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.2) 50%);
    opacity: 0;
    transition: opacity 0.2s;
    touch-action: none; /* 리사이즈 시 브라우저 기본 제스처 및 스크롤 차단 */
}

.chapter-text-box:hover .resize-handle {
    opacity: 1;
}

[data-theme="dark"] .chapter-text-box,
html[style*="--viewer-bg: #1a1a1a"] .chapter-text-box {
    background: transparent;
}

.cover-image-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 80vh;
    display: inline-block;
}
.cover-title-box {
    position: absolute;
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    min-width: 300px;
    text-align: center;
    background: var(--color-surface);
    padding: 1.5rem 2.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}
.cover-title-box h2 {
    margin: 0;
    font-size: 2.4rem;
    color: var(--color-primary);
    line-height: 1.3;
    word-break: keep-all;
}
.cover-author-box {
    position: absolute;
    bottom: 12%;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    min-width: 300px;
    text-align: center;
    background: var(--color-surface);
    padding: 1rem 2.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}

.hide-subtitles .chapter-text-box {
    display: none !important;
}

.subtitle-mode-active .chapter-text-box {
    display: none !important;
}

/* 뷰어 설정 패널 스타일 */
.viewer-settings-panel {
    position: absolute;
    top: 70px;
    right: 2rem;
    background: #ffffff;
    border-radius: var(--radius-md);
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    padding: 1.5rem;
    width: 320px;
    z-index: 100;
    border: 1px solid var(--color-border);
    overscroll-behavior: auto;
    touch-action: auto;
}

.setting-row {
    margin-bottom: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.setting-row:last-child { margin-bottom: 0; }
.setting-row label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-muted);
}
.setting-options {
    display: flex;
    gap: 0.5rem;
}
.setting-options button {
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    cursor: pointer;
}
.setting-options .theme-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    padding: 0;
    display: flex; justify-content: center; align-items: center;
    font-weight: bold;
}
.setting-options .theme-btn.active {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}
.setting-options .font-btn {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
}
.setting-options .font-btn.active {
    background: var(--color-primary);
    color: var(--color-primary-text);
    border-color: var(--color-primary);
}
.controls-group {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    display: flex; align-items: center;
}
.controls-group .control-btn {
    padding: 0.4rem 0.8rem;
    font-weight: bold;
    color: var(--color-text-main);
}
.controls-group .control-btn:hover { background: #eee; }
.val-display {
    padding: 0 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

.preview-nav-container {
    position: absolute;
    bottom: 0.5rem;
    right: 4rem;
    display: flex;
    gap: 0.8rem;
    z-index: 20;
}

.btn-page-nav {
    background: var(--color-surface);
    backdrop-filter: blur(4px);
    border: 1px solid var(--color-border);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    color: var(--color-text-main);
    transition: all 0.3s ease;
}

.btn-page-nav:hover {
    background: var(--color-bg);
    color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

@media (max-width: 768px) {
    .preview-nav-container {
        display: none !important; /* 모바일에서 하단 네비게이션 버튼 숨김 */
    }
    
    #view-preview .editor-toolbar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 100;
        background-color: transparent !important;
        backdrop-filter: none !important;
        padding: 1rem 1.2rem !important;
        transform: translateY(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s ease;
        box-shadow: none !important;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    
    .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }

    #view-preview .current-section-label {
        white-space: nowrap;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        text-overflow: clip;
        flex: 1;
        mask-image: linear-gradient(to right, black 85%, transparent 100%);
        -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
    }
    
    #view-preview .current-section-label::-webkit-scrollbar {
        display: none;
    }

    #view-preview .toolbar-right {
        width: auto;
        overflow: visible;
        justify-content: flex-end;
        gap: 0;
    }

    .preview-mobile-bottom-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 1rem 1.2rem;
        background-color: var(--viewer-bg, rgba(255, 255, 255, 0.95));
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 100;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s ease;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    #view-preview .editor-toolbar.show-mobile-toolbar ~ .preview-mobile-bottom-bar {
        transform: translateY(0);
    }
    
    #view-preview .editor-toolbar.show-mobile-toolbar {
        transform: translateY(0);
    }

    #view-preview:not(.hidden) {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
        overscroll-behavior: none;
    }

    .book-reader-wrapper {
        padding: 0 !important;
        height: 100vh;
        height: 100dvh;
        display: block !important;
    }
    
    .book-reader-container {
        height: 100vh;
        height: 100dvh;
        width: 100vw;
        border-radius: 0;
        box-shadow: none;
        padding: 0;
        box-sizing: border-box;
    }
    
    .book-reader-content {
        overflow-x: auto !important; /* 가로 스와이프 시 스냅 작동을 위해 auto로 변경 */
        scroll-snap-type: x mandatory !important;
        touch-action: pan-y pan-x; /* 스와이프 터치 제스처 허용을 위해 변경 */
        font-size: 1.05rem;
        line-height: 1.9;
    }

    @media (max-width: 900px) and (orientation: landscape) {
        .book-reader-container {
            width: 100vw !important;
            height: 100vh !important;
            height: 100dvh !important;
        }
        .chapter-bg-layer {
            position: absolute !important;
            top: 0 !important;
            left: 0 !important;
            width: 100vw !important;
            height: 100vh !important;
            height: 100dvh !important;
            object-fit: cover !important;
            z-index: 0 !important;
        }
        .chapter-text-box {
            padding-left: max(1.5rem, env(safe-area-inset-left)) !important;
            padding-right: max(1.5rem, env(safe-area-inset-right)) !important;
        }
        .viewer-settings-panel {
            position: fixed !important;
            top: 60px !important;
            right: max(1rem, env(safe-area-inset-right)) !important;
            max-height: calc(100vh - 80px) !important;
            max-height: calc(100dvh - 80px) !important;
            overflow-y: auto !important;
            -webkit-overflow-scrolling: touch !important;
            z-index: 150 !important;
            overscroll-behavior: auto !important;
            touch-action: auto !important;
        }
        .preview-mobile-bottom-bar {
            padding-left: max(1.2rem, env(safe-area-inset-left)) !important;
            padding-right: max(1.2rem, env(safe-area-inset-right)) !important;
        }
        #view-preview .editor-toolbar {
            padding-left: max(1.2rem, env(safe-area-inset-left)) !important;
            padding-right: max(1.2rem, env(safe-area-inset-right)) !important;
        }
    }

    @media (max-width: 768px) and (orientation: portrait) {
        .chapter-text-box h2,
        .chapter-text-box p {
            text-shadow: none;
            -webkit-text-stroke-width: 0;
        }
        .book-reader-content section.preview-chapter {
            display: flex;
            flex-direction: column;
            overflow-y: hidden;
            padding-top: calc(env(safe-area-inset-top, 0px) + 60px) !important;
        }
        .chapter-bg-layer {
            position: relative !important;
            height: auto !important;
            max-height: 55vh !important;
            width: 100% !important;
            object-fit: contain !important;
            object-position: center top !important;
            background: transparent !important;
            flex-shrink: 0 !important;
            display: block !important;
        }
        .chapter-text-box {
            position: relative;
            top: 0 !important;
            left: 0 !important;
            width: 100% !important;
            flex: 1;
            height: auto !important;
            max-height: none;
            background: transparent;
            backdrop-filter: none;
            box-shadow: none;
            border: none;
            padding: 1.5rem;
            cursor: default;
            display: flex;
            flex-direction: column;
            min-height: 0; /* 텍스트 넘침 시 레이아웃 팽창 방지 및 내부 스크롤 활성화 */
        }
        .chapter-text-content {
            overflow-y: auto;
            flex: 1;
            -webkit-overflow-scrolling: touch; /* iOS 부드러운 스크롤 */
            padding-bottom: 2.5rem; /* 하단 여백 추가로 글씨 가림 방지 */
        }
        .chapter-text-box .resize-handle {
            display: none !important;
        }
        .preview-chapter.cover-page {
            padding: calc(env(safe-area-inset-top, 0px) + 60px) 2rem 2rem 2rem !important;
            justify-content: center !important;
        }
        .preview-chapter.cover-page .preview-cover-image {
            max-height: 55vh !important;
        }
        .preview-chapter.cover-page .cover-image-wrapper {
            display: flex !important;
            flex-direction: column;
            align-items: center;
            width: 100%;
        }
        .preview-chapter.cover-page .cover-title-box,
        .preview-chapter.cover-page .cover-author-box {
            position: relative !important;
            top: auto !important;
            bottom: auto !important;
            right: auto !important;
            left: auto !important;
            width: 90% !important;
            text-align: center !important;
            margin-top: 1.5rem;
            padding: 1.2rem !important;
            transform: none !important;
        }
        .preview-chapter.cover-page .cover-title-box h2 {
            font-size: 1.8rem !important;
        }
        .preview-chapter.cover-page div[style*="position: absolute"] {
            position: relative !important;
            bottom: 0 !important;
            margin-top: 1.5rem;
            max-width: 100% !important;
        }
    }

    .viewer-settings-panel {
        position: fixed;
        top: 70px;
        right: 1rem;
        width: calc(100vw - 2rem);
        z-index: 101;
        max-height: calc(100vh - 140px);
        overflow-y: auto;
        overscroll-behavior: auto;
        touch-action: auto;
    }
}

/* -------------------------------------------------------------------------- */
/* Print (PDF) Styles                                                         */
/* -------------------------------------------------------------------------- */
@media print {
    @page {
        margin: 0;
        size: auto;
    }
    body * {
        visibility: hidden;
    }
    #view-preview, #view-preview * {
        visibility: visible;
    }
    #view-preview {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: auto !important;
        overflow: visible !important;
        background: var(--viewer-bg) !important;
        display: block !important;
    }
    /* 숨길 UI */
    .editor-toolbar, .preview-mobile-bottom-bar, #viewer-settings-panel, .preview-nav-container, #preview-subtitle-container {
        display: none !important;
    }
    .book-reader-wrapper, .book-reader-container, .book-reader-content {
        display: block !important;
        height: auto !important;
        width: 100% !important;
        overflow: visible !important;
        transform: none !important;
        position: static !important;
    }
    .preview-chapter {
        position: relative !important;
        width: 100% !important;
        height: 100vh !important;
        break-after: page !important;
        page-break-after: always !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .preview-chapter.cover-page {
        display: flex !important;
    }
    .chapter-bg-layer {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        z-index: 0 !important;
    }
    .chapter-text-box {
        position: absolute !important;
        z-index: 10 !important;
        height: auto !important;
        max-height: none !important;
    }
    .chapter-text-content {
        overflow: visible !important;
    }
    .resize-handle { 
        display: none !important; 
    }
    
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* -------------------------------------------------------------------------- */
/* Thumbnail Mode                                                             */
/* -------------------------------------------------------------------------- */
body.thumbnail-mode .cover-title-box {
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    border: 2px dashed transparent;
    cursor: move;
    padding: 0.5rem !important;
    width: auto !important;
    white-space: nowrap;
    z-index: 1000;
    transition: border-color 0.2s;
}

body.thumbnail-mode .cover-title-box:hover {
    border-color: rgba(255, 255, 255, 0.5);
}

body.thumbnail-mode .cover-author-box {
    display: none !important;
}

body.thumbnail-mode .cover-title-box h2 {
    font-family: 'Pretendard', 'NanumSquareRound', sans-serif !important;
    font-size: clamp(4rem, 12vw, 8rem) !important;
    font-weight: 900 !important;
    color: #fff !important;
    -webkit-text-stroke: 4px #000 !important;
    text-shadow: 6px 6px 0px #000, 0px 10px 30px rgba(0,0,0,0.8) !important;
    line-height: 1.1 !important;
}

body.thumbnail-mode .cover-author-box p {
    font-family: 'Pretendard', sans-serif !important;
    font-size: clamp(1.5rem, 4vw, 2.5rem) !important;
    font-weight: 800 !important;
    color: #ffd700 !important;
    -webkit-text-stroke: 2px #000 !important;
    text-shadow: 3px 3px 0px #000, 0px 5px 15px rgba(0,0,0,0.8) !important;
    text-decoration: none !important;
}

body.thumbnail-mode .chapter-text-box {
    display: none !important;
}

body.thumbnail-mode .cover-title-box .resize-handle {
    display: block !important;
    position: absolute;
    bottom: 0;
    right: 0;
    width: 32px;
    height: 32px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.8) 50%);
    opacity: 0;
    z-index: 10001;
    transition: opacity 0.2s;
}

body.thumbnail-mode .cover-title-box:hover .resize-handle {
    opacity: 1;
}

/* -------------------------------------------------------------------------- */
/* Footer Styles                                                              */
/* -------------------------------------------------------------------------- */
.app-footer {
    background-color: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 3rem 2.5rem;
    margin-top: 5rem;
}

.footer-container {
    max-width: 1080px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 3rem;
}

.footer-left {
    max-width: 500px;
}

.footer-logo {
    font-size: 1.5rem;
    color: var(--color-primary);
    margin-bottom: 1rem;
    font-weight: 600;
}

.footer-company-info {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.footer-copyright {
    color: var(--color-text-light);
    font-size: 0.8rem;
}

.footer-right {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: flex-start;
}

@media (min-width: 768px) {
    .footer-right {
        align-items: flex-end;
        text-align: right;
    }
}

.footer-socials {
    display: flex;
    gap: 1.2rem;
}

.footer-social-link {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.footer-social-link:hover {
    color: var(--color-primary);
}
```