/* ============================================================
   机器人走迷宫 — 样式（Chrome 61 基线层）
   约束：无 flex gap / aspect-ratio / clamp / inset / 逻辑属性 / :has
   主题：编程教学 · 科技蓝
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #f5f7fa;
  color: #1f2329;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  height: 100vh;
  height: calc(var(--app-height, 100vh));
}

/* ---------- 顶栏 ---------- */
.app-header {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  background: #ffffff;
  border-bottom: 1px solid #e5e6eb;
}

.header-brand {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 10px 16px;
}

.header-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  margin-right: 8px;
}

.header-name {
  font-size: 17px;
  font-weight: 600;
}

.header-streak {
  position: absolute;
  right: 12px;
  top: calc(10px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
  font-size: 12px;
  color: #3a7bd5;
}

/* ---------- 主区 ---------- */
.app-main {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.view {
  padding: 16px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- 首页 ---------- */
.home-wrap { text-align: center; }

.home-title {
  font-size: 26px;
  margin: 24px 0 6px;
  color: #3a7bd5;
}

.home-sub {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 24px;
}

.level-card {
  display: block;
  width: 100%;
  background: #ffffff;
  border: 1px solid #e5e6eb;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  text-align: left;
  cursor: pointer;
}

.level-card:active { background: #f2f4f7; }

.level-name {
  font-size: 17px;
  font-weight: 600;
  color: #1f2329;
}

.level-best {
  font-size: 13px;
  color: #86909c;
  margin-top: 4px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block;
  background: #ffffff;
  border: 1px solid #c9cdd4;
  border-radius: 24px;
  padding: 12px 28px;
  font-size: 15px;
  color: #1f2329;
  cursor: pointer;
  margin: 8px 6px;
}

.btn-primary {
  background: #3a7bd5;
  border-color: #3a7bd5;
  color: #ffffff;
}

.btn-checkin { background: #fff7e6; border-color: #ffd591; color: #d46b08; }

.btn-danger { color: #f5222d; border-color: #ffa39e; }

.hidden-entry {
  width: 0;
  height: 0;
  opacity: 0;
  border: none;
  padding: 0;
}

/* ---------- 练习页 ---------- */
.game-wrap {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
}

.game-top {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  margin-bottom: 10px;
}

.game-back {
  background: none;
  border: none;
  font-size: 15px;
  color: #4e5969;
  cursor: pointer;
  padding: 4px 8px;
}

.game-prog { font-size: 14px; font-weight: 600; }

.game-timer { font-size: 14px; color: #86909c; }

.game-hint { font-size: 12px; color: #86909c; }

.board {
  background: #ffffff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(31, 35, 41, 0.06);
  margin-bottom: 12px;
}

.board-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* 指令区 */
.cmd-bar {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.cmd-add {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 22%;
  flex: 1 1 22%;
  min-width: 0;
  background: #e6f0fd;
  border: 1px solid #9cc3f2;
  border-radius: 20px;
  padding: 8px 6px;
  font-size: 13px;
  color: #3a7bd5;
  cursor: pointer;
  margin: 2px;
  font-weight: 600;
}

.cmd-add:active { background: #cfe4fb; }

.seq-wrap {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  margin-bottom: 12px;
}

.seq-box {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-height: 44px;
  background: #ffffff;
  border: 2px dashed #c9cdd4;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 14px;
  color: #86909c;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}

.seq-box.active { border-color: #3a7bd5; color: #1f2329; }

.cmd-chip {
  display: inline-block;
  background: #3a7bd5;
  color: #ffffff;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 14px;
  margin: 2px 3px;
  cursor: pointer;
}

/* V1.5 if 分支块（紫色区分） */
.cmd-chip.if {
  background: #8c5bd6;
  border: 1px solid #7a4ec0;
}

/* V1.7 循环块 chip（绿色区分） */
.cmd-chip.loopb {
  background: #2f9e62;
  border: 1px solid #23824c;
}

/* V1.5 分支内小号 chip */
.cmd-chip.small {
  font-size: 12px;
  padding: 4px 8px;
}

/* V1.4 调试反馈：执行中高亮 / 失败定位 / 锁定灰显 */
.cmd-chip.exec {
  background: #ffffff;
  color: #3a7bd5;
  border: 2px solid #3a7bd5;
  padding: 4px 9px;
  box-shadow: 0 2px 6px rgba(58, 123, 213, 0.4);
}
.cmd-chip.err {
  background: #f5222d;
  color: #ffffff;
  border: 2px solid #cf1322;
  padding: 4px 9px;
}
.cmd-add[disabled], .seq-clear[disabled], .cmd-chip[disabled] {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.seq-clear {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  background: none;
  border: 1px solid #c9cdd4;
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 13px;
  color: #4e5969;
  cursor: pointer;
  margin-left: 8px;
}

.ctrl-row { text-align: center; }

.game-feedback {
  text-align: center;
  font-size: 15px;
  min-height: 28px;
  padding: 12px 0 0;
  color: #4e5969;
}

.game-feedback.ok { color: #52c41a; font-weight: 600; }
.game-feedback.miss { color: #f5222d; }

/* ---------- V1.5 if 分支编辑区（editCtx） ---------- */
.block-edit {
  background: #faf7ff;
  border: 2px solid #d3c4ef;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 12px;
}

.block-edit-title {
  font-size: 14px;
  font-weight: 600;
  color: #6b3fb5;
  margin-bottom: 8px;
}

.block-edit-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
}

.block-edit-col {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 48%;
  flex: 0 0 48%;
  background: #ffffff;
  border: 1px solid #e5e6eb;
  border-radius: 10px;
  padding: 8px;
}

.block-edit-label {
  font-size: 13px;
  font-weight: 600;
  color: #4e5969;
  margin-bottom: 6px;
}

.block-edit-chips {
  min-height: 30px;
  margin-bottom: 6px;
}

.block-edit-add {
  border-top: 1px dashed #e5e6eb;
  padding-top: 6px;
}

.cmd-add-sm {
  display: inline-block;
  background: #f2f4f7;
  border: 1px solid #c9cdd4;
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12px;
  color: #4e5969;
  cursor: pointer;
  margin: 2px 3px 2px 0;
}

.cmd-add-sm:active { background: #e5e6eb; }

.btn-close-edit {
  display: block;
  margin: 8px auto 0;
  background: #ffffff;
  border: 1px solid #c9cdd4;
  border-radius: 16px;
  padding: 6px 20px;
  font-size: 13px;
  color: #4e5969;
  cursor: pointer;
}

/* ---------- 结算 ---------- */
.result-wrap { text-align: center; }

.result-title { font-size: 34px; margin: 30px 0 4px; color: #3a7bd5; }

.result-sub { font-size: 18px; font-weight: 600; margin-bottom: 16px; }

.result-best { font-size: 14px; color: #3a7bd5; margin-top: 6px; font-weight: 600; }

/* ---------- 家长面板 ---------- */
.parent-wrap { text-align: center; }

.parent-title { font-size: 20px; margin: 20px 0 12px; }

.parent-row { font-size: 14px; color: #4e5969; margin: 6px 0; }
.parent-row.small { font-size: 13px; color: #86909c; }

.parent-sub { font-size: 15px; margin: 16px 0 6px; color: #1f2329; }

/* ---------- 页脚 ---------- */
.app-footer {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}

/* ============================================================
   v1.9 关卡编辑器样式
   ============================================================ */

/* 首页自建关卡卡片 */
.custom-card { background: -webkit-linear-gradient(135deg, #ffd591, #ffc069); background: linear-gradient(135deg, #ffd591, #ffc069); }

/* 关卡库列表 */
.custom-wrap { max-width: 420px; margin: 0 auto; padding: 16px; }
.custom-title { font-size: 20px; margin: 0 0 12px; color: #1f2329; }
.custom-empty { font-size: 14px; color: #86909c; margin: 12px 0; }
.custom-row {
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: center; -webkit-align-items: center; align-items: center;
  -webkit-box-pack: justify; -webkit-justify-content: space-between; justify-content: space-between;
  background: #fff; border: 1px solid #e5e6eb; border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
}
.custom-info { -webkit-box-flex: 1; -webkit-flex: 1 1 auto; flex: 1 1 auto; min-width: 0; }
.custom-name { font-size: 15px; color: #1f2329; }
.custom-meta { font-size: 12px; color: #86909c; margin-top: 2px; }
.custom-btns { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; }
.custom-btns .btn { margin-left: 6px; }
.custom-limit { font-size: 12px; color: #f53f3f; margin: 8px 0; }

/* 编辑器 */
.editor-wrap { max-width: 420px; margin: 0 auto; padding: 16px; }
.editor-title { font-size: 20px; margin: 0 0 12px; color: #1f2329; }
.editor-name-row { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-align: center; -webkit-align-items: center; align-items: center; margin-bottom: 10px; }
.editor-name-label { font-size: 14px; color: #4e5969; margin-right: 8px; -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; }
.editor-name-input {
  -webkit-box-flex: 1; -webkit-flex: 1 1 auto; flex: 1 1 auto; min-width: 0;
  font-size: 14px; padding: 6px 10px; border: 1px solid #c9cdd4; border-radius: 8px; color: #1f2329;
}
.editor-grid {
  display: -ms-grid; display: grid;
  width: 100%; margin: 0 auto 10px;
  border: 1px solid #c9cdd4; border-radius: 8px; overflow: hidden;
  -webkit-user-select: none; -moz-user-select: none; user-select: none;
  touch-action: none;
}
.editor-cell {
  position: relative; height: 0; padding-bottom: 100%;
  background: #f0f2f5; border: 1px solid #e5e6eb;
  -webkit-box-sizing: border-box; box-sizing: border-box;
}
.editor-cell.is-wall { background: #8a8f98; }
.editor-cell.has-goal::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 40%; height: 40%;
  -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);
  border: 2px solid #ff9c4a; border-radius: 50%; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.editor-cell.has-box::before {
  content: ''; position: absolute; left: 18%; top: 18%; width: 64%; height: 64%;
  background: #b76a1a; border-radius: 4px; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.editor-cell.has-box.has-goal::before { background: #d98a3a; }
.editor-cell.has-player::before {
  content: ''; position: absolute; left: 25%; top: 25%; width: 50%; height: 50%;
  background: #3a7bd5; border-radius: 50%; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.editor-cell.has-player.has-goal::before { background: #2f5cb0; }

.editor-tools { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; margin-bottom: 10px; }
.editor-tools .btn { margin-right: 6px; margin-bottom: 4px; }
.editor-tools .btn.active { background: #165dff; color: #fff; border-color: #165dff; }
.editor-actions { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; margin-bottom: 10px; }
.editor-actions .btn { margin-right: 6px; margin-bottom: 4px; }
.editor-feedback { font-size: 13px; margin: 8px 0; padding: 8px 10px; border-radius: 8px; background: #f2f3f5; color: #4e5969; }
.editor-feedback.ok { background: #e8ffea; color: #00b42a; }
.editor-feedback.miss { background: #ffece8; color: #f53f3f; }

/* ============ v1.10 自定义指令块（抽象/函数概念） ============ */

/* 块选择按钮（cmd-bar [🧩块]）——紫色系，与普通指令区分 */
.cmd-add-call { background: #f3e8fd; border-color: #c9a8e8; color: #722ed1; }
.cmd-add-call:active { background: #e8d9fb; }

/* 序列中块引用 chip——紫色 .call（与 loop 绿 / if 橙区分） */
.cmd-chip.call {
  background: #f3e8fd;
  border-color: #c9a8e8;
  color: #722ed1;
  font-weight: 600;
}
.cmd-chip.call.deleted { background: #f2f3f5; border-color: #c9cdd4; color: #86909c; }
.cmd-chip.call .chip-x { color: #a07bd1; }

/* 块选择面板（cmd-bar 下方内联） */
.block-picker {
  border: 2px dashed #c9a8e8;
  border-radius: 10px;
  background: #fdfaff;
  padding: 8px;
  margin-bottom: 10px;
}
.block-picker-empty { font-size: 13px; color: #86909c; padding: 6px 2px; }
.block-picker-item {
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-orient: vertical; -webkit-box-direction: normal;
  -webkit-flex-direction: column; flex-direction: column;
  -webkit-box-align: start; -webkit-align-items: flex-start; align-items: flex-start;
  background: #f3e8fd;
  border: 1px solid #c9a8e8;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
}
.block-picker-item:active { background: #e8d9fb; }
.block-picker-name { font-size: 14px; color: #722ed1; font-weight: 600; }
.block-picker-preview { font-size: 12px; color: #a07bd1; margin-top: 2px; }
/* v1.14 N2：预览 span 视觉标记——固定灰底 / 参数浅紫 / loop 灰框 / 基础无底 */
.block-picker-preview .pv-base { color: #555; margin: 0 1px; }
.block-picker-preview .pv-steps { background: #f0f0f0; color: #555; border-radius: 3px; padding: 0 2px; margin: 0 1px; }
.block-picker-preview .pv-param { background: #f3e8fd; color: #722ed1; border-radius: 3px; padding: 0 2px; margin: 0 1px; font-weight: 600; }
.block-picker-preview .pv-loop { display: inline-block; border: 1px solid #ccc; border-radius: 3px; padding: 0 2px; margin: 0 1px; color: #555; }
.block-picker-preview .pv-inner { white-space: nowrap; }
.block-picker-preview .pv-if { display: inline-block; background: #f0e6ff; border: 1px solid #c9a8e8; color: #722ed1; border-radius: 3px; padding: 0 2px; margin: 0 1px; font-weight: 600; }
.block-picker-mgr { margin-top: 6px; }
.block-picker-mgr .cmd-add { -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; }

/* 首页「我的块」卡片——紫色系 */
.block-card { background: -webkit-linear-gradient(135deg, #efdbff, #d3adf7); background: linear-gradient(135deg, #efdbff, #d3adf7); }
.block-card:active { background: #e8d9fb; }

/* ============ v1.11 块参数（函数参数化） ============ */

/* 参数 toggle（块编辑器「🔢 带参数」） */
.block-edit-param { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-align: center; -webkit-align-items: center; align-items: center; margin-bottom: 10px; -webkit-flex-wrap: wrap; flex-wrap: wrap; }
.block-param-toggle { -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; margin: 2px; }
.block-param-toggle.active { background: #722ed1; color: #fff; border-color: #722ed1; }
.block-edit-param-hint { font-size: 12px; color: #a07bd1; margin-left: 8px; }

/* 块编辑器 body 中参数化 steps chip（v1.12：➡?步——? 占位符浅紫 highlight） */
.cmd-chip.param-step { background: #f3e8fd; border-color: #c9a8e8; color: #722ed1; }
.cmd-chip.param-step .chip-x { color: #a07bd1; }

/* 序列中参数块引用 chip（🧩名(N)——(N) 浅紫小字可调暗示）
   v1.13 I6：多参数分段 (N₀,N₁)——.call-param 段独立可点（下划线+手型暗示） */
.cmd-chip.call.param-call { background: #f3e8fd; border-color: #c9a8e8; color: #722ed1; font-weight: 600; }
.cmd-chip.call .call-param { color: #a07bd1; font-weight: 600; text-decoration: underline; -webkit-tap-highlight-color: transparent; cursor: pointer; }

