/* 보드 — 작업대 */
#boardWrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
}

/* display:grid/flex가 [hidden] UA 규칙을 눌러버리는 함정 — 화면 스왑 필수 가드 */
#board[hidden], #orders[hidden] { display: none; }

#board, #eventBoard {
  --cell: 46px;
  display: grid;
  grid-template-columns: repeat(7, var(--cell)); /* 이벤트 보드는 팩토리가 inline으로 6열 override */
  grid-auto-rows: var(--cell);
  gap: 3px;
  padding: 8px;
  background: linear-gradient(160deg, #9b7454, var(--wood-dark));
  border-radius: 18px;
  box-shadow: inset 0 2px 10px rgba(0,0,0,.35), var(--shadow);
  touch-action: none; /* 포인터 드래그 */
}

.cell {
  position: relative;
  border-radius: 9px;
  background: #c9a97e;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.22);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell.d1 { background: #a8917366; box-shadow: none; }
.cell.d2 { background: #7d6a5544; box-shadow: none; }
.cell.d1::after, .cell.d2::after {
  content: '🌫️';
  font-size: 18px;
  opacity: .5;
}
.cell.d2::after { opacity: .85; filter: brightness(.6); }

.cell.selected { outline: 3px solid var(--gold); outline-offset: -2px; }
.cell.dropTarget { outline: 3px dashed var(--gold-soft); outline-offset: -2px; }

.piece {
  width: 88%;
  height: 88%;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 단계별 크기 차등 — 플레이스홀더에서 티어를 몸집으로 구분 (t1 작게 → 최고 크게) */
  font-size: calc(var(--cell) * var(--tier-scale, .52));
  background: radial-gradient(120% 120% at 30% 20%, #fff8ea, #f1dfc0);
  box-shadow: 0 2px 4px rgba(0,0,0,.28);
  border-bottom: 3px solid var(--chain-color, var(--wood));
  position: relative;
  isolation: isolate;
}
.piece > * {
  position: relative;
  z-index: 1;
}
.piece .tier {
  position: absolute;
  right: 1px; bottom: 0;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  background: var(--chain-color, var(--wood));
  border-radius: 6px 0 6px 0;
  padding: 0 4px;
  line-height: 15px;
  z-index: 2;
}

/* 드래그 중: 합성 가능한 짝 하이라이트 (장르 표준) */
@keyframes mergeHintPulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 10px #d4a53188; }
  50% { box-shadow: 0 0 0 3px var(--gold), 0 0 18px #d4a531cc; }
}
.cell.mergeHint .piece { animation: mergeHintPulse .9s ease-in-out infinite; }

/* 합성 불가 드롭 피드백 — scale/이동 없는 translate 셰이크 (base transform 없음) */
@keyframes pieceShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}
.piece.shake { animation: pieceShake .3s ease-in-out; }
.piece.maxTier { border-bottom-color: var(--gold); box-shadow: 0 0 8px #d4a53188, 0 2px 4px rgba(0,0,0,.28); }

/* 반입된 실물 스프라이트 — 아트 자체가 티어를 말하므로 몸집 차등 없이 셀에 꽉 차게 */
.piece.hasArt {
  background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.04));
  box-shadow: 0 1px 2px rgba(0,0,0,.16), inset 0 1px 1px rgba(255,255,255,.16);
  border-bottom-width: 2px;
  border-bottom-color: rgba(255,255,255,.2);
}
.piece img.art {
  width: 90%;
  height: 90%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.12));
}

.piece.gen {
  background: radial-gradient(120% 120% at 30% 20%, #ffefc9, #e8c98d);
  border-bottom-color: var(--gold);
}
.piece.gen::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 12px;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
}
@keyframes readyRingPulse {
  0%, 100% { opacity: .35; transform: scale(1); box-shadow: 0 0 0 1px rgba(255, 238, 185, .45), 0 0 0 0 rgba(212, 165, 49, 0); }
  50% { opacity: .95; transform: scale(1.02); box-shadow: 0 0 0 2px rgba(255, 238, 185, .65), 0 0 14px 3px rgba(212, 165, 49, .2); }
}
.piece.gen.ready::before {
  opacity: 1;
  animation: readyRingPulse 2.2s ease-in-out infinite;
}
.piece.gen.cooling::before {
  opacity: 1;
  background: conic-gradient(from -90deg, rgba(212, 165, 49, .98) 0 var(--cool-angle, 0deg), rgba(255, 255, 255, .12) 0 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  box-shadow: 0 0 16px rgba(212, 165, 49, .12);
}
.piece .charges {
  position: absolute;
  left: 1px; top: 0;
  font-size: 9px;
  font-weight: 800;
  color: #fff;
  background: var(--teal);
  border-radius: 0 6px 0 6px;
  padding: 0 3px;
  line-height: 13px;
}
.piece .cd {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(50, 38, 24, .62);
  border-radius: 8px;
  color: #ffe9b8;
  font-size: 11px;
  font-weight: 800;
}

@keyframes focusCellPulse {
  0%, 100% { transform: scale(1); opacity: .72; }
  50% { transform: scale(1.01); opacity: 1; }
}
.cell.focusItem::before,
.cell.focusGen::before {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
}
.cell.focusItem::before {
  box-shadow: inset 0 0 0 2px rgba(244, 213, 132, .9), 0 0 0 1px rgba(255,255,255,.06), 0 0 16px rgba(244, 213, 132, .24);
  animation: focusCellPulse 1.8s ease-in-out infinite;
}
.cell.focusGen::before {
  box-shadow: inset 0 0 0 2px rgba(92, 220, 185, .9), 0 0 0 1px rgba(255,255,255,.05), 0 0 16px rgba(92, 220, 185, .18);
  animation: focusCellPulse 1.8s ease-in-out infinite;
}

/* 머지 팝 — scale만 사용 (base transform 없음: HUD translate 함정 회피) */
@keyframes mergePop {
  0% { transform: scale(.6); }
  55% { transform: scale(1.22); }
  100% { transform: scale(1); }
}
.piece.pop { animation: mergePop .28s ease-out; }

/* 금이음(킨츠기) 머지 — 금빛이 번지는 시그니처 연출 */
@keyframes goldPop {
  0% { transform: scale(.6); box-shadow: 0 0 0 0 rgba(212, 165, 49, 0); }
  45% { transform: scale(1.3); box-shadow: 0 0 26px 6px rgba(212, 165, 49, .95); }
  100% { transform: scale(1); box-shadow: 0 0 8px 2px rgba(212, 165, 49, .45); }
}
.piece.goldPop { animation: goldPop .55s ease-out; }

@keyframes spawnIn {
  0% { transform: scale(.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.piece.spawn { animation: spawnIn .18s ease-out; }

@keyframes dustClear {
  0% { opacity: 1; }
  100% { opacity: 0; }
}
.cell.dusted::after { animation: dustClear .5s ease-out forwards; }

/* 배출 궤적·납품 흡수 비행 오버레이 — boardView.js flyOverlay가 fromRect 크기로 인라인 지정, 자식은 원본 .piece 복제 */
.flyGhost {
  position: fixed;
  z-index: 45;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#dragGhost {
  position: fixed;
  z-index: 50;
  /* width/height/font-size는 boardView.js가 현재 --cell 크기에 맞춰 인라인으로 지정 — 아래는 폴백 기본값 */
  width: 46px; height: 46px;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  filter: drop-shadow(0 6px 8px rgba(0,0,0,.35));
}
