/**
 * Booky - Estilização de Leitura e Packs Tipográficos
 * Suporte a Fantasia, Sci-Fi, Corporativo, Romance, Booky Dark e Clássicos
 */

/* ==========================================================================
   Variáveis dos Temas de Leitura
   ========================================================================== */

/* Tema Principal Padrão: Booky Dark (Roxo Noturno Moderno) */
:root,
body[data-theme="booky-dark"] {
    --theme-bg: #0c0915;
    --theme-paper: #130e24;
    --theme-text: #e9d5ff;
    --theme-muted: #94a3b8;
    --theme-heading: #faf5ff;
    --theme-accent: #8b5cf6;
    --theme-accent-hover: #a855f7;
    --theme-accent-glow: rgba(139, 92, 246, 0.4);
    --theme-border: rgba(139, 92, 246, 0.2);
    --theme-glass: rgba(18, 14, 34, 0.88);
    --theme-glass-border: rgba(139, 92, 246, 0.22);
    --theme-shadow: 0 4px 24px rgba(0, 0, 0, 0.65);
    --theme-drop-cap: #c084fc;
    --theme-ornament: #8b5cf6;
    --theme-selection: rgba(168, 85, 247, 0.35);
}

/* Tema 2: Sci-Fi Cyberpunk Dark (Deep Navy & Neon Cyan) */
body[data-theme="cyber-dark"] {
    --theme-bg: #080c14;
    --theme-paper: #0e1526;
    --theme-text: #e0f2fe;
    --theme-muted: #64748b;
    --theme-heading: #38bdf8;
    --theme-accent: #06b6d4;
    --theme-accent-hover: #22d3ee;
    --theme-accent-glow: rgba(6, 182, 212, 0.4);
    --theme-border: rgba(6, 182, 212, 0.2);
    --theme-glass: rgba(14, 21, 38, 0.88);
    --theme-glass-border: rgba(6, 182, 212, 0.22);
    --theme-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
    --theme-drop-cap: #38bdf8;
    --theme-ornament: #06b6d4;
    --theme-selection: rgba(6, 182, 212, 0.3);
}

/* Tema 3: Pergaminho de Westeros (Fantasia Quente) */
body[data-theme="parchment"] {
    --theme-bg: #f5ecd7;
    --theme-paper: #f9f3e5;
    --theme-text: #2a2119;
    --theme-muted: #786957;
    --theme-heading: #3a1c0d;
    --theme-accent: #b45309;
    --theme-accent-hover: #92400e;
    --theme-accent-glow: rgba(180, 83, 9, 0.3);
    --theme-border: rgba(120, 105, 87, 0.18);
    --theme-glass: rgba(245, 236, 215, 0.88);
    --theme-glass-border: rgba(120, 105, 87, 0.15);
    --theme-shadow: 0 4px 20px rgba(42, 33, 25, 0.08);
    --theme-drop-cap: #92400e;
    --theme-ornament: #b45309;
    --theme-selection: rgba(180, 83, 9, 0.2);
}

/* Tema 4: Patrulha da Noite (Obsidiana / Preto OLED) */
body[data-theme="night"] {
    --theme-bg: #09090b;
    --theme-paper: #121215;
    --theme-text: #e4e4e7;
    --theme-muted: #71717a;
    --theme-heading: #fafafa;
    --theme-accent: #a855f7;
    --theme-accent-hover: #c084fc;
    --theme-accent-glow: rgba(168, 85, 247, 0.35);
    --theme-border: rgba(255, 255, 255, 0.12);
    --theme-glass: rgba(18, 18, 21, 0.88);
    --theme-glass-border: rgba(255, 255, 255, 0.12);
    --theme-shadow: 0 4px 24px rgba(0, 0, 0, 0.8);
    --theme-drop-cap: #c084fc;
    --theme-ornament: #a855f7;
    --theme-selection: rgba(168, 85, 247, 0.25);
}

/* Tema 5: Cidadela (Warm Sepia Clássico) */
body[data-theme="sepia"] {
    --theme-bg: #f7efe1;
    --theme-paper: #fcf7ed;
    --theme-text: #453728;
    --theme-muted: #8b7964;
    --theme-heading: #312314;
    --theme-accent: #8b5cf6;
    --theme-accent-hover: #7c3aed;
    --theme-accent-glow: rgba(139, 92, 246, 0.25);
    --theme-border: rgba(94, 72, 40, 0.15);
    --theme-glass: rgba(247, 239, 225, 0.9);
    --theme-glass-border: rgba(94, 72, 40, 0.14);
    --theme-shadow: 0 4px 20px rgba(69, 55, 40, 0.08);
    --theme-drop-cap: #7c3aed;
    --theme-ornament: #8b5cf6;
    --theme-selection: rgba(139, 92, 246, 0.2);
}

