/* Story Time — reader styles. Palette follows the vintage gouache illustrations. */
:root {
  --ink: #2b1f14;
  --ink-soft: #5d4a35;
  --paper: #f7eed6;
  --paper-deep: #eadbb6;
  --gold: #f2c832;
  --gold-deep: #c99a12;
  --brick: #b2432b;
  --forest: #1f2a1b;
  --forest-2: #34452c;
  --chrome-h: 206px;            /* top bar + controls + dots, used to size the page */
  --outline: #2a2418;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(ellipse at 50% 35%, var(--forest-2), var(--forest) 75%) fixed;
  color: var(--ink);
  font-family: 'Andika', 'Segoe UI', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
svg { width: 1em; height: 1em; }
[hidden] { display: none !important; }

.screen { height: 100vh; height: 100dvh; }

/* Display lettering like the book's "Hello": golden, dark outline, offset shadow */
.lettering {
  font-family: 'Fredoka', 'Century Gothic', sans-serif;
  font-weight: 700;
  color: var(--gold);
  text-shadow:
    -2px -2px 0 var(--outline), 2px -2px 0 var(--outline), -2px 2px 0 var(--outline), 2px 2px 0 var(--outline),
    0 -2px 0 var(--outline), 0 2px 0 var(--outline), -2px 0 0 var(--outline), 2px 0 0 var(--outline),
    4px 5px 0 var(--outline);
}

/* ---------- Bookshelf ---------- */
#library { overflow-y: auto; padding: 5vh 6vw; }
.lib-head h1 { margin: 0; font-size: clamp(2.6rem, 7vw, 4.6rem); letter-spacing: .02em; }
.lib-head p { margin: .3em 0 0; color: var(--paper); font-size: 1.3rem; opacity: .85; }
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 32px;
  margin-top: 4vh;
}
.book-card {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 10px 10px 18px;
  text-align: left;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .35), 0 16px 30px rgba(0, 0, 0, .3);
  transition: transform .15s ease;
}
.book-card:hover { transform: translateY(-4px) rotate(-.5deg); }
.book-card img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 9px; background: var(--paper-deep); }
.book-card h2 { margin: 14px 8px 2px; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.6rem; }
.book-card p { margin: 0 8px; color: var(--ink-soft); font-size: 1.1rem; }

/* ---------- Reader layout ---------- */
#reader { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px 4px; color: var(--paper); }
.topbar-title { flex: 1; text-align: center; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.2rem; opacity: .9; }
.icon-btn {
  width: 50px; height: 50px; border-radius: 50%;
  border: 2px solid rgba(247, 238, 214, .55); background: rgba(0, 0, 0, .2); color: var(--paper);
  display: grid; place-items: center; font-size: 26px;
}
.icon-btn:hover { background: rgba(0, 0, 0, .35); }

.stage { display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 6px 16px; min-height: 0; perspective: 1600px; }
.page {
  position: relative;
  aspect-ratio: 3 / 2;
  width: min(100%, calc((100vh - var(--chrome-h)) * 1.5));
  width: min(100%, calc((100dvh - var(--chrome-h)) * 1.5));
  container-type: inline-size;
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0 0 7px var(--paper), 0 0 0 9px rgba(0, 0, 0, .3), 0 22px 46px rgba(0, 0, 0, .5);
}
.page.turn-next { animation: turn-next .5s ease both; }
.page.turn-prev { animation: turn-prev .5s ease both; }
@keyframes turn-next { from { opacity: 0; transform: translateX(4%) rotateY(-6deg); } to { opacity: 1; transform: none; } }
@keyframes turn-prev { from { opacity: 0; transform: translateX(-4%) rotateY(6deg); } to { opacity: 1; transform: none; } }

.art { position: absolute; inset: 0; }
.art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.art-missing {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 12%;
  text-align: center; font-family: 'Fredoka', sans-serif; font-size: 3.2cqw; color: var(--ink-soft);
  background: repeating-linear-gradient(45deg, var(--paper) 0 18px, var(--paper-deep) 18px 36px);
}

/* Story text, laid over the calm bottom of each illustration */
.textbox {
  position: absolute; left: 4%; right: 4%; bottom: 3.5%;
  padding: 1.3cqw 2.4cqw 1.5cqw;
  background: rgba(250, 243, 224, .95);
  border: 2px solid rgba(43, 31, 20, .85);
  border-radius: 1.6cqw;
  box-shadow: 0 .5cqw 1.6cqw rgba(0, 0, 0, .35);
  font-size: clamp(17px, 2.55cqw, 42px);
  line-height: 1.55;
}

