/* ==========================================================
   PixelForge · 深色图片工作室
   ========================================================== */
:root {
  --bg:        #0a0c0f;
  --bg-1:      #101317;
  --bg-2:      #151920;
  --bg-3:      #1b2029;
  --bg-4:      #232935;
  --line:      #232a34;
  --line-2:    #2e3745;
  --text:      #e8edf5;
  --text-2:    #97a3b6;
  --text-3:    #626d7e;
  --accent:    #4c8dff;
  --accent-d:  #2f6ee0;
  --accent-2:  #21d4a4;
  --danger:    #ff5f5f;
  --radius:    10px;
  --shadow:    0 12px 40px rgba(0,0,0,.55);
  --topbar-h:  58px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
               "Helvetica Neue", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b3340; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #3b4554; background-clip: content-box; }

.app { height: 100vh; display: flex; flex-direction: column; }

/* ======================= 顶栏 ======================= */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 16px;
  background: linear-gradient(180deg, #12161c, #0d1014);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 168px; }
.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(145deg, #2b6cff, #14b8a6);
  color: #fff;
  box-shadow: 0 4px 14px rgba(43,108,255,.35);
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 13.5px; letter-spacing: .2px; font-weight: 650; }
.brand-text span { font-size: 10.5px; color: var(--text-3); letter-spacing: .4px; }
.brand-text .sub { font-style: normal; }
.brand-text .ver {
  font-style: normal;
  font-weight: 600;
  color: var(--text-3);
  opacity: .78;
  letter-spacing: .3px;
  font-variant-numeric: tabular-nums;
}

.modes {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 11px;
}
.mode-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all .16s ease;
  white-space: nowrap;
}
.mode-btn svg { width: 15px; height: 15px; opacity: .85; }
.mode-btn:hover { color: var(--text); background: rgba(255,255,255,.045); }
.mode-btn.is-active {
  background: linear-gradient(180deg, #2f6ee0, #2a5fc7);
  color: #fff;
  box-shadow: 0 2px 10px rgba(47,110,224,.4);
}
.mode-btn.is-active svg { opacity: 1; }

.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit; font-size: 12.5px; font-weight: 550;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn:active { transform: translateY(.5px) scale(.99); }
.btn-primary {
  background: linear-gradient(180deg, #4c8dff, #3573e8);
  color: #fff;
  box-shadow: 0 2px 12px rgba(76,141,255,.32), inset 0 1px 0 rgba(255,255,255,.18);
}
.btn-primary:hover { background: linear-gradient(180deg, #5b98ff, #3d7cf0); }
.btn-ghost {
  background: var(--bg-3);
  border-color: var(--line-2);
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--bg-4); color: var(--text); border-color: #3b4657; }
.btn-soft {
  background: var(--bg-3);
  border-color: var(--line);
  color: var(--text-2);
}
.btn-soft:hover { background: var(--bg-4); color: var(--text); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.icon-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 0; border-radius: 7px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: all .14s;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: rgba(255,255,255,.07); color: var(--text); }

/* ======================= 工作区 ======================= */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 188px minmax(0,1fr) 316px;
}

/* ---------- 左侧素材栏 ---------- */
.rail {
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail-head {
  height: 40px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 0 14px;
  font-size: 11.5px;
  color: var(--text-3);
  letter-spacing: .3px;
  border-bottom: 1px solid var(--line);
}
.rail-head b { color: var(--text-2); font-weight: 600; margin-left: 2px; }

.rail-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.thumb {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-3);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { border-color: var(--line-2); }
.thumb.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,141,255,.16); }
.thumb-del {
  position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px;
  border: 0; border-radius: 6px;
  background: rgba(10,12,15,.78);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .14s;
  backdrop-filter: blur(6px);
}
.thumb-del svg { width: 11px; height: 11px; }
.thumb:hover .thumb-del { opacity: 1; }
.thumb-del:hover { background: var(--danger); }
.thumb-badge {
  position: absolute; left: 4px; bottom: 4px;
  font-size: 9.5px; font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(33,212,164,.9);
  color: #04231c;
  letter-spacing: .2px;
}

.rail-add {
  flex: 0 0 auto;
  margin: 8px;
  height: 38px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px dashed var(--line-2);
  border-radius: 9px;
  background: transparent;
  color: var(--text-3);
  font-family: inherit; font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}
.rail-add svg { width: 14px; height: 14px; }
.rail-add:hover { border-color: var(--accent); color: var(--accent); background: rgba(76,141,255,.06); }

/* ---------- 中间画布 ---------- */
.stage {
  position: relative;
  min-width: 0;
  background:
    radial-gradient(circle at 50% 40%, #151a22 0%, #0a0c0f 70%),
    var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.stage::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
}

.stage-empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  position: relative;
  z-index: 2;
}
.empty-art { color: #2c3644; margin-bottom: 6px; }
.empty-art svg { width: 92px; height: 92px; }
.stage-empty h2 { font-size: 16px; font-weight: 600; color: var(--text-2); }
.stage-empty p { font-size: 12px; color: var(--text-3); margin-bottom: 16px; }

.canvas-area {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  z-index: 2;
  display: flex;
}
.canvas-scroll {
  flex: 1;
  overflow: hidden;
  position: relative;
  padding: 22px;
  touch-action: none;
}
/* 居中必须用 absolute + translate(-50%,-50%)：
   grid 的 place-items:center 在子元素比容器大时会退化成左对齐（浏览器防止内容丢失），
   放大后就会看到图片左上角、水印直接飞出屏幕。 */
.canvas-inner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  line-height: 0;
  box-shadow: 0 20px 60px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.06);
  border-radius: 2px;
  background: #000;
  transition: box-shadow .2s;
  will-change: transform;
}
.canvas-inner.is-dragging { cursor: grabbing; }
.canvas-inner.can-drag { cursor: grab; }

/* 切图动效层（与平移层分开，互不干扰） */
.canvas-anim { position: relative; line-height: 0; }
@keyframes swInNext {
  from { opacity: 0; transform: translateX(34px) scale(.984); }
  to   { opacity: 1; transform: none; }
}
@keyframes swInPrev {
  from { opacity: 0; transform: translateX(-34px) scale(.984); }
  to   { opacity: 1; transform: none; }
}
.canvas-anim.sw-next { animation: swInNext .26s cubic-bezier(.22,.9,.3,1); }
.canvas-anim.sw-prev { animation: swInPrev .26s cubic-bezier(.22,.9,.3,1); }
@media (prefers-reduced-motion: reduce) {
  .canvas-anim.sw-next, .canvas-anim.sw-prev { animation: none; }
}
#viewCanvas { display: block; border-radius: 2px; }
#maskCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  border-radius: 2px;
  opacity: .58;
}

.drag-hint {
  position: absolute;
  left: 50%; bottom: 12px;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 20px;
  background: rgba(12,16,22,.82);
  border: 1px solid rgba(76,141,255,.3);
  color: #9fc0ff;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  pointer-events: none;
  animation: hintPulse 2.4s ease-in-out infinite;
}
.drag-hint svg { width: 12px; height: 12px; }
.drag-hint em {
  font-style: normal;
  font-size: 10px;
  color: rgba(159,192,255,.6);
  padding-left: 7px;
  border-left: 1px solid rgba(76,141,255,.28);
}
@keyframes hintPulse {
  0%,100% { opacity: .55; }
  50%     { opacity: 1; }
}

.stage-bar {
  flex: 0 0 auto;
  height: 40px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  background: rgba(13,17,22,.9);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 3;
}
.stage-bar-left { display: flex; gap: 7px; align-items: center; min-width: 0; }
.stage-bar-right { display: flex; gap: 8px; align-items: center; }
.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--bg-3);
  color: var(--text-2);
  max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.dim { color: var(--text-3); background: transparent; }
