/* ============================================================
   中国象棋 网页版 - 样式表
   深色典雅主题 / 木纹棋盘 / 玉质棋子
   ============================================================ */

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

:root {
  /* 木纹色 */
  --wood-light: #ebc896;
  --wood-main: #d2aa73;
  --wood-dark: #af8250;
  --wood-deep: #825a32;
  --wood-border: #5f4123;

  /* 金属色 */
  --gold: #c8a550;
  --gold-bright: #f0c86e;
  --bronze: #9b6e37;

  /* 红色系（红方） */
  --red-face: #d23232;
  --red-light: #f0645a;
  --red-dark: #821914;
  --red-deep: #500f0a;

  /* 黑色系（黑方） */
  --black-face: #19191c;
  --black-soft: #2a2a2e;

  /* 背景 */
  --bg-deepest: #0f0a06;
  --bg-deep: #1a120c;
  --bg-main: #241810;
  --bg-elevated: #2e2018;
  --bg-card: #382820;
  --bg-hover: #44302a;

  /* 文字 */
  --text-primary: #f5e8d4;
  --text-secondary: #c4ad8a;
  --text-muted: #8c7560;
  --text-dim: #5a4838;
  --text-gold: #f0c86e;

  /* 状态 */
  --state-success: #5fdc82;
  --state-warning: #ffb74d;
  --state-danger: #f04b4b;
  --state-info: #64b5f6;

  /* 阴影 */
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.6);
  --shadow-inset: inset 0 2px 6px rgba(0, 0, 0, 0.4);

  /* 字体 */
  --font-zh: "PingFang SC", "Microsoft YaHei", "STHeiti", "SimHei", "Noto Sans CJK SC", sans-serif;
  --font-mono: "JetBrains Mono", "Consolas", "Monaco", monospace;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font-zh);
  color: var(--text-primary);
  background:
    radial-gradient(ellipse at top, var(--bg-main) 0%, var(--bg-deep) 50%, var(--bg-deepest) 100%);
  user-select: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0,
      transparent 2px,
      rgba(200, 165, 80, 0.02) 2px,
      rgba(200, 165, 80, 0.02) 3px
    );
  pointer-events: none;
  z-index: 1;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 2;
}

/* ============================================================
   顶部栏
   ============================================================ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-main) 100%);
  border-bottom: 1px solid var(--wood-border);
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 10;
}

.topbar::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--gold) 50%, transparent 100%);
  opacity: 0.6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 30% 30%, var(--gold-bright), var(--gold) 40%, var(--bronze) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--red-deep);
  font-weight: bold;
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.3),
    var(--shadow-md);
  border: 1px solid var(--wood-deep);
}

.brand-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-gold);
  letter-spacing: 2px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--wood-border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.player-info:hover {
  background: var(--bg-hover);
  border-color: var(--gold);
}

.player-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--red-face), var(--red-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  color: white;
  border: 1px solid var(--gold);
}

.player-name {
  font-size: 13px;
  color: var(--text-primary);
}

.storage-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-deep);
  color: var(--text-muted);
  border: 1px solid var(--wood-border);
}

.storage-badge.cloud {
  color: var(--state-success);
  border-color: var(--state-success);
}

.storage-badge.local {
  color: var(--state-warning);
  border-color: var(--state-warning);
}

/* ============================================================
   主体布局
   ============================================================ */

.main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* 左侧工具栏 */
.toolbar {
  width: 70px;
  background: var(--bg-main);
  border-right: 1px solid var(--wood-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 8px;
}

.tool-btn {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--wood-border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all 0.2s;
  position: relative;
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-gold);
  border-color: var(--gold);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.tool-btn.active {
  background: linear-gradient(180deg, var(--gold) 0%, var(--bronze) 100%);
  color: var(--red-deep);
  border-color: var(--gold-bright);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.3),
    var(--shadow-sm);
}

.tool-btn::after {
  content: attr(data-tip);
  position: absolute;
  left: 110%;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-deepest);
  color: var(--text-primary);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  border: 1px solid var(--wood-border);
  z-index: 100;
}

.tool-btn:hover::after {
  opacity: 1;
}

.tool-divider {
  width: 32px;
  height: 1px;
  background: var(--wood-border);
  margin: 6px 0;
}

/* 中央棋盘区 */
.board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.board-container {
  flex: 1;
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#board {
  max-width: 100%;
  max-height: 100%;
  display: block;
  border-radius: 12px;
  box-shadow:
    0 0 0 3px var(--wood-border),
    0 0 0 6px var(--wood-deep),
    0 12px 40px rgba(0, 0, 0, 0.7);
  background: var(--wood-main);
}

