/* Ghub 物理沙盘 - 极简 / 直角 / 纯色 / 深浅色 */

:root {
  --bg: #ffffff;
  --fg: #000000;
  --line: #000000;
  --muted: #666666;
  --grid: #e2e2e2;
  --cross: #4aa3ff;
  --field: #4aa3ff;
  --vec-vel: #1a9c4a;
  --vec-inertia: #c47f00;
  --vec-force: #d0342c;
  --select: #0090ff;
  --select-soft: rgba(0, 144, 255, 0.08);
  --run: #1a9c4a;
  --pause: #9a9a9a;
  --panel-w: 320px;
}

html[data-theme="dark"] {
  --bg: #000000;
  --fg: #ffffff;
  --line: #ffffff;
  --muted: #999999;
  --grid: #262626;
  --cross: #5aa9ff;
  --field: #6fb8ff;
  --vec-vel: #3ad07f;
  --vec-inertia: #e0a83a;
  --vec-force: #ff6b5e;
  --select: #4aa3ff;
  --select-soft: rgba(74, 163, 255, 0.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "PingFang SC",
    "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

#app { display: flex; width: 100vw; height: 100vh; }

/* ---------- 舞台 ---------- */
#viewport {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  background-color: var(--bg);
  background-image: linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-repeat: repeat;
  border-right: 1px solid var(--line);
  cursor: grab;
  user-select: none;
}
#viewport.panning { cursor: grabbing; }

/* 中心十字线（新建物体落点） */
#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  z-index: 5;
  pointer-events: none;
}
#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: var(--cross);
}
#crosshair::before { left: 50%; top: 0; width: 1px; height: 100%; margin-left: -0.5px; }
#crosshair::after { top: 50%; left: 0; height: 1px; width: 100%; margin-top: -0.5px; }

#vectors { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#vectors line { stroke: var(--fg); stroke-width: 1; vector-effect: non-scaling-stroke; }
#vectors line.vec-vel { stroke: var(--vec-vel); stroke-dasharray: none; }
#vectors line.vec-inertia { stroke: var(--vec-inertia); stroke-dasharray: 6 4; }
#vectors line.vec-force { stroke: var(--vec-force); stroke-dasharray: 2 3; }
#vectors line.vec-drag { stroke: var(--fg); stroke-dasharray: 3 2; }

#trails { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#trails polyline { fill: none; stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }

#history { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#history line { stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }

#flashes { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#flashes circle { fill: none; stroke: var(--select); stroke-width: 1; vector-effect: non-scaling-stroke; }

#bodies { position: absolute; inset: 0; pointer-events: none; }

/* 叠加层：所有标注线/文字都画在 canvas 上 */
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- 物体 ---------- */
.body {
  position: absolute;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.body.selected {
  border-color: var(--select);
  outline: 1px dashed var(--select);
  outline-offset: 3px;
}
.body .point {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 3px;
  background: var(--fg);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.vec-label {
  position: absolute;
  margin: 0;
  white-space: nowrap;
  font-size: 11px;
  color: var(--fg);
  transform: translate(4px, -50%);
  pointer-events: none;
}
.vec-label.vec-vel { color: var(--vec-vel); }
.vec-label.vec-inertia { color: var(--vec-inertia); }
.vec-label.vec-force { color: var(--vec-force); }

/* 选区矩形 */
#selection {
  position: absolute;
  z-index: 15;
  border: 1px dashed var(--select);
  background: var(--select-soft);
  pointer-events: none;
}

/* ---------- tooltip ---------- */
#tooltip {
  position: absolute;
  z-index: 20;
  min-width: 220px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
#tooltip .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  border-bottom: 1px dotted var(--line);
  cursor: text;
}
#tooltip .row:last-child { border-bottom: none; }
#tooltip .row .k { color: var(--muted); }
#tooltip .row .v { text-align: right; }
#tooltip .row input {
  width: 120px;
  padding: 1px 4px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  text-align: right;
}
#tooltip .title {
  padding-bottom: 4px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
#tooltip .tooltip-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
}
#tooltip .tooltip-actions .confirm-text { margin-right: auto; color: var(--muted); }
#tooltip .danger-link,
#tooltip .link {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}
#tooltip .danger-link { color: var(--vec-force); }
#tooltip .link { color: var(--muted); }

/* ---------- 控制面板 ---------- */
#panel {
  flex: 0 0 var(--panel-w);
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg);
}

.panel-head {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.brand { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: 1px; }

/* 功能分界线 */
.divider { flex: none; height: 1px; background: var(--line); margin: 2px 0; }

/* 批量面板（选区存在时） */
#batch-panel { display: flex; flex-direction: column; gap: 8px; }
#batch-panel .field { margin-bottom: 0; }
.batch-head { color: var(--select); }
.hint { color: var(--muted); }
.section-title { color: var(--muted); font-size: 11px; letter-spacing: 1px; }

.btn {
  appearance: none;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.btn:hover { background: var(--fg); color: var(--bg); }

.btn-run { background: var(--run); border-color: var(--run); color: #ffffff; }
.btn-run:hover { background: var(--run); color: #ffffff; }
.btn-paused { background: var(--pause); border-color: var(--pause); color: #ffffff; }
.btn-paused:hover { background: var(--pause); color: #ffffff; }
.btn-active { background: var(--fg); color: var(--bg); }
.btn-active:hover { background: var(--fg); color: var(--bg); }

.collapse { display: flex; flex-direction: column; gap: 8px; }
.collapse-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
}
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--fg); margin: 0; }

.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.preset-grid .btn { text-align: center; padding: 6px 4px; }

.speed-row { display: flex; align-items: center; gap: 8px; }
.speed-label { color: var(--muted); white-space: nowrap; }
.speed-row input[type="range"] { flex: 1 1 auto; min-width: 0; accent-color: var(--fg); margin: 0; }
.speed-value { min-width: 46px; text-align: right; }

.drag-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.drag-tabs .tab {
  flex: 1 1 auto;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  text-align: center;
  cursor: pointer;
}
.drag-tabs .tab:hover { background: var(--fg); color: var(--bg); }
.drag-tabs .tab.active { background: var(--fg); color: var(--bg); }

.panel-foot { margin-top: auto; display: flex; justify-content: flex-end; }
.panel-foot .btn { width: auto; }

.io-row { display: flex; gap: 8px; }
.io-row .btn { flex: 1 1 0; text-align: center; }

.hidden { display: none !important; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.modal-box {
  width: 300px;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
.modal-box h2 { margin: 0 0 12px; font-size: 14px; }
.modal-box p { margin: 0 0 8px; color: var(--muted); }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.field span { color: var(--muted); }
.field input {
  width: 150px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  text-align: right;
}
.field select {
  width: 150px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  text-align: right;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-actions .btn { width: auto; }
