:root {
  --bg: #f5f0e6;
  --panel: rgba(255, 252, 246, 0.86);
  --panel-strong: #fffaf1;
  --line: rgba(109, 128, 109, 0.18);
  --text: #324237;
  --muted: #6f7f70;
  --accent: #7ea37f;
  --accent-deep: #5d7f60;
  --warm: #d9b98f;
  --shadow: 0 22px 50px rgba(103, 93, 66, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Georgia, "Times New Roman", "PingFang SC", "Microsoft YaHei", serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(212, 230, 206, 0.9), transparent 30%),
    radial-gradient(circle at top right, rgba(245, 214, 183, 0.85), transparent 24%),
    linear-gradient(180deg, #f7f3ea 0%, #efe7da 100%);
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero {
  display: block;
  margin-bottom: 24px;
}

.hero-copy,
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.hero-copy {
  padding: 32px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(40px, 6vw, 68px);
  line-height: 1;
  margin-bottom: 12px;
}

.subtitle {
  max-width: 620px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.7;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
}

.panel {
  padding: 24px;
}

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

.control-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: 22px;
  border: 1px solid rgba(109, 128, 109, 0.14);
  background: rgba(255, 250, 242, 0.78);
}

.section-head {
  display: grid;
  gap: 4px;
}

.section-head strong {
  font-size: 15px;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
}

.upload-tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-radius: 22px;
  border: 1px dashed rgba(126, 163, 127, 0.45);
  background: rgba(250, 246, 238, 0.95);
  cursor: pointer;
}

.upload-tile.dragging,
.canvas-frame.dragging {
  border-color: rgba(126, 163, 127, 0.65);
  background: rgba(236, 245, 233, 0.98);
  box-shadow: 0 0 0 4px rgba(126, 163, 127, 0.12);
}

.upload-tile input {
  display: none;
}

.upload-tile span {
  font-size: 20px;
}

.upload-tile small,
.tips,
.stage-header p {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 8px;
}

.field-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.actions {
  display: grid;
  gap: 10px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary {
  color: #fdf9f0;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
}

.secondary {
  color: var(--accent-deep);
  background: rgba(126, 163, 127, 0.12);
}

.ghost {
  color: var(--text);
  background: rgba(217, 185, 143, 0.16);
}

.tips {
  display: grid;
  gap: 8px;
  line-height: 1.6;
  font-size: 14px;
  padding: 14px 16px;
}

.status {
  padding: 14px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  background: rgba(109, 128, 109, 0.08);
}

.status.error {
  color: #8d4d46;
  background: rgba(211, 134, 125, 0.15);
}

.status.success {
  color: #436247;
  background: rgba(133, 176, 135, 0.16);
}

.status.busy {
  color: #765f3d;
  background: rgba(217, 185, 143, 0.18);
}

.canvas-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stage-header {
  display: grid;
  gap: 6px;
}

.canvas-frame {
  position: relative;
  min-height: 320px;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid rgba(109, 128, 109, 0.18);
  background:
    linear-gradient(135deg, rgba(255, 250, 242, 0.95), rgba(235, 243, 233, 0.92));
}

.canvas-frame.empty {
  display: grid;
  place-items: center;
}

.canvas-frame.ready {
  display: block;
}

.placeholder {
  display: grid;
  gap: 8px;
  place-items: center;
  align-content: center;
  height: 100%;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

#sourceImage {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

#overlayCanvas,
#maskCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  touch-action: none;
  cursor: none;
}

.brush-preview {
  position: absolute;
  left: 0;
  top: 0;
  width: 45px;
  height: 45px;
  border: 2px solid rgba(126, 163, 127, 0.95);
  border-radius: 999px;
  background: rgba(126, 163, 127, 0.06);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 0.15s ease, width 0.15s ease, height 0.15s ease;
  z-index: 3;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 16px;
  background: rgba(247, 243, 234, 0.74);
  backdrop-filter: blur(6px);
  z-index: 4;
  text-align: center;
  color: var(--accent-deep);
}

.loading-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(126, 163, 127, 0.2);
  border-top-color: var(--accent-deep);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.canvas-frame.ready .placeholder {
  display: none;
}

.canvas-frame.ready #sourceImage,
.canvas-frame.ready #overlayCanvas {
  display: block;
}

.canvas-frame.show-result #overlayCanvas,
.canvas-frame.show-result #maskCanvas {
  display: none;
}

.canvas-frame.show-brush .brush-preview {
  opacity: 1;
}

.canvas-frame.processing .loading-overlay {
  display: grid;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

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

}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 1000px);
    padding-top: 20px;
  }

  .panel,
  .hero-copy {
    border-radius: 22px;
    padding: 20px;
  }

  .control-card {
    padding: 14px;
  }

  .canvas-frame {
    min-height: 320px;
  }
}
