:root {
  --paper: #dfcdb6;
  --paper-deep: #d0b99f;
  --paper-light: #ebdfcf;
  --lyric-ink: #fffdf7;
  --note-ink: #bb5265;
  --note-soft: #e79aa0;
  --line-ink: #171411;
  --water: #61acd0;
  --water-deep: #338db8;
  --demon: #d82c2f;
  --yellow: #f5d500;
  --shadow: rgba(30, 22, 16, .18);
  --hand: "Segoe Script", "Bradley Hand", "Comic Sans MS", cursive;
  --interface: ui-rounded, "Avenir Next", Avenir, system-ui, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --section-width: 1180px;
  --player-height: 154px;
  --ease: cubic-bezier(.22,.7,.16,1);
  --fast: 180ms;
  --slow: 760ms;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--paper); }
body { margin: 0; color: var(--line-ink); background: var(--paper); font-family: var(--interface); min-height: 100vh; overflow-x: hidden; }
button, input, select { font: inherit; }
button { color: inherit; }
img { max-width: 100%; }
::selection { background: var(--water); color: var(--line-ink); }

.skip-link { position: fixed; z-index: 1000; left: 1rem; top: 1rem; padding: .7rem 1rem; background: #fff; color: #000; transform: translateY(-160%); transition: transform var(--fast); }
.skip-link:focus { transform: translateY(0); }

.entry { position: fixed; z-index: 900; inset: 0; display: grid; place-items: center; padding: 1.25rem; background: rgba(35,26,18,.78); backdrop-filter: blur(7px); transition: opacity .6s var(--ease), visibility .6s; }
.entry.is-gone { opacity: 0; visibility: hidden; pointer-events: none; }
.entry__paper { width: min(690px, 100%); padding: clamp(2rem, 7vw, 4.5rem); text-align: center; background: var(--paper); border: 1px solid rgba(20,15,10,.7); box-shadow: 0 35px 100px rgba(0,0,0,.34); position: relative; }
.entry__paper::before { content: ""; position: absolute; inset: 16px; border: 1px solid rgba(20,15,10,.22); pointer-events: none; }
.entry__eyebrow, .entry__technical, .entry__content-note { font-size: .76rem; letter-spacing: .12em; text-transform: uppercase; }
.entry h1 { font-family: var(--hand); font-size: clamp(3.4rem, 11vw, 7.4rem); font-weight: 400; line-height: .9; margin: 1rem 0 .2rem; }
.entry__subtitle { font-family: var(--hand); font-size: clamp(1.2rem, 4vw, 2rem); margin: 0 0 2rem; color: var(--lyric-ink); text-shadow: 0 1px 1px rgba(0,0,0,.2); }
.entry__copy { max-width: 50ch; margin: 0 auto 1.5rem; line-height: 1.6; }
.entry__content-note { color: #6d2937; line-height: 1.5; }
.entry__actions { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; margin: 2rem 0 1rem; }
.ink-button { border: 1px solid var(--line-ink); background: transparent; padding: .8rem 1.2rem; cursor: pointer; box-shadow: 3px 3px 0 var(--line-ink); transition: transform var(--fast), box-shadow var(--fast); }
.ink-button:hover, .ink-button:focus-visible { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--line-ink); }
.ink-button--primary { background: var(--lyric-ink); }

.site-header { position: fixed; z-index: 80; top: 0; left: 0; right: 0; height: 56px; padding: 0 1rem; display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 1rem; background: color-mix(in srgb, var(--paper) 88%, transparent); border-bottom: 1px solid rgba(20,15,10,.18); backdrop-filter: blur(9px); }
.nav-toggle, .site-mark { border: 0; background: transparent; font-family: var(--hand); font-size: 1rem; cursor: pointer; color: var(--line-ink); text-decoration: none; }
.site-mark { font-weight: 700; letter-spacing: .18em; }
.site-progress { height: 2px; background: rgba(20,15,10,.16); overflow: hidden; }
.site-progress span { display: block; width: 0; height: 100%; background: var(--line-ink); transition: width .12s linear; }
.active-chapter { margin: 0; max-width: 28vw; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; font-size: .73rem; text-transform: uppercase; letter-spacing: .1em; }

.chapter-nav { position: fixed; z-index: 150; inset: 0; background: rgba(32,23,16,.62); backdrop-filter: blur(5px); padding: 2rem; }
.chapter-nav__paper { margin: 2rem auto; width: min(760px,100%); max-height: calc(100vh - 8rem); overflow: auto; background: var(--paper-light); border: 1px solid var(--line-ink); box-shadow: 16px 18px 0 rgba(20,15,10,.45); padding: 2rem; }
.chapter-nav__head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(20,15,10,.3); }
.chapter-nav h2 { font-family: var(--hand); font-weight: 400; font-size: 2.4rem; margin: 0 0 1rem; }
.chapter-nav ol { columns: 2; column-gap: 2.5rem; padding-left: 1.6rem; }
.chapter-nav li { break-inside: avoid; margin: 0 0 .85rem; }
.chapter-nav a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.icon-button { border: 0; background: transparent; font-size: 2rem; line-height: 1; cursor: pointer; }

