/* ==========================================================
   Бачу так — МАЙСТЕРНЯ (всередині будиночка) і книга-КАТАЛОГ
   ----------------------------------------------------------
   • Перехід: «камера» наближається до дверей, тепле світло заливає екран,
     з нього проступає кімната (js/room.js, полотно #portal).
   • Кімната — така сама «сцена» 1672 × 941, як галявина: шари у відсотках,
     розміри — через --px (1 піксель оригіналу).
   • Поки немає малюнка від ChatGPT (завдання 005) — тло-чернетка assets/room/draft.svg,
     а хухи — пухнасті кульки з CSS.
   ========================================================== */

:root {
  --paper-page: #fbf4e4;
  --paper-edge: #e9dcc0;
  --sage: #6f8a55;
  --mustard: #d9a63c;
}

/* ---------- Перехід: наближення до дверей і тепле світло ----------
   «Камеру» й світло малює js/room.js на полотні #portal (canvas) — саму сцену ми не збільшуємо:
   браузер не встигав її перемальовувати, і виходили порожні шматки та обрізані смуги. */
.portal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  opacity: 0;
  pointer-events: none;
  z-index: 60;
}
.portal.is-on { display: block; }

/* Поки триває перехід: персонажі завмирають (крім дверей, що розчиняються), плашка й кнопки
   ховаються, гортання вимкнене. */
.viewport.is-travel { overflow: hidden; }
.viewport.is-travel .layers *:not(.cdoor-ev) { animation-play-state: paused !important; }
.viewport.is-travel .hotspots { visibility: hidden; }
.viewport .card { transition: opacity 0.35s ease, visibility 0s linear 0s; }
.viewport.is-travel .card { opacity: 0; visibility: hidden; transition: opacity 0.25s ease, visibility 0s linear 0.25s; }

.viewport.is-away { visibility: hidden; }
.viewport.is-away .layers * { animation-play-state: paused !important; }

