/**
 * NORDLYS MOBILE STUDIO - PHASE 2
 * Thumb-First Recording Interface
 * 
 * CRITICAL: Optimized for one-handed operation
 * All primary controls positioned within natural thumb arc
 */

/* ========================================
   THUMB ZONE MAPPING
   ======================================== */
:root {
  /* Ergonomic zones based on 6" screen average */
  --thumb-easy-reach: 120px; /* Bottom 120px easily reachable */
  --thumb-ok-reach: 200px;   /* Bottom 200px reachable with stretch */
  --thumb-hard-reach: 280px; /* Beyond this requires hand repositioning */
  
  /* Control sizes optimized for touch */
  --control-min-size: 48px;  /* WCAG minimum */
  --control-comfort-size: 56px; /* Comfortable tap target */
  --control-primary-size: 72px; /* Primary action (record) */
  
  /* Safe areas for notched devices */
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-top: env(safe-area-inset-top, 0);
  
  /* Animation timings */
  --haptic-duration: 50ms;
  --state-transition: 200ms;
}

/* ========================================
   MOBILE STUDIO CONTAINER
   ======================================== */
.mobile-studio {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height */
  position: relative;
  overflow: hidden;
  touch-action: pan-y; /* Allow vertical scroll, prevent zoom */
}

/* ========================================
   TOP ZONE: MINIMAL STATUS
   ======================================== */
.studio-zone--top-mobile {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--nordlys-glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  
  /* Ultra-compact for maximum content space */
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

.mobile-progress-bar {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin: 0 12px;
}

.mobile-progress-fill {
  height: 100%;
  background: var(--gradient-brand);
  transition: width 0.3s ease;
  border-radius: 2px;
}

.mobile-counter {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-primary);
  min-width: 60px;
  text-align: center;
}

/* ========================================
   MIDDLE ZONE: SENTENCE DISPLAY
   ======================================== */
.studio-zone--middle-mobile {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  padding-top: 60px; /* Account for fixed header */
  padding-bottom: calc(var(--thumb-easy-reach) + 40px); /* Account for controls */
  
  /* Enable swipe gestures */
  touch-action: pan-x;
  user-select: none;
  -webkit-user-select: none;
}

.sentence-card-mobile {
  background: var(--nordlys-premium-bg);
  border: 1px solid var(--nordlys-premium-border);
  border-radius: 16px;
  padding: 24px 20px;
  width: 100%;
  max-width: 400px;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  
  /* High contrast backdrop for outdoor visibility */
  box-shadow: 
    0 4px 24px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.sentence-text-mobile {
  font-size: 20px;
  line-height: 1.6;
  text-align: center;
  color: var(--color-text-primary);
  font-weight: 500;
  
  /* Ensure readability */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  letter-spacing: 0.3px;
}

/* Swipe indicators */
.swipe-hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-tertiary);
  opacity: 0.5;
  transition: opacity 0.2s;
}

.swipe-hint--left {
  left: -40px;
}

.swipe-hint--right {
  right: -40px;
}

.sentence-card-mobile:hover .swipe-hint,
.sentence-card-mobile:active .swipe-hint {
  opacity: 1;
}

/* ========================================
   BOTTOM ZONE: THUMB-FIRST CONTROLS
   ======================================== */
.studio-zone--bottom-mobile {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--nordlys-glass-elevated-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--nordlys-glass-border);
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
  
  /* Ensure minimum height for thumb comfort */
  min-height: var(--thumb-easy-reach);
  
  /* Shadow for depth */
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
}

