/* ===== DuMing Studio · 积木搭建器 ===== */
:root {
  /* DuMing Studio · 暖夜芒果（对齐 duming.work 深色皮肤） */
  --bg: #17130d;
  --panel: #221b12;
  --panel-2: #33281a;
  --line: rgba(255, 198, 92, .18);
  --text: #fdf4e3;
  --text-dim: rgba(253, 244, 227, .62);
  --accent: #ffc65c;
  --accent-2: #f0ad3a;
  --danger: #ef5a6f;
  --gold-soft: rgba(255, 198, 92, .10);
  --rail-w: 56px;
  --panel-w: 300px;
  --top-h: 44px;
  --status-h: 28px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Open Sans", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg); color: var(--text); font-size: 13px;
  display: flex; flex-direction: column;
}
button { font-family: inherit; }
.hidden { display: none !important; }

/* ===== 顶栏 ===== */
#topbar {
  height: var(--top-h); flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 0 12px;
}
.brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; white-space: nowrap; }
.brand-logo {
  width: 28px; height: 28px; border-radius: 8px; object-fit: contain;
  display: block; flex: 0 0 auto;
}
.brand-name { font-weight: 650; letter-spacing: 1.5px; font-size: 14px; white-space: nowrap; }
.brand { gap: 9px; }
.model-name { color: var(--text-dim); font-size: 12px; margin-left: 6px; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.tbtn {
  background: var(--gold-soft); color: #ffe1a8; border: 1px solid rgba(255,198,92,.30);
  border-radius: 8px; padding: 5px 10px; cursor: pointer; font-size: 12px;
}
.tbtn:hover { background: rgba(255,198,92,.16); border-color: rgba(255,198,92,.45); }
.tbtn:active { background: var(--accent-2); color: #2c2118; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.tgl { display: flex; align-items: center; gap: 5px; color: var(--text-dim); cursor: pointer; user-select: none; }
.tgl input { accent-color: var(--accent); }

/* ===== 工作区：零件库(左) → 工具栏(贴视口) → 视口(占剩余) ===== */
#workspace { flex: 1 1 auto; display: flex; min-height: 0; }

/* 工具栏：贴视口左缘（DOM 中靠前，用 order 排到零件库右侧） */
#toolrail {
  order: 1; width: var(--rail-w); flex: 0 0 auto; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  align-items: center; padding: 10px 0; gap: 6px;
}
.tool {
  width: 38px; height: 38px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--text-dim); font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.tool:hover { background: var(--panel-2); color: var(--text); }
.tool.active { background: var(--accent); color: #2c2118; }
.rail-sep { width: 26px; height: 1px; background: var(--line); margin: 4px 0; }

/* 视口（占剩余空间） */
#viewport { order: 2; flex: 1 1 auto; position: relative; min-width: 0; background: var(--bg); }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hint {
  position: absolute; left: 12px; top: 10px; color: var(--text-dim);
  background: rgba(23,19,13,.72); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 8px; font-size: 12px;
  pointer-events: none;
}
.loading {
  position: absolute; right: 12px; top: 10px; color: #2c2118; background: var(--accent);
  padding: 5px 12px; border-radius: 8px; pointer-events: none;
}

/* 零件库面板：最左 */
#sidepanel {
  order: 0; width: var(--panel-w); flex: 0 0 auto; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; background: transparent; border: none; color: var(--text-dim);
  padding: 10px 0; cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-pane { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.pane-filters { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.pane-filters select, .pane-filters input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 6px 8px; font-size: 12px; outline: none;
}
.pane-filters input::placeholder { color: var(--text-dim); }
.pane-count { padding: 0 10px 6px; color: var(--text-dim); font-size: 11px; }

/* 零件网格：固定双行（每行 2 件），minmax(0,1fr) 自适应面板宽度，绝不产生横向滚动条 */
#part-grid { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 4px 10px 12px;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-content: start; }
.part-cell {
  min-width: 0; box-sizing: border-box;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 4px; cursor: pointer; text-align: center; position: relative;
}
.part-cell .pc-ref, .part-cell .pc-name, .part-cell .pc-set { max-width: 100%; }
.part-cell:hover { border-color: var(--accent); background: #3a2e1d; }
.part-cell img { width: 100%; height: 48px; object-fit: contain; image-rendering: auto; }
.part-cell .pc-ref { font-size: 10px; color: var(--text-dim); margin-top: 2px; }
.part-cell .pc-name {
  font-size: 10px; color: var(--text); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.part-cell .pc-set {
  font-size: 9px; color: var(--accent); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.part-cell.asm::after {
  content: "组"; position: absolute; top: 4px; right: 4px; font-size: 9px;
  background: var(--gold-soft); border: 1px solid rgba(255,198,92,.3); border-radius: 4px; padding: 1px 4px; color: var(--accent);
}
.cell-stl {
  position: absolute; right: 4px; bottom: 4px; font-size: 9px; line-height: 1;
  background: var(--gold-soft); color: var(--accent); border: 1px solid rgba(255,198,92,.3);
  border-radius: 5px; padding: 3px 5px; cursor: pointer;
}
.cell-stl:hover { background: rgba(255,198,92,.22); }

/* 材质 */
#mat-groups { flex: 1 1 auto; overflow-y: auto; padding: 4px 10px 12px; }
.mat-group-title { color: var(--text-dim); font-size: 11px; margin: 8px 0 6px; }
.mat-swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.mat-swatch {
  height: 26px; border-radius: 6px; border: 1px solid rgba(255,255,255,.15); cursor: pointer;
}
.mat-swatch:hover { outline: 2px solid var(--accent); }
.mat-swatch.active { outline: 2px solid var(--accent); }

/* 状态栏 */
#statusbar {
  height: var(--status-h); flex: 0 0 auto; background: var(--panel);
  border-top: 1px solid var(--line); display: flex; align-items: center;
  padding: 0 12px; gap: 18px; color: var(--text-dim); font-size: 12px;
}
.st-right { margin-left: auto; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex;
  align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  width: 460px; max-width: 90vw; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.modal-body { padding: 16px; }
.help-table { width: 100%; border-collapse: collapse; }
.help-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.help-table td:first-child { color: var(--text); width: 45%; }
.help-table td:last-child { color: var(--text-dim); }
.help-note { margin-top: 12px; color: var(--text-dim); font-size: 12px; line-height: 1.6; }

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #5c4b2f; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== 手机 / 窄屏：视口优先 + 底部抽屉面板 =====
   桌面三栏（工具栏56 + 视口弹性 + 面板300）在 <760px 会把视口挤到 56px。
   窄屏改为纵向：顶部横向工具栏 → 全宽视口 → 底部抽屉面板（可收起），保证 3D 主区可用。 */
#panel-toggle { display: none; }

@media (max-width: 760px) {
  :root { --top-h: 42px; --status-h: 26px; }

  /* 顶栏：品牌精简 + 按钮横向滚动，避免溢出裁切 */
  #topbar { gap: 6px; padding: 0 8px; }
  .brand-name { display: none; }
  .model-name { font-size: 11px; margin-left: 0; }
  .top-actions {
    flex: 1 1 auto; min-width: 0; justify-content: flex-end;
    overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .top-actions::-webkit-scrollbar { display: none; }
  .tbtn { flex: 0 0 auto; padding: 6px 9px; min-height: 34px; font-size: 12px; }
  .sep { display: none; }
  .tgl { flex: 0 0 auto; min-height: 34px; }
  #panel-toggle { display: inline-flex; align-items: center; }

  /* 工作区纵向：工具栏横排置顶，视口吃满剩余高度 */
  #workspace { flex-direction: column; }
  #toolrail {
    order: -1; width: 100%; height: auto; flex: 0 0 auto;
    flex-direction: row; justify-content: space-around; align-items: center;
    padding: 6px 8px; gap: 4px;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .tool { width: 40px; height: 40px; flex: 0 0 auto; }
  .rail-sep { width: 1px; height: 24px; margin: 0 2px; }

  /* 视口：全宽主角，触摸不再显示鼠标提示 */
  #viewport { order: 1; flex: 1 1 auto; min-height: 160px; width: 100%; }
  .hint { display: none; }
  .loading { right: 8px; top: 8px; font-size: 11px; }

  /* 面板：底部抽屉，默认展开约 42% 高；收起后视口几乎全屏 */
  #sidepanel {
    order: 2; width: 100%; height: 42vh; flex: 0 0 42vh;
    border-right: none; border-top: 1px solid var(--line);
    transition: height .2s ease, flex-basis .2s ease;
  }
  #sidepanel.sheet-collapsed { height: 0; flex-basis: 0; overflow: hidden; border-top: none; }
  #part-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mat-swatches { grid-template-columns: repeat(8, 1fr); }
  .part-cell img { height: 40px; }

  #statusbar { gap: 10px; font-size: 11px; padding: 0 8px; }
}

/* 矮屏（手机横屏）：抽屉更矮，工具栏更紧凑 */
@media (max-width: 900px) and (max-height: 520px) {
  #sidepanel { height: 50vh; flex-basis: 50vh; }
  #toolrail { padding: 3px 8px; }
  .tool { width: 34px; height: 34px; }
}
