@font-face {
  font-family: 'Madelyn';
  src: url('/fonts/madelyn_regular.otf') format('opentype');
  font-weight: 400;
  font-display: swap;
}

:root {
  --ink: #2B2620;
  --heading: #3A352E;
  --body-muted: #6B675D;
  --label: #6B675D;
  --faint: #B5B0A4;
  --page-bg: #F3EEE6;
  --paper: #FFFDF9;
  --rule: #D8D2C4;
  --error-text: #9A5A48;
  --error-border: #B3705C;
  --hover-fill: #625B5B;
  --field-border: rgba(43, 38, 32, 0.28);
  --ease: cubic-bezier(.22,.8,.3,1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: 'EB Garamond', Georgia, serif;
  min-height: 100%;
}

a { color: #6B5B3E; text-decoration: none; }
a:hover { color: #2B2620; }

input, select {
  font-family: 'EB Garamond', Georgia, serif;
  background: transparent;
}
input:focus { outline: none; }
input:focus-visible { outline: none; box-shadow: 0 0 12px 3px rgba(255,255,255,0.75); }
[role="button"]:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid #6B5B3E; outline-offset: 3px; }
::placeholder { color: #B5AFA1; font-style: italic; }

@keyframes stdFadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes stdWiggle { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-0.3deg); } 75% { transform: rotate(0.3deg); } }
@keyframes stdSpin { to { transform: rotate(360deg); } }

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

#bg {
  position: fixed; inset: 0;
  background: var(--page-bg) url('/warm-palm-bg.webp') center top / cover no-repeat;
  z-index: 0;
}
#bg-wash {
  position: fixed; inset: 0;
  background: rgba(255,253,249,0.32);
  z-index: 0;
  pointer-events: none;
}

#lang-toggle {
  position: fixed; top: 14px; right: 16px; z-index: 40;
  display: flex; align-items: center; gap: 2px;
  font-family: 'Anonymous Pro', monospace;
  font-size: 12px; letter-spacing: 0.14em;
}
.lang-sep { color: var(--faint); }
.lang-btn {
  background: none; border: none; cursor: pointer; padding: 8px 6px;
  font: inherit; letter-spacing: inherit;
  color: var(--body-muted);
  text-decoration: none;
  text-underline-offset: 4px;
}
.lang-btn[aria-pressed="true"] {
  color: #2B2620;
  text-decoration: underline;
}

#app { position: relative; z-index: 1; min-height: 100vh; box-sizing: border-box; }

