:root {
  --paper: #F6EFE0;
  --paper-2: #EFE5CF;
  --ink: #2A2420;
  --ink-soft: #6B5E52;
  --ribbon: #C8452C;
  --night: #22303A;
  --body: 21px;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .16 0 0 0 0 .14 0 0 0 0 .12 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper) var(--grain);
  color: var(--ink);
  font: 400 var(--body)/1.55 "Literata", Georgia, serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--ribbon); outline-offset: 3px; }
h1, h2, h3, .serif { font-family: "Fraunces", Georgia, serif; font-weight: 600; letter-spacing: -0.01em; }
[hidden] { display: none !important; }

/* ---------- shelf ---------- */
.shelf { max-width: 760px; margin: 0 auto; padding: max(28px, env(safe-area-inset-top)) 20px 60px; }
.masthead { text-align: center; padding: 28px 0 10px; }
.masthead h1 { font-size: clamp(44px, 10vw, 72px); font-weight: 800; margin: 0; line-height: 1; }
.masthead h1 span { color: var(--ribbon); }
.masthead p { margin: 12px 0 0; color: var(--ink-soft); font-style: italic; font-size: 19px; }
.shelf h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-soft); margin: 40px 0 14px; font-weight: 600; }
.spines { display: grid; gap: 12px; }
.spine {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 16px; align-items: center; text-align: left;
  padding: 12px 16px 12px 12px; min-height: 88px; width: 100%;
  border-top: 1px solid rgba(42,36,32,.18);
}
.spine:last-child { border-bottom: 1px solid rgba(42,36,32,.18); }
.spine .thumb { width: 64px; height: 64px; border-radius: 3px; background: var(--paper-2) center/cover; box-shadow: inset 0 0 0 1px rgba(42,36,32,.12); }
.spine .thumb.is-cover { height: 88px; width: 59px; margin: 0 auto; border-radius: 2px 4px 4px 2px; box-shadow: 0 2px 6px rgba(42,36,32,.25); }

/* covers, face out */
.covers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 26px 18px; }
@media (min-width: 640px) { .covers { grid-template-columns: repeat(4, 1fr); } }
.cover-card { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.cover {
  position: relative; display: block; width: 100%; aspect-ratio: 2 / 3; overflow: hidden; container-type: inline-size;
  border-radius: 2px 6px 6px 2px; background: var(--cloth, var(--night)) center/cover;
  box-shadow: 0 1px 1px rgba(42,36,32,.2), 0 10px 22px -8px rgba(42,36,32,.45);
  transition: transform .2s, box-shadow .2s;
}
.cover::after { /* the spine fold and a little sheen */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.28) 0, rgba(255,255,255,.18) 2.5%, rgba(0,0,0,.06) 5%, transparent 9%);
}
.cover-card:hover .cover { transform: translateY(-3px) rotate(-.4deg); box-shadow: 0 1px 1px rgba(42,36,32,.2), 0 18px 30px -10px rgba(42,36,32,.5); }
.cover .ct {
  position: absolute; left: 0; right: 0; top: 0; padding: 12% 10% 26%;
  font: 800 clamp(15px, 12.5cqw, 30px)/1.04 "Fraunces", Georgia, serif; letter-spacing: -.01em; text-align: center;
  color: #FBF6EA; text-shadow: 0 1px 2px rgba(0,0,0,.45), 0 0 18px rgba(0,0,0,.35);
  background: linear-gradient(rgba(20,16,14,.5), rgba(20,16,14,.18) 65%, transparent);
  text-wrap: balance;
}
.cover.plain { background-image: var(--grain); }
.cover.plain .ct { top: 50%; transform: translateY(-50%); background: none; padding: 0 12%; text-shadow: none; }
.cover-card .meta { font-size: 14px; line-height: 1.3; color: var(--ink-soft); }
.preset-cover { width: min(220px, 52vw); margin: 6px auto 0; }
.ask .lede, .ask .about { text-align: center; color: var(--ink-soft); font-size: 18px; max-width: 26em; margin: -8px auto 8px; }
.ask .about { margin: 22px auto 26px; font-size: 20px; }
.ask .about b, .ask .lede b { color: var(--ink); font-weight: 600; }
.exists { margin-top: 30px; }
.exists .lede { margin: 18px auto 22px; }
.preset-cover.small { width: min(150px, 40vw); }
#code { text-transform: uppercase; letter-spacing: .1em; }
.name-row .hint { font-size: 15px; color: var(--ink-soft); font-style: italic; margin: 10px 0 0; }
#toshelf { margin-top: 18px; }
.ask h2.under-cover { margin-top: 26px; font-size: clamp(26px, 5vw, 36px); }
.spine .t, .spine .s { display: block; }
.spine .t { font-family: "Fraunces", serif; font-weight: 600; font-size: 21px; line-height: 1.2; }
.spine .s { font-size: 15px; color: var(--ink-soft); margin-top: 2px; }
.spine .go { font-family: "Fraunces", serif; color: var(--ribbon); font-size: 16px; white-space: nowrap; }
.big-btn {
  display: block; width: 100%; margin: 44px 0 0; min-height: 68px; border-radius: 999px;
  background: var(--ink); color: var(--paper); font: 600 22px "Fraunces", serif;
}
.big-btn:active { transform: translateY(1px); }
.empty { color: var(--ink-soft); font-style: italic; }

