/* ============================================
   BOOK READER - PWA Reader
   Minimalist Design with Library
   ============================================ */

/* === Variables de Tema === */
:root {
    /* Tema Oscuro (default) */
    --bg-primary: #0d0d14;
    --bg-secondary: #151520;
    --bg-tertiary: #1a1a28;
    --bg-card: #12121a;
    --text-primary: #e8e6e3;
    --text-secondary: #a8a5a0;
    --text-muted: #6b6966;
    --accent: #00d4aa;
    --accent-glow: rgba(0, 212, 170, 0.15);
    --border: rgba(255, 255, 255, 0.08);
    --shadow: rgba(0, 0, 0, 0.5);
    --overlay: rgba(0, 0, 0, 0.7);

    /* Dimensiones */
    --header-height: 56px;
    --sidebar-width: 320px;
    --content-max-width: 680px;
    --content-padding: 24px;

    /* Tipografía */
    --font-body: 'Crimson Pro', Georgia, serif;
    --font-ui: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-size-base: 18px;
    --line-height: 1.75;

    /* Transiciones */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

/* Tema Claro */
[data-theme="light"] {
    --bg-primary: #fafaf8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0ed;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-muted: #8a8a8a;
    --accent: #0066cc;
    --accent-glow: rgba(0, 102, 204, 0.1);
    --border: rgba(0, 0, 0, 0.1);
    --shadow: rgba(0, 0, 0, 0.1);
    --overlay: rgba(255, 255, 255, 0.8);
}

/* Tema Sepia */
[data-theme="sepia"] {
    --bg-primary: #f4ecd8;
    --bg-secondary: #faf6eb;
    --bg-tertiary: #ebe4d0;
    --bg-card: #faf6eb;
    --text-primary: #3d3426;
    --text-secondary: #5c5142;
    --text-muted: #8a7f6a;
    --accent: #8b5a2b;
    --accent-glow: rgba(139, 90, 43, 0.15);
    --border: rgba(61, 52, 38, 0.12);
    --shadow: rgba(61, 52, 38, 0.15);
    --overlay: rgba(244, 236, 216, 0.9);
}

/* Tema Medianoche */
[data-theme="midnight"] {
    --bg-primary: #0a0e17;
    --bg-secondary: #0f1522;
    --bg-tertiary: #151c2c;
    --bg-card: #0f1522;
    --text-primary: #c5d0e6;
    --text-secondary: #8899b3;
    --text-muted: #4d5d78;
    --accent: #5e9eff;
    --accent-glow: rgba(94, 158, 255, 0.12);
    --border: rgba(94, 158, 255, 0.1);
    --shadow: rgba(0, 0, 0, 0.6);
    --overlay: rgba(10, 14, 23, 0.85);
}

/* === Fuentes === */
[data-font="crimson"] { --font-body: 'Crimson Pro', Georgia, serif; }
[data-font="lora"] { --font-body: 'Lora', Georgia, serif; }
[data-font="sans"] { --font-body: 'Source Sans 3', -apple-system, sans-serif; }
[data-font="mono"] { --font-body: 'IBM Plex Mono', 'Courier New', monospace; }

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: pan-x pan-y;
    -ms-touch-action: pan-x pan-y;
    /* Solo padding arriba, abajo e izquierda para safe-area, sin derecha para que el scroll esté pegado */
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body {
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: scroll; /* Siempre mostrar barra de scroll para evitar saltos */
    touch-action: pan-x pan-y;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--transition-normal),
                color var(--transition-normal);
}

input, select, textarea {
    font-size: 16px !important;
}

button, a, .icon-btn {
    touch-action: manipulation;
}

/* === Vistas === */
.view {
    min-height: 100vh;
    min-height: 100dvh;
}

.view.hidden {
    display: none;
}

