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

:root {
  --bg: #171310;
  --panel: #211a14;
  --panel2: #281f17;
  --line: #3a2e22;
  --text: #e9decb;
  --muted: #9a8a74;
  --gold: #d9a441;
  --red: #c05345;
  --black-chip: #8b93a1;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Heiti SC", sans-serif;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- 顶部 ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0));
  flex: none;
}

h1 { font-size: 19px; letter-spacing: 6px; font-weight: 700; }
.brand .sub {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 2.5px;
  color: var(--muted);
}

#hud { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* 回合状态：浮动显示在棋盘黑底右上角，不占 header 空间 */
#turn {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 6;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid rgba(58, 46, 34, 0.9);
  border-radius: 999px;
  background: rgba(23, 18, 13, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  font-size: 14px;
}

/* 固定视角开关：浮动在棋盘黑底左上角，与回合徽章对称。
   平时只显示图钉图示，滑鼠 hover／键盘 focus 时以动画展开文字标签 */
#btnLock {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 8px;
  border-radius: 999px;
  background: rgba(23, 18, 13, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  border-color: rgba(58, 46, 34, 0.9);
  font-size: 14px;
  transition: gap 0.28s ease, padding 0.28s ease, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
#btnLock svg { flex: none; }
#btnLock .lbl {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  letter-spacing: 1px;
  transition: max-width 0.28s ease, opacity 0.2s ease;
}
#btnLock:hover, #btnLock:focus-visible {
  gap: 7px;
  padding: 8px 14px;
}
#btnLock:hover .lbl, #btnLock:focus-visible .lbl {
  max-width: 104px;
  opacity: 1;
}
#btnLock.on {
  color: var(--gold);
  border-color: rgba(217, 164, 65, 0.55);
  box-shadow: 0 0 16px rgba(217, 164, 65, 0.25);
}
#turnDot { width: 11px; height: 11px; border-radius: 50%; background: var(--red); box-shadow: 0 0 9px var(--red); }

button {
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { background: #33281d; border-color: #4d3c2a; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }

/* 对弈模式选单：外观与按钮一致 */
#modeSel {
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, border-color 0.15s;
}
#modeSel:hover { background: #33281d; border-color: #4d3c2a; }

/* AI 思考中：回合指示灯呼吸闪烁 */
#turn.thinking #turnDot { animation: thinkpulse 1.1s ease-in-out infinite; }
@keyframes thinkpulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.72); }
}

#repoLink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--muted);
  text-decoration: none;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  letter-spacing: 1px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
#repoLink:hover { background: #33281d; border-color: #4d3c2a; color: var(--text); }
#repoLink svg { flex: none; }

/* 「更多」选单按钮：仅小萤幕显示；#hudMore 桌面版摊平成一般按钮列 */
#btnMore { display: none; font-size: 17px; line-height: 1; letter-spacing: 0; padding: 7px 12px; }
#hudMore { display: contents; }
/* 玩法说明仅出现在小萤幕选单（桌面版左栏本来就有说明） */
#btnHelp { display: none; }
/* 「新对局」按钮在小萤幕改用短标签 */
.t-short { display: none; }

/* ---------- 主区域 ---------- */
main { flex: 1; display: flex; min-height: 0; }

#stage { flex: 1; min-width: 0; position: relative; }
#stage canvas { display: block; }

aside {
  width: 232px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px;
  background: var(--panel);
  overflow-y: auto;
}
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }

aside h3 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 8px;
}

.tray { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.chips { min-height: 26px; display: flex; flex-wrap: wrap; gap: 4px; }
.chips em { color: var(--muted); font-size: 13px; font-style: normal; }
.chip {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  background: radial-gradient(circle at 35% 30%, #eed6a8, #c08f52);
}
.chip.red { color: #b32c20; }
.chip.black { color: #26221d; }

.help { color: var(--muted); font-size: 12px; line-height: 1.75; }
.help p { margin-bottom: 4px; }

/* 左下角版权：字体与 .help 说明文字一致，水平置中 */
.copyright {
  margin-top: auto;
  padding-top: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}
.copyright a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 2px;
}
.copyright a:hover { color: var(--text); text-decoration-color: var(--text); }

#log {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
#log li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
}
#log li:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
.side {
  width: 20px; height: 20px;
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}
.side.red { background: rgba(192, 83, 69, 0.2); color: #e08577; border: 1px solid rgba(192, 83, 69, 0.5); }
.side.black { background: rgba(139, 147, 161, 0.16); color: #aeb6c2; border: 1px solid rgba(139, 147, 161, 0.45); }
#logEmpty { color: var(--muted); font-size: 12.5px; line-height: 1.7; padding: 4px 2px; }

/* ---------- 将军提示 ---------- */
#checkBanner {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  font-size: 92px;
  font-weight: 900;
  letter-spacing: 18px;
  padding-left: 18px;
  color: #ffb454;
  text-shadow: 0 0 24px rgba(255, 120, 40, 0.75), 0 4px 22px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  animation: checkpop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) both;
  z-index: 20;
}

@keyframes checkpop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- 胜负覆盖层 ---------- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 5, 0.62);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  animation: fadein 0.25s ease both;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

#confettiCv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.card {
  position: relative;
  width: min(92vw, 440px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 34px 36px 30px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: cardin 0.32s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes cardin { from { opacity: 0; transform: translateY(18px) scale(0.94); } to { opacity: 1; transform: none; } }

/* 胜利：金光；败北：内敛 */
.card.win {
  border-color: rgba(217, 164, 65, 0.55);
  box-shadow:
    0 0 0 1px rgba(217, 164, 65, 0.18),
    0 24px 90px rgba(0, 0, 0, 0.65),
    0 0 80px rgba(217, 164, 65, 0.16);
}
.card.win h2 {
  background: linear-gradient(180deg, #ffe6a8, #f2c14e 55%, #c98f2e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 0 18px rgba(242, 193, 78, 0.35));
}
.card.lose h2 { color: var(--muted); }

#ovBadge {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--gold);
  border: 1px solid rgba(217, 164, 65, 0.45);
  border-radius: 999px;
  padding: 4px 14px;
  margin-bottom: 14px;
  background: rgba(217, 164, 65, 0.08);
}

.card h2 {
  font-size: 38px;
  letter-spacing: 8px;
  padding-left: 8px;
  margin-bottom: 8px;
  color: var(--gold);
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif TC", serif;
  font-weight: 900;
}

#ovStars { font-size: 24px; letter-spacing: 8px; padding-left: 8px; color: #504028; margin-bottom: 6px; }
#ovStars span { display: inline-block; }
#ovStars span.on {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(217, 164, 65, 0.65);
  animation: starpop 0.45s cubic-bezier(0.2, 1.8, 0.4, 1) both;
}
@keyframes starpop {
  0% { opacity: 0; transform: scale(0.2) rotate(-40deg); }
  100% { opacity: 1; transform: none; }
}

#ovSub { color: var(--text); font-size: 14px; letter-spacing: 1px; margin-bottom: 18px; opacity: 0.85; }

#ovStats {
  display: flex;
  justify-content: center;
  gap: 26px;
  padding: 12px 6px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
#ovStats .stat b {
  display: block;
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
#ovStats .stat span { font-size: 11px; letter-spacing: 3px; color: var(--muted); }
/* 全程零悔棋：纯度勋章，金色高亮 */
#ovStats .stat b.pure {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(217, 164, 65, 0.55);
}

