/* ============================================================
   🌸 Foto Kita Blur — Cute Kawaii Stylesheet
   ============================================================ */

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

/* --- CSS Custom Properties --- */
:root {
  /* Pastel Palette */
  --pink-100: #fff0f5;
  --pink-200: #ffd6e7;
  --pink-300: #ffb3d0;
  --pink-400: #ff8cb8;
  --pink-500: #ff69a0;
  --pink-600: #e84d8a;
  --lavender-100: #f3e8ff;
  --lavender-200: #dcc8f5;
  --lavender-300: #c4a7eb;
  --lavender-400: #a87cdb;
  --cream: #fff8f0;
  --gold-100: #fff9e6;
  --gold-200: #ffe680;
  --gold-300: #ffd633;
  --gold-400: #ffcc00;
  --mint: #e0faf0;
  --peach: #ffe5d9;

  /* Semantic Colors */
  --bg-primary: #fdf2f8;
  --bg-secondary: rgba(255, 255, 255, 0.6);
  --text-primary: #5c2d4a;
  --text-secondary: #8b6078;
  --text-muted: #b8929e;
  --border-glow: rgba(255, 105, 160, 0.4);

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.25);
  --glass-border: rgba(255, 255, 255, 0.4);
  --glass-shadow: 0 8px 32px rgba(232, 77, 138, 0.15);

  /* Sizing */
  --border-radius-sm: 12px;
  --border-radius-md: 20px;
  --border-radius-lg: 28px;
  --border-radius-xl: 36px;

  /* Animation */
  --transition-smooth: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

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

/* --- Animated Background --- */
.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: linear-gradient(
    135deg,
    #fdf2f8 0%,
    #fce7f3 20%,
    #f3e8ff 40%,
    #fdf2f8 60%,
    #fff0f5 80%,
    #fce7f3 100%
  );
  background-size: 400% 400%;
  animation: gradientShift 12s ease infinite;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* --- Floating Decorations --- */
.floating-decorations {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

.deco {
  position: absolute;
  opacity: 0.25;
  animation: floatUp linear infinite;
  font-size: 1.5rem;
  filter: drop-shadow(0 0 6px rgba(255, 105, 160, 0.3));
}

.deco:nth-child(1)  { left: 5%;  font-size: 1.2rem; animation-duration: 14s; animation-delay: 0s; }
.deco:nth-child(2)  { left: 12%; font-size: 1.8rem; animation-duration: 18s; animation-delay: 2s; }
.deco:nth-child(3)  { left: 22%; font-size: 1rem;   animation-duration: 12s; animation-delay: 4s; }
.deco:nth-child(4)  { left: 35%; font-size: 2rem;   animation-duration: 16s; animation-delay: 1s; }
.deco:nth-child(5)  { left: 45%; font-size: 1.4rem; animation-duration: 20s; animation-delay: 3s; }
.deco:nth-child(6)  { left: 55%; font-size: 1.6rem; animation-duration: 15s; animation-delay: 5s; }
.deco:nth-child(7)  { left: 65%; font-size: 1.1rem; animation-duration: 17s; animation-delay: 2s; }
.deco:nth-child(8)  { left: 75%; font-size: 1.9rem; animation-duration: 13s; animation-delay: 4s; }
.deco:nth-child(9)  { left: 85%; font-size: 1.3rem; animation-duration: 19s; animation-delay: 1s; }
.deco:nth-child(10) { left: 93%; font-size: 1.7rem; animation-duration: 14s; animation-delay: 3s; }

@keyframes floatUp {
  0% {
    transform: translateY(110vh) rotate(0deg) scale(0.8);
    opacity: 0;
  }
  10% {
    opacity: 0.3;
  }
  90% {
    opacity: 0.2;
  }
  100% {
    transform: translateY(-10vh) rotate(360deg) scale(1.2);
    opacity: 0;
  }
}

/* --- Main Layout --- */
.app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  gap: 1rem;
}

/* --- Title Header --- */
.app-title {
  text-align: center;
  animation: fadeSlideDown 0.8s ease-out;
}

.app-title h1 {
  font-family: 'Comfortaa', 'Quicksand', sans-serif;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--pink-500), var(--lavender-400), var(--pink-400));
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: textGradient 4s ease infinite;
  letter-spacing: -0.5px;
}

.app-title .subtitle {
  font-size: clamp(0.75rem, 2vw, 0.95rem);
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-weight: 500;
}

