/* =============================================
   ImaginingAI — Telegram Mini-App Styles
   Dark theme, mobile-first, Telegram CSS vars
   ============================================= */

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

:root {
  /* Telegram theme variable fallbacks (dark) */
  --tg-theme-bg-color: #0A0A0F;
  --tg-theme-text-color: #F0F0F5;
  --tg-theme-hint-color: #8B8B9E;
  --tg-theme-link-color: #A855F7;
  --tg-theme-button-color: #A855F7;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-secondary-bg-color: #16161F;
  --tg-theme-section-bg-color: #16161F;

  /* App design tokens — derived from Telegram vars for auto-theming */
  --accent: var(--tg-theme-button-color, #A855F7);
  --accent-secondary: #EC4899;
  --accent-glow: rgba(168, 85, 247, 0.35);
  --surface: var(--tg-theme-secondary-bg-color, #16161F);
  --surface-hover: #1E1E2A;
  --text-primary: var(--tg-theme-text-color, #F0F0F5);
  --text-secondary: var(--tg-theme-hint-color, #8B8B9E);
  --bg: var(--tg-theme-bg-color, #0A0A0F);
  --card-radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --tab-bar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tg-safe-top: var(--tg-safe-area-inset-top, 0px);
  --tg-safe-bottom: var(--tg-safe-area-inset-bottom, 0px);
  --tg-safe-left: var(--tg-safe-area-inset-left, 0px);
  --tg-safe-right: var(--tg-safe-area-inset-right, 0px);
  --tg-content-top: var(--tg-content-safe-area-inset-top, 0px);
  --tg-content-bottom: var(--tg-content-safe-area-inset-bottom, 0px);
  --tg-content-left: var(--tg-content-safe-area-inset-left, 0px);
  --tg-content-right: var(--tg-content-safe-area-inset-right, 0px);

  /* Derived opacities that adapt to light/dark via theme vars */
  --overlay-light: rgba(255,255,255,.10);
  --overlay-dark: rgba(0,0,0,.55);
  --border-subtle: rgba(139,139,158,.12);
  --card-shadow: 0 1px 6px rgba(0,0,0,.6);
  --skeleton-mid: #1E1E2A;
}

/* Light-mode overrides when Telegram injects a light background.
   The SDK sets colorScheme; JS applies data-tg-color-scheme + body.tg-light. */
html[data-tg-color-scheme="light"],
html[style*="light"],
body.tg-light {
  --overlay-light: rgba(0,0,0,.06);
  --overlay-dark: rgba(255,255,255,.7);
  --border-subtle: rgba(0,0,0,.1);
  --card-shadow: 0 1px 4px rgba(0,0,0,.12);
  --skeleton-mid: #e8e8ec;
  --accent-glow: rgba(168, 85, 247, 0.2);
}

html, body {
  width: 100%;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — adapts to Telegram chrome */
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden; /* body never scrolls — each view scrolls internally */
}

img { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font: inherit; }

/* --- Views --- */
.view {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tab-bar-h) + max(var(--safe-bottom), var(--tg-safe-bottom)) + 8px);
}
.view.active { display: flex; }

/* Hide tab bar on certain views */
body.hide-tabs #tab-bar { display: none; }
body.hide-tabs .view { padding-bottom: 0; }

/* =============================================
   CATALOG VIEW
   ============================================= */

/* --- Hero Carousel --- */
/* Sticky catalog header */
.catalog-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: var(--tg-safe-top) 16px 4px;
  min-height: calc(var(--tg-safe-top) + var(--tg-content-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.catalog-header-logo {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  object-fit: cover;
}
.catalog-header-brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}
.hero-carousel {
  padding: 8px 0 0;
}
.hero-title {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  padding: 4px 20px 16px;
}
.hero-subtitle-marquee {
  overflow: hidden;
  white-space: nowrap;
  margin-top: -8px;
  padding-bottom: 12px;
}
.hero-subtitle {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 0;
  margin: 0;
  background: linear-gradient(
    90deg,
    #c75378 0%, #c75378 40%,
    #ffc8dd 50%,
    #c75378 60%, #c75378 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: marquee 12s linear infinite, shimmer 3s ease-in-out infinite;
}
@keyframes marquee {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}
@keyframes shimmer {
  0%, 100% { background-position: 100% 0; }
  50%      { background-position: 0 0; }
}
.carousel-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  gap: 10px;
  padding: 0 16px;
  scrollbar-width: none;
}
.carousel-track::-webkit-scrollbar { display: none; }

.carousel-card {
  flex: 0 0 75vw;
  max-width: 340px;
  aspect-ratio: 3 / 4;
  border-radius: var(--card-radius);
  overflow: hidden;
  position: relative;
  scroll-snap-align: center;
  background: var(--surface);
}
.carousel-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.carousel-card .card-label {
  position: absolute;
  bottom: 48px;
  left: 14px;
  right: 14px;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,.6);
  text-align: center;
}
.carousel-card .btn-try {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .2s;
}
.carousel-card.focus .btn-try { opacity: 1; }

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 12px 0 4px;
}
.carousel-dots .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border-subtle);
  transition: background .2s;
}
.carousel-dots .dot.active { background: var(--text-primary); }

