/* =========================================================
 * Components (v2)
 * 全站共用 UI 组件。工具页不得覆盖全局选择器(button/input)。
 * ========================================================= */

/* ---------- Button ---------- */
.btn {
  --_bg: var(--bg-surface);
  --_fg: var(--fg-strong);
  --_border: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid var(--_border);
  background: var(--_bg);
  color: var(--_fg);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast), border-color var(--dur-fast),
              color var(--dur-fast), transform var(--dur-fast);
  white-space: nowrap;
}
.btn:hover { --_bg: var(--bg-surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }

.btn.is-primary { --_bg: var(--color-brand); --_fg: var(--fg-invert); --_border: transparent; }
.btn.is-primary:hover { --_bg: var(--color-brand-hover); }

.btn.is-ghost { --_bg: transparent; --_border: transparent; color: var(--fg-base); }
.btn.is-ghost:hover { background: var(--bg-surface-2); color: var(--fg-strong); }

.btn.is-danger { --_bg: var(--color-danger); --_fg: var(--fg-invert); --_border: transparent; }
.btn.is-danger:hover { filter: brightness(.94); }

.btn.is-sm { padding: 6px 10px; font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn.is-lg { padding: 13px 22px; font-size: var(--text-md); border-radius: var(--radius-lg); }
.btn.is-block { width: 100%; }

.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Form ---------- */
.field { display: grid; gap: 6px; }
.field-label { font-size: var(--text-sm); font-weight: 600; color: var(--fg-base); }
.field-hint { font-size: var(--text-xs); color: var(--fg-muted); }
.field-error { font-size: var(--text-xs); color: var(--color-danger); }

.input,
.select,
.textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-surface);
  color: var(--fg-strong);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  line-height: 1.45;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
}
.textarea { min-height: 140px; resize: vertical; font-family: var(--font-mono); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--color-brand); box-shadow: var(--shadow-focus); outline: none; }
.input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }

.input-group {
  display: flex; align-items: stretch;
  border: 1px solid var(--border-base); border-radius: var(--radius-md);
  background: var(--bg-surface); overflow: hidden;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input-group:focus-within { border-color: var(--color-brand); box-shadow: var(--shadow-focus); }
.input-group > .input { border: 0; border-radius: 0; background: transparent; }
.input-group > .addon {
  display: inline-flex; align-items: center; padding: 0 12px;
  background: var(--bg-surface-2); color: var(--fg-muted);
  font-size: var(--text-sm); border-left: 1px solid var(--border-base);
}
.input-group > .addon:first-child { border-left: 0; border-right: 1px solid var(--border-base); }

/* Switch */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background var(--dur-fast); }
.switch .thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform var(--dur-fast); box-shadow: var(--shadow-xs); }
.switch input:checked ~ .track { background: var(--color-brand); }
.switch input:checked ~ .thumb { transform: translateX(16px); }

/* Checkbox/radio mini */
.checkbox, .radio { display: inline-flex; align-items: center; gap: 8px; font-size: var(--text-sm); cursor: pointer; user-select: none; }
.checkbox input, .radio input { accent-color: var(--color-brand); width: 16px; height: 16px; }

/* Range slider — track fill via --range-pct (set by JS) */
input[type="range"] {
  --range-pct: 50%;
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px;
  background: linear-gradient(to right, var(--color-brand) var(--range-pct), var(--bg-surface-2) var(--range-pct));
  border-radius: 3px; outline: none;
  cursor: pointer; transition: background .15s;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--color-brand); border: 2px solid var(--bg-surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
  margin-top: -6px;
  transition: transform .15s, box-shadow .15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.2); box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-brand) 20%, transparent); }
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--bg-surface);
  background: var(--color-brand); box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
input[type="range"]::-moz-range-progress { background: var(--color-brand); border-radius: 3px; height: 6px; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--bg-surface-2); }