/* ---------- questions ---------- */
.ask { max-width: 820px; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 20px 40px; min-height: 100%; display: flex; flex-direction: column; }
.ask-top { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.dots { display: flex; gap: 8px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(42,36,32,.2); }
.dots i.on { background: var(--ribbon); }
.round { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; color: var(--ink); }
.round svg { width: 26px; height: 26px; }
.ask h2 { font-size: clamp(32px, 6vw, 46px); text-align: center; margin: 18px 0 26px; line-height: 1.1; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (min-width: 700px) { .cards.six { grid-template-columns: repeat(3, 1fr); } .cards.four { grid-template-columns: repeat(4, 1fr); } }
.card {
  min-height: 132px; padding: 18px 14px; border-radius: 14px; text-align: center;
  background: #FBF6EA; box-shadow: 0 0 0 1.5px rgba(42,36,32,.16);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  transition: transform .15s, box-shadow .15s;
}
.card:hover { box-shadow: 0 0 0 2px var(--ink); }
.card:active, .card.on { transform: scale(.98); box-shadow: 0 0 0 3px var(--ribbon); }
.card .glyph { font-size: 44px; line-height: 1; }
.card .lbl { font: 600 20px/1.2 "Fraunces", serif; }
.card .sub { font-size: 14px; color: var(--ink-soft); }
.name-row { margin: 30px auto 0; width: 100%; max-width: 460px; text-align: center; }
.name-row label { display: block; font: 600 22px "Fraunces", serif; margin-bottom: 10px; }
.name-row input {
  width: 100%; min-height: 64px; border: 0; border-bottom: 2px solid var(--ink); background: transparent;
  font: 500 30px "Fraunces", serif; text-align: center; color: var(--ink); padding: 6px;
}
.name-row .big-btn { margin-top: 28px; }

/* ---------- book ---------- */
.book { position: fixed; inset: 0; display: flex; flex-direction: column; }
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 0 6px; padding-top: env(safe-area-inset-top); }
.bar .btitle { font: 600 16px "Fraunces", serif; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px; }
.ribbon-btn { position: relative; width: 56px; height: 60px; align-self: flex-start; }
.ribbon-btn::before {
  content: ""; position: absolute; top: 0; left: 18px; width: 20px; height: 46px; background: var(--ribbon);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%); transition: height .2s;
}
.ribbon-btn:hover::before { height: 54px; }
.stage { position: relative; flex: 1; overflow: hidden; perspective: 1600px; }
.leaf {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; background: var(--paper) var(--grain);
  padding: 0 20px 96px; will-change: transform, opacity;
}
.leaf-inner { max-width: 34em; margin: 0 auto; }
.pic {
  position: relative; width: 100%; aspect-ratio: 1; max-height: 52vh; margin: 4px auto 22px; display: block;
  clip-path: polygon(0.6% 1.2%, 25% 0.3%, 52% 1%, 78% 0.2%, 99.4% 0.9%, 99.8% 30%, 99.2% 62%, 99.7% 98.8%, 74% 99.6%, 47% 98.9%, 21% 99.7%, 0.4% 99.1%, 0.9% 68%, 0.2% 35%);
  background: var(--paper-2);
}
.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .6s; }
.pic img.in { opacity: 1; }
.pic .sketch { position: absolute; inset: 12%; width: 76%; height: 76%; color: rgba(42,36,32,.28); }
.pic .sketch path { stroke-dasharray: 900; stroke-dashoffset: 900; animation: draw 2.8s ease-in-out infinite alternate; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.txt p { margin: 0 0 .7em; }
.txt.dropcap p:first-child::first-letter {
  font: 800 3.4em/.8 "Fraunces", serif; float: left; margin: .08em .1em 0 0; color: var(--ribbon);
}
.folio { text-align: center; font: 400 15px "Fraunces", serif; color: var(--ink-soft); margin-top: 18px; }
.scene-title { text-align: center; font: italic 400 16px "Literata", serif; color: var(--ink-soft); margin: 2px 0 10px; }

/* landscape spread */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  .leaf { padding: 0 32px 40px; display: grid; place-items: center; overflow: hidden; }
  .leaf.page .leaf-inner {
    max-width: 1280px; width: 100%; height: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 0;
    background: linear-gradient(90deg, transparent 49.2%, rgba(42,36,32,.1) 50%, transparent 50.8%);
  }
  .leaf.page .left, .leaf.page .right { display: flex; flex-direction: column; justify-content: center; padding: 10px 40px; min-height: 0; }
  .leaf.page .right { overflow-y: auto; }
  .leaf.page .pic { max-height: min(78vh, 100%); width: auto; height: min(78vh, 46vw); margin: 0 auto; }
  .band-4-6 .book .txt { font-size: 27px; }
}

