/* ════════════════════════════════════════════════
   M75 玩家名片編輯器 /dashboard/card/
   基礎（導覽列、--dark-void／--panel-dark／--hud-amber、.dash-gate、.g-btn）沿用 /dashboard/dashboard.css。
   這裡只放編輯器本體。

   原則：像排版工具／印刷打樣台。整頁唯一的大色塊是畫布上的名片；
   其餘只用字級、字重、1px 細線、留白分層。圓角 0、無陰影光暈、無漸層、無動畫。
   字型：Noto Sans TC（介面）＋Barlow Semi Condensed（數字一律 tabular-nums）。
   強調色只有一個：--hud-amber（選取、吸附、開關的開啟態、主要按鈕）。紅色只用於「刪除／移除」文字。
   ════════════════════════════════════════════════ */

.ce-page {
  --ce-bg:      var(--dark-void, #04060a);   /* 頁底與舞台 */
  --ce-panel:   var(--panel-dark, #080d14);  /* 頂列與左右欄 */
  --ce-field:   #05080c;                     /* 輸入欄底 */
  --ce-rule:    #18212b;                     /* 分區細線 */
  --ce-rule-2:  #2a3644;                     /* 控制項框線 */
  --ce-ink:     #dbe8f4;                     /* 主要文字 15:1 */
  --ce-ink-2:   #a3b4c5;                     /* 次要文字  9:1 */
  --ce-ink-3:   #75889c;                     /* 說明、單位 5.3:1 */
  --ce-accent:  var(--hud-amber, #f5a623);
  --ce-on-accent: #160e00;
  --ce-danger:  #ff8a98;
  --ce-hover:   rgba(219, 232, 244, 0.06);
  --ce-sel-bg:  rgba(245, 166, 35, 0.11);

  --ce-font:    "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --ce-num:     "Barlow Semi Condensed", "Arial Narrow", "Noto Sans TC", sans-serif;

  --ce-left-w:  clamp(232px, 16.5vw, 300px);
  --ce-right-w: clamp(250px, 17.5vw, 320px);
  --ce-bar-h:   46px;
  --ce-ctl-h:   28px;            /* 小欄位、按鈕高度 */
  --ce-handle:  9px;             /* 選取把手邊長（視覺） */
  --ce-hit:     26px;            /* 把手的指標命中區邊長（觸控版 44px） */

  /* 畫布顯示倍率：無單位。正式版由 JS 依舞台大小計算後寫在 #ce-frame 上；這裡是各寬度的預設值 */
  --ce-zoom: 0.9;
}
@media (max-width: 1699px) { .ce-page { --ce-zoom: 0.68; } }
@media (max-width: 1340px) { .ce-page { --ce-zoom: 0.6; } }
@media (max-width: 1100px) { .ce-page { --ce-zoom: 0.46; --ce-left-w: 220px; --ce-right-w: 240px; } }

/* ─── 頁面骨架：導覽列＋編輯器填滿視窗 ─── */
body.ce-page {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; overflow: hidden;
  background: var(--ce-bg);
  line-height: 1.45;
}
body.ce-page::before { content: none; }          /* 關掉 dashboard.css 的全頁格線底紋 */
.ce-page .blog-nav { flex: none; }
/* 編輯器需要垂直空間：共用導覽列在這頁不換行（只收間距，不改樣式） */
@media (min-width: 761px) and (max-width: 1500px) {
  .ce-page .blog-nav { padding-top: 0.6rem; padding-bottom: 0.6rem; gap: 1rem; }
  .ce-page .blog-nav ul { flex-wrap: nowrap; gap: 0.95rem; font-size: 0.95rem; white-space: nowrap; }
  .ce-page .blog-nav-logo img { width: 32px; height: 32px; }
}

.ce-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-family: var(--ce-num); font-variant-numeric: tabular-nums lining-nums; }

.ic {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: square; stroke-linejoin: miter;
}
.ic-sm { width: 14px; height: 14px; }

.ce-app, .ce-empty { font-family: var(--ce-font); color: var(--ce-ink); }
.ce-app button, .ce-app input, .ce-app select, .ce-app textarea { font: inherit; color: inherit; }
.ce-app button { cursor: pointer; }
.ce-app button:disabled { cursor: default; opacity: 0.38; }
.ce-app :focus { outline: none; }
.ce-app :focus-visible, .ce-empty :focus-visible { outline: 2px solid var(--ce-accent); outline-offset: 1px; }
.ce-app h2, .ce-app h3, .ce-app p, .ce-app ol, .ce-app ul, .ce-app dl, .ce-app dd { margin: 0; padding: 0; }
.ce-app ol, .ce-app ul { list-style: none; }

/* ─── 編輯器格局 ─── */
.ce-app {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: var(--ce-left-w) minmax(0, 1fr) var(--ce-right-w);
  grid-template-rows: var(--ce-bar-h) minmax(0, 1fr);
  grid-template-areas: "bar bar bar" "left stage right";
  font-size: clamp(12.5px, 0.2vw + 10.2px, 14.5px);
}

/* ═══ 頂列 ═══ */
.ce-bar {
  grid-area: bar;
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px 0 10px;
  background: var(--ce-panel);
  border-bottom: 1px solid var(--ce-rule);
  min-width: 0;
}
.ce-back {
  display: inline-flex; align-items: center; gap: 4px;
  height: var(--ce-ctl-h); padding: 0 8px 0 2px;
  color: var(--ce-ink-2); text-decoration: none; white-space: nowrap;
}
.ce-back:hover { color: var(--ce-ink); }
.ce-doc {
  min-width: 0; display: flex; align-items: baseline; gap: 10px; min-width: 0;
  padding-left: 14px; border-left: 1px solid var(--ce-rule);
}
.ce-name {
  display: block; max-width: 16em; min-width: 0; padding: 0 6px;
  font-weight: 700; font-size: 1.08em; line-height: var(--ce-ctl-h);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ce-save-state { font-size: 0.9em; color: var(--ce-ink-3); white-space: nowrap; }
.ce-save-state[data-state="dirty"] { color: var(--ce-accent); }
.ce-save-state[data-state="error"] { color: var(--ce-danger); }

.ce-tools { display: flex; align-items: center; gap: 8px; margin: 0 auto; min-width: 0; }
.ce-group { display: flex; align-items: center; gap: 2px; }
.ce-group + .ce-group { padding-left: 8px; border-left: 1px solid var(--ce-rule); }

.ce-ibtn {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  background: none; border: 1px solid transparent; color: var(--ce-ink-2);
}
.ce-ibtn:not(:disabled):hover { color: var(--ce-ink); background: var(--ce-hover); }

.ce-zoom-select {
  height: var(--ce-ctl-h); width: 5.4em; padding: 0 18px 0 6px;
  appearance: none; -webkit-appearance: none;
  background: var(--ce-field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2375889c' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 6px center;
  border: 1px solid var(--ce-rule-2);
  font-family: var(--ce-num); font-weight: 500; font-size: 1.05em; text-align: left;
}
.ce-zoom-select option { background: var(--ce-panel); color: var(--ce-ink); }

/* 開關按鈕（aria-pressed）：關＝灰字；開＝亮字＋強調色圖示＋淡底 */
.ce-tbtn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 8px;
  background: none; border: 1px solid transparent; color: var(--ce-ink-2);
  white-space: nowrap;
}
.ce-tbtn:hover { color: var(--ce-ink); background: var(--ce-hover); }
.ce-tbtn[aria-pressed="true"] { color: var(--ce-ink); background: var(--ce-sel-bg); }
.ce-tbtn[aria-pressed="true"] .ic { color: var(--ce-accent); }

.ce-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.ce-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  background: none; border: 1px solid var(--ce-rule-2); color: var(--ce-ink);
  white-space: nowrap;
}
.ce-btn:hover { border-color: var(--ce-ink-3); background: var(--ce-hover); }
.ce-btn-primary {
  min-width: 5.6em; justify-content: center;
  background: var(--ce-accent); border-color: var(--ce-accent); color: var(--ce-on-accent);
  font-weight: 700;
}
.ce-btn-primary:hover { background: #ffb84d; border-color: #ffb84d; }
.ce-more { display: none; }

/* ═══ 左欄 ═══ */
.ce-left {
  grid-area: left;
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  background: var(--ce-panel);
  border-right: 1px solid var(--ce-rule);
}
.ce-tabs { display: flex; border-bottom: 1px solid var(--ce-rule); }
.ce-tab {
  flex: 1; height: 38px; margin-bottom: -1px;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--ce-ink-2); font-weight: 500;
}
.ce-tab:hover { color: var(--ce-ink); }
.ce-tab[aria-selected="true"] { color: var(--ce-ink); font-weight: 700; border-bottom-color: var(--ce-accent); }

.ce-panel { display: none; min-height: 0; overflow-y: auto; padding: 12px 14px 24px; scrollbar-width: thin; scrollbar-color: var(--ce-rule-2) transparent; }
.ce-left[data-tab="templates"]  #ce-panel-templates,
.ce-left[data-tab="elements"]   #ce-panel-elements,
.ce-left[data-tab="background"] #ce-panel-background { display: block; }

.ce-help { margin: 0 0 10px; font-size: 0.9em; line-height: 1.55; color: var(--ce-ink-3); }
.ce-subhead {
  margin: 18px 0 4px; padding-bottom: 5px;
  border-bottom: 1px solid var(--ce-rule);
  font-size: 0.86em; font-weight: 700; letter-spacing: 0.04em; color: var(--ce-ink-2);
}
.ce-help + .ce-subhead, .ce-sec > .ce-subhead:first-child { margin-top: 2px; }

/* 範本 */
.ce-blank {
  display: flex; align-items: center; gap: 10px; width: 100%;
  height: 38px; padding: 0 10px;
  background: none; border: 1px dashed var(--ce-rule-2); color: var(--ce-ink-2);
  text-align: left;
}
.ce-blank:hover { color: var(--ce-ink); border-color: var(--ce-ink-3); }
.ce-blank-box { width: 28px; height: 16px; border: 1px solid var(--ce-ink-3); }

.ce-tpl-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 10px; margin-top: 14px; }
.ce-tpl {
  display: block; width: 100%; padding: 0;
  background: none; border: 0; color: var(--ce-ink-2); text-align: left;
}
.ce-tpl-thumb {
  position: relative; display: block; aspect-ratio: 16 / 9;
  background: #2b2f34; border: 1px solid rgba(255, 255, 255, 0.08);   /* 縮圖載不到時的灰塊 */
}
.ce-tpl-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.ce-tpl:disabled { cursor: default; opacity: 0.45; }
.ce-tpl-thumb .num {
  position: absolute; left: 0; top: 0; padding: 1px 6px 2px;
  font-size: 0.86em; font-weight: 600; color: var(--ce-ink); background: rgba(4, 6, 10, 0.72);
}
.ce-tpl-name { display: block; margin-top: 5px; font-size: 0.93em; line-height: 1.3; }
.ce-tpl:hover .ce-tpl-thumb { border-color: var(--ce-ink-3); }
.ce-tpl:hover .ce-tpl-name { color: var(--ce-ink); }
.ce-tpl.is-current .ce-tpl-thumb { outline: 2px solid var(--ce-accent); outline-offset: 2px; }
.ce-tpl.is-current .ce-tpl-name { color: var(--ce-ink); font-weight: 700; }

/* 元素清單 */
.ce-ellist li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 28px; padding: 0 4px 0 2px;
}
.ce-ellist li:hover { background: var(--ce-hover); }
.ce-ellist li.is-selected { background: var(--ce-sel-bg); }
.ce-ellist li.is-selected label { color: var(--ce-ink); font-weight: 700; }
.ce-ellist label { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--ce-ink); cursor: pointer; }
.ce-ellist li[data-placed="false"] label, .ce-ellist li.is-hidden label { color: var(--ce-ink-2); }
.ce-elstate { display: inline-flex; align-items: center; gap: 4px; font-size: 0.86em; color: var(--ce-ink-2); white-space: nowrap; }
.ce-elstate.is-off { color: var(--ce-ink-3); }

