/* Pivot — estilos de la app. Variables en :root; temas del panel de texto en .sepia/.light */
* { margin:0; padding:0; box-sizing:border-box; }
:root {
  --bg: #0a0a0a; --surface: #141414; --surface2: #1a1a1a;
  --text: #e8e8e8; --dim: #555; --dim2: #888;
  --accent: #e74c3c; --accent2: #ff6b5b;
  --green: #2ecc71; --border: #222; --radius: 12px;
}
html, body { height: 100%; }
body {
  font-family: 'SF Mono','Fira Code','Consolas',monospace;
  background: var(--bg); color: var(--text);
  height: 100dvh; display: flex; flex-direction: column;
  overflow: hidden; -webkit-tap-highlight-color: transparent; user-select: none;
}
header {
  display:flex; align-items:center; justify-content:space-between;
  padding:10px 16px; border-bottom:1px solid var(--border); flex-shrink:0;
  background: var(--bg); z-index:10;
}
header h1 { font-size:15px; font-weight:600; letter-spacing:1px; }
header h1 span { color:var(--accent); }

.view { display:none; flex-direction:column; flex:1 1 0; min-height:0; overflow:hidden; }
.view.active { display:flex; }

button {
  background:var(--accent); color:#fff; border:none; border-radius:var(--radius);
  padding:10px 20px; font-family:inherit; font-size:14px; font-weight:600;
  cursor:pointer; transition:background .15s; white-space:nowrap;
}
button:active { background:var(--accent2); }
button.secondary { background:var(--surface); border:1px solid var(--border); }
button.sm { padding:6px 14px; font-size:12px; }

/* --- LIBRARY --- */
.library { flex:1 1 0; min-height:0; padding:16px; overflow-y:auto; -webkit-overflow-scrolling:touch; }
.library-empty { text-align:center; color:var(--dim); padding:40px 20px; font-size:14px; }
.book-card { position:relative; }
.bc-del { position:absolute; top:6px; right:6px; background:none; border:none; color:var(--dim); font-size:18px; line-height:1; padding:6px 10px; border-radius:6px; }
.bc-del:active { background:var(--surface2); color:var(--accent); }
.bc-row { display:flex; gap:12px; align-items:center; }
.bc-cover { width:44px; height:60px; border-radius:6px; flex:none; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:20px; color:rgba(255,255,255,.85); }
.bc-body { flex:1; min-width:0; }
.continue-hero { background:var(--surface); border:1px solid var(--accent); border-radius:var(--radius); padding:14px 16px; margin-bottom:12px; cursor:pointer; }
.continue-hero:active { background:var(--surface2); }
.continue-hero .hero-label { color:var(--accent); font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.08em; }
.continue-hero .hero-book { font-weight:600; margin-top:4px; }
.continue-hero .hero-detail { color:var(--dim2); font-size:12px; margin-top:2px; }
.library-footer { display:flex; gap:8px; align-items:center; justify-content:center; padding:8px 0 0; color:var(--dim); font-size:12px; }
.library-footer button { background:none; border:none; color:var(--dim2); font-size:12px; padding:4px 6px; text-decoration:underline; }
.empty-actions { margin-top:16px; }
.empty-actions button { background:var(--surface2); border:1px solid #2a2a2a; color:var(--text); font-size:13px; padding:10px 16px; }
.stats-strip { display:flex; gap:8px; margin-bottom:12px; }
.stats-strip .stat { flex:1; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:10px 4px; text-align:center; min-width:0; }
.stats-strip .stat-v { font-size:17px; font-weight:700; }
.stats-strip .stat-l { font-size:10px; color:var(--dim2); margin-top:2px; }
.lib-search {
  width:100%; margin-bottom:12px; background:var(--surface);
  border:1px solid var(--border); border-radius:var(--radius);
  color:var(--text); font-family:inherit; font-size:14px;
  padding:10px 12px; outline:none;
}
.lib-search:focus { border-color:var(--accent); }
.wpm-presets { display:flex; gap:6px; justify-content:center; margin-top:6px; }
.wpm-presets .preset { background:var(--surface); border:1px solid var(--border); color:var(--dim2); font-size:12px; font-weight:600; padding:5px 0; flex:1; max-width:72px; border-radius:8px; }
.wpm-presets .preset.active { border-color:var(--accent); color:var(--text); }
.book-card {
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:14px 16px; margin-bottom:10px; cursor:pointer; transition:border-color .15s;
}
.book-card:active { border-color:var(--accent); }
.book-card .bc-title { font-size:15px; font-weight:600; margin-bottom:4px; }
.book-card .bc-meta { font-size:12px; color:var(--dim); }
.book-card .bc-progress { margin-top:8px; }
.book-card .bc-progress-bar { width:100%; height:3px; background:var(--border); border-radius:2px; overflow:hidden; }
.book-card .bc-progress-fill { height:100%; background:var(--green); transition:width .3s; }
.book-card .bc-progress-text { font-size:11px; color:var(--dim); margin-top:4px; }
.book-card .bc-resume { color:var(--green); font-size:12px; margin-top:6px; font-weight:600; }
.library-actions { display:flex; gap:8px; padding:0 16px 16px; }
.library-actions button { flex:1; }

/* --- CHAPTERS --- */
.chapters-header { padding:12px 16px; border-bottom:1px solid var(--border); flex-shrink:0; }
.chapters-header .ch-title { font-size:16px; font-weight:600; }
.chapters-header .ch-author { font-size:12px; color:var(--dim); }
.chapters-list { flex:1 1 0; min-height:0; overflow-y:auto; padding:8px 16px; -webkit-overflow-scrolling:touch; }
.ch-item {
  display:flex; align-items:center; gap:12px;
  padding:12px; border-bottom:1px solid var(--border); cursor:pointer;
}
.ch-item:active { background:var(--surface); }
.ch-item .ch-num { color:var(--dim); font-size:13px; min-width:28px; }
.ch-item .ch-info { flex:1; }
.ch-item .ch-name { font-size:14px; }
.ch-item .ch-words { font-size:11px; color:var(--dim); }
.ch-item .ch-read { width:8px; height:8px; border-radius:50%; background:var(--green); flex-shrink:0; }
.ch-item .ch-current { background:var(--accent); }
.ch-item.resuming { background:var(--surface2); }

/* --- INPUT --- */
#view-input { padding:16px; gap:12px; }
.input-group label {
  display:block; font-size:12px; color:var(--dim);
  margin-bottom:6px; text-transform:uppercase; letter-spacing:1px;
}
textarea {
  width:100%; flex:1; min-height:120px; background:var(--surface);
  border:1px solid var(--border); border-radius:var(--radius);
  color:var(--text); font-family:inherit; font-size:14px;
  padding:12px; resize:none; outline:none;
}
textarea:focus { border-color:var(--accent); }
.url-row { display:flex; gap:8px; }
.url-row input {
  flex:1; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius); color:var(--text); font-family:inherit;
  font-size:14px; padding:10px 12px; outline:none;
}
.url-row input:focus { border-color:var(--accent); }
.btn-row { display:flex; gap:8px; }
.btn-row button { flex:1; }
#extract-status { font-size:12px; color:var(--dim); min-height:18px; }

