/* ===== 拼豆图纸生成器 — 新海诚天空 × Apple 毛玻璃 =====
   氛围层：渐变天空 + 漂移云层 + 镜头光晕 + 星芒（纯 CSS 动画）
   结构：顶部玻璃栏 → 居中英雄画布 → 材料统计玻璃条带 → 底部两行玻璃控制栏
   交互：spring 弹跳、点击涟漪、hover 上浮、开关发光、prefers-reduced-motion 兜底
*/

:root {
  --navy: #17395C;
  --navy-2: rgba(23, 57, 92, 0.62);
  --navy-3: rgba(23, 57, 92, 0.38);
  --accent: #E8734A;
  --accent-press: #D05E38;
  --accent-glow: rgba(232, 115, 74, 0.45);
  --card: rgba(255, 255, 255, 0.66);
  --card-solid: #FFFDF8;
  --card-inner: #FFFDF8;
  --empty-cell: #F2F2F7;
  --line: rgba(255, 255, 255, 0.75);
  --line-dim: rgba(23, 57, 92, 0.10);
  --glass-bg: rgba(255, 255, 255, 0.52);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.85);
  --glass-shadow: 0 2px 8px rgba(23, 57, 92, 0.08), 0 12px 32px rgba(23, 57, 92, 0.14), 0 32px 80px rgba(23, 57, 92, 0.10);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont,
               "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--navy);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* ============ 新海诚天空氛围层 ============ */
.sky {
  position: fixed; inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg,
    #1C4C7C 0%, #2F669E 16%, #4E8CBE 34%, #7FB6DC 52%,
    #B7DDEF 68%, #E4F1F3 80%, #FBE8CF 91%, #FFD9AE 100%);
}
/* 右上暖阳 + 地平线暖光 */
.sky-glow {
  position: absolute; inset: 0;
  background:
    radial-gradient(46% 38% at 82% 6%, rgba(255, 214, 150, 0.55), rgba(255, 214, 150, 0) 70%),
    radial-gradient(60% 30% at 50% 100%, rgba(255, 170, 110, 0.35), rgba(255, 170, 110, 0) 70%);
}
/* 漂移云层：两大片柔和云带，超慢速平移 */
.sky-clouds {
  position: absolute; inset: -10% -40%;
  background:
    radial-gradient(38% 14% at 20% 30%, rgba(255, 255, 255, 0.50), rgba(255, 255, 255, 0) 70%),
    radial-gradient(30% 10% at 68% 22%, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0) 70%),
    radial-gradient(44% 16% at 45% 58%, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 72%),
    radial-gradient(26% 9% at 85% 48%, rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0) 70%);
}
/* 镜头光束：斜向微弱光柱 */
.sky-rays {
  position: absolute; inset: -20%;
  background: repeating-linear-gradient(112deg,
    rgba(255, 255, 255, 0.10) 0 3px,
    rgba(255, 255, 255, 0) 3px 110px);
  mask-image: radial-gradient(55% 45% at 78% 8%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(55% 45% at 78% 8%, #000 0%, transparent 75%);
  opacity: 0.55;
}
/* 星芒微粒 */
.sky-sparkle {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(2px 2px at 12% 12%, rgba(255,255,255,0.9), transparent 60%),
    radial-gradient(1.5px 1.5px at 34% 6%, rgba(255,255,255,0.75), transparent 60%),
    radial-gradient(2px 2px at 62% 14%, rgba(255,255,255,0.85), transparent 60%),
    radial-gradient(1.5px 1.5px at 88% 22%, rgba(255,255,255,0.8), transparent 60%),
    radial-gradient(2px 2px at 74% 4%, rgba(255,255,255,0.9), transparent 60%);
  opacity: 0.6;
}

/* ============ Apple 毛玻璃 ============ */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--glass-border);
  box-shadow:
    var(--glass-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 -1px 0 rgba(23, 57, 92, 0.05);
}

/* ---- 图标 ---- */
.ic {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---- 顶部栏 ---- */
.topbar {
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-left: none; border-right: none; border-top: none;
  border-radius: 0;
  z-index: 20;
  animation: slideDown 550ms var(--ease-out) both;
}
.topbar-title {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px;
  white-space: nowrap;
}
.topbar-title .logo-img {
  width: 30px; height: 30px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 1px 5px rgba(23, 57, 92, 0.18);
  transition: transform 350ms var(--spring);
}
.topbar-title .logo-img:hover { transform: rotate(20deg) scale(1.1); }
.topbar-controls { display: flex; align-items: center; gap: 12px; }
.ctl-label { font-size: 14px; color: var(--navy-2); }

/* ---- 下拉 / 输入 ---- */
.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute; right: 12px; top: 50%;
  width: 7px; height: 7px;
  border-right: 2px solid var(--navy-2);
  border-bottom: 2px solid var(--navy-2);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
select {
  appearance: none; -webkit-appearance: none;
  font: inherit; font-size: 14px;
  color: var(--navy);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line-dim);
  border-radius: 14px;
  padding: 6px 32px 6px 13px;
  cursor: pointer;
  transition: transform 300ms var(--spring), box-shadow 200ms ease-out;
}
select:hover { box-shadow: 0 3px 12px rgba(23, 57, 92, 0.12); }
select:active { transform: scale(0.96); }

/* ---- 自定义毛玻璃下拉（品牌选择器）：触发器 + 玻璃弹出菜单 ---- */
.glass-select {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; color: var(--navy);
  background: rgba(255, 255, 255, 0.40);
  -webkit-backdrop-filter: blur(20px) saturate(1.7);
  backdrop-filter: blur(20px) saturate(1.7);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 14px;
  padding: 6px 12px;
  cursor: pointer; user-select: none;
  box-shadow: 0 1px 3px rgba(23, 57, 92, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  transition: transform 300ms var(--spring), box-shadow 200ms ease-out, background 200ms ease-out;
  outline: none;
}
.glass-select:hover { background: rgba(255, 255, 255, 0.55); box-shadow: 0 3px 14px rgba(23, 57, 92, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.9); }
.glass-select:active { transform: scale(0.96); }
.glass-select:focus-visible { box-shadow: 0 0 0 3px rgba(232, 115, 74, 0.22); }
.gs-arrow {
  width: 14px; height: 14px; flex: none;
  fill: none; stroke: var(--navy-2); stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform 300ms var(--spring);
}
.glass-select.open .gs-arrow { transform: rotate(180deg); }
.gs-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
  min-width: 100%;
  display: flex; flex-direction: column; gap: 2px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.48);
  -webkit-backdrop-filter: blur(28px) saturate(1.8);
  backdrop-filter: blur(28px) saturate(1.8);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 16px;
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  opacity: 0; transform: translateY(-6px) scale(0.94);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity 220ms var(--ease-out), transform 320ms var(--spring);
}
.glass-select.open .gs-menu { opacity: 1; transform: none; pointer-events: auto; }
.gs-opt {
  padding: 7px 14px; border-radius: 11px;
  white-space: nowrap; color: var(--navy); font-weight: 500;
  transition: background 160ms ease-out, transform 160ms var(--ease-out);
}
.gs-opt:hover { background: rgba(255, 255, 255, 0.72); }
.gs-opt:active { transform: scale(0.97); }
.gs-opt.sel { background: rgba(232, 115, 74, 0.14); color: var(--accent-press); font-weight: 700; }

