:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a303c;
  --txt: #e6e9ef;
  --dim: #8b93a3;
  --accent: #5cc8ff;
  --accent2: #7dd3a0;
  --warn: #ffb454;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--txt);
  font: 13px/1.5 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  transition: .12s;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.on { background: #123a4d; border-color: var(--accent); color: var(--accent); }
button.primary { background: #14405a; border-color: #2c7fa8; color: #cfefff; }
button.danger:hover { border-color: #ff6b6b; color: #ff6b6b; }
input[type=text], input[type=number], select {
  background: #10131a; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; width: 100%;
}
input[type=range] { width: 100%; accent-color: var(--accent); }

header {
  height: 46px; flex: 0 0 46px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .5px; }
.brand small { color: var(--dim); font-weight: 400; margin-left: 6px; letter-spacing: 0; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs button { padding: 5px 14px; }
.spacer { flex: 1; }

main {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr) 306px;
}

.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.side.right { border-right: 0; border-left: 1px solid var(--line); }
.side h3 {
  margin: 0; padding: 9px 12px;
  font-size: 12px; font-weight: 600; color: var(--dim);
  letter-spacing: .8px; text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 6px;
}
.side h3 .badge {
  background: #232a36; color: var(--dim); font-size: 10px;
  border-radius: 99px; padding: 1px 7px; letter-spacing: 0;
}
.scroll { overflow-y: auto; flex: 1; min-height: 0; }
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: #2c333f; border-radius: 4px; }

/* ---------- 部件库 ---------- */
.pad { padding: 10px 12px; }
.searchrow { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.slot {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px;
  border-bottom: 1px solid #1c212a;
  cursor: pointer; user-select: none;
}
.slot:hover { background: #1b202a; }
.slot.off { opacity: .42; }
.slot .thumb {
  width: 26px; height: 26px; flex: 0 0 26px;
  border: 1px solid var(--line); border-radius: 4px;
  background: #0d1015 url(data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><rect width="4" height="4" fill="%23222a36"/><rect x="4" y="4" width="4" height="4" fill="%23222a36"/></svg>);
  object-fit: contain; image-rendering: pixelated;
}
.slot .nm { flex: 1; min-width: 0; }
.slot .nm b { font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .nm span { color: var(--dim); font-size: 11px; }
.slot .eye { color: var(--dim); font-size: 11px; padding: 0 2px; }
.slot .eye:hover { color: var(--accent); }
.slot .ops { display: none; gap: 2px; }
.slot:hover .ops { display: flex; }
.slot .ops button { padding: 0 4px; font-size: 11px; line-height: 16px; border-radius: 4px; }
.suitcard {
  margin: 8px 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: var(--panel2);
}
.suitcard img { width: 100%; display: block; aspect-ratio: 4/3; object-fit: cover; object-position: top; image-rendering: pixelated; }
.suitcard .row { display: flex; align-items: center; gap: 6px; padding: 7px 9px; }
.suitcard.on { border-color: var(--accent); box-shadow: 0 0 0 1px #2c7fa8 inset; }

/* ---------- 画布 ---------- */
.stage {
  position: relative; min-width: 0; min-height: 0;
  background:
    linear-gradient(45deg, #12151b 25%, transparent 25%, transparent 75%, #12151b 75%),
    linear-gradient(45deg, #12151b 25%, #0d0f14 25%, #0d0f14 75%, #12151b 75%);
  background-size: 22px 22px;
  background-position: 0 0, 11px 11px;
  overflow: hidden;
}
.stage.solid { background: #0d0f14; }
.stage.white { background: #f4f5f7; }
canvas#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
canvas#cv.drag { cursor: grabbing; }
.hud {
  position: absolute; left: 12px; top: 12px;
  background: rgba(15,17,21,.82); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; color: var(--dim); font-size: 11px; line-height: 1.7;
  pointer-events: none; backdrop-filter: blur(4px);
}
.hud b { color: var(--accent); font-weight: 600; }
.zoombar {
  position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px;
  background: rgba(15,17,21,.85); border: 1px solid var(--line); border-radius: 8px; padding: 4px;
}
.zoombar button { padding: 4px 8px; font-size: 12px; }
.framebar {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 4px; align-items: center;
  background: rgba(15,17,21,.85); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px;
}
.framebar .dot { width: 7px; height: 7px; border-radius: 99px; background: #39414f; }
.framebar .dot.on { background: var(--accent2); }

/* ---------- 右栏控件 ---------- */
.group { border-bottom: 1px solid var(--line); padding: 10px 12px; }
.group > label.h {
  display: block; color: var(--dim); font-size: 11px; letter-spacing: .6px;
  text-transform: uppercase; margin-bottom: 7px;
}
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 7px; }
.row:last-child { margin-bottom: 0; }
.row > .k { color: var(--dim); width: 54px; flex: 0 0 54px; font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.grid4 button { padding: 6px 0; font-size: 11px; }
.chk { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; padding: 3px 0; }
.chk input { accent-color: var(--accent); }
.val { color: var(--accent); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }

/* 存档 */
.saveitem {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-bottom: 1px solid #1c212a; cursor: pointer;
}
.saveitem:hover { background: #1b202a; }
.saveitem .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saveitem .tm { color: var(--dim); font-size: 11px; }
.tip { color: var(--dim); font-size: 11px; line-height: 1.6; }
.tip code { background: #10131a; padding: 1px 5px; border-radius: 4px; color: var(--accent); }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(10px);
  background: #20262f; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 16px; opacity: 0; pointer-events: none; transition: .2s; z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.hidden { display: none !important; }

/* ---------- 窄屏：侧栏收成抽屉 ---------- */
.drawer-btns { display: none; gap: 4px; }
@media (max-width: 1180px) {
  main { grid-template-columns: minmax(0, 1fr); position: relative; }
  .side {
    position: absolute; top: 0; bottom: 0; width: 280px; z-index: 6;
    box-shadow: 0 0 40px rgba(0, 0, 0, .65);
    transition: transform .18s ease;
  }
  .side.left { left: 0; transform: translateX(-102%); }
  .side.right { right: 0; transform: translateX(102%); }
  body.lib-open .side.left { transform: none; }
  body.ctl-open .side.right { transform: none; }
  .drawer-btns { display: flex; }
  header { gap: 6px; padding: 0 8px; overflow: hidden; }
  .brand small { display: none; }
  .tabs { margin-left: 4px; }
  .tabs button { padding: 5px 9px; }
}
@media (max-width: 640px) {
  .brand { display: none; }
  header button:not(.primary) { font-size: 12px; padding: 4px 6px; }
  .side { width: 88vw; }
  .hud { font-size: 10px; padding: 4px 7px; }
}
