/* 拼图工坊 · 编辑器样式 */
:root {
  --ink: #14161c;
  --ink-2: #3b4150;
  --muted: #7b8294;
  --line: #ececf2;
  --bg: #f1f2f6;
  --brand: #ff5a36;
  --brand-2: #ff2d55;
  --violet: #6a5cff;
  --shadow: 0 10px 30px rgba(20, 22, 28, .08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body.ed-body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink); background: var(--bg); overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ---------- 顶栏 ---------- */
.ed-top {
  height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 0 16px; background: #fff; border-bottom: 1px solid var(--line); position: relative; z-index: 20;
}
.ed-top-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.ed-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; letter-spacing: .3px; }
.ed-doc { display: flex; align-items: center; gap: 10px; min-width: 0; }
.doc-title {
  border: 1px solid transparent; background: transparent; border-radius: 8px;
  padding: 6px 10px; font-size: 14px; font-weight: 600; width: 190px; min-width: 90px;
}
.doc-title:hover { border-color: var(--line); }
.doc-title:focus { outline: none; border-color: #ffc6b8; background: #fff; box-shadow: 0 0 0 3px rgba(255, 90, 54, .1); }
.doc-state { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.doc-state.dirty { color: var(--brand); }

.ed-top-center { display: flex; align-items: center; gap: 6px; }
.tool {
  height: 34px; min-width: 34px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2);
  font-size: 13px; transition: all .15s ease;
}
.tool:hover:not(:disabled) { background: #f7f8fb; border-color: #dfe2ec; }
.tool:disabled { opacity: .4; cursor: default; }
.tool.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; font-weight: 700; padding: 0 18px; box-shadow: 0 6px 16px rgba(255, 72, 60, .26); }
.tool.ghost { font-weight: 600; padding: 0 16px; }
.divider { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.ratio-pick { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.ratio-pick select {
  height: 32px; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: 0 6px; font-size: 13px;
}
.size-label { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ed-top-right { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: 0; color: #fff; font-weight: 700;
  background: linear-gradient(135deg, var(--violet), var(--brand));
}
.btn-login { font-size: 13px; font-weight: 600; color: var(--brand); padding: 8px 12px; border-radius: 999px; background: #fff2ee; }

/* ---------- 主体三栏 ---------- */
.ed-main { display: flex; height: calc(100vh - 60px); min-height: 0; }

.ed-left {
  width: 272px; flex: 0 0 272px; background: #fff; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.rail-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.rail-tab {
  flex: 1; border: 0; background: transparent; padding: 8px 0; border-radius: 9px;
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.rail-tab:hover { background: #f5f6fa; }
.rail-tab.on { background: #fff2ee; color: var(--brand); font-weight: 700; }

.rail-body { flex: 1; overflow-y: auto; padding: 14px; }
.rail-panel { display: none; }
.rail-panel.on { display: block; }
.rail-title { margin: 0 0 4px; font-size: 14px; }
.rail-tip { margin: 0 0 12px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.rail-sub { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 8px; font-size: 12px; color: var(--muted); }
.rail-sub a { color: var(--brand); font-weight: 600; }

.tpl-mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tpl-mini {
  border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 6px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 11px; color: var(--muted); transition: all .15s ease;
}
.tpl-mini:hover { border-color: #ffc9bd; transform: translateY(-1px); }
.tpl-mini.on { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(255, 90, 54, .14); color: var(--ink); }
.tpl-mini svg { width: 100%; height: auto; border-radius: 8px; display: block; }
.tpl-mini span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

.uploader {
  border: 1.5px dashed #d8dbe8; border-radius: 14px; padding: 22px 14px; text-align: center;
  color: var(--ink-2); background: #fafbff; cursor: pointer; transition: all .16s ease;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.uploader:hover, .uploader.drag { border-color: var(--brand); background: #fff7f4; }
.uploader svg { color: var(--brand); }
.uploader strong { font-size: 13.5px; }
.uploader span { font-size: 11.5px; color: var(--muted); }

.demo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.demo-img { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; padding: 0; background: #fff; aspect-ratio: 4 / 5; }
.demo-img svg { width: 100%; height: 100%; display: block; }
.demo-img:hover { outline: 2px solid rgba(255, 90, 54, .35); outline-offset: -1px; }

.text-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.text-presets button {
  padding: 12px 10px; border-radius: 11px; border: 1px solid var(--line); background: #fff;
  font-size: 13px; text-align: left; transition: all .15s ease;
}
.text-presets button:hover { border-color: #ffc9bd; background: #fff8f5; }

.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sticker-btn {
  aspect-ratio: 1 / 1; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  display: flex; align-items: center; justify-content: center; padding: 6px;
}
.sticker-btn:hover { border-color: #ffc9bd; background: #fff8f5; }
.sticker-btn svg { width: 100%; height: 100%; }

.swatch-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.swatch { aspect-ratio: 1 / 1; border-radius: 9px; border: 1px solid rgba(20, 22, 28, .08); }
.swatch:hover { transform: scale(1.06); }
.swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--brand); }
.gradient-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gradient-item { aspect-ratio: 1 / 1; border-radius: 10px; border: 0; }

/* ---------- 画布区 ---------- */
.ed-stage {
  flex: 1; min-width: 0; position: relative; display: flex; align-items: center; justify-content: center;
  background-color: #eceef4;
  background-image: radial-gradient(rgba(20, 22, 28, .06) 1px, transparent 1px);
  background-size: 18px 18px;
  overflow: hidden;
}
.stage-canvas { padding: 26px; display: flex; align-items: center; justify-content: center; }
.stage-canvas canvas { box-shadow: 0 18px 50px rgba(20, 22, 28, .18); border-radius: 2px; }

.stage-toolbar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px);
  border: 1px solid rgba(20, 22, 28, .08); border-radius: 999px; padding: 5px 8px;
  box-shadow: 0 10px 26px rgba(20, 22, 28, .14);
}
.zoom-btn {
  border: 0; background: transparent; width: 30px; height: 30px; border-radius: 50%;
  font-size: 15px; color: var(--ink-2);
}
.zoom-btn:hover { background: #f1f2f7; }
.zoom-btn.wide { width: auto; padding: 0 12px; font-size: 12.5px; border-radius: 999px; }
.zoom-val { font-size: 12px; color: var(--muted); min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- 右侧 ---------- */
.ed-right {
  width: 288px; flex: 0 0 288px; background: #fff; border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.right-block { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.right-block.props-block { border-top: 1px solid var(--line); flex: 1.25; }
.right-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 8px; flex: 0 0 auto;
}
.right-head h3 { margin: 0; font-size: 13.5px; }
.right-head span { font-size: 11.5px; color: var(--muted); }
.layers { list-style: none; margin: 0; padding: 4px 8px 10px; overflow-y: auto; flex: 1; }
.layer-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 9px; cursor: pointer;
  font-size: 12.5px; color: var(--ink-2);
}
.layer-item:hover { background: #f6f7fb; }
.layer-item.on { background: #fff2ee; color: var(--ink); }
.layer-thumb {
  width: 26px; height: 26px; border-radius: 6px; background: #f2f3f8; overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--muted); flex: 0 0 auto;
}
.layer-thumb img { width: 100%; height: 100%; object-fit: cover; }
.layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-item .icon-btn { border: 0; background: transparent; color: var(--muted); padding: 2px 3px; font-size: 12px; border-radius: 5px; }
.layer-item .icon-btn:hover { background: #fff; color: var(--ink); }
.layer-item.hidden-obj { opacity: .45; }

.props { padding: 6px 14px 18px; overflow-y: auto; flex: 1; }
.props-empty { color: var(--muted); font-size: 12px; padding: 20px 0; text-align: center; }
.props-group { margin-bottom: 14px; }
.props-group > label { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.props-group > label b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.props input[type=text], .props input[type=number], .props select, .props textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; background: #fafbff;
  padding: 8px 10px; font-size: 12.5px; color: var(--ink);
}
.props textarea { resize: vertical; min-height: 62px; line-height: 1.5; }
.props select { padding: 7px 8px; }
.props input:focus, .props select:focus, .props textarea:focus { outline: none; border-color: #ffc6b8; background: #fff; box-shadow: 0 0 0 3px rgba(255, 90, 54, .1); }
.props-row { display: flex; gap: 8px; align-items: center; }
.props-row > * { flex: 1; min-width: 0; }
.props-row.tight > * { flex: 0 0 auto; }
.props-row.tight { justify-content: space-between; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; padding: 7px 0; font-size: 12px; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }
.seg button + button { border-left: 1px solid var(--line); }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent;
}
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 3px; background: #e6e8f0; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; margin-top: -5px;
  background: var(--brand); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(20, 22, 28, .2);
}
.color-line { display: flex; align-items: center; gap: 8px; }
.color-line input[type=color] { width: 34px; height: 30px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; }
.color-line .swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.color-line .swatches span { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(20, 22, 28, .1); cursor: pointer; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--ink-2); padding: 6px 0; }
.switch { position: relative; width: 38px; height: 21px; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; }
.switch i { position: absolute; inset: 0; background: #e2e5ee; border-radius: 999px; transition: background .18s ease; pointer-events: none; }
.switch i::after { content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .18s ease; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(17px); }

/* ---------- 弹窗 / 提示 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100; background: rgba(20, 22, 28, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 440px; background: #fff; border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .3); overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.modal-close:hover { background: #f4f5f9; }
.modal-body { padding: 8px 20px 4px; font-size: 13.5px; color: var(--ink-2); }
.modal-body p { margin: 0 0 12px; }
.modal-body label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 6px; }
.modal-body input[type=text] {
  width: 100%; height: 42px; border-radius: 10px; border: 1px solid var(--line); padding: 0 12px; font-size: 14px;
  background: #fafbff;
}
.modal-body input[type=text]:focus { outline: none; border-color: #ffc6b8; background: #fff; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 20px 20px; flex-wrap: wrap; }
.mbtn {
  height: 40px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  font-size: 13.5px; font-weight: 600;
}
.mbtn:hover { background: #f7f8fb; }
.mbtn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }
.export-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 4px; }
.export-opt { border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; font-size: 12.5px; background: #fff; }
.export-opt.on { border-color: var(--brand); background: #fff7f4; color: var(--brand); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 12px);
  background: rgba(20, 22, 28, .92); color: #fff; font-size: 13px; padding: 10px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 120;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: rgba(190, 40, 40, .95); }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .ed-left { width: 240px; flex-basis: 240px; }
  .ed-right { width: 260px; flex-basis: 260px; }
}
@media (max-width: 980px) {
  .ed-right { display: none; }
  .ed-top-center .size-label { display: none; }
  .doc-title { width: 130px; }
}
@media (max-width: 760px) {
  .ed-left { width: 200px; flex-basis: 200px; }
  .ed-top { flex-wrap: wrap; height: auto; padding: 8px 10px; gap: 6px; }
  .ed-main { height: calc(100vh - 104px); }
  .ed-brand span { display: none; }
  .ed-top-center { order: 3; width: 100%; }
  .tpl-mini-grid { grid-template-columns: 1fr; }
}
