/* ============================================
   DeepFace Face Analysis — Styles
   ============================================ */

:root {
  /* Colors */
  --bg: #0f0f13;
  --card: #1a1a24;
  --card-hover: #1f1f2b;
  --border: #2a2a3a;
  --border-hover: #3a3a4a;
  --accent: #7c5cfc;
  --accent2: #ff6b9d;
  --accent-glow: rgba(124, 92, 252, 0.4);
  --text: #e8e8f0;
  --text-secondary: #b8b8c8;
  --muted: #8888a0;
  --success: #4ade80;
  --error: #ff6b6b;
  --error-bg: rgba(255, 82, 82, 0.12);

  /* Spacing */
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition: 0.25s ease;
  --transition-slow: 0.4s ease;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 4px 30px rgba(124, 92, 252, 0.3);

  /* Typography */
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 2.2rem;
}

/* ============================================
   Global & Reset
   ============================================ */

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Focus styles for accessibility */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Skip to content for accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   Background Gradient
   ============================================ */

.bg-gradient {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(124, 92, 252, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 80% 50%, rgba(255, 107, 157, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 20% 80%, rgba(124, 92, 252, 0.1), transparent);
  pointer-events: none;
}

/* ============================================
   Header
   ============================================ */

header {
  text-align: center;
  padding: clamp(30px, 6vh, 50px) 20px 30px;
  animation: fadeInDown 0.6s ease-out;
}

.header-content {
  max-width: 600px;
  margin: 0 auto;
}

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

.logo-icon {
  width: 42px;
  height: 42px;
  color: var(--accent);
  filter: drop-shadow(0 0 20px var(--accent-glow));
  animation: logoFloat 3s ease-in-out infinite;
}

header h1 {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.tagline {
  color: var(--muted);
  font-size: var(--font-size-sm);
  max-width: 480px;
  margin: 0 auto;
}

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

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Container & Layout
   ============================================ */

.container {
  width: 100%;
  max-width: 1000px;
  padding: 0 20px 60px;
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 28px;
  animation: fadeIn 0.6s ease-out 0.1s both;
}

@media (max-width: 768px) {
  .container {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

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

/* ============================================
   Cards
   ============================================ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  height: fit-content;
}

.card:hover {
  border-color: var(--border-hover);
}

.card h2 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card h2 svg {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.icon-sm {
  flex-shrink: 0;
}

/* ============================================
   Upload Zone
   ============================================ */

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: clamp(32px, 5vw, 48px) 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  background: rgba(124, 92, 252, 0.02);
}

.upload-zone:hover,
.upload-zone:focus-visible {
  border-color: var(--accent);
  background: rgba(124, 92, 252, 0.08);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(124, 92, 252, 0.15);
  outline: none;
}

.upload-zone.drag-over {
  border-color: var(--accent2);
  background: rgba(255, 107, 157, 0.1);
  transform: scale(1.02);
}

.upload-zone input {
  display: none;
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.upload-icon {
  width: 64px;
  height: 64px;
  color: var(--muted);
  transition: color var(--transition), transform var(--transition);
}

.upload-zone:hover .upload-icon {
  color: var(--accent);
  transform: scale(1.1);
}

.upload-icon svg {
  width: 100%;
  height: 100%;
}

.upload-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.upload-title {
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--text);
}

.upload-hint {
  font-size: var(--font-size-sm);
  color: var(--muted);
}

.upload-hint span {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.upload-support {
  font-size: var(--font-size-xs);
  color: var(--muted);
  opacity: 0.8;
  margin-top: 4px;
}

/* ============================================
   Preview Area
   ============================================ */

.preview-area {
  display: none;
  position: relative;
  margin-top: 20px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  animation: fadeIn 0.3s ease;
}

.preview-area.active {
  display: block;
}

#preview-area canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
}

#preview-area img {
  display: none;
}

.btn-reset {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  backdrop-filter: blur(10px);
}

.btn-reset:hover {
  background: rgba(255, 82, 82, 0.8);
  border-color: var(--error);
  transform: scale(1.05);
}

.btn-reset svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 20px;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1), transparent);
  transform: translateX(-100%);
  transition: transform 0.5s;
}

.btn:hover::before {
  transform: translateX(100%);
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 4px 20px rgba(124, 92, 252, 0.25);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-icon {
  width: 20px;
  height: 20px;
}

/* ============================================
   Loading State
   ============================================ */

.loading-state {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  animation: fadeIn 0.3s ease;
}

.loading-state.active {
  display: flex;
}

.scan-animation {
  position: relative;
  width: 100px;
  height: 100px;
  margin-bottom: 24px;
}

.scan-face {
  width: 100%;
  height: 100%;
  color: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

.scan-face svg {
  width: 100%;
  height: 100%;
}

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

.scan-line {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent2), transparent);
  animation: scan 1.5s ease-in-out infinite;
  box-shadow: 0 0 15px var(--accent2);
}

