/* ============================================
   双人对战棋 — 传统棋类风格
   ============================================ */

:root {
  --cell: 80px;
  --grid-size: 4;
  --board-size: calc(var(--grid-size) * var(--cell));
  --board-pad: 28px;
  --board-outer: calc(var(--board-size) + 2 * var(--board-pad));

  /* 木质色系 */
  --wood-light: #d4a96a;
  --wood-mid: #c4944f;
  --wood-dark: #a07030;
  --wood-frame: #5c3d1e;
  --wood-frame-dark: #3e2c1c;

  --bg: #2a1f14;
  --bg-table: #1e1610;
  --card: rgba(62, 44, 28, 0.85);
  --card-border: rgba(160, 112, 48, 0.3);
  --text: #f0e6d6;
  --text-dim: #b8a48a;
  --muted: #8a7560;
  --border: rgba(160, 112, 48, 0.25);
  --primary: #d4a96a;
  --accent: #e8c478;

  --blue-piece: #3a7bd5;
  --blue-piece-light: #5a9bf5;
  --blue-piece-dark: #1e5ba5;
  --red-piece: #d43a3a;
  --red-piece-light: #f45a5a;
  --red-piece-dark: #a51e1e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  font-family: "Noto Serif SC", "Songti SC", "SimSun", Georgia, serif;
  display: flex;
  justify-content: center;
  color: var(--text);
  background-color: var(--bg-table);
  background-image:
    radial-gradient(ellipse at 50% 30%, rgba(80, 55, 30, 0.6) 0%, transparent 70%);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* —— App 容器 —— */
#app {
  width: 100%;
  max-width: 1200px;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* —— 标题 —— */
#app-header {
  text-align: center;
  margin-bottom: 16px;
}

#app-header h1 {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 8px;
  color: var(--accent);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  line-height: 1.3;
}

#app-header .subtitle {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 4px;
  margin-top: 2px;
}

/* —— 顶部控制栏 —— */
#controls {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

#info {
  font-size: 16px;
  padding: 10px 24px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  min-width: 280px;
  text-align: center;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* —— 信息栏小棋子 —— */
.info-piece {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  vertical-align: middle;
  flex-shrink: 0;
}
.info-piece.p1 {
  background: radial-gradient(circle at 35% 30%, var(--blue-piece-light), var(--blue-piece) 55%, var(--blue-piece-dark) 100%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4), inset 0 1px 1px rgba(255,255,255,0.3);
}
.info-piece.p2 {
  background: radial-gradient(circle at 35% 30%, var(--red-piece-light), var(--red-piece) 55%, var(--red-piece-dark) 100%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4), inset 0 1px 1px rgba(255,255,255,0.3);
}

/* —— 主布局 —— */
.play-area {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  flex-wrap: wrap;
}

/* —— 棋盘外框（木质边框） —— */
#board-frame {
  background: linear-gradient(145deg, var(--wood-frame) 0%, var(--wood-frame-dark) 100%);
  padding: 22px;
  border-radius: 12px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.08),
    inset 0 -1px 0 rgba(0,0,0,0.3);
  position: relative;
  overflow: hidden;
}

#board-frame::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(160, 112, 48, 0.15);
  border-radius: 8px;
  pointer-events: none;
}

#board-wrap {
  position: relative;
  width: min(88vw, var(--board-outer));
  height: min(88vw, var(--board-outer));
  touch-action: manipulation;
  border-radius: 4px;
  overflow: visible;
}

/* —— 棋盘 SVG —— */
#board-svg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  background:
    linear-gradient(135deg, var(--wood-light) 0%, var(--wood-mid) 40%, var(--wood-light) 60%, var(--wood-mid) 100%);
  border-radius: 4px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.15);
}

#pieces {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* —— 棋子 —— */
.piece {
  position: absolute;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  cursor: pointer;
  box-sizing: border-box;
  pointer-events: auto;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.95);
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  user-select: none;
  transition: transform 150ms ease, box-shadow 150ms ease;
  border: none;
}

.piece.p1 {
  background: radial-gradient(circle at 35% 30%, var(--blue-piece-light), var(--blue-piece) 55%, var(--blue-piece-dark) 100%);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.45),
    inset 0 1px 2px rgba(255,255,255,0.35),
    inset 0 -2px 4px rgba(0,0,0,0.2);
}

