/* ========== 变量 ========== */
:root {
  --wood-light: #f0d9b5;
  --wood-mid: #dcb483;
  --brown-deep: #8b4513;
  --brown-mid: #a0522d;
  --brown-line: #8b5a2b;
  --text-dark: #3a1a00;
  --text-mid: #6b3a1a;
  --text-light: #a06020;
  --bg-page: #f5e6c8;
  --bg-panel: #fdf3e0;
  --bg-panel-alt: #f8ead0;
  --border-color: #c49a3a;
  --shadow: rgba(80, 30, 0, 0.18);
  --btn-bg: linear-gradient(135deg, #b06030, #7a3a10);
  --btn-hover: linear-gradient(135deg, #c07040, #8a4a20);
  --btn-shadow: 0 2px 6px rgba(80,30,0,0.35);
  --radius: 6px;
  --tabbar-h: 54px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-total-h: calc(var(--tabbar-h) + var(--safe-bottom));
  --header-h: 76px;
  --game-section-top: 18px;
  --game-section-bottom: 28px;
  --game-section-pad: calc(var(--game-section-top) + var(--game-section-bottom));
}

/* ========== 重置 & 基础 ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: "SimSun", "宋体", "STSong", Georgia, serif;
  background: var(--bg-page);
  color: var(--text-dark);
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--brown-mid); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 {
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
  color: var(--brown-deep);
  line-height: 1.4;
}

/* ========== 顶部导航 ========== */
.site-header {
  background: linear-gradient(135deg, #8b4513 0%, #6b2e0a 100%);
  color: #fff8e8;
  text-align: center;
  padding: 14px 20px 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
  position: relative;
  z-index: 10;
}
.site-header h1 {
  font-size: 1.55rem;
  color: #fff8e8;
  letter-spacing: 0.08em;
  text-shadow: 1px 2px 4px rgba(0,0,0,0.5);
}
.site-header h2 {
  font-size: 0.95rem;
  color: #f0c88a;
  font-weight: normal;
  margin-top: 2px;
  letter-spacing: 0.1em;
}

/* ========== 游戏主区域 ========== */
.game-section {
  display: flex;
  flex-direction: row;
  gap: 16px;
  max-width: 1280px;
  margin: 16px auto;
  padding: 0 16px;
  width: 100%;
  align-items: flex-start;
  flex: 1;
}

/* ========== 面板通用 ========== */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px var(--shadow);
  overflow: hidden;
}
.panel-title {
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
  font-size: 1rem;
  color: #fff8e8;
  background: linear-gradient(90deg, #8b4513, #a0522d);
  padding: 8px 14px;
  border-bottom: 1px solid #7a3a10;
}

/* ========== 左侧设置面板 ========== */
#panel-settings {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.settings-block {
  padding: 12px 14px;
  border-bottom: 1px solid #e8d0a0;
}
.settings-block h3 {
  font-size: 1rem;
  color: var(--text-mid);
  margin-bottom: 8px;
}
.mode-btns, .diff-btns { display: flex; flex-direction: column; gap: 6px; }
.btn-mode, .btn-diff {
  padding: 8px 10px;
  border: 1px solid #c49a3a;
  border-radius: var(--radius);
  background: var(--bg-panel-alt);
  color: var(--text-dark);
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
  transition: all 0.18s;
}
.btn-mode:hover, .btn-diff:hover { background: #f0ddb0; }
.btn-mode.active, .btn-diff.active {
  background: var(--btn-bg);
  color: #fff8e8;
  border-color: #7a3a10;
  box-shadow: var(--btn-shadow);
}

.score-board { padding: 10px 14px; }
.score-board h3 { font-size: 1rem; color: var(--text-mid); margin-bottom: 8px; }
.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 1rem;
  border-bottom: 1px dashed #e0c88a;
}
.score-label { color: var(--text-mid); }
.score-val { font-weight: bold; color: var(--brown-deep); min-width: 28px; text-align: right; }
.record-list { list-style: none; margin-top: 8px; max-height: 140px; overflow-y: auto; }
.record-item {
  font-size: 0.95rem;
  padding: 3px 0;
  border-bottom: 1px dashed #f0ddb0;
  color: var(--text-mid);
}
.record-black { color: #2a2a2a; }
.record-white { color: #8a6020; }
.record-draw { color: #999; }
.record-empty { font-size: 0.95rem; color: var(--text-light); padding: 4px 0; }

.sound-toggle { padding: 8px 14px; border-top: 1px solid #e8d0a0; display: flex; flex-direction: column; gap: 6px; }
.btn-sound-toggle {
  width: 100%;
  padding: 7px;
  border: 1px solid #c49a3a;
  border-radius: var(--radius);
  background: var(--bg-panel-alt);
  color: var(--text-dark);
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.18s;
}
.btn-sound-toggle:hover { background: #f0ddb0; }
.privacy-note {
  padding: 0 14px 12px;
  font-size: 0.82rem;
  color: var(--text-light);
  line-height: 1.5;
}
.privacy-note a { color: var(--brown-mid); }

/* ========== 中部棋盘区 ========== */
#panel-game {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.game-status-bar {
  width: 100%;
  max-width: 680px;
  text-align: center;
  padding: 8px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 2px 6px var(--shadow);
}
#game-status {
  font-size: 1.05rem;
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
  color: var(--text-dark);
  transition: color 0.2s;
}
#game-status.status-white { color: #555; }
#game-status.thinking {
  color: var(--brown-mid);
  animation: thinking-pulse 1s ease-in-out infinite;
}
@keyframes thinking-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

#board-wrap {
  width: 100%;
  max-width: 680px;
  aspect-ratio: 1 / 1;
  background: var(--wood-mid);
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(80,30,0,0.35), inset 0 0 30px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
#board { display: block; width: 100%; height: 100%; }

.action-bar {
  width: 100%;
  max-width: 680px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn-action {
  padding: 8px 18px;
  background: var(--btn-bg);
  color: #fff8e8;
  border: 1px solid #6a2e08;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
  box-shadow: var(--btn-shadow);
  transition: all 0.18s;
  white-space: nowrap;
}
.btn-action:hover { background: var(--btn-hover); transform: translateY(-1px); box-shadow: 0 3px 8px rgba(80,30,0,0.4); }
.btn-action:active { transform: translateY(0); }

/* ========== 广告位 ========== */
.ad-slot {
  display: none;
  min-height: 60px;
  max-height: 60px;
  margin: 10px 16px;
  color: #999;
  font-size: 14px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.ad-slot:not(:empty) { display: flex; flex: 0 0 60px; }
.ad-slot img {
  display: block;
  width: 100%;
  height: 60px;
  object-fit: contain;
}

/* ========== 右侧棋谱 + 分析 ========== */
#panel-kifu {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: 700px;
}
.analysis-box {
  padding: 10px 12px;
  border-bottom: 1px solid #e8d0a0;
  background: var(--bg-panel-alt);
}
.analysis-empty { font-size: 0.95rem; color: var(--text-light); }
.analysis-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.analysis-table th, .analysis-table td {
  padding: 3px 4px;
  text-align: center;
  border-bottom: 1px dashed #e0c88a;
}
.analysis-table th { color: var(--text-mid); font-weight: bold; }
.analysis-table td:first-child, .analysis-table th:first-child { text-align: left; color: var(--text-mid); }
.analysis-tip { font-size: 0.88rem; color: var(--text-light); margin-top: 6px; line-height: 1.5; }

.move-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  min-height: 80px;
}
#moveList { list-style: none; }
#moveList li {
  display: flex;
  align-items: center;
  padding: 5px 12px;
  font-size: 0.95rem;
  color: var(--text-mid);
  border-bottom: 1px dashed #f0ddb0;
}
#moveList li.current { background: #f0ddb0; font-weight: bold; color: var(--text-dark); }
#moveList .piece-dot { margin-right: 6px; font-size: 1rem; }

.kifu-footer { padding: 8px; border-top: 1px solid #e8d0a0; }
.btn-full { width: 100%; padding: 8px; font-size: 0.95rem; }

/* ========== 教程面板（桌面隐藏） ========== */
#panel-tutorial { display: none; }

/* ========== 内容区 ========== */
.page-content { max-width: 880px; margin: 0 auto 24px; padding: 0 16px; width: 100%; }
.content-section {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px var(--shadow);
}
.content-section h2 {
  font-size: 1.2rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 8px;
  margin-bottom: 14px;
}
.content-section p { font-size: 1rem; color: var(--text-dark); margin-bottom: 10px; }
.content-section p:last-child { margin-bottom: 0; }
.content-section ul, .content-section ol { padding-left: 1.4em; margin: 8px 0; }
.content-section li { font-size: 1rem; color: var(--text-dark); margin-bottom: 6px; }
.feature-list { list-style: none; padding-left: 0; margin: 12px 0 0; }
.feature-list li {
  font-size: 1rem;
  color: var(--text-dark);
  padding: 7px 0 7px 24px;
  position: relative;
  border-bottom: 1px dashed #e8d0a0;
}
.feature-list li:last-child { border-bottom: none; }
.feature-list li::before {
  content: "●";
  position: absolute;
  left: 4px;
  top: 7px;
  color: var(--brown-mid);
  font-size: 0.8rem;
}
.feature-list strong { color: var(--brown-deep); }

.guide-steps { list-style: none; padding-left: 0; margin: 12px 0 0; counter-reset: step; }
.guide-steps > li {
  position: relative;
  padding: 0 0 14px 36px;
  margin-bottom: 14px;
  border-bottom: 1px dashed #e8d0a0;
}
.guide-steps > li:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.guide-steps > li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 26px;
  height: 26px;
  line-height: 26px;
  text-align: center;
  background: var(--btn-bg);
  color: #fff8e8;
  border-radius: 50%;
  font-size: 0.95rem;
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
  box-shadow: var(--btn-shadow);
}
.guide-steps > li strong { display: block; color: var(--brown-deep); font-size: 1.02rem; margin-bottom: 4px; }
.guide-steps > li p { font-size: 0.98rem; color: var(--text-dark); margin: 0; }

.faq-item { margin-bottom: 14px; }
.faq-q { font-weight: bold; color: var(--brown-deep); font-size: 1rem; margin-bottom: 4px; }
.faq-a { font-size: 0.98rem; color: var(--text-dark); padding-left: 1em; }
.extra-content { font-size: 0.95rem; color: var(--text-light); padding: 10px 0; line-height: 1.8; }

/* ========== 页脚 ========== */
footer {
  background: linear-gradient(135deg, #6b2e0a, #8b4513);
  color: #f0c88a;
  text-align: center;
  padding: 14px 20px;
  font-size: 0.92rem;
  margin-top: auto;
}
footer a { color: #f0c88a; }
footer p { margin-bottom: 4px; }

/* ========== 结束弹层 ========== */
.overlay { position: fixed; inset: 0; z-index: 300; display: none; align-items: center; justify-content: center; }
.overlay.visible { display: flex; }
.overlay-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.overlay-card {
  position: relative;
  background: linear-gradient(145deg, #fdf3e0, #f5e0c0);
  border: 2px solid #8b4513;
  border-radius: 12px;
  padding: 28px 24px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45);
  animation: pop-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes pop-in { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.result-icon { font-size: 2.4rem; margin-bottom: 8px; }
.result-text { font-size: 1.4rem; color: var(--brown-deep); margin-bottom: 8px; }
.commentary-text { font-size: 0.98rem; color: var(--text-mid); margin-bottom: 20px; line-height: 1.6; }
.overlay-btns { display: flex; gap: 12px; justify-content: center; }
.btn-primary, .btn-secondary {
  padding: 9px 22px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
  transition: all 0.18s;
}
.btn-primary { background: var(--btn-bg); color: #fff8e8; border: 1px solid #6a2e08; box-shadow: var(--btn-shadow); }
.btn-primary:hover { background: var(--btn-hover); }
.btn-secondary { background: var(--bg-panel-alt); color: var(--text-dark); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: #f0ddb0; }

/* ========== 底部 TabBar ========== */
.tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tabbar-h);
  background: linear-gradient(180deg, #7a3a10, #5a2200);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
  z-index: 200;
  border-top: 1px solid #c49a3a;
}
/* 向下溢出一段同色背景：盖掉部分机型/缩放下底部 1~2px 缝隙与安全区底色，
   正常机型这段在视口外不可见，无副作用 */
.tabbar::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 40px;
  background: #5a2200;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: #c49a3a;
  transition: color 0.18s, background 0.18s;
  padding: 4px 0;
}
.tab-btn.active { color: #fff8e8; background: rgba(255,255,255,0.1); }
.tab-icon { font-size: 1.15rem; line-height: 1; }
.tab-label { font-size: 0.72rem; letter-spacing: 0.05em; }

/* ========== 桌面：游戏区锁定首屏，广告位完整可见 ========== */
@media (min-width: 769px) {
  .game-section {
    flex: none;
    height: calc(100dvh - var(--header-h) - var(--game-section-pad));
    max-height: calc(100dvh - var(--header-h) - var(--game-section-pad));
    margin: var(--game-section-top) auto var(--game-section-bottom);
    align-items: flex-start;
    overflow: hidden;
  }
  #panel-game {
    align-self: flex-start;
    min-height: 0;
    overflow: hidden;
    justify-content: flex-start;
  }
  #panel-settings,
  #panel-kifu {
    align-self: flex-start;
  }
  #board-wrap {
    flex: 0 0 auto;
    min-height: 0;
    max-height: none;
    aspect-ratio: unset;
  }
  #panel-settings,
  #panel-kifu {
    max-height: 100%;
    overflow: hidden;
  }
  .ad-slot:not(:empty) {
    flex: 0 0 60px;
    margin: 6px 0 0;
    width: 100%;
    max-width: 680px;
  }
}
@media (min-width: 769px) and (max-width: 1040px) {
  #panel-settings { width: 185px; }
  #panel-kifu { width: 185px; }
  .game-section { gap: 10px; padding: 0 10px; }
}

/* ========== 移动端 ========== */
@media (max-width: 768px) {
  :root { --header-h: calc(44px + var(--safe-top)); }
  body { min-height: 100dvh; }

  .site-header { padding: calc(8px + var(--safe-top)) 16px 6px; }
  .site-header h1 { font-size: 1.2rem; }
  .site-header h2 { display: none; }

  .game-section {
    flex-direction: column;
    margin: 0;
    padding: 0;
    gap: 0;
    height: calc(100dvh - var(--header-h) - var(--tabbar-total-h));
    position: relative;
    overflow: hidden;
    flex: none;
  }

  .panel {
    position: absolute;
    inset: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    display: none;
    width: 100%;
    height: 100%;
    overflow-y: auto;
  }
  .panel.tab-active { display: flex; flex-direction: column; }

  #panel-game { display: none; background: var(--wood-mid); padding: 8px; gap: 8px; align-items: stretch; }
  #panel-game.tab-active { display: flex; flex-direction: column; background: var(--wood-mid); }

  .game-status-bar {
    max-width: none;
    padding: 6px 12px;
    flex-shrink: 0;
    background: rgba(0,0,0,0.1);
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: none;
  }
  #board-wrap {
    flex: 1;
    max-width: none;
    aspect-ratio: unset;
    min-height: 0;
    box-shadow: none;
  }
  .action-bar { max-width: none; flex-shrink: 0; gap: 6px; padding-bottom: 4px; }
  .btn-action { padding: 8px 10px; font-size: 0.95rem; flex: 1; min-width: 56px; }

  #panel-settings { width: auto; overflow-y: auto; }
  #panel-settings.tab-active { display: flex; flex-direction: column; }
  #panel-kifu { display: none; width: auto; max-height: none; }
  #panel-kifu.tab-active { display: flex; flex-direction: column; }

  #panel-tutorial { display: none; }
  #panel-tutorial.tab-active { display: flex; flex-direction: column; overflow-y: auto; padding: 16px; gap: 12px; }

  .tabbar { display: flex; height: var(--tabbar-total-h); padding-bottom: var(--safe-bottom); }

  .ad-slot { margin: 8px; }

  .page-content { padding: 16px; padding-bottom: calc(var(--tabbar-total-h) + 8px); }
  footer { padding-bottom: calc(var(--tabbar-total-h) + 8px); }
}

/* ========== 滚动条 ========== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #f0ddb0; }
::-webkit-scrollbar-thumb { background: #c49a3a; border-radius: 3px; }

/* ========== 返回顶部按钮 ========== */
#btn-back-top {
  position: fixed;
  right: 20px;
  bottom: 30px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  z-index: 180;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btn-back-top::before {
  content: "";
  display: block;
  width: 11px;
  height: 11px;
  border-left: 2.5px solid #8b4513;
  border-top: 2.5px solid #8b4513;
  transform: rotate(45deg) translateY(2px);
  border-radius: 1px;
}
#btn-back-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
#btn-back-top:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.26); }
@media (max-width: 768px) {
  #btn-back-top { right: 12px; bottom: calc(var(--tabbar-total-h) + 12px); }
}

/* ========== 教程内容 ========== */
.tutorial-content { padding: 14px; }
.tutorial-content h3 { font-size: 1.1rem; color: var(--brown-deep); margin: 12px 0 8px; }
.tutorial-content h3:first-child { margin-top: 0; }
.tutorial-content p { font-size: 1rem; color: var(--text-dark); margin-bottom: 8px; }
.tutorial-content ul { padding-left: 1.3em; margin-bottom: 8px; }
.tutorial-content li { font-size: 1rem; color: var(--text-dark); margin-bottom: 5px; }
