/**
 * Voice Call Player - Styles
 * iOS-inspired liquid glass morphism design
 * Mobile-first, accessible, RTL-ready
 * Simplified: Call button + CC only
 */

/* Import design system variables */
@import url('../shared/design-system.css');

/* Base layout - Mobile first */
.voice-call-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  background: var(--bg-primary);
  padding: var(--space-6);
  padding-top: max(var(--space-6), env(safe-area-inset-top));
  padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
  position: relative;
  overflow: hidden;
}

/* Background gradient overlay */
.voice-call-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: radial-gradient(
    ellipse at top,
    rgba(0, 122, 255, 0.1) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

/* All content above background */
.voice-call-container > * {
  position: relative;
  z-index: 1;
}

/* ========================================
   IDLE STATE
   ======================================== */

.idle-prompt {
  text-align: center;
  margin-bottom: var(--space-12);
}

.idle-text {
  font-size: var(--text-title-2);
  font-weight: var(--text-title-2-weight);
  color: var(--text-secondary);
  margin: 0;
}

/* ========================================
   CONNECTING ANIMATION
   ======================================== */

.connecting-animation {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  margin-bottom: var(--space-12);
}

.ripple-rings {
  position: relative;
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ripple-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 200px;
  height: 200px;
}

.ripple-ring circle {
  transform-origin: center;
  animation: ripple 2s ease-out infinite;
}

.ring-1 circle {
  animation-delay: 0s;
}

.ring-2 circle {
  animation-delay: 0.5s;
}

.ring-3 circle {
  animation-delay: 1s;
}

@keyframes ripple {
  0% {
    r: 50;
    opacity: 0;
  }
  10% {
    opacity: 0.3;
  }
  50% {
    r: 90;
    opacity: 0.3;
  }
  100% {
    r: 100;
    opacity: 0;
  }
}

.phone-icon-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--brand-primary);
}

.connecting-text {
  font-size: var(--text-body);
  font-weight: var(--text-body-weight);
  color: var(--text-secondary);
  margin: 0;
}

.connecting-text .dots {
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% {
    content: '';
  }
  40% {
    content: '.';
  }
  60% {
    content: '..';
  }
  80%, 100% {
    content: '...';
  }
}

/* ========================================
   AVATAR SECTION
   ======================================== */

.avatar-section {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: var(--space-10);
  position: relative;
  opacity: 0;
  transform: scale(0.95) translateY(10px);
  transition: all 0.3s var(--ease-out);
}

.avatar-section:not(.hidden) {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.avatar-glow {
  position: absolute;
  width: 200px;
  height: 200px;
  background: radial-gradient(
    circle,
    rgba(0, 122, 255, 0.3) 0%,
    rgba(0, 122, 255, 0.1) 40%,
    transparent 70%
  );
  border-radius: 50%;
  animation: pulse 3s ease-in-out infinite;
  pointer-events: none;
}

.avatar-ring {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: var(--liquid-glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 2px solid rgba(255, 255, 255, 0.15);
  padding: 8px;
  box-shadow: var(--shadow-xl);
  position: relative;
  z-index: 1;
}

.avatar-image {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-tertiary);
}

/* ========================================
   COACH INFO
   ======================================== */

.coach-info {
  text-align: center;
  margin-top: var(--space-7);
  opacity: 0;
  transition: opacity 0.3s var(--ease-out) 0.1s;
}

.coach-info:not(.hidden) {
  opacity: 1;
}

.coach-name {
  font-size: var(--text-title-1);
  font-weight: var(--text-title-1-weight);
  line-height: var(--text-title-1-line);
  color: var(--text-primary);
  margin: 0;
}

.coach-title {
  font-size: var(--text-body);
  font-weight: var(--text-body-weight);
  line-height: var(--text-body-line);
  color: var(--text-secondary);
  margin-top: var(--space-2);
}

/* ========================================
   CALL STATUS
   ======================================== */

.call-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  margin-top: auto;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--liquid-glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s var(--ease-out);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transition: background 0.3s ease;
}

.status-dot.idle {
  background: var(--state-idle);
}

.status-dot.listening {
  background: var(--state-listening);
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 12px var(--state-listening);
}

.status-dot.speaking {
  background: var(--state-speaking);
  animation: pulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 12px var(--state-speaking);
}

.status-dot.thinking {
  background: var(--state-warning);
  animation: pulse 1s ease-in-out infinite;
}

