/* Lectura — estilos */
:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #efebe3;
  --text: #1d1b18;
  --muted: #6b665d;
  --primary: #3b5b7a;
  --primary-text: #ffffff;
  --primary-soft: #dbe6f0;
  --border: #ddd6c9;
  --danger: #b3261e;
  --mark: #ffe08a;
  --shadow: 0 6px 24px rgba(0, 0, 0, .14);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --surface: #1e1d1b; --surface-2: #2a2825; --text: #ece8e1; --muted: #a39d92;
    --primary: #9cc0e4; --primary-text: #0d2236; --primary-soft: #26384a; --border: #3a3732;
    --danger: #f2b8b5; --mark: #6b5a1c; --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1e1d1b; --surface-2: #2a2825; --text: #ece8e1; --muted: #a39d92;
  --primary: #9cc0e4; --primary-text: #0d2236; --primary-soft: #26384a; --border: #3a3732;
  --danger: #f2b8b5; --mark: #6b5a1c; --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 8px 16px; }
.error { color: var(--danger); }
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0 10px; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.row > .input { flex: 1; min-width: 0; }
.icon { flex: none; }

.boot, .empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 48px 24px; text-align: center; color: var(--muted); }
.boot { height: 100%; }
.empty h2 { color: var(--text); margin: 4px 0; }
.empty p { max-width: 420px; }

