/* ============================================================
   Lifextend — Design System Partagé
   Thème : Luxury Health / Dark Glassmorphism
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Inter:wght@300;400;500;600&display=swap');

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
  /* Background */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F8FAFC;
  --bg-card: rgba(0, 0, 0, 0.03);
  --bg-glass: rgba(255, 255, 255, 0.6);
  --bg-glass-hover: rgba(255, 255, 255, 0.9);

  /* Text */
  --text-primary: #0F172A;
  --text-secondary: rgba(15, 23, 42, 0.65);
  --text-muted: rgba(15, 23, 42, 0.4);

  /* Accent — Default (Neutral / Phase 1) */
  --accent: #6D28D9;
  --accent-rgb: 109, 40, 217;
  --accent-glow: rgba(109, 40, 217, 0.2);

  /* Theme Colors (Phase 2) */
  --theme-environment: #22C55E;
  --theme-environment-rgb: 34, 197, 94;
  --theme-food: #F97316;
  --theme-food-rgb: 249, 115, 22;
  --theme-routine: #3B82F6;
  --theme-routine-rgb: 59, 130, 246;
  --theme-emotion: #EC4899;
  --theme-emotion-rgb: 236, 72, 153;

  /* Category Colors (Cards) */
  --cat-cardio: #FF4757;
  --cat-mental: #A855F7;
  --cat-nutrition: #22C55E;
  --cat-fitness: #F97316;
  --cat-sleep: #3B82F6;
  --cat-prevention: #06B6D4;

  /* Glass */
  --glass-border: rgba(0, 0, 0, 0.05);
  --glass-blur: 24px;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2.5rem;
  --space-2xl: 4rem;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 9999px;

  /* Transitions */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-elastic: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --duration-fast: 0.2s;
  --duration-normal: 0.4s;
  --duration-slow: 0.7s;

  /* Z-Index */
  --z-bg: 0;
  --z-content: 10;
  --z-overlay: 50;
  --z-modal: 100;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  line-height: 1.15;
}

a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: 'Inter', sans-serif; }

/* --- Animated Background --- */
.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: var(--z-bg);
  background:
    radial-gradient(ellipse 80% 50% at 20% 40%, rgba(var(--accent-rgb), 0.08) 0%, transparent 70%),
    radial-gradient(ellipse 60% 60% at 80% 70%, rgba(99, 102, 241, 0.06) 0%, transparent 70%),
    var(--bg-primary);
  animation: bgShift 20s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes bgShift {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(25deg); }
}

/* Noise overlay for texture */
.bg-gradient::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  opacity: 0.15;
  pointer-events: none;
}

/* --- Main Container --- */
.app-container {
  position: relative;
  z-index: var(--z-content);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-xl);
}

/* --- Glass Panel --- */
.glass-panel {
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  position: relative;
  overflow: hidden;
}

.glass-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
}

/* --- Interactive Card (Base) --- */
.card {
  position: relative;
  width: 200px;
  height: 280px;
  perspective: 1000px;
  cursor: pointer;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--duration-slow) var(--ease-out-expo);
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  text-align: center;
}

/* Card Front */
.card-front {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.03) inset,
    0 8px 32px rgba(0,0,0,0.3);
}

.card-front::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: linear-gradient(135deg, rgba(var(--accent-rgb), 0.4), transparent 50%, rgba(var(--accent-rgb), 0.1));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* Card Back (Holographic) */
.card-back {
  transform: rotateY(180deg);
  background:
    linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  border: 1px solid rgba(255,255,255,0.08);
}

.card-back .holo-effect {
  position: absolute;
  inset: 0;
  background:
    conic-gradient(from var(--holo-angle, 0deg) at 50% 50%,
      rgba(255,0,128,0.15),
      rgba(0,128,255,0.15),
      rgba(0,255,128,0.15),
      rgba(255,255,0,0.15),
      rgba(255,0,128,0.15));
  mix-blend-mode: overlay;
  opacity: 0.6;
  animation: holoRotate 4s linear infinite;
  pointer-events: none;
}

@keyframes holoRotate {
  to { --holo-angle: 360deg; }
}

@property --holo-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