#album { position: relative; z-index: 5; }
.album-section { min-height: 100vh; padding: clamp(6rem, 12vh, 9rem) clamp(1.2rem, 6vw, 5rem) calc(var(--player-height) + 5rem); position: relative; display: grid; align-items: center; border-bottom: 1px solid rgba(20,15,10,.08); isolation: isolate; }
.album-section::before { content: attr(data-page-label); position: absolute; top: 76px; left: max(1.2rem, calc((100vw - var(--section-width))/2)); color: rgba(20,15,10,.4); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; }
.album-section__inner { width: min(var(--section-width),100%); margin: 0 auto; position: relative; }
.album-section__header { max-width: 900px; position: relative; z-index: 2; }
.album-section__kicker { margin: 0 0 .2rem; font-family: var(--hand); font-size: clamp(1.05rem,2vw,1.6rem); color: var(--note-ink); }
.album-section h2 { margin: 0; font-family: var(--hand); font-size: clamp(3rem, 8.5vw, 7.6rem); line-height: .94; font-weight: 400; color: var(--lyric-ink); text-shadow: 0 2px 0 rgba(20,15,10,.16); letter-spacing: -.03em; }
.album-section__subtitle { max-width: 40ch; font-family: var(--hand); font-size: clamp(1.25rem,2.4vw,2rem); color: var(--lyric-ink); }
.song-layout { margin-top: clamp(2rem,6vw,5rem); display: grid; grid-template-columns: minmax(0,1.05fr) minmax(280px,.75fr); gap: clamp(2rem,6vw,7rem); align-items: start; }
.lyrics { white-space: pre-wrap; font-family: var(--hand); font-size: clamp(1.15rem, 1.7vw, 1.65rem); line-height: 1.52; color: var(--lyric-ink); margin: 0; padding: clamp(1.2rem,3vw,2.3rem); background: rgba(63,45,31,.16); border: 1px solid rgba(255,255,255,.2); box-shadow: inset 0 0 40px rgba(255,255,255,.04); text-shadow: 0 1px 1px rgba(0,0,0,.28); transform: rotate(-.25deg); }
.notes { display: grid; gap: 1.3rem; padding-top: 1rem; }
.note { margin: 0; color: var(--note-ink); font-size: clamp(.98rem,1.2vw,1.15rem); line-height: 1.63; transform: rotate(.4deg); }
.note:nth-child(even) { transform: rotate(-.5deg); }
.section-art { width: min(300px, 42vw); max-height: 340px; object-fit: contain; margin: 1.4rem auto 0; display: block; filter: drop-shadow(0 8px 5px rgba(0,0,0,.08)); }
.section-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 2rem; }
.page-button, .section-listen { border: 1px solid rgba(20,15,10,.65); background: rgba(255,255,255,.12); padding: .55rem .85rem; cursor: pointer; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; }
.section-listen[disabled] { opacity: .52; cursor: help; }
.section-listen:not([disabled]):hover, .page-button:hover { background: var(--lyric-ink); }
.audio-badge { display: inline-flex; align-items: center; gap: .4rem; margin-top: 1rem; color: rgba(20,15,10,.63); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.audio-badge::before { content: ""; width: 7px; height: 7px; background: currentColor; border-radius: 50%; }
.audio-badge.is-configured { color: #185f46; }

.cover-section { min-height: 132vh; text-align: center; }
.cover-section .album-section__inner { display: grid; place-items: center; align-content: center; }
.cover-art { width: min(680px,90vw); height: auto; max-height: none; object-fit: contain; filter: drop-shadow(0 18px 22px rgba(30,22,16,.12)); }
.cover-copy { margin-top: 1.5rem; position: relative; z-index: 2; }
.cover-copy h2 { color: var(--line-ink); font-size: clamp(4.2rem,13vw,10rem); }
.cover-copy p { font-family: var(--hand); font-size: clamp(1.1rem,2.3vw,1.7rem); }
.archive-stamp { display: inline-block; max-width: min(620px, 88vw); margin-top: 0; border: 1px solid rgba(20,15,10,.55); padding: .6rem .9rem; transform: rotate(-1deg); font-family: var(--hand); font-size: clamp(.82rem, 1.45vw, 1.05rem); line-height: 1.35; text-transform: none; letter-spacing: .025em; background: color-mix(in srgb, var(--paper-light) 72%, transparent); box-shadow: 3px 4px 0 rgba(20,15,10,.16); }
.editorial-section .album-section__inner { max-width: 900px; }
.editorial-copy { max-width: 48ch; margin: 3rem auto; font-family: var(--hand); font-size: clamp(1.4rem,2.4vw,2.05rem); line-height: 1.6; text-align: center; }
.contents-links { list-style: none; padding: 0; margin: 3rem auto 0; max-width: 760px; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .65rem 2rem; }
.contents-links a { display: flex; justify-content: space-between; gap: 1rem; color: var(--lyric-ink); font-family: var(--hand); font-size: clamp(1.1rem,2vw,1.5rem); text-decoration: none; border-bottom: 1px dashed rgba(255,255,255,.46); }
.contents-links a:hover { color: var(--line-ink); border-color: var(--line-ink); }
.terms-list { margin-top: 3rem; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1.2rem 2rem; }
.term { border-top: 1px solid rgba(255,255,255,.36); padding-top: 1rem; }
.term dt { font-family: var(--hand); color: var(--lyric-ink); font-size: 1.5rem; }
.term dd { margin: .4rem 0 0; color: var(--note-ink); line-height: 1.55; }
.poem-section .lyrics { max-width: 740px; margin: 3rem auto 0; text-align: center; transform: none; background: transparent; border: 0; box-shadow: none; }

.world { --water-height: 0px; position: fixed; z-index: 3; inset: 0; pointer-events: none; overflow: hidden; }
.water { position: absolute; left: -4vw; right: -4vw; bottom: -3vh; height: var(--water-height); min-height: 0; background: var(--water); border-radius: 50% 50% 0 0 / 18px 18px 0 0; transition: height .3s linear; opacity: .93; box-shadow: inset 0 5px 0 rgba(255,255,255,.25); }
.water::before { content: ""; position: absolute; inset: -8px 6% auto; height: 14px; border-top: 2px solid rgba(20,15,10,.7); border-radius: 50%; opacity: .6; }
.water__ripple { position: absolute; width: 70px; height: 16px; border: 2px solid rgba(20,15,10,.45); border-radius: 50%; animation: ripple 3.8s infinite var(--ease); }
.water__ripple--one { left: 25%; top: 18px; }
.water__ripple--two { right: 22%; top: 42px; animation-delay: -1.7s; }
.world-character { position: absolute; z-index: 2; right: clamp(12px,5vw,70px); bottom: max(30px, calc(var(--water-height) - 70px)); width: clamp(90px,13vw,175px); transition: bottom .5s var(--ease), transform .5s var(--ease), opacity .4s; transform-origin: bottom center; }
.world-demon { position: absolute; z-index: 2; left: 5vw; bottom: 12vh; width: clamp(70px,10vw,145px); opacity: 0; transform: translateY(40px) rotate(-10deg); transition: opacity .6s, transform .6s var(--ease); }
.world-demon.is-visible { opacity: .85; transform: translateY(0) rotate(-4deg); }
.world-fish { position: absolute; bottom: 5vh; left: -10%; color: #f36c2d; font-size: 2rem; opacity: 0; }
.world-fish.is-swimming { opacity: .9; animation: swim 9s linear infinite; }
@keyframes ripple { 0% { transform: scale(.4); opacity: 0; } 35% { opacity: .6; } 100% { transform: scale(1.8); opacity: 0; } }
@keyframes swim { from { left: -10%; transform: translateY(0) scaleX(1); } 45% { transform: translateY(-18px) scaleX(1); } 49% { transform: translateY(-18px) scaleX(-1); } 51% { left: 102%; transform: translateY(-18px) scaleX(-1); } 100% { left: -10%; transform: translateY(0) scaleX(-1); } }

.player { position: fixed; z-index: 100; left: 1rem; bottom: 1rem; width: min(500px, calc(100vw - 2rem)); min-height: var(--player-height); padding: .9rem 1rem; background: rgba(235,223,207,.94); border: 1px solid var(--line-ink); box-shadow: 7px 8px 0 rgba(20,15,10,.54); backdrop-filter: blur(8px); transform: rotate(-.35deg); }
.player__label { display: grid; grid-template-columns: 1fr auto; gap: .1rem 1rem; align-items: baseline; }
.player__label span { font-size: .67rem; text-transform: uppercase; letter-spacing: .08em; color: rgba(20,15,10,.62); }
.player__label strong { grid-column: 1; font-family: var(--hand); font-weight: 400; font-size: 1.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#player-status { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.player__controls { display: flex; align-items: center; gap: .45rem; margin-top: .5rem; }
.player-button { min-width: 35px; height: 30px; border: 1px solid rgba(20,15,10,.65); background: transparent; cursor: pointer; font-size: .72rem; }
.player-button:hover, .player-button:focus-visible { background: var(--lyric-ink); }
.volume-label { display: flex; align-items: center; gap: .35rem; font-size: .7rem; margin-left: auto; }
.volume-label input { width: 90px; accent-color: var(--line-ink); }
.player__timeline input { width: 100%; accent-color: var(--water-deep); }
.player__timeline > div { display: flex; justify-content: space-between; font-size: .64rem; }
.scroll-audio { display: inline-flex; align-items: center; gap: .35rem; margin-top: .2rem; font-size: .68rem; }
.scroll-audio input { accent-color: var(--line-ink); }
.cue-help { float: right; border: 0; background: transparent; color: var(--note-ink); text-decoration: underline; font-size: .65rem; cursor: pointer; }

.debug-panel { position: fixed; z-index: 300; top: 70px; right: 1rem; width: min(540px, calc(100vw - 2rem)); max-height: calc(100vh - 90px); overflow: auto; padding: 1rem; background: #f5eee5; border: 1px solid #111; box-shadow: 9px 10px 0 rgba(0,0,0,.55); }
.debug-panel header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid #aaa; }
.debug-panel header span { font-size: .65rem; text-transform: uppercase; letter-spacing: .12em; }
.debug-panel h2 { margin: 0; font-family: var(--hand); font-size: 2rem; font-weight: 400; }
.debug-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: 1rem 0; }
.debug-grid label, .debug-readout { display: grid; gap: .2rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; }
.debug-grid input, .debug-grid select { width: 100%; padding: .45rem; background: #fff; border: 1px solid #555; }
.debug-readout strong { padding: .45rem; background: #e2d6c8; font-size: .86rem; }
.debug-actions { display: flex; flex-wrap: wrap; gap: .45rem; }
.debug-actions button { border: 1px solid #222; background: #fff; padding: .45rem .6rem; cursor: pointer; }
.debug-note { font-size: .72rem; line-height: 1.5; color: #71404a; }

.facsimile-dialog { width: min(880px,94vw); max-height: 94vh; padding: 0; border: 1px solid var(--line-ink); background: var(--paper); box-shadow: 0 30px 80px rgba(0,0,0,.46); }
.facsimile-dialog::backdrop { background: rgba(20,15,10,.78); backdrop-filter: blur(5px); }
.facsimile-dialog__head { position: sticky; z-index: 2; top: 0; display: flex; justify-content: space-between; align-items: center; padding: .5rem 1rem; background: rgba(235,223,207,.95); border-bottom: 1px solid rgba(20,15,10,.3); }
.facsimile-dialog__head p { margin: 0; font-family: var(--hand); }
.facsimile-dialog img { width: 100%; display: block; }
.toast { position: fixed; z-index: 500; right: 1rem; bottom: calc(var(--player-height) + 2rem); max-width: 360px; padding: .75rem 1rem; background: var(--line-ink); color: #fff; opacity: 0; transform: translateY(15px); transition: opacity .25s, transform .25s; pointer-events: none; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

:focus-visible { outline: 3px solid #0b5b7e; outline-offset: 3px; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
.cover-copy h2 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cover-copy { margin-top: 1.5rem; }
.player-collapse { position: absolute; top: .45rem; right: .45rem; border: 0; background: transparent; font-size: 1.1rem; cursor: pointer; }
.player.is-collapsed { min-height: 0; width: min(320px, calc(100vw - 2rem)); }
.player.is-collapsed .player__controls,
.player.is-collapsed .player__timeline,
.player.is-collapsed .scroll-audio,
.player.is-collapsed .cue-help,
.player.is-collapsed #player-status { display: none; }
.player.is-collapsed .player__label { display: block; padding-right: 1.5rem; }
.player.is-collapsed .player__label strong { display: block; }

/* Dedicated chapter audio and Bandcamp handoff */
.entry__bandcamp {
  display: inline-block;
  margin-top: 1rem;
  color: var(--line-ink);
  font-size: .75rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-underline-offset: .25em;
}
.player-bandcamp {
  display: inline-block;
  margin-top: .2rem;
  color: var(--line-ink);
  font-size: .65rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-underline-offset: .2em;
}
.debug-readout--wide { grid-column: 1 / -1; }
.debug-readout--wide strong {
  overflow-wrap: anywhere;
  text-transform: none;
  letter-spacing: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: .72rem;
}
.player.is-collapsed .player-bandcamp { display: none; }

/* Stage 3: resumable story narration and remembered chapter positions */
.story-resume {
  position: fixed;
  z-index: 105;
  left: 1.35rem;
  bottom: calc(var(--player-height) + 2rem);
  display: grid;
  gap: .12rem;
  min-width: min(340px, calc(100vw - 2.7rem));
  padding: .78rem 1rem .72rem;
  border: 1px solid var(--line-ink);
  background: rgba(255,253,247,.96);
  box-shadow: 5px 6px 0 rgba(20,15,10,.52);
  font-family: var(--hand);
  text-align: left;
  cursor: pointer;
  transform: rotate(.45deg) translateY(0);
  animation: story-resume-arrive .45s var(--ease) both;
}
.story-resume[hidden] { display: none !important; }
.story-resume::before {
  content: "";
  position: absolute;
  left: .55rem;
  right: .55rem;
  bottom: .38rem;
  border-bottom: 1px dashed var(--note-ink);
  opacity: .48;
}
.story-resume span { font-size: 1.18rem; line-height: 1.05; }
.story-resume small {
  font-family: var(--interface);
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--note-ink);
}
.story-resume:hover,
.story-resume:focus-visible {
  transform: rotate(-.2deg) translate(-2px,-2px);
  box-shadow: 8px 9px 0 rgba(20,15,10,.58);
}
@keyframes story-resume-arrive {
  from { opacity: 0; transform: rotate(.45deg) translateY(14px); }
  to { opacity: 1; transform: rotate(.45deg) translateY(0); }
}

.section-listen.is-current {
  background: var(--lyric-ink);
  box-shadow: 3px 3px 0 rgba(20,15,10,.45);
}
.section-actions--audio { align-items: center; }

.player.is-story-pinned { border-left-width: 4px; }
.player.is-story-pinned .scroll-audio::after {
  content: "story narration has the wheel";
  margin-left: .35rem;
  color: var(--note-ink);
  font-size: .61rem;
  letter-spacing: .04em;
}
.player__seek-label {
  display: block;
  margin-top: .3rem;
  font-size: .58rem;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(20,15,10,.58);
}
#seek {
  --seek-progress: 0%;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 23px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: ew-resize;
  touch-action: none;
}
#seek::-webkit-slider-runnable-track {
  height: 5px;
  border: 1px solid rgba(20,15,10,.42);
  background: linear-gradient(to right, var(--water-deep) 0 var(--seek-progress), rgba(20,15,10,.14) var(--seek-progress) 100%);
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border: 1px solid var(--line-ink);
  border-radius: 50%;
  background: var(--lyric-ink);
  box-shadow: 2px 2px 0 rgba(20,15,10,.4);
}
#seek::-moz-range-track {
  height: 5px;
  border: 1px solid rgba(20,15,10,.42);
  background: rgba(20,15,10,.14);
}
#seek::-moz-range-progress {
  height: 5px;
  background: var(--water-deep);
}
#seek::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 1px solid var(--line-ink);
  border-radius: 50%;
  background: var(--lyric-ink);
  box-shadow: 2px 2px 0 rgba(20,15,10,.4);
}
#seek:focus-visible { outline-offset: 0; }
.player.is-collapsed + .story-resume { bottom: 6rem; }