.foot-folio { display: none; }
/* portrait: the read-aloud button gets its own strip so it never covers the words */
@media not ((min-width: 900px) and (min-aspect-ratio: 5/4)) {
  .stage { margin-bottom: calc(86px + env(safe-area-inset-bottom)); }
  .no-foot .stage { margin-bottom: 0; }
  .no-foot .foot-folio { display: none; }
  .leaf { padding-bottom: 8px; }
  .leaf .folio { display: none; }
  .foot-folio { display: block; position: fixed; left: 0; right: 0; bottom: calc(38px + env(safe-area-inset-bottom)); text-align: center; font: 400 15px "Fraunces", serif; color: var(--ink-soft); pointer-events: none; }
  .stage::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 22px; z-index: 1; pointer-events: none; background: linear-gradient(transparent, var(--paper)); }
}
@media (max-width: 480px) { .band-4-6 { --body: 21px; } .band-4-6 .txt { line-height: 1.45; } .pic { margin-bottom: 14px; } }

/* read aloud */
.aloud {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 5;
  width: 64px; height: 64px; border-radius: 50%; background: var(--ink); color: var(--paper);
  display: grid; place-items: center; box-shadow: 0 0 0 4px var(--paper);
}
.aloud svg { width: 28px; height: 28px; }
.aloud.auto { box-shadow: 0 0 0 4px var(--paper), 0 0 0 7px var(--ribbon); }
.aloud.busy svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.aloud-hint { position: fixed; right: 92px; bottom: 34px; font-size: 14px; color: var(--ink-soft); font-style: italic; pointer-events: none; transition: opacity .4s; }

.edge { position: absolute; top: 0; bottom: 0; width: 18%; z-index: 2; }
.edge.l { left: 0; } .edge.r { right: 0; }
.edge:hover { background: linear-gradient(90deg, rgba(42,36,32,.035), transparent); }
.edge.r:hover { background: linear-gradient(270deg, rgba(42,36,32,.035), transparent); }
@media (max-width: 899px) { .edge { width: 14%; } }

