/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none; /* prevent text selection iOS */
  user-select: none;
}

:root { --safe-bottom: env(safe-area-inset-bottom, 0px); }

html, body, #app, video, canvas, button, .word-text, .preview-label, #preview-container, #bottomBar {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

img { -webkit-user-drag: none; }

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #000;
  overflow: hidden;
  position: relative;
  width: 100vw;
  height: 100vh;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Top gradient overlay (violeta a transparente) */
.top-gradient-overlay {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 33vh;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(to bottom,
    rgba(62,60,255,0.78) 0%,
    rgba(62,60,255,0.55) 18%,
    rgba(62,60,255,0.28) 48%,
    rgba(62,60,255,0.10) 70%,
    rgba(62,60,255,0.0) 100%);
  backdrop-filter: blur(0.5px);
  -webkit-backdrop-filter: blur(0.5px);
}

/* Bottom bar container to pin record button to the bottom */
#bottomBar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 150px; /* nudged a bit higher again */
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px 20px 24px; /* small bottom padding */
  z-index: 20; /* above footer and canvas */
  pointer-events: auto;
}

/* Video and canvas */
#webcam {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  transform: scaleX(-1); /* Mirror video horizontally for natural selfie view */
}

#overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* Controls - stick button at the bottom */
.controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 20px 30px; /* Minimal top padding so it sits near the bottom */
  z-index: 10;
}

.controls-container { display:flex; justify-content:center; align-items:center; }

