/* ============ BeadDay — Figma-inspired Design System ============ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Noto+Sans+SC:wght@300;400;500;600;700&display=swap');

:root {
  /* Mono palette (interface chrome) */
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --bg-panel: #f5f5f5;
  --text: #000000;
  --text-2: #555555;
  --text-3: #999999;
  --border: #e6e6e6;
  --border-strong: #000000;

  /* Glass overlays */
  --glass-dark: rgba(0,0,0,0.06);
  --glass-dark-hover: rgba(0,0,0,0.10);

  /* Accent (used very sparingly; bead colors carry the chroma) */
  --accent: #0d99ff;
  --accent-hover: #0079c9;
  --danger: #f24822;
  --success: #14ae5c;
  --warn: #ffcd29;

  /* Radii */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-pill: 9999px;

  /* Shadows */
  --shadow-1: 0 1px 2px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.04);
  --shadow-2: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-3: 0 10px 30px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Noto Sans SC', system-ui, -apple-system, 'PingFang SC', sans-serif;
  font-feature-settings: "kern", "ss01";
  background: var(--bg);
  color: var(--text);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { font-size: 14px; line-height: 1.45; min-height: 100vh; overflow: hidden; }

.mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0;
}
.label-up {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  border: none;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s, transform 0.12s;
  outline: none;
}
.btn:focus-visible { outline: 2px dashed #000; outline-offset: 2px; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: #000; color: #fff; }
.btn-primary:hover { background: #222; }
.btn-ghost { background: var(--glass-dark); color: #000; }
.btn-ghost:hover { background: var(--glass-dark-hover); }
.btn-white { background: #fff; color: #000; border: 1px solid var(--border); }
.btn-white:hover { background: var(--bg-soft); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }

.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 50%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 22px; font-size: 14px; }

/* ============ Inputs ============ */
.input, .select {
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  width: 100%;
}
.input:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 153, 255, 0.18);
}
.color-input {
  width: 100%;
  height: 40px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #fff;
  cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch {
  border: 0;
  border-radius: calc(var(--r-sm) - 3px);
}
.color-input::-moz-color-swatch {
  border: 0;
  border-radius: calc(var(--r-sm) - 3px);
}
.adjust-number {
  width: 72px;
  height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #fff;
  color: #000;
  font: 500 12px 'JetBrains Mono', ui-monospace, monospace;
  text-align: right;
  outline: none;
}
.adjust-number:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 153, 255, 0.18);
}
.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #000;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #000;
}
.range::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #000;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #000;
}

