/* READSPEED 1.0.0 — tema "lámpara de lectura": negro cálido, tinta de papel y ámbar */

:root[data-theme="dark"] {
  --bg: #131109;
  --surface: #1d1a12;
  --surface-2: #262217;
  --line: #35301f;
  --ink: #ede6d8;
  --ink-muted: #9d9382;
  --accent: #e8a13c;
  --accent-ink: #131109;
  --chart: #c9821f;
}

:root[data-theme="light"] {
  --bg: #f7f2e7;
  --surface: #fffdf7;
  --surface-2: #efe8d8;
  --line: #ddd3bd;
  --ink: #2a241a;
  --ink-muted: #7d7462;
  --accent: #b5741a;
  --accent-ink: #fffdf7;
  --chart: #b5741a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }

/* ── barra superior ─────────────────────────────── */

.topbar {
  display: flex;
  align-items: baseline;
  gap: 2rem;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1.25rem;
  letter-spacing: .12em;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}
.brand span { color: var(--accent); }
.brand small { margin-left: .6em; font-size: .6em; letter-spacing: 0; color: var(--ink-muted); font-family: ui-monospace, monospace; }

.nav { display: flex; gap: 1.25rem; flex: 1; }
.nav a { color: var(--ink-muted); text-decoration: none; padding-bottom: 2px; }
.nav a:hover { color: var(--ink); }
.nav a.active { color: var(--ink); border-bottom: 2px solid var(--accent); }

.account-area { display: flex; align-items: center; gap: .5rem; }
.account-email {
  color: var(--ink-muted);
  font-size: .8rem;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn, .ghost-btn, .play-btn, .primary-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
}
.icon-btn { width: 2.2rem; height: 2.2rem; }
.icon-btn:hover, .ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.ghost-btn { padding: .4rem .8rem; background: transparent; }
.primary-btn { background: var(--accent); color: var(--accent-ink); border: none; padding: .6rem 1.2rem; font-weight: 600; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── vistas ─────────────────────────────────────── */

main { max-width: 1100px; margin: 0 auto; padding: 2rem; }

.view-head { margin-bottom: 1.5rem; }
.view-head h1 {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-weight: 600;
  font-size: 2rem;
}
.hint { color: var(--ink-muted); font-size: .9rem; }
.hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ── biblioteca ─────────────────────────────────── */

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.5rem;
}

.book-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease;
  display: flex;
  flex-direction: column;
}
.book-card:hover { transform: translateY(-3px); border-color: var(--accent); }

.book-cover {
  aspect-ratio: 2 / 3;
  width: 100%;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}
.book-cover-fallback {
  aspect-ratio: 2 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1.05rem;
  color: var(--ink-muted);
}

.book-meta { padding: .75rem .9rem 1rem; }
.book-title {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: .95rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-author { color: var(--ink-muted); font-size: .8rem; margin-top: .2rem; }

.book-progress { height: 3px; background: var(--surface-2); margin-top: .7rem; border-radius: 2px; overflow: hidden; }
.book-progress i { display: block; height: 100%; background: var(--accent); }
.book-percent { font-size: .75rem; color: var(--ink-muted); margin-top: .3rem; }

.read-btn {
  margin-top: .6rem;
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 6px;
  padding: .4rem 0;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}
.read-btn:hover { filter: brightness(1.1); }

.upload-card {
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 260px;
  color: var(--ink-muted);
  cursor: pointer;
  background: transparent;
  font-size: .9rem;
}
.upload-card:hover { border-color: var(--accent); color: var(--accent); }
.upload-card b { font-size: 2rem; font-weight: 400; }

/* ── entrenamiento ──────────────────────────────── */

.view-training { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; z-index: 10; }

#train-progress { height: 3px; background: var(--surface-2); }
#train-progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

.train-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .8rem 1.5rem;
}
.train-title { flex: 1; text-align: center; color: var(--ink-muted); font-size: .9rem; }
.train-title #train-book-title { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; }
.train-title .mono { margin-left: .8em; }
.train-live { min-width: 7rem; text-align: right; color: var(--ink-muted); font-size: .85rem; }

.train-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 1rem 2rem;
  position: relative;
}

/* marcador focal: la firma visual — dos ticks ámbar que fijan el centro del campo visual */
.focal { width: 2px; height: 22px; background: var(--orp, var(--accent)); opacity: .85; border-radius: 1px; }

/* Punto de Reconocimiento Óptimo: la letra que fija el ojo en modo palabras */
.orp { color: var(--orp, var(--accent)); font-weight: 700; font-style: normal; }

/* Palabra central de cada línea: mismo color que el puntero, sin negrita
   para no alterar el ancho de la línea */
.cword { color: var(--orp, var(--accent)); font-weight: inherit; font-style: normal; }

html.no-focal .focal { display: none; }

.train-block {
  font-family: var(--reading-font, "Iowan Old Style", "Palatino Linotype", Georgia, serif);
  text-align: center;
  line-height: 1.7;
  white-space: pre-wrap;
  max-width: 90vw;
}
.train-block .tline { display: block; width: fit-content; margin: 0 auto; white-space: nowrap; }

.train-finished { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; background: var(--bg); }

.train-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .8rem;
  padding: .8rem 1.5rem .4rem;
  border-top: 1px solid var(--line);
}

.transport { display: flex; align-items: center; justify-content: center; gap: .8rem; }

.ctrl-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.2rem;
  width: 100%;
}

.play-btn {
  width: 3rem; height: 3rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-size: 1.1rem;
}
.play-btn:hover { filter: brightness(1.1); }

