/* ============================================================================
 * 用户端 H5 —— Widgy 风格
 *
 * 设计语言（参考 Widgy）
 *   · 深色底 + 深灰面板 + 大圆角 + 细边框
 *   · 蓝色强调色
 *   · 顶栏固定；中间内容滚动；编辑页 = 上预览 / 下功能面板
 *   · 图层行：图标 + 标题/副标题 + 右侧圆形操作按钮
 * ========================================================================== */

:root {
  --bg: #0b0d10;
  --bg-2: #14171c;
  --panel: #1a1e24;
  --panel-2: #22272f;
  --line: #2b3139;
  --text: #eef2f7;
  --muted: #8b95a3;
  --accent: #3d8bfd;
  --accent-soft: rgba(61, 139, 253, .16);
  --danger: #ff5a5f;
  --radius: 16px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* 软键盘高度：由 JS 用 Visual Viewport API 写入（见 installKeyboardInset）。
     键盘收起时是 0px，所以可直接参与 calc，不必再判断开/关。 */
  --kb-h: 0px;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
input { font: inherit; }

/* --------------------------------------------------------------------------
 * 视图容器
 * ------------------------------------------------------------------------ */
.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* 顶栏 */
.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: rgba(11, 13, 16, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}
.bar h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-spacer { flex: 0 0 40px; }

.icon-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  background: var(--panel-2);
  color: var(--text);
}
.icon-btn.primary { background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; }
.icon-btn.ghost { background: transparent; }
.icon-btn:disabled { opacity: .3; }
.icon-btn:active { transform: scale(.94); }
/* 图标按钮里的 <svg>：别让它参与字体排版，点击也始终由 button 接手 */
.icon-btn > svg { display: block; pointer-events: none; }

.scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(var(--safe-bottom) + 24px);
}

.section-title {
  margin: 20px 2px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 32px 12px; }

.hint { margin: 0 2px 6px; font-size: 12px; line-height: 1.5; color: var(--text); }
.hint.muted { color: var(--muted); }
.hint:empty { display: none; }

/* --------------------------------------------------------------------------
 * ① 我的组件库
 * ------------------------------------------------------------------------ */
.entry-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.entry-card {
  position: relative;
  height: 96px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.entry-card:active { transform: scale(.98); }
.entry-card .badge {
  position: absolute;
  top: 8px;
  right: 10px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-style: normal;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 作品列表：**一个作品一行**，行内并排该作品所有尺寸的缩略图。
   旧版是按尺寸分成 2x2 / 4x2 / 4x4 三段网格，一个作品只在其中一段出现、
   且只画一张图，多尺寸作品看起来像丢了尺寸。 */
.works-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.work-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  text-align: left;
  /* 兜底：行内任何东西算错尺寸都不许把整页撑出横向滚动
     （之前 .thumb-canvas 抢占优先级失败就是这样把布局搞崩的） */
  overflow: hidden;
}
.work-row:active { background: var(--panel-2); }

.work-thumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.work-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
/* 缩略图外框：高度统一 56px，宽度按该尺寸真实长宽比走，方便一行内对齐。
   边框用 inset box-shadow 而不是 border —— border 会占掉 2px 内容尺寸，
   让「按内容高度算出的缩放」和外框长宽比对不上，右边留一条缝。 */
.work-thumb .thumb-host {
  position: relative;
  height: 56px;
  border-radius: 6px;
  background: #0a0e14;
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
}
.work-thumb[data-size="2x2"] .thumb-host,
.work-thumb[data-size="4x4"] .thumb-host { aspect-ratio: 1 / 1; }
.work-thumb[data-size="4x2"] .thumb-host { aspect-ratio: 364 / 170; }
.work-thumb em {
  font-size: 10px;
  font-style: normal;
  color: var(--muted);
  line-height: 1;
}

/* 缩略图里的画布：按**画布原生像素**铺好（复用 .canvas[data-size] 的尺寸），
   再靠 transform: scale(--fit) 整体缩放 —— 与编辑器同一套样式，不会各画各的。

   ⚠️⚠️ 选择器必须写成 `.thumb-host .thumb-canvas`（两条类名），不能只写 `.thumb-canvas`：
   本文件里 `.canvas` 在**后面**（约 381 行），两者优先级相同 → 后者胜，
   于是 `position: absolute` 被 `.canvas` 的 `position: relative` 覆盖，
   画布变成**在流内**元素，把单元格撑到画布原生宽度（170 / 364px）。

   实测后果（macOS WKWebView，与 App 同一引擎）：一行两个缩略图时
   行 `scrollWidth 586 > clientWidth 360`，第二个缩略图被切在屏幕边缘、
   右侧的标题整块被挤出可视区；同时这些超大画布继承了 `.canvas` 的
   `touch-action: none`，把列表大半区域盖住 → **手指落上去滑不动列表**。
   提高优先级后画布才真的脱离文档流（见下方 touch-action 说明）。 */
.thumb-host .thumb-canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: top left;
  border: 0;
  border-radius: 0;
  /* 缩略图是纯展示的，绝不能拦住列表的纵向滑动。
     （.canvas 给编辑器画布设的是 none，那是拖拽元素用的，这里必须覆盖掉） */
  touch-action: pan-y;
}

