/*
 * Sam Kido - 📐 Phòng Hình Khối (spatial-lab.js)
 * Mọi lớp mới đều có tiền tố sp-
 * Mục tiêu: hình SVG đọc được rõ ở màn 360px, vùng chạm >= 48px, không tràn ngang.
 */

/* ================= KHUNG CHUNG ================= */
.game-card.sp-card {
  max-width: 100%;
  overflow: hidden;
}

.sp-card .section-instruction small {
  display: block;
  margin-top: 4px;
  font-size: 0.92rem;
  color: #718096;
}

.sp-card .feedback-msg.sp-info {
  background: #E8F7FF;
  color: #075985;
  border: 2px solid #90E0EF;
}

.sp-red {
  color: #E01B45;
}

.sp-btn {
  min-height: 52px;
  padding: 10px 20px;
  border-radius: 20px;
  border: 3px solid #CBD5E0;
  background: white;
  color: #2D3748;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 5px 0 #A0AEC0;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
}

.sp-btn:hover:not(:disabled) { transform: translateY(-2px); }
.sp-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #A0AEC0; }
.sp-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sp-btn-soft { background: #F7FAFC; }

.sp-rotate-btn {
  background: linear-gradient(180deg, #FFE07A, var(--primary-yellow));
  border-color: #C9A227;
  color: #6B4A00;
  box-shadow: 0 5px 0 #A37E12;
}
.sp-rotate-btn:active:not(:disabled) { box-shadow: 0 2px 0 #A37E12; }

.sp-btn-next {
  margin-top: 12px;
  background: linear-gradient(180deg, #60C5FF, var(--primary-blue));
  border-color: #1E88D8;
  color: white;
  box-shadow: 0 5px 0 #1569A8;
}
.sp-btn-next:active:not(:disabled) { box-shadow: 0 2px 0 #1569A8; }

.sp-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

@keyframes spShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.sp-shake { animation: spShake 0.5s ease; }

/* ================= LỰA CHỌN TRẮC NGHIỆM ================= */
.sp-card .options-grid.sp-opts {
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 12px;
  max-width: 560px;
}

.game-opt-btn.sp-opt {
  position: relative;
  padding: 12px 10px 10px;
  min-height: 124px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #FCFDFF;
  touch-action: manipulation;
}

.game-opt-btn.sp-opt.sk-eliminated {
  opacity: 0.35;
}

.sp-opt-num {
  position: absolute;
  top: 6px;
  left: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #EDF2F7;
  color: #4A5568;
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 24px;
  text-align: center;
  pointer-events: none;
}

.game-opt-btn.sp-opt.correct-answer .sp-opt-num,
.game-opt-btn.sp-opt.wrong-answer .sp-opt-num {
  background: rgba(255, 255, 255, 0.85);
  color: #2D3748;
}

.game-opt-btn.sp-opt-num-big {
  min-height: 72px;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sp-opt .sp-fig,
.sp-opt .sp-sheet-svg,
.sp-opt .sp-view-svg {
  display: block;
  width: 100%;
  max-width: 142px;
  height: 100px;
}

/* ================= 1. XOAY HÌNH TRONG ĐẦU ================= */
.sp-ref-wrap {
  display: flex;
  justify-content: center;
  margin: 4px 0 14px;
}

.sp-ref-box {
  position: relative;
  padding: 14px 18px 10px;
  border-radius: 26px;
  background: linear-gradient(180deg, #FFFBEF, #FFF3D6);
  border: 4px dashed #FFD13B;
  min-width: 150px;
}

.sp-ref-box.sp-spinning {
  border-style: solid;
  border-color: #38D39F;
  background: linear-gradient(180deg, #F2FFFA, #DFFBEF);
}

.sp-tag {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-yellow);
  color: #6B4A00;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.85rem;
  padding: 3px 14px;
  border-radius: 14px;
  white-space: nowrap;
}

.sp-ref-box .sp-fig {
  display: block;
  width: 130px;
  height: 130px;
}

/* ================= 2. GẤP GIẤY ĐOÁN HÌNH ================= */
.sp-steps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 2px;
  padding: 12px 6px;
  margin-bottom: 14px;
  background: #F8FBFF;
  border: 3px dashed #D6E4FF;
  border-radius: 24px;
}

.sp-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.sp-step-pic {
  background: white;
  border-radius: 14px;
  border: 2px solid #E2E8F0;
  padding: 2px;
}

.sp-step-svg {
  display: block;
  width: 72px;
  height: 72px;
}

.sp-step-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #5A6270;
  text-align: center;
  max-width: 82px;
  line-height: 1.2;
}

.sp-step-arrow {
  font-size: 1rem;
  color: #8AA2BD;
  padding: 0 1px;
  align-self: center;
  margin-bottom: 14px;
}

/* ================= 3. NHÌN TỪ TRÊN XUỐNG ================= */
.sp-scene {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
  padding: 8px;
  background: linear-gradient(180deg, #FBFDFF, #EEF5FF);
  border: 3px solid #E2EBF6;
  border-radius: 26px;
}

.sp-iso-svg {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  max-height: 230px;
}

/* ================= 4. GHÉP HÌNH THEO MẪU ================= */
.sp-build-stage {
  display: flex;
  justify-content: center;
  padding: 10px;
  margin-bottom: 12px;
  background: #FBFDFF;
  border: 3px solid #E2EBF6;
  border-radius: 26px;
}

.sp-target-svg {
  display: block;
  width: 100%;
  max-width: 290px;
  height: auto;
  max-height: 290px;
  touch-action: manipulation;
}

.sp-slot {
  pointer-events: all;
  cursor: pointer;
}

.sp-slot:hover {
  fill: rgba(58, 168, 247, 0.22);
}

.sp-slot-full:hover {
  fill: rgba(255, 255, 255, 0.3);
}

.sp-slot-done {
  animation: spPop 0.3s ease;
}

@keyframes spPop {
  0% { transform: scale(0.75); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

.sp-tray-label {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 800;
  color: #5A6270;
  margin-bottom: 6px;
}

.sp-tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  background: #F8FBFF;
  border: 3px dashed #D6E4FF;
  border-radius: 24px;
}

.sp-piece {
  width: 80px;
  height: 80px;
  padding: 4px;
  border-radius: 18px;
  border: 3px solid #D8E2EF;
  background: white;
  cursor: pointer;
  box-shadow: 0 4px 0 #BCCBDC;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  touch-action: manipulation;
}

.sp-piece:hover:not(:disabled) { transform: translateY(-3px); }
.sp-piece:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #BCCBDC; }

.sp-piece-sel {
  border-color: var(--primary-blue);
  box-shadow: 0 4px 0 #1E88D8, 0 0 0 4px rgba(58, 168, 247, 0.25);
  background: #F2FAFF;
}

.sp-piece-used {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

.sp-piece-svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ================= MÀN HÌNH NHỎ ================= */
@media (max-width: 600px) {
  .game-card.sp-card {
    padding: 16px 12px;
    border-radius: 24px;
  }

  .sp-card .game-question {
    font-size: 1.2rem;
    margin-bottom: 14px;
  }

  .sp-card .section-instruction {
    font-size: 0.98rem;
    margin-bottom: 14px;
  }

  .sp-card .options-grid.sp-opts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .game-opt-btn.sp-opt {
    min-height: 116px;
    padding: 10px 6px 8px;
    border-radius: 20px;
  }

  .sp-opt .sp-fig,
  .sp-opt .sp-sheet-svg,
  .sp-opt .sp-view-svg {
    height: 96px;
    max-width: 100%;
  }

  .sp-ref-box .sp-fig {
    width: 112px;
    height: 112px;
  }

  .sp-step-svg {
    width: 60px;
    height: 60px;
  }

  .sp-step-label {
    font-size: 0.7rem;
    max-width: 64px;
  }

  .sp-step-arrow {
    font-size: 0.82rem;
    margin-bottom: 12px;
  }

  .sp-steps {
    padding: 10px 2px;
    gap: 2px 0;
  }

  .sp-iso-svg {
    max-width: 100%;
    max-height: 200px;
  }

  .sp-target-svg {
    max-width: 100%;
    max-height: 252px;
  }

  .sp-piece {
    width: 72px;
    height: 72px;
  }

  .sp-btn {
    min-height: 50px;
    font-size: 1rem;
    padding: 10px 16px;
  }
}

@media (max-width: 380px) {
  .sp-step-svg { width: 52px; height: 52px; }
  .sp-step-label { font-size: 0.64rem; max-width: 56px; }
  .sp-step-arrow { font-size: 0.7rem; padding: 0; }
  .sp-piece { width: 66px; height: 66px; }
}

/* Máy tính: hình to hơn cho dễ nhìn */
@media (min-width: 900px) {
  .sp-ref-box .sp-fig { width: 160px; height: 160px; }
  .sp-opt .sp-fig,
  .sp-opt .sp-sheet-svg,
  .sp-opt .sp-view-svg { height: 124px; max-width: 160px; }
  .game-opt-btn.sp-opt { min-height: 150px; }
  .sp-step-svg { width: 92px; height: 92px; }
  .sp-step-label { max-width: 100px; font-size: 0.85rem; }
  .sp-iso-svg { max-width: 340px; max-height: 280px; }
  .sp-target-svg { max-width: 340px; max-height: 340px; }
}

@media (prefers-reduced-motion: reduce) {
  .sp-shake,
  .sp-slot-done {
    animation: none;
  }
  .sp-btn,
  .sp-piece {
    transition: none;
  }
}
