:root {
  --cream: #fff7ef;
  --paper: #ffffff;
  --ink: #2d3b34;
  --muted: #6b7a72;
  --pink: #ff7fa3;
  --pink-soft: #ffe3ec;
  --mint: #9fdcbf;
  --mint-deep: #2f7a5a;
  --sun: #ffd166;
  --sky: #8ec9f5;
  --lilac: #c4b0ff;
  --peach: #ffb38a;
  --accent: #4a8fe7;        /* wird pro Buch gesetzt */
  --accent-soft: #e3efff;
  --bar-h: 58px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ================= Startseite ================= */
#shelf {
  position: relative; overflow: hidden;
  min-height: 100dvh;
  padding: calc(64px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center;
  background:
    radial-gradient(circle at 8% 18%, #ffe6ef 0, transparent 32%),
    radial-gradient(circle at 92% 30%, #e2f5ea 0, transparent 34%),
    radial-gradient(circle at 20% 92%, #fff0c9 0, transparent 34%),
    radial-gradient(circle at 85% 95%, #e8e1ff 0, transparent 34%),
    var(--cream);
}

/* Wimpelkette */
.bunting {
  position: absolute; top: var(--safe-t); left: -10px; right: -10px; height: 56px;
  display: flex; justify-content: space-between; pointer-events: none; z-index: 1;
}
.bunting::before {
  content: ""; position: absolute; left: 0; right: 0; top: -30px; height: 44px;
  border-bottom: 2px solid #d9b9a0; border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.flag {
  position: relative; width: 30px; height: 38px; flex: none;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0;
  animation: swing 3.6s ease-in-out infinite alternate;
}
@keyframes swing { from { transform: translateY(var(--y)) rotate(-5deg); } to { transform: translateY(var(--y)) rotate(5deg); } }

/* schwebende Deko */
.floaties { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.floaty {
  position: absolute; bottom: -40px; font-size: var(--s, 22px); opacity: .55;
  animation: floatUp var(--d, 18s) linear infinite; animation-delay: var(--delay, 0s);
}
@keyframes floatUp {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  10%  { opacity: .55; }
  50%  { transform: translate(var(--dx, 30px), -55vh) rotate(160deg); }
  90%  { opacity: .45; }
  100% { transform: translate(0, -110vh) rotate(320deg); opacity: 0; }
}

.shelf-head { position: relative; z-index: 2; text-align: center; margin-bottom: 30px; }
.for {
  font-family: "Caveat", cursive; font-weight: 700; font-size: clamp(30px, 7vw, 40px);
  color: var(--pink); transform: rotate(-4deg); display: inline-block;
}
.for .heart { display: inline-block; animation: beat 1.4s ease-in-out infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.25); } 30% { transform: scale(1); } 45% { transform: scale(1.15); } }
.rainbow {
  font-family: "Fredoka", sans-serif; font-weight: 700;
  font-size: clamp(44px, 12vw, 76px); line-height: 1; margin: 2px 0 12px;
  letter-spacing: 1px;
}
.rainbow span {
  display: inline-block;
  text-shadow: 0 3px 0 rgba(0,0,0,.08);
  animation: hop 2.8s ease-in-out infinite; animation-delay: calc(var(--i) * 90ms);
}
@keyframes hop { 0%, 70%, 100% { transform: translateY(0); } 80% { transform: translateY(-7px); } }
.wish {
  margin: 0; font-weight: 800; font-size: clamp(18px, 4.6vw, 22px);
  display: inline-block; padding: 8px 18px; border-radius: 999px;
  background: #fff; box-shadow: 0 6px 18px rgba(255,127,163,.2); color: #d9567c;
}
.sub { margin: 14px 0 0; color: var(--muted); font-size: 16px; }

.books {
  position: relative; z-index: 2;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 30px 34px;
  width: 100%; max-width: 860px;
}
.book-card {
  appearance: none; border: 0; cursor: pointer; text-align: left;
  width: min(100%, 360px);
  background: #fff; border-radius: 26px; padding: 14px 14px 18px;
  box-shadow: 0 2px 0 rgba(0,0,0,.03), 0 18px 40px -12px color-mix(in srgb, var(--c) 45%, transparent);
  display: flex; flex-direction: column; gap: 14px;
  position: relative;
  transform: rotate(var(--tilt, 0deg));
  transition: transform .3s cubic-bezier(.3,1.6,.5,1), box-shadow .3s;
}
.book-card:nth-child(1) { --tilt: -1.6deg; }
.book-card:nth-child(2) { --tilt: 1.6deg; }
.book-card:hover, .book-card:focus-visible { transform: rotate(0deg) translateY(-8px) scale(1.02); }
.book-card:active { transform: scale(.98); }
.book-card:focus-visible { outline: 3px solid var(--c); outline-offset: 4px; }
.cover {
  position: relative; width: 100%;
  aspect-ratio: var(--ar, 1.55);
  background: var(--soft); border-radius: 16px; overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 46px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }
.bow {
  position: absolute; top: -18px; right: 18px; width: 64px; height: 50px; z-index: 3;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,.15));
}
.ribbon { position: absolute; top: 0; bottom: 0; right: 48px; width: 12px; background: var(--c); opacity: .85; }
.card-text { display: flex; flex-direction: column; gap: 2px; padding: 0 6px; }
.plant { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 26px; color: var(--ink); display: flex; align-items: center; gap: 10px; }
.chip { font-family: "Nunito", sans-serif; font-size: 12px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; background: var(--soft); color: var(--deep); }
.nick { font-family: "Caveat", cursive; font-size: 24px; font-weight: 700; color: var(--deep); line-height: 1.1; }
.meta { color: var(--muted); font-size: 14px; margin-top: 4px; }
.open-btn {
  align-self: flex-start; margin: 0 6px;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px; border-radius: 999px; font-weight: 800; font-size: 16px;
  background: var(--c); color: #fff; box-shadow: 0 6px 14px -4px var(--c);
}
.book-card[data-id="yellow"] .open-btn { color: #5a4200; }
.open-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.book-card:hover .open-btn svg { transform: translateX(4px); }

.shelf-foot { position: relative; z-index: 2; margin-top: auto; padding-top: 34px; text-align: center; }
.duo { margin: 0 0 6px; font-family: "Caveat", cursive; font-weight: 700; font-size: 24px; color: var(--mint-deep); }
.tip { margin: 0; color: var(--muted); font-size: 13px; }

/* ================= Leser ================= */
#reader {
  height: 100dvh; display: flex; flex-direction: column;
  background:
    radial-gradient(circle, rgba(255,255,255,.75) 1.6px, transparent 1.8px) 0 0 / 24px 24px,
    linear-gradient(165deg, var(--accent-soft) 0%, #f3fbf5 55%, #fff4ee 100%);
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
}
.topbar, .bottombar { flex: none; display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.topbar { height: calc(var(--bar-h) + var(--safe-t)); padding-top: var(--safe-t); }
.topbar .title {
  flex: 1; min-width: 0; display: flex; justify-content: center; align-items: center; gap: 9px;
  font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 19px;
  white-space: nowrap; overflow: hidden;
}
#reader-title { overflow: hidden; text-overflow: ellipsis; }
.title-dot { flex: none; width: 13px; height: 13px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px #fff; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: #fff; cursor: pointer; color: var(--ink);
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(40,60,50,.12);
  transition: transform .15s;
}
.icon-btn:hover { transform: scale(1.07); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg, .nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.stage {
  flex: 1; min-height: 0; position: relative;
  display: grid; place-items: center;
  perspective: 2200px;
  touch-action: pan-y pinch-zoom;
  overflow: hidden;
}
.book { position: relative; transform-style: preserve-3d; }
.slot, .leaf, .face { position: absolute; top: 0; height: 100%; }
.slot { background: var(--paper); }
.slot img { border-radius: inherit; }
.slot img, .face img { width: 100%; height: 100%; display: block; object-fit: contain; pointer-events: none; }
.slot.empty { background: transparent; box-shadow: none !important; }
.slot.empty img { visibility: hidden; }

/* Einzelseite */
.book.single .slot.left { display: none; }
.book.single .slot.right {
  left: 0; width: 100%; border-radius: 8px;
  box-shadow: 2px 2px 0 #f3eee6, 4px 4px 0 #e4ddd2, 6px 6px 0 #f3eee6, 8px 8px 0 #dcd4c7, 0 24px 40px -8px rgba(50,70,60,.28);
}
.book.single .leaf { left: 0; width: 100%; }
.book.single .face { border-radius: 8px; }
.book.single .spine { display: none; }

/* Doppelseite */
.book.spread .slot.left { left: 0; width: 50%; border-radius: 8px 0 0 8px; box-shadow: -2px 2px 0 #f3eee6, -4px 4px 0 #e4ddd2, -6px 6px 0 #dcd4c7, 0 24px 40px -8px rgba(50,70,60,.28); }
.book.spread .slot.right { left: 50%; width: 50%; border-radius: 0 8px 8px 0; box-shadow: 2px 2px 0 #f3eee6, 4px 4px 0 #e4ddd2, 6px 6px 0 #dcd4c7, 0 24px 40px -8px rgba(50,70,60,.28); }
.book.spread .leaf { left: 50%; width: 50%; }
.spine {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 60px; transform: translateX(-50%);
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.08) 40%, rgba(0,0,0,.18) 50%, rgba(0,0,0,.08) 60%, transparent);
}

.leaf { transform-origin: left center; transform-style: preserve-3d; z-index: 5; }
.face {
  inset: 0; width: 100%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--paper); overflow: hidden;
}
.face.back { transform: rotateY(180deg); }
.book.single .face.back img { visibility: hidden; }
.book.single .face.back { background: #fbf7f0; }

.nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px; border: 0; border-radius: 50%;
  background: #fff; color: var(--accent); cursor: pointer;
  display: grid; place-items: center; z-index: 10;
  box-shadow: 0 6px 16px rgba(40,60,50,.16);
  transition: opacity .2s, transform .15s;
}
.nav:hover { transform: translateY(-50%) scale(1.08); }
.nav:disabled { opacity: 0; pointer-events: none; }
.nav.prev { left: 14px; }
.nav.next { right: 14px; }
.nav svg { width: 26px; height: 26px; stroke-width: 2.8; }

.bottombar {
  height: calc(var(--bar-h) + 8px + var(--safe-b)); padding-bottom: calc(10px + var(--safe-b));
  justify-content: center; position: relative;
}
.pill {
  display: flex; align-items: center; gap: 14px; width: min(100%, 720px);
  background: #fff; border-radius: 999px; padding: 6px 18px 6px 8px;
  box-shadow: 0 6px 18px rgba(40,60,50,.1);
}
.pageinfo {
  flex: none; min-width: 92px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 14px;
  background: var(--accent-soft); color: var(--accent-deep, var(--accent)); border-radius: 999px; padding: 7px 12px;
}
#slider { flex: 1; min-width: 0; accent-color: var(--accent); height: 30px; cursor: pointer; }
.progress { position: absolute; left: 0; right: 0; top: 0; height: 4px; background: rgba(0,0,0,.04); }
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--sun), var(--mint), var(--sky)); border-radius: 0 4px 4px 0; transition: width .35s; }

.loading { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--muted); font-weight: 700; }
.spinner { font-size: 44px; animation: grow 1.2s ease-in-out infinite; }
@keyframes grow { 0%, 100% { transform: scale(.8) rotate(-8deg); } 50% { transform: scale(1.1) rotate(8deg); } }

