:root {
  --bg: #f6efe6;
  --panel: #fffdf8;
  --ink: #3f3830;
  --muted: #8d8274;
  --line: #e8ddcc;
  --accent: #7d9672;
  --accent-deep: #5f7657;
  --warm: #b9765c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(86, 64, 44, .05), 0 12px 30px rgba(86, 64, 44, .07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(900px 520px at 6% -12%, #fdf6ec 0%, rgba(253, 246, 236, 0) 62%),
    radial-gradient(760px 500px at 104% 0%, #f8e9dd 0%, rgba(248, 233, 221, 0) 58%),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

/* ------------------------------------------------------------ 顶部 */
.top {
  flex: none;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 28px 8px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.brand { text-align: center; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------ 布局 */
.editor {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 28px 18px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
  overflow: hidden;
}

.side {
  display: flex; flex-direction: column; gap: 14px;
  min-height: 0; min-width: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}
.card, .photo-list, .photo-group, .photo-grid, .bg-lib { min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px; font-size: 13.5px; font-weight: 600; color: #4b4339;
}
.card h2 b {
  display: grid; place-items: center;
  width: 19px; height: 19px; border-radius: 50%;
  background: #f2e7d8; color: #a97d5f;
  font-size: 11px; font-weight: 600;
}

.drop-mini {
  border: 1.5px dashed #dccbb4;
  border-radius: 11px;
  background: linear-gradient(180deg, #fffdf8, #fdf7ed);
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color .16s, background .16s;
}
.drop-mini:hover, .drop-mini.is-over { border-color: var(--warm); background: #fdf6ee; }
.drop-mini strong { display: block; font-size: 13.5px; font-weight: 600; }
.drop-mini span { display: block; margin-top: 3px; font-size: 11.5px; color: var(--muted); }

.summary-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 10px;
}
.summary { margin: 0 2px; font-size: 12px; color: var(--muted); flex: 1; min-width: 0; }

.photo-list {
  margin-top: 9px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 2px;
}
.photo-group {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 5px;
  margin-bottom: 8px;
  transition: background .15s, border-color .15s;
}
.photo-group.on { background: #fbf7ef; }
.photo-group.drop-on {
  border-color: #b9765c;
  background: #fdf3ea;
}
.photo-group-head {
  display: block; width: 100%;
  border: 0; background: none; padding: 2px 2px 6px;
  font-size: 11px; color: #8d8274; text-align: left; cursor: pointer;
}
.photo-group-head.on { color: #a9715a; font-weight: 600; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.p-item {
  cursor: grab;
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  overflow: hidden;
  background: #f1e9dd;
  border: 1px solid #e8ddcc;
}
.p-item img { display: block; width: 100%; height: 100%; object-fit: cover; }
.p-n {
  position: absolute; left: 3px; top: 3px;
  min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 5px;
  background: rgba(58, 44, 31, .74);
  color: #fff; font-size: 9.5px; line-height: 15px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.p-del {
  position: absolute; right: 3px; top: 3px;
  width: 17px; height: 17px; padding: 0;
  border: 0; border-radius: 50%;
  background: rgba(58, 44, 31, .74);
  color: #fff; font-size: 12px; line-height: 17px;
  cursor: pointer;
}
.p-del:hover { background: #b0503f; }
.p-item.is-dragging { opacity: .45; }
.add-photos {
  width: 100%;
  height: 40px;
  margin-top: 8px;
  border: 1.5px dashed #d8bda2;
  border-radius: 9px;
  background: #fffdf9;
  color: #a9715a;
  font-size: 12.5px;
  display: flex; align-items: center; justify-content: center;
  gap: 6px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.add-photos b { font-size: 17px; font-weight: 400; line-height: 1; }
.add-photos:hover, .add-photos.is-over {
  border-color: #b9765c;
  background: #fdf3ea;
}

.p-item.broken::after {
  content: attr(data-ext);
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 10px; color: #9b8f80;
}
.drop-sub { display: block; margin-top: 5px; font-size: 10.5px; color: #b08f7a; }


.batches { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.batch {
  border: 1px solid var(--line); background: #fffdf9; color: #6d6153;
  font-size: 11.5px; padding: 5px 9px; border-radius: 8px; cursor: pointer;
}
.batch.on { border-color: #c9a98a; background: #fbf1e6; color: #8a5f42; }
.batch.drop-on { border-color: #b9765c; background: #fdf3ea; }
.frame-del {
  position: absolute; right: 5px; top: 5px;
  width: 18px; height: 18px; padding: 0;
  border: 0; border-radius: 50%;
  background: rgba(58, 44, 31, .72);
  color: #fff; font-size: 12px; line-height: 18px;
  text-align: center; cursor: pointer;
  opacity: .82; z-index: 3;
}
.frame-del:hover { background: #b0503f; opacity: 1; }

.seg {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4px; padding: 4px;
  background: #f7f1e6; border-radius: 10px;
}
.seg button {
  border: 0; background: transparent; color: #7c7162;
  font-size: 12.5px; padding: 7px 0; border-radius: 7px; cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.seg button.on {
  background: #fffdf9; color: #5d5142;
  box-shadow: 0 1px 3px rgba(90, 66, 44, .14);
  font-weight: 600;
}

.row { display: flex; gap: 8px; margin-top: 10px; }

.range { margin-top: 14px; }
.range-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 12px; color: #6f6456;
}
.range-head output {
  color: #a9715a; font-variant-numeric: tabular-nums; font-size: 11.5px;
}
.range input[type="range"] {
  width: 100%; margin: 9px 0 1px;
  accent-color: #b9765c; cursor: pointer;
}
.range-ends {
  display: flex; justify-content: space-between;
  font-size: 10.5px; color: #a2957f;
}

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 13px; font-size: 12.5px; color: #5f5548;
  cursor: pointer;
}
.switch-row small {
  display: block; margin-top: 2px;
  font-size: 10.5px; font-weight: 400; color: #a2957f;
}
.switch {
  appearance: none; -webkit-appearance: none;
  width: 34px; height: 20px; border-radius: 999px;
  background: #e4daca; position: relative; flex: none;
  cursor: pointer; transition: background .16s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(60, 42, 28, .22);
  transition: transform .16s;
}
.switch:checked { background: #b9765c; }
.switch:checked::after { transform: translateX(14px); }
.btn {
  flex: 1; height: 36px; border-radius: 9px;
  border: 1px solid var(--line); background: #fffdf9; color: #5c5244;
  font-size: 12.5px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #faf3e8; border-color: #dccbb4; }
.btn.ghost { background: #fffdf9; }

.tip { margin: 10px 0 0; font-size: 11.5px; line-height: 1.55; color: #9b8f80; }

.bgs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.bg-chip {
  height: 48px; border-radius: 9px; cursor: pointer;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .04);
}
.bg-chip.on { border-color: #b98a6c; box-shadow: 0 0 0 3px rgba(185, 138, 108, .14); }
.auto-bg {
  background: #fffdf9;
  border: 1.5px dashed #d8bda2;
  color: #a9715a; font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}
.auto-bg.on {
  background: #fdf3ea;
  border-color: #b9765c;
  box-shadow: 0 0 0 3px rgba(185, 118, 92, .13);
  font-weight: 600;
}

.bg-lib-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-top: 13px; font-size: 12px; color: #6f6456;
}
.bg-lib {
  display: flex; gap: 6px; overflow-x: auto;
  margin-top: 6px; padding: 2px 0 5px;
  scrollbar-width: thin;
}
.bg-thumb {
  flex: 0 0 54px; width: 54px; aspect-ratio: 3 / 4;
  padding: 0; border: 2px solid transparent; border-radius: 6px;
  overflow: hidden; background: #f1e9dd; cursor: pointer;
}
.bg-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.bg-thumb.on {
  border-color: #b9765c;
  box-shadow: 0 0 0 2px rgba(185, 118, 92, .16);
}
.bg-0 { background: linear-gradient(150deg, #fdf1e3, #f8d8cb 60%, #f4c8bf); }
.bg-1 { background: linear-gradient(150deg, #fdeef0, #f9d5dc 60%, #f4c3cd); }
.bg-2 { background: linear-gradient(150deg, #fff4df, #f9dfbf 60%, #f2cfa8); }
.bg-3 { background: linear-gradient(150deg, #f8f5e8, #e6eddc 60%, #d6e1cc); }

#bgPick { width: 100%; margin-top: 10px; }

.bg-current {
  display: flex; gap: 10px; align-items: center;
  margin-top: 10px; padding: 8px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fffdf9;
}
.bg-current img {
  width: 52px; height: 69px; object-fit: cover;
  border-radius: 6px; flex: none;
}
.bg-info { min-width: 0; flex: 1; }
.bg-info strong {
  display: block; font-size: 11.5px; color: #6f6456;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bg-info .link { margin-top: 2px; }

.side-actions { display: flex; flex-direction: column; gap: 8px; }
.primary {
  height: 48px; border: 0; border-radius: 11px;
  background: linear-gradient(180deg, #c48366, #b06b50);
  color: #fff; font-size: 14.5px; font-weight: 600; letter-spacing: .3px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(150, 92, 66, .24);
  transition: filter .15s, transform .15s;
}
.primary:hover { filter: brightness(1.03); }
.primary:active { transform: translateY(1px); }
.side-actions .btn { height: 38px; }

/* ------------------------------------------------------------ 舞台 */
.stage {
  min-width: 0; min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}
.stage-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 2px 4px 8px;
  font-size: 12.5px; color: #6f6456;
}
.stage .batches {
  margin: 0 0 10px;
  padding: 0 4px;
}
.stage-meta { color: #a2957f; font-size: 11.5px; }

.board-wrap { display: flex; justify-content: center; }

.board {
  position: relative;
  width: min(100%, 54vh);
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  box-shadow:
    0 2px 4px rgba(110, 78, 52, .10),
    0 24px 60px rgba(110, 78, 52, .18);
  touch-action: none;
  user-select: none;
}

.board.bg-0 {
  background:
    radial-gradient(58% 44% at 14% 6%, #ffe7cd 0%, rgba(255, 231, 205, 0) 70%),
    radial-gradient(52% 40% at 88% 16%, #ffd6d2 0%, rgba(255, 214, 210, 0) 72%),
    radial-gradient(70% 52% at 50% 106%, #f7c9c0 0%, rgba(247, 201, 192, 0) 70%),
    linear-gradient(168deg, #fdf0e2, #f8d5c8 56%, #f2c2b9);
}
.board.bg-1 {
  background:
    radial-gradient(60% 46% at 16% 8%, #fff0f1 0%, rgba(255, 240, 241, 0) 70%),
    radial-gradient(56% 42% at 86% 20%, #ffd9e2 0%, rgba(255, 217, 226, 0) 70%),
    radial-gradient(72% 54% at 50% 108%, #f6c6d2 0%, rgba(246, 198, 210, 0) 72%),
    linear-gradient(168deg, #fdeef1, #f9d3db 55%, #f3c3cf);
}
.board.bg-2 {
  background:
    radial-gradient(58% 44% at 14% 8%, #fff2d8 0%, rgba(255, 242, 216, 0) 70%),
    radial-gradient(54% 40% at 88% 18%, #ffdfb9 0%, rgba(255, 223, 185, 0) 72%),
    radial-gradient(70% 52% at 50% 106%, #f4cf9f 0%, rgba(244, 207, 159, 0) 70%),
    linear-gradient(168deg, #fff3e0, #f9dcbb 58%, #f1cca2);
}
.board.bg-3 {
  background:
    radial-gradient(58% 44% at 14% 6%, #fbf8ec 0%, rgba(251, 248, 236, 0) 70%),
    radial-gradient(54% 42% at 88% 16%, #e9f0df 0%, rgba(233, 240, 223, 0) 72%),
    radial-gradient(72% 54% at 50% 108%, #dbe6d2 0%, rgba(219, 230, 210, 0) 70%),
    linear-gradient(168deg, #f9f6e9, #e9efdf 58%, #dbe6d1);
}

.deco {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.board.has-image .deco { display: none; }
.board.has-image .grain { opacity: .16; }
.board.bg-drop::after {
  content: "松手替换背景";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 249, 242, .55);
  border: 3px dashed #c98a6e;
  border-radius: 10px;
  color: #a9715a; font-size: 14px; letter-spacing: .08em;
  z-index: 50; pointer-events: none;
}
.grain {
  position: absolute; inset: 0; pointer-events: none;
  opacity: .38; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='160' height='160' filter='url(%23n)' opacity='0.22'/></svg>");
}

.frames { position: absolute; inset: 0; }

/* ------------------------------------------------------------ 空相框 */
.frame {
  position: absolute;
  aspect-ratio: 3 / 4;
  border-radius: 4px;
  background: linear-gradient(178deg, #fffef9 0%, #fdf8ea 100%);
  box-shadow:
    0 1px 2px rgba(112, 80, 55, .14),
    0 12px 26px rgba(112, 80, 55, .19);
  cursor: grab;
  transform-origin: 50% 50%;
  will-change: left, top, width, transform;
  transition: left .16s ease, top .16s ease, width .16s ease, transform .16s ease;
}
.frame.is-dragging { cursor: grabbing; transition: none; }

.frame .photo {
  position: absolute;
  inset: 4.5% 4.5% 7% 4.5%;
  border-radius: 2px;
  overflow: hidden;
  display: none;
  background: #f1e9dd;
}
.frame.has-photo .photo { display: block; }
.frame .photo img {
  display: block; width: 100%; height: 100%;
  object-fit: cover;
}
.frame.has-photo .slot { display: none; }

.frame .badge {
  position: absolute; left: 5px; top: 5px;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 6px;
  background: rgba(58, 44, 31, .74);
  color: #fff; font-size: 10.5px; line-height: 18px;
  text-align: center; font-variant-numeric: tabular-nums;
  display: none;
  pointer-events: none;
}
.frame.has-photo .badge { display: block; }

.frame .slot {
  position: absolute; inset: 7%;
  border: 1.5px dashed rgba(171, 122, 96, .46);
  border-radius: 3px;
  background: rgba(255, 253, 245, .45);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  pointer-events: none;
}
.frame .num {
  font-family: "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-size: var(--num, 42px);
  line-height: 1;
  color: #a96f57;
  font-weight: 500;
  letter-spacing: -.02em;
}
.frame .cap {
  font-size: calc(var(--num, 42px) * .20);
  letter-spacing: .26em;
  text-indent: .26em;
  color: #c9a58d;
}

.frame.is-selected {
  box-shadow:
    0 0 0 2px #7d9672,
    0 14px 30px rgba(101, 74, 52, .22);
  z-index: 999;
}

.frame.is-swap-target {
  box-shadow:
    0 0 0 2px #c07a5e,
    0 16px 34px rgba(120, 76, 54, .26);
}
.frame.is-swap-target .slot {
  border-color: rgba(192, 122, 94, .72);
  background: rgba(255, 243, 233, .82);
}
.frame.is-swap-target::after {
  content: "松开交换";
  position: absolute;
  left: 50%; top: -9px;
  transform: translate(-50%, -100%);
  background: #b06b50; color: #fff;
  font-size: 10.5px; letter-spacing: .04em;
  padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(130, 76, 54, .28);
}

.handle {
  position: absolute;
  opacity: 0; pointer-events: none;
  transition: opacity .12s;
  background: #fffef9;
  border: 2px solid #7d9672;
  box-shadow: 0 2px 6px rgba(80, 60, 40, .18);
}
.frame.is-selected .handle { opacity: 1; pointer-events: auto; }

.handle.res {
  right: -9px; bottom: -9px;
  width: 17px; height: 17px; border-radius: 50%;
  cursor: nwse-resize;
}
.handle.rot {
  left: 50%; top: -27px;
  width: 15px; height: 15px; border-radius: 50%;
  transform: translateX(-50%);
  cursor: grab;
}
.handle.rot::after {
  content: "";
  position: absolute; left: 50%; top: 12px;
  width: 1.5px; height: 15px;
  background: #7d9672; transform: translateX(-50%);
}

/* ------------------------------------------------------------ 其他 */
.stage-foot {
  margin: 12px 0 0; text-align: center;
  font-size: 11.5px; color: #a2957f;
}

#generate.is-busy { position: relative; color: transparent; pointer-events: none; }
#generate.is-busy::after {
  content: ""; position: absolute; width: 18px; height: 18px;
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ 成品 */
.results { margin-top: 22px; }
.results-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 0 4px 10px;
}
.results-head h2 { margin: 0; font-size: 14px; }
.results-head span { font-size: 11.5px; color: #a2957f; }
.results-tools { display: flex; align-items: center; gap: 10px; }
.zip-btn {
  border: 1px solid #e0cdb9; background: #fffdf9; color: #a9715a;
  font-size: 11.5px; padding: 5px 10px; border-radius: 999px;
  cursor: pointer;
}
.zip-btn:hover { background: #fdf3ea; }
.zip-btn:disabled { opacity: .6; cursor: default; }
#bgCard { transition: border-color .15s, background .15s, box-shadow .15s; }
#bgCard.bg-drop {
  border-color: #b9765c;
  background: #fdf6ee;
  box-shadow: 0 0 0 3px rgba(185, 118, 92, .12), var(--shadow);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.result-grid.single { grid-template-columns: minmax(0, 1fr); }
.result-grid.single .shot { max-width: 520px; margin: 0 auto; width: 100%; }
.shot {
  margin: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; box-shadow: var(--shadow);
}
.shot > a { display: block; }
.shot img { display: block; width: 100%; height: auto; background: #f3ece2; }
.shot figcaption { padding: 10px 12px 12px; }
.shot-title { font-size: 12px; color: #6f6456; }
.shot-actions { display: flex; gap: 8px; margin-top: 8px; }
.shot-actions a, .shot-actions button {
  flex: 1; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; text-decoration: none; cursor: pointer;
}
.shot-actions a {
  background: #fffdf9; color: #5c5244; border: 1px solid var(--line);
}
.shot-actions a:hover { background: #faf3e8; }
.shot-actions button {
  background: #b9765c; border: 1px solid #b9765c; color: #fff;
}
.shot-actions button:hover { filter: brightness(1.04); }
.shot-actions button:disabled { opacity: .6; cursor: default; }
.shot-saved {
  margin: 8px 0 0; font-size: 10.5px; color: #5f7a55;
  word-break: break-all;
}

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #403931; color: #fdf9f0;
  font-size: 13px; padding: 11px 18px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(40, 32, 22, .26);
  max-width: 80vw; z-index: 50;
}
.toast.err { background: #7d4437; }

@media (max-width: 1120px) {
  .editor { grid-template-columns: 292px minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .editor { grid-template-columns: 258px minmax(0, 1fr); gap: 16px; }
  .card { padding: 13px; }
}

@media (max-width: 700px) {
  body { display: block; height: auto; max-height: none; overflow: auto; }
  .editor {
    grid-template-columns: 1fr; grid-template-rows: auto;
    padding: 10px 16px 24px;
    height: auto; overflow: visible;
  }
  .top { padding: 16px 16px 6px; }
  .side { display: grid; grid-template-columns: 1fr 1fr; align-items: start;
          overflow: visible; min-height: 0; padding-right: 0; }
  .stage { overflow: visible; min-height: 0; padding-right: 0; }
  .side-actions { grid-column: 1 / -1; flex-direction: row; }
  .side-actions > * { flex: 1; }
  .board { width: min(100%, 62vh); }
}

@media (max-width: 560px) {
  .side { grid-template-columns: 1fr; }
  .brand p { display: none; }
  .back { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================================================
   Phase 1 手机端增强
   ============================================================ */

.settings-toggle {
  display: none;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf9;
  color: #6d6153;
  font-size: 13px;
  font-weight: 600;
}

.mobile-bar {
  display: none;
}

.progress {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf9;
  padding: 11px 13px;
}
.progress-track {
  height: 7px;
  border-radius: 999px;
  background: #efe5d6;
  overflow: hidden;
}
.progress-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #9ab38e, #6f8d68);
  transition: width .2s ease;
}
.progress span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.error-box {
  border: 1px solid #e5c4b8;
  border-radius: 12px;
  background: #fdf1ed;
  color: #8d4f3f;
  padding: 11px 13px;
  font-size: 12px;
  line-height: 1.65;
}
.error-box strong { display: block; margin-bottom: 4px; }
.error-box ul { margin: 6px 0 0 18px; padding: 0; }
.error-box button {
  margin-top: 8px;
  min-height: 38px;
  border: 1px solid #d9a996;
  border-radius: 9px;
  background: #fffaf7;
  color: #8d4f3f;
  padding: 6px 12px;
}

.results-hint {
  margin: 0 4px 12px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.65;
}

/* 照片缩略图上的“移动”按钮 */
.p-move {
  position: absolute;
  right: 3px;
  bottom: 3px;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border: 0;
  border-radius: 8px;
  background: rgba(58, 44, 31, .74);
  color: #fff;
  font-size: 11px;
  line-height: 26px;
  cursor: pointer;
}

/* 移动照片底部弹层 */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(40, 32, 22, .38);
  padding: 18px;
}
.sheet-card {
  width: min(560px, 100%);
  max-height: 76vh;
  overflow-y: auto;
  border-radius: 18px;
  background: #fffdf8;
  box-shadow: 0 24px 70px rgba(40, 32, 22, .28);
  padding: 16px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sheet-head h3 { margin: 0; font-size: 15px; }
.sheet-close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #f3ebdf;
  color: #6d6153;
  font-size: 22px;
  line-height: 40px;
}
.move-options {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.move-options button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fffdf9;
  color: #5d5142;
  text-align: left;
  padding: 10px 13px;
  font-size: 13px;
}
.move-options button.current {
  border-color: #c9a98a;
  background: #fbf1e6;
}
.move-options button:disabled {
  opacity: .45;
}

/* 照片预览：非 3:4 用 contain，避免预览与成品不一致 */
.frame .photo.is-contain { background: #f0e8db; }
.frame .photo.is-contain img { object-fit: contain; }

@media (max-width: 900px) {
  body {
    display: block;
    height: auto;
    max-height: none;
    overflow: auto;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .top {
    padding: calc(14px + env(safe-area-inset-top)) 16px 4px;
    justify-content: flex-start;
  }
  .brand { text-align: left; }
  .brand h1 { font-size: 18px; }
  .brand p { display: block; }

  .editor {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 12px 24px;
    height: auto;
    overflow: visible;
  }

  .stage {
    order: 1;
    overflow: visible;
    min-height: 0;
    padding-right: 0;
  }
  .side {
    order: 2;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: visible;
    min-height: 0;
    padding-right: 0;
  }

  .settings-toggle { display: block; }
  .advanced { display: none; }
  .side.show-advanced .advanced { display: block; }

  .side-actions { display: none; }

  .stage-head { padding: 2px 4px 6px; }
  .board { width: min(100%, 430px); }
  .board-wrap { padding: 0 2px; }
  .stage-foot {
    display: block;
    margin: 8px 4px 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.6;
  }

  .mobile-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: 1fr 1.35fr 1fr;
    gap: 8px;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
    background: rgba(255, 253, 248, .96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 28px rgba(80, 60, 40, .10);
    backdrop-filter: blur(12px);
  }
  .mobile-bar button {
    min-height: 48px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fffdf9;
    color: #5d5142;
    font-size: 13px;
    font-weight: 600;
  }
  .mobile-bar button.primary {
    border-color: #7d9672;
    background: #7d9672;
    color: #fff;
  }
  .mobile-bar button b { font-weight: 500; margin-right: 2px; }
  .mobile-bar button:disabled { opacity: .55; }

  .photo-list { max-height: none; overflow: visible; }
  .photo-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }

  .p-item {
    cursor: pointer;
    touch-action: manipulation;
  }
  .p-del, .p-move {
    width: 28px;
    height: 28px;
    min-width: 28px;
    line-height: 28px;
    font-size: 14px;
    border-radius: 9px;
  }
  .p-del { right: 2px; top: 2px; }
  .p-move { right: 2px; bottom: 2px; font-size: 10.5px; line-height: 26px; }
  .p-n {
    left: 3px; top: 3px;
    min-width: 18px; height: 18px;
    font-size: 10.5px; line-height: 18px;
  }

  /* 未选中的相框允许页面纵向滚动；点选后再拖动/缩放/旋转。 */
  .frame { touch-action: pan-y; }
  .frame.is-selected { touch-action: none; }
  .frame .handle { touch-action: none; }
  .board { touch-action: pan-y; }

  .handle.res {
    width: 30px;
    height: 30px;
    right: -13px;
    bottom: -13px;
  }
  .handle.rot {
    width: 28px;
    height: 28px;
    top: -38px;
  }
  .handle.rot::after { top: 16px; height: 20px; }
  .handle::before {
    content: "";
    position: absolute;
    inset: -10px;
  }
  .frame-del {
    width: 28px;
    height: 28px;
    line-height: 28px;
    font-size: 16px;
    right: 2px;
    top: 2px;
  }

  .result-grid { grid-template-columns: 1fr; }
  .result-grid.single .shot { max-width: none; }
  .shot-actions a, .shot-actions button { height: 44px; font-size: 13px; }

  .results { margin-top: 14px; }
  .results-head {
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }
  .results-tools { width: 100%; justify-content: space-between; }

  .toast {
    bottom: calc(90px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 32px);
  }

  .bg-lib {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 4px;
  }
  .bg-thumb, .bg-lib img { scroll-snap-align: start; }

  .card { padding: 13px; }
  .drop-mini { padding: 16px 12px; }
  .add-photos { min-height: 46px; }
}

@media (max-width: 430px) {
  .photo-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .brand h1 { font-size: 17px; }
  .editor { padding-left: 10px; padding-right: 10px; }
  .mobile-bar { padding-left: 8px; padding-right: 8px; }
  .mobile-bar button { font-size: 12px; }
}

/* 无法解码的照片：预览显示格式提示，生成时会被拦截 */
.frame.is-broken .photo {
  display: block;
  background: #f1e9dd;
}
.frame.is-broken .photo img { display: none; }
.frame.is-broken .photo::after {
  content: "无法解码";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #9b8f80;
  font-size: 10px;
}
.sheet-open { overflow: hidden !important; }

@media (max-width: 900px) {
  /* 手机上默认不显示每张相框的删除按钮，避免 9 张时过于拥挤；
     点选相框后再显示，缩略图右上角也始终可以删除。 */
  .frame .frame-del {
    opacity: 0;
    pointer-events: none;
  }
  .frame.is-selected .frame-del {
    opacity: .95;
    pointer-events: auto;
  }
}

@media (max-width: 900px) {
  /* 保留“导出布局 JSON”，隐藏重复的生成按钮 */
  .side-actions {
    display: flex;
    flex-direction: row;
    gap: 8px;
  }
  .side-actions #generate { display: none; }
  .side-actions #exportLayout { flex: 1; min-height: 44px; }
}

.stage-action {
  display: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdf9;
  color: #7a6c5b;
  font-size: 12px;
  padding: 7px 12px;
  min-height: 36px;
}

@media (max-width: 900px) {
  .stage-head {
    flex-wrap: wrap;
    align-items: center;
  }
  .stage-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
  }
}

@media (max-width: 900px) {
  .btn,
  .seg button,
  .add-photos,
  .zip-btn,
  .bg-chip {
    min-height: 44px;
  }
  .summary-row .link {
    min-height: 40px;
    padding: 8px 10px;
  }
  .p-del,
  .p-move {
    width: 30px;
    height: 30px;
    min-width: 30px;
    line-height: 30px;
  }
}

.preview-sheet {
  align-items: flex-start;
  overflow-y: auto;
}
.preview-card {
  width: min(560px, 100%);
  margin: auto;
  border-radius: 18px;
  background: #fffdf8;
  box-shadow: 0 24px 70px rgba(40, 32, 22, .3);
  padding: 14px;
}
.preview-card .hint { margin: 6px 0 10px; }
.preview-card img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #f3ece2;
}
