:root {
  color-scheme: dark;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Robust Dark Theme Palette (Consistent across Telegram & Web) */
  --bg-color: #0f172a;
  --secondary-bg-color: #1e293b;
  --text-color: #f8fafc;
  --hint-color: #94a3b8;
  --link-color: #38bdf8;
  --button-color: #3b82f6;
  --button-text-color: #ffffff;
  --header-bg-color: #0f172a;
  --section-bg-color: #1e293b;

  --primary-gradient: linear-gradient(135deg, #3b82f6 0%, #6366f1 50%, #8b5cf6 100%);
  --card-bg: rgba(30, 41, 59, 0.75);
  --card-border: rgba(255, 255, 255, 0.09);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

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

html, body {
  background-color: var(--bg-color) !important;
  color: var(--text-color) !important;
  font-family: var(--font-family);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#root, .app-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(var(--safe-bottom) + 24px);
  position: relative;
  background-color: var(--bg-color);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 16px 0;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 20px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 38px; height: 38px; border-radius: var(--radius-sm); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
.brand-title {
  font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.user-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--secondary-bg-color); padding: 6px 12px;
  border-radius: var(--radius-full); font-size: 0.8rem;
  color: var(--hint-color); border: 1px solid var(--card-border);
}

.lang-switch-wrap {
  display: flex; align-items: center; position: relative;
}
.lang-select {
  background: var(--secondary-bg-color); color: #93c5fd; border: 1px solid var(--card-border);
  padding: 5px 8px; border-radius: var(--radius-full); font-size: 0.78rem; font-weight: 700;
  cursor: pointer; outline: none; transition: border-color 0.15s ease;
}
.lang-select:focus, .lang-select:hover {
  border-color: #3b82f6;
}
.lang-select option {
  background: #1e293b; color: #ffffff;
}

.guarantee-banner {
  display: flex; align-items: center; gap: 10px;
  background: rgba(59, 130, 246, 0.12); border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-md); padding: 12px 14px; margin-bottom: 20px;
  font-size: 0.85rem; color: #93c5fd;
}

.screen-content {
  display: flex; flex-direction: column; flex: 1;
  animation: fadeIn 0.25s ease-out;
}

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

.hero-section { text-align: center; padding: 24px 12px 32px 12px; }
.hero-title {
  font-size: 1.75rem; font-weight: 800; line-height: 1.25; letter-spacing: -0.03em;
  margin-bottom: 12px; background: linear-gradient(135deg, #ffffff 0%, #94a3b8 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.hero-subtitle { font-size: 0.95rem; color: var(--hint-color); max-width: 440px; margin: 0 auto 28px auto; }

.upload-zone {
  border: 2px dashed rgba(59, 130, 246, 0.45);
  background: rgba(30, 41, 59, 0.55); backdrop-filter: blur(12px);
  border-radius: var(--radius-lg); padding: 36px 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s ease;
}
.upload-zone:hover, .upload-zone.active {
  border-color: #60a5fa; background: rgba(59, 130, 246, 0.12); transform: translateY(-2px);
}

.upload-icon-wrapper {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--primary-gradient); display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px; box-shadow: 0 8px 24px rgba(59, 130, 246, 0.35);
}

.btn-primary-add {
  background: var(--primary-gradient); color: #ffffff !important; border: none;
  font-size: 1.05rem; font-weight: 600; padding: 14px 28px;
  border-radius: var(--radius-full); display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
  transition: all 0.15s ease; margin-bottom: 12px;
}
.btn-primary-add:active { transform: scale(0.97); }
.upload-limit-note { font-size: 0.85rem; color: var(--hint-color); }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title { font-size: 1.1rem; font-weight: 700; color: #ffffff; }

.images-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px; margin-bottom: 24px;
}

.image-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-md); padding: 12px; display: flex;
  align-items: center; gap: 12px; backdrop-filter: blur(8px);
}

