/* ═══════════════════════════════════════════════════════════════
   mkbooks Reader — Editorial Digital Reading Experience
   Typography: Literata (body) + DM Sans (UI)
   Pagination: CSS multi-column + JS translateX
   ═══════════════════════════════════════════════════════════════ */

/* ── Theme tokens ─────────────────────────────────────────── */
[data-theme="light"] {
    --bg:            #F6F4F0;
    --bg-surface:    #FFFFFF;
    --text:          #1C1917;
    --text-muted:    #78716C;
    --text-faint:    #A8A29E;
    --accent:        #92400E;
    --accent-soft:   rgba(146, 64, 14, 0.08);
    --border:        #E7E5E4;
    --shadow:        rgba(28, 25, 23, 0.06);
    --shadow-deep:   rgba(28, 25, 23, 0.12);
    --bar-bg:        rgba(255, 255, 255, 0.88);
    --bar-border:    rgba(231, 229, 228, 0.7);
    --drawer-bg:     #FFFFFF;
    --overlay-bg:    rgba(28, 25, 23, 0.3);
    --progress-bg:   #E7E5E4;
    --progress-fill: #92400E;
    --code-bg:       #F5F5F4;
    --blockquote-border: #D6D3D1;
    --cover-shadow:  rgba(28, 25, 23, 0.25);
}

[data-theme="dark"] {
    --bg:            #171412;
    --bg-surface:    #231F1C;
    --text:          #E7E5E4;
    --text-muted:    #A8A29E;
    --text-faint:    #57534E;
    --accent:        #D4A056;
    --accent-soft:   rgba(212, 160, 86, 0.10);
    --border:        #2E2A27;
    --shadow:        rgba(0, 0, 0, 0.2);
    --shadow-deep:   rgba(0, 0, 0, 0.4);
    --bar-bg:        rgba(23, 20, 18, 0.92);
    --bar-border:    rgba(46, 42, 39, 0.7);
    --drawer-bg:     #1E1B18;
    --overlay-bg:    rgba(0, 0, 0, 0.5);
    --progress-bg:   #2E2A27;
    --progress-fill: #D4A056;
    --code-bg:       #1E1B18;
    --blockquote-border: #44403C;
    --cover-shadow:  rgba(0, 0, 0, 0.5);
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background 0.35s ease, color 0.35s ease;
}

body {
    height: 100%;
    overflow: hidden;
    font-family: 'Literata', Georgia, 'Times New Roman', serif;
    font-size: 18px;
    line-height: 1.78;
}

/* ── Top Bar ──────────────────────────────────────────────── */
.reader-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    height: 52px;
    padding: 0 12px;
    background: var(--bar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--bar-border);
    transition: transform 0.3s ease, background 0.35s ease;
    font-family: 'DM Sans', system-ui, sans-serif;
}

.reader-bar.hidden {
    transform: translateY(-100%);
}

.bar-title {
    flex: 1;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 8px;
    transition: color 0.35s ease;
}

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

.bar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    text-decoration: none;
}

.bar-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.bar-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.print-link {
    color: var(--text-faint);
}

.print-link:hover {
    color: var(--accent);
}

/* ── TOC Drawer ───────────────────────────────────────────── */
.toc-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: var(--overlay-bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

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

.toc-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1200;
    width: 320px;
    max-width: 85vw;
    background: var(--drawer-bg);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), background 0.35s ease;
    display: flex;
    flex-direction: column;
    font-family: 'DM Sans', system-ui, sans-serif;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.toc-drawer.open {
    transform: translateX(0);
}

.toc-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

.toc-drawer-title {
    font-family: 'Literata', Georgia, serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    transition: color 0.35s ease;
}

.toc-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    flex-shrink: 0;
}

.toc-close-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.toc-close-btn svg {
    width: 18px;
    height: 18px;
}

.toc-drawer-subtitle {
    padding: 4px 24px 0;
    font-size: 13px;
    font-style: italic;
    color: var(--text-muted);
    line-height: 1.4;
    transition: color 0.35s ease;
}

.toc-drawer-author {
    padding: 4px 24px 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-faint);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transition: color 0.35s ease;
}

.toc-list {
    list-style: none;
    padding: 0 12px 24px;
    flex: 1;
}

.toc-list li {
    margin: 0;
}

.toc-link {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
    line-height: 1.4;
    transition: background 0.12s ease, color 0.12s ease;
}

.toc-link:hover {
    background: var(--accent-soft);
}

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

.toc-link-num {
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 22px;
    transition: color 0.35s ease;
}

.toc-link.active .toc-link-num {
    color: var(--accent);
}

.toc-link-title {
    transition: color 0.35s ease;
}

/* ── Reader Viewport ──────────────────────────────────────── */
.reader-viewport {
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    bottom: 44px;
    overflow: hidden;
}

