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

:root {
  --font-body: 'Plus Jakarta Sans', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Space Grotesk', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;

  --bg-0: #f6f3eb;
  --bg-1: #efe7d8;
  --bg-2: #e9ddd0;
  --surface-1: rgba(255, 251, 243, 0.82);
  --surface-2: rgba(255, 255, 255, 0.9);
  --surface-solid: #fffaf2;

  --text-primary: #171722;
  --text-secondary: #52576a;
  --text-soft: #7f8496;

  --accent: #ee4f2a;
  --accent-strong: #d74422;
  --accent-soft: rgba(238, 79, 42, 0.14);
  --success: #137553;
  --warning: #a34b11;

  --border: rgba(23, 24, 34, 0.14);
  --border-strong: rgba(23, 24, 34, 0.24);

  --card-surface: var(--surface-1);
  --card-border: var(--border);

  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-xl: 30px;

  --shadow-xs: 0 1px 3px rgba(17, 18, 28, 0.08);
  --shadow-sm: 0 8px 20px rgba(17, 18, 28, 0.1);
  --shadow-md: 0 20px 45px rgba(17, 18, 28, 0.16);
  --shadow-lg: 0 36px 72px rgba(17, 18, 28, 0.22);

  --transition-fast: 160ms ease;
  --transition-base: 240ms ease;
  --transition-slow: 420ms ease;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  color: var(--text-primary);
  background:
    radial-gradient(circle at 5% 10%, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0) 42%),
    radial-gradient(circle at 95% 0%, rgba(238, 79, 42, 0.24), rgba(238, 79, 42, 0) 34%),
    linear-gradient(135deg, var(--bg-0), var(--bg-1) 46%, var(--bg-2));
  line-height: 1.5;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: '';
  position: fixed;
  pointer-events: none;
  z-index: -1;
  border-radius: 50%;
}

body::before {
  width: 460px;
  height: 460px;
  top: -210px;
  right: -130px;
  background: radial-gradient(circle at center, rgba(30, 38, 78, 0.15), rgba(30, 38, 78, 0));
}

body::after {
  width: 520px;
  height: 520px;
  bottom: -290px;
  left: -200px;
  background: radial-gradient(circle at center, rgba(238, 79, 42, 0.18), rgba(238, 79, 42, 0));
}

img,
canvas,
svg {
  max-width: 100%;
}

button,
input,
select,
label {
  font: inherit;
}

button {
  border: 0;
  background: none;
  color: inherit;
}