/* --- SPLIT READER --- */
#view-reader { position:relative; }

.split-container {
  flex:1 1 0; min-height:0; display:flex; flex-direction:column; position:relative; overflow:hidden;
}

/* Top: RSVP */
.split-rsvp {
  /* el panel RSVP es oscuro siempre: el fondo negro es parte del método */
  --bg:#0a0a0a; --text:#e8e8e8; --dim:#555; --dim2:#888; --border:#222;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  position:relative; overflow:hidden; flex-shrink:0;
  background: var(--bg);
}
/* Reticle at 35% from the left (the ORP's natural position in a word), so
   words read balanced instead of right-loaded. Keep in sync with ORP_ANCHOR. */
.orp-line {
  position:absolute; left:35%; top:15%; bottom:15%;
  width:2px; background:var(--accent); opacity:.2; pointer-events:none;
  transform:translateX(-50%);
}
 /* Dinkus (• • •) bajo la retícula que marca la frontera de párrafo (última
    palabra de uno y primera del siguiente). Tres puntos horizontales — el
    símbolo tipográfico de corte de sección — en la periferia de la fijación:
    se percibe sin mover el ojo, y al ser horizontal no se confunde con la
    línea vertical de la retícula (un punto solo, pegado a su extremo inferior,
    parecía "gotear" de la línea y era casi imperceptible). Los dos puntos
    laterales salen por box-shadow, así el .show/opacity los tiñe a todos. */
 .para-dot {
   position:absolute; left:35%; bottom:15%; width:7px; height:7px;
   border-radius:50%; background:var(--accent); opacity:0;
   transform:translateX(-50%); transition:opacity .18s; pointer-events:none;
   box-shadow:-16px 0 0 var(--accent), 16px 0 0 var(--accent);
 }
 .para-dot.show { opacity:.9; }
.word-display {
  font-size:clamp(32px,9vw,68px); font-weight:700; letter-spacing:2px;
  white-space:nowrap; width:100%; text-align:left;
}
/* ORP alignment + auto-fit: JS applies a single translateX()+scale() to
   .word-inner so the pivot glyph lands on the centred reticle AND the whole
   word shrinks to fit the panel when it is wider than the screen. */
.word-display .word-inner { display:inline-block; transform-origin:left center; will-change:transform; }
.word-display .orp { color:var(--accent); }
.rsvp-meta {
  font-size:11px; color:var(--dim); margin-top:6px; text-align:center;
  padding:0 16px;
}