input[type="number"] {
  font: inherit; font-size: 14px;
  width: 54px;
  color: var(--navy);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line-dim);
  border-radius: 12px;
  padding: 5px 8px;
  transition: box-shadow 200ms ease-out, border-color 200ms ease-out;
}
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 115, 74, 0.22);
}

/* ---- 滑块 ---- */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, rgba(232,115,74,0.55), rgba(23,57,92,0.18));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; margin-top: -7.5px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 1px solid rgba(23, 57, 92, 0.12);
  box-shadow: 0 1px 4px rgba(23, 57, 92, 0.25), 0 0 0 0 var(--accent-glow);
  transition: transform 250ms var(--spring), box-shadow 250ms ease-out;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); box-shadow: 0 2px 8px rgba(23,57,92,0.3), 0 0 0 6px rgba(232,115,74,0.14); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.25); box-shadow: 0 2px 10px rgba(23,57,92,0.35), 0 0 0 9px rgba(232,115,74,0.2); }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: rgba(23,57,92,0.18); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 1px solid rgba(23,57,92,0.12); box-shadow: 0 1px 4px rgba(23,57,92,0.25); }

/* ---- 按钮：涟漪 + spring ---- */
.btn {
  font: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  position: relative;
  overflow: hidden;
  border: none; cursor: pointer;
  border-radius: 16px;
  padding: 10px 18px;
  font-size: 16px; font-weight: 600;
  white-space: nowrap;
  transition: transform 350ms var(--spring), background 200ms ease-out,
              box-shadow 250ms ease-out, opacity 200ms ease-out;
}
.btn:active { transform: scale(0.95); }
.btn-cta {
  background: linear-gradient(135deg, #F08A5C, var(--accent) 55%, #D9603A);
  color: #FFFFFF;
  box-shadow: 0 2px 10px rgba(232, 115, 74, 0.4);
}
.btn-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(232, 115, 74, 0.5);
}
.btn-cta::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,0.4) 50%, transparent 60%);
  transform: translateX(-130%);
  transition: transform 650ms var(--ease-out);
  pointer-events: none;
}
.btn-cta:hover::before { transform: translateX(130%); }
.btn-quiet {
  background: rgba(255, 255, 255, 0.68);
  color: var(--navy);
  border: 1px solid var(--line-dim);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.btn-quiet:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(23, 57, 92, 0.14); }
