/* ==========================================================================
   海报工坊 — 编辑器界面
   浅色专业工具风：白底、细线、克制的强调色，让画布上的配色成为主角。
   ========================================================================== */

:root {
  /* 表面 */
  --bg:            #f5f6f8;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --surface-3:     #f1f3f5;
  --stage:         #e9ebef;

  /* 线条 */
  --line:          #e3e6ea;
  --line-strong:   #cdd2d9;
  --line-focus:    #2563eb;

  /* 文字 */
  --ink:           #14181f;
  --ink-2:         #4a5361;
  --ink-3:         #7c8797;
  --ink-4:         #a8b1bd;

  /* 强调 */
  --accent:        #2563eb;
  --accent-ink:    #1d4ed8;
  --accent-soft:   #eef3fe;
  --danger:        #dc2626;
  --danger-soft:   #fef2f2;
  --lock:          #f59e0b;
  --lock-soft:     #fffbeb;
  --ok:            #16a34a;

  --radius:        8px;
  --radius-sm:     6px;
  --radius-lg:     12px;
  --shadow-sm:     0 1px 2px rgba(16, 24, 40, .06);
  --shadow:        0 4px 14px rgba(16, 24, 40, .10);
  --shadow-lg:     0 18px 48px rgba(16, 24, 40, .18);

  --topbar-h:      52px;
  --panel-w:       268px;
  --status-h:      34px;

  --font-ui: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", system-ui, sans-serif;
  --font-num: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }

/* ── 启动占位 ───────────────────────────────────────────────────────────── */
.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink-3);
  font-size: 14px;
  letter-spacing: .04em;
  background: var(--bg);
  z-index: 200;
}
.boot--error { color: var(--danger); white-space: pre-wrap; text-align: center; padding: 32px; }

/* ==========================================================================
   外壳
   ========================================================================== */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.topbar__logo { width: 26px; height: 26px; flex: 0 0 auto; border-radius: 7px; }
.topbar__name {
  width: 190px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-weight: 600;
  font-size: 13px;
}
.topbar__name:hover { background: var(--surface-3); }
.topbar__name:focus { outline: none; background: var(--surface); border-color: var(--line-focus); }

.topbar__group { display: flex; align-items: center; gap: 6px; }
.topbar__group--insert { flex: 0 0 auto; }
.topbar__group--right { margin-left: auto; flex: 0 0 auto; }

/* ── 按钮 ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); }
.btn svg { width: 16px; height: 16px; fill: currentColor; flex: 0 0 auto; }
.btn__caret { width: 9px !important; height: 9px !important; opacity: .6; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 0 14px;
}
.btn--primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }

.btn--icon { width: 32px; padding: 0; }
.btn--tiny { height: 22px; width: 22px; font-size: 14px; }

.btn--tool { flex-direction: column; height: 40px; gap: 1px; padding: 0 9px; font-size: 11px; color: var(--ink-2); }
.btn--tool svg { width: 17px; height: 17px; }
.btn--tool span { line-height: 1; }

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
}
.btn--ghost:hover { background: var(--surface-3); }

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

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg .btn { border: none; border-radius: 0; }
.seg .btn + .btn { border-left: 1px solid var(--line); }

.zoom { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.zoom .btn { border: none; border-radius: 0; }
.zoom__value {
  min-width: 54px;
  height: 32px;
  border: none;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.zoom__value:hover { background: var(--surface-3); }

/* ── 下拉菜单 ───────────────────────────────────────────────────────────── */
.menu-anchor { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 60;
}
.menu--right { left: auto; right: 0; }
.menu__title {
  margin: 6px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: .04em;
}
.menu__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
}
.menu__item:hover { background: var(--surface-3); }

.menu__grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 0 4px 4px; }
.shape-chip {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  padding: 6px;
}
.shape-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.shape-chip svg { width: 100%; height: 100%; }
.shape-chip path { fill: #cbd5e1; stroke: #64748b; stroke-width: 4; }
.shape-chip:hover path { fill: #bfdbfe; stroke: var(--accent); }

/* ==========================================================================
   工作区
   ========================================================================== */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr) var(--panel-w);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  z-index: 10;
}
.panel--left { border-right: 1px solid var(--line); }
.panel--right { border-left: 1px solid var(--line); }

.panel__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--line);
}
.panel__title { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.panel__count { margin-left: auto; font-size: 11px; color: var(--ink-4); font-variant-numeric: tabular-nums; }
.panel__scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.panel__foot {
  flex: 0 0 auto;
  display: flex;
  gap: 2px;
  padding: 6px;
  border-top: 1px solid var(--line);
}

/* ── 图层列表 ───────────────────────────────────────────────────────────── */
.tier-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 10px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
}
.tier-label em { font-style: normal; font-weight: 400; color: var(--ink-4); font-size: 10px; }
.tier-label--overlay span { color: var(--accent); }