/* Nueva barra de filtros */
/* Barra filtros animada (posición absoluta) */
#filters-bar { position:relative; width:300px; height:90px; }
.filter-wrapper { position:absolute; top:50%; transform:translate(-50%,-50%) scale(.55); width:70px; height:70px; display:flex; align-items:center; justify-content:center; transition:left .38s cubic-bezier(.4,.15,.25,1), transform .38s ease, opacity .3s ease; opacity:.78; }
.filter-wrapper[data-pos='left'] { left:20%; }
.filter-wrapper[data-pos='center'] { left:50%; transform:translate(-50%,-50%) scale(1); opacity:1; }
.filter-wrapper[data-pos='right'] { left:80%; }
/* Desplazar un poco abajo los laterales para separarlos visualmente del central */
.filter-wrapper[data-pos='left'],
.filter-wrapper[data-pos='right'] { top:56%; }
.filter-btn { width:100%; height:100%; border-radius:50%; border:4px solid rgba(255,255,255,0.85); background:rgba(255,255,255,0.12); color:#fff; font-size:32px; display:flex; align-items:center; justify-content:center; cursor:pointer; backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px); transition:background .25s ease, border-color .25s ease, box-shadow .3s ease; position:relative; font-family:'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-weight:800; letter-spacing:.5px; }
.filter-btn .btn-inner.text { line-height:1.0; font-size:14px; text-transform:uppercase; display:inline-block; text-align:center; }
.btn-alterego .btn-inner { display:none; }
.btn-dots .btn-inner { font-size:38px; line-height:1; }
.btn-none .btn-inner { font-size:32px; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
/* Botón Alter Ego basado en export Figma */
.btn-alterego { background:transparent center/contain no-repeat url('/kaseya/assets/icons/Alter Ego Button.svg'); border:none; box-shadow:none; }
.filter-wrapper.active .btn-alterego { background:transparent center/contain no-repeat url('/kaseya/assets/icons/Alter Ego Button.svg'); box-shadow:0 0 18px 0 rgba(170,59,255,0.55); }
.btn-alterego:focus-visible { outline:2px solid #7945ff; outline-offset:4px; }
.btn-dots { background:rgba(255,255,255,0.10); border-color:rgba(255,255,255,0.85); color:transparent; position:relative; overflow:hidden; }
/* Mini círculos internos estilo filtro (radial-gradients) */
.btn-dots::before { content:""; position:absolute; inset:8px; border-radius:50%; background:
  radial-gradient(circle at 25% 30%, #00FFFF 0 6px, transparent 7px),
  radial-gradient(circle at 68% 28%, #C77DFF 0 5px, transparent 6px),
  radial-gradient(circle at 45% 62%, #7209B7 0 8px, transparent 9px),
  radial-gradient(circle at 72% 68%, #36E5FF 0 5px, transparent 6px),
  radial-gradient(circle at 30% 74%, #8A2BE2 0 6px, transparent 7px),
  radial-gradient(circle at 58% 52%, #A45CFF 0 4px, transparent 5px);
  opacity:0.9; filter:drop-shadow(0 0 4px rgba(0,0,0,0.4)); pointer-events:none; }
/* Estado activo modo spheres: vidrio + halo morado */
.filter-wrapper.active[data-mode="spheres"] .btn-dots { background:rgba(255,255,255,0.18); border-color:#AA3BFF; box-shadow:0 0 22px -2px rgba(170,59,255,0.55),0 0 0 6px rgba(170,59,255,0.25); }
.filter-wrapper.active[data-mode="spheres"] .btn-dots::before { opacity:1; filter:drop-shadow(0 0 6px rgba(170,59,255,0.55)); }
.btn-none { background:rgba(255,255,255,0.10); color:#ffffff; }
.filter-wrapper.active .btn-none { background:rgba(255,255,255,0.18); }
.filter-btn:hover { background:rgba(255,255,255,0.28); }
/* Estado activo general (fallback) si no hay estilos específicos */
.filter-wrapper.active .filter-btn { background:#ff4757; border-color:#ff4757; box-shadow:0 0 22px -2px rgba(255,71,87,0.65),0 0 0 6px rgba(255,71,87,0.25); }
/* Excepción: modo none (X) no debe ponerse rojo */
.filter-wrapper.active[data-mode="none"] .filter-btn { background:rgba(255,255,255,0.12); border-color:rgba(255,255,255,0.85); box-shadow:none; }
.filter-wrapper.active[data-mode="draw"] .filter-btn { background:transparent; border-color:transparent; box-shadow:none; }
#filters-bar .recorder-container { position:absolute; inset:0; pointer-events:auto; display:flex; align-items:center; justify-content:center; }
#filters-bar .recorder-container .progress-container { pointer-events:none; }
.filter-wrapper.active { z-index:10; }
.filter-wrapper:not(.active) { z-index:1; }

/* Mobile tweaks */
@media (max-width:768px){
  #filters-bar { width:260px; height:84px; }
  .filter-wrapper { width:62px; height:62px; }
  .filter-btn { font-size:28px; }
  .filter-wrapper[data-pos='left'] { left:23%; }
  .filter-wrapper[data-pos='right'] { left:77%; }
  .filter-wrapper[data-pos='left'],
  .filter-wrapper[data-pos='right'] { top:57%; }
}

@media (min-width:1024px){
  #filters-bar { width:340px; }
  .filter-wrapper { width:76px; height:76px; }
  .filter-btn { font-size:34px; }
  .filter-wrapper[data-pos='left'] { left:32%; }
  .filter-wrapper[data-pos='right'] { left:68%; }
  .filter-wrapper[data-pos='left'],
  .filter-wrapper[data-pos='right'] { top:55%; }
}

/* Particles toggle button */
#particles-toggle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.7);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 3;
}

#particles-toggle:hover {
  background: rgba(255,255,255,0.2);
  border-color: #fff;
  transform: scale(1.1);
}

#particles-toggle.active {
  background: rgba(255,215,0,0.8);
  border-color: #ffd700;
  box-shadow: 0 0 20px rgba(255,215,0,0.5);
}

.control-btn {
  background: rgba(255,255,255,0.9);
  border: none;
  border-radius: 50px;
  padding: 15px 20px;
  color: #333;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 80px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.control-btn:hover {
  background: rgba(255,255,255,1);
  transform: scale(1.05);
}

.control-btn:active {
  transform: scale(0.95);
  background: rgba(255,255,255,0.8);
}

.control-btn span {
  font-size: 1.5rem;
}

.control-btn div {
  font-size: 0.8rem;
}

/* Recorder button */
.recorder-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* track recorder size so press-indicator can align to its edge */
  --rec-size: 70px; /* default; mirrors #recorder-button */
}

.progress-container {
  position: absolute;
  width: 80px;
  height: 80px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.progress-track, .progress-bar, .loading-circle {
  fill: none;
  stroke-width: 2;
}

.progress-track {
  stroke: rgba(255,255,255,0.3);
}

.progress-bar {
  stroke: #AA3BFF;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 18px 18px;
  stroke-dasharray: 100.531;
  stroke-dashoffset: 100.531;
  transition: stroke-dashoffset 0.1s linear;
}

.loading-circle {
  stroke: rgba(255,255,255,0.6);
  stroke-dasharray: 4 4;
  transform: rotate(-90deg);
  transform-origin: 18px 18px;
  animation: spin 1s linear infinite;
  opacity: 0;
}

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

.recorder-container.loading .loading-circle {
  opacity: 1;
}

 #recorder-button {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.1);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  z-index: 3;
  animation: gentle-pulse 2.5s ease-in-out infinite;
}

#recorder-button:hover {
  background: rgba(255,255,255,0.2);
  border-color: #fff;
  animation: none; /* Stop pulse on hover */
}

.recorder-container.active #recorder-button {
  background: rgba(170,59,255,0.25);
  border-color: #AA3BFF;
  transform: scale(0.9);
  box-shadow:0 0 18px -2px rgba(170,59,255,0.55),0 0 0 6px rgba(170,59,255,0.25);
}

.recorder-container.recording #recorder-button {
  background: #AA3BFF;
  border-color: #AA3BFF;
  animation: pulse 1s infinite;
  box-shadow:0 0 25px -2px rgba(170,59,255,0.75),0 0 0 6px rgba(170,59,255,0.35);
}

/* Press indicator image */
.press-indicator {
  position: absolute;
  /* align the left edge of the image with the right edge of the recorder button */
  left: calc(50% + (var(--rec-size) / 2) + 8px); /* moved 8px to the right */
  top: -35px; /* moved up from -21px to -35px */
  width: 59px;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.3s ease;
  animation: subtle-pulse 2s ease-in-out infinite;
  -webkit-transform-origin: left center;
  transform-origin: left center;
}

/* Show press indicator only in draw mode */
.draw-mode .press-indicator {
  opacity: 1;
}

/* Hide press indicator in sphere mode */
.sphere-mode .press-indicator {
  opacity: 0;
  display: none;
}

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

@keyframes gentle-pulse {
  0%, 100% { 
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.5);
  }
  50% { 
    transform: scale(1.12);
    box-shadow: 0 0 0 15px rgba(255, 255, 255, 0);
  }
}

@keyframes subtle-pulse {
  0%, 100% { transform: scale(1) translateX(0); }
  50% { transform: scale(1.12) translateX(0); }
}

/* iPhone / small screens: reduce offset so the image isn't pushed offscreen by safe-area insets */
@media (max-width: 420px), (max-device-width: 420px) {
  .press-indicator {
    --press-offset: -18px; /* smaller negative offset on narrow screens */
    width: 56px; /* slightly smaller on small screens */
    z-index: 30; /* bring above overlays */
  }
}

/* Flash effect */
.flash-element {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.1s ease;
}

.flash-element.flashing {
  opacity: 0.8;
}

/* Preview container */
.fade-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.fade-container.visible {
  display: flex;
}

/* Wrapper para medir y posicionar acciones */
#preview-media-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 96vw;
  max-height: 82vh; /* allow taller preview; actions sit outside now */
  /* Maintain same aspect as screen; JS sets --screen-ar and provides width/height clamps */
  aspect-ratio: var(--screen-ar, auto);
  /* Mobile safe-area responsive tweaks will override below */
}

/* iPhone Portrait optimized preview sizing - highest specificity */
@media screen and (max-width: 480px) and (orientation: portrait) and (max-height: 950px) {
  #preview-media-wrapper { 
  max-width: 94vw !important; 
  max-height: 60vh !important; 
  min-height: 300px !important;
  }
  .preview-actions { 
  gap: 28px !important; 
  bottom: calc(env(safe-area-inset-bottom, 0px) + 40px) !important;
  }
  .preview-btn { 
  width: 56px !important; 
  height: 56px !important; 
  }
  .preview-label { 
    font-size: 12px !important; 
  }
  /* iPhone specific word-text sizing */
  .word-text {
    width: 380px !important;
    height: 130px !important;
  }
  .word-text .word-inner {
    font-size: clamp(18px, 5vw, 32px) !important;
  }
}

/* iPhone Pro/Max Portrait */
@media screen and (max-width: 430px) and (orientation: portrait) and (max-height: 950px) {
  #preview-media-wrapper { 
  max-width: 96vw !important; 
  max-height: 58vh !important; 
  min-height: 290px !important;
  }
  .preview-actions { 
  gap: 28px !important; 
  bottom: calc(env(safe-area-inset-bottom, 0px) + 35px) !important;
  }
  .preview-btn { 
  width: 54px !important; 
  height: 54px !important; 
  }
  .preview-label { 
    font-size: 11px !important; 
  }
  /* iPhone Pro/Max specific word-text sizing */
  .word-text {
    width: 370px !important;
    height: 125px !important;
  }
  .word-text .word-inner {
    font-size: clamp(16px, 4.5vw, 28px) !important;
  }
}

/* Standard iPhone Portrait (375px) */
@media screen and (max-width: 390px) and (orientation: portrait) and (max-height: 850px) {
  #preview-media-wrapper { 
  max-width: 96vw !important; 
  max-height: 56vh !important; 
  min-height: 260px !important;
  }
  .preview-actions { 
  gap: 26px !important; 
  bottom: calc(env(safe-area-inset-bottom, 0px) + 30px) !important;
  }
  .preview-btn { 
  width: 50px !important; 
  height: 50px !important; 
  }
  .preview-label { 
    font-size: 10px !important; 
  }
  /* Standard iPhone specific word-text sizing */
  .word-text {
    width: 350px !important;
    height: 120px !important;
  }
  .word-text .word-inner {
    font-size: clamp(15px, 4.2vw, 26px) !important;
  }
}