/* === Pantalla de Carga === */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity var(--transition-slow);
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loader-ring {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loader-text {
    font-size: 14px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

/* ============================================
   BIBLIOTECA
   ============================================ */

.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px var(--content-padding);
    padding-top: calc(20px + env(safe-area-inset-top));
}

.header-buttons {
    display: flex;
    gap: 8px;
}

.library-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.library-content {
    padding: 0 var(--content-padding) 40px;
}

.library-section {
    margin-bottom: 40px;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Books grid */
.novels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
}

.novel-card {
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.novel-card:hover {
    transform: translateY(-4px);
}

.novel-card:active {
    transform: scale(0.98);
}

/* Book cover */
.novel-cover {
    position: relative;
    aspect-ratio: 2/3;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-tertiary);
    box-shadow: 0 4px 20px var(--shadow);
    margin-bottom: 12px;
}

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

/* Placeholder cuando no hay imagen */
.novel-cover-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    text-align: center;
}

.placeholder-icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.placeholder-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Barra de progreso en portada */
.novel-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(0, 0, 0, 0.5);
}

.novel-progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width var(--transition-normal);
}

/* Book info */
.novel-info {
    flex: 1;
}

.novel-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.novel-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.novel-progress-text {
    color: var(--accent);
    font-weight: 500;
}

/* Message when no books */
.empty-library {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-library-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-library h3 {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-library p {
    font-size: 14px;
}

/* Estado vacío cuando no hay pineados */
.empty-pinned-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 30px;
    min-height: 300px;
}

.empty-pinned-icon {
    width: 120px;
    height: 120px;
    margin-bottom: 24px;
    opacity: 0.3;
}

.empty-pinned-icon svg {
    width: 100%;
    height: 100%;
    stroke: var(--text-secondary);
}

.empty-pinned-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.empty-pinned-text {
    font-size: 14px;
    color: var(--text-muted);
    max-width: 280px;
    line-height: 1.5;
}

/* === Botón Flotante (FAB) para abrir biblioteca === */
.fab-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 28px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 212, 170, 0.4);
    transition: all var(--transition-fast);
    z-index: 100;
}

.fab-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(0, 212, 170, 0.5);
}

.fab-button:active {
    transform: scale(0.97);
}

.fab-button svg {
    width: 20px;
    height: 20px;
}

/* === Bottom Sheet (Panel deslizable desde abajo) === */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    z-index: 250;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 30px var(--shadow);
}

.bottom-sheet.open {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 12px auto 8px;
    cursor: grab;
}

.bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.bottom-sheet-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.bottom-sheet-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 40px;
}

.bottom-sheet-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.bottom-sheet-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* === Book card with pin button === */
.novel-card {
    position: relative;
}

.novel-pin-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: var(--bg-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all var(--transition-fast);
    z-index: 10;
    box-shadow: 0 2px 8px var(--shadow);
}

.novel-card:hover .novel-pin-btn,
.novel-pin-btn.pinned,
#pinned-novels .novel-pin-btn {
    opacity: 1;
}

.novel-pin-btn svg {
    width: 16px;
    height: 16px;
    stroke: var(--text-secondary);
    transition: all var(--transition-fast);
}

.novel-pin-btn.pinned svg {
    stroke: var(--accent);
    fill: var(--accent);
}

.novel-pin-btn:hover svg {
    stroke: var(--accent);
}

/* Responsive para móviles */
@media (max-width: 600px) {
    .fab-button {
        bottom: 20px;
        right: 20px;
        padding: 12px 16px;
        font-size: 13px;
    }

    .fab-button span {
        display: none;
    }

    .fab-button {
        padding: 14px;
        border-radius: 50%;
    }

    .bottom-sheet {
        max-height: 90vh;
    }

    .novel-pin-btn {
        opacity: 1;
    }
}

/* ============================================
   LECTOR
   ============================================ */

/* Header del lector */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    z-index: 100;
    transition: transform var(--transition-normal),
                background-color var(--transition-normal);
}

#header.hidden {
    transform: translateY(-100%);
}