/* --- Packages Banner --- */
.packages-banner {
  margin: 12px 16px;
  padding: 14px 16px;
  border-radius: var(--card-radius);
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: transform .15s, background .3s;
}
.packages-banner:active { transform: scale(.97); }
.packages-banner-left { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.packages-banner-credits {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 15px; color: #fff;
}
.packages-banner-credits svg { flex-shrink: 0; }
.packages-banner-bar-track {
  height: 4px; border-radius: 2px;
  background: rgba(255,255,255,.25); overflow: hidden;
}
.packages-banner-bar-fill {
  height: 100%; border-radius: 2px;
  background: rgba(255,255,255,.85);
  transition: width .4s ease;
}
.packages-banner-cta { font-size: 12px; opacity: .8; color: #fff; }
.packages-banner-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.7;
}

/* Zero credits — subtle emphasis */
.packages-banner.banner-empty .packages-banner-bar-fill {
  width: 0% !important;
}

/* --- Category Sections --- */
.category-section {
  padding: 18px 0 0;
}
.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px 10px;
}
.category-title {
  font-size: 18px;
  font-weight: 700;
}
.btn-see-all {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}
.category-row {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  gap: 10px;
  padding: 0 16px 4px;
  scrollbar-width: none;
}
.category-row::-webkit-scrollbar { display: none; }

.style-card {
  flex: 0 0 42vw;
  max-width: 180px;
  aspect-ratio: 3 / 4;
  border-radius: var(--card-radius);
  overflow: hidden;
  position: relative;
  scroll-snap-align: start;
  background: var(--surface);
  cursor: pointer;
  transition: transform .15s;
}
.style-card:active { transform: scale(.96); }
.style-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.style-card .card-label {
  position: absolute;
  bottom: 36px;
  left: 10px;
  right: 10px;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,.6);
}
.style-card .btn-try {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 4px 14px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  pointer-events: none;
  white-space: nowrap;
}
/* =============================================
   CATEGORY VIEW
   ============================================= */
.category-header-bar {
  padding: calc(var(--tg-safe-top) + var(--tg-content-top) + 8px) 16px 10px;
  text-align: center;
}
.category-header-bar .header-brand {
  font-size: 18px;
  font-weight: 700;
}
.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 12px 16px;
}
.category-grid .style-card {
  flex: none;
  max-width: none;
  width: 100%;
}

/* =============================================
   STYLE DETAIL VIEW
   ============================================= */