.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.small { width: 20px; height: 20px; border-width: 2px; margin: 8px auto; }
.spinner.light { border-color: rgba(255, 255, 255, .35); border-top-color: currentColor; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- botones ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; justify-content: center; border: 0; border-radius: 999px; padding: 9px 18px; cursor: pointer; background: transparent; font-weight: 500; min-height: 40px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.outlined { border: 1px solid var(--border); background: var(--surface); }
.btn.text { color: var(--primary); padding: 8px 12px; }
.btn.danger { color: var(--danger); }
.btn.primary.danger { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; color: inherit; flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.active { color: var(--primary); }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; background: var(--surface); cursor: pointer; font-size: .9rem; white-space: nowrap; }
.chip.selected { background: var(--primary-soft); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; align-items: center; }
.fab { position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 16px; padding: 14px 20px; background: var(--primary); color: var(--primary-text); box-shadow: var(--shadow); cursor: pointer; font-weight: 600; z-index: 5; }
body:has(.mini-player:not([hidden])) .fab { bottom: calc(92px + env(safe-area-inset-bottom)); }

.input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-height: 42px; }
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.input.small { width: 90px; flex: none; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field > span { font-size: .9rem; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.field.inline .input { flex: 1; }
.inline-field { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; }
.check-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.check-item input { width: 18px; height: 18px; accent-color: var(--primary); }
.label { font-size: .9rem; color: var(--muted); margin-top: 8px; }
.small-title { font-size: .95rem; margin: 18px 0 6px; color: var(--primary); font-weight: 600; }
.section-title { font-size: 1rem; color: var(--primary); margin: 28px 0 8px; }

/* ---------- estructura ---------- */
.view { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; padding-top: calc(6px + env(safe-area-inset-top)); background: var(--bg); min-height: 56px; flex: none; }
.topbar h1 { font-size: 1.25rem; margin: 0 8px; font-weight: 600; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--primary); }
.content { flex: 1; overflow-y: auto; padding: 0 16px 120px; -webkit-overflow-scrolling: touch; }
.content > * { max-width: 1100px; margin-left: auto; margin-right: auto; }
.settings { max-width: 760px; margin: 0 auto; width: 100%; }

.tabs { display: flex; border-bottom: 1px solid var(--border); flex: none; overflow-x: auto; }
.tab { flex: 1; border: 0; background: none; padding: 12px 8px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; min-width: 100px; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.search { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 999px; padding: 4px 14px; margin: 14px auto 6px; color: var(--muted); }
.search-input { border: 0; background: transparent; flex: 1; padding: 8px 0; outline: none; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.badge-wrap { position: relative; display: inline-flex; }
.badge { position: absolute; top: 4px; right: 4px; background: var(--danger); color: #fff; font-size: .7rem; border-radius: 999px; min-width: 16px; height: 16px; display: grid; place-items: center; padding: 0 4px; }
.filter-summary { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; margin: 4px 0; }
.section-head { display: flex; align-items: center; gap: 4px; margin: 10px auto; }
.section-head h2 { margin: 0; font-size: 1.15rem; }

.folder-list, .collection-list { display: flex; flex-direction: column; gap: 2px; margin: 8px auto; }
.folder-item, .collection-open { display: flex; align-items: center; gap: 14px; border: 0; background: none; padding: 10px 8px; border-radius: 10px; cursor: pointer; text-align: left; width: 100%; color: inherit; }
.folder-item:hover, .collection-open:hover { background: var(--surface-2); }
.folder-item .icon:first-child { color: var(--primary); }
.folder-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collection-item { display: flex; align-items: center; }

/* ---------- libros ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px 14px; margin: 12px auto; }
.book-grid.compact { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 12px 10px; }
.book-card { position: relative; cursor: pointer; border-radius: 10px; outline-offset: 3px; min-width: 0; }
.book-card .icon-btn { position: absolute; top: 4px; right: 4px; background: rgba(0, 0, 0, .45); color: #fff; width: 34px; height: 34px; opacity: 0; transition: opacity .15s; }
.book-card:hover .icon-btn, .book-card:focus-within .icon-btn { opacity: 1; }
@media (hover: none) { .book-card .icon-btn { opacity: .85; } }
.cover { position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; background: var(--surface-2); box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 10px; color: #fff; text-align: center; font-weight: 600; font-size: .85rem; overflow: hidden; word-break: break-word; }
.cover-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0, 0, 0, .35); }
.cover-progress > div { height: 100%; background: var(--primary); }
.book-card-text { padding: 6px 2px 0; }
.book-title { font-weight: 600; font-size: .92rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.compact .book-title { font-size: .8rem; }
.book-author { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-list { display: flex; flex-direction: column; gap: 4px; margin: 10px auto; }
.book-row { display: flex; align-items: center; gap: 14px; padding: 8px; border-radius: 12px; cursor: pointer; }
.book-row:hover { background: var(--surface-2); }
.book-row .cover { width: 52px; flex: none; }
.book-row .cover-placeholder { font-size: .55rem; padding: 4px; }
.book-row-text { flex: 1; min-width: 0; }
.book-meta { color: var(--muted); font-size: .8rem; }
.book-info { margin-top: 16px; color: var(--muted); font-size: .88rem; display: grid; gap: 2px; word-break: break-word; }
.check-list { display: flex; flex-direction: column; }

/* ---------- diálogos, hojas, menús ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.dialog { background: var(--surface); border-radius: 24px; width: min(440px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.dialog.wide { width: min(620px, 100%); }
.dialog-title { margin: 0; padding: 22px 24px 8px; font-size: 1.25rem; font-weight: 600; word-break: break-word; }
.dialog-body { padding: 4px 24px 8px; overflow-y: auto; }
.dialog-body .input + .input { margin-top: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 6px; padding: 10px 16px 16px; flex-wrap: wrap; }
.sheet-backdrop { place-items: end center; padding: 0; }
.sheet-backdrop.closing { opacity: 0; transition: opacity .18s; }
.sheet { background: var(--surface); width: min(640px, 100%); border-radius: 24px 24px 0 0; max-height: 88vh; max-height: 88dvh; overflow-y: auto; padding: 8px 20px calc(24px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 10px; }
.sheet-title { margin: 0 0 4px; font-size: 1.3rem; }
.menu-layer { position: fixed; inset: 0; z-index: 60; }
.menu { position: fixed; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 6px 0; min-width: 200px; max-width: calc(100vw - 16px); max-height: 70vh; overflow-y: auto; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; padding: 11px 16px; cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.menu-item span { flex: 1; }
.menu-item.checked { color: var(--primary); font-weight: 600; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); background: #2f2d2a; color: #f5f1ea; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 70; display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); font-size: .92rem; }
.toast .btn.text { color: #9cc0e4; }
body:has(.mini-player:not([hidden])) .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }

.slider-row { margin: 12px 0; }
.slider-label { display: flex; justify-content: space-between; font-size: .92rem; }
.slider-value { color: var(--muted); }
.slider-row input[type=range] { width: 100%; accent-color: var(--primary); }
.tool-btn { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; padding: 12px 4px; cursor: pointer; text-align: left; border-radius: 8px; }
.tool-btn:hover { background: var(--surface-2); }
.sheet-body { padding-bottom: 8px; }

.setting { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.setting-text { flex: 1; min-width: 180px; }
.setting .row { flex: 1; min-width: 240px; margin: 0; }
.catalog { max-height: 55vh; overflow-y: auto; }
.rules { display: flex; flex-direction: column; gap: 4px; }
.rule { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.rule-text { flex: 1; min-width: 0; word-break: break-all; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.progress-box progress { width: 100%; accent-color: var(--primary); }
.toc-list { max-height: 55vh; overflow-y: auto; margin-top: 8px; }
.toc-item { display: flex; justify-content: space-between; gap: 12px; width: 100%; border: 0; background: none; padding: 10px 12px; cursor: pointer; text-align: left; border-radius: 8px; }
.toc-item:hover { background: var(--surface-2); }
.toc-item.current { background: var(--primary-soft); font-weight: 600; }
.banner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 16px; background: var(--primary-soft); font-size: .9rem; flex: none; }

/* ---------- lector ---------- */
.reader { --r-bg: var(--bg); --r-text: var(--text); --r-muted: var(--muted); height: 100%; display: flex; flex-direction: column; background: var(--r-bg); color: var(--r-text); }
.reader[data-theme="light"] { --r-bg: #ffffff; --r-text: #1d1b18; --r-muted: #6b665d; --mark: #ffe08a; --surface: #fff; --surface-2: #f0ede6; --border: #ddd6c9; color-scheme: light; }
.reader[data-theme="sepia"] { --r-bg: #f4ecd8; --r-text: #4a3b26; --r-muted: #806c4f; --mark: #ecc76f; --surface: #faf4e6; --surface-2: #eadfc6; --border: #d8c9a8; --text: #4a3b26; --muted: #806c4f; color-scheme: light; }
.reader[data-theme="dark"] { --r-bg: #101010; --r-text: #dcd7cf; --r-muted: #8f897f; --mark: #5c4d16; --surface: #1e1d1b; --surface-2: #2a2825; --border: #3a3732; --text: #dcd7cf; --muted: #8f897f; --primary: #9cc0e4; --primary-text: #0d2236; --primary-soft: #26384a; color-scheme: dark; }
.reader .topbar { background: var(--r-bg); border-bottom: 1px solid var(--border); }
.reader-title { flex: 1; min-width: 0; padding: 0 4px; }
.reader-book { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-section { color: var(--r-muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.locate-btn { display: none; }
.reader.has-narration .locate-btn { display: inline-grid; }
.reader-content { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 20px; outline: none; -webkit-overflow-scrolling: touch; }
.page, .flow { max-width: 720px; margin: 0 auto; padding: 12px 0 40px; font-size: var(--reader-font, 18px); line-height: var(--reader-line, 1.5); font-family: Georgia, "Iowan Old Style", "Noto Serif", "Times New Roman", serif; }
.page { transition: transform .16s ease-out, opacity .16s; }
.page.enter-right { transform: translateX(40%); opacity: 0; transition: none; }
.page.enter-left { transform: translateX(-40%); opacity: 0; transition: none; }
.page.leave-left { transform: translateX(-40%); opacity: 0; }
.page.leave-right { transform: translateX(40%); opacity: 0; }
.reader-content.swipe { touch-action: pan-y; }
.sec { padding-bottom: 12px; }
.flow .sec + .sec { border-top: 1px dashed var(--border); padding-top: 12px; }
.sec-title { font-size: 1.3em; line-height: 1.3; margin: .6em 0 .8em; }
.page-label { text-align: center; color: var(--r-muted); font-size: .7em; font-family: system-ui, sans-serif; margin: .8em 0; }
.para { cursor: pointer; border-radius: 6px; margin: 0 -6px; padding: 0 6px; }
.para p { margin: 0 0 .85em; }
.para .tr { font-style: italic; color: var(--r-muted); margin-top: -.45em; }
.para .pending { opacity: .55; }
.para.narrating { background: color-mix(in srgb, var(--mark) 25%, transparent); }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.page-nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 24px 0 8px; font-family: system-ui, sans-serif; font-size: 1rem; flex-wrap: wrap; }
.swipe-hint { margin: 0 auto; font-size: .85rem; }
.pdf-page { display: flex; flex-direction: column; align-items: center; padding: 12px 0 40px; }
.pdf-canvas { background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .2); max-width: 100%; }
.pdf-page .page-nav { width: 100%; max-width: 1000px; }

/* ---------- reproductor ---------- */
.player-bar { flex: none; background: var(--surface); border-top: 1px solid var(--border); padding: 4px 8px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -2px 12px rgba(0, 0, 0, .08); }
.player-info { font-size: .75rem; color: var(--r-muted, var(--muted)); text-align: center; min-height: 1.1em; padding: 2px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-info.error { color: var(--danger); white-space: normal; }
.player-row { display: flex; align-items: center; justify-content: space-evenly; max-width: 620px; margin: 0 auto; gap: 2px; }
.play-btn { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; cursor: pointer; flex: none; }
.play-btn.small { width: 44px; height: 44px; }
.play-btn.small .icon { width: 24px; height: 24px; }
.chip.speed { min-width: 58px; justify-content: center; }
.mini-player { position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 8px 8px 8px 10px; z-index: 20; }
.mini-open { flex: 1; display: flex; align-items: center; gap: 12px; border: 0; background: none; cursor: pointer; text-align: left; min-width: 0; padding: 0; }
.mini-open img { width: 40px; height: 56px; object-fit: cover; border-radius: 4px; }
.mini-text { min-width: 0; }
.mini-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-sub { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; overflow: auto; padding: 16px; }
.login-card { background: var(--surface); padding: 32px 28px; border-radius: 24px; box-shadow: var(--shadow); width: min(400px, 100%); text-align: center; }
.login-card h1 { margin: 8px 0 4px; }
.login-card form { text-align: left; margin-top: 16px; }
.login-card .btn { margin-top: 12px; }

@media (max-width: 600px) {
  .content { padding: 0 12px 120px; }
  .reader-content { padding: 0 16px; }
  .reader-top .icon-btn { width: 38px; height: 38px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 10px; }
  .book-grid.compact { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
  .player-row .icon-btn { width: 38px; height: 38px; }
  .play-btn { width: 52px; height: 52px; }
  .dialog-title { padding: 18px 18px 6px; }
  .dialog-body { padding: 4px 18px 8px; }
}
