/* 指环大师（创） — 深色工作区 + 右侧参数 + 底部预设 */

:root {
  --bg: #0a0a0a;
  --panel: #111111;
  --border: #d8d8d8;
  --text: #f0f0f0;
  --muted: #9a9a9a;
  --accent: #7ec8e3;
  --accent-hover: #9ad7ee;
  --preset-active: #e8d98a;
  --track: #2a2a2a;
  --thumb: #cfcfcf;
  --danger: #e07070;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* 抑制 iPad Scribble：touch-action 不含 auto/manipulation/handwriting */
.no-scribble #panel,
.no-scribble #params {
  touch-action: pan-y;
}

/* 上传：允许系统文件选择手势（iPad，对齐壁厚大师） */
.no-scribble #panel .file-upload-btn,
.no-scribble #panel .file-upload-btn input[type="file"] {
  touch-action: manipulation;
}

.no-scribble .param-row input[type="range"],
.no-scribble .param-row input[type="number"],
.no-scribble .finger-size-input,
.no-scribble .param-step,
.no-scribble .size-system-opt span,
.no-scribble #panel-actions button,
.no-scribble #view-modes button,
.no-scribble .preset-btn {
  touch-action: none;
}

.no-scribble .param-row input[type="number"]:not([readonly]) {
  -webkit-user-select: text;
  user-select: text;
}

#app {
  display: grid;
  grid-template-columns: 1fr 330px;
  grid-template-rows: 1fr 88px;
  width: 100%;
  height: 100%;
}

#viewport-wrap {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  background: #0c0c0c;
  border-right: 1px solid #333;
  border-bottom: 1px solid #333;
  min-width: 0;
  min-height: 0;
}

#lattice-lasso-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
}

#lattice-lasso-layer canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
}

#status {
  position: absolute;
  left: 12px;
  bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
  opacity: 0.85;
  z-index: 2;
}

#profile-diagram {
  position: absolute;
  left: 12px;
  top: 12px;
  width: 168px;
  height: 132px;
  z-index: 2;
  pointer-events: none;
  background: rgba(12, 12, 12, 0.72);
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.profile-diagram-label {
  flex: 0 0 auto;
  padding: 4px 8px 0;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.06em;
  user-select: none;
}

#profile-diagram-svg {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  display: block;
  padding: 4px 8px 8px;
}

#profile-diagram-path {
  fill: none;
  stroke: #c8c8c8;
  stroke-width: 1.4;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

#view-hud {
  position: absolute;
  right: 12px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 3;
  pointer-events: none;
}

#profile-dims {
  flex: 0 0 auto;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 9px 11px;
  background: rgba(10, 10, 10, 0.84);
  border: 1px solid #454545;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.4;
  color: #a8a8a8;
  user-select: none;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

#profile-dims div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

#profile-dims span {
  color: #6a6a6a;
  flex: 0 0 auto;
  font-size: 11px;
}

#profile-dims b {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 13px;
}

#profile-dims b.dim-max {
  color: #e8b84a;
}

#profile-dims b.dim-min {
  color: #5dce7a;
}

#dim-finger {
  color: #ffffff;
  font-size: 13px;
}

#view-modes {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
  pointer-events: auto;
}

#app-brand {
  align-self: center;
  margin-right: 2px;
  color: #c8c8c8;
  font-size: 11px;
  letter-spacing: 0.04em;
  user-select: none;
  white-space: nowrap;
}

#app-version {
  align-self: center;
  margin-right: 4px;
  color: #888;
  font-size: 11px;
  letter-spacing: 0.04em;
  opacity: 0.85;
  user-select: none;
}

