:root {
  --bg: #eef1f6;
  --ink: #0f172a;
  --muted: #64748b;
  --line: rgba(15, 23, 42, 0.08);
  --glass: rgba(255, 255, 255, 0.82);
  --accent: #0d9488;
  --accent-ink: #0b7c72;
  --shadow: 0 12px 34px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.04);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", "HarmonyOS Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#view { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

body::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(115% 85% at 52% 42%, rgba(255,255,255,0) 52%, rgba(15, 23, 42, 0.07) 100%);
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: fixed;
  top: 16px; left: 16px; right: 16px;
  display: flex; align-items: center; gap: 20px;
  padding: 12px 18px;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 320px; }

.mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #12b3a4, #0d9488 55%, #0b6f66);
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .5px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 6px 14px rgba(13,148,136,.35);
}

.titles h1 { font-size: 15px; margin: 0 0 3px; font-weight: 650; letter-spacing: .2px; }
.titles p { margin: 0; font-size: 11.5px; color: var(--muted); letter-spacing: .2px; }

.modes {
  display: flex; gap: 4px; padding: 4px;
  background: rgba(15, 23, 42, 0.045);
  border-radius: 12px;
  margin: 0 auto;
}
.modes button {
  border: 0; background: transparent; color: #475569;
  padding: 8px 16px; font-size: 13px; font-weight: 550;
  border-radius: 9px; cursor: pointer;
  transition: all .18s ease;
  font-family: inherit;
}
.modes button:hover { color: var(--ink); }
.modes button.active {
  background: #fff; color: var(--accent-ink);
  box-shadow: 0 2px 8px rgba(15,23,42,.10);
}

.state {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 13px; border-radius: 999px;
  background: rgba(13, 148, 136, 0.10);
  color: var(--accent-ink); font-size: 12.5px; font-weight: 600;
  white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,.18); }