/* Buttons */
.btn {
  display: inline-block;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  text-transform: uppercase;
  border-radius: 0;
  background: transparent;
  border: 1px solid var(--field-border);
  padding: 14px 24px;
  font-family: 'Anonymous Pro', monospace;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: #2B2620;
  text-decoration: none;
  transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease, opacity 200ms ease;
}
.btn:hover:not(:disabled) { background: var(--hover-fill); border-color: var(--hover-fill); color: #FFFFFF; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-full { width: 100%; box-sizing: border-box; }
.btn-cta { padding: 12px 20px; }

/* ---------- Login screen ---------- */
.screen-login {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 10vh 6vw 8vh; box-sizing: border-box;
  animation: stdFadeUp 600ms ease both;
}
.login-eyebrow { margin: 0 0 6px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: 12px; letter-spacing: 0.32em; color: var(--body-muted); text-align: center; }
.login-title { margin: 0 0 18px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: clamp(34px, 6.4vw, 56px); font-weight: 400; font-style: normal; letter-spacing: 0.01em; line-height: 1.15; text-align: center; color: #595354; }
.login-sub { margin: 0 0 32px; font-size: 16px; color: var(--body-muted); text-align: center; max-width: 360px; line-height: 1.5; }
.login-form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 22px; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: 11px; letter-spacing: 0.2em; color: var(--label); }
.field-input {
  width: 100%; box-sizing: border-box; padding: 13px 14px;
  font-size: 15px; color: #2B2620; background: transparent;
  border: 1px solid var(--field-border); border-radius: 0;
}
.field-input.is-invalid { border-color: var(--error-border); }
.field-input[readonly] { color: var(--body-muted); }
.error-note { margin: 0; text-align: center; font-style: italic; font-size: 14px; color: var(--error-text); }

/* ---------- Card screen ---------- */
.screen-card {
  position: relative; z-index: 1; min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 9vh 6vw 8vh; box-sizing: border-box;
}
.card-headline {
  margin: 0 0 6vh; font-weight: 500; line-height: 1.15; text-align: center;
  animation: stdFadeUp 600ms ease both;
}
.card-headline .hl-text {
  display: block; font-family: 'EB Garamond', Georgia, serif; font-style: italic; font-weight: 400;
  font-size: clamp(22px, 3.6vw, 32px); color: var(--heading); text-wrap: balance;
}
.card-headline .hl-greet { font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-style: normal; }
.card-headline .hl-thanks { font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-style: normal; animation: stdFadeUp 700ms ease both; }
.card-content { width: min(100%, 620px); }

.save-retry-banner {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  margin: -3vh 0 4vh; text-align: center;
  font-style: italic; font-size: 14px; color: var(--error-text);
  animation: stdFadeUp 400ms ease both;
}
.save-retry-banner .edit-link { text-decoration-color: currentColor; }

/* mobile envelope (above, once saved) */
.mobile-envelope {
  position: relative; aspect-ratio: 1650 / 1219;
  padding: 10px 12px; margin-bottom: 22px;
  border: 1px solid rgba(43,38,32,0.25); background: var(--paper);
  overflow: hidden; display: flex; flex-direction: column; justify-content: center; box-sizing: border-box;
}
.mobile-envelope.below { margin-bottom: 0; margin-top: 22px; }
.mobile-envelope .stamp { position: absolute; top: 8px; right: 8px; width: 118px; }
.mobile-envelope .env-inner { margin: 0 auto; max-width: 66%; text-align: left; }
.mobile-envelope .env-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.mobile-envelope .env-to { margin: 0 0 4px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: 13px; letter-spacing: 0.22em; color: var(--body-muted); }
.mobile-envelope .env-name { margin: 0; font-size: 17px; line-height: 1.4; color: #2B2620; font-style: normal; border-bottom: none; }
.mobile-envelope .env-name-placeholder { color: var(--faint); font-style: italic; }
.mobile-envelope .env-lines { display: flex; flex-direction: column; }
.mobile-envelope .env-cta-wrap { position: absolute; left: 0; right: 0; bottom: 4%; display: flex; justify-content: center; }
@media (min-width: 640px) { .mobile-envelope { display: none !important; } }

.edit-link {
  cursor: pointer; font-size: 12px; letter-spacing: 0.1em; color: var(--body-muted);
  text-decoration: underline; text-decoration-color: rgba(107,103,93,0.45); text-underline-offset: 2px;
  padding: 8px 6px; white-space: nowrap; background: none; border: none; font-family: 'Anonymous Pro', monospace;
}
.edit-link:hover { color: #6B5B3E; }

/* Postcard */
.postcard-outer {
  position: relative; width: 100%; aspect-ratio: 1650 / 1219;
  outline: none; cursor: pointer; perspective: 1500px; -webkit-tap-highlight-color: transparent;
  transform: rotate(-1.4deg);
  animation: stdFadeUp 700ms cubic-bezier(.22,.8,.3,1) both;
  background: transparent; border: none; padding: 0; display: block; text-align: left;
}
.postcard-wiggle { position: relative; width: 100%; height: 100%; transform-origin: center; }
.postcard-wiggle.wiggling { animation: stdWiggle 3.6s ease-in-out infinite; }
.postcard-inner {
  position: relative; width: 100%; height: 100%; transform-style: preserve-3d;
  transition: transform 700ms cubic-bezier(.22,.8,.3,1);
}
.postcard-inner.flipped { transform: rotateY(180deg); }
.reduced-motion .postcard-inner { transition: none; }

.postcard-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: hidden; border-radius: 2px;
  box-shadow: 0 20px 40px rgba(90,76,54,0.18), 0 2px 6px rgba(90,76,54,0.14);
  font-family: 'EB Garamond', Georgia, serif;
}
.postcard-face .hairline { position: absolute; inset: 0; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5); }
.postcard-front { background: #EDE7DB; z-index: 2; }
.postcard-front img { width: 100%; height: 100%; object-fit: cover; object-position: center; display: block; }
.postcard-back { background: var(--paper); transform: rotateY(180deg); z-index: 1; }

.reduced-motion .postcard-front { transition: opacity 320ms ease; }
.reduced-motion .postcard-back { transition: opacity 320ms ease; transform: none; }
.reduced-motion .postcard-inner.flipped .postcard-front { opacity: 0; z-index: 1; }
.reduced-motion .postcard-inner.flipped .postcard-back { opacity: 1; z-index: 2; }
.reduced-motion .postcard-inner:not(.flipped) .postcard-front { opacity: 1; z-index: 2; }
.reduced-motion .postcard-inner:not(.flipped) .postcard-back { opacity: 0; z-index: 1; }

.postcard-inner:not(.reduced-motion-inner) .postcard-front.hidden-face,
.postcard-inner:not(.reduced-motion-inner) .postcard-back.hidden-face { opacity: 0; }

.back-normal { position: relative; height: 100%; box-sizing: border-box; padding: 6% 6%; display: grid; grid-template-columns: 1fr 1fr; gap: 6%; overflow: visible; }
.back-divider { position: absolute; top: 6%; bottom: 6%; left: 50%; width: 1px; background: rgba(43,38,32,0.25); pointer-events: none; display: none; }
@media (min-width: 640px) { .back-divider { display: block; } }
@media (max-width: 639px) { .back-normal { display: none !important; } }

.back-left { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.back-left .std { margin: 0 0 10px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: clamp(8px, 1.6vw, 13px); letter-spacing: 0.30em; color: #4A4740; }
.back-left .names { margin: 0 0 12px; font-family: 'Madelyn', cursive; font-size: clamp(38px, 8.5vw, 54px); line-height: 1.3; color: #595354; }
.back-left .date { margin: 0 0 14px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: clamp(8px, 1.5vw, 12px); letter-spacing: 0.16em; line-height: 2; color: #3F3C35; }
.back-left .rule { width: 28px; height: 1px; background: rgba(43,38,32,0.28); margin: 8px 0 12px; }
.back-left .formal { margin: 0; font-style: italic; font-size: clamp(11px, 2vw, 15px); color: var(--body-muted); }

.back-right { position: relative; display: flex; flex-direction: column; }
.back-right .stamp { position: absolute; top: -20px; right: -20px; width: clamp(95px, 26vw, 150px); mix-blend-mode: multiply; opacity: 0.9; }
.back-right .spacer { height: min(26%, 120px); }
.back-right .to { margin: 12px 0 6px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: clamp(11px, 1.5vw, 13px); letter-spacing: 0.22em; color: var(--body-muted); }
.back-right .to-name { margin: 0; font-size: clamp(12px, 2.2vw, 20px); line-height: 1.4; border-bottom: 1px solid rgba(43,38,32,0.5); padding-bottom: 4px; color: #2B2620; }
.back-right .addr-row { margin-top: 14px; display: flex; align-items: baseline; justify-content: space-between; }
.back-right .addr-row .lbl { font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: clamp(10px, 1.3vw, 12px); letter-spacing: 0.16em; color: var(--body-muted); }
.back-right .addr-row .edit-link { font-size: clamp(11px, 1.4vw, 13px); letter-spacing: 0.08em; margin: -8px -6px; }
.back-right .addr-lines { margin-top: 10px; display: flex; flex-direction: column; gap: 14px; }
.addr-line {
  margin: 0; line-height: 1.4; min-height: 22px; padding-bottom: 4px;
  font-size: clamp(11px, 1.8vw, 16px);
  border-bottom: 1px dashed rgba(43,38,32,0.26);
  color: var(--faint); font-style: italic;
}
.addr-line.filled {
  font-size: clamp(12px, 2.2vw, 20px);
  border-bottom: 1px solid rgba(43,38,32,0.5);
  color: #2B2620; font-style: normal;
}
.back-right .cta-row { margin-top: 16px; display: flex; justify-content: center; }

.back-skinny { position: relative; height: 100%; box-sizing: border-box; padding: 10% 8%; display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
@media (max-width: 639px) { .back-skinny { display: flex; } }
.back-skinny .std { margin: 0 0 8px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: 11px; letter-spacing: 0.28em; color: #4A4740; }
.back-skinny .names { margin: 0 0 10px; font-family: 'Madelyn', cursive; font-size: clamp(40px, 12vw, 54px); line-height: 1.2; color: #595354; }
.back-skinny .date { margin: 0 0 12px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: 11px; letter-spacing: 0.14em; line-height: 1.8; color: #3F3C35; }
.back-skinny .rule { width: 28px; height: 1px; background: rgba(43,38,32,0.28); margin: 6px 0 12px; }
.back-skinny .formal { margin: 0; font-style: italic; font-size: 14px; color: var(--body-muted); }

.hint-wrap { margin: 4px 0 0; text-align: center; }
.hint-btn {
  display: flex; align-items: center; gap: 12px; margin: 0 auto; background: none; border: none; cursor: pointer;
  padding: 12px 10px; color: var(--body-muted); font-family: 'EB Garamond', Georgia, serif; font-weight: 600;
  font-size: 15px; letter-spacing: 0.16em;
}
.hint-btn:hover { color: #6B5B3E; }
.hint-line { width: 22px; height: 1px; background: currentColor; opacity: 0.5; }
.save-link-row { margin-top: 6px; text-align: right; }
.save-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--body-muted); text-decoration: none; cursor: pointer;
  font-family: 'Anonymous Pro', monospace; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
}
.save-link:hover { color: #2B2620; }
.save-icon { display: inline-flex; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(43,38,32,0.42); backdrop-filter: blur(2px);
  z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-panel {
  box-sizing: border-box; background: var(--paper); font-family: 'EB Garamond', Georgia, serif;
  box-shadow: 0 24px 60px rgba(43,38,32,0.3);
  animation: stdFadeUp 340ms cubic-bezier(.22,.8,.3,1) both;
  width: min(92vw, 480px); max-height: 90vh; overflow: auto; padding: 36px 32px; border-radius: 2px;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.modal-title { margin: 0; font-size: 22px; }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--body-muted); padding: 4px; }
.modal-close:hover { color: #2B2620; }
.modal-fields { display: flex; flex-direction: column; gap: 20px; }
.section-header { margin: 0 0 -6px; font-family: 'Marcellus', 'EB Garamond', Georgia, serif; font-size: 12px; letter-spacing: 0.24em; color: var(--heading); border-bottom: 1px solid var(--rule); padding-bottom: 8px; }
.section-header.second { margin: 14px 0 -6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.partner-note { margin: -8px 0 -12px; font-size: 15px; font-style: italic; color: var(--body-muted); text-wrap: pretty; }
.select-wrap { position: relative; }
.select-field {
  width: 100%; box-sizing: border-box; padding: 13px 14px; font-size: 15px; color: #2B2620; background: transparent;
  border: 1px solid var(--field-border); border-radius: 0; appearance: none; -webkit-appearance: none;
  font-family: 'EB Garamond', Georgia, serif; cursor: pointer; padding-right: 36px;
}
.select-caret { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--body-muted); font-size: 12px; }
.cep-msg { margin: 2px 0 0; font-size: 14px; font-style: italic; }
.grid-2-110 { display: grid; grid-template-columns: minmax(0,1fr) 110px; gap: 16px; }
.grid-2-120 { display: grid; grid-template-columns: 120px minmax(0,1fr); gap: 16px; }
.modal-note { margin: 0 0 0; text-align: center; font-style: italic; font-size: 15px; color: var(--error-text); min-height: 0; }
.modal-note.show { margin: 18px 0 0; }

/* loading spinner inside buttons */
.spinner {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: stdSpin 700ms linear infinite; vertical-align: -2px; margin-right: 8px;
}

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

@media (max-width: 420px) {
  .two-col, .grid-2-110, .grid-2-120 { gap: 12px; }
}