/* Tema 6: Winterfell (Clean White - Apple Books Clássico) */
body[data-theme="white"] {
    --theme-bg: #ffffff;
    --theme-paper: #ffffff;
    --theme-text: #1d1d1f;
    --theme-muted: #86868b;
    --theme-heading: #111112;
    --theme-accent: #7c3aed;
    --theme-accent-hover: #6d28d9;
    --theme-accent-glow: rgba(124, 58, 237, 0.25);
    --theme-border: rgba(0, 0, 0, 0.08);
    --theme-glass: rgba(255, 255, 255, 0.88);
    --theme-glass-border: rgba(0, 0, 0, 0.08);
    --theme-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    --theme-drop-cap: #7c3aed;
    --theme-ornament: #7c3aed;
    --theme-selection: rgba(124, 58, 237, 0.18);
}

/* Tema 7: Fogo Valiriano (Esmeralda Noturna) */
body[data-theme="valyrian"] {
    --theme-bg: #0d1514;
    --theme-paper: #121c1b;
    --theme-text: #cfe2dd;
    --theme-muted: #74928b;
    --theme-heading: #eef7f4;
    --theme-accent: #10b981;
    --theme-accent-hover: #34d399;
    --theme-accent-glow: rgba(16, 185, 129, 0.35);
    --theme-border: rgba(16, 185, 129, 0.18);
    --theme-glass: rgba(13, 21, 20, 0.9);
    --theme-glass-border: rgba(16, 185, 129, 0.18);
    --theme-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
    --theme-drop-cap: #34d399;
    --theme-ornament: #10b981;
    --theme-selection: rgba(16, 185, 129, 0.25);
}

/* ==========================================================================
   Estilização do Livro e Conteúdo
   ========================================================================== */

::selection {
    background: var(--theme-selection);
    color: inherit;
}

/* Conteúdo de leitura */
.reader-article {
    color: var(--theme-text);
    transition: color 0.25s ease;
}

/* Famílias de fontes */
body[data-font="garamond"] .reader-article {
    font-family: "EB Garamond", Garamond, Georgia, serif;
}
body[data-font="space"] .reader-article {
    font-family: "Space Grotesk", "Inter", -apple-system, sans-serif;
}
body[data-font="cormorant"] .reader-article {
    font-family: "Cormorant Garamond", Georgia, serif;
}
body[data-font="merriweather"] .reader-article {
    font-family: "Merriweather", Georgia, serif;
}
body[data-font="inter"] .reader-article {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body[data-font="jetbrains"] .reader-article {
    font-family: "JetBrains Mono", Consolas, monospace;
}

/* Títulos épicos em Cinzel (Compatível com Game of Thrones e EPUBs padrão) */
.reader-article h1,
.reader-article h2,
.reader-article h3,
.reader-article h4,
.reader-article .titulo-corpo-18,
.reader-article .titulo-ficha-tecnica,
.reader-article .chapter_heading,
.reader-header-title,
.fantasy-title {
    font-family: "Cinzel", "EB Garamond", Georgia, serif !important;
    font-weight: 700 !important;
    color: var(--theme-heading) !important;
    letter-spacing: 0.07em !important;
    line-height: 1.3 !important;
}

.reader-article h1,
.reader-article .titulo-corpo-18,
.reader-article .chapter_heading {
    font-size: 1.85em !important;
    text-align: center !important;
    margin-top: 1.8em !important;
    margin-bottom: 0.8em !important;
    text-transform: uppercase !important;
    display: block !important;
}

.reader-article h2 {
    font-size: 1.35em !important;
    text-align: center !important;
    margin-top: 1.4em !important;
    margin-bottom: 0.4em !important;
    color: var(--theme-accent) !important;
}

.reader-article h3 {
    font-size: 1.15em !important;
    margin-top: 1.2em !important;
    margin-bottom: 0.3em !important;
}

/* Subtítulo de capítulo (ex: Além da Muralha) */
.chapter-subtitle,
.reader-article .subtitle {
    text-align: center;
    font-family: "EB Garamond", Georgia, serif;
    font-style: italic;
    font-size: 1.05em;
    color: var(--theme-muted);
    margin-bottom: 1.8em;
    letter-spacing: 0.02em;
}

/* Divisores ornamentais */
.flourish,
.ornament-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1.8em 0;
    color: var(--theme-ornament);
    font-size: 1.25em;
    opacity: 0.85;
    user-select: none;
}