/* Words: tap to hear; the spoken word is highlighted */
.w {
  border-radius: .22em;
  padding: 0 .05em;
  margin: 0 -.05em;
  cursor: pointer;
  transition: background-color .12s ease, box-shadow .12s ease;
}
.w:hover { text-decoration: underline dotted rgba(43, 31, 20, .45); text-underline-offset: .22em; }
.w.on { background: var(--gold); box-shadow: 0 0 0 .1em var(--gold); }

/* ---------- Cover ---------- */
.cover-panel { position: absolute; inset: 0; pointer-events: none; }
.cover-title {
  position: absolute; left: 0; right: 0; top: 4.5cqw; margin: 0;
  text-align: center; font-size: 7.4cqw; letter-spacing: .02em; line-height: 1.05;
  text-shadow:
    -.3cqw -.3cqw 0 var(--outline), .3cqw -.3cqw 0 var(--outline), -.3cqw .3cqw 0 var(--outline), .3cqw .3cqw 0 var(--outline),
    0 -.3cqw 0 var(--outline), 0 .3cqw 0 var(--outline), -.3cqw 0 0 var(--outline), .3cqw 0 0 var(--outline),
    .55cqw .7cqw 0 var(--outline), 0 1cqw 2.5cqw rgba(0, 0, 0, .45);
}
.cover-title .w { display: inline-block; transition: transform .15s ease, color .15s ease; pointer-events: auto; }
.cover-title .w.on { background: none; box-shadow: none; color: #fff7d1; transform: scale(1.08) translateY(-2%); }
.cover-actions {
  position: absolute; right: 3cqw; bottom: 4cqw;
  display: flex; flex-direction: column; gap: 1.3cqw; pointer-events: auto;
}

.big-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  padding: .55em 1.2em; min-height: 52px;
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: clamp(17px, 2.2cqw, 30px);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .4);
}
.big-btn.gold { background: var(--gold); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .4); }

/* ---------- Recap / The End ---------- */
.recap {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
  padding: 2cqw 4cqw 2.6cqw;
  background: radial-gradient(ellipse at 50% 40%, #fbf4de, var(--paper-deep) 95%);
}
.recap-heading { margin: 0; font-size: 3.6cqw; font-weight: 700; }
.steps { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2.6cqw; }
.steps li { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; }
.steps li:not(:last-child)::after {  /* arrow to the next step */
  content: ''; position: absolute; top: 5.2cqw; right: -2.15cqw;
  border-left: 1.4cqw solid var(--brick); border-top: 1cqw solid transparent; border-bottom: 1cqw solid transparent;
}
.step-thumb {
  width: 100%; aspect-ratio: 3 / 2; padding: 0; overflow: hidden;
  border: .3cqw solid var(--ink); border-radius: 1.1cqw; background: var(--paper-deep);
  box-shadow: 0 .4cqw 0 rgba(0, 0, 0, .3);
}
.step-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.step-num {
  position: absolute; left: -1cqw; top: -1cqw; width: 3.6cqw; height: 3.6cqw;
  display: grid; place-items: center; border-radius: 50%;
  font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 2.1cqw;
  background: var(--brick); color: #fff; border: .3cqw solid var(--paper);
}
.step-text { margin: 1.2cqw 0 0; font-size: 2.4cqw; font-weight: 700; line-height: 1.3; }
.the-end { margin: 0; font-size: 6cqw; }
.recap-actions { display: flex; gap: 2cqw; }

/* ---------- Controls ---------- */
.controls { display: flex; justify-content: center; align-items: center; gap: 26px; padding: 10px 0 2px; }
.nav-btn, .play-btn {
  display: grid; place-items: center; border-radius: 50%;
  border: 3px solid var(--ink); box-shadow: 0 5px 0 rgba(0, 0, 0, .4);
}
.nav-btn { width: 62px; height: 62px; background: var(--paper); font-size: 28px; }
.play-btn { width: 80px; height: 80px; background: var(--gold); font-size: 36px; }
.nav-btn:active:not(:disabled), .play-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .4); }
.nav-btn:disabled, .play-btn:disabled { opacity: .35; cursor: default; }
.play-btn.speaking { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 5px 0 rgba(0, 0, 0, .4), 0 0 0 10px rgba(242, 200, 50, .25); } }

.dots { display: flex; justify-content: center; gap: 9px; padding: 8px 0 14px; }
.dot { width: 13px; height: 13px; padding: 0; border-radius: 50%; border: 2px solid var(--paper); background: transparent; opacity: .65; }
.dot.on { background: var(--gold); border-color: var(--gold); opacity: 1; }