.piece.p2 {
  background: radial-gradient(circle at 35% 30%, var(--red-piece-light), var(--red-piece) 55%, var(--red-piece-dark) 100%);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.45),
    inset 0 1px 2px rgba(255,255,255,0.35),
    inset 0 -2px 4px rgba(0,0,0,0.2);
}

.piece:hover {
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow:
    0 6px 16px rgba(0,0,0,0.5),
    inset 0 1px 2px rgba(255,255,255,0.35),
    inset 0 -2px 4px rgba(0,0,0,0.2);
}

/* 选中动画 */
.selected { animation: pulse-glow 1.6s ease-in-out infinite; }
.p1.selected {
  box-shadow:
    0 0 0 4px rgba(58, 123, 213, 0.5),
    0 3px 8px rgba(0,0,0,0.45),
    inset 0 1px 2px rgba(255,255,255,0.35);
}
.p2.selected {
  box-shadow:
    0 0 0 4px rgba(212, 58, 58, 0.5),
    0 3px 8px rgba(0,0,0,0.45),
    inset 0 1px 2px rgba(255,255,255,0.35);
}

@keyframes pulse-glow {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.08); }
}

/* —— 可移动位置提示 —— */
.move-dot {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0.15) 100%);
  border: 2.5px solid rgba(255, 255, 255, 0.85);
  pointer-events: auto;
  z-index: 2;
  cursor: pointer;
  animation: dot-breathe 2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(255,255,255,0.3);
}

@keyframes dot-breathe {
  0%, 100% { opacity: 0.7; transform: translate(-50%, -50%) scale(0.92); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
}

.move-dot:hover {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.75) 0%, rgba(255, 255, 255, 0.3) 100%);
  border: 2.5px solid rgba(255, 255, 255, 1);
  transform: translate(-50%, -50%) scale(1.12);
  box-shadow: 0 0 14px rgba(255,255,255,0.5);
}

/* —— 按钮系统 —— */
button {
  font-family: "Noto Serif SC", "Songti SC", Georgia, serif;
  cursor: pointer;
  transition: all 180ms ease;
  outline: none;
}

.btn-action {
  padding: 10px 24px;
  min-height: 40px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: linear-gradient(180deg, rgba(160, 112, 48, 0.3) 0%, rgba(92, 61, 30, 0.5) 100%);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 2px;
  backdrop-filter: blur(4px);
}
.btn-action:hover {
  background: linear-gradient(180deg, rgba(160, 112, 48, 0.5) 0%, rgba(92, 61, 30, 0.7) 100%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transform: translateY(-1px);
}
.btn-action:active { transform: translateY(0); }

.btn-primary {
  padding: 9px 16px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid var(--card-border);
  background: linear-gradient(180deg, rgba(160, 112, 48, 0.4) 0%, rgba(92, 61, 30, 0.6) 100%);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 1px;
  flex: 1;
}
.btn-primary:hover {
  background: linear-gradient(180deg, rgba(160, 112, 48, 0.6) 0%, rgba(92, 61, 30, 0.8) 100%);
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  padding: 8px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid rgba(160, 112, 48, 0.3);
  background: linear-gradient(180deg, rgba(160, 112, 48, 0.25) 0%, rgba(92, 61, 30, 0.4) 100%);
  color: var(--accent);
  letter-spacing: 1px;
  flex: 1;
  font-weight: 600;
}
.btn-secondary:hover {
  background: linear-gradient(180deg, rgba(160, 112, 48, 0.45) 0%, rgba(92, 61, 30, 0.65) 100%);
  color: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  transform: translateY(-1px);
}
.btn-secondary:active { transform: translateY(0); }

.btn-ghost-small {
  font-size: 12px;
  padding: 4px 10px;
  min-height: auto;
  line-height: 1.2;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  letter-spacing: 1px;
}
.btn-ghost-small:hover {
  border-color: var(--primary);
  color: var(--text-dim);
  background: rgba(160, 112, 48, 0.1);
}

/* —— 右侧面板 —— */
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-left: 0;
  align-items: stretch;
  width: 300px;
  max-width: min(92vw, 400px);
}

