/* bead-studio · editor.css — 编辑器外壳（样张 v1）
 * 规范：DESIGN.md §6.1（画布 + 浮动工具条 + 四侧标尺 + 底部色量条 + 右面板 320px） */

body.editor {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--editor-panel-w);
  background:
    radial-gradient(820px 520px at 50% -12%, color-mix(in oklab, var(--color-accent) 7%, transparent), transparent 64%),
    var(--color-void);
  background-attachment: fixed;
}

/* ---------- 舞台（画布区） ---------- */

.editor__stage {
  position: relative;
  overflow: hidden;
}

/* 画布滚动容器 / 标尺 / 画布区：公共实现见 app.css「工作台共享组件」（v2.4 上收，编辑器与生成页共用） */

/* ---------- 浮动工具条 ---------- */

.toolbar {
  position: absolute;
  top: 16px;
  left: 50%;
  /* v2.24：居中偏移 + 让位位移（layoutChrome 写 --toolbar-shift；默认 0＝保持居中） */
  transform: translateX(calc(-50% - var(--toolbar-shift, 0px)));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: calc(6px * var(--ui-scale));
  border-radius: var(--radius-pill);
  max-width: calc(100% - 48px);
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }

/* v2.40：窄屏分组下拉按钮（桌面不显示——桌面仍是常驻的选区 / 镜像 / 缩放按钮）；
   选择器带 .toolbar 前缀压过公共层 .tool-btn 的 display */
.toolbar .tool-btn--mobile { display: none; position: relative; }

.toolbar__sep { width: 1px; height: calc(24px * var(--ui-scale)); background: var(--color-rule); margin: 0 6px; flex: none; }

/* 当前工具位：图标随 data-tool 切换 + 右下小箭头 */
.tool-slot { position: relative; }
.tool-slot .slot-icon { display: none; }
.tool-slot[data-tool="pen"] .slot-icon[data-tool="pen"],
.tool-slot[data-tool="drop"] .slot-icon[data-tool="drop"],
.tool-slot[data-tool="eraser"] .slot-icon[data-tool="eraser"],
.tool-slot[data-tool="bucket"] .slot-icon[data-tool="bucket"],
.tool-slot[data-tool="swap"] .slot-icon[data-tool="swap"],
.tool-slot[data-tool="pipette"] .slot-icon[data-tool="pipette"],
.tool-slot[data-tool="none"] .slot-icon[data-tool="none"] { display: block; }

/* 中性态（未选工具）：工具位提示「可点」——指针图标 + 琥珀细环，选出任意工具后提示消失 */
body.editor[data-tool="none"] .tool-slot {
  color: var(--color-accent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--color-accent) 42%, transparent);
}

.slot-caret {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: calc(11px * var(--ui-scale));
  height: calc(11px * var(--ui-scale));
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.7;
}

/* 工具弹层（锚定在工具位下方，JS 设置 left） */
.tool-pop {
  position: absolute;
  top: 74px;
  left: 16px;
  z-index: 25;
  display: flex;
  gap: 2px;
  padding: calc(8px * var(--ui-scale));
  border-radius: 18px;
}
.tool-pop[hidden] { display: none; }

.tool-pop__item {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: calc(72px * var(--ui-scale));
  padding: calc(10px * var(--ui-scale)) calc(4px * var(--ui-scale)) calc(8px * var(--ui-scale));
  border-radius: 12px;
  font-size: calc(12px * var(--ui-scale));
  color: var(--color-ink-2);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.tool-pop__item:hover { background: color-mix(in oklab, var(--color-ink) 6%, transparent); color: var(--color-ink); }
.tool-pop__item .icon { width: calc(22px * var(--ui-scale)); height: calc(22px * var(--ui-scale)); }
.tool-pop__item.is-active {
  background: var(--color-accent-soft);
  color: var(--color-ink);
  box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--color-accent) 55%, transparent);
}

