:root {
  --pink: #c42e7c;
  --pink-deep: #8f1d5a;
  --pink-soft: #f7d6e8;
  --plum: #2a0f22;
  --plum-2: #3b1631;
  --ink: #2a0f22;
  --paper: #fff8fc;
  --gold: #f5b83d;
  --blue: #5fc8f0;
  --text-on-dark: #fdeef6;
  --muted: #b98aa6;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(20, 0, 15, .45);
  --page-ratio: 1244 / 1754;
  --font-brand: 'Luckiest Guy', 'Arial Black', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text-on-dark);
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(95, 200, 240, .18), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(245, 184, 61, .16), transparent 60%),
    linear-gradient(160deg, var(--plum-2), var(--plum));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
[hidden] { display: none !important; }

/* ---------- Typo ---------- */
.brand {
  font-family: var(--font-brand);
  font-weight: 400;
  color: var(--pink);
  letter-spacing: .02em;
  margin: 0;
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1;
  text-shadow: -3px -3px 0 #fff, 3px -3px 0 #fff, -3px 3px 0 #fff, 3px 3px 0 #fff, 0 3px 0 #fff, 0 -3px 0 #fff, 3px 0 0 #fff, -3px 0 0 #fff, 4px 7px 10px rgba(0,0,0,.45);
}
.brand.sm { font-size: 1.7rem; text-shadow: -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff, 2px 2px 0 #fff, 3px 5px 8px rgba(0,0,0,.35); }
.tagline { font-family: var(--font-brand); color: #fff; letter-spacing: .04em; margin: .6rem 0 1.4rem; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .9rem; margin: 0; }
.error { color: #ff8fb6; min-height: 1.2em; margin: 0; font-weight: 700; }

/* ---------- Buttons & Inputs ---------- */
.btn {
  font: 800 1rem/1 var(--font-body);
  border: 0; border-radius: 999px; padding: .85rem 1.3rem; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s;
  color: #fff; white-space: nowrap;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn:focus-visible, input:focus-visible, .nav:focus-visible, .tab:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn-primary { background: var(--pink); box-shadow: 0 4px 0 var(--pink-deep), 0 8px 18px rgba(196,46,124,.35); }
.btn-primary:hover { background: #d53a8b; }
.btn-gold { background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 #b9821a; }
.btn-ghost { background: rgba(255,255,255,.08); color: var(--text-on-dark); box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.18); }
.btn-ghost:hover { background: rgba(255,255,255,.14); }
.btn-sm { padding: .6rem 1rem; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: progress; }

label { display: grid; gap: .35rem; font-weight: 700; font-size: .9rem; text-align: left; }
input {
  font: 600 1rem var(--font-body); color: var(--ink);
  background: var(--paper); border: 2px solid transparent; border-radius: 12px; padding: .75rem .9rem; width: 100%;
}
input:focus { border-color: var(--pink); outline: none; }
.stack { display: grid; gap: .9rem; }
.row { display: flex; gap: .7rem; justify-content: flex-end; align-items: end; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }
.grow { flex: 1 1 180px; }
.center { text-align: center; justify-items: center; }

/* ---------- Login ---------- */
.screen { min-height: 100vh; min-height: 100dvh; }
#login { display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(420px, 100%); text-align: center;
  background: linear-gradient(180deg, rgba(196,46,124,.95), rgba(160,30,100,.95));
  border-radius: 28px; padding: 32px 24px 28px; box-shadow: var(--shadow);
  position: relative;
}
.login-logo { width: 120px; height: 120px; margin: -92px auto 14px; display: block; filter: drop-shadow(0 12px 18px rgba(0,0,0,.45)); animation: bob 3.2s ease-in-out infinite; }
.login-card .hint { color: #ffd4ea; }
.signup { margin-top: 1rem; text-align: left; }
.signup summary { cursor: pointer; font-weight: 800; color: #fff; }
#login-container { min-height: 380px; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(42, 15, 34, .78); backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mini { display: flex; align-items: center; gap: 10px; font-family: var(--font-brand); font-size: 1.25rem; color: #fff; letter-spacing: .03em; }
.brand-mini img { width: 34px; height: 34px; }
.progress { display: flex; align-items: center; gap: 10px; flex: 1 1 160px; min-width: 140px; }
.progress-bar { flex: 1; height: 12px; border-radius: 999px; background: rgba(255,255,255,.12); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--pink), var(--gold)); transition: width .8s cubic-bezier(.2,.9,.2,1); }
.progress strong { font-variant-numeric: tabular-nums; font-size: .95rem; white-space: nowrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
#user-name { font-weight: 800; }

/* ---------- Buch ---------- */
.stage {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 20px 16px 8px; max-width: 980px; margin: 0 auto;
}
.book {
  justify-self: center;
  position: relative;
  height: min(calc(100dvh - 170px), calc((100vw - 120px) / (1244 / 1754)));
  max-width: calc(100vw - 32px);
  aspect-ratio: var(--page-ratio);
  perspective: 2200px;
  touch-action: pan-y;
}
.page {
  position: absolute; inset: 0;
  border-radius: 10px; overflow: hidden;
  background: #fff center / cover no-repeat;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,.06);
  transform-origin: left center;
  backface-visibility: hidden;
  user-select: none;
}
.page::after { /* leichte Papier-Kante zur Bindung */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.18), transparent 4%, transparent 96%, rgba(255,255,255,.08));
}
.page.flip-out-next { animation: flipOutNext .55s cubic-bezier(.45,.05,.55,.95) forwards; z-index: 2; }
.page.flip-in-prev  { animation: flipInPrev .55s cubic-bezier(.45,.05,.55,.95) forwards; z-index: 2; }
@keyframes flipOutNext { to { transform: rotateY(-100deg); opacity: .2; } }
@keyframes flipInPrev  { from { transform: rotateY(-100deg); opacity: .2; } to { transform: none; opacity: 1; } }

.slot {
  position: absolute; width: 15.4%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%;
}
.slot img { width: 100%; height: 100%; display: block; border-radius: 50%; filter: drop-shadow(0 3px 4px rgba(60,0,40,.35)); }
.slot.new img { animation: stickOn 1.1s cubic-bezier(.2,1.4,.4,1) both; animation-delay: var(--delay, 0s); }
.slot.new::after {
  content: ''; position: absolute; inset: -30%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(255,255,255,.95) 0 20%, rgba(245,184,61,.6) 35%, transparent 65%);
  animation: sparkle 1.1s ease-out both; animation-delay: var(--delay, 0s);
}
@keyframes stickOn {
  0%   { transform: scale(2.4) rotate(-30deg); opacity: 0; filter: drop-shadow(0 30px 25px rgba(0,0,0,.4)); }
  55%  { transform: scale(.92) rotate(6deg); opacity: 1; }
  75%  { transform: scale(1.05) rotate(-2deg); }
  100% { transform: none; opacity: 1; }
}
@keyframes sparkle { 0%,40% { opacity: 0; transform: scale(.3); } 60% { opacity: 1; } 100% { opacity: 0; transform: scale(1.4); } }

.page-cover-cta { position: absolute; left: 50%; bottom: 3.5%; transform: translateX(-50%); }

.nav {
  width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.1); color: #fff; font-size: 2rem; line-height: 1;
  display: grid; place-items: center; padding-bottom: 4px;
  transition: background .15s, transform .15s;
}
.nav:hover:not([disabled]) { background: var(--pink); transform: scale(1.06); }
.nav[disabled] { opacity: .2; cursor: default; }

.dots { display: flex; justify-content: center; gap: 8px; padding: 8px 16px 20px; flex-wrap: wrap; }
.dot {
  border: 0; cursor: pointer; padding: 0; height: 10px; width: 10px; border-radius: 999px;
  background: rgba(255,255,255,.25); transition: width .25s, background .25s; position: relative;
}
.dot.active { width: 28px; background: var(--pink); }
.dot.has-new::after { content: ''; position: absolute; top: -4px; right: -4px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }

/* ---------- Dialoge ---------- */
.dialog {
  border: 0; border-radius: 24px; padding: 26px; width: min(440px, calc(100vw - 32px));
  background: linear-gradient(180deg, #4a1c3d, #2f1128); color: var(--text-on-dark); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(15, 0, 10, .6); backdrop-filter: blur(3px); }
.code-input { font: 400 1.5rem var(--font-brand); letter-spacing: .12em; text-align: center; text-transform: uppercase; padding: .9rem; }
.win-sticker { width: 140px; animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 14px 18px rgba(0,0,0,.5)); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--paper); color: var(--ink); font-weight: 800; padding: .9rem 1.3rem; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 50; max-width: calc(100vw - 32px); text-align: center;
  animation: toastIn .35s cubic-bezier(.2,1.3,.4,1);
}
@keyframes toastIn { from { transform: translate(-50%, 20px); opacity: 0; } }

/* ---------- Konfetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- Admin ---------- */
.admin { position: fixed; inset: 0; z-index: 30; background: rgba(20, 5, 16, .7); backdrop-filter: blur(6px); overflow-y: auto; padding: 24px 16px; }
.admin-inner { max-width: 820px; margin: 0 auto; background: linear-gradient(180deg, #4a1c3d, #2f1128); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); }
.admin-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.admin-head .tabs { flex: 1; display: flex; gap: 6px; }
.tab { border: 0; cursor: pointer; font: 800 .95rem var(--font-body); color: var(--text-on-dark); background: transparent; padding: .55rem 1rem; border-radius: 999px; }
.tab.active { background: rgba(255,255,255,.12); }
.note-field { margin-bottom: 14px; }
.friends { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.friend {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; align-items: center;
  background: rgba(255,255,255,.06); border-radius: 16px; padding: 14px 16px;
}
.friend-name { font-weight: 800; font-size: 1.05rem; }
.friend-mail { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.friend-bar { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.friend-bar .progress-bar { height: 8px; }
.friend-bar small { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.friend-actions { display: flex; gap: 6px; }
.friend-actions .btn { padding: .5rem .8rem; }
.friend.bump { animation: bump .5s ease; }
@keyframes bump { 40% { background: rgba(245,184,61,.25); } }

.codes { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: .92rem; }
.codes th { text-align: left; color: var(--muted); font-weight: 700; padding: 8px; border-bottom: 1px solid rgba(255,255,255,.1); }
.codes td { padding: 10px 8px; border-bottom: 1px solid rgba(255,255,255,.06); vertical-align: middle; }
.codes code { font: 400 1rem var(--font-brand); letter-spacing: .08em; color: #fff; }
.pill { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 800; }
.pill.open { background: rgba(95,200,240,.2); color: var(--blue); }
.pill.value { background: rgba(245,184,61,.2); color: var(--gold); }
.pill.used { background: rgba(255,255,255,.08); color: var(--muted); }
.icon-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-weight: 800; padding: .3rem .5rem; border-radius: 8px; }
.icon-btn:hover { color: #fff; background: rgba(255,255,255,.08); }

/* ---------- Druckbogen ---------- */
.print-sheet { display: none; }
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff !important; }
  body > *:not(.print-sheet) { display: none !important; }
  .print-sheet { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 6mm; }
  .print-card { border: 1px dashed #c42e7c; border-radius: 4mm; padding: 4mm; text-align: center; color: #2a0f22; break-inside: avoid; font-family: var(--font-body); }
  .print-card .qr { width: 32mm; height: 32mm; margin: 2mm auto; }
  .print-card .qr img, .print-card .qr canvas { width: 100% !important; height: 100% !important; }
  .print-card h3 { font: 400 13pt var(--font-brand); color: #c42e7c; margin: 0; }
  .print-card code { font: 400 11pt var(--font-brand); letter-spacing: .08em; }
  .print-card p { margin: 1mm 0 0; font-size: 8pt; }
}

/* ---------- Klein ---------- */
@media (max-width: 640px) {
  .topbar { gap: 10px; }
  .brand-mini span { display: none; }
  .progress { order: 3; flex-basis: 100%; }
  .actions { margin-left: auto; }
  .actions #logout { padding: .6rem .8rem; }
  .actions #logout .who { display: none; }
  .stage { grid-template-columns: 1fr; padding: 14px 16px 4px; }
  .nav { display: none; }
  .book { height: min(calc(100dvh - 200px), calc((100vw - 32px) / (1244 / 1754))); }
  .codes th:nth-child(3), .codes td:nth-child(3) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}
