:root {
  --ink: #312d27;
  --muted: #7d7468;
  --paper: #f6f0e4;
  --paper-2: #efe6d7;
  --desk: #d8cdbc;
  --accent: #8e6f59;
  --accent-soft: #bba48d;
  --line: rgba(69, 55, 43, .14);
  --shadow: 0 26px 70px rgba(58, 46, 35, .18);
  --hand: "Caveat", cursive;
  --serif: "Libre Baskerville", serif;
  --sans: "DM Sans", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(circle at 18% 10%, rgba(255,255,255,.72), transparent 25rem),
    linear-gradient(135deg, #e9e0d2, #d8cdbd 58%, #ccc0af);
  overflow-x: hidden;
}
button, input { font: inherit; }
button { color: inherit; }

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 40; opacity: .08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.app { width: min(1380px, 100%); margin: 0 auto; padding: 42px 24px 54px; }
.hero { text-align: center; margin-bottom: 22px; }
.eyebrow {
  margin: 0 0 5px; text-transform: uppercase; letter-spacing: .24em; font-size: .68rem;
  font-weight: 600; color: var(--muted);
}
.hero h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(2rem, 4vw, 3.2rem); margin: 0; }
.subtitle { margin: 8px 0 13px; color: var(--muted); font-family: var(--hand); font-size: 1.25rem; }
.progress-wrap { display: inline-flex; align-items: center; gap: 10px; font-size: .72rem; color: var(--muted); }
.progress-track { width: 116px; height: 4px; border-radius: 99px; background: rgba(49,45,39,.12); overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .55s ease; }

.book-shell { position: relative; display: flex; align-items: center; justify-content: center; transition: filter .25s, transform .25s; }
.book {
  position: relative; width: min(1160px, calc(100vw - 150px)); aspect-ratio: 1.62;
  border-radius: 11px; box-shadow: var(--shadow); perspective: 1800px;
  background: #d5c4ae;
}
.binding {
  position: absolute; z-index: 8; left: 50%; top: 0; bottom: 0; width: 34px; transform: translateX(-50%); pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(67,51,38,.12) 30%, rgba(255,255,255,.45) 49%, rgba(67,51,38,.14) 52%, transparent);
}
.spread {
  position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr;
  opacity: 0; visibility: hidden; transform: translateX(16px) scale(.995); transition: opacity .38s ease, transform .38s ease, visibility .38s;
}
.spread.active { opacity: 1; visibility: visible; transform: none; z-index: 2; }
.spread.leaving-left { transform: translateX(-16px) scale(.995); }
.paper {
  position: relative; min-width: 0; padding: 6% 6.7% 5%; overflow: hidden;
  background:
    linear-gradient(rgba(255,255,255,.16), rgba(255,255,255,0)),
    radial-gradient(circle at 15% 7%, rgba(255,255,255,.6), transparent 30%),
    var(--paper);
}
.page-left { border-radius: 10px 0 0 10px; box-shadow: inset -12px 0 22px -20px rgba(45,34,24,.7); }
.page-right { border-radius: 0 10px 10px 0; box-shadow: inset 12px 0 22px -20px rgba(45,34,24,.7); }
.paper::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .22;
  background-image: repeating-linear-gradient(0deg, transparent 0 4px, rgba(71,56,43,.025) 5px);
}
.page-heading { position: relative; z-index: 1; height: 11%; display: flex; align-items: baseline; gap: 10px; border-bottom: 1px solid var(--line); margin-bottom: 5%; }
.page-heading h2 { font-family: var(--serif); font-size: clamp(.95rem, 1.5vw, 1.35rem); font-weight: 400; margin: 0; }
.page-kicker { text-transform: uppercase; letter-spacing: .19em; font-size: .52rem; color: var(--muted); }
.ghost-heading { opacity: 0; }
.page-number { position: absolute; bottom: 2.6%; left: 50%; transform: translateX(-50%); font-family: var(--serif); font-size: .58rem; color: rgba(49,45,39,.42); }

