:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #22201c;
  --muted: #6d6860;
  --border: #e6e1d8;
  --accent: #8a3b5c;
  --accent-text: #ffffff;
  --accent-soft: #f5e9ee;
  --ok: #2f6b3f;
  --warn: #8a6100;
  --danger: #b0302f;
  --reader-size: 19px;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

:root[data-theme='sepia'] {
  --bg: #f4ecd8;
  --surface: #faf4e6;
  --text: #3b2f22;
  --muted: #7a6a55;
  --border: #e1d4b8;
  --accent: #8a4b2a;
  --accent-soft: #eddcc4;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='sepia']) {
    --bg: #17161a;
    --surface: #211f24;
    --text: #e8e4dd;
    --muted: #a39d94;
    --border: #35323a;
    --accent: #e08aad;
    --accent-text: #1a1418;
    --accent-soft: #3a2630;
    --ok: #7cc48f;
    --warn: #e0b44f;
    --danger: #f07c7a;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #17161a;
  --surface: #211f24;
  --text: #e8e4dd;
  --muted: #a39d94;
  --border: #35323a;
  --accent: #e08aad;
  --accent-text: #1a1418;
  --accent-soft: #3a2630;
  --ok: #7cc48f;
  --warn: #e0b44f;
  --danger: #f07c7a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }
h1 { font-size: clamp(1.8rem, 5vw, 2.5rem); margin: 0.3em 0; }
h2 { font-size: 1.4rem; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.admin .wrap { max-width: 920px; }

/* Cabecera */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-row { display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 12px; }
.brand { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; color: var(--text); text-decoration: none; }
.header-nav { display: flex; align-items: center; gap: 12px; }
.header-nav a { text-decoration: none; }

.site-footer { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 0.85rem; padding-top: 48px; padding-bottom: 32px; }
.quiet { color: var(--muted); }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.6em 1.1em; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text); font: 600 0.95rem var(--sans);
  text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { padding: 0.35em 0.75em; font-size: 0.85rem; }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; min-width: 36px; height: 36px; font-size: 0.95rem; cursor: pointer;
}
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }

/* Portada */
.hero { text-align: center; padding: 48px 0 16px; }
.byline { color: var(--muted); font-style: italic; margin: 0; }
.intro { text-align: center; color: var(--muted); max-width: 580px; margin: 0 auto; }
.section-title { margin-top: 40px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.book-grid { display: grid; gap: 16px; }
.book-card {
  display: block; padding: 20px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); text-decoration: none; transition: border-color 0.15s;
}
.book-card:hover { border-color: var(--accent); }
.book-card h2 { margin: 0 0 6px; }
.synopsis { margin: 8px 0 0; color: var(--muted); }
.meta { color: var(--muted); font-size: 0.88rem; margin: 4px 0; }
.eyebrow { font-size: 0.9rem; color: var(--muted); margin: 24px 0 0; }
.eyebrow a { text-decoration: none; }
.empty { color: var(--muted); font-style: italic; list-style: none; }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); margin-right: 4px;
}
.badge-completado { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge-pausa, .badge-draft { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

/* Libro */
.prose p { margin: 0 0 0.8em; }
.synopsis-full { font-family: var(--serif); font-size: 1.08rem; }
.chapter-list { list-style: none; padding: 0; margin: 0; }
.chapter-list a {
  display: grid; grid-template-columns: 2.5em 1fr auto; gap: 12px; align-items: baseline;
  padding: 12px 4px; border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none;
}
.chapter-list a:hover .ch-title { color: var(--accent); }
.ch-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.ch-date { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }

/* Lector */
.chapter h1 { text-align: center; margin-top: 8px; }
.chapter .eyebrow { text-align: center; }
.reader-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  border-block: 1px solid var(--border); padding: 8px 0; margin: 20px 0 28px;
}
.font-ctrl { display: flex; gap: 6px; }
.reader-text {
  font-family: var(--serif); font-size: var(--reader-size); line-height: 1.75;
  overflow-wrap: break-word;
}
.reader-text p { margin: 0 0 1em; }
hr.scene { border: 0; text-align: center; margin: 2em 0; }
hr.scene::after { content: '✦  ✦  ✦'; color: var(--muted); letter-spacing: 0.3em; }
.chapter-nav { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; margin: 40px 0; }
.chapter-nav [rel='next'] { justify-self: end; }
.chapter-nav [rel='prev'] { justify-self: start; }

/* Comentarios */
.comment-list { list-style: none; padding: 0; }
.comment { border-bottom: 1px solid var(--border); padding: 12px 0; }
.comment-head { margin: 0 0 4px; }
.comment-head span { color: var(--muted); font-size: 0.82rem; margin-left: 6px; }
.comment-body { overflow-wrap: break-word; }
.comment-form { display: grid; gap: 12px; margin-top: 16px; }
.hp { position: absolute; left: -9999px; }

/* Formularios */
label { display: grid; gap: 4px; font-weight: 600; font-size: 0.92rem; }
input, textarea, select {
  font: 400 1rem var(--sans); color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.55em 0.7em; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.stack { display: grid; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }
.row > label { flex: 1 1 200px; }
.row > .narrow { flex: 0 0 110px; }
.row > .grow { flex: 1 1 260px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; }
.editor { font-family: var(--serif); font-size: 1.05rem; line-height: 1.6; min-height: 50vh; resize: vertical; }
.editor-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-btn { display: inline-flex; font-weight: 600; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }
code, kbd { font-size: 0.85em; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.notice { padding: 10px 14px; border-radius: 8px; border: 1px solid; }
.notice.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.notice.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.notice.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

/* Panel */
.auth-box { max-width: 400px; margin: 48px auto; }
.admin-nav {
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.admin-nav a { text-decoration: none; font-weight: 600; }
.admin-nav form { margin-left: auto; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.admin-list { list-style: none; padding: 0; }
.admin-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.row-title { font-weight: 600; font-size: 1.05rem; text-decoration: none; color: var(--text); }
.row-title:hover { color: var(--accent); }
.row-actions { display: flex; gap: 8px; }
.comment-admin > div { flex: 1 1 400px; }
.danger-zone { margin-top: 40px; border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.danger-zone summary { cursor: pointer; color: var(--danger); font-weight: 600; }

@media (max-width: 520px) {
  .chapter-list a { grid-template-columns: 2em 1fr; }
  .ch-date { display: none; }
  .chapter-nav .btn { padding-inline: 0.7em; }
}

/* Importador */
.dropzone {
  display: grid; place-items: center; gap: 4px; text-align: center; cursor: pointer;
  padding: 36px 16px; border: 2px dashed var(--border); border-radius: 12px; background: var(--surface);
  font-weight: 400;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { color: var(--accent); font-size: 1.1rem; }
.import h2 { font-size: 1.15rem; margin: 8px 0; }
.import-summary { font-size: 1.05rem; }
.import-list { max-height: 360px; overflow: auto; padding-left: 0; list-style: none; border: 1px solid var(--border); border-radius: 8px; }
.import-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 12px; border-bottom: 1px solid var(--border); }
.import-list li:last-child { border-bottom: 0; }
.import details summary { cursor: pointer; color: var(--accent); }
.indent { margin-left: 26px; }
.import-progress progress { width: 100%; height: 14px; accent-color: var(--accent); }
