:root {
  --ink: #2a1238;
  --plum: #4f0053;
  --plum-night: #1c0723;
  --plum-soft: #6b2a70;
  --parchment: #f6eddd;
  --parchment-deep: #ecdcc0;
  --parchment-edge: #dcc69e;
  --gilt: #c9961a;
  --gilt-ink: #7a5402;
  --amber: #ffbe0b;
  --amber-hi: #ffd35c;
  --ember: #b8430a;
  --teal: #00735e;
  --fell: "IM Fell English", "Iowan Old Style", Georgia, serif;
  --cardo: "Cardo", "Palatino Linotype", Palatino, Georgia, serif;
  --reading: 46rem;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--cardo);
  font-size: 1.125rem;
  line-height: 1.68;
  background-color: var(--plum-night);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255, 190, 11, .10) 0 1px, transparent 2px),
    radial-gradient(circle at 78% 64%, rgba(255, 190, 11, .08) 0 1px, transparent 2px),
    radial-gradient(circle at 42% 88%, rgba(246, 237, 221, .07) 0 1px, transparent 2px),
    linear-gradient(160deg, #2b0a33 0%, #1c0723 55%, #12041a 100%);
  background-size: 140px 140px, 190px 190px, 230px 230px, 100% 100%;
  overflow-x: hidden;
}

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

a { color: var(--plum); text-decoration-color: var(--gilt); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
a:hover { color: var(--ember); }
a:focus-visible, summary:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }

.tome-skip-jump {
  position: absolute; left: -999px; top: 8px; z-index: 50;
  background: var(--amber); color: var(--plum-night); padding: .5rem .9rem; font-weight: 700;
}
.tome-skip-jump:focus { left: 12px; }

.gilt-masthead-ribbon {
  background: linear-gradient(180deg, #5a0a5f 0%, var(--plum) 60%, #3d0041 100%);
  border-bottom: 3px double var(--gilt);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  position: relative;
  z-index: 5;
}
.masthead-ribbon-inner {
  max-width: 1240px; margin: 0 auto; padding: .7rem 1.25rem;
  display: flex; align-items: center; gap: 1.25rem;
}
.tale-crest-lettering {
  display: inline-flex; align-items: center; gap: .6rem;
  color: var(--parchment); text-decoration: none; flex: 0 0 auto;
}
.tale-crest-lettering:hover { color: var(--amber-hi); }
.crescent-glyph-mark { width: 38px; height: 38px; flex: 0 0 38px; }
.tale-crest-lettering strong {
  display: block; color: inherit; font-family: var(--fell); font-weight: 400; font-size: 1.45rem; line-height: 1.05; letter-spacing: .02em;
}
.tale-crest-subtitle { display: block; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--amber-hi); }

.tale-wayfinder-strand { flex: 1 1 auto; }
.tale-wayfinder-strand ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: .15rem .3rem;
}
.tale-wayfinder-strand a {
  display: block; padding: .35rem .6rem; color: var(--parchment); text-decoration: none;
  font-family: var(--fell); font-size: 1.08rem; border-bottom: 1px solid transparent;
}
.tale-wayfinder-strand a:hover { color: var(--amber-hi); border-bottom-color: var(--gilt); }
.tale-wayfinder-strand a[aria-current="page"] { color: var(--amber); border-bottom-color: var(--amber); }

.wayfinder-fold-pouch { display: none; }