#usage-admin-root {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#usage-admin-root[hidden] {
  display: none !important;
}
.usage-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.usage-panel {
  position: relative;
  z-index: 1;
  width: min(720px, calc(100vw - 24px));
  max-height: min(86vh, 900px);
  overflow: auto;
  background: #161616;
  border: 1px solid #444;
  border-radius: 6px;
  color: #ddd;
  padding: 14px 16px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.usage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.usage-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.usage-close {
  border: 0;
  background: transparent;
  color: #aaa;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.usage-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: #999;
  line-height: 1.45;
}
.usage-login-form {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.usage-login-form input {
  flex: 1;
  min-width: 0;
  height: 34px;
  border: 1px solid #555;
  border-radius: 3px;
  background: #0e0e0e;
  color: #eee;
  padding: 0 10px;
}
.usage-err {
  color: #e74c3c;
  font-size: 12px;
  margin: 0;
}
.usage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 13px;
}
.usage-toolbar select {
  margin: 0 4px;
  background: #0e0e0e;
  color: #eee;
  border: 1px solid #555;
  border-radius: 3px;
  height: 28px;
}
.usage-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.usage-card {
  background: #101010;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 8px 6px;
  text-align: center;
}
.usage-card b {
  display: block;
  font-size: 18px;
  color: #f0f0f0;
  margin-bottom: 2px;
}
.usage-card span {
  font-size: 11px;
  color: #888;
}
.usage-dash h3 {
  margin: 14px 0 6px;
  font-size: 13px;
  color: #bbb;
  font-weight: 600;
}
.usage-table-wrap {
  overflow: auto;
  border: 1px solid #333;
  border-radius: 4px;
}
.usage-recent-wrap {
  max-height: 180px;
}
.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.usage-table th,
.usage-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #2a2a2a;
  text-align: left;
  white-space: nowrap;
}
.usage-table th {
  background: #1c1c1c;
  color: #aaa;
  font-weight: 500;
  position: sticky;
  top: 0;
}
.usage-note {
  margin: 10px 0 0;
  font-size: 11px;
  color: #777;
  line-height: 1.4;
}
@media (max-width: 640px) {
  .usage-overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

#view-modes button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 52px;
  height: 48px;
  padding: 4px 2px;
  border: 1px solid #666;
  background: rgba(22, 22, 22, 0.88);
  color: #c8c8c8;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

#view-modes button svg {
  width: 20px;
  height: 20px;
  display: block;
}

#view-modes button span {
  font-size: 10px;
  line-height: 1;
  user-select: none;
}

#view-modes button:hover {
  border-color: #aaa;
  color: #fff;
  background: rgba(40, 40, 40, 0.95);
}

#view-modes button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  color: #666;
}

#view-modes button:disabled:hover {
  border-color: #666;
  color: #666;
  background: rgba(22, 22, 22, 0.88);
}

#view-modes button.active {
  border-color: var(--accent);
  color: #0a1a22;
  background: var(--accent);
}

#view-modes button.active svg {
  color: #0a1a22;
}

#panel {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid #444;
  padding: 10px 14px 12px;
  gap: 6px;
  overflow: hidden;
}

#panel-tabs {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  padding-bottom: 4px;
  border-bottom: 1px solid #333;
}

.panel-tab {
  flex: 1;
  appearance: none;
  border: 1px solid #444;
  background: #1a1a1a;
  color: #aaa;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.panel-tab.active {
  background: #2a4a5a;
  border-color: #4a9bbb;
  color: #e8f4f8;
}

.panel-pane {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.panel-pane.active {
  display: flex;
}

#pane-ring #params,
#params {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}

#pane-ref,
#pane-resize {
  gap: 12px;
  overflow-y: auto;
}

.panel-tab[data-pane="resize"].active {
  background: rgba(126, 200, 160, 0.28);
  border-color: rgba(126, 200, 160, 0.65);
  color: #e8f8ef;
}

.ref-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 4px solid #888;
}

#lattice-section {
  border-left-color: #6eb8e8;
  background: rgba(110, 184, 232, 0.05);
}

#resize-section {
  border-left-color: #7ec8a0;
  background: rgba(126, 200, 160, 0.06);
}

#resize-rotate-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px 0 8px;
  margin: 0 0 4px;
}

#resize-rotate-pad > .btn-rot {
  width: 72px;
}

#resize-rotate-pad .rotate-mid {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
}

#resize-rotate-pad .rotate-mid .btn-rot {
  width: calc(50% - 4px);
  max-width: 88px;
}

#resize-rotate-pad .btn-rot {
  height: 34px;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#resize-rotate-pad .btn-rot-spin .rot-spin-icon {
  width: 20px;
  height: 20px;
  display: block;
  color: #e8e8e8;
}

#resize-rotate-pad .btn-rot-spin:disabled .rot-spin-icon {
  color: #777;
}

#resize-protect-hint {
  margin-top: 2px;
}

.work-mode-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 10px;
}