/* 右上操作组：专注拼豆 / 导出图纸 / 面板开关 */
.stage-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: calc(6px * var(--ui-scale));
  border-radius: var(--radius-pill);
}
.stage-actions__sep { width: 1px; height: calc(20px * var(--ui-scale)); background: var(--color-rule); margin: 0 4px; flex: none; }
.stage-actions .btn { gap: 6px; }
.stage-actions .btn .icon { width: calc(15px * var(--ui-scale)); height: calc(15px * var(--ui-scale)); }
.icon-btn.is-active { background: var(--color-accent-soft); color: var(--color-accent); }

.tool-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: calc(36px * var(--ui-scale));
  height: calc(36px * var(--ui-scale));
  flex: none;
  border-radius: 10px;
  color: var(--color-ink-2);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.tool-btn:hover { background: color-mix(in oklab, var(--color-ink) 6%, transparent); color: var(--color-ink); }
.tool-btn.is-active { background: var(--color-accent-soft); color: var(--color-accent); }
.tool-btn:disabled { color: var(--color-neutral); cursor: not-allowed; }
.tool-btn:disabled:hover { background: none; }

/* 指针分工：画布＝绘制十字；舞台留白 / 平移模式＝抓手 */
body.editor #board { cursor: crosshair; }
body.editor .stage__scroller { cursor: grab; }
body.editor.pan-mode #board { cursor: grab; }
body.editor #ed-scroll.is-panning #board { cursor: grabbing; }
body.editor .stage__scroller.is-panning { cursor: grabbing; }

/* 工具弹层里的快捷键小字 */
.tool-pop__item .kbd { margin-top: -2px; }

/* 悬浮提示（仅桌面指针） */
@media (hover: hover) {
  .tool-btn[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 10px;
    border-radius: 8px;
    background: var(--color-paper-3);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    font-family: var(--font-mono);
    font-size: calc(11px * var(--ui-scale));
    color: var(--color-ink-2);
    white-space: nowrap;
    pointer-events: none;
    z-index: 30;
  }
}

/* ---------- 底部色量条 / 右侧面板 / 分段控件 / 色卡行：公共实现见 app.css「工作台共享组件」（v2.4 上收） ---------- */

/* ---------- 面板 · 画板设置（板型 / 自定义 / 四方向扩板） ---------- */

.board-actions { display: flex; gap: 8px; flex-wrap: wrap; } /* v2.23：放不下时换行，不得撑破固定宽面板 */
.board-actions .btn { flex: 1; }

.board-custom {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.board-custom[hidden] { display: none; } /* display:flex 会压过 hidden 属性，须显式让位 */
.board-custom__field { display: grid; gap: 6px; flex: 1; min-width: 0; }
.board-custom__x {
  padding-bottom: 10px;
  color: var(--color-muted);
  font-family: var(--font-mono);
}

#board-note[data-tone="warn"] { color: var(--color-warn); }

/* ---------- 图层行 ---------- */

.layer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-input);
  font-size: var(--ui-sm);
  color: var(--color-ink-2);
}
.layer-row .icon { width: calc(16px * var(--ui-scale)); height: calc(16px * var(--ui-scale)); }
.layer-row__name { flex: 1; color: var(--color-ink); }

/* ---------- 面板显示/隐藏（右上角开关） ---------- */

body.editor.panel-off { grid-template-columns: minmax(0, 1fr) 0; }
body.editor.panel-off .panel { display: none; }

/* ---------- 响应式 ---------- */

@media (max-width: 1279px) {
  body.editor { grid-template-columns: minmax(0, 1fr) 300px; }
  body.editor.panel-off { grid-template-columns: minmax(0, 1fr) 0; }
}