/* ---------- Card ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--dur-base), transform var(--dur-base), border-color var(--dur-base);
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card-body { padding: var(--space-5); }
.card-title { font-size: var(--text-lg); font-weight: 650; color: var(--fg-strong); margin: 0 0 4px; }
.card-subtitle { color: var(--fg-muted); font-size: var(--text-sm); margin: 0; }
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.card-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-subtle); }

/* ---------- Tool card (首页/列表用) ---------- */
.tool-card {
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-lg);
  color: inherit;
  text-decoration: none;
  transition: transform var(--dur-base) var(--ease-emph),
              box-shadow var(--dur-base),
              border-color var(--dur-base);
  position: relative;
  overflow: hidden;
}
.tool-card::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(135deg, hsl(var(--brand-h) 90% 70% / 0), hsl(200 90% 70% / 0));
  opacity: 0;
  transition: opacity var(--dur-base);
  pointer-events: none;
}
.tool-card:hover {
  transform: translateY(-3px);
  border-color: var(--color-brand);
  box-shadow: var(--shadow-md);
}
.tool-card:hover::after { opacity: .08; }
[data-performance="low"] .tool-card:hover { transform: none; }
[data-performance="low"] .tool-card::after { display: none; }

.tool-card .tool-card-head { display: flex; align-items: center; gap: var(--space-3); }
.tool-card .tool-icon {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--color-brand-soft); color: var(--color-brand);
  font-size: 20px; flex-shrink: 0;
}
.tool-card h4 { margin: 0; font-size: var(--text-md); font-weight: 650; color: var(--fg-strong); }
.tool-card p { margin: 0; color: var(--fg-muted); font-size: var(--text-sm); line-height: 1.55; }
.tool-card .tool-card-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* Badges/tags */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; font-size: var(--text-xs); font-weight: 600;
  background: var(--bg-surface-2); color: var(--fg-muted);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
}
.badge.is-brand { color: var(--color-brand); background: var(--color-brand-soft); border-color: transparent; }

/* ---------- Tabs / Pills ---------- */
.tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  flex-wrap: wrap;
}
.tab-btn {
  padding: 8px 14px;
  font-size: var(--text-sm); font-weight: 600;
  color: var(--fg-muted);
  border-radius: var(--radius-pill);
  transition: background var(--dur-fast), color var(--dur-fast);
  display: inline-flex; align-items: center; gap: 6px;
}
.tab-btn:hover { color: var(--fg-strong); }
.tab-btn.is-active {
  background: var(--bg-surface); color: var(--fg-strong);
  box-shadow: var(--shadow-xs);
}

/* ---------- Search ---------- */
.search-shell {
  position: relative;
  display: flex; align-items: center;
  max-width: 560px; margin: 0 auto;
  background: var(--bg-surface); border: 1px solid var(--border-base);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.search-shell:focus-within { border-color: var(--color-brand); box-shadow: var(--shadow-focus); }
.search-shell .search-icon {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--fg-subtle); pointer-events: none;
}
.search-shell .search-box {
  flex: 1;
  -webkit-appearance: none; appearance: none;
  padding: 12px 16px 12px 44px;
  background: transparent; border: 0; outline: none; box-shadow: none;
  font-size: var(--text-md); color: var(--fg-strong);
  border-radius: inherit;
}
.search-shell .search-box:focus { outline: none; box-shadow: none; }
.search-shell .search-box::-webkit-search-cancel-button,
.search-shell .search-box::-webkit-search-decoration { -webkit-appearance: none; display: none; }
.search-shell .clear-search {
  margin-right: 6px;
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
}
.search-shell .clear-search:hover { background: var(--bg-surface-2); color: var(--fg-strong); }