.header-row {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
}

#header h1 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 45vw;
    letter-spacing: 0.3px;
}

.header-actions {
    display: flex;
    gap: 4px;
}

/* Barra de progreso en header */
#reading-progress {
    height: 3px;
    background: var(--bg-tertiary);
    width: 100%;
}

#progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.1s ease-out;
}

/* === Botones de Icono === */
.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

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

.icon-btn:active {
    transform: scale(0.95);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.icon-btn.active {
    color: var(--accent);
}

.icon-btn.active svg {
    fill: var(--accent);
}

/* === Botón Text-to-Speech === */
#tts-btn .tts-stop-icon {
    display: none;
}

#tts-btn.playing .tts-play-icon {
    display: none;
}

#tts-btn.playing .tts-stop-icon {
    display: block;
}

#tts-btn.playing {
    color: var(--accent);
    animation: tts-pulse 1.5s ease-in-out infinite;
}

@keyframes tts-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Resaltado del párrafo que se está leyendo */
.tts-highlight {
    background: var(--accent-glow) !important;
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin-left: -15px;
    border-radius: 0 4px 4px 0;
    transition: background 0.3s ease, border-left 0.3s ease;
}

/* Cuando TTS está activo, los párrafos son clicables */
.tts-active #novel-content p,
.tts-active #novel-content h1,
.tts-active #novel-content h2,
.tts-active #novel-content h3,
.tts-active #novel-content li,
.tts-active #novel-content blockquote {
    cursor: pointer;
    transition: background 0.2s ease;
}

.tts-active #novel-content p:hover,
.tts-active #novel-content h1:hover,
.tts-active #novel-content h2:hover,
.tts-active #novel-content h3:hover,
.tts-active #novel-content li:hover,
.tts-active #novel-content blockquote:hover {
    background: rgba(var(--accent), 0.05);
    background: var(--bg-tertiary);
}

/* === Sidebar === */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
}

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

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.sidebar-tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.sidebar-tab:hover {
    color: var(--text-secondary);
}

.sidebar-tab.active {
    color: var(--accent);
}

.sidebar-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 16px;
    right: 16px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    display: none;
}