.panel-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 14px 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.panel-card-header {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 2px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* —— 联机控制 —— */
.net-controls {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
  width: 100%;
}

.net-controls input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  background: rgba(30, 22, 16, 0.7);
  color: var(--text);
  min-height: 38px;
  width: 100%;
  letter-spacing: 1px;
}
.net-controls input::placeholder { color: var(--muted); }
.net-controls input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(212, 169, 106, 0.15);
}

.net-btn-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

#net-status {
  flex: 0 0 100%;
  display: block;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 4px;
  letter-spacing: 1px;
}

/* —— 房间列表 —— */
.room-list-wrap .panel-card-header { margin-bottom: 8px; }

#room-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-height: 72px;
  overflow-y: auto;
}
#room-list::-webkit-scrollbar { width: 4px; }
#room-list::-webkit-scrollbar-track { background: transparent; }
#room-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#room-list li { display: contents; }

#room-list button {
  padding: 6px 14px;
  font-size: 12px;
  font-family: inherit;
  border-radius: 6px;
  border: 1px solid rgba(160, 112, 48, 0.3);
  background: linear-gradient(180deg, rgba(160, 112, 48, 0.25) 0%, rgba(92, 61, 30, 0.4) 100%);
  color: var(--accent);
  cursor: pointer;
  letter-spacing: 1px;
  font-weight: 600;
  transition: all 150ms ease;
}
#room-list button:hover:not(:disabled) {
  background: linear-gradient(180deg, rgba(160, 112, 48, 0.5) 0%, rgba(92, 61, 30, 0.7) 100%);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  transform: translateY(-1px);
}
#room-list button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* —— 对弈记录（棋盘下方） —— */
#log-wrapper {
  width: 100%;
  max-width: 760px;
  margin-top: 20px;
  padding: 0;
  overflow: hidden;
}

#log-wrapper .panel-card-header {
  margin-bottom: 0;
}

#log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 0;
}

#log-container {
  height: 160px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
  padding: 10px 16px 14px;
  letter-spacing: 0.5px;
}
#log-container::-webkit-scrollbar { width: 4px; }
#log-container::-webkit-scrollbar-track { background: transparent; }
#log-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#log-container p {
  margin: 0 0 3px;
  padding: 3px 8px;
  border-radius: 4px;
}

.log-move { background-color: rgba(58, 123, 213, 0.15); color: var(--blue-piece-light); }
.log-capture { background-color: rgba(212, 168, 74, 0.2); color: var(--accent); font-weight: 700; }
.log-win { background-color: rgba(40, 167, 69, 0.2); color: #5ddf5d; font-weight: 700; }
.log-info { color: var(--muted); }
.log-error { background-color: rgba(212, 58, 58, 0.15); color: #f45a5a; font-weight: 700; }

/* —— 游戏规则 —— */
#rules {
  width: 100%;
  max-width: 760px;
  margin-top: 20px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.rules-inner {
  padding: 18px 22px;
  line-height: 1.7;
  font-size: 14px;
  overflow: visible;
  max-height: none;
}

#rules h3 {
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 2px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
#rules p { margin: 6px 0; }
#rules ul { padding-left: 20px; }
#rules li { margin: 4px 0; }

kbd {
  display: inline-block;
  padding: 3px 10px;
  font-size: 13px;
  font-family: "Courier New", Consolas, monospace;
  font-weight: 700;
  background: rgba(30, 22, 16, 0.8);
  border: 1px solid rgba(232, 196, 120, 0.5);
  border-radius: 4px;
  color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  letter-spacing: 1px;
}

/* —— 胜利状态 —— */
.win {
  color: #5ddf5d;
  font-weight: 700;
  text-shadow: 0 0 8px rgba(93, 223, 93, 0.3);
}
.muted { font-size: 12px; color: var(--muted); }

/* —— 吃子爆炸动画 —— */
.capture-fx {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 10;
  animation: capture-explode 0.6s ease-out forwards;
}
.capture-fx.p1 {
  width: 36px; height: 36px;
  background: radial-gradient(circle, rgba(90, 155, 245, 0.7) 0%, rgba(90, 155, 245, 0) 70%);
}
.capture-fx.p2 {
  width: 36px; height: 36px;
  background: radial-gradient(circle, rgba(244, 90, 90, 0.7) 0%, rgba(244, 90, 90, 0) 70%);
}

.capture-ring {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 9;
  animation: capture-ring-expand 0.5s ease-out forwards;
}
.capture-ring.p1 {
  width: 36px; height: 36px;
  border: 3px solid rgba(90, 155, 245, 0.8);
  background: transparent;
}
.capture-ring.p2 {
  width: 36px; height: 36px;
  border: 3px solid rgba(244, 90, 90, 0.8);
  background: transparent;
}

@keyframes capture-explode {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2.5); }
}

