:root {
  --bg: #f7f3ee;
  --ink: #2c2723;
  --muted: #7d756c;
  --accent: #b08968;
  --accent-dark: #8c6a4f;
  --card: #fffdfa;
  --danger: #b3553a;
  --ok: #5a7d5a;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(60, 45, 30, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.wrap {
  width: 100%;
  max-width: 560px;
  padding: 24px 20px 48px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ---------- Front page ---------- */
.cover {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: block;
}

.headline {
  font-size: 1.9rem;
  font-weight: 700;
  text-align: center;
  margin: 28px 0 8px;
  letter-spacing: 0.2px;
}

.subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 0 auto 32px;
  max-width: 42ch;
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 16px 24px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 1.1rem;
  box-shadow: var(--shadow);
  transition: transform 0.05s ease, background 0.15s ease;
  text-decoration: none;
  text-align: center;
  display: inline-block;
}
.btn:active { transform: translateY(1px); }
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-block { display: block; width: 100%; }

/* Ensure the hidden attribute wins over display rules like .btn-block. */
[hidden] { display: none !important; }

/* Stacked full-width buttons on phones, side by side on wider screens. */
.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (min-width: 520px) {
  .btn-stack { flex-direction: row; }
  .btn-stack .btn { flex: 1; }
}

.btn-secondary {
  background: transparent;
  color: var(--accent-dark);
  box-shadow: none;
  border: 2px solid var(--accent);
}
.btn-secondary:hover { background: rgba(176, 137, 104, 0.1); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-weight: 500;
  padding: 10px;
  font-size: 0.95rem;
}
.btn-ghost:hover { color: var(--ink); }

.center { text-align: center; }
.spacer { flex: 1; }

/* ---------- Share page ---------- */
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 8px 0 4px;
  text-align: center;
}
.page-sub {
  text-align: center;
  color: var(--muted);
  margin: 0 0 24px;
}