.switch-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.switch {
  position: relative;
  width: 32px; height: 18px;
  background: var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch.on { background: #000; }
.switch.on::after { transform: translateX(14px); }

/* ============ Panels / Cards ============ */
.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.panel-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-body {
  padding: 14px 16px;
}

/* ============ Tabs (pill) ============ */
.tabs {
  display: inline-flex;
  background: var(--bg-panel);
  border-radius: var(--r-pill);
  padding: 3px;
  gap: 2px;
}
.tab {
  padding: 6px 14px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-2);
  transition: background 0.12s, color 0.12s;
  border: none;
  background: transparent;
}
.tab.active {
  background: #000;
  color: #fff;
}
.tab:not(.active):hover { color: #000; }

/* ============ Layout ============ */
.app {
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 280px 1fr 320px;
  grid-template-areas:
    "topbar topbar topbar"
    "left   stage  right";
  height: 100vh;
  width: 100vw;
  background: var(--bg-soft);
}
.topbar {
  grid-area: topbar;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.left  { grid-area: left;  border-right: 1px solid var(--border); background:#fff; overflow-y:auto; }
.right { grid-area: right; border-left:  1px solid var(--border); background:#fff; overflow-y:auto; }
.stage { grid-area: stage; overflow:hidden; padding: 24px; background: var(--bg-soft); position:relative; }

@media (max-width: 1100px) {
  .app {
    grid-template-columns: 240px 1fr 280px;
  }
}

.mobile-sheet-head,
.mobile-sheet-backdrop,
.mobile-controls-fab {
  display: none;
}

/* 全屏编辑模式：藏掉 topbar / 左 / 右栏，画布占满，工具栏保留 */
body.editor-fullscreen .app {
  grid-template-rows: 0 1fr;
  grid-template-columns: 0 1fr 0;
}
body.editor-fullscreen .topbar,
body.editor-fullscreen .left,
body.editor-fullscreen .right {
  display: none;
}
body.editor-fullscreen #btnFullscreen {
  background: #000;
  color: #fff;
}

@media (max-width: 760px) {
  html, body {
    min-height: 100%;
    overflow: auto;
  }

  body.mobile-controls-open {
    overflow: hidden;
  }

  .app {
    display: flex;
    flex-direction: column;
    width: 100vw;
    min-height: 100vh;
    height: auto;
    padding-bottom: 86px;
  }

  .topbar {
    min-height: 92px;
    height: auto;
    flex-wrap: wrap;
    align-content: center;
    gap: 8px;
    padding: 10px 12px;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .topbar > .label-up { display: none; }
  .topbar .logo { flex: 1; }
  .topbar .spacer { display: none; }
  .topbar #modeTabs {
    order: 3;
    width: 100%;
    overflow-x: auto;
    justify-content: space-between;
  }
  .topbar .tab {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
  }
  #btnExportBead {
    min-height: 38px;
    padding-inline: 14px;
  }

  .left {
    order: 1;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
    background: #fff;
  }
  .left .upload-section {
    border-bottom: 0;
    padding: 12px;
  }
  .left .controls-sheet {
    display: none;
  }
  .left .mobile-sheet-head {
    display: flex;
  }

  .stage {
    order: 2;
    flex: 1;
    min-height: 52vh;
    padding: 12px;
    overflow: visible;
  }
  .stage-inner {
    min-height: 52vh;
  }
  .stage-toolbar {
    padding: 8px 10px;
  }
  .stage-canvas-wrap {
    padding: 12px;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }

  .right {
    order: 3;
    border-left: 0;
    border-top: 1px solid var(--border);
    overflow: visible;
    background: #fff;
  }

  .btn, .select {
    min-height: 40px;
  }
  .adjust-number {
    width: 86px;
    height: 36px;
    font-size: 13px;
  }
  .range {
    height: 6px;
  }
  .range::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }
  .range::-moz-range-thumb {
    width: 20px;
    height: 20px;
  }

  .mobile-controls-fab {
    display: inline-flex;
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 80;
    align-items: center;
    justify-content: center;
    min-width: 132px;
    height: 48px;
    padding: 0 22px;
    border: 0;
    border-radius: 999px;
    background: #000;
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 12px 34px rgba(0,0,0,0.22);
  }

  .mobile-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.34);
    opacity: 0;
    pointer-events: none;
    z-index: 70;
    transition: opacity 0.18s ease;
  }

  .left .mobile-sheet-head {
    position: fixed;
    left: 0;
    right: 0;
    bottom: min(72vh, calc(100vh - 96px));
    z-index: 91;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 16px;
    background: #fff;
    border-radius: 18px 18px 0 0;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 -10px 30px rgba(0,0,0,0.12);
    transform: translateY(110vh);
    transition: transform 0.24s cubic-bezier(.2,.8,.2,1);
    font-size: 14px;
    font-weight: 700;
  }
  .left .mobile-sheet-head .h3-action {
    font-size: 12px;
    padding: 5px 12px;
  }

  .left .controls-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    display: block;
    max-height: min(72vh, calc(100vh - 96px));
    overflow-y: auto;
    background: #fff;
    transform: translateY(110vh);
    transition: transform 0.24s cubic-bezier(.2,.8,.2,1);
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .left .controls-sheet .controls-section {
    display: block;
    border-bottom: 1px solid var(--border);
    padding: 16px;
  }
  .left .controls-sheet .controls-section:last-child {
    border-bottom: 0;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  body.mobile-controls-open .mobile-sheet-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  body.mobile-controls-open .left .mobile-sheet-head,
  body.mobile-controls-open .left .controls-sheet {
    transform: translateY(0);
  }
  body.mobile-controls-open .mobile-controls-fab {
    display: none;
  }
}

@media (min-width: 761px) {
  .mobile-sheet-head,
  .mobile-sheet-backdrop,
  .mobile-controls-fab {
    display: none !important;
  }
}

/* ============ Topbar ============ */
.topbar .logo {
  display:flex; align-items:center; gap:8px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.02em;
}
.topbar .logo-mark {
  width: 22px; height: 22px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  flex-shrink: 0;
}
.topbar .logo-mark span {
  display: block;
  border-radius: 50%;
}
.topbar .spacer { flex: 1; }

/* ============ Side panel sections ============ */
.section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.section h3 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.section h3 .h3-action {
  font-family: 'Inter', 'Noto Sans SC', sans-serif;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 3px 10px;
  cursor: pointer;
  font-weight: 500;
}
.section h3 .h3-action:hover { background: var(--glass-dark); color: #000; }
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-2);
}
.field-row .val {
  font-family: 'JetBrains Mono', monospace;
  color: #000;
  font-weight: 500;
}