/* 状态条 */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--wood-border);
  font-size: 13px;
}

.status-turn {
  display: flex;
  align-items: center;
  gap: 8px;
}

.turn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--wood-border);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.turn-dot.red {
  background: radial-gradient(circle at 30% 30%, var(--red-light), var(--red-face) 60%, var(--red-dark));
}

.turn-dot.black {
  background: radial-gradient(circle at 30% 30%, #4a4a4f, #1a1a1c 70%, #050505);
}

.status-text {
  color: var(--text-secondary);
}

.status-text strong {
  color: var(--text-gold);
  font-weight: 600;
}

.status-info {
  display: flex;
  gap: 18px;
  color: var(--text-muted);
  font-size: 12px;
}

.status-info span strong {
  color: var(--text-secondary);
  font-weight: 600;
}

/* ============================================================
   右侧信息面板
   ============================================================ */

.sidepanel {
  width: 320px;
  background: var(--bg-main);
  border-left: 1px solid var(--wood-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--wood-border);
  background: var(--bg-elevated);
}

.panel-tab {
  flex: 1;
  padding: 12px 8px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.panel-tab:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.panel-tab.active {
  color: var(--text-gold);
  border-bottom-color: var(--gold);
  background: var(--bg-main);
  font-weight: 600;
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.panel-content::-webkit-scrollbar {
  width: 6px;
}
.panel-content::-webkit-scrollbar-track {
  background: var(--bg-deep);
}
.panel-content::-webkit-scrollbar-thumb {
  background: var(--wood-border);
  border-radius: 3px;
}
.panel-content::-webkit-scrollbar-thumb:hover {
  background: var(--bronze);
}

.panel-section {
  margin-bottom: 18px;
}

.panel-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--wood-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title .count {
  font-size: 10px;
  padding: 1px 7px;
  background: var(--bg-card);
  border-radius: 8px;
  color: var(--text-secondary);
}

/* 走棋记录 */
.move-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.move-pair {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg-card);
  border-radius: 4px;
  border-left: 2px solid var(--wood-border);
}

.move-num {
  color: var(--text-muted);
  font-size: 11px;
  min-width: 22px;
}

.move-text {
  flex: 1;
  color: var(--text-primary);
}

.move-red {
  color: var(--red-light);
}

.move-black {
  color: #b8b8c0;
}

.move-empty {
  color: var(--text-dim);
  font-style: italic;
}

/* 历史记录 */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--bg-card);
  border-radius: 6px;
  padding: 10px 12px;
  border: 1px solid var(--wood-border);
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  background: var(--bg-hover);
  border-color: var(--gold);
  transform: translateX(-2px);
}

.history-row1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.history-name {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
}

.history-result {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 3px;
  font-weight: 600;
}

.history-result.win { background: rgba(95, 220, 130, 0.2); color: var(--state-success); }
.history-result.lose { background: rgba(240, 75, 75, 0.2); color: var(--state-danger); }
.history-result.draw { background: rgba(255, 183, 77, 0.2); color: var(--state-warning); }

.history-row2 {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.history-mode {
  padding: 1px 6px;
  background: var(--bg-deep);
  border-radius: 3px;
}

/* 玩家统计 */
.stat-card {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 14px;
  border: 1px solid var(--wood-border);
}

.stat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--wood-border);
}

.stat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--red-face), var(--red-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  color: white;
  border: 2px solid var(--gold);
}

.stat-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-active {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-cell {
  background: var(--bg-deep);
  padding: 10px;
  border-radius: 6px;
  text-align: center;
  border: 1px solid var(--wood-border);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-gold);
  line-height: 1;
}

.stat-value.win { color: var(--state-success); }
.stat-value.lose { color: var(--state-danger); }
.stat-value.draw { color: var(--state-warning); }

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-rate {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, rgba(200, 165, 80, 0.1), rgba(200, 165, 80, 0.05));
  padding: 12px;
  border-radius: 6px;
  text-align: center;
  border: 1px solid var(--wood-border);
}

.stat-rate-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-gold);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.stat-rate-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 2px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* ============================================================
   弹窗
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.modal-backdrop.show {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--gold);
  border-radius: 14px;
  padding: 28px 32px;
  min-width: 380px;
  max-width: 90vw;
  box-shadow:
    0 0 0 1px var(--wood-border),
    var(--shadow-lg);
  position: relative;
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  bottom: 6px;
  border: 1px solid var(--wood-border);
  border-radius: 10px;
  pointer-events: none;
  opacity: 0.5;
}