/* 方形勾選框（全編輯器共用） */
.ce-app input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 14px; height: 14px; margin: 0;
  border: 1px solid var(--ce-ink-3); background: var(--ce-field);
  display: inline-grid; place-content: center; cursor: pointer;
}
.ce-app input[type="checkbox"]:checked {
  background: var(--ce-accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='8'%3E%3Cpath d='M1 4l2.8 2.8L9 1.2' fill='none' stroke='%23160e00' stroke-width='1.8'/%3E%3C/svg%3E") no-repeat center;
  border-color: var(--ce-accent);
}

/* 新增裝飾 */
.ce-addgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
.ce-add {
  display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 8px;
  background: none; border: 1px solid var(--ce-rule-2); color: var(--ce-ink);
  text-align: left;
}
.ce-add .ic { color: var(--ce-ink-2); }
.ce-add:hover { border-color: var(--ce-ink-3); background: var(--ce-hover); }

/* 背景 */
.ce-sec { padding-bottom: 14px; }
.ce-swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 8px; }
.ce-swatch {
  width: 26px; height: 26px; padding: 0;
  background: var(--c); border: 1px solid rgba(255, 255, 255, 0.2);
}
.ce-swatch[aria-checked="true"] { outline: 2px solid var(--ce-accent); outline-offset: 2px; }

