/* ============================================================
   PixelCraft — Studio kéo thả (studio.js).
   Dùng đúng token của pc.css (--surface, --line, --r-lg, --shadow-md…).
   Canvas: nền lưới chấm; thẻ 280px, kéo bằng đầu thẻ; trên điện thoại
   (<=720px) canvas thành danh sách dọc, tắt zoom/kéo.
   ============================================================ */

/* ---------- Đầu trang + cài đặt ---------- */
.sd-head { align-items: flex-start; }
.sd-head .btn { flex: none; margin-top: 2px; }
.sd-tools { display: flex; gap: 20px 28px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.sd-set { min-width: 0; }
.sd-set .flabel { margin-bottom: 6px; }
.sd-set .ratios { min-width: 260px; }
.sd-go { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.sd-go .btn { height: 50px; font-size: 15px; }
.sd-count { font-size: 12.5px; color: var(--muted); text-align: right; }

/* ---------- Canvas lưới chấm ---------- */
.sd-canvas {
  position: relative; overflow: hidden; height: 70vh; min-height: 480px;
  border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--bg-2);
  touch-action: none;
}
.sd-layer {
  position: absolute; top: 0; left: 0; width: 4000px; height: 3000px;
  transform-origin: 0 0;
  background-image: radial-gradient(var(--line-2) 1.1px, transparent 1.2px);
  background-size: 24px 24px;
}
.sd-empty { margin-top: 14px; text-align: center; color: var(--text-2); }
.sd-empty h3 { font-size: 16px; color: var(--text); }
.sd-empty p { font-size: 13.5px; margin-top: 4px; }

/* ---------- Thẻ ---------- */
.sd-card {
  position: absolute; width: 280px; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-md); overflow: hidden;
}
.sd-card-h {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 10px;
  border-bottom: 1px solid var(--line); cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.sd-card-h:active { cursor: grabbing; }
.sd-grip {
  flex: none; width: 14px; height: 14px; opacity: .55;
  background-image: radial-gradient(var(--muted) 1.2px, transparent 1.3px);
  background-size: 5px 5px;
}
.sd-card-t {
  flex: 1 1 auto; min-width: 0; font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sd-card .sd-x { width: 30px; height: 30px; flex: none; }
.sd-media { aspect-ratio: 16/10; background: #07080a; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.sd-media img, .sd-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.sd-media video { object-fit: contain; background: #000; }
.sd-nophoto { color: var(--muted); display: flex; }
.sd-card .sd-prompt {
  margin: 10px 10px 0; min-height: 76px; resize: vertical;
  padding: 10px 12px; line-height: 1.5; height: auto; font-size: 13.5px;
}
.sd-foot { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px; }
.sd-foot .btn { margin-left: auto; }
.sd-foot .btn:first-child { margin-left: 0; }
.sd-st { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.sd-st.run { color: var(--accent-text); }
.sd-st.done { color: var(--ok); }
.sd-st.fail { color: var(--err); }
.sd-err { font-size: 12.5px; color: var(--err); line-height: 1.4; flex-basis: 100%; }

/* ---------- Thanh zoom (góc dưới canvas) ---------- */
.sd-zoom {
  position: absolute; right: 12px; bottom: 12px; z-index: 5;
  display: flex; align-items: center; gap: 6px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
}
.sd-zoom .icb { width: 32px; height: 32px; font-size: 18px; line-height: 1; }
.sd-zoom-pct { min-width: 44px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-2); }

/* ---------- Modal chọn nguồn / xác nhận ---------- */
.sd-ov {
  position: fixed; inset: 0; z-index: 950; background: rgba(5, 6, 8, .72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sd-dlg {
  width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.sd-dlg .cm-b { overflow-y: auto; }
.sd-pick { display: grid; gap: 10px; }
.sd-pick .btn { justify-content: center; }
.sd-cell-nm {
  display: block; font-size: 12px; color: var(--text-2); text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 4px 2px 0;
}
.sd-dlg .bt-low { color: var(--err); }

/* ---------- Điện thoại: danh sách dọc, không zoom/kéo ---------- */
@media (max-width: 720px) {
  .sd-head { flex-direction: column; }
  .sd-head .btn { width: 100%; justify-content: center; }
  .sd-tools { gap: 14px; }
  .sd-set { width: 100%; }
  .sd-set .ratios { min-width: 0; width: 100%; }
  .sd-go { margin-left: 0; width: 100%; align-items: stretch; }
  .sd-go .btn { width: 100%; }
  .sd-count { text-align: left; }
  .sd-canvas {
    height: auto; min-height: 0; overflow: visible;
    border: 0; background: transparent; border-radius: 0; touch-action: auto;
  }
  .sd-layer {
    position: static; width: auto; height: auto; transform: none !important;
    background: none; display: grid; gap: 12px;
  }
  .sd-card { position: static !important; width: 100%; max-width: 520px; }
  .sd-card-h { cursor: default; }
  .sd-zoom { display: none; }
}
