:root {
  --ink: #2b1a10;
  --ink-soft: #5a3e2b;
  --oxblood: #7a1f1a;
  --gold: #c9a24a;
  --gold-hi: #f1d58a;
  --wood: #1c120b;
  --bar: 76px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--wood); color: var(--ink); }
body {
  font-family: "IM Fell English", Georgia, "Times New Roman", serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; }

/* ---------- the filmed desk ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, #3a2414, #120b06 75%); }
/* world = one 1920x1080 video frame; JS scales and moves it like a camera */
#world { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; transform-origin: 0 0; }
#world.glide { transition: transform 2.4s cubic-bezier(.45, 0, .25, 1); }
.clip { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .22s linear; pointer-events: none; }
.clip.on { opacity: 1; }
.clip.top { z-index: 1; }
#vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse 75% 70% at 50% 46%, transparent 62%, rgba(10,5,2,.6)); }

/* the printed pages sit on the blank paper in the film. #ink hides them, frame by frame, wherever the
   film moves (turning paper, hands, the cover), using a mask sprite measured from the clip */
#ink { position: absolute; inset: 0; z-index: 2; mix-blend-mode: multiply; opacity: 0; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; }
#ink.show { opacity: 1; }
#ink.fade { transition: opacity .45s ease; }
.page { position: absolute; top: 88px; height: 862px; width: 520px; container-type: size; overflow: hidden; }
.page.left { left: 398px; }
.page.right { left: 1000px; }
.single .page.left { display: none; }

#opener {
  position: absolute; left: 50%; bottom: calc(var(--bar) + 2vh); transform: translateX(-50%);
  border: 0; background: none; cursor: pointer; padding: 10px 24px; z-index: 5;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #f6dfa6; text-shadow: 0 2px 8px #000, 0 0 20px rgba(0,0,0,.8);
  transition: opacity .6s;
}
#opener .o-the { font-family: "IM Fell English SC", serif; letter-spacing: .3em; font-size: clamp(14px, 1.6vw, 20px); }
#opener .o-main { font-family: "UnifrakturMaguntia", serif; font-size: clamp(38px, 5.4vw, 72px); line-height: 1; color: #f3d48a; }
#opener .o-tap { font-style: italic; font-size: clamp(15px, 1.6vw, 20px); margin-top: 8px; animation: breathe 2.2s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .45 } }
.opened #opener { opacity: 0; pointer-events: none; }
body:not(.single) #opener { left: 23%; top: 34%; bottom: auto; gap: 6px; }
body:not(.single) #opener .o-main { font-size: clamp(44px, 6.4vw, 104px); text-align: center; line-height: .95; max-width: 6em; }
.og #bar, .og #opener .o-tap { display: none; }

/* ---------- page content ---------- */
.pg { position: absolute; inset: 0; padding: 4cqh 5cqw 6.5cqh; display: flex; flex-direction: column; color: var(--ink); }
.pnum { position: absolute; bottom: 1.4cqh; left: 0; right: 0; text-align: center; font-size: 2.2cqh; color: var(--ink-soft); font-style: italic; }

.illus { justify-content: center; align-items: center; gap: 2cqh; }
.frame { width: 100%; flex: 1 1 auto; min-height: 0; position: relative; padding: 1.6cqw; border: 2px solid rgba(90, 50, 20, .75); outline: 1px solid rgba(90, 50, 20, .5); outline-offset: 4px; }
.frame img { display: block; width: 100%; height: 100%; object-fit: cover; }
.caption { text-align: center; font-style: italic; font-size: 2.5cqh; line-height: 1.3; color: var(--ink-soft); max-width: 92%; }
.chap { font-family: "IM Fell English SC", serif; letter-spacing: .14em; font-size: 2.3cqh; color: var(--oxblood); text-align: center; }