/* choice page */
.leaf.choice .leaf-inner, .leaf.end .leaf-inner, .leaf.wait .leaf-inner { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 30px 0; }
.choice .q { font: 600 clamp(28px, 5vw, 40px)/1.18 "Fraunces", serif; text-align: center; margin: 0 0 30px; }
.choice .kicker { text-align: center; font-size: 15px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 14px; }
.slips { display: grid; gap: 14px; }
.slip {
  position: relative; text-align: left; min-height: 72px; padding: 18px 22px 18px 58px; border-radius: 4px;
  background: #FBF6EA; box-shadow: 0 1px 0 rgba(42,36,32,.12), 0 0 0 1.5px rgba(42,36,32,.14);
  font: 500 21px/1.3 "Literata", serif; transform: rotate(var(--r, 0deg)); transition: transform .15s, box-shadow .15s;
}
.slip::before { content: attr(data-n); position: absolute; left: 20px; top: 50%; transform: translateY(-50%); font: 800 22px "Fraunces", serif; color: var(--ribbon); }
.slip:hover { transform: rotate(0) translateY(-2px); box-shadow: 0 6px 16px rgba(42,36,32,.12), 0 0 0 2px var(--ink); }
.slip.taken { box-shadow: 0 0 0 3px var(--ribbon); }
.slip .mark { display: block; font-size: 14px; font-style: italic; color: var(--ribbon); margin-top: 4px; }
.slip:disabled { opacity: .45; cursor: default; transform: none; box-shadow: 0 0 0 1px rgba(42,36,32,.14); }
.leaf.night { background: var(--night) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); color: var(--paper); }
.night .kicker { color: #C9B99B; }
.night .slip { background: #2C3C48; color: var(--paper); box-shadow: 0 0 0 1.5px rgba(246,239,224,.25); }
.night .slip:hover { box-shadow: 0 0 0 2px var(--paper); }
.night .slip::before, .night .slip .mark { color: #E8826B; }
.seal {
  width: 74px; height: 74px; margin: 0 auto 18px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #E0634A, var(--ribbon) 55%, #8F2C1A);
  box-shadow: 0 3px 0 #7A2414, inset 0 0 0 5px rgba(0,0,0,.12); color: #F7D9C9; font: 800 30px "Fraunces", serif;
}
.changes { text-align: center; font-style: italic; color: #E8D9BC; margin: -14px 0 26px; }

/* waiting */
.wait { text-align: center; }
.quill { width: 120px; height: 120px; margin: 0 auto 20px; color: var(--ink); }
.quill .nib { transform-origin: 30% 90%; animation: write 1.1s ease-in-out infinite alternate; }
@keyframes write { from { transform: rotate(-6deg) translateX(-6px); } to { transform: rotate(4deg) translateX(8px); } }
.wait .line { font: italic 400 21px "Literata", serif; color: var(--ink-soft); min-height: 1.6em; transition: opacity .3s; }
.wait h2 { font-size: clamp(30px, 6vw, 44px); margin: 0 0 12px; }
.wait .retry { margin-top: 26px; }
.wait .first-note { font-size: 16px; color: var(--ink-soft); max-width: 22em; margin: 34px auto 0; opacity: .8; }
.back-link { display: block; margin: 26px auto 0; min-height: 48px; padding: 0 16px; font-size: 17px; font-style: italic; color: var(--ink-soft); }
.night .back-link { color: #C9B99B; }

/* end */
.end { text-align: center; }
.end h2 { font: 800 clamp(48px, 12vw, 84px) "Fraunces", serif; margin: 0 0 4px; }
.end .sub { color: var(--ink-soft); font-style: italic; margin-bottom: 26px; }
.end ol { list-style: none; padding: 0; margin: 0 auto 30px; max-width: 28em; text-align: left; }
.end li { padding: 10px 0 10px 36px; position: relative; border-top: 1px solid rgba(42,36,32,.15); font-size: 18px; }
.end li::before { content: ""; position: absolute; left: 6px; top: 16px; width: 16px; height: 16px; border-radius: 50%; background: var(--ribbon); }
.end li b { font-weight: 500; display: block; font-size: 15px; color: var(--ink-soft); }
.btn-row { display: grid; gap: 12px; max-width: 420px; margin: 0 auto; width: 100%; }
.ghost-btn { min-height: 60px; border-radius: 999px; box-shadow: inset 0 0 0 2px var(--ink); font: 600 20px "Fraunces", serif; }
.big-btn.inline { margin: 0; }

/* the path */
.path {
  position: fixed; inset: 0; z-index: 10; background: rgba(42,36,32,.35); display: flex; justify-content: flex-end;
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.path-panel {
  width: min(520px, 100%); height: 100%; overflow-y: auto; background: var(--paper) var(--grain);
  padding: max(20px, env(safe-area-inset-top)) 22px 60px; box-shadow: -10px 0 40px rgba(0,0,0,.18);
  animation: slidein .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes slidein { from { transform: translateX(40px); opacity: .4; } }
.path-head { display: flex; justify-content: space-between; align-items: center; }
.path-head h2 { font-size: 30px; margin: 0; }
.path-intro { color: var(--ink-soft); font-size: 16px; font-style: italic; margin: 6px 0 22px; }
.trail { position: relative; padding-left: 34px; }
.trail::before { content: ""; position: absolute; left: 13px; top: 8px; bottom: 8px; width: 3px; background: var(--ink); border-radius: 2px; }
.stop { position: relative; padding: 6px 0 16px; }
.stop::before { content: ""; position: absolute; left: -27px; top: 12px; width: 11px; height: 11px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 3px var(--paper); }
.stop .small { font-size: 15px; color: var(--ink-soft); line-height: 1.35; }
.stop .small em { color: var(--ink); font-style: normal; }
.stop.big::before { left: -33px; top: 4px; width: 26px; height: 26px; background: radial-gradient(circle at 35% 30%, #E0634A, var(--ribbon) 55%, #8F2C1A); box-shadow: 0 2px 0 #7A2414, 0 0 0 3px var(--paper); }
.stop.big .bq { font: 600 19px/1.25 "Fraunces", serif; margin-bottom: 8px; }
.road { display: block; width: 100%; text-align: left; padding: 9px 12px; margin: 6px 0; border-radius: 6px; font-size: 16px; line-height: 1.3; min-height: 44px; }
.road.taken { background: var(--ink); color: var(--paper); }
.road.other { box-shadow: inset 0 0 0 1.5px rgba(42,36,32,.35); border: 0; background-image: repeating-linear-gradient(90deg, transparent 0 6px, rgba(42,36,32,.04) 6px 12px); }
.road.other:hover { box-shadow: inset 0 0 0 2px var(--ribbon); }
.road .was { display: block; font-size: 13px; font-style: italic; color: var(--ribbon); }
.road.taken .was { color: #F0B7A8; }
.stop.here::before { background: var(--ribbon); }
.stop.here .small { color: var(--ribbon); font-style: italic; }

/* confirm */
.confirm { position: fixed; inset: 0; z-index: 20; background: rgba(42,36,32,.45); display: grid; place-items: center; padding: 20px; animation: fade .15s; }
.confirm-box { background: var(--paper) var(--grain); max-width: 440px; width: 100%; border-radius: 14px; padding: 28px 24px 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.confirm-box h3 { font-size: 26px; margin: 0 0 8px; }
.confirm-box p { margin: 0 0 22px; color: var(--ink-soft); font-size: 18px; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 30; background: var(--ink); color: var(--paper); padding: 12px 20px; border-radius: 999px; font-size: 16px; max-width: calc(100% - 32px); text-align: center; }

/* turns */
.turn-out-next { animation: outNext .26s ease-in forwards; transform-origin: left center; }
.turn-in-next { animation: inNext .26s ease-out; }
.turn-out-prev { animation: outPrev .26s ease-in forwards; transform-origin: right center; }
.turn-in-prev { animation: inPrev .26s ease-out; }
@keyframes outNext { to { transform: translateX(-32%) rotate(-4deg); opacity: 0; } }
@keyframes inNext { from { transform: translateX(6%); opacity: 0; } }
@keyframes outPrev { to { transform: translateX(32%) rotate(4deg); opacity: 0; } }
@keyframes inPrev { from { transform: translateX(-6%); opacity: 0; } }
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  @keyframes outNext { to { transform: rotateY(-28deg) translateX(-8%); opacity: 0; } }
  @keyframes outPrev { to { transform: rotateY(28deg) translateX(8%); opacity: 0; } }
}
@media (prefers-reduced-motion: reduce) {
  .turn-out-next, .turn-out-prev { animation: fadeout .2s forwards; }
  .turn-in-next, .turn-in-prev { animation: fade .2s; }
  @keyframes fadeout { to { opacity: 0; } }
  .pic .sketch path, .quill .nib, .aloud.busy svg { animation: none; }
}

/* age-band body sizes */
.band-4-6 { --body: 24px; }
.band-7-9 { --body: 21px; }
.band-10-12, .band-adult { --body: 19px; }
.book .txt { font-size: var(--body); }
