:root {
  color-scheme: dark;
  --bg: #070a12;
  --panel: rgba(17, 24, 39, 0.78);
  --panel-strong: #111827;
  --line: rgba(148, 163, 184, 0.2);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #7c3aed;
  --accent-2: #a78bfa;
  --danger: #f87171;
  --success: #34d399;
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 0 0, rgba(124, 58, 237, 0.2), transparent 34rem),
    radial-gradient(circle at 100% 18%, rgba(14, 165, 233, 0.12), transparent 28rem), var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 2px 22px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(26px, 8vw, 42px);
  letter-spacing: -0.045em;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.privacy {
  flex: 0 0 auto;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--success);
  background: rgba(52, 211, 153, 0.07);
  font-size: 12px;
  font-weight: 800;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.upload {
  display: grid;
  place-items: center;
  min-height: 210px;
  margin-bottom: 14px;
  padding: 22px;
  border: 1.5px dashed rgba(167, 139, 250, 0.45);
  border-radius: var(--radius);
  background: rgba(124, 58, 237, 0.07);
  text-align: center;
  cursor: pointer;
  transition: 160ms ease;
}

.upload:active,
.upload.dragging {
  transform: scale(0.99);
  border-color: var(--accent-2);
  background: rgba(124, 58, 237, 0.14);
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  font-size: 28px;
  box-shadow: 0 12px 34px rgba(124, 58, 237, 0.35);
}

.upload strong {
  display: block;
  font-size: 18px;
}

.upload span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

#fileInput {
  display: none;
}

.workspace {
  display: none;
}

.workspace.active {
  display: block;
}

.preview-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 240px;
  max-height: 56dvh;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(45deg, #0b1020 25%, transparent 25%),
    linear-gradient(-45deg, #0b1020 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0b1020 75%),
    linear-gradient(-45deg, transparent 75%, #0b1020 75%), #0f172a;
  background-size: 20px 20px;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
}

#preview {
  display: block;
  max-width: 100%;
  max-height: calc(56dvh - 28px);
  border-radius: 12px;
  object-fit: contain;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

.meta {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 20px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.meta span {
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.72);
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 800;
  backdrop-filter: blur(10px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  padding: 18px;
}

.section-title {
  margin: 0 0 11px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dimension-grid {
  display: grid;
  grid-template-columns: 1fr 42px 1fr;
  gap: 10px;
  align-items: end;
}

label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.input-shell {
  display: flex;
  align-items: center;
  margin-top: 7px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.48);
}

.input-shell:focus-within {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.14);
}

input[type="number"] {
  width: 100%;
  min-width: 0;
  padding: 13px 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 17px;
  font-weight: 800;
}

.unit {
  margin-left: 8px;
  color: #64748b;
  font-size: 12px;
  font-weight: 900;
}

.lock {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(167, 139, 250, 0.35);
  border-radius: 13px;
  color: var(--accent-2);
  background: rgba(124, 58, 237, 0.1);
  font-size: 18px;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.preset {
  padding: 9px 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.68);
  font-size: 12px;
  font-weight: 900;
}

.format-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

select {
  width: 100%;
  margin-top: 7px;
  padding: 13px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: 0;
  color: var(--text);
  background: var(--panel-strong);
  font-weight: 800;
}

.quality-shell {
  margin-top: 7px;
  padding: 10px 12px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.48);
}

.quality-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

#qualityValue {
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-2);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1.8fr;
  gap: 10px;
  margin-top: 20px;
}

.button {
  min-height: 52px;
  padding: 12px 14px;
  border: 0;
  border-radius: 16px;
  font-weight: 950;
}

.button.secondary {
  border: 1px solid var(--line);
  color: #e2e8f0;
  background: rgba(30, 41, 59, 0.72);
}

.button.primary {
  color: white;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  box-shadow: 0 12px 30px rgba(124, 58, 237, 0.28);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

.status {
  min-height: 20px;
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--success);
}

footer {
  margin: 18px 0 0;
  color: #64748b;
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
}

@media (min-width: 640px) {
  .app {
    padding-inline: 22px;
  }

  .controls {
    padding: 22px;
  }
}