@keyframes textGradient {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Camera Frame Wrapper --- */
.camera-wrapper {
  position: relative;
  width: 100%;
  max-width: 720px;
  animation: fadeSlideUp 0.8s ease-out 0.2s both;
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Animated gradient border */
.camera-frame {
  position: relative;
  border-radius: var(--border-radius-xl);
  padding: 5px;
  background: linear-gradient(
    var(--gradient-angle, 0deg),
    var(--pink-400),
    var(--lavender-300),
    var(--pink-300),
    var(--gold-200),
    var(--pink-400)
  );
  background-size: 300% 300%;
  animation: borderGradient 4s ease infinite, borderRotate 8s linear infinite;
  box-shadow:
    0 0 20px rgba(255, 105, 160, 0.2),
    0 0 60px rgba(255, 105, 160, 0.1),
    0 10px 40px rgba(168, 124, 219, 0.15);
  transition: box-shadow 0.6s ease;
}

.camera-frame.peace-active {
  box-shadow:
    0 0 30px rgba(255, 204, 0, 0.4),
    0 0 80px rgba(255, 204, 0, 0.2),
    0 0 120px rgba(255, 105, 160, 0.15),
    0 10px 40px rgba(168, 124, 219, 0.2);
  animation: borderGradient 2s ease infinite, borderRotate 4s linear infinite, pulseGlow 1.5s ease infinite;
}

@keyframes borderGradient {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes borderRotate {
  from { --gradient-angle: 0deg; }
  to { --gradient-angle: 360deg; }
}

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

@keyframes pulseGlow {
  0%, 100% { 
    box-shadow:
      0 0 30px rgba(255, 204, 0, 0.4),
      0 0 80px rgba(255, 204, 0, 0.2),
      0 0 120px rgba(255, 105, 160, 0.15);
  }
  50% { 
    box-shadow:
      0 0 40px rgba(255, 204, 0, 0.5),
      0 0 100px rgba(255, 204, 0, 0.3),
      0 0 150px rgba(255, 105, 160, 0.2);
  }
}

/* Inner camera container */
.camera-inner {
  position: relative;
  border-radius: calc(var(--border-radius-xl) - 4px);
  overflow: hidden;
  background: #1a0a12;
  aspect-ratio: 16 / 9;
}

/* Corner Decorations */
.corner-deco {
  position: absolute;
  width: 50px;
  height: 50px;
  z-index: 10;
  pointer-events: none;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 2px 8px rgba(255, 105, 160, 0.5));
  transition: var(--transition-smooth);
}

.corner-deco.top-left     { top: -8px; left: -8px; }
.corner-deco.top-right    { top: -8px; right: -8px; }
.corner-deco.bottom-left  { bottom: -8px; left: -8px; }
.corner-deco.bottom-right { bottom: -8px; right: -8px; }

.camera-frame.peace-active .corner-deco {
  animation: bounceScale 0.6s ease;
  filter: drop-shadow(0 2px 12px rgba(255, 204, 0, 0.6));
}

@keyframes bounceScale {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); }
  100% { transform: scale(1); }
}

/* Video & Canvas */
.camera-inner video,
.camera-inner canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-inner video {
  opacity: 0;
  pointer-events: none;
}

.camera-inner canvas {
  z-index: 1;
}

/* --- Welcome Overlay (before camera starts) --- */
.welcome-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(253, 242, 248, 0.95), rgba(243, 232, 255, 0.95));
  border-radius: calc(var(--border-radius-xl) - 4px);
  gap: 1rem;
  transition: opacity 0.6s ease, visibility 0.6s ease;
  cursor: pointer;
}

.welcome-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.welcome-icon {
  font-size: 3.5rem;
  animation: pulse 2s ease infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.welcome-text {
  font-family: 'Comfortaa', sans-serif;
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
}

.welcome-hint {
  font-size: clamp(0.75rem, 2vw, 0.85rem);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  animation: fadeInUp 1s ease 0.5s both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Ripple effect on click */
.welcome-overlay::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 105, 160, 0.2);
  transition: width 0.6s ease, height 0.6s ease;
}

.welcome-overlay.ripple::after {
  width: 300%;
  height: 300%;
}

/* --- Status Bubble --- */
.status-bubble {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  z-index: 15;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 50px;
  padding: 0.45rem 1.1rem;
  font-size: clamp(0.7rem, 1.8vw, 0.82rem);
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(232, 77, 138, 0.12);
}

.status-bubble.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.status-bubble .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.status-bubble.peace .status-dot {
  background: var(--gold-400);
  box-shadow: 0 0 12px rgba(255, 204, 0, 0.6);
  animation: dotPulse 1s ease infinite;
}

@keyframes dotPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.4); }
}