/* ============ Drop zone ============ */
.dropzone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 12px 10px 16px;
  cursor: pointer;
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s, transform 0.12s;
  overflow: hidden;
}
.dropzone-file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.dropzone:hover, .dropzone.drag {
  border-color: #000;
  background: #fbfbfb;
  box-shadow: 0 3px 10px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.04);
}
.dropzone:active {
  transform: translateY(1px);
}
.dropzone .dz-title {
  font-size: 13px;
  line-height: 1.2;
  font-weight: 600;
  color: #000;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.dropzone .dz-hint {
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-3);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ============ Stage / canvas ============ */
.stage-inner {
  background: #fff;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  /* 必须用固定 height，否则 flex:1 子项会被内容撑爆 */
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.stage-tools-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.stage-tool-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}
.stage-tool-group { position: relative; }

.tool-toggle.on {
  background: #000;
  color: #fff;
}
.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.tool-tabs {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
  background: #fff;
  height: 28px;
}
.tool-tab {
  font: inherit;
  font-size: 12px;
  padding: 0 12px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  height: 100%;
  display: inline-flex;
  align-items: center;
}
.tool-tab + .tool-tab { border-left: 1px solid var(--border); }
.tool-tab.on {
  background: #000;
  color: #fff;
}
.brush-size {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
  background: #fff;
  height: 28px;
}
.brush-size button {
  font: inherit;
  font-size: 12px;
  width: 28px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  height: 100%;
  border-right: 1px solid var(--border);
}
.brush-size button:last-of-type { border-right: 1px solid var(--border); }
.brush-size button.on {
  background: #000;
  color: #fff;
}
.brush-size input[type="number"] {
  width: 44px;
  height: 100%;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12px;
  text-align: center;
  color: var(--text-1);
  padding: 0 4px;
  outline: none;
  -moz-appearance: textfield;
}
.brush-size input[type="number"]::-webkit-outer-spin-button,
.brush-size input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.paint-color-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  height: 28px;
}
.paint-color-chip input[type="color"] {
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.paint-color-chip input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.paint-color-chip input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(0,0,0,0.15); border-radius: 50%; }
.paint-color-chip input[type="color"]::-moz-color-swatch { border: 1px solid rgba(0,0,0,0.15); border-radius: 50%; }

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.zoom-controls .mono {
  font-size: 12px;
  min-width: 42px;
  text-align: center;
  color: var(--text-2);
}
.zoom-controls .btn-icon {
  width: 26px;
  height: 26px;
  font-size: 16px;
  line-height: 1;
}
.toolbar-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-right: 6px;
  white-space: nowrap;
  user-select: none;
}
.toolbar-hint kbd {
  font: inherit;
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fafafa;
  color: var(--text-2);
  margin: 0 2px;
}
@media (max-width: 760px) {
  .toolbar-hint { display: none; }
}

.blank-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 60;
  width: 240px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
  padding: 12px;
}
.blank-popover[hidden] { display: none; }

/* 水印面板：与 blank-popover 同源样式 */
.watermark-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 60;
  width: 280px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
  padding: 12px;
}
.watermark-popover[hidden] { display: none; }