.flourish::before,
.flourish::after {
    content: "";
    display: inline-block;
    height: 1px;
    width: 40px;
    background: currentColor;
    margin: 0 14px;
    opacity: 0.4;
}

/* Parágrafos da prosa (Mapeamento específico para GOT) */
.reader-article p,
.reader-article .texto,
.reader-article p.texto {
    margin-top: 0 !important;
    margin-bottom: 0.85em !important;
    text-indent: 1.6em !important;
    text-align: justify !important;
    hyphens: auto;
    -webkit-hyphens: auto;
    word-break: break-word;
    color: var(--theme-text) !important;
}

/* Primeiro parágrafo não tem recuo */
.reader-article p:first-of-type,
.reader-article p.first-p,
.reader-article .texto-sem-firstline-inicio-CAPITULAR,
.reader-article .texto-sem-firstline-inicio-2CAPITULAR,
.reader-article h1 + p,
.reader-article h2 + p,
.reader-article .titulo-corpo-18 + p,
.reader-article .flourish + p {
    text-indent: 0 !important;
}

/* Suporte à formatação interna do livro */
.reader-article span.Regular {
    color: inherit !important;
    font-family: inherit !important;
    font-size: inherit !important;
    line-height: inherit !important;
}
.reader-article span.Italic {
    font-style: italic !important;
    color: inherit !important;
}
.reader-article span.Bold {
    font-weight: 700 !important;
    color: inherit !important;
}
.reader-article .imagem-centrada {
    text-align: center !important;
    margin: 1.5em auto !important;
}
.reader-article .TOC {
    display: none !important;
}

/* Travessão ou aspas de diálogo antes de capitulares */
.dialogue-dash {
    font-size: 1.2em !important;
    font-family: inherit !important;
    color: var(--theme-text) !important;
    float: left !important;
    margin-right: 4px !important;
    line-height: 1.2 !important;
    font-weight: 500 !important;
}

/* Capitular (Drop Cap) - estritamente a 1ª letra majestosa */
body.enable-dropcap .reader-article .drop-cap {
    float: left !important;
    font-family: "Cinzel", "EB Garamond", serif !important;
    font-size: 3.1em !important;
    line-height: 0.82 !important;
    padding-top: 2px !important;
    padding-right: 6px !important;
    padding-bottom: 2px !important;
    color: var(--theme-drop-cap) !important;
    font-weight: 700 !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    margin-right: 4px !important;
    margin-top: 2px !important;
}

body:not(.enable-dropcap) .reader-article .char-style-override-1,
body:not(.enable-dropcap) .reader-article .drop-cap {
    float: none !important;
    font-size: inherit !important;
    line-height: inherit !important;
    color: inherit !important;
    font-family: inherit !important;
    padding: 0 !important;
    margin: 0 !important;
    font-weight: inherit !important;
    text-shadow: none !important;
}

body:not(.enable-dropcap) .dialogue-dash {
    float: none !important;
    font-size: inherit !important;
    line-height: inherit !important;
    margin: 0 !important;
}

/* Card Navegador de Final de Capítulo */
.chapter-end-nav {
    margin-top: 3.5em;
    padding: 24px 16px;
    text-align: center;
    border-top: 1px solid var(--theme-border);
    background: rgba(120, 105, 87, 0.04);
    border-radius: 12px;
}

.chapter-end-title {
    font-family: "Cinzel", serif;
    font-size: 0.9em;
    color: var(--theme-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 12px;
}

.chapter-next-btn {
    font-family: "Cinzel", "SF Pro Text", sans-serif;
    font-size: 0.95rem;
    padding: 10px 22px;
    letter-spacing: 0.04em;
    box-shadow: var(--theme-shadow);
}

/* Diálogos e citações em itálico */
.reader-article blockquote {
    margin: 1.4em 1.2em;
    padding-left: 1em;
    border-left: 2px solid var(--theme-accent);
    color: var(--theme-muted);
    font-style: italic;
}

/* Imagens dentro do livro */
.reader-article img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.5em auto;
    border-radius: 4px;
    box-shadow: var(--theme-shadow);
}

/* Alinhamento opcional (Justificado vs Esquerda) */
body[data-align="left"] .reader-article p {
    text-align: left;
}

/* Scrollbar personalizada discreta */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--theme-border);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--theme-muted);
}
