:root {
  --ink: #182433;
  --ink-soft: #4c5864;
  --paper: #f8f1e4;
  --paper-deep: #eee1cc;
  --gold: #b98b4a;
  --rose: #c96f72;
  --lavender: #8077a8;
  --shadow: rgba(24, 36, 51, .22);
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: #d8c8b0;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}

.story-app {
  min-height: 100svh;
  overflow: hidden;
  position: relative;
  isolation: isolate;
  background:
    linear-gradient(135deg, rgba(255,255,255,.22), transparent 40%),
    #d8c8b0;
}

.cover-screen,
.reader {
  min-height: 100svh;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.cover-screen {
  display: grid;
  place-items: center;
  transition: opacity .7s ease, visibility .7s ease;
}

.cover-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.cover-book {
  width: min(82vw, 390px);
  aspect-ratio: .72;
  position: relative;
  color: #f8ead0;
  border-radius: 8px 16px 16px 8px;
  background: linear-gradient(105deg, #172637 0%, #253c50 55%, #13202d 100%);
  box-shadow: 22px 28px 42px rgba(45, 33, 23, .28), inset -8px 0 0 rgba(0,0,0,.14);
  transform: perspective(1100px) rotateY(-7deg) rotateZ(-1deg);
  transition: transform .8s cubic-bezier(.2,.8,.2,1), opacity .6s ease;
}

.cover-book:hover { transform: perspective(1100px) rotateY(-13deg) rotateZ(-1deg) translateY(-4px); }

.cover-book::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(231, 192, 125, .58);
  border-radius: 3px 10px 10px 3px;
}
.cover-book__edge {
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: -9px;
  width: 14px;
  border-radius: 5px 0 0 5px;
  background: repeating-linear-gradient(to bottom, #b98b4a 0 2px, #7f5a31 2px 4px);
}

.cover-book__content {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 30px;
  text-align: center;
  position: relative;
}

.eyebrow,
.reader-kicker {
  margin: 0;
  color: var(--gold);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.cover-book h1 {
  max-width: 290px;
  margin: 20px 0 18px;
  color: #f8ead0;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 10vw, 4.4rem);
  font-weight: 500;
  line-height: .9;
  text-wrap: balance;
}

.cover-subtitle {
  max-width: 240px;
  margin: 0;
  color: rgba(248, 234, 208, .78);
  font-family: var(--serif);
  font-size: 1.15rem;
  font-style: italic;
}

.cover-open,
.secondary-button {
  border: 1px solid rgba(231, 192, 125, .7);
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}

.cover-open {
  margin-top: 34px;
  padding: 12px 20px;
  color: #f8ead0;
  background: transparent;
  font-size: .78rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.cover-open:hover,
.cover-open:active {
  color: var(--ink);
  background: #f8ead0;
  transform: translateY(-2px);
}

.reader {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: auto;
  opacity: 1;
  transition: opacity .5s ease;
}

.reader[hidden],
.flower-message[hidden] { display: none; }

.reader-header,
.reader-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.reader-header { min-height: 36px; }

.text-button,
.icon-button {
  border: 0;
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
}

.text-button {
  padding: 8px 0;
  font-size: .75rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.text-button:hover { color: var(--rose); }

.book-stage {
  flex: 1;
  display: grid;
  place-items: center;
  position: relative;
  min-height: 0;
  padding: 22px 0;
}

.story-page {
  width: min(88vw, 570px);
  min-height: min(73svh, 620px);
  max-height: 72svh;
  position: relative;
  overflow: hidden;
  padding: clamp(28px, 7vw, 64px) clamp(24px, 8vw, 72px);
  border-radius: 3px 12px 12px 3px;
  background:
    linear-gradient(90deg, rgba(95, 63, 28, .09), transparent 13%),
    repeating-linear-gradient(to bottom, transparent 0 32px, rgba(185, 139, 74, .11) 33px 34px),
    var(--paper);
  box-shadow: 18px 24px 36px var(--shadow), inset 9px 0 12px rgba(80, 48, 20, .08);
  transform-origin: left center;
}

.story-page.is-turning { animation: turn-page .55s cubic-bezier(.4,0,.2,1); }

@keyframes turn-page {
  0% { transform: perspective(1200px) rotateY(0); }
  45% { transform: perspective(1200px) rotateY(-78deg); box-shadow: 2px 20px 20px var(--shadow); }
  100% { transform: perspective(1200px) rotateY(0); }
}

.page-ruling {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 26px;
  width: 1px;
  background: rgba(201, 111, 114, .24);
}

.page-content { height: 100%; position: relative; z-index: 1; }

.page-content h2 {
  max-width: 450px;
  margin: 10px 0 18px;
  font-family: var(--serif);
  font-size: clamp(2.35rem, 9vw, 4.6rem);
  font-weight: 500;
  line-height: .95;
  text-wrap: balance;
}

.page-content p {
  max-width: 455px;
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: clamp(1.1rem, 3.8vw, 1.35rem);
  line-height: 1.45;
}

.page-content .chapter-lead {
  color: var(--rose);
  font-family: var(--sans);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.page-photo {
  width: 100%;
  max-width: 430px;
  aspect-ratio: 1.45;
  display: block;
  margin: 26px auto 20px;
  object-fit: cover;
  border: 7px solid #fffaf0;
  box-shadow: 0 12px 20px rgba(67, 45, 28, .16);
  transform: rotate(-1.5deg);
}

.page-photo.image-missing {
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  background: linear-gradient(135deg, #ddcbb8, #f2e8d8);
  font-family: var(--serif);
  font-size: 1rem;
}

.page-photo.image-missing::after { content: "Reemplaza esta foto"; }

.page-number {
  position: absolute;
  right: 28px;
  bottom: 20px;
  color: var(--gold);
  font-family: var(--serif);
  font-size: 1.1rem;
  font-style: italic;
}

.edge-control {
  width: 44px;
  height: 64px;
  position: absolute;
  top: 50%;
  z-index: 2;
  border: 0;
  color: var(--ink-soft);
  background: rgba(248, 241, 228, .45);
  cursor: pointer;
  font-family: var(--serif);
  font-size: 3rem;
  line-height: 1;
  transform: translateY(-50%);
  transition: color .2s ease, background .2s ease;
}

.edge-control:hover { color: var(--rose); background: rgba(248, 241, 228, .9); }
.edge-control--left { left: 0; border-radius: 0 10px 10px 0; }
.edge-control--right { right: 0; border-radius: 10px 0 0 10px; }
.edge-control:disabled, .icon-button:disabled { opacity: .25; cursor: not-allowed; }

.reader-footer { justify-content: center; }
.icon-button { padding: 10px 16px; font-size: 1.3rem; }

.page-dots { display: flex; align-items: center; gap: 8px; }

.page-dot {
  width: 7px;
  height: 7px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(76, 88, 100, .35);
  cursor: pointer;
  transition: transform .2s ease, background .2s ease;
}

.page-dot[aria-selected="true"] { background: var(--rose); transform: scale(1.55); }

.swipe-hint {
  min-height: 18px;
  margin: 4px 0 0;
  color: rgba(76, 88, 100, .72);
  font-size: .7rem;
  text-align: center;
}

.flower-canvas {
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.flower-message {
  width: min(86vw, 440px);
  position: fixed;
  left: 50%;
  bottom: max(34px, env(safe-area-inset-bottom));
  z-index: 6;
  padding: 22px 24px;
  border: 1px solid rgba(185, 139, 74, .38);
  border-radius: 8px;
  background: rgba(248, 241, 228, .9);
  box-shadow: 0 20px 50px rgba(45, 33, 23, .2);
  text-align: center;
  transform: translateX(-50%);
  animation: message-in .8s ease both;
}

.flower-message h2 {
  margin: 8px 0 18px;
  font-family: var(--serif);
  font-size: clamp(2rem, 8vw, 3.4rem);
  font-weight: 500;
}

.secondary-button { padding: 10px 17px; color: var(--ink); background: transparent; }
.secondary-button:hover { color: #fff; background: var(--rose); }

@keyframes message-in { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (min-width: 700px) {
  .cover-screen, .reader { padding-inline: 44px; }
  .story-page { min-height: min(70svh, 650px); }
  .edge-control--left { left: -48px; background: transparent; }
  .edge-control--right { right: -48px; background: transparent; }
}

@media (max-height: 680px) and (orientation: landscape) {
  .story-page { min-height: 70svh; max-height: 70svh; padding-block: 24px; }
  .page-content h2 { font-size: 2.2rem; }
  .page-photo { max-height: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* Editor de contenido en /subir/lalo */
body.editor-mode {
  min-height: 100svh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,.45), transparent 36rem),
    #d8c8b0;
}

.editor-mode .story-app {
  min-height: 100svh;
  overflow: visible;
  background: transparent;
}

.editor-shell {
  width: min(100% - 28px, 1080px);
  margin: 0 auto;
  padding: max(26px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom));
}

.editor-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 0 24px;
}

.editor-header h1 {
  margin: 8px 0 8px;
  font-family: var(--serif);
  font-size: clamp(2.4rem, 7vw, 4.8rem);
  font-weight: 500;
  line-height: .95;
}

.editor-intro {
  max-width: 580px;
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.4;
}

.editor-link {
  flex: 0 0 auto;
  padding: 10px 15px;
  border: 1px solid rgba(185,139,74,.6);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(248,241,228,.65);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-decoration: none;
  text-transform: uppercase;
}

.editor-link:hover { background: var(--paper); }

.editor-panel {
  padding: clamp(16px, 3vw, 30px);
  border: 1px solid rgba(185,139,74,.38);
  border-radius: 14px;
  background: rgba(248,241,228,.84);
  box-shadow: 0 20px 45px rgba(45,33,23,.15);
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.editor-action {
  min-height: 44px;
  padding: 10px 15px;
  border: 1px solid rgba(76,88,100,.24);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255,255,255,.52);
  cursor: pointer;
  font-size: .86rem;
  font-weight: 700;
  transition: transform .2s ease, background .2s ease, border-color .2s ease;
}

.editor-action:hover { border-color: var(--gold); background: #fffaf0; transform: translateY(-1px); }
.editor-action--primary { border-color: var(--ink); color: #fffaf0; background: var(--ink); }
.editor-action--primary:hover { color: var(--ink); background: transparent; }
.editor-file-action { display: inline-flex; align-items: center; position: relative; }
.editor-file-action input { width: 1px; height: 1px; position: absolute; overflow: hidden; clip: rect(0 0 0 0); }
.editor-status { min-height: 22px; margin: 14px 0 18px; color: var(--ink-soft); font-size: .88rem; }
.editor-status.is-error { color: #a33846; font-weight: 700; }

.editor-pages { display: grid; gap: 18px; }
.editor-page-card {
  padding: clamp(14px, 2vw, 22px);
  border: 1px solid rgba(185,139,74,.3);
  border-radius: 11px;
  background: rgba(255,250,240,.75);
}

.editor-page-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.editor-page-number { color: var(--rose); font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.editor-remove { padding: 7px 10px; border: 1px solid rgba(163,56,70,.4); border-radius: 7px; color: #a33846; background: transparent; cursor: pointer; font-size: .78rem; }
.editor-remove:hover { color: #fff; background: #a33846; }
.editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.editor-grid label { display: grid; gap: 7px; color: var(--ink-soft); font-size: .78rem; font-weight: 800; letter-spacing: .04em; }
.editor-wide { grid-column: 1 / -1; }
.editor-grid input, .editor-grid textarea {
  width: 100%;
  border: 1px solid rgba(76,88,100,.28);
  border-radius: 7px;
  padding: 11px 12px;
  color: var(--ink);
  background: rgba(255,255,255,.76);
  font: 500 .98rem/1.35 var(--sans);
  letter-spacing: normal;
}
.editor-grid textarea { resize: vertical; min-height: 112px; }
.editor-grid input:focus, .editor-grid textarea:focus { outline: 3px solid rgba(185,139,74,.3); border-color: var(--gold); }
.editor-upload small { color: var(--ink-soft); font-size: .73rem; font-weight: 500; letter-spacing: normal; }
.editor-photo-preview-wrap { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.editor-photo-preview { width: 120px; height: 86px; display: block; object-fit: cover; border: 5px solid #fffaf0; box-shadow: 0 7px 15px rgba(67,45,28,.14); transform: rotate(-1deg); }
.editor-photo-preview[hidden] { display: none; }
.editor-closing { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: .85rem; }
.editor-closing input { width: 18px; height: 18px; accent-color: var(--rose); }

@media (max-width: 620px) {
  .editor-shell { width: min(100% - 20px, 1080px); padding-top: max(16px, env(safe-area-inset-top)); }
  .editor-header { align-items: flex-start; flex-direction: column; gap: 16px; }
  .editor-header h1 { font-size: clamp(2.45rem, 13vw, 4rem); }
  .editor-toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor-action { width: 100%; padding-inline: 8px; font-size: .78rem; text-align: center; }
  .editor-file-action { justify-content: center; }
  .editor-grid { grid-template-columns: 1fr; }
  .editor-wide { grid-column: auto; }
  .editor-photo-preview-wrap { align-items: flex-start; flex-direction: column; }
  .editor-photo-preview { width: min(100%, 240px); height: 150px; }
}