/* ========== 通用确认弹窗 ========== */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: confirm-fade-in 0.14s ease-out;
}
.confirm-backdrop[hidden] { display: none; }
.confirm-dialog {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  padding: 20px 20px 16px;
  animation: confirm-pop-in 0.16s ease-out;
}
.confirm-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.confirm-message {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.55;
  margin-bottom: 18px;
  white-space: pre-wrap;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.confirm-actions .btn { min-width: 72px; }

/* dialog 内的输入框（promptDialog 用）*/
.confirm-input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
  color: var(--text);
  outline: none;
  transition: border-color 0.12s, background 0.12s;
  margin-bottom: 18px;
}
.confirm-input:focus {
  border-color: var(--text);
  background: #fff;
}
.confirm-input::placeholder { color: #b8b8b8; }
.confirm-input.error { border-color: #d33; }
.confirm-tip {
  font-size: 12px;
  color: #888;
  line-height: 1.5;
  margin-top: -10px;
  margin-bottom: 14px;
}

/* 顶栏作者标签 */
.author-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px;
  margin-right: 4px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Inter', sans-serif;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  user-select: none;
}
.author-chip:hover {
  background: #f3f3f3;
  border-color: var(--border);
  color: var(--text);
}
.author-chip.empty {
  color: #aaa;
  font-style: italic;
}
@keyframes confirm-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes confirm-pop-in {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.wm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.wm-label {
  width: 36px;
  font-size: 12px;
  color: var(--text-3);
}
.wm-row input[type="text"] {
  flex: 1;
  font: inherit;
  font-size: 12px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 8px;
  outline: none;
}
.wm-row input[type="text"]:focus { border-color: var(--text-1); }
.wm-segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
  background: #fff;
  height: 28px;
}
.wm-segmented button {
  font: inherit;
  font-size: 12px;
  padding: 0 12px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  height: 100%;
  border-right: 1px solid var(--border);
}
.wm-segmented button:last-child { border-right: none; }
.wm-segmented button.on { background: #000; color: #fff; }
.wm-positions {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
  background: #fff;
  height: 28px;
}
.wm-positions button {
  width: 30px;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  border-right: 1px solid var(--border);
}
.wm-positions button:last-child { border-right: none; }
.wm-positions button.on { background: #000; color: #fff; }
.wm-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.wm-actions .wm-hint {
  font-size: 10px;
  color: var(--text-3);
}
.blank-presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.blank-presets button {
  font: inherit;
  font-size: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #fff;
  cursor: pointer;
}
.blank-presets button:hover { background: var(--bg-soft); }

/* 常用板子尺寸 chips（横向格数下方） */
.grid-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 6px;
}
.grid-presets button {
  font: inherit;
  font-size: 11px;
  padding: 5px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.grid-presets button:hover { background: var(--bg-soft); }
.grid-presets button.active {
  background: #000;
  border-color: #000;
  color: #fff;
}
.blank-custom {
  display: flex;
  align-items: center;
  gap: 6px;
}
.blank-custom .adjust-number {
  width: 64px;
  text-align: center;
}
.blank-custom span { color: var(--text-3); font-size: 12px; }
.blank-custom .btn { margin-left: auto; }
.stage-canvas-wrap {
  flex: 1;
  background: var(--bg-soft);
  overflow: auto;
  /* 画布平移用滚动条实现；不在 wrap 上设 padding，否则会偏移坐标系 */
  padding: 0;
  /* 防止内容把 flex 子项撑爆，保持 wrap 等于父容器剩余空间 */
  min-width: 0;
  min-height: 0;
}
.stage-canvas-pad {
  /* JS 在窗口/缩放变化时把 padding 设为 wrap 可视尺寸的一半（最小 24px），
     使画布的任意一角都能被拖到屏幕中心。 */
  padding: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  box-sizing: border-box;
}
.canvas-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  display: block;
  position: relative;
  flex-shrink: 0;
}
.canvas-card canvas {
  width: auto;
  max-width: none;
  height: auto;
}
canvas { display: block; image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges; }
canvas.paint-active { cursor: none; }
/* 触摸交互全部自己 handle（pan / pinch / 画笔），别让浏览器原生滚动/缩放抢走 */
#stageCanvas { touch-action: none; }
/* 平移光标：未编辑或按住 Ctrl/空格 时显示抓手；正在拖动时显示握紧 */
canvas.pan-grab,
canvas.paint-active.pan-grab { cursor: grab; }
canvas.panning,
canvas.paint-active.panning,
canvas.pan-grab.panning { cursor: grabbing; }

/* 笔刷光标浮层：跟随鼠标，按 cellSize × brushSize snap 到格 */
.brush-cursor {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  box-sizing: border-box;
  border: 1px solid #000;
  background: rgba(0,0,0,0.18);
  /* 中心点偏移用 transform translate 控制 */
  transform: translate3d(0,0,0);
  will-change: transform, width, height;
  z-index: 5;
}
.brush-cursor[hidden] { display: none; }
.brush-cursor.eraser {
  background: rgba(255,255,255,0.5);
  border: 1px dashed #000;
  outline: 1px solid rgba(255,255,255,0.9);
  outline-offset: -2px;
}

.empty {
  text-align: center;
  color: var(--text-3);
}
.empty .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty h2 { font-size: 18px; font-weight: 500; color: #000; margin: 0 0 4px; letter-spacing: -0.02em; }

/* ============ Right panel: color list ============ */
.color-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.1s;
}
.color-row:hover { background: var(--bg-soft); }
.color-row .swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.18);
  flex-shrink: 0;
}
.color-row .code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-2);
  width: 38px;
  flex-shrink: 0;
}
.color-row .name {
  font-size: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.color-row .count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: #000;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-200%);
  background: #000;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--r-pill);
  font-size: 13px;
  z-index: 1000;
  box-shadow: var(--shadow-3);
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), opacity 0.2s;
  opacity: 0;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* ============ Loading Overlay ============ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  gap: 16px;
  transition: opacity .3s ease;
}
.loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}
.loading-logo {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.loading-logo .logo-mark {
  width: 18px;
  height: 18px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
}
.loading-logo .logo-mark span {
  border-radius: 1px;
}
.loading-bar {
  width: 160px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.loading-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 40%;
  background: var(--text);
  border-radius: 2px;
  animation: loading-slide 1.2s ease-in-out infinite;
}
@keyframes loading-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
.loading-hint {
  font-size: 11px;
  color: var(--text-3);
}
