/* =============================================================================
 * 圈叉棋（井字棋）小游戏样式（shijinwa.com/games/，见 docs/12 §8.15）
 *
 * 🔴 与 site.css 同一纪律：完全自包含，不引用任何外部资源（无字体/图标/图片）；
 *    卡通感全部来自原生 CSS（厚描边、圆角、贴纸式投影）与内联 SVG。
 * 🔴 动画（云朵飘动 / 弹跳 / 撒花）在 prefers-reduced-motion 下全部停用。
 * ========================================================================== */

.game-world {
  --o-main: #ff9d3b;
  --o-deep: #e07f16;
  --x-main: #2fb9a6;
  --x-deep: #1d8f81;
  --gold: #f5b942;
  --ink-brown: #5b4636;

  position: relative;
  overflow: hidden;
  padding: 56px 0 72px;
  background: linear-gradient(180deg, #c9ecff 0%, #e8f7ff 52%, #fdf6e3 100%);
}

/* ── 天空装饰：太阳 / 云朵 / 小山（纯 CSS，纯装饰）──────────────────────── */
.sky-deco { position: absolute; inset: 0; pointer-events: none; }
.sun {
  position: absolute;
  top: 34px;
  right: 8%;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: #ffd23f;
  box-shadow: 0 0 0 14px rgba(255, 210, 63, .28), 0 0 0 30px rgba(255, 210, 63, .13);
}
.cloud {
  position: absolute;
  width: 108px;
  height: 34px;
  border-radius: 999px;
  background: #fff;
  opacity: .92;
}
.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: #fff;
}
.cloud::before { width: 44px; height: 44px; top: -22px; left: 18px; }
.cloud::after  { width: 30px; height: 30px; top: -13px; right: 22px; }
.cloud.c1 { top: 40px;  left: 6%;  animation: cloud-drift 46s linear infinite; }
.cloud.c2 { top: 108px; left: 58%; animation: cloud-drift 62s linear infinite; animation-delay: -30s; }
.cloud.c3 { top: 26px;  left: 38%; width: 84px; height: 27px; opacity: .8; animation: cloud-drift 54s linear infinite; animation-delay: -14s; }
@keyframes cloud-drift {
  from { transform: translateX(-16vw); }
  to   { transform: translateX(120vw); }
}
.hill {
  position: absolute;
  bottom: -46px;
  height: 130px;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}
