/* ============================================================
   指挥机器人送餐 · 电子教具  样式表
   配色参考课本页面：米黄底 + 墨绿标题 + 橙色餐桌圆点
   ============================================================ */

:root {
  --bg: #f2e9d5;
  --panel: #fffdf6;
  --panel-2: #f7f1e1;
  --ink: #2f3a3c;
  --ink-soft: #6b7470;
  --line: #ded2b6;
  --teal: #1c8069;
  --teal-dark: #12594a;
  --gold: #e9b949;
  --orange: #e2953c;
  --blue: #4c86c9;
  --green: #3ea77a;
  --red: #d0563f;
  --hl: #ffe08a;
  --shadow: 0 2px 10px rgba(70, 55, 20, .10);
  --radius: 10px;
  --font: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

/* 全屏时给浏览器留出的黑边也铺上底色 */
:fullscreen { background: var(--bg); }
:-webkit-full-screen { background: var(--bg); }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  font-size: 15px;
}

button { font-family: inherit; color: inherit; cursor: pointer; }
b, strong { font-weight: 600; }

.app {
  --wb-h: 292px;              /* 下方工作台高度，由拉柄拖动写入 */
  position: relative;
  height: 100%;
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr) var(--wb-h);
  gap: 6px;
  padding: 6px;
}
body.wb-collapsed .workbench { display: none; }

/* ---------------- 工作台高度拉柄 ---------------- */
.splitter {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--wb-h) + 4px);
  width: 300px; height: 16px; z-index: 9;
  display: flex; align-items: center; justify-content: center;
  cursor: ns-resize; touch-action: none;
}
.splitter::before {
  content: ''; position: absolute; left: 8px; right: 8px; top: 50%;
  width: auto; height: 2px; margin-top: -1px; border-radius: 1px;
  background: rgba(28, 128, 105, .22); pointer-events: none;
}
.splitter:hover::before { background: rgba(28, 128, 105, .45); }
.split-line { display: none; }
.split-btn {
  position: relative; z-index: 1;
  width: 58px; height: 20px; padding: 0;
  display: grid; place-items: center;
  background: rgba(255, 253, 244, .88);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 1px 5px rgba(70, 55, 20, .18);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  color: var(--teal-dark); cursor: pointer; touch-action: none;
}
.split-btn:hover { background: var(--hl); }
.split-btn svg { width: 13px; height: 13px; }
.split-btn .ico-up { display: none; }
body.wb-collapsed .split-btn .ico-up { display: block; }
body.wb-collapsed .split-btn .ico-down { display: none; }
body.is-resizing, body.is-resizing * { cursor: ns-resize !important; }
body.is-resizing .splitter::before { background: var(--teal); }

