/* =========================================================
   草莓拼豆 · iOS 风格设计系统
   参考 iOS 系统视觉语言：分组卡片 / 毛玻璃 / 分段控件 / 弹簧动效
   ========================================================= */

/* ---------------- Tokens ---------------- */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --bg-glass: rgba(255, 255, 255, .72);
  --bg-glass-strong: rgba(255, 255, 255, .88);
  --fill: rgba(118, 118, 128, .12);
  --fill-2: rgba(118, 118, 128, .08);
  --sep: rgba(60, 60, 67, .12);
  --sep-strong: rgba(60, 60, 67, .22);

  --label: #000000;
  --label-2: rgba(60, 60, 67, .62);
  --label-3: rgba(60, 60, 67, .34);

  --tint: #ff375f;
  --tint-2: #ff2d55;
  --tint-soft: rgba(255, 55, 95, .12);

  /* iOS 蓝：选择态 / 工具 / 数值（粉色只留给主按钮） */
  --accent: #0a84ff;
  --accent-2: #0071e3;
  --accent-soft: rgba(10, 132, 255, .13);
  --green: #34c759;
  --blue: #0a84ff;
  --amber: #ff9f0a;

  --r-xl: 26px;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;

  --sh-1: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .05);
  --sh-2: 0 2px 8px rgba(0, 0, 0, .06), 0 16px 40px rgba(0, 0, 0, .10);
  --sh-3: 0 24px 70px rgba(0, 0, 0, .22);

  --ease: cubic-bezier(.22, .61, .36, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --dur: .28s;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --bg-glass: rgba(28, 28, 30, .72);
    --bg-glass-strong: rgba(28, 28, 30, .9);
    --fill: rgba(120, 120, 128, .26);
    --fill-2: rgba(120, 120, 128, .16);
    --sep: rgba(84, 84, 88, .6);
    --sep-strong: rgba(84, 84, 88, .9);
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, .6);
    --label-3: rgba(235, 235, 245, .32);
    --tint: #ff4d6d;
    --tint-2: #ff375f;
    --tint-soft: rgba(255, 77, 109, .18);
    --accent: #0a84ff;
    --accent-2: #0a84ff;
    --accent-soft: rgba(10, 132, 255, .22);
    --sh-1: 0 1px 2px rgba(0, 0, 0, .5);
    --sh-2: 0 8px 30px rgba(0, 0, 0, .6);
    --sh-3: 0 24px 70px rgba(0, 0, 0, .7);
  }
}

/* ---------------- Base ---------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--tint); text-decoration: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
code { font-family: var(--mono); font-size: .92em; background: var(--fill-2); padding: 1px 5px; border-radius: 5px; }

/* ---------------- Nav ---------------- */
.nav {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 14px;
  height: 60px; padding: 0 16px;
  background: var(--bg-glass);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-bottom: .5px solid var(--sep);
  animation: navIn .5s var(--ease) both;
}
@keyframes navIn { from { opacity: 0; transform: translateY(-8px); } }

.nav-brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  box-shadow: 0 2px 8px rgba(10, 132, 255, .28);
}
.brand-name { font-size: 15px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand-name em { font-style: normal; font-size: 10.5px; font-weight: 500; color: var(--label-3); letter-spacing: .04em; }
.brand-mark svg { width: 19px; height: 19px; color: #fff; }

.segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--fill); border-radius: 11px;
  margin-left: auto;
}
.seg-btn {
  padding: 5px 14px; border-radius: 9px; font-size: 13px; font-weight: 560;
  color: var(--label-2); transition: color var(--dur) var(--ease), background var(--dur) var(--ease), transform .18s var(--ease);
}
.seg-btn:hover { color: var(--label); }
.seg-btn:active { transform: scale(.96); }
.seg-btn.active {
  background: var(--bg-elev); color: var(--label);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.nav-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  color: var(--label-2); transition: background var(--dur) var(--ease), color var(--dur), transform .18s var(--ease);
}
.icon-btn:hover { background: var(--fill); color: var(--label); }
.icon-btn:active { transform: scale(.92); }

.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 999px;
  font-size: 13px; font-weight: 560; color: var(--label);
  background: var(--fill);
  transition: background var(--dur) var(--ease), transform .18s var(--ease), box-shadow var(--dur);
}
.pill-btn:hover { background: var(--fill); filter: brightness(.97); }
.pill-btn:active { transform: scale(.96); }
.pill-btn svg { width: 16px; height: 16px; stroke-width: 2; }
.pill-btn.primary {
  color: #fff; background: linear-gradient(160deg, var(--tint), var(--tint-2));
  box-shadow: 0 4px 14px rgba(255, 55, 95, .3);
}
.pill-btn.primary:hover { filter: brightness(1.04); }
.pill-btn.account { position: relative; padding-left: 12px; }
.lic-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--label-3);
  transition: background var(--dur), box-shadow var(--dur);
}
.lic-dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(52, 199, 89, .18); }