.ce-upload {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; margin-top: 8px;
  border: 1px dashed var(--ce-rule-2); color: var(--ce-ink); cursor: pointer;
}
.ce-upload:hover { border-color: var(--ce-ink-3); background: var(--ce-hover); }
.ce-upload:has(+ input:focus-visible) { outline: 2px solid var(--ce-accent); outline-offset: 1px; }
.ce-upload + input + .ce-help { margin-top: 6px; }

.ce-bgfile {
  display: grid; grid-template-columns: 64px minmax(0, 1fr); grid-template-rows: auto auto; align-items: center; gap: 2px 10px;
  padding: 8px 0; margin-bottom: 8px;
  border-top: 1px solid var(--ce-rule); border-bottom: 1px solid var(--ce-rule);
}
.ce-bgfile-thumb { grid-row: span 2; width: 64px; height: 36px; background: #3b4148; border: 1px solid rgba(255, 255, 255, 0.1); }
.ce-bgfile-meta { display: grid; min-width: 0; line-height: 1.3; }
.ce-bgfile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ce-bgfile-meta .num { font-size: 0.9em; color: var(--ce-ink-3); white-space: nowrap; }
.ce-bgfile .ce-link-danger { justify-self: start; }
.ce-link-danger {
  padding: 2px 0; background: none; border: 0;
  color: var(--ce-danger); font-size: 0.9em;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}

.ce-range { display: grid; grid-template-columns: 3.2em minmax(0, 1fr) auto; align-items: center; gap: 8px; height: 30px; margin-top: 4px; }
.ce-range label { color: var(--ce-ink-2); }
.ce-rv { width: 76px; }
.ce-rv input { text-align: right; padding-right: 0; }
.ce-rv .ce-fl { min-width: 0; padding: 0 6px 0 2px; }
.ce-app input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; margin: 0; background: none; cursor: pointer; }
.ce-app input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--ce-rule-2); }
.ce-app input[type="range"]::-moz-range-track { height: 2px; background: var(--ce-rule-2); }
.ce-app input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 8px; height: 16px; margin-top: -7px; background: var(--ce-ink); border: 0; }
.ce-app input[type="range"]::-moz-range-thumb { width: 8px; height: 16px; background: var(--ce-ink); border: 0; border-radius: 0; }

