/* PLIEGO — lector 3D. Los colores de cada ambiente viven en themes.css. */
:root {
  --rd-fg: #f4f2ee;
  --rd-muted: rgba(244, 242, 238, .62);
  --rd-ui: rgba(16, 18, 32, .62);
  --rd-ui-line: rgba(255, 255, 255, .12);
  --rd-ui-fg: #f4f2ee;
  --rd-accent: #f2c14e;
  --rd-accent-fg: #17130a;
  --rd-book-shadow: rgba(0, 0, 0, .55);
  --rd-paper: #ffffff;
  --rd-verso: #f3f0e8;
  --rd-top-h: 64px;
  --rd-dock-h: 84px;
  --rd-font: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --rd-display: 'Bricolage Grotesque', 'Instrument Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.rd {
  overflow: hidden; height: 100dvh; font-family: var(--rd-font); color: var(--rd-fg);
  background: #0c0f1c; -webkit-font-smoothing: antialiased; touch-action: manipulation;
}
button { font: inherit; color: inherit; }
.rd-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------ escena */
.rd-scene { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.rd-bg { position: absolute; inset: 0; background: var(--rd-bg, #0c0f1c); transition: background .6s; }
.rd-light { position: absolute; inset: 0; background: var(--rd-light, none); mix-blend-mode: screen; }
.rd-fx { position: absolute; inset: 0; width: 100%; height: 100%; }
.rd-ornament { position: absolute; left: 0; right: 0; top: calc(var(--rd-top-h) - 10px); pointer-events: none; }
.rd-ornament svg { display: block; overflow: visible; }

/* ------------------------------------------------------------ cabecera */
.rd-top {
  position: fixed; z-index: 5; top: 0; left: 0; right: 0; height: var(--rd-top-h);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; padding: 0 20px;
  background: linear-gradient(180deg, rgba(0,0,0,.35), rgba(0,0,0,0));
}
.rd-brand { display: flex; align-items: center; gap: 10px; color: var(--rd-fg); text-decoration: none; font-family: var(--rd-display); font-weight: 800; letter-spacing: .04em; font-size: 15px; }
.rd-regmark { width: 22px; height: 22px; border-radius: 50%; position: relative; flex: none;
  border: 1.6px solid currentColor; }
.rd-regmark::before, .rd-regmark::after { content: ''; position: absolute; background: currentColor; }
.rd-regmark::before { left: 50%; top: -5px; bottom: -5px; width: 1.6px; transform: translateX(-50%); }
.rd-regmark::after { top: 50%; left: -5px; right: -5px; height: 1.6px; transform: translateY(-50%); }
.rd-title { min-width: 0; text-align: center; }
.rd-title h1 { margin: 0; font-family: var(--rd-display); font-weight: 600; font-size: 17px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rd-title p { margin: 2px 0 0; font-size: 12.5px; color: var(--rd-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rd-top-actions { display: flex; gap: 8px; }
.rd-chip { display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  color: var(--rd-ui-fg); background: var(--rd-ui); border: 1px solid var(--rd-ui-line); text-decoration: none; backdrop-filter: blur(10px); }
.rd-chip:hover { border-color: var(--rd-accent); }
.rd-draft { position: fixed; z-index: 6; top: calc(var(--rd-top-h) + 4px); left: 50%; transform: translateX(-50%);
  background: #f5c400; color: #1b1500; font-size: 13px; font-weight: 600; padding: 6px 14px; border-radius: 999px; }

/* ------------------------------------------------------------ escenario */
.rd-stage { position: fixed; z-index: 2; left: 0; right: 0; top: var(--rd-top-h); bottom: var(--rd-dock-h); perspective: 2600px; perspective-origin: 50% 40%; }
.rd-book { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; touch-action: none; user-select: none; -webkit-user-select: none;
  --tilt-x: 0deg; --tilt-y: 0deg; }

/* ------------------------------------------------------------ motor PLFlip */
.pf-wrap { transform-style: preserve-3d; transition: transform .65s cubic-bezier(.3,.7,.2,1); will-change: transform; }
.pf-book { position: relative; width: calc(var(--pw) * 2); height: var(--ph); transform-style: preserve-3d;
  transform: rotateX(var(--tilt-x)) rotateY(var(--tilt-y)); transition: transform .5s ease-out, opacity .16s; cursor: pointer;
  will-change: transform, opacity; /* capa estable: sin re-rasterizar al animar */ }
.pf-single .pf-book { width: var(--pw); }
.rd-book:not(.rd-intro) .pf-book { opacity: 0.01; }  /* casi invisible: así ya está pintado cuando entra */
.rd-book.rd-intro .pf-book { animation: rd-enter 1.15s cubic-bezier(.2,.75,.2,1) backwards; }
@keyframes rd-enter {
  0% { opacity: 0.01; transform: translateY(70px) rotateX(32deg) scale(.82); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: rotateX(var(--tilt-x)) rotateY(var(--tilt-y)); }
}
.pf-jump .pf-book { opacity: .25; }
.pf-zoomed .pf-book { cursor: grab; }
.pf-zoomed .pf-wrap { transition: transform .25s ease-out; }

.pf-page { position: absolute; top: 0; width: var(--pw); height: var(--ph); background: var(--rd-paper);
  box-shadow: 0 30px 60px -20px var(--rd-book-shadow), 0 8px 18px -8px rgba(0,0,0,.35); }
.pf-left { left: 0; border-radius: 3px 0 0 3px; }
.pf-right { left: var(--pw); border-radius: 0 3px 3px 0; }
.pf-single .pf-left { display: none; }
.pf-single .pf-right { left: 0; border-radius: 2px 4px 4px 2px; }
.pf-face { position: absolute; inset: 0; background-color: var(--rd-paper); background-size: 100% 100%; background-repeat: no-repeat; border-radius: inherit; }
.pf-face:not(.pf-loaded):not(.pf-blank), .pf-sf:not(.pf-loaded):not(.pf-verso):not(.pf-blank) {
  /* página aún sin imagen: papel quieto (una animación aquí se percibe como parpadeo al hojear) */
  background-image: radial-gradient(circle at 50% 50%, rgba(0,0,0,.035), rgba(0,0,0,0) 60%) !important;
}
.pf-gutter { position: absolute; top: 0; bottom: 0; width: 18%; pointer-events: none; }
.pf-left .pf-gutter { right: 0; background: linear-gradient(90deg, rgba(0,0,0,0), rgba(0,0,0,.10) 70%, rgba(0,0,0,.28)); }
.pf-right .pf-gutter { left: 0; background: linear-gradient(270deg, rgba(0,0,0,0), rgba(0,0,0,.08) 70%, rgba(0,0,0,.24)); }
.pf-single .pf-right .pf-gutter { width: 5%; }
.pf-hard { box-shadow: 0 34px 70px -18px var(--rd-book-shadow), 0 0 0 1px rgba(0,0,0,.25), inset 0 0 0 1px rgba(255,255,255,.08); }
.pf-right.pf-hard { border-radius: 2px 6px 6px 2px; }
.pf-left.pf-hard { border-radius: 6px 2px 2px 6px; }
.pf-hard .pf-gutter { opacity: .55; }

/* canto de las páginas: grosor según las hojas restantes */
.pf-edge { position: absolute; top: 3px; bottom: 3px; width: 0; pointer-events: none;
  background: repeating-linear-gradient(90deg, #d9d5cc 0 1px, #fbfaf6 1px 2.5px); box-shadow: 0 20px 30px -18px var(--rd-book-shadow); }
.pf-edge-l { right: 100%; border-radius: 3px 0 0 3px; }
.pf-edge-r { left: 100%; border-radius: 0 3px 3px 0; }
.pf-single .pf-edge-l { display: none; }

.pf-spine { position: absolute; top: 0; height: 100%; left: calc(var(--pw) - 14px); width: 28px; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,0), rgba(0,0,0,.18) 45%, rgba(255,255,255,.08) 52%, rgba(0,0,0,.12) 58%, rgba(0,0,0,0));
  transform: translateZ(.6px); }
.pf-single .pf-spine { left: -6px; width: 16px; }

.pf-leaf { position: absolute; top: 0; left: var(--pw); width: var(--pw); height: var(--ph); transform-style: preserve-3d;
  transform: translateZ(1.2px); pointer-events: none; }
.pf-single .pf-leaf { left: 0; }
.pf-strip { position: absolute; top: 0; height: 100%; transform-origin: 0 50%; transform-style: preserve-3d; }
.pf-sf { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background-color: var(--rd-paper); background-size: var(--pw) var(--ph); background-repeat: no-repeat; overflow: hidden; }
.pf-sf-back { transform: rotateY(180deg); }
.pf-verso { background: var(--rd-verso) linear-gradient(90deg, rgba(0,0,0,.05), rgba(0,0,0,0) 30%); }
.pf-shade { position: absolute; inset: -1px; background: #000; opacity: 0; pointer-events: none; }
.pf-leaf-hard .pf-sf { box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.pf-cast { position: absolute; top: 0; height: 100%; width: 0; opacity: 0; pointer-events: none; transform: translateZ(.8px); }
.pf-cast-r { background: linear-gradient(90deg, rgba(0,0,0,.45), rgba(0,0,0,0)); }
.pf-cast-l { background: linear-gradient(270deg, rgba(0,0,0,.45), rgba(0,0,0,0)); }
.pf-corner-hint { display: none; }
.pf-gl { position: absolute; visibility: hidden; pointer-events: none; transform: translateZ(2px); z-index: 3; }

/* flechas laterales */
.rd-arrow { position: absolute; top: 50%; z-index: 3; width: 46px; height: 46px; margin-top: -23px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; border: 1px solid var(--rd-ui-line); background: var(--rd-ui); color: var(--rd-ui-fg);
  backdrop-filter: blur(10px); transition: opacity .25s, transform .2s, border-color .2s; }
.rd-arrow svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rd-arrow:hover { border-color: var(--rd-accent); transform: scale(1.06); }
.rd-arrow-prev { left: 14px; }
.rd-arrow-next { right: 14px; }
.rd-arrow.rd-hide { opacity: 0; pointer-events: none; }

/* cargador: pliegos que caen sobre la pila */
.rd-loader { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  transition: opacity .5s, visibility .5s; }
.rd-loader.rd-done { opacity: 0; visibility: hidden; }
.rd-press { position: relative; width: 84px; height: 108px; perspective: 600px; }
.rd-press span { position: absolute; inset: 0; border-radius: 3px; background: var(--rd-paper); box-shadow: 0 10px 24px -10px rgba(0,0,0,.6);
  transform-origin: 0 50%; animation: rd-sheet 2.4s cubic-bezier(.5,0,.3,1) infinite; }
.rd-press span:nth-child(1) { animation-delay: 0s; } .rd-press span:nth-child(2) { animation-delay: .6s; }
.rd-press span:nth-child(3) { animation-delay: 1.2s; } .rd-press span:nth-child(4) { animation-delay: 1.8s; background: var(--rd-accent); }
@keyframes rd-sheet { 0% { transform: rotateY(0); opacity: 1; } 45% { transform: rotateY(-180deg); opacity: 1; } 55%, 100% { transform: rotateY(-180deg); opacity: 0; } }
.rd-loader p { margin: 0; font-size: 14px; color: var(--rd-muted); }
.rd-progress { width: 160px; height: 3px; border-radius: 3px; background: var(--rd-ui-line); overflow: hidden; }
.rd-progress i { display: block; height: 100%; width: 0; background: var(--rd-accent); transition: width .25s; }
.rd-loader.rd-error .rd-press { opacity: .25; }
.rd-hint { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 3; margin: 0; padding: 7px 14px; border-radius: 999px;
  background: var(--rd-ui); border: 1px solid var(--rd-ui-line); color: var(--rd-ui-fg); font-size: 13px; backdrop-filter: blur(10px);
  transition: opacity .6s; white-space: nowrap; }
.rd-hint-out { opacity: 0; }

/* ------------------------------------------------------------ dock */
.rd-dock { position: fixed; z-index: 6; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px;
  padding: 6px; border-radius: 16px; background: var(--rd-ui); border: 1px solid var(--rd-ui-line); color: var(--rd-ui-fg);
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  box-shadow: 0 18px 40px -16px rgba(0,0,0,.6); max-width: calc(100vw - 16px); }
.rd-btn { display: inline-flex; align-items: center; gap: 6px; height: 40px; min-width: 40px; padding: 0 9px; border: 0; border-radius: 10px;
  background: transparent; cursor: pointer; color: inherit; text-decoration: none; justify-content: center; font-size: 13.5px; font-weight: 600; }
.rd-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.rd-btn:hover:not(:disabled) { background: rgba(255,255,255,.1); }
.rd-btn:disabled { opacity: .35; cursor: default; }
.rd-btn:focus-visible, .rd-arrow:focus-visible, .rd-chip:focus-visible, .rd-sheet button:focus-visible, .rd-sheet a:focus-visible { outline: 2px solid var(--rd-accent); outline-offset: 2px; }
.rd-btn[aria-pressed="true"], .rd-btn.rd-on { background: rgba(255,255,255,.14); }
.rd-btn-accent { background: var(--rd-accent); color: var(--rd-accent-fg); }
.rd-btn-accent:hover:not(:disabled) { background: var(--rd-accent); filter: brightness(1.08); }
.rd-btn .rd-ic-pause { display: none; }
.rd-btn.rd-on .rd-ic-play { display: none; }
.rd-btn.rd-on .rd-ic-pause { display: inline; }
.rd-btn .rd-ic-mute { display: none; }
.rd-btn.rd-off .rd-ic-mute { display: inline; }
.rd-btn.rd-off .rd-ic-wave { display: none; }
.rd-sep { width: 1px; height: 22px; background: var(--rd-ui-line); margin: 0 4px; }
.rd-pager { display: flex; align-items: center; gap: 4px; padding: 0 4px; font-variant-numeric: tabular-nums; font-size: 13.5px; }
.rd-pager input { width: 64px; height: 32px; border-radius: 8px; border: 1px solid var(--rd-ui-line); background: rgba(0,0,0,.18); color: inherit;
  text-align: center; font: inherit; font-weight: 600; }
.rd-pager input:focus { outline: 2px solid var(--rd-accent); outline-offset: 0; }
.rd-pager span { color: var(--rd-muted); white-space: nowrap; }

/* ------------------------------------------------------------ paneles */
.rd-sheet { position: fixed; z-index: 8; top: calc(var(--rd-top-h) + 8px); right: 16px; bottom: calc(var(--rd-dock-h) + 8px); width: 340px;
  display: flex; flex-direction: column; border-radius: 16px; background: var(--rd-ui); border: 1px solid var(--rd-ui-line); color: var(--rd-ui-fg);
  backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3); box-shadow: 0 24px 60px -20px rgba(0,0,0,.7);
  animation: rd-sheet-in .28s cubic-bezier(.2,.8,.2,1); }
.rd-sheet[hidden] { display: none; }
.rd-sheet-sm { bottom: auto; max-height: calc(100dvh - var(--rd-top-h) - var(--rd-dock-h) - 16px); overflow: auto; }
@keyframes rd-sheet-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.rd-sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.rd-sheet h2 { margin: 0; font-family: var(--rd-display); font-size: 16px; font-weight: 600; }
.rd-close { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; font-size: 22px; line-height: 1; }
.rd-close:hover { background: rgba(255,255,255,.1); }
.rd-thumbs-grid { flex: 1; overflow: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 6px 16px 16px; align-content: start; }
.rd-thumb { border: 0; padding: 0; background: none; cursor: pointer; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.rd-thumb-img { width: 100%; aspect-ratio: .72; background: rgba(255,255,255,.08); border-radius: 3px; overflow: hidden; display: block;
  outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .2s; }
.rd-thumb-img canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.rd-thumb-n { font-size: 11.5px; color: var(--rd-muted); font-variant-numeric: tabular-nums; }
.rd-thumb.on .rd-thumb-img { outline-color: var(--rd-accent); }
.rd-thumb:hover .rd-thumb-img { outline-color: var(--rd-ui-line); }

.rd-share-card { display: flex; gap: 12px; align-items: center; margin: 4px 16px 12px; padding: 10px; border-radius: 12px; background: rgba(0,0,0,.2); }
.rd-share-card img { width: 96px; aspect-ratio: 1.905; object-fit: cover; border-radius: 6px; flex: none; }
.rd-share-card strong { display: block; font-size: 14px; line-height: 1.25; }
.rd-share-card small { display: block; margin-top: 3px; font-size: 12px; color: var(--rd-muted); word-break: break-all; }
.rd-share-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 16px; }
.rd-share-grid a, .rd-share-grid button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 12px;
  border: 1px solid var(--rd-ui-line); background: transparent; color: inherit; text-decoration: none; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.rd-share-grid a:hover, .rd-share-grid button:hover { border-color: var(--rd-accent); }
.rd-share-grid svg { width: 22px; height: 22px; fill: currentColor; }
.rd-share-grid [data-net="email"] svg, .rd-share-grid [data-net="copy"] svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.rd-linkpage { display: block; margin: 10px 16px 16px; width: calc(100% - 32px); padding: 10px; border-radius: 10px; border: 1px dashed var(--rd-ui-line);
  background: none; cursor: pointer; font-size: 13px; color: var(--rd-muted); }
.rd-linkpage:hover { color: var(--rd-ui-fg); border-color: var(--rd-accent); }
.rd-theme-group { margin: 8px 16px 6px; font-size: 12px; color: var(--rd-muted); }
.rd-theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 0 16px 8px; }
.rd-theme { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 10px; border: 1px solid var(--rd-ui-line); background: none; cursor: pointer;
  font-size: 13px; text-align: left; }
.rd-theme:hover { border-color: rgba(255,255,255,.35); }
.rd-theme.on { border-color: var(--rd-accent); box-shadow: inset 0 0 0 1px var(--rd-accent); }
.rd-theme-chip { width: 30px; height: 30px; border-radius: 7px; flex: none;
  background: radial-gradient(circle at 70% 30%, var(--c3) 0 18%, transparent 19%), linear-gradient(135deg, var(--c1), var(--c2)); box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.rd-sheet-sm:last-of-type { padding-bottom: 8px; }

.rd-toast { position: fixed; z-index: 9; left: 50%; bottom: calc(var(--rd-dock-h) + 10px); transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  padding: 9px 16px; border-radius: 999px; background: var(--rd-accent); color: var(--rd-accent-fg); font-size: 13.5px; font-weight: 600; transition: all .25s; }
.rd-toast.on { opacity: 1; transform: translate(-50%, 0); }
.rd-noscript { position: fixed; inset: 40% 20px auto; text-align: center; z-index: 10; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 760px) {
  :root { --rd-top-h: 54px; --rd-dock-h: 70px; }
  .rd-top { padding: 0 12px; gap: 10px; }
  .rd-brand-name { display: none; }
  .rd-title { text-align: left; }
  .rd-title h1 { font-size: 15px; }
  .rd-arrow { display: none; }
  .rd-dock { bottom: 10px; gap: 0; padding: 4px; border-radius: 14px; }
  .rd-btn { min-width: 36px; height: 38px; padding: 0 6px; }
  .rd-btn span { display: none; }
  .rd-dock [data-act="first"], .rd-dock [data-act="last"], .rd-dock [data-act="play"], .rd-dock [data-act="zoom"] { display: none; }
  .rd-pager input { width: 54px; }
  .rd-sheet { left: 8px; right: 8px; width: auto; top: auto; bottom: calc(var(--rd-dock-h) + 6px); max-height: 70dvh; }
  .rd-hint { bottom: 4px; font-size: 12px; }
}
@media (max-width: 400px) {
  .rd-dock [data-act="fullscreen"], .rd-dock .rd-sep { display: none; }
}

/* modo incrustado: sin cabecera, dock compacto */
.rd-embed { --rd-top-h: 44px; }
.rd-embed .rd-top { height: 44px; }
.rd-embed .rd-title p { display: none; }
.rd-embed .rd-ornament { display: none; }

@media (prefers-reduced-motion: reduce) {
  .rd-book.rd-intro .pf-book { animation: none; }
  .pf-wrap, .pf-book { transition: none; }
  .rd-press span { animation-duration: 6s; }
}

/* ------------------------------------------------------------ 404 */
body.rd-404 { min-height: 100vh; margin: 0; display: grid; place-items: center; background: #161a33; color: #f3f1ec;
  font-family: 'Instrument Sans', system-ui, sans-serif; text-align: center; padding: 24px; }
.rd-404 main { max-width: 420px; }
.rd-404 h1 { font-size: 28px; margin: 18px 0 8px; }
.rd-404 p { color: rgba(243,241,236,.7); line-height: 1.5; }
.rd-404 a { color: #00a7c8; }
.rd-404-mark { display: inline-block; width: 48px; height: 48px; border-radius: 50%; border: 2px solid #e0307a; }
.rd-draft.rd-preview { background: #00a7c8; color: #04212a; }
