/* Landing (the QR target): dedication, pack-code field, progress. iPhone-first: 100dvh, safe areas, no hover states. */
.page-landing {
  min-height: 100dvh;
  background:
    radial-gradient(90% 55% at 50% 0%, rgba(201, 162, 74, 0.16), transparent 70%),
    radial-gradient(70% 45% at 50% 100%, rgba(139, 30, 30, 0.16), transparent 75%),
    var(--obsidian);
  display: flex; flex-direction: column;
  overflow-x: clip;
}
.page-landing footer.site { position: relative; z-index: 1; padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 24px)); }

/* drifting embers: transform/opacity only */
.embers { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.embers i {
  position: absolute; left: var(--x); bottom: -12px; width: 3px; height: 3px; border-radius: 50%;
  background: radial-gradient(circle, #ffd88a 0%, rgba(255, 150, 60, 0.6) 45%, transparent 70%);
  scale: var(--s); opacity: 0;
  animation: ember var(--d) linear var(--t) infinite;
}
@keyframes ember {
  0% { transform: translate3d(0, 0, 0); opacity: 0; }
  12% { opacity: 0.9; }
  70% { opacity: 0.5; }
  100% { transform: translate3d(28px, -105vh, 0); opacity: 0; }
}

.landing {
  position: relative; z-index: 1; flex: 1;
  width: 100%; max-width: 480px; margin: 0 auto;
  padding: max(34px, calc(env(safe-area-inset-top) + 18px)) max(20px, env(safe-area-inset-right)) 28px max(20px, env(safe-area-inset-left));
  display: flex; flex-direction: column; align-items: stretch; gap: 22px;
}

/* returning visitor (she already holds cards): the code field comes before the letter */
.landing.is-returning .dedication { order: 5; }

/* crest */
.crest { text-align: center; }
.crest__sigil { width: 70px; height: 70px; margin: 0 auto 12px; color: var(--gold); filter: drop-shadow(0 0 14px rgba(201, 162, 74, 0.45)); animation: crest-glow 5s ease-in-out infinite; }
@keyframes crest-glow { 50% { filter: drop-shadow(0 0 24px rgba(243, 220, 148, 0.65)); } }
.crest__eyebrow { margin: 0; font-family: var(--display); font-size: 0.72rem; letter-spacing: 0.36em; text-transform: uppercase; color: var(--muted); }
.crest h1 { margin: 6px 0 0; font-size: clamp(2.1rem, 10.5vw, 3rem); letter-spacing: 0.05em; }
.crest__sub { margin: 8px auto 0; max-width: 34ch; text-wrap: balance; font-style: italic; color: var(--parchment-2); font-size: 1.02rem; line-height: 1.4; }

/* dedication: a letter, sealed in gold */
.dedication {
  position: relative; margin: 0; padding: 22px 22px 18px;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(201, 162, 74, 0.12), transparent 60%),
    linear-gradient(170deg, #1a1510, #100d0b);
  box-shadow: inset 0 0 0 1px rgba(201, 162, 74, 0.38), inset 0 0 0 5px rgba(11, 10, 13, 0.7), inset 0 0 0 6px rgba(201, 162, 74, 0.14), 0 18px 40px rgba(0, 0, 0, 0.45);
  color: var(--parchment);
}
.dedication::before { /* top ornament */
  content: '✦'; position: absolute; top: -11px; left: 50%; translate: -50% 0;
  width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%;
  background: var(--obsidian); color: var(--gold); font-size: 12px; box-shadow: 0 0 0 1px rgba(201, 162, 74, 0.5);
}
.dedication p { margin: 0; }
.dedication__to { font-family: var(--display); font-size: 0.82rem; letter-spacing: 0.26em; text-transform: uppercase; color: var(--gold-hi); text-align: center; margin-bottom: 10px !important; }
.dedication__msg { font-style: italic; font-size: 1.08rem; line-height: 1.5; text-wrap: pretty; }
.dedication__signoff { margin-top: 12px !important; text-align: right; font-family: var(--display); font-size: 0.8rem; letter-spacing: 0.12em; color: var(--gold); }

/* the code field: four gilded cells over one real input */
.redeem { display: flex; flex-direction: column; align-items: stretch; gap: 12px; margin: 4px 0 0; }
.redeem__label { text-align: center; font-family: var(--display); font-size: 0.86rem; letter-spacing: 0.24em; text-transform: uppercase; color: var(--gold-hi); }
.redeem__field { position: relative; align-self: center; width: min(100%, 300px); height: 74px; }
.redeem__field input {
  position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; border-radius: 12px; outline: none;
  background: transparent; color: transparent; caret-color: transparent;
  font-size: 16px; /* ≥16px: iOS never zooms */ letter-spacing: 3em; text-indent: -999px;
  -webkit-appearance: none; appearance: none;
}
.redeem__field input::selection { background: transparent; }
.redeem__cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; pointer-events: none; }
.redeem__cells span { /* four wax tablets set in gilt bezels; each letter is stamped into the wax */
  display: grid; place-items: center; border-radius: 12px;
  font-family: var(--display); font-weight: 700; font-size: 2rem; color: #f6dc98;
  background: radial-gradient(90% 80% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.45) 100%),
    url("../materials/wax.webp?v=5d9bef09c3") 0 0 / 128px, radial-gradient(circle at 40% 30%, #6a1a1e, #440b10 55%, #260508);
  background-blend-mode: normal, hard-light, normal;
  box-shadow: inset 0 0 0 1px rgba(232, 196, 112, 0.7), inset 0 0 0 3px rgba(20, 6, 6, 0.75), inset 0 3px 8px rgba(0, 0, 0, 0.6),
    inset 0 -1px 0 3px rgba(255, 170, 150, 0.08), 0 1px 0 rgba(255, 230, 170, 0.12), 0 6px 16px rgba(0, 0, 0, 0.4);
  text-shadow: 0 -1px 0 rgba(30, 2, 4, 0.9), 0 1px 0 rgba(255, 200, 170, 0.25);
  transition: box-shadow 0.25s, transform 0.25s;
}
.redeem__cells span.is-filled { color: #ffe7a8; text-shadow: 0 -1px 0 rgba(30, 2, 4, 0.9), 0 1px 0 rgba(255, 200, 170, 0.25), 0 0 12px rgba(243, 220, 148, 0.4); }
.redeem__field:focus-within .redeem__cells span.is-cursor {
  box-shadow: inset 0 0 0 1.5px var(--gold-hi), inset 0 0 0 3px rgba(20, 6, 6, 0.75), inset 0 3px 8px rgba(0, 0, 0, 0.6), 0 0 18px rgba(243, 220, 148, 0.4);
}
/* keyboard focus on the code field: a gold ring around the four tablets */
.redeem__field:focus-within { outline: 2px solid var(--gold-hi); outline-offset: 6px; border-radius: 16px; }
.redeem__field:focus-within .redeem__cells span.is-cursor::after {
  content: ''; width: 2px; height: 28px; background: var(--gold-hi); border-radius: 1px; animation: caret 1.05s steps(1) infinite;
}
.redeem__cells span.is-filled.is-cursor::after { display: none; }
@keyframes caret { 50% { opacity: 0; } }
.redeem.is-error .redeem__field { animation: shake 0.42s cubic-bezier(.36, .07, .19, .97); }
.redeem.is-error .redeem__cells span { box-shadow: inset 0 0 0 1.5px #c8574f, inset 0 -10px 18px rgba(0, 0, 0, 0.45); }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

.redeem__go {
  position: relative; overflow: hidden; align-self: center; width: min(100%, 300px); min-height: 54px;
  border: 0; border-radius: 999px; cursor: pointer;
  font-family: var(--display); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.2em; text-transform: uppercase; color: #1b1308;
  /* an engraved gold-leaf plate (materials.css) */
  background: url("../materials/gold.webp?v=1a1d0dbee7") 0 0 / 128px, linear-gradient(180deg, #f6e2a2, #dcb55c 48%, #b48a34 78%, #9a7428);
  background-blend-mode: hard-light, normal;
  text-shadow: 0 1px 0 rgba(255, 240, 200, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 250, 228, 0.85), inset 0 -2px 0 rgba(96, 62, 12, 0.6), inset 0 0 0 1px rgba(110, 74, 18, 0.75),
    0 1px 0 rgba(0, 0, 0, 0.6), 0 10px 26px rgba(201, 162, 74, 0.26);
  transition: transform 0.15s, filter 0.2s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.redeem__go::before { /* the engraved groove inside the rim, with its lit lower lip */
  content: ''; position: absolute; inset: 5px; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 1px 0 var(--engrave-dark), inset 0 0 0 1px rgba(96, 62, 12, 0.35), 0 1px 0 var(--engrave-lit);
}
.redeem__go > span { position: relative; }
.redeem__go:active { transform: translateY(1px) scale(0.985); filter: brightness(0.93);
  box-shadow: inset 0 2px 7px rgba(70, 40, 4, 0.6), inset 0 0 0 1px rgba(110, 74, 18, 0.8), 0 4px 12px rgba(201, 162, 74, 0.16); }
.redeem__go:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 4px; border-radius: 999px; }
.redeem__go::after { /* foil glint */
  content: ''; position: absolute; inset: 0; translate: -120% 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.55) 50%, transparent 70%);
  animation: glint 4.5s ease-in-out 1.2s infinite;
}
@keyframes glint { 0%, 70% { translate: -120% 0; } 100% { translate: 120% 0; } }
.redeem__go[aria-busy='true'] { filter: saturate(0.6) brightness(0.9); }
.redeem__go[aria-busy='true']::after { animation-duration: 0.9s; animation-delay: 0s; }
.redeem__hint { margin: 0; text-align: center; color: var(--muted); font-size: 0.92rem; font-style: italic; }
.redeem__error:empty { display: none; }
.redeem__error { /* a wax-red notice slip */
  margin: 0; padding: 10px 14px; border-radius: 12px; text-align: center; font-size: 1rem; line-height: 1.4; color: #fbe3dc;
  background: url("../materials/wax.webp?v=5d9bef09c3") 0 0 / 128px, linear-gradient(180deg, #5a1418, #3c0a0e);
  background-blend-mode: hard-light, normal;
  box-shadow: inset 0 0 0 1px rgba(232, 150, 130, 0.45), inset 0 0 0 3px rgba(20, 4, 6, 0.6), 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* progress */
.progress { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 4px; }
.progress p { margin: 0; color: var(--parchment-2); font-size: 1.02rem; }
.progress b { font-family: var(--display); font-weight: 600; color: var(--gold-hi); letter-spacing: 0.08em; }
.progress__ring { width: 40px; height: 40px; rotate: -90deg; flex: none; }
.progress__ring circle { fill: none; stroke: rgba(201, 162, 74, 0.2); stroke-width: 3; }
.progress[data-empty] .progress__arc { opacity: 0; }
.progress__ring .progress__arc { stroke: var(--gold-hi); stroke-linecap: round; stroke-dasharray: var(--p, 0) 100; transition: stroke-dasharray 0.9s cubic-bezier(.2, .8, .2, 1); filter: drop-shadow(0 0 3px rgba(243, 220, 148, 0.6)); }

.to-codex { /* a blackened-steel plate with a gold rim */
  align-self: center; display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 26px;
  border-radius: 999px; text-decoration: none;
  font-family: var(--display); font-size: 0.82rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold-hi);
  background: url("../materials/steel.webp?v=2193069f85") 0 0 / 128px, linear-gradient(175deg, #34323a, #1b1a20 42%, #26242b 70%, #111014);
  background-blend-mode: hard-light, normal;
  box-shadow: inset 0 0 0 1px rgba(214, 178, 96, 0.6), inset 0 0 0 4px rgba(8, 7, 10, 0.7), inset 0 0 0 5px rgba(214, 178, 96, 0.18),
    inset 0 8px 12px -8px rgba(255, 255, 255, 0.12), 0 2px 0 rgba(0, 0, 0, 0.55), 0 8px 18px rgba(0, 0, 0, 0.35);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.8);
}
.to-codex:active { transform: translateY(1px); box-shadow: inset 0 0 0 1px rgba(214, 178, 96, 0.7), inset 0 3px 8px rgba(0, 0, 0, 0.75); }
.to-codex:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 4px; border-radius: 999px; }

/* Add to Home Screen hint (iOS Safari, not installed) */
.a2hs {
  display: flex; align-items: center; gap: 10px; margin-top: 4px; padding: 12px 12px 12px 16px; border-radius: 14px;
  background: rgba(29, 26, 34, 0.85); box-shadow: inset 0 0 0 1px var(--line); color: var(--parchment-2); font-size: 0.95rem; line-height: 1.4;
}
.a2hs[hidden] { display: none; }
.a2hs p { margin: 0; flex: 1; }
.a2hs b { color: var(--gold-hi); font-weight: 600; }
.a2hs__icon svg { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; color: #7fb0ff; }
.a2hs__close { flex: none; width: 44px; height: 44px; margin: -4px -4px -4px 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 1.4rem; line-height: 1; cursor: pointer; }
.a2hs__close:active { background: rgba(201, 162, 74, 0.12); }

html.pack-open, html.pack-open body { overflow: hidden; overscroll-behavior: none; }

@media (prefers-reduced-motion: reduce) {
  .embers { display: none; }
  .crest__sigil, .redeem__go::after { animation: none; }
  .redeem.is-error .redeem__field { animation: none; }
}
