/* 光墨 Studio — 亮色默认 + 可切换暗色 */
:root {
  /* ---- 基础色板（亮色） ---- */
  --bg: #eef1f5;
  --bg-soft: #e8ecf1;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --elev: #ffffff;
  --line: #dee3eb;
  --line-soft: #e9edf3;
  --text: #232932;
  --muted: #5f6a7a;
  --faint: #8d97a6;
  --accent: #e0871a;
  --accent-ink: #2b1a04;
  --accent-text: #b06408;
  --accent-soft: rgba(224, 135, 26, .12);
  --danger: #d84f4f;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgba(20, 30, 50, .08);
  --shadow-2: 0 24px 60px -24px rgba(30, 42, 60, .35);

  /* ---- 语义组件色（亮色） ---- */
  --hover: rgba(20, 30, 50, .05);
  --hover-strong: rgba(20, 30, 50, .08);
  --topbar-bg: linear-gradient(180deg, #ffffff, #f8fafc);
  --rail-bg: #f7f9fc;
  --group-bg: #f1f4f8;
  --input-bg: #f6f8fb;
  --card-bg: #f6f8fb;
  --card-bg-hover: #eff3f8;
  --card-border: #ccd5e0;
  --card-border-hover: #b3bfd0;
  --seg-active-bg: #e7ecf3;
  --track-bg: #d9dfe8;
  --switch-bg: #d3dae3;
  --switch-knob: #ffffff;
  --scroll-thumb: #ccd4df;
  --scroll-thumb-hover: #b4c0cf;
  --modal-bg: #ffffff;
  --modal-border: #e2e7ef;
  --modal-foot-bg: #f8fafc;
  --modal-mask: rgba(40, 48, 62, .38);
  --float-bg: rgba(255, 255, 255, .97);
  --float-border: #dfe4ec;
  --float-ink: #5c6774;
  --kbd-bg: #f0f3f7;
  --kbd-border: #d9dfe8;
  --kbd-ink: #4d5866;
  --toast-bg: #232a34;
  --toast-ink: #f4f6f9;
  --stage-bg:
    radial-gradient(1000px 600px at 55% 38%, rgba(125, 140, 165, .16), transparent 70%),
    radial-gradient(700px 400px at 85% 90%, rgba(255, 150, 60, .07), transparent 70%),
    #edf0f4;
  --stage-dot: rgba(30, 40, 60, .05);
  --checker-base: #e9ecf0;
  --checker-sq: #dde2e9;
  --artboard-ring: rgba(20, 30, 50, .12);
  --artboard-shadow: 0 40px 90px -35px rgba(40, 55, 80, .45);
  --hint-bg: rgba(255, 255, 255, .82);
  --hint-ink: #7d8794;
  --drop-mask-bg: rgba(248, 250, 252, .88);
  --btn-ghost-bg: #f1f4f8;
  --btn-ghost-bg-hover: #e9edf3;
  --btn-ghost-border: #dee3eb;
  --btn-ghost-border-hover: #c3cdd9;
  --primary-disabled-bg: #e0e5ec;
  --primary-disabled-ink: #97a2b1;
  --ink-2: #5e6a7a;
  --ink-strong: #333d4a;
  --thumb-bg: #eef1f6;

  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

/* ---- 暗色覆盖 ---- */
[data-theme="dark"] {
  --bg: #0a0c0f;
  --bg-soft: #0f1216;
  --panel: #12161b;
  --panel-2: #171c23;
  --elev: #1c222a;
  --line: #232a34;
  --line-soft: #1b212a;
  --text: #e9edf3;
  --muted: #94a0b0;
  --faint: #66707f;
  --accent: #ffb454;
  --accent-ink: #1a1206;
  --accent-text: #ffce8c;
  --accent-soft: rgba(255, 180, 84, .13);
  --danger: #ff6b6b;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-2: 0 24px 60px -18px rgba(0, 0, 0, .75);

  --hover: rgba(255, 255, 255, .06);
  --hover-strong: rgba(255, 255, 255, .08);
  --topbar-bg: linear-gradient(180deg, #11151a, #0d1014);
  --rail-bg: #0d1014;
  --group-bg: #0c0f13;
  --input-bg: #0d1116;
  --card-bg: #0f1419;
  --card-bg-hover: #141a21;
  --card-border: #333d49;
  --card-border-hover: #3a4552;
  --seg-active-bg: #232b35;
  --track-bg: #2a323c;
  --switch-bg: #29313b;
  --switch-knob: #8e99a8;
  --scroll-thumb: #262e38;
  --scroll-thumb-hover: #333d49;
  --modal-bg: #14181e;
  --modal-border: #29313c;
  --modal-foot-bg: #11151a;
  --modal-mask: rgba(4, 6, 9, .68);
  --float-bg: rgba(23, 28, 35, .96);
  --float-border: #2b3440;
  --float-ink: #b6c0cd;
  --kbd-bg: #1c222a;
  --kbd-border: #2c3541;
  --kbd-ink: #c2ccd9;
  --toast-bg: #f2f5f9;
  --toast-ink: #14181e;
  --stage-bg:
    radial-gradient(1000px 600px at 55% 38%, rgba(60, 72, 92, .2), transparent 70%),
    radial-gradient(700px 400px at 85% 90%, rgba(255, 150, 60, .05), transparent 70%),
    #0a0d11;
  --stage-dot: rgba(255, 255, 255, .045);
  --checker-base: #20252c;
  --checker-sq: #2a3038;
  --artboard-ring: rgba(255, 255, 255, .07);
  --artboard-shadow: 0 40px 90px -30px rgba(0, 0, 0, .9);
  --hint-bg: rgba(10, 13, 17, .7);
  --hint-ink: #5a6472;
  --drop-mask-bg: rgba(13, 16, 21, .82);
  --btn-ghost-bg: #171c23;
  --btn-ghost-bg-hover: #1d232b;
  --btn-ghost-border: #232a34;
  --btn-ghost-border-hover: #2e3742;
  --primary-disabled-bg: #2a3038;
  --primary-disabled-ink: #6c7684;
  --ink-2: #b9c3d0;
  --ink-strong: #c9d2df;
  --thumb-bg: #171c22;

  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { cursor: not-allowed; }
::selection { background: rgba(224, 135, 26, .28); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------------- 顶栏 ---------------- */

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px 0 16px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #ffcb7d, #ff9d3d 60%, #f2812a);
  color: #221604;
  box-shadow: 0 6px 16px -8px rgba(255, 160, 60, .8), inset 0 1px 0 rgba(255, 255, 255, .45);
}
.brand-mark .icon { width: 17px; height: 17px; stroke-width: 2; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-size: 15px; letter-spacing: .16em; font-weight: 600; }
.brand-text span { font-size: 8px; letter-spacing: .34em; color: var(--faint); margin-top: 3px; }

.doc { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.doc-name {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 4px 8px;
  max-width: 240px;
  font-size: 13px;
  color: var(--ink-strong);
  outline: none;
  transition: border-color .15s, background .15s;
}
.doc-name:hover { border-color: var(--line); }
.doc-name:focus { border-color: rgba(224, 135, 26, .5); background: var(--input-bg); }
.doc-size { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }

.top-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.group { display: flex; align-items: center; gap: 2px; padding: 3px; background: var(--group-bg); border: 1px solid var(--line-soft); border-radius: 9px; }
.group + .group { margin-left: 2px; }

.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 7px;
  color: var(--muted);
  transition: background .15s, color .15s, transform .1s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .28; color: var(--muted); background: none; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.theme-btn .icon-sun { display: none; }
[data-theme="dark"] .theme-btn .icon-sun { display: block; }
[data-theme="dark"] .theme-btn .icon-moon { display: none; }

.lang-btn {
  width: auto;
  min-width: 30px;
  padding: 0 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
}

.zoom { gap: 0; padding: 3px 4px; }
.zoom-value {
  min-width: 52px;
  height: 28px;
  font-size: 11.5px;
  color: var(--ink-strong);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  transition: color .15s, background .15s;
}
.zoom-value:hover { background: var(--hover); color: var(--text); }

.btn {
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(180deg, #ffc06a, #ffab42);
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: 0 6px 18px -10px rgba(255, 175, 70, .9), inset 0 1px 0 rgba(255, 255, 255, .4);
}
.btn.primary:hover { background: linear-gradient(180deg, #ffcb80, #ffb455); }
.btn.primary:disabled { background: var(--primary-disabled-bg); color: var(--primary-disabled-ink); box-shadow: none; }
.btn.ghost { background: var(--btn-ghost-bg); border-color: var(--btn-ghost-border); color: var(--ink-strong); }
.btn.ghost:hover { background: var(--btn-ghost-bg-hover); border-color: var(--btn-ghost-border-hover); }
.btn.ghost:disabled { opacity: .4; }
.btn.danger { color: var(--danger); }
.btn .icon { width: 16px; height: 16px; }
.btn.block { width: 100%; height: 38px; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 6px; }

/* ---------------- 布局 ---------------- */

.workspace {
  height: calc(100% - 58px);
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 322px;
  background: var(--bg);
}

/* ---------------- 左侧工具栏 ---------------- */

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 12px 8px;
  background: var(--rail-bg);
  border-right: 1px solid var(--line);
  z-index: 20;
}
.rail-btn {
  width: 60px;
  height: 54px;
  border-radius: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: .04em;
  transition: background .15s, color .15s;
  position: relative;
}
.rail-btn .icon { width: 19px; height: 19px; }
.rail-btn:hover { color: var(--ink-strong); background: var(--hover); }
.rail-btn.active { color: var(--accent); background: var(--accent-soft); }
.rail-btn:focus-visible, .seg-btn:focus-visible, .chip:focus-visible, .tab:focus-visible,
.text-preset:focus-visible, .shape-btn:focus-visible, .emoji-btn:focus-visible, .layer-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.rail-btn.active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 20px;
  border-radius: 2px;
  background: var(--accent);
}

/* ---------------- 舞台 ---------------- */

.stage {
  position: relative;
  overflow: hidden;
  background: var(--stage-bg);
  touch-action: none;
  isolation: isolate;
}
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(var(--stage-dot) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: .5;
  z-index: 0;
}
.stage.panning { cursor: grabbing; }
.stage.panning .artboard { cursor: grabbing; }

.artboard {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background-color: var(--checker-base);
  background-image:
    linear-gradient(45deg, var(--checker-sq) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-sq) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-sq) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-sq) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  box-shadow: 0 0 0 1px var(--artboard-ring), var(--artboard-shadow);
  z-index: 2;
}
.artboard canvas { display: block; width: 100%; height: 100%; }

.overlay { position: absolute; inset: 0; pointer-events: none; }

.stage.space, .stage.space .artboard { cursor: grab; }

.color-input {
  width: 100%;
  height: 32px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 5px; }

.selection {
  position: absolute;
  border: calc(1px * var(--inv, 1)) solid var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
  pointer-events: none;
  transform-origin: center center;
}
.handle {
  position: absolute;
  width: calc(9px * var(--inv, 1));
  height: calc(9px * var(--inv, 1));
  border-radius: 50%;
  background: #fff;
  border: calc(1.5px * var(--inv, 1)) solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
  pointer-events: auto;
  transform: translate(-50%, -50%);
}
.handle[data-handle="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.handle[data-handle="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.handle[data-handle="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.handle[data-handle="se"] { left: 100%; top: 100%; cursor: nwse-resize; }

.rot-handle {
  position: absolute;
  left: 50%;
  top: 0;
  width: calc(24px * var(--inv, 1));
  height: calc(24px * var(--inv, 1));
  margin-left: calc(-12px * var(--inv, 1));
  margin-top: calc(-38px * var(--inv, 1));
  border-radius: 50%;
  background: #fff;
  color: #2b3038;
  display: grid;
  place-items: center;
  pointer-events: auto;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
.rot-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: calc(1px * var(--inv, 1));
  height: calc(14px * var(--inv, 1));
  background: var(--accent);
  transform: translateX(-50%);
}
.rot-handle .icon { width: calc(13px * var(--inv, 1)); height: calc(13px * var(--inv, 1)); }

.text-editor {
  position: absolute;
  transform-origin: center center;
  pointer-events: auto;
  z-index: 5;
}
.text-editor textarea {
  width: 100%;
  height: 100%;
  resize: none;
  overflow: hidden;
  border: 1px solid rgba(255, 180, 84, .85);
  border-radius: 4px;
  background: rgba(10, 13, 18, .45);
  color: #fff;
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 180, 84, .16);
  caret-color: var(--accent);
  white-space: pre;
}

/* 浮动工具条 */
.float-bar {
  position: absolute;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 4px;
  background: var(--float-bg);
  border: 1px solid var(--float-border);
  border-radius: 10px;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, .35);
  transform: translate(-50%, -100%);
  backdrop-filter: blur(10px);
}
.float-bar button {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: grid; place-items: center;
  color: var(--float-ink);
  transition: background .12s, color .12s;
}
.float-bar button:hover { background: var(--hover-strong); color: var(--text); }
.float-bar button.danger:hover { background: rgba(224, 79, 79, .14); color: var(--danger); }
.float-bar .icon { width: 15px; height: 15px; }
.float-bar .sep { width: 1px; height: 16px; background: var(--line); margin: 0 3px; }

/* 空状态 */
.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 6;
  padding: 24px;
}
.empty-card { max-width: 440px; text-align: center; animation: rise .5s cubic-bezier(.2, .8, .2, 1) both; }
.empty-art { position: relative; height: 118px; margin-bottom: 6px; }
.ea {
  position: absolute;
  left: 50%;
  top: 10px;
  width: 96px; height: 96px;
  border-radius: 18px;
  border: 1px solid rgba(127, 140, 160, .18);
}
.ea-back { transform: translateX(-98%) rotate(-13deg); background: linear-gradient(160deg, #2a3340, #1a2028); }
.ea-mid { transform: translateX(-2%) rotate(11deg); background: linear-gradient(160deg, #3b2f26, #1d2028); }
.ea-front {
  display: grid; place-items: center;
  transform: translateX(-50%);
  background: linear-gradient(150deg, #ffd18a, #ff9f3d 55%, #e97a24);
  color: #241605;
  box-shadow: 0 30px 60px -26px rgba(255, 160, 70, .7), inset 0 1px 0 rgba(255, 255, 255, .5);
  z-index: 2;
}
.ea-front .icon { width: 34px; height: 34px; stroke-width: 1.5; }
.empty h1 { font-size: 25px; margin: 22px 0 10px; letter-spacing: .03em; font-weight: 600; color: var(--text); }
.empty-sub { color: var(--muted); font-size: 13px; line-height: 1.8; margin: 0 0 22px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; }
.empty-actions .btn { height: 36px; padding: 0 20px; }
.empty-hint { color: var(--faint); font-size: 11.5px; margin-top: 18px; }

.stage-hint {
  position: absolute;
  left: 16px;
  bottom: 14px;
  font-size: 11px;
  color: var(--hint-ink);
  background: var(--hint-bg);
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  padding: 4px 9px;
  pointer-events: none;
  z-index: 5;
  backdrop-filter: blur(6px);
}

.drop-mask {
  position: absolute;
  inset: 10px;
  border-radius: 16px;
  border: 1.5px dashed rgba(224, 135, 26, .8);
  background: var(--drop-mask-bg);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s;
  z-index: 40;
  backdrop-filter: blur(3px);
}
.drop-mask.show { opacity: 1; }
.drop-box { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--accent); font-size: 14px; }
.drop-box .icon { width: 30px; height: 30px; }

/* ---------------- 右侧面板 ---------------- */

.panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 20;
}
.panel-head {
  padding: 16px 18px 13px;
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}
.panel-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; letter-spacing: .02em; }
.panel-head p { margin: 3px 0 0; font-size: 11.5px; color: var(--faint); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 18px 26px;
  overscroll-behavior: contain;
}
.panel-body::-webkit-scrollbar { width: 9px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 9px; border: 3px solid var(--panel); }
.panel-body::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

.sec { padding: 15px 0; border-bottom: 1px solid var(--line-soft); }
.sec:last-child { border-bottom: 0; padding-bottom: 8px; }
.sec-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--faint);
  margin-bottom: 11px;
  font-weight: 600;
}
.hint { font-size: 11.5px; color: var(--faint); line-height: 1.7; margin: 9px 0 0; }
.hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .hint-desktop { display: none; }
  .hint-touch { display: inline; }
}

.field { margin-bottom: 13px; }
.field:last-child { margin-bottom: 0; }
.field-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; font-size: 12px; color: var(--ink-2); }
.field-top output { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: var(--track-bg);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #f5f7fa;
  border: 2px solid #ffb454;
  margin-top: -4.5px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  transition: transform .1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
input[type="range"]:focus-visible { outline: 2px solid rgba(224, 135, 26, .6); outline-offset: 3px; border-radius: 4px; }

.input, .textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12.5px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 58px; line-height: 1.6; }
.input:focus, .textarea:focus { border-color: rgba(224, 135, 26, .55); box-shadow: 0 0 0 3px rgba(224, 135, 26, .1); }

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--input-bg);
  border: 1px solid var(--line-soft);
  border-radius: 9px;
}
.seg-btn {
  flex: 1;
  height: 27px;
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--muted);
  transition: background .14s, color .14s;
  padding: 0 6px;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text); background: var(--hover); }
