/* The Night Library: shared look for the interactive story books. One page at a time, warm parchment under a
   midnight-blue bar that carries the golden word (one letter per solved puzzle). Matches the printed books:
   Andika for reading, Poppins ExtraBold for titles, Patrick Hand for Mira's logbook. */
:root {
  --ink: #22223A; --paper: #F7F0E1; --parch: #EFE3C4; --night: #1B2140; --night2: #262E57; --night3: #333C6E;
  --brass: #C99A2E; --brass-d: #8F6A1C; --brass-l: #E8C766; --glow: #FFE9A8; --lamp: #2F6B4F; --lamp-d: #224E3A; --lamp-l: #4E9A73;
  --ember: #B5452F; --ember-d: #8C3322; --teal: #3E8E91; --pen: #22306B; --desk: #E4DCCB; --line: #E2D6BF; --rule: #DDE2EE;
  --muted: #5F6377; --gray: #8A8FA3; --green: #2E8B57; --red: #C0392B;
  --f-body: "Andika", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --f-display: "Poppins", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --f-hand: "Patrick Hand", "Comic Sans MS", "Segoe Print", cursive;
  --f-greek: "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--desk); color: var(--ink); font-family: var(--f-body); font-size: 19px; line-height: 1.65; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 800; line-height: 1.15; text-wrap: balance; margin: 0; letter-spacing: -.005em; }
a { color: var(--lamp); }
.art { width: 100%; max-width: 100%; height: auto; display: block; }
.greek { font-family: var(--f-greek); }

/* top bar: the golden word */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--night); color: #fff;
  padding-block: 9px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.topbar-in { max-width: 980px; margin: 0 auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { display: grid; line-height: 1; color: #fff; text-decoration: none; }
.brand small { font-size: 10px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: var(--brass-l); }
.brand span { font-family: var(--f-display); font-weight: 800; font-size: 20px; letter-spacing: .01em; }
.slots { display: flex; gap: 4px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.slots .lbl { font-size: 12px; font-weight: 700; color: #C9CDEA; margin-right: 4px; letter-spacing: .06em; text-transform: uppercase; }
.slot { width: 26px; height: 30px; border-radius: 5px; border: 2px dashed #6F77A8; display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 17px; color: var(--night); }
.slot.full { border: 2px solid var(--brass); background: var(--glow); box-shadow: 0 0 10px rgba(255, 220, 140, .45); }
.tools { display: flex; gap: 6px; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--night3); color: #fff; display: grid; place-items: center; }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn[aria-pressed="true"] { background: var(--lamp); }
.iconbtn.off { opacity: .55; }

/* stage and pages */
.stage { padding-block: 22px 120px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.screen { max-width: 900px; margin: 0 auto; background: var(--paper); border-radius: 8px 22px 22px 8px; box-shadow: 0 1px 0 #D2C6A9, 0 12px 30px rgba(27,33,64,.16);
  overflow: hidden; animation: pageIn .45s ease both; position: relative; }
@keyframes pageIn { from { opacity: .3; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.band { background: var(--night); color: #fff; padding: 18px 26px 20px; position: relative; overflow: hidden; }
.band.puzzle { background: var(--lamp); }
.band .eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--brass-l); }
.band.puzzle .eyebrow { color: #FFE9A8; }
.band h1 { font-size: clamp(26px, 4.2vw, 36px); margin-top: 2px; }
.band .bandart { position: absolute; right: 10px; top: -6px; width: 92px; opacity: .16; }
.body { padding: 24px 26px 30px; display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.lead { margin: 0; max-width: 64ch; }
.small { font-size: 15px; color: var(--muted); }
.label { font-size: 14px; color: var(--muted); margin: 0 0 6px; font-weight: 700; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.center { text-align: center; justify-items: center; }
.split { display: grid; gap: 24px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .split { grid-template-columns: 1.2fr 1fr; align-items: start; } .split.even { grid-template-columns: 1fr 1fr; } }
.split > * { min-width: 0; }
.col { display: grid; gap: 14px; align-content: start; min-width: 0; }

/* chapter pages */
.chapter .opener { padding: 22px 26px 0; display: grid; gap: 10px; justify-items: center; text-align: center; }
.chapter .opener .artbox { width: 100%; max-width: 640px; border-radius: 14px; overflow: hidden; }
.chapter .chnum { font-size: 13px; font-weight: 700; letter-spacing: .18em; color: var(--brass-d); text-transform: uppercase; margin-top: 6px; }
.chapter .opener h1 { font-size: clamp(28px, 4.6vw, 40px); color: var(--night); }
.story { padding: 18px 26px 30px; display: grid; justify-items: center; }
.story .text { max-width: 60ch; width: 100%; }
.story p { margin: 0 0 .8em; }
.story p.first::first-letter { font-family: var(--f-display); font-weight: 800; float: left; font-size: 3.2em; line-height: .85; color: var(--brass-d); padding: .06em .1em 0 0; }
.story p.big { font-family: var(--f-display); font-weight: 800; font-size: 1.4em; text-align: center; letter-spacing: .08em; color: var(--brass-d); }
.story .orn { display: flex; justify-content: center; gap: 14px; margin: 6px 0 18px; }
.story .orn svg { width: 14px; height: 14px; }
.story .orn svg:nth-child(2) { width: 18px; height: 18px; }
.story .vig { max-width: 340px; margin: 10px auto 0; opacity: .95; }
.stopnote { justify-self: center; background: var(--ember); color: #fff; font-weight: 700; padding: 12px 22px; border-radius: 8px; transform: rotate(-1.5deg);
  box-shadow: 3px 4px 0 rgba(0,0,0,.1); margin-top: 8px; text-align: center; }
.theend { font-family: var(--f-display); font-weight: 800; color: var(--brass-d); font-size: 32px; text-align: center; margin: 10px 0 0; }

/* speech: a small face and a bubble */
.say { display: flex; align-items: flex-end; gap: 10px; }
.say .face { width: 64px; height: 80px; flex: none; }
.say .face svg { width: 100%; height: 100%; }
.bubble { position: relative; background: #E6EFE9; color: var(--ink); border-radius: 18px 18px 18px 4px; padding: 10px 16px; margin: 0; max-width: 56ch; font-size: 17px; }
.say.mira .bubble { background: #FBEBD6; } .say.dewey .bubble { background: #F5EBCB; } .say.smudge .bubble { background: #E4E0EF; font-style: italic; }
.bubble b.who { display: block; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--lamp); }
.say.mira .bubble b.who { color: #B0611B; } .say.dewey .bubble b.who { color: var(--brass-d); }
.bubble.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.94); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }

/* papers found in the story */
.papyrus { background: #EADBB0; border-radius: 4px; padding: 18px 24px; position: relative; box-shadow: 4px 5px 0 rgba(0,0,0,.08);
  background-image: repeating-linear-gradient(0deg, rgba(160,130,70,.12) 0 1px, transparent 1px 5px); font-family: var(--f-hand); font-size: 21px; line-height: 1.4; color: var(--pen); }
.papyrus::before, .papyrus::after { content: ""; position: absolute; top: -4px; bottom: -4px; width: 12px; border-radius: 6px; background: #D6C59C; }
.papyrus::before { left: -6px; } .papyrus::after { right: -6px; }
.papyrus p { margin: 0 0 .4em; }
.card { background: #fff; border-radius: 12px; padding: 14px 16px; box-shadow: 0 1px 0 var(--line); }
.tilt-l { transform: rotate(-1deg); } .tilt-r { transform: rotate(1deg); }

/* Mira's logbook: the answer card */
.notebook { background: #fff; border: 1px solid var(--rule); border-radius: 10px; padding: 30px 18px 16px; display: grid; gap: 10px; position: relative; margin-top: 14px;
  background-image: linear-gradient(transparent 31px, #E8EBF3 31px); background-size: 100% 32px; background-position: 0 22px; }
.notebook .tab { position: absolute; left: 14px; top: -14px; background: var(--lamp); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; padding: 4px 12px; border-radius: 6px; }
.notebook .q { margin: 0; font-weight: 700; max-width: 62ch; }
.nb-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.nb-input { border: 0; border-bottom: 3px dashed var(--pen); background: transparent; font-family: var(--f-hand); font-size: 28px; color: var(--pen); padding: 2px 6px; min-width: 0; width: min(100%, 340px); letter-spacing: .03em; }
.nb-input.short { width: 140px; text-align: center; }
.nb-input.ok { border-bottom: 3px solid var(--green); color: var(--green); }
.nb-input:focus { outline: none; background: #FFFBEA; }
.feedback { margin: 0; font-weight: 700; min-height: 1.5em; }
.feedback.good { color: var(--green); } .feedback.bad { color: var(--red); }
.stamp { position: absolute; right: 16px; top: 8px; font-family: var(--f-display); font-weight: 800; color: var(--brass-d); border: 3px solid var(--brass); border-radius: 8px; padding: 0 10px; font-size: 18px; letter-spacing: .08em;
  transform: rotate(-10deg); opacity: 0; pointer-events: none; background: var(--glow); }
.solved .stamp, .notebook.done .stamp { opacity: .92; animation: stampIn .35s ease both; }
@keyframes stampIn { from { transform: rotate(-10deg) scale(1.8); opacity: 0; } to { transform: rotate(-10deg) scale(1); opacity: .92; } }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* hints */
.hints { display: grid; gap: 10px; }
.btn.hintbtn { background: #fff; color: var(--brass-d); box-shadow: inset 0 0 0 2px var(--brass); justify-self: start; }
.btn.hintbtn svg { width: 18px; height: 26px; }
.btn.hintbtn.nudge { animation: nudge 1s ease 3; }
@keyframes nudge { 50% { transform: scale(1.06); } }
.hint-item { animation: pageIn .3s ease both; }

/* buttons */
.btn { border: 0; border-radius: 14px; padding: 12px 22px; min-height: 50px; font-weight: 700; background: var(--ember); color: #fff;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center; box-shadow: 0 3px 0 var(--ember-d); text-decoration: none; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ember-d); }
.btn.lamp { background: var(--lamp); box-shadow: 0 3px 0 var(--lamp-d); }
.btn.night { background: var(--night2); box-shadow: 0 3px 0 #121732; }
.btn.brass { background: var(--brass-l); color: var(--ink); box-shadow: 0 3px 0 var(--brass-d); }
.btn.ghost { background: transparent; color: var(--night); box-shadow: inset 0 0 0 2px var(--line); }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: 16px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* shared widgets */
.scene { position: relative; background: var(--parch); border-radius: 16px; overflow: hidden; touch-action: manipulation; }
.scene svg { width: 100%; height: auto; display: block; }
.linputs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.linputs .sp { width: 16px; }
.linput { width: 42px; height: 48px; border-radius: 8px; border: 2px dashed var(--pen); background: #fff; text-align: center; font-family: var(--f-hand); font-size: 26px; text-transform: uppercase; color: var(--pen); }
.linput.ok { background: #E3F4EA; border: 2px solid var(--green); color: var(--green); }
.choices { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.choice { border: 3px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 14px; text-align: left; display: grid; gap: 6px; justify-items: start; }
.choice .badge { width: 36px; height: 36px; border-radius: 50%; background: var(--night2); color: #fff; display: grid; place-items: center; font-weight: 700; }
.choice[aria-pressed="true"] { border-color: var(--lamp); background: #EAF3EE; }
.choice.right { border-color: var(--green); background: #E3F4EA; }
.choice.wrong { border-color: var(--red); background: #FBE9E5; }
.dials { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.dial { display: grid; justify-items: center; gap: 4px; }
.dial button { width: 56px; height: 34px; border-radius: 10px; border: 0; background: var(--night2); color: #fff; font-size: 18px; line-height: 1; }
.dial output { width: 64px; height: 70px; border-radius: 10px; background: #fff; border: 4px solid var(--brass); display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 34px; color: var(--ink); }
.dial small { font-weight: 700; color: var(--brass-d); font-size: 13px; }
.gridbox { overflow-x: auto; }
.chart { width: 100%; border-collapse: collapse; font-size: 16px; background: #fff; }
.chart th, .chart td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.chart th { background: var(--night2); color: #fff; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 44px; height: 44px; border-radius: 10px; border: 0; background: var(--night2); color: #fff; font-size: 22px; font-weight: 700; }
.stepper output { font-family: var(--f-display); font-weight: 800; font-size: 28px; min-width: 52px; text-align: center; }
details.peek { background: var(--parch); border-radius: 12px; padding: 10px 14px; }
details.peek summary { cursor: pointer; font-weight: 700; color: var(--lamp); }
details.peek[open] summary { margin-bottom: 10px; }

/* cover */
.cover { background: var(--night); color: #fff; }
.cover .inner { display: grid; gap: 22px; padding: 28px 26px; }
@media (min-width: 760px) { .cover .inner { grid-template-columns: 1.05fr 1fr; align-items: center; } }
.cover .coverart { border-radius: 10px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.35); max-width: 380px; justify-self: center; width: 100%; }
.cover .eyebrow { color: var(--brass-l); font-weight: 700; letter-spacing: .16em; text-transform: uppercase; font-size: 14px; }
.cover h1 { font-size: clamp(36px, 6.4vw, 58px); line-height: 1.02; }
.cover h1 span { color: var(--brass-l); display: block; font-size: .6em; margin-top: 8px; }
.cover .sub { color: #D3D6F0; margin: 0; }
.namefield { display: grid; gap: 6px; min-width: 0; }
.namefield label { font-size: 13px; font-weight: 700; color: var(--brass-l); letter-spacing: .08em; text-transform: uppercase; }
.namefield input { border-radius: 12px; border: 0; padding: 12px 14px; font-size: 22px; font-family: var(--f-hand); color: var(--pen); max-width: 360px; width: 100%; box-sizing: border-box; min-width: 0; }
.namefield.light label { color: var(--brass-d); } .namefield.light input { border: 2px solid var(--line); }

/* cast, golden word, what was real */
.cast { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.castcard { background: #fff; border-radius: 14px; padding: 12px; display: flex; gap: 12px; align-items: center; }
.castcard .ph { width: 76px; height: 76px; border-radius: 50%; background: var(--parch); overflow: hidden; flex: none; display: grid; place-items: end center; }
.castcard .ph svg { width: 70px; height: 88px; margin-bottom: -14px; }
.castcard h3 { font-size: 19px; } .castcard p { margin: 0; font-size: 15px; color: var(--muted); }
.goldword { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.goldword span { width: 40px; height: 48px; border-radius: 8px; border: 2px solid var(--brass); background: #fff; display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 26px; color: var(--brass-d); }
.goldword span.on { background: var(--glow); box-shadow: 0 0 14px rgba(255, 210, 120, .7); }
.real { display: grid; gap: 10px; } .real p { margin: 0; font-size: 17px; }

/* next book teaser and certificate */
.teaser { background: var(--night); color: #fff; border-radius: 16px; padding: 22px; display: grid; gap: 10px; justify-items: center; text-align: center; }
.teaser .eyebrow { color: var(--brass-l); font-weight: 700; letter-spacing: .14em; font-size: 13px; }
.teaser h2 { font-size: 28px; } .teaser p { margin: 0; max-width: 52ch; color: #DFE2F5; }
.cert { background: #FFF8E8; border: 10px double var(--night); border-radius: 14px; padding: 30px 22px; text-align: center; display: grid; gap: 10px; justify-items: center; position: relative; }
.cert .eyebrow { color: var(--brass-d); font-weight: 700; letter-spacing: .14em; font-size: 13px; text-transform: uppercase; }
.cert h2 { font-size: 28px; color: var(--night); } .cert h2 span { display: block; color: var(--lamp); font-size: 38px; }
.cert .who { font-family: var(--f-hand); font-size: 38px; color: var(--pen); border-bottom: 2px solid var(--night); min-width: 60%; padding: 0 10px; line-height: 1.2; }
@media (max-width: 420px) { .cert { padding: 22px 12px; } .cert h2 span { font-size: 30px; } .cert .who { font-size: 30px; } }
.cert .sigs { display: flex; gap: 34px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.cert .sigs div { display: grid; font-size: 13px; color: var(--muted); }
.cert .sigs b { font-family: var(--f-hand); font-size: 24px; font-weight: 400; color: var(--pen); border-bottom: 1px solid var(--night); padding: 0 12px; }
.cert .owl { width: 80px; }

/* pager */
.pager { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: rgba(247,240,225,.97); border-top: 1px solid var(--line);
  padding-block: 10px calc(10px + env(safe-area-inset-bottom, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.pager-in { max-width: 900px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.pager .where { flex: 1; min-width: 0; text-align: center; font-size: 14px; color: var(--muted); font-weight: 700; }
.dots { display: flex; gap: 5px; justify-content: center; margin-top: 4px; flex-wrap: wrap; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); display: block; }
.dots i.done { background: var(--brass-l); } .dots i.now { background: var(--lamp); transform: scale(1.3); }
.pager .btn { min-width: 118px; }

/* grown-ups sheet */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(20,24,50,.6); display: grid; place-items: center;
  padding-block: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.sheet-card { background: #fff; border-radius: 20px; max-width: 640px; width: 100%; max-height: 92vh; overflow: auto; padding: 22px; display: grid; gap: 16px; }
.sheet-card h2 { font-size: 24px; color: var(--night); }
.sheet-card p { margin: 0; font-size: 16px; }
.toggle { display: flex; gap: 12px; align-items: center; font-size: 16px; font-weight: 700; }
.toggle input { width: 24px; height: 24px; accent-color: var(--lamp); }
.jump { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.jump button { text-align: left; border: 0; border-radius: 10px; background: var(--parch); padding: 8px 12px; font-size: 14px; }
.answers { background: var(--parch); border-radius: 12px; padding: 12px 14px; font-size: 15px; }
.answers ol { margin: 0; padding-left: 22px; }
.holdbtn { position: relative; overflow: hidden; }
.holdbtn .fillbar { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(255,255,255,.35); }

.fly { position: fixed; z-index: 60; width: 40px; height: 46px; pointer-events: none; border-radius: 8px; border: 2px solid var(--brass); background: var(--glow);
  display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 26px; color: var(--brass-d); box-shadow: 0 0 22px rgba(255, 210, 120, .9); }

@media (max-width: 560px) {
  body { font-size: 18px; }
  .band, .body, .story, .chapter .opener { padding-left: 16px; padding-right: 16px; }
  .brand { display: none; }
  .topbar-in { flex-wrap: nowrap; gap: 8px; }
  .slots { margin-left: 0; gap: 2px; flex-wrap: nowrap; } .slots .lbl { display: none; }
  .slot { width: 20px; height: 26px; font-size: 13px; border-width: 1.5px; }
  .tools { gap: 4px; } .iconbtn { width: 40px; height: 40px; }
  .pager .btn { min-width: 0; padding: 10px 14px; }
  .dots { display: none; }
  .stamp { top: -14px; right: 8px; font-size: 15px; }
  .goldword span { width: 30px; height: 38px; font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media print {
  body.printing .topbar, body.printing .pager, body.printing .band, body.printing .namefield, body.printing .say, body.printing .row, body.printing .small { display: none !important; }
  body.printing .stage { padding: 0; } body.printing .screen { box-shadow: none; }
}
