:root {
  --bg: #f4f3ef;
  --panel: #fbfbf9;
  --card: #ffffff;
  --border: #deddd7;
  --text: #2f2f2c;
  --muted: #74736e;
  --faint: #aaa9a3;
  --control: #f0efeb;
  --control-hover: #e7e6e1;
  --shadow: 0 1px 2px rgba(35,35,30,.05), 0 18px 52px rgba(35,35,30,.08);
}

* { box-sizing: border-box; }

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

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

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1440px, calc(100% - 40px));
  min-height: calc(100vh - 40px);
  margin: 20px auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  height: 76px;
  padding: 0 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: #30302d; border-radius: 11px; }
.brand-mark svg { width: 22px; fill: none; stroke: white; stroke-width: 1.8; stroke-linejoin: round; }
.brand h1 { margin: 0; font-size: 17px; line-height: 1.2; letter-spacing: .04em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.offline-badge { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.offline-badge i { width: 7px; height: 7px; border-radius: 50%; background: #7e9a7b; box-shadow: 0 0 0 3px #e6ede4; }

.workspace { display: grid; grid-template-columns: 320px 1fr; min-height: calc(100vh - 117px); }
.controls { padding: 28px 24px 24px; border-right: 1px solid var(--border); overflow-y: auto; }
.section-title { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.section-title > span { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font: 600 10px/1 ui-monospace, monospace; }
.section-title div { display: grid; gap: 2px; }
.section-title strong { font-size: 13px; }
.section-title small { color: var(--muted); font-size: 11px; }

.upload-card {
  width: 100%; min-height: 76px; padding: 12px;
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--card); border: 1px dashed #c9c8c2; border-radius: 11px; cursor: pointer;
}
.upload-card:hover { background: #f8f8f6; border-color: #9f9e98; }
.upload-card:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid #6c6b67; outline-offset: 2px; }
.upload-icon { width: 40px; height: 40px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 9px; background: var(--control); }
.upload-icon svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.upload-card > span:last-child { display: grid; gap: 5px; }
.upload-card strong { font-size: 12px; }
.upload-card small { color: var(--muted); font-size: 10px; }
.divider { height: 1px; margin: 28px 0; background: var(--border); }
.field-label { margin-top: 18px; display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 600; }
.field-label output, .field-label code { color: var(--muted); font: 500 11px/1 ui-monospace, SFMono-Regular, monospace; }

.range { width: 100%; height: 4px; margin: 18px 0 4px; appearance: none; background: linear-gradient(to right, #393936 var(--range-progress, 19%), #deddd8 var(--range-progress, 19%)); border-radius: 99px; cursor: pointer; }
.range::-webkit-slider-thumb { width: 18px; height: 18px; appearance: none; border: 4px solid #fff; background: #343431; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.24); }
.range::-moz-range-thumb { width: 10px; height: 10px; border: 4px solid #fff; background: #343431; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.24); }
.color-row { min-height: 38px; }
.color-control { display: flex; align-items: center; gap: 9px; }
input[type="color"] { width: 30px; height: 30px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.segmented { padding: 3px; display: grid; grid-template-columns: 1fr 1fr; background: var(--control); border-radius: 9px; }
.segment { height: 32px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 650; cursor: pointer; }
.segment.active { color: var(--text); background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.is-hidden { display: none; }

.primary-button { width: 100%; height: 44px; margin-top: 30px; display: flex; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 999px; background: #30302d; color: #fff; font-size: 12px; font-weight: 700; cursor: pointer; }
.primary-button:hover { background: #1f1f1d; }
.primary-button:disabled { background: #d7d6d1; cursor: not-allowed; }
.primary-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.stage-panel { min-width: 0; display: grid; grid-template-rows: 62px minmax(460px, 1fr) 44px; }
.stage-toolbar { padding: 0 18px 0 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.file-meta { min-width: 0; display: grid; gap: 3px; }
.file-meta span { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 650; }
.file-meta small { color: var(--muted); font-size: 10px; }
.zoom-controls { display: flex; align-items: center; gap: 5px; }
.zoom-controls button { height: 30px; min-width: 30px; border: 1px solid var(--border); border-radius: 8px; background: #fff; font-size: 13px; cursor: pointer; }
.zoom-controls button:hover { background: var(--control); }
.zoom-controls output { min-width: 48px; text-align: center; color: var(--muted); font-size: 10px; }
.zoom-controls .fit-button { padding: 0 10px; margin-left: 4px; color: var(--muted); font-size: 10px; }

.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; display: grid; place-items: center; }
.checkerboard { background-color: #e8e7e2; background-image: linear-gradient(45deg, #dcdbd5 25%, transparent 25%), linear-gradient(-45deg, #dcdbd5 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #dcdbd5 75%), linear-gradient(-45deg, transparent 75%, #dcdbd5 75%); background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0; }
.stage.drag-over::after { content: "松开以添加 PNG"; position: absolute; inset: 18px; display: grid; place-items: center; border: 2px dashed #4f4f4b; border-radius: 14px; background: rgba(250,250,248,.9); font-size: 16px; font-weight: 700; z-index: 4; }
.empty-state { width: min(400px, calc(100% - 40px)); padding: 38px; text-align: center; background: rgba(251,251,249,.94); border: 1px solid rgba(255,255,255,.8); border-radius: 15px; box-shadow: 0 12px 34px rgba(45,45,40,.12); }
.ghost-card { width: 74px; height: 68px; margin: 0 auto 20px; display: grid; place-items: center; transform: rotate(-3deg); border: 1px solid #cac9c3; border-radius: 10px; background: #fff; box-shadow: 7px 7px 0 #ecebe6; }
.ghost-card i { width: 30px; height: 34px; border: 2px solid #a3a29d; border-radius: 48% 48% 42% 42%; position: relative; }
.ghost-card i::before, .ghost-card i::after { content: ""; position: absolute; top: 11px; width: 3px; height: 6px; border-radius: 3px; background: #a3a29d; }
.ghost-card i::before { left: 7px; }.ghost-card i::after { right: 7px; }
.empty-state h2 { margin: 0; font-size: 17px; }
.empty-state p { margin: 9px auto 20px; color: var(--muted); font-size: 11px; line-height: 1.7; }
.empty-state button { height: 36px; padding: 0 18px; border: 1px solid var(--border); border-radius: 999px; background: #fff; font-size: 11px; font-weight: 700; cursor: pointer; }
.canvas-wrap { position: absolute; transform-origin: center; cursor: grab; will-change: transform; }
.canvas-wrap.dragging { cursor: grabbing; }
#previewCanvas { display: block; max-width: none; box-shadow: 0 12px 36px rgba(30,30,25,.16); }
.processing { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,.92); box-shadow: 0 4px 16px rgba(0,0,0,.1); color: var(--muted); font-size: 10px; z-index: 3; }
.processing[hidden] { display: none; }
.processing span { width: 12px; height: 12px; border: 2px solid #d2d1cc; border-top-color: #343431; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.stage-footer { padding: 0 20px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--border); color: var(--muted); font-size: 10px; }
kbd { padding: 2px 6px; border: 1px solid var(--border); border-radius: 5px; background: white; font: inherit; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 10; transform: translate(-50%, 18px); padding: 10px 15px; border-radius: 999px; background: #30302d; color: #fff; font-size: 11px; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .app-shell { width: 100%; min-height: 100vh; margin: 0; border: 0; border-radius: 0; }
  .workspace { grid-template-columns: 1fr; }
  .controls { border-right: 0; border-bottom: 1px solid var(--border); }
  .stage-panel { min-height: 620px; }
  .stage-toolbar { padding: 0 12px; }
  .file-meta span { max-width: 150px; }
  .zoom-controls .fit-button { display: none; }
}
