/* 五子棋 · 界面样式 */
:root {
  --bg: #14161c;
  --bg-soft: #1c1f28;
  --card: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.09);
  --text: #eceef4;
  --muted: #99a0b0;
  --accent: #e2453c;
  --accent-soft: rgba(226, 69, 60, 0.15);
  --radius: 14px;
}

* { box-sizing: border-box; }

/* hidden 属性必须压过后面的 display 声明，否则 [hidden] 元素照样显示 */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 600px at 15% -10%, #2a2233 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #1e2a33 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1040px; margin: 0 auto; padding: 28px 20px 48px; }

.topbar { margin-bottom: 22px; }
.topbar h1 {
  margin: 0;
  font-size: 27px;
  letter-spacing: 6px;
  font-weight: 600;
}
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 13px; letter-spacing: 1px; }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 296px;
  gap: 24px;
  align-items: start;
}

/* 网格项默认 min-width:auto，会被 canvas 的固有宽度撑开导致棋盘溢出屏幕。
   必须显式归零，测量到的容器宽度才是真实可用宽度。 */
.layout > * { min-width: 0; }

/* ---------- 棋盘 ---------- */
.board-area { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; min-width: 0; }

.board-wrap {
  position: relative;
  width: fit-content;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.06);
  line-height: 0;
}

#board { display: block; cursor: pointer; touch-action: manipulation; }

/* 胜利提示贴在棋盘底部：既要显眼，又不能挡住高亮的获胜五子 */
.banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4%;
  background: linear-gradient(to top, rgba(10, 10, 14, 0.82) 0%, rgba(10, 10, 14, 0.4) 26%, transparent 48%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.banner.show { opacity: 1; pointer-events: auto; }

.banner-card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: center;
  line-height: 1.5;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: pop 0.25s ease;
}
.banner-card p { margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; }
.banner-card .btn { flex: none; padding: 9px 18px; }

@keyframes pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.statusbar {
  width: 100%;
  max-width: var(--board-w, 620px);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 14px;
}

/* ---------- 侧栏 ---------- */
.panel { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
}
.card h2 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.card h2 .count { letter-spacing: 0; font-weight: 400; }
.card h2 b { color: var(--text); }

.radio-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.radio {
  position: relative;
  display: block;
  text-align: center;
  padding: 9px 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.radio input { position: absolute; opacity: 0; pointer-events: none; }
.radio:hover { background: rgba(255, 255, 255, 0.05); }
.radio:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #ffd9d6;
}