.btn-sm { padding: 7px 13px; font-size: 14px; border-radius: 13px; }
.btn[disabled] { opacity: 0.4; cursor: default; transform: none; box-shadow: none; }

/* 点击涟漪（JS 注入 span.ripple） */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.75) 0%, rgba(255,255,255,0) 68%);
  transform: scale(0);
  animation: rippleOut 620ms var(--ease-out) forwards;
  pointer-events: none;
}
@keyframes rippleOut { to { transform: scale(1); opacity: 0; } }

/* ============ 首页英雄区 ============ */
.home {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 24px;
  position: relative; z-index: 1;
  min-height: 0;
}
.hero-card {
  max-width: 560px;
  border-radius: 28px;
  padding: 52px 48px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  text-align: center;
  animation: riseIn 700ms var(--spring) both;
}
.large-title {
  font-size: 34px; font-weight: 700; letter-spacing: -0.02em;
  background: linear-gradient(160deg, #17395C 20%, #3E7CB1 70%, #E8734A 115%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
/* ---- 顶栏品牌名：Apple 石墨黑 + 逐字轻量入场（一次性播放，不循环） ---- */
.brand-name { color: #1D1D1F; }
.brand-name .bn {
  display: inline-block; font-style: normal;
  opacity: 0;
  animation: brandIn 460ms var(--spring) forwards;
}
.brand-name .bn:nth-child(1) { animation-delay: 120ms; }
.brand-name .bn:nth-child(2) { animation-delay: 170ms; }
.brand-name .bn:nth-child(3) { animation-delay: 220ms; }
.brand-name .bn:nth-child(4) { animation-delay: 270ms; }
/* 像把豆子轻轻摆上模板：小幅度下落 + 一次极轻回弹，克制不花哨 */
@keyframes brandIn {
  0%   { opacity: 0; transform: translateY(-14px) scale(0.6); }
  60%  { opacity: 1; transform: translateY(2px) scale(1.06); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .brand-name .bn { animation: none; opacity: 1; }
}
.subtitle { font-size: 16px; color: var(--navy-2); }
.hero-card .btn-cta {
  margin-top: 10px;
  font-size: 17px;
  padding: 14px 30px;
  border-radius: 28px;
}
.footnote { font-size: 13px; color: var(--navy-3); line-height: 1.6; }

/* ============ 工作台（画布居中 + 底部控制栏） ============ */
.workbench {
  flex: 1;
  display: flex; flex-direction: column;
  gap: 12px;
  padding: 12px 16px 14px;
  min-height: 0;
  position: relative; z-index: 1;
}
.workbench.enter { animation: riseIn 550ms var(--spring) both; }

.card {
  border-radius: 24px;
  padding: 16px;
  min-height: 0;
}

/* ---- 画布英雄卡片 ---- */
.canvas-card {
  flex: 1;
  display: flex; flex-direction: column;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255,255,255,0.9);
  animation: fadeUp 500ms var(--ease-out) both;
}
.canvas-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.view-label {
  display: inline-block;
  font-size: 13px; font-weight: 700; color: var(--accent);
  background: rgba(232, 115, 74, 0.12);
  border: 1px solid rgba(232, 115, 74, 0.25);
  border-radius: 12px;
  padding: 3px 12px;
}
.view-label.swap { animation: swapIn 450ms var(--spring); }
@keyframes swapIn {
  0% { transform: translateY(6px) scale(0.9); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.canvas-area {
  flex: 1;
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--card-solid);
  border-radius: 16px;
  border: 1px solid var(--line-dim);
  overflow: hidden;
  position: relative;
  perspective: 1200px;
}
#mainCanvas.editable { cursor: crosshair; }
/* 触屏：画布上的手势交给绘制/裁剪，不触发页面滚动与双击缩放 */
#mainCanvas {
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
#mainCanvas.pop { animation: canvasPop 420ms var(--spring); }
@keyframes canvasPop {
  0% { transform: scale(0.965); }
  100% { transform: scale(1); }
}
#mainCanvas.flip { animation: canvasFlip 620ms var(--ease-out); }
@keyframes canvasFlip {
  0% { transform: rotateY(0deg); }
  50% { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

/* ---- 裁剪覆盖层 ---- */
.crop-ui {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: space-between;
  padding: 14px;
  pointer-events: none;
}
.crop-hint {
  pointer-events: auto;
  font-size: 13px; color: #fff;
  background: rgba(23, 57, 92, 0.65);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 6px 16px;
  animation: fadeUp 400ms var(--ease-out) both;
}
.crop-actions { pointer-events: auto; display: flex; gap: 10px; animation: fadeUp 400ms 60ms var(--ease-out) both; }

/* ---- 材料统计：横向玻璃条带 ---- */
.bom-card {
  flex: none;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255,255,255,0.9);
  animation: fadeUp 500ms 100ms var(--ease-out) both;
}
.bom-head {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 8px;
}
.card-title {
  font-size: 13px; font-weight: 700;
  color: var(--navy-2);
  letter-spacing: 0.03em;
}
.bom-total {
  font-size: 14px; font-weight: 700; color: var(--accent);
  background: rgba(232, 115, 74, 0.1);
  border-radius: 12px;
  padding: 2px 12px;
}
.bom-hint { font-size: 12px; color: var(--navy-3); margin-left: auto; }
.bom-list {
  display: flex; flex-wrap: wrap; gap: 8px;
  max-height: 96px;
  overflow: auto;
  scrollbar-width: thin;
}
.bom-row {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line-dim);
  border-radius: 14px;
  padding: 4px 11px 4px 6px;
  cursor: pointer;
  position: relative; overflow: hidden;
  animation: rowIn 420ms var(--spring) both;
  transition: transform 300ms var(--spring), box-shadow 200ms ease-out, border-color 200ms ease-out;
}
.bom-row:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(23,57,92,0.14); }
.bom-row:active { transform: scale(0.94); }
.bom-row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(232,115,74,0.3), 0 4px 14px rgba(232,115,74,0.25);
}
@keyframes rowIn {
  0% { transform: translateY(10px) scale(0.9); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.bom-swatch {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(23, 57, 92, 0.15);
  flex: none;
}
.bom-code { font-size: 13px; font-weight: 700; }
.bom-name { font-size: 12px; color: var(--navy-2); max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bom-count { font-size: 13px; font-weight: 700; color: var(--accent); }
.bom-count::after { content: " 颗"; font-weight: 400; font-size: 11px; color: var(--navy-2); }

/* ============ 底部玻璃控制栏 ============ */
.dock {
  flex: none;
  border-radius: 24px;
  padding: 10px 16px;
  display: flex; flex-direction: column; gap: 8px;
  animation: fadeUp 500ms 160ms var(--ease-out) both;
}
.dock-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dock-tools { justify-content: center; }
.dock-spacer { flex: 1; }
.tool-sep { width: 1px; height: 26px; background: var(--line-dim); flex: none; }
.dock-sep { width: 1px; align-self: stretch; background: var(--line-dim); flex: none; }

.tool-group { display: flex; align-items: center; gap: 6px; }
.tool-btn {
  min-width: 40px; height: 40px;
  padding: 0 9px;
  white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  position: relative; overflow: hidden;
  border: 1px solid var(--line-dim);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--navy);
  cursor: pointer;
  transition: transform 300ms var(--spring), background 200ms ease-out, box-shadow 200ms ease-out, color 200ms ease-out;
}
.tool-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 14px rgba(23,57,92,0.15); }
.tool-btn:active { transform: scale(0.9); }
.tool-btn[disabled] { opacity: 0.35; cursor: default; transform: none; box-shadow: none; }
.tool-btn.active {
  background: linear-gradient(135deg, #F08A5C, var(--accent));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 3px 12px var(--accent-glow);
  animation: pop 380ms var(--spring);
}
.tool-btn .ic { width: 18px; height: 18px; }
.tool-label { font-size: 12px; font-weight: 600; }
@keyframes pop {
  0% { transform: scale(0.85); }
  100% { transform: scale(1); }
}

.active-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 6px rgba(23, 57, 92, 0.3);
  background: #fff;
  flex: none;
}
.active-swatch.pulse { animation: swatchPulse 500ms var(--spring); }
@keyframes swatchPulse {
  0% { transform: scale(0.7); box-shadow: 0 0 0 8px rgba(232,115,74,0.35); }
  100% { transform: scale(1); box-shadow: 0 1px 6px rgba(23,57,92,0.3); }
}

/* ---- 设置组 ---- */
.dock-group {
  display: flex; flex-direction: column; gap: 5px;
  min-width: 0;
}
.dock-group-title {
  font-size: 11px; font-weight: 700;
  color: var(--navy-2);
  letter-spacing: 0.05em;
}
.dock-group-title b { color: var(--accent); font-size: 12px; }

.chip-row { display: flex; gap: 6px; }
.chip {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--navy);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--line-dim);
  border-radius: 12px;
  padding: 5px 11px;
  cursor: pointer;
  position: relative; overflow: hidden;
  transition: transform 300ms var(--spring), background 200ms ease-out,
              color 200ms ease-out, box-shadow 200ms ease-out;
}
.chip:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(23,57,92,0.12); }
.chip:active { transform: scale(0.92); }
.chip.active {
  background: linear-gradient(135deg, #F08A5C, var(--accent));
  color: #fff; border-color: transparent;
  animation: pop 380ms var(--spring);
  box-shadow: 0 3px 12px var(--accent-glow);
}

.custom-grid { display: flex; align-items: center; gap: 6px; }
.custom-grid .x { color: var(--navy-3); font-size: 13px; }
.physical-info {
  font-size: 11px; color: var(--navy-2);
  line-height: 1.4;
  max-width: 230px;
}

.setting-value {
  font-size: 12px; font-weight: 700; color: var(--accent);
  min-width: 22px; text-align: center;
  display: inline-block;
}
.setting-value.bump { animation: bump 380ms var(--spring); }
@keyframes bump {
  0% { transform: scale(1.45); color: #fff; text-shadow: 0 0 12px var(--accent-glow); }
  100% { transform: scale(1); }
}

/* ---- 选项胶囊（竖排：名称 + 开关） ---- */
.opts-group { flex: 1; min-width: 0; }
.opts-row { display: flex; gap: 8px; flex-wrap: wrap; }
.opt-pill {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line-dim);
  border-radius: 16px;
  padding: 7px 10px 8px;
  cursor: pointer;
  user-select: none;
  transition: transform 300ms var(--spring), box-shadow 200ms ease-out, border-color 200ms ease-out, background 200ms ease-out;
}
.opt-pill:hover { transform: translateY(-2px); box-shadow: 0 5px 16px rgba(23,57,92,0.13); background: rgba(255,255,255,0.72); }
.opt-pill:active { transform: scale(0.95); }
.opt-name { font-size: 12px; font-weight: 600; white-space: nowrap; }
.opt-extra { display: flex; align-items: center; gap: 4px; width: 96px; }
.opt-extra input[type="range"] { height: 18px; }

/* ---- iOS 开关 ---- */
.switch { position: relative; display: inline-block; width: 42px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i {
  position: absolute; inset: 0;
  border-radius: 999px;
  background: rgba(23, 57, 92, 0.2);
  transition: background 250ms ease-out, box-shadow 250ms ease-out;
}
.switch i::after {
  content: "";
  position: absolute; top: 2.5px; left: 2.5px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(23, 57, 92, 0.35);
  transition: transform 320ms var(--spring);
}
.switch input:checked + i {
  background: linear-gradient(135deg, #F08A5C, var(--accent));
  box-shadow: 0 0 12px var(--accent-glow);
}
.switch input:checked + i::after { transform: translateX(17px); }
.switch:active i::after { width: 23px; }

/* ============ 导出弹窗 ============ */
.modal-backdrop {
  position: fixed; inset: 0;
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 40, 68, 0.35);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  animation: fadeIn 250ms ease-out both;
}
.modal-panel {
  width: min(480px, calc(100vw - 40px));
  border-radius: 28px;
  padding: 26px;
  background: rgba(255, 255, 255, 0.82);
  animation: modalIn 480ms var(--spring) both;
}
@keyframes modalIn {
  0% { transform: translateY(26px) scale(0.92); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.modal-row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.seg {
  display: inline-flex;
  background: rgba(23, 57, 92, 0.08);
  border-radius: 14px;
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--navy-2);
  background: transparent;
  border: none; border-radius: 11px;
  padding: 7px 14px;
  cursor: pointer;
  position: relative; overflow: hidden;
  transition: background 200ms ease-out, color 200ms ease-out, transform 250ms var(--spring);
}
.seg-btn:active { transform: scale(0.94); }
.seg-btn.active {
  background: #fff; color: var(--navy);
  box-shadow: 0 1px 6px rgba(23, 57, 92, 0.18);
}

/* ============ 拖拽浮层 / Toast ============ */
.drop-overlay {
  position: fixed; inset: 0;
  z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(28, 76, 124, 0.28);
  -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
  animation: fadeIn 200ms ease-out both;
}
.drop-ring {
  width: 220px; height: 220px;
  border-radius: 50%;
  border: 3px dashed rgba(255, 255, 255, 0.9);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px; font-weight: 700;
  text-shadow: 0 1px 8px rgba(23, 57, 92, 0.5);
  background: rgba(255, 255, 255, 0.12);
  animation: ringPulse 1.6s ease-in-out infinite;
}
@keyframes ringPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,0.35); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 26px rgba(255,255,255,0); }
}

