/* =========================================================
   Nuestra Biblioteca — estilos
   ========================================================= */

:root, [data-theme="claro"] {
  --bg: #f6f1e7; --surface: #fffdf8; --surface-2: #f0e9db; --ink: #2b2420; --muted: #7b6f64;
  --line: #e3dacb; --accent: #8c2f39; --accent-ink: #fff; --accent-soft: #f3e1e1; --ok: #2f6b4a; --err: #b3261e;
  --paper: #fffbf3; --paper-ink: #2b2420; --paper-edge: #e9dfcc; --desk: #e9e1d2;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 24px rgba(60, 40, 20, .08);
}
[data-theme="sepia"] {
  --bg: #efe2c6; --surface: #f8edd6; --surface-2: #e7d6b4; --ink: #45331f; --muted: #806a4e;
  --line: #dcc8a3; --accent: #8a4b22; --accent-soft: #edd7bd; --paper: #f7ebd2; --paper-ink: #3f2e1c;
  --paper-edge: #dfcaa2; --desk: #e4d3b0;
}
[data-theme="noche"] {
  --bg: #141318; --surface: #1d1c22; --surface-2: #26252c; --ink: #ece6dc; --muted: #9d958a;
  --line: #312f37; --accent: #e57a83; --accent-ink: #1a1016; --accent-soft: #3a252a; --ok: #7cc59b; --err: #ff8a80;
  --paper: #1f1e24; --paper-ink: #d9d2c5; --paper-edge: #2b2a31; --desk: #0f0e12;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ---------- Tipografías ---------- */
.font-literata .page-text, .font-literata .fo-sample, font[face="literata"], .bp-title.font-literata, .print-book.font-literata { font-family: "Literata", Georgia, serif; }
.font-garamond .page-text, .font-garamond .fo-sample, font[face="garamond"], .bp-title.font-garamond, .print-book.font-garamond { font-family: "EB Garamond", Garamond, Georgia, serif; }
.font-lora .page-text, .font-lora .fo-sample, font[face="lora"], .bp-title.font-lora, .print-book.font-lora { font-family: "Lora", Georgia, serif; }
.font-merriweather .page-text, .font-merriweather .fo-sample, font[face="merriweather"], .bp-title.font-merriweather, .print-book.font-merriweather { font-family: "Merriweather", Georgia, serif; }
.font-crimson .page-text, .font-crimson .fo-sample, font[face="crimson"], .bp-title.font-crimson, .print-book.font-crimson { font-family: "Crimson Pro", Georgia, serif; }
font[face="creepster"] { font-family: "Creepster", fantasy; letter-spacing: .03em; }
font[face="special"] { font-family: "Special Elite", "Courier New", monospace; }
font[face="caveat"] { font-family: "Caveat", cursive; font-size: 1.25em; }
font[face="cinzel"] { font-family: "Cinzel", serif; }
font[face="pixel"] { font-family: "VT323", monospace; font-size: 1.2em; }
font[face="inherit"] { font-family: inherit; }
.page-title, .hero-title, .section-title, .auth-title, .logo-txt, .bp-title, .modal-title, .write-head h1 {
  font-family: "Fraunces", Georgia, serif; font-weight: 700; letter-spacing: -.01em;
}

/* ---------- Estructura ---------- */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px clamp(14px, 3vw, 32px) 120px; }
body.reading .main, body.writing .main { max-width: none; padding: 0; }
body.reading .topbar, body.reading .tabbar, body.writing .topbar, body.writing .tabbar { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  padding: 10px clamp(14px, 3vw, 32px); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none !important; }
.logo-mark { font-size: 1.4rem; }
.logo-txt { font-size: 1.2rem; }
.topnav { display: flex; gap: 4px; margin-left: 12px; }
.topnav a { padding: 8px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; text-decoration: none; }
.topnav a:hover { background: var(--surface-2); color: var(--ink); }
.topnav a.current { background: var(--accent-soft); color: var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.bell { position: relative; font-size: 1.2rem; padding: 6px 8px; border-radius: 999px; text-decoration: none !important; }
.bell:hover, .bell.current { background: var(--surface-2); }
.badge {
  position: absolute; top: -2px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
}
.me-btn { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; color: var(--ink); text-decoration: none !important; border: 1px solid var(--line); background: var(--surface); }
.me-btn .avatar { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); }
.me-name { font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabbar { display: none; }
@media (max-width: 760px) {
  .topnav, .me-btn, .top-right .bell { display: none; }
  .topbar { padding: 10px 16px; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding: 6px 0; color: var(--muted); font-size: .72rem; font-weight: 600; text-decoration: none; border-radius: 12px;
  }
  .tabbar a.current { color: var(--accent); background: var(--accent-soft); }
  .tabbar .tb-ico { font-size: 1.25rem; line-height: 1.2; }
  .tabbar .badge { top: 2px; right: calc(50% - 22px); }
  body.writing .tabbar { display: none; }
  .main { padding-bottom: 110px; }
}

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer;
  text-decoration: none !important; transition: transform .08s, background .15s, border-color .15s; min-height: 44px;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.big { padding: 14px 22px; font-size: 1.05rem; flex-direction: column; gap: 0; }
.btn.big small { font-weight: 400; opacity: .85; font-size: .8rem; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: .88rem; }
.btn.current { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.danger-text { color: var(--err) !important; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; border: 1px solid transparent;
  background: transparent; cursor: pointer; font-size: 1.15rem; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: .92rem; }
.input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; min-height: 44px;
}
textarea.input { resize: vertical; line-height: 1.5; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.help { color: var(--muted); font-size: .85rem; margin: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 48px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: 0; cursor: pointer; width: 40px; height: 40px; opacity: .6; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: end; }
.grid-4 { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .grid-2, .grid-4 { grid-template-columns: 1fr 1fr; } .grid-2 { grid-template-columns: 1fr; } }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 18px; }
.inline-form .field { width: 110px; }
.inline-form .grow { flex: 1; min-width: 180px; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.gap, .gap { gap: 10px; }
.row.center { justify-content: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.actions { margin-top: 20px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err { color: var(--err); }
.ok { color: var(--ok); }
.warn-box { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); padding: 12px 14px; border-radius: 12px; margin: 0; font-weight: 600; }
.code-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); margin: 12px 0; }
.code-box code { font-size: 1.25rem; font-weight: 700; letter-spacing: .08em; }
.code-box.big code { font-size: 1.5rem; }

/* ---------- Etiquetas ---------- */
.tag { display: inline-block; font-size: .74rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin: 0 4px 4px 0; }
.tag-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.tag-live { background: var(--accent-soft); color: var(--accent); }
.tag-err { background: color-mix(in srgb, var(--err) 14%, transparent); color: var(--err); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0; scrollbar-width: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--ink); text-decoration: none !important; }
.chip.current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Secciones ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: clamp(18px, 3vw, 34px); box-shadow: var(--shadow); margin-bottom: 24px; }
.panel.narrow { max-width: 720px; margin-left: auto; margin-right: auto; }
.page-title { font-size: clamp(1.6rem, 3vw, 2.2rem); margin: 0 0 8px; line-height: 1.15; }
.section-title { font-size: 1.3rem; margin: 30px 0 14px; }
.lead { color: var(--muted); font-size: 1.05rem; margin: 0 0 20px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; font-weight: 700; color: var(--accent); margin: 0 0 6px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding: 18px 0 8px; }
.hero-title { font-size: clamp(1.7rem, 4vw, 2.6rem); margin: 0; line-height: 1.1; max-width: 22ch; }
.hero-actions { display: flex; gap: 10px; }
.challenges { display: grid; gap: 12px; margin-top: 20px; }
.challenge { display: flex; gap: 14px; padding: 16px 18px; border-radius: 16px; background: linear-gradient(120deg, var(--accent-soft), var(--surface)); border: 1px solid var(--line); }
.challenge p { margin: 4px 0 0; }
.ch-ico { font-size: 1.8rem; }