.zoom-group {
  display: flex; align-items: center; gap: 1px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 1px;
}
.zoom-group span {
  font-size: 10.5px;
  color: var(--text-2);
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- 右侧面板 ---------- */
.panel {
  background: var(--bg-1);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
}
.panel-body { padding: 14px 14px 28px; }
.panel-title {
  font-size: 12px;
  font-weight: 650;
  color: var(--text);
  letter-spacing: .3px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.group {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.group-title {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: .5px;
  margin-bottom: 9px;
  font-weight: 500;
}
.group-title .hint {
  color: var(--accent);
  opacity: .75;
  font-weight: 400;
  letter-spacing: 0;
  margin-left: 4px;
}

/* 分段控件 */
.segmented {
  display: flex;
  gap: 3px;
  background: var(--bg-1);
  border-radius: 8px;
  padding: 3px;
}
.seg {
  flex: 1;
  height: 27px;
  border: 0; border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  font-family: inherit; font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}
.seg:hover { color: var(--text-2); }
.seg.is-active { background: var(--bg-4); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
/* 选项多于 3 个时换行，避免每个都挤成一条 */
.seg-wrap { flex-wrap: wrap; }
.seg-wrap .seg { flex: 1 0 calc(33.333% - 3px); min-width: 62px; }
/* 5 个选项时第二行两个各占一半，避免右边留空 */
.seg-wrap .seg:nth-child(4),
.seg-wrap .seg:nth-child(5) { flex: 1 0 calc(50% - 3px); }

/* 输入控件 */
.input {
  width: 100%;
  height: 30px;
  padding: 0 9px;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: var(--bg-1);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,141,255,.12); }
.textarea {
  height: auto;
  padding: 7px 9px;
  resize: vertical;
  line-height: 1.45;
  min-height: 52px;
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23626d7e' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  background-size: 12px;
  padding-right: 24px;
  cursor: pointer;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 7px; }

.field {
  display: flex; align-items: center; justify-content: space-between;
  height: 30px;
  padding: 0 8px;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: var(--bg-1);
  font-size: 11.5px;
  color: var(--text-3);
}
.field input[type="color"] {
  width: 30px; height: 21px;
  padding: 0; border: 0; border-radius: 5px;
  background: transparent;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 1px solid var(--line-2); border-radius: 4px; }

/* 滑块 */
.slider-row { margin-bottom: 11px; }
.slider-row:last-child { margin-bottom: 0; }
.slider-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-2);
  margin-bottom: 5px;
}
.slider-head em {
  font-style: normal;
  color: var(--accent);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 550;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 3px;
  background: var(--bg-4);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #f0f4fa;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 5px rgba(0,0,0,.45);
  transition: transform .12s;
  cursor: grab;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; transform: scale(1.05); }

/* 开关 */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-2);
  padding-top: 9px;
  margin-top: 3px;
  border-top: 1px solid var(--line);
}
.switch {
  width: 34px; height: 19px;
  border-radius: 20px;
  border: 0;
  background: var(--bg-4);
  position: relative;
  cursor: pointer;
  transition: background .18s;
  padding: 0;
}
.switch i {
  position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: #7d8798;
  transition: all .18s cubic-bezier(.3,1.4,.6,1);
}
.switch.is-on { background: rgba(76,141,255,.28); }
.switch.is-on i { left: 17px; background: var(--accent); box-shadow: 0 0 8px rgba(76,141,255,.6); }