.seg-btn.active { background: var(--seg-active-bg); color: var(--accent); box-shadow: var(--shadow-1); }
.seg.small .seg-btn { height: 24px; font-size: 11px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 13px; }
.chip {
  height: 28px;
  padding: 0 11px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--card-bg);
  color: var(--ink-2);
  font-size: 12px;
  transition: all .14s;
}
.chip:hover { border-color: var(--card-border-hover); color: var(--text); }
.chip.active { border-color: rgba(224, 135, 26, .6); background: var(--accent-soft); color: var(--accent-text); }

.swatches { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.swatch {
  width: 23px; height: 23px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(127, 140, 160, .25);
  transition: transform .12s, box-shadow .12s;
  position: relative;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: inset 0 0 0 1px rgba(127, 140, 160, .25), 0 0 0 2px var(--panel), 0 0 0 3.5px var(--accent); }
.swatch.custom {
  overflow: hidden;
  background: conic-gradient(#ff6b6b, #ffd93d, #8ee38e, #5bc8ff, #c084fc, #ff6b6b);
  display: grid; place-items: center;
}
.swatch.custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; font-size: 12.5px; color: var(--ink-2); }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i {
  position: absolute; inset: 0;
  background: var(--switch-bg);
  border-radius: 20px;
  transition: background .16s;
  pointer-events: none;
}
.switch i::after {
  content: "";
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--switch-knob);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .18s cubic-bezier(.3, .8, .3, 1), background .18s;
}
.switch input:checked + i { background: rgba(224, 135, 26, .35); }
.switch input:checked + i::after { transform: translateX(14px); background: var(--accent); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 12px; color: var(--faint); }
.kv b { color: var(--ink-strong); font-weight: 500; font-variant-numeric: tabular-nums; }
.ellipsis { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-2 .btn { height: 31px; }

.upload-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 12px;
  border-radius: 11px;
  border: 1px dashed var(--card-border);
  background: var(--card-bg);
  color: var(--ink-2);
  transition: all .15s;
}
.upload-card:hover { border-color: rgba(224, 135, 26, .55); background: rgba(224, 135, 26, .06); color: var(--text); }
.upload-card .icon { width: 22px; height: 22px; color: var(--accent); margin-bottom: 3px; }
.upload-card strong { font-size: 12.5px; font-weight: 500; }
.upload-card span { font-size: 10.5px; color: var(--faint); }