@keyframes scan {
  0% { top: 0; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

.scan-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  position: absolute;
  bottom: -20px;
  left: 0;
  right: 0;
}

.scan-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.scan-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.scan-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1.2); opacity: 1; }
}

.loading-text {
  color: var(--muted);
  font-size: var(--font-size-sm);
  animation: fadePulse 1.5s ease-in-out infinite;
}

@keyframes fadePulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ============================================
   Error Message
   ============================================ */

.error-message {
  display: none;
  align-items: flex-start;
  gap: 12px;
  background: var(--error-bg);
  border: 1px solid rgba(255, 82, 82, 0.3);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 20px;
  animation: shake 0.4s ease;
}

.error-message.active {
  display: flex;
}

.error-icon {
  width: 20px;
  height: 20px;
  color: var(--error);
  flex-shrink: 0;
  margin-top: 2px;
}

.error-text {
  flex: 1;
  color: #ff9999;
  font-size: var(--font-size-sm);
  line-height: 1.5;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ============================================
   Results Panel
   ============================================ */

.results {
  display: none;
  opacity: 0;
  transform: translateY(10px);
}

.results.active {
  display: block;
  animation: fadeSlideUp 0.5s ease forwards;
}

@keyframes fadeSlideUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#facesContainer {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ============================================
   Face Card
   ============================================ */

.face-card {
  background: rgba(124, 92, 252, 0.06);
  border: 1px solid rgba(124, 92, 252, 0.2);
  border-radius: var(--radius);
  padding: 20px;
  transition: all var(--transition);
  animation: faceCardReveal 0.4s ease forwards;
  opacity: 0;
  transform: translateY(10px);
}

.face-card:hover {
  background: rgba(124, 92, 252, 0.1);
  border-color: rgba(124, 92, 252, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(124, 92, 252, 0.1);
}

@keyframes faceCardReveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.face-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(124, 92, 252, 0.15);
}

.face-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 50%;
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.face-confidence {
  font-size: var(--font-size-xs);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.confidence-bar {
  width: 60px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  background: var(--success);
  border-radius: 2px;
  transition: width 0.6s ease;
}

.face-card-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--accent);
}

.face-card-content {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

/* ============================================
   Result Items
   ============================================ */

.result-item {
  background: rgba(124, 92, 252, 0.06);
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: background var(--transition);
}

.result-item:hover {
  background: rgba(124, 92, 252, 0.12);
}

.result-item.large {
  grid-column: 1 / -1;
}

.result-label {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.result-label svg {
  width: 14px;
  height: 14px;
  opacity: 0.6;
}

.result-value {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.result-value.secondary {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-secondary);
}

.icon-inline {
  display: inline-flex;
  align-items: center;
}

.icon-inline svg {
  width: 100%;
  height: 100%;
}

/* ============================================
   Bar Charts
   ============================================ */

.bar-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(124, 92, 252, 0.1);
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--font-size-sm);
  opacity: 0;
  animation: barFadeIn 0.4s ease forwards;
}

.bar-name {
  width: 85px;
  text-align: right;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: capitalize;
}

.bar-track {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: 5px;
  width: 0;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transform: translateX(-100%);
  animation: barShimmer 2s ease-in-out infinite;
}

@keyframes barShimmer {
  to { transform: translateX(100%); }
}

.bar-val {
  width: 48px;
  text-align: right;
  color: var(--muted);
  font-weight: 500;
  font-size: var(--font-size-xs);
}

@keyframes barFadeIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============================================
   Footer
   ============================================ */

footer {
  margin-top: auto;
  padding: 30px 20px;
  text-align: center;
  animation: fadeIn 0.6s ease 0.2s both;
}

footer p {
  color: var(--muted);
  font-size: var(--font-size-xs);
}

footer a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

footer a:hover {
  color: var(--accent2);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
  header {
    padding: 24px 16px 20px;
  }

  .logo-icon {
    width: 36px;
    height: 36px;
  }

  header h1 {
    font-size: 1.75rem;
  }

  .card {
    padding: 20px;
  }

  .upload-zone {
    padding: 32px 16px;
  }

  .upload-icon {
    width: 48px;
    height: 48px;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .bar-name {
    width: 70px;
  }

  .face-card-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 16px 40px;
  }

  .card {
    padding: 16px;
  }

  .btn {
    padding: 12px 20px;
    font-size: var(--font-size-sm);
  }
}

/* ============================================
   Utilities
   ============================================ */

.full-width {
  grid-column: 1 / -1;
}

/* High contrast mode for accessibility */
@media (prefers-contrast: high) {
  :root {
    --border: #4a4a5a;
    --muted: #a0a0b0;
  }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