/* Extra small iPhone screens */
@media screen and (max-width: 375px) and (orientation: portrait) and (max-height: 800px) {
  .preview-actions { 
    bottom: calc(env(safe-area-inset-bottom, 0px) + 45px) !important;
    gap: 24px !important;
  }
  .preview-btn { 
    width: 48px !important; 
    height: 48px !important; 
  }
  /* Extra small iPhone specific word-text sizing */
  .word-text {
    width: 340px !important;
    height: 115px !important;
  }
  .word-text .word-inner {
    font-size: clamp(14px, 4vw, 24px) !important;
  }
}

#preview-video, #preview-image {
  max-width: 100%;
  max-height: 100%;
  border-radius: 22px;
  box-shadow: 0 20px 50px -10px rgba(0,0,0,0.6), 0 0 0 4px rgba(255,255,255,0.06);
  outline: 0;
}

#preview-image {
  display: none;
}

/* New preview actions (bottom) */
.preview-actions {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  transform: translate(-50%, 0);
  display: flex;
  gap: clamp(32px, 7vw, 72px); /* responsive gap between buttons - AUMENTADO para el pulso más grande */
  align-items: center;
  z-index: 25; /* above bottomBar (20) and footer (18) but not interfering with other elements */
  pointer-events: none; /* sólo botones clickeables */
}

