:root {
  color-scheme: light;
  font-family:
    "Inter", "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  background: #edf0f3;
  color: #15202b;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --line: #d8dde4;
  --muted: #6c7684;
  --text: #15202b;
  --green: #18a058;
  --green-dark: #0d7a42;
  --coral: #f05d5e;
  --blue: #3b73f6;
  --shadow: 0 18px 40px rgba(28, 42, 58, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
}

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

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

button:hover:not(:disabled) {
  border-color: #aeb8c5;
  background: #f8fafc;
}

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

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

button svg,
.file-picker svg,
.brand-mark svg,
.empty-icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  background: var(--surface-2);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e9f8f0;
  color: var(--green-dark);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

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

.file-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.file-picker:hover {
  background: var(--green-dark);
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.panel h2 {
  margin: 0;
  color: #3b4754;
  font-size: 13px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f0f3f6;
}

.segmented button {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--blue);
  box-shadow: 0 2px 7px rgba(29, 42, 57, 0.11);
}

.range-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #3b4754;
  font-size: 14px;
  font-weight: 700;
}

.range-row output {
  min-width: 38px;
  padding: 2px 8px;
  border-radius: 8px;
  background: #edf2ff;
  color: #3157c9;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

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

select,
textarea,
.text-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

select,
.text-input {
  min-height: 40px;
  padding: 0 10px;
}

.text-input::placeholder {
  color: #9aa4b1;
}

textarea {
  min-height: 132px;
  padding: 10px;
  resize: vertical;
  color: #3b4754;
  font-size: 12px;
  line-height: 1.55;
}

.primary-button {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

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

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.workspace-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f0f3f6;
}

.workspace-switch button {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.workspace-switch button.is-active {
  background: var(--surface);
  color: var(--green-dark);
  box-shadow: 0 2px 7px rgba(29, 42, 57, 0.11);
}

.status-line {
  min-height: 38px;
  margin: 0;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f2f6fb;
  color: #586575;
  font-size: 12px;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

.workspace {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.file-status {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.file-status strong {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.zoom-controls {
  display: inline-grid;
  grid-template-columns: 38px 66px 38px 38px;
  align-items: center;
  gap: 6px;
}

.zoom-controls button {
  width: 38px;
  min-height: 38px;
  padding: 0;
}

.zoom-controls output {
  color: #384555;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(45deg, #dfe4ea 25%, transparent 25%),
    linear-gradient(-45deg, #dfe4ea 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe4ea 75%),
    linear-gradient(-45deg, transparent 75%, #dfe4ea 75%);
  background-color: #f5f7fa;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.stage.is-dragging {
  outline: 3px solid rgba(24, 160, 88, 0.28);
  outline-offset: -3px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--blue);
  box-shadow: var(--shadow);
}

.empty-icon svg {
  width: 30px;
  height: 30px;
}

#emptyUploadBtn {
  min-width: 132px;
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.canvas-shell {
  position: absolute;
  top: 48px;
  left: 48px;
  width: 0;
  height: 0;
  box-shadow: var(--shadow);
  background: #fff;
  transform-origin: top left;
}

.canvas-shell canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#maskCanvas {
  cursor: none;
  touch-action: none;
}

.brush-cursor {
  position: absolute;
  z-index: 3;
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255, 255, 255, 0.96);
  border-radius: 50%;
  background: rgba(240, 93, 94, 0.16);
  box-shadow:
    0 0 0 1px rgba(240, 93, 94, 0.88),
    0 2px 10px rgba(14, 24, 38, 0.28);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.selection-rect {
  position: absolute;
  z-index: 4;
  min-width: 2px;
  min-height: 2px;
  border: 2px dashed rgba(59, 115, 246, 0.96);
  background: rgba(59, 115, 246, 0.14);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.86),
    0 8px 24px rgba(14, 24, 38, 0.14);
  pointer-events: none;
}

.selection-rect.is-locked {
  border-color: rgba(20, 160, 96, 0.98);
  background: rgba(20, 160, 96, 0.13);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.9),
    0 0 0 4px rgba(20, 160, 96, 0.12),
    0 10px 28px rgba(14, 24, 38, 0.18);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid rgba(20, 28, 38, 0.12);
  border-radius: 8px;
  background: rgba(21, 32, 43, 0.94);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(560px, 1fr);
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    min-height: 620px;
  }

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

  .canvas-shell {
    top: 28px;
    left: 28px;
  }
}

@media (max-width: 520px) {
  .sidebar {
    padding: 14px;
  }

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

  .zoom-controls {
    grid-template-columns: 38px 64px 38px 38px;
  }
}