/* ── Sections (cover + chapters) ──────────────────────────── */
.reader-section {
    position: absolute;
    inset: 0;
}

/* ── Cover ────────────────────────────────────────────────── */
.reader-cover {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    transition: background 0.35s ease;
}

.cover-image-wrap {
    max-width: 360px;
    width: 60%;
    aspect-ratio: 2 / 3;
    border-radius: 4px;
    overflow: hidden;
    box-shadow:
        0 20px 60px var(--cover-shadow),
        0 4px 12px var(--shadow);
    transition: box-shadow 0.35s ease;
}

.cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cover-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 40px;
}

.cover-fallback-inner {
    max-width: 360px;
    width: 60%;
    aspect-ratio: 2 / 3;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    box-shadow:
        0 20px 60px var(--cover-shadow),
        0 4px 12px var(--shadow);
    transition: box-shadow 0.35s ease;
}

.cover-title {
    font-family: 'Literata', Georgia, serif;
    font-size: 28px;
    font-weight: 700;
    line-height: 1.15;
    margin-bottom: 8px;
}

.cover-subtitle {
    font-family: 'Literata', Georgia, serif;
    font-size: 14px;
    font-style: italic;
    margin-bottom: 16px;
    opacity: 0.85;
}

.cover-author {
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    opacity: 0.8;
}

/* ── Chapter Columns (pagination container) ───────────────── */
.reader-chapter {
    overflow: hidden;  /* clip horizontal column overflow — KEEP here, NOT on .chapter-columns */
}

.chapter-columns {
    height: 100%;
    padding-top: 48px;
    padding-bottom: 24px;
    column-fill: auto;
    /* column-width, column-gap, padding-left, padding-right are set dynamically by reader.js */
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    will-change: transform;
}

/* ── Chapter Typography ───────────────────────────────────── */
.chapter-header {
    break-after: avoid;
    break-inside: avoid;
    text-align: center;
    padding-top: 20px;
    padding-bottom: 32px;
    margin-bottom: 8px;
}

.ch-number {
    display: block;
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 12px;
    transition: color 0.35s ease;
}

.ch-number::before {
    content: 'Chapter ';
}

.ch-title {
    font-family: 'Literata', Georgia, serif;
    font-size: 32px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
    letter-spacing: -0.01em;
    transition: color 0.35s ease;
}

/* Body text */
.chapter-body {
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
}

.chapter-body > h1:first-child {
    display: none;
}

.chapter-body p {
    margin: 0 0 0.9em;
    text-indent: 1.5em;
    orphans: 3;
    widows: 3;
}

.chapter-body > p:first-of-type {
    text-indent: 0;
}

.chapter-body > h1 + p {
    text-indent: 0;
}

.chapter-body > h2 + p {
    text-indent: 0;
}

.chapter-body > h3 + p {
    text-indent: 0;
}

.chapter-body > blockquote + p {
    text-indent: 0;
}

.chapter-body > hr + p {
    text-indent: 0;
}

/* Drop cap — first paragraph */
.chapter-body > p:first-of-type::first-letter {
    font-size: 3.4em;
    float: left;
    line-height: 0.78;
    padding-right: 8px;
    padding-top: 5px;
    font-weight: 700;
    color: var(--accent);
    font-family: 'Literata', Georgia, serif;
    transition: color 0.35s ease;
}

/* Headings */
.chapter-body h2 {
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 22px;
    font-weight: 600;
    margin: 1.8em 0 0.6em;
    color: var(--text);
    text-align: left;
    letter-spacing: -0.01em;
    transition: color 0.35s ease;
}

.chapter-body h3 {
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 17px;
    font-weight: 600;
    margin: 1.4em 0 0.5em;
    color: var(--text);
    text-align: left;
    transition: color 0.35s ease;
}

/* Scene break */
.chapter-body hr {
    border: none;
    text-align: center;
    margin: 1.8em 0;
    break-before: avoid;
}

.chapter-body hr::after {
    content: "✦   ✦   ✦";
    font-size: 10px;
    letter-spacing: 4px;
    color: var(--text-faint);
    transition: color 0.35s ease;
}

/* Blockquote */
.chapter-body blockquote {
    margin: 1.4em 1.5em;
    padding: 0;
    border-left: 3px solid var(--blockquote-border);
    padding-left: 18px;
    font-style: italic;
    color: var(--text-muted);
    transition: border-color 0.35s ease, color 0.35s ease;
}

.chapter-body blockquote p {
    text-indent: 0;
    margin-bottom: 0.5em;
}

/* Inline */
.chapter-body strong {
    font-weight: 700;
}

.chapter-body em {
    font-style: italic;
}

/* Code */
.chapter-body code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 0.85em;
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.35s ease;
}

