/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-gradient: linear-gradient(135deg, #064e3b 0%, #0f2b1d 50%, #022c22 100%);
  --bg-card: rgba(255, 255, 255, 0.96);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #009b3a; /* Verde Brasil */
  --primary-dark: #007a2e;
  --accent: #fedf00; /* Amarelo Brasil */
  --blue-accent: #002776; /* Azul Brasil */
  --border: #e2e8f0;
  --border-active: #009b3a;
  --success: #10b981;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --radius: 20px;
  --radius-sm: 12px;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow-x: hidden;
}

/* Background Decorations (Brazil Glow) */
.bg-decorations {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
}

.orb-green {
  top: -10%;
  left: -10%;
  width: 320px;
  height: 320px;
  background: #009b3a;
}

.orb-yellow {
  top: 40%;
  right: -10%;
  width: 300px;
  height: 300px;
  background: #fedf00;
  opacity: 0.22;
}

.orb-blue {
  bottom: -10%;
  left: 20%;
  width: 350px;
  height: 350px;
  background: #002776;
  opacity: 0.4;
}

.flag-watermark {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.4;
}

.flag-watermark svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-container {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 28px;
  position: relative;
  z-index: 1;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: var(--shadow);
}

.header-icon {
  background: linear-gradient(135deg, #009b3a, #007a2e);
  color: #ffffff;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0, 155, 58, 0.35);
}

.header-text h1 {
  font-size: 1.18rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

.header-text p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Section Cards */
.section-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: all 0.2s ease;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-badge {
  background: linear-gradient(135deg, #009b3a, #007a2e);
  color: #ffffff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 155, 58, 0.3);
}

.step-badge-success {
  background: var(--success);
  color: #ffffff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.section-title h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

/* Mask Selector */
.mask-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mask-loading-placeholder {
  grid-column: span 2;
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.mask-option {
  position: relative;
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  transition: all 0.2s ease;
}

.mask-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mask-option:hover {
  border-color: #cbd5e1;
}

.mask-option.active {
  border-color: var(--primary);
  background: #f0fdf4;
  box-shadow: 0 0 0 2px rgba(0, 155, 58, 0.25);
}

.mask-preview-box {
  width: 100%;
  height: 64px;
  background: #0f172a;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 4px;
}

.mask-thumb {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.mask-label-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mask-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
}

.mask-status {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.mask-option.active .mask-status {
  color: var(--primary-dark);
  font-weight: 700;
}

/* Hidden File Inputs */
.hidden-file-input {
  position: fixed;
  top: -9999px;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

/* Upload Options Grid (2 Cards Perfeitos Lado a Lado) */
.upload-grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.upload-action-card {
  width: 100%;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  border: 2px solid var(--border);
  background: #f8fafc;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
  outline: none;
}

.upload-action-card:active {
  transform: scale(0.97);
}

.camera-card {
  background: linear-gradient(180deg, #ffffff 0%, #f0fdf4 100%);
  border-color: #bbf7d0;
}

.camera-card:hover {
  border-color: var(--primary);
  background: #dcfce7;
  box-shadow: 0 4px 12px rgba(0, 155, 58, 0.15);
}

.gallery-card {
  background: linear-gradient(180deg, #ffffff 0%, #eff6ff 100%);
  border-color: #bfdbfe;
}

.gallery-card:hover {
  border-color: #2563eb;
  background: #dbeafe;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.action-card-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.camera-icon {
  color: var(--primary-dark);
  background: #dcfce7;
}

.gallery-icon {
  color: #1d4ed8;
  background: #dbeafe;
}

.action-card-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.action-card-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
}

.action-card-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Preview Section */
.preview-wrapper, .result-wrapper {
  width: 100%;
  background: #000000;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.5);
}

.preview-container, .result-container {
  position: relative;
  width: 100%;
  max-height: 520px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
}

.preview-media, .result-media {
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
}

/* Safe Area Overlay Layer */
.preview-overlay-container {
  position: absolute;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.preview-overlay-container img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

/* Buttons */
.btn {
  width: 100%;
  padding: 15px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: all 0.2s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, #009b3a, #007a2e);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 155, 58, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #007a2e, #005c23);
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-share {
  background: linear-gradient(135deg, #002776, #001c54);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 39, 118, 0.3);
}

.btn-share:hover {
  background: linear-gradient(135deg, #001c54, #001238);
}

.action-buttons, .result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Progress Section */
.progress-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 8px;
  gap: 12px;
}

.spinner {
  width: 46px;
  height: 46px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary);
  border-right-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.progress-box h3 {
  font-size: 1.1rem;
  font-weight: 800;
}

.progress-box p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.progress-bar-container {
  width: 100%;
  height: 10px;
  background: #e2e8f0;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #009b3a, #fedf00);
  border-radius: 5px;
  transition: width 0.3s ease;
}

.progress-percentage {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--primary-dark);
}

/* Footer */
.app-footer {
  text-align: center;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.7);
  padding: 8px;
}

/* Download Progress Indicator */
.download-progress-box {
  width: 100%;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeIn 0.2s ease;
}

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

.download-bar-track {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.download-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #009b3a, #10b981);
  border-radius: 4px;
  transition: width 0.15s linear;
}

.download-status-text {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-align: center;
}

/* Helpers */
.hidden {
  display: none !important;
}