/* Primary record button - centered and prominent */
.record-button-mobile {
  width: var(--control-primary-size);
  height: var(--control-primary-size);
  margin: 0 auto 12px;
  display: block;
  border-radius: 50%;
  background: var(--gradient-brand);
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 
    0 4px 16px rgba(139, 92, 246, 0.4),
    0 2px 4px rgba(0, 0, 0, 0.2);
  position: relative;
  cursor: pointer;
  transition: all var(--state-transition) ease;
  
  /* Touch feedback */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.record-button-mobile:active {
  transform: scale(0.95);
  box-shadow: 
    0 2px 8px rgba(139, 92, 246, 0.4),
    0 1px 2px rgba(0, 0, 0, 0.2);
}

.record-button-mobile.recording {
  background: var(--color-error);
  animation: record-pulse-mobile 1.5s infinite;
}

@keyframes record-pulse-mobile {
  0%, 100% { 
    box-shadow: 
      0 0 0 0 rgba(239, 68, 68, 0.6),
      0 4px 16px rgba(239, 68, 68, 0.4);
  }
  50% { 
    box-shadow: 
      0 0 0 16px rgba(239, 68, 68, 0),
      0 4px 16px rgba(239, 68, 68, 0.4);
  }
}

/* Record button icon */
.record-icon {
  width: 32px;
  height: 32px;
  display: block;
  margin: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Secondary controls - optimally positioned for thumb */
.control-bar-mobile {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  margin: 0 auto;
}

.control-btn-mobile {
  flex: 1;
  min-width: var(--control-comfort-size);
  min-height: var(--control-comfort-size);
  background: var(--nordlys-glass-bg);
  border: 1px solid var(--nordlys-glass-border);
  border-radius: 12px;
  color: var(--color-text-primary);
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--haptic-duration) ease;
  
  /* Touch optimization */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.control-btn-mobile:active:not(:disabled) {
  transform: scale(0.95);
  background: var(--nordlys-glass-hover);
}

.control-btn-mobile:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Primary next button - slightly larger */
.control-btn-mobile--primary {
  background: var(--gradient-brand);
  border: none;
  color: white;
  min-width: calc(var(--control-comfort-size) + 8px);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.control-btn-mobile--primary:active:not(:disabled) {
  transform: scale(0.95) translateY(1px);
  box-shadow: 0 1px 4px rgba(139, 92, 246, 0.3);
}

/* ========================================
   WAVEFORM VISUALIZATION (OPTIONAL)
   ======================================== */
.waveform-mobile {
  height: 48px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  margin: 12px 0;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.waveform-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
}

.waveform-bar {
  width: 3px;
  background: var(--gradient-brand);
  border-radius: 2px;
  animation: wave 1s ease-in-out infinite;
}

.waveform-bar:nth-child(odd) {
  animation-delay: 0.1s;
}

.waveform-bar:nth-child(even) {
  animation-delay: 0.2s;
}

@keyframes wave {
  0%, 100% { height: 40%; }
  50% { height: 100%; }
}

/* ========================================
   GESTURE FEEDBACK
   ======================================== */
.swipe-feedback {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s;
}

.swipe-feedback.active {
  opacity: 1;
}

.swipe-arrow {
  font-size: 48px;
  color: var(--color-brand-primary);
  filter: drop-shadow(0 2px 8px rgba(139, 92, 246, 0.5));
  animation: swipe-move 0.4s ease-out;
}

@keyframes swipe-move {
  0% { transform: translateX(0); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: translateX(var(--swipe-direction, 50px)); opacity: 0; }
}

/* ========================================
   HAPTIC FEEDBACK VISUAL CUE
   ======================================== */
.haptic-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--color-brand-primary);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
}

.haptic-active .haptic-ring {
  animation: haptic-pulse 0.3s ease-out;
}

@keyframes haptic-pulse {
  0% { 
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% { 
    transform: translate(-50%, -50%) scale(1.5);
    opacity: 0;
  }
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

/* Small phones (< 360px width) */
@media (max-width: 359px) {
  .control-btn-mobile {
    min-width: var(--control-min-size);
    min-height: var(--control-min-size);
    font-size: 18px;
  }
  
  .record-button-mobile {
    width: 64px;
    height: 64px;
  }
  
  .sentence-text-mobile {
    font-size: 18px;
  }
}

/* Large phones (> 428px width - iPhone Pro Max) */
@media (min-width: 428px) {
  .control-bar-mobile {
    max-width: 380px;
    gap: 12px;
  }
  
  .sentence-card-mobile {
    max-width: 440px;
    padding: 28px 24px;
  }
  
  .sentence-text-mobile {
    font-size: 22px;
  }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 500px) {
  .studio-zone--middle-mobile {
    padding-top: 50px;
    padding-bottom: calc(var(--thumb-easy-reach) + 20px);
  }
  
  .sentence-card-mobile {
    min-height: 100px;
    padding: 16px 20px;
  }
  
  .sentence-text-mobile {
    font-size: 18px;
    line-height: 1.4;
  }
  
  .studio-zone--bottom-mobile {
    min-height: 100px;
    padding: 8px 12px;
  }
  
  .control-bar-mobile {
    max-width: 400px;
  }
}

/* ========================================
   ACCESSIBILITY ENHANCEMENTS
   ======================================== */

/* Focus indicators for keyboard navigation */
.control-btn-mobile:focus,
.record-button-mobile:focus {
  outline: 3px solid var(--color-brand-primary);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .sentence-card-mobile {
    border-width: 2px;
    background: var(--color-background);
  }
  
  .control-btn-mobile {
    border-width: 2px;
  }
  
  .sentence-text-mobile {
    font-weight: 700;
    text-shadow: none;
  }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================================
   FEATURE FLAGS
   ======================================== */

/* Enable with body.nordlys-mobile-studio */
body:not(.nordlys-mobile-studio) .mobile-studio,
body:not(.nordlys-mobile-studio) .studio-zone--top-mobile,
body:not(.nordlys-mobile-studio) .studio-zone--middle-mobile,
body:not(.nordlys-mobile-studio) .studio-zone--bottom-mobile {
  display: none;
}

/* Hide original studio when mobile studio is active */
body.nordlys-mobile-studio .studio-container:not(.mobile-studio),
body.nordlys-mobile-studio .studio-zone:not([class*="-mobile"]) {
  display: none;
}