/* Freentity invitation — design tokens, base layer, and the gate backdrop.
   The envelope object itself lives in envelope.css. */

:root {
  --green-950: #04120c;
  --green-900: #06170f;
  --green-850: #082017;
  --green-800: #0c2a20;
  --green-700: #12332a;
  --green-600: #173c2f;
  --green-500: #1c4737;
  --green-400: #2a5b4a;
  --green-300: #3d7562;
  --stone-50: #f8faf9;
  --stone-100: #f2f4f3;
  --stone-200: #e4e8e5;
  --stone-300: #d6dcd9;
  --stone-400: #b6bfba;
  --stone-500: #8e9b95;
  --stone-700: #55625d;
  --paper: #fff;

  --ease-expo: cubic-bezier(.16, 1, .3, 1);
  --ease-settle: cubic-bezier(.2, .72, .22, 1);
  --ease-swing: cubic-bezier(.38, .02, .18, 1);
  --ease-turn: cubic-bezier(.52, .02, .16, 1);

  /* Desaturated in the filter chain so the veil needs no mix-blend-mode, which would
     force the whole gate to re-composite on every frame of the opening sequence. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23g)'/%3E%3C/svg%3E");

  --shell-width: min(86vw, 560px, calc((100vh - 48px) * .92));
  --shell-width: min(86vw, 560px, calc((100svh - 48px) * .92));

  color-scheme: light;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--stone-200);
  color: var(--green-600);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--stone-200);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgb(255 255 255 / 82%), transparent 40rem),
    var(--stone-200);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

img {
  max-width: 100%;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

html[data-state="sealed"],
html[data-state="opening"],
html[data-state="sealed"] body,
html[data-state="opening"] body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ---------------------------------------------------------------- gate stage */

.gate {
  display: none;
}

html[data-state="sealed"] .gate,
html[data-state="opening"] .gate {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  padding:
    max(16px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden;
  background:
    radial-gradient(110% 72% at 50% 40%, rgb(21 56 43 / 88%) 0%, rgb(8 26 20 / 82%) 44%, transparent 74%),
    radial-gradient(90% 60% at 50% 114%, rgb(14 44 34 / 50%), transparent 66%),
    linear-gradient(168deg, #0a1712 0%, #060e0b 52%, #030706 100%);
  place-items: center;
}

.gate__grid {
  position: absolute;
  display: none;
  inset: -10%;
  background:
    repeating-linear-gradient(0deg, rgb(215 235 226 / 4%) 0 1px, transparent 1px 46px),
    repeating-linear-gradient(90deg, rgb(215 235 226 / 4%) 0 1px, transparent 1px 46px);
  mask-image: radial-gradient(58% 46% at 50% 42%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(58% 46% at 50% 42%, #000 0%, transparent 78%);
  opacity: .5;
  pointer-events: none;
}

.gate__glow {
  position: absolute;
  inset: 40% auto auto 50%;
  width: min(92vw, 620px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(142 204 178 / 20%) 0%, rgb(70 142 113 / 12%) 32%, rgb(38 92 73 / 5%) 56%, transparent 74%);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.gate__grain {
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  background-size: 180px 180px;
  opacity: .14;
  pointer-events: none;
}

.gate__bloom {
  position: absolute;
  inset: 0;
  background: radial-gradient(72% 58% at 50% 46%, var(--paper) 0%, rgb(244 247 245 / 88%) 46%, rgb(228 232 229 / 72%) 100%);
  opacity: 0;
  pointer-events: none;
}

.gate__stage {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  place-items: center;
}

/* The arrival plays on the light pool, never on the stage itself. A transform here
   would nest inside .gate__open's opening transform, which WebKit mis-composites
   when a visitor opens the envelope mid-animation; fading the stage instead starts
   the envelope at opacity 0, which leaves Chrome with no LCP candidate at all. */
.gate__glow {
  animation: gate-arrive 900ms ease-out both;
}

.gate__open {
  position: relative;
  display: flex;
  width: min(100%, 640px);
  padding: 0;
  border: 0;
  appearance: none;
  flex-direction: column;
  align-items: center;
  color: var(--stone-50);
  background: transparent;
  cursor: pointer;
  perspective: 1500px;
  perspective-origin: 50% 36%;
  transform: translateY(0);
  transition: transform 720ms var(--ease-settle);
  will-change: transform;
}

.gate__open:focus-visible {
  outline: none;
}

.gate__open:focus-visible .gate__prompt strong {
  outline: 2px solid rgb(216 232 224 / 78%);
  outline-offset: 8px;
  border-radius: 2px;
}

.gate__open:disabled {
  cursor: default;
}

/* ------------------------------------------------------------------- prompt */

.gate__prompt {
  display: grid;
  margin-top: clamp(26px, 5vh, 46px);
  place-items: center;
  transition: opacity 360ms ease, transform 520ms ease;
}

.gate__prompt strong {
  position: relative;
  display: inline-block;
  padding: 0 0 10px;
  border: 0;
  color: #e9f0ec;
  background: transparent;
  font-family: Baskerville, "Palatino Linotype", Georgia, serif;
  font-size: clamp(1.15rem, 4.6vw, 1.45rem);
  font-style: italic;
  font-weight: 400;
  letter-spacing: .34em;
  line-height: 1.2;
  text-indent: .34em;
  text-shadow: 0 6px 18px rgb(2 14 9 / 60%);
  animation: open-float 3.4s ease-in-out infinite;
}

.gate__prompt strong::before {
  position: absolute;
  right: 22%;
  bottom: 0;
  left: 22%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgb(224 236 231 / 62%), transparent);
  content: "";
  transform: scaleX(1);
  transition: transform 420ms var(--ease-expo);
}

.gate__prompt strong::after {
  position: absolute;
  z-index: -1;
  right: 12%;
  bottom: -12px;
  left: 12%;
  height: 7px;
  border-radius: 50%;
  background: rgb(126 190 165 / 22%);
  filter: blur(6px);
  content: "";
  animation: open-shadow 3.4s ease-in-out infinite;
}

.gate__hint {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  margin-top: 16px;
  color: rgb(216 230 224 / 66%);
  font-size: clamp(.72rem, 3vw, .8rem);
  letter-spacing: .18em;
  line-height: 1.4;
  text-align: center;
  transition: opacity 320ms ease;
}

.gate__open:hover .gate__prompt strong {
  color: var(--paper);
}

.gate__open:hover .gate__prompt strong::before {
  transform: scaleX(1.42);
}


/* -------------------------------------------------------------- opening flow */

html[data-state="opening"] .gate__prompt,
html[data-state="opening"] .gate__hint {
  opacity: 0;
  transform: translateY(9px);
}

html[data-opening-phase="card"] .gate__bloom {
  opacity: .1;
  transition: opacity 900ms ease;
}

html[data-opening-phase="departing"] .gate__bloom {
  animation: gate-bloom 560ms ease forwards;
}

html[data-opening-phase="departing"] .gate {
  animation: gate-departure 560ms ease forwards;
}

/* --------------------------------------------------------------- keyframes */

@keyframes gate-arrive {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes open-float {
  0%, 100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-7px);
  }
}

@keyframes open-shadow {
  0%, 100% {
    opacity: .7;
    transform: scaleX(1);
  }

  50% {
    opacity: .4;
    transform: scaleX(.78);
  }
}

@keyframes gate-bloom {
  from {
    opacity: .1;
  }

  to {
    opacity: 1;
  }
}

@keyframes gate-departure {
  to {
    opacity: 0;
    transform: scale(1.02);
  }
}

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

/* Opening needs headroom for the raised flap. A tall phone already has it, because
   the envelope is width-bound and sits high; a wide or short viewport does not, so
   the whole composition slides down by an amount derived from the envelope itself
   instead of a per-breakpoint guess. */
@media (min-width: 900px), (max-height: 620px) {
  html[data-state="opening"] .gate__open {
    transform: translateY(calc(var(--shell-width) * .13 + 28px));
  }
}

@media (min-width: 900px) {
  :root {
    --shell-width: min(70vw, 720px, calc((100vh - 48px) * .92));
    --shell-width: min(70vw, 720px, calc((100svh - 48px) * .92));
  }

  .gate__grid {
    display: block;
  }

  .gate__glow {
    width: min(80vw, 900px);
  }

  .gate__open {
    width: min(100%, 820px);
  }
}

@media (max-height: 560px) {
  .gate__prompt {
    margin-top: 14px;
  }

  .gate__prompt strong {
    font-size: 1.05rem;
  }

  .gate__hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .gate__glow {
    animation: none;
  }

  .gate__open {
    transition-duration: 260ms;
  }

  .gate__prompt {
    transition-duration: 160ms, 200ms;
  }

  .gate__prompt strong,
  .gate__prompt strong::after {
    animation: none !important;
  }

  html[data-opening-phase="departing"] .gate,
  html[data-opening-phase="departing"] .gate__bloom {
    animation-duration: 220ms;
  }
}

@media print {
  .gate {
    display: none !important;
  }
}