/* Draw ellipses behind the banner (true rings rendered via inline SVG) */
.draw-ellipse {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: transparent;
  border: none; /* ring stroke is drawn by SVG inside */
  box-shadow: none;
  filter: none;
  opacity: 0;
  transition: opacity .12s ease;
  pointer-events: none;
}
.draw-ellipse.ellipse-purple { color: #AA3BFF; border-color: #AA3BFF; }
.draw-ellipse.ellipse-cyan { color: #00F0FF; border-color: #00F0FF; }

/* Mobile devices general positioning adjustment */
@media screen and (max-width: 768px) and (orientation: portrait) {
  .preview-actions {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 25px) !important;
    z-index: 25 !important;
  }
  /* General mobile word-text sizing */
  .word-text {
    width: 360px !important;
    height: 125px !important;
  }
  .word-text .word-inner {
    font-size: clamp(16px, 4.5vw, 30px) !important;
    font-weight: 900 !important; /* make text bolder on mobile */
  }
}

/* Specific rule for very small iPhone screens to ensure button visibility */
@media screen and (max-width: 414px) and (max-height: 896px) and (orientation: portrait) {
  .preview-actions {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 35px) !important;
    z-index: 25 !important;
  }
}

/* === Responsive preview button styles === */
.preview-action { 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  gap: clamp(8px, 2vw, 14px); 
  min-width: clamp(60px, 15vw, 120px); 
}

.preview-btn { 
  width: clamp(72px, 20vw, 110px); 
  height: clamp(72px, 20vw, 110px); 
  border: none; 
  background: none; 
  padding: 0; 
  border-radius: 50%; 
  cursor: pointer; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  pointer-events: auto; 
  transition: transform .18s ease; 
  -webkit-appearance: none; 
  appearance: none; 
}

