:root {
  --bg-1: #070b17;
  --bg-2: #0c1326;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-strong: rgba(255, 255, 255, 0.06);
  --stroke: rgba(236, 228, 210, 0.1);
  --stroke-gold: rgba(212, 176, 114, 0.32);
  --text: #ece6da;
  --muted: rgba(236, 230, 218, 0.56);
  --gold: #d4b072;
  --gold-light: #ead2a0;
  --rose: #c99393;
  --radius: 20px;
  --serif: 'Cormorant Garamond', 'Cormorant', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-soft: cubic-bezier(0.25, 0.8, 0.25, 1);
  color-scheme: dark;
  font-family: var(--sans);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--bg-1);
  color: var(--text);
  font-size: 15.5px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
/* Fixed layer rather than background-attachment: fixed, which iOS Safari ignores. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -3;
  background:
    radial-gradient(900px 600px at 50% -15%, rgba(54, 74, 138, 0.45), transparent 70%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
}

/* ---------- ambient background ---------- */

.aurora { position: fixed; inset: -10%; z-index: -2; pointer-events: none; filter: blur(100px); }
.aurora span {
  position: absolute;
  width: 45vmax;
  height: 45vmax;
  border-radius: 50%;
  opacity: 0.16;
  animation: drift 40s ease-in-out infinite alternate;
}
.aurora span:nth-child(1) { top: -10%; left: -5%; background: #2f4a9a; }
.aurora span:nth-child(2) { top: 40%; right: -15%; background: #8a6a35; opacity: 0.1; animation-duration: 52s; animation-delay: -20s; }
.aurora span:nth-child(3) { display: none; }
@keyframes drift { to { transform: translate(6vw, 5vh) scale(1.1); } }

#snow, .confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#snow { z-index: -1; }
.confetti { z-index: 50; }

/* ---------- layout ---------- */

.shell { width: min(560px, 100%); margin: 0 auto; padding: clamp(36px, 8vh, 84px) 16px 48px; }
.shell.wide { width: min(820px, 100%); }
main { display: grid; gap: 16px; view-transition-name: main; }

.hero { margin-bottom: 34px; text-align: center; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.32em;
  text-transform: uppercase;
}
.eyebrow::before, .eyebrow::after { content: ''; width: 28px; height: 1px; background: var(--stroke-gold); }
.title {
  margin: 16px 0 14px;
  background: linear-gradient(180deg, #f6efe0 30%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-family: var(--serif);
  font-size: clamp(3rem, 13vw, 4.8rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.01em;
  animation: rise 1.1s var(--ease-out) both;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  border: 1px solid var(--stroke-gold);
  border-radius: 999px;
  color: var(--gold-light);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

footer .heart { color: var(--gold); font-style: normal; }
footer {
  margin-top: 44px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 1.05rem;
  font-style: italic;
  text-align: center;
  opacity: 0.7;
}

/* ---------- surfaces & type ---------- */

.glass {
  padding: clamp(22px, 5vw, 34px);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 24px 60px -30px rgba(0, 0, 0, 0.7);
}

h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 500;
  line-height: 1.15;
}
h3 {
  margin: 26px 0 12px;
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}
p { margin: 0 0 8px; line-height: 1.6; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
a { color: var(--gold-light); text-decoration-color: var(--stroke-gold); text-underline-offset: 3px; }

.ornament { display: block; color: var(--gold); font-size: 1.1rem; letter-spacing: 0.6em; text-align: center; }
.ornament::before { content: '— ✦ —'; letter-spacing: 0.4em; }

/* ---------- motion ---------- */

.rise { animation: rise 0.9s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms); }
.d1 { --i: 1; }
.d2 { --i: 2; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); filter: blur(4px); } }

::view-transition-group(root) { animation: none; }
::view-transition-old(main) { animation: vt-out 0.25s ease-in both; }
::view-transition-new(main) { animation: vt-in 0.6s var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; filter: blur(3px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(10px); filter: blur(4px); } }

/* ---------- controls ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--gold);
  color: #141019;
  font: 500 0.9rem var(--sans);
  letter-spacing: 0.02em;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.3s, border-color 0.3s, color 0.3s, transform 0.3s var(--ease-soft), opacity 0.2s;
}
.btn:hover { background: var(--gold-light); }
.btn:active { transform: scale(0.98); }
.btn.ghost { border-color: var(--stroke-gold); background: transparent; color: var(--gold-light); }
.btn.ghost:hover { background: rgba(212, 176, 114, 0.08); }
.btn.danger { border-color: rgba(201, 147, 147, 0.4); background: transparent; color: var(--rose); }
.btn.danger:hover { background: rgba(201, 147, 147, 0.08); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  text-decoration: underline;
  text-decoration-color: var(--stroke-gold);
  text-underline-offset: 4px;
  cursor: pointer;
  transition: color 0.2s;
}
.link:hover { color: var(--gold-light); }

input, textarea, select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  font: 400 0.98rem var(--sans);
  transition: border-color 0.25s, box-shadow 0.25s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--stroke-gold); box-shadow: 0 0 0 3px rgba(212, 176, 114, 0.1); }
textarea { min-height: 130px; resize: vertical; line-height: 1.6; }
select option { background: #0f1730; }
::placeholder { color: rgba(236, 230, 218, 0.3); }

.field { display: grid; gap: 6px; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.02em; }
.row { display: flex; gap: 10px; }
.row > input { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 18px; }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--stroke-gold);
  border-radius: 50%;
  background: rgba(212, 176, 114, 0.06);
  color: var(--gold-light);
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ---------- family page ---------- */

.hello { display: flex; align-items: center; gap: 16px; }
.hello .avatar { width: 50px; height: 50px; font-size: 1.25rem; }
.hello h2 { margin: 0; }

.waiting { padding: 28px 8px 8px; text-align: center; }
.waiting .ornament { margin-bottom: 18px; animation: glow 4s ease-in-out infinite; }
.waiting .when { color: var(--gold-light); font-weight: 500; }

/* Countdown to the automatic draw */
.countdown { display: flex; justify-content: center; gap: 10px; margin: 22px 0 18px; }
.count-unit {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-width: 74px; padding: 14px 8px 12px;
  border: 1px solid rgba(212, 176, 114, 0.22); border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}
.count-value {
  font-family: var(--serif); font-size: 2.4rem; line-height: 1; color: var(--gold-light);
  font-variant-numeric: lining-nums tabular-nums;
}
.count-label { font-size: 0.66rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.waiting.due .count-unit { border-color: var(--gold); animation: due 2.4s ease-in-out infinite; }
@keyframes due { 0%, 100% { box-shadow: 0 0 12px rgba(212, 176, 114, 0.1); } 50% { box-shadow: 0 0 30px rgba(212, 176, 114, 0.32); } }

/* Admin: automatic draw */
.schedule { margin-top: 20px; padding-top: 18px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.schedule h3 { margin: 0 0 6px; }
.schedule .row { margin-top: 12px; }
input[type="datetime-local"] { color-scheme: dark; }
@keyframes glow { 50% { opacity: 0.45; } }

/* envelope */
.envelope-stage { display: grid; place-items: center; padding: 64px 0 6px; perspective: 900px; }
.envelope {
  position: relative;
  width: 240px;
  height: 158px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 24px 30px rgba(0, 0, 0, 0.55));
  animation: float 6s ease-in-out infinite;
  transform-style: preserve-3d;
}
.envelope:focus-visible { outline: 1px solid var(--gold); outline-offset: 16px; border-radius: 6px; }
.env-back, .env-front, .env-flap, .env-letter { position: absolute; display: block; }
.env-back { inset: 0; border-radius: 6px; background: linear-gradient(180deg, #1a2342, #141b35); }
.env-letter {
  z-index: 2;
  top: 8%;
  left: 7%;
  right: 7%;
  height: 84%;
  padding: 18px 16px;
  border-radius: 3px;
  background: linear-gradient(180deg, #f4ecdc, #e6dac2);
  transition: transform 0.8s 0.5s var(--ease-out);
}
.env-letter::before, .env-letter::after { content: ''; display: block; height: 1px; margin: 0 auto 10px; background: rgba(140, 108, 56, 0.35); }
.env-letter::before { width: 46%; }
.env-letter::after { width: 70%; }
.env-front {
  z-index: 3;
  inset: 0;
  border-radius: 6px;
  background: linear-gradient(170deg, #222c50, #19213f);
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
}
.env-front::after {
  /* gold hairline along the pocket edges */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top right, transparent calc(50% - 0.6px), rgba(212, 176, 114, 0.35) 50%, transparent calc(50% + 0.6px)) left / 50% 100% no-repeat,
    linear-gradient(to top left, transparent calc(50% - 0.6px), rgba(212, 176, 114, 0.35) 50%, transparent calc(50% + 0.6px)) right / 50% 100% no-repeat;
  opacity: 0.6;
}
.env-flap {
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  height: 58%;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #27325a, #1e2748);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  transition: transform 0.7s 0.15s var(--ease-soft), z-index 0s 0.5s;
}
.env-seal {
  position: absolute;
  z-index: 5;
  top: calc(58% - 21px);
  left: calc(50% - 21px);
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ecd39d, #b8904c 70%);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45), inset 0 0 0 3px rgba(120, 88, 40, 0.35);
  color: #5e4520;
  font-size: 1rem;
  transition: transform 0.35s var(--ease-soft), opacity 0.3s;
}
.envelope:hover .env-seal { transform: scale(1.06); }
.envelope.open { animation: none; pointer-events: none; }
.envelope.open .env-seal { transform: scale(0.6); opacity: 0; }
.envelope.open .env-flap { z-index: 1; transform: rotateX(180deg); }
.envelope.open .env-letter { transform: translateY(-48%); }
.envelope.open.leaving { opacity: 0; transform: translateY(-10px); filter: blur(6px); transition: opacity 0.5s, transform 0.5s, filter 0.5s; }
.hint { margin-top: 30px; color: var(--muted); font-size: 0.88rem; text-align: center; animation: glow 3.6s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }

/* name roulette */
.result { margin-top: 26px; text-align: center; }
.result-label { color: var(--muted); font-family: var(--serif); font-size: 1.15rem; font-style: italic; }
.slot {
  position: relative;
  height: 1.3em;
  margin: 4px 0 6px;
  overflow: hidden;
  font-family: var(--serif);
  font-size: clamp(2.7rem, 12vw, 3.9rem);
  font-weight: 500;
  -webkit-mask-image: linear-gradient(transparent, #000 25%, #000 75%, transparent);
  mask-image: linear-gradient(transparent, #000 25%, #000 75%, transparent);
}
.reel { will-change: transform; }
.slot span {
  display: block;
  height: 1.3em;
  overflow: hidden;
  line-height: 1.3em;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform-origin: center;
}
.slot span:last-child { transition: color 0.6s, text-shadow 0.6s; }
.slot.landed span { color: var(--gold-light); text-shadow: 0 0 30px rgba(212, 176, 114, 0.3); }
.receiver-details { text-align: left; }

.wishlist {
  padding: 16px 18px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* full draw list */
.pairs { display: grid; gap: 0; margin: 14px 0 0; padding: 0; list-style: none; }
.pair {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--stroke);
}
.pair:last-child { border-bottom: 0; }
.pair .avatar { width: 32px; height: 32px; font-size: 0.85rem; }
.pair .giver, .pair .receiver { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pair .receiver { text-align: right; }
.pair-arrow { color: var(--gold); font-family: var(--serif); font-size: 1.2rem; }
.pair.mine .giver, .pair.mine .receiver { color: var(--gold-light); }

/* ---------- admin ---------- */

.years { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.year {
  padding: 6px 16px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 500 0.85rem var(--sans);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.25s, border-color 0.25s, background 0.25s;
}
.year:hover { border-color: var(--stroke-gold); color: var(--text); }
.year[aria-pressed='true'] { border-color: var(--gold); background: rgba(212, 176, 114, 0.12); color: var(--gold-light); }
.year.add { border-style: dashed; }

.banner {
  padding: 12px 18px;
  border: 1px solid var(--stroke-gold);
  border-radius: 12px;
  color: var(--gold-light);
  font-family: var(--serif);
  font-size: 1.1rem;
  font-style: italic;
  text-align: center;
}
.warn { color: var(--gold-light); }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.count { color: var(--gold); font-family: var(--serif); font-size: 1.4rem; }

.people { display: grid; gap: 0; margin: 18px 0 0; padding: 0; list-style: none; }
.person {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px 14px;
  padding: 14px 2px;
  border-top: 1px solid var(--stroke);
}
.person .meta { min-width: 0; }
.person .name { overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.badge {
  padding: 1px 8px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
}
.badge.ok { border-color: var(--stroke-gold); color: var(--gold-light); }
.controls { display: flex; align-items: center; gap: 8px; }
.controls select { width: auto; max-width: 200px; padding: 8px 10px; font-size: 0.88rem; }
.arrow { display: inline-flex; align-items: center; gap: 8px; color: var(--gold-light); white-space: nowrap; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.05rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.icon-btn:hover { border-color: rgba(201, 147, 147, 0.5); color: var(--rose); }
.link-actions { display: flex; flex-wrap: wrap; gap: 6px 20px; grid-column: 1 / -1; padding-left: 52px; }
.link-actions .link { font-size: 0.8rem; }

.people.shuffling .person { animation: shuffle 0.5s ease-in-out infinite alternate; animation-delay: calc(var(--i) * -90ms); }
@keyframes shuffle { from { opacity: 1; } to { opacity: 0.35; transform: translateX(4px); } }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  z-index: 60;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 11px 18px;
  border: 1px solid var(--stroke-gold);
  border-radius: 10px;
  background: rgba(12, 18, 38, 0.92);
  backdrop-filter: blur(12px);
  font-size: 0.9rem;
  translate: -50% 0;
  animation: toast-in 0.5s var(--ease-out) both;
}
.toast.error { border-color: rgba(201, 147, 147, 0.55); color: #e8c4c4; }
.toast.out { animation: toast-out 0.3s ease-in both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive & accessibility ---------- */

@media (max-width: 560px) {
  .countdown { gap: 8px; }
  .count-unit { flex: 1; min-width: 0; padding: 12px 4px 10px; }
  .count-value { font-size: 1.9rem; }
  .count-label { font-size: 0.6rem; letter-spacing: 0.1em; }
  .grid2 { grid-template-columns: 1fr; }
  .person { grid-template-columns: auto 1fr; }
  .controls { grid-column: 1 / -1; justify-content: space-between; padding-left: 52px; }
  .controls select { flex: 1; max-width: none; }
}

/* Reduced motion (also set by Windows "Animation effects: off"): ambient, looping motion stops,
   but the short envelope reveal the visitor triggers themselves is kept. */
@media (prefers-reduced-motion: reduce) {
  .aurora { display: none; }
  .title, .rise, .envelope, .hint, .waiting .ornament, .people.shuffling .person { animation: none !important; }
  ::view-transition-old(main), ::view-transition-new(main) { animation: none; }
}