/* ---------------- 顶部栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  background: linear-gradient(90deg, var(--teal-dark), var(--teal));
  color: #fffdf4;
  border-radius: var(--radius);
  padding: 0 10px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-ico { width: 22px; height: 22px; flex: none; color: #ffe9a8; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.1; }
.brand-txt strong { font-size: 15px; letter-spacing: .5px; }
.brand-txt span { font-size: 10px; opacity: .8; }

.mode-badge {
  flex: none;
  background: #fffdf4;
  color: var(--teal-dark);
  font-weight: 700;
  font-size: 14px;
  padding: 3px 13px;
  border-radius: 16px;
  box-shadow: inset 0 0 0 2px var(--gold);
}

.hud { display: flex; gap: 8px; font-size: 12px; }
.hud-item { background: rgba(255, 255, 255, .14); padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.hud-item b { font-size: 13px; }

.topbar-right { display: flex; align-items: center; gap: 7px; margin-left: auto; min-width: 0; }
.speed-box { display: flex; align-items: center; gap: 4px; font-size: 12px; flex: none; }
.speed-box select {
  background: #fffdf4; color: var(--ink); border: none; border-radius: 6px;
  padding: 3px 4px; font-size: 12px; font-family: inherit;
}

/* 提示条：从画面内移到顶栏，超出宽度自动省略 */
.hint-bar {
  flex: 0 1 auto; min-width: 0; max-width: 42vw;
  background: rgba(255, 253, 244, .95); color: var(--teal-dark);
  font-size: 12.5px; line-height: 1.35; padding: 5px 11px; border-radius: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hint-bar[hidden] { display: none; }
.hint-bar.warn { background: rgba(208, 86, 63, .95); color: #fff; }

/* 收起工作台后的快捷执行钮 */
.mini-run {
  flex: none; display: flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 11px; border: none; border-radius: 14px;
  background: var(--gold); color: #4a3703; font-size: 13px; font-weight: 700;
  box-shadow: 0 2px 0 #c29422;
}
.mini-run svg { width: 15px; height: 15px; flex: none; }
.mini-run:disabled { opacity: .5; }
.mini-run[hidden] { display: none; }

.icon-btn {
  width: 28px; height: 28px; flex: none; display: grid; place-items: center;
  background: rgba(255, 255, 255, .14); border: none; border-radius: 8px; color: inherit;
}
.icon-btn:hover { background: rgba(255, 255, 255, .28); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------------- 中部舞台 ---------------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 306px;
  gap: 8px;
  min-height: 0;
}

.display {
  position: relative;
  background: #fbf6e9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.display canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.display canvas[hidden] { display: none; }

/* 左上角项目切换：与画面里其余三个常驻浮层同一套毛玻璃口径。
   里面的按钮不能留不透明白底，否则等于在玻璃上贴了张纸，毛玻璃白做 */
.proj-tabs {
  position: absolute; left: 10px; bottom: 10px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 253, 244, .40);
  border: 1px solid rgba(255, 255, 255, .58);
  border-radius: 9px; padding: 5px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px) saturate(1.3);
  -webkit-backdrop-filter: blur(9px) saturate(1.3);
  z-index: 6;
}
.ptab {
  border: none; background: transparent; border-radius: 6px;
  padding: 7px 13px; font-size: 14px;
}
.ptab:hover { background: rgba(226, 211, 178, .55); }
.ptab.active { background: var(--teal); color: #fff; font-weight: 600; }
.ptab-sub { display: flex; gap: 4px; padding-left: 6px; border-left: 1px dashed rgba(120, 105, 70, .34); }
.ptab-sub[hidden] { display: none; }
.ttab {
  border: 1px solid rgba(120, 105, 70, .26); background: rgba(255, 255, 255, .62);
  border-radius: 6px; padding: 6px 10px; font-size: 13px;
}
.ttab:hover { border-color: var(--gold); background: rgba(255, 255, 255, .88); }
.ttab.active { background: var(--gold); border-color: #d19f22; font-weight: 700; }

/* 结果横幅：从左上角滑入，毛玻璃半透，不挡住画面中心的机器人。
   top 留 60px 是为了避开左上角的视图操作条 */
.banner {
  position: absolute; left: 10px; top: 60px;
  min-width: 240px; max-width: min(52%, 440px);
  background: rgba(255, 253, 246, .58);
  border: 1px solid rgba(255, 255, 255, .66);
  border-left: 3px solid var(--teal);
  border-radius: 12px; padding: 9px 34px 9px 13px;
  backdrop-filter: blur(10px) saturate(1.3);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
  box-shadow: 0 4px 18px rgba(60, 45, 10, .16);
  text-align: left;
  z-index: 6;
  animation: slide-in-l .26s ease-out;
}
.banner.fail { border-left-color: var(--red); }
.banner-main { font-size: 17px; font-weight: 700; color: var(--teal-dark); text-shadow: 0 1px 0 rgba(255, 255, 255, .7); }
.banner.fail .banner-main { color: var(--red); }
.banner-sub { margin-top: 3px; font-size: 12px; color: var(--ink-soft); line-height: 1.5; }
.banner-close {
  position: absolute; right: 7px; top: 7px; width: 24px; height: 24px;
  border: none; background: rgba(239, 230, 208, .7); border-radius: 50%; display: grid; place-items: center;
}
.banner-close svg { width: 13px; height: 13px; }
@keyframes slide-in-l { from { transform: translateX(-18px); opacity: 0; } }

/* 逐步执行等操作提示：原来在画面正中央，改成视图操作条同一行的左上位置，同样毛玻璃 */
.toast {
  position: absolute; left: 180px; top: 12px;
  background: rgba(47, 58, 60, .62); color: #fffdf4; font-size: 13px;
  padding: 7px 14px; border-radius: 11px; pointer-events: none;
  border: 1px solid rgba(255, 255, 255, .22);
  backdrop-filter: blur(9px) saturate(1.3);
  -webkit-backdrop-filter: blur(9px) saturate(1.3);
  box-shadow: 0 3px 12px rgba(30, 25, 8, .18);
  max-width: 46%; text-align: left; z-index: 9;
  animation: slide-in-l .2s ease-out;
}
.toast[hidden] { display: none; }

/* ---------------- 代码展示区 ---------------- */
.code-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 14px; font-weight: 700; color: var(--teal-dark);
}
.panel-head em { font-style: normal; font-weight: 400; font-size: 12px; color: var(--ink-soft); }
.panel-head em.drag-hint { display: inline-flex; align-items: center; gap: 4px; }
.panel-head em.drag-hint svg { width: 12px; height: 12px; flex: none; opacity: .8; }

.code-list { overflow: auto; padding: 8px 6px 10px; font-size: 14px; }
.code-empty { color: var(--ink-soft); font-size: 13px; padding: 14px 10px; line-height: 1.7; }
.cline {
  display: flex; gap: 8px; align-items: baseline;
  padding: 3px 8px; border-radius: 6px; line-height: 1.7;
  font-variant-numeric: tabular-nums;
}
.cline .cno { width: 22px; flex: none; text-align: right; color: #b3a888; font-size: 12px; }
.cline .ctxt { white-space: pre-wrap; }
.cline .ctag { color: var(--ink-soft); font-size: 12px; }
.cline.lv1 { padding-left: 24px; }
.cline.lv2 { padding-left: 40px; }
.cline.loophead { color: var(--orange); font-weight: 700; }
.cline.loopend { color: #c2a878; }
.cline.active { background: var(--hl); box-shadow: inset 0 0 0 2px var(--gold); font-weight: 700; }
.cline.done .ctxt { color: #98a08f; }

.view-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 8px; border-top: 1px solid var(--line); background: var(--panel-2);
}
.vtab {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 8px 4px; font-size: 13px;
}
.vtab svg { width: 17px; height: 17px; flex: none; }
.vtab:hover { border-color: var(--teal); color: var(--teal-dark); }
.vtab.active { background: var(--teal); border-color: var(--teal-dark); color: #fff; font-weight: 600; }
.vtab.disabled { opacity: .45; cursor: not-allowed; }

/* ---------------- 底部工作台 ---------------- */
.workbench {
  display: grid;
  grid-template-columns: 274px 300px minmax(0, 1fr) 148px;
  gap: 8px;
  min-height: 0;
}
.workbench > section {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); display: grid; grid-template-rows: auto minmax(0, 1fr);
  min-height: 0; overflow: hidden;
}

/* 任务说明 / 设置 */
.task-body { overflow: auto; padding: 10px 12px; font-size: 13px; line-height: 1.75; }
.task-body h3 { margin: 0 0 6px; font-size: 16px; color: var(--teal-dark); }
.task-body p { margin: 0 0 8px; }
.task-body .route {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  background: #fdf3d8; border: 1px dashed var(--gold); border-radius: 8px; padding: 7px 9px; margin-bottom: 9px;
  font-size: 13px;
}
.task-body .route .rp { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 1px 8px; font-weight: 600; }
.task-body .route .rp.next { background: var(--hl); border-color: var(--gold); }
.task-body .route .arw { color: var(--ink-soft); }
.task-body .note { color: var(--ink-soft); font-size: 12px; background: var(--panel-2); border-left: 3px solid var(--gold); padding: 6px 8px; border-radius: 0 6px 6px 0; }
.task-body .ok { color: var(--teal-dark); font-weight: 700; }
.task-body .bad { color: var(--red); font-weight: 700; }

.form-row { display: flex; align-items: center; gap: 5px; margin-bottom: 8px; flex-wrap: wrap; }
.form-row > label { width: 56px; flex: none; color: var(--ink-soft); white-space: nowrap; }
.form-row .su { font-size: 12px; color: var(--ink-soft); margin-left: 2px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.stepper button { width: 20px; height: 26px; border: none; background: var(--panel-2); font-size: 15px; line-height: 1; }
.stepper button:hover { background: var(--hl); }
.stepper input {
  width: 34px; height: 26px; border: none; text-align: center; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--ink);
}
.stepper input:focus { outline: 2px solid var(--gold); }
.chip-row { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 3px 10px; font-size: 13px; }
.chip.active { background: var(--teal); border-color: var(--teal-dark); color: #fff; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; white-space: nowrap; width: auto !important; }
.tbtn {
  border: none; border-radius: 8px; padding: 8px 12px; font-size: 14px; font-weight: 600;
  background: var(--orange); color: #fff; box-shadow: 0 2px 0 #c2751d;
}
.tbtn:hover { filter: brightness(1.06); }
.tbtn:active { transform: translateY(2px); box-shadow: none; }
.tbtn.teal { background: var(--teal); box-shadow: 0 2px 0 var(--teal-dark); }
.tbtn.plain { background: #efe6d0; color: var(--ink); box-shadow: 0 2px 0 #d8caa6; }
.tbtn:disabled { opacity: .5; cursor: not-allowed; }

/* 积木库 */
.palette-body { overflow: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.pal-group { width: 100%; }
.pal-label { font-size: 11px; color: var(--ink-soft); margin-bottom: 4px; padding-left: 2px; }

/* 积木外观 */
.blk {
  position: relative;
  border-radius: 7px;
  color: #fff;
  font-size: 14px;
  padding: 8px 10px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .22);
  cursor: grab;
  touch-action: none;
  max-width: 100%;
}
.blk:active { cursor: grabbing; }
.blk.move { background: var(--blue); }
.blk.turn { background: var(--green); }
.blk.loop { background: var(--orange); padding-bottom: 6px; display: block; }

.blk .blk-txt { font-weight: 600; letter-spacing: .5px; }
.field {
  border: none; border-radius: 5px; background: rgba(255, 255, 255, .95); color: var(--ink);
  min-width: 34px; padding: 3px 6px; font-size: 14px; font-family: inherit; font-weight: 700;
  text-align: center; cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .12);
}
.field:hover { background: #fff; box-shadow: inset 0 0 0 2px var(--gold); }
.blk .blk-del {
  width: 20px; height: 20px; border: none; border-radius: 50%;
  background: rgba(0, 0, 0, .18); color: #fff; display: grid; place-items: center;
  margin-left: auto; padding: 0;
}
.blk .blk-del svg { width: 11px; height: 11px; }
.blk .blk-del:hover { background: var(--red); }
.blk.loop > .blk-row { display: flex; align-items: center; gap: 6px; }

/* 循环体槽位 */
.slot { min-height: 34px; }
.blk.loop .slot {
  margin: 6px 0 0 0; padding: 6px 8px 6px 10px;
  border-left: 4px solid rgba(255, 255, 255, .55);
  background: rgba(255, 255, 255, .17);
  border-radius: 0 7px 7px 0;
  display: flex; flex-direction: column; gap: 6px;
}
.blk.loop .slot .blk { box-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
.loop-foot { height: 8px; border-bottom: 4px solid var(--orange); border-radius: 0 0 7px 7px; margin-top: 2px; }
.slot-empty { font-size: 12px; color: rgba(255, 255, 255, .85); padding: 4px 2px; }
.slot-root > .slot-empty { color: #b6ab8d; }

/* 编程区 */
.program-scroll { overflow: auto; padding: 12px; }
.slot-root { display: flex; flex-direction: column; gap: 8px; min-height: 100%; align-items: flex-start; }
.slot-root > .blk { width: -webkit-fit-content; width: fit-content; max-width: 100%; }
.pal-group > .blk { width: -webkit-fit-content; width: fit-content; max-width: 100%; }
.blk.is-next { opacity: .35; }
.blk.active { outline: 3px solid #fff2b8; box-shadow: 0 0 0 5px var(--gold), 0 2px 0 rgba(0, 0, 0, .22); }
.blk.loop.active { outline: 3px solid #fff2b8; }
.blk .loop-badge {
  position: absolute; right: 34px; top: 7px; font-size: 11px;
  background: rgba(0, 0, 0, .25); border-radius: 10px; padding: 1px 7px;
  pointer-events: none;
}
.blk .loop-badge[hidden] { display: none; }

.drop-indicator { height: 4px; background: var(--gold); border-radius: 3px; box-shadow: 0 0 6px var(--gold); }
.drop-indicator.bad { background: var(--red); box-shadow: none; }

/* 运行按钮列 */
.run-panel {
  grid-template-rows: none !important;
  align-content: start;
  gap: 8px;
  padding: 8px;
  display: grid !important;
  grid-template-columns: 1fr;
  overflow: auto;
}
.rbtn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border: none; border-radius: 9px; padding: 11px 6px; font-size: 14px; font-weight: 700;
  color: #fff; background: #8b9a86;
}
.rbtn svg { width: 17px; height: 17px; flex: none; }
.rbtn:disabled { opacity: .45; cursor: not-allowed; }
.rbtn.run { background: var(--teal); box-shadow: 0 3px 0 var(--teal-dark); }
.rbtn.step { background: var(--blue); box-shadow: 0 3px 0 #2f6099; }
.rbtn.pause { background: var(--gold); color: #4a3703; box-shadow: 0 3px 0 #c29422; }
.rbtn.reset { background: #7d8a8f; box-shadow: 0 3px 0 #5b676c; }
.rbtn.ghost { background: #efe6d0; color: var(--ink); box-shadow: 0 3px 0 #d8caa6; }
.rbtn:not(:disabled):hover { filter: brightness(1.07); }
.rbtn:not(:disabled):active { transform: translateY(3px); box-shadow: none; }
/* 工作台被拉矮时：右侧按钮改排两列，只留文字保证窄列也放得下 */
body.wb-sm .run-panel { grid-template-columns: 1fr 1fr; }
body.wb-sm .rbtn { padding: 9px 2px; font-size: 12px; gap: 0; }
body.wb-sm .rbtn svg { display: none; }

/* ---------------- 参数选择弹层 ---------------- */
.picker {
  position: fixed; z-index: 60; width: 232px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 26px rgba(60, 45, 10, .24); padding: 10px;
}
.picker[hidden] { display: none; }
.picker h4 { margin: 0 0 8px; font-size: 13px; color: var(--teal-dark); font-weight: 600; }
.pick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pick-grid button {
  border: 1px solid var(--line); background: #fff; border-radius: 7px;
  padding: 9px 0; font-size: 15px; font-weight: 700;
}
.pick-grid button:hover { background: var(--hl); border-color: var(--gold); }
.pick-grid button.on { background: var(--teal); border-color: var(--teal-dark); color: #fff; }
.pick-grid.wide button { font-size: 14px; }
.pick-custom { display: flex; gap: 6px; margin-top: 9px; align-items: center; }
.pick-custom input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
.pick-custom span { font-size: 12px; color: var(--ink-soft); }
.pick-tip { font-size: 12px; color: var(--ink-soft); margin-top: 7px; }

/* ---------------- 拖拽幽灵 ---------------- */
.drag-ghost {
  position: fixed; z-index: 70; pointer-events: none; left: 0; top: 0;
  opacity: .92; transform: translate(-9999px, -9999px) scale(1.02);
  filter: drop-shadow(0 8px 12px rgba(60, 45, 10, .3));
}
.drag-ghost[hidden] { display: none; }
body.is-dragging { cursor: grabbing; }
body.is-dragging .blk { cursor: grabbing; }

/* ---------------- 说明弹层 ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 80; background: rgba(40, 32, 12, .5);
  display: grid; place-items: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(760px, 100%); max-height: 86vh; overflow: auto;
  background: var(--panel); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel-2); position: sticky; top: 0;
}
.modal-head h2 { margin: 0; font-size: 18px; color: var(--teal-dark); }
.modal-body { padding: 14px 20px 22px; font-size: 14px; line-height: 1.8; }
.modal-body h3 { margin: 14px 0 6px; font-size: 15px; color: var(--teal-dark); border-left: 4px solid var(--gold); padding-left: 8px; }
.modal-body ul { margin: 0; padding-left: 20px; }
.modal-body li { margin: 3px 0; }

/* ---------------- 毛玻瑞浮层控件通用 ---------------- */
.view-tools, .fs-btn, .zoom-tools {
  background: rgba(255, 253, 244, .40);
  border: 1px solid rgba(255, 255, 255, .58);
  border-radius: 12px;
  backdrop-filter: blur(9px) saturate(1.3);
  -webkit-backdrop-filter: blur(9px) saturate(1.3);
  box-shadow: 0 2px 10px rgba(70, 55, 20, .14);
}
/* 只悬停 / 长按时才出现的文字说明 */
.vt-btn::after, .fs-btn::after, .zt-btn::after {
  content: attr(data-tip);
  position: absolute; left: 0; top: calc(100% + 7px);
  background: rgba(47, 58, 60, .93); color: #fffdf4;
  font-size: 12px; font-weight: 400; line-height: 1.45;
  padding: 5px 9px; border-radius: 7px; white-space: nowrap;
  opacity: 0; pointer-events: none; transform: translateY(-3px);
  transition: opacity .15s ease, transform .15s ease;
  z-index: 20;
}
.vt-btn:hover::after, .vt-btn.tip-show::after,
.fs-btn:hover::after, .fs-btn.tip-show::after,
.zt-btn:hover::after, .zt-btn.tip-show::after { opacity: 1; transform: translateY(0); }
/* 贴在画面下缘的控件，说明文字往上弹 */
.zt-btn::after { top: auto; bottom: calc(100% + 7px); }

/* ---------------- 左上：视图操作模式 ---------------- */
.view-tools {
  position: absolute; left: 10px; top: 10px;
  display: flex; gap: 2px; padding: 4px;
  z-index: 6;
}
.view-tools[hidden] { display: none; }
/* 按当前视图收起无效项：平面视图无角度可调，追随镜头不需要平移 */
.view-tools.flat .vt-btn[data-gizmo="orbit"],
.view-tools.follow .vt-btn[data-gizmo="pan"] { display: none; }
.vt-btn {
  position: relative; width: 34px; height: 34px; padding: 0;
  border: none; border-radius: 9px;
  background: transparent; color: var(--teal-dark);
  display: grid; place-items: center;
}
.vt-btn svg { width: 19px; height: 19px; }
.vt-btn:hover { background: rgba(255, 253, 244, .78); }
.vt-btn.active { background: var(--teal); color: #fffdf4; }

/* ---------------- 右上：全屏开关 ---------------- */
.fs-btn {
  position: absolute; right: 14px; top: 10px; z-index: 7;
  display: flex; align-items: center; gap: 4px;
  height: 32px; padding: 0 9px;
  color: var(--teal-dark); font-size: 12px;
}
.fs-btn[hidden] { display: none; }
.fs-btn:hover { color: #4a3703; }
.fs-btn svg { width: 16px; height: 16px; flex: none; }
.fs-btn .fs-out { display: none; }
.fs-btn.is-full .fs-out { display: block; }
.fs-btn.is-full .fs-in { display: none; }

/* ---------------- 右上：视图立方体 ---------------- */
.viewcube {
  position: absolute; right: 14px; top: 48px;
  width: 128px; height: 128px; z-index: 6;
}
.viewcube[hidden] { display: none; }
.vc-stage {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  perspective: 620px;
}
.vc-cube {
  position: relative; width: 72px; height: 72px;
  transform-style: preserve-3d;
  transform: rotateX(-26deg) rotateY(-32deg);
}
.vc-face {
  position: absolute; inset: 0;
  border: 1px solid #a8b8ac; border-radius: 6px;
  background: rgba(253, 249, 238, .95); color: var(--teal-dark);
  font-size: 19px; font-weight: 700; font-family: inherit;
  display: grid; place-items: center;
  backface-visibility: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .7);
}
.vc-face:hover { background: var(--hl); color: #4a3703; }
.f-front { transform: translateZ(36px); }
.f-back { transform: rotateY(180deg) translateZ(36px); }
.f-right { transform: rotateY(90deg) translateZ(36px); }
.f-left { transform: rotateY(-90deg) translateZ(36px); }
.f-top { transform: rotateX(90deg) translateZ(36px); background: rgba(255, 240, 205, .96); }
.f-bottom { transform: rotateX(-90deg) translateZ(36px); }
.vc-corner {
  position: absolute; width: 26px; height: 26px; padding: 0;
  border: 1px solid var(--line); border-radius: 50%;
  background: rgba(255, 253, 244, .92);
}
.vc-corner::after {
  content: ''; position: absolute; inset: 7px; border-radius: 50%; background: #a8b8ac;
}
.vc-corner:hover { border-color: var(--gold); }
.vc-corner:hover::after { background: var(--gold); }
.c-tl { left: 6px; top: 6px; }
.c-tr { right: 6px; top: 6px; }
.c-bl { left: 6px; bottom: 6px; }
.c-br { right: 6px; bottom: 6px; }

/* ---------------- 右下：缩放比例 ---------------- */
.zoom-tools {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 1px;
  padding: 3px; z-index: 6;
}
.zt-btn {
  position: relative; width: 30px; height: 30px;
  border: none; border-radius: 8px;
  background: transparent; color: var(--teal-dark);
  display: grid; place-items: center;
}
.zt-btn svg { width: 17px; height: 17px; }
.zt-btn:hover { background: rgba(255, 253, 244, .8); }
.zt-btn:active { transform: translateY(1px); }
.zt-val {
  font-size: 11px; width: 30px; text-align: center; color: var(--teal-dark);
  font-variant-numeric: tabular-nums; text-shadow: 0 1px 0 rgba(255, 255, 255, .7);
}
/* 锁定视角与比例时，缩放控件暂时不可调 */
.zoom-tools.locked .zt-btn,
.zoom-tools.locked #zoomRange { opacity: .38; pointer-events: none; }
.zoom-tools.locked .zt-val { opacity: .55; }

#zoomRange {
  -webkit-appearance: none; appearance: none;
  width: 62px; height: 30px; background: transparent; cursor: pointer;
}
#zoomRange::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: #ded2b6;
}
#zoomRange::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px;
  border-radius: 50%; background: var(--teal); border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .32);
}
#zoomRange::-moz-range-track { height: 4px; border-radius: 2px; background: #ded2b6; }
#zoomRange::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--teal); border: 2px solid #fff;
}

/* ---------------- 自适应 ---------------- */
@media (max-width: 1360px) {
  .workbench { grid-template-columns: 250px 260px minmax(0, 1fr) 132px; }
  .stage { grid-template-columns: minmax(0, 1fr) 268px; }
  .hud { display: none; }
  .viewcube { width: 108px; height: 108px; right: 10px; }
  .fs-btn { right: 10px; }
  .vc-cube { width: 58px; height: 58px; }
  .f-front { transform: translateZ(29px); }
  .f-back { transform: rotateY(180deg) translateZ(29px); }
  .f-right { transform: rotateY(90deg) translateZ(29px); }
  .f-left { transform: rotateY(-90deg) translateZ(29px); }
  .f-top { transform: rotateX(90deg) translateZ(29px); background: rgba(255, 240, 205, .96); }
  .f-bottom { transform: rotateX(-90deg) translateZ(29px); }
  .vc-face { font-size: 16px; }
  .vc-corner { width: 22px; height: 22px; }
  .vc-corner::after { inset: 6px; }
  #zoomRange { width: 54px; }
}
@media (max-width: 1100px) {
  .brand-txt span { display: none; }
  .workbench { grid-template-columns: 224px 232px minmax(0, 1fr) 120px; }
  .view-switch { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   手机端自适应
   断点由 app.js 统一判定并打在 body 上（body.mobile / m-portrait /
   m-landscape / mtab-*），CSS 不再重复写一套数字，避免两边对不上。
   竖屏：画面常驻 + 底部标签栏切换抽屉；横屏：无标签，工作台压成两行。
   ============================================================ */
.mtabs { display: none; }

/* 用 dvh 而不是 100%：手机浏览器地址栏收起 / 弹出时 100% 会算错，整页被顶出滚动条 */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body.mobile {
  -webkit-text-size-adjust: 100%;
  font-size: 14px;
}

/* ---------------- 竖屏：标签页 ---------------- */
body.mobile.m-portrait .app {
  grid-template-rows: 42px minmax(0, 1fr) var(--wb-h) calc(54px + env(safe-area-inset-bottom));
  gap: 5px; padding: 5px;
}
/* 抽屉收起时（演示 / 代码标签）只剩三行实际内容 */
body.mobile.m-portrait.mtab-view .app,
body.mobile.m-portrait.mtab-code .app {
  grid-template-rows: 42px minmax(0, 1fr) 0 calc(54px + env(safe-area-inset-bottom));
}
body.mobile.m-portrait.mtab-view .workbench,
body.mobile.m-portrait.mtab-code .workbench { display: none; }

/* 画面独占一列，代码展示区降级成画面下方的一条模式切换栏 */
body.mobile .stage {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
}
body.mobile .code-panel { min-height: 0; }
body.mobile.m-portrait.mtab-code .stage { grid-template-rows: minmax(0, 1fr) minmax(0, 46%); }
body.mobile .code-panel .view-switch {
  grid-template-columns: repeat(4, 1fr);
  gap: 5px; padding: 5px; border-top: none;
}
body.mobile .vtab {
  flex-direction: column; gap: 1px; padding: 5px 2px;
  font-size: 11px; line-height: 1.2; min-height: 46px;
}
body.mobile .vtab svg { width: 19px; height: 19px; }
/* 非「代码」标签下，只保留模式切换栏，省出画面空间。
   必须限定 m-portrait：横屏不用标签栏，这条不加限定会把横屏的代码展示区一并藏掉 */
body.mobile.m-portrait:not(.mtab-code) .code-panel .panel-head,
body.mobile.m-portrait:not(.mtab-code) .code-panel .code-list { display: none; }

/* 底部标签栏 */
body.mobile.m-portrait .mtabs {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px;
  padding-bottom: env(safe-area-inset-bottom);
}
.mtab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--ink-soft);
  font-family: inherit; font-size: 11.5px; font-weight: 600;
  box-shadow: var(--shadow); -webkit-tap-highlight-color: transparent;
}
.mtab svg { width: 21px; height: 21px; }
.mtab.active { background: var(--teal); border-color: var(--teal-dark); color: #fffdf4; }

/* 竖屏抽屉：积木库 + 编程区并排，运行按钮横铺一行区 */
body.mobile.m-portrait .workbench {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  grid-template-rows: minmax(0, 1fr) auto;
}
body.mobile.m-portrait .palette { grid-area: 1 / 1; }
body.mobile.m-portrait .program-panel { grid-area: 1 / 2; }
body.mobile.m-portrait .run-panel { grid-area: 2 / 1 / 3 / 3; }
body.mobile.m-portrait .task-panel { grid-area: 1 / 1 / 3 / 3; }
body.mobile.m-portrait .run-panel { grid-template-columns: repeat(3, 1fr); }
/* 编程标签只留编辑三件套，任务标签只留说明 */
body.mobile.m-portrait.mtab-prog .task-panel { display: none; }
body.mobile.m-portrait.mtab-task .palette,
body.mobile.m-portrait.mtab-task .program-panel,
/* .run-panel 根规则带 display:grid !important，这里不加 !important 顶不掉 */
body.mobile.m-portrait.mtab-task .run-panel { display: none !important; }
body.mobile.m-portrait.mtab-task .workbench { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
body.mobile.m-portrait.mtab-task .task-panel { grid-area: 1 / 1; }

/* ---------------- 横屏：不用标签，两行全展开 ---------------- */
body.mobile.m-landscape .app { grid-template-rows: 38px minmax(0, 1fr) minmax(148px, 42%); gap: 5px; padding: 5px; }
body.mobile.m-landscape .mtabs { display: none; }
body.mobile.m-landscape .stage { grid-template-columns: minmax(0, 1fr) 150px; grid-template-rows: minmax(0, 1fr); }
body.mobile.m-landscape .code-panel .view-switch { grid-template-columns: 1fr 1fr; }
body.mobile.m-landscape .code-panel .panel-head { padding: 5px 8px; font-size: 12px; }
/* 横屏画面只有 170px 高：缩放条回到右下角（竖屏那套 bottom:60 是为避开项目切换条），
   模式切换改回横排，给代码展示区留出可见行数 */
body.mobile.m-landscape .zoom-tools { bottom: 5px; }
body.mobile.m-landscape .vtab { flex-direction: row; min-height: 32px; padding: 3px 4px; font-size: 11px; }
body.mobile.m-landscape .vtab svg { width: 15px; height: 15px; }
body.mobile.m-landscape .viewcube { width: 66px; height: 66px; }
body.mobile.m-landscape .vc-cube { width: 36px; height: 36px; }
body.mobile.m-landscape .f-front { transform: translateZ(18px); }
body.mobile.m-landscape .f-back { transform: rotateY(180deg) translateZ(18px); }
body.mobile.m-landscape .f-right { transform: rotateY(90deg) translateZ(18px); }
body.mobile.m-landscape .f-left { transform: rotateY(-90deg) translateZ(18px); }
body.mobile.m-landscape .f-top { transform: rotateX(90deg) translateZ(18px); background: rgba(255, 240, 205, .96); }
body.mobile.m-landscape .f-bottom { transform: rotateX(-90deg) translateZ(18px); }
body.mobile.m-landscape .vc-corner { width: 15px; height: 15px; }
body.mobile.m-landscape .vc-corner::after { inset: 4px; }
/* 横屏无视标签状态，四块面板一律显示 */
body.mobile.m-landscape .code-panel .code-list,
body.mobile.m-landscape .workbench > section { display: grid; }
body.mobile.m-landscape .workbench {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
}
body.mobile.m-landscape .task-panel { grid-area: 1 / 1; }
body.mobile.m-landscape .palette { grid-area: 1 / 2; }
body.mobile.m-landscape .program-panel { grid-area: 2 / 1; }
/* 抽屉两行共 160px，运行区只分到 76px；3 列两排装不下（含 padding 要 94px），改成一排六个 */
body.mobile.m-landscape .run-panel { grid-area: 2 / 2; grid-template-columns: repeat(6, 1fr); padding: 5px; gap: 5px; }
body.mobile.m-landscape .rbtn { padding: 6px 1px; font-size: 11px; gap: 3px; min-height: 36px; }
body.mobile.m-landscape .rbtn svg { width: 14px; height: 14px; }

/* ---------------- 共用的触控与拥挤治理 ---------------- */
body.mobile .splitter { display: none; }
body.mobile .hud { display: none; }
body.mobile .brand-txt { display: none; }
body.mobile .brand-ico { width: 20px; height: 20px; }
body.mobile .mode-badge { font-size: 12px; padding: 2px 9px; }
body.mobile .hint-bar { font-size: 11.5px; padding: 4px 8px; max-width: 34vw; }
body.mobile .speed-box { font-size: 11.5px; }
body.mobile .speed-box select { min-height: 30px; font-size: 12px; }
/* 顶栏按钮在触控屏上普遍偏小，统一抬到 34px 以上 */
body.mobile .icon-btn { width: 34px; height: 34px; }
body.mobile .icon-btn svg { width: 19px; height: 19px; }
body.mobile .mini-run { height: 32px; }

/* 画面里的浮层控件在小屏上会互相压住：方向立方缩小，工具按钮加大 */
body.mobile .viewcube { width: 78px; height: 78px; }
body.mobile .vc-cube { width: 42px; height: 42px; }
body.mobile .f-front { transform: translateZ(21px); }
body.mobile .f-back { transform: rotateY(180deg) translateZ(21px); }
body.mobile .f-right { transform: rotateY(90deg) translateZ(21px); }
body.mobile .f-left { transform: rotateY(-90deg) translateZ(21px); }
body.mobile .f-top { transform: rotateX(90deg) translateZ(21px); background: rgba(255, 240, 205, .96); }
body.mobile .f-bottom { transform: rotateX(-90deg) translateZ(21px); }
body.mobile .vc-face { font-size: 12px; }
body.mobile .vc-corner { width: 17px; height: 17px; }
body.mobile .vc-corner::after { inset: 5px; }
body.mobile .view-tools { gap: 2px; padding: 2px; }
body.mobile .vt-btn { width: 34px; height: 34px; }
body.mobile .vt-btn svg { width: 19px; height: 19px; }
body.mobile .zoom-tools { gap: 2px; padding: 2px; }
body.mobile .zt-btn { width: 34px; height: 34px; }
body.mobile .zt-btn svg { width: 19px; height: 19px; }
body.mobile .zt-val { width: 34px; font-size: 12px; }
body.mobile #zoomRange { width: 52px; height: 32px; }
/* 全屏钮改成纯图标：强塞 34px 宽会把“全屏”两个字挤成竖排 */
body.mobile .fs-btn { width: 38px; height: 34px; padding: 0; justify-content: center; }
body.mobile .fs-btn span { display: none; }

/* 项目 / 任务切换和面板标题都要能按得动 */
body.mobile .panel-head { padding: 7px 9px; font-size: 13px; }
body.mobile .panel-head em { font-size: 11px; }

/* 画面底部的项目切换条在窄屏上几乎满宽，缩放条必须躲开它，否则两者完全重叠 */
body.mobile .proj-tabs { left: 5px; bottom: 5px; gap: 4px; padding: 4px; }
body.mobile .ptab { min-height: 30px; font-size: 11.5px; padding: 4px 7px; }
body.mobile .ttab { min-height: 30px; font-size: 11px; padding: 4px 6px; }
body.mobile .zoom-tools { position: absolute; right: 5px; left: auto; bottom: 60px; }
body.mobile .palette-body { padding: 8px 6px; gap: 8px; }
body.mobile .pal-label { font-size: 11px; }
body.mobile .program-scroll { padding: 8px; }
body.mobile .rbtn { padding: 9px 3px; font-size: 12.5px; gap: 4px; }
body.mobile .rbtn svg { width: 16px; height: 16px; }
body.mobile .task-body { font-size: 13px; padding: 9px; }
body.mobile .cline { font-size: 12.5px; }

/* 弹窗在小屏上不能横跨半个画面 */
body.mobile .banner { left: 6px; top: 52px; max-width: min(72%, 300px); padding: 7px 30px 7px 10px; }
body.mobile .banner-main { font-size: 14px; }
body.mobile .banner-sub { font-size: 11px; }
body.mobile .toast { left: 6px; top: 52px; max-width: 62%; font-size: 12px; }
body.mobile .modal-card { max-width: 94vw; max-height: 88vh; }

/* 长按选中文字、双击缩放都会和拖积木抢手势 */
body.mobile .palette, body.mobile .program-panel { touch-action: pan-y; }
body.mobile img { -webkit-user-drag: none; }

/* 积木内部的参数钮与删除钮：默认 24px / 20px 手指按不准 */
body.mobile .field { min-width: 40px; min-height: 32px; padding: 4px 6px; font-size: 15px; }
body.mobile .blk .blk-del { width: 30px; height: 30px; }
body.mobile .blk .blk-del svg { width: 14px; height: 14px; }
body.mobile .slot { min-height: 40px; }
/* 弹层不能超出屏幕，数字 chip 抬到 44px 方便点选 */
body.mobile .picker { width: min(232px, calc(100vw - 16px)); }
body.mobile .pick-grid button { min-height: 42px; }
body.mobile .pick-custom input, body.mobile .pick-custom button { min-height: 38px; }