.polaroid-grid { position: relative; z-index: 1; height: 78%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 7.5% 7%; }
.polaroid {
  min-width: 0; min-height: 0; background: #fffdfa; padding: 7px 7px 8px; border: 1px solid rgba(91,75,59,.09);
  box-shadow: 0 7px 18px rgba(53,42,31,.15), 0 1px 0 rgba(255,255,255,.7) inset;
  transform: rotate(var(--tilt, 0deg)); transition: transform .2s ease, box-shadow .2s ease, opacity .2s;
  display: flex; flex-direction: column; cursor: default; position: relative;
}
.polaroid:nth-child(odd) { --tilt: -1.15deg; }
.polaroid:nth-child(even) { --tilt: .85deg; }
.polaroid:hover:not(.locked) { transform: rotate(0deg) translateY(-3px); box-shadow: 0 12px 25px rgba(53,42,31,.18); }
.polaroid.zoomable { cursor: zoom-in; }
.photo-window {
  flex: 1 1 auto; min-height: 0; aspect-ratio: 1; position: relative; overflow: hidden; background: #181817;
  display: grid; place-items: center;
}
.photo-window .photo-bg {
  position: absolute;
  inset: -8%;
  width: 116%;
  height: 116%;
  object-fit: cover;
  object-position: 50% 50%;
  filter: blur(18px) brightness(.68) saturate(.82);
  transform: scale(1.05);
  opacity: .9;
  display: block;
}
.photo-window .photo-main {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 50%;
  display: block;
  filter: drop-shadow(0 0 10px rgba(0,0,0,.16));
}
.empty-mark { font-family: var(--serif); font-size: clamp(2rem, 4.2vw, 4rem); color: rgba(255,255,255,.75); font-weight: 400; }
.drop-note { position: absolute; inset: auto 8px 8px; text-align: center; color: rgba(255,255,255,.64); font-size: clamp(.48rem,.72vw,.68rem); letter-spacing: .06em; text-transform: uppercase; opacity: .85; }
.polaroid.user.empty { cursor: pointer; }
.polaroid.user.empty.dragover { transform: rotate(0deg) scale(1.035); box-shadow: 0 0 0 3px rgba(142,111,89,.28), 0 14px 28px rgba(53,42,31,.2); }
.polaroid.user.empty.dragover .photo-window { background: #2a2521; }
.polaroid-caption { flex: 0 0 auto; min-height: 44px; padding: 6px 5px 1px; display: flex; align-items: center; justify-content: center; text-align: center; }
.polaroid-caption p { margin: 0; font-family: var(--hand); font-size: clamp(.76rem, 1.15vw, 1.05rem); line-height: 1.05; }
.polaroid.mine.locked .polaroid-caption { color: transparent; user-select: none; }
.polaroid.mine.locked { opacity: .96; }
.polaroid.mine.locked .photo-window { background: #f6f4ef; border: 1px solid rgba(49,45,39,.05); }
.polaroid.mine.locked .empty-mark { color: rgba(49,45,39,.13); }

.uploading .photo-window::after {
  content: ""; position: absolute; width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,.22); border-top-color: white; animation: spin .8s linear infinite;
}
.uploading .empty-mark, .uploading .drop-note { opacity: .15; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes develop {
  0% { opacity: .12; filter: brightness(2.1) contrast(.55) saturate(.1) blur(8px); transform: scale(1.04); }
  35% { opacity: .72; filter: brightness(1.45) contrast(.75) saturate(.45) blur(3px); }
  100% { opacity: 1; filter: none; transform: scale(1); }
}
.revealing .photo-main { animation: develop 2.2s cubic-bezier(.2,.7,.2,1) both; }

.admin-delete {
  display: none; position: absolute; top: 11px; right: 11px; z-index: 4; width: 25px; height: 25px; border: 0; border-radius: 50%;
  background: rgba(126,48,42,.9); color: white; line-height: 1; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.22);
}
.admin-mode .polaroid.user:not(.empty) .admin-delete { display: grid; place-items: center; }
.exit-admin { position: fixed; right: 22px; bottom: 22px; z-index: 21; border: 0; border-radius: 999px; background: #382f29; color: #fff; padding: 10px 15px; cursor: pointer; box-shadow: 0 8px 25px rgba(0,0,0,.18); }

.nav-arrow {
  position: absolute; z-index: 10; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(49,45,39,.12);
  background: rgba(248,244,236,.72); backdrop-filter: blur(8px); box-shadow: 0 6px 18px rgba(53,42,31,.1); cursor: pointer; font-size: 1.35rem; transition: .2s;
}
.nav-arrow:hover:not(:disabled) { background: rgba(255,253,248,.95); transform: translateY(-50%) scale(1.04); }
.nav-arrow:disabled { opacity: .2; cursor: default; }
.nav-arrow.prev { left: 2px; }
.nav-arrow.next { right: 2px; }
.spread-dots { display: flex; justify-content: center; gap: 9px; margin-top: 18px; }
.dot { width: 7px; height: 7px; padding: 0; border: 0; border-radius: 50%; background: rgba(49,45,39,.22); cursor: pointer; transition: .2s; }
.dot.active { width: 22px; border-radius: 20px; background: var(--accent); }

.final-copy-page { display: grid; place-items: center; }
.final-copy-wrap { width: min(78%, 390px); text-align: center; position: relative; z-index: 1; }
.tiny-star { display: block; margin-bottom: 18px; color: var(--accent-soft); font-size: 1.15rem; }
.final-message { min-height: 140px; margin: 0; font-family: var(--hand); font-size: clamp(1.15rem, 2vw, 1.75rem); line-height: 1.35; color: #3f382f; white-space: pre-wrap; }
.final-photo-page { display: grid; place-items: center; }
.final-polaroid-mount { width: min(72%, 410px); position: relative; z-index: 1; }
.polaroid.final { width: 100%; padding: 10px 10px 14px; transform: rotate(.8deg); }
.polaroid.final .polaroid-caption { min-height: 65px; }
.polaroid.final .polaroid-caption p { font-size: clamp(1rem, 1.65vw, 1.45rem); }
.final-lock-count { font-family: var(--hand); font-size: clamp(1.1rem,1.6vw,1.4rem); }
.final-reveal-button { border: 0; background: none; font-family: var(--hand); font-size: clamp(1rem,1.6vw,1.4rem); cursor: pointer; padding: 4px 8px; position: relative; }
.final-reveal-button::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 2px; height: 1px; background: currentColor; transform: scaleX(.2); opacity: .25; transition: .2s; }
.final-reveal-button:hover::after { transform: scaleX(1); opacity: .55; }
.final-ready { animation: gentlePulse 1.8s ease-in-out infinite; }
@keyframes gentlePulse { 50% { transform: translateY(-2px); } }

.modal {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 50px 78px; opacity: 0; pointer-events: none; transition: opacity .22s ease;
  background: rgba(247,241,230,.16); backdrop-filter: blur(9px) saturate(.85);
}
.modal.open { opacity: 1; pointer-events: auto; }
.modal-close { position: absolute; top: 22px; right: 26px; width: 42px; height: 42px; border: 0; border-radius: 50%; background: rgba(255,255,255,.78); cursor: pointer; font-size: 1.7rem; box-shadow: 0 5px 16px rgba(0,0,0,.09); }
.zoom-stage { width: min(560px, 75vw); max-height: 83vh; display: grid; place-items: center; }
.zoom-stage .polaroid { width: 100%; max-height: 82vh; transform: rotate(.2deg); padding: 12px 12px 16px; cursor: default; }
.zoom-stage .photo-window { width: 100%; }
.zoom-stage .polaroid-caption { min-height: 70px; }
.zoom-stage .polaroid-caption p { font-size: clamp(1.25rem,2.2vw,1.75rem); }
.modal-side { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; border: 0; border-radius: 50%; background: rgba(255,255,255,.72); cursor: pointer; font-size: 2rem; line-height: 1; box-shadow: 0 5px 16px rgba(0,0,0,.08); }
.modal-prev { left: 24px; }.modal-next { right: 24px; }
.modal-side:disabled { opacity: .18; cursor: default; }
body.modal-open { overflow: hidden; }
body.modal-open .book-shell, body.modal-open .hero, body.modal-open .spread-dots { filter: blur(5px); transform: scale(.995); }

.delete-dialog { border: 0; padding: 0; background: transparent; color: var(--ink); }
.delete-dialog::backdrop { background: rgba(246,240,228,.5); backdrop-filter: blur(7px); }
.delete-card { width: min(420px, calc(100vw - 38px)); border-radius: 18px; background: #fffaf1; padding: 30px; text-align: center; box-shadow: 0 25px 70px rgba(53,42,31,.2); }
.delete-icon { color: var(--accent); }
.delete-card h3 { font-family: var(--serif); font-weight: 400; margin: 10px 0 7px; }
.delete-card p { color: var(--muted); margin: 0 0 22px; }
.delete-actions { display: flex; gap: 10px; justify-content: center; }
.btn { border: 0; border-radius: 999px; padding: 10px 16px; cursor: pointer; }
.btn.subtle { background: #eee7da; }.btn.danger { background: #84463f; color: white; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; background: rgba(47,40,34,.92); color: white; border-radius: 999px; padding: 10px 15px; font-size: .79rem; transition: .25s; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 960px) {
  .app { padding-inline: 12px; }
  .book { width: calc(100vw - 76px); }
  .nav-arrow { width: 38px; height: 38px; }
  .nav-arrow.prev { left: -2px; }.nav-arrow.next { right: -2px; }
  .paper { padding-inline: 5.5%; }
  .polaroid { padding: 5px 5px 6px; }
}

@media (max-width: 720px) {
  .app { padding: 26px 10px 36px; }
  .hero { margin-bottom: 15px; }
  .subtitle { font-size: 1.05rem; }
  .book-shell { padding: 0 32px; }
  .book { width: 100%; aspect-ratio: auto; min-height: 980px; }
  .binding { display: none; }
  .spread { grid-template-columns: 1fr; align-content: start; position: absolute; overflow-y: auto; border-radius: 10px; }
  .paper { min-height: 470px; border-radius: 0; padding: 28px 28px 34px; }
  .page-left { border-radius: 10px 10px 0 0; box-shadow: inset 0 -8px 18px -20px rgba(45,34,24,.7); }
  .page-right { border-radius: 0 0 10px 10px; box-shadow: inset 0 8px 18px -20px rgba(45,34,24,.7); }
  .page-heading { height: 45px; margin-bottom: 20px; }
  .polaroid-grid { height: 365px; gap: 20px 18px; }
  .polaroid-caption { min-height: 42px; }
  .polaroid-caption p { font-size: .95rem; }
  .nav-arrow { top: 46%; }
  .nav-arrow.prev { left: 0; }.nav-arrow.next { right: 0; }
  .final-copy-page, .final-photo-page { min-height: 480px; }
  .final-polaroid-mount { width: min(70%, 330px); }
  .modal { padding: 48px 42px; }
  .zoom-stage { width: min(510px, 86vw); }
  .modal-side { width: 38px; height: 38px; }
  .modal-prev { left: 7px; }.modal-next { right: 7px; }
}

@media (max-width: 470px) {
  .book-shell { padding-inline: 25px; }
  .book { min-height: 860px; }
  .paper { padding: 22px 20px 30px; min-height: 415px; }
  .polaroid-grid { height: 320px; gap: 15px 12px; }
  .polaroid-caption p { font-size: .82rem; }
  .drop-note { font-size: .43rem; }
  .final-copy-page, .final-photo-page { min-height: 430px; }
  .final-message { font-size: 1.28rem; }
}

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