* { margin: 0; padding: 0; box-sizing: border-box; }
/* 锁定页面缩放:禁止双击/双指放大整个 UI(画布自身手势由 #viewer 单独处理) */
* { touch-action: pan-x pan-y; }
#viewer { touch-action: none; }
/* hidden 属性必须能压过组件自身的 display 声明(首页/查看器切换靠它) */
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; overflow: hidden; color: #26303b;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: #f4f6f8; }

.glass {
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(148,158,172,0.28);
  box-shadow: 0 6px 24px rgba(30,40,60,0.10);
}

/* ================= 首页 hub ================= */
#hub {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 20px; background:
    radial-gradient(900px 500px at 85% -10%, rgba(58,110,168,.08), transparent 60%),
    radial-gradient(700px 420px at -10% 110%, rgba(58,110,168,.06), transparent 60%);
}
.hub-card { width: min(560px, 100%); border-radius: 18px; padding: 28px 26px 20px; }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.hub-card h1 { font-size: 19px; }
.hub-card .brand p { color: #7a838f; font-size: 12.5px; margin-top: 2px; }
.logo { position: relative; width: 34px; height: 34px; flex: none; display: block; }
.logo i { position: absolute; inset: 0; border: 2px solid #3a6ea8; border-radius: 5px; }
.logo i:nth-child(1) { transform: translate(6px, 6px); opacity: .25; }
.logo i:nth-child(3) { transform: translate(-6px, -6px); opacity: .5; }

.dropzone {
  border: 1.5px dashed rgba(148,158,172,0.4); border-radius: 12px;
  padding: 36px 16px; text-align: center; color: #8a929d; cursor: pointer;
  transition: all .18s; outline: none; display: block;
}
.dropzone:hover, .dropzone:focus-visible {
  border-color: #3a6ea8; background: rgba(58,110,168,.05); color: #4d5661;
}
.dropzone.over { border-color: #3a6ea8; background: rgba(58,110,168,.09); }
.dz-title { font-size: 15px; color: #3a424c; margin: 10px 0 6px; }
.dz-sub { font-size: 12px; }

.engine { display: flex; align-items: center; gap: 8px; margin-top: 16px;
  font-size: 12.5px; color: #5a636e; }
.engine .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.engine .dot.wait { background: #c9a86a; animation: pulse 1s infinite alternate; }
.engine .dot.ok { background: #6aa86a; animation: none; }
.engine .dot.err { background: #b2342a; animation: none; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }

.progress { margin-top: 16px; }
.progress .bar { height: 6px; border-radius: 3px; overflow: hidden; background: rgba(148,158,172,0.2); }
.progress .bar i { display: block; height: 100%; width: 0; background: #3a6ea8;
  border-radius: 3px; transition: width .2s; }
.progress p { font-size: 12.5px; color: #7a838f; margin-top: 8px; }

.err { margin-top: 12px; padding: 10px 14px; border-radius: 10px; font-size: 13px;
  color: #b2342a; background: rgba(178,52,42,.07); border: 1px solid rgba(178,52,42,.25); }

.tips { margin-top: 18px; border-top: 1px solid rgba(148,158,172,0.2); padding-top: 14px;
  font-size: 12px; color: #8a929d; line-height: 1.8; }

/* ================= 查看器 ================= */
#viewer { position: fixed; inset: 0; cursor: grab; touch-action: none; background: #f4f6f8; }
#viewer:active { cursor: grabbing; }
#viewer canvas { display: block; }

#topleft {
  position: absolute; top: 16px; left: 16px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  z-index: 5; max-width: calc(100vw - 32px);
}
#hud, #selinfo {
  display: flex; flex-direction: column; gap: 5px;
  border-radius: 12px; padding: 9px 16px; pointer-events: none;
  font-size: 12px; color: #4d5661; white-space: nowrap; overflow: hidden;
}
#hud .row1, #hud .row2, #selinfo .row1, #selinfo .row2 { display: flex; align-items: center; gap: 9px; }
#hud .row2, #selinfo .row2 { color: #5a636e; }
#hud .bar { width: 3px; height: 13px; border-radius: 2px; flex: none;
  background: linear-gradient(180deg, #4a7fb5, #3a6ea8); }
#hud .model { font-size: 13px; font-weight: 700; color: #26303b; }
#hud .desc { color: #7a838f; overflow: hidden; text-overflow: ellipsis; }
/* 版本徽标: 一眼确认打开的是哪一份文件(手机更新后常用它判断有没有生效) */
#hud .ver { flex: none; font-size: 10px; font-weight: 700; color: #6d7681; line-height: 1;
  border: 1px solid rgba(120,132,148,0.35); border-radius: 999px; padding: 2px 6px; }
#hud .sep, #selinfo .sep { width: 1px; height: 12px; background: rgba(148,158,172,0.35); flex: none; }
#hud b, #selinfo b { font-weight: 700; color: #26303b; font-variant-numeric: tabular-nums; }
#hud .mass, #selinfo .mass { color: #b2342a; font-weight: 700; font-variant-numeric: tabular-nums; }

/* 窄屏(手机竖屏): 信息行改为可换行, 避免被 nowrap 截断成半个字 */
@media (max-width: 620px) {
  #hud, #selinfo { white-space: normal; }
  #hud .row1, #hud .row2, #selinfo .row1, #selinfo .row2 { flex-wrap: wrap; row-gap: 4px; }
  #hud .row2 .sep, #selinfo .row2 .sep { display: none; }
}

#dens {
  font-family: inherit;
  /* 必须 >=16px:低于它 iOS Safari 聚焦时会自动放大整个页面 */
  font-size: 16px; font-weight: 700; color: #26303b;
  width: 48px; height: 22px; padding: 0 2px 0 6px; text-align: center;
  background: #fff; border: 1px solid rgba(148,158,172,0.45); border-radius: 6px;
  outline: none; pointer-events: auto; cursor: text; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield; appearance: textfield;
}
#dens:focus { border-color: #3a6ea8; box-shadow: 0 0 0 3px rgba(58,110,168,0.15); }
#dens::-webkit-outer-spin-button, #dens::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

#selinfo { display: none; }
#selinfo.show { display: flex; }
#selinfo .dot { width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: #3a6ea8; box-shadow: 0 0 0 3px rgba(58,110,168,0.18); }
#selinfo .model { font-size: 13px; font-weight: 700; color: #2c5d96; }

.btn-new {
  position: absolute; top: 16px; right: 16px; z-index: 6;
  font-family: inherit; font-size: 12.5px; font-weight: 600; color: #3a424c;
  border: 1px solid rgba(148,158,172,0.28); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; transition: all .15s;
}
.btn-new:hover { background: #eef1f5; }

/* ---- 缩放控件(右侧竖排): 触屏双指捏合不精确, 给显式按钮 ---- */
#zoomctl {
  position: fixed; right: 16px; top: 50%; transform: translateY(-50%);
  z-index: 6; display: flex; flex-direction: column; gap: 1px;
  padding: 4px; border-radius: 13px;
}
#zoomctl button {
  width: 38px; height: 38px; border: 0; border-radius: 9px; background: transparent;
  font-family: inherit; font-size: 20px; line-height: 1; font-weight: 600;
  color: #3a424c; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
#zoomctl button:hover { background: rgba(58,110,168,.10); color: #2c5d96; }
#zoomctl button:active { background: rgba(58,110,168,.22); color: #2c5d96; }
#zoomctl button[data-z="fit"] { font-size: 17px; }
#zoomctl button + button { border-top: 1px solid rgba(148,158,172,0.18); border-radius: 0 0 9px 9px; }
#zoomctl button:first-child { border-radius: 9px 9px 0 0; }

@media (max-width: 620px) {
  /* 手机上右侧中部会压住模型, 挪到右下(dock 与 pickbar 之上), 尺寸略收 */
  #zoomctl {
    right: 8px; top: auto;
    bottom: calc(126px + env(safe-area-inset-bottom));
    transform: none;
    padding: 3px; border-radius: 12px;
  }
  #zoomctl button { width: 38px; height: 38px; font-size: 20px; }
}

/* ---- bottom dock ---- */
#dock {
  position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  /* left:50% 会把自动宽度限制在视口一半, 窄屏上按钮被挤到换行 -> 显式用 max-content */
  width: max-content; max-width: calc(100vw - 24px);
  display: flex; gap: 6px; align-items: center; border-radius: 999px; padding: 6px;
  z-index: 10;
}
.dd { position: relative; }

/* 单件视图专用: 一键回装配(只在 .solo-view 下出现) */
#btn-back-asm {
  display: none;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  color: #2c5f9e; background: #e6effb; border: none; border-radius: 999px;
  padding: 8px 16px; white-space: nowrap; flex: none;
}
#btn-back-asm:active { background: #d6e4f8; }
.solo-view #btn-back-asm { display: inline-flex; align-items: center; }
/* 单件视图只有一个零件: 爆炸/自动摆放没有意义, 还会把零件挪走 -> 收起来 */
.solo-view #explode-row,
.solo-view #btn-arrange { display: none; }

/* 点选零件后的浮动操作条(在 dock 上方, 不遮挡模型) */
#pickbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 58px);
  /* 同 #dock: left:50% 会把自动宽度限制在视口一半, 必须显式 max-content */
  width: max-content; max-width: calc(100vw - 24px);
  display: none; align-items: center; gap: 10px;
  padding: 7px 8px 7px 14px; border-radius: 18px;
  font-size: 13px; color: #26303b; z-index: 11;
}
#pickbar.show { display: flex; }
#pickbar .pinfo { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
#pickbar .pn {
  font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 46vw;
}
#pickbar .pd {
  font-size: 10.5px; color: #6b7683; white-space: nowrap;
  font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis;
}
#pickbar button {
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border: none; border-radius: 999px; padding: 7px 13px; flex: none;
}
#pickbar .ps { background: #e6effb; color: #2c5f9e; }
#pickbar .ps:active { background: #d6e4f8; }
#pickbar .ph { background: #fdf2f1; color: #b4402f; }
#pickbar .ph:active { background: #fae3e0; }
#pickbar .pc { background: transparent; color: #7b8590; font-size: 17px; padding: 2px 8px; }
/* 隐藏零件后的轻提示: 落在浮条原位(浮条此时已消失), 不压尺寸标签 */
#toast {
  position: absolute; left: 50%; transform: translate(-50%, 8px);
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 58px);
  width: max-content; max-width: calc(100vw - 32px);
  padding: 8px 14px; border-radius: 12px;
  font-size: 12.5px; color: #26303b; z-index: 12;
  opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