button,
label,
select,
input[type='range'] {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-main {
  width: min(1320px, calc(100% - 40px));
  margin: 24px auto 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 25;
  border-bottom: 1px solid var(--border);
  background: rgba(249, 245, 236, 0.78);
  backdrop-filter: blur(14px);
}

.header-inner {
  width: min(1320px, calc(100% - 40px));
  margin: 0 auto;
  padding: 16px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.app-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(24px, 2.3vw, 34px);
  letter-spacing: -0.03em;
  text-transform: uppercase;
}

.app-subtitle {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: clamp(12px, 1.1vw, 14px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ===== Upload Hero ===== */
.upload-section {
  min-height: clamp(560px, 73vh, 760px);
  position: relative;
  isolation: isolate;
}

.upload-hero {
  height: 100%;
  border: 1px solid rgba(23, 24, 34, 0.1);
  border-radius: var(--radius-xl);
  padding: clamp(22px, 4vw, 42px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: clamp(20px, 3vw, 38px);
  align-items: center;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.72), rgba(255, 248, 236, 0.82));
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.upload-hero::before,
.upload-hero::after {
  content: '';
  position: absolute;
  pointer-events: none;
  z-index: -1;
}

.upload-hero::before {
  width: 360px;
  height: 360px;
  top: -140px;
  left: -120px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(238, 79, 42, 0.22), rgba(238, 79, 42, 0));
}

.upload-hero::after {
  width: 330px;
  height: 330px;
  right: -120px;
  bottom: -130px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(23, 24, 34, 0.17), rgba(23, 24, 34, 0));
}

.upload-copy {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.upload-eyebrow {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(23, 24, 34, 0.08);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.upload-headline {
  font-family: var(--font-display);
  font-size: clamp(34px, 5.2vw, 62px);
  line-height: 0.96;
  letter-spacing: -0.045em;
  text-wrap: balance;
  max-width: 13ch;
}

.upload-lede {
  font-size: clamp(16px, 1.4vw, 20px);
  color: var(--text-secondary);
  max-width: 48ch;
}

.trust-points {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.trust-pill {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.56);
}

.upload-card-shell {
  width: 100%;
}

.upload-zone {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  background: var(--card-surface);
  box-shadow: var(--shadow-sm);
  min-height: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: clamp(24px, 3vw, 40px);
  cursor: pointer;
  transition:
    transform var(--transition-base),
    border-color var(--transition-base),
    box-shadow var(--transition-base),
    background var(--transition-base);
  backdrop-filter: blur(8px);
}

.upload-zone:hover,
.upload-zone.dragover {
  transform: translateY(-4px);
  border-color: rgba(238, 79, 42, 0.5);
  box-shadow: var(--shadow-md);
  background: var(--surface-2);
}

.upload-icon {
  color: var(--accent);
}

.upload-text {
  font-family: var(--font-display);
  font-size: clamp(22px, 2.2vw, 30px);
  font-weight: 600;
  letter-spacing: -0.02em;
  max-width: 16ch;
}

.upload-hint {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.upload-formats {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Shared Components ===== */
.btn-primary,
.btn-secondary,
.ratio-btn,
.preset-btn,
.format-btn,
.lock-btn,
.preset-select,
.size-input,
.preview-controls,
.image-info,
.control-section,
.preview-container {
  border: 1px solid var(--card-border);
  background: var(--card-surface);
  backdrop-filter: blur(8px);
}

.btn-primary,
.btn-secondary,
.btn-text,
.ratio-btn,
.preset-btn,
.format-btn,
.lock-btn {
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.btn-primary {
  width: 100%;
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #fff;
  border-color: rgba(0, 0, 0, 0);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 14px 26px rgba(215, 68, 34, 0.28);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(215, 68, 34, 0.34);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.btn-secondary:hover {
  border-color: rgba(238, 79, 42, 0.48);
  background: var(--accent-soft);
}

.btn-text {
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 6px 8px;
}

.btn-text:hover {
  color: var(--text-primary);
  background: rgba(23, 24, 34, 0.08);
}

/* ===== Workspace ===== */
.workspace {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  align-items: start;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-container {
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  min-height: clamp(320px, 62vh, 720px);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(155deg, rgba(8, 9, 16, 0.9), rgba(24, 25, 36, 0.92));
  box-shadow: var(--shadow-sm);
}

.preview-container.show-transparency {
  background-image:
    linear-gradient(45deg, rgba(250, 250, 250, 0.2) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(250, 250, 250, 0.2) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(250, 250, 250, 0.2) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(250, 250, 250, 0.2) 75%),
    linear-gradient(155deg, rgba(8, 9, 16, 0.92), rgba(24, 25, 36, 0.96));
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0, 0 0;
}

#preview-canvas {
  display: block;
  cursor: grab;
  touch-action: none;
}

#preview-canvas:active {
  cursor: grabbing;
}

.preview-controls {
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-xs);
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.zoom-control label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-secondary);
}

#zoom-slider,
#quality-slider {
  flex: 1;
  accent-color: var(--accent);
  height: 5px;
}

#zoom-value {
  min-width: 42px;
  text-align: right;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 13px;
}

.image-info {
  border-radius: var(--radius-md);
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
}

.image-info span {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
  font-size: 13px;
}

#file-name-display {
  color: var(--text-primary);
  font-weight: 700;
}

.image-info .btn-text {
  margin-left: auto;
  white-space: nowrap;
}

/* ===== Controls ===== */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control-section {
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-xs);
}

.download-section {
  position: relative;
}

.section-title {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 15px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.aspect-ratio-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.ratio-btn {
  border-radius: 10px;
  padding: 9px 4px;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-primary);
}

.ratio-btn:hover {
  border-color: rgba(238, 79, 42, 0.42);
  background: var(--accent-soft);
}

.ratio-btn.active {
  color: #fff;
  border-color: rgba(0, 0, 0, 0);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.custom-ratio-control {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(247, 240, 236, 0.88));
}