/* ---------- Tarjetas de libros ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(160px, 42vw), 1fr)); gap: clamp(14px, 2vw, 24px); }
.row-scroll { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 180px); gap: 16px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; }
.row-scroll > * { scroll-snap-align: start; }
.book-card { display: flex; flex-direction: column; gap: 10px; color: var(--ink); text-decoration: none !important; }
.book-card:hover .cover { transform: translateY(-4px) rotate(-.5deg); box-shadow: 0 14px 30px rgba(0,0,0,.18); }
.cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 4px 10px 10px 4px; overflow: hidden; background: var(--surface-2);
  box-shadow: 0 6px 16px rgba(0,0,0,.14); transition: transform .2s, box-shadow .2s;
}
.cover::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: linear-gradient(90deg, rgba(0,0,0,.25), transparent); z-index: 1; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.gen {
  background: linear-gradient(160deg, hsl(var(--hue) 45% 38%), hsl(calc(var(--hue) + 40) 50% 22%));
  color: #fff8ee; display: flex; flex-direction: column; justify-content: space-between; padding: 14% 12%;
}
.gen-title { font-family: "Fraunces", Georgia, serif; font-weight: 700; font-size: clamp(1rem, 2vw, 1.25rem); line-height: 1.15; overflow-wrap: anywhere; }
.gen-author { font-size: .8rem; opacity: .85; }
.cover.big { width: 100%; }
.cover.big .gen-title { font-size: 1.8rem; }
.bc-title { font-size: 1rem; margin: 0; line-height: 1.25; overflow-wrap: anywhere; }
.bc-author { margin: 2px 0 6px; color: var(--muted); font-size: .88rem; }
.bc-tags { display: flex; flex-wrap: wrap; }
img.broken { opacity: 0; }

/* ---------- Página del libro ---------- */
.book-page { display: grid; grid-template-columns: minmax(180px, 280px) 1fr; gap: clamp(20px, 4vw, 48px); align-items: start; margin-bottom: 20px; }
.bp-title { font-size: clamp(1.8rem, 4vw, 3rem); margin: 8px 0 6px; line-height: 1.1; overflow-wrap: anywhere; }
.bp-author { font-weight: 600; font-size: 1.05rem; }
.bp-syn { font-size: 1.05rem; line-height: 1.65; white-space: pre-line; max-width: 62ch; }
.read-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 20px 0 14px; max-width: 720px; }
@media (max-width: 640px) {
  .book-page { grid-template-columns: 1fr; }
  .bp-cover { max-width: 200px; margin: 0 auto; }
  .read-actions { grid-template-columns: 1fr; }
}
.panel-flat { margin-bottom: 20px; }
.chapter-list { display: flex; flex-direction: column; gap: 6px; }
.chapter-item {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); text-decoration: none !important; cursor: pointer; text-align: left; width: 100%;
}
.chapter-item:hover { border-color: var(--accent); }
.chapter-item.current { border-color: var(--accent); background: var(--accent-soft); }
.ch-num { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); font-weight: 700; font-size: .9rem; }
.ch-title { flex: 1; font-weight: 600; }

