:root {
  color-scheme: light;
  --bg: #f4f1eb;
  --ink: #161616;
  --muted: #6c665d;
  --line: #ded7cc;
  --panel: #fffdf8;
  --accent: #1f7a68;
  --accent-strong: #0f5f50;
  --blue: #2b5f8a;
  --danger: #a73737;
  --shadow: 0 18px 50px rgba(35, 31, 24, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.82), rgba(244, 241, 235, 0.94)),
    url("data:image/svg+xml,%3Csvg width='120' height='120' viewBox='0 0 120 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23d8d0c3' stroke-width='1'%3E%3Cpath d='M0 40h120M0 80h120M40 0v120M80 0v120'/%3E%3C/g%3E%3C/svg%3E");
  color: var(--ink);
}

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

.app-shell {
  min-height: 100vh;
  padding: 28px;
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.05;
}

h2 {
  font-size: 18px;
}

.icon-button,
.small-button,
.primary-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fffdf8;
  box-shadow: var(--shadow);
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 0.8fr) minmax(280px, 0.95fr);
  gap: 16px;
  align-items: stretch;
}

.panel {
  min-height: 650px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

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

.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  background: #e8f0ed;
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.small-button.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.drop-zone,
.result-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 528px;
  overflow: hidden;
  border: 1px dashed #bcb1a3;
  border-radius: 8px;
  background: #f8f5ef;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: #eef8f4;
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-zone img,
.result-frame img {
  display: none;
  width: 100%;
  height: 100%;
  max-height: 560px;
  object-fit: contain;
}

.drop-zone.has-image img,
.result-frame.has-image img {
  display: block;
}

.drop-zone.has-image span,
.result-frame.has-image span {
  display: none;
}

#dropHint,
#resultHint {
  color: var(--muted);
  font-weight: 700;
}

.mask-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-weight: 800;
}

.mask-row input {
  width: 100%;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input,
.field select {
  min-height: 42px;
  padding: 0 11px;
}

.field textarea {
  min-height: 170px;
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 104, 0.14);
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.settings-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf7f1;
}

.primary-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  width: 100%;
  margin-top: auto;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 900;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.status-text {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.status-text.ok {
  color: var(--blue);
}

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

@media (max-width: 1120px) {
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
  }

  .drop-zone,
  .result-frame {
    min-height: 420px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
  }

  .control-row {
    grid-template-columns: 1fr;
  }

  .drop-zone,
  .result-frame {
    min-height: 300px;
  }
}