/* 水印位置作用范围 */
.pos-scope {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}
.pos-state {
  font-size: 10.5px;
  color: var(--text-3);
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pos-state.is-custom { color: var(--accent); }
.pos-acts { display: flex; gap: 5px; flex: 0 0 auto; }
.mini-btn {
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--bg-3);
  color: var(--text-2);
  font-family: inherit;
  font-size: 10.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .14s;
}
.mini-btn:hover { border-color: rgba(76,141,255,.45); color: #9fc0ff; }
.mini-btn:active { background: var(--bg-4); }

/* 九宫格位置 */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  aspect-ratio: 1 / .62;
  margin-bottom: 7px;
}
.pos-grid button {
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--bg-1);
  cursor: pointer;
  position: relative;
  transition: all .14s;
}
.pos-grid button::after {
  content: '';
  position: absolute; inset: 50% auto auto 50%;
  width: 5px; height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: var(--text-3);
  transition: all .14s;
}
.pos-grid button:hover { border-color: #3d4a5c; background: var(--bg-3); }
.pos-grid button.is-active {
  border-color: var(--accent);
  background: rgba(76,141,255,.12);
}
.pos-grid button.is-active::after { background: var(--accent); box-shadow: 0 0 7px var(--accent); }

.tile-btn {
  width: 100%;
  height: 29px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--bg-1);
  color: var(--text-2);
  font-family: inherit; font-size: 11.5px;
  cursor: pointer;
  transition: all .14s;
}
.tile-btn svg { width: 13px; height: 13px; }
.tile-btn:hover { color: var(--text-2); border-color: #3d4a5c; }
.tile-btn.is-active {
  border-color: var(--accent);
  background: rgba(76,141,255,.12);
  color: #9fc0ff;
}

/* 上传按钮 */
.upload-drop {
  width: 100%;
  height: 54px;
  border: 1px dashed var(--line-2);
  border-radius: 8px;
  background: var(--bg-1);
  color: var(--text-3);
  font-family: inherit; font-size: 11.5px;
  cursor: pointer;
  transition: all .15s;
  margin-bottom: 10px;
  padding: 0 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.upload-drop:hover { border-color: var(--accent); color: var(--accent); background: rgba(76,141,255,.05); }

/* 预设 */
.preset-row { display: grid; grid-template-columns: repeat(4,1fr); gap: 5px; }
.preset {
  height: 27px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--bg-1);
  color: var(--text-3);
  font-family: inherit; font-size: 11.5px;
  cursor: pointer;
  transition: all .14s;
}
.preset:hover { color: var(--text); border-color: var(--accent); background: rgba(76,141,255,.08); }

/* 涂抹工具 */
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px;
  height: 58px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--bg-1);
  color: var(--text-3);
  font-family: inherit; font-size: 11px;
  cursor: pointer;
  transition: all .15s;
}
.tool svg { width: 17px; height: 17px; }
.tool:hover { color: var(--text-2); border-color: #3d4a5c; }
.tool.is-active {
  border-color: var(--accent);
  background: rgba(76,141,255,.11);
  color: #9fc0ff;
}

.panel-actions { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.panel-actions .row-2 { margin-top: 0; }
.panel-actions .btn { width: 100%; height: 34px; }

.tip-box {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  background: rgba(76,141,255,.06);
  border: 1px solid rgba(76,141,255,.16);
  font-size: 11px;
  line-height: 1.55;
  color: #8fa8cc;
}

.group-info {
  margin-top: 9px;
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.group-info b { color: var(--accent); font-weight: 600; }

/* ======================= 浮层 ======================= */
.drop-overlay {
  position: fixed; inset: 0;
  z-index: 200;
  display: none;
  place-items: center;
  background: rgba(8,10,14,.82);
  backdrop-filter: blur(6px);
}
.drop-overlay.is-on { display: grid; }
.drop-card {
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
  padding: 38px 54px;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  color: var(--accent);
  background: rgba(76,141,255,.06);
}
.drop-card svg { width: 34px; height: 34px; }
.drop-card strong { font-size: 14px; letter-spacing: .3px; }

.progress {
  position: fixed; inset: 0;
  z-index: 210;
  display: none;
  place-items: center;
  background: rgba(8,10,14,.7);
  backdrop-filter: blur(4px);
}
.progress.is-on { display: grid; }
.progress-card {
  width: 300px;
  padding: 20px;
  border-radius: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
}
.progress-text { font-size: 12.5px; color: var(--text-2); margin-bottom: 11px; }
.progress-track { height: 5px; border-radius: 4px; background: var(--bg-4); overflow: hidden; }
.progress-fill {
  height: 100%; width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s ease;
}

.toast-wrap {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  z-index: 125;
  display: flex; flex-direction: column; gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 9px 16px;
  border-radius: 9px;
  background: rgba(28,34,44,.96);
  border: 1px solid var(--line-2);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  animation: toastIn .24s cubic-bezier(.2,1.3,.5,1);
  backdrop-filter: blur(10px);
  white-space: nowrap;
}
.toast.err { border-color: rgba(255,95,95,.5); color: #ffb3b3; }
.toast.ok  { border-color: rgba(33,212,164,.4); color: #a5f0da; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

/* ======================= 全屏放大预览 ======================= */
body.is-locked { overflow: hidden; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  background: #05070a;
  overflow: hidden;
  touch-action: none;
}
.lightbox.is-on { display: block; }

.lb-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: default;
}
#lbCanvas {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  will-change: transform;
  transition: transform .16s cubic-bezier(.2,.9,.3,1);
  box-shadow: 0 24px 80px rgba(0,0,0,.7);
}
#lbCanvas.is-free { transition: none; }

.lb-close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: 14px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  backdrop-filter: blur(12px);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 3;
}
.lb-close:hover { background: rgba(255,255,255,.18); }
.lb-close svg { width: 18px; height: 18px; }

.lb-bar {
  position: absolute;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(20,26,34,.88);
  border: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(14px);
  z-index: 3;
}
.lb-nav {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .14s;
}
.lb-nav:hover:not(:disabled) { background: rgba(255,255,255,.18); }
.lb-nav:disabled { opacity: .28; cursor: default; }
.lb-nav svg { width: 16px; height: 16px; }

.lb-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 128px;
}
.lb-meta span:first-child {
  font-size: 12px;
  color: #e8edf5;
  font-variant-numeric: tabular-nums;
}
.lb-tip { font-size: 9.5px; color: #6b7787; letter-spacing: .2px; white-space: nowrap; }

/* ======================= 素材网格（多图一览） ======================= */
.assets {
  position: fixed;
  inset: 0;
  z-index: 120;   /* 低于 toast(125)，导入提示还能看见；add-menu(130) 只在网格关闭后才开 */
  display: none;
  flex-direction: column;
  background: #0a0d12;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.assets.is-on { display: flex; }

.assets-head {
  flex: 0 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}
.assets-title { font-size: 13px; font-weight: 650; color: var(--text); }
.assets-title b { color: var(--accent); font-variant-numeric: tabular-nums; }
.assets-done {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 2px;
  cursor: pointer;
}

.assets-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  align-content: start;
}

.asset {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #141a22;
  cursor: pointer;
  transition: transform .12s;
}
.asset:active { transform: scale(.965); }
.asset canvas { width: 100%; height: 100%; display: block; }
.asset.is-active { box-shadow: 0 0 0 2px var(--accent) inset; }
.asset-idx {
  position: absolute;
  left: 5px;
  bottom: 5px;
  font-size: 9.5px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 5px;
  background: rgba(0,0,0,.62);
  color: #e8edf5;
  font-variant-numeric: tabular-nums;
}
.asset-cur {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 9px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
}
.asset-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  font-size: 9px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 5px;
  background: rgba(255,255,255,.9);
  color: #111;
}

.assets-foot {
  flex: 0 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}
.assets-foot .btn { width: 100%; height: 42px; gap: 6px; }
.assets-foot .btn svg { width: 15px; height: 15px; }

/* ======================= 缩略图（canvas 实时预览） ======================= */
.thumb canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.thumb-view {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 6px;
  background: rgba(10,12,15,.78);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .14s;
  backdrop-filter: blur(6px);
}
.thumb-view svg { width: 11px; height: 11px; }
.thumb:hover .thumb-view { opacity: 1; }
.thumb-view:hover { background: var(--accent); }

.icon-btn.is-active {
  background: rgba(76,141,255,.18);
  color: var(--accent);
}

.icon-btn:disabled {
  opacity: .3;
  cursor: default;
  pointer-events: none;
}

/* ======================= 移动端组件（桌面隐藏） ======================= */
.mobile-bar { display: none; }
.sheet-handle { display: none; }
.sheet-backdrop { display: none; }

.add-menu {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px);
}
.add-menu.is-on { display: flex; }