#ovReason { color: var(--muted); font-size: 13px; margin-bottom: 20px; letter-spacing: 2px; }

.ovBtns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.ovBtns button { font-size: 15px; padding: 10px 24px; }
.ovBtns .primary {
  background: linear-gradient(180deg, #f0c463, #d9a441);
  border-color: #b98a2f;
  color: #241a0c;
  font-weight: 700;
}
.ovBtns .primary:hover { background: linear-gradient(180deg, #f7d17a, #e2ad4a); }

/* ---------- 提示浮层 ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  max-width: 88vw;
  background: rgba(20, 15, 9, 0.92);
  border: 1px solid rgba(217, 164, 65, 0.5);
  color: var(--text);
  font-size: 13.5px;
  letter-spacing: 1px;
  padding: 10px 20px;
  border-radius: 999px;
  z-index: 40;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  animation: fadein 0.2s ease both;
}

.hidden { display: none !important; }

/* ---------- 小萤幕 ---------- */
@media (max-width: 900px) {
  main { flex-direction: column; }
  /* 棋盘置顶居中，吃子列移到棋盘下方，说明收进选单 */
  #stage { order: 1; flex: 1; }
  #right { display: none; }
  h1 { font-size: 15px; letter-spacing: 3px; }
  .brand .sub { display: none; }

  header { padding: 6px 10px; gap: 8px; }
  #hud { gap: 6px; position: relative; }
  #turn { min-width: 0; padding: 6px 10px; font-size: 12.5px; gap: 6px; }
  #turnDot { width: 9px; height: 9px; }
  button, #modeSel { padding: 6px 10px; font-size: 12.5px; }
  #btnMore { display: inline-flex; align-items: center; justify-content: center; }
  .t-short { display: inline; }
  .t-full { display: none; }

  /* 次要按钮收进「⋯」下拉选单 */
  #hudMore {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-width: 168px;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55);
    z-index: 60;
  }
  #hudMore.open { display: flex; }
  #hudMore > button, #hudMore > #repoLink {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    border-radius: 8px;
  }
  #btnHelp { display: inline-flex; }

  /* 吃子托盘：浮动贴在棋盘底部黑边上，指标事件穿透可继续转视角 */
  #left {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 6;
    flex-direction: row;
    align-items: stretch;
    gap: 8px;
    width: auto;
    max-height: none;
    padding: 0;
    background: transparent;
    border: none;
    pointer-events: none;
  }
  #left .tray {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: rgba(33, 26, 20, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
  #left .tray h3 { margin: 0; font-size: 11px; white-space: nowrap; }
  .chip { width: 22px; height: 22px; font-size: 13px; }
  .chips { min-height: 22px; }
  .chips em { font-size: 12px; }
  .help { display: none; }
  .copyright { display: none; }
  /* 从「⋯ → 玩法说明」展开成浮动说明面板 */
  #left.show-help {
    pointer-events: auto;
    flex-direction: column;
    background: rgba(23, 19, 16, 0.96);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    max-height: 48dvh;
    overflow-y: auto;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  #left.show-help .tray { pointer-events: auto; }
  #left.show-help .help { display: block; }

  #checkBanner { font-size: 54px; letter-spacing: 10px; padding-left: 10px; }
}

@media (max-width: 480px) {
  header { padding: 6px; gap: 6px; }
  #hud { gap: 5px; }
  h1 { font-size: 13px; letter-spacing: 1px; }
  button, #modeSel { padding: 5px 8px; font-size: 11.5px; letter-spacing: 0.5px; }
  #turn { top: 9px; right: 9px; padding: 4px 10px; font-size: 11.5px; gap: 5px; }
  #turnDot { width: 8px; height: 8px; }
  #btnMore { padding: 5px 9px; font-size: 15px; }
}