/* ---------- Perfil, avisos ---------- */
.profile { text-align: center; padding: 20px 0; }
.pf-avatar { font-size: 3.5rem; width: 96px; height: 96px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.pf-bio { max-width: 54ch; margin: 10px auto 16px; white-space: pre-line; }
.avatar-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.av { width: 44px; height: 44px; font-size: 1.4rem; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.av.current { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }
.notifs { display: flex; flex-direction: column; gap: 8px; }
.notif { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); color: var(--ink); text-decoration: none !important; }
.notif.unread { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.n-text { flex: 1; }
.theme-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-claro { background: #fffbf3 !important; color: #2b2420 !important; }
.theme-sepia { background: #f3e3c3 !important; color: #45331f !important; }
.theme-noche { background: #1d1c22 !important; color: #ece6dc !important; }
.theme-btns .btn.current { box-shadow: 0 0 0 3px var(--accent); }

/* ---------- Entrar / registro ---------- */
.auth { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; align-items: center; min-height: calc(100dvh - 140px); }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: clamp(22px, 4vw, 40px); box-shadow: var(--shadow); max-width: 480px; width: 100%; }
.auth-title { font-size: 2rem; margin: 0 0 6px; line-height: 1.15; }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-top: 18px; font-size: .92rem; }
.auth-art { display: grid; place-items: center; }
.art-book { display: flex; transform: perspective(900px) rotateX(18deg); }
.art-book span {
  width: min(180px, 18vw); aspect-ratio: 2/3; background: var(--paper); border: 1px solid var(--paper-edge);
  background-image: repeating-linear-gradient(transparent 0 18px, color-mix(in srgb, var(--muted) 22%, transparent) 18px 19px);
  background-size: 70% 100%; background-position: center 18%; background-repeat: no-repeat;
}
.art-book span:first-child { border-radius: 10px 0 0 10px; transform: rotateY(14deg); transform-origin: right; box-shadow: inset -20px 0 30px -20px rgba(0,0,0,.3); }
.art-book span:last-child { border-radius: 0 10px 10px 0; transform: rotateY(-14deg); transform-origin: left; box-shadow: inset 20px 0 30px -20px rgba(0,0,0,.3); }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; justify-items: center; } .auth-art { display: none; } }
.ts { min-height: 0; }

/* ---------- Ventanas ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 100; background: rgba(15, 10, 8, .5); display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fade .15s; backdrop-filter: blur(2px);
}
.modal-back.out { opacity: 0; transition: opacity .18s; }
.modal {
  background: var(--surface); border-radius: 20px; width: 100%; max-width: 480px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .18s ease-out;
}
.modal-wide { max-width: 760px; }
.modal-title { margin: 0; padding: 20px 22px 4px; font-size: 1.35rem; }
.modal-body { padding: 12px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body p { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 22px 20px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { border-radius: 20px 20px 0 0; max-height: 92dvh; animation: up .2s ease-out; padding-bottom: env(safe-area-inset-bottom); }
  .modal-actions .btn { flex: 1; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (max-width: 760px) { .toasts { top: auto; bottom: calc(90px + env(safe-area-inset-bottom)); } }

.toasts { position: fixed; z-index: 200; left: 50%; transform: translateX(-50%); top: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast { background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); animation: up .2s; transition: opacity .4s, transform .4s; text-align: center; }
.toast-err { background: var(--err); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- Comentarios ---------- */
.comments { display: flex; flex-direction: column; gap: 10px; max-height: 44dvh; overflow-y: auto; }
.comment { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.comment.mine { background: var(--accent-soft); }
.c-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.c-who { font-weight: 700; }
.c-head .link { margin-left: auto; }
.c-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { display: flex; flex-direction: column; gap: 6px; }
.admin-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

/* =========================================================
   LECTOR — el libro
   ========================================================= */
.reader {
  --zoom: 1;
  /* tamaño de cada página del libro abierto (proporción 1 : 1.48) */
  --ph: min(calc(100dvh - 190px), calc((100vw - 150px) / 2 * 1.48), 1500px);
  --pw: calc(var(--ph) / 1.48);
  min-height: 100dvh; display: flex; flex-direction: column; background: var(--desk);
  background-image: radial-gradient(ellipse at 50% 40%, color-mix(in srgb, var(--paper) 30%, transparent), transparent 70%);
}
.reader-top {
  display: flex; align-items: center; gap: 8px; padding: 8px clamp(8px, 2vw, 20px); position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--desk) 90%, transparent); backdrop-filter: blur(8px);
}
.reader-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; background: none; border: 0; cursor: pointer; padding: 2px 6px; border-radius: 10px; }
.reader-title:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.rt-book { font-family: "Fraunces", Georgia, serif; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt-ch { font-size: .82rem; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-tools { display: flex; gap: 2px; }
.reader-stage { flex: 1; display: flex; align-items: center; justify-content: center; gap: clamp(4px, 1vw, 16px); padding: 4px 8px; }
.reader-footer { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; padding: 6px 16px 14px; }
.progress-txt { color: var(--muted); font-size: .88rem; white-space: nowrap; }
.comment-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 9px 16px; cursor: pointer; font-weight: 600; min-height: 42px; }
.comment-btn:hover { border-color: var(--accent); }

/* Libro abierto */
.spread { display: flex; filter: drop-shadow(0 18px 30px rgba(30, 15, 5, .22)); }
.spread-col { display: flex; flex-direction: column; align-items: center; }
.page {
  position: relative; width: var(--pw); height: var(--ph); background: var(--paper); color: var(--paper-ink);
  container-type: inline-size; overflow: hidden;
}
.page.left { border-radius: 8px 2px 2px 8px; background-image: linear-gradient(270deg, rgba(0,0,0,.13), rgba(0,0,0,0) 9%); border-right: 1px solid var(--paper-edge); }
.page.right { border-radius: 2px 8px 8px 2px; background-image: linear-gradient(90deg, rgba(0,0,0,.13), rgba(0,0,0,0) 9%); }
[data-theme="noche"] .page.left { background-image: linear-gradient(270deg, rgba(0,0,0,.45), rgba(0,0,0,0) 9%); }
[data-theme="noche"] .page.right { background-image: linear-gradient(90deg, rgba(0,0,0,.45), rgba(0,0,0,0) 9%); }
.page-blank { opacity: .92; }
.page-inner { position: absolute; inset: 7.5% 9% 9% 9%; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
.page-num { position: absolute; bottom: 3.2%; left: 0; right: 0; text-align: center; font-size: max(11px, 2.4cqi); color: var(--muted); font-family: Georgia, serif; }

.page-text { font-size: max(15px, calc(2.95cqi * var(--zoom))); line-height: 1.58; hyphens: auto; -webkit-hyphens: auto; overflow-wrap: break-word; }
.page-text p { margin: 0 0 .55em; text-indent: 1.4em; }
.page-text p:first-child { text-indent: 0; }
.page-text p.al-c, .page-text p.al-r { text-indent: 0; }
.al-j { text-align: justify; } .al-l { text-align: left; } .al-c { text-align: center; } .al-r { text-align: right; }
.pg-img { margin: .6em 0; text-align: center; }
.pg-img img { max-width: 100%; max-height: calc(var(--ph) * .78); border-radius: 4px; object-fit: contain; }

.nav-side {
  flex: none; width: 52px; height: 120px; border-radius: 14px; border: 0; background: color-mix(in srgb, var(--ink) 6%, transparent);
  font-size: 2.4rem; color: var(--muted); cursor: pointer; transition: background .15s;
}
.nav-side:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 12%, transparent); color: var(--ink); }
.nav-side:disabled { opacity: .25; cursor: default; }