/* 滤镜 */
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 4px;
  border-radius: 9px;
  border: 1px solid transparent;
  transition: all .14s;
  text-align: left;
}
.preset-card:hover { background: var(--hover); }
.preset-card.active { border-color: rgba(224, 135, 26, .55); background: var(--accent-soft); }
.preset-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  background: var(--thumb-bg);
  display: block;
  object-fit: cover;
}
.preset-name { font-size: 10.5px; color: var(--ink-2); text-align: center; }
.preset-card.active .preset-name { color: var(--accent-text); }

/* 贴纸 */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; padding: 3px; background: var(--input-bg); border: 1px solid var(--line-soft); border-radius: 9px; }
.tab { flex: 1; height: 27px; border-radius: 6px; font-size: 11.5px; color: var(--muted); }
.tab:hover { color: var(--text); }
.tab.active { background: var(--seg-active-bg); color: var(--accent); }

.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.emoji-btn {
  aspect-ratio: 1;
  border-radius: 8px;
  font-size: 21px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background .12s, transform .12s;
}
.emoji-btn:hover { background: var(--hover-strong); transform: scale(1.06); }

.shape-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.shape-btn {
  aspect-ratio: 1;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--ink-2);
  transition: all .14s;
}
.shape-btn:hover { border-color: var(--card-border-hover); background: var(--card-bg-hover); }
.shape-btn svg { width: 22px; height: 22px; }
.shape-btn span { font-size: 9.5px; color: var(--faint); }