.state.busy { background: rgba(245, 158, 11, .14); color: #b45309; }
.state.busy .dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,.18); animation: pulse 1.1s infinite; }
.state.error { background: rgba(239, 68, 68, .12); color: #b91c1c; }
.state.error .dot { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.18); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- 侧栏 ---------- */
.panel {
  position: fixed;
  top: 96px;
  width: 292px;
  max-height: calc(100vh - 432px);
  overflow-y: auto;
  padding: 16px;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 15;
  scrollbar-width: thin;
  scrollbar-color: rgba(100,116,139,.35) transparent;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: rgba(100,116,139,.3); border-radius: 99px; }

.panel-left { left: 16px; }
.panel-right { right: 16px; width: 276px; }
.panel-left { max-height: calc(100vh - 200px); }

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { font-size: 13px; margin: 0; font-weight: 650; letter-spacing: .3px; }
.chip {
  font-size: 11px; font-weight: 700; color: #fff; background: var(--ink);
  padding: 2px 8px; border-radius: 999px; min-width: 22px; text-align: center;
}
.chip.soft { background: rgba(15,23,42,.06); color: var(--muted); font-weight: 600; }

/* 零件列表 */
.obj-list { list-style: none; margin: 0 0 4px; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.obj-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 11px; cursor: pointer;
  border: 1px solid transparent;
  transition: all .16s ease;
}
.obj-list li:hover { background: rgba(15,23,42,.04); }
.obj-list li.active { background: #fff; border-color: rgba(13,148,136,.35); box-shadow: 0 3px 10px rgba(15,23,42,.07); }
.obj-list .dotc { width: 12px; height: 12px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.obj-list .nm { font-size: 12.5px; font-weight: 550; }
.obj-list .meta { margin-left: auto; font-size: 10.5px; color: var(--muted); }
.obj-list li.done { opacity: .45; }
.obj-list li.done .meta { color: var(--accent-ink); font-weight: 600; }

/* 分区 */
.section { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.section h3 { font-size: 11.5px; font-weight: 650; color: var(--muted); margin: 0 0 9px; letter-spacing: .4px; text-transform: uppercase; }

.seg { display: flex; gap: 4px; padding: 3px; background: rgba(15,23,42,.05); border-radius: 10px; margin-bottom: 10px; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 7px 0; border-radius: 8px;
  font-size: 12.5px; font-weight: 600; color: #475569; cursor: pointer; font-family: inherit;
  transition: all .16s ease;
}
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(15,23,42,.09); }

.btn {
  width: 100%; border: 1px solid rgba(15,23,42,.10); background: #fff; color: var(--ink);
  padding: 10px 12px; border-radius: 11px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all .16s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(15,23,42,.10); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(150deg, #12b3a4, #0d9488);
  color: #fff; border-color: transparent;
  box-shadow: 0 8px 18px rgba(13,148,136,.28), inset 0 1px 0 rgba(255,255,255,.28);
}
.btn.ghost { background: rgba(255,255,255,.6); }
.btn + .btn { margin-top: 8px; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row .btn { margin-top: 0; }

/* 关节滑块 */
.sliders { display: flex; flex-direction: column; gap: 9px; }
.slider-row { display: grid; grid-template-columns: 26px 1fr 46px; align-items: center; gap: 8px; }
.slider-row label { font-size: 11px; font-weight: 700; color: var(--muted); }
.slider-row output { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink); text-align: right; font-weight: 600; }
input[type="range"] { -webkit-appearance: none; width: 100%; height: 4px; border-radius: 99px; background: rgba(15,23,42,.12); outline: none; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: pointer;
  box-shadow: 0 1px 4px rgba(15,23,42,.25);
}

.teach-list { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.teach-list div {
  font-size: 11px; color: var(--muted); padding: 6px 9px; border-radius: 8px;
  background: rgba(15,23,42,.035); font-variant-numeric: tabular-nums;
  display: flex; justify-content: space-between;
}

/* 右栏 */
.joints { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.jrow { display: grid; grid-template-columns: 20px 1fr 52px; align-items: center; gap: 8px; }
.jrow span.jn { font-size: 10.5px; font-weight: 700; color: var(--muted); }
.jrow .track { height: 5px; background: rgba(15,23,42,.08); border-radius: 99px; position: relative; overflow: hidden; }
.jrow .fill { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: var(--accent); border-radius: 99px; transition: width .08s linear; }
.jrow b { font-size: 11px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

.block { padding-top: 12px; border-top: 1px solid var(--line); margin-bottom: 12px; }
.block h3 { font-size: 11px; font-weight: 650; color: var(--muted); margin: 0 0 9px; letter-spacing: .3px; }
.block h3 em { font-style: normal; color: #94a3b8; font-weight: 500; margin-left: 4px; }

.tcp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tcp-grid div { background: rgba(15,23,42,.035); border-radius: 8px; padding: 5px 7px; }
.tcp-grid label { display: block; font-size: 9.5px; color: var(--muted); margin-bottom: 1px; }
.tcp-grid b { font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

.grip { display: flex; align-items: center; gap: 10px; }
.grip-bar { flex: 1; height: 6px; background: rgba(15,23,42,.08); border-radius: 99px; overflow: hidden; }
.grip-bar i { display: block; height: 100%; width: 70%; background: linear-gradient(90deg, #12b3a4, #0d9488); border-radius: 99px; transition: width .12s ease; }
.grip span { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.stats div { text-align: center; }
.stats b { display: block; font-size: 17px; font-weight: 650; letter-spacing: -.3px; }
.stats label { font-size: 9.5px; color: var(--muted); }

/* 视角切换 */
.viewbar {
  position: fixed; right: 432px; bottom: 16px; z-index: 15;
  display: flex; flex-direction: column; gap: 4px; padding: 4px;
  background: var(--glass); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.viewbar button {
  border: 0; background: transparent; padding: 7px 12px; font-size: 11.5px; font-weight: 600;
  color: #64748b; border-radius: 8px; cursor: pointer; font-family: inherit; transition: all .15s;
}
.viewbar button.active { background: #fff; color: var(--accent-ink); box-shadow: 0 2px 6px rgba(15,23,42,.08); }
.viewbar button.toggle.on { background: rgba(13,148,136,.13); color: var(--accent-ink); font-weight: 700; }
.vb-sep { height: 1px; background: var(--line); margin: 3px 6px; }

/* ---------- 任务程序面板 ---------- */
.codepanel {
  position: fixed; right: 16px; bottom: 16px; z-index: 18;
  width: 400px; height: 404px;
  display: flex; flex-direction: column;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: height .22s ease;
}
.codepanel.folded { height: 46px; }
.codepanel.folded .cp-body, .codepanel.folded .cp-foot { display: none; }

.cp-head {
  display: flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 10px 0 14px; flex: none;
  border-bottom: 1px solid var(--line);
}
.cp-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(13,148,136,.15); }
.cp-head b { font-size: 12px; font-weight: 650; letter-spacing: .2px; }
.cp-tag {
  flex: none; margin-left: -4px; margin-right: auto;
  font-size: 9px; font-weight: 700; letter-spacing: .6px; color: #0d9488;
  padding: 2px 5px; border-radius: 5px; background: rgba(13,148,136,.12);
}
.cp-btn {
  height: 26px; padding: 0 11px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(15,23,42,.10); background: #fff; color: var(--ink);
  font-size: 11.5px; font-weight: 600; font-family: inherit; transition: all .15s ease;
}
.cp-btn:hover:not(:disabled) { box-shadow: 0 3px 10px rgba(15,23,42,.10); transform: translateY(-1px); }
.cp-btn:disabled { opacity: .45; cursor: not-allowed; }
.cp-btn.primary { background: linear-gradient(150deg, #12b3a4, #0d9488); color: #fff; border-color: transparent; }
.cp-btn.icon { width: 26px; padding: 0; font-size: 12px; }

.cp-body { flex: 1; min-height: 0; position: relative; background: #fafcfe; }
.cp-edit { position: absolute; inset: 0; overflow: hidden; }
.cp-hl, .cp-area {
  position: absolute; margin: 0;
  padding: 24px 12px 10px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10.5px; line-height: 1.55; letter-spacing: .1px;
  white-space: pre; tab-size: 2;
}
/* 高亮层必须随内容增高，否则滚动时会被自身高度裁掉（只显示首屏） */
.cp-hl {
  left: 0; right: 0; top: 0; min-height: 100%;
  pointer-events: none; overflow: visible;
  color: #0f172a; will-change: transform;
}
.cp-area { inset: 0; }
.cp-area {
  background: transparent; color: transparent; caret-color: #0f172a;
  border: 0; outline: 0; resize: none; overflow: auto;
}
.cp-area::selection { background: rgba(13,148,136,.22); color: transparent; }
.cp-area::-webkit-scrollbar { width: 8px; height: 8px; }
.cp-area::-webkit-scrollbar-thumb { background: rgba(100,116,139,.28); border-radius: 99px; }

.tok-key { color: #0f766e; font-weight: 600; }
.tok-num { color: #b45309; }
.tok-cmd { color: #1d4ed8; font-weight: 600; }
.tok-arg { color: #7c3aed; }
.tok-str { color: #15803d; }
.tok-doc { color: #15803d; opacity: .85; }
.tok-kw { color: #7c3aed; font-weight: 600; }
.tok-fn { color: #1d4ed8; }
.tok-cmt { color: #94a3b8; font-style: italic; }

.cp-foot {
  height: 26px; flex: none; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; font-size: 10.5px; color: var(--muted);
  border-top: 1px solid var(--line); background: rgba(255,255,255,.5);
}
#codeTarget { flex: none; max-width: 44%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #475569; font-weight: 600; }
#codeMsg { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-foot .error { color: #b91c1c; font-weight: 600; }
.cp-foot .ok { color: var(--accent-ink); font-weight: 600; }
.cp-foot .dirty { color: #b45309; font-weight: 600; }

/* 日志 */
.logbar {
  position: fixed; left: 16px; bottom: 16px; width: 292px; z-index: 15;
  padding: 12px 14px;
  background: var(--glass); backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.log-head { font-size: 11px; font-weight: 650; color: var(--muted); margin-bottom: 7px; letter-spacing: .4px; }
.logbar ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 96px; overflow: hidden; }
.logbar li { font-size: 11.5px; color: #334155; display: flex; gap: 7px; line-height: 1.35; }
.logbar li time { color: #94a3b8; font-variant-numeric: tabular-nums; flex: none; }
.logbar li.ok { color: var(--accent-ink); }
.logbar li.warn { color: #b45309; }

/* 提示 */
.toast {
  position: fixed; left: 50%; top: 92px; transform: translate(-50%, -12px);
  background: rgba(15,23,42,.9); color: #fff; font-size: 12.5px; font-weight: 550;
  padding: 9px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: all .25s ease; z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hidden { display: none !important; }

/* 载入遮罩 */
.loader {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: radial-gradient(80% 60% at 50% 40%, #f7f9fc, #e6ebf2 100%);
  transition: opacity .45s ease, visibility .45s ease;
}
.loader.hide { opacity: 0; visibility: hidden; }
.loader-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 26px 34px; border-radius: 18px;
  background: rgba(255,255,255,.86); border: 1px solid rgba(15,23,42,.06);
  box-shadow: 0 18px 44px rgba(15,23,42,.10);
}
.loader-card b { font-size: 14px; letter-spacing: .3px; }
.loader-card p { margin: 0; font-size: 12px; color: var(--muted); }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid rgba(13,148,136,.18);
  border-top-color: var(--accent);
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader.error .spinner { display: none; }
.loader.error .loader-card b { color: #b91c1c; }

@media (max-width: 1400px) {
  .codepanel { width: 348px; height: 340px; }
  .viewbar { right: 380px; }
  .panel-right { max-height: calc(100vh - 470px); }
}

@media (max-width: 1180px) {
  .panel-left, .logbar { width: 260px; }
  .panel-right { width: 250px; }
  .brand { min-width: 0; }
  .titles p { display: none; }
  .codepanel { width: 322px; height: 336px; }
  .viewbar { right: 354px; }
}

@media (max-width: 980px) {
  .codepanel { width: 300px; height: 300px; }
  .viewbar { right: 332px; }
}
@media (max-width: 900px) {
  .panel-right { display: none; }
  .modes button { padding: 7px 10px; font-size: 12px; }
  .titles h1 { font-size: 13px; }
}

/* ---------- 急停按钮与状态 ---------- */
.viewbar button.estop {
  background: linear-gradient(180deg, #ef4444, #dc2626);
  color: #fff; border-color: transparent;
  font-weight: 700; letter-spacing: .5px;
  box-shadow: 0 4px 12px rgba(220, 38, 38, .35), inset 0 1px 0 rgba(255,255,255,.25);
}
.viewbar button.estop:hover { filter: brightness(1.06); }
.viewbar button.estop.on {
  background: linear-gradient(180deg, #f59e0b, #d97706);
  box-shadow: 0 4px 12px rgba(217, 119, 6, .35), inset 0 1px 0 rgba(255,255,255,.25);
  animation: estopPulse 1.1s ease-in-out infinite;
}
@keyframes estopPulse { 0%,100% { opacity: 1 } 50% { opacity: .72 } }
.state .dot.estop, .state .dot.estop + * { }
.topbar .state:has(.dot.estop) { color: #b91c1c; }

/* ---------- 实验指导面板 ---------- */
.lab-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 16, 28, .34);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
}
.lab-overlay[hidden] { display: none; }
.lab-card {
  width: min(780px, calc(100vw - 48px));
  max-height: min(86vh, 760px);
  display: flex; flex-direction: column;
  background: #fff; border-radius: 18px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, .28);
  overflow: hidden;
}
.lab-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; }
.lab-head b { font-size: 15px; }
.lab-sub { margin-left: 10px; font-size: 11.5px; color: var(--muted); }
.lab-x { border: 0; background: #f1f5f9; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; color: #475569; }
.lab-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 10px; border-bottom: 1px solid var(--line); }
.lab-tabs button {
  border: 1px solid var(--line); background: #f8fafc; color: #475569;
  padding: 7px 14px; border-radius: 9px; font-size: 12px; cursor: pointer;
}
.lab-tabs button.active { background: #0d9488; border-color: #0d9488; color: #fff; font-weight: 600; }
.lab-body { overflow: auto; padding: 14px 20px 20px; font-size: 12.5px; line-height: 1.72; color: #334155; }
.lab-title { display: flex; align-items: baseline; gap: 10px; }
.lab-title h3 { margin: 2px 0 0; font-size: 15px; color: #0f172a; }
.lab-title span { font-size: 11px; color: var(--muted); }
.lab-title em { margin-left: auto; font-style: normal; font-size: 11.5px; color: #0d9488; font-weight: 700; }
.lab-goal { margin: 6px 0 10px; color: #475569; }
.lab-body h4 { margin: 14px 0 6px; font-size: 12px; letter-spacing: .3px; color: #0f172a; }
.lab-body h4 em { font-style: normal; font-size: 10.5px; color: #0d9488; border: 1px solid #99f6e4; background: #f0fdfa; padding: 1px 6px; border-radius: 6px; margin-left: 6px; }
.lab-body ul, .lab-body ol { margin: 0; padding-left: 20px; }
.lab-body li { margin: 3px 0; }
.lab-body .tips li { color: #475569; }
.lab-checks { list-style: none; padding-left: 0 !important; }
.lab-checks li { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; background: #f8fafc; margin-bottom: 4px; }
.lab-checks li.ok { background: #ecfdf5; color: #0f766e; }
.lab-checks i { font-style: normal; width: 16px; text-align: center; color: #94a3b8; }
.lab-checks li.ok i { color: #0d9488; font-weight: 700; }
.lab-foot { margin: 12px 0 0; font-size: 11px; color: var(--muted); }
.lab-foot code { background: #f1f5f9; padding: 1px 5px; border-radius: 5px; }

/* ---------- 代码面板全屏 ---------- */
.codepanel.full {
  left: 24px; right: 24px; top: 84px; bottom: 24px;
  width: auto; height: auto;
}
.codepanel.full .cp-hl, .codepanel.full .cp-area { font-size: 12.5px; line-height: 1.62; padding: 30px 18px 16px; }
.codepanel.full .cp-btn.icon { transform: rotate(45deg); }

/* ---------- 代码面板跳转 ---------- */
.cp-nav {
  position: absolute; top: 4px; right: 8px; z-index: 3;
  display: flex; gap: 3px;
  background: rgba(255,255,255,.86);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 2px; backdrop-filter: blur(6px);
}
.cp-nav button {
  border: 0; background: transparent; color: #64748b;
  font-size: 10px; padding: 2px 6px; border-radius: 6px; cursor: pointer;
}
.cp-nav button:hover { background: #eef2f7; color: #0f172a; }