.work-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1 1 auto;
}
.work-meta .t {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.work-meta .s {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.work-meta .tag {
  align-self: flex-start;
  margin-top: 2px;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 10px;
  font-style: normal;
  background: rgba(0, 0, 0, .55);
  color: #fff;
}
.work-meta .tag.draft { background: rgba(255, 180, 0, .85); color: #241a00; }

/* --------------------------------------------------------------------------
 * ② 组件模板
 * ------------------------------------------------------------------------ */
.new-blank {
  width: 100%;
  height: 56px;
  border-radius: var(--radius);
  border: 1px dashed var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.new-blank .plus { font-size: 20px; }
.new-blank:active { transform: scale(.99); }

.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tpl-card {
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
  text-align: left;
}
.tpl-card:active { transform: scale(.98); }
.tpl-card .thumb {
  height: 108px;
  background: var(--panel-2) center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tpl-card .thumb .mini-canvas {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  background: #fff;
  position: relative;
  overflow: hidden;
}
.tpl-card .meta { padding: 8px 10px 10px; }
.tpl-card .meta .t { font-size: 14px; font-weight: 600; }
.tpl-card .meta .s { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* --------------------------------------------------------------------------
 * ③ 创作编辑器
 * ------------------------------------------------------------------------ */
.ed-preview {
  flex: 0 0 auto;
  padding: 10px 14px 12px;
  background: var(--bg);
}
/* 键盘弹起时把画布预览整块让出去，高度全给下面的属性面板。
   ⚠️ 必须是「让出去」而不是只做滚动：App 里 Flutter 会随键盘把 WebView
   一起压矮（键盘形态 B，见 installKeyboardInset），此时 .ed-panel 是
   flex:1，会被挤到只剩几十像素 —— 输入框看着就是"被键盘挡住"。
   键盘收起后 kb-open 摘掉，预览自动恢复。 */
html.kb-open .ed-preview { display: none; }
.ed-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.size-chips { display: flex; gap: 6px; flex: 1 1 auto; }
.size-chips button {
  flex: 1 1 0;
  height: 32px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.size-chips button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.mini-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.mini-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* 作品名（存到 ssme 的 title 字段） */
.title-row { margin-bottom: 10px; }
.title-row input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
}
.title-row input::placeholder { color: var(--muted); }

/* 贴图缩放手柄（选中后右下角出现） */
.cv-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
  cursor: nwse-resize;
  touch-action: none;
}

/* 画布：原生像素尺寸 + transform 缩放（保证与生成脚本所见即所得）
   拖拽换算用 getBoundingClientRect()，对缩放透明 */
.canvas-wrap {
  display: flex;
  justify-content: center;
  overflow: hidden;
}
.canvas {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #0a0e14;
  transform-origin: top center;
  transform: scale(var(--fit, 1));
  touch-action: none;
}
.canvas[data-size="2x2"] { width: 170px; height: 170px; }
.canvas[data-size="4x2"] { width: 364px; height: 170px; }
.canvas[data-size="4x4"] { width: 364px; height: 364px; }

/* 图层容器必须 pointer-events:none，否则 inset:0 的容器会挡住下层，
   导致贴图（z-index 2）永远收不到指针事件——实测画布拖拽/缩放全部失效。
   只有真正的元素/贴图/手柄才恢复 pointer-events:auto。 */
.canvas .layer { position: absolute; inset: 0; pointer-events: none; }
.canvas .bg-layer { z-index: 1; }
.canvas .sticker-layer { z-index: 2; }
.canvas .element-layer { z-index: 3; }

/* 网格：10×10 淡网格，可开关 */
.grid-layer {
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, .14) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, .14) 1px, transparent 1px);
  background-size: 10% 10%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
}
.canvas.grid-on .grid-layer { opacity: 1; }

/* 吸附辅助线 */
.snap-guide { position: absolute; background: var(--accent); z-index: 6; pointer-events: none; }
.snap-guide.v { top: 0; bottom: 0; width: 1px; }
.snap-guide.h { left: 0; right: 0; height: 1px; }

/* 画布内元素 */
.cv-el {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
  cursor: grab;
  user-select: none;
  line-height: 1.15;
  pointer-events: auto;
}
.cv-el.selected { outline: 1px dashed var(--accent); outline-offset: 2px; }
.cv-sticker { position: absolute; cursor: grab; user-select: none; pointer-events: auto; }
.cv-sticker.selected { outline: 1px dashed var(--accent); outline-offset: 2px; }
.cv-sticker img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.cv-sticker .ph {
  width: 100%; height: 100%;
  border: 1px dashed rgba(255, 255, 255, .5);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; color: rgba(255, 255, 255, .7);
  text-align: center; padding: 2px;
}

/* 下部分：功能面板 */
.ed-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding-bottom: var(--safe-bottom);
}

/* 分类按钮（添加该分类的动态贴图） */
.cat-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 12px 14px 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.cat-bar::-webkit-scrollbar { display: none; }
.cat-bar button {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border-radius: 17px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.cat-bar button:active { transform: scale(.96); }

.panel-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 6px 14px 0;
}
.panel-tabs .ptab {
  flex: 1 1 0;
  height: 36px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.panel-tabs .ptab.active { background: var(--panel-2); color: var(--text); }

.panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* 底部多留一个键盘的高度：否则滚动区没有余量，聚焦的输入框
     **永远滚不到键盘之上**（iOS 弹键盘时布局视口不缩，见 installKeyboardInset）。
     键盘收起时 --kb-h 回到 0px，padding 自动还原。 */
  padding: 10px 14px calc(20px + var(--kb-h));
}

/* 面板里的原生表单控件要**把纵向滚动还给列表**。
   原因：这些控件（文本框 / 选择器 / 取色器 / 滑块）都是满宽的，几乎铺满面板中部，
   只有左右各 14px 的内边距是空白。iOS 上手指落在原生控件上时，手势容易被控件
   自己吃掉（文本选择、原生选择器、控件内部拖动），于是表现成
   「中间上滑滑不动、只有两边偶尔能滑动」。
   显式声明 pan-y：纵向滑动（滚动）一律允许，控件只保留自己需要的横向/点按行为。 */
.panel-body input,
.panel-body select,
.panel-body textarea {
  touch-action: pan-y;
}

/* 图层行：图标 + 标题/副标题 + 操作 / 显示隐藏 */
.layer-list { display: flex; flex-direction: column; gap: 8px; }
.layer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.layer-row.selected { border-color: var(--accent); background: var(--accent-soft); }
.layer-row .ico {
  flex: 0 0 30px;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--panel-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.layer-row .txt { flex: 1 1 auto; min-width: 0; }
.layer-row .txt .t {
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.layer-row .txt .s {
  font-size: 11px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.layer-row .ops { display: flex; gap: 6px; flex: 0 0 auto; }
/* 圆角胶囊而非正圆：正圆 34px 放不下「操作」「隐藏」两个汉字，会被挤成两行 */
.round-btn {
  min-width: 46px;
  height: 32px;
  padding: 0 9px;
  border-radius: 16px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.round-btn.on { background: var(--accent-soft); color: var(--accent); }
.round-btn.off { opacity: .45; }
.round-btn:active { transform: scale(.94); }

.add-row {
  width: 100%;
  margin-top: 10px;
  height: 44px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 14px;
}

/* 属性面板（内联在下面板，不遮预览） */
.prop-head {
  position: sticky;
  top: -10px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -10px -14px 12px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.prop-head .prop-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-btn.danger { color: var(--danger); border-color: rgba(255, 90, 95, .4); }
.mini-btn.upload { border-color: var(--accent); color: var(--accent); }

/* 原生 select（字体选择）*/
.native-select {
  width: 100%;
  height: 42px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
}

/* 图层行上的删除按钮（紧凑图标按钮）*/
.round-btn.del {
  min-width: 32px;
  padding: 0;
  color: var(--danger);
  font-size: 13px;
}

/* 输入框 + 右侧按钮（上传）*/
.row-with-btn { display: flex; gap: 8px; align-items: stretch; }
.row-with-btn input[type="text"] { flex: 1 1 auto; min-width: 0; }
.row-with-btn input[type="color"] { flex: 0 0 56px; min-height: 42px; }
.row-with-btn .mini-btn { flex: 0 0 auto; height: auto; min-height: 42px; }

/* 可直接输入/粘贴的 hex 文本框（iOS 原生取色器不能粘贴色值）。
   非法输入用红框提示 —— 只在失焦/超长时标注，不打断输入过程 */
.hex-input.invalid {
  border-color: var(--danger) !important;
  color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

/* 渐变颜色档 */
.color-stop {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.color-stop input[type="color"] { flex: 0 0 56px; height: 40px; }
.color-stop input[type="text"] { flex: 1 1 auto; min-width: 0; height: 40px; padding: 0 10px; }
.color-stop .stop-idx {
  flex: 0 0 auto;
  width: 20px;
  font-size: 11px;
  color: var(--muted);
}
.color-stop .rm {
  flex: 0 0 auto;
  width: 34px;
  height: 40px;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--muted);
}
.color-stop .rm:disabled { opacity: .3; }

/* 电量档位行 */
.band-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.band-row .thr {
  flex: 0 0 78px;
  height: 40px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 0 8px;
  font-size: 14px;
}
.band-row .url { flex: 1 1 auto; min-width: 0; }
.band-row .rm {
  flex: 0 0 auto;
  width: 34px;
  height: 40px;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--muted);
}
/* 尺寸选择列表 */
.size-list { display: flex; flex-direction: column; gap: 10px; }
.size-list button {
  height: 52px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 15px;
  color: var(--text);
}
.size-list button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* 保存对话框里的尺寸多选 */
.size-opts { display: flex; gap: 8px; }
.size-opts button {
  flex: 1 1 0;
  height: 44px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
}
.size-opts button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.size-opts button:disabled { opacity: .35; text-decoration: line-through; }

/* 分类行右端的尺寸按钮 */
.cat-bar .size-btn {
  margin-left: auto;
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* 十字方向键（Widgy 风格：原点 / 大小 并排一行） */
.dpad-row {
  display: flex;
  /* space-around 让两组各自居中于半区，摊开整个面板宽度，两侧不留大片空白 */
  justify-content: space-around;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
}
.dpad-block { flex: 0 0 auto; }
.dpad-title {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  text-align: center;
}
/*
 * ⚠️ 列宽与行高必须都是固定值。
 * 之前用 repeat(3, 1fr) + 44px 行高，单元格是 86×44 的【长方形】，
 * 配 border-radius:50% 出来的是椭圆（实测被指出「按钮是椭圆」）。
 */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 5px;
  justify-content: center;
}
.dpad .dbtn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.dpad .dbtn:active { transform: scale(.94); background: var(--accent-soft); }
.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .center {
  grid-area: 2 / 2;
  width: 44px;
  height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }

.dlg-btn.primary { background: var(--accent); color: #fff; font-weight: 600; }
.dlg-btn.primary:disabled { opacity: .4; }

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 2px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
}
.group-head::after {
  content: '';
  flex: 1 1 auto;
  height: 1px;
  background: var(--line);
}
.group-head:first-child { margin-top: 2px; }

/* 图层拖拽排序手柄 */
.layer-row .grip {
  flex: 0 0 auto;
  width: 26px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  margin-left: -4px;
}
.layer-row .grip:active { cursor: grabbing; }
.layer-row.dragging {
  opacity: .5;
  border-color: var(--accent);
}
.layer-row.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.layer-row.drop-after { box-shadow: 0 2px 0 var(--accent); }

/* 添加元素调色板 */
.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
}
.palette button {
  height: 76px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
}
.palette button:active { transform: scale(.96); }
.palette button .pi {
  font-size: 17px;
  color: var(--accent);
  line-height: 1;
}

/* 背景面板字段 */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input[type="text"] {
  width: 100%; height: 42px; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 15px;
}
.field input[type="color"] {
  width: 100%; height: 42px; padding: 2px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
}
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1 1 0; height: 40px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); font-size: 13px;
}
.seg button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* --------------------------------------------------------------------------
 * 属性抽屉 + 弹窗 + toast
 * ------------------------------------------------------------------------ */
.sheet-mask, .dialog-mask {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .5);
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 41;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding-bottom: var(--safe-bottom);
}
/* 底部抽屉里的输入框同样会被键盘盖住：整块抬到键盘之上（--kb-h 见 installKeyboardInset） */
html.kb-open .sheet { bottom: var(--kb-h); }
.sheet-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { flex: 1 1 auto; margin: 0; font-size: 15px; text-align: center; }
.sheet-body {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 16px 24px;
}

/* 滑块（目前只有「字号」用）。
   系统默认拇指在手机上约 16px，很难按住并连续拖动 —— 表现为「拖不动 / 一跳一跳」。
   这里放大到 22px，滑块行本身留 30px 触控高度，并给拖动中的反馈。 */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 30px;                 /* 触控区高度，不是轨道高度 */
  margin: 0;
  background: transparent;
  /* ⚠️ 这里原本是 `none`，是个 bug：`none` 表示「浏览器完全不处理手势」，
     于是手指落在滑块上纵向滑动时**页面滚不动**（滑块是满宽的，横跨整个面板）。
     改成 pan-y：纵向滑动照样滚页面，横向拖动仍归我们（滑块只需要横向）。
     JS 里另做了手势判定，纵向滑动不会误改字号。 */
  touch-action: pan-y;
  --thumb: 22px;                /* 拇指直径；JS 里按指针位置换算数值时要用 */
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc((4px - var(--thumb)) / 2);   /* 让拇指在轨道上居中 */
  border-radius: 50%;
  background: var(--accent);
  border: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.12);
  background: #5a9dff;
}
/* 非 WebKit 内核兜底（H5 主要跑 WebView，这里只保证不丑） */
input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 2px; background: var(--line);
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--accent);
}