/* ---------------- Banner ---------------- */
.banner {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px; font-size: 12.5px;
  color: #a32343; background: linear-gradient(90deg, #fff1f4, #fff7f0);
  border-bottom: .5px solid rgba(255, 55, 95, .16);
}
.banner.ok { color: #12703a; background: linear-gradient(90deg, #eefbf2, #f2fdf6); border-color: rgba(52, 199, 89, .2); }
@media (prefers-color-scheme: dark) {
  .banner { color: #ffb3c4; background: rgba(255, 55, 95, .12); border-color: rgba(255, 55, 95, .2); }
  .banner.ok { color: #8ef0b0; background: rgba(52, 199, 89, .12); border-color: rgba(52, 199, 89, .22); }
}
.link-btn { font-size: 12.5px; font-weight: 600; color: var(--tint); }
.link-btn:hover { text-decoration: underline; }

/* ---------------- Layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 356px;
  gap: 18px;
  max-width: 1760px; margin: 0 auto;
  padding: 16px 18px 8px;
  align-items: start;
}
.layout.no-panel { grid-template-columns: minmax(0, 1fr); }
.layout.no-panel .panel { display: none; }

/* ---------------- Stage ---------------- */
.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  min-height: min(70vh, 720px);
  max-height: min(74vh, 800px);   /* 固定可视高度：放大时内部滚动，缩放锚点才稳 */
  padding: 26px;
  overflow: auto;
  border-radius: var(--r-xl);
  background:
    radial-gradient(1200px 600px at 12% -10%, rgba(255, 55, 95, .10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(10, 132, 255, .09), transparent 60%),
    var(--bg-elev);
  border: 1px solid var(--sep);
  animation: rise .55s var(--ease) both;
}
.canvas-wrap::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 0 0 .5px var(--sep);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.995); } }

#gridCanvas {
  margin: auto;   /* 用 auto margin 居中：溢出时可完整滚动，不会被裁掉左/上边 */
  background: #fff; border-radius: 14px; touch-action: none; cursor: crosshair;
  box-shadow: 0 10px 34px rgba(15, 23, 42, .16), 0 1px 0 rgba(0, 0, 0, .04);
  transition: box-shadow var(--dur) var(--ease);
}

/* 悬浮尺寸胶囊 */
.size-chip {
  position: absolute; top: 14px; left: 16px; z-index: 3;
  padding: 6px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--label-2);
  background: var(--bg-glass-strong);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  backdrop-filter: blur(16px) saturate(180%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .1);
}
@media (prefers-color-scheme: dark) { .size-chip { color: #fff; } }

/* 悬浮工具栏 */
.rail {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%); z-index: 4;
  display: flex; flex-direction: column; gap: 4px; padding: 6px;
  border-radius: 18px;
  background: var(--bg-glass-strong);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--sh-2);
  animation: railIn .5s var(--spring) both .08s;
}
@keyframes railIn { from { opacity: 0; transform: translateY(-50%) translateX(-14px); } }

.rail-btn {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  color: var(--label-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform .22s var(--spring);
}
.rail-btn svg { width: 21px; height: 21px; }
.rail-btn:hover { background: var(--fill-2); color: var(--label); }
.rail-btn:active { transform: scale(.9); }
.rail-btn.active {
  background: var(--bg-elev); color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
}
.rail-sep { height: .5px; background: var(--sep); margin: 2px 6px; }

/* 缩放胶囊 */
.zoom-pill {
  position: absolute; right: 16px; bottom: 16px; z-index: 4;
  display: flex; align-items: center; gap: 2px; padding: 4px;
  border-radius: 999px;
  background: var(--bg-glass-strong);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--sh-2);
}
.zoom-btn {
  min-width: 34px; height: 30px; padding: 0 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--label-2);
  transition: background var(--dur), color var(--dur), transform .18s var(--spring);
}
.zoom-btn:hover { background: var(--fill); color: var(--label); }
.zoom-btn:active { transform: scale(.92); }
.zoom-btn.wide { font-size: 12px; }