/* ---------- Settings ---------- */
dialog {
  width: min(92vw, 480px); padding: 24px 28px;
  border: 3px solid var(--ink); border-radius: 20px;
  background: var(--paper); color: var(--ink);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}
dialog::backdrop { background: rgba(16, 22, 13, .6); }
dialog h2 { margin: 0 0 16px; font-family: 'Fredoka', sans-serif; font-weight: 600; }
.field { display: block; margin: 0 0 18px; font-weight: 700; }
.field select, .field input[type=range] { display: block; width: 100%; margin-top: 8px; }
.field select { padding: 10px; font: inherit; font-weight: 400; border: 2px solid var(--ink); border-radius: 10px; background: #fffaf0; }
.field input[type=range] { accent-color: var(--brick); height: 28px; }
#rateLabel { font-weight: 400; color: var(--ink-soft); }
.check { display: flex; gap: 10px; align-items: center; margin: 0 0 14px; }
.check input { width: 22px; height: 22px; accent-color: var(--brick); }
.note { margin: 0 0 18px; font-size: .95rem; color: var(--ink-soft); }
.dialog-actions { display: flex; gap: 12px; justify-content: flex-end; }
.dialog-actions .big-btn { font-size: 18px; }

/* ---------- Animated pages (js/stage.js) ---------- */
.anim-stage { position: absolute; inset: 0; z-index: 0; isolation: isolate; opacity: 0; transition: opacity .3s ease; touch-action: none; user-select: none; -webkit-user-select: none; overflow: hidden; }
.anim-stage.ready { opacity: 1; }
.art .anim-stage img { position: absolute; display: block; object-fit: fill; pointer-events: none; -webkit-user-drag: none; user-select: none; }
.art .anim-stage img.stage-base { left: 0; top: 0; width: 100%; height: 100%; }
.actor, .actor-fx { position: absolute; inset: 0; pointer-events: none; }
.actor.dragging .actor-fx { filter: drop-shadow(0 .9cqw .6cqw rgba(30, 16, 6, .38)); }
.stage-fx { position: absolute; inset: 0; pointer-events: none; z-index: 3000; }
.fx-p { position: absolute; display: grid; place-items: center; }
.fx-p svg { display: block; width: 100%; height: 100%; overflow: visible; }
.fx-z { font-family: 'Fredoka', sans-serif; font-weight: 700; line-height: 1; font-size: 1em;
  text-shadow: -.06em -.06em 0 var(--outline), .06em -.06em 0 var(--outline), -.06em .06em 0 var(--outline), .06em .06em 0 var(--outline), .1em .12em 0 var(--outline); }
.fx-puff { width: 100%; height: 100%; border-radius: 50%; filter: blur(.25cqw); }
.fx-light { position: absolute; border-radius: 50%; mix-blend-mode: screen; pointer-events: none; }
.stage-label {
  position: absolute; z-index: 5; transform: translate(-50%, -100%); white-space: nowrap;
  padding: .2em .75em .25em; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: clamp(15px, 2.3cqw, 34px);
  color: var(--ink); background: #fffaf0; border: .22cqw solid var(--ink); border-radius: 999px; box-shadow: 0 .35cqw 0 rgba(0, 0, 0, .3);
}
.stage-hand { position: absolute; width: 6.5cqw; height: 6.5cqw; margin: -.6cqw 0 0 -1.4cqw; pointer-events: none; filter: drop-shadow(0 .4cqw .3cqw rgba(0, 0, 0, .35)); }
.stage-hand svg { width: 100%; height: 100%; }
.stage-prompt {
  position: absolute; left: 50%; top: 2.4cqw; z-index: 30; transform: translateX(-50%);
  display: flex; align-items: center; gap: .55em; max-width: 80%; width: max-content;
  padding: .45em 1.1em .5em .7em; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: clamp(16px, 2.25cqw, 32px); line-height: 1.25;
  color: var(--ink); text-align: start; background: rgba(255, 250, 236, .97); border: 3px solid var(--ink); border-radius: 1.4cqw;
  box-shadow: 0 .45cqw 0 rgba(0, 0, 0, .32), 0 1cqw 2cqw rgba(0, 0, 0, .25);
}
.stage-prompt.gone { display: none; }
.stage-prompt .sp-icon { flex: none; width: 1.7em; height: 1.7em; animation: sp-wag 1.6s ease-in-out infinite; }
.stage-prompt .sp-icon svg { width: 100%; height: 100%; }
@keyframes sp-wag { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(10deg) translateY(-6%); } }
.stage-praise { position: absolute; left: 50%; top: 42%; z-index: 40; font-size: 8cqw; pointer-events: none; white-space: nowrap; }
#reader:lang(ar) .stage-prompt, #reader:lang(ar) .stage-label, #reader:lang(ar) .stage-praise {
  font-family: 'Sakkal Majalla', 'Noto Naskh Arabic', 'Geeza Pro', 'Traditional Arabic', 'Segoe UI', serif; font-weight: 700;
}
#reader:lang(ar) .stage-prompt { font-size: clamp(20px, 2.9cqw, 42px); padding-top: .25em; padding-bottom: .35em; }
#reader:lang(ar) .stage-label { font-size: clamp(19px, 3cqw, 44px); padding-top: 0; padding-bottom: .1em; }
#reader:lang(ar) .stage-praise { font-size: 10cqw; }