@media (max-width: 1023px) {
  body.editor { height: auto; overflow: auto; grid-template-columns: 1fr; }
  .editor__stage { min-height: 72vh; }
  /* v2.54：顶部只留**一行**浮动层（编辑抽屉入口 + 常驻操作组）——舞台顶距从「两行」的 96 收回「一行」的 48 */
  .stage__scroller { padding: calc(42px + 48px * var(--ui-scale)) 16px 96px; }
  .panel { height: auto; border-left: 0; border-top: 1px solid var(--glass-border); }
  .strip { width: calc(100% - 32px); }
  /* v2.54：操作组回到常驻（专注拼豆 · 导出 · 面板 · Aa），与工具条同一行右侧；
     窄屏压缩内边距 / 分隔线 / 图标按钮，让「返回胶囊 + 当前工具 + 四个操作」在 360 宽也放得下 */
  .stage-actions { top: 16px; right: 12px; padding: calc(4px * var(--ui-scale)); gap: 0; }
  .stage-actions__sep { margin: 0 calc(2px * var(--ui-scale)); }
  .stage-actions .icon-btn { width: calc(34px * var(--ui-scale)); height: calc(34px * var(--ui-scale)); }
  .stage-actions #export-open { padding-left: calc(8px * var(--ui-scale)); padding-right: calc(8px * var(--ui-scale)); }
  .tool-pop { max-width: calc(100vw - 32px); overflow-x: auto; }
  /* v2.26：工具条不再居中（居中盒宽跨过左上「返回首页」胶囊，胶囊 z-60 反压、工具位按钮被盖）——
     锚定胶囊右缘 + 12px（JS 量宽写 --toolbar-left，随档 / 随文案自适应；下方 calc 为兜底），右端留 20px，放不下横向滑动 */
  .toolbar {
    left: var(--toolbar-left, calc(28px + 106px * var(--ui-scale)));
    /* v2.46：不再 `right: 20px` 撑满整行——只包住这 5 个控件（此前那条长玻璃横贯整屏：
       视觉重、且空玻璃压在舞台上挡住旁边的可拖区域）；极窄 + 更大档仍允许控件等比收缩 */
    right: auto;
    width: fit-content;
    /* 可用宽＝舞台宽 − 本条的 left 偏移 − 20（max-width 只按包含块算，不减 left 会溢出） */
    max-width: calc(100% - var(--toolbar-left, calc(28px + 106px * var(--ui-scale))) - 20px);
    transform: none;
  }
  /* v2.54：工具条只留「当前工具」一格＝编辑抽屉入口；选区 / 撤销 / 重做 / 视图全部收进抽屉
     （用户：「把编辑栏的东西做成抽屉，你做进抽屉的才是进来就要看到的」——常驻让给操作组） */
  .toolbar { overflow: visible; }
  .toolbar .tool-btn--desktop,
  .toolbar .toolbar__sep--desktop { display: none; }
  .toolbar .tool-btn--mobile { display: inline-flex; }
  .toolbar #sel-btn,
  .toolbar #view-btn,
  .toolbar #undo,
  .toolbar #redo,
  .toolbar .toolbar__sep { display: none; }
  .toolbar { gap: 0; }
  .toolbar .tool-btn { flex: 0 1 auto; min-width: 0; }
}

/* v2.22 / v2.24 浮动层收纳：居中会撞上操作组时工具条先左移让位（--toolbar-shift，见 .toolbar）；
 * 真放不下（< 工具条宽 + 操作组宽 + 48）才把操作组落到第二行（JS 量宽切类 editor--chrome-stacked） */
@media (min-width: 1024px) {
  body.editor.editor--chrome-stacked .stage-actions { top: calc(28px + 48px * var(--ui-scale)); }
}

/* v2.25 手机：操作组收纳，整组永不左溢出屏（收纳后的按钮文案走 aria-label / title）——
   ≤640px 导出图纸图标化；「更大」档 ≤380px、标准 / 大档 ≤340px「专注拼豆」也图标化（断点按实测需要宽度定） */
@media (max-width: 640px) {
  #export-open .btn__label { display: none; }
  /* v2.26：返回胶囊只留图标（与焦点页同规，aria-label / title 保留）——给工具条腾出可见宽度 */
  body.editor .back-pill__label { display: none; }
}
@media (max-width: 380px) {
  html[data-ui="xl"] #focus-open .btn__label { display: none; }
}
@media (max-width: 340px) {
  #focus-open .btn__label { display: none; }
}
/* v2.54：≤420px 操作组再省两条分隔线、压缩「专注拼豆」内边距——
   一行两段（工具抽屉 + 四个操作）在 360 / 375 宽不许重叠 */
