/* Adwentowa biblioteczka – kolory wzięte z „Bibliotecznego Labiryntu” */
:root {
  --wall-hi: #4a2f1c;
  --wall-lo: #1f130b;
  --walnut: #6b3e1f;
  --walnut-dk: #4a2810;
  --hollow: #3b200e;
  --plank: #9c6232;
  --paper: #fff6dc;
  --paper-dk: #f1d9a6;
  --ink: #4a2810;
  --gold: #ffe066;
  --brass: #e0b43a;
  --turtle: #2b8a3e;
  --rooster: #c2410c;
  --heart: #e64980;

  --display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --serif: "Literata", Georgia, serif;

  --row-h: clamp(150px, 19vw, 200px);
  --book-w: clamp(52px, 8.2vw, 84px);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-book: cubic-bezier(.6, .02, .25, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--paper);
  font-family: var(--display);
  background:
    radial-gradient(ellipse 70% 55% at 50% 28%, rgba(255, 190, 110, .16), transparent 70%),
    radial-gradient(circle at 50% 40%, var(--wall-hi), var(--wall-lo) 78%);
  background-color: var(--wall-lo);
  background-attachment: fixed;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 6px; }

/* ---------- nagłówek ---------- */
.masthead {
  text-align: center;
  padding: clamp(28px, 6vw, 56px) 16px 0;
}
.title {
  margin: 0;
  font-weight: 700;
  font-size: clamp(2.1rem, 6.4vw, 4rem);
  line-height: 1.02;
  letter-spacing: -.01em;
  color: #ffe9b8;
  -webkit-text-stroke: 0;
  text-shadow:
    0 3px 0 var(--walnut),
    0 6px 0 var(--hollow),
    0 14px 28px rgba(0, 0, 0, .45);
}
.subtitle {
  margin: 14px auto 0;
  max-width: 34ch;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  line-height: 1.5;
  color: #e8cfa3;
}

