:root {
  color-scheme: dark;
  --gold: #d7ad61;
  --gold-soft: #9c7740;
  --ink: #070504;
  --paper: #17110c;
}

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

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(113, 67, 26, .24), transparent 38rem),
    linear-gradient(135deg, #030201, #0b0704 48%, #030201);
  color: #ead9b2;
  font-family: Georgia, "Times New Roman", serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(90deg, transparent 0 13rem, rgba(223, 189, 114, .018) 13rem 13.05rem);
}

.reader-header {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 10rem minmax(0, 1fr) 10rem;
  align-items: center;
  gap: 1rem;
  width: min(92rem, 96vw);
  margin: 0 auto;
  padding: 1.15rem 0 .9rem;
  border-bottom: 1px solid rgba(215, 173, 97, .28);
}

.reader-home {
  justify-self: start;
  align-self: center;
  padding: .65rem .75rem;
  border: 1px solid rgba(215, 173, 97, .55);
  color: #e4c787;
  font-size: .82rem;
  letter-spacing: .04em;
  text-decoration: none;
}
.reader-home:hover, .reader-home:focus-visible { border-color: #f1dfb9; color: #fff1ce; outline: 2px solid #f1dfb9; outline-offset: 2px; }

.reader-heading { min-width: 0; text-align: center; }
.reader-heading p { margin: 0 0 .2rem; color: #917445; font-size: .62rem; letter-spacing: .2em; text-transform: uppercase; }
.reader-heading h1 { margin: 0; overflow: hidden; color: #f1dfb9; font-size: clamp(1.25rem, 2.3vw, 2.2rem); font-weight: 400; line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }

.reader-shell {
  position: relative;
  z-index: 2;
  width: min(92rem, 96vw);
  margin: 0 auto;
  padding: .65rem 0 1rem;
}

.reader-ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  height: 1.2rem;
  color: #a57b3e;
  font-size: .7rem;
}

.reader-ornament i { width: 3.5rem; height: 1px; background: linear-gradient(90deg, transparent, rgba(215,173,97,.55)); }
.reader-ornament i:last-child { transform: scaleX(-1); }

.reader-page {
  position: relative;
  height: calc(100vh - 9rem);
  min-height: 34rem;
  overflow: hidden;
  border: 1px solid rgba(188, 139, 68, .52);
  background: #f1eadb;
  box-shadow: inset 0 0 0 4px #130d08, 0 1.5rem 4rem rgba(0,0,0,.62), 0 0 2rem rgba(124,76,27,.12);
}

.reader-page::before,
.reader-page::after {
  content: "";
  position: absolute;
  z-index: 4;
  width: 2.2rem;
  height: 2.2rem;
  pointer-events: none;
}

.reader-page::before { top: .55rem; left: .55rem; border-top: 2px solid var(--gold); border-left: 2px solid var(--gold); }
.reader-page::after { right: .55rem; bottom: .55rem; border-right: 2px solid var(--gold); border-bottom: 2px solid var(--gold); }

.reader-scroll {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  background:
    linear-gradient(90deg, rgba(102, 70, 39, .05), transparent 12%, transparent 88%, rgba(102, 70, 39, .05)),
    #f1eadb;
  color: #251b13;
  scrollbar-color: #9c7740 #dfd4bf;
  scrollbar-width: thin;
}

.reader-scroll:focus { outline: none; }

.story-content {
  width: min(48rem, calc(100% - 3rem));
  margin: 0 auto;
  padding: clamp(3rem, 6vw, 5.5rem) 0 clamp(5rem, 9vw, 8rem);
  font-size: clamp(1.05rem, 1.15vw, 1.18rem);
  line-height: 1.88;
  text-rendering: optimizeLegibility;
}

.story-content p {
  margin: 0 0 1.35em;
  text-align: justify;
  text-wrap: pretty;
  hyphens: auto;
}

.story-opening .drop-cap {
  float: left;
  margin: .1em .12em 0 0;
  color: #7e5529;
  font-size: 4.25em;
  line-height: .74;
}

.reader-poem {
  --gold: #a9a5c7;
  --gold-soft: #746b9a;
  background: radial-gradient(circle at 50% -10%, rgba(87, 73, 119, .28), transparent 38rem), linear-gradient(135deg, #050409, #0b0812 48%, #050409);
}
.reader-poem .reader-page { border-color: rgba(142, 130, 174, .6); }
.reader-poem .reader-scroll { background: linear-gradient(90deg, rgba(85, 73, 126, .05), transparent 12%, transparent 88%, rgba(85, 73, 126, .05)), #f0ecf2; scrollbar-color: #82749d #dad4e1; }
.reader-poem .reader-heading p, .reader-poem .reader-footer { color: #aa9ec0; }
.reader-poem .reader-heading h1 { color: #e8def2; }
.reader-poem .story-opening .drop-cap { color: #655582; }
.reader-poem .story-content p.poem-stanza { white-space: pre-line; text-align: left; hyphens: none; margin-bottom: 1.8em; }

.story-separator {
  margin: 2.8rem 0;
  color: #9c7740;
  font-size: .72rem;
  letter-spacing: .7em;
  text-align: center;
}

.story-subheading,
.story-fin {
  margin: 1rem 0 2.25rem;
  color: #6d4c2d;
  font-size: .82rem;
  font-weight: 400;
  letter-spacing: .18em;
  text-align: center;
  text-transform: uppercase;
}

.story-fin { margin-top: 4rem; }

.reader-loading,
.reader-fallback {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: .8rem;
  background: radial-gradient(circle, #24180e, #0b0704 70%);
  color: #b99559;
  text-align: center;
}

.reader-loading span {
  width: 2rem;
  height: 2rem;
  border: 1px solid rgba(215,173,97,.28);
  border-top-color: #d7ad61;
  border-radius: 50%;
  animation: reader-spin 1s linear infinite;
}

.reader-loading p, .reader-fallback p { margin: 0; font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; }
.reader-fallback a { padding: .7rem 1rem; border: 1px solid rgba(215,173,97,.5); color: #e5c784; text-decoration: none; }

.reader-footer {
  display: flex;
  justify-content: space-between;
  padding: .72rem .15rem 0;
  color: #80683f;
  font-size: .62rem;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.reader-ambience { position: fixed; z-index: 1; inset: 0; overflow: hidden; pointer-events: none; }
.reader-ambience i { position: absolute; left: var(--x); top: var(--y); width: var(--size); height: var(--size); border-radius: 50%; background: rgba(255,223,163,.84); box-shadow: 0 0 6px rgba(255,159,51,.52); opacity: 0; animation: reader-drift var(--duration) linear var(--delay) infinite; }

@keyframes reader-spin { to { transform: rotate(360deg); } }
@keyframes reader-drift { 0% { opacity: 0; transform: translateY(8px); } 18% { opacity: var(--opacity); } 100% { opacity: 0; transform: translate3d(var(--dx), -110px, 0); } }

@media (max-width: 720px), (max-width: 1000px) and (max-height: 600px) and (pointer: coarse) {
  .reader-header { grid-template-columns: 1fr; gap: .45rem; padding: .85rem 0 .65rem; }
  .reader-header__balance { display: none; }
  .reader-home { padding: .45rem .65rem; font-size: .78rem; }
  .reader-heading { text-align: center; }
  .reader-heading h1 { font-size: 1rem; }
  .reader-page { height: calc(100vh - 7.2rem); min-height: 28rem; }
  .reader-footer { gap: 1rem; font-size: .52rem; }
}

@media (prefers-reduced-motion: reduce) {
  .reader-loading span, .reader-ambience i { animation: none; }
  .reader-ambience { display: none; }
}

@media (max-width: 720px), (max-width: 1000px) and (max-height: 600px) and (pointer: coarse) {
  .story-content { width: min(100% - 2rem, 42rem); padding-top: 2.75rem; font-size: 1.03rem; line-height: 1.78; }
  .story-content p { text-align: left; }
}

/* La página de lectura llena el alto disponible y conserva el título completo. */
@media (max-width: 720px), (max-width: 1000px) and (max-height: 600px) and (pointer: coarse) {
  html { height: auto; min-height: 100%; overflow-y: auto; }
  body { height: auto; min-height: 100dvh; display: block; overflow-x: hidden; overflow-y: visible; }
  /* Solo los lectores con panel interior bloquean el scroll del documento. */
  html:has(.reader-shell) { height: 100%; min-height: 0; overflow: hidden; }
  body:has(.reader-shell) { height: 100dvh; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .reader-header {
    flex: none;
    width: calc(100% - 1rem);
    padding: .7rem 0 .55rem;
  }
  .reader-heading h1 {
    overflow: visible;
    font-size: clamp(1.2rem, 5vw, 1.6rem);
    line-height: 1.2;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .reader-shell {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: calc(100% - 1rem);
    min-height: 0;
    padding: .4rem 0 .5rem;
  }
  .reader-ornament, .reader-footer { flex: none; }
  .reader-page { flex: 1; height: auto; min-height: 0; }
  .reader-footer {
    flex-wrap: wrap;
    gap: .35rem 1rem;
    padding-bottom: env(safe-area-inset-bottom);
    font-size: .6rem;
  }
  .story-content {
    width: min(calc(100% - 2.25rem), 40rem);
    padding: 2rem 0 4rem;
    font-size: 1.0625rem;
    line-height: 1.75;
    overflow-wrap: break-word;
  }
  .story-content p { text-align: left; }
  .story-opening .drop-cap { font-size: 3.4em; }
  .reader-poem .story-content p.poem-stanza { white-space: pre-wrap; overflow-wrap: anywhere; }
}