.hint {
  display: none; position: absolute; left: 96px; right: 96px; bottom: 18px; height: 54px;
  align-items: center; justify-content: center; text-align: center;
  font-size: 13px; line-height: 1.3; color: var(--muted);
}
@media (orientation: landscape) { .hint { display: none !important; } }
@media (max-width: 640px) and (orientation: portrait) {
  .stage { padding-bottom: 80px; }
}

/* ================= Zoom ================= */
.zoom {
  position: fixed; inset: 0; z-index: 50; background: #2b302d;
  display: flex; flex-direction: column; color: #fff;
}
.zoom .icon-btn { background: rgba(255,255,255,.14); color: #fff; box-shadow: none; }
.zoom-bar {
  flex: none; display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
}
#zoom-level { min-width: 64px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }
#zoom-close { margin-left: 12px; background: var(--pink); }
.zoom-scroll { flex: 1; display: grid; align-content: safe center; overflow: auto; -webkit-overflow-scrolling: touch; padding: 8px 8px calc(16px + var(--safe-b)); touch-action: pan-x pan-y pinch-zoom; }
.zoom-scroll .zwrap { margin: 0 auto 12px; background: #fff; border-radius: 8px; overflow: hidden; }
.zoom-scroll img { display: block; width: 100%; height: auto; }

/* ================= Geschafft ================= */
.celebrate {
  position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 16px;
  background: rgba(45,59,52,.35); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .3s ease;
}
@keyframes fade { from { opacity: 0; } }
.cel-card {
  width: min(100%, 400px); background: #fff; border-radius: 28px; padding: 28px 24px 22px; text-align: center;
  box-shadow: 0 30px 60px rgba(0,0,0,.2);
  animation: pop .5s cubic-bezier(.3,1.6,.5,1);
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.cel-emoji { font-size: 60px; line-height: 1; animation: beat 1.4s ease-in-out infinite; }
.cel-card h2 { font-family: "Fredoka", sans-serif; font-size: 30px; margin: 12px 0 6px; color: var(--accent-deep, var(--accent)); }
.cel-card p { margin: 0 0 20px; color: var(--muted); font-size: 17px; line-height: 1.45; }
.cel-actions { display: flex; flex-direction: column; gap: 10px; }
.btn {
  border: 0; cursor: pointer; border-radius: 999px; padding: 13px 18px; font-weight: 800; font-size: 16px;
  background: #f1f4f2; color: var(--ink);
}
.btn.primary { background: var(--pink); color: #fff; box-shadow: 0 8px 18px -6px var(--pink); }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* ================= Handy ================= */
@media (max-width: 640px) {
  :root { --bar-h: 54px; }
  #shelf { padding-top: calc(56px + var(--safe-t)); }
  .books { gap: 30px; }
  .nav { top: auto; bottom: 18px; transform: none; width: 60px; height: 52px; border-radius: 26px; }
  .nav:hover { transform: none; }
  .nav.prev { left: 16px; }
  .nav.next { right: 16px; }
  .hint { display: flex; }
  .topbar .title { font-size: 17px; }
  .pill { padding-right: 14px; gap: 10px; }
  .pageinfo { min-width: 80px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .floaties { display: none; }
}
