/* =========================================================
   Premium Background Remover - Stylesheet
   ========================================================= */

:root {
  --bg: #fafafa;
  --card-bg: #ffffff;
  --accent: #7c3aed;
  --accent-dark: #6d28d9;
  --accent-light: #f5f3ff;
  --success: #16a34a;
  --success-dark: #15803d;
  --danger: #dc2626;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border-light: #eef0f3;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 16px 50px rgba(0, 0, 0, 0.12);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  background-image:
    radial-gradient(circle at 15% 10%, rgba(124, 58, 237, 0.06) 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(124, 58, 237, 0.05) 0%, transparent 45%);
  min-height: 100vh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.app-wrapper {
  width: 100%;
  max-width: 640px;
}

/* ---------------- Glass Card ---------------- */
.glass-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 44px;
  position: relative;
  overflow: hidden;
  animation: fadeScaleIn 0.5s ease;
  border: 1px solid rgba(255, 255, 255, 0.6);
}

@keyframes fadeScaleIn {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------------- Header ---------------- */
.app-icon {
  width: 76px;
  height: 76px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), #c084fc);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.3);
  color: #fff;
}

.app-icon svg {
  width: 38px;
  height: 38px;
}

.app-title {
  text-align: center;
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.app-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.98rem;
  margin-bottom: 34px;
  line-height: 1.5;
}

/* ---------------- Upload Zone ---------------- */
.upload-zone {
  border: 2px dashed #d7dce2;
  border-radius: var(--radius-sm);
  background: #fbfcfd;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-2px);
}

.upload-zone .upload-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  color: var(--accent);
  opacity: 0.85;
}

.upload-zone .upload-text {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.upload-zone .upload-subtext {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 18px;
}

.btn-choose {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: var(--transition);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.25);
}

.btn-choose:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.35);
}

.upload-meta {
  margin-top: 16px;
  font-size: 0.78rem;
  color: #9aa2ad;
}

/* ---------------- Processing Screen ---------------- */
.processing-screen {
  text-align: center;
  padding: 24px 0 8px;
}

.progress-circle-wrap {
  position: relative;
  width: 170px;
  height: 170px;
  margin: 0 auto 28px;
}

.progress-circle-wrap svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.progress-circle-bg {
  fill: none;
  stroke: #eef0f3;
  stroke-width: 10;
}

.progress-circle-fg {
  fill: none;
  stroke: url(#gradient-stroke);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease;
}

.progress-percent {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.1rem;
  font-weight: 800;
  color: var(--accent);
}

.progress-bar-track {
  width: 100%;
  height: 10px;
  background: #eef0f3;
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 18px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #c084fc);
  border-radius: 100px;
  width: 0%;
  transition: width 0.4s ease;
}

.processing-message {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  min-height: 24px;
  animation: fadeIn 0.3s ease;
}

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

.processing-subtext {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 6px;
}

/* ---------------- Result Screen ---------------- */
.result-screen {
  animation: fadeScaleIn 0.4s ease;
}

.preview-panel {
  margin-bottom: 20px;
}

/* A checkerboard pattern behind the cutout is the universal visual
   language for "this area is transparent" -- without it a transparent
   PNG preview would just look like a plain white box. */
.preview-checkerboard {
  border-radius: var(--radius-sm);
  overflow: hidden;
  background-image:
    linear-gradient(45deg, #e6e9ee 25%, transparent 25%),
    linear-gradient(-45deg, #e6e9ee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e6e9ee 75%),
    linear-gradient(-45deg, transparent 75%, #e6e9ee 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  background-color: #f8f9fb;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  max-height: 420px;
}

.preview-checkerboard canvas {
  max-width: 100%;
  max-height: 396px;
  width: auto;
  height: auto;
  display: block;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

/* ---------------- Background color picker ---------------- */
.bg-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 22px;
  padding: 14px;
  background: #f8f9fb;
  border-radius: var(--radius-sm);
}

.bg-color-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-right: 2px;
}

.bg-swatch,
.bg-swatch-custom {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #e6e9ee;
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: #fff;
}

.bg-swatch:hover,
.bg-swatch-custom:hover {
  transform: translateY(-1px);
}

.bg-swatch svg {
  width: 16px;
  height: 16px;
}

.bg-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.bg-swatch-custom {
  overflow: hidden;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
}

.bg-swatch-custom input[type="color"] {
  width: 140%;
  height: 140%;
  margin: -20%;
  border: none;
  cursor: pointer;
  background: none;
  padding: 0;
}

/* ---------------- Download Section ---------------- */
.download-section {
  border-top: 1px solid var(--border-light);
  margin-top: 4px;
  padding-top: 24px;
}

.download-label {
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 8px;
  display: block;
}

.download-filename-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid #e6e9ee;
  font-size: 0.95rem;
  margin-bottom: 16px;
  transition: var(--transition);
  background: #fbfcfd;
}

.download-filename-input:focus {
  outline: none;
  border-color: var(--success);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.1);
}

.btn-download {
  width: 100%;
  background: linear-gradient(135deg, var(--success), #22c55e);
  color: #fff;
  border: none;
  padding: 18px;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 8px 24px rgba(22, 163, 74, 0.3);
}

.btn-download:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(22, 163, 74, 0.4);
}

.btn-download:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-download svg {
  width: 20px;
  height: 20px;
}

.btn-compress-another {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.88rem;
  margin-top: 14px;
  padding: 10px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-compress-another:hover {
  color: var(--accent);
}

/* ---------------- Toast / Error Popup ---------------- */
.toast-container {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1080;
  width: min(420px, 90vw);
}

.toast-error {
  background: #fff;
  border-left: 4px solid var(--danger);
  border-radius: 14px;
  box-shadow: var(--shadow-hover);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translate(-50%, -16px); }
  to { opacity: 1; transform: translate(0, 0); }
}

.toast-error .toast-icon {
  color: var(--danger);
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-top: 1px;
}

.toast-error .toast-body {
  flex: 1;
}

.toast-error .toast-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.toast-error .toast-message {
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.toast-warning {
  border-left-color: #D97706;
}

.toast-warning .toast-icon {
  color: #D97706;
}

.toast-close {
  background: none;
  border: none;
  color: #9aa2ad;
  cursor: pointer;
  padding: 2px;
}

/* ---------------- Screen transitions ---------------- */
.screen {
  display: none;
}

.screen.active {
  display: block;
}

/* ---------------- Footer ---------------- */
.app-footer {
  text-align: center;
  margin-top: 22px;
  color: #b0b6bf;
  font-size: 0.78rem;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 576px) {
  .glass-card {
    padding: 32px 22px;
  }

  .app-title {
    font-size: 1.5rem;
  }

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

  .preview-checkerboard {
    max-height: 320px;
  }

  .preview-checkerboard canvas {
    max-height: 296px;
  }

  .bg-swatch,
  .bg-swatch-custom {
    width: 26px;
    height: 26px;
  }
}

/* ---------------- Accessibility ---------------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
.upload-zone:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