.text-preset-list { display: flex; flex-direction: column; gap: 7px; }
.text-preset {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card-bg);
  transition: all .14s;
  text-align: left;
}
.text-preset:hover { border-color: var(--card-border-hover); background: var(--card-bg-hover); }
.text-preset .tp-sample { font-size: 15px; color: var(--text); }
.text-preset .tp-name { font-size: 10.5px; color: var(--faint); flex: none; }

/* 效果 */
.effect-row { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.effect-row:last-of-type { border-bottom: 0; }
.effect-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.effect-name { font-size: 12.5px; color: var(--ink-strong); }
.effect-hint { font-size: 10.5px; color: var(--faint); margin-top: 1px; }
.effect-slider { margin-top: 6px; }
.effect-slider input { width: 100%; }
.effect-row:not(.on) .effect-slider { display: none; }

/* 图层 */
.layer-list { display: flex; flex-direction: column; gap: 3px; }
.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 7px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background .12s;
  cursor: pointer;
}
.layer-row:hover { background: var(--hover); }
.layer-row.active { background: var(--accent-soft); border-color: rgba(224, 135, 26, .32); }
.layer-thumb {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--thumb-bg);
  border: 1px solid var(--line-soft);
  display: grid;
  place-items: center;
  font-size: 14px;
  flex: none;
  color: var(--muted);
}
.layer-thumb .icon { width: 14px; height: 14px; }
.layer-name { flex: 1; min-width: 0; font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row.active .layer-name { color: var(--accent-text); }
.layer-actions { display: flex; gap: 1px; opacity: 0; transition: opacity .12s; }
.layer-row:hover .layer-actions, .layer-row.active .layer-actions { opacity: 1; }
.layer-actions button { width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center; color: var(--faint); }
.layer-actions button:hover { background: var(--hover-strong); color: var(--text); }
.layer-actions .icon { width: 13px; height: 13px; }

.empty-line { padding: 18px 0; text-align: center; color: var(--faint); font-size: 12px; line-height: 1.8; }

/* ---------------- 弹窗 ---------------- */

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; }
.modal-mask { position: absolute; inset: 0; background: var(--modal-mask); backdrop-filter: blur(6px); animation: fade .2s both; }
.modal-card {
  position: relative;
  width: min(540px, 100%);
  max-height: 90vh;
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: 16px;
  box-shadow: 0 40px 100px -30px rgba(0, 0, 0, .45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop .24s cubic-bezier(.2, .9, .25, 1) both;
}
.modal-card.narrow { width: min(470px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 13px; border-bottom: 1px solid var(--line-soft); }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 9px; background: var(--modal-foot-bg); }

.export-preview {
  border-radius: 11px;
  background-color: var(--checker-base);
  background-image:
    linear-gradient(45deg, var(--checker-sq) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-sq) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-sq) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-sq) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  border: 1px solid var(--line-soft);
  display: grid;
  place-items: center;
  padding: 12px;
  min-height: 180px;
  margin-bottom: 16px;
}
.export-preview canvas { max-width: 100%; max-height: 260px; border-radius: 4px; box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .5); }

