/* ============ 基础 ============ */
* { box-sizing: border-box; }
html, body { height: 100%; }
:root {
  --panel-bg: rgba(255, 255, 255, 0.9);
  --panel-border: #d3dbe6;
  --text: #1f2937;
  --text-soft: #64748b;
  --accent: #2563eb;
  --pill-bg: #eef2f7;
}
body {
  margin: 0;
  display: flex;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(191, 219, 254, 0.55), transparent 50%),
    radial-gradient(ellipse 60% 50% at 100% 50%, rgba(224, 231, 255, 0.4), transparent 45%),
    linear-gradient(165deg, #f1f5f9 0%, #e2e8f0 48%, #cbd5e1 100%);
  font-family: "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  font-size: 13px;
}

/* ============ 左右面板 ============ */
.panel {
  width: 300px;
  flex: 0 0 300px;
  background: var(--panel-bg);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  transition: margin 0.25s ease;
  position: relative;
  z-index: 5;
  max-height: 100vh;
}
.panel--left  { border-right: 1px solid var(--panel-border); }
.panel--right { border-left: 1px solid var(--panel-border); }
.panel--left.collapsed  { margin-left: -300px; }
.panel--right.collapsed { margin-right: -300px; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 8px;
}
.panel-header h2 { margin: 0; font-size: 15px; }
.panel-body { flex: 1; overflow-y: auto; padding: 0 14px 14px; }
.panel-footer {
  border-top: 1px solid var(--panel-border);
  padding: 10px 14px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}

.btn-icon {
  border: 1px solid var(--panel-border); background: #fff; border-radius: 6px;
  width: 26px; height: 26px; cursor: pointer; font-size: 15px; line-height: 1; color: var(--text-soft);
}
.panel--left.collapsed .btn-collapse-left,
.panel--right.collapsed .btn-collapse-right { display: none; }

/* 收起后的外飘按钮 */
.panel-edge-btn {
  position: absolute; top: 50%; z-index: 6;
  width: 22px; height: 64px; border: 1px solid var(--panel-border);
  background: var(--panel-bg); cursor: pointer; color: var(--text-soft); font-size: 13px;
}
.panel--left .panel-edge-btn { right: -22px; border-radius: 0 8px 8px 0; border-left: none; transform: translateY(-50%); display: none; }
.panel--right .panel-edge-btn { left: -22px; border-radius: 8px 0 0 8px; border-right: none; transform: translateY(-50%); display: none; }
.panel--left.collapsed .panel-edge-btn { display: block; }
.panel--right.collapsed .panel-edge-btn { display: block; }