.status-text {
  font-size: var(--text-callout);
  font-weight: var(--text-callout-weight);
  color: var(--text-primary);
  white-space: nowrap;
}

/* Call timer */
.call-timer {
  font-size: var(--text-caption-1);
  font-weight: var(--text-caption-1-weight);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

/* ========================================
   WAVEFORM VISUALIZATION
   ======================================== */

.waveform-container {
  margin-block: var(--space-6);
}

.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 60px;
}

.waveform-bar {
  width: 4px;
  background: var(--brand-success);
  border-radius: 2px;
  transition: height 0.1s ease-out;
}

.waveform-bar:nth-child(1) { animation: wave 1.2s ease-in-out infinite; animation-delay: 0s; }
.waveform-bar:nth-child(2) { animation: wave 1.2s ease-in-out infinite; animation-delay: 0.1s; }
.waveform-bar:nth-child(3) { animation: wave 1.2s ease-in-out infinite; animation-delay: 0.2s; }
.waveform-bar:nth-child(4) { animation: wave 1.2s ease-in-out infinite; animation-delay: 0.1s; }
.waveform-bar:nth-child(5) { animation: wave 1.2s ease-in-out infinite; animation-delay: 0s; }

@keyframes wave {
  0%, 100% { height: 12px; }
  50% { height: 48px; }
}

/* ========================================
   LEVEL METER
   ======================================== */

.level-meter-container {
  width: 200px;
  margin-block: var(--space-4);
}

.level-meter {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.level-meter-fill {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--brand-primary) 0%,
    var(--brand-primary) 50%,
    var(--brand-warning) 100%
  );
  transition: width 0.1s ease-out;
}

/* ========================================
   CALL BUTTON
   ======================================== */

.call-button-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  margin-top: auto;
  margin-bottom: var(--space-8);
}

.btn-call {
  width: 80px;
  height: 80px;
  min-width: 80px;
  min-height: 80px;
  border-radius: 50%;
  background: var(--brand-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: all 0.3s var(--ease-in-out);
  box-shadow: var(--shadow-lg);
  position: relative;
}

.btn-call:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-xl), 0 0 32px rgba(0, 122, 255, 0.4);
}

.btn-call:active {
  transform: scale(0.95);
}

.btn-call:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 4px;
}

/* Call button states */
.btn-call.listening {
  background: var(--state-listening);
  animation: pulse 2s ease-in-out infinite;
}

.btn-call.speaking {
  background: var(--state-speaking);
}

.btn-call.active {
  background: var(--brand-error);
}

/* ========================================
   CC (CLOSED CAPTIONS) BUTTON
   ======================================== */

.cc-button-container {
  position: fixed;
  bottom: max(var(--space-8), env(safe-area-inset-bottom));
  right: var(--space-6);
  z-index: 100;
}

.btn-cc {
  width: 56px;
  height: 56px;
  min-width: 56px;
  min-height: 56px;
  border-radius: 50%;
  background: var(--liquid-glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: all 0.2s var(--ease-out);
  box-shadow: var(--shadow-md);
}

.btn-cc:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-cc:active {
  transform: translateY(0);
}

.btn-cc:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

.btn-cc[aria-pressed="true"] {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
}

/* ========================================
   LANGUAGE SWITCHER
   ======================================== */

.language-switcher {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  z-index: 200;
  display: flex;
  align-items: center;
  height: 36px;
  background: var(--liquid-glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.lang-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s var(--ease-out);
}

.lang-option.active {
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
}

.lang-option:hover:not(.active) {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
}

.lang-option:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: -2px;
  border-radius: 16px;
}

.lang-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.2);
  align-self: center;
}

/* ========================================
   CAPTION OVERLAY (TRUE CC)
   ======================================== */

.caption-overlay {
  position: fixed;
  bottom: max(84px, calc(76px + env(safe-area-inset-bottom)));
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 400px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 90;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s var(--ease-out);
}

.caption-overlay:not(.hidden) {
  opacity: 1;
}

.caption-speaker {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
  margin-right: 6px;
}

.caption-speaker[data-speaker="coach"] {
  color: var(--brand-primary);
}

.caption-speaker[data-speaker="user"] {
  color: var(--brand-success);
}

.caption-text {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  color: #FFFFFF;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  letter-spacing: 0.2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-wrap: break-word;
}

