:root {
  --line: 30px;
  --paper: #fbf6e9;
  --paper-edge: #efe6d0;
  --ink: #2b2a33;
  --rule: #cbd8ea;
  --margin: #e4a0a0;
  --hl: #fff176;
  --desk: #3b322d;
  --bar: #2a2320;
  --bar-ink: #f3e9d7;
  --scale: 1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 30%, #4a3f38, var(--desk));
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

/* Barra */
.toolbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 8px 12px;
  background: var(--bar); color: var(--bar-ink);
  font-family: system-ui, sans-serif; font-size: 14px;
}
.toolbar button, .toolbar a, .toolbar input {
  font: inherit; color: var(--bar-ink); background: #3d332e;
  border: 1px solid #5a4c44; border-radius: 6px;
  padding: 6px 10px; text-decoration: none; cursor: pointer;
}
.toolbar button:hover, .toolbar a:hover { background: #4d4139; }
.toolbar .spacer { flex: 1; }
.status { font-size: 12px; opacity: .8; min-width: 9em; }
.status[data-state="error"] { color: #ff9b8a; opacity: 1; }

/* Panel de exportación */
.export-panel {
  position: absolute; top: 100%; right: 12px; z-index: 3;
  display: grid; gap: 10px; width: min(300px, calc(100vw - 24px));
  padding: 14px; margin-top: 4px;
  background: var(--bar); border: 1px solid #5a4c44; border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0,0,0,.4);
}
.export-panel[hidden] { display: none; }
.export-quick { display: flex; flex-wrap: wrap; gap: 6px; }
.export-panel label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.export-error { min-height: 1em; margin: 0; font-size: 12px; color: #ff9b8a; }
.export-panel #export-download { text-align: center; background: #6b2f2a; border-color: #8a4a43; }
.export-panel #export-download.disabled { opacity: .45; cursor: not-allowed; }

/* Libro: hojas de tamaño fijo, escaladas para entrar en pantalla */
.book {
  display: flex; justify-content: center; overflow: hidden;
  padding: 16px 0;
  height: calc(760px * var(--scale) + 32px);
}
.book-inner {
  display: flex; flex-shrink: 0;
  transform: scale(var(--scale)); transform-origin: top center;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,.45));
}
.page {
  position: relative;
  width: 520px; height: 760px;
  padding: 24px 28px 36px 64px;
  background: var(--paper);
}
.page::before { /* margen rojo */
  content: ""; position: absolute; top: 0; bottom: 0; left: 52px;
  width: 2px; background: var(--margin);
}
.book-inner .page:first-child:not(:last-child) {
  background: linear-gradient(to left, var(--paper-edge), var(--paper) 40px);
  border-radius: 6px 0 0 6px;
}
.book-inner .page:last-child:not(:first-child) {
  background: linear-gradient(to right, var(--paper-edge), var(--paper) 40px);
  border-radius: 0 6px 6px 0;
}
.book-inner .page:only-child { border-radius: 6px; }

.page-head {
  display: flex; align-items: center; gap: 8px;
  height: 40px; font-family: system-ui, sans-serif; font-size: 14px; color: #7a6f63;
}
.page-date {
  font: inherit; color: var(--ink); background: transparent;
  border: none; border-bottom: 1px dashed #c8bba6; padding: 2px 0;
}
.page-inherited { font-style: italic; }
.page-num { margin-left: auto; }

.page-body {
  height: calc(var(--line) * 22);
  overflow: hidden;
  font-size: 19px; line-height: var(--line);
  outline: none; white-space: pre-wrap; overflow-wrap: anywhere;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0, transparent calc(var(--line) - 1px),
    var(--rule) calc(var(--line) - 1px), var(--rule) var(--line));
}

mark {
  color: inherit;
  background: linear-gradient(transparent 12%, var(--hl) 12%, var(--hl) 88%, transparent 88%);
}

/* Animación de vuelta de hoja */
.turn-next .page { animation: turn-next .35s ease-out; transform-origin: left center; }
.turn-prev .page { animation: turn-prev .35s ease-out; transform-origin: right center; }
@keyframes turn-next { from { transform: perspective(1400px) rotateY(-28deg); opacity: .3; } }
@keyframes turn-prev { from { transform: perspective(1400px) rotateY(28deg); opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .turn-next .page, .turn-prev .page { animation: none; } }

/* Login */
.login-body { display: grid; place-items: center; padding: 16px; }
.cover {
  width: min(340px, 100%); padding: 40px 28px;
  display: grid; gap: 12px;
  background: linear-gradient(135deg, #6b2f2a, #4a1f1c); color: #f6e7c8;
  border-radius: 4px 12px 12px 4px; border-left: 14px solid #3a1714;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
  font-family: system-ui, sans-serif;
}
.cover h1 { margin: 0 0 12px; text-align: center; font-family: Georgia, serif; font-weight: normal; font-size: 32px; }
.cover input, .cover button { font: inherit; padding: 10px; border-radius: 6px; border: 1px solid #a0716a; }
.cover button { background: #f6e7c8; color: #4a1f1c; cursor: pointer; }
.login-error { min-height: 1.2em; margin: 0; color: #ffc4b8; }

.page.measuring { position: fixed; left: -10000px; top: 0; visibility: hidden; pointer-events: none; }