.work-mode-tab {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #c8c2b8;
  font-size: 13px;
  cursor: pointer;
}

.work-mode-tab.active {
  background: rgba(110, 184, 232, 0.22);
  border-color: rgba(110, 184, 232, 0.55);
  color: #eef6fb;
}

.work-mode-tab[data-work-mode="resize"].active {
  background: rgba(126, 200, 160, 0.22);
  border-color: rgba(126, 200, 160, 0.55);
}

#ref-gizmo-section {
  border-left-color: #c4a574;
  background: rgba(196, 165, 116, 0.06);
}

.ref-tip {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: #9a9488;
}

#resize-size-tip {
  margin: 6px 0 2px;
  padding: 0 2px;
}

#resize-size-block {
  margin-bottom: 2px;
}

/* 改圈手寸行：第三列需放下输入框+▲▼（勿用 ref 默认 2.75em） */
#resize-size-block .finger-size-row {
  grid-template-columns: 3.4em minmax(0, 1fr) 58px;
  column-gap: 6px;
  align-items: center;
}

#resize-size-block .finger-size-row > label {
  width: auto;
  min-width: 0;
  white-space: normal;
  line-height: 1.15;
  font-size: 12px;
}

#resize-size-block .param-number-wrap {
  width: 58px;
  flex-shrink: 0;
}

/* 宽补/强度：与港度同行布局（滑条 + 输入框 + ▲▼） */
#resize-side-comp-wrap .finger-size-row {
  grid-template-columns: 3.4em minmax(0, 1fr) 58px;
  column-gap: 6px;
  align-items: center;
}

#resize-side-comp-wrap .finger-size-row > label {
  width: auto;
  min-width: 0;
  white-space: nowrap;
  line-height: 1.15;
  font-size: 12px;
}

#resize-side-comp-wrap .param-number-wrap {
  width: 58px;
  flex-shrink: 0;
}

.ref-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ref-actions .btn {
  flex: 1;
  min-width: 90px;
}

.ref-actions.ref-actions-stack {
  flex-direction: column;
  flex-wrap: nowrap;
}

.ref-actions .resize-import-full {
  flex: 1 1 100%;
  width: 100%;
  min-width: 0;
  height: 36px;
  min-height: 36px;
  box-sizing: border-box;
}

#resize-edit-row {
  margin-top: 8px;
}

#resize-edit-row .btn {
  height: 36px;
  min-height: 36px;
  box-sizing: border-box;
}

/* label 作上传按钮时与同排 .btn 等高 */
.ref-actions .file-upload-btn.btn {
  height: 36px;
  min-height: 36px;
  padding: 0 18px;
  box-sizing: border-box;
}

.ref-actions .btn.is-active {
  border-color: #3ec7d8;
  color: #8fe8f2;
  box-shadow: inset 0 0 0 1px rgba(62, 199, 216, 0.35);
}

/* iPad：文件选择须由手指直接点在 input 上，不能 JS 间接 click */
.file-upload-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin: 0;
  -webkit-user-select: none;
  user-select: none;
  box-sizing: border-box;
}

.file-upload-btn input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.01;
  cursor: pointer;
  font-size: 16px;
  z-index: 2;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.file-upload-btn.is-disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

.file-upload-btn.is-disabled input[type="file"] {
  pointer-events: none;
}

.ref-reset-row .btn {
  min-width: 0;
  font-size: 11px;
  padding: 7px 4px;
}

.ref-info {
  font-size: 12px;
  color: #c8c4bc;
  word-break: break-all;
}

.ref-gizmo-params {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0 0 10px;
  padding: 0;
  border: none;
  background: transparent;
}

.ref-gizmo-params .param-row {
  grid-template-columns: 5.5em 1fr 2.75em;
  column-gap: 8px;
  align-items: center;
}

.ref-gizmo-params .param-row.has-reset {
  grid-template-columns: 5.5em 1fr 2.4em 1.5em;
}

.ref-gizmo-params .param-row label {
  width: 5.5em;
  min-width: 5.5em;
  text-align: left;
  white-space: nowrap;
}

.ref-gizmo-params .param-row input[type="range"] {
  width: 100%;
  min-width: 0;
}

.ref-slider-val {
  font-size: 11px;
  color: #aaa;
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-width: 2.4em;
}

