/* CSS Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Reduce CLS by reserving space */
img {
  aspect-ratio: attr(width) / attr(height);
}

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #1e293b;
  --text: #334155;
  --text-light: #64748b;
  --text-dark: #0f172a;
  --bg: #ffffff;
  --bg-alt: #f8fafc;
  --bg-dark: #f1f5f9;
  --border: #e2e8f0;
  --success: #22c55e;
  --error: #ef4444;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

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

a:hover {
  color: var(--primary-dark);
}

img {
  max-width: 100%;
  height: auto;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-dark);
  line-height: 1.3;
  margin-bottom: 1rem;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.25rem; }

p { margin-bottom: 1rem; }

ul, ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

li { margin-bottom: 0.5rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: var(--bg-dark);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--text-dark);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: white;
}

/* Header */
.header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 70px;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.logo:hover {
  color: var(--primary);
}

.nav-links {
  display: flex;
  align-items: center;
  list-style: none;
  gap: 32px;
  margin: 0;
  padding: 0;
}

.nav-links li {
  margin-bottom: 0;
}

.nav-links a {
  color: var(--text);
  font-weight: 500;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--primary);
}

/* Hero Section */
.hero {
  padding: 42px 0 80px;
  background: linear-gradient(180deg, var(--bg-alt) 0%, var(--bg) 100%);
}

.hero h1 {
  text-align: center;
  margin-bottom: 16px;
}

.hero-subtitle {
  text-align: center;
  font-size: 1.25rem;
  color: var(--text-light);
  max-width: 600px;
  margin: 0 auto 40px;
}

/* Upload Area */
.upload-area {
  max-width: 600px;
  margin: 0 auto;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 60px 40px;
  text-align: center;
  background: var(--bg);
  transition: all var(--transition);
  cursor: pointer;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.05);
}

.upload-icon {
  color: var(--text-light);
  margin-bottom: 20px;
}

.upload-text {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 8px;
}

.upload-or {
  color: var(--text-light);
  margin-bottom: 16px;
}

.upload-hint {
  font-size: 0.875rem;
  color: var(--text-light);
  margin-top: 16px;
  margin-bottom: 0;
}

/* Preview Area */
.preview-area {
  max-width: 600px;
  margin: 0 auto;
  text-align: center;
  padding-bottom: 40px;
}

.preview-image-container {
  margin-bottom: 24px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: var(--bg-alt);
}

.preview-image-container img {
  max-height: 350px;
  width: auto;
  display: block;
  margin: 0 auto;
}

.preview-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}

/* Loading Area */
.loading-area {
  max-width: 600px;
  margin: 0 auto;
  text-align: center;
  padding: 60px 40px;
}

.spinner {
  width: 60px;
  height: 60px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 24px;
}

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