.ai-options { margin-top: 12px; display: grid; gap: 9px; }
.field { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.field > span { color: var(--muted); }

select, .name-input {
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
select { min-width: 128px; }
select:focus, .name-input:focus { border-color: var(--accent); }
.name-input:disabled { opacity: 0.85; background: transparent; border-color: transparent; padding-left: 0; }

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}
.player.muted { color: var(--muted); }
.name-input { flex: 1; min-width: 0; }
.name-static { flex: 1; font-size: 13px; }
.score { font-variant-numeric: tabular-nums; font-size: 17px; min-width: 22px; text-align: right; }

.dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.35);
}
.dot.black { background: radial-gradient(circle at 33% 30%, #6e6e78, #0a0a0e); }
.dot.white { background: radial-gradient(circle at 33% 30%, #fff, #c6bfb2); }
.dot.draw { background: linear-gradient(135deg, #0a0a0e 50%, #e6e0d5 50%); }

.btn-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.btn-row:last-child { margin-bottom: 0; }

.btn {
  flex: 1;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ef564d; }
.btn.ghost { background: transparent; }

kbd {
  font-size: 10px;
  padding: 1px 4px;
  margin-left: 3px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  opacity: 0.7;
  font-family: ui-monospace, Menlo, monospace;
}

.switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }

.grow { flex: 1; min-height: 0; }

.move-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 208px;
  overflow-y: auto;
  font-size: 13px;
}
.move-log li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.move-log li:last-child { border-bottom: none; }
.move-log .seq { color: var(--muted); width: 26px; font-variant-numeric: tabular-nums; }
.move-log .coord { font-family: ui-monospace, Menlo, monospace; letter-spacing: 1px; }
.move-log .empty { color: var(--muted); justify-content: center; }
.move-log .chip {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.move-log .chip.black { background: radial-gradient(circle at 33% 30%, #6e6e78, #0a0a0e); }
.move-log .chip.white { background: radial-gradient(circle at 33% 30%, #fff, #c6bfb2); }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .app { padding: 20px 14px 36px; }
  .panel { order: 2; }
  .topbar h1 { font-size: 23px; }
}

/* ==================== AI 小教练 ==================== */

/* 棋盘上闪动的推荐落点：用 DOM + CSS 动画，比每帧重绘 canvas 省得多 */
.hint {
  position: absolute;
  border-radius: 50%;
  border: 2.5px solid #47c2ff;
  box-shadow: 0 0 12px rgba(71, 194, 255, 0.9), inset 0 0 10px rgba(71, 194, 255, 0.45);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: hint-pulse 1.5s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.45; transform: translate(-50%, -50%) scale(0.9); }
  50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.12); }
}

/* 光球本体。定位在 board-area 而不是棋盘里 —— 压在棋盘上会挡住右下角的落子点 */
.orb {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 58px;
  height: 58px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  z-index: 3;
  -webkit-tap-highlight-color: transparent;
}

.orb-core {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, #ffffff 0%, #9be7ff 22%, #4aa8ff 55%, #2b62d8 100%);
  box-shadow:
    0 0 18px rgba(90, 180, 255, 0.75),
    0 6px 16px rgba(0, 0, 0, 0.35),
    inset 0 -6px 12px rgba(20, 40, 90, 0.4);
  animation: orb-breathe 3.4s ease-in-out infinite;
  transition: transform 0.2s ease;
}

/* 外圈波纹，只在听/想/说的时候扩散 */
.orb-wave {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(120, 200, 255, 0.85);
  opacity: 0;
  pointer-events: none;
}

@keyframes orb-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.07); }
}

@keyframes orb-ripple {
  0%   { opacity: 0.85; transform: scale(1); }
  100% { opacity: 0;    transform: scale(1.85); }
}

@keyframes orb-spin {
  to { transform: rotate(360deg); }
}

.orb:hover .orb-core { transform: scale(1.08); }
.orb:active .orb-core { transform: scale(0.94); }

/* 听：转成温暖的橙红，波纹快速扩散 */
.orb.listening .orb-core {
  background: radial-gradient(circle at 34% 30%, #fff 0%, #ffd9a8 22%, #ff8a5c 55%, #e2453c 100%);
  box-shadow: 0 0 26px rgba(255, 130, 90, 0.85), 0 6px 16px rgba(0, 0, 0, 0.35);
  animation: orb-breathe 0.9s ease-in-out infinite;
}
.orb.listening .orb-wave {
  border-color: rgba(255, 150, 110, 0.9);
  animation: orb-ripple 1.1s ease-out infinite;
}

/* 想：加一道旋转的弧线 */
.orb.thinking .orb-core { animation: orb-breathe 1.6s ease-in-out infinite; }
.orb.thinking .orb-wave {
  opacity: 1;
  border-color: transparent;
  border-top-color: rgba(155, 231, 255, 0.95);
  border-right-color: rgba(155, 231, 255, 0.5);
  animation: orb-spin 0.9s linear infinite;
}

/* 说：柔和的绿松色，波纹慢速扩散 */
.orb.speaking .orb-core {
  background: radial-gradient(circle at 34% 30%, #fff 0%, #b8ffe8 22%, #4ad6b4 55%, #1f8f8f 100%);
  box-shadow: 0 0 24px rgba(90, 220, 190, 0.8), 0 6px 16px rgba(0, 0, 0, 0.35);
}
.orb.speaking .orb-wave {
  border-color: rgba(120, 230, 200, 0.85);
  animation: orb-ripple 1.6s ease-out infinite;
}

/* 对话气泡 */
.bubble {
  position: absolute;
  right: 0;
  bottom: 70px;
  width: min(320px, calc(100% - 28px));
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(22, 25, 33, 0.96);
  border: 1px solid rgba(120, 200, 255, 0.3);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  color: var(--text);
  z-index: 3;
  animation: bubble-in 0.22s ease;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* 气泡下方的小尖角，指向光球 */
.bubble::after {
  content: '';
  position: absolute;
  right: 24px;
  bottom: -7px;
  width: 13px;
  height: 13px;
  background: rgba(22, 25, 33, 0.96);
  border-right: 1px solid rgba(120, 200, 255, 0.3);
  border-bottom: 1px solid rgba(120, 200, 255, 0.3);
  transform: rotate(45deg);
}

/* 推荐落点落在棋盘下半部时，气泡挪到上方，免得挡住教练指的那个点 */
.bubble.at-top { top: 12px; bottom: auto; }
.bubble.at-top::after {
  bottom: auto;
  top: -7px;
  border: none;
  border-left: 1px solid rgba(120, 200, 255, 0.3);
  border-top: 1px solid rgba(120, 200, 255, 0.3);
}

.bubble-heard {
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.14);
  font-size: 12px;
  color: var(--muted);
}
.bubble-heard::before { content: '你问：'; opacity: 0.7; }

.bubble-text { margin: 0; font-size: 14.5px; line-height: 1.65; }

.bubble-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.bubble-tag {
  flex: 1;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.mini-btn {
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.mini-btn:hover { background: rgba(255, 255, 255, 0.14); }

.coach-hint {
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}

@media (max-width: 860px) {
  .orb { width: 52px; height: 52px; right: 4px; bottom: 2px; }
  .bubble { right: 4px; bottom: 62px; }
}

/* 尊重"减少动效"的系统设置 */
@media (prefers-reduced-motion: reduce) {
  .orb-core, .orb-wave, .hint, .bubble { animation: none !important; }
}