.layers { list-style: none; margin: 0; padding: 0 6px; }
.layer {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}
.layer:hover { background: var(--surface-3); }
.layer.is-selected { background: var(--accent-soft); box-shadow: inset 0 0 0 1px #c7d9fb; }
.layer__icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--ink-3); }
.layer__icon svg { width: 100%; height: 100%; fill: currentColor; }
.layer__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.layer__name[contenteditable="true"] {
  outline: 1px solid var(--accent);
  border-radius: 3px;
  background: #fff;
  cursor: text;
}
.layer__badge { font-size: 10px; color: var(--ink-4); flex: 0 0 auto; }
.layer__lock {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-4);
  cursor: pointer;
}
.layer__lock:hover { background: #fff; color: var(--ink-2); }
.layer__lock svg { width: 13px; height: 13px; fill: currentColor; }
.layer.is-locked .layer__lock { color: var(--lock); }
.layer.is-locked .layer__name { color: var(--ink-3); }
.layer--child { margin-left: 12px; }
.layer--child::before {
  content: "";
  width: 8px;
  height: 8px;
  border-left: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  margin-left: -8px;
  margin-bottom: 6px;
  flex: 0 0 auto;
}
.layer--wire .layer__name { font-style: italic; color: var(--ink-2); }
.layers--wires { padding-bottom: 12px; }

/* ==========================================================================
   舞台
   ========================================================================== */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--stage);
}

.stage__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 28px;
}
.stage__inner { display: flex; justify-content: center; align-items: flex-start; min-height: 100%; }

/* The artboard is laid out at 1:1 and *scaled* with a transform, so scrolling
   still has to reserve the scaled footprint: `.artboard` is sized by script to
   the scaled dimensions and `.artboard__scale` carries the poster's own pixel
   size with the transform applied. */
.artboard {
  position: relative;
  flex: 0 0 auto;
  transform-origin: top left;
}
.artboard__scale {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .16), 0 12px 32px rgba(16, 24, 40, .10);
  transform-origin: top left;
  overflow: hidden;
}
.artboard.is-dropping .artboard__scale { outline: 3px dashed var(--accent); outline-offset: 4px; }