.preview-icon { 
  width: 100%; 
  height: 100%; 
  object-fit: contain; 
  display: block; 
  pointer-events: none; 
  -webkit-user-select: none; 
  user-select: none; 
  image-rendering: -webkit-optimize-contrast; 
}

.preview-btn:hover { 
  transform: translateY(-4px); 
}

.preview-btn:active { 
  transform: scale(.94); 
}

.preview-cancel, .preview-save, .preview-share { 
  background: none !important; 
}

.preview-label { 
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
  font-weight: 800; 
  font-size: clamp(14px, 4vw, 18px); 
  color: #fff; 
  text-shadow: 0 6px 22px rgba(0,0,0,.65); 
  letter-spacing: .5px; 
  user-select: none; 
}
/* No media queries: identical rendering iPhone / desktop */

/* iOS force identical desktop look (neutralize Safari quirks) */
@supports (-webkit-touch-callout: none) {
  .preview-btn { -webkit-tap-highlight-color: rgba(0,0,0,0); outline:none; }
  .preview-icon { -webkit-user-drag:none; }
  /* Prevent automatic image shrinking in some Safari viewport scenarios */
  #preview-media-wrapper { transform: translateZ(0); -webkit-transform: translateZ(0); }
}

/* When preview open, hide bottomBar controls to avoid overlap */
#preview-container.visible ~ #bottomBar, #preview-container.visible + #bottomBar { display: none; }

/* Hide footer when preview is open to prevent overlap with preview buttons */
#preview-container.visible ~ #kaseya-footer, #preview-container.visible + #kaseya-footer { display: none; }

/* Particles system */
.particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.3s ease;
  will-change: transform, width, height, opacity;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

/* Figma Dots Assets (face-follow group) */
.dot-asset {
  mix-blend-mode: normal;
  opacity: 1;
  filter: saturate(110%) brightness(1.05);
}

/* Remove old size classes as we're handling sizes dynamically */

/* Word display - hidden in sphere mode */
.sphere-mode #word-display {
  display: none !important;
}

.sphere-mode .word-text {
  display: none !important;
}
#word-display {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

.word-text {
  background: #2A127F;
  color: white;
  width: 360px; /* increased from 320px */
  height: 120px; /* increased from 100px */
  padding: 0;
  border-radius: 30px;
  font-weight: 700;
  text-align: center;
  border: 3px solid #A44BFF;
  box-shadow: 0 10px 30px rgba(138, 43, 226, 0.3), 0 0 20px rgba(138, 43, 226, 0.2), inset 0 1px 0 rgba(255,255,255,0.3);
  backdrop-filter: blur(10px);
  letter-spacing: 1px;
  position: relative;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 4px 12px;
}

/* Inner wrapper so we can animate without overriding parent's translateX centering */
.word-text .word-inner {
  display: block;
  width: 100%;
  height: 100%;
  line-height: 1.15;
  font-size: clamp(16px, 3.5vw, 28px); /* increased further from clamp(12px, 2.8vw, 24px) */
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 800;
  word-break: break-word;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 4px;
}

/* Desktop: cartel más grande y proporcional */
@media (min-width: 768px) {
  .word-text {
    width: 480px;
    height: 160px;
    border-radius: 40px;
  }
  
  .word-text .word-inner {
    font-size: clamp(20px, 2vw, 32px);
    padding: 0 8px;
  }
}

.word-text.spinning {
  animation: word-glow 0.4s ease-in-out infinite alternate;
  background: #2A127F;
  background-size: 400% 400%;
  animation: word-glow 0.4s ease-in-out infinite alternate; /* keep glow only */
  border-color: #A44BFF;
  box-shadow: 
    0 10px 30px rgba(138, 43, 226, 0.4),
    0 0 40px rgba(138, 43, 226, 0.3),
    inset 0 1px 0 rgba(255,255,255,0.4);
}

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

@keyframes word-glow {
  0% { 
    box-shadow: 
      0 10px 30px rgba(138, 43, 226, 0.4),
      0 0 20px rgba(138, 43, 226, 0.2),
      inset 0 1px 0 rgba(255,255,255,0.3);
  }
  100% { 
    box-shadow: 
      0 10px 30px rgba(138, 43, 226, 0.6),
      0 0 50px rgba(138, 43, 226, 0.4),
      inset 0 1px 0 rgba(255,255,255,0.4);
  }
}