.sidebar-content.active {
    display: block;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* === Estadísticas de Lectura === */
.reading-stats {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.reading-stat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
}

.stat-icon {
    font-size: 18px;
    opacity: 0.9;
}

.stat-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* === Lista de Capítulos === */
.chapter-item {
    display: block;
    width: 100%;
    padding: 12px 20px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chapter-item:hover {
    background: var(--bg-tertiary);
}

.chapter-item.active {
    background: var(--accent-glow);
    border-left: 3px solid var(--accent);
}

.chapter-item.act-header {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
    padding: 16px 20px 8px;
    cursor: default;
}

.chapter-item.act-header:hover {
    background: transparent;
}

.chapter-number {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 2px;
}

.chapter-title {
    font-size: 14px;
    color: var(--text-primary);
}

/* === Niveles de la Tabla de Contenidos === */
/* Nivel 1: Título principal - sin indentación, más prominente */
.chapter-item.toc-level-1 {
    padding-left: 20px;
    font-weight: 600;
}

.chapter-item.toc-level-1 .chapter-title {
    font-size: 15px;
    color: var(--accent);
}

/* Nivel 2: Capítulos - indentación moderada */
.chapter-item.toc-level-2 {
    padding-left: 32px;
}

.chapter-item.toc-level-2 .chapter-title {
    font-size: 14px;
}

/* Nivel 3: Subsecciones - mayor indentación, más pequeño */
.chapter-item.toc-level-3 {
    padding-left: 44px;
}

.chapter-item.toc-level-3 .chapter-title {
    font-size: 13px;
    color: var(--text-secondary);
}

/* === Lista de Marcadores === */
.bookmark-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.bookmark-item:hover {
    background: var(--bg-tertiary);
}

.bookmark-info {
    flex: 1;
    min-width: 0;
}

.bookmark-chapter {
    font-size: 12px;
    color: var(--accent);
    margin-bottom: 4px;
}

.bookmark-preview {
    font-size: 13px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bookmark-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.bookmark-delete {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.bookmark-delete:hover {
    background: rgba(255, 80, 80, 0.15);
    color: #ff5050;
}

.bookmark-delete svg {
    width: 16px;
    height: 16px;
}

.empty-message {
    font-size: 14px;
    color: var(--text-muted);
    text-align: center;
    padding: 32px 20px;
}

/* === Panel de Configuración === */
.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-width);
    max-width: 90vw;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 200;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
}

.settings-panel.open {
    transform: translateX(0);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height);
}

.settings-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.setting-group {
    margin-bottom: 28px;
}

.setting-group h3 {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Opciones de Tema */
.theme-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.theme-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border: 2px solid var(--border);
    background: var(--bg-tertiary);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 12px;
    color: var(--text-secondary);
}

.theme-btn:hover {
    border-color: var(--text-muted);
}

.theme-btn.active {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.theme-preview {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.1);
}

.theme-preview.dark { background: linear-gradient(135deg, #0d0d14 50%, #1a1a28 50%); }
.theme-preview.light { background: linear-gradient(135deg, #fafaf8 50%, #f0f0ed 50%); }
.theme-preview.sepia { background: linear-gradient(135deg, #f4ecd8 50%, #ebe4d0 50%); }
.theme-preview.midnight { background: linear-gradient(135deg, #0a0e17 50%, #151c2c 50%); }

/* Language Options */
.lang-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.lang-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 16px;
    border: 2px solid var(--border);
    background: var(--bg-tertiary);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 13px;
    color: var(--text-secondary);
}

.lang-btn:hover {
    border-color: var(--text-muted);
}

.lang-btn.active {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--text-primary);
}


/* Font Options */
.font-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.font-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 2px solid var(--border);
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 13px;
    color: var(--text-secondary);
}

.font-btn:hover {
    border-color: var(--text-muted);
}

.font-btn.active {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.font-preview {
    font-size: 20px;
    color: var(--text-primary);
    width: 36px;
    text-align: center;
}

/* Control de Tamaño de Fuente */
.font-size-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.size-btn {
    width: 44px;
    height: 44px;
    border: 2px solid var(--border);
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

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

.size-btn:active {
    transform: scale(0.95);
}

#font-size-value,
#line-height-value {
    font-size: 14px;
    color: var(--text-primary);
    min-width: 50px;
    text-align: center;
}

/* Opciones de Justificación */
.justify-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.justify-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border: 2px solid var(--border);
    background: var(--bg-tertiary);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 12px;
    color: var(--text-secondary);
}

.justify-btn:hover {
    border-color: var(--text-muted);
}

.justify-btn.active {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.justify-btn svg {
    width: 24px;
    height: 24px;
}

/* === Control de Velocidad de Narración (TTS) === */
.tts-speed-control {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
}

#tts-speed-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

#tts-speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#tts-speed-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 12px var(--accent-glow);
}

#tts-speed-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#tts-speed-slider::-moz-range-track {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.tts-speed-value {
    text-align: center;
    margin-top: 8px;
}

#tts-speed-display {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-glow);
    padding: 4px 12px;
    border-radius: 12px;
}

/* Voice selector */
.voice-selector-container {
    display: flex;
    gap: 10px;
    align-items: center;
}

.voice-selector {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.voice-selector:hover {
    border-color: var(--text-muted);
}

.voice-selector:focus {
    outline: none;
    border-color: var(--accent);
}

.voice-selector option {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px;
}

.test-voice-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.test-voice-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.test-voice-btn:active {
    transform: scale(0.95);
}

.test-voice-btn svg {
    width: 18px;
    height: 18px;
    stroke: var(--bg-primary);
    fill: var(--bg-primary);
}

.voice-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
}

/* === Contenido Principal del Lector === */
#reader {
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    max-width: 100vw;
    padding: calc(var(--header-height) + 8px) var(--content-padding) 40px;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
}

#novel-content {
    width: 100%;
    max-width: var(--content-max-width);
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
    transition: max-width var(--transition-normal);
}

/* === Book Cover (content header) === */
.novel-cover-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px 20px 60px;
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border);
}

