:root {
  color-scheme: light;
  --bg: #f4f5f1;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #747a81;
  --line: #d9ded6;
  --accent: #1f7a5a;
  --accent-dark: #155a42;
  --accent-soft: #dff1e8;
  --warn: #b15c32;
  --shadow: 0 18px 60px rgba(28, 36, 30, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  cursor: pointer;
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-1px);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr);
  min-height: 100vh;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  overflow: hidden;
  background: #eef8f3;
}

.brand-mark img {
  display: block;
  width: 42px;
  height: 42px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

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

.upload-zone {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 132px;
  padding: 18px;
  border: 1.5px dashed #b8c4b8;
  border-radius: 8px;
  background: #fbfcf9;
  cursor: pointer;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: #f7fbf8;
}

.upload-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 26px;
  line-height: 1;
}

.upload-zone strong {
  font-size: 15px;
}

.upload-zone small,
.status {
  color: var(--muted);
  font-size: 12px;
}

.control-group {
  display: grid;
  gap: 10px;
}

.smart-action {
  min-height: 48px;
  font-size: 15px;
}

.processing-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ai-action {
  border-color: #8d6d39;
  background: #fffaf0;
  color: #684b1f;
  font-weight: 700;
}

.ai-action:hover:not(:disabled) {
  border-color: #684b1f;
  background: #f8eedb;
}

.quick-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.advanced-panel {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 4px;
}

.advanced-panel summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  list-style-position: inside;
  min-height: 32px;
}

.advanced-panel[open] {
  gap: 16px;
}

.advanced-panel[open] summary {
  color: var(--ink);
}

.advanced-panel .control-group {
  margin-top: 12px;
}

.section-title {
  color: #4b514d;
  font-size: 12px;
  font-weight: 700;
}

.brush-row,
.field {
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: center;
  gap: 10px;
}

.field {
  grid-template-columns: 44px 1fr 34px;
}

.field span,
output {
  color: var(--muted);
  font-size: 12px;
}

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

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

.button-grid button {
  font-size: 20px;
}

.button-grid button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.preset-grid,
.preset-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset-grid button,
.preset-row button {
  font-size: 13px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mode-toggle label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
}

.mode-toggle input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.status {
  margin-top: auto;
  padding: 12px;
  border-radius: 8px;
  background: #f6f7f3;
  min-height: 42px;
}

.workspace {
  min-width: 0;
  padding: 24px;
  display: grid;
  place-items: center;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: calc(100vh - 48px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #e7e9e1 25%, transparent 25%),
    linear-gradient(-45deg, #e7e9e1 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e7e9e1 75%),
    linear-gradient(-45deg, transparent 75%, #e7e9e1 75%);
  background-color: #f8f9f4;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

canvas {
  position: absolute;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  image-rendering: auto;
  border-radius: 6px;
}

#image-canvas {
  box-shadow: 0 18px 54px rgba(27, 32, 28, 0.22);
}

#mask-canvas {
  cursor: default;
  pointer-events: none;
  touch-action: none;
}

body.manual-mask-enabled #mask-canvas {
  cursor: crosshair;
  pointer-events: auto;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  font-size: 34px;
}

.empty-state p {
  margin: 0;
  font-size: 15px;
}

body.has-image .empty-state {
  display: none;
}

body:not(.show-mask) #mask-canvas {
  opacity: 0;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 34px rgba(28, 36, 30, 0.1);
  }

  .processing-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .workspace {
    padding: 12px;
  }

  .stage {
    height: 68vh;
  }

  .mode-toggle {
    grid-template-columns: 1fr;
  }
}