/* ---------- regał ---------- */
.room {
  padding: clamp(84px, 12vw, 120px) 16px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.bookcase {
  position: relative;
  width: min(100%, 980px);
  padding: 0 clamp(10px, 2vw, 18px) clamp(10px, 2vw, 18px);
  background:
    repeating-linear-gradient(92deg, rgba(0,0,0,.05) 0 3px, transparent 3px 11px),
    linear-gradient(180deg, #7a4826, var(--walnut) 40%, #5c3418);
  border: 3px solid var(--walnut-dk);
  border-radius: 10px 10px 6px 6px;
  box-shadow:
    inset 0 2px 0 rgba(255, 210, 160, .18),
    0 30px 60px -20px rgba(0, 0, 0, .7),
    0 4px 0 var(--walnut-dk);
}

.crown {
  position: relative;
  height: 26px;
  margin: 0 calc(-1 * clamp(10px, 2vw, 18px)) clamp(10px, 2vw, 16px);
  background: linear-gradient(180deg, #a86a37, var(--plank) 45%, #7a4826);
  border-bottom: 3px solid var(--walnut-dk);
  border-radius: 8px 8px 0 0;
}
.garland {
  position: absolute;
  left: 4%; right: 4%;
  top: 14px;
  width: 92%;
  height: 44px;
  overflow: visible;
  pointer-events: none;
  z-index: 2;
}
.garland path { fill: none; stroke: #2f4a1f; stroke-width: 3; vector-effect: non-scaling-stroke; }
.bulbs { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.bulb {
  position: absolute;
  width: 9px; height: 12px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--c);
  box-shadow: 0 0 10px 2px color-mix(in srgb, var(--c) 70%, transparent);
  transform: translate(-50%, -2px);
  animation: twinkle 3.4s ease-in-out infinite;
  animation-delay: var(--d);
}
.bulb::before {
  content: ""; position: absolute; left: 2px; right: 2px; top: -3px; height: 4px;
  background: #3a3a2a; border-radius: 1px;
}
@keyframes twinkle { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.hero {
  position: absolute;
  bottom: 18px;
  width: clamp(96px, 14vw, 150px);
  height: clamp(96px, 14vw, 150px);
  z-index: 4;
  cursor: pointer;
}
.hero--turtle { left: clamp(8px, 4vw, 40px); }
.hero--bear   { right: clamp(8px, 4vw, 40px); }

/* ---------- półki ---------- */
.shelves { display: flex; flex-direction: column; gap: 0; }
.shelf {
  position: relative;
  height: var(--row-h);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(4px, 1.1vw, 12px);
  padding: 12px clamp(8px, 2vw, 22px) 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,.55), rgba(0,0,0,0) 30%),
    linear-gradient(90deg, rgba(0,0,0,.35), transparent 12%, transparent 88%, rgba(0,0,0,.35)),
    var(--hollow);
  border-left: 2px solid var(--walnut-dk);
  border-right: 2px solid var(--walnut-dk);
}
.shelf::after { /* deska */
  content: "";
  position: absolute;
  left: -2px; right: -2px; bottom: -14px;
  height: 14px;
  background: linear-gradient(180deg, #b0743e, var(--plank) 40%, #7c4a22);
  border: 2px solid var(--walnut-dk);
  border-radius: 2px;
  z-index: 1;
}
.shelf + .shelf { margin-top: 14px; }
.shelf:last-child { margin-bottom: 14px; }

/* ---------- książka (okienko) ---------- */
.book {
  --c: #1971c2;
  position: relative;
  flex: 0 1 calc(var(--book-w) * var(--w, 1));
  min-width: 0;
  height: var(--h, 90%);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-origin: 50% 100%;
  transition: transform .35s var(--ease-out), filter .3s;
  -webkit-tap-highlight-color: transparent;
}
.spine {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 4px 4px 2px 2px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.28), rgba(255,255,255,.16) 22%, rgba(255,255,255,0) 45%, rgba(0,0,0,.22)),
    var(--c);
  border: 2px solid color-mix(in srgb, var(--c) 55%, black);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.12);
  overflow: hidden;
}
.spine::before, .spine::after { /* złote opaski */
  content: "";
  position: absolute; left: 0; right: 0;
  height: 4px;
  background: var(--brass);
  box-shadow: 0 6px 0 -2px color-mix(in srgb, var(--brass) 70%, transparent);
}
.spine::before { top: 10%; }
.spine::after  { bottom: 12%; box-shadow: 0 -6px 0 -2px color-mix(in srgb, var(--brass) 70%, transparent); }

.plate {
  position: relative;
  min-width: 70%;
  padding: 6px 2px 5px;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--paper), var(--paper-dk));
  border: 2px solid color-mix(in srgb, var(--c) 45%, black);
  color: var(--ink);
  font-weight: 700;
  font-size: clamp(1rem, 2.4vw, 1.55rem);
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.lock {
  position: absolute;
  bottom: 20%;
  width: 14px; height: 16px;
  opacity: .9;
}
.lock path, .lock rect { fill: none; stroke: var(--brass); stroke-width: 2.2; }
.lock rect { fill: color-mix(in srgb, var(--brass) 35%, transparent); }

.book:hover:not(.is-locked) { transform: translateY(-8px); }
.book:active:not(.is-locked) { transform: translateY(-3px); }

.book.is-locked { cursor: not-allowed; }
.book.is-locked .spine { filter: saturate(.45) brightness(.72); }
.book.is-locked .plate { opacity: .8; }

.book.is-opened { transform: rotate(-3.5deg) translateY(-2px); }
.book.is-opened:hover { transform: rotate(-3.5deg) translateY(-9px); }
.book.is-opened .ribbon {
  position: absolute;
  bottom: -18px; left: 62%;
  width: 7px; height: 26px;
  background: var(--heart);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
  z-index: 2;
}