.add-menu-card {
  width: 100%;
  max-width: 460px;
  padding: 16px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-2);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line-2);
  animation: sheetUp .26s cubic-bezier(.2,1,.4,1);
}
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: none; }
}

.add-menu-title {
  font-size: 11.5px;
  color: var(--text-3);
  letter-spacing: .5px;
  padding: 0 12px 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.add-menu-title span { color: var(--accent); font-variant-numeric: tabular-nums; }
.add-item:disabled { opacity: .38; cursor: default; }

.ex-tip {
  margin: 2px 12px 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(255,176,32,.09);
  border: 1px solid rgba(255,176,32,.28);
  color: #f0c46a;
  font-size: 11px;
  line-height: 1.55;
  word-break: break-all;
}
.ex-tip b { color: #ffd98a; font-weight: 600; }

.add-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background .14s;
}
.add-item:hover { background: rgba(255,255,255,.05); }
.add-item:active { background: rgba(255,255,255,.09); }
.add-item svg { width: 22px; height: 22px; color: var(--accent); flex: 0 0 auto; }
.add-item span { display: flex; flex-direction: column; gap: 1px; }
.add-item em {
  font-style: normal;
  font-size: 11px;
  color: var(--text-3);
}

.add-cancel {
  width: 100%;
  margin-top: 8px;
  height: 46px;
  border: 0;
  border-radius: 13px;
  background: var(--bg-4);
  color: var(--text-2);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.add-cancel:active { background: #2c3441; }

.mb-btn {
  position: relative;
  flex: 1;
  height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 10.5px;
  cursor: pointer;
  transition: background .14s;
}
.mb-badge {
  position: absolute;
  top: 3px;
  left: 50%;
  margin-left: 9px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-style: normal;
  line-height: 15px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.mb-badge:empty, .mb-badge[data-n="0"] { display: none; }
.mb-btn svg { width: 18px; height: 18px; }
.mb-btn:active { background: rgba(255,255,255,.08); }
.mb-primary { color: var(--accent); }
.mb-primary:active { background: rgba(76,141,255,.14); }

/* 触摸设备：画布不参与页面滚动 */
#viewCanvas { touch-action: none; }

/* 桌面端弹窗居中 */
@media (min-width: 861px) {
  .add-menu { align-items: center; }
  .add-menu-card {
    border-radius: 16px;
    border: 1px solid var(--line-2);
    box-shadow: var(--shadow);
    padding-bottom: 12px;
  }
}

/* ======================= 响应式 ======================= */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 156px minmax(0,1fr) 288px; }
  /* 只隐藏中文副标题，版本号要留着——它是判断有没有拿到新 JS 的唯一线索 */
  .brand-text .sub { display: none; }
}

@media (max-width: 860px) {
  :root { --topbar-h: 54px; }

  .app { height: 100dvh; }

  .workspace {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
  }

  /* 画布在上 */
  .stage { order: 1; flex: 1 1 auto; min-height: 0; }

  /* 缩略图变成底部横条 */
  .rail {
    order: 2;
    flex: 0 0 auto;
    height: 90px;
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .rail-head, .rail-add { display: none; }
  .rail-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px;
    gap: 8px;
    align-items: center;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .rail-list::-webkit-scrollbar { display: none; }
  .thumb {
    width: 68px;
    height: 68px;
    flex: 0 0 auto;
    aspect-ratio: 1;
  }
  .thumb-del { opacity: 1; width: 18px; height: 18px; top: 3px; right: 3px; }
  .thumb-badge { font-size: 8.5px; padding: 0 4px; }
  /* 触屏没有 hover，放大按钮常显 */
  .thumb-view { opacity: .92; width: 18px; height: 18px; top: 3px; left: 3px; border-radius: 5px; }
  .thumb-view svg { width: 10px; height: 10px; }

  /* 参数面板变底部抽屉 */
  .panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 50vh;
    max-height: 460px;
    border-left: 0;
    border-top: 1px solid var(--line-2);
    border-radius: 18px 18px 0 0;
    transform: translateY(103%);
    transition: transform .3s cubic-bezier(.32,1,.4,1);
    z-index: 70;
    box-shadow: 0 -16px 48px rgba(0,0,0,.55);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overscroll-behavior: contain;
  }
  .panel.is-open { transform: translateY(0); }

  /* 抽屉打开时把工作区压到抽屉上方，保证画布始终完整可见 */
  .app.is-sheet .workspace { padding-bottom: min(50vh, 460px); }
  /* 调参时不需要缩略条，把 90px 纵向空间让给画布 */
  .app.is-sheet .rail { display: none; }
  .app.is-sheet .drag-hint { display: none; }

  .sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 9px 0 5px;
    position: sticky;
    top: 0;
    background: var(--bg-1);
    z-index: 3;
    cursor: grab;
    touch-action: none;
  }
  .sheet-handle span {
    width: 38px;
    height: 4px;
    border-radius: 3px;
    background: #3d4756;
  }

  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(0,0,0,.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity .26s;
  }
  .sheet-backdrop.is-on { opacity: 1; pointer-events: auto; }

  /* 底部工具条 */
  .mobile-bar {
    display: flex;
    flex: 0 0 auto;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    padding: 0 8px env(safe-area-inset-bottom, 0px);
    background: var(--bg-1);
    border-top: 1px solid var(--line);
    align-items: center;
    gap: 6px;
  }

  /* 顶栏收紧 */
  .topbar { gap: 8px; padding: 0 10px; }
  .brand { min-width: auto; }
  .brand-text { display: none; }
  .brand-mark { width: 30px; height: 30px; }
  .modes { gap: 1px; padding: 3px; }
  .mode-btn {
    flex-direction: column;
    gap: 2px;
    padding: 5px 7px;
    min-width: 50px;
  }
  .mode-btn svg { width: 16px; height: 16px; }
  .mode-btn span { display: block; font-size: 9px; line-height: 1; letter-spacing: 0; }
  .top-actions .btn { padding: 0 10px; }
  .top-actions .btn span { display: none; }

  .stage-bar { height: 34px; padding: 0 8px; }
  .chip { font-size: 10.5px; max-width: 108px; }
  .zoom-group span { min-width: 30px; font-size: 10px; }

  .canvas-scroll { padding: 10px; }
  /* 提示挪到画布顶部，避开默认右下角的水印 */
  .drag-hint { font-size: 10px; padding: 4px 9px; bottom: auto; top: 8px; }
  .stage-empty h2 { font-size: 15px; }
  .stage-empty p { font-size: 11.5px; }

  .panel-title { margin-bottom: 10px; }
  .group { padding: 11px; }

  /* 提示条抬高到缩略条 + 工具条之上 */
  .toast-wrap { bottom: calc(162px + env(safe-area-inset-bottom, 0px)); }
  .toast { font-size: 12px; padding: 8px 14px; }
}


/* ======================= 横屏手机：抽屉改侧滑，纵向空间还给画布 ======================= */
@media (max-width: 900px) and (orientation: landscape) {
  :root { --topbar-h: 46px; }

  .rail { height: 64px; }
  .rail-list { padding: 6px; gap: 6px; }
  .thumb { width: 48px; height: 48px; }

  .mobile-bar { height: calc(48px + env(safe-area-inset-bottom, 0px)); }
  .mb-btn { height: 40px; font-size: 9.5px; }
  .mb-btn svg { width: 16px; height: 16px; }
  .mb-badge { top: 1px; }

  .stage-bar { height: 30px; }
  .canvas-scroll { padding: 6px; }

  /* 参数面板从底部抽屉改成右侧抽屉 */
  .panel {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    width: 330px;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--line-2);
    transform: translateX(103%);
  }
  .panel.is-open { transform: none; }
  /* 侧滑抽屉占住右侧，画布在剩下的区域居中 */
  .app.is-sheet .workspace { padding-bottom: 0; padding-right: 330px; }
  .sheet-handle { display: none; }

  .toast-wrap { bottom: calc(110px + env(safe-area-inset-bottom, 0px)); }

  .assets-body { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
}