@keyframes capture-ring-expand {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); border-width: 3px; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(3.5); border-width: 1px; }
}

/* 吃子时棋子消失动画 */
.piece.captured {
  animation: piece-captured 0.4s ease-out forwards !important;
  pointer-events: none !important;
}
@keyframes piece-captured {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  40% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0); }
}

/* —— Footer —— */
footer {
  margin-top: 32px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 2px;
  text-align: center;
}

/* ============================================
   响应式
   ============================================ */

@media (max-width: 768px) {
  #app { padding: 16px 12px 32px; }

  #app-header h1 { font-size: 26px; letter-spacing: 6px; }
  #app-header .subtitle { font-size: 11px; }

  .play-area { gap: 16px; }

  #board-frame { padding: 12px; }

  .right-panel {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 520px) {
  :root { --cell: 60px; --board-pad: 22px; }

  #app-header h1 { font-size: 22px; letter-spacing: 4px; }

  .piece { width: 28px; height: 28px; font-size: 9px; }
  .move-dot { width: 20px; height: 20px; }
  .capture-fx, .capture-ring { width: 28px; height: 28px; }

  #board-frame { padding: 10px; border-radius: 8px; }

  .panel-card { padding: 12px; }

  .btn-primary, .btn-secondary { padding: 7px 10px; font-size: 12px; }
}

/* ============================================
   适配深色模式（已有深色基底，微调即可）
   ============================================ */
@media (prefers-color-scheme: light) {
  :root {
    --bg-table: #e8dcc8;
    --bg: #d8ccb8;
    --card: rgba(255, 250, 240, 0.92);
    --card-border: rgba(160, 112, 48, 0.2);
    --text: #3e2c1c;
    --text-dim: #6b5540;
    --muted: #9a8570;
    --border: rgba(160, 112, 48, 0.18);
    --primary: #a07030;
    --accent: #7a5020;
  }

  body {
    background-image:
      radial-gradient(ellipse at 50% 30%, rgba(212, 169, 106, 0.3) 0%, transparent 70%);
  }

  #board-svg {
    background:
      linear-gradient(135deg, #dbb878 0%, #c9a55a 40%, #dbb878 60%, #c9a55a 100%);
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.1);
    width: 100%;
    height: 100%;
  }

  #board-frame {
    background: linear-gradient(145deg, #6b4c2a 0%, #4a3218 100%);
    padding: 22px;
    box-shadow:
      0 6px 24px rgba(0,0,0,0.2),
      inset 0 1px 0 rgba(255,255,255,0.12),
      inset 0 -1px 0 rgba(0,0,0,0.15);
  }

  .piece.p1 {
    box-shadow:
      0 3px 8px rgba(0,0,0,0.3),
      inset 0 1px 2px rgba(255,255,255,0.4),
      inset 0 -2px 4px rgba(0,0,0,0.15);
  }
  .piece.p2 {
    box-shadow:
      0 3px 8px rgba(0,0,0,0.3),
      inset 0 1px 2px rgba(255,255,255,0.4),
      inset 0 -2px 4px rgba(0,0,0,0.15);
  }

  .log-move { background-color: rgba(58, 123, 213, 0.1); color: var(--blue-piece); }
  .log-capture { background-color: rgba(160, 112, 48, 0.15); color: var(--accent); }
  .log-win { background-color: rgba(40, 167, 69, 0.15); color: #1a7a30; }
  .log-info { color: var(--muted); }
  .log-error { background-color: rgba(212, 58, 58, 0.1); color: #a51e1e; }

  .win { color: #1a7a30; text-shadow: none; }

  .net-controls input {
    background: rgba(255, 250, 240, 0.8);
    color: var(--text);
  }

  #log-container { color: var(--text-dim); }
}