.loading-timer {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

.loading-hint {
  font-size: 0.875rem;
  color: var(--text-light);
}

/* Sections */
.section {
  padding: 0 0 48px;
  /* Improve rendering performance for below-fold sections */
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

.section h2 {
  padding-top: 30px;
}

.section-alt {
  background: var(--bg-alt);
}

.section-intro {
  font-size: 1.125rem;
  color: var(--text-light);
  max-width: 800px;
  margin-bottom: 48px;
}

/* Steps Grid */
.steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 32px;
}

.step {
  text-align: center;
  padding: 32px;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.step-number {
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 auto 20px;
}

.step h3 {
  margin-bottom: 12px;
}

.step p {
  color: var(--text-light);
  margin-bottom: 0;
}

/* Features Grid */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 32px;
}

.feature {
  padding: 32px;
  background: var(--bg-alt);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.feature-icon {
  width: 56px;
  height: 56px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.feature h3 {
  margin-bottom: 12px;
}

.feature p {
  color: var(--text-light);
  margin-bottom: 0;
}

/* Feature List */
.feature-list {
  display: grid;
  gap: 32px;
}

.feature-item {
  padding: 32px;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.feature-item h3 {
  color: var(--primary);
  margin-bottom: 12px;
}

.feature-item p {
  color: var(--text);
  margin-bottom: 0;
}

/* FAQ */
.faq-list {
  display: grid;
  gap: 32px;
  max-width: 800px;
}

.faq-item {
  padding: 16px 20px;
  background: var(--bg-alt);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.faq-item h3 {
  color: var(--text-dark);
  margin: 0 0 8px 0;
  font-size: 1.125rem;
}

.faq-item p {
  color: var(--text);
  margin-bottom: 0;
}

.cta-text {
  font-size: 1.125rem;
  margin-top: 48px;
}

/* FAQ Full Page */
.faq-full {
  max-width: 800px;
}

.faq-category {
  margin-bottom: 48px;
}

.faq-category .faq-item {
  margin-bottom: 24px;
}

.faq-category .faq-item:last-child {
  margin-bottom: 0;
}

.faq-category h2 {
  color: var(--primary);
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}

.faq-cta {
  text-align: center;
  padding: 32px;
  background: var(--bg-alt);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: 48px;
}

.faq-cta h2 {
  color: var(--text-dark);
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.faq-cta p {
  color: var(--text-light);
  margin-bottom: 0;
}

.faq-cta a {
  color: var(--primary);
  font-weight: 600;
}

/* Page Hero */
.page-hero {
  padding: 42px 0 0;
  background: linear-gradient(180deg, var(--bg-alt) 0%, var(--bg) 100%);
  text-align: center;
}

.page-hero h1 {
  margin-bottom: 12px;
}

/* Content Pages */
.content-page {
  max-width: 800px;
}

.content-page h2 {
  margin-top: 48px;
  margin-bottom: 16px;
  color: var(--primary);
}

.content-page h2:first-child {
  margin-top: 0;
}

.content-page h3 {
  margin-top: 32px;
  margin-bottom: 12px;
}

.content-page .faq-item h3 {
  margin-top: 0;
}

.legal-page h2 {
  font-size: 1.5rem;
}

.legal-page h3 {
  font-size: 1.125rem;
  color: var(--text-dark);
}

/* Result Section */
.result-section {
  padding: 42px 0;
}

.result-section h1 {
  text-align: center;
  margin-bottom: 8px;
}

.result-subtitle {
  text-align: center;
  font-size: 1.25rem;
  color: var(--text-light);
  margin-bottom: 40px;
}

.comparison-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 32px;
  max-width: 900px;
  margin: 0 auto 40px;
}

.comparison-item {
  text-align: center;
}

.comparison-item h3 {
  margin-bottom: 16px;
  color: var(--text-light);
  font-weight: 500;
}

.image-wrapper {
  background: var(--bg-alt);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.image-wrapper img {
  display: block;
  width: 100%;
  height: auto;
}

.result-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.try-again {
  text-align: center;
}

/* Share image container */
.share-image-container {
  max-width: 800px;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.share-image-container img {
  display: block;
  width: 100%;
  height: auto;
}

/* Error Section */
.error-section {
  padding: 120px 0;
  text-align: center;
}

.error-content h1 {
  font-size: 8rem;
  color: var(--primary);
  margin-bottom: 0;
  line-height: 1;
}

.error-content h2 {
  margin-bottom: 16px;
}

.error-content p {
  color: var(--text-light);
  margin-bottom: 8px;
}

.error-content .btn {
  margin-top: 24px;
}

/* Footer */
.footer {
  background: var(--secondary);
  color: var(--bg-dark);
  padding: 60px 0 24px;
  margin-top: auto;
  /* Improve rendering performance for footer */
  content-visibility: auto;
  contain-intrinsic-size: auto 300px;
}

.footer-content {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 48px;
  margin-bottom: 48px;
}

.footer-brand .logo {
  color: white;
  display: inline-block;
  margin-bottom: 16px;
}

.footer-brand p {
  color: var(--text-light);
  max-width: 300px;
}

.footer-links h4 {
  color: white;
  font-size: 1rem;
  margin-bottom: 16px;
}

.footer-links ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.footer-links li {
  margin-bottom: 8px;
}

.footer-links a {
  color: var(--text-light);
}

.footer-links a:hover {
  color: white;
}

.footer-bottom {
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.footer-bottom p {
  color: var(--text-light);
  margin: 0;
  font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }

  .nav-links {
    gap: 20px;
  }

  .hero {
    padding: 28px 0 60px;
  }

  .upload-area {
    padding: 40px 24px;
  }

  .section {
    padding: 60px 0;
  }

  .features-grid,
  .steps-grid {
    grid-template-columns: 1fr;
  }

  .footer-content {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .result-actions {
    flex-direction: column;
    align-items: center;
  }

  .result-actions .btn {
    width: 100%;
    max-width: 300px;
  }

  .error-content h1 {
    font-size: 5rem;
  }
}

@media (max-width: 480px) {
  .nav-links {
    gap: 16px;
    font-size: 0.875rem;
  }

  .logo {
    font-size: 1.25rem;
  }

  .preview-actions {
    flex-direction: column;
  }

  .preview-actions .btn {
    width: 100%;
  }
}

/* Language Selector */
.lang-selector {
  position: relative;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  font-size: 0.875rem;
  line-height: 1;
  transition: all var(--transition);
}

.lang-btn svg {
  display: block;
  flex-shrink: 0;
}

.lang-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.lang-btn .chevron {
  transition: transform var(--transition);
}

.lang-btn[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.lang-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  list-style: none;
  padding: 8px 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all var(--transition);
  z-index: 100;
}

.lang-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-dropdown li {
  margin: 0;
}

.lang-dropdown a {
  display: block;
  padding: 8px 16px;
  color: var(--text);
  font-size: 0.875rem;
  transition: background var(--transition);
}

.lang-dropdown a:hover {
  background: var(--bg-alt);
  color: var(--primary);
}

.lang-dropdown a.active {
  background: var(--bg-alt);
  color: var(--primary);
  font-weight: 600;
}

/* RTL Support */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] ul,
[dir="rtl"] ol {
  padding-left: 0;
  padding-right: 1.5rem;
}

[dir="rtl"] .nav-links {
  flex-direction: row-reverse;
}

[dir="rtl"] .lang-dropdown {
  right: auto;
  left: 0;
}

[dir="rtl"] .footer-content {
  direction: rtl;
}

[dir="rtl"] .feature-icon {
  margin-left: 0;
  margin-right: 0;
}

[dir="rtl"] .btn svg {
  order: 1;
}

[dir="rtl"] .logo-icon {
  margin-left: 8px;
  margin-right: 0;
}

@media (max-width: 768px) {
  .lang-btn span {
    display: none;
  }

  .lang-btn {
    padding: 6px 8px;
  }

  .lang-dropdown {
    right: -20px;
  }

  [dir="rtl"] .lang-dropdown {
    left: -20px;
    right: auto;
  }
}
