/* Root Variables */
:root {
  --bg-primary: #0a0b10;
  --bg-secondary: #131520;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.08);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: #6d28d9;
  --accent-purple: #8b5cf6;
  --accent-cyan: #06b6d4;
  --accent-gold: #f59e0b;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --glass-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', 'Noto Sans KR', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.app-header {
  margin-bottom: 24px;
  text-align: center;
}

.logo-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.logo-area h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.sparkle-icon {
  font-size: 1.8rem;
  animation: sparkle-pulse 2s infinite ease-in-out;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 300;
}

/* Main Content Grid */
.main-content {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
  flex: 1;
  align-items: start;
}

@media (max-width: 968px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

/* Viewer Section (Left) */
.viewer-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 969px) {
  .viewer-section {
    position: sticky;
    top: 20px;
    height: max-content;
  }
}

.camera-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: #000;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--glass-glow);
  border: 1px solid var(--border-color);
}

#webcam {
  display: none; /* Hide original video element, we only draw to canvas */
}

#output-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror camera horizontally */
}

/* State Overlays */
.state-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 11, 16, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
  transition: opacity 0.3s ease;
}

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

/* Spinner Animation */
.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-left-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-subtext {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.permission-icon {
  font-size: 3rem;
}

/* Face warning overlay */
.face-warning {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(220, 38, 38, 0.85);
  backdrop-filter: blur(8px);
  padding: 8px 16px;
  border-radius: 30px;
  font-size: 0.9rem;
  color: #fff;
  z-index: 5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: pulse 1.5s infinite ease-in-out;
}

.face-warning.hidden {
  display: none;
}

/* Flash Screen */
.flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: white;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
}

.flash.active {
  animation: flash-animation 0.5s ease-out;
}

/* Camera Controls */
.camera-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  margin-top: 10px;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
  transform: translateY(-2px);
}

.capture-btn {
  background: #fff;
  border: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-smooth);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.capture-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 25px rgba(255, 255, 255, 0.8);
}

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

.inner-circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 3px solid var(--bg-primary);
  background-color: transparent;
  transition: var(--transition-smooth);
}

.capture-btn:hover .inner-circle {
  border-width: 4px;
}

/* Control Section (Right) */
.control-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.section-title h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.section-title p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Hat Grid */
.hat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.hat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.hat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.05), rgba(139, 92, 246, 0.05));
  opacity: 0;
  transition: var(--transition-smooth);
}

.hat-card:hover {
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-3px);
  background: var(--bg-card-hover);
}

.hat-card.active {
  border-color: var(--accent-purple);
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.2);
  background: rgba(139, 92, 246, 0.06);
}

.hat-card.active::before {
  opacity: 1;
}

.hat-thumbnail {
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  z-index: 1;
}

.hat-thumbnail img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
  transition: var(--transition-smooth);
}

.hat-card:hover .hat-thumbnail img {
  transform: scale(1.08);
}

.hat-info {
  text-align: center;
  z-index: 1;
}

.hat-info h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.country-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.hat-card.active .country-tag {
  color: var(--text-main);
  background: rgba(139, 92, 246, 0.2);
  border-color: rgba(139, 92, 246, 0.3);
}

/* Adjustments Panel */
.adjustments-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.adjustments-panel h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
  transition: var(--transition-smooth);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3);
  text-decoration: none;
  text-align: center;
  display: inline-block;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--text-muted);
}

/* Gallery Section */
.gallery-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gallery-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.gallery-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 0;
  min-height: 80px;
}

.gallery-list::-webkit-scrollbar {
  height: 6px;
}

.gallery-list::-webkit-scrollbar-track {
  background: transparent;
}

.gallery-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.no-images {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  padding: 20px 0;
}

.gallery-item {
  position: relative;
  width: 80px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition-smooth);
  flex-shrink: 0;
}

.gallery-item:hover {
  transform: scale(1.05);
  border-color: var(--accent-cyan);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Modals */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 11, 16, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: var(--transition-smooth);
}

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

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 24px;
  width: 90%;
  max-width: 500px;
  box-shadow: var(--glass-glow);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.close-btn {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition-smooth);
}

.close-btn:hover {
  color: var(--text-main);
}

.preview-img-container {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  aspect-ratio: 4 / 3;
  background-color: #000;
}

.preview-img-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Draw it mirrored to match the mirrored feed user saw! */
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.modal-actions .primary-btn {
  flex: 1;
}

.modal-actions .secondary-btn {
  flex: 1;
}

/* Footer */
.app-footer {
  text-align: center;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Animations */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

@keyframes sparkle-pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; filter: drop-shadow(0 0 8px var(--accent-cyan)); }
}

@keyframes flash-animation {
  0% { opacity: 1; }
  100% { opacity: 0; }
}