/* --- FPS Badge --- */
.fps-badge {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 15;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 0.2rem 0.65rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  letter-spacing: 0.5px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.fps-badge.visible {
  opacity: 1;
}

/* --- Loading Spinner --- */
.loading-spinner {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(26, 10, 18, 0.85);
  border-radius: calc(var(--border-radius-xl) - 4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.loading-spinner.visible {
  opacity: 1;
  visibility: visible;
}

.spinner-ring {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 179, 208, 0.2);
  border-top-color: var(--pink-400);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  font-size: 0.85rem;
  color: var(--pink-200);
  font-weight: 500;
}

/* --- Error State --- */
.error-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background: linear-gradient(135deg, rgba(253, 242, 248, 0.97), rgba(243, 232, 255, 0.97));
  border-radius: calc(var(--border-radius-xl) - 4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
  text-align: center;
  padding: 2rem;
}

.error-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.error-icon {
  font-size: 2.5rem;
}

.error-text {
  font-size: clamp(0.8rem, 2vw, 0.95rem);
  color: var(--text-secondary);
  font-weight: 500;
  max-width: 280px;
  line-height: 1.5;
}

/* --- Sparkle Burst (when peace detected) --- */
.sparkle-container {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
  overflow: hidden;
  border-radius: calc(var(--border-radius-xl) - 4px);
}

.sparkle {
  position: absolute;
  font-size: 1rem;
  opacity: 0;
  animation: sparkleBurst 1.2s ease forwards;
}

@keyframes sparkleBurst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(0.5);
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx), var(--ty)) scale(1.2) rotate(180deg);
  }
}

/* --- Instruction Hint (bottom) --- */
.instruction-hint {
  text-align: center;
  animation: fadeSlideUp 0.8s ease-out 0.4s both;
}

.instruction-hint p {
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.instruction-hint .peace-emoji {
  font-size: 1.2em;
  animation: wave 2s ease infinite;
}

@keyframes wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(15deg); }
  75% { transform: rotate(-15deg); }
}

/* --- Permission Denied / No Camera --- */
.permission-toast {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 100;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--pink-200);
  border-radius: var(--border-radius-md);
  padding: 0.8rem 1.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(232, 77, 138, 0.15);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
  max-width: 90vw;
}

.permission-toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* --- Flash Overlay --- */
.flash-overlay {
  position: absolute;
  inset: 0;
  background-color: white;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease-out;
}

.flash-overlay.active {
  opacity: 1;
  transition: none;
}

/* --- Polaroid Result --- */
.polaroid-result {
  position: absolute;
  bottom: -150%;
  left: 50%;
  transform: translateX(-50%) rotate(5deg);
  background: white;
  padding: 10px 10px 40px 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  z-index: 30;
  width: 60%;
  max-width: 300px;
  border-radius: 4px;
  transition: bottom 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.6s ease;
  pointer-events: none;
}

.polaroid-result.visible {
  bottom: 20px;
  transform: translateX(-50%) rotate(-3deg);
}

.polaroid-result img {
  width: 100%;
  height: auto;
  border: 1px solid #eee;
  display: block;
}

.polaroid-caption {
  position: absolute;
  bottom: 12px;
  width: 100%;
  text-align: center;
  left: 0;
  font-family: 'Comfortaa', sans-serif;
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 700;
}

/* --- Responsive --- */

/* Large tablets & small desktops */
@media (max-width: 900px) {
  .camera-wrapper {
    max-width: 90vw;
  }
}

/* Tablets */
@media (max-width: 768px) {
  .app-container {
    padding: 1rem;
    gap: 0.8rem;
  }

  .camera-frame {
    border-radius: var(--border-radius-lg);
    padding: 4px;
  }

  .camera-inner {
    border-radius: calc(var(--border-radius-lg) - 3px);
    aspect-ratio: 3 / 4;
  }

  .corner-deco {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }
}

/* Mobile phones */
@media (max-width: 480px) {
  .app-container {
    padding: 0.75rem;
    gap: 0.6rem;
    justify-content: flex-start;
    padding-top: 1.5rem;
  }

  .camera-wrapper {
    max-width: 100%;
  }

  .camera-frame {
    border-radius: var(--border-radius-md);
    padding: 3px;
  }

  .camera-inner {
    border-radius: calc(var(--border-radius-md) - 2px);
    aspect-ratio: 3 / 4;
  }

  .corner-deco {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .corner-deco.top-left     { top: -5px; left: -5px; }
  .corner-deco.top-right    { top: -5px; right: -5px; }
  .corner-deco.bottom-left  { bottom: -5px; left: -5px; }
  .corner-deco.bottom-right { bottom: -5px; right: -5px; }

  .status-bubble {
    top: 8px;
    padding: 0.35rem 0.8rem;
  }

  .fps-badge {
    bottom: 8px;
    right: 8px;
    font-size: 0.6rem;
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .app-container {
    padding: 0.5rem;
    gap: 0.4rem;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
  }

  .app-title {
    width: 100%;
  }

  .app-title h1 {
    font-size: 1.1rem;
  }

  .app-title .subtitle {
    display: none;
  }

  .camera-wrapper {
    max-width: 80vh;
    max-height: 75vh;
  }

  .instruction-hint {
    width: 100%;
  }

  .instruction-hint p {
    font-size: 0.7rem;
  }
}

/* Very small screens */
@media (max-width: 360px) {
  .app-title h1 {
    font-size: 1.2rem;
  }

  .welcome-icon {
    font-size: 2.5rem;
  }

  .welcome-text {
    font-size: 0.9rem;
  }
}