/* Caption fade-in animation */
@keyframes caption-fade-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Caption fade-out animation */
@keyframes caption-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* ========================================
   LOADING OVERLAY
   ======================================== */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: var(--text-body);
  color: var(--text-primary);
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */

.toast-container {
  position: fixed;
  top: max(var(--space-6), env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  pointer-events: none;
}

.toast {
  background: var(--liquid-glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: var(--space-3) var(--space-5);
  color: var(--text-primary);
  font-size: var(--text-callout);
  box-shadow: var(--shadow-lg);
  animation: slideDown 0.3s var(--ease-out);
  pointer-events: auto;
  margin-bottom: var(--space-3);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast.error {
  border-color: var(--brand-error);
  background: linear-gradient(
    135deg,
    rgba(255, 59, 48, 0.2),
    rgba(255, 59, 48, 0.1)
  );
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.8;
  }
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--brand-primary);
  color: var(--text-primary);
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  border-radius: 0 0 8px 0;
  z-index: 3000;
}

.skip-link:focus {
  top: 0;
}

/* ========================================
   RESPONSIVE - TABLET
   ======================================== */

@media (min-width: 768px) {
  .voice-call-container {
    padding: var(--space-8);
  }

  .avatar-ring {
    width: 200px;
    height: 200px;
  }

  .avatar-glow {
    width: 240px;
    height: 240px;
  }

  .btn-call {
    width: 96px;
    height: 96px;
    min-width: 96px;
    min-height: 96px;
  }

  .btn-cc {
    width: 64px;
    height: 64px;
    min-width: 64px;
    min-height: 64px;
  }

  .language-switcher {
    top: 24px;
    right: 24px;
    height: 40px;
    border-radius: 20px;
  }

  .lang-option {
    width: 44px;
    height: 40px;
    font-size: 15px;
  }

  .lang-option.active {
    border-radius: 18px;
  }

  .lang-divider {
    height: 24px;
  }

  .caption-overlay {
    bottom: 96px;
    width: 80%;
    max-width: 600px;
    padding: 12px 18px;
    border-radius: 14px;
  }

  .caption-text {
    font-size: 18px;
  }
}

/* ========================================
   RESPONSIVE - DESKTOP
   ======================================== */

@media (min-width: 1024px) {
  .voice-call-container {
    max-width: 600px;
    margin: 0 auto;
  }
}

/* ========================================
   RTL SUPPORT
   ======================================== */

[dir="rtl"] .status-indicator {
  flex-direction: row-reverse;
}

[dir="rtl"] .cc-button-container {
  right: auto;
  left: var(--space-6);
}

[dir="rtl"] .language-switcher {
  right: auto;
  left: 16px;
}

@media (min-width: 768px) {
  [dir="rtl"] .language-switcher {
    left: 24px;
  }
}

[dir="rtl"] .caption-text {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .caption-speaker {
  margin-right: 0;
  margin-left: 6px;
}

/* ========================================
   HIGH CONTRAST MODE
   ======================================== */

@media (prefers-contrast: high) {
  .avatar-ring,
  .status-indicator,
  .btn-cc,
  .language-switcher,
  .caption-overlay {
    border-width: 2px;
    border-color: rgba(255, 255, 255, 0.4);
  }

  .status-text,
  .coach-title {
    color: #d0d0d0;
  }

  .caption-text {
    text-shadow: none;
    font-weight: 600;
  }
}

/* ========================================
   REDUCED MOTION
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .avatar-glow,
  .status-dot,
  .waveform-bar,
  .ripple-ring circle {
    animation: none !important;
  }
}

/* ========================================
   LANDSCAPE MOBILE OPTIMIZATION
   ======================================== */

@media (max-height: 600px) and (orientation: landscape) {
  .voice-call-container {
    padding-block: var(--space-4);
  }

  .avatar-section {
    margin-top: var(--space-4);
  }

  .avatar-ring {
    width: 120px;
    height: 120px;
  }

  .coach-info {
    margin-top: var(--space-4);
  }

  .call-button-container {
    margin-block: var(--space-4);
  }

  .btn-call {
    width: 64px;
    height: 64px;
    min-width: 64px;
    min-height: 64px;
  }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
  .btn-call,
  .btn-cc,
  .language-switcher,
  .loading-overlay {
    display: none !important;
  }

  .caption-overlay {
    position: static;
    transform: none;
  }
}