@media (max-width: 420px) {
  .stage-actions__sep { display: none; }
  .stage-actions #focus-open {
    padding-left: calc(8px * var(--ui-scale));
    padding-right: calc(8px * var(--ui-scale));
  }
}
/* v2.54：≤340px（320 宽 + 更大档）把「Aa 界面大小」收进编辑抽屉，保一行不重叠 */
@media (max-width: 340px) {
  .stage-actions [data-ui-size] { display: none; }
}

/* ---------- v2.54 窄屏编辑抽屉（工具位点开） ---------- */

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 75;
  background: var(--color-scrim);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.drawer-scrim[hidden] { display: none; }
/* 抽屉打开时锁住底页滚动（抽屉内部自己滚） */
body.drawer-open { overflow: hidden; }

.edit-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: calc(8px * var(--ui-scale));
  max-height: 68vh;
  padding: calc(10px * var(--ui-scale)) calc(16px * var(--ui-scale))
    calc(16px + env(safe-area-inset-bottom, 0px));
  border-radius: 20px 20px 0 0;
  border-bottom: 0;
  animation: drawer-rise var(--dur-mid) var(--ease-out);
}
.edit-drawer[hidden] { display: none; }

@keyframes drawer-rise {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .edit-drawer { animation: none; }
}

.edit-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: calc(2px * var(--ui-scale));
}
.edit-drawer__title {
  margin: 0;
  font-size: calc(15px * var(--ui-scale));
  font-weight: 600;
}
.edit-drawer__body {
  display: grid;
  gap: calc(10px * var(--ui-scale));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 2px;
}
.edit-drawer__label {
  margin: 0;
  font-size: var(--ui-xs);
  color: var(--color-muted);
}
.edit-drawer__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: calc(8px * var(--ui-scale));
}
.edit-drawer__group {
  display: grid;
  gap: calc(8px * var(--ui-scale));
}
.edit-drawer__group--ui { display: none; }
#drawer-ui { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* 只在右上「Aa」被收起的极窄屏出现（见文件末尾 ≤340px 规则） */
@media (max-width: 340px) {
  .edit-drawer__group--ui { display: grid; }
}
.edit-drawer__item {
  display: grid;
  justify-items: center;
  gap: calc(6px * var(--ui-scale));
  min-height: calc(62px * var(--ui-scale));
  padding: calc(8px * var(--ui-scale)) calc(4px * var(--ui-scale));
  border: 1px solid var(--color-line);
  border-radius: 12px;
  background: transparent;
  color: var(--color-ink-2);
  font-size: calc(12px * var(--ui-scale));
  line-height: 1.2;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
}
.edit-drawer__item .icon {
  width: calc(22px * var(--ui-scale));
  height: calc(22px * var(--ui-scale));
}
.edit-drawer__item:hover,
.edit-drawer__item:focus-visible {
  border-color: var(--color-accent);
  color: var(--color-ink);
}
.edit-drawer__item.is-active {
  border-color: color-mix(in oklab, var(--color-accent) 55%, transparent);
  background: var(--color-accent-soft);
  color: var(--color-ink);
}

/* ---------- v2.59 本机作品库（面板内列表：名字 + 尺寸 / 颗数 / 时间，点开即切换） ---------- */

.local {
  display: grid;
  gap: 6px;
  margin-top: var(--space-xs);
  padding-top: var(--space-xs);
  border-top: 1px solid var(--color-rule);
}
.local__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.local__title {
  font-size: var(--ui-sm);
  color: var(--color-ink-2);
}
.local__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.local__item { display: flex; align-items: center; gap: 4px; }
.local__open {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.local__open:hover {
  background: color-mix(in oklab, var(--color-ink) 5%, transparent);
  border-color: var(--color-rule);
}
.local__open.is-current {
  border-color: color-mix(in oklab, var(--color-accent) 45%, transparent);
  background: var(--color-accent-soft);
}
.local__name {
  font-size: var(--ui-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.local__meta {
  font-size: var(--ui-xs);
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}
.local__del {
  flex: none;
  width: calc(32px * var(--ui-scale));
  height: calc(32px * var(--ui-scale));
  color: var(--color-muted);
}
.local__del:hover { color: var(--color-danger); }
.local__state[data-tone="warn"] { color: var(--color-danger); }
