/* =========================================
   E-book Reader Interface
   Conducting Textbook - Clean Reading Experience
   ========================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Merriweather:ital,wght@0,400;0,700;1,400&family=Noto+Serif+KR:wght@300;400;500;600;700&display=swap');

/* ── View Transitions API (MPA cross-document) ── */
@view-transition {
    navigation: auto;
}

/* ── Page slide-in animation (swipe entry) ── */
@keyframes page-slide-from-left {
    from { transform: translateX(-25%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
@keyframes page-slide-from-right {
    from { transform: translateX(25%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
.page.active.enter-from-left {
    animation: page-slide-from-left 250ms cubic-bezier(0.4, 0, 0.2, 1) both;
}
.page.active.enter-from-right {
    animation: page-slide-from-right 250ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* -----------------------------------------
   1. CSS Variables & Theming
   ----------------------------------------- */
:root {
    /* Light Mode Colors - Book Theme */
    --bg-primary: #e8e6e0;
    --bg-secondary: #f9f7f1;
    --bg-page: #ffffff;
    --text-primary: #2d2d2d;
    --text-secondary: #5a5a5a;
    --text-muted: #888888;
    --border-color: rgba(0, 0, 0, 0.06);
    --border-hover: rgba(0, 0, 0, 0.12);

    /* Accent Colors */
    --accent-blue: #3b82f6;
    --accent-green: #10b981;
    --accent-purple: #8b5cf6;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;

    /* E-book Specific */
    --header-height: 56px;

    --sidebar-width: 280px;
    --page-max-width: 960px;
    --card-gap: 20px;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Merriweather', Georgia, 'Times New Roman', serif;
    --font-size-base: 1.05rem;
    --line-height-base: 1.7;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] {
    --bg-primary: #1c1c1e;
    --bg-secondary: #242426;
    --bg-page: #2c2c2e;
    --text-primary: #e8e8e8;
    --text-secondary: #b8b8b8;
    --text-muted: #888888;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* -----------------------------------------
   2. Base Styles
   ----------------------------------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
    text-rendering: optimizeLegibility;
}

.hidden {
    display: none !important;
}

/* -----------------------------------------
   3. Layout - E-book Container
   ----------------------------------------- */
.ebook-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* -----------------------------------------
   4. Floating Navigation Buttons
   ----------------------------------------- */
.float-btn {
    position: fixed;
    top: 14px;
    z-index: 150;
    width: 34px;
    height: 34px;
    border: none;
    background: rgba(255, 255, 255, 0.6);
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0.75;
    transition: opacity 0.3s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.float-btn.hide-on-scroll {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.08s ease;
}

.float-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.float-menu { left: 14px; }
.float-home { right: 14px; }

/* Bottom float nav */
.float-prev {
    top: auto;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    left: 14px;
}

.float-next {
    top: auto;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    right: 14px;
}

.float-progress {
    top: auto;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    height: auto;
    border-radius: 17px;
    padding: 6px 14px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-direction: column;
    gap: 3px;
    cursor: pointer;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.progress-bar-mini {
    width: 48px;
    height: 3px;
    background: var(--bg-primary);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill-mini {
    height: 100%;
    background: var(--accent-blue);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.float-prev:disabled,
.float-next:disabled {
    opacity: 0.15;
    cursor: not-allowed;
    pointer-events: none;
}

[data-theme="dark"] .float-btn {
    background: rgba(50, 50, 52, 0.6);
    color: var(--text-muted);
}

[data-theme="dark"] .float-btn:hover {
    background: rgba(50, 50, 52, 0.9);
    color: var(--text-primary);
}

/* ── Page Slider (long-press scrubber) ── */
.page-slider-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    padding: 0 20px calc(60px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(transparent, rgba(0,0,0,0.4));
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.page-slider-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.page-slider-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 16px 0;
}

.page-slider-track {
    position: relative;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    touch-action: none;
}

.page-slider-overlay.active .page-slider-track {
    height: 6px;
    border-radius: 3px;
}

.page-slider-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: var(--accent-blue);
    border-radius: inherit;
    transition: width 0.05s linear;
}

.page-slider-thumb {
    position: absolute;
    top: 50%;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 6px rgba(0,0,0,0.3);
    transition: transform 0.15s ease;
}

.page-slider-thumb.dragging {
    transform: translate(-50%, -50%) scale(1.3);
}

.page-slider-preview {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.page-slider-preview img {
    max-width: 160px;
    max-height: 200px;
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    background: #fff;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.page-slider-preview img.loaded {
    opacity: 1;
}

.page-slider-label {
    text-align: center;
    margin-bottom: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="dark"] .page-slider-track {
    background: rgba(255,255,255,0.15);
}

/* -----------------------------------------
   4b. Running Page Header (textbook style)
   ----------------------------------------- */
.running-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 0 36px 16px;
    margin-bottom: 28px;
    border-bottom: none;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    user-select: none;
}

.running-header .rh-left,
.running-header .rh-right {
    white-space: nowrap;
}

/* Even page: number left, title right */
.running-header.even .rh-left {
    /* page number */
}
.running-header.even .rh-right {
    /* chapter title */
}

/* Odd page: title left, number right */
.running-header.odd .rh-left {
    /* chapter title */
}
.running-header.odd .rh-right {
    /* page number */
}

/* -----------------------------------------
   5. Page Container - Book Page
   ----------------------------------------- */
.page-container {
    flex: 1;
    position: relative;
    margin-top: 0;
    margin-bottom: 60px;
    overflow: hidden;
    max-width: var(--page-max-width);
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: 0;
    background: var(--bg-page);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.08);
}

.page {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 50px 60px;
    opacity: 0;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 400px;
    background: var(--bg-page);
}

.page.active {
    opacity: 1;
    transform: translateX(0);
    z-index: 2;
    position: relative;
}

.page.next {
    opacity: 0;
    transform: translateX(100%);
    z-index: 1;
}

.page.prev {
    opacity: 0;
    transform: translateX(-100%);
    z-index: 1;
}

/* Page transition animations */
.page.slide-out-left {
    opacity: 0;
    transform: translateX(-100%);
}

.page.slide-in-right {
    opacity: 1;
    transform: translateX(0);
}

.page.slide-out-right {
    opacity: 0;
    transform: translateX(100%);
}

.page.slide-in-left {
    opacity: 1;
    transform: translateX(0);
}

/* -----------------------------------------
   6. Content (Book-style, no cards)
   ----------------------------------------- */
.content-card {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    margin-bottom: 32px;
    box-shadow: none;
    transition: none;
}

.content-card:hover {
    box-shadow: none;
    border-color: transparent;
}

/* English Text - Book Style */
.card-header {
    display: block;
    margin-bottom: 20px;
    position: relative;
}

.tts-button {
    position: absolute;
    top: 0;
    right: 0;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    opacity: 0.4;
}

.tts-button:hover {
    background: var(--accent-blue);
    color: white;
    opacity: 1;
    transform: scale(1.1);
}

.tts-button.playing {
    background: var(--accent-red);
    color: white;
    opacity: 1;
}

.english-text {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    text-align: justify;
    hyphens: auto;
    padding-right: 40px;
}

.english-text:hover {
    color: var(--accent-blue);
}

.english-text strong {
    font-weight: 700;
    color: var(--text-primary);
}

.english-text em {
    font-style: italic;
    color: var(--text-secondary);
}

/* Translation Section - Book Style */
.translation-section {
    margin-top: 20px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease;
}

.translation-section.show {
    max-height: 1000px;
    opacity: 1;
}

.translation-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 0;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
    border-bottom: 1px solid transparent;
}

.translation-toggle:hover {
    background: transparent;
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

.translation-toggle i {
    font-size: 0.7rem;
    transition: transform 0.3s ease;
}

.translation-toggle.active i {
    transform: rotate(180deg);
}

.translation-content {
    background: transparent;
    border-radius: 0;
    padding: 20px 0;
    margin-top: 16px;
    border: none;
    border-left: 3px solid var(--border-color);
    padding-left: 20px;
}

.translation-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 12px;
    display: block;
}

.korean-text {
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text-secondary);
    text-align: justify;
}

/* Grammar Box - Book Style */
.grammar-box {
    margin-top: 16px;
    background: transparent;
    border-left: 2px solid var(--text-muted);
    border-radius: 0;
    padding: 12px 0 12px 20px;
}

.grammar-title {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.grammar-content {
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

.structure-tag {
    display: inline-block;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    background: transparent;
    color: var(--text-muted);
    margin-right: 6px;
    font-weight: 600;
    border: 1px solid var(--border-color);
}

/* Image - Book Style */
.image-card {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 32px 0;
    text-align: center;
}

.content-image {
    max-width: 100%;
    height: auto;
    border-radius: 0;
    cursor: pointer;
    transition: opacity 0.2s ease;
    box-shadow: none;
    border: 1px solid var(--border-color);
}

.content-image:hover {
    transform: none;
    opacity: 0.9;
    box-shadow: none;
}

.image-caption-en {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
    font-family: var(--font-serif);
}

.image-caption-ko {
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Interactive Words */
.interactive-word {
    cursor: inherit; /* Inherit cursor from parent sentence */
    border-radius: 4px;
    padding: 1px 3px;
    transition: none; /* No visual changes */
    user-select: none; /* Prevent text selection on double-click */
}

/* No hover effects - clean reading experience */
.interactive-word:hover {
    /* No changes */
}

/* No active effects */
.interactive-word:active {
    /* No changes */
}

/* -----------------------------------------
   6b. Paragraph-Based Interface
   ----------------------------------------- */

/* Individual Sentence */
.sentence {
    cursor: default;
    display: inline;
    color: var(--text-primary);
}

.sentence strong {
    font-weight: 700;
}

.sentence em {
    font-style: italic;
}

/* Sentence TTS Button - Hidden by default, shown on sentence click */
.sentence-tts-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    background: var(--accent-blue);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.65rem;
    margin-left: 4px;
    transition: all 0.2s ease;
    vertical-align: middle;
    opacity: 0.9;
}

.sentence-tts-button:hover {
    opacity: 1;
    transform: scale(1.1);
}

.sentence-tts-button.playing {
    background: var(--accent-red);
}

.sentence-tts-button.hidden {
    display: none;
}

/* =========================================
   Translation - Line-height Expansion + Overlay
   ========================================= */

/* =========================================
   Bilingual Side-by-Side Layout
   ========================================= */

.bilingual-container {
    display: flex;
    flex-direction: column;
}

.bilingual-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    padding: 14px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.bilingual-row:last-child {
    border-bottom: none;
}

/* 원문 (좌측) */
.original-col {
    font-family: var(--font-serif);
    font-size: calc(1.05rem * var(--font-size-scale, 1));
    line-height: 1.8;
    color: var(--text-primary);
}

.original-col .sentence {
    cursor: default;
    display: inline;
}

/* 번역 (우측) */
.translation-col {
    font-family: 'Noto Serif KR', '바탕', Batang, Georgia, serif;
    font-size: calc(1.02rem * var(--font-size-scale, 1));
    line-height: 1.85;
    color: #1a1a24;
    font-weight: 400;
    word-break: keep-all;
}

/* 다크모드 */
[data-theme="dark"] .bilingual-row {
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .translation-col {
    color: #dcdee8;
}

/* ── Role-based text styling ── */
.bilingual-row.bilingual-title .original-col,
.bilingual-row.bilingual-title .translation-col {
    font-size: 1.3em;
    font-weight: 700;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--glass-border, rgba(0,0,0,0.1));
    margin-bottom: 4px;
}
.bilingual-row.bilingual-subtitle .original-col,
.bilingual-row.bilingual-subtitle .translation-col {
    font-size: 1.1em;
    font-weight: 600;
}

/* 이미지 (전체 너비, 행 사이에 배치) */
.bilingual-image {
    padding: 20px 0;
    text-align: center;
}

.bilingual-image img {
    max-width: 100%;
    height: auto;
}

.bilingual-image .image-caption-en {
    margin-top: 10px;
    font-family: var(--font-serif);
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
}

.bilingual-image .image-caption-ko {
    margin-top: 4px;
    font-family: 'Noto Serif KR', serif;
    font-size: 0.82rem;
    color: var(--text-muted);
}

[data-theme="dark"] .bilingual-image img {
    opacity: 0.92;
}

.image-placeholder-viewer {
    padding: 32px 20px;
    background: rgba(245, 158, 11, 0.06);
    border: 2px dashed rgba(245, 158, 11, 0.3);
    border-radius: 8px;
    text-align: center;
    color: #a0937a;
    font-size: 0.9rem;
    font-style: italic;
    line-height: 1.6;
}

/* -----------------------------------------
   7. Footer Navigation (removed — now uses float-btn)
   ----------------------------------------- */

/* -----------------------------------------
   8. Sidebar (TOC)
   ----------------------------------------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100%;
    background: var(--bg-secondary);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
}

.sidebar.show {
    transform: translateX(0);
}

/* Sidebar Backdrop */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

/* ── Sidebar Header ── */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 12px 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.sidebar-controls {
    display: flex;
    align-items: center;
    gap: 2px;
}

.sidebar-ctrl-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-ctrl-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.sidebar-ctrl-btn:active {
    transform: scale(0.92);
}

.sidebar-close {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-left: 4px;
}

/* ── Sidebar Content ── */
.sidebar-content {
    padding: 8px 8px 20px;
    flex: 1;
    overflow-y: auto;
}

/* ── TOC List ── */
.toc-list {
    list-style: none;
}

/* ── Chapter Group ── */
.toc-chapter {
    margin-bottom: 1px;
}

.toc-chapter-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s ease;
    user-select: none;
}

.toc-chapter-header:hover {
    background: var(--bg-primary);
}

.toc-chapter.current > .toc-chapter-header {
    background: rgba(59, 130, 246, 0.06);
}

.toc-chevron {
    font-size: 0.5rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
    width: 12px;
    flex-shrink: 0;
    text-align: center;
    opacity: 0.6;
}

.toc-chapter-header.expanded .toc-chevron {
    transform: rotate(90deg);
}

.toc-chapter-info {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.toc-chapter-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    letter-spacing: 0.01em;
}

.toc-chapter-count {
    font-size: 0.6rem;
    color: var(--text-muted);
    flex-shrink: 0;
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 500;
    min-width: 18px;
    text-align: center;
}

.toc-chapter.current .toc-chapter-count {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
}

/* ── Chapter Pages (collapsible) ── */
.toc-chapter-pages {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.toc-chapter-pages.expanded {
    max-height: 3000px;
}

/* ── Individual Page Item ── */
.toc-page {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 28px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s ease;
    margin: 1px 4px 1px 0;
    position: relative;
}

.toc-page::before {
    content: '';
    position: absolute;
    left: 16px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border-color);
    opacity: 0.6;
}

.toc-page:last-child::before {
    bottom: 50%;
}

.toc-page:hover {
    background: var(--bg-primary);
}

.toc-page.active {
    background: var(--accent-blue);
    box-shadow: 0 1px 4px rgba(59, 130, 246, 0.25);
}

.toc-page.active::before {
    background: rgba(59, 130, 246, 0.3);
}

.toc-page-num {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
    width: 28px;
    font-variant-numeric: tabular-nums;
}

.toc-page.active .toc-page-num {
    color: rgba(255, 255, 255, 0.8);
}

.toc-page-title {
    font-size: 0.76rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 400;
}

.toc-page.active .toc-page-title {
    color: white;
}

.toc-page.unavail {
    opacity: 0.3;
    cursor: default;
}

.toc-chapter-label {
    font-size: 0.56rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-right: 2px;
    opacity: 0.7;
}

.toc-section-header {
    padding: 4px 10px 2px 28px;
    font-size: 0.66rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 6px;
    letter-spacing: 0.01em;
}

.toc-section-header.current .toc-sec-title {
    color: var(--accent-blue);
}

.toc-chapter-pages .toc-chapter-pages {
    max-height: none;
}

/* ── Dark mode adjustments ── */
[data-theme="dark"] .sidebar {
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .toc-chapter.current > .toc-chapter-header {
    background: rgba(59, 130, 246, 0.08);
}

[data-theme="dark"] .toc-chapter-count {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .toc-chapter.current .toc-chapter-count {
    background: rgba(59, 130, 246, 0.15);
}

/* Loading & Empty */
.empty-state {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    padding: 20px 0;
}

/* -----------------------------------------
   9. Word Popup - Tooltip Style
   ----------------------------------------- */
.word-popup {
    position: fixed;
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateY(5px);
}

.word-popup.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.popup-tooltip {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    max-width: 280px;
    position: relative;
}

[data-theme="dark"] .popup-tooltip {
    background: var(--bg-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Tooltip arrow - points up by default */
.popup-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    width: 12px;
    height: 12px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    transform: translateX(-50%) rotate(45deg);
}

[data-theme="dark"] .popup-tooltip::before {
    background: var(--bg-primary);
}

/* Arrow points down when popup is above word */
.word-popup[style*="--arrow-position: bottom"] .popup-tooltip::before {
    top: auto;
    bottom: -6px;
    border-left: none;
    border-top: none;
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.popup-word-container {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.popup-word {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-blue);
    font-family: var(--font-serif);
}

.popup-play-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--accent-blue);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.popup-play-btn:hover {
    background: var(--accent-blue);
    color: white;
    transform: scale(1.1);
}

.popup-close-btn {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    opacity: 0.6;
}

.popup-close-btn:hover {
    background: var(--accent-red);
    color: white;
    opacity: 1;
}

.popup-meaning {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
    line-height: 1.5;
}

.popup-grammar {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: transparent;
    padding: 6px 0 0 0;
    border-radius: 0;
    line-height: 1.4;
    border: none;
    border-top: 1px solid var(--border-color);
}

/* -----------------------------------------
   10. Image Overlay
   ----------------------------------------- */
.image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.overlay-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    z-index: 401;
}

.overlay-content img {
    max-width: 100%;
    max-height: 95vh;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.overlay-close-btn {
    position: absolute;
    top: -50px;
    right: 0;
    width: 40px;
    height: 40px;
    border: none;
    background: white;
    color: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all 0.2s ease;
}

.overlay-close-btn:hover {
    background: var(--accent-red);
    color: white;
    transform: scale(1.1);
}

/* -----------------------------------------
   11. Loading State
   ----------------------------------------- */
.loading-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.loading-state i {
    font-size: 2rem;
    margin-bottom: 16px;
    display: block;
}

.loading-state p {
    font-size: 0.95rem;
}

/* -----------------------------------------
   12. Animations
   ----------------------------------------- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* -----------------------------------------
   13. Responsive Design
   ----------------------------------------- */

/* Tablet */
@media (max-width: 768px) {
    :root {

        --page-max-width: 100%;
        --sidebar-width: 260px;
    }

    .page {
        padding: 30px 20px;
    }

    .running-header {
        font-size: 0.62rem;
        margin-bottom: 18px;
        padding-bottom: 10px;
    }

    .bilingual-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .translation-col {
        padding-left: 14px;
        border-left: 2px solid rgba(59, 130, 246, 0.15);
        font-size: 0.88rem;
    }

    .bilingual-row.bilingual-title .translation-col,
    .bilingual-row.bilingual-subtitle .translation-col {
        border-left: none;
        padding-left: 0;
    }

}

/* Mobile */
@media (max-width: 480px) {
    :root {
        --font-size-base: 1rem;
    }

    .page {
        padding: 24px 20px;
    }

    .content-card {
        padding: 0;
    }

    .english-text {
        font-size: 1.05rem;
        padding-right: 35px;
    }

    .korean-text {
        font-size: 0.9rem;
    }

    /* Paragraph mode mobile optimization */
    .paragraph-content {
        font-size: 1.05rem;
        line-height: 1.75;
    }

    .sentence {
        padding: 3px 5px;
        margin: -3px -5px;
    }

    .inline-translation {
        font-size: 0.85rem;
        padding-left: 16px;
    }

    .sentence-tts-button {
        width: 24px;
        height: 24px;
        font-size: 0.7rem;
    }

    /* Word popup mobile optimization */
    .popup-tooltip {
        max-width: calc(100vw - 40px);
        padding: 10px 14px;
    }

    .popup-word {
        font-size: 1rem;
    }

    .popup-meaning {
        font-size: 0.9rem;
    }

    .popup-grammar {
        font-size: 0.75rem;
    }
}

/* Desktop - Sidebar toggleable but menu button hidden by default */
@media (min-width: 1024px) {
    body.sidebar-open {
        padding-left: var(--sidebar-width);
    }

    /* Remove forced visibility - let .show class control it */
    .sidebar.show {
        transform: translateX(0);
    }
}

/* -----------------------------------------
   14. Print Styles
   ----------------------------------------- */
@media print {
    .float-btn,
    .sidebar,
    .tts-button,
    .translation-toggle {
        display: none !important;
    }

    .page-container {
        margin: 0;
        padding: 0;
    }

    .page {
        position: static;
        opacity: 1;
        transform: none;
    }

    .content-card {
        page-break-inside: avoid;
    }
}

/* -----------------------------------------
   Page Continuity Indicators
   ----------------------------------------- */
.continuity-indicator {
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(74, 108, 247, 0.06);
    border-left: 3px solid var(--accent-color, #4a6cf7);
    margin: 12px 0;
}
.continuity-indicator.from-prev {
    margin-bottom: 16px;
}
.continuity-indicator.to-next {
    margin-top: 16px;
}
.continuity-badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-color, #4a6cf7);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.continuity-badge:hover {
    text-decoration: underline;
}
.continuity-fragment {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.continuity-fragment .frag-en {
    font-family: var(--font-english, 'Merriweather', serif);
    font-size: 0.82rem;
    color: var(--text-secondary, #5a5a5a);
    font-style: italic;
}
.continuity-fragment .frag-ko {
    font-family: var(--font-korean, 'Noto Serif KR', serif);
    font-size: 0.78rem;
    color: var(--text-muted, #888);
}

[data-theme="dark"] .continuity-indicator {
    background: rgba(74, 108, 247, 0.1);
    border-left-color: #6b8cff;
}
[data-theme="dark"] .continuity-badge {
    color: #6b8cff;
}
[data-theme="dark"] .continuity-fragment .frag-en {
    color: #b0b0b0;
}
[data-theme="dark"] .continuity-fragment .frag-ko {
    color: #888;
}

/* Dark mode text color override */
[data-theme="dark"] .original-col,
[data-theme="dark"] .sentence,
[data-theme="dark"] .sentence * {
    color: #e8e8e8 !important;
}

/* ── Image Lightbox ── */
.img-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(18, 18, 22, 0);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    overflow: hidden;
    transition: background 300ms ease;
}

.img-lightbox.active {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(18, 18, 22, 0.96);
}

.img-lightbox.closing {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: rgba(18, 18, 22, 0) !important;
    transition: background 250ms ease;
}

.lightbox-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

.img-lightbox img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform-origin: 0 0;
    will-change: transform;
    user-select: none;
    -webkit-user-select: none;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.08),
        0 4px 16px rgba(0, 0, 0, 0.25),
        0 12px 40px rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.img-lightbox.closing img {
    opacity: 0;
    transform: scale(0.92) !important;
    transition: opacity 200ms ease, transform 250ms cubic-bezier(0.4, 0, 1, 1);
}
