:root {
  color-scheme: dark;
  --background: #100e13;
  --panel: #1d1820;
  --soft: #c7b7bd;
  --text: #f6ece7;
  --copper: #efb58b;
  --border: #594039;
  font: 16px/1.5 system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background: radial-gradient(ellipse at 40% 26%, #33212a 0%, var(--background) 66%) fixed;
}
button, input, select { font: inherit; }
button, .file-button, select, input:not([type="range"]) {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
}
button, .file-button {
  padding: .53rem .8rem;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled), .file-button:hover { border-color: var(--copper); background: #33232c; }
button:disabled { opacity: .44; cursor: default; }
:focus-visible { outline: 2px solid #ffd3a9; outline-offset: 4px; }
input:not([type="range"]) { padding: .54rem .7rem; min-width: 0; }
input[type="range"] { width: 7.5rem; accent-color: #eab08a; vertical-align: middle; }
select { padding: .35rem; }
a { color: var(--copper); }
button.primary {
  background: #eab08a;
  border-color: #eab08a;
  color: #211413;
  font-weight: 700;
}
button.primary:hover:not(:disabled) { background: #ffd3ad; }
.masthead {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 4rem);
  min-height: 4.1rem;
  border-bottom: 1px solid #ecc19c28;
  background: #100e13b8;
}
.wordmark {
  font: 700 .82rem/1.25 system-ui, sans-serif;
  letter-spacing: .18em;
  text-decoration: none;
}
.room-label { color: var(--soft); border-left: 1px solid var(--border); padding-left: 1rem; }
.quiet { margin-left: auto; background: transparent; }
.gate {
  display: grid;
  grid-template-columns: minmax(13rem, .85fr) minmax(16rem, 1fr);
  align-items: center;
  gap: clamp(2rem, 8vw, 8rem);
  min-height: calc(100dvh - 4.1rem);
  max-width: 78rem;
  margin: auto;
  padding: clamp(2rem, 6vw, 6rem);
}
.gate-art {
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  aspect-ratio: 1;
  perspective: 900px;
}
.gate-art::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -18%;
  background: radial-gradient(ellipse, #c8794d30, transparent 64%);
}
.cloth {
  width: 70%;
  aspect-ratio: 2/3;
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid #b28165;
  border-radius: 5px 9px 9px 5px;
  background:
    linear-gradient(90deg, #07060e 0%, #282039 4%, transparent 9%, #81695917 95%, #1c1326),
    repeating-linear-gradient(44deg, #ffffff05 0 1px, #0000000c 1px 3px),
    radial-gradient(ellipse at 58% 32%, #2b2439, #10101f 70%);
  box-shadow: 6px 4px #9f8272, 11px 7px #392826, 19px 16px 35px #000a, 35px 45px 90px #0008;
  transform: rotateY(-16deg) rotateZ(-7deg);
}
.foil { position: absolute; inset: 5% 7% 5% 10%; border: 1px solid #bb8a6690; border-radius: 2px; }
.foil::before, .foil::after { content: ""; position: absolute; border: 1px solid #b7815775; inset: 3%; }
.foil::after { inset: 20% 14%; border-radius: 50%; transform: rotate(24deg); border-color: #c9906d32; }
.foil i {
  position: absolute;
  width: 1rem;
  aspect-ratio: 1;
  translate: -50% -50%;
  background: #ffe2b5;
  filter: drop-shadow(0 0 6px #dc9d67);
  clip-path: polygon(50% 0%, 59% 40%, 100% 50%, 59% 60%, 50% 100%, 41% 60%, 0% 50%, 41% 40%);
}
.foil i:nth-child(1) { top: 30%; left: 49%; }
.foil i:nth-child(2) { top: 47%; left: 28%; }
.foil i:nth-child(3) { top: 45%; left: 70%; }
.foil i:nth-child(4) { top: 67%; left: 54%; }
.foil i:nth-child(5) { top: 54%; left: 61%; width: .63rem; }
.eyebrow { color: var(--copper); text-transform: uppercase; letter-spacing: .21em; font-size: .78rem; font-weight: 650; }
.gate h1 { margin: .7rem 0 2rem; font: 400 clamp(2.4rem, 5.8vw, 5.7rem)/.97 Georgia, serif; letter-spacing: -.045em; text-wrap: balance; }
.gate label { display: block; color: var(--soft); margin-bottom: .35rem; }
.unlock-fields { display: flex; gap: .6rem; max-width: 25rem; }
.unlock-fields input { flex: 1; }
.status { color: var(--soft); min-height: 1.5em; }
#reader { max-width: 110rem; margin-inline: auto; padding: 0 clamp(.6rem, 3vw, 2rem) 2rem; }
.reader-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .65rem; margin: 1rem 0; }
.reader-bar h1 { margin: 0; font: 400 clamp(1.3rem, 3vw, 2.1rem)/1.2 Georgia, serif; overflow-wrap: anywhere; }
.tools { display: flex; flex-wrap: wrap; gap: .35rem; font-size: .89rem; align-items: center; }
#import:focus-visible + button, .tools:has(#import:focus-visible) .file-button { outline: 2px solid #ffd3a9; outline-offset: 4px; }
.theatre {
  --view-height: clamp(22rem, 71dvh, 60rem);
  --zoom: 1;
  --ratio: .666667;
  --columns: 2;
  --book-width: min(calc((100vw - 2.4rem) / var(--columns)), calc(var(--view-height) * var(--ratio)));
  position: relative;
  overflow: auto;
  border: 1px solid #ad856d33;
  border-radius: 14px;
  background: radial-gradient(ellipse at 50% 33%, #46312a, #18121b 76%);
  overscroll-behavior: contain;
  max-height: calc(var(--view-height) + 2rem);
  touch-action: pan-y pinch-zoom;
}
.theatre[data-single="true"] { --columns: 1; }
.desk {
  display: grid;
  place-items: center;
  min-width: 100%;
  width: max-content;
  min-height: calc(var(--view-height) + 1rem);
  padding: .5rem;
}
.book {
  --leaf-width: calc(var(--book-width) * var(--zoom));
  --leaf-height: calc(var(--leaf-width) / var(--ratio));
  position: relative;
  width: calc(var(--leaf-width) * var(--columns));
  height: var(--leaf-height);
  perspective: calc(var(--leaf-width) * 4);
  isolation: isolate;
}
.leaves { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--columns), minmax(0, 1fr)); }
.page {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--paper, #fffdf7);
  color: var(--ink, #28211d);
  box-shadow: 0 14px 25px #0008, 0 0 1px #4c3727;
}
.page > canvas, .page > img { display: block; width: 100%; height: 100%; object-fit: contain; }
.page > canvas { object-position: center; }
.page[data-side="left"] { border-radius: 4px 0 0 4px; }
.page[data-side="right"] { border-radius: 0 4px 4px 0; }
.page[data-side="left"]::after, .page[data-side="right"]::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.page[data-side="left"]::after { background: linear-gradient(90deg, transparent 94%, #30211a2a); }
.page[data-side="right"]::after { background: linear-gradient(90deg, #30211a35, transparent 6%); }
.page[data-cover="true"] { border-radius: 3px 6px 6px 3px; box-shadow: 3px 2px #8a6e5a, 6px 4px #48352f, 0 18px 36px #000b; }
.page[data-cover="true"]::after { background: linear-gradient(90deg, #0003, transparent 5%, transparent 96%, #ffffff12); }
.theatre[data-theme="paper"] .page:not([data-cover="true"]) canvas { filter: sepia(.22) brightness(.98); }
.theatre[data-theme="night"] .page:not([data-cover="true"]) canvas { filter: invert(.9) hue-rotate(180deg); }
.theatre[data-theme="contrast"] .page:not([data-cover="true"]) canvas { filter: contrast(1.28); }
.theatre[data-theme="custom"] .page:not([data-cover="true"]) canvas { mix-blend-mode: multiply; }
.readable {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: clamp(.8rem, 5%, 2.6rem);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overscroll-behavior: contain;
  font: var(--text-size, 18px)/var(--line-space, 1.65) var(--text-face, Georgia, serif);
}
.theatre, .readable {
  scrollbar-width: none;
}
.theatre::-webkit-scrollbar, .readable::-webkit-scrollbar {
  display: none;
}
.book[data-pose="front"] .leaves, .book[data-pose="back"] .leaves { width: var(--leaf-width); left: 50%; translate: -50% 0; grid-template-columns: 1fr; }
.paper-canvas, .paper-leaf { position: absolute; z-index: 3; pointer-events: none; }
.paper-canvas { top: 50%; left: 50%; translate: -50% -50%; }
.paper-leaf { top: 0; left: 50%; height: 100%; transform-style: preserve-3d; }
.paper-face { position: absolute; inset: 0; overflow: hidden; backface-visibility: hidden; border-radius: var(--edge-round, 0); }
.paper-face + .paper-face { transform: rotateY(180deg); }
.paper-face .page { height: 100%; box-shadow: none; }
.paper-light {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #3a2524, #291a1700 36%, #ffffff44 64%, #372927);
  opacity: var(--curl-shade, 0);
  pointer-events: none;
}
.reader-nav { display: flex; gap: .65rem; justify-content: center; align-items: center; margin-top: .8rem; }
.jump { display: flex; align-items: center; gap: .4rem; color: var(--soft); }
.jump input { width: 4.6rem; text-align: center; }
#reader-status { text-align: center; margin: .4rem 0 .65rem; }
.bookmarks { max-width: 66rem; margin: auto; padding: 1rem 0 .2rem; border-top: 1px solid #ad856d44; }
.bookmark-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.bookmark-heading h2, dialog h2 { font: 400 1.4rem/1.1 Georgia, serif; margin: 0; }
.bookmark-heading span { color: var(--soft); font-size: .86rem; }
#slots { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(10rem,100%),1fr)); gap: .5rem; list-style: none; margin: .75rem 0 0; padding: 0; }
#slots li { display: flex; align-items: stretch; min-width: 0; }
#slots button:first-child { flex: 1; text-align: left; min-width: 0; padding: .4rem .53rem; }
#slots button span { display: block; font-size: .8rem; color: var(--soft); }
#slots .remove { padding: .4rem .52rem; margin-left: .18rem; }
#slots .saved { border-color: #a47d63; }
.sr-only { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
dialog {
  width: min(calc(100% - 1.6rem), 32rem);
  max-height: min(85dvh, 48rem);
  margin: auto;
  padding: 1rem 1.15rem;
  background: #1d1820;
  color: var(--text);
  border: 1px solid #ae816b;
  border-radius: 12px;
  box-shadow: 0 24px 70px #000a;
}
dialog::backdrop { background: #08060bd6; }
dialog > header { display: flex; justify-content: space-between; align-items: center; }
dialog form { margin: 0; }
.setting-list { display: grid; gap: .3rem; margin: .85rem 0; }
.setting-list label { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.dialog-note { color: var(--soft); font-size: .87rem; }
.search-form { display: flex; gap: .5rem; margin-top: .75rem; }
.search-form input { flex: 1; }
.link-list { list-style: none; margin: .5rem 0; padding: 0; display: grid; gap: .4rem; }
.link-list button { width: 100%; text-align: left; overflow-wrap: anywhere; }
.link-list span { font-size: .87rem; color: var(--soft); display: block; }
body.focus-reader .masthead, body.focus-reader .bookmarks { display: none; }
body.focus-reader .theatre { --view-height: 82dvh; }
@media (max-width: 740px) {
  .gate { grid-template-columns: 1fr; align-content: center; gap: 1.15rem; }
  .gate-art { width: min(54vw, 14rem); margin: 0 auto; }
  .gate h1 { margin-bottom: 1.4rem; }
  #slots { grid-template-columns: repeat(2, 1fr); }
  .theatre { --view-height: 65dvh; }
  .masthead { gap: .55rem; }
  .room-label { padding-left: .6rem; }
}
@media (max-width: 360px) {
  .reader-nav { gap: .35rem; }
  .reader-nav button { padding-inline: .45rem; }
  .jump input { width: 3.6rem; }
}
.turn-underlay { position: absolute; top: 0; height: var(--leaf-height); width: var(--leaf-width); z-index: 2; pointer-events: none; }
.resume { display: flex; justify-content: center; }
.resume:has(button:not([hidden])) { margin: .35rem 0 .8rem; }
.vr-status:empty { display: none; }
.vr-status { margin: .4rem 0 .75rem; }

.room-switch { margin-left: auto; }
.room-switch a { text-underline-offset: .2em; white-space: nowrap; }
.masthead .quiet { margin-left: 0; white-space: nowrap; }
.public-choice { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem 1rem; margin-top: .9rem; }
.public-choice span { color: var(--soft); font-size: .875rem; }
a.file-button { display: inline-block; text-decoration: none; }
@media (max-width: 570px) {
  .masthead { flex-wrap: wrap; }
  .room-switch { margin-left: auto; }
}

.room-music {
  width: fit-content;
  max-width: 100%;
  margin: 0 0 .75rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #1f1922;
}
.room-music summary {
  padding: .5rem .9rem;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 650;
  color: var(--copper);
}
.room-music[open] { width: 100%; }
.music-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem 1rem;
  padding: .3rem .85rem .8rem;
}
.track-display { display: grid; min-width: min(12rem,100%); }
.track-display span, .music-panel a { font-size: .85rem; }
.track-display span { color: var(--soft); }
.transport { display: flex; gap: .35rem; }
.transport button { min-width: 4.2rem; }
.music-volume { display: flex; gap: .4rem; align-items: center; font-size: .86rem; }
.music-volume input { width: 5.4rem; }

.cover-in-motion .leaves { visibility: hidden; }
.cover-block, .hinged-board {
  position: absolute; left: 50%; top: 0; height: 100%; pointer-events: none;
}
.cover-block {
  overflow: hidden;
  box-shadow: 0 2px #dbccb6, 0 3px #978472, 1px 5px #c2aa90, 1px 7px #4a322c, 2px 13px 25px #0007;
}
.cover-shadow { position: absolute; inset: 0; }
.hinged-board {
  --thickness: clamp(2px,.38vw,4px);
  transform-style: preserve-3d;
  z-index: 2;
}
.board-panel {
  position: absolute; inset: 0; overflow: hidden; backface-visibility: hidden;
  border-radius: 2px; background: #ded1b8;
}
.board-panel .page { height: 100%; box-shadow: none; }
.board-panel.outside { transform: translateZ(var(--thickness)); }
.board-panel.inside { transform: rotateY(180deg); }
.board-panel::after {
  content: ''; position: absolute; inset: 0; opacity: var(--board-light);
  background: linear-gradient(115deg,#fff2d91f,transparent 42%,#22131038);
}
.board-edge {
  position: absolute; top: 0; height: 100%; width: var(--thickness);
  transform-origin: left center; transform: rotateY(-90deg);
  background: linear-gradient(to right,#513729,#b69a76,#624937);
}

.ambience-library { display:grid;grid-template-columns:repeat(auto-fit,minmax(min(15rem,100%),1fr));gap:.75rem 1rem;margin:.3rem .85rem .8rem;padding:.75rem 0;border:0;border-bottom:1px solid var(--border); }
.ambience-library legend { color:var(--copper);font:1.45rem Georgia,serif; }
.ambience-library label { display:grid;gap:.35rem;font-size:.9rem;align-content:start; }
.ambience-library select { width:100%;min-width:0;padding:.6rem;color:inherit;background:#34252b;border:1px solid #93725d;border-radius:.45rem; }
.ambience-library input { width:100%;accent-color:var(--copper); }
#room-scene-status:empty { display:none; }

.page .printed-link {position:absolute;z-index:1;padding:0;min-height:0;min-width:0;background:transparent;border:0;border-radius:0;color:transparent;font-size:0;}
.page .printed-link:hover,.page .printed-link:focus-visible {background:#ce92452b;outline:1px solid #916137;}
.readable .chapter-jump {display:block;padding:.3em 0;background:none;color:inherit;border:0;text-align:start;text-decoration:underline;font:inherit;}

[data-reader-controls] {transition:opacity 280ms ease;}
body.reading-controls-idle:has(#reader:not([hidden])) [data-reader-controls]:not(:has(:focus-visible)):not(:focus-visible) {opacity:0;pointer-events:none;}
@media(prefers-reduced-motion:reduce) { [data-reader-controls] {transition:none;} }

@media (hover:hover) { body.reading-controls-idle #reader #cover-actions:has(button:hover) {opacity:1;pointer-events:auto;} }

#room-chart-note { grid-column: 1 / -1; color: var(--soft); line-height: 1.45; }

#ai-scene { grid-column: 1 / -1; color: var(--soft); }
#ai-ambience[aria-pressed=true] { border-color: var(--copper); }

.reader-dock { position:sticky; bottom:0; z-index:4; max-height:45dvh; overflow:auto;
  padding:.35rem .75rem max(.5rem,env(safe-area-inset-bottom)); background:#171219f5;
  border-top:1px solid var(--border); }
.reader-dock .tools { justify-content:center; }
.reader-dock .room-switch { display:inline-flex; margin:.35rem .7rem .25rem 0; }