.style-header {
  display: flex;
  align-items: center;
  padding: calc(var(--tg-safe-top) + var(--tg-content-top) + 8px) 16px 12px;
  gap: 12px;
}
.btn-back {
  font-size: 18px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.header-brand {
  font-size: 16px;
  font-weight: 700;
}

.style-detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 20px;
}
.style-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.style-name {
  font-size: 28px;
  font-weight: 800;
}
.btn-share {
  padding: 8px;
  border-radius: 50%;
  background: var(--surface);
}
.style-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
}

/* Before / After Preview */
.preview-section {
  margin-top: 20px;
}
.preview-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.preview-pair {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.preview-pair.compact {
  margin-bottom: 0;
}
.preview-pair.compact .preview-card {
  aspect-ratio: 3 / 4;
  max-height: 160px;
  border-radius: 10px;
}
.preview-card {
  flex: 1;
  aspect-ratio: 3 / 4;
  border-radius: var(--card-radius);
  overflow: hidden;
  position: relative;
  background: var(--surface);
}
.preview-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preview-label {
  position: absolute;
  bottom: 8px;
  left: 10px;
  font-weight: 600;
  font-size: 12px;
  text-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.unisex-hint {
  text-align: center;
  font-size: 12px;
  color: #c75378;
  margin: 8px 20px 0;
}

/* Upload Section */
.upload-section { margin-top: 8px; }
.section-label {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 10px;
}

.photo-slots {
  display: flex;
  gap: 10px;
  max-height: 180px;
}
.photo-slot {
  aspect-ratio: 3 / 4;
  border-radius: var(--card-radius);
  overflow: hidden;
  position: relative;
  background: var(--surface);
  max-height: 180px;
}
.photo-slot-active { flex: 1.3; }
.photo-slot-upload { flex: 1; }
.photo-slot.empty {
  border: 2px dashed var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-slot .file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}
.slot-placeholder {
  color: var(--text-secondary);
  opacity: .5;
}
.photo-slot .thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-slot .btn-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  z-index: 3;
  color: #fff;
}
/* Active photo has accent border when filled */
.photo-slot-active:not(.empty) {
  border: 2.5px solid var(--accent);
  box-shadow: 0 0 0 2px rgba(169, 112, 255, .35);
}

/* No credits warning */
.no-credits-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 20px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(220, 38, 38, .12);
  border: 1px solid rgba(220, 38, 38, .25);
  color: #F87171;
  font-size: 13px;
  line-height: 1.35;
}
.no-credits-hint svg { flex-shrink: 0; stroke: #F87171; }
.no-credits-hint strong {
  color: #fff;
  text-decoration: underline;
  cursor: pointer;
}

/* CTA */
.btn-create-look {
  margin: 12px 16px calc(max(var(--safe-bottom), var(--tg-safe-bottom)) + 16px);
  padding: 16px;
  border-radius: 28px;
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  color: #fff;
  text-align: center;
  transition: opacity .15s, transform .15s;
}
.btn-create-look:not(:disabled) {
  box-shadow: 0 4px 20px rgba(168, 85, 247, .35);
}
.btn-create-look:disabled {
  opacity: .35;
  pointer-events: none;
}
.btn-create-look:active { transform: scale(.97); }

/* =============================================
   PROCESSING VIEW
   ============================================= */
#view-processing {
  align-items: center;
  justify-content: center;
  padding-top: calc(var(--tg-safe-top) + var(--tg-content-top));
  padding-bottom: 0;
}
.processing-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
}
.processing-title {
  font-size: 22px;
  font-weight: 700;
}
.processing-sub {
  color: var(--text-secondary);
  font-size: 14px;
}
.processing-progress {
  width: 200px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface);
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), #7C3AED);
  transition: width .4s ease;
}

/* Morphing Loader — GPU-accelerated, 60fps */
.morphing-loader {
  position: relative;
  width: 120px;
  height: 120px;
  margin-bottom: 8px;
  will-change: transform;
}