/* ---------- Empty state ---------- */
.empty-panel {
  text-align: center;
  padding: var(--space-16) var(--space-4);
  color: var(--fg-muted);
}
.empty-panel h3 { color: var(--fg-strong); margin-bottom: 8px; font-size: var(--text-lg); }
.empty-panel p { margin: 0; }

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed; z-index: var(--z-toast);
  top: 20px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 200px; max-width: 80vw;
  padding: 10px 16px;
  background: var(--bg-inverse);
  color: var(--fg-invert);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  opacity: 0; transform: translateY(-8px);
  transition: opacity var(--dur-base), transform var(--dur-base);
}
.toast.is-in { opacity: 1; transform: translateY(0); }
.toast.is-success { background: var(--color-success); color: white; }
.toast.is-error   { background: var(--color-danger);  color: white; }
.toast.is-warn    { background: var(--color-warning); color: white; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: hsl(230 30% 10% / 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  opacity: 0; transition: opacity var(--dur-base);
}
.modal-backdrop.is-open { opacity: 1; }
[data-performance="low"] .modal-backdrop { backdrop-filter: none; }
.modal-panel {
  width: min(560px, 100%);
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(8px); transition: transform var(--dur-base) var(--ease-emph);
}
.modal-backdrop.is-open .modal-panel { transform: translateY(0); }
.modal-header { padding: var(--space-5); border-bottom: 1px solid var(--border-subtle); }
.modal-body { padding: var(--space-5); }
.modal-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-subtle); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Dock (macOS 风格底部快捷栏) ---------- */
body:has(.dock)::after { content: ''; display: block; height: 70px; }

.dock {
  position: fixed;
  bottom: 12px; left: 50%; transform: translateX(-50%);
  z-index: var(--z-dock);
  display: flex; align-items: end; gap: 6px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg-surface) 45%, transparent);
  backdrop-filter: blur(18px) saturate(1.6);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  transition: transform .3s ease, opacity .3s ease;
}
.dock.is-hidden {
  transform: translateX(-50%) translateY(calc(100% + 20px));
  opacity: 0; pointer-events: none;
}

.dock-item {
  position: relative;
  width: 52px; height: 52px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-base); font-size: 26px;
  text-decoration: none;
  transition: transform 180ms var(--ease-emph), margin 180ms var(--ease-emph);
  transform-origin: bottom center;
  cursor: pointer;
  flex-shrink: 0;
}
.dock-item:hover { transform: scale(1.4) translateY(-8px); margin: 0 8px; }
.dock-item.is-neighbor { transform: scale(1.18) translateY(-3px); margin: 0 4px; }
.dock-item img { width: 100%; height: 100%; border-radius: var(--radius-md); pointer-events: none; object-fit: cover; padding: 10px; box-sizing: border-box; }
.dock-item .lucide { width: 26px; height: 26px; }

.dock-tip {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) scale(0.8);
  background: var(--bg-inverse); color: var(--fg-invert);
  padding: 4px 10px; border-radius: var(--radius-sm);
  font-size: 11px; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity 120ms, transform 120ms;
}
.dock-item:hover .dock-tip { opacity: 1; transform: translateX(-50%) scale(1); }

.dock-sep {
  width: 1px; height: 34px;
  background: var(--border-strong); margin: 0 4px;
  flex-shrink: 0; align-self: center; opacity: .5;
}

.dock-add {
  background: var(--bg-surface-2); border: 1px dashed var(--border-strong);
  color: var(--fg-muted);
}
.dock-add:hover { background: var(--color-brand-soft); border-color: var(--color-brand); color: var(--color-brand); }

/* Dock 排序拖拽指示线 */
.dock-item.is-drag-before { box-shadow: -3px 0 0 0 var(--color-brand); }
.dock-item.is-drag-after  { box-shadow:  3px 0 0 0 var(--color-brand); }

/* Dock 拖拽放入高亮 */
.dock.is-drop-ready {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 2px var(--color-brand-ring), var(--shadow-md);
}
.dock.is-drop-hover {
  border-color: var(--color-brand);
  background: color-mix(in srgb, var(--color-brand) 18%, var(--bg-surface) 45%);
  box-shadow: 0 0 20px var(--color-brand-ring), 0 0 0 3px var(--color-brand-ring), var(--shadow-lg);
  transform: translateX(-50%) scale(1.06);
}