.gilt-clasp-opener {
  position: relative;
  display: inline-flex; align-items: center; gap: .55rem;
  padding: .62rem 1.15rem .62rem 1.55rem;
  background: linear-gradient(180deg, var(--amber-hi) 0%, var(--amber) 55%, #e8a700 100%);
  color: var(--plum-night); font-family: var(--cardo); font-weight: 700; font-size: 1rem; line-height: 1.25;
  text-decoration: none; border: 2px solid var(--gilt-ink); border-radius: 6px 22px 22px 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), 0 3px 0 #8a5d00, 0 6px 14px rgba(0, 0, 0, .25);
}
.gilt-clasp-opener::before {
  content: ""; position: absolute; left: .55rem; top: 50%; width: .55rem; height: .55rem; margin-top: -.275rem;
  border-radius: 50%; background: var(--plum); box-shadow: 0 0 0 2px var(--amber-hi);
}
.gilt-clasp-opener::after { content: "\2192"; font-weight: 400; }
.gilt-clasp-opener:hover { color: var(--plum-night); filter: brightness(1.06); transform: translateY(-1px); }
.gilt-masthead-ribbon .gilt-clasp-opener { flex: 0 0 auto; font-size: .95rem; }

.open-tome-spread {
  max-width: 1240px; margin: 2.2rem auto 2.6rem;
  display: grid; grid-template-columns: 290px minmax(0, 1fr);
  background: var(--parchment);
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--parchment-edge), 0 0 0 7px #3d0041, 0 0 0 9px var(--gilt), 0 24px 60px rgba(0, 0, 0, .55);
  position: relative;
}
.open-tome-gutter {
  position: absolute; top: 0; bottom: 0; left: 290px; width: 34px; margin-left: -17px; pointer-events: none;
  background: linear-gradient(90deg, rgba(91, 58, 20, 0) 0%, rgba(91, 58, 20, .16) 45%, rgba(91, 58, 20, .28) 50%, rgba(91, 58, 20, .16) 55%, rgba(91, 58, 20, 0) 100%);
}
.night-contents-leaf {
  padding: 2.2rem 1.6rem 2.2rem 1.8rem;
  background: linear-gradient(90deg, var(--parchment-deep) 0%, var(--parchment) 85%);
  border-radius: 6px 0 0 6px;
  font-size: .98rem;
}
.night-contents-leaf > div { position: sticky; top: 1.2rem; }
.night-contents-caption {
  font-family: var(--fell); font-size: 1.2rem; color: var(--plum); margin: 0 0 .6rem;
  border-bottom: 1px solid var(--gilt); padding-bottom: .35rem;
}
.night-contents-trail { list-style: none; margin: 0 0 1.6rem; padding: 0; counter-reset: noche; }
.night-contents-trail li { counter-increment: noche; margin: 0 0 .35rem; padding-left: 2.1rem; position: relative; line-height: 1.35; }
.night-contents-trail li::before {
  content: counter(noche, upper-roman); position: absolute; left: 0; top: .05rem; width: 1.7rem;
  font-family: var(--fell); color: var(--gilt-ink); text-align: right;
}
.night-contents-trail a { text-decoration: none; color: var(--ink); }
.night-contents-trail a:hover { color: var(--ember); text-decoration: underline; }

.night-facts-tablet {
  border: 1px solid var(--gilt); background: #fbf5ea; padding: 1rem 1rem .6rem; border-radius: 4px;
  box-shadow: inset 0 0 0 3px #fbf5ea, inset 0 0 0 4px rgba(201, 150, 26, .45);
}
.night-facts-heading { font-family: var(--fell); color: var(--plum); font-size: 1.1rem; margin: 0 0 .5rem; }
.night-facts-tablet dl { margin: 0; }
.fact-pair-term { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--gilt-ink); margin-top: .55rem; }
.fact-pair-value { margin: 0; line-height: 1.38; }

.tale-reading-leaf { padding: 2.4rem clamp(1.25rem, 4vw, 3.6rem) 3rem; min-width: 0; }
.tale-reading-leaf > * { max-width: var(--reading); margin-left: auto; margin-right: auto; }