/* Outer ring — morphs circle → rounded-square */
.morph-ring {
  position: absolute;
  inset: 0;
  border: 2.5px solid var(--accent);
  opacity: .6;
  animation: morphShape 3s ease-in-out infinite, spin 2.4s linear infinite;
  will-change: transform, border-radius;
}

/* Middle ring — counter-rotate, offset timing */
.morph-ring.delay-1 {
  inset: 14px;
  border-color: #7c3aed;
  opacity: .45;
  animation: morphShape 3s ease-in-out infinite reverse, spinReverse 3.2s linear infinite;
  animation-delay: -1s;
}

/* Inner ring — fast spin, stays circular */
.morph-ring.delay-2 {
  inset: 28px;
  border-color: var(--accent);
  opacity: .3;
  border-style: dashed;
  animation: spin 1.8s linear infinite;
}

/* Center glowing orb */
.morph-spark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 24px 6px var(--accent-glow), 0 0 48px 12px var(--accent-glow);
  animation: orbPulse 1.6s ease-in-out infinite;
  will-change: transform, box-shadow;
}

/* Floating particle dots (via pseudo-elements on loader) */
.morphing-loader::before,
.morphing-loader::after {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .7;
  will-change: transform;
}
.morphing-loader::before {
  top: 8px; left: 50%;
  animation: floatParticle1 2.4s ease-in-out infinite;
}
.morphing-loader::after {
  bottom: 8px; right: 14px;
  animation: floatParticle2 2.8s ease-in-out infinite;
}

@keyframes morphShape {
  0%, 100% { border-radius: 50%; }
  33%      { border-radius: 40% 60% 55% 45%; }
  66%      { border-radius: 55% 45% 40% 60%; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes spinReverse {
  to { transform: rotate(-360deg); }
}

@keyframes orbPulse {
  0%, 100% {
    transform: scale(.85);
    box-shadow: 0 0 20px 4px var(--accent-glow), 0 0 40px 8px var(--accent-glow);
  }
  50% {
    transform: scale(1.15);
    box-shadow: 0 0 32px 8px var(--accent-glow), 0 0 60px 16px var(--accent-glow);
  }
}

@keyframes floatParticle1 {
  0%, 100% { transform: translate(0, 0) scale(1); opacity: .7; }
  50%      { transform: translate(8px, 14px) scale(.6); opacity: .3; }
}
@keyframes floatParticle2 {
  0%, 100% { transform: translate(0, 0) scale(1); opacity: .5; }
  50%      { transform: translate(-10px, -12px) scale(.5); opacity: .2; }
}

/* =============================================
   RESULT VIEW
   ============================================= */
#view-result { padding-bottom: 0; }
.result-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
}
.result-image {
  width: 100%;
  max-width: 400px;
  border-radius: var(--card-radius);
  background: var(--surface);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  cursor: pointer;
}
.result-style-label {
  margin-top: 10px;
  font-weight: 700;
  font-size: 16px;
}
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px;
  padding-bottom: calc(max(var(--safe-bottom), var(--tg-safe-bottom)) + 16px);
}
.btn-result-action {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 6px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s;
}
.btn-result-action.primary {
  flex: 1 1 100%;
}
.btn-result-action:active { background: var(--surface-hover); }
.btn-result-action.primary {
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  color: #fff;
  padding: 14px 6px;
  font-size: 15px;
}
.btn-result-action.btn-story {
  background: linear-gradient(135deg, #E1306C, #F77737, #FCAF45);
  color: #fff;
}
.story-reward-badge {
  font-size: 11px;
  font-weight: 700;
  background: rgba(255,255,255,0.3);
  padding: 1px 4px;
  border-radius: 6px;
  margin-left: 2px;
}

/* Story reward info banner */
.story-reward-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 8px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(225,48,108,0.12), rgba(252,175,69,0.12));
  border: 1px solid rgba(225,48,108,0.25);
  font-size: 13px;
  color: var(--tg-theme-text-color, #fff);
}
.story-reward-banner-icon { font-size: 18px; }
.story-reward-banner-text { flex: 1; line-height: 1.3; }

