:root {
  --bg: #fff; --side: #fafaf9; --ink: #1d1d1f; --sub: #86868b; --line: #ebebea; --hover: #f2f2f1; --err: #d93a3a;
  /* 唯一的主色：跟导出图纸底部的颜色一样 */
  --accent: #e8566c; --accent-d: #d43f57; --accent-soft: #fdeef0;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { background: var(--hover); }
button:disabled { opacity: .35; cursor: default; background: none; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-d); }
button.soft { background: var(--hover); }
button.soft:hover { background: #e8e8e7; }
button.big { padding: 10px 22px; font-size: 15px; border-radius: 8px; }
.grow { flex: 1; }

/* 顶栏 */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; height: 52px; padding: 0 20px;
  background: rgba(255,255,255,.86); backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 3px; font-weight: 600; font-size: 15px; text-decoration: none; }
.brand i { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.brand i:nth-child(2) { background: #f2c94c; } .brand i:nth-child(3) { background: #3d7be0; margin-right: 5px; }
.top .tabs { flex: 1; }

/* 两种切换：tabs＝文字分页，seg＝苹果式分段 */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; }
.tabs button { color: var(--sub); }
.tabs button.on { color: var(--accent-d); background: var(--accent-soft); font-weight: 500; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; background: #efefee; border-radius: 8px; }
.seg button { padding: 3px 10px; color: var(--sub); }
.seg button:hover { background: none; color: var(--ink); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 .5px rgba(0,0,0,.06); }

/* 图库 */
body.on-home .make, body:not(.on-home) .home { display: none; }
.home { max-width: 1120px; margin: 0 auto; padding: 24px 20px 40px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 20px; }
.filters input { flex: 0 1 200px; height: 32px; padding: 0 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; background: var(--side); outline: none; }
.filters input:focus { background: #fff; border-color: var(--accent); }
#gSort { margin-left: auto; }
.g-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 20px 16px; }
.g-card { display: flex; flex-direction: column; padding: 0; text-align: left; }
.g-card:hover { background: none; }
.g-thumb { display: grid; place-items: center; aspect-ratio: 1; margin-bottom: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; transition: border-color .15s; }
.g-card:hover .g-thumb { border-color: var(--accent); }
.g-thumb canvas { width: auto; height: auto; max-width: 76%; max-height: 76%; }
.g-card b { font-weight: 500; }
.g-meta, .none { color: var(--sub); font-size: 12px; font-variant-numeric: tabular-nums; }
.credit { margin-top: 40px; color: var(--sub); font-size: 12px; }

/* 制作 */
.make { display: grid; grid-template-columns: 272px 1fr; min-height: calc(100vh - 52px); }
.side { padding: 4px 16px 24px; background: var(--side); border-right: 1px solid var(--line); }
.side .seg { display: flex; flex-wrap: nowrap; }
.side .seg button { flex: 1; padding: 3px 4px; }
.side section, .side details { padding: 12px 0; border-bottom: 1px solid var(--line); }
.side > :last-child { border-bottom: 0; }
.side label { display: flex; justify-content: space-between; margin-bottom: 6px; color: var(--sub); font-size: 12px; }
.side output { color: var(--ink); font-variant-numeric: tabular-nums; }
.side summary { color: var(--sub); font-size: 12px; cursor: pointer; }
.side details[open] summary { margin-bottom: 8px; }
.side .row { display: flex; gap: 6px; margin-top: 8px; }
.ck { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.side .ck { justify-content: flex-start; margin: 4px 0; color: var(--ink); font-size: 14px; }
.ck input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
input[type=range] { width: 100%; margin: 0 0 8px; accent-color: var(--accent); }

.work { min-width: 0; padding: 12px 20px 24px; }
.bar, .legend-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bar { margin-bottom: 12px; }
.stage { position: relative; height: min(70vh, 820px); min-height: 300px; overflow: auto; background: var(--side); border: 1px solid var(--line); border-radius: 10px; touch-action: pan-x pan-y; }
.stage.over { border-color: var(--accent); background: var(--accent-soft); }
.stage canvas { display: block; margin: 0 auto; cursor: crosshair; }
.stage img { display: block; max-width: 100%; max-height: 100%; margin: 0 auto; }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
#sample { color: var(--sub); }
.status { height: 28px; line-height: 28px; color: var(--sub); font-size: 12px; font-variant-numeric: tabular-nums; }
#total { font-variant-numeric: tabular-nums; }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 2px; max-height: 260px; margin-top: 8px; overflow: auto; }
.legend button { display: flex; align-items: center; gap: 8px; padding: 4px 8px; text-align: left; }
.legend i { flex: none; width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.legend b { font-weight: 500; }
.legend span { margin-left: auto; color: var(--sub); font-variant-numeric: tabular-nums; }
.legend button.on { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; max-width: calc(100% - 32px); transform: translateX(-50%); padding: 8px 16px; background: var(--ink); color: #fff; font-size: 13px; border-radius: 8px; }
.toast.err { background: var(--err); }
.toast.hidden { display: none; }

/* 手机：图纸在上，参数在下 */
@media (max-width: 820px) {
  .top { gap: 8px; padding: 0 12px; }
  .home { padding: 16px 12px 32px; }
  .filters input { flex: 1 1 100%; }
  #gSort { margin-left: 0; }
  .g-grid { grid-template-columns: repeat(2, 1fr); gap: 16px 12px; }
  .make { display: flex; flex-direction: column; }
  .work { order: -1; padding: 12px; }
  .side { border-right: 0; border-top: 1px solid var(--line); }
  .stage { height: min(100vw, 62vh); }
}