.novel-cover-image {
    max-width: 400px;
    width: 90%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 40px var(--shadow),
                0 4px 20px rgba(0, 0, 0, 0.3);
    margin-bottom: 32px;
    transition: transform var(--transition-normal);
}

.novel-cover-image:hover {
    transform: scale(1.02);
}

.novel-cover-title {
    font-size: 2em;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 12px 0;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.novel-cover-author {
    font-size: 1.1em;
    color: var(--text-secondary);
    font-style: italic;
    margin: 0 0 20px 0;
}

.novel-cover-description {
    font-size: 0.95em;
    color: var(--text-muted);
    max-width: 500px;
    line-height: 1.6;
    margin: 0;
}

@media (max-width: 600px) {
    .novel-cover-header {
        padding: 30px 16px 40px;
        margin-bottom: 30px;
    }

    .novel-cover-image {
        max-width: 300px;
        width: 85%;
        margin-bottom: 24px;
    }

    .novel-cover-title {
        font-size: 1.6em;
    }

    .novel-cover-author {
        font-size: 1em;
    }
}

/* Book content styles */
#novel-content h1 {
    font-size: 2.2em;
    font-weight: 600;
    margin: 1.5em 0 0.5em;
    color: var(--text-primary);
    text-align: center;
    letter-spacing: -0.01em;
}

#novel-content h2 {
    font-size: 1.6em;
    font-weight: 600;
    margin: 2em 0 0.8em;
    padding-top: 1.5em;
    border-top: 1px solid var(--border);
    color: var(--accent);
    letter-spacing: 0.02em;
}

#novel-content h3 {
    font-size: 1.3em;
    font-weight: 600;
    margin: 1.8em 0 0.6em;
    color: var(--text-primary);
}

#novel-content p {
    margin-bottom: 1.2em;
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
}

[data-justify="false"] #novel-content p {
    text-align: left;
    hyphens: none;
    -webkit-hyphens: none;
}

#novel-content em {
    font-style: italic;
}

#novel-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

#novel-content hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 2.5em 0;
}

#novel-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1.2em;
    margin: 1.5em 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* Bloques de código */
#novel-content pre {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1em;
    margin: 1.5em 0;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

#novel-content code {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    font-size: 0.85em;
    background: var(--bg-tertiary);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    color: var(--accent);
}

#novel-content pre code {
    background: transparent;
    padding: 0;
    font-size: 0.8em;
    line-height: 1.5;
    display: block;
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
}

/* Marca de capítulo - ahora usamos .toc-heading para todos los encabezados de la TOC */
.toc-heading {
    scroll-margin-top: calc(var(--header-height) + 20px);
}

/* === Toast Notification === */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    padding: 12px 24px;
    border-radius: 10px;
    box-shadow: 0 4px 20px var(--shadow);
    z-index: 300;
    opacity: 0;
    transition: all var(--transition-normal);
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

#toast-message {
    font-size: 14px;
    color: var(--text-primary);
}

/* === Banner de Actualización === */
.update-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--accent);
    color: var(--bg-primary);
    padding: 12px 16px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0, 212, 170, 0.3);
    z-index: 400;
    opacity: 0;
    transition: all var(--transition-normal);
}

.update-banner.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.update-banner button {
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-fast);
}

#update-btn {
    background: var(--bg-primary);
    color: var(--accent);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
}

#update-btn:hover {
    background: var(--bg-secondary);
}