/* dzisiejsza książka: jedyny stały ruch na półce – ciepła poświata */
.book.is-today:not(.is-opened)::before {
  content: "";
  position: absolute;
  inset: -14px -10px -4px;
  border-radius: 14px;
  background: radial-gradient(closest-side, rgba(255, 245, 170, .75), rgba(255, 245, 170, 0));
  animation: glow 2.4s ease-in-out infinite;
  z-index: -1;
}
.book.is-today:not(.is-opened) .plate { background: linear-gradient(180deg, #fffbe6, var(--gold)); }
@keyframes glow { 0%, 100% { opacity: .55; transform: scale(.96); } 50% { opacity: 1; transform: scale(1.04); } }

.book.is-lifted { transform: translateY(-16px) !important; transition-duration: .25s; }
.book.is-away .spine, .book.is-away .ribbon { visibility: hidden; }

.book.shake { animation: shake .45s; }
@keyframes shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-4deg); }
  40% { transform: rotate(3.5deg); }
  60% { transform: rotate(-2deg); }
  80% { transform: rotate(1deg); }
}

.status {
  margin: 28px auto 0;
  max-width: 46ch;
  min-height: 1.5em;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.08rem;
  line-height: 1.5;
  color: #f2dcb2;
}

/* ---------- czytnik (otwarta książka) ---------- */
.reader {
  position: fixed; inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
}
.reader[hidden] { display: none; }
.reader__backdrop {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 45%, rgba(74, 47, 28, .82), rgba(20, 11, 5, .94));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.reader__close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 16px;
  z-index: 5;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 3px solid var(--walnut);
  background: var(--paper);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--walnut-dk);
}
.reader__close svg { width: 22px; height: 22px; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }

.stage {
  --page-w: min(400px, 44vw, calc((100dvh - 150px) * .74));
  --page-h: calc(var(--page-w) * 1.36);
  position: relative;
  z-index: 2;
  perspective: 3200px;
}
.fly { transform-style: preserve-3d; will-change: transform; }
.shift {
  transform-style: preserve-3d;
  transform: translateX(calc(var(--page-w) * -.5));
  transition: transform 1s var(--ease-book);
}
.reader.is-open .shift { transform: translateX(calc(var(--page-w) * .5)); }

.tome {
  position: relative;
  width: var(--page-w);
  height: var(--page-h);
  transform-style: preserve-3d;
}

.page {
  position: absolute; inset: 0;
  border-radius: 4px 12px 12px 4px;
  background:
    linear-gradient(90deg, rgba(120, 80, 30, .22), rgba(120, 80, 30, 0) 9%),
    linear-gradient(180deg, var(--paper), #fbecc4);
  box-shadow:
    4px 0 0 -1px #efdcae, 7px 0 0 -2px #e4cd98, 10px 1px 0 -3px #d9c088,
    0 30px 60px -18px rgba(0, 0, 0, .7);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7% 8%;
  gap: 5%;
}
.page__mobilehead, .page__mobilenote { display: none; }

.photo { margin: 0; width: 100%; flex: 1 1 auto; min-height: 0; display: flex; }
.photo__frame {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 10px 10px 34px;
  background: #fffdf6;
  border-radius: 3px;
  box-shadow: 0 2px 0 #e2cfa2, 0 10px 22px -10px rgba(74, 40, 16, .55);
  transform: rotate(1.2deg);
  overflow: hidden;
}
.photo img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 2px;
  background: #e9dcc0;
}
.photo img[hidden] { display: none; }
.photo__missing {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: .95rem;
  line-height: 1.5;
  text-align: center;
  color: #7a5a3a;
  max-width: 26ch;
}
.reader.is-developing .photo img { animation: develop 1.6s var(--ease-out) both; }
@keyframes develop {
  0%   { filter: blur(10px) sepia(1) brightness(1.6) contrast(.6); opacity: .3; }
  60%  { filter: blur(1px) sepia(.3) brightness(1.1); opacity: 1; }
  100% { filter: none; opacity: 1; }
}

