/* ============================================================
   Anecdotario Taurino — Diseño editorial
   Paleta: papel envejecido, tinta café, vino discreto, latón viejo.
   Tipografía: serifs editoriales del sistema (sin dependencias
   externas, para garantizar funcionamiento sin conexión).
   ============================================================ */

:root {
  --paper: #F5EFE1;
  --paper-panel: #FBF7EC;
  --ink: #2B2118;
  --ink-soft: #4A3826;
  --wine: #6B1F1F;
  --wine-soft: #8C3A3A;
  --brass: #C9A063;
  --line: #D8CBA9;

  --font-display: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', serif;
  --font-body: var(--font-display);

  --reading-size: 1.125rem;
  --reading-line-height: 1.6;
  --reading-width: 640px;
  --reading-margin: 24px;

  --bg: var(--paper);
  --surface: var(--paper-panel);
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --accent: var(--wine);
  --border: var(--line);
}

/* ---------- Temas de lectura ---------- */
[data-theme="claro"] {
  --bg: #FFFFFF;
  --surface: #F7F5F0;
  --text: #211A12;
  --text-soft: #55483A;
  --border: #E3DCCB;
}

[data-theme="sepia"] {
  --bg: #F1E4C6;
  --surface: #F8EFDA;
  --text: #4A3826;
  --text-soft: #6B5842;
  --border: #E0CFA6;
}

[data-theme="oscuro"] {
  --bg: #1B1712;
  --surface: #241F18;
  --text: #E8DCC4;
  --text-soft: #C4B393;
  --border: #3A322760;
  --accent: #C9847E;
}

[data-theme="taurino"] {
  --bg: #EFE3C4;
  --surface: #F7EFDA;
  --text: #2E2013;
  --text-soft: #5A4326;
  --border: #C9A063;
  --accent: #6B1F1F;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

img { max-width: 100%; display: block; }

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

/* ---------- Portada ---------- */
.screen-cover {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  background:
    radial-gradient(ellipse at top, rgba(201,160,99,0.14), transparent 60%),
    var(--bg);
}

.cover-ornament {
  width: 46px;
  height: 2px;
  background: var(--brass);
  margin-bottom: 28px;
}

.cover-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 3rem);
  letter-spacing: 0.01em;
  margin: 0 0 8px;
  line-height: 1.15;
}

.cover-subtitle {
  font-size: 1.15rem;
  font-style: italic;
  color: var(--text-soft);
  margin: 0 0 26px;
}

.cover-author {
  font-size: 1rem;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  margin-bottom: 40px;
}

.cover-author::before { content: '— '; }

.btn-primary {
  background: var(--wine);
  color: var(--paper);
  border: none;
  padding: 14px 34px;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.btn-primary:hover { background: #521818; }

.cover-progress {
  margin-top: 26px;
  width: 100%;
  max-width: 320px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin: 10px 0 6px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--brass);
}

.cover-continue-label {
  font-size: 0.85rem;
  color: var(--text-soft);
  font-style: italic;
}

/* ---------- Navegación principal ---------- */
.app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
}

.app-nav button {
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 0.66rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  flex: 1;
}

.app-nav button .icon { font-size: 1.15rem; }
.app-nav button[aria-current="true"] { color: var(--accent); }

/* ---------- Encabezado de sección ---------- */
.section-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-header h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: normal;
  letter-spacing: 0.02em;
}

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.2rem;
  padding: 0 4px;
}

.screen {
  min-height: 100vh;
  padding-bottom: 84px;
}

/* ---------- Lector ---------- */
.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

.reader-toolbar button {
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 1.1rem;
  padding: 6px 8px;
}

.reader-chapter-title {
  font-size: 0.85rem;
  color: var(--text-soft);
  font-style: italic;
}

.reader-content {
  max-width: var(--reading-width);
  margin: 0 auto;
  padding: 30px var(--reading-margin) 60px;
  font-size: var(--reading-size);
  line-height: var(--reading-line-height);
}

.reader-content h2.chapter-title {
  font-family: var(--font-display);
  font-size: 1.7em;
  text-align: center;
  margin: 0 0 6px;
}

.chapter-ornament {
  width: 40px;
  height: 1px;
  background: var(--brass);
  margin: 0 auto 34px;
}

.reader-content p { margin: 0 0 1.1em; }

.reader-content blockquote {
  margin: 1.6em 0;
  padding: 0.4em 0 0.4em 1.1em;
  border-left: 2px solid var(--brass);
  font-style: italic;
  color: var(--text-soft);
}

.reader-content figure { margin: 1.8em 0; }
.reader-content figcaption {
  font-size: 0.82em;
  color: var(--text-soft);
  text-align: center;
  margin-top: 0.5em;
  font-style: italic;
}

.reader-content hr {
  border: none;
  text-align: center;
  margin: 2.4em 0;
}
.reader-content hr::after { content: '❧'; color: var(--brass); font-size: 1.3rem; }

/* Anchos de lectura */
[data-width="estrecho"] .reader-content { --reading-width: 480px; }
[data-width="normal"] .reader-content { --reading-width: 640px; }
[data-width="amplio"] .reader-content { --reading-width: 780px; }