.card-back .pattern {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 25% 25%, rgba(255,255,255,0.04) 1px, transparent 1px),
    radial-gradient(circle at 75% 75%, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 20px 20px;
  pointer-events: none;
}

/* Card Icon */
.card-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-md);
}

.card-icon svg {
  width: 100%;
  height: 100%;
}

/* Card Title & Text */
.card-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.card-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* --- Card Glow Effect --- */
.card-glow {
  position: absolute;
  inset: -2px;
  border-radius: var(--radius-lg);
  background: radial-gradient(
    circle at var(--glow-x, 50%) var(--glow-y, 50%),
    rgba(var(--accent-rgb), 0.3) 0%,
    transparent 70%
  );
  opacity: 0;
  transition: opacity var(--duration-normal) ease;
  pointer-events: none;
  z-index: -1;
}

.card:hover .card-glow {
  opacity: 1;
  animation: glowPulse 2s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* --- Levitation Animation --- */
.levitate {
  animation: levitate 4s ease-in-out infinite;
  animation-delay: 2s;
  /* 2-second pause before cards start floating so users can read them */
}

@keyframes levitate {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  25% { transform: translateY(-8px) rotate(0.5deg); }
  75% { transform: translateY(6px) rotate(-0.5deg); }
}

/* Staggered delays for wave effect (2s base + stagger) */
.levitate-delay-1 { animation-delay: 2s; }
.levitate-delay-2 { animation-delay: 2.5s; }
.levitate-delay-3 { animation-delay: 3s; }
.levitate-delay-4 { animation-delay: 3.5s; }
.levitate-delay-5 { animation-delay: 4s; }
.levitate-delay-6 { animation-delay: 4.5s; }

/* --- Selection Card (Questionnaire) --- */
.select-card {
  position: relative;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg) var(--space-xl);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-out-expo);
  user-select: none;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.select-card:hover {
  background: var(--bg-glass-hover);
  transform: translateY(-4px);
  border-color: rgba(var(--accent-rgb), 0.3);
  box-shadow: 0 8px 30px rgba(var(--accent-rgb), 0.1);
}

.select-card.selected {
  border-color: rgba(var(--accent-rgb), 0.85);
  background: rgba(var(--accent-rgb), 0.18);
  box-shadow:
    0 0 30px rgba(var(--accent-rgb), 0.35),
    0 0 60px rgba(var(--accent-rgb), 0.15),
    0 0 0 2px rgba(var(--accent-rgb), 0.4) inset;
  transform: translateY(-4px) scale(1.03);
}

.select-card.selected::before {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.75rem;
  color: rgb(var(--accent-rgb));
  font-weight: 700;
}

.select-card .card-emoji {
  font-size: 2rem;
  display: block;
  margin-bottom: var(--space-sm);
}

.select-card .card-img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  margin-bottom: var(--space-sm);
  display: block;
  margin-left: auto;
  margin-right: auto;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}

.select-card .card-label {
  font-family: 'Outfit', sans-serif;
  font-weight: 500;
  font-size: 0.95rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font-family: 'Outfit', sans-serif;
  font-weight: 500;
  font-size: 1rem;
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-full);
  transition: all var(--duration-normal) var(--ease-out-expo);
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: linear-gradient(135deg, rgb(var(--accent-rgb)), rgba(var(--accent-rgb), 0.7));
  color: #fff;
  box-shadow: 0 4px 20px rgba(var(--accent-rgb), 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(var(--accent-rgb), 0.4);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}

.btn-ghost:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
  border-color: rgba(var(--accent-rgb), 0.3);
}

.btn:disabled {
  background: rgba(0, 0, 0, 0.15);
  color: rgba(0, 0, 0, 0.4);
  box-shadow: none;
  cursor: not-allowed;
  transform: none !important;
}

/* --- Progress Bar --- */
.progress-bar {
  width: 100%;
  max-width: 400px;
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: var(--space-md) auto;
}

.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, rgb(var(--accent-rgb)), rgba(var(--accent-rgb), 0.5));
  border-radius: var(--radius-full);
  transition: width 0.6s var(--ease-out-expo);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.4);
}