/* ---------- Кімната ---------- */
.room[hidden] { display: none; }
.room { z-index: 5; background: #3b2416; }
.room::before { background-image: url("../assets/room/base.webp"); filter: blur(30px) brightness(0.8); }
.room.is-entering .room__stage { animation: room-in 1.3s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes room-in {                /* лише рух: фільтр яскравості на всю кімнату смикався; світло й так зверху */
  from { transform: scale(1.12); }
  to   { transform: scale(1); }
}

.room__stage .scene { pointer-events: none; }
.room__layers {
  position: absolute;
  inset: 0;
  --px: calc(100cqw / 1672);
}
.room__layers > * { position: absolute; }

/* напис «чернетка» */
.room__draft-note {
  left: calc(735 * var(--px));
  top: calc(400 * var(--px));
  width: calc(250 * var(--px));
  padding: calc(8 * var(--px)) calc(10 * var(--px));
  font: 700 calc(19 * var(--px)) / 1.05 var(--font-hand);
  color: #5a3a24;
  text-align: center;
  background: rgba(255, 248, 230, 0.86);
  border: calc(2 * var(--px)) dashed #b9532c;
  border-radius: calc(10 * var(--px));
  transform: rotate(-3deg);
  pointer-events: none;
}

/* --- Вогонь у каміні --- */
.fire {
  left: calc((var(--x) - var(--w) / 2) * var(--px));
  top: calc((var(--y) - var(--h)) * var(--px));
  width: calc(var(--w) * var(--px));
  height: calc(var(--h) * var(--px));
  pointer-events: auto;
  cursor: pointer;
  border: 0; padding: 0; background: none;
  -webkit-tap-highlight-color: transparent;
}
.fire::before {                         /* сяйво */
  content: "";
  position: absolute;
  inset: -45% -60% -10%;
  background: radial-gradient(ellipse at 50% 80%, rgba(255, 190, 90, 0.75), rgba(255, 140, 60, 0) 62%);
  mix-blend-mode: screen;
  animation: fire-glow 2.6s ease-in-out infinite;
}
.fire i {
  position: absolute;
  bottom: 6%;
  left: calc(50% - var(--fw) / 2);
  width: var(--fw);
  height: var(--fh);
  border-radius: 50% 50% 45% 45% / 70% 70% 30% 30%;
  background: radial-gradient(ellipse at 50% 85%, #fff6c8 0%, #ffd36b 25%, #ff9a3c 55%, rgba(214, 72, 28, 0.85) 75%, rgba(214, 72, 28, 0) 100%);
  transform-origin: 50% 100%;
  filter: blur(calc(1.5 * var(--px)));
  mix-blend-mode: screen;
  animation: flame-dance var(--d, 1.4s) ease-in-out infinite alternate;
}
.fire i:nth-child(1) { --fw: 46%; --fh: 88%; --d: 1.3s; }
.fire i:nth-child(2) { --fw: 30%; --fh: 64%; --d: 0.9s; left: 22%; animation-delay: -0.4s; }
.fire i:nth-child(3) { --fw: 30%; --fh: 70%; --d: 1.1s; left: 50%; animation-delay: -0.7s; }
.fire i:nth-child(4) { --fw: 20%; --fh: 44%; --d: 0.7s; left: 12%; animation-delay: -0.2s; }
.fire i:nth-child(5) { --fw: 20%; --fh: 48%; --d: 0.8s; left: 68%; animation-delay: -0.5s; }
@keyframes flame-dance {
  0%   { transform: scale(1, 1) skewX(0deg); }
  30%  { transform: scale(0.92, 1.08) skewX(4deg); }
  60%  { transform: scale(1.05, 0.9) skewX(-5deg); }
  100% { transform: scale(0.96, 1.12) skewX(2deg); }
}
@keyframes fire-glow {
  0%, 100% { opacity: 0.75; }
  40%      { opacity: 1; }
  70%      { opacity: 0.85; }
}
.fire.is-whoosh i { animation-duration: 0.35s; }
.fire.is-whoosh::before { animation: fire-glow 0.35s ease-in-out 4; }

/* іскри */
.spark {
  left: calc(var(--x) * var(--px));
  top: calc(var(--y) * var(--px));
  width: calc(5 * var(--px));
  height: calc(5 * var(--px));
  border-radius: 50%;
  background: #ffe7a0;
  box-shadow: 0 0 calc(6 * var(--px)) #ffb347;
  pointer-events: none;
  animation: spark-fly var(--t, 1.6s) ease-out forwards;
}
@keyframes spark-fly {
  0%   { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(calc(var(--dx) * var(--px)), calc(-160 * var(--px))) scale(0.2); opacity: 0; }
}

/* --- Свічки: полум'я на ґнотах --- */
.candle {
  left: calc((var(--x) - var(--s) * 0.5) * var(--px));
  top: calc((var(--y) - var(--s) * 1.15) * var(--px));
  width: calc(var(--s) * var(--px));
  height: calc(var(--s) * 1.15 * var(--px));
  pointer-events: auto;
  cursor: pointer;
  border: 0; padding: 0; background: none;
  -webkit-tap-highlight-color: transparent;
}
.candle::before {                       /* ореол */
  content: "";
  position: absolute;
  left: -150%; right: -150%; top: -120%; bottom: -120%;
  background: radial-gradient(circle, rgba(255, 214, 140, 0.6), rgba(255, 200, 120, 0) 60%);
  mix-blend-mode: screen;
  animation: candle-halo 3.1s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
.candle::after {                        /* полум'я */
  content: "";
  position: absolute;
  left: 30%; right: 30%; top: 8%; bottom: 0;
  border-radius: 50% 50% 45% 45% / 70% 70% 30% 30%;
  background: radial-gradient(ellipse at 50% 80%, #fff 0%, #fff1b0 30%, #ffb347 70%, rgba(255, 120, 40, 0) 100%);
  box-shadow: 0 0 calc(var(--s) * 0.25 * var(--px)) rgba(255, 190, 90, 0.8);
  transform-origin: 50% 100%;
  animation: candle-flicker 1.7s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
@keyframes candle-flicker {
  0%, 100% { transform: scale(1, 1) rotate(0deg); }
  25%      { transform: scale(0.9, 1.1) rotate(-3deg); }
  50%      { transform: scale(1.05, 0.92) rotate(2deg); }
  75%      { transform: scale(0.95, 1.06) rotate(-1deg); }
}
@keyframes candle-halo {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.08); }
}
.candle.is-flare::after { animation: candle-flare 0.9s ease-out; }
@keyframes candle-flare {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.5, 1.9); }
  100% { transform: scale(1); }
}

/* --- Хухи (чернетка: пухнасті кульки зі скляними оченятами) --- */
.huha {
  left: calc((var(--x) - var(--s) / 2) * var(--px));
  top: calc((var(--y) - var(--s) * 0.92) * var(--px));
  width: calc(var(--s) * var(--px));
  height: calc(var(--s) * 0.92 * var(--px));
  padding: 0; border: 0; background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transform-origin: 50% 100%;
  animation: huha-breathe var(--br, 4s) ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
.huha:focus-visible { outline: 2px dashed #fff; outline-offset: 4px; border-radius: 50%; }
@keyframes huha-breathe {
  0%, 100% { transform: scale(1, 1); }
  50%      { transform: scale(1.03, 0.97); }
}
.huha.is-hop { animation: huha-hop 0.9s cubic-bezier(0.3, 0, 0.3, 1); }
@keyframes huha-hop {
  0%   { transform: translateY(0) scale(1, 1); }
  20%  { transform: translateY(0) scale(1.12, 0.86); }
  45%  { transform: translateY(-28%) scale(0.94, 1.08); }
  70%  { transform: translateY(0) scale(1.08, 0.92); }
  100% { transform: translateY(0) scale(1, 1); }
}
.huha__fur {
  position: absolute;
  inset: 0;
  border-radius: 50% 50% 44% 44% / 56% 56% 44% 44%;
  background:
    radial-gradient(circle at 38% 28%, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0) 45%),
    radial-gradient(circle at 50% 60%, var(--c) 55%, color-mix(in srgb, var(--c), #3a2010 30%) 100%);
  filter: url(#fur);
}
.huha__fur::before {                    /* чубчик */
  content: "";
  position: absolute;
  left: 32%; top: -14%;
  width: 36%; height: 34%;
  border-radius: 50% 50% 20% 20%;
  background: var(--c);
  transform: rotate(-8deg);
}
.huha__eye {
  position: absolute;
  top: 26%;
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--iris, #7fc7a8) 0 46%, var(--ring, #e8a94a) 47% 62%, #f7efe0 63%);
  box-shadow: inset 0 calc(-2 * var(--px)) calc(3 * var(--px)) rgba(0, 0, 0, 0.25), 0 0 0 calc(1.5 * var(--px)) rgba(70, 40, 20, 0.4);
  overflow: hidden;
  transition: transform 0.07s linear;
}
.huha__eye--l { left: 18%; }
.huha__eye--r { right: 18%; }
.huha__eye::before {                    /* зіничка — дивиться довкола */
  content: "";
  position: absolute;
  left: 32%; top: 32%;
  width: 36%; height: 36%;
  border-radius: 50%;
  background: #1d1410;
  transform: translate(var(--lx, 0%), var(--ly, 0%));
  transition: transform 0.4s ease;
}
.huha__eye::after {                     /* відблиск скляного ока */
  content: "";
  position: absolute;
  left: 22%; top: 18%;
  width: 24%; height: 24%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
}
.huha.is-blink .huha__eye { transform: scaleY(0.08); }
.huha__nose {
  position: absolute;
  left: 44%; top: 54%;
  width: 12%; height: 8%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c), #6b2c18 55%);
}
.huha__arm {
  position: absolute;
  bottom: 14%;
  width: 22%;
  height: 30%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c), #3a2010 12%);
  filter: url(#fur);
  transform-origin: 50% 15%;
  transition: transform 0.25s ease;
}
.huha__arm--l { left: -4%; transform: rotate(18deg); }
.huha__arm--r { right: -4%; transform: rotate(-18deg); }
.huha.is-wave .huha__arm--r { animation: huha-wave 0.45s ease-in-out 3 alternate; }
.huha.is-wave .huha__arm--l { animation: huha-wave-l 0.5s ease-in-out 2 alternate; }
@keyframes huha-wave   { from { transform: rotate(-18deg); } to { transform: rotate(-150deg); } }
@keyframes huha-wave-l { from { transform: rotate(18deg); }  to { transform: rotate(70deg); } }

.heart, .star-fall {
  left: calc(var(--x) * var(--px));
  top: calc(var(--y) * var(--px));
  pointer-events: none;
}
.heart {
  font-size: calc(26 * var(--px));
  color: #e2577a;
  animation: heart-up 1.8s ease-out forwards;
}
@keyframes heart-up {
  0%   { transform: translate(-50%, 0) scale(0.4); opacity: 0; }
  20%  { transform: translate(-50%, -30%) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -260%) scale(0.9); opacity: 0; }
}

/* --- Віконце: падаюча зірка --- */
.window-btn {
  left: calc((var(--x) - var(--r)) * var(--px)); top: calc((var(--y) - var(--r)) * var(--px));
  width: calc(var(--r) * 2 * var(--px)); height: calc(var(--r) * 2 * var(--px));
  border-radius: 50%;
  border: 0; padding: 0; background: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.star-fall {
  width: calc(60 * var(--px));
  height: calc(3 * var(--px));
  border-radius: 99px;
  background: linear-gradient(90deg, rgba(255, 250, 220, 0), #fffbe6);
  transform: rotate(-28deg);
  animation: star-fall 1.1s ease-in forwards;
}
@keyframes star-fall {
  0%   { transform: translate(0, 0) rotate(152deg); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translate(calc(-110 * var(--px)), calc(70 * var(--px))) rotate(152deg); opacity: 0; }
}

/* --- Книга-каталог на полиці --- */
.shelf-book {
  left: calc(1300 * var(--px));
  top: calc(284 * var(--px));
  width: calc(128 * var(--px));
  height: calc(138 * var(--px));
  padding: 0; border: 0; background: none;
  cursor: pointer;
  transform: rotate(-4deg);
  transform-origin: 50% 100%;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.shelf-book:hover, .shelf-book:focus-visible { transform: rotate(-1deg) translateY(calc(-8 * var(--px))) scale(1.05); outline: none; }
.shelf-book::before {                   /* тепле сяйво — «натисніть мене» */
  content: "";
  position: absolute;
  inset: -30%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 222, 140, 0.75), rgba(255, 210, 120, 0) 65%);
  mix-blend-mode: screen;
  animation: book-glow 3s ease-in-out infinite;
}
@keyframes book-glow {
  0%, 100% { opacity: 0.35; transform: scale(0.92); }
  50%      { opacity: 1; transform: scale(1.06); }
}
.cover-art {                             /* обкладинка книги (і на полиці, і у великій книзі) */
  position: absolute;
  inset: 0;
  border-radius: 4% 7% 7% 4% / 3% 5% 5% 3%;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 50%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.28) 0 6%, rgba(255, 255, 255, 0.08) 7% 8%, rgba(0, 0, 0, 0) 9%),
    #2f5a4a;
  box-shadow: inset 0 0 0 0.5em rgba(0, 0, 0, 0.06), 0.15em 0.2em 0.5em rgba(40, 20, 10, 0.45);
  display: grid;
  place-items: center;
  overflow: hidden;
  container-type: inline-size;
}
.cover-art::before {                     /* золота рамка */
  content: "";
  position: absolute;
  inset: 9% 9% 9% 15%;
  border: max(1px, 2.2cqw) solid #e6c06a;
  border-radius: 10cqw;
  opacity: 0.85;
}
.cover-art__title {
  position: relative;
  margin-left: 6%;
  font: 700 21cqw/0.9 var(--font-hand);
  color: #f6dc95;
  text-align: center;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}
.cover-art__title small { display: block; font-size: 0.5em; color: #f2e4c4; margin-top: 0.2em; }
.cover-art__eyes {                       /* хуха-емблема з двома оченятами */
  position: absolute;
  left: calc(50% + 3%);
  bottom: 15%;
  width: 34cqw;
  height: 18cqw;
  transform: translateX(-50%);
  border-radius: 50% 50% 40% 40%;
  background: #e8a94a;
}
.cover-art__eyes::before, .cover-art__eyes::after {
  content: "";
  position: absolute;
  top: 18%;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #1d1410 0 30%, #7fc7a8 31% 55%, #f7efe0 56%);
}
.cover-art__eyes::before { left: 10%; }
.cover-art__eyes::after { right: 10%; }

/* підказка біля книги */
.book-hint {
  left: calc(1140 * var(--px));
  top: calc(330 * var(--px));
  font: 700 calc(24 * var(--px)) / 1 var(--font-hand);
  color: #fff6dc;
  text-shadow: 0 0 calc(6 * var(--px)) rgba(120, 60, 20, 0.9);
  pointer-events: none;
  white-space: nowrap;
  animation: hint-bob 2.4s ease-in-out infinite;
}
@keyframes hint-bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50%      { transform: translateY(calc(-6 * var(--px))) rotate(-2deg); }
}

/* ---------- Справжня кімната (малюнок ChatGPT, завдання 005) ---------- */
.rl, .rhot, .shelf-book--art {
  left: calc(var(--x) * var(--px));
  top: calc(var(--y) * var(--px));
  width: calc(var(--w) * var(--px));
  height: calc(var(--h) * var(--px));
}
img.rl { display: block; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.rhot {
  padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 40%;
  -webkit-tap-highlight-color: transparent;
}
.rhot:focus-visible { outline: 2px dashed rgba(255, 255, 255, 0.9); outline-offset: 2px; }

/* кліпання, лапки, руки — вирізки, що на мить проявляються */
.blink-art, .wave-art, .hands-art, .look-art { opacity: 0; transition: opacity 0.05s linear; }
.blink-art.is-on, .wave-art.is-on, .hands-art.is-on, .look-art.is-on { opacity: 1; }
.hands-art { transition-duration: 0.12s; }

/* вогонь: друга мить полум'я переливається з першою; над ним — тепле сяйво й іскри */
.fire-frame { animation: fire-frames 1.9s ease-in-out infinite; }
@keyframes fire-frames {
  0%, 100% { opacity: 0; }
  22%      { opacity: 0.85; }
  40%      { opacity: 0.35; }
  58%      { opacity: 1; }
  80%      { opacity: 0.15; }
}
.fire-frame.is-whoosh { animation-duration: 0.45s; }
.fire--art::before { inset: -20% -25% -5%; opacity: 0.6; }

/* свічки: полум'я намальоване — живе ореол і ледь помітне тремтіння світла */
.candle--art {
  left: calc((var(--x) - var(--s)) * var(--px));
  top: calc((var(--y) - var(--s) * 1.3) * var(--px));
  width: calc(var(--s) * 2 * var(--px));
  height: calc(var(--s) * 2.6 * var(--px));
}
.candle--art::after {
  left: 32%; right: 32%; top: 22%; bottom: 26%;
  background: radial-gradient(ellipse at 50% 70%, rgba(255, 255, 235, 0.85), rgba(255, 220, 140, 0.25) 55%, rgba(255, 200, 120, 0) 75%);
  box-shadow: none;
  mix-blend-mode: screen;
  opacity: 0.55;
}
.candle--art::before { left: -110%; right: -110%; top: -70%; bottom: -70%; }

/* книга на полиці: вирізка з малюнка; під нею — порожня полиця (видно, коли книгу «взяли») */
.shelf-book--art { transform: none; }
.shelf-book--art img { width: 100%; height: 100%; display: block; transition: opacity 0.25s; }
.shelf-book--art::before { inset: 0 10% 5% 30%; }
.shelf-book--art:hover, .shelf-book--art:focus-visible { transform: translateY(calc(-8 * var(--px))) rotate(-2deg); }
.shelf-book.is-out img, .shelf-book.is-out::before { opacity: 0; }
.book-hint--art {
  left: calc(1180 * var(--px)); top: calc(442 * var(--px));
  font-size: calc(27 * var(--px));
  color: #7a3a18;
  text-shadow: 0 0 calc(5 * var(--px)) #fff6e0, 0 0 calc(10 * var(--px)) #fff6e0;
}
.book-hint__arrow { display: inline-block; transform: rotate(-55deg); }

/* ---------- Навігація в майстерні: паперові бирки на мотузці ---------- */
.room-nav {
  position: fixed;
  z-index: 20;
  inset: auto 0 max(14px, env(safe-area-inset-bottom)) 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(8px, 1.4vw, 18px);
  padding: 0 12px;
  pointer-events: none;
}
.room-nav[hidden] { display: none; }
.tag.room-nav__back {
  position: fixed;
  z-index: 20;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
}
.tag {
  pointer-events: auto;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.38em 0.95em 0.42em 1.25em;
  border: 0;
  border-radius: 0.35em 0.55em 0.55em 0.35em;
  clip-path: polygon(0.7em 0, 100% 0, 100% 100%, 0.7em 100%, 0 50%);
  background: linear-gradient(180deg, #fff8e6, #f2e2bd);
  box-shadow: 0 2px 0 rgba(120, 80, 40, 0.35);
  font: 700 clamp(19px, 1.7vw, 26px) / 1 var(--font-hand);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transform: rotate(var(--r, -2deg));
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1), background-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.tag::before {                          /* дірочка для мотузки */
  content: "";
  position: absolute;
  left: 0.55em;
  top: calc(50% - 0.16em);
  width: 0.32em;
  height: 0.32em;
  border-radius: 50%;
  background: #8a5a35;
}
.tag:nth-child(2) { --r: 1.5deg; }
.tag:nth-child(3) { --r: -1deg; }
.tag:hover, .tag:focus-visible { transform: rotate(0deg) translateY(-3px) scale(1.04); outline: none; }
.tag:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
.tag--main { background: linear-gradient(180deg, #ffe7a8, #f0c565); }

/* ---------- Спільне для «вікон» поверх кімнати ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 12px;
  background: radial-gradient(ellipse at 50% 45%, rgba(60, 32, 14, 0.35), rgba(30, 14, 6, 0.75));
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.45s ease;
}
.overlay[hidden] { display: none; }
.overlay.is-open { opacity: 1; }
.x-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 248, 230, 0.92);
  color: var(--ink);
  font: 700 26px/1 var(--font-hand);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(60, 30, 10, 0.3);
}
.x-btn:hover, .x-btn:focus-visible { background: #fff; outline: 2px solid var(--accent); }
.hand { font-family: var(--font-hand); font-weight: 700; }

/* ---------- КНИГА-КАТАЛОГ ---------- */
.book {
  --bw: min(1180px, 96vw);
  --bh: min(760px, 90svh);
  position: relative;
  width: var(--bw);
  height: var(--bh);
  perspective: 2600px;
  transition: transform 0.85s cubic-bezier(0.2, 0.75, 0.25, 1);
}
.book__spread {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(250px, 0.62fr) 1.38fr;
  transform: translateX(-15.5%);              /* закрита: видно лише праву частину з обкладинкою */
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1) 0.45s;
  transform-style: preserve-3d;
  filter: drop-shadow(0 18px 30px rgba(20, 8, 2, 0.55));
}
.book.is-open .book__spread { transform: none; }
.book__page {
  position: relative;
  min-height: 0;
  min-width: 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 60%),
    linear-gradient(var(--paper-page), var(--paper-page));
  color: var(--ink);
}
.book__page--left {
  border-radius: 14px 4px 4px 14px;
  box-shadow: inset -26px 0 30px -22px rgba(90, 50, 20, 0.45), -6px 0 0 -1px var(--paper-edge), -10px 2px 0 -2px #d6c49e;
  padding: clamp(18px, 2.4vw, 34px) clamp(16px, 2vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  opacity: 0;
  transition: opacity 0.35s ease 0.75s;
}
.book.is-open .book__page--left { opacity: 1; }
.book__page--right {
  border-radius: 4px 14px 14px 4px;
  box-shadow: inset 26px 0 30px -22px rgba(90, 50, 20, 0.45), 6px 0 0 -1px var(--paper-edge), 10px 2px 0 -2px #d6c49e;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* намальований папір сторінок і гілочки в кутах (завдання ChatGPT 006) */
.book__page--left {
  background:
    url("../assets/book/sprig-left.webp") right 8px top 10px / clamp(64px, 7vw, 96px) auto no-repeat,
    url("../assets/book/page-left.webp") center / 100% 100% no-repeat,
    var(--paper-page);
}
.book__page--right {
  background:
    url("../assets/book/sprig-right.webp") right 14px bottom 10px / clamp(70px, 8vw, 110px) auto no-repeat,
    url("../assets/book/page-right.webp") center / 100% 100% no-repeat,
    var(--paper-page);
}
.book__cover {
  position: absolute;
  top: -6px;
  right: -8px;
  bottom: -6px;
  width: calc(69% + 8px);                     /* лежить точно над правою сторінкою */
  transform-origin: left center;
  transition: transform 1.05s cubic-bezier(0.55, 0, 0.3, 1) 0.3s;
  backface-visibility: hidden;
  font-size: 18px;
  z-index: 3;
}
.book__cover .cover-art { border-radius: 6px 18px 18px 6px; }
.book__cover .cover-art { backface-visibility: hidden; }
/* намальована обкладинка (завдання ChatGPT 006): кути з завитками не розтягуються, середина — так */
.book__cover { container-type: size; }
.book__cover .cover-art {
  border: solid transparent;
  border-image: url("../assets/book/cover.webp") 280 280 280 300 fill / 27.3cqmin 27.3cqmin 27.3cqmin 29.3cqmin stretch;
  background: #2a390f;
  box-shadow: 0.15em 0.2em 0.5em rgba(40, 20, 10, 0.45);
}
.book__cover .cover-art::before { content: none; }       /* рамка вже намальована */
.book__cover .cover-art__title {
  margin: 0 0 14% 4%;                           /* трохи вище — під ним медалька */
  color: #f0cf72;
  text-shadow: 0 1px 0 rgba(60, 40, 0, 0.6), 0 -1px 0 rgba(255, 240, 190, 0.35), 0 0 0.3em rgba(0, 0, 0, 0.35);
}
.book__cover .cover-art__eyes {                 /* намальована медалька з хухою */
  bottom: 9%;
  width: 26cqw;
  height: auto;
  aspect-ratio: 420 / 423;
  border-radius: 0;
  background: url("../assets/book/emblem.webp") center / contain no-repeat;
}
.book__cover .cover-art__eyes::before, .book__cover .cover-art__eyes::after { content: none; }
.book.is-open .book__cover {
  transform: rotateY(-178deg);
  opacity: 0;                                  /* на півдорозі обкладинка «лягає» ліворуч і зникає */
  pointer-events: none;
  transition: transform 1.05s cubic-bezier(0.55, 0, 0.3, 1) 0.3s, opacity 0.15s linear 0.95s;
}

.book__title {
  margin: 0;
  font: 700 clamp(44px, 4.6vw, 70px) / 0.9 var(--font-hand);
  color: var(--accent);
}
.book__subtitle { margin: -6px 0 0; font: 700 clamp(18px, 1.6vw, 24px) / 1.1 var(--font-hand); color: #8a6a4a; }

/* закладки-розділи (стрічечки) */
.ribbons { display: flex; flex-direction: column; gap: 7px; margin: 4px 0 0; padding: 0; list-style: none; }
.ribbon {
  --rc: #c8643a;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 7px 14px 7px 12px;
  border: 0;
  border-radius: 4px 0 0 4px;
  clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 50%, 100% 100%, 0 100%);
  background: color-mix(in srgb, var(--rc), #fff 78%);
  color: var(--ink);
  font: 700 clamp(19px, 1.65vw, 24px) / 1 var(--font-hand);
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease;
}
.ribbon small { font-family: var(--font-text); font-weight: 600; font-size: 13px; opacity: 0.7; padding-right: 10px; }
.ribbon:hover, .ribbon:focus-visible { transform: translateX(6px); outline: none; background: color-mix(in srgb, var(--rc), #fff 60%); }
.ribbon[aria-pressed="true"] { background: var(--rc); color: #fff; transform: translateX(10px); }
.ribbons li:nth-child(6n+1) .ribbon { --rc: #c8643a; }
.ribbons li:nth-child(6n+2) .ribbon { --rc: #d9a63c; }
.ribbons li:nth-child(6n+3) .ribbon { --rc: #6f8a55; }
.ribbons li:nth-child(6n+4) .ribbon { --rc: #5f7aa0; }
.ribbons li:nth-child(6n+5) .ribbon { --rc: #b66a8a; }
.ribbons li:nth-child(6n+6) .ribbon { --rc: #8a6a4a; }

/* перемикач «лише в наявності» */
.stock-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  font: 700 clamp(19px, 1.6vw, 23px) / 1 var(--font-hand);
  cursor: pointer;
  user-select: none;
}
.stock-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.stock-toggle__track {
  position: relative;
  flex: none;
  width: 46px;
  height: 26px;
  border-radius: 99px;
  background: #d9ccb0;
  box-shadow: inset 0 1px 3px rgba(60, 30, 10, 0.35);
  transition: background-color 0.25s;
}
.stock-toggle__track::after {
  content: "🌿";
  position: absolute;
  left: 2px; top: 2px;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  font-size: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(60, 30, 10, 0.4);
  transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.stock-toggle input:checked + .stock-toggle__track { background: var(--sage); }
.stock-toggle input:checked + .stock-toggle__track::after { transform: translateX(20px); }
.stock-toggle input:focus-visible + .stock-toggle__track { outline: 3px solid var(--accent); outline-offset: 2px; }

.book__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.45em 0.95em;
  border: 2px solid var(--accent);
  border-radius: 99px;
  background: transparent;
  color: var(--accent);
  font: 600 15px/1 var(--font-text);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, transform 0.2s;
}
.pill:hover, .pill:focus-visible { background: var(--accent); color: #fff; transform: translateY(-1px); outline: none; }
.pill--solid { background: var(--accent); color: #fff; }
.pill--solid:hover, .pill--solid:focus-visible { background: #a2461f; }
.book__foot { margin-top: auto; font-size: 13px; line-height: 1.4; color: #8a6a4a; }
.book__foot a { color: var(--accent); font-weight: 600; }

/* права сторінка: заголовок розділу і роботи */
.book__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(16px, 2vw, 26px) clamp(54px, 5vw, 64px) 6px clamp(18px, 2.4vw, 34px);
}
.book__section { margin: 0; font: 700 clamp(30px, 2.8vw, 42px) / 1 var(--font-hand); }
.book__count { font-size: 14px; color: #8a6a4a; white-space: nowrap; }
.book__items {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px clamp(16px, 2.2vw, 32px) 26px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(168px, 42%), 1fr));
  gap: clamp(16px, 1.8vw, 24px) clamp(12px, 1.5vw, 20px);
  align-content: start;
  scrollbar-width: thin;
  scrollbar-color: #d6b98a transparent;
}
.book__items.is-turn { animation: page-in 0.5s ease both; }
@keyframes page-in {
  from { opacity: 0; transform: translateX(14px); }
  to   { opacity: 1; transform: none; }
}
.book__flip {                          /* сторінка, що перегортається при зміні розділу */
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  transform-origin: left center;
  background: linear-gradient(90deg, rgba(120, 80, 30, 0.18), rgba(120, 80, 30, 0) 30%), url("../assets/book/page-right.webp") center / 100% 100%, var(--paper-page);
  border-radius: 4px 14px 14px 4px;
  opacity: 0;
}
.book__flip.is-on { animation: page-flip 0.6s cubic-bezier(0.4, 0, 0.3, 1); }
@keyframes page-flip {
  0%   { opacity: 1; transform: rotateY(0deg); box-shadow: -10px 0 30px rgba(60, 30, 10, 0.2); }
  100% { opacity: 1; transform: rotateY(-90deg); box-shadow: -10px 0 30px rgba(60, 30, 10, 0); }
}

/* картка роботи — фото-«полароїд» на скотчі */
.item {
  --tilt: -1.2deg;
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 8px 10px;
  background: #fff;
  border-radius: 3px;
  box-shadow: 0 3px 10px rgba(70, 40, 15, 0.18), 0 1px 2px rgba(70, 40, 15, 0.2);
  color: var(--ink);
  text-decoration: none;
  transform: rotate(var(--tilt));
  transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1), box-shadow 0.3s;
  animation: item-in 0.5s ease both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes item-in {
  from { opacity: 0; transform: translateY(14px) rotate(var(--tilt)); }
  to   { opacity: 1; transform: rotate(var(--tilt)); }
}
.item:nth-child(3n+2) { --tilt: 1.4deg; }
.item:nth-child(3n+3) { --tilt: -0.4deg; }
.item:hover, .item:focus-visible {
  transform: rotate(0deg) translateY(-5px) scale(1.03);
  box-shadow: 0 12px 24px rgba(70, 40, 15, 0.28);
  outline: none;
  z-index: 1;
}
.item:focus-visible { box-shadow: 0 0 0 3px var(--accent), 0 12px 24px rgba(70, 40, 15, 0.28); }
.item::before {                        /* скотч */
  content: "";
  position: absolute;
  left: 50%;
  top: -9px;
  width: 58px;
  height: 20px;
  transform: translateX(-50%) rotate(calc(var(--tilt) * -3));
  background: rgba(232, 214, 160, 0.75);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  z-index: 2;
}
.item:nth-child(4n+2)::before { background: rgba(196, 220, 186, 0.75); }
.item:nth-child(4n+3)::before { background: rgba(240, 196, 196, 0.75); }
.item__photo {
  position: relative;
  display: block;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #efe5d2;
}
.item__photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.6s ease; }
.item:hover .item__photo img { transform: scale(1.06); }
.item__play {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(30, 15, 5, 0.55);
  color: #fff;
  font-size: 11px;
  padding-left: 2px;
}
.item__badge {
  position: absolute;
  left: -6px;
  bottom: 10px;
  padding: 4px 10px 4px 8px;
  border-radius: 0 99px 99px 0;
  font: 700 17px/1 var(--font-hand);
  color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.item__badge--yes { background: var(--sage); }
.item__badge--order { background: var(--mustard); }
.item__badge--sold { background: #a89a88; }
.item__title { margin-top: 8px; font: 700 20px/1.02 var(--font-hand); }
.item__meta { margin-top: 3px; font-size: 13px; color: #8a6a4a; }
.item__meta b { color: var(--accent); }

.book__empty {
  grid-column: 1 / -1;
  padding: 40px 10px;
  text-align: center;
  font: 700 24px/1.25 var(--font-hand);
  color: #8a6a4a;
}
.book__empty .pill { margin-top: 14px; font-family: var(--font-text); }

/* ---------- Листи: «Зв'язатися» і «Важливо» ---------- */
.letter, .note {
  position: relative;
  width: min(560px, 94vw);
  max-height: 88svh;
  overflow: auto;
  padding: clamp(26px, 4vw, 44px) clamp(22px, 4vw, 44px) clamp(22px, 3vw, 34px);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
  transform: translateY(30px) rotate(-3deg) scale(0.96);
  transition: transform 0.55s cubic-bezier(0.25, 1.3, 0.4, 1);
}
.is-open > .letter, .is-open > .note { transform: rotate(-1deg); }
.letter {
  background:
    repeating-linear-gradient(transparent 0 31px, rgba(150, 110, 60, 0.11) 31px 32px),
    url("../assets/book/letter.webp") center / 100% 100% no-repeat,   /* намальований папір (ChatGPT 006) */
    linear-gradient(#fffaf0, #fbf1dc);
  border-radius: 6px;
  box-shadow: 0 20px 50px rgba(20, 8, 2, 0.5);
}
.letter::after {                       /* поштова марка (ChatGPT 006) */
  content: "";
  position: absolute;
  right: 62px;
  top: 12px;
  width: 104px;
  aspect-ratio: 300 / 253;
  background: url("../assets/book/stamp.webp") center / contain no-repeat;
  transform: rotate(4deg);
  pointer-events: none;
}
.note {
  background:
    url("../assets/book/note.webp") center / 100% 100% no-repeat,     /* намальований папір (ChatGPT 006) */
    linear-gradient(#fff6c9, #fbe9a6);
  border-radius: 2px 2px 6px 18px;
  box-shadow: 0 20px 50px rgba(20, 8, 2, 0.5), inset 0 -12px 20px -16px rgba(120, 80, 20, 0.4);
}
.note::before {                        /* шпилька (ChatGPT 006) */
  content: "";
  position: absolute;
  left: 50%;
  top: 6px;
  width: 40px;
  aspect-ratio: 140 / 152;
  margin-left: -20px;
  background: url("../assets/book/pin.webp") center / contain no-repeat;
  pointer-events: none;
}
.letter h2, .note h2 { margin: 0 0 10px; font: 700 clamp(40px, 6vw, 56px) / 1 var(--font-hand); color: var(--accent); }
.note h3 { margin: 18px 0 4px; font: 700 26px/1.1 var(--font-hand); color: #6a4428; }
.letter p, .note p { margin: 0 0 12px; }
.note blockquote { margin: 0 0 12px; padding: 0 0 0 14px; border-left: 3px solid #e2b04a; }
.sign { font: 700 24px/1 var(--font-hand); color: #8a5a35; text-align: right; margin-top: 8px; }
.contact-list { display: grid; gap: 10px; margin: 16px 0; padding: 0; list-style: none; }
.contact-list a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(70, 40, 15, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
}
.contact-list a:hover, .contact-list a:focus-visible { transform: translateX(4px); box-shadow: 0 3px 10px rgba(70, 40, 15, 0.25); outline: none; }
.contact-list small { display: block; font-weight: 400; color: #8a6a4a; }
.contact-list__ico { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: #fff; font-size: 18px; }
.draft {
  padding: 8px 12px;
  border: 2px dashed #b9532c;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  font-size: 14px;
  color: #7a4a2a;
}

/* кнопка «Каталог» на галявині (у плашці-візитці) */
.card__links { display: flex; flex-wrap: wrap; gap: 0.5em; justify-content: center; }
.card__link--book { background: #2f5a4a; }
.card__link--book:hover { background: #24473a; }

/* ---------- Телефон і вузькі екрани ---------- */
@media (max-width: 760px) {
  .book { --bw: 96vw; --bh: 92svh; }
  .book__spread {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    transform: none;
    border-radius: 14px;
    overflow: hidden;
  }
  .book__page--left {
    border-radius: 14px 14px 0 0;
    box-shadow: inset 0 -20px 24px -22px rgba(90, 50, 20, 0.45);
    padding: 16px 14px 10px;
    gap: 8px;
    overflow: visible;
  }
  .book__page--right { border-radius: 0 0 14px 14px; box-shadow: none; }
  .book__page--left, .book__page--right { background-size: 0 0, cover; }   /* без гілочок; папір не сплющувати */
  .book__title { font-size: 40px; }
  .book__subtitle, .book__foot, .book__doodle { display: none; }
  .ribbons { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; scrollbar-width: none; }
  .ribbons::-webkit-scrollbar { display: none; }
  .ribbon { width: auto; white-space: nowrap; clip-path: none; border-radius: 99px; padding: 6px 12px; font-size: 19px; }
  .ribbon[aria-pressed="true"] { transform: none; }
  .ribbon:hover { transform: none; }
  .book__actions .pill { font-size: 13px; padding: 0.4em 0.8em; }
  .book__cover { top: 0; right: 0; bottom: 0; width: 100%; }
  .book__head { padding: 12px 54px 2px 14px; }
  .book__items { padding: 10px 14px 22px; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
  .item__title { font-size: 18px; }
  .item__badge { font-size: 15px; }

  .room-nav { gap: 6px; padding: 0 8px; }
  .tag { font-size: 18px; padding: 0.38em 0.6em 0.42em 1.05em; }
}

@media (max-aspect-ratio: 1/1) {
  .tag.room-nav__back { top: max(10px, env(safe-area-inset-top)); left: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .room__layers * { animation: none !important; }
  .book__spread, .book__cover, .book__page--left { transition: none !important; }
}
