/* ==============================================================
   井字棋 · 游戏专属样式
   选择器统一以 .g-tictactoe 前缀限定
   ============================================================== */

.g-tictactoe {
  gap: 10px;
}

/* ------------------------------ 模式切换 ------------------------------ */

.g-tictactoe .tt-mode {
  display: flex;
  padding: 3px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  gap: 3px;
}
.g-tictactoe .tt-mode-btn {
  min-height: 40px;
  padding: 0 9px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--dim);
  border: 0;
  background: transparent;
  transition: background 0.16s, color 0.16s;
  white-space: nowrap;
}
.g-tictactoe .tt-mode-btn.on {
  color: #fff;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 88%, #fff 12%), var(--accent2));
  box-shadow: 0 4px 12px -6px var(--accent);
}

/* ------------------------------ 状态条 ------------------------------ */

.g-tictactoe .tt-hud {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.g-tictactoe .tt-turn { display: flex; align-items: center; gap: 7px; min-width: 0; }
.g-tictactoe .tt-turn-t {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
}
.g-tictactoe .tt-turn-t.thinking { color: var(--accent); }
.g-tictactoe .tt-turn-t.thinking::after {
  content: "…";
  display: inline-block;
  animation: ttBlink 1s steps(2) infinite;
}
.g-tictactoe .tt-score {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  white-space: nowrap;
}
.g-tictactoe .tt-sc { display: inline-flex; align-items: center; gap: 3px; }
.g-tictactoe .tt-sc i {
  width: 11px;
  height: 11px;
  display: inline-block;
  flex: none;
}
.g-tictactoe .tt-sc.x i {
  background: var(--accent);
  clip-path: polygon(0 0, 18% 0, 50% 34%, 82% 0, 100% 0, 60% 50%, 100% 100%, 82% 100%, 50% 66%, 18% 100%, 0 100%, 40% 50%);
}
.g-tictactoe .tt-sc.o i {
  border: 2.5px solid #79b8ff;
  border-radius: 50%;
}
.g-tictactoe .tt-sc.draw i {
  border: 1.5px dashed rgba(255, 255, 255, 0.35);
  border-radius: 3px;
}
.g-tictactoe .tt-target { font-size: 10px; font-weight: 600; color: var(--faint); }

.g-tictactoe .tt-dot {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
}
.g-tictactoe .tt-dot.x {
  border-radius: 3px;
  background: var(--accent);
  clip-path: polygon(0 0, 20% 0, 50% 30%, 80% 0, 100% 0, 62% 50%, 100% 100%, 80% 100%, 50% 70%, 20% 100%, 0 100%, 38% 50%);
}
.g-tictactoe .tt-dot.o { border: 3px solid #79b8ff; background: transparent; }
.g-tictactoe .tt-dot.draw {
  border: 1px dashed rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.06);
}

/* ------------------------------ 棋盘 ------------------------------ */

.g-tictactoe .tt-board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 0;
}
.g-tictactoe .tt-board {
  position: relative;
  width: min(100%, 330px, calc(100dvh - 336px));
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 92, 108, 0.09), transparent 60%),
    linear-gradient(160deg, #1b2433, #10161f 70%);
  box-shadow: 0 26px 50px -28px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  touch-action: manipulation;
}
.g-tictactoe .tt-grid,
.g-tictactoe .tt-win {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.g-tictactoe .tt-grid-line {
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 2.4;
  stroke-linecap: round;
}
.g-tictactoe .tt-cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.g-tictactoe .tt-cell {
  position: relative;
  border: 0;
  background: transparent;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.15s ease;
}
.g-tictactoe .tt-cell:active { background: rgba(255, 255, 255, 0.05); }
.g-tictactoe .tt-cell.win { background: radial-gradient(circle, rgba(255, 233, 166, 0.16), transparent 70%); }
.g-tictactoe .tt-cell.win .tt-mark { filter: drop-shadow(0 0 10px rgba(255, 233, 166, 0.7)); }

.g-tictactoe .tt-mark {
  width: 74%;
  height: 74%;
  overflow: visible;
}
.g-tictactoe .tt-mark line,
.g-tictactoe .tt-mark circle {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.g-tictactoe .tt-x line { stroke: var(--accent); stroke-width: 11; }
.g-tictactoe .tt-o circle { stroke: #79b8ff; stroke-width: 11; }
.g-tictactoe .tt-mark.new.tt-x line {
  stroke-dasharray: 76;
  stroke-dashoffset: 76;
  animation: ttDraw 0.2s ease forwards;
}
.g-tictactoe .tt-mark.new.tt-x line:nth-child(2) { animation-delay: 0.05s; }
.g-tictactoe .tt-mark.new.tt-o circle {
  stroke-dasharray: 172;
  stroke-dashoffset: 172;
  animation: ttDrawO 0.34s ease forwards;
}

.g-tictactoe .tt-win-line {
  fill: none;
  stroke: #ffe9a6;
  stroke-width: 9;
  stroke-linecap: round;
  opacity: 0;
  stroke-dasharray: 420;
  stroke-dashoffset: 420;
  filter: drop-shadow(0 0 8px rgba(255, 233, 166, 0.6));
}
.g-tictactoe .tt-win.show .tt-win-line {
  opacity: 1;
  animation: ttWin 0.42s ease forwards;
}

/* ------------------------------ 难度 / 操作 ------------------------------ */

.g-tictactoe .tt-diff {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-height: 36px;
  padding: 4px 10px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.g-tictactoe .tt-diff-k { font-size: 10.5px; color: var(--faint); letter-spacing: 0.04em; flex: none; }
.g-tictactoe .tt-diff-btns { display: flex; gap: 6px; margin-left: auto; }
.g-tictactoe .tt-diff-btn {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--dim);
  font-size: 11.5px;
  font-weight: 600;
}
.g-tictactoe .tt-diff-btn.on {
  color: #ffe1e5;
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.g-tictactoe .tt-ctrl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: none;
}
.g-tictactoe .tt-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 0 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--dim);
  font-size: 12.5px;
  font-weight: 600;
  transition: transform 0.08s, background 0.15s;
  touch-action: manipulation;
}
.g-tictactoe .tt-btn:active { transform: scale(0.96); background: var(--surface-2); }
.g-tictactoe .tt-btn.is-disabled { opacity: 0.38; pointer-events: none; }
.g-tictactoe .tt-btn-i { font-size: 15px; color: var(--accent); line-height: 1; }

/* ------------------------------ 动画 ------------------------------ */

@keyframes ttDraw { to { stroke-dashoffset: 0; } }
@keyframes ttDrawO { to { stroke-dashoffset: 0; } }
@keyframes ttWin { to { stroke-dashoffset: 0; } }
@keyframes ttBlink { 50% { opacity: 0.25; } }

/* ------------------------------ 适配 ------------------------------ */

@media (max-height: 710px) {
  .g-tictactoe { gap: 8px; }
  .g-tictactoe .tt-btn { min-height: 42px; }
  .g-tictactoe .tt-mode-btn { min-height: 36px; }
  .g-tictactoe .tt-hud { min-height: 34px; }
  .g-tictactoe .tt-diff { min-height: 32px; }
  .g-tictactoe .tt-board { width: min(100%, 300px, calc(100dvh - 330px)); }
}

@media (max-width: 365px) {
  .g-tictactoe .tt-mode-btn { padding: 0 7px; font-size: 11px; }
  .g-tictactoe .tt-btn { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .g-tictactoe .tt-mark,
  .g-tictactoe .tt-win.show .tt-win-line { animation: none; }
  .g-tictactoe .tt-turn-t.thinking::after { animation: none; }
}