/* 统计抽屉 */
.dock {
  border-radius: var(--r-lg); background: var(--bg-elev); border: 1px solid var(--sep);
  padding: 10px 14px 8px;
  animation: rise .55s var(--ease) both .06s;
}
.dock-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dock-sum { display: flex; align-items: baseline; gap: 8px; font-size: 13.5px; }
.dock-sum strong { font-weight: 650; }
.dock-sum span { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.dock-tools { display: flex; gap: 6px; }
.ghost-mini {
  height: 28px; padding: 0 11px; border-radius: 999px;
  font-size: 12px; font-weight: 560; color: var(--label-2); background: var(--fill-2);
  transition: background var(--dur), color var(--dur), transform .16s var(--ease);
}
.ghost-mini:hover { background: var(--fill); color: var(--label); }
.ghost-mini:active { transform: scale(.95); }

.dock-body {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(152px, 1fr));
  gap: 6px; margin-top: 10px; max-height: 190px; overflow-y: auto;
  transition: max-height .38s var(--ease), opacity .3s var(--ease), margin .3s var(--ease);
}
.dock-body.collapsed { max-height: 0; opacity: 0; margin-top: 0; overflow: hidden; }
.empty-tip { grid-column: 1 / -1; font-size: 12.5px; color: var(--label-3); padding: 6px 2px; }

.statusline {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 8px; padding-top: 7px; border-top: .5px solid var(--sep);
  font-size: 11.5px; color: var(--label-3); min-height: 22px; align-items: center;
}

/* ---------------- Panel ---------------- */
.panel {
  display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto; overscroll-behavior: contain;
  padding-right: 2px;
  scrollbar-width: thin;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: var(--sep-strong); border-radius: 3px; }

.group { animation: rise .5s var(--ease) both; }
.group:nth-child(2) { animation-delay: .04s; }
.group:nth-child(3) { animation-delay: .08s; }
.group:nth-child(4) { animation-delay: .12s; }
.group:nth-child(5) { animation-delay: .16s; }

.group-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 0 8px 4px; font-size: 14px; font-weight: 600;
  letter-spacing: -.01em; color: var(--label);
}
.group-title em { font-style: normal; font-size: 12px; font-weight: 400; color: var(--label-3); }

.card {
  background: var(--bg-elev); border-radius: var(--r-lg);
  padding: 16px; border: 1px solid var(--sep);
}
.card + .card { margin-top: 10px; }

/* 上传 */
.dropzone {
  position: relative; border-radius: var(--r-md); overflow: hidden;
  background: var(--fill-2); cursor: pointer;
  transition: background var(--dur) var(--ease), transform .2s var(--ease), box-shadow var(--dur);
}
.dropzone:hover { background: var(--fill); }
.dropzone.drag { background: var(--tint-soft); box-shadow: inset 0 0 0 1.5px var(--tint); transform: scale(.995); }
.dz-inner { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 20px 12px; text-align: center; }
.dz-icon { color: var(--label-3); margin-bottom: 2px; }
.dz-icon svg { width: 26px; height: 26px; }
.dz-inner strong { font-size: 13.5px; font-weight: 600; }
.dz-inner small { font-size: 11.5px; color: var(--label-3); }
.dz-thumb { width: 100%; max-height: 132px; object-fit: contain; border-radius: 10px; background: #fff; }

/* 通用行/列 */
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.row-2.tight { margin-top: 0; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 16px; border-radius: var(--r-md);
  font-size: 14px; font-weight: 590; letter-spacing: -.01em;
  transition: background var(--dur) var(--ease), color var(--dur), transform .18s var(--spring), box-shadow var(--dur), filter var(--dur);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn.locked, .pill-btn.locked { opacity: .58; }
.btn.locked::after, .pill-btn.locked::after { content: '🔒'; font-size: 11px; margin-left: 2px; }

.btn.filled {
  color: #fff; background: linear-gradient(160deg, var(--tint), var(--tint-2));
  box-shadow: 0 6px 18px rgba(255, 55, 95, .28);
}
.btn.filled:hover { filter: brightness(1.04); }
.btn.tonal { color: var(--label); background: var(--fill); }
.btn.tonal:hover { background: var(--fill-2); filter: brightness(.99); }
.btn.plain { color: var(--tint); background: transparent; }
.btn.plain:hover { background: var(--tint-soft); }
.btn.block { width: 100%; margin-top: 10px; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: 10px; }
.btn.mini { height: 34px; padding: 0 12px; font-size: 12.5px; border-radius: 10px; background: var(--fill); color: var(--label); }
.btn.mini:hover { background: var(--fill-2); }

/* 表单块 */
.field { margin-top: 14px; }
.field-label { display: block; font-size: 12px; font-weight: 560; color: var(--label-2); margin-bottom: 6px; }
.select-wrap { position: relative; }
.select-wrap select {
  -webkit-appearance: none; appearance: none; width: 100%;
  height: 42px; padding: 0 36px 0 13px;
  border: 0; border-radius: var(--r-md); background: var(--fill-2); color: var(--label);
  font-size: 14px;
  transition: background var(--dur), box-shadow var(--dur);
}
.select-wrap select:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tint-soft); }
.select-wrap .chev { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--label-3); pointer-events: none; }
.text-input {
  width: 100%; height: 42px; padding: 0 13px; border: 0; border-radius: var(--r-md);
  background: var(--fill-2); color: var(--label); font-size: 14px;
}
.text-input:focus { outline: none; box-shadow: 0 0 0 3px var(--tint-soft); }
.text-input::placeholder { color: var(--label-3); }