/* 清单里被 3D 点选高亮的行 */
.pp-row.picked { background: #d9e7fa; border-radius: 8px; }
.dd > button {
  font-family: inherit; font-size: 13px; font-weight: 600; color: #3a424c; cursor: pointer;
  display: flex; align-items: center; gap: 5px; white-space: nowrap; flex: none;
  background: transparent; border: none; border-radius: 999px;
  padding: 8px 18px; transition: background 0.15s;
}
.dd > button:hover { background: #eef1f5; }
.dd > button::after {
  content: ""; width: 0; height: 0; margin-left: 3px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid #8a929d; transition: transform 0.15s;
}
.dd-menu {
  position: absolute; bottom: calc(100% + 10px); left: 50%;
  transform: translate(-50%, 8px);
  min-width: 196px; max-width: calc(100vw - 16px); border-radius: 14px; padding: 8px;
  /* 菜单浮在模型上方, 必须有实底否则零件透过菜单, 文字读不清 */
  background: rgba(255,255,255,0.95);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid rgba(148,158,172,0.24);
  box-shadow: 0 8px 28px rgba(30,40,60,0.14);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  z-index: 20;
}
/* 关闭瞬间就断开点击: 淡出动画期间点到菜单会误改勾选/触发选项 */
.dd-menu.open { opacity: 1; visibility: visible; pointer-events: auto; transform: translate(-50%, 0); }
.dd-menu .item {
  font-family: inherit; font-size: 13px; color: #3a424c; cursor: pointer; text-align: left;
  width: 100%; background: transparent; border: none; border-radius: 8px;
  padding: 8px 12px; display: block; transition: all 0.15s;
}
.dd-menu .item:hover { background: #eef1f5; }
.dd-menu .item.on { background: #e9eff8; color: #2c5d96; font-weight: 600; }
.dd-menu .item:disabled { color: #a6aeb8; cursor: default; }
.dd-menu .item:disabled:hover { background: transparent; }
.dd-menu .sep-h { height: 1px; background: rgba(148,158,172,0.22); margin: 6px 4px; }
.m-slider { display: flex; align-items: center; gap: 10px; padding: 8px 12px 6px; }
.m-slider label { font-size: 12px; color: #4d5661; white-space: nowrap; }
#explode {
  flex: 1; min-width: 90px; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, #3a6ea8 var(--fill, 0%), #dde3ea var(--fill, 0%));
  outline: none; cursor: pointer;
}
#explode::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: #fff; border: 2px solid #3a6ea8; box-shadow: 0 1px 4px rgba(30,40,60,0.25);
  cursor: grab;
}
#explode-val { font-size: 12px; font-weight: 700; color: #3a6ea8; min-width: 36px; text-align: right;
  font-variant-numeric: tabular-nums; }

.pp-title { display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; letter-spacing: 1px; color: #8a929d; padding: 4px 12px 7px; }
.pp-title button {
  font-family: inherit; font-size: 11px; letter-spacing: 0; color: #2c5d96; cursor: pointer;
  background: #e9eff8; border: none; border-radius: 6px; padding: 3px 10px; font-weight: 600;
}
.pp-title button:hover { background: #dce6f3; }
/* 零件多时菜单会超出屏幕 -> 限高并滚动 */
#parts-menu-body { max-height: 46vh; overflow-y: auto; overscroll-behavior: contain; }
.pp-row { display: flex; align-items: center; gap: 9px; padding: 6px 12px; border-radius: 8px;
  transition: background 0.15s; }
.pp-row:hover { background: #f3f5f8; }
.pp-row input[type="checkbox"] { width: 15px; height: 15px; accent-color: #3a6ea8; cursor: pointer; flex: none; }
.pp-swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.15); flex: none; }
.pp-name { flex: 1; font-size: 13px; color: #3a424c;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-solo {
  font-family: inherit; font-size: 11px; color: #3a424c; cursor: pointer;
  background: #fff; border: 1px solid rgba(148,158,172,0.45); border-radius: 6px; padding: 2px 9px;
  transition: all 0.15s; flex: none;
}
.pp-solo:hover { background: #eef1f5; border-color: rgba(148,158,172,0.7); }
.pp-row.pp-hidden .pp-name { color: #a9b1bc; text-decoration: line-through; }
.pp-row.pp-hidden .pp-swatch { opacity: 0.3; }

@media (max-width: 560px) {
  #hud .row2 span:not(.sep) { font-size: 11.5px; }
  #dock { padding: 4px; }
  .dd > button { padding: 8px 12px; font-size: 12.5px; }
  .pp-solo { padding: 2px 7px; font-size: 10.5px; }
}