.notice {
  background: #fbeee6;
  border: 1px solid #e7c9b3;
  color: #8a5a3a;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  font-size: 0.95rem;
  line-height: 1.45;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 8px 0 24px;
}
@media (max-width: 380px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: #e9e1d8;
  box-shadow: 0 2px 8px rgba(60, 45, 30, 0.1);
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb .remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb .status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
}
.thumb.failed .status { background: rgba(179, 85, 58, 0.7); }
.thumb.done .status { background: rgba(90, 125, 90, 0.6); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  border: 2px dashed #d8cdbf;
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.actions { display: flex; flex-direction: column; gap: 12px; }

.thankyou {
  text-align: center;
  padding: 48px 0;
}
.thankyou .check {
  font-size: 3rem;
  margin-bottom: 12px;
}
.thankyou h2 { margin: 0 0 8px; font-size: 1.5rem; }
.thankyou p { color: var(--muted); margin: 0 0 28px; }

.hidden { display: none !important; }

/* ---------- Modal dialog (share page submit results) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(44, 39, 35, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}
.modal-card h2 { margin: 0 0 10px; font-size: 1.25rem; }
.modal-card p {
  color: var(--muted);
  margin: 0 0 22px;
  line-height: 1.5;
}

footer {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 24px 0 8px;
}

/* ---------- Photobook ---------- */
/* Scroll-driven 3D flipbook (design borrowed from example-book/The Raven
   Scholar, re-themed to the wedding palette). Leaves are injected and
   rotated by photobook.js; everything here is scoped to .book-* so the
   other pages are unaffected. */

body.book-body { display: block; }

.book-scroller {
  height: 100vh;
  height: 100dvh; /* iOS toolbar collapse shouldn't jitter the stage */
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  background: radial-gradient(130% 120% at 50% 8%, #6b5140 0%, #4a3a2d 45%, #322820 100%);
  scrollbar-width: thin;
  scrollbar-color: var(--accent-dark) #322820;
}

.book-stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.book {
  position: relative;
  width: min(90vw, 820px);
  height: min(66vh, 540px);
  perspective: 2400px;
}

/* Cover boards behind the leaves. */
.book-boards {
  position: absolute;
  inset: -16px -18px;
  background: linear-gradient(120deg, var(--accent-dark) 0%, #7a5c44 45%, #5d4634 100%);
  border-radius: 5px 10px 10px 5px;
  box-shadow: 0 40px 80px -30px rgba(30, 20, 10, 0.8),
              0 8px 24px -8px rgba(30, 20, 10, 0.6),
              inset 0 0 0 1px rgba(255, 250, 240, 0.14);
}

/* Endpapers: the static spread under the turning leaves. */
.book-endpaper {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  color: rgba(140, 106, 79, 0.18);
}
.book-endpaper-left {
  left: 0;
  background: radial-gradient(120% 120% at 70% 30%, var(--card) 0%, var(--bg) 78%, #ece2d2 100%);
  box-shadow: inset -26px 0 42px -30px rgba(90, 70, 50, 0.5);
}
.book-endpaper-right {
  left: 50%;
  background: radial-gradient(120% 120% at 30% 30%, var(--card) 0%, var(--bg) 78%, #ece2d2 100%);
  box-shadow: inset 26px 0 42px -30px rgba(90, 70, 50, 0.5);
}

/* A leaf = one turning sheet; front face is a right-hand page, back face a
   left-hand page. transform/z-index are set per-frame by photobook.js. */
.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  will-change: transform;
}

.leaf-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7% 8%;
}
.leaf-front {
  background: radial-gradient(120% 120% at 30% 22%, var(--card) 0%, var(--bg) 68%, #efe6d9 100%);
  border-left: 1px solid rgba(90, 70, 50, 0.14);
  box-shadow: inset 26px 0 44px -34px rgba(90, 70, 50, 0.5),
              inset 0 0 60px rgba(176, 137, 104, 0.06);
}
.leaf-back {
  transform: rotateY(180deg);
  background: radial-gradient(120% 120% at 70% 22%, var(--card) 0%, var(--bg) 68%, #efe6d9 100%);
  border-right: 1px solid rgba(90, 70, 50, 0.14);
  box-shadow: inset -26px 0 44px -34px rgba(90, 70, 50, 0.5),
              inset 0 0 60px rgba(176, 137, 104, 0.06);
}
/* Only the face turned toward the reader is visible (swap at half-turn). */
.leaf.turned .leaf-front,
.leaf:not(.turned) .leaf-back { opacity: 0; }

.leaf-photo {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.leaf-photo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff; /* photo mat */
  padding: 6px;
  border-radius: 3px;
  box-shadow: 0 3px 14px rgba(60, 45, 30, 0.25);
}
.leaf-photo .photo-error {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.leaf-num {
  position: absolute;
  bottom: 5%;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--muted);
}
.leaf-front .leaf-num { right: 8%; }
.leaf-back .leaf-num { left: 8%; }

/* Thin spine-gutter shadow above the pages. */
.book-gutter {
  position: absolute;
  top: 2%;
  left: calc(50% - 9px);
  width: 18px;
  height: 96%;
  pointer-events: none;
  z-index: 2;
  background: linear-gradient(90deg, rgba(70, 50, 30, 0) 0%, rgba(70, 50, 30, 0.22) 48%,
              rgba(70, 50, 30, 0.22) 52%, rgba(70, 50, 30, 0) 100%);
}

/* Cover / decorative faces. */
.leaf-cover { text-align: center; padding: 0 6%; }
.leaf-cover img {
  width: min(70%, 260px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.leaf-cover .kicker {
  font-size: 12px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin-bottom: 14px;
}
.leaf-cover h2 {
  margin: 0;
  font-size: clamp(22px, 4vw, 34px);
  color: var(--ink);
}
.leaf-cover .cover-hint {
  font-size: 12px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 18px;
}
.leaf-flourish {
  font-size: 54px;
  color: rgba(140, 106, 79, 0.25);
}
.leaf-fin {
  text-align: center;
  color: var(--muted);
}
.leaf-fin .leaf-flourish { display: block; margin-bottom: 14px; }
.leaf-empty { text-align: center; }
.leaf-empty p { color: var(--muted); margin: 0 0 20px; }

/* Fixed chrome around the book (non-interactive except the back link). */
.book-chrome {
  position: fixed;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 8;
  pointer-events: none;
  color: rgba(247, 243, 238, 0.65);
}
.book-chrome-top {
  top: 26px;
  font-size: 12px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
}
.book-chrome-bottom { bottom: 24px; }
.book-counter {
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--accent);
}
.book-progress {
  height: 1px;
  width: 180px;
  margin: 12px auto 0;
  background: rgba(247, 243, 238, 0.16);
  position: relative;
  overflow: hidden;
}
.book-progress > div {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.16s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .book-progress > div { transition: none; }
}

.book-hint {
  position: fixed;
  bottom: 60px;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 8;
  pointer-events: none;
  transition: opacity 0.6s ease;
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: rgba(247, 243, 238, 0.65);
}

.book-back {
  position: fixed;
  top: 16px;
  left: 12px;
  z-index: 9;
  color: rgba(247, 243, 238, 0.7);
}
.book-back:hover { color: #fff; }

.book-notice {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  max-width: min(90vw, 420px);
  margin: 0;
}

.book-grid-toggle {
  position: fixed;
  top: 16px;
  right: 12px;
  z-index: 9;
  color: rgba(247, 243, 238, 0.7);
}
.book-grid-toggle:hover { color: #fff; }

/* ---------- Photobook: grid view ---------- */
/* Product-page style alternative to the flipbook; photobook.js toggles it
   against .book-scroller. Scrolls with the document, on the light theme. */

.grid-view {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}
.grid-view > .btn { margin-bottom: 20px; }
.grid-view .empty p { margin: 0 0 20px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.photo-grid .grid-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: #e9e1d8;
  box-shadow: 0 2px 8px rgba(60, 45, 30, 0.1);
}
.photo-grid .grid-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#gridSentinel { height: 1px; }

/* ---------- Photobook: mobile single-page mode ---------- */
/* photobook.js toggles body.book-mobile at the (max-width: 700px) breakpoint.
   The book becomes one portrait page; leaves stop rotating (no 3D) and
   instead crossfade — .m-active marks the visible leaf and the shared
   .turned rule picks which of its faces shows. */

body.book-mobile .book {
  width: min(92vw, 440px);
  height: min(72dvh, 640px);
  perspective: none;
}
body.book-mobile .book-boards {
  inset: -10px -10px;
  border-radius: 8px;
}
body.book-mobile .book-endpaper-left { display: none; }
body.book-mobile .book-endpaper-right {
  left: 0;
  width: 100%;
  box-shadow: none;
}
body.book-mobile .book-gutter { display: none; }

body.book-mobile .leaf {
  left: 0;
  width: 100%;
  transform: none !important; /* wins over any stale inline flip transform */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  will-change: opacity;
}
body.book-mobile .leaf.m-active {
  opacity: 1;
  pointer-events: auto;
}
body.book-mobile .leaf-face {
  padding: 6% 7%;
  transition: opacity 0.28s ease;
}
body.book-mobile .leaf-front {
  border-left: none;
  box-shadow: inset 0 0 60px rgba(176, 137, 104, 0.06);
}
body.book-mobile .leaf-back {
  transform: none; /* the flat page replaces the rotated back face */
  border-right: none;
  box-shadow: inset 0 0 60px rgba(176, 137, 104, 0.06);
}
body.book-mobile .leaf-front .leaf-num { right: 7%; }
body.book-mobile .leaf-back .leaf-num { left: auto; right: 7%; }

@media (prefers-reduced-motion: reduce) {
  body.book-mobile .leaf,
  body.book-mobile .leaf-face { transition: none; }
}