/* =============================================
   PROFILE VIEW
   ============================================= */
.profile-content {
  padding: calc(var(--tg-safe-top) + var(--tg-content-top) + 20px) 16px 20px;
}
.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
}
.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #A855F7, #EC4899);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 10px;
}
.profile-name {
  font-size: 20px;
  font-weight: 700;
}
.profile-desc {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

/* Subscription Card */
.subscription-card {
  background: var(--surface);
  border-radius: var(--card-radius);
  padding: 16px;
  margin-bottom: 24px;
}
.sub-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.sub-tier {
  font-weight: 700;
  font-size: 15px;
}
.btn-upgrade {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}
.credit-box { display: flex; flex-direction: column; gap: 6px; }
.credit-text { font-size: 14px; color: var(--text-secondary); }
.credit-bar-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border-subtle);
  overflow: hidden;
}
.credit-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), #7C3AED);
  transition: width .4s ease;
}
.credit-total {
  font-size: 12px;
  color: var(--text-secondary);
  align-self: flex-end;
}

/* Profile sections */
.profile-section { margin-bottom: 24px; }
/* ── Settings page ── */
.settings-content {
  padding: calc(var(--tg-safe-top) + var(--tg-content-top) + 20px) 16px 20px;
}
.settings-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 28px;
}
.settings-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.settings-page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.settings-desc {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}
.settings-card {
  background: var(--surface);
  border-radius: var(--card-radius);
  padding: 16px;
  margin-bottom: 16px;
}
.settings-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.settings-card-icon {
  font-size: 20px;
  line-height: 1;
}
.settings-card-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

/* Language picker (inside settings card) */
.language-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lang-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.lang-option:active {
  background: var(--surface-hover);
}
.lang-option.active {
  background: rgba(168, 85, 247, 0.08);
  border-color: var(--accent);
}
.lang-option .lang-check {
  display: none;
  color: var(--accent);
}
.lang-option.active .lang-check {
  display: block;
}

/* Settings footer */
.settings-footer {
  text-align: center;
  margin-top: 40px;
  padding: 16px 0;
}
.settings-version {
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.profile-photos {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.profile-photos::-webkit-scrollbar { display: none; }
.profile-photo-slot {
  flex: 0 0 100px;
  height: 100px;
}

/* Profile photo cards with remove button (matches reference UI) */
.profile-photo-card {
  flex: 0 0 calc(33.333% - 7px);
  aspect-ratio: 1;
  border-radius: var(--card-radius);
  overflow: hidden;
  position: relative;
  background: var(--surface);
}
.profile-photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.btn-remove-profile-photo {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  color: #fff;
  z-index: 3;
  transition: background .15s;
}
.btn-remove-profile-photo:active {
  background: rgba(0,0,0,.7);
}

.generations-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.gen-card {
  aspect-ratio: 3 / 4;
  border-radius: var(--card-radius);
  overflow: hidden;
  position: relative;
  background: var(--surface);
  cursor: pointer;
  transition: transform .15s;
}
.gen-card:active { transform: scale(.97); }
.gen-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gen-card .card-label {
  position: absolute;
  bottom: 10px;
  left: 10px;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 32px 16px;
}

/* All Generations View */
.all-generations-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 16px 20px;
}

/* =============================================
   SAVED PHOTOS PICKER (Style View)
   ============================================= */
.saved-photos-picker {
  margin-top: 14px;
}
.picker-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.saved-photos-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.saved-photos-row::-webkit-scrollbar { display: none; }

.saved-photo-thumb {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  background: var(--surface);
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s, transform .1s;
}
.saved-photo-thumb:active { transform: scale(.93); }
.saved-photo-thumb.selected {
  border-color: var(--accent);
}
.saved-photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* =============================================
   GENERATION DETAIL OVERLAY
   ============================================= */
.gen-detail-sheet {
  width: 100%;
  max-width: 500px;
  max-height: 92vh;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: slideUp .3s ease;
}
.gen-detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.gen-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.gen-detail-image {
  width: 100%;
  max-width: 380px;
  border-radius: var(--card-radius);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: var(--bg);
  cursor: pointer;
}

/* Tap-to-expand indicator on zoomable images */
.img-expandable {
  position: relative;
  display: inline-block;
}
.img-expand-hint {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.8);
  pointer-events: none;
  opacity: 1;
  transition: opacity .3s;
}
.gen-detail-label {
  margin-top: 12px;
  font-weight: 700;
  font-size: 17px;
}
.gen-detail-date {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}
.gen-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: calc(max(var(--safe-bottom), var(--tg-safe-bottom)) + 16px);
}
.btn-gen-delete {
  flex: 1 1 100%;
  color: #ff4d4f !important;
  border-color: rgba(255,77,79,.25) !important;
}
.btn-gen-delete:active {
  background: rgba(255,77,79,.15) !important;
}

