:root {
  --paper: #f4eee4;
  --paper-2: #ece4d6;
  --card: #fffcf6;
  --ink: #1e1a15;
  --ink-2: #4a4239;
  --muted: #8a7f72;
  --line: rgba(30, 26, 21, .12);
  --accent: #9a7442;
  --accent-ink: #fffaf1;
  --ok: #4f7a52;
  --danger: #a3433a;
  --shadow: 0 18px 50px -18px rgba(40, 28, 10, .35);
  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "Manrope", system-ui, -apple-system, sans-serif;
  --hand: "Caveat", "Segoe Script", cursive;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #13110e; --paper-2: #1b1814; --card: #1f1b17; --ink: #f3ece1; --ink-2: #cfc5b7;
    --muted: #8f8577; --line: rgba(243, 236, 225, .12); --accent: #cfa96c; --accent-ink: #1a140b;
    --shadow: 0 18px 50px -18px rgba(0, 0, 0, .7); color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--paper); }
body {
  margin: 0; min-height: 100dvh; background: var(--paper); color: var(--ink);
  font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased;
}
body::before { /* paper grain */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .3 0 0 0 0 .2 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) body::before { mix-blend-mode: screen; opacity: .25; } }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.wrap { position: relative; z-index: 1; max-width: 1100px; margin: 0 auto; padding: 0 16px calc(120px + env(safe-area-inset-bottom)); }

/* ---------- hero ---------- */
.hero { text-align: center; padding: calc(56px + env(safe-area-inset-top)) 0 28px; }
.eyebrow { font-size: 11px; letter-spacing: .32em; text-transform: uppercase; color: var(--muted); margin: 0 0 18px; font-weight: 600; }
.names {
  font-family: var(--serif); font-weight: 400; font-style: italic; line-height: .92;
  font-size: clamp(3.4rem, 16vw, 7.5rem); margin: 0; letter-spacing: -.02em;
  opacity: 0; animation: rise 1.1s .1s cubic-bezier(.2, .7, .2, 1) forwards;
}
.names .amp { display: block; font-size: .5em; color: var(--accent); margin: .08em 0 .06em; }
.ornament { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 22px auto 16px; color: var(--accent); max-width: 240px; }
.ornament::before, .ornament::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .5; }
.lede { font-family: var(--serif); font-size: 1.3rem; line-height: 1.35; color: var(--ink-2); max-width: 30ch; margin: 0 auto; text-wrap: balance;
  opacity: 0; animation: rise 1s .35s cubic-bezier(.2, .7, .2, 1) forwards; }
.counter { margin-top: 18px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter b { color: var(--ink); font-weight: 700; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

/* ---------- actions ---------- */
.actions { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 18px 0 36px;
  opacity: 0; animation: rise 1s .55s cubic-bezier(.2, .7, .2, 1) forwards; }
.shutter { position: relative; display: grid; place-items: center; width: 108px; height: 108px; border-radius: 50%; cursor: pointer; }
.shutter input, .pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; font-size: 0; }
.shutter .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--ink); transition: transform .3s; }
.shutter .disc { width: 84px; height: 84px; border-radius: 50%; background: var(--ink); color: var(--paper); display: grid; place-items: center;
  transition: transform .18s cubic-bezier(.3, .7, .4, 1.4); box-shadow: var(--shadow); }
.shutter:active .disc { transform: scale(.88); }
.shutter .ring::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 1px solid var(--accent); opacity: 0; animation: halo 3.2s 1.6s ease-out infinite; }
@keyframes halo { 0% { opacity: .7; transform: scale(.9); } 70%, 100% { opacity: 0; transform: scale(1.25); } }
.shutter-label { font-size: 12px; letter-spacing: .22em; text-transform: uppercase; font-weight: 700; margin-top: -4px; }
.pick { position: relative; display: inline-flex; align-items: center; gap: 10px; padding: 12px 20px; border-radius: 999px;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--card) 70%, transparent); font-weight: 600; font-size: 14px; }
.pick:active { transform: scale(.97); }
.shutter:focus-within .ring, .pick:focus-within { outline: 2px solid var(--accent); outline-offset: 4px; }

/* ---------- tabs ---------- */
.bar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: center; padding: 10px 0 12px;
  background: linear-gradient(var(--paper) 70%, transparent); }
.tabs { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 7px 18px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); transition: .25s; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 2px 10px -4px rgba(0,0,0,.25); }

/* ---------- grid ---------- */
.grid { columns: 2; column-gap: 8px; }
@media (min-width: 640px) { .grid { columns: 3; column-gap: 12px; } }
@media (min-width: 980px) { .grid { columns: 4; } }
.tile { position: relative; display: block; width: 100%; padding: 0; border: 0; margin: 0 0 8px; break-inside: avoid;
  border-radius: 10px; overflow: hidden; background: var(--paper-2); }
