/* ==========================================================================
   Layout Styles (Mobile-First + Desktop Wrapper)
   ========================================================================== */

/* Desktop Ambient Backdrop */
.app-viewport-wrapper {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--desktop-backdrop);
  overflow: hidden;
  position: relative;
}

/* Main Mobile Frame Container */
.mobile-app-container {
  width: 100%;
  max-width: var(--mobile-max-width);
  height: 100%;
  max-height: 100vh;
  max-height: 100dvh;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  transition: background-color var(--transition-normal);
}

/* On Desktop screens, give the mobile container a rounded phone-like frame */
@media (min-width: 500px) and (min-height: 550px) {
  .mobile-app-container {
    height: 94vh;
    max-height: 880px;
    border-radius: 40px;
    border: 8px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(255, 255, 255, 0.2);
  }
}

/* In Landscape orientation on mobile/emulated devices, take full width & height */
@media (orientation: landscape) and (max-height: 600px) {
  .mobile-app-container {
    max-width: 100% !important;
    width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
  }
  .app-viewport-wrapper {
    background: var(--bg-page) !important;
  }

  /* Landscape 2-column panoramic view for Spotlight World Beauty Modal */
  #spotlight-modal .modal-sheet {
    max-width: 100% !important;
    width: 100% !important;
    padding: calc(var(--safe-top) + 6px) 14px calc(var(--safe-bottom) + 6px) 14px !important;
  }
  #spotlight-modal .spotlight-modal-body {
    flex-direction: row !important;
    gap: 14px !important;
    align-items: stretch !important;
    overflow: hidden !important;
  }
  #spotlight-modal #spotlight-image-card {
    flex: 1.4 !important;
    min-height: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 16px !important;
  }
  #spotlight-modal .spotlight-modal-sidebar {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    overflow-y: auto !important;
    gap: 8px !important;
    padding-right: 4px !important;
  }
  #spotlight-modal #spotlight-action-area {
    margin-top: 6px !important;
  }
}

/* Header Area */
.app-header {
  height: calc(58px + var(--safe-top));
  min-height: calc(58px + var(--safe-top));
  padding: 0 var(--space-lg);
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-page);
  z-index: 20;
  flex-shrink: 0;
}

.app-header .header-left,
.app-header .header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 40px;
}

.app-header .header-right {
  justify-content: flex-end;
}

.app-header .header-center {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0 4px;
}

.header-title-main {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.15;
  white-space: normal;
  word-break: normal;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

/* Primary touch targets remain usable on phones and with motor impairments. */
button, .btn, .nav-item, .quick-plus-btn, .chip, select {
  min-height: 44px;
}

@media (max-width: 340px) {
  .app-header { padding-left: var(--space-sm); padding-right: var(--space-sm); }
  .app-main { padding-left: var(--space-sm); padding-right: var(--space-sm); }
  .nav-item { font-size: 0.66rem; }
}

.icon-btn:active {
  transform: scale(0.92);
  background-color: var(--bg-card-hover);
}

/* Main Content Area */
.app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  padding: var(--space-md) var(--space-lg);
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Scrollbar polish */
.app-main::-webkit-scrollbar {
  width: 4px;
}
.app-main::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--nav-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 30;
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  gap: 3px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  transition: color var(--transition-fast), transform var(--transition-fast);
}

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke-width: 2;
  transition: transform var(--transition-fast), color var(--transition-fast);
}

.nav-item.active {
  color: var(--accent-primary);
  font-weight: 600;
}

.nav-item.active svg {
  transform: translateY(-1px);
}

.nav-item:active {
  transform: scale(0.92);
}

/* Central Floating Action Button (+) */
.nav-fab-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.nav-fab {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  padding: 0;
  transform: translateY(-8px);
  transition: transform var(--transition-bounce), filter var(--transition-fast);
  cursor: pointer;
}

.nav-fab:hover,
.nav-fab:active {
  transform: translateY(-10px) scale(1.08);
}

.nav-fab.open {
  transform: translateY(-8px) rotate(45deg);
}

.nav-mascot-svg {
  width: 52px;
  height: 52px;
  display: block;
  animation: mascotBreathe 3s ease-in-out infinite;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.22));
}

@keyframes mascotBreathe {
  0%, 100% {
    transform: scale(1) translateY(0);
  }
  50% {
    transform: scale(1.04) translateY(-2px);
  }
}

.nav-fab-classic-inner {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
  transition: background-color var(--transition-fast), transform var(--transition-bounce), box-shadow var(--transition-fast);
}

/* View Container (Screen switching) */
.view-container {
  display: none;
  animation: fadeIn 0.22s ease-out forwards;
}

.view-container.active {
  display: block;
}

/* Modal Overlay & Sheet Animations */
@keyframes modalOverlayFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalOverlayFadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes modalSheetSlideIn {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modalSheetSlideOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
}

/* Modal Overlay */
.modal-overlay {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  padding: var(--safe-top) 0 var(--safe-bottom);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
  animation: modalOverlayFadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-overlay.closing {
  animation: modalOverlayFadeOut 0.16s ease-out forwards;
  pointer-events: none;
}

.modal-sheet {
  background: var(--bg-card);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  max-height: 90%;
  box-sizing: border-box;
  overflow-y: auto;
  padding: var(--space-lg);
  padding-bottom: calc(var(--safe-bottom) + 24px) !important;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  will-change: transform, opacity;
}

/* Every mobile modal must fit between the system status and navigation bars. */
.modal-safe-sheet {
  max-height: calc(100% - var(--safe-top) - var(--safe-bottom)) !important;
}

/* Fullscreen modal overlay & sheet contract */
.modal-overlay.modal-fullscreen {
  padding: 0 !important;
  justify-content: stretch !important;
  align-items: stretch !important;
}

.modal-sheet.modal-fullscreen-sheet {
  height: 100% !important;
  height: 100dvh !important;
  max-height: 100% !important;
  max-height: 100dvh !important;
  width: 100% !important;
  border-radius: 0 !important;
  border-top-left-radius: 0 !important;
  border-top-right-radius: 0 !important;
  box-shadow: none !important;
  display: flex !important;
  flex-direction: column !important;
}

.modal-overlay.open .modal-sheet {
  animation: modalSheetSlideIn 0.24s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-overlay.closing .modal-sheet {
  animation: modalSheetSlideOut 0.16s ease-out forwards;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Fullscreen spotlight photo details stay clear of Android system bars. */
.spotlight-fullscreen-layer {
  box-sizing: border-box;
  padding-top: var(--safe-top);
}

.spotlight-fullscreen-top {
  padding: 18px 18px 0;
}

.spotlight-fullscreen-bottom {
  padding: 20px 18px 28px;
  padding-bottom: calc(28px + var(--safe-bottom));
}

/* Keep dynamically opened modals above the fullscreen onboarding layer. */
#modal-container {
  position: absolute;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}

/* Fullscreen Onboarding Layer */
#onboarding-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  pointer-events: none;
}

#onboarding-container:not(:empty) {
  pointer-events: auto;
  background: var(--bg-page);
}