/* =============================================
   PACKAGES OVERLAY
   ============================================= */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.65);
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn .2s ease;
}
.overlay.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.packages-sheet {
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: slideUp .3s ease;
}

.packages-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--overlay-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.packages-body {
  padding: 24px 20px 0;
  overflow-y: auto;
  flex: 1;
}

.packages-title {
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 4px;
}

.packages-sub {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

/* Package Cards */
.packages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 20px;
}

.package-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-radius: var(--card-radius);
  background: var(--bg);
  border: 2px solid var(--border-subtle);
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
  position: relative;
}
.package-card:active { transform: scale(.98); }
.package-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 12px var(--accent-glow);
}
.package-card.featured {
  border-color: var(--border-subtle);
}

.package-badge {
  position: absolute;
  top: -10px;
  left: 16px;
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.3px;
}

.package-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.package-name {
  font-weight: 700;
  font-size: 16px;
}
.package-count {
  font-size: 14px;
  color: var(--text-secondary);
}
.package-desc {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.8;
  margin-top: 2px;
}

.package-price {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  margin-left: 12px;
}
.package-price-amount {
  font-size: 18px;
  font-weight: 800;
}
.package-price-per {
  font-size: 11px;
  color: var(--text-secondary);
}
.package-price-usd {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Purchase button inside packages modal */
.btn-purchase {
  margin: 0 20px 24px;
  padding: 16px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  text-align: center;
  transition: transform .15s;
  box-shadow: 0 4px 20px rgba(59, 130, 246, .4);
  position: relative;
  z-index: 2;
}
.btn-purchase:active { transform: scale(.97); }
.btn-purchase:disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* =============================================
   PHOTO GUIDELINES OVERLAY
   ============================================= */
.guidelines-sheet {
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: slideUp .3s ease;
}

.guidelines-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--overlay-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.guidelines-body {
  padding: 24px 20px 0;
  overflow-y: auto;
  flex: 1;
}

.guidelines-title {
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 16px;
}

.guidelines-photos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.guidelines-photo-card {
  border-radius: var(--card-radius);
  overflow: hidden;
  position: relative;
  aspect-ratio: 3 / 4;
}

.guidelines-photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.guidelines-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 0;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.guidelines-label-good {
  background: linear-gradient(transparent, rgba(34, 197, 94, .85));
}

.guidelines-label-bad {
  background: linear-gradient(transparent, rgba(239, 68, 68, .85));
}

.guidelines-tips {
  background: var(--bg);
  border-radius: var(--card-radius);
  padding: 14px 16px;
  margin-bottom: 8px;
}

.guidelines-tips-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 8px;
}