/* ---------- Arabic and other right-to-left books ---------- */
/* Arabic books use a Naskh face with clear vowel marks (tashkeel), for punctuation and digits too. */
:lang(ar), :lang(ar) .lettering, :lang(ar) .big-btn, :lang(ar) .topbar-title, .book-card:lang(ar) h2, :lang(ar) .step-num {
  font-family: 'Sakkal Majalla', 'Noto Naskh Arabic', 'Geeza Pro', 'Traditional Arabic', 'Segoe UI', serif;
}
/* Naskh runs small for its size and needs room above and below the line for the vowel marks */
#reader:lang(ar) .textbox { font-size: clamp(21px, 3.25cqw, 54px); line-height: 1.6; padding-top: .9cqw; padding-bottom: 1.1cqw; }
#reader:lang(ar) .topbar-title { font-size: 1.55rem; font-weight: 700; }
#reader:lang(ar) .cover-title { font-size: 9cqw; line-height: 1.3; }
#reader:lang(ar) .big-btn { font-size: clamp(21px, 2.8cqw, 38px); font-weight: 700; padding-top: .35em; padding-bottom: .45em; }
#reader:lang(ar) .recap-heading { font-size: 4.4cqw; }
#reader:lang(ar) .step-text { font-size: 3cqw; line-height: 1.5; }
#reader:lang(ar) .the-end { font-size: 7.5cqw; }
.book-card:lang(ar) h2 { font-size: 2rem; font-weight: 700; }
.book-card:lang(ar) p { font-size: 1.35rem; }
.book-card[dir="rtl"] { text-align: right; }
/* mirrored arrows, page turns and the recap arrows */
[dir="rtl"] .nav-btn svg { transform: scaleX(-1); }
[dir="rtl"] .page.turn-next { animation-name: turn-prev; }
[dir="rtl"] .page.turn-prev { animation-name: turn-next; }
[dir="rtl"] .steps li:not(:last-child)::after { right: auto; left: -2.15cqw; border-left: 0; border-right: 1.4cqw solid var(--brick); }
[dir="rtl"] .step-num { left: auto; right: -1cqw; }

/* ---------- Small and portrait screens ---------- */
@media (max-height: 640px) {
  :root { --chrome-h: 160px; }
  .icon-btn { width: 42px; height: 42px; font-size: 22px; }
  .nav-btn { width: 50px; height: 50px; font-size: 22px; }
  .play-btn { width: 62px; height: 62px; font-size: 28px; }
  .dots { padding: 4px 0 8px; }
}
@media (max-aspect-ratio: 1 / 1) {
  body { overflow-y: auto; }
  .screen { height: auto; min-height: 100dvh; }
  .stage { align-content: start; }
  .page { width: 100%; aspect-ratio: auto; overflow: visible; background: none; box-shadow: none; }
  .art { position: relative; aspect-ratio: 3 / 2; border-radius: 10px; overflow: hidden; box-shadow: 0 0 0 5px var(--paper), 0 14px 30px rgba(0, 0, 0, .45); }
  .textbox { position: static; margin-top: 18px; font-size: clamp(18px, 5.2cqw, 30px); }
  .cover-panel { position: relative; inset: auto; pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 16px; margin-top: 18px; }
  .cover-title { position: static; font-size: 11cqw; }
  .cover-actions { position: static; }
  .recap { position: static; border-radius: 12px; padding: 18px; }
  .recap-heading { font-size: 6cqw; }
  .steps { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .steps li::after { display: none; }
  .step-num { width: 8cqw; height: 8cqw; font-size: 4.5cqw; }
  .step-text { font-size: 4.6cqw; }
  .the-end { font-size: 12cqw; margin: 20px 0; }
}