.tale-opening-frontispiece { text-align: center; margin-bottom: 2rem; }
.tale-overture-whisper {
  font-size: .86rem; letter-spacing: .16em; text-transform: uppercase; color: var(--gilt-ink); margin: 0 0 .7rem;
}
h1, h2, h3 { font-family: var(--fell); font-weight: 400; color: var(--plum); line-height: 1.15; }
h1 { font-size: clamp(2.05rem, 4.2vw, 3.05rem); margin: 0 0 .8rem; }
h2 { font-size: clamp(1.6rem, 2.8vw, 2.05rem); margin: .2rem 0 .9rem; }
h3 { font-size: 1.32rem; margin: 1.6rem 0 .5rem; }
.tale-edition-imprint { font-style: italic; color: #5b4a3a; margin: 0; font-size: 1rem; }

.tale-lede-paragraph { font-size: 1.2rem; }

.night-passage-block { margin-top: 2.6rem; }
.night-numeral-ribbon {
  display: flex; align-items: center; justify-content: center; gap: .8rem;
  font-family: var(--fell); font-style: italic; color: var(--gilt-ink); font-size: 1.05rem; letter-spacing: .08em; margin: 0 0 .2rem;
}
.night-numeral-ribbon::before, .night-numeral-ribbon::after {
  content: ""; flex: 0 1 5rem; height: 1px; background: linear-gradient(90deg, transparent, var(--gilt));
}
.night-numeral-ribbon::after { background: linear-gradient(90deg, var(--gilt), transparent); }
.night-passage-block h2 { text-align: center; }

.ornate-initial-capital::first-letter {
  float: left;
  font-family: var(--fell);
  font-size: 3.7em; line-height: .8;
  color: var(--plum);
  padding: .2em .17em .12em;
  margin: .08em .14em 0 0;
  background: url("/cuentos/orla-capitular.svg") center / 100% 100% no-repeat;
  text-shadow: 1px 1px 0 rgba(201, 150, 26, .55);
}

p { margin: 0 0 1.05rem; }
ul, ol { padding-left: 1.4rem; }
li { margin-bottom: .35rem; }
strong { color: #1d0b26; }

.fleuron-divider-rule {
  border: 0; height: 32px; margin: 2.4rem auto;
  background: url("/cuentos/fleuron-noche.svg") center / 320px 32px no-repeat;
}

.lamp-plate-illustration {
  margin: 0 auto 1.8rem; max-width: 380px; padding: 10px; background: #fbf5ea;
  border: 1px solid var(--gilt); box-shadow: 0 0 0 4px var(--parchment), 0 0 0 5px var(--gilt-ink), 0 10px 22px rgba(42, 18, 56, .25);
  transform: rotate(-.6deg);
}
.lamp-plate-illustration img { width: 100%; aspect-ratio: 580 / 560; object-fit: cover; }
.lamp-plate-caption { font-size: .86rem; font-style: italic; text-align: center; margin-top: .5rem; color: #5b4a3a; }

.sultan-ledger-casing { overflow-x: auto; margin: 1.4rem auto 1.4rem; -webkit-overflow-scrolling: touch; }
.sultan-ledger-matrix {
  width: 100%; border-collapse: collapse; font-size: 1rem; min-width: 520px;
  border-top: 3px double var(--gilt); border-bottom: 3px double var(--gilt);
}
.sultan-ledger-caption { caption-side: top; text-align: left; font-family: var(--fell); color: var(--plum); font-size: 1.15rem; padding-bottom: .4rem; }
.sultan-ledger-matrix th, .sultan-ledger-matrix td { padding: .55rem .7rem; text-align: left; vertical-align: top; border-bottom: 1px solid rgba(201, 150, 26, .45); }
.sultan-ledger-matrix th { font-weight: 700; color: var(--plum); background: rgba(201, 150, 26, .12); }
.sultan-ledger-matrix tbody tr:nth-child(even) td { background: rgba(236, 220, 192, .45); }

.provenance-whisper-remark { font-size: .9rem; color: #5b4a3a; font-style: italic; }

.candle-caution-plate {
  position: relative; margin: 1.5rem auto; padding: 1rem 1.2rem 1rem 3.2rem;
  background: #fbefe4; border: 1px solid rgba(184, 67, 10, .45); border-left: 5px solid var(--ember); border-radius: 4px;
}
.candle-caution-plate::before {
  content: ""; position: absolute; left: 1.05rem; top: 1.15rem; width: 1.3rem; height: 1.3rem;
  background: radial-gradient(circle at 50% 30%, var(--amber) 0 22%, transparent 24%), linear-gradient(var(--ember), var(--ember)) 50% 100% / 34% 55% no-repeat;
}
.candle-caution-plate p:last-child { margin-bottom: 0; }

.clasp-bridge-passage {
  margin: 2.4rem auto; padding: 1.5rem 1.4rem 1.6rem; text-align: center;
  background: linear-gradient(180deg, rgba(79, 0, 83, .06), rgba(79, 0, 83, .11));
  border: 1px solid rgba(79, 0, 83, .25); border-radius: 4px;
}
.clasp-bridge-passage p { margin-bottom: .9rem; font-style: italic; }

.tale-ritual-sequence { counter-reset: paso; list-style: none; padding-left: 0; }
.tale-ritual-sequence li { counter-increment: paso; position: relative; padding-left: 2.6rem; margin-bottom: .8rem; }
.tale-ritual-sequence li::before {
  content: counter(paso); position: absolute; left: 0; top: .05rem; width: 1.9rem; height: 1.9rem; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--fell); color: var(--parchment); background: var(--plum);
  box-shadow: 0 0 0 2px var(--gilt);
}

.vizier-riddle-set { margin-top: 1rem; }
.vizier-riddle-entry { border-bottom: 1px solid rgba(201, 150, 26, .55); }
.vizier-riddle-entry summary {
  cursor: pointer; list-style: none; padding: .85rem 2.2rem .85rem 0; position: relative;
  font-family: var(--fell); font-size: 1.2rem; color: var(--plum);
}
.vizier-riddle-entry summary::-webkit-details-marker { display: none; }
.vizier-riddle-entry summary::after {
  content: "+"; position: absolute; right: .3rem; top: .7rem; font-size: 1.4rem; color: var(--gilt-ink);
}
.vizier-riddle-entry[open] summary::after { content: "\2212"; }
.vizier-riddle-answer { padding: 0 0 .6rem; }

.endpaper-closing-leaf {
  color: var(--parchment);
  background-color: #2b0a33;
  background-image:
    radial-gradient(ellipse at 20% 30%, rgba(0, 115, 94, .35) 0 18%, transparent 40%),
    radial-gradient(ellipse at 80% 20%, rgba(255, 190, 11, .18) 0 14%, transparent 36%),
    radial-gradient(ellipse at 60% 85%, rgba(184, 67, 10, .25) 0 16%, transparent 38%),
    radial-gradient(ellipse at 35% 75%, rgba(246, 237, 221, .08) 0 20%, transparent 42%);
  border-top: 3px double var(--gilt);
  padding: 2.4rem 1.25rem 2.8rem;
}
.endpaper-closing-leaf > div { max-width: 1040px; margin: 0 auto; }
.endpaper-wayfinder-strand ul { list-style: none; margin: 0 0 1.4rem; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: .3rem 1.2rem; }
.endpaper-wayfinder-strand a { color: var(--amber-hi); font-family: var(--fell); font-size: 1.05rem; }
.endpaper-disclosure-text { font-size: .95rem; line-height: 1.6; text-align: center; max-width: 52rem; margin: 0 auto 1rem; color: #efe2cc; }
.endpaper-disclosure-text a { color: var(--amber-hi); }
.endpaper-imprint-sentence { text-align: center; font-size: .85rem; color: #cdb99b; margin: 0; letter-spacing: .03em; }

.lost-night-parchment {
  max-width: 760px; margin: 3rem auto; padding: 2.6rem clamp(1.25rem, 5vw, 3rem) 3rem; text-align: center;
  background: var(--parchment); border-radius: 6px;
  box-shadow: 0 0 0 7px #3d0041, 0 0 0 9px var(--gilt), 0 24px 60px rgba(0, 0, 0, .55);
}
.lost-night-trail { list-style: none; padding: 0; margin: 1.6rem 0 0; display: grid; gap: .6rem; }
.lost-night-trail a { font-family: var(--fell); font-size: 1.25rem; }

@media (max-width: 1080px) {
  .masthead-ribbon-inner { flex-wrap: wrap; }
  .tale-wayfinder-strand { display: none; }
  .wayfinder-fold-pouch { display: block; order: 3; flex: 1 0 100%; }
  .wayfinder-fold-trigger {
    cursor: pointer; list-style: none; color: var(--parchment); font-family: var(--fell); font-size: 1.1rem;
    padding: .45rem .8rem; border: 1px solid var(--gilt); border-radius: 4px; display: inline-flex; gap: .5rem; align-items: center;
  }
  .wayfinder-fold-trigger::-webkit-details-marker { display: none; }
  .wayfinder-fold-trigger::before { content: "\2630"; color: var(--amber); }
  .wayfinder-fold-pouch[open] .wayfinder-fold-trigger::before { content: "\2715"; }
  .wayfinder-fold-sheaf { list-style: none; margin: .6rem 0 .3rem; padding: 0; border-top: 1px solid rgba(201, 150, 26, .5); }
  .wayfinder-fold-sheaf a {
    display: block; padding: .6rem .2rem; color: var(--parchment); text-decoration: none; font-family: var(--fell); font-size: 1.15rem;
    border-bottom: 1px solid rgba(201, 150, 26, .25);
  }
  .wayfinder-fold-sheaf a[aria-current="page"] { color: var(--amber); }
  .gilt-masthead-ribbon .gilt-clasp-opener { margin-left: auto; }
  .open-tome-spread { grid-template-columns: minmax(0, 1fr); margin: 1.4rem 1rem 2rem; }
  .open-tome-gutter { display: none; }
  .night-contents-leaf { order: 2; border-radius: 0 0 6px 6px; padding: 1.6rem 1.25rem; background: var(--parchment-deep); border-top: 3px double var(--gilt); }
  .night-contents-leaf > div { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; }
  .tale-reading-leaf { order: 1; }
}

@media (max-width: 640px) {
  body { font-size: 1.06rem; line-height: 1.64; }
  .masthead-ribbon-inner { padding: .6rem 1rem; gap: .7rem; }
  .crescent-glyph-mark { width: 32px; height: 32px; flex-basis: 32px; }
  .tale-crest-lettering strong { font-size: 1.22rem; }
  .tale-crest-subtitle { font-size: .66rem; letter-spacing: .1em; }
  .gilt-masthead-ribbon .gilt-clasp-opener { order: 4; margin-left: 0; width: 100%; justify-content: center; font-size: .92rem; }
  .open-tome-spread { margin: 1rem .5rem 1.6rem; box-shadow: 0 0 0 1px var(--parchment-edge), 0 0 0 4px #3d0041, 0 0 0 5px var(--gilt), 0 14px 30px rgba(0, 0, 0, .5); }
  .tale-reading-leaf { padding: 1.8rem 1rem 2.2rem; }
  .night-contents-leaf > div { grid-template-columns: minmax(0, 1fr); }
  .ornate-initial-capital::first-letter { font-size: 3.1em; }
  .clasp-bridge-passage { padding: 1.2rem .9rem 1.3rem; }
  .gilt-clasp-opener { max-width: 100%; white-space: normal; text-align: left; }
  .sultan-ledger-matrix { font-size: .93rem; min-width: 0; }
  .sultan-ledger-matrix th, .sultan-ledger-matrix td { padding: .5rem .45rem; }
  .lamp-plate-illustration { max-width: 300px; }
  .lost-night-parchment { margin: 1.6rem .75rem; }
}

@media (min-width: 1700px) {
  body { font-size: 1.18rem; }
  .masthead-ribbon-inner, .open-tome-spread { max-width: 1320px; }
  .open-tome-spread { grid-template-columns: 310px minmax(0, 1fr); }
  .open-tome-gutter { left: 310px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .gilt-clasp-opener:hover { transform: none; }
}