.chapter-body pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    padding: 14px 18px;
    overflow-x: auto;
    font-size: 14px;
    line-height: 1.5;
    border-radius: 6px;
    margin: 1.4em 0;
    transition: background 0.35s ease, border-color 0.35s ease;
}

.chapter-body pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

/* Lists */
.chapter-body ul {
    margin: 0.8em 0;
    padding-left: 1.8em;
}

.chapter-body ol {
    margin: 0.8em 0;
    padding-left: 1.8em;
}

.chapter-body li {
    margin-bottom: 0.3em;
}

.chapter-body li p {
    text-indent: 0;
    margin-bottom: 0.3em;
}

/* Images */
.chapter-body img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.5em auto;
    border-radius: 4px;
}

/* Footnotes */
.footnote-ref {
    font-size: 0.75em;
    vertical-align: super;
    text-decoration: none;
    color: var(--accent);
    transition: color 0.35s ease;
}

.footnotes {
    margin-top: 2em;
    padding-top: 1em;
    border-top: 1px solid var(--border);
    font-size: 14px;
    color: var(--text-muted);
    transition: border-color 0.35s ease, color 0.35s ease;
}

.footnotes ol {
    padding-left: 1.5em;
}

.footnotes li {
    margin-bottom: 0.5em;
}

/* ── Bottom Bar ───────────────────────────────────────────── */
.reader-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: 44px;
    background: var(--bar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--bar-border);
    transition: transform 0.3s ease, background 0.35s ease;
    font-family: 'DM Sans', system-ui, sans-serif;
}

.reader-footer.hidden {
    transform: translateY(100%);
}

.footer-inner {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 8px;
    gap: 6px;
}

.footer-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.footer-nav-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.footer-nav-btn:active {
    transform: scale(0.92);
}

.footer-nav-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.footer-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
}

.page-info {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    transition: color 0.35s ease;
}

.progress-track {
    width: 100%;
    height: 3px;
    background: var(--progress-bg);
    border-radius: 2px;
    overflow: hidden;
    transition: background 0.35s ease;
}

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

/* ── Tap Zones ────────────────────────────────────────────── */
.tap-zone {
    position: fixed;
    top: 52px;
    bottom: 44px;
    z-index: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.tap-prev {
    left: 0;
    width: 30%;
}

.tap-next {
    right: 0;
    width: 50%;
}

/* Center zone for toggling bars — handled by JS on the gap between tap zones */

/* ── Page turn animation feedback ─────────────────────────── */
.reader-section.turning-prev .chapter-columns {
    animation: page-hint-prev 0.2s ease;
}

.reader-section.turning-next .chapter-columns {
    animation: page-hint-next 0.2s ease;
}

@keyframes page-hint-prev {
    0% { filter: brightness(0.97); }
    100% { filter: brightness(1); }
}

@keyframes page-hint-next {
    0% { filter: brightness(0.97); }
    100% { filter: brightness(1); }
}

/* ── Responsive ───────────────────────────────────────────── */

/* Mobile — compact everything */
@media (max-width: 600px) {
    body {
        font-size: 16px;
        line-height: 1.72;
    }

    .reader-bar {
        height: 48px;
        padding: 0 8px;
    }

    .bar-title {
        font-size: 13px;
    }

    .bar-btn {
        width: 36px;
        height: 36px;
    }

    .bar-btn svg {
        width: 18px;
        height: 18px;
    }

    .reader-viewport {
        top: 48px;
        bottom: 40px;
    }

    .chapter-columns {
        padding-top: 28px;
        padding-bottom: 16px;
    }

    .chapter-header {
        padding-top: 8px;
        padding-bottom: 20px;
    }

    .ch-title {
        font-size: 26px;
    }

    .ch-number {
        font-size: 11px;
    }

    .reader-footer {
        height: 40px;
    }

    .footer-inner {
        padding: 0 14px;
        gap: 12px;
    }

    .page-info {
        font-size: 11px;
    }

    .footer-nav-btn {
        width: 32px;
        height: 32px;
    }

    .footer-nav-btn svg {
        width: 16px;
        height: 16px;
    }

    .tap-zone {
        top: 48px;
        bottom: 40px;
    }

    .cover-image-wrap {
        width: 70%;
        max-width: 280px;
    }

    .cover-fallback-inner {
        width: 70%;
        max-width: 280px;
        padding: 28px 18px;
    }

    .cover-title {
        font-size: 22px;
    }

    .cover-subtitle {
        font-size: 12px;
    }
}

/* Tablet */
@media (min-width: 601px) and (max-width: 1024px) {
    .chapter-columns {
        padding-top: 40px;
        padding-bottom: 20px;
    }
}

/* ── Print — hide reader UI ───────────────────────────────── */
@media print {
    .reader-bar,
    .reader-footer,
    .toc-drawer,
    .toc-overlay,
    .tap-zone {
        display: none !important;
    }
}
