:root {
  --primary: #242c6d;
  --primary-2: #283179;
  --primary-soft: rgba(36, 44, 109, 0.08);
  --success: #29b348;
  --info: #44a2d2;
  --warning: #f5b225;
  --danger: #ec536c;
  --text: #2d3b48;
  --muted: #6c757d;
  --muted-soft: #a1a7cc;
  --border: #e9ecef;
  --border-input: #ced4da;
  --bg: #eff3f6;
  --rail: #f7f9fc;
  --panel: #ffffff;
  --line: #d5dee8;
  --line-soft: #e4ebf2;
  --accent: var(--primary);
  --accent-strong: var(--primary-2);
  --accent-dim: var(--primary-soft);
  --ok: var(--success);
  --surface: #f4f7fb;
  --surface-2: #ebf1f7;
  --shadow: 1px 0 20px rgba(0, 0, 0, 0.05);
  --radius: 6px;
  --rail-w: 56px;
  --side-w: 288px;
  --font: "Work Sans", "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --display: var(--font);
  --scroll-size: 8px;
  --scroll-track: color-mix(in srgb, var(--primary) 6%, transparent);
  --scroll-thumb: color-mix(in srgb, var(--primary) 28%, #d5d9e8);
  --scroll-thumb-hover: color-mix(in srgb, var(--primary) 48%, #c8cce0);
  --scroll-thumb-active: color-mix(in srgb, var(--primary) 68%, #b4b9d4);
}

* { box-sizing: border-box; }

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

/* Chromium / Safari */
*::-webkit-scrollbar {
  width: var(--scroll-size);
  height: var(--scroll-size);
}

*::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
  min-height: 32px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:active {
  background: var(--scroll-thumb-active);
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

/* 侧栏/列表略加强轨道，更好辨认 */
.sidebar-scroll,
.stitch-list,
.batch-log,
.rail-tools {
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

.sidebar-scroll::-webkit-scrollbar-track,
.stitch-list::-webkit-scrollbar-track,
.batch-log::-webkit-scrollbar-track,
.rail-tools::-webkit-scrollbar-track {
  background: var(--scroll-track);
  margin: 4px 0;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(900px 520px at 12% -10%, #d9e0f0 0%, transparent 55%),
    radial-gradient(760px 420px at 100% 0%, #e3e8f4 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

.app {
  display: grid;
  grid-template-columns: var(--rail-w) var(--side-w) 1fr;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns 0.22s ease;
}

.app.panel-collapsed {
  grid-template-columns: var(--rail-w) 0 1fr;
}

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  min-height: 0;
  height: 100%;
  background: color-mix(in srgb, var(--rail) 94%, white);
  border-right: 1px solid var(--line-soft);
  z-index: 5;
  overflow: visible;
}

.rail-logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  margin-bottom: 6px;
  overflow: hidden;
}

.rail-logo svg,
.rail-logo img {
  display: block;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.rail-tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 2px 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.rail-btn {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.rail-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* 提示改由 body 浮层渲染，避免伪元素撑出横向滚动条 */
.rail-btn[data-tip]::after,
.rail-btn[data-tip]::before {
  content: none !important;
  display: none !important;
}

.rail-fly-tip {
  position: fixed;
  z-index: 1000;
  padding: 6px 10px;
  border-radius: 6px;
  background: #1e2433;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(20, 24, 36, 0.22);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-50%) translateX(-2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.rail-fly-tip.is-on {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.rail-btn:hover:not(:disabled) {
  color: var(--text);
  background: rgba(28, 36, 48, 0.05);
}

.rail-btn.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
}

.rail-btn:disabled,
.rail-btn.soon {
  opacity: 0.38;
  cursor: not-allowed;
}

.rail-foot {
  margin-top: auto;
  padding-bottom: 4px;
}

.app.panel-collapsed #btnTogglePanel svg {
  transform: rotate(180deg);
}

#btnTogglePanel svg {
  transition: transform 0.22s ease;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  border-right: 1px solid var(--line-soft);
  transition: opacity 0.18s ease, border-color 0.18s;
}

.app.panel-collapsed .sidebar {
  opacity: 0;
  pointer-events: none;
  border-right-color: transparent;
}

.sidebar-head {
  flex: 0 0 auto;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.sidebar-title {
  font-family: var(--display);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.sidebar-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.sidebar-scroll {
  flex: 1;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-foot {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line-soft);
}

.module {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.module.hidden { display: none; }

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

.block {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.block > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.block > summary::-webkit-details-marker { display: none; }

.block > summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s;
  opacity: 0.8;
}

.block[open] > summary::after {
  transform: rotate(-135deg);
}

.block-body {
  padding: 4px 14px 16px;
  display: grid;
  gap: 14px;
}

.block-body > .form-group,
.block-body > .form-actions,
.block-body > .custom-control,
.block-body > .btn {
  margin-bottom: 0;
  margin-top: 0;
}

#wmTextPanel,
#wmImagePanel {
  display: grid;
  gap: 14px;
}

#wmTextPanel > .form-group,
#wmImagePanel > .form-group {
  margin-bottom: 0;
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 1.15rem;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  border-bottom: 1px solid #e8ecf2;
}

.seg-item {
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
}

.seg-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg-item span {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 0.7rem;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  color: #9aa3b5;
  transition: color 0.2s ease;
}

.seg-item span::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.22s ease;
}

.seg-item:hover span {
  color: var(--text);
}

.seg-item input:checked + span {
  color: var(--primary);
  font-weight: 700;
  background: transparent;
}

.seg-item input:checked + span::after {
  transform: scaleX(1);
}

.file-btn,
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 0.25rem;
  border: 1px solid var(--border-input);
  padding: 0.375rem 0.9rem;
  cursor: pointer;
  background: #fff;
  color: var(--text);
  transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-decoration: none;
  user-select: none;
  vertical-align: middle;
}

.btn.compact,
.btn-sm,
.file-btn.compact {
  padding: 0.25rem 0.55rem;
  font-size: 12.5px;
}

.file-btn:hover,
.btn:hover:not(:disabled):not(.disabled) {
  background: #f8f9fa;
  border-color: #b1b7c1;
}

.btn.primary,
.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled):not(.disabled),
.btn-primary:hover:not(:disabled):not(.disabled) {
  background-color: #1e245a;
  border-color: #1e245a;
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn.ghost:hover:not(:disabled):not(.disabled) {
  background: var(--primary-soft);
  color: var(--primary);
}

.btn-block {
  width: 100%;
  display: flex;
}

.btn:disabled,
.btn.disabled,
.file-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.form-actions {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.module-actions {
  margin-top: 8px;
  padding: 4px 2px 8px;
}

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

.seg.wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  border-bottom: 1px solid #e8ecf2;
  padding-bottom: 2px;
  margin-bottom: 2px;
}

.stitch-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  min-width: 0;
}

.stitch-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: #fff;
  min-width: 0;
  cursor: grab;
}

.stitch-item.dragging {
  opacity: 0.55;
  cursor: grabbing;
}

.stitch-item img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 0.2rem;
  background: var(--surface);
}

.stitch-item-name {
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.stitch-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.stitch-item-actions .btn {
  padding: 0.15rem 0.4rem;
  font-size: 11px;
  min-width: 28px;
}

/* File upload — 侧栏纵向排布，避免横向溢出 */
.file-upload {
  position: relative;
  min-width: 0;
  width: 100%;
}

.file-upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.file-upload-box {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border: 1px dashed var(--border-input);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  min-width: 0;
  overflow: hidden;
}

.file-upload:hover .file-upload-box,
.file-upload.is-dragover .file-upload-box,
.file-upload.has-file .file-upload-box {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.file-upload.disabled .file-upload-box {
  opacity: 0.6;
  cursor: not-allowed;
}

.file-upload-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-upload-icon {
  width: 36px;
  height: 36px;
  border-radius: 10%;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  flex-shrink: 0;
}

.file-upload.has-file .file-upload-icon {
  color: var(--success);
  background: rgba(41, 179, 72, 0.12);
}

.file-upload-meta {
  flex: 1;
  min-width: 0;
}

.file-upload-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-upload-hint {
  margin-top: 0.15rem;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
}

.file-upload-btn {
  width: 100%;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

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

.actions #btnDownload {
  grid-column: 1 / -1;
}

/* Forms — aligned with mp-hub */
.form-group,
.field {
  display: grid;
  gap: 8px;
  margin-bottom: 0;
}

.form-label,
label.form-label {
  display: inline-block;
  margin-bottom: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.form-value {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.form-text,
.mini {
  display: block;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}

.block-body > .form-text,
.block-body > .mini {
  margin: 0;
}

.form-control,
input.form-control,
select.form-control,
textarea.form-control,
.text {
  display: block;
  width: 100%;
  height: calc(2.25rem + 2px);
  padding: 0.375rem 0.75rem;
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  color: #495057;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid var(--border-input);
  border-radius: 0.25rem;
  transition: border-color 0.15s ease-in-out;
  appearance: none;
  -webkit-appearance: none;
}

select.form-control,
.custom-select {
  padding-right: 1.75rem;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 8px 10px;
}

.form-control:focus,
.text:focus {
  color: #495057;
  background-color: #fff;
  border-color: var(--primary);
  outline: 0;
  box-shadow: none;
}

.form-control::placeholder,
.text::placeholder {
  color: #adb5bd;
  opacity: 1;
}

.form-control.mono,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
}

.form-control-color {
  height: 2.5rem;
  padding: 0.25rem;
  cursor: pointer;
}

.form-range,
input[type="range"] {
  width: 100%;
  height: 1.4rem;
  padding: 0;
  background: transparent;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-control-color::-webkit-color-swatch-wrapper { padding: 0; }
.form-control-color::-webkit-color-swatch {
  border: none;
  border-radius: 0.2rem;
}

/* Checkbox — mp-hub custom-control */
.custom-control {
  position: relative;
  display: block;
  min-height: 1.5rem;
  padding-left: 1.5rem;
  margin: 2px 0;
}

.custom-control-input {
  position: absolute;
  z-index: -1;
  opacity: 0;
  width: 1rem;
  height: 1rem;
  left: 0;
  top: 0.2rem;
}

.custom-control-label {
  position: relative;
  margin-bottom: 0;
  vertical-align: top;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

.custom-control-label::before {
  position: absolute;
  top: 0.15rem;
  left: -1.5rem;
  display: block;
  width: 1rem;
  height: 1rem;
  pointer-events: none;
  content: "";
  background-color: #fff;
  border: 1px solid #adb5bd;
  border-radius: 0.25rem;
}

.custom-control-label::after {
  position: absolute;
  top: 0.15rem;
  left: -1.5rem;
  display: block;
  width: 1rem;
  height: 1rem;
  content: "";
  background: no-repeat 50% / 50% 50%;
}

.custom-control-input:checked ~ .custom-control-label::before {
  color: #fff;
  border-color: var(--primary);
  background-color: var(--primary);
}

.custom-control-input:checked ~ .custom-control-label::after {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23fff' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z'/%3e%3c/svg%3e");
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.batch-log {
  margin: 0;
  max-height: 140px;
  overflow: auto;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
}

.batch-log[hidden] { display: none; }

.status {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
  min-height: 2.6em;
}

.status.error { color: var(--danger); }
.status.ok { color: var(--success); }

.color {
  width: 100%;
  height: 34px;
  padding: 2px;
  border-radius: 0.25rem;
  border: 1px solid var(--border-input);
  background: #fff;
  cursor: pointer;
}

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

.tpl-btn {
  height: 34px;
  padding: 0 8px;
  border-radius: 0.25rem;
  border: 1px solid var(--border-input);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.tpl-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.workspace-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, #fff 78%, transparent);
}

.topbar-left {
  min-width: 0;
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  flex: 0 0 auto;
}

.topbar-sep {
  width: 1px;
  height: 20px;
  background: var(--line);
  margin: 0 4px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  display: block;
}

.icon-btn:hover:not(:disabled):not(.disabled) {
  border-color: #b7c6d6;
  background: var(--surface-2);
  color: var(--accent-strong);
}

.icon-btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.icon-btn.primary:hover:not(:disabled):not(.disabled) {
  background: #1e245a;
  border-color: #1e245a;
  color: #fff;
}

.icon-btn:disabled,
.icon-btn.disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

.brand-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand-sep {
  color: #b7c4d2;
  font-weight: 400;
}

.brand-tool {
  font-size: 14px;
  color: var(--muted);
}

.hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.stage {
  flex: 1;
  min-height: 0;
  padding: 14px;
  display: flex;
}

.dropzone,
.workspace {
  flex: 1;
  border: 1px dashed #b7c6d6;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.dropzone {
  flex-direction: column;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(47, 127, 212, 0.08);
}

.dropzone .sub {
  margin-top: 8px;
  font-size: 12px;
  opacity: 0.9;
}

.workspace { padding: 12px; }

.workspace.hidden,
.dropzone.hidden { display: none; }

#canvas {
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
  box-shadow: var(--shadow);
  background: #fff;
  border: 1px solid var(--line-soft);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

@media (max-width: 900px) {
  html, body {
    overflow-x: hidden;
    overflow-y: auto;
    max-width: 100%;
    width: 100%;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-x: none;
  }

  .app,
  .app.panel-collapsed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    height: auto;
    max-height: none;
    min-height: 100dvh;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: visible;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  /* 拆开工作区，使顶栏操作与画布可分别排序 */
  .workspace-wrap {
    display: contents;
  }
  .rail {
    order: 1;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 8px 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    gap: 6px;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line-soft);
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--rail) 96%, white);
    overflow: hidden;
  }
  .rail-tools {
    flex-direction: row;
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .rail-tools::-webkit-scrollbar {
    display: none;
    height: 0;
  }
  .rail-btn {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
  }
  .rail-fly-tip {
    max-width: min(70vw, 220px);
    white-space: normal;
  }
  .rail-fly-tip.is-on {
    transform: translateX(-50%) translateY(0);
  }
  .rail-foot {
    margin: 0 0 0 auto;
    flex: 0 0 auto;
  }
  .rail-logo {
    margin: 0 4px 0 0;
    flex: 0 0 auto;
  }
  .sidebar {
    order: 3;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: auto;
    max-height: min(36vh, 320px);
    border-right: none;
    border-bottom: 1px solid var(--line-soft);
    border-top: none;
    overflow-x: hidden;
  }
  .sidebar-scroll {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    overflow-x: hidden;
    max-width: 100%;
  }
  .sidebar-head,
  .sidebar-foot,
  .block-body,
  .module,
  .form-actions {
    max-width: 100%;
    min-width: 0;
  }
  .app.panel-collapsed .sidebar {
    display: flex; /* 移动端参数面板始终显示 */
  }
  #btnTogglePanel {
    display: none;
  }
  .topbar {
    order: 2;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    position: sticky;
    top: 58px;
    z-index: 18;
    background: color-mix(in srgb, #fff 92%, var(--bg));
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line-soft);
  }
  .stage {
    order: 4;
    padding: 10px;
    min-height: 48vh;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    display: flex;
  }
  .dropzone,
  .workspace {
    flex: 1;
    max-width: 100%;
    min-width: 0;
    overflow: auto;
    overflow-x: hidden;
  }
  .topbar-left,
  .topbar-actions,
  .brand-row,
  .hint {
    max-width: 100%;
    min-width: 0;
  }
  .hint {
    overflow-wrap: anywhere;
  }
  .topbar-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .icon-btn {
    width: 44px;
    height: 44px;
  }
  .btn,
  .seg-item span {
    min-height: 40px;
  }
  .seg {
    gap: 0.75rem 1rem;
    max-width: 100%;
  }
  .seg-item span {
    display: inline-flex;
    align-items: center;
    padding-left: 4px;
    padding-right: 4px;
  }
  .btn-grid {
    grid-template-columns: 1fr 1fr;
    max-width: 100%;
  }
  .form-control,
  .custom-select,
  input,
  select,
  textarea,
  button {
    max-width: 100%;
  }
  .form-control,
  .custom-select {
    min-height: 42px;
    font-size: 16px; /* 避免 iOS 聚焦自动放大 */
  }
  .file-upload,
  .file-upload-box,
  .stitch-list,
  .batch-log {
    max-width: 100%;
    min-width: 0;
  }
  .dropzone .sub {
    font-size: 13px;
    overflow-wrap: anywhere;
  }
  #canvas {
    max-width: 100%;
    max-height: min(58vh, 720px);
    width: auto;
    height: auto;
  }
}