.param-slider-reset {
  width: 1.5em;
  height: 1.5em;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #9a9a9a;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.param-slider-reset:hover:not(:disabled) {
  color: #e8e8e8;
  background: rgba(255, 255, 255, 0.08);
}

.param-slider-reset:disabled {
  opacity: 0.35;
  cursor: default;
}

/* 侧补等双极滑块：0 点按导入手寸偏移（--bipolar-zero） */
.ref-gizmo-params .param-row.bipolar {
  position: relative;
}
.ref-gizmo-params .param-row.bipolar input[type="range"] {
  position: relative;
  z-index: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45))
      var(--bipolar-zero, 50%) / 1px 10px no-repeat;
}

.ref-switch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
  row-gap: 10px;
  margin: 0 0 12px;
  align-items: center;
}

.ref-switch-grid .switch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.ref-switch-grid .switch-item > label:first-child {
  color: #ccc;
  font-size: 12px;
  white-space: nowrap;
  user-select: none;
}

.lattice-tool-btns {
  display: flex;
  flex-direction: row;
  gap: 8px;
  margin: 0 0 12px;
}

.lattice-tool-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  appearance: none;
  border: 1px solid #555;
  background: #1a1a1a;
  color: #c8c8c8;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  /* 勿过渡 color：active 时文字变深、背景仍暗的一帧会让图标“闪没” */
  transition: background 0.12s ease, border-color 0.12s ease;
}

.lattice-tool-btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: block;
  color: #d0d0d0;
}

.lattice-tool-btn span {
  font-size: 13px;
  line-height: 1;
  user-select: none;
}

.lattice-tool-btn:hover:not(:disabled) {
  border-color: #888;
  color: #fff;
  background: #242424;
}

.lattice-tool-btn:hover:not(:disabled) svg {
  color: #fff;
}

.lattice-tool-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* :hover 选择器权重更高，须显式覆盖，否则点按后仍悬停时看不到激活色 */
.lattice-tool-btn.active,
.lattice-tool-btn.active:hover:not(:disabled) {
  border-color: var(--accent, #6eb8e8);
  color: #0a1a22;
  background: var(--accent, #6eb8e8);
}

.lattice-tool-btn.active svg,
.lattice-tool-btn.active:hover:not(:disabled) svg {
  color: #0a1a22;
}

.lattice-sym-row {
  margin: 0 0 12px;
}

.lattice-hist-row {
  margin: 0 0 8px;
}

.lattice-hist-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.lattice-hist-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
  overflow: visible;
}

.lattice-hist-btn span {
  line-height: 1;
}

#ref-import-row {
  margin: 0 0 12px;
}

.ref-gizmo-controls.is-disabled,
.ref-gizmo-params.is-disabled,
#lattice-controls-body.is-disabled,
#lattice-bspline-item.is-disabled {
  opacity: 0.42;
  pointer-events: none;
  user-select: none;
}

#lattice-controls-body.is-disabled input,
#lattice-controls-body.is-disabled button,
#lattice-bspline-item.is-disabled input {
  pointer-events: none;
}

