/* codex: 2026-09-29 board.css 严密暗格底盘、严格等比纸片暗格细分与米白/暗色双主题适配 */

.board-container {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 14px;
  overflow: visible;
  transition: all 0.2s ease;
}

/* 棋盘实体外框 */
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--grid-n), var(--cell-size));
  grid-template-rows: repeat(var(--grid-n), var(--cell-size));
  background: var(--board-bg, #090e1a);
  border: 3px solid var(--board-border, #334155);
  border-radius: 6px;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.35),
    0 0 0 1px var(--board-outline, rgba(255, 255, 255, 0.12));
  user-select: none;
  touch-action: none;
}

/* 棋盘背景暗格层 (明确绘制每一个1x1格子，大幅增强亮度与对比) */
.grid-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-n), var(--cell-size));
  grid-template-rows: repeat(var(--grid-n), var(--cell-size));
  pointer-events: none;
  background: var(--grid-bg, #0b1120);
}

.grid-cell {
  border-right: 1px solid var(--grid-line, rgba(255, 255, 255, 0.18));
  border-bottom: 1px solid var(--grid-line, rgba(255, 255, 255, 0.18));
  background: var(--cell-bg-1, rgba(30, 41, 59, 0.4));
  box-sizing: border-box;
}

.grid-cell:nth-child(even) {
  background: var(--cell-bg-2, rgba(30, 41, 59, 0.65));
}

/* 棋子放置层 */
.tiles-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-n), var(--cell-size));
  grid-template-rows: repeat(var(--grid-n), var(--cell-size));
  pointer-events: none;
}

/* 正方形纸片：加入暗格分割线，严丝合缝贴合，无外缩变形 */
.board-tile, .floating-drag-tile {
  pointer-events: auto;
  position: relative;
  border-radius: 2px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  overflow: hidden;
  /* 内部暗格细分线：黑透分界线，高对比可辨 */
  background-image:
    linear-gradient(to right, rgba(0, 0, 0, 0.38) 1.5px, transparent 1.5px),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.38) 1.5px, transparent 1.5px);
}

.board-tile {
  cursor: grab;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.board-tile:active {
  cursor: grabbing;
}

/* 严格按比例划分纸片内部暗格：
   6x6 严格 6 等分 (16.666667%)，5x5 严格 5 等分 (20%)，4x4 严格 4 等分 (25%)，3x3 严格 3 等分 (33.333%)，2x2 严格 2 等分 (50%) */
.tile-size-6, .tile-color-6 {
  background-color: #7c3aed;
  border-color: #a78bfa;
  background-size: 16.666667% 16.666667% !important;
}

.tile-size-5, .tile-color-5 {
  background-color: #0891b2;
  border-color: #38bdf8;
  background-size: 20% 20% !important;
}

.tile-size-4, .tile-color-4 {
  background-color: #4f46e5;
  border-color: #818cf8;
  background-size: 25% 25% !important;
}

.tile-size-3, .tile-color-3 {
  background-color: #059669;
  border-color: #34d399;
  background-size: 33.333333% 33.333333% !important;
}

.tile-size-2, .tile-color-2 {
  background-color: #d97706;
  border-color: #fbbf24;
  background-size: 50% 50% !important;
}

.tile-size-1, .tile-color-1 {
  background-color: #e11d48;
  border-color: #fb7185;
  background-size: 100% 100% !important;
}

.tile-badge {
  font-size: clamp(0.72rem, 1.8vw, 0.95rem);
  font-weight: 800;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 1px 6px;
  border-radius: 4px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 2;
}

.btn-tile-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: none;
  font-size: 13px;
  line-height: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  z-index: 5;
}

.board-tile:hover .btn-tile-remove {
  opacity: 1;
}

.btn-tile-remove:hover {
  background: #ef4444;
}

/* 吸附幽灵预览（像素级严密对齐网格） */
.placement-ghost {
  display: none;
  position: relative;
  box-sizing: border-box;
  border-radius: 2px;
  pointer-events: none;
  z-index: 10;
}

.ghost-valid {
  background: rgba(52, 211, 153, 0.35);
  border: 2px solid #10b981;
}

.ghost-invalid {
  background: rgba(239, 68, 68, 0.4);
  border: 2px solid #ef4444;
}

.ghost-hint-pulse {
  background: rgba(251, 191, 36, 0.45);
  border: 2px solid #f59e0b;
  animation: pulse-glow 1s infinite alternate ease-in-out;
}

@keyframes pulse-glow {
  0% { opacity: 0.5; }
  100% { opacity: 0.95; }
}

/* 纸片备料区与垃圾桶 */
.tray-wrapper {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.tray-title-text {
  font-size: 0.86rem;
  color: var(--text-muted);
  text-align: center;
}

.tray-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 12px 22px;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  flex-wrap: wrap;
}

.tray-item {
  position: relative;
  border-radius: 4px;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  touch-action: none;
  user-select: none;
  box-sizing: border-box;
  background-image:
    linear-gradient(to right, rgba(0, 0, 0, 0.3) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.3) 1px, transparent 1px);
}

.tray-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}

.tray-item:active {
  cursor: grabbing;
}

.tray-item.selected {
  outline: 3px solid #38bdf8;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.7);
  transform: translateY(-2px);
}

.tray-size-6 { width: 92px; height: 92px; font-size: 1.15rem; }
.tray-size-5 { width: 80px; height: 80px; font-size: 1.05rem; }
.tray-size-4 { width: 70px; height: 70px; font-size: 0.98rem; }
.tray-size-3 { width: 58px; height: 58px; font-size: 0.9rem; }
.tray-size-2 { width: 46px; height: 46px; font-size: 0.82rem; }
.tray-size-1 { width: 34px; height: 34px; font-size: 0.75rem; }

/* 丢弃垃圾桶区域 */
.trash-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(239, 68, 68, 0.12);
  border: 1.5px dashed rgba(239, 68, 68, 0.35);
  color: #f87171;
  padding: 6px 20px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  opacity: 0.8;
  transition: all 0.2s ease;
}

.trash-active {
  opacity: 1;
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.28);
}

.trash-hover {
  background: rgba(239, 68, 68, 0.55);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.75);
}