/* Drag handle */
.split-handle {
  height:24px; background:var(--surface); display:flex;
  align-items:center; justify-content:center; cursor:ns-resize;
  flex-shrink:0; border-top:1px solid var(--border); border-bottom:1px solid var(--border);
  touch-action:none; z-index:5;
}
.split-handle .grip {
  width:40px; height:4px; background:var(--dim); border-radius:2px;
}

/* Bottom: ereader text */
.split-reader {
  flex:1 1 0; min-height:0; overflow-y:auto; -webkit-overflow-scrolling:touch;
  background:#111; padding:16px 20px;
  font-family:'Georgia','Times New Roman','Noto Serif',serif;
  font-size:17px; line-height:1.75; color:#bbb;
  user-select:text;
}
 .split-reader p { margin-bottom:.8em; }
 /* Marca de diálogo: acento sutil a la izquierda del parlamento (— …). */
 .split-reader.dlg-on p.dlg { border-left:2px solid rgba(231,76,60,.35); padding-left:10px; }
 /* Per-word state: default = upcoming (light), .passed = already read (dim),
    .sentence = oración actual (brillante, "you are here" — reconstruye el mapa
    espacial al bajar la vista), .current = palabra actual. El orden importa:
    .sentence pisa a .passed, y .current pisa a .sentence. */
 .split-reader .w { color:#c8c8c8; cursor:pointer; contain:layout style; }
 .split-reader .w.passed { color:#555; }
 .split-reader .w.sentence { color:#f4f4f4; }
 .split-reader .w.current { color:var(--accent); font-weight:600; }
 /* Temas del panel de texto: el RSVP de arriba queda siempre oscuro */
 .split-reader.sepia { background:#f2e8d5; color:#59462f; }
 .split-reader.sepia .w { color:#59462f; }
 .split-reader.sepia .w.passed { color:#b9ab8c; }
 .split-reader.sepia .w.sentence { color:#2f2109; }
 .split-reader.sepia .w.current { color:#c0392b; }
 .split-reader.light { background:#fafafa; color:#2b2b2b; }
 .split-reader.light .w { color:#2b2b2b; }
 .split-reader.light .w.passed { color:#b8b8b8; }
 .split-reader.light .w.sentence { color:#000; }
 .split-reader.light .w.current { color:#c0392b; }

/* Controls bar */
.reader-controls {
  padding:10px 16px 14px; display:flex; flex-direction:column; gap:8px;
  flex-shrink:0; border-top:1px solid var(--border); background:var(--bg);
}
/* El wrapper agranda la zona de toque sin engordar la barra visual */
.progress-tap { padding:8px 0; margin:-8px 0; cursor:pointer; touch-action:none; }
.progress-bar { width:100%; height:3px; background:var(--border); border-radius:2px; overflow:hidden; }
.progress-bar .fill { height:100%; background:var(--accent); transition:width .1s linear; width:0%; }
.wpm-row { display:flex; align-items:center; gap:10px; }
.wpm-row label { font-size:11px; color:var(--dim); white-space:nowrap; }
.wpm-row .wpm-val { font-size:18px; font-weight:700; min-width:48px; text-align:right; }
input[type=range] {
  flex:1; -webkit-appearance:none; appearance:none;
  height:4px; background:var(--border); border-radius:2px; outline:none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance:none; width:20px; height:20px;
  background:var(--accent); border-radius:50%; cursor:pointer;
}
.ctrl-btns { display:flex; gap:6px; justify-content:center; }
.ctrl-btns button {
  width:48px; height:48px; border-radius:50%; padding:0;
  font-size:18px; display:flex; align-items:center; justify-content:center;
}
.ctrl-btns button.play-btn { width:56px; height:56px; font-size:22px; }
.chapter-nav { display:flex; gap:6px; }
.chapter-nav button { flex:1; }

.reader-top {
  display:flex; justify-content:space-between; align-items:center;
  padding:4px 16px; font-size:11px; color:var(--dim); flex-shrink:0; gap:8px;
}
.reader-top #reader-info { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.fs-controls { display:flex; gap:4px; flex-shrink:0; }
.fs-btn { background:none; border:1px solid var(--border); color:var(--dim2); font-size:11px; font-weight:600; padding:2px 8px; border-radius:6px; line-height:1.4; }
.fs-btn:active { border-color:var(--accent); color:var(--text); }

.finished-msg { font-size:16px; color:var(--dim); text-align:center; }
.finished-msg span { color:var(--accent); font-weight:700; }

/* Loading */
.loading {
  position:fixed; inset:0; background:rgba(0,0,0,.8);
  display:none; align-items:center; justify-content:center;
  z-index:100; font-size:16px; flex-direction:column; gap:12px;
}
.loading.active { display:flex; }
.spinner {
  width:32px; height:32px; border:3px solid var(--border);
  border-top-color:var(--accent); border-radius:50%; animation:spin .8s linear infinite;
}
@keyframes spin { to { transform:rotate(360deg); } }

/* Ajustes de lectura: bottom sheet */
.sheet-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.55); z-index:150; display:none; }
.sheet-backdrop.open { display:block; }
.sheet {
  position:absolute; left:0; right:0; bottom:0; background:var(--surface);
  border-top:1px solid var(--border); border-radius:16px 16px 0 0;
  padding:16px 20px calc(20px + env(safe-area-inset-bottom)); max-height:75dvh; overflow-y:auto;
}
.sheet-title { font-size:12px; color:var(--dim2); text-transform:uppercase; letter-spacing:.08em; margin-bottom:4px; }
.set-row {
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:12px 0; border-bottom:1px solid var(--border); cursor:pointer;
}
.set-row:last-child { border-bottom:none; }
.set-label { font-size:14px; }
.set-hint { font-size:11px; color:var(--dim2); margin-top:2px; }
.set-row input[type=checkbox] { width:22px; height:22px; accent-color:var(--accent); flex:none; cursor:pointer; }
.seg { display:flex; gap:4px; flex:none; flex-wrap:wrap; justify-content:flex-end; }
.seg button { background:var(--surface2); border:1px solid var(--border); color:var(--dim2); font-size:12px; font-weight:600; padding:6px 10px; border-radius:8px; }
.seg button.active { border-color:var(--accent); color:var(--text); }

/* Toast — always-visible feedback overlay (replaces hidden extractStatus errors) */
.toast {
  position:fixed; left:50%; bottom:24px; transform:translate(-50%, 80px);
  background:var(--surface2); border:1px solid var(--border); color:var(--text);
  padding:10px 16px; border-radius:var(--radius); font-size:13px;
  box-shadow:0 6px 24px rgba(0,0,0,.5); z-index:200;
  max-width:min(90vw, 420px); pointer-events:none; opacity:0;
  transition:transform .25s ease, opacity .25s ease; white-space:pre-wrap;
}
.toast.show { transform:translate(-50%, 0); opacity:1; }
.toast.error { border-color:var(--accent); }
.toast.info { border-color:var(--green); }

/* Inbox (ADR-016): elementos compartidos que esperan red */
.inbox-status { margin:4px 16px 0; padding:6px 10px; border-radius:8px; background:var(--surface2); color:var(--dim2); font-size:12px; text-align:center; }

/* Card de instalación (beforeinstallprompt) */
.install-card { margin:8px 16px 0; padding:12px 14px; border:1px solid var(--border); border-radius:var(--radius); background:var(--surface); display:flex; align-items:center; gap:12px; font-size:13px; color:var(--dim2); }
.install-card strong { color:var(--text); }
.install-card button { flex:none; padding:8px 14px; border-radius:8px; border:none; background:var(--accent); color:#fff; font-weight:600; font-size:13px; }
/* Toast accionable (versión nueva) */
.toast.action { cursor:pointer; text-decoration:underline; text-underline-offset:3px; }

/* Cita por long-press en el panel de texto (plan v4, ítem 6) */
#split-container { position:relative; }
.split-reader .w.quote { background:rgba(231,76,60,.22); border-radius:3px; }
.quote-bar { position:absolute; left:50%; bottom:10px; transform:translateX(-50%); display:flex; gap:8px; align-items:center;
  padding:8px 10px; border-radius:999px; background:var(--surface2); border:1px solid var(--border); box-shadow:0 6px 20px rgba(0,0,0,.35); z-index:5; font-size:13px; color:var(--dim2); white-space:nowrap; }
.quote-bar button { padding:6px 12px; border-radius:999px; border:none; background:var(--accent); color:#fff; font-weight:600; font-size:13px; }
.quote-bar button#btn-quote-copy { background:var(--surface); color:var(--text); border:1px solid var(--border); }

/* Tema del sistema (plan v4, ítem 16): el chrome sigue a prefers-color-scheme;
   el panel RSVP conserva sus variables oscuras (ver .split-rsvp). */
@media (prefers-color-scheme: light) {
  :root { --bg:#f4f4f2; --surface:#ffffff; --surface2:#ececea; --text:#1a1a1a; --dim:#9a9a9a; --dim2:#666; --border:#dcdcd8; }
  .quote-bar { box-shadow:0 6px 20px rgba(0,0,0,.15); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration:.01ms !important; animation-duration:.01ms !important; animation-iteration-count:1 !important; }
}
.install-card { position:relative; padding-right:36px; }
.install-dismiss { position:absolute; top:4px; right:6px; background:none; border:none; color:var(--dim2); font-size:18px; padding:4px 8px; line-height:1; }
