.hidden { display: none !important; }
* { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #eef3fb;
  color: #2b2b3a;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  min-height: 100vh;
  margin: 0;
  overflow: auto;
}
h1 { font-size: 1.5rem; margin: 0 0 14px; color: #5b4bc4; }
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  background: #ffffff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(90, 110, 150, 0.12);
}
.controls label { font-size: 0.9rem; }
select, button {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #c3d0e4;
  background: #f4f8ff;
  color: #2b2b3a;
  font-size: 0.9rem;
  cursor: pointer;
}
select:disabled { opacity: 0.55; cursor: not-allowed; }
button:hover { background: #e1ecfb; border-color: #9fb8db; }
.status {
  font-size: 1rem;
  margin-bottom: 12px;
  display: flex;
  gap: 20px;
  align-items: center;
  color: #2b2b3a;
}
.score-black { color: #111; background: #ddd; padding: 2px 10px; border-radius: 12px; }
.score-white { color: #111; background: #fff; padding: 2px 10px; border-radius: 12px; }
.turn-indicator {
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
  border: 2px solid #9aa7bb;
}
.turn-black { background: #111; }
.turn-white { background: #fff; }

/* ===== 棋盘 ===== */
/* width / gap / padding 由 JS 按屏幕算好再写进来，这里只留默认值 */
#board {
  display: grid;
  gap: 2px;
  background: #3f9d6e;
  padding: 6px;
  border-radius: 10px;
  box-shadow: 0 8px 26px rgba(50, 90, 120, 0.22);
}
/* 【改】去掉固定 44px，用 aspect-ratio 跟着网格列宽自动缩放 */
.cell {
  aspect-ratio: 1;
  background: #7fce9f;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}
/* 【改】hover 只在有鼠标的设备上生效，避免触摸屏"点完一直亮" */
@media (hover: hover) {
  .cell:hover { background: #a2e0bb; }
}
/* 【新增】触摸设备上，被选中待确认的格子 */
.cell.selected {
  background: #ffe9a8;
  box-shadow: inset 0 0 0 3px #ffb703;
}
/* 【改】提示点也改成百分比 */
.cell.legal::after {
  content: '';
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
  position: absolute;
}
/* 【改】棋子改成百分比，跟着格子缩放 */
.piece {
  width: 77%;
  height: 77%;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  transition: opacity 0.15s ease;
}
.piece.black { background: radial-gradient(circle at 35% 35%, #555, #111); }
.piece.white { background: radial-gradient(circle at 35% 35%, #fff, #ccc); }
.piece.flipping { animation: flip 0.5s ease-in-out forwards; }
@keyframes flip {
  0% { transform: scaleX(1); }
  50% { transform: scaleX(0); }
  100% { transform: scaleX(1); }
}
.cell.last-move { box-shadow: inset 0 0 0 3px #ffd166; }
.piece.will-flip { opacity: 0.5; }

/* ===== 棋盘下方按钮区 ===== */
.game-buttons {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 54px;
}
.btn-start {
  font-size: 1.15rem;
  padding: 13px 64px;
  background: #22a559;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(34, 165, 89, 0.35);
  transition: background 0.15s, transform 0.1s;
}
.btn-start:hover { background: #1e9450; }
.btn-start:active { transform: translateY(1px); }
.play-controls { display: flex; gap: 16px; }
.play-controls button {
  font-size: 1rem;
  padding: 10px 40px;
  border-radius: 10px;
  cursor: pointer;
}
.btn-giveup { background: #f4f8ff; border: 1px solid #c3d0e4; }
.btn-giveup:hover { background: #ffe5e5; border-color: #e0a3a3; }

/* 【新增】确认按钮 */
.btn-confirm {
  background: #22a559;
  color: #fff;
  border: 1px solid #1e9450;
  font-weight: 600;
}
.btn-confirm:hover { background: #1e9450; }
.btn-confirm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #a9c9b7;
  border-color: #88a898;
}

/* ===== 结算弹窗（未改） ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 50, 70, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.overlay.hidden { display: none; }
.modal {
  background: #ffffff;
  border: none;
  border-radius: 20px;
  padding: 44px 64px;
  min-width: 400px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(40, 60, 90, 0.4);
}
.modal h2 { margin: 0 0 20px; font-size: 2rem; color: #5b4bc4; }
.modal-score { margin: 0 0 32px; font-size: 1.3rem; color: #2b2b3a; }
.modal-buttons { display: flex; gap: 14px; justify-content: center; }
.modal-buttons button { padding: 10px 22px; font-size: 1rem; border-radius: 10px; }

/* ============================================================
   【新增】手机适配
   ============================================================ */
@media (max-width: 700px) {
  body { padding: 8px; }
  h1 { font-size: 1.15rem; margin: 0 0 8px; }

  /* 顶部三个选择框排成一排 */
  .controls {
    flex-wrap: nowrap;
    width: 100%;
    padding: 8px 10px;
    gap: 6px;
    margin-bottom: 10px;
  }
  .controls label {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.72rem;
    line-height: 1.2;
    white-space: nowrap;
  }
  .controls select {
    width: 100%;
    min-width: 0;
    padding: 4px 2px;
    font-size: 0.78rem;
    text-align: center;
  }

  .status {
    gap: 10px;
    font-size: 0.85rem;
    margin-bottom: 10px;
    white-space: nowrap;
  }
  .turn-indicator { width: 14px; height: 14px; margin-right: 4px; }

  #board { border-radius: 8px; }

  /* 按钮铺满一行，方便手指按 */
  .game-buttons { margin-top: 14px; width: 100%; }
  .btn-start { width: 100%; padding: 12px 0; font-size: 1rem; }
  .play-controls { width: 100%; gap: 8px; }
  .play-controls button { flex: 1 1 0; padding: 11px 0; font-size: 0.88rem; }

  /* 手机上不要长按选中 / 蓝色高亮 / 双击缩放 */
  .cell, button, select {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
  }
}
/* ===== 游戏说明按钮 ===== */
.help-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 900;               /* 低于弹窗遮罩，弹窗打开时会被盖住 */
  padding: 6px 14px;
  font-size: 0.82rem;
  border-radius: 20px;
  border: 1px solid #c3d0e4;
  background: #ffffff;
  color: #5b4bc4;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(90, 110, 150, 0.15);
  transition: background 0.15s, box-shadow 0.15s;
}
.help-btn:hover {
  background: #f4f8ff;
  box-shadow: 0 4px 12px rgba(90, 110, 150, 0.25);
}

/* ===== 游戏说明弹窗 ===== */
.help-modal {
  max-width: 560px;
  width: calc(100vw - 40px);
  min-width: 0;               /* 覆盖 .modal 的 min-width，防止小屏溢出 */
  padding: 32px 36px 28px;
  text-align: left;
  max-height: 80vh;
  overflow-y: auto;
}
.help-modal h2 {
  text-align: center;
  margin: 0 0 16px;
}
.help-body {
  font-size: 0.92rem;
  line-height: 1.65;
  color: #2b2b3a;
}
.help-body h3 {
  font-size: 1rem;
  color: #5b4bc4;
  margin: 18px 0 6px;
}
.help-body p {
  margin: 6px 0;
}
.help-body ul {
  margin: 6px 0;
  padding-left: 20px;
}
.help-body li {
  margin: 4px 0;
}
.help-body b {
  color: #1f1f2e;
}
.help-example {
  background: #f4f8ff;
  border-left: 4px solid #5b4bc4;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 14px;
  font-size: 0.88rem;
  line-height: 1.6;
}
.help-modal .modal-buttons {
  margin-top: 22px;
}

/* 手机适配 */
@media (max-width: 700px) {
  .help-btn {
    top: 8px;
    right: 8px;
    padding: 5px 10px;
    font-size: 0.72rem;
  }
  .help-modal {
    width: calc(100vw - 24px);
    padding: 22px 18px 18px;
    max-height: 85vh;
  }
  .help-body {
    font-size: 0.85rem;
  }
}