/* AR Face Filter - Mobile-First Styles */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #007AFF;
  --primary-dark: #0056CC;
  --bg: #000;
  --text: #fff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --overlay: rgba(0, 0, 0, 0.5);
  --success: #34C759;
  --warning: #FF9500;
  --danger: #FF3B30;
  --card-bg: rgba(255, 255, 255, 0.1);
  --blur: saturate(180%) blur(20px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Screens */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
}

.screen.hidden {
  display: none;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

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

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-overlay p {
  margin-top: 16px;
  color: var(--text-secondary);
}

/* Permission Screen */
.permission-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.permission-icon {
  font-size: 80px;
  margin-bottom: 24px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.permission-content h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
}

.permission-content p {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 32px;
  max-width: 300px;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 16px 48px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: scale(1.02);
}

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

.hint {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* Camera Container */
.camera-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  overflow: hidden;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
  pointer-events: none;
}

/* Face Status */
.face-status {
  position: absolute;
  top: calc(var(--safe-top) + 70px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--overlay);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.face-status.visible {
  opacity: 1;
}

.face-status.detected {
  background: rgba(52, 199, 89, 0.3);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.face-status.detected .status-dot {
  background: var(--success);
  animation: pulse 1.5s ease-in-out infinite;
}

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

/* Top Bar */
.top-bar {
  position: absolute;
  top: var(--safe-top);
  left: 0;
  right: 0;
  padding: 16px;
  display: flex;
  align-items: center;
  z-index: 10;
}

.spacer {
  flex: 1;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--overlay);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.icon-btn:active {
  transform: scale(0.9);
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  color: white;
}

/* Filter Bar */
.filter-bar {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 120px);
  left: 0;
  right: 0;
  padding: 0 16px;
}

.filter-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 8px 0;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filter-list::-webkit-scrollbar {
  display: none;
}

.filter-item {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--card-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 3px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  cursor: pointer;
  transition: all 0.2s ease;
  scroll-snap-align: center;
}

.filter-item:hover {
  transform: scale(1.05);
}

.filter-item:active {
  transform: scale(0.95);
}

.filter-item.active {
  border-color: var(--primary);
  background: rgba(0, 122, 255, 0.3);
}

.filter-item.none {
  font-size: 16px;
  color: var(--text-secondary);
}

/* Capture Bar */
.capture-bar {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 24px);
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 0 24px;
}

.capture-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: white;
  border: 4px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.capture-btn:hover {
  transform: scale(1.05);
}

.capture-btn:active {
  transform: scale(0.9);
}

.capture-inner {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: white;
  transition: all 0.1s ease;
}

.capture-btn:active .capture-inner {
  background: #ddd;
}

.side-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--overlay);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: all 0.2s ease;
}

.side-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.side-btn:active {
  transform: scale(0.9);
}

.side-btn svg {
  width: 24px;
  height: 24px;
  color: white;
}

.side-btn.hidden {
  visibility: hidden;
}

.gallery-preview {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  border-radius: 8px;
}

/* Preview Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  max-width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#preview-image {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-actions {
  display: flex;
  gap: 16px;
  margin-top: 24px;
}

.modal-btn {
  background: var(--card-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  color: white;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.modal-btn:active {
  transform: scale(0.95);
}

.modal-btn svg {
  width: 20px;
  height: 20px;
}

/* Language Selector */
.lang-selector {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  right: 70px;
  z-index: 50;
}

#camera-screen .lang-selector {
  display: none;
}

.lang-selector select {
  background: var(--overlay);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 200px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--overlay);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 200;
  animation: toastIn 0.3s ease;
}

.toast.hidden {
  display: none;
}

.toast.success {
  background: rgba(52, 199, 89, 0.9);
}

.toast.error {
  background: rgba(255, 59, 48, 0.9);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Responsive */
@media (min-width: 768px) {
  .camera-container {
    max-width: 600px;
    margin: 0 auto;
    border-radius: 24px;
    margin-top: 24px;
    margin-bottom: 24px;
    height: calc(100% - 48px);
  }

  #video, #canvas {
    border-radius: 24px;
  }

  .filter-bar {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
  }
}

/* Flash Effect */
.flash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: white;
  pointer-events: none;
  animation: flash 0.3s ease;
  z-index: 50;
}

@keyframes flash {
  from { opacity: 1; }
  to { opacity: 0; }
}