.export-rows { display: flex; flex-direction: column; gap: 4px; }
.field-row { display: flex; align-items: center; gap: 12px; min-height: 36px; font-size: 12.5px; color: var(--ink-2); }
.field-row > span { width: 62px; flex: none; color: var(--muted); }
.field-row .seg { flex: 1; }
.field-row input[type="range"] { flex: 1; }
.field-row output { width: 34px; text-align: right; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.estimate { margin-top: 8px; padding: 10px 12px; background: var(--input-bg); border: 1px solid var(--line-soft); border-radius: 8px; font-size: 11.5px; color: var(--faint); display: flex; justify-content: space-between; gap: 10px; }
.estimate b { color: var(--ink-strong); font-weight: 500; }

.shortcut-list { display: flex; flex-direction: column; gap: 2px; }
.shortcut-list > div { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; color: var(--ink-2); }
.shortcut-list > div:last-child { border-bottom: 0; }
.shortcut-list span { flex: 1; }
kbd {
  font-family: var(--font);
  font-size: 10.5px;
  color: var(--kbd-ink);
  background: var(--kbd-bg);
  border: 1px solid var(--kbd-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 7px;
}

/* 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 12.5px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 10px;
  box-shadow: 0 20px 40px -16px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 70px minmax(0, 1fr) 296px; }
  .rail-btn { width: 54px; }
  .panel-body { padding-left: 14px; padding-right: 14px; }
  .doc-name { max-width: 160px; }
}

@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto 220px;
  }
  .stage { grid-row: 1; }
  .panel { grid-row: 3; border-left: 0; border-top: 1px solid var(--line); min-height: 0; }
  .rail {
    grid-row: 2;
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
    padding: 6px 10px;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    gap: 4px;
    scrollbar-width: none;
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail-btn { width: 58px; height: 46px; flex: none; }
  .rail-btn:focus-visible, .seg-btn:focus-visible, .chip:focus-visible, .tab:focus-visible,
.text-preset:focus-visible, .shape-btn:focus-visible, .emoji-btn:focus-visible, .layer-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.rail-btn.active::before { left: 50%; top: auto; bottom: -6px; transform: translateX(-50%); width: 18px; height: 2px; }
  .panel-head { padding: 11px 16px 9px; }
  .panel-body { padding: 2px 16px 18px; }
  .brand-text span { display: none; }
  .brand-text strong { font-size: 14px; letter-spacing: .1em; }
  .doc { display: none; }
  .topbar { gap: 10px; justify-content: space-between; }
  .stage-hint { display: none; }
  .toast { bottom: 282px; }
  .empty h1 { font-size: 21px; }
  .empty-art { height: 96px; }
  .ea { width: 78px; height: 78px; border-radius: 15px; }
  .modal-card { max-height: 94vh; }
}

@media (pointer: coarse) {
  .handle { width: calc(13px * var(--inv, 1)); height: calc(13px * var(--inv, 1)); }
  .rot-handle { width: calc(30px * var(--inv, 1)); height: calc(30px * var(--inv, 1)); margin-left: calc(-15px * var(--inv, 1)); margin-top: calc(-44px * var(--inv, 1)); }
  .rot-handle .icon { width: calc(15px * var(--inv, 1)); height: calc(15px * var(--inv, 1)); }
}

@media (max-width: 520px) {
  .top-actions .group:first-child { display: none; }
  .zoom { display: none; }
  .empty-sub br { display: none; }
  .empty-card { padding: 0 6px; }
  .empty-actions { flex-direction: column; }
  .empty-actions .btn { width: 100%; }
}

/* ICP 备案（画布右下角，与左下角 stage-hint 对称） */
.icp {
  position: absolute;
  right: 16px;
  bottom: 14px;
  z-index: 5;
  font-size: 11px;
  color: var(--hint-ink, var(--faint));
  pointer-events: auto;
}
.icp a { color: inherit; text-decoration: none; }
.icp a:hover { color: var(--accent); }
@media (max-width: 920px) {
  .icp { display: none; }
}
