/* 默认主题：暖阳奶油羊绒 (Creamy Cashmere — 温暖、轻盈、柔和) */
:root,
html[data-theme="cashmere"] {
  --bg-canvas: #f4f0e8;
  --bg-inspector: #faf7f2;
  --bg-surface: #ffffff;
  --bg-subtle: #f7f3ec;
  --bg-muted: #efeae0;
  --bg-glass: rgba(250, 247, 242, 0.92);
  --line: rgba(148, 124, 94, 0.14);
  --line-strong: rgba(148, 124, 94, 0.28);
  --ink: #332b24;
  --ink-secondary: #6e6256;
  --ink-muted: #9e9183;
  --accent: #a8865e;
  --accent-hover: #94734d;
  --cta-bg: linear-gradient(180deg, #bfa07a 0%, #a88760 100%);
  --cta-bg-hover: linear-gradient(180deg, #c8aa85 0%, #b2916a 100%);
  --cta-ink: #ffffff;
  --cta-shadow: 0 6px 18px rgba(168, 135, 96, 0.22);
  --cta-disabled-bg: #e5ded2;
  --cta-disabled-ink: #afa496;
  --seg-active-bg: #ffffff;
  --seg-active-shadow: 0 2px 6px rgba(120, 96, 68, 0.09);
  --panel-shadow: 0 4px 20px rgba(120, 98, 72, 0.05);
  --card-shadow: 0 10px 28px rgba(110, 88, 62, 0.08);
  --radius-card: 14px;
  --radius-sm: 9px;
}

/* 可切换主题：晨风晴空浅蓝 (Airy Sky & Cloud — 清透、轻松、明快) */
html[data-theme="sky"] {
  --bg-canvas: #edf4fa;
  --bg-inspector: #f5f9fd;
  --bg-surface: #ffffff;
  --bg-subtle: #f0f7fc;
  --bg-muted: #e7f1f9;
  --bg-glass: rgba(245, 249, 253, 0.92);
  --line: rgba(92, 142, 186, 0.14);
  --line-strong: rgba(82, 134, 180, 0.28);
  --ink: #1f3242;
  --ink-secondary: #536d84;
  --ink-muted: #869fb4;
  --accent: #4a8ec8;
  --accent-hover: #3b7eb8;
  --cta-bg: linear-gradient(180deg, #5da1d9 0%, #488bc4 100%);
  --cta-bg-hover: linear-gradient(180deg, #69aae0 0%, #5294cd 100%);
  --cta-ink: #ffffff;
  --cta-shadow: 0 6px 18px rgba(72, 139, 196, 0.22);
  --cta-disabled-bg: #d6e5f2;
  --cta-disabled-ink: #94aec4;
  --seg-active-bg: #ffffff;
  --seg-active-shadow: 0 2px 6px rgba(56, 108, 154, 0.10);
  --panel-shadow: 0 4px 20px rgba(68, 118, 162, 0.05);
  --card-shadow: 0 10px 28px rgba(56, 104, 148, 0.08);
  --radius-card: 14px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-canvas);
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.22s ease, color 0.22s ease;
}

.hidden {
  display: none !important;
}

.mt-12 {
  margin-top: 12px;
}

.mb-12 {
  margin-bottom: 12px;
}

/* ================= 顶部栏 ================= */
.topbar {
  height: 54px;
  padding: 0 28px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

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

.brand-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.brand-sep {
  color: var(--line-strong);
  font-weight: 300;
}

.brand-sub {
  font-size: 12.5px;
  color: var(--ink-muted);
  letter-spacing: 0.03em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 22px;
}

.privacy-note {
  font-size: 12px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

.tone-switch {
  display: inline-flex;
  align-items: center;
  background: var(--bg-muted);
  padding: 3px 5px;
  border-radius: 99px;
  gap: 2px;
}

.tone-div {
  display: none;
}

.tone-btn {
  background: transparent;
  border: none;
  color: var(--ink-secondary);
  font-size: 12px;
  padding: 3px 11px;
  border-radius: 99px;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
}

.tone-btn.active {
  background: var(--bg-surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--seg-active-shadow);
}

.btn-link {
  background: none;
  border: none;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}

/* ================= 桌面端工作台布局 (>= 960px) ================= */
@media (min-width: 960px) {
  body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 388px 1fr;
    min-height: 0;
  }

  .inspector {
    border-right: 1px solid var(--line);
    background: var(--bg-inspector);
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .inspector::-webkit-scrollbar,
  .stage-viewport::-webkit-scrollbar {
    width: 6px;
  }

  .inspector::-webkit-scrollbar-thumb,
  .stage-viewport::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border-radius: 99px;
  }

  .mobile-drawer-tabs,
  .mobile-bottom-bar,
  #btnTopReset {
    display: none !important;
  }

  .stage {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-canvas);
  }

  .stage-viewport {
    flex: 1;
    overflow-y: auto;
    padding: 30px 36px;
  }

  .cards-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
    gap: 26px;
    align-items: start;
  }
}

/* ================= 控制面板模块 ================= */
.panel-block {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 18px;
  box-shadow: var(--panel-shadow);
}

.block-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 14px;
}