.hill-1 { left: -14%; width: 64%; background: #cdeec9; }
.hill-2 { right: -18%; width: 58%; background: #bce6b6; }

/* ── 舞台（棋盘区容器，压在装饰之上）────────────────────────────────────── */
.game-stage {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px;
  text-align: center;
}

.game-title {
  margin: 0 0 6px;
  font-size: clamp(40px, 9vw, 58px);
  font-weight: 900;
  letter-spacing: .08em;
  color: var(--ink-brown);
  line-height: 1.15;
}
.game-title .tc { display: inline-block; }
.game-title .tc-o { color: var(--o-main); }
.game-title .tc-x { color: var(--x-main); transform: rotate(-7deg); }
.game-title .tc:nth-child(3) { transform: rotate(4deg); }

.game-sub {
  margin: 0 0 26px;
  font-size: 17px;
  font-weight: 600;
  color: #6f5a49;
}
.game-noscript {
  display: inline-block;
  margin: 0 0 18px;
  padding: 10px 20px;
  border: 3px dashed var(--o-main);
  border-radius: 999px;
  background: #fff;
  color: var(--o-deep);
  font-weight: 700;
}

/* ── 玩家卡片与 VS ───────────────────────────────────────────────────────── */
.players {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}
.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 118px;
  padding: 12px 18px 10px;
  border: 3px solid #e8e2d4;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 5px 0 rgba(91, 70, 54, .12);
}
.player-card .ox-svg { width: 58px; height: 58px; }
.pc-name { font-size: 16px; font-weight: 800; }
.name-o { color: var(--o-deep); }
.name-x { color: var(--x-deep); }
.player-card.is-active { border-color: var(--o-main); animation: card-bounce 1.15s ease-in-out infinite; }
.player-card.pc-o.is-active { border-color: var(--o-main); box-shadow: 0 5px 0 var(--o-main); }
.player-card.pc-x.is-active { border-color: var(--x-main); box-shadow: 0 5px 0 var(--x-main); }
@keyframes card-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.vs-badge {
  font-size: 15px;
  font-weight: 900;
  color: #a08b76;
  background: #fff;
  border: 3px solid #efe7d8;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

/* ── 状态气泡 ────────────────────────────────────────────────────────────── */
.game-status {
  display: inline-block;
  margin: 0 0 22px;
  padding: 9px 24px;
  border: 3px solid #ffe1a8;
  border-radius: 999px;
  background: #fff;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-brown);
}

/* ── 棋盘 ────────────────────────────────────────────────────────────────── */
.board-wrap { position: relative; max-width: 400px; margin: 0 auto; }
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 14px;
  border: 4px solid #e9d5ac;
  border-radius: 26px;
  background: #fffaef;
  box-shadow: 0 8px 0 rgba(91, 70, 54, .14);
}
.cell {
  aspect-ratio: 1;
  padding: 0;
  border: 3px solid #ead9b8;
  border-radius: 18px;
  background: #fffdf6;
  box-shadow: 0 5px 0 #ead9b8;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
}
.cell > svg { width: 74%; height: 74%; margin: 13% auto; display: block; }
.cell > svg { animation: pop-in .34s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes pop-in {
  from { transform: scale(.25); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ── 悬停预览：空格子里淡淡透出「这一下会放下的棋子」─────────────────────
   灰阶 + 半透明的幽灵棋子，孩子不看顶部提示也知道点了会出什么；
   刻意不弹跳（pop-in 只给真正落下的棋子），只做一次短淡入。
   触屏设备没有 hover（hover:hover 不匹配），点了就落子，不需要预览；
   键盘聚焦同样显示，方向键/Tab 选格子的小朋友也能先看到结果。 */
.ox-preview {
  display: block;
  width: 74%;
  height: 74%;
  margin: 13% auto;
  opacity: 0;
  filter: grayscale(1);
  transition: opacity .12s ease;
}
.ox-preview svg { width: 100%; height: 100%; display: block; }
@media (hover: hover) {
  .cell:not(:disabled):hover { transform: translateY(-2px); }
  .cell:not(:disabled):hover .ox-preview { opacity: .5; }
}
.cell:not(:disabled):focus-visible .ox-preview { opacity: .5; }
.cell:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 #ead9b8; }
.cell:focus-visible {
  outline: 4px dashed var(--o-main);
  outline-offset: 3px;
}
.cell:disabled { cursor: default; }
.cell.is-o { border-color: #ffc98e; box-shadow: 0 5px 0 #ffc98e; }
.cell.is-x { border-color: #9adfd6; box-shadow: 0 5px 0 #9adfd6; }
.cell.shake { animation: cell-shake .3s ease; }
@keyframes cell-shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.cell.is-win {
  border-color: var(--gold);
  background: #fff3cf;
  box-shadow: 0 5px 0 var(--gold);
  animation: cell-pulse 1.1s ease-in-out infinite;
}
@keyframes cell-pulse {
  50% { transform: scale(1.07); }
}

/* ── 结果浮层 ────────────────────────────────────────────────────────────── */
.result-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border-radius: 26px;
  background: rgba(255, 250, 239, .86);
}
.result-card {
  max-width: 300px;
  padding: 24px 30px 26px;
  border: 4px solid var(--gold);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 9px 0 rgba(91, 70, 54, .16);
  animation: pop-in .32s cubic-bezier(.2, 1.6, .4, 1) both;
}
.result-icon { display: block; width: 56px; height: 56px; margin: 0 auto 6px; }
.result-icon svg { width: 100%; height: 100%; display: block; }
.result-text {
  margin: 0 0 16px;
  font-size: 21px;
  font-weight: 900;
  color: var(--ink-brown);
}

/* ── 按钮（糖果/胶囊两式，均为贴纸投影，按下会陷下去）───────────────────── */
.btn-candy,
.btn-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 800;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn-candy {
  padding: 12px 34px;
  font-size: 18px;
  color: #fff;
  background: var(--o-main);
  border: 3px solid var(--o-deep);
  box-shadow: 0 5px 0 var(--o-deep);
}
.btn-candy:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--o-deep); }
.btn-candy:focus-visible,
.btn-pill:focus-visible { outline: 4px dashed var(--x-deep); outline-offset: 3px; }
.btn-pill {
  padding: 9px 20px;
  font-size: 15px;
  color: #6f5a49;
  background: #fff;
  border: 3px solid #e8dcc4;
  box-shadow: 0 4px 0 #e8dcc4;
}
.btn-pill:hover { border-color: var(--x-main); color: var(--x-deep); }
.btn-pill:active { transform: translateY(3px); box-shadow: 0 1px 0 #e8dcc4; }
.btn-pill.is-off { color: #b0a18f; border-color: #eee5d4; box-shadow: 0 4px 0 #eee5d4; }
.ico-svg { width: 18px; height: 18px; flex: none; }

/* ── 记分板 ──────────────────────────────────────────────────────────────── */
.scoreboard {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}
.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px;
  border: 3px solid #efe7d8;
  border-radius: 999px;
  background: #fff;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink-brown);
}
.score-chip b { font-size: 16.5px; }
.sc-o b { color: var(--o-deep); }
.sc-x b { color: var(--x-deep); }
.sc-d b { color: #a3845a; }
.mini-svg { width: 17px; height: 17px; flex: none; }

/* ── 控制行 ──────────────────────────────────────────────────────────────── */
.game-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

/* ── 撒花（JS 生成，win 时来一波）────────────────────────────────────────── */
.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
  overflow: hidden;
  pointer-events: none;
}
.confetti-layer i {
  position: absolute;
  top: -22px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(112vh) rotate(720deg); }
}

/* ── 玩法说明区 ──────────────────────────────────────────────────────────── */
.game-rules { padding: 58px 0 64px; background: #fdf9ef; border-top: 3px solid #f3ead6; }
.game-rules h2 { text-align: center; }
.rules-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  max-width: 960px;
  margin: 34px auto 0;
}
.rule-card {
  position: relative;
  padding: 24px 20px 20px;
  border: 3px solid #efe3cb;
  border-radius: 20px;
  background: #fff;
  text-align: left;
}
.rule-num {
  position: absolute;
  top: -16px;
  left: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  border: 3px solid #fff;
  box-shadow: 0 3px 0 rgba(91, 70, 54, .18);
}
.rule-num.n1 { background: var(--o-main); }
.rule-num.n2 { background: var(--x-main); }
.rule-num.n3 { background: #ff8fab; }
.rule-card h3 { margin: 4px 0 8px; font-size: 16.5px; color: var(--ink-brown); }
.rule-card p { margin: 0; font-size: 14.5px; color: #7a6753; }
.rules-note {
  max-width: 720px;
  margin: 30px auto 0;
  padding: 18px 24px;
  border: 3px dashed #dcc9a4;
  border-radius: 18px;
  background: #fffdf6;
  text-align: left;
}
.rules-note h3 { margin: 0 0 6px; font-size: 15.5px; color: var(--ink-brown); }
.rules-note p { margin: 0; font-size: 14px; color: #7a6753; }

/* ── 窄屏 ────────────────────────────────────────────────────────────────── */
@media (max-width: 620px) {
  .game-world { padding: 40px 0 56px; }
  .players { gap: 10px; }
  .player-card { min-width: 100px; padding: 10px 13px 8px; }
  .player-card .ox-svg { width: 46px; height: 46px; }
  .vs-badge { width: 38px; height: 38px; font-size: 13px; }
  .rules-grid { grid-template-columns: 1fr; }
  .board { gap: 9px; padding: 11px; }
}

/* ── 减少动态：停掉一切装饰动画 ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .cloud, .player-card.is-active, .cell.is-win, .cell > svg, .result-card { animation: none; }
  .cell, .btn-candy, .btn-pill, .ox-preview { transition: none; }
  .confetti-layer { display: none; }
}