.artboard__bg { position: absolute; inset: 0; overflow: hidden; }
.artboard__grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(37, 99, 235, .10) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(37, 99, 235, .10) 1px, transparent 1px);
  background-size: 20px 20px;
}
.artboard__layers { position: absolute; inset: 0; }
.artboard__wires { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.artboard__ui { position: absolute; inset: 0; pointer-events: none; }

/* ── 元素 ───────────────────────────────────────────────────────────────── */
.element { position: absolute; }
.element__shape { position: absolute; inset: 0; width: 100%; height: 100%; }
.element__clipper { position: absolute; width: 0; height: 0; }
.element__content { position: absolute; inset: 0; }
.element__text { width: 100%; height: 100%; }
/* An empty picture area: a quiet slot waiting for a photo, not an error state.
   The dashed outline is the drop hint; it never reaches the export, because the
   exporter only paints an element when it has a picture. */
.element__slot {
  width: 100%;
  height: 100%;
  border: 1px dashed var(--line-strong);
  border-radius: 2px;
  background: repeating-linear-gradient(135deg, #fbfdff, #fbfdff 6px, #f4f7fb 6px, #f4f7fb 12px);
}
.element__missing {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(45deg, #f1f5f9, #f1f5f9 8px, #e2e8f0 8px, #e2e8f0 16px);
  color: var(--ink-3);
  font-size: 11px;
  border: 1px dashed var(--line-strong);
}

/* 锁定状态：只在编辑态提示，导出与 DOM 快照都不受影响 */
.element[data-locked="1"] { cursor: default; }

/* 文字编辑中 */
.element.is-editing { z-index: 50 !important; }
.element.is-editing .element__text {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  cursor: text;
  background: rgba(255, 255, 255, .55);
}

/* 图片拖动提示 */
.element[data-element-type="image"] { cursor: move; }
.element[data-element-type="image"] [data-image-wrapper] { pointer-events: none; }

/* ── 选中框 ─────────────────────────────────────────────────────────────── */
.selection {
  position: absolute;
  pointer-events: none;
  z-index: 90;
}
.selection__handle {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: 0;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  box-sizing: border-box;
  pointer-events: auto;
}
.selection__handle--rotate {
  left: 50%;
  top: -26px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  cursor: grab;
}
.selection__lock {
  position: absolute;
  top: -22px;
  right: 0;
  font-size: 12px;
  line-height: 1;
  background: var(--lock-soft);
  border: 1px solid var(--lock);
  border-radius: 4px;
  padding: 2px 4px;
}

/* ── 选中对象上的浮动工具条 ─────────────────────────────────────────────── */
.selection-tools {
  position: absolute;
  z-index: 96;
  transform: translateX(-50%);
  pointer-events: none;
}
.selection-tools__delete {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--danger);
  border-radius: 6px;
  background: #fff;
  color: var(--danger);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  pointer-events: auto;
  white-space: nowrap;
}
.selection-tools__delete:hover { background: var(--danger); color: #fff; }
.selection-tools__delete svg { width: 12px; height: 12px; fill: currentColor; }

/* ── 点与连线 ───────────────────────────────────────────────────────────── */
.point { z-index: 95; }
.point__dot { box-sizing: border-box; cursor: pointer; }
.point__label {
  font-family: var(--font-ui);
  text-shadow: 0 1px 0 #fff, 0 0 3px #fff;
  font-weight: 600;
}
.point[data-locked="1"] .point__dot { cursor: not-allowed; }

.link-hint {
  position: absolute;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 2px solid var(--danger);
  border-radius: 50%;
  animation: link-pulse 1.1s ease-out infinite;
  pointer-events: none;
}
@keyframes link-pulse {
  0%   { transform: scale(.6); opacity: .9; }
  100% { transform: scale(1.5); opacity: 0; }
}

.marquee {
  position: absolute;
  border: 1px solid var(--accent);
  background: rgba(37, 99, 235, .10);
  pointer-events: none;
}

/* ── 状态栏 ─────────────────────────────────────────────────────────────── */
.stage__status {
  flex: 0 0 auto;
  height: var(--status-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-3);
}
.status__size { font-variant-numeric: tabular-nums; }
.status__hint { color: var(--accent); font-weight: 600; }
.status__spacer { flex: 1 1 auto; }
.status__toggle {
  height: 22px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink-3);
  cursor: pointer;
  font-size: 11px;
}
.status__toggle:hover { background: var(--surface-3); }
.status__toggle.is-on { background: var(--accent-soft); border-color: #c7d9fb; color: var(--accent-ink); font-weight: 600; }
.status__zoom { display: flex; align-items: center; width: 120px; }

/* ==========================================================================
   检视器
   ========================================================================== */
.inspector__section { padding: 12px; border-bottom: 1px solid var(--line); }
.inspector__section:last-child { border-bottom: none; }
.inspector__head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.inspector__title { margin: 0; font-size: 11px; font-weight: 700; color: var(--ink-2); letter-spacing: .04em; }
.inspector__hint { margin: 6px 0 0; font-size: 11px; color: var(--ink-4); line-height: 1.45; }

.field-row { display: flex; gap: 8px; }
.field-row + .field-row { margin-top: 8px; }
.field { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.field__label { font-size: 11px; color: var(--ink-3); }

.input {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  font-variant-numeric: tabular-nums;
}
.input:hover { border-color: var(--line-strong); }
.input:focus { border-color: var(--line-focus); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
textarea.input { height: auto; min-height: 64px; padding: 6px 8px; resize: vertical; line-height: 1.5; font-variant-numeric: normal; }
select.input { cursor: pointer; padding-right: 4px; }
.input--mini { height: 24px; font-size: 11px; }

.range { width: 100%; accent-color: var(--accent); }

.check { display: flex; align-items: center; gap: 7px; margin-top: 8px; cursor: pointer; font-size: 12px; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; }

/* 颜色 */
.color-field { display: flex; align-items: center; gap: 6px; }
.color-field input[type="color"] {
  width: 30px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}
.color-field .input { flex: 1 1 auto; }
.swatches { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; margin-top: 6px; }
.swatch {
  aspect-ratio: 1;
  border: 1px solid rgba(0, 0, 0, .10);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
}
.swatch:hover { transform: scale(1.12); }

/* 分段选择 */
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.choice {
  height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-size: 11px;
  color: var(--ink-2);
  padding: 0 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.choice:hover { background: var(--surface-3); }
.choice.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.choices--two { grid-template-columns: repeat(2, 1fr); }
.choices--four { grid-template-columns: repeat(4, 1fr); }

/* 填充方式预览 */
.fit-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.fit-choice {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  padding: 4px 3px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.fit-choice:hover { border-color: var(--line-strong); background: var(--surface-2); }
.fit-choice.is-on { border-color: var(--accent); background: var(--accent-soft); }
.fit-choice__box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: #fff;
  overflow: hidden;
}
.fit-choice__fill { position: absolute; background: linear-gradient(135deg, #93b4f7, #2563eb); }
.fit-choice__label { font-size: 10px; color: var(--ink-2); white-space: nowrap; }
.fit-choice.is-on .fit-choice__label { color: var(--accent-ink); font-weight: 600; }

/* 分模板形状选择 */
.shape-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.shape-picker .shape-chip { padding: 5px; aspect-ratio: 1; }

/* 字体选择器 */
.font-picker__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}
.font-picker__trigger:hover { border-color: var(--line-strong); }
.font-picker__sample {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}
.font-picker__meta { flex: 0 0 auto; font-size: 10px; color: var(--ink-4); }

.font-sheet {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  background: rgba(16, 24, 40, .42);
  padding: 40px;
  gap: 16px;
}
.font-sheet__panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.font-sheet__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.font-sheet__title { margin: 0; font-size: 13px; font-weight: 700; }
.font-sheet__search { flex: 1 1 auto; }
.font-sheet__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 6px; }
.font-sheet__foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-3);
}

.font-group { padding: 6px 8px 2px; font-size: 11px; font-weight: 700; color: var(--ink-3); letter-spacing: .04em; }
.font-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.font-row:hover { background: var(--surface-3); }
.font-row.is-on { background: var(--accent-soft); box-shadow: inset 0 0 0 1px #c7d9fb; }
.font-row__sample { flex: 1 1 auto; min-width: 0; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.font-row__name { flex: 0 0 auto; font-size: 11px; color: var(--ink-3); max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.font-badge {
  flex: 0 0 auto;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--surface-3);
  color: var(--ink-3);
}
.font-badge--builtin { background: #dcfce7; color: #15803d; }
.font-badge--web { background: #e0e7ff; color: #4338ca; }

.font-sheet__preview {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
}
.font-preview__stage {
  flex: 1 1 auto;
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  overflow: hidden;
}

/* 分模板内图片位置：拖动圆点直接摆位 */
.position-pad__row { display: flex; align-items: flex-start; gap: 10px; }
.position-pad {
  position: relative;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  cursor: grab;
  touch-action: none;
}
.position-pad:active { cursor: grabbing; }
.position-pad__svg { width: 100%; height: 100%; display: block; }
.position-pad__thumb { fill: #93b4f7; stroke: var(--accent); stroke-width: 1; }
.position-pad__handle {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 2;
  pointer-events: none;
}
.position-pad__side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.position-pad__readout {
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 连线列表 */
.wire-list { display: flex; flex-direction: column; gap: 4px; }
.wire-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 11px;
}
.wire-item__dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.wire-item__text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   对话框
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  background: rgba(16, 24, 40, .42);
  padding: 24px;
  overflow-y: auto;
}
.dialog {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.dialog--narrow { width: min(460px, 100%); }
.dialog__head { padding: 18px 20px 12px; }
.dialog__title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .01em; }
.dialog__sub { margin: 5px 0 0; font-size: 12px; color: var(--ink-3); }
.dialog__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 20px 16px; }
.dialog__foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.dialog__note { flex: 1 1 auto; font-size: 11px; color: var(--ink-3); }

.setup__tabs { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 14px; background: var(--surface-3); border-radius: var(--radius-sm); }
.setup__tab {
  border: none;
  background: transparent;
  border-radius: 5px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-2);
}
.setup__tab.is-active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.setup__hint { margin: 12px 0 0; font-size: 11px; color: var(--ink-4); }

.preset-groups { display: flex; flex-direction: column; gap: 14px; }
.preset-group__title { margin: 0 0 8px; font-size: 11px; font-weight: 700; color: var(--ink-3); letter-spacing: .04em; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
.preset-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}
.preset-card:hover { border-color: var(--line-strong); background: var(--surface-2); }
.preset-card.is-on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.preset-card__thumb {
  height: 40px;
  display: grid;
  place-items: center;
}
.preset-card__shape { background: #cbd5e1; border-radius: 2px; }
.preset-card.is-on .preset-card__shape { background: var(--accent); }
.preset-card__label { font-size: 12px; font-weight: 600; }
.preset-card__note { font-size: 10px; color: var(--ink-4); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   提示条
   ========================================================================== */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  max-width: min(560px, 88vw);
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(20, 24, 31, .92);
  color: #fff;
  font-size: 12px;
  box-shadow: var(--shadow);
  animation: toast-in .22s ease;
}
.toast--ok { background: #14532d; }
.toast--warn { background: #78350f; }
.toast--error { background: #7f1d1d; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* 离屏测量容器：不参与布局，只供文本测量使用 */
.measure {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: pre;
}

/* ==========================================================================
   窄屏适配
   ========================================================================== */
@media (max-width: 1180px) {
  :root { --panel-w: 232px; }
  .topbar__name { width: 130px; }
  .btn--tool span { display: none; }
  .btn--tool { height: 34px; padding: 0 8px; }
  .font-sheet { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .font-sheet__preview { display: none; }
}

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .panel--left, .panel--right { display: none; }
}