.custom-ratio-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.custom-ratio-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.custom-ratio-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.92);
}

.custom-ratio-input:focus {
  outline: none;
  border-color: rgba(238, 79, 42, 0.42);
  box-shadow: 0 0 0 3px rgba(238, 79, 42, 0.12);
}

.custom-ratio-suffix {
  flex-shrink: 0;
  min-width: 38px;
  padding: 10px 0;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.custom-ratio-help {
  margin-top: 8px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.4;
}

.preset-section {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
}

.preset-section-title {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.preset-select {
  width: 100%;
  border-radius: 10px;
  padding: 10px 36px 10px 12px;
  color: var(--text-primary);
  font-size: 14px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%), linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 20px) calc(50% - 3px), calc(100% - 14px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.preset-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.preset-btn {
  border-radius: 10px;
  text-align: left;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preset-btn:hover {
  border-color: rgba(238, 79, 42, 0.42);
}

.preset-btn.active {
  border-color: rgba(0, 0, 0, 0);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.preset-btn.active .preset-label,
.preset-btn.active .preset-dims {
  color: #fff;
}

.preset-label {
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.preset-dims {
  color: var(--text-secondary);
  font-size: 11px;
}

#reset-presets-btn {
  margin-top: 8px;
}

.size-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.size-input-group {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.size-input-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.size-input {
  width: 100%;
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text-primary);
  font-size: 14px;
  -moz-appearance: textfield;
  appearance: textfield;
}

.size-input::-webkit-inner-spin-button,
.size-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.unit {
  color: var(--text-soft);
  font-size: 12px;
}

.lock-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.lock-btn:hover {
  color: var(--accent);
  border-color: rgba(238, 79, 42, 0.46);
}

.lock-btn.locked {
  color: #fff;
  border-color: rgba(0, 0, 0, 0);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.warning-text {
  margin-top: 9px;
  font-size: 12px;
  color: var(--warning);
  font-weight: 600;
}

#remove-bg-btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.bg-removal-progress {
  margin-top: 12px;
}

.progress-bar-track {
  border-radius: 999px;
  overflow: hidden;
  height: 7px;
  background: rgba(23, 24, 34, 0.1);
}

.progress-bar-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #f0775c);
  transition: width var(--transition-base);
}

.progress-text {
  margin-top: 7px;
  font-size: 12px;
  color: var(--text-secondary);
}

.bg-toggle-container {
  margin-top: 11px;
  display: grid;
  gap: 8px;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.toggle-label input[type='checkbox'] {
  display: none;
}

.toggle-switch {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: rgba(23, 24, 34, 0.2);
  position: relative;
  transition: background var(--transition-fast);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  left: 2px;
  top: 2px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform var(--transition-fast);
}

.toggle-label input:checked + .toggle-switch {
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
}

.toggle-label input:checked + .toggle-switch::after {
  transform: translateX(18px);
}

.format-selector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.format-btn {
  border-radius: 10px;
  padding: 10px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.format-btn:hover {
  border-color: rgba(238, 79, 42, 0.42);
  background: var(--accent-soft);
}

.format-btn.active {
  color: #fff;
  border-color: rgba(0, 0, 0, 0);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.quality-control {
  margin-top: 14px;
}

.quality-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.quality-header label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}

#quality-value {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 700;
}

.estimated-size {
  display: block;
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}

.download-filename {
  margin-top: 8px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  word-break: break-word;
}

/* ===== Footer ===== */
.app-footer {
  width: min(1320px, calc(100% - 40px));
  margin: 24px auto 20px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 253, 246, 0.66);
  color: var(--text-secondary);
  text-align: center;
  font-size: 13px;
  box-shadow: var(--shadow-xs);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  right: 16px;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  min-width: 220px;
  max-width: min(360px, calc(100vw - 32px));
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow-lg);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.12);
  animation: toast-in var(--transition-base) forwards;
}

.toast.info {
  background: #242738;
}

.toast.error {
  background: #b4232f;
}

.toast.warning {
  color: #261708;
  background: #f7a95f;
}

.toast.fade-out {
  animation: toast-out var(--transition-fast) forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

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

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .upload-hero {
    grid-template-columns: minmax(0, 1fr) minmax(290px, 450px);
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 350px;
  }
}

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

  .upload-copy {
    max-width: none;
  }

  .upload-headline {
    max-width: 14ch;
  }

  .upload-zone {
    min-height: 360px;
  }

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

  .preview-container {
    min-height: 380px;
  }
}