/* Dock 工具选择器弹窗 */
.dock-picker-overlay {
  position: fixed; inset: 0; z-index: calc(var(--z-dock) + 1);
  background: hsl(230 20% 10% / .35);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; transition: opacity var(--dur-base);
  display: none;
}
.dock-picker-overlay.is-open { display: block; opacity: 1; }

.dock-picker {
  position: fixed; z-index: calc(var(--z-dock) + 2);
  bottom: 88px; left: 50%; transform: translateX(-50%);
  width: 560px; height: 520px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: none; flex-direction: column;
  overflow: hidden;
}
.dock-picker.is-open { display: flex; }
.dock-picker-header {
  padding: 12px 16px; border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; gap: 8px;
}
.dock-picker-header input {
  flex: 1; background: var(--bg-surface-2); border: 1px solid var(--border-base);
  border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: var(--text-md); color: var(--fg-base); outline: none;
}
.dock-picker-header input:focus { border-color: var(--color-brand); }
.dock-picker-tabs {
  display: flex; gap: 4px; padding: 8px 16px; overflow-x: auto;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.dock-picker-tabs::-webkit-scrollbar { display: none; }
.dock-picker-tab {
  padding: 5px 12px; border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 600; color: var(--fg-muted);
  white-space: nowrap; cursor: pointer; border: none;
  background: transparent; transition: background var(--dur-fast), color var(--dur-fast);
}
.dock-picker-tab:hover { background: var(--bg-surface-2); }
.dock-picker-tab.is-active { background: var(--color-brand); color: var(--fg-invert); }
.dock-picker-list {
  flex: 1; overflow-y: auto; padding: 12px 16px;
}
.dock-picker-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
}
.dock-picker-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-md);
  cursor: pointer; font-size: var(--text-sm); color: var(--fg-base);
  transition: background var(--dur-fast);
  min-width: 0; overflow: hidden;
}
.dock-picker-item > div { min-width: 0; overflow: hidden; }
.dock-picker-item:hover { background: var(--bg-surface-2); }
.dock-picker-item.is-added { opacity: .55; cursor: pointer; }
.dock-picker-item.is-added:hover { opacity: 1; background: rgba(239,68,68,.06); }
.dock-picker-item.is-added .remove-hint { display: none; }
.dock-picker-item.is-added:hover .added-hint { display: none; }
.dock-picker-item.is-added:hover .remove-hint { display: inline; }
.dock-picker-item i { font-size: 20px; color: var(--fg-muted); width: 28px; text-align: center; flex-shrink: 0; }
.dock-picker-item .pi-title { font-weight: 600; }
.dock-picker-item .pi-desc { font-size: 11px; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock-picker-hint {
  flex-shrink: 0; padding: 10px 16px;
  border-top: 1px solid var(--border-subtle);
  font-size: var(--text-xs); color: var(--fg-subtle); text-align: center;
}

@media (max-width: 640px) {
  .dock { bottom: 8px; padding: 5px 6px; gap: 3px; }
  .dock-item { width: 42px; height: 42px; font-size: 22px; }
  .dock-item .lucide { width: 22px; height: 22px; }
  .dock-picker { width: calc(100vw - 32px); bottom: 74px; }
  .dock-picker-grid { grid-template-columns: 1fr; }
}

/* ---------- Panels / result area ---------- */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  min-width: 0;
}
:not(.grid) > .panel + .panel { margin-top: var(--space-4); }
.panel-title { font-size: var(--text-md); font-weight: 650; color: var(--fg-strong); margin: 0 0 var(--space-3); display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.panel-sub { color: var(--fg-muted); font-size: var(--text-sm); }

/* Inline result strip */
.result-strip {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4); border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  border: 1px dashed var(--border-base);
  font-family: var(--font-mono);
  color: var(--fg-strong);
  word-break: break-all;
  font-size: var(--text-md);
}