.word-text.final { /* keep glow on parent if needed, but bounce moves to inner */
  animation: final-glow 2s ease-in-out infinite;
  background: linear-gradient(135deg, #8A2BE2, #6A5ACD);
  background-size: 200% 200%;
  border-color: rgba(255,215,0,0.9);
  color: #fff;
}

/* Bounce only the inner so parent's translateX stays intact */
.word-text .word-inner.final {
  animation: final-bounce 0.8s ease-out;
}

@keyframes final-bounce {
  0% { transform: scale(0.9); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes final-glow {
  0%, 100% { 
    box-shadow: 
      0 15px 40px rgba(138, 43, 226, 0.6),
      0 0 30px rgba(255,215,0,0.4),
      inset 0 2px 0 rgba(255,255,255,0.3);
  }
  50% { 
    box-shadow: 
      0 15px 40px rgba(138, 43, 226, 0.8),
      0 0 60px rgba(255,215,0,0.6),
      inset 0 2px 0 rgba(255,255,255,0.4);
  }
}


/* Mobile optimizations */
@media (max-width: 768px) {
  .controls-container {
    gap: 20px;
    padding: 0 10px;
  }
  /* Preview layout adjustments (mobile) */
  #preview-container { 
    padding: env(safe-area-inset-top, 12px) 0 calc(env(safe-area-inset-bottom, 12px) + 90px);
  }
  #preview-media-wrapper {
    max-width: 100vw;
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 190px);
    padding: 0 10px;
  }
  #preview-video, #preview-image {
    width: 100%;
    height: auto;
    max-height: 100%;
  }
  .preview-actions { 
    gap: clamp(18px, 10vw, 46px); 
    bottom: calc(env(safe-area-inset-bottom, 0px) + 30px) !important;
  }
  .preview-btn { 
    width: clamp(54px, 18vw, 78px); 
    height: clamp(54px, 18vw, 78px); 
  }
  .preview-action { min-width: auto; }
  
  .control-btn {
    min-width: 70px;
    padding: 12px 16px;
  }
  
  .control-btn span {
    font-size: 1.3rem;
  }
  
  .control-btn div {
    font-size: 0.7rem;
  }
  
  #recorder-button {
    width: 55px;
    height: 55px;
  }

  /* mirror the recorder size for alignment calculations */
  .recorder-container { --rec-size: 55px; }
  
  .progress-container {
    width: 75px;
    height: 75px;
  }
  
  .word-text {
    width: 340px; /* slightly larger for mobile */
    height: 110px; /* slightly larger for mobile */
    font-size: 1.8rem; /* increased from 1.5rem */
    padding: 12px 20px;
    margin: 0 15px;
  }
}

/* Loading states */
.recorder-container.loading .progress-bar {
  opacity: 0;
}

.recorder-container.recording .progress-bar {
  opacity: 1;
}

/* Footer */
#kaseya-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100vw; /* Ancho completo de la pantalla */
  height: auto;
  z-index: 18; /* behind controls (bottomBar z-index 20), above canvas */
  opacity: 0.85;
  pointer-events: none;
  /* Fix para Safari en iPhone */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#kaseya-footer img {
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(138, 43, 226, 0.4));
  /* Ajuste específico para Safari */
  transform: translateY(0);
  display: block;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .controls-container {
    gap: 20px;
    padding: 0 10px;
    justify-content: center; /* Centrar el único botón */
  }
  
  .control-btn {
    min-width: 70px;
    padding: 12px 16px;
  }
  
  .control-btn span {
    font-size: 1.3rem;
  }
  
  .control-btn div {
    font-size: 0.7rem;
  }
  
  #recorder-button {
    width: 55px;
    height: 55px;
  }
  
  .progress-container {
    width: 75px;
    height: 75px;
  }
  
  .word-text {
    width: 340px; /* larger for mobile */
    height: 110px; /* larger for mobile */ 
    font-size: 1.8rem; /* increased from 1.5rem */
    padding: 10px 16px;
    margin: 0 10px;
  }
  
  /* Botón en mobile también subido */
  #bottomBar {
    padding: 20px 15px 20px; /* Keep it near the bottom on mobile too */
  }
  
  /* Preview controls en mobile */
  .preview-controls {
    top: 20px;
    right: 20px;
    gap: 12px;
  }
  
  .preview-controls button {
    width: 50px;
    height: 50px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .word-text,
  .word-text.spinning,
  .word-text.final,
  #recorder-button,
  .loading-circle {
    animation: none !important;
  }
  
  .control-btn:hover,
  .preview-controls button:hover {
    transform: none;
  }
}