.text { gap: 1.1cqh; }
.text .chap { margin-bottom: -.4cqh; }
.text h2, .combo h2 { margin: 0; font-family: "IM Fell English SC", serif; font-weight: 400; font-size: 3.7cqh; line-height: 1.08; text-align: center; color: var(--ink); }
.tick { text-align: center; font-size: 2.3cqh; color: var(--oxblood); letter-spacing: .08em; }
.rule { flex: 0 0 auto; height: 1.6cqh; background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 12'%3E%3Cpath d='M0 6h80M120 6h80' stroke='%237a1f1a' stroke-width='1'/%3E%3Cpath d='M100 1l5 5-5 5-5-5z' fill='%237a1f1a'/%3E%3Ccircle cx='86' cy='6' r='1.6' fill='%237a1f1a'/%3E%3Ccircle cx='114' cy='6' r='1.6' fill='%237a1f1a'/%3E%3C/svg%3E"); opacity: .85; }
.tale { flex: 1 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: none; font-size: var(--fs, 2.06cqh); line-height: 1.36; text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
.tale::-webkit-scrollbar { display: none; }
.tale p { margin: 0 0 .5em; text-indent: 1.2em; }
.tale p:first-child { text-indent: 0; }
.tale p:first-child::first-letter { float: left; font-family: "IM Fell English SC", serif; font-size: 3.15em; line-height: .82; padding: .06em .1em 0 0; color: var(--oxblood); }
.tale .s { transition: background-color .35s, color .35s; border-radius: 3px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.tale .s.now { background: rgba(214, 170, 70, .45); color: #1d0f06; }

.facts { flex: 0 0 auto; display: grid; grid-template-columns: auto 1fr; gap: .15em .7em; font-size: 1.9cqh; line-height: 1.25; padding: 1cqh 1.5cqw; border-top: 1px solid rgba(122,31,26,.55); border-bottom: 1px solid rgba(122,31,26,.55); }
.facts dt { font-family: "IM Fell English SC", serif; color: var(--oxblood); white-space: nowrap; }
.facts dd { margin: 0; }

/* single page (phones): picture on top, tale below, all on the right page */
.combo { padding: 3.5cqh 4cqw 5.5cqh; gap: 1cqh; }
.combo .frame { flex: 0 0 30cqh; padding: 1.2cqw; }
.combo .frame img { object-position: 50% 40%; }
.combo h2 { font-size: 3.6cqh; }
.combo .tick { font-size: 2.1cqh; }
.combo .scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: none; display: flex; flex-direction: column; gap: 1cqh; -webkit-mask-image: linear-gradient(#000 88%, transparent); mask-image: linear-gradient(#000 88%, transparent); padding-bottom: 3cqh; }
.combo .scroll::-webkit-scrollbar { display: none; }
.combo .tale { --fs: 2.75cqh; overflow: visible; flex: 0 0 auto; text-align: left; hyphens: manual; }
.combo .facts { font-size: 2.3cqh; }

/* title, foreword, contents */
.titlepg { justify-content: center; align-items: center; text-align: center; gap: 2cqh; }
.titlepg .t1 { font-family: "IM Fell English SC", serif; font-size: 3.2cqh; letter-spacing: .3em; color: var(--ink-soft); }
.titlepg .t2 { font-family: "UnifrakturMaguntia", serif; font-size: 9.5cqh; line-height: .95; color: var(--oxblood); }
.titlepg .t3 { font-style: italic; font-size: 2.7cqh; line-height: 1.35; max-width: 84%; }
.titlepg .orn { width: 44%; aspect-ratio: 1; background: center / contain no-repeat url(/assets/emblem.webp); }
.titlepg .t4 { font-family: "IM Fell English SC", serif; font-size: 2.1cqh; letter-spacing: .12em; color: var(--ink-soft); }
.plate { justify-content: center; align-items: center; gap: 3cqh; text-align: center; }
.plate .orn { width: 70%; aspect-ratio: 1; background: center / contain no-repeat url(/assets/emblem.webp); }
.plate .motto { font-style: italic; font-size: 2.8cqh; line-height: 1.4; max-width: 80%; color: var(--ink-soft); }
.toc h2 { margin: 0 0 1cqh; text-align: center; font-family: "IM Fell English SC", serif; font-weight: 400; font-size: 4.2cqh; color: var(--oxblood); }
.toc ol { list-style: none; margin: 0; padding: 0; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: space-between; }
.toc li button { all: unset; cursor: pointer; display: flex; align-items: baseline; gap: .4em; width: 100%; font-size: 2.35cqh; line-height: 1.45; }
.toc li button:focus-visible { outline: 2px solid var(--oxblood); }
.toc .dots { flex: 1; min-width: 1em; border-bottom: 1.5px dotted rgba(90,62,43,.6); transform: translateY(-.25em); }
.toc .tk { color: var(--oxblood); font-family: "IM Fell English SC", serif; }
.toc .nm { font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 64%; }
.single .toc li button { font-size: 2.6cqh; min-height: 4cqh; }

/* ---------- controls ---------- */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--bar);
  display: flex; justify-content: center; align-items: center; gap: clamp(10px, 3vw, 22px);
  padding-bottom: env(safe-area-inset-bottom);
  background: linear-gradient(to top, rgba(10,5,2,.85), rgba(10,5,2,0));
  z-index: 40; transition: opacity .6s;
}
.btn {
  width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #f3d98f, #b98a35 55%, #6d4a17);
  box-shadow: 0 3px 8px rgba(0,0,0,.6), inset 0 -2px 3px rgba(0,0,0,.35), inset 0 1px 2px rgba(255,255,220,.7);
}
.btn:active { transform: translateY(1px) scale(.97); }
.btn:disabled { filter: grayscale(.7) brightness(.6); cursor: default; }
.btn svg { width: 26px; height: 26px; fill: none; stroke: #3a2208; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
#bSound .x { display: none; }
#bSound[aria-pressed="false"] .w1, #bSound[aria-pressed="false"] .w2 { display: none; }
#bSound[aria-pressed="false"] .x { display: inline; }
#bAuto .play { fill: #3a2208; stroke: none; }
#bAuto[aria-pressed="true"] { background: radial-gradient(circle at 35% 30%, #ffe9a8, #e0aa3e 55%, #8a5a12); box-shadow: 0 0 14px rgba(255,200,90,.8), 0 3px 8px rgba(0,0,0,.6); }
#bar.closed .btn:not(#bSound) { visibility: hidden; }
.ready #bNext { animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 22px rgba(255, 210, 110, .95), 0 3px 8px rgba(0,0,0,.6); } }

/* CA bar */
#ca[hidden] { display: none; }
#ca { position: fixed; left: 50%; top: max(10px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 45; display: flex; align-items: center; gap: 8px; max-width: calc(100vw - 24px); padding: 6px 6px 6px 12px; border-radius: 999px; background: rgba(28,14,6,.88); border: 1px solid rgba(201,162,74,.6); color: #f3dfa9; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.5); }
#ca .ca-tick { font-family: "IM Fell English SC", serif; color: var(--gold-hi); }
#ca code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
#ca button, #ca a { min-height: 44px; min-width: 56px; padding: 0 14px; border-radius: 999px; border: 0; display: grid; place-items: center; font-family: "IM Fell English SC", serif; text-decoration: none; cursor: pointer; }
#ca button { background: #f3dfa9; color: #2b1a10; }
#ca a { background: var(--oxblood); color: #fbe9bd; }

/* stream mode: no chrome */
.stream #bar, .stream #ca { display: none; }

@media (prefers-reduced-motion: reduce) { #opener .o-tap { animation: none; } }
