/* ---------- Story mode (js/stories.js) ---------- */

/* Bookshelf button: top corner, child-sized, glows while a story waits */
.books-btn {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: calc(10px + env(safe-area-inset-left, 0px));
  width: 96px;
  height: 96px;
  padding: 18px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: #ffe8a3;
  box-shadow: 0 6px 0 rgba(74, 63, 122, .2);
  z-index: 2;
}
.books-btn svg { display: block; width: 100%; height: 100%; overflow: visible; }
.bk-page  { fill: #fff; stroke: var(--zk-line); stroke-width: 3; stroke-linejoin: round; }
.bk-spine { stroke: var(--zk-line); stroke-width: 3; }
.books-btn.is-current { animation: door-glow 1.6s ease-in-out infinite; }
.books-btn.is-unlocked { animation: door-unlock .9s ease-out, door-glow 1.6s ease-in-out .9s infinite; }

/* Shelf: one book per story */
.shelf { flex-wrap: wrap; gap: 5vmin; align-content: flex-start; align-content: safe center; overflow-y: auto; }
.book {
  position: relative;
  width: clamp(96px, 26vmin, 150px);
  aspect-ratio: 4 / 5;
  display: flex;
  align-items: center;
  padding: 0 clamp(18px, 5vmin, 28px) 0 clamp(10px, 3vmin, 18px);   /* % would resolve against the modal */
  border: 0;
  border-radius: 18px 8px 8px 18px;   /* Arabic books bind on the right */
  background: #ff9fc0;
  box-shadow: inset -12px 0 0 rgba(0, 0, 0, .12), 0 6px 0 rgba(74, 63, 122, .3);
}
.book:nth-child(3n+2) { background: #6ec6ff; }
.book:nth-child(3n)   { background: #7fd36b; }
.book--daily { background: #ffd84d; }
.book img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  padding: 10%;
  border-radius: 50%;
  background: #fff;
  object-fit: contain;
  pointer-events: none;
}
.book.is-locked { filter: grayscale(.7); opacity: .75; }
.book.is-locked::after,
.book.is-done::after {
  content: "";
  position: absolute;
  top: -12px;
  right: -12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffd84d url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='5' y='11' width='14' height='10' rx='2' fill='%23b89a10'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3' fill='none' stroke='%23b89a10' stroke-width='2.5'/%3E%3C/svg%3E") center / 66% no-repeat;
  border: 3px solid #fff;
}
.book.is-done::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2l3 6.5 7 .8-5.2 4.8 1.4 7L12 17.6 5.8 21.1l1.4-7L2 9.3l7-.8Z' fill='%23fff' stroke='%23b89a10' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.book.is-open { animation: door-glow 1.6s ease-in-out infinite; }
.book.is-shake { animation: opt-wiggle .4s ease-in-out; }

/* Story scene: props placed by the page JSON (percent of the screen) */
.story-scene { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.prop {
  position: absolute;
  transform: translate(-50%, -50%);
  animation: prop-in .4s ease-out;
  filter: drop-shadow(0 4px 0 rgba(74, 63, 122, .15));
}
.prop.is-flip { transform: translate(-50%, -50%) scaleX(-1); }
.prop--bob   { animation: prop-in .4s ease-out, prop-bob 2.4s ease-in-out .4s infinite; }
.prop--hop   { animation: prop-in .4s ease-out, prop-hop 1.4s ease-in-out .4s infinite; }
.prop--sway  { animation: prop-in .4s ease-out, prop-sway 3s ease-in-out .4s infinite; }
@keyframes prop-in   { from { opacity: 0; scale: .6; } }
@keyframes prop-bob  { 50% { translate: 0 -8px; } }
@keyframes prop-hop  { 0%, 60%, 100% { translate: 0 0; } 30% { translate: 0 -18px; } }
@keyframes prop-sway { 50% { rotate: 8deg; } }

/* count / order: two rows (pool + basket, or slots + pool) */
.stage--count, .stage--order { flex-direction: column; align-items: center; gap: 3vmin; }
.count-pool, .count-basket, .order-pool, .order-slots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2vmin;
  min-height: calc(clamp(64px, 17vmin, 100px) + 16px);
  max-width: 92vw;
}
.count-basket {
  min-width: min(80vw, 420px);
  padding: 8px;
  border: 5px solid #b07a4a;
  border-top-width: 10px;
  border-radius: 10px 10px 40px 40px;
  background: repeating-linear-gradient(45deg, #e8b27a 0 10px, #d99a5c 10px 20px);
}
.order-slots { direction: rtl; }
.slot {
  width: clamp(64px, 17vmin, 100px);
  height: clamp(64px, 17vmin, 100px);
  border: 4px dashed rgba(255, 255, 255, .9);
  border-radius: 24%;
}
.slot .token { width: 100%; height: 100%; }
.option.token {
  width: clamp(64px, 17vmin, 100px);
  height: clamp(64px, 17vmin, 100px);
  padding: clamp(6px, 2vmin, 12px);
}
.count-basket.is-wrong, .order-slots.is-wrong { animation: opt-wiggle .5s ease-in-out; }

@media (orientation: landscape) {
  .stage--count, .stage--order { max-width: 46vw; }
  .count-basket { min-width: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .prop, .books-btn, .book { animation: none !important; }
}