.turn-next .spread-col:last-child .page { animation: turnR .5s cubic-bezier(.3,.7,.3,1); transform-origin: left center; }
.turn-next .spread-col:first-child .page { animation: dim .5s; }
.turn-prev .spread-col:first-child .page { animation: turnL .5s cubic-bezier(.3,.7,.3,1); transform-origin: right center; }
.turn-prev .spread-col:last-child .page { animation: dim .5s; }
@keyframes turnR { from { transform: perspective(2200px) rotateY(-28deg); filter: brightness(.85); } }
@keyframes turnL { from { transform: perspective(2200px) rotateY(28deg); filter: brightness(.85); } }
@keyframes dim { from { filter: brightness(.9); } }

/* Reacciones */
.react-bar { display: flex; justify-content: center; gap: 4px; padding: 10px 4px 0; flex-wrap: wrap; min-height: 50px; }
.react {
  display: inline-flex; align-items: center; gap: 3px; padding: 4px 8px; border-radius: 999px; border: 1px solid transparent;
  background: color-mix(in srgb, var(--paper) 70%, transparent); cursor: pointer; font-size: 1.05rem; min-height: 36px; min-width: 40px; justify-content: center;
  transition: transform .1s;
}
.react .emo { filter: grayscale(.6); opacity: .75; transition: filter .15s, opacity .15s; }
.react.has .emo, .react:hover .emo, .react.mine .emo { filter: none; opacity: 1; }
.react:hover { transform: translateY(-2px) scale(1.08); }
.react.mine { border-color: var(--accent); background: var(--accent-soft); }
.react .cnt { font-size: .8rem; font-weight: 700; color: var(--muted); }