/* 滑杆 */
.slider-row { margin-bottom: 4px; }
.slider-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.slider-head label { font-size: 13px; font-weight: 560; color: var(--label); }
.value-pill {
  min-width: 44px; text-align: center; padding: 2px 9px; border-radius: 8px;
  font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums;
  color: var(--accent); background: var(--accent-soft);
}
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) 0 var(--p, 0%), var(--fill) var(--p, 0%) 100%);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 24px; height: 24px; margin-top: -10px;
  border-radius: 50%; background: #fff; border: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .22), 0 0 0 .5px rgba(0, 0, 0, .08);
  transition: transform .18s var(--spring);
}
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.15); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--fill); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.22); }

.fine-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.fine-row input[type=number] {
  width: 78px; height: 34px; padding: 0 10px; border: 0; border-radius: 10px;
  background: var(--fill-2); font-size: 13px; font-variant-numeric: tabular-nums;
}
.fine-row input[type=number]:focus { outline: none; box-shadow: 0 0 0 3px var(--tint-soft); }
.hint-inline { font-size: 11.5px; color: var(--label-3); margin-left: auto; }

/* 分组内列表 */
.list-card {
  margin-top: 14px; border-radius: var(--r-md); background: var(--fill-2); overflow: hidden;
}
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 46px; padding: 0 13px; font-size: 14px;
  position: relative;
}
.list-row + .list-row::before {
  content: ''; position: absolute; left: 13px; right: 0; top: 0; height: .5px; background: var(--sep);
}

/* iOS 开关 */
.switch { display: inline-flex; }
.switch input {
  -webkit-appearance: none; appearance: none;
  width: 51px; height: 31px; border-radius: 16px; background: var(--fill);
  position: relative; transition: background var(--dur) var(--ease); margin: 0;
}
.switch input::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18), 0 0 0 .5px rgba(0, 0, 0, .04);
  transition: transform .32s var(--spring);
}
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:active::after { width: 30px; }

