/* ==========================================================================
   MAIN LAYOUT & RESPONSIVE ARCHITECTURE (MOBILE-FIRST)
   ========================================================================== */

/* Modern CSS Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  background-color: var(--bg-palace);
  color: var(--text-ivory);
  font-family: var(--font-sans);
  overflow-x: hidden;
}

/* App Container wrapper */
.app-wrapper {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

.main-content {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 0 32px;
  width: 100%;
}

/* State Containers (Show/Hide with smooth crossfade) */
.state-panel {
  display: none;
  width: 100%;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.state-panel.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 1;
  transform: translateY(0);
}

/* Accessibility Focus States */
a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--gold-champagne);
  outline-offset: 3px;
}

/* Mobile Viewport Optimizations (Single-Screen Zero-Scroll Architecture) */
@media (max-width: 480px) {

  html,
  body {
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
    position: fixed;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .app-wrapper {
    height: 100dvh;
    height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: max(14px, env(safe-area-inset-top, 14px)) 0 max(14px, env(safe-area-inset-bottom, 14px));
    box-sizing: border-box;
  }

  /* Main Top Logo: Centered harmoniously above heading */
  .site-header {
    width: 100%;
    padding: 0 16px;
    margin-bottom: 24px;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .soundtrack-widget-wrap {
    position: absolute;
    right: 16px;
    top: calc(max(14px, env(safe-area-inset-top, 14px)) + 12px);
    z-index: 50;
  }

  .btn-royal-soundtrack {
    width: 36px;
    height: 36px;
  }

  .btn-royal-soundtrack .music-title {
    font-size: 0.56rem;
    letter-spacing: 1px;
  }

  .btn-royal-soundtrack .music-state {
    font-size: 0.64rem;
    letter-spacing: 1.2px;
  }

  .brand-logo-wrap {
    margin: 0 auto;
  }

  .brand-logo-img {
    height: clamp(75px, 20vw, 90px);
    max-width: min(300px, calc(100vw - 84px));
    display: block;
  }

  .logo-aura-glow {
    width: 260px;
    height: 75px;
  }

  /* Main Content Area: groups heading and card closely together */
  .main-content {
    flex: 0 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 0;
    width: 100%;
    overflow: hidden;
  }

  /* Heading: brought down right near the image card with tight margin */
  .hero-section {
    padding: 0 14px;
    margin-bottom: 24px;
    flex-shrink: 0;
    text-align: center;
  }

  .hero-title {
    font-size: clamp(1.32rem, 5.4vw, 1.7rem);
    letter-spacing: 1.8px;
    line-height: 1.22;
    word-spacing: 0.16em;
    margin: 0;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0) 75%);
    padding: 15px 30px;
    margin: -15px -30px;
    /* Offset the padding so it doesn't affect layout */
    border-radius: 50%;
    display: inline-block;
  }

  .hero-title .gold-accent {
    display: block;
    word-spacing: 0.22em;
    letter-spacing: 1.5px;
    white-space: nowrap;
  }

  /* Portrait Stage & Royal Frame: positioned immediately beneath heading */
  .portrait-stage {
    flex: 0 1 auto;
    width: 100%;
    max-width: 410px;
    padding: 0 14px;
    display: flex;
    flex-direction: column;
  }

  .royal-frame {
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  .frame-ornate-overlay {
    display: none !important;
  }

  .frame-inner {
    min-height: 0;
    max-height: 100%;
    padding: clamp(12px, 2vh, 18px) 14px clamp(10px, 1.8vh, 16px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
  }

  /* State 1: Upload Card */
  .upload-dropzone {
    padding: clamp(12px, 2.5vh, 22px) 12px clamp(10px, 2vh, 18px);
    border-radius: 16px;
  }

  .upload-icon-wrap {
    width: 36px;
    height: 28px;
    margin-bottom: clamp(12px, 2vh, 18px);
  }

  .static-gold-crown-svg {
    width: 34px;
    height: 24px;
  }

  .upload-title {
    font-size: clamp(1.05rem, 3.8vw, 1.18rem);
    margin-bottom: 4px;
    letter-spacing: 1.8px;
  }

  .upload-title-divider {
    display: none !important;
  }

  .upload-hint {
    font-size: clamp(0.74rem, 2.8vw, 0.82rem);
    line-height: 1.35;
    margin-bottom: clamp(8px, 1.8vh, 16px);
    max-width: 270px;
  }

  .btn-gold-primary {
    padding: clamp(10px, 1.8vh, 13px) 18px;
    font-size: 0.8rem;
    letter-spacing: 1.5px;
    min-height: 44px;
    width: 100%;
    max-width: 300px;
  }

  .file-specs {
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    margin-top: clamp(6px, 1.4vh, 12px);
  }

  .spec-pill {
    padding: 2px 6px;
    font-size: 0.62rem;
  }

  .demo-trigger-wrap {
    margin-top: clamp(6px, 1.4vh, 10px);
  }

  .demo-trigger-btn {
    font-size: 0.74rem;
    padding: 2px 6px;
  }

  /* State 2: Photo Preview (Fully contained, CTA 100% visible without scroll) */
  .preview-container {
    width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
  }

  .preview-header {
    margin-bottom: clamp(4px, 1vh, 8px);
    width: 100%;
  }

  .preview-badge {
    font-size: 0.8rem;
    letter-spacing: 1.4px;
  }

  .preview-change-btn {
    font-size: 0.74rem;
    padding: 2px 4px;
  }

  .preview-image-box {
    width: auto;
    max-width: 100%;
    height: clamp(150px, 27vh, 215px);
    aspect-ratio: 4 / 5;
    margin: 0 auto clamp(6px, 1.2vh, 10px) auto;
    border-radius: 14px;
  }

  .preview-image-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
  }

  .consent-wrapper {
    padding: clamp(5px, 1vh, 8px) 10px;
    margin-bottom: clamp(6px, 1.2vh, 10px);
    gap: 8px;
    border-radius: 10px;
    width: 100%;
  }

  .consent-label {
    font-size: clamp(0.68rem, 2.6vw, 0.74rem);
    line-height: 1.3;
  }

  .custom-checkbox {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .preview-container .btn-gold-primary {
    min-height: 44px;
    padding: 11px 18px;
    font-size: 0.78rem;
    letter-spacing: 1.4px;
  }

  /* State 3: Loading container */
  .loading-container {
    min-height: 0;
    padding: 6px 4px;
  }

  .loading-visual-orb {
    width: clamp(76px, 14vh, 96px);
    height: clamp(76px, 14vh, 96px);
    margin: 0 auto clamp(8px, 1.5vh, 14px) auto;
  }

  .loading-headline {
    font-size: clamp(1.0rem, 3.6vw, 1.15rem);
    margin-bottom: 4px;
  }

  .loading-subtext {
    font-size: 0.75rem;
    line-height: 1.3;
    margin-bottom: 8px;
    max-width: 260px;
  }

  .loading-progress-track {
    margin: 8px auto 0;
    height: 4px;
  }

  /* State 4: Result container */
  .result-container {
    width: 100%;
    max-height: 100%;
  }

  .result-crest-badge {
    margin-bottom: 4px;
    font-size: 0.68rem;
  }

  .result-title {
    font-size: clamp(1.05rem, 3.8vw, 1.18rem);
    letter-spacing: 1.8px;
    margin: 0 0 clamp(4px, 1vh, 8px);
  }

  .result-image-box {
    width: auto;
    max-width: 100%;
    height: clamp(160px, 28vh, 220px);
    aspect-ratio: 4 / 5;
    margin: 0 auto clamp(6px, 1.2vh, 10px) auto;
    border-radius: 14px;
  }

  .result-actions-stack {
    gap: 6px;
    width: 100%;
  }

  .result-actions-stack .btn-gold-primary,
  .result-actions-stack .btn-secondary-action {
    min-height: 42px;
    padding: 10px 16px;
    font-size: 0.78rem;
  }
}

/* Two-Column Desktop & Tablet Split Layout */
.main-layout-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 5;
}

.layout-ui-column {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.layout-queen-column {
  display: none;
  /* Hidden on mobile */
}

/* Tablet & Desktop: Reference Image 1 Two-Column Imperial Showcase */
@media (min-width: 900px) {
  .app-wrapper {
    position: relative;
    min-height: 100vh;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px 48px;
    box-sizing: border-box;
  }

  .soundtrack-widget-wrap {
    position: fixed;
    top: 32px;
    right: 42px;
    z-index: 100;
  }

  .btn-royal-soundtrack {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
  }

  .btn-royal-soundtrack .music-title {
    font-size: 0.66rem;
    letter-spacing: 1.3px;
  }

  .btn-royal-soundtrack .music-state {
    font-size: 0.74rem;
    letter-spacing: 1.5px;
  }

  .site-header {
    position: static;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0 0 16px 0;
    z-index: 5;
  }

  .brand-logo-wrap {
    margin: 0 auto;
  }

  .brand-logo-img {
    height: 72px;
    max-width: 320px;
  }

  .main-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1260px;
    margin: 0 auto;
    padding: 10px 0;
  }

  .main-layout-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(36px, 5vw, 64px);
    width: 100%;
  }

  .layout-ui-column {
    flex: 1;
    max-width: 490px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .layout-ui-column .hero-section {
    text-align: center;
    padding: 0;
    margin: 0 0 14px 0;
    width: 100%;
  }

  .layout-ui-column .hero-title {
    text-align: center;
    font-size: clamp(1.5rem, 2.3vw, 1.95rem);
    letter-spacing: 2px;
    line-height: 1.25;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0) 70%);
    padding: 20px 40px;
    margin: -20px -40px;
    /* Offset the padding so it doesn't affect layout */
    border-radius: 50%;
  }

  .layout-ui-column .hero-lotus-divider {
    margin: 6px auto 0;
    justify-content: center;
    max-width: 180px;
  }

  .layout-ui-column .portrait-stage {
    padding: 0;
    max-width: 470px;
    width: 100%;
  }

  .frame-ornate-overlay {
    display: none;
  }



  .frame-inner {
    min-height: 380px;
    padding: 24px 20px 20px;
  }

  .upload-dropzone {
    padding: 22px 18px 18px;
    border: none;
    background: transparent;
    box-shadow: none;
  }

  .upload-dropzone:hover,
  .upload-dropzone.drag-over {
    border: none;
    background: transparent;
    box-shadow: none;
    transform: none;
  }

  .upload-icon-wrap {
    display: flex;
    width: 60px;
    height: 46px;
    margin-bottom: 16px;
  }

  .desktop-crown-divider {
    display: flex;
  }

  .desktop-demo-crown-divider {
    display: flex;
  }

  .upload-title-divider {
    display: none;
  }

  .btn-scroll-left,
  .btn-scroll-right {
    display: none;
  }

  .btn-upload-icon {
    display: inline-flex;
  }

  .btn-gold-primary {
    max-width: 320px;
    padding: 13px 22px;
    font-size: 0.84rem;
  }

  .bullet-mobile {
    display: none;
  }

  .bullet-desktop {
    display: inline;
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--gold-champagne);
    opacity: 0.85;
  }

  .preview-image-box {
    height: clamp(200px, 45vh, 360px);
    width: auto;
    max-width: 100%;
    aspect-ratio: 4 / 5;
    margin: 0 auto 16px auto;
  }

  /* Right Column: Royal Queen on Throne */
  .layout-queen-column {
    display: flex;
    flex: 1.15;
    align-items: center;
    justify-content: center;
    position: relative;
    max-height: 720px;
    pointer-events: none;
  }

  .queen-hero-backdrop {
    position: relative;
    width: 100%;
    max-width: 530px;
    display: flex;
    justify-content: center;
  }

  .desktop-queen-portrait {
    width: 100%;
    height: auto;
    max-height: 640px;
    object-fit: contain;
    filter: drop-shadow(0 25px 60px rgba(0, 0, 0, 0.98)) drop-shadow(0 0 50px rgba(62, 19, 91, 0.4));
    animation: queenGlowBreathe 8s ease-in-out infinite alternate;
  }

  @keyframes queenGlowBreathe {
    0% {
      filter: drop-shadow(0 25px 60px rgba(0, 0, 0, 0.98)) drop-shadow(0 0 40px rgba(62, 19, 91, 0.35));
    }

    100% {
      filter: drop-shadow(0 25px 70px rgba(0, 0, 0, 0.98)) drop-shadow(0 0 70px rgba(223, 192, 103, 0.25));
    }
  }
}