/* ============================================================
   循环指令 — 样式（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-small {
  padding: 6px 14px;
  font-size: 13px;
  margin: 4px 4px;
}

.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: 10px;
}

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

.concept-note {
  background: #e6f0fd;
  border: 1px solid #9cc3f2;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: #3a7bd5;
  margin-bottom: 10px;
}

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

.cmd-add {
  background: #e6f0fd;
  border: 1px solid #9cc3f2;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  color: #3a7bd5;
  cursor: pointer;
  margin: 3px 4px;
  font-weight: 600;
}

.cmd-add:active { background: #cfe4fb; }
.cmd-add.small { padding: 6px 12px; font-size: 13px; margin: 3px 3px; }

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

.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;
}

.loop-chip {
  background: #7b5ad5;
  border: 2px solid #5a3ab5;
}

.loop-chip.active { background: #5a3ab5; }

.body-chip { background: #3a7bd5; }

/* 执行高亮 / 失败定位 */
.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;
}

.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;
}

/* 循环块内编辑区 */
.block-edit {
  display: none;
}

.block-edit.open {
  display: block;
  background: #f6f3ff;
  border: 2px solid #7b5ad5;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
}

.block-crumb {
  font-size: 13px;
  font-weight: 600;
  color: #5a3ab5;
  margin-bottom: 6px;
}

.block-body {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  min-height: 32px;
  background: #ffffff;
  border: 1px dashed #b99cf0;
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 13px;
  color: #86909c;
  margin-bottom: 6px;
}

.block-add-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.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; }

/* ---------- 家长面板 ---------- */
.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));
}