/* Stats row */
.stat-grid {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.stat {
  padding: var(--space-4); border-radius: var(--radius-md);
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle);
}
.stat-label { font-size: var(--text-xs); color: var(--fg-muted); margin-bottom: 4px; }
.stat-value { font-size: var(--text-2xl); font-weight: 700; color: var(--fg-strong); font-feature-settings: "tnum"; }

/* ---------- Chip / Tag ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-surface);
  font-size: var(--text-sm); cursor: pointer; transition: border-color .15s, background .15s;
}
.chip:hover { background: var(--bg-surface-2); }
.chip.is-active { border-color: var(--color-brand); background: var(--color-brand-soft); font-weight: 600; }
.chip-sub { font-size: var(--text-xs); color: var(--fg-muted); }

/* 列表条目（侧边栏 / 导航等） */
.list-item {
  padding: 6px 10px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: var(--text-sm); transition: background .15s;
}
.list-item:hover { background: var(--bg-surface-2); }
.list-item.is-active { background: var(--color-brand); color: var(--fg-invert); font-weight: 600; }

/* 结果行：左 label 右 value */
.result-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-3); padding: 6px 0;
  border-bottom: 1px dashed var(--border-subtle); font-size: var(--text-sm);
}

/* ---------- Table (轻量数据表) ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th, .data-table td { padding: 8px 10px; text-align: left; }
.data-table th { font-weight: 650; color: var(--fg-strong); border-bottom: 2px solid var(--border-base); }
.data-table td { border-bottom: 1px solid var(--border-subtle); }
.data-table tbody tr:hover { background: var(--bg-surface-2); }

/* ---------- Preview stage (html_preview / web_preview 共用) ---------- */
.preview-stage {
  position: relative; padding: 0; overflow: hidden;
  background: var(--bg-surface-2);
  display: flex; align-items: center; justify-content: center;
}
.preview-frame {
  border: 0; background: #fff;
  box-shadow: 0 8px 28px rgba(0,0,0,.12);
  transition: width var(--dur-base), height var(--dur-base), transform var(--dur-base);
  transform-origin: center center;
}
.preview-stage[data-device="desktop"] .preview-frame { position: static; width: 100%; height: 100%; }
.preview-stage[data-device="laptop"]  .preview-frame,
.preview-stage[data-device="tablet"]  .preview-frame,
.preview-stage[data-device="mobile"]  .preview-frame { position: absolute; }
.preview-stage[data-device="laptop"]  .preview-frame { width: 1440px; height: 900px; }
.preview-stage[data-device="tablet"]  .preview-frame { width: 834px;  height: 1194px; }
.preview-stage[data-device="mobile"]  .preview-frame { width: 390px;  height: 844px; border-radius: 24px; }

/* ---------- Embedded CodeMirror (填满 flex 父容器) ---------- */
.cm-embed { min-width: 0; overflow-x: hidden; }
.cm-embed .CodeMirror {
  flex: 1; min-height: 0;
  height: 100% !important; max-height: 65vh;
}
.cm-embed .CodeMirror-scroll { max-height: 65vh; }
.cm-embed .CodeMirror-focused { box-shadow: none; }

/* ---------- Back to top ---------- */
.back-top {
  position: fixed; right: 24px; bottom: 92px;
  z-index: var(--z-dock);
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-base);
  background: var(--bg-surface);
  color: var(--fg-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity var(--dur-base), transform var(--dur-base), background var(--dur-fast), color var(--dur-fast);
}
.back-top.is-visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
.back-top:hover { background: var(--color-brand-soft); color: var(--color-brand); border-color: var(--color-brand); }
.back-top svg, .back-top .lucide { width: 20px; height: 20px; }
