/* ==========================================================================
   中国象棋 —— 样式
   配色走暖木色：深棕底 + 原木棋盘 + 象牙棋子
   ========================================================================== */

:root {
  --bg-deep: #1d1410;
  --bg-mid: #2b1e16;
  --wood: #e9c88e;
  --wood-dark: #d8b071;
  --line: #7a5230;
  --line-soft: rgba(122, 82, 48, 0.55);
  --ivory: #f8eed8;
  --ivory-edge: #c9a86a;
  --red: #b3352b;
  --black: #23201c;
  --accent: #d9a441;
  --text: #efe4d2;
  --text-dim: #a89680;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 50% 0%, #3a281c 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-mid), var(--bg-deep));
  color: var(--text);
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ------------------------------------------------------------ 顶部标题 */

.topbar {
  position: relative;
  text-align: center;
  margin-bottom: 18px;
}

/* 标题行：logo + 标题 */
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.logo {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  background: #2b1e16;
  border: 2px solid rgba(217, 164, 65, 0.55);
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.sound-toggle {
  position: absolute;
  right: 0;
  top: -2px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.08s;
}

.sound-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
}

.sound-toggle:active {
  transform: scale(0.94);
}

.sound-toggle.is-off {
  opacity: 0.5;
  filter: grayscale(1);
}

.sound-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: var(--accent);
}

.subtitle {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

/* -------------------------------------------------------------- 整体布局 */

.layout {
  display: flex;
  gap: 22px;
  align-items: flex-start;
  justify-content: center;
}

.board-panel {
  flex: 0 0 auto;
  max-width: 100%;
}

.board-frame {
  position: relative;
  border-radius: var(--radius);
  padding: 6px;
  background: linear-gradient(150deg, #b8905a, #8a6538);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

#board {
  display: block;
  width: 592px;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background:
    repeating-linear-gradient(
      92deg,
      rgba(160, 120, 70, 0.06) 0px,
      rgba(160, 120, 70, 0.06) 2px,
      transparent 2px,
      transparent 7px
    ),
    linear-gradient(165deg, var(--wood), var(--wood-dark));
  /* 棋盘上禁止浏览器接管滑动手势，否则拖棋子会变成滚动页面 */
  touch-action: none;
  cursor: default;
}

/* ------------------------------------------------------------ 侧边栏 */

.side {
  flex: 1 1 260px;
  min-width: 240px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 联机模式下多了聊天面板，把记谱区压矮一点，给聊天留出空间 */
.side.is-online .moves {
  min-height: 92px;
  max-height: 128px;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  min-height: 46px;
}

.turn-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
  transition: background 0.2s;
}

.turn-dot.red {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(179, 53, 43, 0.24);
}

.turn-dot.black {
  background: #6d6357;
  box-shadow: 0 0 0 3px rgba(109, 99, 87, 0.24);
}

.status.is-check {
  background: rgba(179, 53, 43, 0.16);
  border-color: rgba(179, 53, 43, 0.45);
  color: #ffc9c2;
}

.status.is-over {
  background: rgba(217, 164, 65, 0.16);
  border-color: rgba(217, 164, 65, 0.45);
  color: #ffdf9e;
}

/* ------------------------------------------------------------ 控件 */

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(180deg, #c8892f, #a56c1d);
  border-color: #d9a441;
  color: #2a1b0a;
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #d99a3c, #b57a26);
}

.btn.danger {
  grid-column: 1 / -1;
  background: rgba(179, 53, 43, 0.22);
  border-color: rgba(179, 53, 43, 0.55);
  color: #ffb8b0;
}

.btn.danger:hover:not(:disabled) {
  background: rgba(179, 53, 43, 0.35);
}

/* ------------------------------------------------------------ 联机面板 */

.online-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(217, 164, 65, 0.07);
  border: 1px solid rgba(217, 164, 65, 0.22);
}

.online-panel[hidden] {
  display: none;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 0.2em;
  text-align: center;
}

.join-row input::placeholder {
  letter-spacing: 0.05em;
  font-size: 13px;
  color: var(--text-dim);
}

.join-row input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.online-status {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-dim);
  text-align: center;
}

.online-status.is-good {
  color: #9ed3a0;
}