/* --- Input Field --- */
.input-field {
  width: 100%;
  max-width: 380px;
  padding: 14px 20px;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  color: var(--text-primary);
  background: rgba(255,255,255,0.04);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--duration-normal) ease;
}

.input-field::placeholder { color: var(--text-muted); }

.input-field:focus {
  border-color: rgba(var(--accent-rgb), 0.5);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
  background: rgba(255,255,255,0.06);
}

/* --- Section Title --- */
.section-title {
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 700;
  margin-bottom: var(--space-sm);
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.section-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 500px;
  margin: 0 auto var(--space-xl);
  line-height: 1.6;
}

/* --- Card Grid --- */
.card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-lg);
  justify-content: center;
  align-items: stretch;
  margin: var(--space-lg) auto;
  max-width: 900px;
}
.card-grid .select-card {
  flex: 1 1 200px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* --- Step Indicator (top bar) --- */
.step-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-overlay);
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
}

.step-indicator .logo {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  background: linear-gradient(135deg, rgb(var(--accent-rgb)), #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.step-indicator .step-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* --- Screen Transitions --- */
.screen-enter {
  animation: screenEnter 0.8s var(--ease-out-expo) forwards;
}

@keyframes screenEnter {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.97);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0px);
  }
}

.screen-exit {
  animation: screenExit 0.5s var(--ease-out-expo) forwards;
}

@keyframes screenExit {
  to {
    opacity: 0;
    transform: translateY(-20px) scale(0.97);
    filter: blur(4px);
  }
}

/* --- Particle Canvas --- */
#particles-canvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* --- Confetti burst on selection --- */
@keyframes confettiBurst {
  0% { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translateY(-100px) rotate(720deg) scale(0); opacity: 0; }
}

.confetti-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
  animation: confettiBurst 0.8s var(--ease-out-expo) forwards;
}

/* --- Lifextend Specific Effects --- */
.no-levitate {
  animation: none !important;
}

@keyframes peurStep {
  0% { transform: translateX(0); }
  15% { transform: translateX(-15px) rotate(-3deg); }
  30% { transform: translateX(10px) rotate(2deg); }
  45% { transform: translateX(-5px) rotate(-1deg); }
  100% { transform: translateX(0); }
}
.effect-peur {
  animation: peurStep 2s cubic-bezier(0.25, 1, 0.5, 1) forwards !important;
}

.effect-fuite {
  transition: transform 3s cubic-bezier(0.68, -0.55, 0.265, 1.55) !important;
}

.frayeur-target {
  z-index: 10 !important;
}
.frayeur-scared {
  z-index: 1 !important;
}

.flip-anim {
  transition: transform 1s ease-in-out !important;
}

/* --- Golden Mailbox Animation --- */
@keyframes mailboxAppear {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes cardFlyToMailbox {
  0% { opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(var(--fly-x), var(--fly-y)) scale(0.1) rotate(360deg); opacity: 0; }
}

/* --- Theme Background Transitions --- */
body.theme-neutral {
  --accent-rgb: 167, 139, 250;
  --accent: #A78BFA;
}

body.theme-environment {
  --accent-rgb: 34, 197, 94;
  --accent: #22C55E;
}

body.theme-violet {
  --accent-rgb: 139, 92, 246;
  --accent: #8B5CF6;
}

body.theme-food {
  --accent-rgb: 249, 115, 22;
  --accent: #F97316;
}

body.theme-routine {
  --accent-rgb: 59, 130, 246;
  --accent: #3B82F6;
}

body.theme-emotion {
  --accent-rgb: 236, 72, 153;
  --accent: #EC4899;
}

body.theme-payment {
  --accent-rgb: 250, 204, 21;
  --accent: #FACC15;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .app-container { padding: var(--space-lg); }
  .card { width: 160px; height: 220px; }
  .select-card { min-width: 110px; padding: var(--space-md); }
  .section-title { font-size: 1.4rem; }
  #welcome-logo { width: 200px; height: 200px; }
}

@media (max-width: 480px) {
  .card-grid { gap: var(--space-md); }
  .card { width: 140px; height: 200px; }
  .btn { padding: 12px 24px; font-size: 0.9rem; }
  #welcome-logo { width: 160px; height: 160px; }
}