.lattice-sym-btn {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.lattice-sym-btn.lattice-sym-x {
  color: #e74c3c;
  border-color: #7a3a36;
}

.lattice-sym-btn.lattice-sym-y {
  color: #2ecc71;
  border-color: #2f6b48;
}

.lattice-sym-btn.lattice-sym-z {
  color: #4aa3e8;
  border-color: #2f5f86;
}

.lattice-sym-btn.lattice-sym-x:hover:not(:disabled) {
  border-color: #e74c3c;
  background: rgba(231, 76, 60, 0.12);
}

.lattice-sym-btn.lattice-sym-y:hover:not(:disabled) {
  border-color: #2ecc71;
  background: rgba(46, 204, 113, 0.12);
}

.lattice-sym-btn.lattice-sym-z:hover:not(:disabled) {
  border-color: #4aa3e8;
  background: rgba(74, 163, 232, 0.12);
}

.lattice-sym-btn.lattice-sym-x.active {
  color: #fff;
  background: #c0392b;
  border-color: #e74c3c;
}

.lattice-sym-btn.lattice-sym-y.active {
  color: #fff;
  background: #27ae60;
  border-color: #2ecc71;
}

.lattice-sym-btn.lattice-sym-z.active {
  color: #fff;
  background: #2980b9;
  border-color: #4aa3e8;
}

.lattice-sym-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  cursor: pointer;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 999px;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.switch-slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #d0d0d0;
  border: 1px solid #888;
  transition: transform 0.18s ease, background 0.18s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.switch input:checked + .switch-slider {
  background: #6eb8e8;
  border-color: #6eb8e8;
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
  background: #f2f2f2;
  border-color: #f2f2f2;
}

.switch input:disabled + .switch-slider {
  opacity: 0.45;
  cursor: not-allowed;
}

.switch:has(input:disabled) {
  cursor: not-allowed;
}

.switch input:focus-visible + .switch-slider {
  outline: 1px solid #6eb8e8;
  outline-offset: 2px;
}

.ref-gizmo-modes {
  display: flex;
  gap: 4px;
}

.ref-mode-btn {
  flex: 1;
  appearance: none;
  border: 1px solid #444;
  background: #1a1a1a;
  color: #bbb;
  font-size: 12px;
  padding: 7px 4px;
  border-radius: 4px;
  cursor: pointer;
}

.ref-mode-btn.active {
  background: #3a5a3a;
  border-color: #7d9b76;
  color: #e8f0e6;
}

.ref-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #ccc;
  user-select: none;
}

#params {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}

.param-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 0 8px 8px;
  border-radius: 5px;
  border-left: 4px solid var(--group-accent, #555);
  background: var(--group-bg, rgba(255, 255, 255, 0.03));
}

.param-group.param-hidden {
  display: none;
}