/* 分块 chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips + .chips { margin-top: 8px; }
.chip {
  height: 34px; padding: 0 15px; border-radius: 999px;
  font-size: 12.5px; font-weight: 500; color: var(--label-2);
  background: var(--bg-elev);
  box-shadow: inset 0 0 0 .5px var(--sep-strong);
  transition: background var(--dur) var(--ease), color var(--dur), transform .18s var(--spring), box-shadow var(--dur);
}
.chip:hover { background: var(--fill); color: var(--label); }
.chip:active { transform: scale(.95); }
.chip.active {
  background: linear-gradient(160deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 4px 12px rgba(10, 132, 255, .26);
}

.pick-row { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 7px; }
.pick-label { font-size: 12px; color: var(--label-2); }
.pick-value { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

.palette-grid {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px;
  max-height: 188px; overflow-y: auto; padding: 8px;
  border-radius: var(--r-md); background: var(--fill-2);
}
.swatch {
  aspect-ratio: 1; border-radius: 6px; border: .5px solid rgba(0, 0, 0, .14);
  transition: transform .16s var(--spring), box-shadow .16s var(--ease);
}
.swatch:hover { transform: scale(1.16); z-index: 2; }
.swatch.active { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px var(--accent); z-index: 3; }

.footnote { margin: 10px 0 0; font-size: 11.5px; color: var(--label-3); line-height: 1.5; }
.footnote b { color: var(--label-2); }

/* 用量条目 */
.stat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border-radius: 11px; background: var(--fill-2);
  font-size: 12px; cursor: pointer;
  transition: background var(--dur), transform .16s var(--ease);
}
.stat-item:hover { background: var(--fill); }
.stat-item:active { transform: scale(.985); }
.stat-item i { width: 18px; height: 18px; border-radius: 5px; border: .5px solid rgba(0,0,0,.16); flex: 0 0 auto; }
.stat-item .code { font-family: var(--mono); font-size: 11.5px; font-weight: 600; }
.stat-item .name { flex: 1 1 auto; color: var(--label-3); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-item .cnt { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

/* 导出记录 */
.export-log { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.export-log:empty { display: none; }
.el-head { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: var(--label-3); }
.el-head b { color: var(--label-2); font-size: 12px; }
.el-item {
  display: grid; grid-template-columns: 36px minmax(0, 1fr); grid-template-areas: "thumb main" "actions actions";
  gap: 6px 8px; padding: 8px; border-radius: var(--r-md); background: var(--fill-2);
}
.el-item img { grid-area: thumb; width: 36px; height: 36px; object-fit: cover; border-radius: 8px; background: #fff; }
.el-main { grid-area: main; min-width: 0; }
.el-name { font-size: 11.5px; font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el-path { margin-top: 2px; font-size: 10.5px; color: #15803d; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el-path.hint { color: var(--label-3); }
.el-actions { grid-area: actions; display: flex; gap: 6px; }
.el-actions button {
  flex: 1; height: 28px; border-radius: 9px; font-size: 11.5px; font-weight: 560;
  color: var(--label); background: var(--fill);
}
.el-actions button:hover { background: var(--fill-2); }

/* ---------------- Modals（iOS Sheet） ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  background: rgba(0, 0, 0, .32);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade .24s var(--ease) both;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: relative; width: min(560px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 26px 26px 0 0;
  padding: 12px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--sh-3);
  animation: sheetUp .42s var(--spring) both;
}
.sheet.wide { width: min(900px, 100%); }
.sheet.narrow { width: min(440px, 100%); }
@keyframes sheetUp { from { transform: translateY(100%); } }

.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--sep-strong); margin: 0 auto 10px; }
.sheet-close {
  position: absolute; top: 12px; right: 14px;
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; color: var(--label-2); background: var(--fill);
  transition: background var(--dur), transform .18s var(--ease);
}
.sheet-close:hover { background: var(--fill-2); }
.sheet-close:active { transform: scale(.92); }

.sheet h2 { margin: 2px 0 5px; font-size: 21px; font-weight: 700; letter-spacing: -.02em; }

/* 居中对话框（替换杂色等操作型弹窗）：标题居中、无抓手 */
.sheet.dialog { width: min(480px, 100%); }
.sheet.dialog h2 { text-align: center; margin-top: 4px; }
.sheet.dialog .sheet-sub { text-align: center; }
.sheet.dialog .btn.block { margin-top: 14px; }
.sheet-sub { margin: 0 0 14px; font-size: 13px; color: var(--label-2); line-height: 1.55; }
.sheet-sub code { color: var(--tint); background: var(--tint-soft); }

.key-row { display: flex; gap: 8px; }
.key-row input {
  flex: 1; height: 46px; padding: 0 14px; border: 0; border-radius: 13px;
  background: var(--fill-2); font-family: var(--mono); font-size: 15px; letter-spacing: .12em;
  text-transform: uppercase;
}
.key-row input:focus { outline: none; box-shadow: 0 0 0 3px var(--tint-soft); }
.key-row .btn { height: 46px; }

.lic-status {
  margin-top: 12px; padding: 11px 13px; border-radius: 13px;
  font-size: 12.5px; background: var(--fill-2); color: var(--label-2);
}
.lic-status.ok { background: rgba(52, 199, 89, .12); color: #12703a; }
.lic-status.err { background: rgba(255, 59, 48, .1); color: #b3261e; }
@media (prefers-color-scheme: dark) {
  .lic-status.ok { color: #8ef0b0; }
  .lic-status.err { color: #ffb4ab; }
}

.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.plan {
  padding: 13px 8px; border-radius: var(--r-md); text-align: center;
  background: var(--fill-2); transition: transform .18s var(--spring), background var(--dur);
}
.plan.best { background: var(--tint-soft); box-shadow: inset 0 0 0 1.5px rgba(255, 55, 95, .35); }
.plan b { display: block; font-size: 18px; font-weight: 700; color: var(--tint); letter-spacing: -.02em; }
.plan span { display: block; margin-top: 3px; font-size: 12px; color: var(--label-2); }
.plan em { display: block; margin-top: 5px; font-style: normal; font-size: 10.5px; color: var(--label-3); line-height: 1.35; }

.steps { margin: 16px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--label-2); line-height: 1.95; }

.exp-preview { display: flex; justify-content: center; padding: 8px; border-radius: var(--r-md); background: var(--fill-2); }
.exp-preview img { max-width: 100%; max-height: 42vh; border-radius: 10px; display: block; }
.exp-path {
  margin: 10px 0 12px; padding: 10px 12px; border-radius: 12px;
  font-size: 12px; line-height: 1.55; word-break: break-all; white-space: pre-line;
  color: #12703a; background: rgba(52, 199, 89, .1);
}
.exp-path.warn { color: #92400e; background: rgba(255, 159, 10, .12); }
@media (prefers-color-scheme: dark) {
  .exp-path { color: #8ef0b0; }
  .exp-path.warn { color: #ffd60a; }
}

.history-list { display: flex; flex-direction: column; gap: 8px; max-height: 54vh; overflow-y: auto; }
.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--r-md); background: var(--fill-2);
}
.history-item img { width: 44px; height: 44px; object-fit: cover; border-radius: 9px; background: #fff; }
.hi-main { flex: 1; min-width: 0; }
.hi-main strong { display: block; font-size: 12.5px; font-weight: 600; }
.hi-main small { font-size: 11.5px; color: var(--label-3); }
.history-item button {
  height: 30px; padding: 0 11px; border-radius: 9px; font-size: 12px; font-weight: 560;
  background: var(--fill); color: var(--label);
}
.history-item button:hover { background: var(--bg-elev); }

.pal-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.pal-tools input {
  flex: 1 1 90px; min-width: 84px; height: 38px; padding: 0 11px;
  border: 0; border-radius: 11px; background: var(--fill-2); font-size: 12.5px;
}
.pal-tools .btn { flex: 0 0 auto; }
.pal-manage-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  gap: 6px; max-height: 42vh; overflow-y: auto; padding-right: 2px;
}
.pm-item {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px;
  border-radius: 11px; background: var(--fill-2); font-size: 11.5px;
  transition: opacity var(--dur) var(--ease);
}
.pm-item.off { opacity: .42; }
.pm-item i { width: 16px; height: 16px; border-radius: 5px; border: .5px solid rgba(0,0,0,.16); flex: 0 0 auto; }
.pm-item .pm-code { font-family: var(--mono); font-weight: 600; }
.pm-item button {
  margin-left: auto; height: 24px; padding: 0 8px; border-radius: 7px;
  font-size: 10.5px; background: var(--fill); color: var(--label-2);
}
.pm-item button:hover { background: var(--bg-elev); color: var(--tint); }

.info-body { font-size: 13.5px; color: var(--label-2); line-height: 1.8; }
.info-body ol { padding-left: 18px; }
.info-body li { margin-bottom: 4px; }
.info-body b { color: var(--label); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; top: 14px; left: 50%; z-index: 120;
  transform: translate(-50%, -140%);
  padding: 10px 16px; border-radius: 999px; max-width: min(92vw, 620px);
  font-size: 13px; font-weight: 560; color: #fff;
  background: rgba(28, 28, 30, .92);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
  opacity: 0; pointer-events: none;
  transition: transform .42s var(--spring), opacity .28s var(--ease);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------------- 全屏 ---------------- */
body.fs .nav, body.fs .banner, body.fs .panel { display: none; }
body.fs .layout { grid-template-columns: minmax(0, 1fr); padding: 8px; gap: 8px; }
body.fs .canvas-wrap { min-height: calc(100vh - 120px); border-radius: 18px; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; padding: 12px 14px 6px; }
  .palette-grid { grid-template-columns: repeat(10, 1fr); }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .stage { order: 1; }
  .panel { order: 2; position: static; max-height: none; overflow: visible; }
  .canvas-wrap { min-height: 58vh; max-height: 66vh; padding: 14px; }
  .nav { height: 54px; padding: 0 12px; gap: 8px; }
  .brand-name { font-size: 14px; }
  .brand-mark { width: 28px; height: 28px; border-radius: 9px; }
  .brand-mark svg { width: 17px; height: 17px; }
  .nav-seg { display: none; }
  .pill-btn { height: 32px; padding: 0 12px; font-size: 12.5px; }
  .rail {
    position: static; transform: none; flex-direction: row; flex-wrap: wrap;
    justify-content: center; margin-bottom: 10px; animation: none; width: fit-content;
  }
  .rail-sep { width: .5px; height: 24px; margin: 0 2px; }
  .canvas-wrap { flex-direction: column; }
  .size-chip { top: 10px; left: 12px; }
  .zoom-pill { right: 12px; bottom: 12px; }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .brand-name { font-size: 13px; }
  .nav-actions .icon-btn { display: none; }
  .layout { padding: 10px 10px 4px; }
  .card { padding: 12px; border-radius: 18px; }
  .canvas-wrap { border-radius: 20px; min-height: 62vh; max-height: 70vh; padding: 12px; }
  .rail { padding: 4px; gap: 2px; }
  .rail-btn { width: 38px; height: 38px; border-radius: 10px; }
  .dock-body { grid-template-columns: repeat(auto-fill, minmax(134px, 1fr)); }
  .palette-grid { grid-template-columns: repeat(9, 1fr); max-height: 132px; }
  .sheet { border-radius: 22px 22px 0 0; padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); }
  .sheet h2 { font-size: 19px; }
  .plan-grid { grid-template-columns: 1fr; }
}

/* 桌面端把 sheet 居中显示，更像系统面板 */
@media (min-width: 700px) {
  .modal { align-items: center; padding: 24px; }
  .sheet { border-radius: 26px; animation: sheetPop .42s var(--spring) both; }
  @keyframes sheetPop { from { opacity: 0; transform: translateY(18px) scale(.97); } }
}

/* ---------------- 无障碍：减少动效 ---------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-delay: 0s !important;
    transition-duration: .001ms !important;
  }
}

/* 焦点可见（键盘） */
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; border-radius: 8px; }

/* ---------- 跟随光标的色号 HUD ---------- */
.hover-hud {
  position: fixed; left: 0; top: 0; z-index: 30;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 11px 6px 8px; border-radius: 11px;
  font: 700 14.5px/1.15 var(--mono); color: #fff;
  background: rgba(17, 24, 39, .92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
  pointer-events: none;
  opacity: 0; transition: opacity .12s var(--ease);
}
.hover-hud.show { opacity: 1; }
.hover-hud i {
  width: 17px; height: 17px; border-radius: 4px;
  border: .5px solid rgba(255, 255, 255, .45);
  box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .2);
}
.hover-hud[hidden] { display: none; }

/* ---------- 工具网格 / 笔刷 / 图片颜色 / 替换杂色 ---------- */
.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tool-cell {
  position: relative; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; font-weight: 500; letter-spacing: -.01em; color: var(--label);
  background: var(--bg-elev);
  box-shadow: inset 0 0 0 .5px var(--sep-strong);
  transition: background var(--dur) var(--ease), color var(--dur), transform .16s var(--spring), box-shadow var(--dur);
}
.tool-cell em { font-style: normal; font-size: 10.5px; font-weight: 600; color: var(--accent); opacity: .72; }
.tool-cell em::before { content: '('; }
.tool-cell em::after { content: ')'; }
.tool-cell:hover { background: var(--fill-2); }
.tool-cell:active { transform: scale(.97); }
.tool-cell.active {
  background: linear-gradient(160deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 5px 14px rgba(10, 132, 255, .28);
}
.tool-cell.active em { color: rgba(255, 255, 255, .78); }
.tool-cell.on {
  background: var(--accent-soft); color: var(--accent);
  box-shadow: inset 0 0 0 1.2px rgba(10, 132, 255, .45);
}
.tool-cell.on em { color: var(--accent); opacity: .8; }
.tool-cell:disabled { opacity: .38; }

.brush-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.brush-label { flex: 0 0 auto; width: 58px; font-size: 12px; color: var(--label-2); }
.seg-mini { display: inline-flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--fill-2); }
.seg-mini button {
  height: 28px; padding: 0 10px; border-radius: 7px; font-size: 12px; color: var(--label-2);
  transition: background var(--dur), color var(--dur);
}
.seg-mini button.active { background: var(--bg-elev); color: var(--label); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.brush-row input[type=range] { flex: 1; }

.img-color-head {
  margin: 12px 0 8px; padding: 9px 11px; border-radius: 11px;
  background: var(--fill-2); font-size: 12px; color: var(--label-2); text-align: center;
}
.img-color-row { display: flex; flex-wrap: wrap; gap: 6px; }
.img-color-row .sw {
  width: 40px; height: 40px; border-radius: 10px; border: .5px solid rgba(0, 0, 0, .14);
  display: grid; place-items: center;
  font: 700 11px/1 var(--mono); letter-spacing: -.02em;
  transition: transform .16s var(--spring), box-shadow .16s var(--ease);
}
.img-color-row .sw:hover { transform: scale(1.08); }
.img-color-row .sw.active { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px var(--accent); }

.replace-list { display: flex; flex-direction: column; gap: 6px; max-height: 38vh; overflow-y: auto; margin-bottom: 14px; }
.replace-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px;
  border-radius: 12px; background: var(--fill-2); text-align: left; width: 100%;
  transition: background var(--dur), box-shadow var(--dur);
}
.replace-item:hover { background: var(--fill); }
.replace-item.sel { background: var(--accent-soft); box-shadow: inset 0 0 0 1.6px var(--accent); }
.replace-item i { width: 18px; height: 18px; border-radius: 5px; border: .5px solid rgba(0, 0, 0, .14); flex: 0 0 auto; }
.replace-item .rc { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.replace-item .rn { flex: 1; font-size: 11.5px; color: var(--label-3); }
.replace-item .rcnt { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

/* 下载图纸的系统面板 */
.export-settings {
  --export-panel-gap: 14px;
  width: min(500px, calc(100% - 28px));
  max-height: min(760px, calc(100dvh - 28px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--sep);
  border-radius: 24px;
  color: var(--label);
  overflow: hidden;
}
.export-settings::backdrop {
  background: rgba(15, 23, 42, .36);
  backdrop-filter: blur(4px);
}
.export-settings form {
  display: flex;
  flex-direction: column;
  max-height: min(758px, calc(100dvh - 30px));
  padding: 18px 18px 14px;
}
.export-settings h2, .export-settings .sheet-sub { padding-right: 30px; }
.export-settings .sheet-sub { margin: 0 0 12px; }
.export-settings-body { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.export-settings .list-card { margin: 0; }
.export-settings .list-row { cursor: pointer; }
.export-settings .switch { flex: none; }
.export-settings .switch input:checked { background: var(--accent); }
.export-settings :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.export-grid-details {
  margin: 0 13px 4px;
  padding: 8px 0 10px;
  border-top: 1px solid var(--sep);
  border-bottom: 1px solid var(--sep);
}
.export-grid-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.export-grid-label, .export-colors legend { font-size: 12.5px; color: var(--label-2); }
.export-grid-label output { color: var(--accent); font-weight: 650; font-variant-numeric: tabular-nums; }
.export-grid-details input[type=range] { display: block; width: 100%; margin: 7px 0 6px; }
.export-colors { display: flex; flex-wrap: wrap; gap: 5px; margin: 0; padding: 3px 0 0; border: 0; }
.export-colors legend { padding: 0; }
.export-color {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: 37px;
  block-size: 36px;
  cursor: pointer;
}
.export-color input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.export-color span {
  width: 23px;
  height: 23px;
  background: var(--swatch);
  border: 2px solid var(--bg-elev);
  border-radius: 50%;
  outline: 1px solid var(--sep-strong);
}
.export-color input:checked + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.export-color input:focus-visible + span { box-shadow: 0 0 0 5px var(--accent-soft); }
.export-file-options {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 10px;
  margin: var(--export-panel-gap) 0;
}
.export-file-options .field { margin: 0; min-width: 0; }
.export-file-options .text-input { width: 100%; min-width: 0; }
.export-settings-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: var(--export-panel-gap); }
@media (max-width: 640px) {
  .export-settings { border-radius: 22px; }
  .export-settings form { padding: 15px 14px 12px; }
}

.sheet [hidden] { display: none !important; }

/* 项目和用量 */
.history-thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; border: 1px solid var(--sep); }
.stat-item { min-width: 0; text-align: left; }
.stat-action { color: var(--label-2); font-size: 11px; white-space: nowrap; }
#btnApplyReplace:disabled { opacity: .44; cursor: default; }
.brand-short, .mobile-tabs, .mobile-undo { display: none; }
.canvas-region { display: contents; }

@media (max-width: 640px) {
  body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .nav { justify-content: space-between; padding-inline: 12px; }
  .nav-brand { flex: 0 1 auto; gap: 7px; }
  .nav-brand .brand-mark { flex: none; }
  .nav-brand .brand-name { display: none; }
  .brand-short { display: inline; font-size: 14px; font-weight: 650; white-space: nowrap; }
  .nav-actions { flex: 0 0 auto; gap: 6px; }
  .nav-actions .pill-btn { flex: none; height: 38px; white-space: nowrap; padding: 0 10px; }
  .nav-actions .account { display: none; }
  .stage { scroll-margin-top: 60px; }
  .banner { gap: 5px; padding-inline: 8px; }
  .banner a { flex: none; white-space: nowrap; }
  .mobile-tabs {
    position: fixed; z-index: 68; bottom: calc(8px + env(safe-area-inset-bottom));
    left: 50%; transform: translateX(-50%); width: min(420px, calc(100% - 20px));
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
    padding: 4px; border: 1px solid var(--sep); border-radius: 20px;
    background: var(--bg-glass-strong); backdrop-filter: blur(16px); box-shadow: var(--sh-2);
  }
  .mobile-tabs button {
    min-width: 0; min-height: 46px; display: grid; justify-items: center; align-content: center; gap: 3px;
    border-radius: 14px; font-size: 11.5px; font-weight: 620; color: var(--label-2); white-space: nowrap;
  }
  .mobile-tabs button:active, .mobile-tabs button:focus-visible { background: var(--fill-2); }
  .mobile-tabs svg, .mobile-undo svg { width: 18px; height: 18px; stroke-width: 1.8; }
  .canvas-region { display: block; position: relative; }
  .rail #btnUndo { display: none; }
  .mobile-undo {
    display: flex; align-items: center; gap: 5px;
    position: absolute; left: 12px; bottom: 12px; z-index: 5;
    min-height: 40px; padding: 0 10px; border-radius: 20px;
    background: var(--bg-glass-strong); backdrop-filter: blur(16px); box-shadow: var(--sh-2);
    color: var(--accent); font-size: 12px; font-weight: 650;
  }
  .mobile-undo:disabled { color: var(--label-2); opacity: .65; cursor: default; }
  .stat-item .name { display: none; }
  .stat-item .stat-action { margin-left: auto; }
}

