/* =========================================
   全局变量与基础设置
   ========================================= */
:root {
  --board-size: 500px;
  --inner-size: 400px;
  --cell-size: 100px;
  --piece-size: 60px;
  --bg-color: #f4f4f4;
  --board-bg: #fff;
  --line-color: #000;
}

body {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: var(--bg-color);
  font-family: "Microsoft YaHei", sans-serif;
  user-select: none;
}

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title {
  margin: 10px 0;
  font-size: 28px;
  color: #333;
  font-weight: bold;
}

#status-bar {
  background: #fff;
  padding: 12px 30px;
  border-radius: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  font-size: 18px;
  font-weight: bold;
  color: #d32f2f;
  min-width: 320px;
  text-align: center;
}

/* =========================================
   棋盘区域
   ========================================= */
#game-container {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background-color: var(--board-bg);
  padding: 40px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  box-sizing: border-box;
}

/* 网格线 */
.grid-layer {
  position: absolute;
  top: 40px;
  left: 40px;
  width: var(--inner-size);
  height: var(--inner-size);
  border: 3px solid var(--line-color);
  z-index: 0;
}
.line-h,
.line-v {
  position: absolute;
  background-color: var(--line-color);
}
.line-h {
  width: 100%;
  height: 2px;
  left: 0;
}
.line-v {
  height: 100%;
  width: 2px;
  top: 0;
}

/* 红线层 */
#line-layer {
  position: absolute;
  top: 40px;
  left: 40px;
  width: var(--inner-size);
  height: var(--inner-size);
  z-index: 5;
  pointer-events: none;
  overflow: visible;
}

/* 交互层 */
#interaction-layer {
  position: absolute;
  top: 40px;
  left: 40px;
  width: var(--inner-size);
  height: var(--inner-size);
  z-index: 10;
}

/* =========================================
   格子与棋子
   ========================================= */
.cell {
  position: absolute;
  width: var(--piece-size);
  height: var(--piece-size);
  transform: translate(-50%, -50%);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1;
}

.cell:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

/* --- 棋子 --- */
.piece {
  width: 100%;
  height: 100%;
  position: absolute;
  transition:
    transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    filter 0.3s;
}
.piece.bottom-stack {
  transform: scale(0.8);
  filter: brightness(0.6) grayscale(0.5);
  z-index: 1;
}
.piece.top-stack {
  transform: translateY(-5px) scale(1.05);
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.4));
  z-index: 2;
}

/* --- 状态特效 --- */

/* 1. 选中 */
.cell.selected {
  box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.5);
  background-color: rgba(76, 175, 80, 0.1);
  z-index: 20;
}

/* 2. 可被吃/目标 */
.cell.targetable {
  animation: pulse 1.5s infinite;
  cursor: crosshair;
  z-index: 20;
}
.cell.targetable::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px dashed #f44336;
}

/* 3. 解围目标 (带X) */
.cell.blocker-targetable {
  animation: pulse-red 1s infinite;
  z-index: 50;
  cursor: not-allowed;
}
.cell.blocker-targetable::after {
  content: "X";
  position: absolute;
  color: rgba(255, 0, 0, 0.7);
  font-size: 40px;
  font-weight: bold;
  pointer-events: none;
}

/* 4. 成项高亮 (放大) */
.cell.formation-piece {
  z-index: 30;
}
.cell.formation-piece .piece {
  transform: scale(1.15) !important;
  filter: drop-shadow(0 0 8px rgba(255, 0, 0, 0.6)) brightness(1.1);
}

/* 5. 关键修改：最后一步轨迹标记 (红圈) */
.cell.last-move-marker::before {
  content: "";
  position: absolute;
  /* 比棋子(60px)大一圈，保证不被遮挡 */
  width: 80px;
  height: 80px;
  border: 2px solid rgba(255, 0, 0, 0.6); /* 红色实线 */
  border-radius: 50%;
  transform: translate(-50%, -50%); /* 居中 */
  top: 50%;
  left: 50%;
  pointer-events: none;
  z-index: 0; /* 在棋子下方，但在网格上方 */
  box-shadow: 0 0 8px rgba(255, 0, 0, 0.2);
}

/* =========================================
   动画定义
   ========================================= */
@keyframes pulse {
  0% {
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0.8;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.05);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0.8;
  }
}
@keyframes pulse-red {
  0% {
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.1);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
}

.formation-line {
  transform: none !important;
  filter: drop-shadow(0 0 5px rgba(255, 50, 50, 0.8));
  animation: line-breathe 1.5s infinite ease-in-out;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@keyframes line-breathe {
  0% {
    stroke-width: 5px;
    opacity: 0.7;
  }
  50% {
    stroke-width: 9px;
    opacity: 1;
    filter: drop-shadow(0 0 10px rgba(255, 0, 0, 1));
  }
  100% {
    stroke-width: 5px;
    opacity: 0.7;
  }
}

/* 落子动画 */
.piece.falling {
  animation: fall-down 0.6s ease-out forwards;
  z-index: 100;
}
@keyframes fall-down {
  0% {
    transform: translateY(-40px) scale(1.5);
    opacity: 0;
  }
  60% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  80% {
    transform: translateY(-5px) scale(1.02);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

/* 消除动画 */
.piece.dying {
  transition: all 0.6s ease-in;
  transform: scale(0.1) rotate(180deg);
  opacity: 0;
  filter: sepia(1) hue-rotate(-50deg) saturate(5);
}

/* =========================================
   界面控件
   ========================================= */
.controls {
  margin-top: 25px;
}
button {
  padding: 10px 30px;
  font-size: 16px;
  background-color: #333;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}
button:hover {
  background-color: #555;
}

/* 图例 */
.legend {
  margin-top: 15px;
  display: flex;
  gap: 20px;
  font-size: 14px;
  color: #666;
}
.icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-right: 6px;
}
.stick-icon {
  background: linear-gradient(135deg, #8b4513, #a0522d);
}
.stone-icon {
  background: radial-gradient(circle at 30% 30%, #eee, #555);
}

/* 日志框 */
.game-log {
  margin-top: 20px;
  width: var(--board-size);
  height: 120px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px;
  box-sizing: border-box;
  overflow-y: auto;
  font-size: 14px;
  color: #333;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.log-entry {
  line-height: 1.4;
  border-bottom: 1px dashed #eee;
  padding-bottom: 4px;
}
.log-entry.highlight {
  color: #d32f2f;
  font-weight: bold;
}
.log-entry.system {
  color: #666;
  font-style: italic;
}