/* Specific fix for Safari on iOS */
@supports (-webkit-touch-callout: none) {
  /* Avoid ancestor clipping on iOS Safari */
  #app { overflow: visible; }

  #kaseya-footer {
    /* Safari específico en iOS */
    bottom: 10px;
    width: 100vw;
    min-width: 100vw;
    padding-bottom: 0;
  z-index: 18;
    clip-path: inset(0);
    height: clamp(160px, 22vh, 250px);
  }
  
  #kaseya-footer img {
    width: 100vw !important;
    min-width: 100vw;
    height: 100% !important;
  object-fit: contain;
  clip-path: inset(0);
  }
}

/* iOS specific preview safe-area handling - adjusted for smaller iPhone preview */
@supports (-webkit-touch-callout: none) {
  #preview-container { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); }
  #preview-media-wrapper { 
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 190px); 
  }
  /* Ensure preview actions are properly positioned on iOS Safari */
  .preview-actions {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 20px) !important;
    z-index: 25 !important;
  }
}

/* Landscape small-height devices (e.g., iPhone landscape) */
@media (max-height: 500px) and (orientation: landscape) {
  #preview-media-wrapper { 
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 130px); 
  }
  .preview-actions { 
    bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); 
    gap: clamp(14px, 6vw, 32px); 
  }
  .preview-btn { 
    width: clamp(46px, 13vw, 64px); 
    height: clamp(46px, 13vw, 64px); 
  }
  .preview-label { font-size: clamp(12px, 2.5vw, 14px); }
}

/* Ultra-narrow phones - adjusted to not conflict with iPhone portrait rules */
@media (max-width: 360px) and (orientation: landscape) {
  #preview-media-wrapper { max-width: 96vw; }
  .preview-actions { gap: clamp(14px, 14vw, 30px); }
  .preview-btn { width: clamp(48px, 22vw, 62px); height: clamp(48px, 22vw, 62px); }
}

/* Additional fix for iOS viewport issues */
@media screen and (max-device-width: 480px) {
  #kaseya-footer {
    bottom: 15px;
  min-height: 193px;
    height: clamp(193px, 30vh, 308px);
    width: 100vw;
    min-width: 100vw;
  z-index: 18;
  }
  
  #kaseya-footer img {
  max-height: none;
    width: 100vw !important;
    min-width: 100vw;
    height: 100% !important;
  object-fit: contain;
  clip-path: inset(0);
  }
}

/* Specific Safari iPhone detection */
@media screen and (max-width: 414px) and (-webkit-min-device-pixel-ratio: 2) {
  #kaseya-footer {
    bottom: 20px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    min-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
  height: clamp(193px, 30vh, 308px) !important;
  z-index: 18 !important;
  }
  
  #kaseya-footer img {
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: none !important;
  object-fit: contain !important;
    display: block !important;
  height: 100% !important;
  }
}

/* iPhone 12 Pro and similar models (390px width) */
@media screen and (max-width: 428px) and (min-width: 375px) and (-webkit-min-device-pixel-ratio: 3) {
  #kaseya-footer {
    bottom: 10px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
  height: clamp(290px, 39vh, 444px) !important;
  z-index: 18 !important;
  }
  
  #kaseya-footer img {
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: none !important;
  object-fit: contain !important; /* Avoid cropping on Safari iPhone 12/13/14 */
    display: block !important;
  height: 100% !important;
  }
}

/* iPhone 12 Pro Max and larger models */
@media screen and (min-width: 428px) and (-webkit-min-device-pixel-ratio: 3) {
  #kaseya-footer {
    bottom: 5px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    min-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
  height: clamp(209px, 30vh, 333px) !important;
  z-index: 18 !important;
  }
  
  #kaseya-footer img {
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: none !important;
  object-fit: contain !important; /* Avoid cropping on larger iPhones */
    display: block !important;
  height: 100% !important;
  }
}

/* Universal iPhone Safari fix */
@media screen and (max-width: 480px) and (-webkit-min-device-pixel-ratio: 2) {
  #kaseya-footer {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 5px) !important;
  min-height: 193px !important;
    height: clamp(211px, 30vh, 320px) !important;
  z-index: 18 !important;
  }
  
  #kaseya-footer img {
    width: 100vw !important;
    min-width: 100vw !important;
    max-width: none !important;
  object-fit: contain !important; /* Prevent top being cut in Safari */
  object-position: center bottom !important;
    display: block !important;
  height: 100% !important;
  }
}