.online-status.is-bad {
  color: #ffb8b0;
}

/* ------------------------------------------------------------ 聊天与语音 */

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  max-height: 220px;
}

.chat-panel[hidden] {
  display: none;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--text-dim);
}

.voice-btn {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: 999px;
}

.voice-btn.is-live {
  background: rgba(70, 160, 90, 0.24);
  border-color: rgba(90, 200, 120, 0.7);
  color: #b6f0c4;
  animation: voice-pulse 1.6s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(90, 200, 120, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(90, 200, 120, 0); }
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 54px;
  max-height: 110px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  line-height: 1.5;
}

.chat-list li {
  padding: 6px 10px;
  border-radius: 10px;
  max-width: 88%;
  word-break: break-word;
  white-space: pre-wrap;
  animation: chat-in 0.16s ease-out;
}

@keyframes chat-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-list li.mine {
  align-self: flex-end;
  background: rgba(179, 53, 43, 0.22);
  color: #ffd9d4;
  border-bottom-right-radius: 3px;
}

.chat-list li.theirs {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

.chat-list li.system {
  align-self: center;
  background: none;
  color: var(--text-dim);
  font-size: 11.5px;
  letter-spacing: 0.05em;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.chat-form input::placeholder {
  color: var(--text-dim);
}

.chat-form input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.voice-status {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-dim);
  min-height: 0;
}

.voice-status:empty {
  display: none;
}

.field {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

/* hidden 属性要能压过 display:flex，否则人机模式外的控件藏不住 */
.field[hidden] {
  display: none;
}

.field span {
  flex: 0 0 34px;
}

.field select {
  flex: 1;
  appearance: none;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.field select:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------ 记谱 */

.moves {
  flex: 1;
  min-height: 120px;
  max-height: 200px;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  padding: 12px 14px;
  overflow: hidden;
}

.moves h2 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--text-dim);
}

.move-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
  flex: 1;
}

.move-list li {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 4px;
  padding: 3px 0;
  font-size: 14px;
  line-height: 1.6;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.move-list .no {
  color: var(--text-dim);
  font-size: 12px;
  text-align: right;
  padding-right: 8px;
}

.move-list .red-move {
  color: #ef9a8f;
}

.move-list .black-move {
  color: #cfc4b2;
}

.move-list li.latest {
  background: rgba(217, 164, 65, 0.1);
  border-radius: 4px;
}

.empty-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.empty-hint[hidden] {
  display: none;
}

/* ------------------------------------------------------------ 结算画面 */

.banner {
  position: absolute;
  inset: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 14, 10, 0.76);
  backdrop-filter: blur(3px);
  animation: fade-in 0.25s ease-out;
}

.banner[hidden] {
  display: none;
}

.result-card {
  width: min(100%, 360px);
  padding: 24px 22px 20px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(48, 34, 23, 0.98), rgba(26, 18, 12, 0.98));
  border: 1px solid rgba(217, 164, 65, 0.35);
  box-shadow:
    0 22px 50px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  text-align: center;
  animation: rise 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.result-kicker {
  font-size: 11px;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: var(--text-dim);
}

.result-title {
  margin: 8px 0 4px;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  line-height: 1.2;
}

.result-title.red-win {
  color: #ec6a60;
  text-shadow: 0 0 26px rgba(236, 106, 96, 0.35);
}

.result-title.black-win {
  color: #d5ccbe;
  text-shadow: 0 0 26px rgba(213, 204, 190, 0.22);
}

.result-reason {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 18px 0 0;
}

.stat {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
}

.stat-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.result-captures {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
}

.capture-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.capture-label {
  flex: 0 0 62px;
  text-align: right;
  color: var(--text-dim);
  font-size: 11.5px;
}

.capture-list {
  flex: 1;
  text-align: left;
  letter-spacing: 0.14em;
  word-break: break-all;
}

.red-row .capture-list {
  color: #e08a80;
}

.black-row .capture-list {
  color: #bdb3a4;
}