mark.highlight-ambar { background: #E8C766; color: inherit; }
mark.highlight-rosa { background: #E4B7C0; color: inherit; }
mark.highlight-verde { background: #B7CBA0; color: inherit; }
mark.highlight-azul { background: #ACC3D6; color: inherit; }

.selection-popover {
  position: absolute;
  display: flex;
  gap: 4px;
  background: var(--ink);
  border-radius: 6px;
  padding: 6px;
  z-index: 60;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

.selection-popover button {
  background: none;
  border: none;
  color: var(--paper);
  font-size: 0.95rem;
  padding: 4px 8px;
}

/* ---------- Modo enfoque ---------- */
body.focus-mode .app-nav,
body.focus-mode .reader-toolbar,
body.focus-mode .section-header { display: none !important; }
body.focus-mode .reader-content { padding-top: 40px; }
.focus-exit {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 70;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  color: var(--text-soft);
  display: none;
}
body.focus-mode .focus-exit { display: block; }

/* ---------- Listas (contenido, marcadores, notas, citas) ---------- */
.list-item {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  color: var(--text);
}

.list-item .item-title { font-size: 1rem; }
.list-item .item-meta { font-size: 0.8rem; color: var(--text-soft); }
.list-item .item-excerpt {
  font-size: 0.88rem;
  color: var(--text-soft);
  font-style: italic;
  margin-top: 2px;
}

.list-item .item-progress {
  font-size: 0.78rem;
  color: var(--brass);
}

.empty-state {
  padding: 60px 24px;
  text-align: center;
  color: var(--text-soft);
  font-style: italic;
}

/* ---------- Configuración de lectura ---------- */
.settings-group {
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.settings-group h3 {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--text-soft);
  font-weight: normal;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stepper button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  border-radius: 4px;
}

.option-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.option-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  font-size: 0.85rem;
  border-radius: 20px;
}

.option-chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}

.theme-swatch { display: flex; gap: 10px; }
.theme-swatch button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--border);
}
.theme-swatch button[aria-pressed="true"] { border-color: var(--accent); }
.swatch-claro { background: #FFFFFF; }
.swatch-sepia { background: #F1E4C6; }
.swatch-oscuro { background: #1B1712; }
.swatch-taurino { background: linear-gradient(135deg, #EFE3C4 50%, #6B1F1F 50%); }

/* ---------- Búsqueda ---------- */
.search-box {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.search-box input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.search-result mark { background: var(--brass); color: var(--ink); }

/* ---------- Tarjeta de cita compartible ---------- */
.quote-card {
  aspect-ratio: 4 / 5;
  max-width: 420px;
  margin: 0 auto;
  padding: 40px 32px;
  background: linear-gradient(160deg, #EFE3C4, #E4D3A6);
  border: 1px solid var(--brass);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  color: #2E2013;
  font-family: var(--font-display);
}

.quote-card .quote-text {
  font-size: 1.3rem;
  font-style: italic;
  line-height: 1.5;
  margin-bottom: 24px;
}

.quote-card .quote-attribution {
  font-size: 0.85rem;
  letter-spacing: 0.03em;
}

/* ---------- Galería ---------- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 14px;
}

.gallery-grid figure {
  margin: 0;
  cursor: pointer;
}

.gallery-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* ---------- Offline banner ---------- */
.offline-banner {
  background: var(--brass);
  color: var(--ink);
  text-align: center;
  font-size: 0.8rem;
  padding: 6px;
}

/* Utilidad de accesibilidad: foco visible */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* ---------- Modales: nota, tarjeta de cita ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 8, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 80;
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}

.modal-card {
  background: var(--paper-panel, var(--surface));
  color: var(--ink, var(--text));
  width: 100%;
  max-width: 480px;
  padding: 22px;
  border-top: 3px solid var(--brass);
}

.modal-card h3 { margin-top: 0; font-size: 1rem; }

.modal-quoted {
  font-style: italic;
  color: var(--ink-soft, var(--text-soft));
  border-left: 2px solid var(--brass);
  padding-left: 12px;
  margin: 10px 0 16px;
}

.modal-card textarea {
  width: 100%;
  min-height: 90px;
  padding: 10px;
  border: 1px solid var(--line, var(--border));
  font-family: inherit;
  font-size: 1rem;
  background: #fff;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.modal-actions button {
  border: none;
  padding: 9px 18px;
  background: var(--wine, var(--accent));
  color: var(--paper, var(--bg));
}

.modal-actions .btn-secondary {
  background: none;
  color: var(--ink-soft, var(--text-soft));
  border: 1px solid var(--line, var(--border));
}

.quote-card-modal .modal-card { background: transparent; border: none; padding: 20px; max-width: 460px; }

/* ---------- Franjas de estado (offline / instalar / toast) ---------- */
#install-banner, #offline-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

#install-banner {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#install-banner button {
  border: none;
  background: var(--wine, var(--accent));
  color: var(--paper, var(--bg));
  padding: 6px 12px;
  font-size: 0.8rem;
}

#install-dismiss { background: none !important; color: var(--text-soft) !important; }

.toast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink, #2B2118);
  color: var(--paper, #F5EFE1);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.85rem;
  z-index: 90;
}