.download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px 12px;
  border-radius: 999px;
  background: var(--turtle);
  border: 3px solid #1b5e20;
  box-shadow: 0 4px 0 #1b5e20;
  color: #fff;
  font-weight: 600;
  font-size: 1.05rem;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .15s, box-shadow .15s;
}
.download svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.download:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #1b5e20; }
.download:active { transform: translateY(3px); box-shadow: 0 1px 0 #1b5e20; }
.download[aria-disabled="true"] { background: #adb5bd; border-color: #868e96; box-shadow: 0 4px 0 #868e96; pointer-events: none; }

/* okładka */
.cover {
  position: absolute; inset: 0;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  transition: transform 1.25s var(--ease-book);
  z-index: 3;
}
.reader.is-open .cover { transform: rotateY(-180deg); }
.cover__front, .cover__back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.cover__front {
  --c: #1971c2;
  border-radius: 4px 14px 14px 4px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.38), rgba(0,0,0,.05) 7%, rgba(255,255,255,.1) 9%, rgba(0,0,0,0) 14%),
    radial-gradient(circle at 70% 20%, rgba(255,255,255,.14), transparent 55%),
    var(--c);
  border: 3px solid color-mix(in srgb, var(--c) 50%, black);
  box-shadow: 0 30px 60px -18px rgba(0, 0, 0, .75);
  padding: 9%;
  display: flex;
}
.cover__frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4%;
  border: 3px solid var(--brass);
  border-radius: 10px;
  outline: 1.5px solid color-mix(in srgb, var(--brass) 60%, transparent);
  outline-offset: 5px;
  color: var(--gold);
}
.cover__month {
  font-family: var(--serif);
  font-style: italic;
  font-size: calc(var(--page-w) * .07);
  color: #ffeaa0;
}
.cover__num {
  font-weight: 700;
  font-size: calc(var(--page-w) * .42);
  line-height: .9;
  color: var(--gold);
  text-shadow: 0 4px 0 color-mix(in srgb, var(--c) 45%, black);
}
.cover__star { width: 14%; fill: var(--brass); }

.cover__back {
  transform: rotateY(180deg);
  border-radius: 12px 4px 4px 12px;
  background:
    linear-gradient(270deg, rgba(120, 80, 30, .25), rgba(120, 80, 30, 0) 10%),
    linear-gradient(180deg, var(--paper), #fbecc4);
  box-shadow:
    -4px 0 0 -1px #efdcae, -7px 0 0 -2px #e4cd98, -10px 1px 0 -3px #d9c088;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10%;
}
.leftpage__num {
  margin: 0;
  font-weight: 700;
  font-size: calc(var(--page-w) * .46);
  line-height: .85;
  color: var(--rooster);
  text-shadow: 0 5px 0 #ffd8a8;
}
.leftpage__date {
  margin: 4% 0 0;
  font-weight: 600;
  font-size: calc(var(--page-w) * .066);
  color: var(--walnut);
}
.leftpage__note {
  margin: 8% 0 0;
  max-width: 22ch;
  font-family: var(--serif);
  font-style: italic;
  font-size: calc(var(--page-w) * .05);
  line-height: 1.55;
  color: #6b4a2c;
}

/* goście w czytniku */
.guest {
  position: absolute;
  z-index: 3;
  bottom: max(6px, env(safe-area-inset-bottom));
  width: clamp(110px, 15vw, 170px);
  height: clamp(110px, 15vw, 170px);
  pointer-events: none;
  opacity: 0;
}
.guest--turtle { left: max(2vw, 8px); }
.guest--bear   { right: max(2vw, 8px); }

.sparks { position: absolute; inset: 0; pointer-events: none; z-index: 4; overflow: hidden; }
.spark { position: absolute; left: 0; top: 0; will-change: transform, opacity; }
.spark svg { display: block; width: 100%; height: 100%; }

/* ---------- telefon ---------- */
@media (max-width: 700px) {
  :root { --row-h: 150px; --book-w: 19vw; }
  .stage { --page-w: min(86vw, calc((100dvh - 190px) * .74)); }
  .shift, .reader.is-open .shift { transform: none; }
  .reader.is-open .cover { transform: rotateY(-180deg); opacity: 0; transition: transform 1.25s var(--ease-book), opacity .35s .75s; }
  .page__mobilenote {
    display: block;
    margin: 0;
    max-width: 30ch;
    font-family: var(--serif);
    font-style: italic;
    font-size: 1rem;
    line-height: 1.45;
    text-align: center;
    color: #6b4a2c;
  }
  .page__mobilenote:empty { display: none; }
  .page__mobilehead {
    display: block;
    margin: 0;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--rooster);
  }
  .page { gap: 3.5%; padding: 6% 7%; }
  .guest { width: 96px; height: 96px; }
  .hero { bottom: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