.guidelines-tips ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guidelines-tips li {
  font-size: 14px;
  color: var(--text-secondary);
  padding-left: 20px;
  position: relative;
}

.guidelines-tips li::before {
  content: "\2022";
  position: absolute;
  left: 4px;
  color: var(--accent);
  font-weight: 700;
}

.guidelines-actions {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  padding-bottom: calc(max(var(--safe-bottom), var(--tg-safe-bottom)) + 16px);
}

.btn-guidelines {
  flex: 1;
  padding: 14px 0;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  transition: transform .15s;
}

.btn-guidelines:active { transform: scale(.97); }

.btn-guidelines-take {
  background: transparent;
  border: 2px solid var(--border-subtle);
  color: var(--text-primary);
}

.btn-guidelines-choose {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px rgba(169, 112, 255, .35);
}

/* =============================================
   BOTTOM TAB BAR
   ============================================= */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: var(--tab-bar-h);
  padding-bottom: max(var(--safe-bottom), var(--tg-safe-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 50;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2px;
  color: var(--text-secondary);
  padding: 6px 20px;
  transition: color .15s;
}
.tab.active { color: var(--text-primary); }
.tab.active svg {
  filter: drop-shadow(0 0 6px var(--accent));
}
.tab svg { transition: color .15s, filter .15s; }

/* =============================================
   UTILITY & ANIMATIONS
   ============================================= */
.catalog-loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--skeleton-mid) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--card-radius);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: calc(var(--tab-bar-h) + max(var(--safe-bottom), var(--tg-safe-bottom)) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 12px;
  border-left: 3px solid var(--accent);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  opacity: 0;
  transition: opacity .3s, transform .3s;
  z-index: 200;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Pause animations when app is deactivated (backgrounded) */
body.tg-inactive *,
body.tg-inactive *::before,
body.tg-inactive *::after {
  animation-play-state: paused !important;
}

/* View transitions */
.view { animation: viewFadeIn .25s ease; }
@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =============================================
   TELEGRAM-ONLY ACCESS GATE
   ============================================= */
.tg-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #fff;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  z-index: 9999;
}
.tg-gate-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 32px 24px;
  max-width: 380px;
}
.tg-gate-icon {
  margin-bottom: 20px;
  opacity: 0.9;
}
.tg-gate-title {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #A855F7, #7C3AED);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tg-gate-text {
  font-size: 16px;
  color: #8e8e93;
  line-height: 1.5;
  margin-bottom: 28px;
}
.tg-gate-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 32px;
  border-radius: 28px;
  background: linear-gradient(135deg, #0088cc, #0077b5);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 4px 20px rgba(0, 136, 204, .35);
}
.tg-gate-btn:active { transform: scale(.96); }
.tg-gate-hint {
  margin-top: 20px;
  font-size: 13px;
  color: #555;
}

/* =============================================
   FULLSCREEN IMAGE VIEWER
   ============================================= */
.fs-viewer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  flex-direction: column;
}
.fs-viewer.active { display: flex; }

.fs-toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 210;
  display: flex;
  justify-content: space-between;
  padding: calc(var(--tg-safe-top, 0px) + var(--tg-content-top, 0px) + 12px) 14px 16px;
  background: linear-gradient(to bottom, rgba(0,0,0,.7) 60%, transparent);
  pointer-events: none;
}
.fs-btn {
  pointer-events: all;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.fs-btn:active { background: rgba(255,255,255,.45); }

.fs-image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.fs-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: 0 0;
  will-change: transform;
  transition: none;
}
.fs-image.animating {
  transition: transform .25s ease;
}

.fs-hint {
  position: absolute;
  bottom: calc(var(--tg-safe-bottom, 0px) + 20px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 20px;
  background: rgba(255,255,255,.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255,255,255,.7);
  font-size: 12px;
  pointer-events: none;
  opacity: 1;
  transition: opacity .5s;
}
.fs-hint.hidden { opacity: 0; }