/* ================= Desktop Enhancements (>= 1024px) ================= */
@media (min-width: 1024px) {
  /* Keep footer present but not overwhelmingly tall on large screens */
  #kaseya-footer {
    height: clamp(110px, 16vh, 180px) !important;
    opacity: 0.9;
  }

  /* Bring record controls closer to bottom for desktop ergonomics */
  #bottomBar {
    bottom: 70px; /* previously 150px */
  }

  .controls-container { gap: 40px; }

  #recorder-button { width: 70px; height: 70px; }
  .progress-container { width: 95px; height: 95px; }
  .recorder-container { --rec-size: 70px; }

  /* Larger word display on desktop */
  .word-text { font-size: 3.2rem; padding: 28px 48px; }

  /* Preview controls spacing tweak */
  .preview-controls { top: 40px; right: 40px; }
  .preview-controls button { width: 56px; height: 56px; font-size: 22px; }

  /* Video & canvas crisp alignment */
  #webcam, #overlay-canvas { object-fit: cover; }
}

/* Ultra-wide screens */
@media (min-width: 1600px) {
  .word-text { font-size: 3.8rem; }
  #bottomBar { bottom: 80px; }
}

/* Mid-size tablets (between mobile and desktop) refine spacing */
@media (min-width: 768px) and (max-width: 1023px) {
  #bottomBar { bottom: 90px; }
  .word-text { font-size: 2.4rem; }
  #kaseya-footer { height: clamp(140px, 18vh, 240px); }
}

/* Safari Preview Mode fix - cuando no hay barra de navegación */
@media screen and (max-width: 480px) and (-webkit-min-device-pixel-ratio: 2) and (display-mode: browser) {
  #kaseya-footer {
    height: clamp(240px, 35vh, 380px) !important;
    min-height: 240px !important;
  }
}

/* Safari Preview Mode alternativo - para pantallas sin UI chrome */
@supports (-webkit-touch-callout: none) {
  @media screen and (max-width: 480px) and (min-height: 700px) {
    #kaseya-footer {
      height: clamp(250px, 32vh, 400px) !important;
      min-height: 250px !important;
    }
  }
  
  @media screen and (max-width: 428px) and (min-width: 375px) and (min-height: 750px) {
    #kaseya-footer {
      height: clamp(320px, 42vh, 500px) !important;
      min-height: 320px !important;
    }
  }
}

/* ============================================
   LOADING OVERLAY - Initial page load
   ============================================ */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.5s ease-out;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  color: white;
  position: relative;
}

.loading-spinner {
  width: 80px;
  height: 80px;
  margin: 0 auto 30px;
  position: relative;
}

/* Animación de círculos orbitando */
.spinner-orbit {
  width: 100%;
  height: 100%;
  position: relative;
  animation: orbit-rotate 2s linear infinite;
}

.spinner-dot {
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -8px 0 0 -8px;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.spinner-dot:nth-child(1) {
  transform: translate(32px, 0);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.spinner-dot:nth-child(2) {
  transform: translate(-32px, 0);
  animation: pulse-dot 1.5s ease-in-out infinite 0.5s;
}

.spinner-dot:nth-child(3) {
  transform: translate(0, 32px);
  animation: pulse-dot 1.5s ease-in-out infinite 1s;
}

@keyframes orbit-rotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes pulse-dot {
  0%, 100% { 
    transform: translate(var(--x, 32px), var(--y, 0)) scale(1);
    opacity: 1;
  }
  50% { 
    transform: translate(var(--x, 32px), var(--y, 0)) scale(1.3);
    opacity: 0.7;
  }
}

.spinner-dot:nth-child(1) { --x: 32px; --y: 0; }
.spinner-dot:nth-child(2) { --x: -32px; --y: 0; }
.spinner-dot:nth-child(3) { --x: 0; --y: 32px; }

.loading-text {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  animation: fade-pulse 2s ease-in-out infinite;
}

.loading-subtext {
  font-size: 0.9rem;
  opacity: 0.8;
  font-weight: 500;
  animation: fade-pulse 2s ease-in-out infinite 0.5s;
}

@keyframes fade-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
