/* ==========================================================================
   Endy & Rathanin — Modern Cambodian Luxury Wedding Invitation
   Color Palette:
   - Primary Background: Warm Ivory / Cream (#FAF7F2)
   - Secondary / Card Surface: Soft Champagne (#F3EDE2)
   - Primary Accent: Deep Sage / Olive Green (#4A5D4E)
   - Luxury Accent: Antique Metallic Gold (#C5A059)
   - Text Primary: Deep Charcoal (#2C302E)
   ========================================================================== */

:root {
  --bg-ivory: #FAF7F2;
  --bg-champagne: #F3EDE2;
  --sage-primary: #4A5D4E;
  --sage-dark: #364639;
  --sage-light: #657B6A;
  --gold-primary: #C5A059;
  --gold-light: #DFC286;
  --gold-dark: #9D7A36;
  --text-charcoal: #2C302E;
  --text-muted: #5A605D;
  --brand-color: #4A5D4E;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background-color: var(--bg-ivory);
  color: var(--text-charcoal);
  accent-color: var(--brand-color);
  color-scheme: light;
}

body {
  font-family: 'Plus Jakarta Sans', 'Kantumruy Pro', sans-serif;
  background-color: var(--bg-ivory);
  color: var(--text-charcoal);
  overflow-x: hidden;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

/* Lock scroll while envelope splash is closed */
body.envelope-locked {
  overflow: hidden;
  height: 100dvh;
}

/* ==========================================================================
   Typography & Khmer Script Line-Height Safeguards
   ========================================================================== */

.font-kh-title {
  font-family: 'Moul', 'Moulpali', serif;
  line-height: 2.0 !important;
  letter-spacing: 0.02em;
  padding-top: 0.18em;
  padding-bottom: 0.18em;
}

.font-kh-sub {
  font-family: 'Moulpali', 'Moul', serif;
  line-height: 1.95 !important;
  padding-top: 0.12em;
  padding-bottom: 0.12em;
}

.font-kh-body {
  font-family: 'Kantumruy Pro', 'Battambang', sans-serif;
  line-height: 1.9 !important;
}

.font-en-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
}

.font-en-body {
  font-family: 'Plus Jakarta Sans', 'Montserrat', sans-serif;
}

/* Modern Web Guidance: improve-text-layout-and-legibility */
h1, h2, h3, h4, .balance-text {
  text-wrap: balance;
}

p, blockquote, li, .pretty-text {
  text-wrap: pretty;
}

/* ==========================================================================
   Luxury Metallic Gold & Sage Textures
   ========================================================================== */

.gold-gradient-text {
  background: linear-gradient(135deg, #9D7A36 0%, #C5A059 35%, #E8CF96 50%, #C5A059 65%, #94712F 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.gold-metallic-bg {
  background: linear-gradient(135deg, #B38B40 0%, #C5A059 35%, #E5CA8F 50%, #C5A059 70%, #9A7432 100%);
}

.sage-luxury-bg {
  background: radial-gradient(circle at 50% 25%, #586E5D 0%, #4A5D4E 55%, #37473A 100%);
}

/* Subtle Cambodian Silk / Paper Texture Overlay */
.paper-texture {
  background-image: 
    radial-gradient(rgba(197, 160, 89, 0.07) 1px, transparent 0),
    radial-gradient(rgba(74, 93, 78, 0.05) 1px, transparent 0);
  background-size: 28px 28px;
  background-position: 0 0, 14px 14px;
}

/* Arch Silhouette Framing (Matching Physical Envelope & Inner Card) */
.luxury-arch-frame {
  border-radius: 220px 220px 24px 24px;
  position: relative;
}

@media (min-width: 640px) {
  .luxury-arch-frame {
    border-radius: 280px 280px 28px 28px;
  }
}

.double-gold-border {
  border: 1.5px solid rgba(197, 160, 89, 0.55);
  box-shadow:
    inset 0 0 0 6px var(--bg-ivory),
    inset 0 0 0 7px rgba(197, 160, 89, 0.35),
    0 20px 50px -15px rgba(44, 48, 46, 0.12);
}

.double-gold-border-champagne {
  border: 1.5px solid rgba(197, 160, 89, 0.55);
  box-shadow:
    inset 0 0 0 6px var(--bg-champagne),
    inset 0 0 0 7px rgba(197, 160, 89, 0.35),
    0 18px 40px -15px rgba(44, 48, 46, 0.10);
}

/* ==========================================================================
   Envelope Splash Screen & 3D Flap Opening Animation
   ========================================================================== */

#envelope-overlay {
  transition: opacity 0.9s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.9s cubic-bezier(0.22, 1, 0.36, 1),
              visibility 0.9s;
  will-change: opacity, transform;
}

#envelope-overlay.is-opened {
  opacity: 0;
  transform: scale(1.06) translateY(-20px);
  visibility: hidden;
  pointer-events: none;
}

.envelope-card-shell {
  perspective: 1400px;
}

.envelope-top-flap {
  transform-origin: top center;
  transition: transform 0.85s cubic-bezier(0.4, 0, 0.2, 1);
  backface-visibility: hidden;
}

.envelope-card-shell.flap-opening .envelope-top-flap {
  transform: rotateX(165deg);
}

.butterfly-seal {
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s ease;
}

.envelope-card-shell.flap-opening .butterfly-seal {
  transform: translateY(-24px) scale(1.18);
  opacity: 0;
}

@keyframes floatSlow {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
}

.animate-float-slow {
  animation: floatSlow 4.5s ease-in-out infinite;
}

@keyframes shimmerPulse {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.03); }
}

