/* --- 积木工坊：Scratch 风格拼搭画布 --------------------------------------
   凸口/凹口/贝塞尔连线/分类配色，亮暗主题各一套表面。
   所有选择器 .blk-* 作用域封闭，不与其它页面样式冲突。 -------------------- */

.blk-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .blk-layout { grid-template-columns: 1fr; } }

/* 积木抽屉 */
.blk-drawer { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-hairline); }
.blk-drawer h3 { margin: 0 0 2px; font-size: 15px; }
.blk-drawer .help { margin: 0 0 6px; }
.blk-chip {
  border: 0; cursor: pointer; text-align: left; padding: 9px 12px 9px 14px;
  font-size: 13.5px; font-weight: 600; color: #fff;
  border-radius: 12px 4px 12px 4px; box-shadow: 0 2px 0 rgba(0,0,0,.18);
  transition: transform .15s cubic-bezier(.23,1,.32,1), filter .15s;
}
.blk-chip:hover { transform: translateX(3px); filter: brightness(1.08); }

/* 分类色（Scratch 调色板映射到校鱼暖纸底） */
.c-model   { background: #7b5ea7; }
.c-text    { background: #3f7fd6; }
.c-canvas  { background: #2a9d8f; }
.c-sampler { background: #d97934; }
.c-output  { background: #3d8b5f; }

/* 画布 */
.blk-canvas {
  overflow: auto; max-height: 680px; border-radius: 16px;
  background:
    radial-gradient(color-mix(in srgb, var(--ink) 14%, transparent) 1px, transparent 1.5px);
  background-size: 22px 22px;
  box-shadow: inset 0 0 0 1px var(--line);
}
html.dark .blk-canvas { background: radial-gradient(rgba(196,226,208,.12) 1px, transparent 1.5px); background-size: 22px 22px; }
.blk-surface { position: relative; min-width: 900px; min-height: 560px; transition: width 240ms cubic-bezier(.25,1,.5,1), height 240ms cubic-bezier(.25,1,.5,1); }
.blk-wires { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.blk-wire { fill: none; stroke-width: 3.5; stroke-linecap: round; pointer-events: none; opacity: .85; }
.blk-wire.t-model { stroke: #7b5ea7; }
.blk-wire.t-text { stroke: #3f7fd6; }
.blk-wire.t-canvas { stroke: #2a9d8f; }
.blk-wire.t-output { stroke: #3d8b5f; }
.blk-wire.t-sampler { stroke: #d97934; }
.blk-wire.temp { stroke-dasharray: 7 6; opacity: .9; }
.blk-wire-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.blk-wire-hit:hover + .blk-wire { opacity: .4; }

/* 积木块 */
.blk {
  position: absolute; min-width: 216px; max-width: 280px;
  background: var(--surface); border-radius: 14px;
  box-shadow: 0 1px 0 rgba(0,0,0,.05), 0 6px 18px rgba(15,25,20,.12);
  user-select: none;
}
.blk:has(.blk-head:active) { box-shadow: 0 10px 26px rgba(15,25,20,.22); }
html.dark .blk { background: var(--surface); box-shadow: 0 6px 18px rgba(0,0,0,.4); }
.blk-head {
  display: flex; align-items: center; gap: 7px; padding: 8px 10px;
  color: #fff; font-size: 13.5px; border-radius: 14px 14px 0 0; cursor: grab; touch-action: none;
}
.blk-head:active { cursor: grabbing; }
.blk-grip { opacity: .7; letter-spacing: -1px; }
.blk-del {
  margin-left: auto; border: 0; background: rgba(255,255,255,.18); color: #fff;
  width: 20px; height: 20px; border-radius: 6px; cursor: pointer; line-height: 1; font-size: 13px;
}
.blk-del:hover { background: rgba(255,255,255,.34); }
.blk-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.blk-field { display: flex; flex-direction: column; gap: 3px; position: relative; }
.blk-field small { color: var(--ink-2); font-size: 11.5px; }
.blk-field input, .blk-field textarea, .blk-field select {
  font: inherit; font-size: 12.5px; padding: 5px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--inset); color: var(--ink); width: 100%;
}
.blk-field textarea { resize: vertical; min-height: 44px; }
.blk-field input:focus, .blk-field textarea:focus, .blk-field select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
.blk-dice { position: absolute; right: 4px; bottom: 4px; border: 0; background: transparent; cursor: pointer; font-size: 13px; padding: 2px; }
.blk-toolbar { margin-bottom: 10px; }

/* 端口：凸口在右缘，凹口在左缘 */
.blk-ports { position: absolute; top: 0; display: flex; flex-direction: column; gap: 12px; padding-top: 38px; }
.blk-ins { left: -8px; }
.blk-outs { right: -8px; }
.blk-port {
  width: 15px; height: 15px; border-radius: 50%; box-sizing: border-box;
  background: var(--surface); cursor: crosshair; touch-action: none; flex: none;
}
.blk-port.in { border: 3px solid; }
.blk-port.out { border: 3px solid; background: currentColor; }
.blk-port.t-model { border-color: #7b5ea7; color: #7b5ea7; }
.blk-port.t-text { border-color: #3f7fd6; color: #3f7fd6; }
.blk-port.t-canvas { border-color: #2a9d8f; color: #2a9d8f; }
.blk-port.t-output { border-color: #3d8b5f; color: #3d8b5f; }
.blk-port:hover { transform: scale(1.25); }

@media (prefers-reduced-motion: reduce) {
  .blk-chip, .blk-port { transition: none; }
}

/* 交互动效：新积木落位、拖动投影、连线绘制（尊重 prefers-reduced-motion） */
@media (prefers-reduced-motion: no-preference) {
  @keyframes blk-land {
    0%   { opacity: 0; transform: translateY(8px) scale(.92); }
    60%  { transform: translateY(-2px) scale(1.015); }
    100% { opacity: 1; transform: none; }
  }
  .blk-land { animation: blk-land 320ms cubic-bezier(.23,1,.32,1); }
  .blk { transition: box-shadow .18s ease; }
  .blk:has(.blk-head:active) { transition: box-shadow .18s ease; }
  @keyframes wire-draw {
    from { stroke-dashoffset: var(--wire-len, 600); }
    to   { stroke-dashoffset: 0; }
  }
  .blk-wire.draw { stroke-dasharray: none; animation: wire-draw 380ms cubic-bezier(.25,1,.5,1) both; }
  /* 连线成功后端口轻微回弹，确认「接上了」 */
  @keyframes port-pulse {
    0%   { transform: scale(1); }
    45%  { transform: scale(1.5); }
    100% { transform: scale(1); }
  }
  .blk-port.pulse { animation: port-pulse 360ms ease-out; }
}