.param-group-title {
  position: sticky;
  top: 0;
  z-index: 2;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--group-accent, #8a8a8a);
  text-transform: none;
  margin: 0 -8px;
  padding: 8px 8px 5px 10px;
  border-bottom: 1px solid var(--group-line, #2a2a2a);
  background: var(--group-sticky, #141414);
  user-select: none;
}

.param-group.group-dirty .param-group-title::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 7px;
  border-radius: 50%;
  background: var(--group-accent, #ccc);
  vertical-align: 1px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.param-group-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.finger-size-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.size-system-radios {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  width: 100%;
  padding: 2px 0;
}

.size-system-opt {
  display: inline-flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  gap: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  min-width: 0;
}

.size-system-opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.size-system-opt span {
  display: block;
  width: 100%;
  padding: 5px 0;
  text-align: center;
  font-size: 12px;
  color: #c8c8c8;
  border: 1px solid #444;
  background: #1a1a1a;
  touch-action: none;
}

.size-system-opt input:checked + span {
  color: #0a1a22;
  background: var(--group-accent, #6eb8d6);
  border-color: var(--group-accent, #6eb8d6);
  font-weight: 700;
}

.finger-size-unit {
  display: block;
  margin-top: 1px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
}

.finger-size-row label {
  line-height: 1.15;
}

.finger-size-input.is-invalid {
  border-color: var(--danger) !important;
  color: #f0a0a0;
}

.finger-size-error {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  padding: 4px 6px;
  font-size: 11px;
  color: #f0a0a0;
  background: rgba(224, 112, 112, 0.12);
  border: 1px solid rgba(224, 112, 112, 0.35);
}

/* 各组色标 */
.param-group[data-group="basic"] {
  --group-accent: #6eb8d6;
  --group-bg: rgba(110, 184, 214, 0.1);
  --group-line: rgba(110, 184, 214, 0.4);
  --group-sticky: #141c22;
  --group-track: rgba(110, 184, 214, 0.22);
}
.param-group[data-group="profile"] {
  --group-accent: #a78bdb;
  --group-bg: rgba(167, 139, 219, 0.1);
  --group-line: rgba(167, 139, 219, 0.4);
  --group-sticky: #1a1624;
  --group-track: rgba(167, 139, 219, 0.22);
}
.param-group[data-group="shoulder"] {
  --group-accent: #d4a35c;
  --group-bg: rgba(212, 163, 92, 0.11);
  --group-line: rgba(212, 163, 92, 0.4);
  --group-sticky: #1f1a14;
  --group-track: rgba(212, 163, 92, 0.22);
}
.param-group[data-group="opening"] {
  --group-accent: #d47a7a;
  --group-bg: rgba(212, 122, 122, 0.11);
  --group-line: rgba(212, 122, 122, 0.4);
  --group-sticky: #1f1515;
  --group-track: rgba(212, 122, 122, 0.22);
}
.param-group[data-group="inner"] {
  --group-accent: #5cb89a;
  --group-bg: rgba(92, 184, 154, 0.11);
  --group-line: rgba(92, 184, 154, 0.4);
  --group-sticky: #141c19;
  --group-track: rgba(92, 184, 154, 0.22);
}
.param-group[data-group="carve"] {
  --group-accent: #7a9fd4;
  --group-bg: rgba(122, 159, 212, 0.11);
  --group-line: rgba(122, 159, 212, 0.4);
  --group-sticky: #141820;
  --group-track: rgba(122, 159, 212, 0.22);
}
.param-group[data-group="other"] {
  --group-accent: #9a9a9a;
  --group-bg: rgba(154, 154, 154, 0.07);
  --group-line: rgba(154, 154, 154, 0.35);
  --group-sticky: #171717;
  --group-track: rgba(154, 154, 154, 0.2);
}

.param-row {
  display: grid;
  grid-template-columns: 72px 1fr 58px;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.param-row.param-hidden {
  display: none;
}

.param-row.param-child {
  margin-left: 4px;
  padding-left: 10px;
  border-left: 2px solid var(--group-line, #444);
  grid-template-columns: 62px 1fr 58px;
}

.param-row.param-child label {
  color: #c4c4c4;
}

.param-row.param-dirty label::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--group-accent, #aaa);
  vertical-align: 1px;
}

.param-row.disabled {
  opacity: 0.35;
  pointer-events: none;
}

.param-row label {
  color: var(--text);
  font-size: 12px;
  white-space: nowrap;
  user-select: none;
}

/* 轨道视觉仍细，整体高度加大便于手指 / Apple Pencil 点按 */
.param-group .param-row input[type="range"],
.ref-gizmo-params .param-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
  border: none;
  outline: none;
  min-width: 0;
  touch-action: none;
  cursor: pointer;
}

.param-group .param-row input[type="range"]::-webkit-slider-runnable-track,
.ref-gizmo-params .param-row input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--group-track, var(--track));
  border-radius: 3px;
  border: 1px solid var(--group-line, #444);
}

.param-group .param-row input[type="range"]::-moz-range-track,
.ref-gizmo-params .param-row input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--group-track, var(--track));
  border-radius: 3px;
  border: 1px solid var(--group-line, #444);
}

.param-group .param-row input[type="range"]::-webkit-slider-thumb,
.ref-gizmo-params .param-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px; /* (18 - 6) / 2 ≈ 居中到 6px 轨道 */
  border-radius: 50%;
  background: var(--group-accent, var(--thumb));
  border: 1px solid #1a1a1a;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
  /* 透明外圈扩大可点区域，视觉仍是圆点 */
  outline: 10px solid transparent;
  cursor: pointer;
}

.param-group .param-row input[type="range"]::-moz-range-thumb,
.ref-gizmo-params .param-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--group-accent, var(--thumb));
  border: 1px solid #1a1a1a;
  cursor: pointer;
}

.param-row input[type="number"],
.param-row .finger-size-input {
  width: 100%;
  height: 28px;
  min-width: 0;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-right: none;
  color: var(--text);
  text-align: center;
  font-size: 12px;
  border-radius: 0;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  /* 隐藏原生上下箭头，改用自定义步进（触控笔可用） */
  -moz-appearance: textfield;
  appearance: textfield;
}

.param-row input[type="number"]::-webkit-outer-spin-button,
.param-row input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.param-row input[type="number"]:focus,
.param-row .finger-size-input:focus {
  border-color: var(--accent);
}

.param-number-wrap {
  display: grid;
  grid-template-columns: 1fr 18px;
  grid-template-rows: 14px 14px;
  width: 58px;
  height: 28px;
  align-items: stretch;
}

.param-number-wrap input[type="number"] {
  grid-column: 1;
  grid-row: 1 / 3;
}

.param-step {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  background: #222;
  color: var(--text);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.param-step-up {
  grid-column: 2;
  grid-row: 1;
  border-bottom: none;
}

.param-step-down {
  grid-column: 2;
  grid-row: 2;
}

.param-step:active,
.param-step:hover {
  background: #333;
  color: var(--accent);
}

.param-row.disabled .param-step {
  pointer-events: none;
}

#panel-actions {
  flex-shrink: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 8px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid #2a2a2a;
}