.dismiss-btn {
    background: transparent;
    color: var(--bg-primary);
    padding: 4px 8px;
    font-size: 16px;
    opacity: 0.7;
}

.dismiss-btn:hover {
    opacity: 1;
}

/* === Responsive === */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
        --content-padding: 20px;
    }

    .novels-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 16px;
    }

    .settings-panel,
    .sidebar {
        max-width: 100vw;
    }
}

@media (max-width: 600px) {
    :root {
        --content-padding: 16px;
        --font-size-base: 17px;
        --header-height: 52px;
    }

    .library-title {
        font-size: 24px;
    }

    .novels-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 12px;
    }

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

    #header h1 {
        max-width: 40vw;
        font-size: 13px;
    }

    #novel-content h1 {
        font-size: 1.8em;
    }

    #novel-content h2 {
        font-size: 1.4em;
    }

    #novel-content h3 {
        font-size: 1.2em;
    }

    #novel-content p {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .settings-panel,
    .sidebar {
        width: 100vw;
        max-width: 100vw;
    }

    #novel-content pre {
        padding: 0.8em;
        font-size: 0.75em;
    }
}

@media (max-width: 380px) {
    :root {
        --content-padding: 12px;
        --font-size-base: 16px;
    }

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

    .novels-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .icon-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* === Animaciones === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

#novel-content {
    animation: fadeIn 0.6s ease;
}

.novel-card {
    animation: slideUp 0.4s ease backwards;
}

.novel-card:nth-child(1) { animation-delay: 0.05s; }
.novel-card:nth-child(2) { animation-delay: 0.1s; }
.novel-card:nth-child(3) { animation-delay: 0.15s; }
.novel-card:nth-child(4) { animation-delay: 0.2s; }
.novel-card:nth-child(5) { animation-delay: 0.25s; }
.novel-card:nth-child(6) { animation-delay: 0.3s; }

/* === Selección de texto === */
::selection {
    background: var(--accent);
    color: var(--bg-primary);
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* === Focus Visible === */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* === Print === */
@media print {
    #header, #sidebar, .settings-panel, #sidebar-overlay, #library-view {
        display: none !important;
    }

    #reader-view {
        display: block !important;
    }

    #reader {
        padding: 0;
    }

    #novel-content {
        max-width: 100%;
    }
}

/* ============================================
   DIALOGS
   ============================================ */

.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    padding: 20px;
}

.dialog-overlay.active {
    opacity: 1;
    visibility: visible;
}

.dialog-panel {
    background: var(--bg-secondary);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-normal);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.dialog-overlay.active .dialog-panel {
    transform: scale(1) translateY(0);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.dialog-close-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.dialog-close-btn:hover {
    background: var(--bg-tertiary);
}

.dialog-close-btn svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-secondary);
}

.dialog-content {
    padding: 24px 20px;
    overflow-y: auto;
    max-height: calc(90vh - 80px);
}

/* About Dialog */
.about-dialog .dialog-content {
    text-align: center;
}

.about-logo {
    font-size: 64px;
    margin-bottom: 16px;
}

.about-beta {
    display: inline-block;
    background: var(--accent);
    color: var(--bg-primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 20px;
}

.about-description {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.about-contribute {
    color: var(--accent);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 24px;
}

.about-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.about-version {
    color: var(--text-muted);
    font-size: 12px;
}

/* Request Book Dialog */
.request-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition-fast);
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

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

.submit-btn {
    padding: 14px 24px;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: 8px;
}

.submit-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.submit-btn:active {
    transform: translateY(0);
}

/* Request Book Card (placeholder) */
.request-book-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
    aspect-ratio: 2/3;
    min-height: 200px;
}

.request-book-card:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.request-book-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: 50%;
    margin-bottom: 12px;
    font-size: 24px;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.request-book-card:hover .request-book-icon {
    background: var(--accent);
    color: var(--bg-primary);
}

.request-book-text {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    padding: 0 12px;
}
