:root {
  --night: #160B0D;
  --wine: #3A1A1E;
  --card: #100C0D;
  --gold: #D9B46E;
  --gold-line: rgba(217, 180, 110, 0.55);
  --cream: #F3E6D8;
  --satin: #9A1023;
  --hand: "Caveat", "Segoe Print", cursive;
  --ui: "Manrope", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  background: radial-gradient(120% 80% at 50% 35%, var(--wine) 0%, var(--night) 68%) fixed, var(--night);
  color: var(--cream);
  font-family: var(--ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { cursor: pointer; }
button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

/* Стартовый экран: бирка от букета на фоне упаковочной бумаги */
.intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow: hidden;
}

/* Тёплые огоньки гирлянды не в фокусе, как на вечернем фото */
.intro::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  filter: blur(2px);
  background:
    radial-gradient(circle at 8% 9%, rgba(255, 196, 120, 0.55) 0 7px, transparent 15px),
    radial-gradient(circle at 17% 4%, rgba(255, 196, 120, 0.4) 0 9px, transparent 18px),
    radial-gradient(circle at 4% 22%, rgba(255, 196, 120, 0.35) 0 6px, transparent 13px),
    radial-gradient(circle at 26% 14%, rgba(255, 196, 120, 0.3) 0 11px, transparent 22px),
    radial-gradient(circle at 12% 33%, rgba(255, 196, 120, 0.25) 0 8px, transparent 17px),
    radial-gradient(circle at 34% 6%, rgba(255, 196, 120, 0.22) 0 6px, transparent 13px),
    radial-gradient(circle at 88% 12%, rgba(255, 196, 120, 0.18) 0 10px, transparent 21px),
    radial-gradient(circle at 94% 30%, rgba(255, 196, 120, 0.14) 0 7px, transparent 15px),
    radial-gradient(circle at 80% 86%, rgba(255, 196, 120, 0.12) 0 12px, transparent 24px);
}

.tag-wrap {
  position: relative;
  z-index: 1;
  width: min(340px, 100%);
  margin-top: 8vh;
  filter: drop-shadow(0 26px 40px rgba(0, 0, 0, 0.55));
  transform-origin: 50% -30vh;
  transform: rotate(-3deg);
  animation: swing 2.6s cubic-bezier(0.3, 0.7, 0.3, 1) both;
}

/* Ленточка, на которой висит бирка */
.tag-wrap::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% - 27px);
  width: 4px;
  height: 60vh;
  margin-left: -2px;
  background: linear-gradient(90deg, #6E0A18, var(--satin) 45%, #C23048 55%, #6E0A18);
  border-radius: 2px;
}

.tag {
  position: relative;
  padding: 66px 28px 28px;
  text-align: center;
  background: var(--card);
  clip-path: polygon(17% 0, 83% 0, 100% 9%, 100% 100%, 0 100%, 0 9%);
}

.tag-hole {
  position: absolute;
  top: 18px;
  left: 50%;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border-radius: 50%;
  background: var(--night);
  box-shadow: inset 0 0 0 2px var(--gold-line);
}

/* Тонкая золотая рамка внутри карточки */
.tag::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid var(--gold-line);
  clip-path: polygon(16% 0, 84% 0, 100% 8%, 100% 100%, 0 100%, 0 8%);
  pointer-events: none;
}

.tag-hello {
  margin: 0 0 8px;
  font: 700 clamp(40px, 12vw, 52px)/1 var(--hand);
  color: var(--gold);
}

.tag-text {
  margin: 0 0 26px;
  font: 500 31px/1.1 var(--hand);
  color: var(--cream);
}

.btn {
  width: 100%;
  padding: 18px 28px;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: var(--card);
  font: 700 16px/1 var(--ui);
  transition: transform 0.15s;
}
.btn:active { transform: scale(0.98); }
a.btn {
  display: block;
  text-align: center;
  text-decoration: none;
}

.text-link {
  margin-top: 10px;
  padding: 6px;
  border: 0;
  background: none;
  color: var(--cream);
  font: 500 13px/1.3 var(--ui);
  opacity: 0.75;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-link:disabled { opacity: 0.35; cursor: default; }
.btn:disabled { opacity: 0.5; cursor: default; }

.tag-note {
  margin: 14px 0 0;
  font: 500 13px/1.45 var(--ui);
  color: var(--cream);
  opacity: 0.6;
}

@keyframes swing {
  0%   { transform: rotate(-9deg); opacity: 0; }
  12%  { opacity: 1; }
  40%  { transform: rotate(4deg); }
  68%  { transform: rotate(-4.5deg); }
  100% { transform: rotate(-3deg); }
}

/* 3D-сцена (когда AR недоступен) */
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  touch-action: none;
}
#scene.is-on { display: block; }

/* Интерфейс поверх камеры */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.overlay > * { pointer-events: auto; }

.actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.actions > * { pointer-events: auto; }

.chip {
  padding: 12px 16px;
  border: 0;
  border-radius: 999px;
  background: rgba(16, 12, 13, 0.62);
  color: var(--cream);
  font: 700 14px/1 var(--ui);
  backdrop-filter: blur(8px);
}

.hint {
  align-self: center;
  max-width: 320px;
  margin: 14px 0 0;
  padding: 12px 18px;
  border-radius: 18px;
  background: rgba(16, 12, 13, 0.78);
  color: var(--cream);
  box-shadow: inset 0 0 0 1px var(--gold-line);
  font: 500 15px/1.35 var(--ui);
  text-align: center;
  pointer-events: none;
}

.card {
  align-self: center;
  width: min(420px, 100%);
  max-height: 46vh;
  margin-top: auto;
  padding: 22px 24px 14px;
  overflow: auto;
  border-radius: 4px;
  background: var(--card);
  color: var(--cream);
  box-shadow: inset 0 0 0 1px var(--gold-line), inset 0 0 0 7px var(--card), inset 0 0 0 8px rgba(217, 180, 110, 0.25), 0 18px 40px rgba(0, 0, 0, 0.5);
  transform: rotate(-1.2deg);
  animation: rise 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.card-msg {
  margin: 0;
  font: 500 31px/1.1 var(--hand);
  white-space: pre-line;
}

.card-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.card-sign {
  margin: 0;
  font: 700 30px/1 var(--hand);
  color: var(--gold);
}

.card-hide {
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--cream);
  font: 500 13px/1 var(--ui);
  opacity: 0.6;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.place {
  align-self: center;
  margin-top: auto;
  margin-bottom: 12px;
  padding: 18px 30px;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: var(--card);
  font: 700 17px/1 var(--ui);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.envelope {
  align-self: center;
  margin-top: auto;
  padding: 14px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: var(--card);
  font: 700 15px/1 var(--ui);
}

.chip-gold {
  background: var(--gold);
  color: var(--card);
}
a.chip {
  display: inline-block;
  text-decoration: none;
}

/* Готовое фото поверх камеры */
.photo {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(10, 5, 7, 0.88);
}
.photo img {
  max-width: 100%;
  max-height: 74vh;
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--gold-line), 0 18px 40px rgba(0, 0, 0, 0.5);
}
.photo-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* Вспышка при снимке */
.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  pointer-events: none;
  animation: flash 0.35s ease-out forwards;
}
@keyframes flash {
  from { opacity: 0.85; }
  to   { opacity: 0; }
}

@keyframes rise {
  from { transform: translateY(40px) rotate(-1.2deg); opacity: 0; }
  to   { transform: translateY(0) rotate(-1.2deg); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .tag-wrap, .card { animation: none; }
}