.block-index {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.block-head h2 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink);
  flex: 1;
}

.btn-text-muted {
  background: none;
  border: none;
  font-size: 12px;
  color: var(--ink-muted);
  cursor: pointer;
  transition: color 0.15s;
}

.btn-text-muted:hover {
  color: var(--accent);
}

/* 上传区 */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 11px;
  background: var(--bg-subtle);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
  text-align: center;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--bg-muted);
}

.dropzone-main {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.dropzone-hint {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 6px;
}

.demo-row {
  margin-top: 10px;
}

.btn-quiet {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  color: var(--ink-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  transition: border-color 0.16s, color 0.16s, background 0.16s;
}

.btn-quiet:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-surface);
}

/* 已加载缩略图条 */
.source-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.meta-text {
  font-size: 12px;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

.btn-add-more {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}

.thumb-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.thumb-item {
  position: relative;
  width: 52px;
  height: 88px;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  flex-shrink: 0;
  background: var(--bg-muted);
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-idx {
  position: absolute;
  bottom: 3px;
  right: 3px;
  background: rgba(31, 50, 66, 0.72);
  color: #ffffff;
  font-size: 10px;
  padding: 0 5px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}

/* 复选框行 */
.option-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.Line-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-secondary);
  cursor: pointer;
  user-select: none;
}

.Line-check input[type="checkbox"] {
  width: 14.5px;
  height: 14.5px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* 分段选择器 */
.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.row-label {
  font-size: 12.5px;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.seg-bar {
  flex: 1;
  display: flex;
  background: var(--bg-muted);
  padding: 3px;
  border-radius: var(--radius-sm);
  gap: 2px;
}

.seg-bar.compact {
  flex: initial;
}

.seg-item {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
  white-space: nowrap;
}

.seg-item.active {
  background: var(--seg-active-bg);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--seg-active-shadow);
}

/* 角色卡片列表 */
.placeholder-note {
  margin-top: 14px;
  padding: 20px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--ink-muted);
  text-align: center;
}

.role-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.role-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  transition: border-color 0.15s, background 0.15s;
}

.role-card.selected {
  border-color: var(--accent);
  background: var(--bg-surface);
}

.role-avatar-thumb {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  object-fit: cover;
  flex-shrink: 0;
}

.role-name-input {
  flex: 1;
  min-width: 54px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-surface);
  font-size: 12.5px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}

.role-name-input:focus {
  border-color: var(--accent);
}

.swatch-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.color-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid rgba(31, 50, 66, 0.16);
  cursor: pointer;
  padding: 0;
  transition: transform 0.14s;
}

.color-dot:hover {
  transform: scale(1.14);
}

.color-dot.active {
  outline: 2px solid var(--accent);
  outline-offset: 1.5px;
}

.role-count {
  font-size: 11.5px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  min-width: 26px;
  text-align: right;
}

/* 快捷命名词条 */
.preset-words {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.preset-caption {
  display: block;
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.word-chip {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  color: var(--ink-secondary);
  padding: 4px 11px;
  border-radius: 99px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.word-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-surface);
}

/* 清透主按钮 */
.desktop-export-wrap {
  margin-top: 18px;
}

.btn-primary {
  width: 100%;
  height: 42px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--cta-bg);
  color: var(--cta-ink);
  box-shadow: var(--cta-shadow);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.16s, transform 0.12s, box-shadow 0.16s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--cta-bg-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  background: var(--cta-disabled-bg);
  color: var(--cta-disabled-ink);
  box-shadow: none;
  cursor: not-allowed;
}

/* ================= 预览画廊舞台 ================= */
.stage-bar {
  height: 50px;
  padding: 0 28px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.stage-tabs {
  display: flex;
  gap: 26px;
  height: 100%;
}

.stage-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  height: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s, border-color 0.15s;
}