.result-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.result-actions .btn {
  flex: 1;
  padding: 11px 8px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ------------------------------------------------------------ 棋盘元素 */

.grid-line {
  stroke: var(--line);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.grid-line.border {
  stroke-width: 2.6;
}

.grid-line.thin {
  stroke-width: 0.8;
  stroke: var(--line-soft);
}

.river-text {
  fill: var(--line);
  font-size: 21px;
  font-family: 'KaiTi', 'STKaiti', 'SimSun', serif;
  letter-spacing: 8px;
  opacity: 0.82;
  user-select: none;
}

.coord-label {
  fill: var(--line);
  font-size: 12px;
  font-weight: 500;
  opacity: 0.8;
  user-select: none;
  font-family: inherit;
}

/* 棋子 */
.piece {
  cursor: grab;
}

.piece .disc {
  fill: url(#ivoryGrad);
  stroke: var(--ivory-edge);
  stroke-width: 1.5;
  filter: drop-shadow(0 2px 2px rgba(60, 35, 10, 0.45));
  transition: stroke 0.15s, stroke-width 0.15s;
}

.piece .ring {
  fill: none;
  stroke: rgba(180, 140, 90, 0.55);
  stroke-width: 1;
}

.piece .label {
  font-family: 'KaiTi', 'STKaiti', 'SimSun', 'Songti SC', serif;
  font-size: 27px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

.piece.red .label {
  fill: var(--red);
}

.piece.black .label {
  fill: var(--black);
}

.piece:hover .disc {
  stroke: var(--accent);
  stroke-width: 2.4;
}

.piece.selected .disc {
  stroke: var(--accent);
  stroke-width: 3;
}

/* 被拖起来的棋子：高亮 + 阴影加深，看起来像被拿离棋盘 */
.piece.dragging {
  cursor: grabbing;
}

.piece.dragging .disc {
  stroke: var(--accent);
  stroke-width: 3;
  filter: drop-shadow(0 10px 10px rgba(40, 20, 5, 0.5));
}

/* 拖拽时指针下方的落点提示加强显示 */
.hint-active {
  filter: drop-shadow(0 0 7px rgba(217, 164, 65, 0.95));
}

.hint-dot.hint-active {
  fill: rgba(60, 130, 65, 0.95);
}

.hint-capture.hint-active {
  stroke: var(--accent);
  stroke-width: 4;
}

/* 暗示落点 */
.hint-dot {
  fill: rgba(45, 90, 50, 0.42);
  pointer-events: none;
}

.hint-capture {
  fill: none;
  stroke: rgba(179, 53, 43, 0.72);
  stroke-width: 3;
  pointer-events: none;
}

/* 最后一步标记 */
.last-move {
  fill: none;
  stroke: rgba(217, 164, 65, 0.85);
  stroke-width: 2;
  pointer-events: none;
}

/* 被将军时，己方走不动的棋子半透明 —— 不用点就知道它动不了 */
.piece.blocked {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 提示气泡 */
.toast {
  position: absolute;
  left: 50%;
  bottom: 10px;
  /* 绝对定位 + left:50% 时，可用宽度只剩一半，会过早换行把棋盘底线压住。
     width:max-content 让它按内容撑开，再用 max-width 兜底。 */
  width: max-content;
  max-width: 86%;
  padding: 8px 15px;
  border-radius: 999px;
  background: rgba(22, 15, 10, 0.94);
  border: 1px solid rgba(217, 164, 65, 0.55);
  color: #f4e8d6;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 3;
  transform: translate(-50%, 10px);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 被将军的将帅 */
.check-glow {
  fill: rgba(214, 40, 30, 0.3);
  pointer-events: none;
}

/* ------------------------------------------------------------ 响应式 */

@media (max-width: 860px) {
  .layout {
    flex-direction: column;
    align-items: center;
  }

  .side {
    width: 100%;
    max-width: 592px;
  }

  .moves {
    max-height: 200px;
  }
}

@media (max-width: 600px) {
  .app {
    padding: 14px 10px 28px;
  }

  .topbar h1 {
    font-size: 21px;
  }

  .brand {
    gap: 10px;
  }

  .logo {
    width: 40px;
    height: 40px;
  }

  .sound-toggle {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .subtitle {
    font-size: 12px;
  }

  .board-frame {
    padding: 4px;
  }

  .result-title {
    font-size: 26px;
  }

  .result-card {
    padding: 18px 16px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .piece .disc,
  .banner {
    transition: none;
    animation: none;
  }
}