.dialog {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 41;
  width: min(300px, 84vw);
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
}
.dialog h3 { margin: 0 0 14px; font-size: 15px; text-align: center; }

/* 弹窗里有输入框（保存对话框的作品名）：键盘弹起时，垂直居中会被键盘盖住
   下半截（含「保存」按钮），所以改成贴到键盘上沿之上，并把水平居中保留。
   变量 --kb-h 由 installKeyboardInset 写入，键盘收起时规则不生效（kb-open 摘掉）。 */
html.kb-open .dialog {
  top: auto;
  bottom: calc(var(--kb-h) + 16px);
  transform: translateX(-50%);
  max-height: calc(100% - var(--kb-h) - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* 确认弹窗正文 */
.dialog-msg { margin: 0 0 14px; font-size: 14px; line-height: 1.5; color: var(--muted); text-align: center; }
.dlg-btn {
  width: 100%; height: 44px; margin-bottom: 8px;
  border-radius: 12px; background: var(--panel-2);
  font-size: 15px;
}
.dlg-btn.danger { color: var(--danger); }
.dlg-btn.cancel { background: transparent; color: var(--muted); }

/* 底部演示提示 */
.mock-tip {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px calc(var(--safe-bottom) + 8px);
  font-size: 12px;
  color: #ffd479;
  background: rgba(255, 180, 0, .1);
  border-top: 1px solid rgba(255, 180, 0, .25);
}

.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-bottom) + 40px);
  transform: translateX(-50%);
  z-index: 60;
  max-width: 84vw;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .88);
  color: #fff;
  font-size: 13px;
  text-align: center;
}
.toast.err { background: rgba(200, 40, 45, .94); }

/* 横屏/大屏时限制内容宽度，避免拉伸 */
@media (min-width: 560px) {
  .view { max-width: 480px; left: 50%; transform: translateX(-50%); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet, .dialog { max-width: 480px; }
  .sheet { left: 50%; transform: translateX(-50%); }
}