@media (min-width: 640px) { .tile { margin-bottom: 12px; } }
.tile img, .tile video { display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .6s, transform .6s; transform: scale(1.04); }
.tile.loaded img, .tile.loaded video { opacity: 1; transform: none; }
.tile.fresh { animation: pop .8s cubic-bezier(.2, .8, .2, 1.2); }
.tile.fresh::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 2px var(--accent); animation: fadeout 3s 1s forwards; pointer-events: none; }
@keyframes pop { from { transform: scale(.6) rotate(-3deg); opacity: 0; } }
@keyframes fadeout { to { opacity: 0; } }
.badge { position: absolute; right: 8px; top: 8px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(0,0,0,.45); backdrop-filter: blur(6px); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-family: var(--serif); font-size: 1.25rem; }

/* ---------- upload tray ---------- */
.tray { position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%); z-index: 20;
  width: min(440px, calc(100% - 24px)); background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow);
  transition: transform .5s cubic-bezier(.2, .8, .2, 1); overflow: hidden; }
.tray.show { transform: translate(-50%, 0); }
.tray-head { display: flex; align-items: center; gap: 14px; padding: 12px 16px; width: 100%; border: 0; background: none; text-align: left; }
.ring-prog { width: 40px; height: 40px; flex: none; transform: rotate(-90deg); }
.ring-prog circle { fill: none; stroke-width: 3.5; }
.ring-prog .bg { stroke: var(--line); }
.ring-prog .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .3s; }
.tray-title { font-weight: 700; font-size: 14px; }
.tray-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tray-list { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 14px; scrollbar-width: none; }
.tray-item { position: relative; flex: none; width: 54px; height: 54px; border-radius: 10px; overflow: hidden; background: var(--paper-2); }
.tray-item img { width: 100%; height: 100%; object-fit: cover; }
.tray-item .bar-p { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width .3s; }
.tray-item.done::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.35); color: #fff; font-weight: 700; }
.tray-item.error::after { content: "!"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(163,67,58,.7); color: #fff; font-weight: 700; }
.tray-item.queued img { opacity: .5; }

/* hearts burst */
.burst { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.burst span { position: absolute; bottom: 60px; left: 50%; font-size: 18px; color: var(--accent); animation: float 2.2s cubic-bezier(.2, .7, .3, 1) forwards; }
@keyframes float { from { transform: translate(0, 0) scale(.4) rotate(0); opacity: 1; } to { transform: translate(var(--x), var(--y)) scale(1.2) rotate(var(--r)); opacity: 0; } }

/* ---------- sheet (name) ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; display: grid; align-items: end; background: rgba(20, 14, 6, .35); backdrop-filter: blur(3px);
  animation: fadein .3s; }
.sheet-card { background: var(--card); border-radius: 26px 26px 0 0; padding: 26px 22px calc(22px + env(safe-area-inset-bottom)); max-width: 520px; width: 100%; margin: 0 auto;
  animation: up .45s cubic-bezier(.2, .8, .2, 1); box-shadow: var(--shadow); }
.sheet h2 { font-family: var(--serif); font-weight: 400; font-size: 2rem; margin: 0 0 4px; }
.sheet p { margin: 0 0 18px; color: var(--muted); }
.sheet input { width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--paper); font-size: 17px; outline: none; }
.sheet input:focus { border-color: var(--accent); }
.btn { display: block; width: 100%; padding: 15px; border-radius: 14px; border: 0; background: var(--ink); color: var(--paper); font-weight: 700; margin-top: 12px; font-size: 15px; }
.btn.link { background: none; color: var(--muted); font-weight: 500; margin-top: 4px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fadein { from { opacity: 0; } }

/* ---------- lightbox ---------- */
.lb { position: fixed; inset: 0; z-index: 50; background: rgba(8, 6, 4, .96); color: #fff; display: grid; grid-template-rows: auto 1fr auto; animation: fadein .25s; touch-action: none; }
.lb-top, .lb-bottom { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; gap: 10px; }
.lb-bottom { padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
.lb-stage { position: relative; overflow: hidden; display: grid; place-items: center; }
.lb-media { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .3s cubic-bezier(.2, .8, .2, 1), opacity .3s; user-select: none; -webkit-user-drag: none; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(255,255,255,.1); color: #fff; display: grid; place-items: center; }
.lb-who { font-family: var(--hand); font-size: 1.6rem; line-height: 1; }
.lb-when { font-size: 12px; opacity: .6; }
.lb-save { display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 999px; border: 0; background: #fff; color: #111; font-weight: 700; font-size: 14px; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); }
.lb-nav.prev { left: 12px; } .lb-nav.next { right: 12px; }
@media (hover: none) { .lb-nav { display: none; } }

/* ---------- gate ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; text-align: center; padding: 24px; position: relative; z-index: 1; }
.gate .names { font-size: clamp(3rem, 14vw, 6rem); }
.gate p { color: var(--muted); max-width: 30ch; margin: 18px auto 0; }

.toast { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 600; animation: fadein .3s; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
.tray-item.preparing { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
/* videos: always-visible poster box */
.tile.vid { background: radial-gradient(circle at 50% 40%, #3a3129, #1c1814); }
.tile.vid::before { content: ""; position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%;
  background: rgba(255,255,255,.18) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E") center/22px no-repeat; }
.tile.vid img, .tile.vid video { position: relative; z-index: 1; }
.lb-novideo { text-align: center; color: #fff; padding: 24px; }
.lb-novideo p { opacity: .75; margin: 0 0 14px; }
.tile .badge { z-index: 2; }
.pick-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