.toast {
  position: fixed; left: 50%; bottom: 120px;
  transform: translateX(-50%) translateY(16px);
  z-index: 70;
  font-size: 14px; font-weight: 600; color: #fff;
  background: rgba(23, 57, 92, 0.78);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 18px;
  padding: 10px 22px;
  opacity: 0;
  transition: opacity 240ms ease-out, transform 380ms var(--spring);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 通用入场动画 ============ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: none; }
}
@keyframes riseIn {
  0% { transform: translateY(30px) scale(0.97); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

/* ============ 手机 / 窄屏适配（含微信浏览器） ============
   策略：页面改为纵向自然滚动；顶栏吸顶压缩；画布固定视口比例高度；
   dock 设置组纵向堆叠；弹窗限高内滚。dvh 均带 vh 回退（兼容旧 X5 内核）。 */
@media (max-width: 768px) {
  html, body { height: auto; }
  body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  /* ---- 顶栏：吸顶 + 压缩，控件不换行 ---- */
  .topbar {
    position: sticky; top: 0;
    height: auto; min-height: 52px;
    padding: 8px 12px;
  }
  .topbar-title { font-size: 15px; gap: 8px; }
  .topbar-title .logo-img { width: 26px; height: 26px; }
  .ctl-label {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .topbar-controls { gap: 8px; }
  .glass-select { padding: 5px 10px; font-size: 13px; }
  .btn-sm { padding: 6px 11px; font-size: 13px; }

  /* ---- 首页英雄区 ---- */
  .home { padding: 20px 14px; }
  .hero-card { padding: 34px 22px; gap: 14px; border-radius: 24px; }
  .large-title { font-size: 26px; }
  .subtitle { font-size: 14px; }
  .hero-card .btn-cta { font-size: 16px; padding: 12px 26px; }

  /* ---- 工作台：纵向滚动堆叠 ---- */
  .workbench {
    padding: 10px 10px calc(18px + env(safe-area-inset-bottom));
    gap: 10px;
  }
  .card { padding: 12px; border-radius: 20px; }
  .canvas-card { flex: none; }
  .canvas-area { flex: none; height: 52vh; height: 52dvh; min-height: 300px; }

  /* ---- 材料统计 ---- */
  .bom-head { flex-wrap: wrap; gap: 8px; }
  .bom-hint { display: none; }
  .bom-list { max-height: 88px; }

  /* ---- 底部控制栏 ---- */
  .dock { flex: none; padding: 12px; border-radius: 20px; }
  .dock-settings { flex-direction: column; align-items: stretch; }
  .dock-sep { display: none; }
  .dock-group { min-width: 0; }
  .opts-group { flex: none; }
  .opts-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .opt-extra { width: auto; flex: 1; }
  .physical-info { max-width: none; }

  /* ---- 弹窗 / Toast ---- */
  .modal-panel {
    width: calc(100vw - 24px);
    padding: 20px;
    max-height: 82vh; max-height: 82dvh;
    overflow: auto;
  }
  .toast { bottom: 90px; max-width: calc(100vw - 48px); text-align: center; }
}

/* 触屏设备：裁剪提示改为手指操作说明 */
.hint-touch { display: none; }
@media (pointer: coarse) {
  .hint-wheel { display: none; }
  .hint-touch { display: inline; }
}

/* ============ 降低动态偏好 ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