/* Una hoja (celular, tablet vertical, ventanas angostas) */
.sheet { width: 100%; max-width: 680px; margin: 0 auto; }
.sheet .page { width: 100%; height: auto; min-height: min(72dvh, 900px); border-radius: 10px; box-shadow: 0 10px 30px rgba(30, 15, 5, .14); background-image: none; container-type: normal; }
.sheet .page-inner { position: static; inset: auto; padding: clamp(24px, 6vw, 48px) clamp(20px, 6vw, 52px) 56px; overflow: visible; }
.sheet .page-text { font-size: calc(clamp(17px, 2.4vw, 20px) * var(--zoom)); line-height: 1.7; }
.sheet .page-num { font-size: 13px; bottom: 16px; }
.sheet .pg-img img { max-height: 75dvh; }
.slide-next { animation: slideN .3s ease-out; }
.slide-prev { animation: slideP .3s ease-out; }
@keyframes slideN { from { transform: translateX(40px); opacity: 0; } }
@keyframes slideP { from { transform: translateX(-40px); opacity: 0; } }
.mobile-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; max-width: 680px; }
@media (max-width: 900px) {
  .reader-stage { align-items: flex-start; padding: 8px 10px; }
  .reader-footer { flex-direction: column; gap: 10px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* Música */
.music-bar {
  position: fixed; z-index: 40; left: 16px; bottom: 16px; display: flex; align-items: center; gap: 8px; max-width: min(360px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 6px 6px 14px; box-shadow: var(--shadow);
}
.music-bar[hidden] { display: none; }
.mb-name { flex: 1; min-width: 0; font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-ico.spinning { display: inline-block; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px) rotate(-8deg); } }
.mb-btn { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer; font-size: 1rem; flex: none; }
.mb-unblock { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 8px 14px; font-weight: 700; cursor: pointer; }
@media (max-width: 900px) { .music-bar { left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); } }
.yt-host, .yt-test { position: fixed; left: -10000px; top: 0; width: 200px; height: 200px; overflow: hidden; pointer-events: none; }
.yt-slot { width: 200px; height: 200px; }

/* Ajustes de lectura */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.zoom { display: flex; align-items: center; gap: 8px; }
.zoom-txt { width: 48px; text-align: center; font-weight: 700; }
.page-jump { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pj { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; }
.pj.current { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* =========================================================
   ESCRIBIR
   ========================================================= */
.write-head { display: flex; gap: 22px; align-items: flex-start; }
.cover-sm { width: 110px; flex: none; aspect-ratio: 2/3; border-radius: 4px 8px 8px 4px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; font-size: 2.4rem; box-shadow: 0 6px 16px rgba(0,0,0,.14); }
.cover-sm img { width: 100%; height: 100%; object-fit: cover; }
.wh-info { flex: 1; min-width: 0; }
.wh-info .page-title { overflow-wrap: anywhere; }
.stats { display: flex; gap: 22px; margin: 12px 0 14px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.stat-n { font-weight: 700; font-size: 1.15rem; }
@media (max-width: 560px) { .write-head { flex-direction: column; } .cover-sm { width: 90px; } }
.ch-cards { display: flex; flex-direction: column; gap: 10px; }
.ch-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); flex-wrap: wrap; }
.link-card { color: var(--ink); text-decoration: none !important; }
.link-card:hover { border-color: var(--accent); }
.chc-main { display: flex; gap: 14px; align-items: center; min-width: 0; flex: 1; }
.chc-main h3 { margin: 0 0 2px; font-size: 1.05rem; overflow-wrap: anywhere; }
.chc-main p { margin: 0; }
.chc-actions { display: flex; gap: 8px; }
.add-ch { width: 100%; margin-top: 12px; border-style: dashed; }
.finish-zone { margin-top: 34px; padding: 18px; border-radius: 14px; border: 1px dashed color-mix(in srgb, var(--err) 50%, var(--line)); display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.finish-zone h3 { margin: 0 0 4px; }
.finish-zone p { margin: 0; }
.font-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.font-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; }
.font-opt.current { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.fo-sample { font-size: 1.15rem; }
.fo-name { font-weight: 700; font-size: .85rem; }
.fo-note { font-size: .75rem; color: var(--muted); }
.cover-prev { width: 120px; }
.cover-prev img { border-radius: 4px 8px 8px 4px; box-shadow: var(--shadow); }

/* Editor */
.editor {
  --zoom: 1;
  --ph: min(calc(100dvh - 270px), calc((100vw - 60px) / 2 * 1.48), 1500px);
  --pw: calc(var(--ph) / 1.48);
  min-height: 100dvh; background: var(--desk); display: flex; flex-direction: column;
}
.ed-top { display: flex; align-items: center; gap: 10px; padding: 8px clamp(8px, 2vw, 20px); background: var(--surface); border-bottom: 1px solid var(--line); }
.ed-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ch-title-in { font-family: "Fraunces", Georgia, serif; font-weight: 700; font-size: 1.15rem; border: 1px solid transparent; background: transparent; color: var(--ink); border-radius: 8px; padding: 2px 6px; margin-left: -6px; width: 100%; }
.ch-title-in:hover, .ch-title-in:focus { border-color: var(--line); background: var(--bg); outline: none; }
.page-tabs { display: flex; gap: 6px; padding: 10px clamp(8px, 2vw, 20px) 4px; overflow-x: auto; align-items: center; scrollbar-width: thin; }
.ptab { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .88rem; min-height: 38px; }
.ptab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .5; }
.ptab.pub .dot { background: var(--ok); opacity: 1; }
.ptab.current { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.ptab.add { border-style: dashed; color: var(--accent); }
.tab-note { padding-left: 6px; }
.ed-toolbar {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: center;
  padding: 6px 10px; margin: 6px auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); max-width: calc(100% - 16px);
}
.tb { min-width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; font-size: 1rem; }
.tb:hover { background: var(--surface-2); }
.tb.b { font-weight: 900; } .tb.i { font-style: italic; font-family: Georgia, serif; } .tb.u { text-decoration: underline; }
.tb-font { height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); padding: 0 8px; font: inherit; max-width: 170px; }
.tb-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.ed-area { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 8px 8px 16px; }
.ed-spread { filter: drop-shadow(0 18px 30px rgba(30, 15, 5, .2)); }
.ed-text { min-height: 100%; outline: none; cursor: text; }
.ed-text:empty::before { content: "Empieza a escribir aquí…"; color: var(--muted); }
.page.editing { box-shadow: 0 0 0 2px var(--accent); z-index: 1; }
.page.preview { cursor: pointer; }
.page.preview .page-inner { opacity: .65; }
.page.preview:hover .page-inner { opacity: .9; }
.preview-tag { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); font-size: .72rem; font-weight: 700; background: var(--surface-2); color: var(--muted); padding: 3px 10px; border-radius: 999px; opacity: 0; transition: opacity .2s; }
.page.preview:hover .preview-tag { opacity: 1; }
.center-col { display: flex; align-items: center; justify-content: center; }
.ed-img { position: relative; }
.img-x { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.ed-status {
  position: sticky; bottom: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px clamp(10px, 2vw, 20px) calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.st-left, .st-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ed-status .full { flex-basis: 100%; margin: 0; }
.words { font-weight: 700; font-variant-numeric: tabular-nums; }
.words.near { color: #b7791f; }
.words.over { color: var(--err); }
.save-state { color: var(--muted); font-size: .85rem; }
.save-state.dirty { color: #b7791f; }
.pub-badge { color: var(--ok); font-weight: 700; }
@media (max-width: 600px) {
  .ed-status .btn { padding: 8px 12px; min-height: 40px; font-size: .9rem; }
  .ed-toolbar { margin: 4px 6px; border-radius: 12px; }
  .tb { min-width: 36px; height: 38px; }
  .tb-sep { display: none; }
  .ed-sheet .page-inner { padding: 22px 18px 48px; }
  .ed-toolbar { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  .tb, .tb-font { flex: none; }
  .tb-font { max-width: 120px; }
  .ed-status { padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
  .st-right { gap: 8px; }
  .hide-sm { display: none; }
  .ed-top .btn { padding: 8px 12px; min-height: 40px; }
  .ed-titles .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
.songs { display: flex; flex-direction: column; gap: 14px; }
.song { padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; gap: 10px; }
.song-head { display: flex; justify-content: space-between; }

/* ---------- Admin ---------- */
.admin-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 20px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; padding: 10px 12px; background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
.table td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.td-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-warn { background: color-mix(in srgb, var(--err) 7%, transparent); }
.row-dim { opacity: .5; }

/* ---------- Imprimir / PDF ---------- */
.print-book { display: none; }
@media print {
  body.printing > *:not(.print-book) { display: none !important; }
  body.printing .print-book { display: block; color: #000; }
  .print-cover { text-align: center; padding-top: 30vh; page-break-after: always; }
  .print-cover h1 { font-size: 32pt; }
  .print-ch { page-break-before: always; font-size: 20pt; margin-bottom: 1.5em; }
  .print-page { font-size: 12pt; line-height: 1.6; margin-bottom: 1em; }
  .print-page p { margin: 0 0 .5em; text-indent: 1.4em; }
  .print-page img { max-height: 80vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