.modal-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-gold);
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: 2px;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 20px;
}

.modal-body {
  margin: 20px 0;
}

.form-row {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.form-input, .form-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-deep);
  border: 1px solid var(--wood-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: var(--font-zh);
  font-size: 14px;
  transition: all 0.2s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--gold);
  background: var(--bg-main);
  box-shadow: 0 0 0 2px rgba(200, 165, 80, 0.2);
}

.form-select {
  cursor: pointer;
}

.form-radio-group {
  display: flex;
  gap: 10px;
}

.form-radio {
  flex: 1;
  padding: 10px;
  background: var(--bg-deep);
  border: 1px solid var(--wood-border);
  border-radius: 6px;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.form-radio:hover {
  border-color: var(--gold);
  color: var(--text-primary);
}

.form-radio.selected {
  background: linear-gradient(180deg, var(--gold) 0%, var(--bronze) 100%);
  color: var(--red-deep);
  border-color: var(--gold-bright);
  font-weight: 600;
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.3),
    var(--shadow-sm);
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

/* ============================================================
   按钮
   ============================================================ */

.btn {
  padding: 10px 22px;
  border-radius: 6px;
  border: 1px solid var(--wood-border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-zh);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--gold);
  color: var(--text-gold);
}

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

.btn-primary {
  background: linear-gradient(180deg, var(--gold) 0%, var(--bronze) 100%);
  color: var(--red-deep);
  border-color: var(--gold-bright);
  font-weight: 600;
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.3),
    var(--shadow-sm);
}

.btn-primary:hover {
  color: var(--red-deep);
  filter: brightness(1.1);
}

.btn-danger {
  background: linear-gradient(180deg, var(--red-light) 0%, var(--red-face) 100%);
  color: white;
  border-color: var(--red-light);
  font-weight: 600;
}

.btn-danger:hover {
  color: white;
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  border-color: var(--wood-border);
  color: var(--text-secondary);
}

/* ============================================================
   游戏结束对话框
   ============================================================ */

.game-over-result {
  text-align: center;
  padding: 14px 0;
}

.result-text {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-gold);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  margin-bottom: 6px;
}

.result-text.win { color: var(--state-success); }
.result-text.lose { color: var(--state-danger); }
.result-text.draw { color: var(--state-warning); }

.result-detail {
  font-size: 13px;
  color: var(--text-secondary);
}

.game-stats {
  display: flex;
  justify-content: space-around;
  margin: 16px 0;
  padding: 12px;
  background: var(--bg-deep);
  border-radius: 6px;
  border: 1px solid var(--wood-border);
}

.game-stat {
  text-align: center;
}

.game-stat-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-gold);
}

.game-stat-lbl {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================
   Toast
   ============================================================ */

.toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--gold);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 2.7s forwards;
  pointer-events: auto;
}

.toast.success { border-color: var(--state-success); }
.toast.error { border-color: var(--state-danger); }
.toast.warning { border-color: var(--state-warning); }
.toast.info { border-color: var(--state-info); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(-10px); }
}

/* ============================================================
   AI 思考指示
   ============================================================ */

.thinking {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15, 10, 6, 0.85);
  padding: 14px 22px;
  border-radius: 8px;
  border: 1px solid var(--gold);
  color: var(--text-gold);
  font-size: 14px;
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 50;
  box-shadow: var(--shadow-md);
}

.thinking.show {
  display: flex;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  animation: thinking 1.2s infinite ease-in-out;
}

.thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.thinking-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinking {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1.2); }
}

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

@media (max-width: 1024px) {
  .sidepanel { width: 280px; }
  .toolbar { width: 60px; }
  .tool-btn { width: 42px; height: 42px; font-size: 18px; }
}

@media (max-width: 768px) {
  .sidepanel { display: none; }
  .toolbar { width: 54px; }
  .topbar { padding: 10px 16px; }
  .brand-title { font-size: 16px; }
  .brand-sub { display: none; }
}

/* ============================================================
   实用类
   ============================================================ */

.hidden { display: none !important; }
.text-gold { color: var(--text-gold); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--state-success); }
.text-danger { color: var(--state-danger); }
.flex-center { display: flex; align-items: center; justify-content: center; }