/* ============ 分组 ============ */
.group { padding: 10px 0; border-bottom: 1px dashed var(--panel-border); }
.group:last-child { border-bottom: none; }
.group-head h3 { margin: 0; font-size: 13px; }
.group-head p { margin: 2px 0 8px; font-size: 12px; color: var(--text-soft); }
.group--disabled { opacity: 0.55; }
.hint { font-size: 12px; color: var(--text-soft); margin: 6px 0; line-height: 1.5; }
.field-label { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; }
.pill {
  background: var(--pill-bg); border-radius: 999px; padding: 2px 10px;
  font-size: 12px; color: var(--text); white-space: nowrap;
}
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
input[type="color"] { width: 42px; height: 26px; border: 1px solid var(--panel-border); border-radius: 6px; padding: 1px; background: #fff; cursor: pointer; }

/* ============ 按钮 ============ */
.btn-primary {
  border: none; background: var(--accent); color: #fff; border-radius: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #9db4e8; cursor: not-allowed; }
.btn-muted { background: #64748b; }
.btn-muted:hover { background: #475569; }
.btn-secondary {
  border: 1px solid var(--panel-border); background: #fff; border-radius: 6px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--text);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-secondary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; margin-bottom: 8px; }
.btn-ghost {
  border: 1px solid var(--panel-border); background: rgba(255,255,255,0.8);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; color: var(--text-soft); font-size: 12px;
}

/* ============ 图层卡片 ============ */
.layer-card {
  display: flex; gap: 10px; align-items: center;
  border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 8px; margin-bottom: 8px; background: #fff; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.layer-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,.18); }
.layer-card.is-empty { border-style: dashed; }
.layer-thumb {
  width: 52px; height: 52px; flex: 0 0 52px; border-radius: 8px;
  background:
    repeating-conic-gradient(#f1f5f9 0 25%, #fff 0 50%) 0 0/12px 12px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.layer-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.layer-thumb .empty-mark { color: #94a3b8; font-size: 11px; }
.layer-card-main { flex: 1; min-width: 0; }
.layer-card-main .name { font-weight: 600; font-size: 13px; }
.layer-card-main .status { font-size: 12px; color: var(--text-soft); }
.layer-card-main .status.is-added { color: #16a34a; }
.layer-card-actions { display: flex; flex-direction: column; gap: 4px; }
.layer-mgmt { display: flex; gap: 8px; margin-top: 2px; }
.layer-mgmt .btn-secondary { flex: 1; }

/* ============ 案例预览（水平滚动） ============ */
.combo-row {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 2px 2px 8px; scrollbar-width: thin;
}
.combo-card {
  flex: 0 0 auto; width: 92px;
  border: 1px solid var(--panel-border); border-radius: 10px;
  background: #fff; cursor: pointer; padding: 6px 4px 7px;
  text-align: center; font: inherit; color: var(--text);
}
.combo-card:hover { border-color: var(--accent); }
.combo-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37, 99, 235, .15); }
.combo-card .cc-thumbs { display: flex; justify-content: center; align-items: center; height: 42px; }
.combo-card .cc-name {
  display: block; font-size: 12px; font-weight: 600; margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.combo-card .cc-layers { display: block; font-size: 10px; color: var(--text-soft); margin-top: 1px; }
.mini-thumb {
  width: 34px; height: 34px; border-radius: 6px; overflow: hidden;
  background: repeating-conic-gradient(#f1f5f9 0 25%, #fff 0 50%) 0 0/9px 9px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--panel-border);
}
.mini-thumb img { max-width: 100%; max-height: 100%; }
.mini-thumb--float { margin-left: -9px; box-shadow: 2px 0 4px rgba(15, 23, 42, .18); }

/* ============ 资源库 ============ */
.resource-list { list-style: none; margin: 4px 0 0; padding: 0; }
.resource-item {
  display: flex; gap: 8px; align-items: center;
  border: 1px solid transparent; border-radius: 8px; padding: 6px; cursor: pointer;
}
.resource-item:hover { background: #fff; border-color: var(--panel-border); }
.resource-item .thumb {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 6px;
  background: repeating-conic-gradient(#f1f5f9 0 25%, #fff 0 50%) 0 0/10px 10px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.resource-item .thumb img { max-width: 100%; max-height: 100%; }
.resource-item .meta { flex: 1; min-width: 0; font-size: 12px; }
.resource-item .meta .rname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.resource-item .meta .rinfo { color: var(--text-soft); font-size: 11px; }
.resource-item .tag { font-size: 10px; color: #64748b; background: var(--pill-bg); border-radius: 4px; padding: 1px 5px; }
.resource-item .tag--builtin { color: #92400e; background: #fef3c7; }

/* ============ 每层参数区 ============ */
.layer-param {
  border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 10px; background: rgba(255,255,255,.65);
}
.layer-param .lp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.layer-param .lp-head .name { font-weight: 600; }
.sub-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.sub-row .ctrl-name { flex: 0 0 58px; font-size: 12px; color: var(--text-soft); }
.sub-row input[type="range"] { flex: 1; }
.sub-row .pill { min-width: 46px; text-align: center; }
.sub-row input[type="color"] { flex: 0 0 42px; }

/* ============ 色板 ============ */
.tint-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.swatch {
  width: 20px; height: 20px; border-radius: 50%; cursor: pointer;
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--panel-border);
}
.swatch--restore {
  background: conic-gradient(#f87171, #fbbf24, #34d399, #60a5fa, #a78bfa, #f87171);
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: #fff; text-shadow: 0 0 2px rgba(0,0,0,.6);
}

/* ============ 灯光圆盘 ============ */
.light-dial-row { display: flex; align-items: center; gap: 14px; padding: 8px 0 4px; }
.light-azimuth {
  position: relative; width: 104px; height: 104px; border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: radial-gradient(circle at 50% 40%, #fff, #e7edf5);
  cursor: pointer; flex: 0 0 104px;
  touch-action: none;
}
.light-hub {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px;
  margin: -3px; border-radius: 50%; background: #94a3b8;
}
.light-knob {
  position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px;
  border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff6d8, #fbbf24 55%, #f59e0b);
  box-shadow: 0 0 8px 2px rgba(251,191,36,.55);
}
.light-auto {
  position: absolute; right: 2px; bottom: 2px; width: 22px; height: 22px;
  border-radius: 50%; border: 1px solid var(--panel-border); background: #fff;
  cursor: pointer; font-size: 12px; color: var(--text-soft); line-height: 1;
}
.light-auto[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* ============ 中央舞台 ============ */
.stage-area { flex: 1; position: relative; display: flex; min-width: 0; }
.stage-scroll { flex: 1; overflow: auto; display: flex; }
.stage-zoom {
  margin: auto; padding: 30px;
  transform: scale(var(--zoom, 1)); transform-origin: center center;
}
.measure-area { position: relative; padding: 26px 0 0 30px; }
.ruler-corner {
  position: absolute; left: 0; top: 0; width: 26px; height: 22px;
  font-size: 10px; color: #64748b; display: flex; align-items: center; justify-content: center;
}
.ruler { position: absolute; }
.ruler-h { top: 0; left: 30px; height: 22px; }
.ruler-v { left: 0; top: 26px; width: 22px; }
.stage-cell { position: relative; }

.size-readout {
  margin-top: 10px; text-align: center; font-size: 13px; color: #475569;
  background: rgba(255,255,255,.7); border: 1px solid var(--panel-border);
  border-radius: 999px; padding: 4px 14px; width: fit-content;
  position: relative; left: 50%; transform: translateX(-50%);
}

/* ============ 直尺 ============ */
.v-measure, .h-measure { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.guide { position: absolute; pointer-events: none; }
.guide--zero .line { background: #9ca3af; }
.guide--drag { pointer-events: auto; cursor: grab; touch-action: none; }
.v-measure .guide { left: 0; right: 0; height: 0; }
.v-measure .guide .stick {
  position: absolute; left: -12px; top: -7px; width: 8px; height: 14px;
  border-radius: 3px; display: block;
}
.v-measure .guide--zero .stick { background: #9ca3af; }
.v-measure .guide--drag .stick { background: #16a34a; }
.v-measure .guide .line { position: absolute; left: 0; right: 0; top: 0; height: 1px; }
.v-measure .guide--drag .line { background: #22c55e; }
.v-measure .guide .label {
  position: absolute; left: calc(100% + 6px); top: -9px; font-size: 11px;
  background: #fff; border: 1px solid var(--panel-border); border-radius: 4px; padding: 0 4px; white-space: nowrap;
}
.v-measure .guide--drag .label { color: #15803d; border-color: #86efac; }

.h-measure .guide { top: 0; bottom: 0; width: 0; }
.h-measure .guide .stick {
  position: absolute; top: -12px; left: -7px; height: 8px; width: 14px;
  border-radius: 3px; display: block;
}
.h-measure .guide--zero .stick { background: #9ca3af; }
.h-measure .guide--drag .stick { background: #2563eb; }
.h-measure .guide .line { position: absolute; top: 0; bottom: 0; left: 0; width: 1px; }
.h-measure .guide--drag .line { background: #3b82f6; }
.h-measure .guide .label {
  position: absolute; top: calc(100% + 4px); left: -20px; font-size: 11px;
  background: #fff; border: 1px solid var(--panel-border); border-radius: 4px; padding: 0 4px; white-space: nowrap;
}
.h-measure .guide--drag .label { color: #1d4ed8; border-color: #93c5fd; }

/* ============ 3D 徽章 ============ */
.badge-wrapper {
  position: relative;
  perspective: 900px;
  transition: transform 0.35s ease-out;
  cursor: grab;
  touch-action: none;
  overflow: visible;
}
.badge-wrapper:hover { transform: translateY(-6px) scale(1.02); }
.badge-wrapper.dragging { cursor: grabbing; transform: none; }

.badge {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.18s ease-out;
  overflow: visible;
}
.badge-layer {
  position: absolute; inset: 0;
  display: flex; justify-content: center; align-items: center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  pointer-events: none;
  overflow: visible;
}
.layer-scale {
  position: absolute; inset: 0;
  transform-origin: center center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  transition: transform 0.12s ease-out;
  overflow: visible;
}
.badge-layer img.layer-src {
  width: 100%; height: 100%; object-fit: contain;
  transform-origin: center center; user-select: none; -webkit-user-drag: none;
}
.ss-host { position: absolute; inset: 0; pointer-events: none; transform-style: preserve-3d; }
.ss-host canvas {
  position: absolute; left: 50%; top: 50%;
  width: calc(100% * var(--ss-factor, 3)); height: calc(100% * var(--ss-factor, 3));
  transform: translate(-50%, -50%) scale(calc(1 / var(--ss-factor, 3)));
  transform-origin: center center; backface-visibility: hidden; display: block;
}

/* 分析标注层：随素材缩放平移 */
.axis-overlay {
  position: absolute; inset: 0; pointer-events: none;
}
.axis-overlay canvas { width: 100%; height: 100%; display: block; }

/* ============ 悬浮投影 ============ */
.floating-shadow {
  position: absolute; inset: 0;
  display: flex; justify-content: center; align-items: center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  pointer-events: none;
  --ps-color: rgba(83, 86, 90, 0.55);
  --ps-core-blur: 0px;
  --ps-penumbra-blur: 9px;
  --ps-core-opacity: 1;
  --ps-penumbra-opacity: 0;
}
.fs-shape {
  position: absolute; inset: 0;
  background: var(--ps-color);
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-size: contain; mask-size: contain;
  -webkit-mask-mode: alpha; mask-mode: alpha;
  -webkit-mask-position: center; mask-position: center;
}
.fs-component {
  position: absolute; inset: 0;
  transform-origin: center center;
  transition: transform 0.12s ease-out;
  pointer-events: none;
}
.fs-component--core { filter: blur(var(--ps-core-blur)); opacity: var(--ps-core-opacity); }
.fs-component--penumbra { filter: blur(var(--ps-penumbra-blur)); opacity: var(--ps-penumbra-opacity); }

/* ============ 接地投影 ============ */
.badge-glow {
  position: absolute; left: 6%; right: 6%; bottom: -22px; height: 52px;
  background:
    radial-gradient(ellipse 52% 70% at 50% 62%, var(--shadow-core, rgba(83,86,90,.42)) 0%, transparent 62%),
    radial-gradient(ellipse 95% 100% at 50% 55%, var(--shadow-soft, rgba(83,86,90,.18)) 0%, transparent 72%);
  filter: blur(10px);
  transform: translateZ(-60px);
  pointer-events: none;
}

/* ============ 弹窗 ============ */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
}
.overlay[hidden] { display: none; }
.dialog {
  background: #fff; border-radius: 14px; padding: 20px 22px;
  width: min(420px, 92vw); max-height: 86vh; overflow-y: auto;
  box-shadow: 0 24px 60px rgba(15,23,42,.25);
}
.dialog--wide { width: min(760px, 94vw); }
.dialog--tight { width: 300px; text-align: center; }
.dialog-header { position: relative; margin-bottom: 10px; }
.dialog-header h2 { margin: 0 0 6px; font-size: 17px; }
.dialog-header p { margin: 0; color: var(--text-soft); font-size: 13px; }
.dialog-close {
  position: absolute; right: -8px; top: -10px; border: none; background: none;
  font-size: 22px; cursor: pointer; color: var(--text-soft);
}
.dialog-actions {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-top: 14px; flex-wrap: wrap;
}
.notice-list { padding-left: 18px; font-size: 13px; line-height: 1.7; color: #374151; }
.input-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 13px; }
.input-row input {
  flex: 1; border: 1px solid var(--panel-border); border-radius: 8px;
  padding: 7px 10px; font-size: 13px;
}
.mm-inputs { display: flex; gap: 10px; margin-top: 8px; }
.mm-inputs label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-soft); flex: 1; }
.mm-inputs input {
  width: 100%; border: 1px solid var(--panel-border); border-radius: 6px;
  padding: 4px 6px; font-size: 12px;
}

/* ============ 杂项 ============ */
.save-status { width: 100%; font-size: 12px; min-height: 16px; color: var(--text-soft); }
.save-status.is-error { color: #dc2626; }
.save-status .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #f59e0b; margin-right: 5px; vertical-align: 1px;
}
.save-status .dot--saved { background: #16a34a; }

.spinner {
  width: 34px; height: 34px; margin: 4px auto 10px;
  border-radius: 50%; border: 3px solid #e2e8f0; border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.width-tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: #1f2937; color: #fff; font-size: 12px;
  border-radius: 6px; padding: 3px 8px; transform: translate(-50%, -140%);
  white-space: nowrap;
}

.btn-display-mode { position: absolute; right: 14px; top: 12px; z-index: 4; }
.btn-exit-display { position: fixed; right: 14px; top: 12px; z-index: 40; }

/* 展示模式：隐藏面板 */
body.display-mode .panel { display: none; }
body.display-mode .btn-display-mode { display: none; }

/* 未登录：隐藏编辑面板 */
body.needs-auth .panel { display: none; }
body.needs-auth .btn-display-mode { display: none; }
.dialog--tight2 { width: 340px; }

/* 分享链接打开的纯展示模式：只有 3D 主体 */
body.share-mode .panel { display: none; }
body.share-mode .btn-display-mode { display: none; }
body.share-mode .btn-exit-display { display: none !important; }
.tag--srv { color: #1d4ed8; background: #dbeafe; }

/* 响应式 */
@media (max-width: 980px) {
  body { flex-direction: column; overflow: auto; height: auto; }
  .panel { width: 100%; flex: none; max-height: 42vh; }
  .panel--left.collapsed, .panel--right.collapsed { margin: 0; max-height: 44px; overflow: hidden; }
  .stage-area { min-height: 60vh; }
}

/* ============ 资源库弹窗网格 ============ */
.dialog--library { width: min(560px, 92vw); }
.dialog--library .btn-primary { margin: 4px 0 6px; }
.resource-grid {
  list-style: none; margin: 8px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.resource-grid .resource-item {
  display: flex; flex-direction: column; align-items: center;
  border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 6px; cursor: pointer; background: #fff;
}
.resource-grid .resource-item:hover { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37, 99, 235, .12); }
.resource-grid .resource-item .thumb {
  width: 100%; height: 74px; border-radius: 6px;
  background: repeating-conic-gradient(#f1f5f9 0 25%, #fff 0 50%) 0 0/10px 10px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.resource-grid .resource-item .thumb img { max-width: 100%; max-height: 100%; }
.resource-grid .resource-item .meta { width: 100%; font-size: 11px; text-align: center; margin-top: 4px; }
.resource-grid .resource-item .meta .rname {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600;
}
.resource-grid .resource-item .meta .rinfo { color: var(--text-soft); font-size: 10px; }
.resource-grid .resource-item .tag { margin-top: 3px; }
.resource-grid .resource-item .btn-secondary { margin-top: 4px; }