.ctrl { display: flex; flex-direction: column; gap: .25rem; font-size: .75rem; color: var(--ink-muted); min-width: 140px; }
.ctrl b { color: var(--ink); font-weight: 600; }
.ctrl input[type="range"] { accent-color: var(--accent); width: 100%; max-width: 180px; }
.ctrl select {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .25rem .4rem;
  font-size: .85rem;
}
.ctrl-color { min-width: 70px; }
.ctrl input[type="color"] {
  width: 100%;
  height: 1.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 2px;
  cursor: pointer;
}
.icon-btn.wide { width: auto; padding: 0 .6rem; font-size: .8rem; font-family: ui-monospace, Menlo, monospace; }

.shortcuts { text-align: center; color: var(--ink-muted); font-size: .72rem; padding: .3rem 0 .8rem; letter-spacing: .04em; }

/* ── tabla de contenido (panel lateral) ─────────── */

.toc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 20;
}

.toc-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 21;
  display: flex;
  flex-direction: column;
  box-shadow: 8px 0 30px rgba(0, 0, 0, .3);
}

.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1.05rem;
}

.toc-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: .5rem 0;
}
.toc-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: var(--ink);
  padding: .55rem 1.2rem;
  font-size: .9rem;
  line-height: 1.35;
  cursor: pointer;
}
.toc-list button:hover { background: var(--surface-2); }
.toc-list button.current {
  border-left-color: var(--orp, var(--accent));
  color: var(--orp, var(--accent));
  font-weight: 600;
}
.toc-list .toc-percent { display: block; font-size: .72rem; color: var(--ink-muted); font-weight: 400; }
.toc-empty { padding: 1rem 1.2rem; color: var(--ink-muted); font-size: .85rem; }

/* ── estadísticas ───────────────────────────────── */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.tile-value { font-size: 1.7rem; font-weight: 600; }
.tile-label { color: var(--ink-muted); font-size: .8rem; }

.chart-card, .sessions-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.2rem 1.4rem;
  margin-bottom: 1.5rem;
}
.chart-card h2, .sessions-card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

.chart-wrap { position: relative; }
#wpm-chart { width: 100%; display: block; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: .35rem .6rem;
  font-size: .78rem;
  white-space: nowrap;
  transform: translate(-50%, -120%);
}

.sessions-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.sessions-table th { text-align: left; color: var(--ink-muted); font-weight: 500; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
.sessions-table td { padding: .45rem .5rem; border-bottom: 1px solid var(--surface-2); }
.sessions-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── panel de ajustes ───────────────────────────── */

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(0, 0, 0, .3);
}

.settings-body { overflow-y: auto; padding: 1rem 1.2rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.settings-body h3 {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-muted);
  font-weight: 600;
  margin-top: .5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.set { display: flex; flex-direction: column; gap: .35rem; font-size: .82rem; color: var(--ink-muted); }
.set b { color: var(--ink); font-weight: 600; }
.set select {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .35rem .5rem;
  font-size: .9rem;
}
.set input[type="range"] { accent-color: var(--accent); }
.set input[type="color"] {
  width: 3rem;
  height: 1.8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  padding: 2px;
  cursor: pointer;
}
.set-row { flex-direction: row; align-items: center; justify-content: space-between; }
.set input[type="checkbox"] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

/* ── pie de página ──────────────────────────────── */

.site-footer {
  text-align: center;
  color: var(--ink-muted);
  font-size: .8rem;
  padding: 1.2rem 1rem 1.5rem;
  border-top: 1px solid var(--line);
  margin-top: 2rem;
}
.site-footer a { color: var(--accent); text-decoration: none; font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }

/* ── aviso de girar pantalla ────────────────────── */

.rotate-hint {
  text-align: center;
  font-size: .8rem;
  color: var(--accent-ink);
  background: var(--accent);
  padding: .45rem .8rem;
}

/* ── modal de email ─────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.6rem;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}
.modal-card h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1.3rem;
}
.modal-card p { color: var(--ink-muted); font-size: .9rem; }
.modal-card input[type="email"], .set input[type="email"] {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .5rem .7rem;
  font-size: .95rem;
  width: 100%;
}
.modal-actions { display: flex; justify-content: flex-end; gap: .7rem; }

.set-inline { display: flex; gap: .5rem; }
.set-inline input { flex: 1; }

/* ── toast ──────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--ink);
  border-radius: 8px;
  padding: .7rem 1.2rem;
  font-size: .9rem;
  z-index: 100;
  max-width: 90vw;
}

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

@media (max-width: 700px) {
  main { padding: 1rem; }
  .topbar { padding: .7rem 1rem; gap: .8rem; flex-wrap: wrap; }
  .brand { font-size: 1.05rem; }
  .account-email { max-width: 110px; }
  .nav { gap: .9rem; }
  .library-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 1rem; }
  .upload-card { min-height: 200px; }

  .train-head { padding: .6rem .8rem; gap: .5rem; }
  .train-live { min-width: 0; }
  .train-title { font-size: .8rem; }
  .train-stage { padding: .5rem 1rem; gap: .8rem; }
  .train-block { max-width: 94vw; }
  .train-controls { padding: .6rem .8rem .2rem; gap: .6rem; }
  .ctrl-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .6rem .9rem; }
  .ctrl { min-width: 0; }
  .ctrl input[type="range"] { max-width: none; }
  .shortcuts { display: none; }

  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
  .tile-value { font-size: 1.4rem; }
  .sessions-card { overflow-x: auto; }
}