.ce-textures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 8px; margin-top: 8px; }
.ce-textures button { display: block; width: 100%; padding: 0; background: none; border: 0; color: var(--ce-ink-2); text-align: left; font-size: 0.92em; }
.ce-textures button[aria-checked="true"] { color: var(--ce-ink); font-weight: 700; }
.ce-textures button[aria-checked="true"] .ce-tex { outline: 2px solid var(--ce-accent); outline-offset: 2px; }
.ce-tex { display: block; aspect-ratio: 16 / 10; margin-bottom: 4px; border: 1px solid rgba(255, 255, 255, 0.1); }
.x0 { background: var(--ce-field); }
.x1 { background: #c9c0a7 repeating-linear-gradient(0deg, rgba(0,0,0,.05) 0 1px, transparent 1px 3px); }
.x2 { background: #dedad0 repeating-linear-gradient(90deg, rgba(0,0,0,.04) 0 1px, transparent 1px 4px); }
.x3 { background: #2c2824 radial-gradient(rgba(255,255,255,.07) 1px, transparent 1.3px) 0 0 / 4px 4px; }
.x4 { background: #e9e8e3 repeating-linear-gradient(0deg, rgba(0,0,0,.035) 0 2px, transparent 2px 7px); }
.x5 { background: #4a4d45 repeating-linear-gradient(90deg, rgba(255,255,255,.05) 0 1px, transparent 1px 3px); }

/* ─── 共用：小欄位 ─── */
.ce-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 8px; }
.ce-field {
  display: flex; align-items: center; min-width: 0;
  height: var(--ce-ctl-h);
  background: var(--ce-field); border: 1px solid var(--ce-rule-2);
}
.ce-field:focus-within { border-color: var(--ce-accent); }
.ce-field:has(:focus-visible) { outline: none; }
.ce-field :focus-visible { outline: none; }
.ce-fl { flex: none; min-width: 2.1em; padding: 0 4px 0 7px; font-size: 0.88em; color: var(--ce-ink-3); white-space: nowrap; }
.ce-field input, .ce-field select {
  flex: 1; min-width: 0; height: 100%;
  padding: 0 6px 0 2px; background: transparent; border: 0;
}
.ce-field input.num { font-size: 1.08em; font-weight: 500; }
.ce-field input[type="number"] { -moz-appearance: textfield; }
.ce-field input::-webkit-outer-spin-button, .ce-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ce-field select {
  appearance: none; -webkit-appearance: none; padding-right: 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2375889c' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 6px center;
}
.ce-field select option { background: var(--ce-panel); color: var(--ce-ink); }
.ce-unit { padding-right: 7px; color: var(--ce-ink-3); }
.ce-field-wide { margin: 6px 0; }
.ce-field-inline { width: 6.4em; }
.ce-chip { flex: none; width: 14px; height: 14px; margin: 0 4px 0 7px; background: var(--c); border: 1px solid rgba(255, 255, 255, 0.3); }
.ce-field-color .ce-fl { min-width: 0; }

.ce-seg { display: inline-flex; border: 1px solid var(--ce-rule-2); margin-top: 8px; }
.ce-seg button {
  height: calc(var(--ce-ctl-h) - 2px); padding: 0 12px;
  background: none; border: 0; color: var(--ce-ink-2);
}
.ce-seg button + button { border-left: 1px solid var(--ce-rule-2); }
.ce-seg button:hover { color: var(--ce-ink); }
.ce-seg button[aria-checked="true"] { background: var(--ce-sel-bg); color: var(--ce-ink); }
.ce-seg button[aria-checked="true"] .ic { color: var(--ce-accent); }
.ce-seg-icons { margin-top: 0; }
.ce-seg-icons button { display: inline-grid; place-items: center; width: 30px; padding: 0; }
.ce-seg-icons .ic { width: 16px; height: 16px; }

.ce-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.ce-tbtn-sq { height: var(--ce-ctl-h); border-color: var(--ce-rule-2); }
.ce-check { display: inline-flex; align-items: center; gap: 7px; color: var(--ce-ink); cursor: pointer; }

/* ═══ 畫布區 ═══ */
.ce-stage {
  grid-area: stage;
  display: grid; grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0; min-height: 0;
  background: var(--ce-bg);
}
.ce-stage-scroll { display: grid; overflow: auto; padding: 44px 32px 36px; user-select: none; -webkit-user-select: none; }

.ce-frame {
  position: relative; margin: auto;            /* auto 外距：比視窗小時置中，放大超出時仍可捲到左／上緣 */
  width: calc(1200px * var(--ce-zoom));
  height: calc(675px * var(--ce-zoom));
  outline: 1px solid #000;
}
.ce-app[hidden] { display: none; }
.ce-bar { position: relative; }
.ce-artboard {
  position: absolute; left: 0; top: 0;
  width: 1200px; height: 675px;
  transform: scale(var(--ce-zoom)); transform-origin: 0 0;
  overflow: hidden;
  background: #d9d2bd; color: #1d1f22;
  font-family: var(--ce-font);
}

/* 編輯疊層：不縮放，座標＝畫布 px × --ce-zoom */
.ce-overlay { position: absolute; inset: 0; pointer-events: none; }
.ce-overlay > * { position: absolute; }
.ce-layer { inset: 0; }
.ce-layer > * { position: absolute; }

.ce-gridlines {
  inset: 0; display: none;
  background-image:
    linear-gradient(90deg, rgba(20, 30, 40, 0.22) 1px, transparent 1px),
    linear-gradient(rgba(20, 30, 40, 0.22) 1px, transparent 1px);
  background-size: calc(100px * var(--ce-zoom)) calc(75px * var(--ce-zoom));   /* 12 欄 × 9 列 */
}
.ce-frame[data-grid="on"] .ce-gridlines { display: block; }

/* 安全邊界：深色虛線＋淺色細邊，淺底深底都看得到 */
.ce-safe {
  inset: calc(var(--inset) * var(--ce-zoom) * 1px);
  border: 1px dashed rgba(16, 20, 26, 0.7);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
}
.ce-frame[data-safe="off"] .ce-safe { display: none; }

/* 吸附參考線 */
.ce-guide-v {
  top: -14px; bottom: -14px; width: 1px;
  left: round(calc(var(--x) * var(--ce-zoom) * 1px), 1px);   /* 對齊整數像素，線才不會被反鋸齒糊成灰色 */
  background: var(--ce-accent);
  box-shadow: -1px 0 0 rgba(0, 0, 0, 0.35), 1px 0 0 rgba(0, 0, 0, 0.35);
}
.ce-guide-tag {
  left: calc(var(--x) * var(--ce-zoom) * 1px + 6px);
  top: calc(var(--y) * var(--ce-zoom) * 1px - 9px);
  padding: 0 5px; line-height: 17px; white-space: nowrap;
  background: var(--ce-accent); color: var(--ce-on-accent);
  font-size: 11px; font-weight: 600;
}

.ce-guide-h {
  left: -14px; right: -14px; height: 1px;
  top: round(calc(var(--y) * var(--ce-zoom) * 1px), 1px);
  background: var(--ce-accent);
  box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.35), 0 1px 0 rgba(0, 0, 0, 0.35);
}

/* 鍵盤代理：每個元素一顆透明按鈕（Tab 巡覽＝選取），不吃指標 */
.ce-proxy {
  left: calc(var(--x) * var(--ce-zoom) * 1px); top: calc(var(--y) * var(--ce-zoom) * 1px);
  width: calc(var(--w) * var(--ce-zoom) * 1px); height: calc(var(--h) * var(--ce-zoom) * 1px);
  padding: 0; border: 0; background: none; opacity: 0; pointer-events: none;
}

/* 鎖定元素 */
.ce-locked {
  left: calc(var(--x) * var(--ce-zoom) * 1px);
  top: calc(var(--y) * var(--ce-zoom) * 1px);
  width: calc(var(--w) * var(--ce-zoom) * 1px);
  height: calc(var(--h) * var(--ce-zoom) * 1px);
  outline: 1px dotted rgba(16, 20, 26, 0.75);
  outline-offset: 2px;
}
.ce-locked-tag {
  position: absolute; right: -10px; top: -10px;
  display: grid; place-items: center; width: 18px; height: 18px;
  background: var(--ce-bg); color: var(--ce-ink-2);
}
.ce-locked-tag .ic { width: 12px; height: 12px; }

/* 選取框＋把手 */
.ce-sel {
  left: round(calc(var(--x) * var(--ce-zoom) * 1px), 1px);
  top: round(calc(var(--y) * var(--ce-zoom) * 1px), 1px);
  width: round(calc(var(--w) * var(--ce-zoom) * 1px), 1px);
  height: round(calc(var(--h) * var(--ce-zoom) * 1px), 1px);
  outline: 2px solid var(--ce-accent);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3);
  transform-origin: 50% 50%;
}
.ce-sel[hidden] { display: none; }
.ce-sel.is-locked :is(.ce-h, .ce-rot) { display: none; }
.ce-h {
  position: absolute; width: var(--ce-handle); height: var(--ce-handle);
  margin: calc(var(--ce-handle) / -2) 0 0 calc(var(--ce-handle) / -2);
  background: var(--ce-accent); border: 1px solid #1a1206;
}
.ce-h, .ce-rot { pointer-events: auto; touch-action: none; }
/* 指標命中區往元素外側長（桌面 26px、觸控 44px），不蓋住元素本體，小元素也拖得動 */
.ce-h::before { content: ""; position: absolute; width: var(--ce-hit); height: var(--ce-hit); }
.h-nw::before { right: calc(var(--ce-handle) / 2); bottom: calc(var(--ce-handle) / 2); }
.h-ne::before { left: calc(var(--ce-handle) / 2); bottom: calc(var(--ce-handle) / 2); }
.h-se::before { left: calc(var(--ce-handle) / 2); top: calc(var(--ce-handle) / 2); }
.h-sw::before { right: calc(var(--ce-handle) / 2); top: calc(var(--ce-handle) / 2); }
.h-n::before  { left: 50%; margin-left: calc(var(--ce-hit) / -2); bottom: calc(var(--ce-handle) / 2); }
.h-s::before  { left: 50%; margin-left: calc(var(--ce-hit) / -2); top: calc(var(--ce-handle) / 2); }
.h-e::before  { top: 50%; margin-top: calc(var(--ce-hit) / -2); left: calc(var(--ce-handle) / 2); }
.h-w::before  { top: 50%; margin-top: calc(var(--ce-hit) / -2); right: calc(var(--ce-handle) / 2); }
.h-nw, .h-se { cursor: nwse-resize; } .h-ne, .h-sw { cursor: nesw-resize; }
.h-n, .h-s { cursor: ns-resize; } .h-e, .h-w { cursor: ew-resize; }
.ce-rot { cursor: grab; z-index: 2; }       /* 旋轉把手壓在上邊中把手的命中區之上 */
.ce-rot::before { content: ""; position: absolute; inset: -14px; }
.h-nw { left: 0;    top: 0; }
.h-n  { left: 50%;  top: 0; }
.h-ne { left: 100%; top: 0; }
.h-e  { left: 100%; top: 50%; }
.h-se { left: 100%; top: 100%; }
.h-s  { left: 50%;  top: 100%; }
.h-sw { left: 0;    top: 100%; }
.h-w  { left: 0;    top: 50%; }
.ce-rot {
  position: absolute; left: 50%; top: -30px;
  width: 12px; height: 12px; margin-left: -6px;
  background: #fff; border: 1px solid #1a1206; border-radius: 50%;
}
.ce-rot::after { content: ""; position: absolute; left: 4.5px; top: 11px; width: 1.5px; height: 18px; background: var(--ce-accent); box-shadow: 1px 0 0 rgba(0, 0, 0, 0.4); }
.ce-sel-size {
  position: absolute; left: 50%; top: calc(100% + 10px); transform: translateX(-50%);
  padding: 0 6px; line-height: 17px; white-space: nowrap;
  background: var(--ce-bg); color: var(--ce-ink); border: 1px solid var(--ce-rule-2);
  font-size: 11px; font-weight: 500;
}

/* 狀態列 */
.ce-status {
  display: flex; align-items: center; gap: 18px; min-width: 0;
  height: 28px; padding: 0 14px;
  border-top: 1px solid var(--ce-rule);
  font-size: 0.88em; color: var(--ce-ink-3); white-space: nowrap; overflow: hidden;
}
.ce-status-sel { color: var(--ce-ink-2); }
.ce-status-hint { margin-left: auto; overflow: hidden; text-overflow: ellipsis; }

/* ═══ 右欄 ═══ */
.ce-right {
  grid-area: right;
  display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, clamp(180px, 36%, 420px));
  min-height: 0;
  background: var(--ce-panel);
  border-left: 1px solid var(--ce-rule);
}
.ce-props { min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; padding: 0; overflow: hidden; }
.ce-props > .ce-rhead, .ce-props > .ce-help { padding-left: 14px; padding-right: 14px; }
.ce-props [hidden] { display: none; }
.ce-props > .ce-rhead { grid-row: 1; } .ce-props > .ce-help { grid-row: 2; } #ce-props-body { grid-row: 3; } .ce-props > .ce-sec-actions { grid-row: 4; }
#ce-props-body { min-height: 0; overflow-y: auto; padding: 0 14px; scrollbar-width: thin; scrollbar-color: var(--ce-rule-2) transparent; }
.ce-props .ce-sec.ce-sec-actions { padding: 10px 14px 12px; border-top: 1px solid var(--ce-rule); background: var(--ce-panel); }
.ce-rhead { padding: 10px 0 8px; }
.ce-rhead h2 { font-size: 0.86em; font-weight: 700; letter-spacing: 0.04em; color: var(--ce-ink-3); }
.ce-props-target { display: flex; align-items: baseline; gap: 8px; margin-top: 2px; }
.ce-props-target b { font-size: 1.15em; font-weight: 700; }
.ce-props-target span { font-size: 0.88em; color: var(--ce-ink-3); }
.ce-props .ce-sec { padding: 10px 0 12px; border-top: 1px solid var(--ce-rule); }
.ce-props .ce-sec > .ce-subhead { margin: 0 0 6px; padding: 0; border: 0; }

.ce-actrow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.ce-actrow + .ce-actrow { margin-top: 6px; }
.ce-actrow-order { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ce-act {
  display: inline-flex; align-items: center; gap: 5px; min-width: 0;
  height: 30px; padding: 0 7px;
  background: none; border: 1px solid var(--ce-rule-2); color: var(--ce-ink);
  font-size: 0.93em; white-space: nowrap;
}
.ce-act .ic { width: 16px; height: 16px; color: var(--ce-ink-2); }
.ce-act:not(:disabled):hover { border-color: var(--ce-ink-3); background: var(--ce-hover); }
.ce-act[aria-pressed="true"] { background: var(--ce-sel-bg); }
.ce-act-danger, .ce-act-danger .ic { color: var(--ce-danger); }
.ce-act-danger:not(:disabled):hover { border-color: var(--ce-danger); }

/* 圖層 */
.ce-layers { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; border-top: 1px solid var(--ce-rule); }
.ce-rhead-row { display: flex; align-items: baseline; justify-content: space-between; padding: 10px 14px 6px; }
.ce-layers-hint { font-size: 0.85em; color: var(--ce-ink-3); }
.ce-layerlist { counter-reset: ce-layer; overflow-y: auto; padding-bottom: 8px; scrollbar-width: thin; scrollbar-color: var(--ce-rule-2) transparent; }
.ce-layerlist li {
  display: grid; grid-template-columns: 1.8em minmax(0, 1fr) auto 24px 24px; align-items: center; gap: 4px;
  height: 27px; padding: 0 6px 0 10px;
  color: var(--ce-ink-2); cursor: default;
}
.ce-layerlist li::before {
  counter-increment: ce-layer;
  content: counter(ce-layer, decimal-leading-zero);
  font-family: var(--ce-num); font-variant-numeric: tabular-nums; font-size: 0.88em; color: var(--ce-ink-3);
}
.ce-layerlist li:hover { background: var(--ce-hover); }
.ce-layerlist li[aria-selected="true"] { background: var(--ce-sel-bg); color: var(--ce-ink); }
.ce-layerlist li[aria-selected="true"] .ce-ln { font-weight: 700; }
.ce-layerlist li[data-hidden="true"] .ce-ln { color: var(--ce-ink-3); text-decoration: line-through; text-decoration-thickness: 1px; }
.ce-layerlist li[data-fixed="true"] { border-top: 1px solid var(--ce-rule); }
.ce-ln { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ce-lk { font-size: 0.82em; color: var(--ce-ink-3); }
.ce-lbtn {
  display: inline-grid; place-items: center; width: 24px; height: 24px; padding: 0;
  background: none; border: 0; color: var(--ce-ink-3); opacity: 0.45;
}
.ce-layerlist li:hover .ce-lbtn, .ce-lbtn:focus-visible { opacity: 1; }
.ce-lbtn.is-on { opacity: 1; color: var(--ce-ink); }
.ce-lbtn:hover { color: var(--ce-ink); }

/* 其他新增 */
.ce-field-area { height: auto; align-items: flex-start; }
.ce-field-area .ce-fl { padding-top: 6px; }
.ce-field textarea { flex: 1; min-width: 0; padding: 5px 6px 5px 2px; resize: vertical; background: transparent; border: 0; line-height: 1.4; }
.ce-field-color { position: relative; }
.ce-chip { padding: 0; cursor: pointer; appearance: none; -webkit-appearance: none; }
input[type="color"].ce-chip, .ce-field input[type="color"].ce-chip { flex: none; height: 14px; width: 14px; margin: 0 4px 0 7px; padding: 0; background: var(--c, #000); border: 1px solid rgba(255, 255, 255, 0.3); }
input[type="color"].ce-chip::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"].ce-chip::-webkit-color-swatch { border: 0; }
input[type="color"].ce-chip::-moz-color-swatch { border: 0; }
.ce-auto { flex: none; height: 100%; padding: 0 7px; background: none; border: 0; border-left: 1px solid var(--ce-rule-2); color: var(--ce-ink-3); font-size: 0.86em; }
.ce-auto[aria-pressed="true"] { color: var(--ce-ink); background: var(--ce-sel-bg); }
.ce-help-warn { color: var(--ce-ink-2); }
.ce-upload.is-disabled { opacity: 0.4; cursor: default; }
.ce-bgfile-acts { grid-column: 1 / -1; display: flex; gap: 14px; margin-top: 4px; }
.ce-link { padding: 2px 0; background: none; border: 0; color: var(--ce-ink); font-size: 0.9em; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.ce-assetpick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
.ce-assetpick[hidden] { display: none; }
.ce-assetbtn { display: grid; place-items: center; width: 100%; aspect-ratio: 1; padding: 6px; background: #1b222a; border: 1px solid var(--ce-rule-2); }
.ce-assetbtn:hover { border-color: var(--ce-ink-3); }
.ce-assetbtn img { width: 100%; height: 100%; object-fit: contain; }
.ce-stage { position: relative; }
.ce-notes { position: absolute; left: 12px; right: 12px; top: 8px; z-index: 3; display: grid; gap: 4px; justify-items: start; pointer-events: none; }
.ce-note { margin: 0; padding: 3px 10px; background: var(--ce-panel); border: 1px solid var(--ce-rule-2); color: var(--ce-ink-2); font-size: 0.9em; }
.ce-note[hidden] { display: none; }
.ce-note-toast { color: var(--ce-ink); border-color: var(--ce-accent); }
.ce-moremenu {
  position: absolute; z-index: 5; right: 8px; top: calc(100% + 1px);
  display: grid; gap: 4px; padding: 8px; min-width: 220px;
  background: var(--ce-panel); border: 1px solid var(--ce-rule-2);
}
.ce-moremenu[hidden] { display: none; }
.ce-moremenu .ce-zoom, .ce-moremenu #ce-toggle-preview, .ce-moremenu #ce-reset { display: flex; }
.ce-moremenu .ce-tbtn, .ce-moremenu .ce-btn { justify-content: flex-start; }
.ce-layerlist li:focus-visible { outline-offset: -2px; }

/* 手機抽屜分頁（桌面不顯示） */
.ce-drawer-tabs { display: none; }

/* ═══ 空狀態（未登入／尚未 /link）═══ */
.ce-empty { flex: 1; overflow-y: auto; width: 100%; max-width: 760px; margin: 0 auto; padding: clamp(28px, 6vh, 64px) 20px 48px; }
.ce-empty-head { margin-bottom: 28px; }
.ce-empty-back { display: inline-flex; align-items: center; gap: 4px; color: var(--ce-ink-2); text-decoration: none; font-size: 0.95rem; }
.ce-empty-back:hover { color: var(--ce-ink); }
.ce-empty-head h1 { margin: 14px 0 6px; font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 700; line-height: 1.25; color: #fff; }
.ce-empty-head p { margin: 0; color: #8ea3b8; }
.ce-empty .dash-status { margin: 0; }

/* ═══ 平板以下：欄寬收窄 ═══ */
@media (max-width: 1340px) {
  .ce-tools { gap: 6px; }
  .ce-bar { gap: 10px; }
  .ce-status-hint { display: none; }
}

/* ═══ 手機：畫布置頂，工具收進底部抽屜 ═══ */
@media (max-width: 760px) {
  .ce-page { --ce-zoom: 0.31; --ce-handle: 10px; --ce-hit: 44px; --ce-ctl-h: 36px; --ce-bar-h: 52px; }

  /* 共用導覽列在這頁收成一行、可橫向捲動，把高度留給畫布 */
  .ce-page .blog-nav { gap: 0.8rem; padding: 0.4rem 0.75rem; }
  .ce-page .blog-nav-logo span { display: none; }
  .ce-page .blog-nav-logo img { width: 30px; height: 30px; }
  .ce-page .blog-nav ul { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; gap: 1rem; font-size: 0.95rem; scrollbar-width: none; }
  .ce-page .blog-nav ul::-webkit-scrollbar { display: none; }

  .ce-app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--ce-bar-h) auto auto minmax(0, 1fr);
    grid-template-areas: "bar" "stage" "tabs" "drawer";
    font-size: 14px;
  }

  /* 頂列：只留返回、名稱、復原重做、檢視、儲存 */
  .ce-bar { gap: 6px; padding: 0 8px 0 4px; }
  .ce-back { width: 40px; height: 40px; padding: 0; justify-content: center; }
  .ce-back span { display: none; }
  .ce-back .ic { width: 22px; height: 22px; }
  .ce-doc { flex: 1; flex-direction: column; gap: 0; padding-left: 8px; }
  .ce-name { max-width: 100%; line-height: 26px; padding: 0 4px; }
  .ce-save-state { padding-left: 5px; font-size: 0.8em; line-height: 1.2; }
  .ce-tools { margin: 0; gap: 0; }
  .ce-zoom, .ce-viewtoggles, #ce-toggle-preview, #ce-reset { display: none; }
  .ce-ibtn { width: 40px; height: 40px; }
  .ce-ibtn .ic { width: 20px; height: 20px; }
  .ce-more { display: inline-flex; height: 40px; border-color: var(--ce-rule-2); }
  .ce-btn-primary { height: 40px; min-width: 4.2em; }

  /* 畫布 */
  .ce-stage { grid-template-rows: auto auto; }
  .ce-stage-scroll { padding: 46px 8px 30px; overflow: hidden; touch-action: none; }   /* 高度由 JS 固定；縮放平移靠 transform，不靠捲動 */
  .ce-status { display: none; }
  /* 觸控版：邊中把手只在選取框夠寬／夠高（螢幕上 ≥ 90px，JS 加 .is-wide／.is-tall）才出現；四角永遠在 */
  .ce-sel:not(.is-wide) :is(.h-n, .h-s) { display: none; }
  .ce-sel:not(.is-tall) :is(.h-e, .h-w) { display: none; }
  .ce-rot { width: 16px; height: 16px; margin-left: -8px; top: -38px; }
  .ce-rot::before { inset: -14px; }
  .ce-rot::after { left: 6.75px; top: 15px; height: 22px; }
  .ce-guide-tag { font-size: 10px; }
  .ce-sel-size { top: calc(100% + 14px); }

  /* 抽屜 */
  .ce-drawer-tabs {
    grid-area: tabs; position: relative;
    display: flex; padding-top: 10px;
    background: var(--ce-panel);
    border-top: 1px solid var(--ce-rule-2); border-bottom: 1px solid var(--ce-rule);
  }
  .ce-grab { position: absolute; left: 50%; top: 4px; width: 36px; height: 3px; margin-left: -18px; background: var(--ce-rule-2); }
  .ce-drawer-tabs button {
    flex: 1; height: 44px; margin-bottom: -1px;
    background: none; border: 0; border-bottom: 2px solid transparent;
    color: var(--ce-ink-2); font: inherit; font-size: 14px;
  }
  .ce-drawer-tabs button[aria-selected="true"] { color: var(--ce-ink); font-weight: 700; border-bottom-color: var(--ce-accent); }

  .ce-left, .ce-right { grid-area: drawer; border: 0; display: none; }
  .ce-left .ce-tabs { display: none; }
  #ce-app .ce-left .ce-panel { display: none; padding: 12px 16px 28px; }
  #ce-app[data-drawer="templates"] .ce-left,
  #ce-app[data-drawer="elements"] .ce-left,
  #ce-app[data-drawer="background"] .ce-left { display: grid; grid-template-rows: minmax(0, 1fr); }
  #ce-app[data-drawer="templates"]  #ce-panel-templates,
  #ce-app[data-drawer="elements"]   #ce-panel-elements,
  #ce-app[data-drawer="background"] #ce-panel-background { display: block; }
  #ce-app[data-drawer="props"] .ce-right,
  #ce-app[data-drawer="layers"] .ce-right { display: grid; grid-template-rows: minmax(0, 1fr); }
  #ce-app[data-drawer="props"] .ce-layers,
  #ce-app[data-drawer="layers"] .ce-props { display: none; }

  .ce-props > .ce-rhead, .ce-props > .ce-help, #ce-props-body, .ce-props .ce-sec.ce-sec-actions { padding-left: 16px; padding-right: 16px; }
  .ce-rhead { padding-top: 12px; }
  .ce-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ce-props .ce-fields .ce-field-color { grid-column: span 2; }
  .ce-act, .ce-add, .ce-tbtn, .ce-seg button, .ce-blank { min-height: 40px; }
  .ce-seg-icons button { width: 40px; }
  .ce-ellist li, .ce-layerlist li { min-height: 40px; height: auto; }
  .ce-lbtn { width: 40px; height: 40px; }
  .ce-layerlist li { grid-template-columns: 2em minmax(0, 1fr) auto 40px 40px; }
  .ce-actrow-order { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .ce-actrow { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .ce-actrow:not(.ce-actrow-order) .ce-act { flex-direction: column; justify-content: center; gap: 2px; height: 52px; font-size: 0.82em; }
  .ce-actrow-order .ce-act { flex-direction: column; justify-content: center; gap: 2px; height: 52px; font-size: 0.82em; }
  .ce-app input[type="checkbox"] { width: 18px; height: 18px; }
  .ce-tpl-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
