:root {
  --pine: #10291f;
  --pine-2: #173a2c;
  --pine-3: #1f4a38;
  --paper: #fbf5ea;
  --paper-2: #f4ead9;
  --line: #e7dbc7;
  --ink: #2b211c;
  --ink-2: #5a4b40;
  --muted: #8a7b6d;
  --berry: #b3262e;
  --berry-dark: #8f1c23;
  --gold: #d4a650;
  --gold-soft: #f0cf86;
  --green: #2f7a52;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(120% 60% at 50% -10%, #2a5a43 0%, transparent 60%),
    radial-gradient(80% 50% at 50% 110%, #0a1c14 0%, transparent 70%),
    var(--pine);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

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

/* String lights */
.lights {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  z-index: 1;
}
.bulbs {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  z-index: 1;
  pointer-events: none;
}
.bulb {
  position: absolute;
  width: 10px;
  height: 15px;
  margin-left: -5px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--c);
  box-shadow: 0 0 10px 2px color-mix(in srgb, var(--c) 70%, transparent);
  transform: rotate(var(--r, 0deg));
  transform-origin: 50% 0;
  animation: twinkle 2.8s ease-in-out infinite;
  animation-delay: var(--d);
}
.bulb::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 2px;
  width: 6px;
  height: 5px;
  border-radius: 2px;
  background: #0b1d15;
}
@keyframes twinkle {
  0%, 100% { opacity: 1; filter: brightness(1.1); }
  50% { opacity: 0.45; filter: brightness(0.8); box-shadow: none; }
}

/* Layout */
.shell {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 44px) 18px calc(env(safe-area-inset-bottom) + 40px);
}

.top {
  position: relative;
  text-align: center;
  color: var(--paper);
  padding: 18px 0 22px;
}

.lang {
  position: absolute;
  top: -22px;
  right: 0;
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
}
.lang button {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(251, 245, 234, 0.65);
  font: 600 12px/1 var(--body);
  letter-spacing: 0.06em;
  padding: 7px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.lang button[aria-pressed="true"] {
  background: var(--paper);
  color: var(--pine);
}

.star {
  width: 34px;
  height: 34px;
  fill: var(--gold);
  filter: drop-shadow(0 0 14px rgba(240, 207, 134, 0.65));
  animation: glow 3.6s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.08) rotate(6deg); }
}

.kicker {
  margin: 10px 0 6px;
  font: 600 12px/1.2 var(--body);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-soft);
}
.kicker.dark { color: var(--berry); margin-top: 0; }

h1 {
  margin: 0;
  font: 600 clamp(32px, 9vw, 40px) / 1.05 var(--display);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.budget {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 0;
  padding: 9px 16px 9px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f6dc9c, var(--gold));
  color: #3a2a12;
  font: 700 15px/1 var(--body);
  letter-spacing: 0.01em;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 8px 22px -10px rgba(240, 207, 134, 0.7);
}
.budget-icon { font-size: 16px; line-height: 1; }

h2 {
  margin: 0 0 8px;
  font: 600 24px/1.2 var(--display);
  color: var(--ink);
  text-wrap: balance;
}

/* Cards */
.stage { position: relative; }

.card {
  position: relative;
  /* candy cane stitch along the top, clipped by the card's own radius */
  background:
    repeating-linear-gradient(135deg, var(--berry) 0 12px, var(--paper) 12px 24px) top / 100% 7px no-repeat,
    var(--paper);
  border-radius: 24px;
  padding: 30px 22px 24px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 24px 60px -20px rgba(0, 0, 0, 0.55),
    0 2px 6px rgba(0, 0, 0, 0.18);
}
.view { animation: enter 0.55s var(--ease-out) both; }
@keyframes enter {
  from { opacity: 0; transform: translateY(16px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.lead {
  margin: 0 0 20px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-2);
}
.lead.small { font-size: 15px; margin-bottom: 18px; }
.lead strong { color: var(--ink); font-weight: 600; }

.label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font: 600 14px/1.2 var(--body);
  color: var(--ink);
}
.wishes-form .label:not(:first-child) { margin-top: 18px; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.dot-green { background: var(--green); }
.dot-red { background: var(--berry); }

input,
textarea {
  display: block;
  width: 100%;
  font: 400 17px/1.4 var(--body);
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}
input { height: 56px; }
textarea { resize: none; min-height: 96px; field-sizing: content; max-height: 260px; }
input::placeholder,
textarea::placeholder { color: #b5a796; }
input:focus,
textarea:focus {
  border-color: var(--berry);
  box-shadow: 0 0 0 4px rgba(179, 38, 46, 0.12);
}
[aria-invalid="true"] { border-color: var(--berry); }

.code-input {
  text-align: center;
  font: 600 28px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.4em;
  padding-left: calc(16px + 0.4em);
  height: 64px;
}

.error {
  min-height: 0;
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--berry);
  overflow: hidden;
  transition: margin 0.2s;
}
.error:not(:empty) { margin-top: 10px; animation: shake 0.4s var(--ease-out); }
@keyframes shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-5px); }
  60% { transform: translateX(4px); }
}