.animate-shimmer {
  animation: shimmerPulse 3.2s ease-in-out infinite;
}

/* ==========================================================================
   Scroll-Driven Reveal Animations (Modern Web Guidance: scroll-entry-exit-effects)
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  @supports ((animation-timeline: view()) and (animation-range: entry)) {
    @keyframes luxury-reveal-in {
      from {
        opacity: 0;
        transform: translateY(32px) scale(0.98);
      }
      to {
        opacity: 1;
        transform: translateY(0) scale(1);
      }
    }

    .reveal-on-scroll {
      animation: luxury-reveal-in auto cubic-bezier(0.22, 1, 0.36, 1) backwards;
      animation-timeline: view(block);
      animation-range: entry 5% cover 24%;
    }
  }
}

/* IntersectionObserver Fallback for browsers without animation-timeline: view() */
.reveal-fallback-init {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.75s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.75s cubic-bezier(0.22, 1, 0.36, 1);
}

.reveal-fallback-init.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   Forms: Modern Web Guidance (form-fields-automatically-fit-contents,
   brand-consistent-forms, required-field-feedback)
   ========================================================================== */

textarea.auto-fit-textarea {
  field-sizing: content;
  height: auto;
  width: 100%;
  min-block-size: 3.5lh;
  max-block-size: 10lh;
}

/* Fallback for browsers without field-sizing: content */
@supports not (field-sizing: content) {
  .growable-textarea {
    display: grid;
  }
  .growable-textarea::after,
  .growable-textarea > textarea {
    grid-area: 1 / 1 / 2 / 2;
  }
  .growable-textarea::after {
    content: attr(data-replicated-value) " ";
    white-space: pre-wrap;
    visibility: hidden;
    padding: 0.75rem 1rem;
    font: inherit;
  }
}

/* Fallback for older browsers without accent-color */
@supports not (accent-color: var(--brand-color)) {
  input[type="radio"].visually-hidden-fallback {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }
}

/* Required Field Feedback (:user-invalid + fallback) */
.error-msg {
  display: none;
  color: #b91c1c;
  font-size: 0.8125rem;
  margin-top: 0.375rem;
}

input:user-invalid,
textarea:user-invalid,
input.user-invalid-fallback,
textarea.user-invalid-fallback {
  border-color: #b91c1c !important;
  background-color: #fef2f2 !important;
}

input:user-invalid ~ .error-msg,
textarea:user-invalid ~ .error-msg,
input.user-invalid-fallback ~ .error-msg,
textarea.user-invalid-fallback ~ .error-msg {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

input:required:user-valid,
textarea:required:user-valid {
  border-color: var(--sage-primary);
}

/* ==========================================================================
   Language Display Modes (KH | EN | BOTH)
   ========================================================================== */

body[data-lang="kh"] .lang-en-only {
  display: none !important;
}

body[data-lang="en"] .lang-kh-only {
  display: none !important;
}

/* In BOTH mode, both .lang-kh-only and .lang-en-only remain visible harmoniously */

/* ==========================================================================
   Floating Glassmorphism Bottom Navigation & Sticky Header
   ========================================================================== */

.glass-panel {
  background: rgba(250, 247, 242, 0.84);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(197, 160, 89, 0.38);
}

.glass-panel-dark {
  background: rgba(54, 70, 57, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(197, 160, 89, 0.45);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-ivory);
}

::-webkit-scrollbar-thumb {
  background: #C5A059;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4A5D4E;
}
