/* 小小程序员 · 统一积木 UI（Code.org 风，点击添加，纵向堆叠） */

.container { max-width: 980px !important; }

/* ===== 双栏：左网格 · 右代码（指令+程序合一） ===== */
.play-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  align-items: stretch;
}
.stage-panel {
  display: flex;
  justify-content: center;
  width: 100%;
}
.code-panel {
  width: 100%;
}
.code-panel-inner {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.code-section { padding: 10px 12px; }
.code-section-hd {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.code-section-hd .step-count { color: rgba(255, 255, 255, 0.75); font-weight: bold; }
.code-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0 10px;
}
.code-hint {
  font-size: 10px;
  color: #ffd54a;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 213, 74, 0.1);
  border: 1px solid rgba(255, 213, 74, 0.25);
  display: none;
}
.code-hint.show { display: inline-block; }

@media (min-width: 680px) {
  .play-area {
    flex-direction: row;
    align-items: flex-start;
    gap: 14px;
  }
  .stage-panel {
    flex: 1;
    min-width: 0;
    justify-content: center;
  }
  .code-panel {
    width: min(320px, 36vw);
    flex-shrink: 0;
    position: sticky;
    top: 8px;
    max-height: calc(100dvh - 150px);
  }
  .code-panel-inner {
    max-height: calc(100dvh - 150px);
  }
  .program-stack {
    max-height: min(42vh, 320px);
  }
}

/* ===== 积木基础（palette + program 共用） ===== */
.blk {
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-weight: bold;
  border: none;
  font-family: inherit;
}
.blk:active { transform: scale(0.98); }

/* 调色板：紧凑横排 */
.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.blk-palette {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(0, 0, 0, 0.12);
}
.blk-palette .blk-ico { font-size: 15px; line-height: 1; }
.blk-palette .blk-sub { font-size: 9px; opacity: 0.8; font-weight: normal; }
.blk-palette.locked { display: none; }

/* 程序区：纵向堆叠 */
.program-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  min-height: 88px;
  max-height: min(38vh, 280px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 4px 8px;
  -webkit-overflow-scrolling: touch;
}
.program-stack.empty::after {
  content: "👆 点上方积木加入程序";
  display: block;
  text-align: center;
  color: rgba(255, 255, 255, 0.35);
  font-size: 12px;
  padding: 24px 8px;
  font-weight: normal;
}
.program-stack.editing-loop { background: rgba(255, 213, 74, 0.05); border-radius: 10px; }
.program-stack.lab-debug { background: rgba(255, 107, 157, 0.06); border-radius: 10px; border: 1px dashed rgba(255, 107, 157, 0.3); }

/* 程序块：Code.org 长条 + 凹凸 */
.blk-seq {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px 9px 10px;
  min-height: 40px;
  cursor: pointer;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
  position: relative;
  margin-bottom: 2px;
  border-radius: 6px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: blkIn 0.15s ease;
}
@keyframes blkIn { from { transform: scaleY(0.6); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }

.blk-seq::before {
  content: "";
  position: absolute;
  top: -3px;
  left: 14px;
  width: 18px;
  height: 4px;
  background: inherit;
  border-radius: 3px 3px 0 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.blk-seq:first-child::before { display: none; }
.blk-seq::after {
  content: "";
  position: absolute;
  bottom: -3px;
  left: 14px;
  width: 22px;
  height: 4px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 0 0 3px 3px;
}
.blk-seq:last-child::after { display: none; }

.blk-seq.running {
  outline: 2px solid #fff;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.65), 0 3px 0 rgba(0, 0, 0, 0.2);
  z-index: 2;
}
.blk-seq.suspect {
  outline: 2px dashed rgba(255, 107, 157, 0.85);
  animation: blkWiggle 1.2s ease infinite;
}
@keyframes blkWiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-1deg); }
  75% { transform: rotate(1deg); }
}

.blk-num {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}
.blk-ico { font-size: 16px; line-height: 1; flex-shrink: 0; }
.blk-text { flex: 1; }