@media (max-width: 700px) {
  .app-main,
  .header-inner,
  .app-footer {
    width: calc(100% - 24px);
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 0;
  }

  .upload-section {
    min-height: auto;
  }

  .upload-hero {
    padding: 18px;
    border-radius: var(--radius-lg);
  }

  .upload-headline {
    font-size: clamp(28px, 11vw, 44px);
  }

  .upload-lede {
    font-size: 15px;
  }

  .trust-pill {
    font-size: 12px;
    padding: 7px 11px;
  }

  .upload-zone {
    min-height: 320px;
    padding: 22px;
  }

  .controls-panel {
    gap: 12px;
  }

  .control-section {
    padding: 14px;
  }

  .preview-container {
    min-height: 300px;
  }

  .size-inputs {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .lock-btn {
    width: 100%;
    height: 36px;
  }

  .image-info {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .image-info .btn-text {
    margin-left: 0;
    width: fit-content;
  }

  .toast-container {
    right: 10px;
    left: 10px;
    top: auto;
    bottom: calc(10px + var(--safe-bottom));
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 600px) {
  .app-main {
    width: calc(100% - 16px);
    margin-top: 12px;
    gap: 12px;
  }

  .header-inner {
    width: calc(100% - 16px);
  }

  .upload-section {
    min-height: auto;
  }

  .upload-hero {
    padding: 14px;
    gap: 12px;
    border-radius: var(--radius-md);
  }

  .upload-copy {
    gap: 10px;
  }

  .upload-headline {
    font-size: clamp(24px, 8.4vw, 32px);
    max-width: 14ch;
  }

  .upload-lede {
    font-size: 14px;
  }

  .trust-points {
    gap: 6px;
  }

  .trust-pill {
    font-size: 11px;
    padding: 6px 10px;
  }

  .upload-zone {
    min-height: clamp(220px, 42svh, 300px);
    padding: 18px;
    gap: 10px;
  }

  .upload-text {
    font-size: clamp(18px, 6.5vw, 24px);
  }

  .workspace {
    gap: 12px;
  }

  .preview-panel {
    gap: 10px;
  }

  .preview-container {
    min-height: clamp(220px, 42svh, 300px);
  }

  .preview-controls,
  .image-info {
    padding: 10px 11px;
  }

  .zoom-control {
    gap: 8px;
  }

  .controls-panel {
    gap: 10px;
    padding-bottom: calc(86px + var(--safe-bottom));
  }

  .control-section {
    padding: 12px;
  }

  .download-section {
    position: sticky;
    bottom: calc(8px + var(--safe-bottom));
    z-index: 20;
    border-color: rgba(23, 24, 34, 0.22);
    box-shadow: 0 14px 26px rgba(17, 18, 28, 0.16);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
  }

  .download-section .btn-primary {
    min-height: 46px;
  }

  .ratio-btn,
  .format-btn,
  .preset-btn,
  .lock-btn,
  .size-input,
  .custom-ratio-input,
  .preset-select,
  .btn-secondary {
    min-height: 44px;
  }

  .btn-text {
    min-height: 40px;
  }

  .size-inputs {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .lock-btn {
    width: 100%;
  }

  .format-selector {
    gap: 6px;
  }

  .app-footer {
    width: calc(100% - 16px);
    margin: 12px auto calc(12px + var(--safe-bottom));
    padding: 12px 14px;
  }

  .toast-container {
    right: 8px;
    left: 8px;
    bottom: calc(8px + var(--safe-bottom));
  }
}

@media (max-width: 430px) {
  .aspect-ratio-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .custom-ratio-input-wrap {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .custom-ratio-suffix {
    width: 100%;
    min-width: 0;
    padding: 0;
    text-align: left;
  }

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

  .format-selector {
    grid-template-columns: 1fr;
  }
}

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

  .upload-zone:hover,
  .btn-primary:hover {
    transform: none;
  }
}