#btn-reset,
#btn-export {
  flex: 1 1 0;
  min-width: 0;
  height: 40px;
  margin: 0;
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

#btn-reset {
  background: #161616;
  color: #b8b8b8;
  border-color: #3a3a3a;
  font-weight: 500;
}

#btn-reset:hover {
  background: #222;
  border-color: #666;
  color: #eee;
}

#btn-export {
  border-color: #6eb4cc;
  background: var(--accent);
  color: #0a1a22;
  font-weight: 700;
  letter-spacing: 0.06em;
}

#panel-actions.export-only #btn-export {
  flex: 1 1 100%;
}

#btn-export:hover:not(:disabled) {
  background: var(--accent-hover);
}

#btn-export:disabled {
  opacity: 0.55;
  cursor: wait;
}

#presets-bar {
  grid-column: 1;
  grid-row: 2;
  background: #0d0d0d;
  border-top: 1px solid #333;
  display: flex;
  align-items: center;
  padding: 0 10px;
  overflow: hidden;
  gap: 12px;
}

#presets {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 8px 0;
}

.preset-btn {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  background: #141414;
  border: 1px solid #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.preset-btn:hover {
  border-color: #ccc;
  background: #1c1c1c;
}

.preset-btn.active {
  background: var(--preset-active);
  border-color: #c4b56a;
}

.preset-btn.active svg {
  stroke: #222;
}

.preset-btn svg {
  width: 100%;
  height: 100%;
  stroke: #ddd;
  fill: none;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.preset-btn span.fallback {
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  line-height: 1.2;
}

/* 导出等待提示（对齐排石大师） */
#busy-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 12, 12, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#busy-overlay[hidden] {
  display: none !important;
}

#choice-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 8, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#choice-overlay[hidden] {
  display: none !important;
}


.confirm-card {
  min-width: 320px;
  max-width: min(440px, 92vw);
  padding: 18px 20px 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(22, 22, 22, 0.96);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.confirm-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.confirm-message {
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-line;
  margin-bottom: 16px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.choice-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.choice-options .choice-option {
  width: 100%;
  justify-content: center;
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  min-width: 96px;
  padding: 0 18px;
  border: 1px solid #555;
  border-radius: 2px;
  background: #1a1a1a;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.btn:hover {
  border-color: #888;
  background: #242424;
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #0a1a22;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.confirm-actions .btn {
  min-width: 96px;
  padding: 0 22px;
  height: 36px;
}

.busy-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 28px;
  border: 1px solid #555;
  background: rgba(18, 18, 18, 0.92);
  border-radius: 4px;
  min-width: 200px;
  max-width: min(360px, 88vw);
}

.busy-card.is-progress {
  align-items: stretch;
}

.busy-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #3a3a3a;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: busy-spin 0.75s linear infinite;
  flex-shrink: 0;
  align-self: center;
}

.busy-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.02em;
}

#busy-text {
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.45;
}

.busy-card.is-progress #busy-text {
  color: var(--accent);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.busy-steps {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.busy-steps li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.busy-steps li::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-top: 4px;
  border-radius: 50%;
  border: 1.5px solid #666;
  flex-shrink: 0;
  box-sizing: border-box;
}

.busy-steps li.is-done {
  color: #b8b8b8;
}

.busy-steps li.is-done::before {
  border-color: #6a9e78;
  background: #6a9e78;
}

.busy-steps li.is-active {
  color: var(--text);
  font-weight: 500;
}

.busy-steps li.is-active::before {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(126, 200, 227, 0.18);
}

.busy-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
  line-height: 1.5;
}

@keyframes busy-spin {
  to {
    transform: rotate(360deg);
  }
}

/* 窄屏：参数面板叠在下方 */
@media (max-width: 720px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto auto;
  }

  #viewport-wrap {
    grid-column: 1;
    grid-row: 1;
    border-right: none;
  }

  #presets-bar {
    grid-column: 1;
    grid-row: 2;
  }

  #panel {
    grid-column: 1;
    grid-row: 3;
    max-height: 42vh;
    border-left: none;
    border-top: 1px solid #444;
  }
}