/* Buttons */
.btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 56px;
  margin-top: 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #c42f37, var(--berry));
  color: #fff;
  font: 600 17px/1 var(--body);
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 8px 20px -8px rgba(143, 28, 35, 0.8);
  transition: transform 0.15s var(--ease-out), filter 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); filter: brightness(0.95); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn[aria-busy="true"] { pointer-events: none; }
.btn[aria-busy="true"] > span { opacity: 0; }
.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-quiet {
  background: var(--pine-2);
  box-shadow: 0 8px 20px -10px rgba(16, 41, 31, 0.8);
}
.btn-quiet.saved { background: var(--green); }

.link {
  display: block;
  margin: 16px auto 0;
  padding: 8px 12px;
  border: 0;
  background: none;
  color: var(--berry);
  font: 600 15px/1 var(--body);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.link:disabled { color: var(--muted); cursor: default; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: -4px 0 14px -6px;
  padding: 6px;
  border: 0;
  background: none;
  color: var(--muted);
  font: 500 14px/1 var(--body);
  cursor: pointer;
}
.back::before { content: "←"; font-size: 16px; }

.status {
  margin: 18px 0 0;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}
.status:empty { display: none; }
.status .pips {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 10px;
}
.status .pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
}
.status .pip.on { background: var(--green); }

/* Match */
.match-name {
  margin: 4px 0 18px;
  font: 700 clamp(40px, 12vw, 52px) / 1 var(--display);
  color: var(--ink);
  letter-spacing: -0.02em;
}
.match-wishes { display: grid; gap: 10px; }
.wish {
  padding: 14px 16px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 16px;
}
.wish h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font: 600 12px/1.2 var(--body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.wish p {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.wish.empty {
  background: var(--paper-2);
  border-style: dashed;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.5;
}

.meta {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.meta:empty { display: none; }

.home { display: grid; gap: 16px; }
.logout { color: rgba(251, 245, 234, 0.7); }

/* Reveal */
.reveal {
  display: grid;
  justify-items: center;
  min-height: 60dvh;
  align-content: start;
  padding-top: 10px;
}
.gift {
  display: grid;
  justify-items: center;
  gap: 8px;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.gift svg {
  width: min(72vw, 260px);
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 24px 30px rgba(0, 0, 0, 0.45));
  animation: wiggle 2.4s ease-in-out infinite;
  transform-origin: 50% 90%;
}
.gift:focus-visible { outline: 3px solid var(--gold); outline-offset: 8px; border-radius: 20px; }
@keyframes wiggle {
  0%, 70%, 100% { transform: rotate(0); }
  76% { transform: rotate(-4deg) scale(1.02); }
  82% { transform: rotate(4deg) scale(1.02); }
  88% { transform: rotate(-2deg); }
  94% { transform: rotate(1deg); }
}
.gift-lid { transform-box: fill-box; transform-origin: 20% 100%; transition: transform 0.7s var(--spring), opacity 0.5s 0.25s; }
.gift-box { transform-box: fill-box; transform-origin: 50% 100%; transition: transform 0.6s var(--ease-out), opacity 0.4s 0.35s; }
.gift-hint {
  color: var(--gold-soft);
  font: 600 15px/1 var(--body);
  letter-spacing: 0.02em;
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.5; } }

.reveal.opening .gift svg { animation: none; }
.reveal.opening .gift-lid { transform: translate(-30px, -90px) rotate(-28deg); opacity: 0; }
.reveal.opening .gift-box { transform: scale(0.9) translateY(10px); opacity: 0; }
.reveal.opening .gift-hint { opacity: 0; animation: none; }
.reveal.opened .gift { display: none; }

.sparks { position: absolute; left: 50%; top: 140px; width: 0; height: 0; }
.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--c);
  animation: fly 1.1s var(--ease-out) forwards;
}
@keyframes fly {
  0% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) rotate(var(--rot)) scale(0.4); opacity: 0; }
}

.reveal-card {
  width: 100%;
  text-align: left;
  animation: rise 0.8s var(--spring) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(40px) scale(0.92); }
  to { opacity: 1; transform: none; }
}
.secret {
  margin: 18px 0 0;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  z-index: 10;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: 600 15px/1 var(--body);
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s var(--spring), opacity 0.25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (min-width: 600px) {
  .shell { padding-top: 72px; }
  .card { padding: 32px 30px 28px; }
}

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