* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
  background: #111;
}
#map {
  position: absolute;
  inset: 0 360px 0 0;
  z-index: 1;
}
.overlay-host {
  position: absolute;
  inset: 0 360px 0 0;
  z-index: 450;
  pointer-events: none;
  overflow: hidden;
}
.overlay-host.is-selected {
  pointer-events: none; /* 仅盒子本身可点 */
}
.overlay-box {
  position: absolute;
  pointer-events: none;
  transform-origin: center center;
  will-change: transform, left, top, width, height;
}
.overlay-host.is-selected .overlay-box {
  pointer-events: auto;
  cursor: move;
  outline: 2px solid #0d6efd;
  outline-offset: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8);
}
.overlay-box img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.overlay-box .handle {
  display: none;
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid #0d6efd;
  border-radius: 2px;
  z-index: 2;
  pointer-events: auto;
}
.overlay-host.is-selected .handle {
  display: block;
}
.handle.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.handle.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.handle.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.handle.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.handle.rot {
  left: 50%;
  top: -28px;
  margin-left: -7px;
  border-radius: 50%;
  cursor: grab;
  background: #ffc107;
  border-color: #e0a800;
}
.handle.rot::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 12px;
  width: 1px;
  height: 10px;
  background: #0d6efd;
  transform: translateX(-50%);
}

#sidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: 360px;
  height: 100%;
  z-index: 500;
  background: #f7f9fc;
  border-left: 1px solid #d0d7de;
  overflow: auto;
  padding: 14px;
  color: #222;
}
.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.side-head h1 { margin: 0; font-size: 18px; }
.link { color: #0d6efd; font-size: 13px; text-decoration: none; }
.hint, .muted { font-size: 12px; color: #57606a; line-height: 1.45; }
.block {
  margin-top: 14px;
  padding: 12px;
  background: #fff;
  border: 1px solid #e5e9ef;
  border-radius: 8px;
}
.block h2 { margin: 0 0 10px; font-size: 14px; }
label {
  display: block;
  font-size: 12px;
  color: #444;
  margin-bottom: 8px;
}
input[type="number"],
input[type="file"],
select {
  width: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid #ced4da;
  border-radius: 6px;
}
input[type="range"] {
  width: calc(100% - 48px);
  vertical-align: middle;
}
.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn {
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: #0d6efd;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.btn.secondary { background: #6c757d; }
.btn.success { background: #198754; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.on {
  outline: 2px solid #ffc107;
  outline-offset: 1px;
}
.overlay-fine {
  margin: 8px 0 4px;
  padding: 10px;
  background: #f6f8fa;
  border: 1px solid #e5e9ef;
  border-radius: 8px;
}
.fine-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: #333;
}
.nudge-pad {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  max-width: 140px;
  margin: 0 auto 10px;
}
.btn-nudge {
  padding: 8px 0;
  border: 1px solid #ced4da;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}
.btn-nudge:hover { background: #e9f2ff; border-color: #0d6efd; }
.step-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.step-row input[type="number"] {
  width: 72px;
  margin-top: 0;
  text-align: center;
}
.scale-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-mini {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #ced4da;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
}
.btn-mini:hover { background: #e9f2ff; border-color: #0d6efd; }
.building-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow: auto;
}
.building-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  font-size: 12px;
}
.building-list button {
  border: 1px solid #ced4da;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
@media (max-width: 800px) {
  #map { inset: 0 0 45% 0; }
  .overlay-host { inset: 0 0 45% 0; }
  #sidebar {
    top: auto;
    bottom: 0;
    width: 100%;
    height: 45%;
    border-left: none;
    border-top: 1px solid #d0d7de;
  }
}