.image-thumbnail-wrap {
  width: 64px; height: 64px; border-radius: var(--radius-sm); overflow: hidden;
  background: #0f172a; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.image-thumbnail { width: 100%; height: 100%; object-fit: cover; }
.image-details { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.image-filename { font-size: 0.9rem; font-weight: 600; color: #ffffff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 4px; }
.image-meta-row { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--hint-color); }
.format-badge { background: rgba(59, 130, 246, 0.2); color: #60a5fa; font-weight: 600; padding: 2px 6px; border-radius: 4px; font-size: 0.72rem; }

.btn-remove {
  background: rgba(239, 68, 68, 0.15); color: #f87171; border: none;
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.15s ease;
}
.btn-remove:hover { background: #ef4444; color: #ffffff; }

.action-cards-container { display: flex; flex-direction: column; gap: 16px; margin-top: 12px; }
.action-card {
  background: var(--card-bg); border: 1.5px solid var(--card-border);
  border-radius: var(--radius-lg); padding: 24px 20px; display: flex;
  align-items: center; gap: 18px; cursor: pointer; transition: all 0.2s ease;
}
.action-card:hover { border-color: #3b82f6; background: rgba(59, 130, 246, 0.1); transform: translateY(-2px); }
.action-card-icon {
  width: 52px; height: 52px; border-radius: var(--radius-md);
  background: rgba(59, 130, 246, 0.2); color: #60a5fa; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.action-card-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 4px; color: #ffffff; }
.action-card-desc { font-size: 0.85rem; color: var(--hint-color); line-height: 1.4; }

.options-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 20px 0 28px 0; }
.option-btn {
  background: var(--card-bg); border: 1.5px solid var(--card-border);
  border-radius: var(--radius-md); padding: 18px 12px; font-size: 1.1rem;
  font-weight: 700; color: #ffffff; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px; transition: all 0.15s ease;
}
.option-btn:hover { border-color: rgba(59, 130, 246, 0.5); }
.option-btn.selected { background: rgba(59, 130, 246, 0.25); border-color: #3b82f6; box-shadow: 0 0 16px rgba(59, 130, 246, 0.35); }
.option-subtext { font-size: 0.75rem; font-weight: 400; color: var(--hint-color); }

.conversion-preview-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.conversion-preview-row {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(15, 23, 42, 0.65); padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 0.82rem; border: 1px solid var(--card-border); color: #f8fafc;
}
.status-chip { font-size: 0.72rem; font-weight: 600; padding: 3px 8px; border-radius: var(--radius-full); }
.status-chip.change { background: rgba(59, 130, 246, 0.25); color: #93c5fd; }
.status-chip.unchanged { background: rgba(100, 116, 139, 0.25); color: #94a3b8; }

.processing-box {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-lg); padding: 32px 20px; text-align: center; margin-bottom: 24px;
}
.processing-spinner {
  width: 54px; height: 54px; border: 4px solid rgba(59, 130, 246, 0.2);
  border-top-color: #3b82f6; border-radius: 50%; animation: spin 0.9s linear infinite; margin: 0 auto 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-bar-wrap {
  width: 100%; height: 10px; background: rgba(15, 23, 42, 0.8);
  border-radius: var(--radius-full); overflow: hidden; margin: 18px 0 10px 0;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4); position: relative;
}
.progress-bar-fill {
  height: 100%; background: linear-gradient(90deg, #3b82f6 0%, #6366f1 50%, #8b5cf6 100%);
  border-radius: var(--radius-full); transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative; overflow: hidden;
}
.progress-bar-fill::after {
  content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.35) 50%, rgba(255, 255, 255, 0) 100%);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

.status-chip.pulse {
  animation: pulseChip 1.2s infinite ease-in-out;
  background: rgba(59, 130, 246, 0.35); color: #bfdbfe;
}
@keyframes pulseChip { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.65; transform: scale(0.96); } }

.result-cards { display: flex; flex-direction: column; gap: 14px; margin-bottom: 24px; }
.result-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-md); padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.result-header { display: flex; align-items: center; justify-content: space-between; }
.result-title { font-size: 0.92rem; font-weight: 600; color: #ffffff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

.result-stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  background: rgba(15, 23, 42, 0.5); padding: 10px; border-radius: var(--radius-sm); text-align: center;
}
.stat-item { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 0.7rem; color: var(--hint-color); text-transform: uppercase; }
.stat-val { font-size: 0.85rem; font-weight: 700; color: #ffffff; }
.stat-val.saved { color: var(--success-color); }

.resolution-guarantee-tag {
  display: inline-flex; align-items: center; gap: 4px; font-size: 0.74rem;
  color: #34d399; background: rgba(16, 185, 129, 0.15); padding: 3px 8px; border-radius: var(--radius-full);
}

.warning-alert {
  font-size: 0.78rem; color: #fbbf24; background: rgba(245, 158, 11, 0.15);
  padding: 6px 10px; border-radius: var(--radius-sm); border-left: 3px solid #f59e0b;
}

.button-row { display: flex; gap: 12px; margin-top: auto; }
.btn-primary {
  flex: 1; background: var(--primary-gradient); color: #ffffff !important; border: none;
  font-size: 1rem; font-weight: 600; padding: 14px 20px; border-radius: var(--radius-md);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-secondary {
  background: var(--secondary-bg-color); color: #f8fafc; border: 1px solid var(--card-border);
  font-size: 1rem; font-weight: 600; padding: 14px 20px; border-radius: var(--radius-md);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-download-single {
  background: rgba(59, 130, 246, 0.25); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.35);
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 0.82rem; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn-download-single:hover { background: #3b82f6; color: #ffffff; }

.batch-card-header {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(59, 130, 246, 0.12); border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 12px 14px; border-radius: var(--radius-md); margin-bottom: 16px;
}
.batch-btn-group { display: flex; gap: 8px; }
.btn-batch-small {
  background: var(--primary-gradient); color: #ffffff !important; border: none;
  font-size: 0.8rem; font-weight: 600; padding: 8px 14px; border-radius: var(--radius-full);
  cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.btn-batch-small.zip {
  background: var(--secondary-bg-color); border: 1px solid var(--card-border); color: #93c5fd !important;
}

.toast-container { position: fixed; bottom: calc(var(--safe-bottom) + 20px); left: 50%; transform: translateX(-50%); z-index: 1000; width: 90%; max-width: 440px; }
.toast {
  background: #1e293b; color: #ffffff; border: 1px solid var(--card-border);
  padding: 12px 16px; border-radius: var(--radius-md); display: flex; align-items: center; gap: 10px; font-size: 0.88rem;
}
.toast.error { border-color: #ef4444; background: #2c1518; }
.toast.warning { border-color: #f59e0b; background: #2b2210; }
.toast.success { border-color: #10b981; background: #132822; }