/* 颜色：移动 / 转向 / 循环 / 条件 */
.blk-dir-up, .blk-motion { background: linear-gradient(180deg, #4fc3f7, #0288d1); }
.blk-dir-down { background: linear-gradient(180deg, #ffb74d, #f57c00); }
.blk-dir-left { background: linear-gradient(180deg, #4db6ac, #00897b); }
.blk-dir-right { background: linear-gradient(180deg, #b39ddb, #7e57c2); }
.blk-turn-l { background: linear-gradient(180deg, #ffd54f, #ff8f00); color: #1a1208; text-shadow: none; }
.blk-turn-r { background: linear-gradient(180deg, #ce93d8, #8e24aa); }

.blk-loop-wrap {
  margin-bottom: 4px;
  border-radius: 8px;
  background: rgba(40, 217, 121, 0.08);
  border: 2px solid rgba(40, 217, 121, 0.45);
  overflow: hidden;
  animation: blkIn 0.15s ease;
}
.blk-loop-wrap.editing {
  border-color: #ffd54a;
  box-shadow: 0 0 12px rgba(255, 213, 74, 0.35);
}
.blk-loop-wrap.running { outline: 2px solid #fff; }

.blk-loop-hdr {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #43a047, #2e7d32);
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.blk-loop-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  color: #2e7d32;
  font-size: 14px;
  font-weight: bold;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.blk-loop-count:active { transform: scale(0.95); }
.blk-loop-del {
  margin-left: auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(255, 107, 157, 0.5);
  background: rgba(255, 107, 157, 0.3);
  color: #ffcdd2;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.blk-loop-body {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 6px 8px 8px 16px;
  min-height: 44px;
  border-left: 4px solid rgba(40, 217, 121, 0.5);
  margin: 4px 6px 6px 10px;
  cursor: pointer;
}
.blk-loop-body.empty::after {
  content: "+ 点指令加入";
  color: rgba(255, 255, 255, 0.35);
  font-size: 11px;
  font-weight: normal;
  padding: 8px 0;
  text-align: center;
}
.blk-loop-body .blk-seq {
  font-size: 12px;
  min-height: 34px;
  padding: 6px 10px;
}

/* 条件块 */
.blk-if-wrap {
  margin-bottom: 4px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  animation: blkIn 0.15s ease;
}
.blk-if-wrap.if-path { border-color: rgba(255, 107, 157, 0.5); background: rgba(255, 107, 157, 0.08); }
.blk-if-wrap.if-wall { border-color: rgba(149, 117, 205, 0.55); background: rgba(149, 117, 205, 0.1); }
.blk-if-wrap.editing { border-color: #ffd54a; box-shadow: 0 0 12px rgba(255, 213, 74, 0.35); }

.blk-if-hdr {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: bold;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.blk-if-wrap.if-path .blk-if-hdr { background: linear-gradient(180deg, #ff8a80, #e53935); }
.blk-if-wrap.if-wall .blk-if-hdr { background: linear-gradient(180deg, #9575cd, #5e35b1); }
.blk-if-del { margin-left: auto; width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3); background: rgba(0,0,0,0.2); color: #fff; font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.blk-if-body {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 6px 8px 8px 16px;
  min-height: 40px;
  margin: 4px 6px 6px 10px;
  cursor: pointer;
}
.blk-if-body.empty::after {
  content: "+ 点指令加入";
  color: rgba(255, 255, 255, 0.35);
  font-size: 11px;
  padding: 8px 0;
  text-align: center;
}

.blk-palette.blk-loop-add {
  background: linear-gradient(180deg, #43a047, #2e7d32);
}
.blk-palette.if-path { background: linear-gradient(180deg, #ff8a80, #e53935); }
.blk-palette.if-wall { background: linear-gradient(180deg, #9575cd, #5e35b1); }

.program-hint-bar {
  font-size: 11px;
  color: #ff9a8b;
  padding: 6px 12px 0;
  line-height: 1.4;
}