.stage-tab.active {
  color: var(--accent);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.count-num {
  font-size: 11px;
  background: var(--bg-muted);
  color: var(--accent);
  padding: 1px 7px;
  border-radius: 99px;
  font-variant-numeric: tabular-nums;
}

.canvas-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-outline-sm {
  background: var(--bg-surface);
  border: 1px solid var(--line-strong);
  color: var(--ink-secondary);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-outline-sm:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.stage-empty {
  height: 100%;
  min-height: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
}

.empty-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink-secondary);
  letter-spacing: 0.04em;
}

.empty-desc {
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-top: 8px;
  max-width: 360px;
}

/* 画廊卡片框 */
.slice-card-item {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slice-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.btn-dl-single {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  color: var(--ink-secondary);
  padding: 3px 11px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-dl-single:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-surface);
}

.slice-card-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}

/* 画布微调视图 */
.canvas-guide {
  font-size: 12.5px;
  color: var(--ink-secondary);
  text-align: center;
  margin-bottom: 16px;
}

.canvas-holder {
  display: flex;
  justify-content: center;
}

#interactiveCanvas {
  max-width: 440px;
  width: 100%;
  height: auto;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  cursor: crosshair;
  touch-action: none;
  background: var(--bg-surface);
}

/* ================= 手机端专属自适应布局 (< 960px) ================= */
@media (max-width: 959px) {
  .topbar {
    height: 48px;
    padding: 0 16px;
  }

  .brand-sub,
  .privacy-note,
  .brand-sep {
    display: none;
  }

  .topbar-right {
    gap: 12px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    padding-bottom: 78px;
  }

  body:not(.has-content) .stage,
  body:not(.has-content) .mobile-drawer-tabs,
  body:not(.has-content) .mobile-bottom-bar,
  body:not(.has-content) .panel-block[data-sec="roles"],
  body:not(.has-content) .panel-block[data-sec="layout"] {
    display: none !important;
  }

  body:not(.has-content) .inspector {
    padding: 24px 16px;
  }

  body:not(.has-content) .dropzone {
    padding: 54px 20px;
  }

  body.has-content .stage {
    order: 1;
    border-bottom: 1px solid var(--line);
  }

  body.has-content .inspector {
    order: 2;
    background: var(--bg-inspector);
    padding: 0 16px 20px;
  }

  .stage-bar {
    height: 44px;
    padding: 0 16px;
  }

  .stage-tabs {
    gap: 18px;
  }

  .stage-viewport {
    padding: 16px;
  }

  .cards-gallery {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
  }

  .slice-card-item {
    flex: 0 0 74vw;
    max-width: 300px;
    scroll-snap-align: center;
    padding: 10px;
  }

  .mobile-drawer-tabs {
    display: flex;
    border-bottom: 1px solid var(--line);
    margin: 0 -16px 16px;
    padding: 0 16px;
    background: var(--bg-surface);
  }

  .m-tab {
    flex: 1;
    height: 42px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-muted);
    cursor: pointer;
  }

  .m-tab.active {
    color: var(--accent);
    font-weight: 600;
    border-bottom-color: var(--accent);
  }

  body.has-content .panel-block {
    display: none;
    border: none;
    box-shadow: none;
    padding: 2px 0;
    background: transparent;
  }

  body.has-content .panel-block.is-mobile-active {
    display: block;
  }

  body.has-content .block-head {
    display: none;
  }

  .desktop-export-wrap {
    display: none;
  }

  .mobile-bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    z-index: 30;
  }
}

/* ================= 弹窗与手机端相册直存浮层 ================= */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(34, 28, 22, 0.36);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 90;
}

.modal-card {
  width: 100%;
  max-width: 392px;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 22px;
  box-shadow: var(--card-shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.modal-head h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.03em;
}

.modal-desc {
  font-size: 12.5px;
  color: var(--ink-secondary);
  margin-bottom: 14px;
}

.modal-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--ink);
  font-size: 13.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.modal-input:focus {
  border-color: var(--accent);
  background: var(--bg-surface);
}

.modal-err {
  margin-top: 8px;
  font-size: 12px;
  color: #b8564b;
}

.modal-save-sheet {
  max-width: 440px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
}

.mobile-save-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 2px;
  -webkit-overflow-scrolling: touch;
}

.mobile-save-item {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.mobile-save-label {
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

.mobile-save-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  -webkit-touch-callout: default;
  user-select: auto;
}

@media (max-width: 640px) {
  .modal-mask {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card.modal-save-sheet {
    max-width: 100%;
    max-height: 88vh;
    border-radius: 18px 18px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
}
