/* ========== 变量 ========== */
:root {
  --wood-light: #f0d9b5;
  --wood-mid: #dcb483;
  --wood-dark: #c49a3a;
  --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;
  --tabbar-total-h: calc(var(--tabbar-h) + var(--safe-bottom));
  --header-h: 72px;
  --ad-h: 90px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ========== 重置 & 基础 ========== */
*, *::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);
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
}
.site-header h2 {
  font-size: 0.82rem;
  color: #f0c88a;
  font-weight: normal;
  margin-top: 2px;
  letter-spacing: 0.12em;
}

/* ========== 游戏主区域 ========== */
.game-section {
  display: flex;
  flex-direction: row;
  gap: 16px;
  max-width: 1140px;
  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: 0.95rem;
  color: #fff8e8;
  background: linear-gradient(90deg, #8b4513, #a0522d);
  padding: 8px 14px;
  border-bottom: 1px solid #7a3a10;
}

/* ========== 左侧面板（设置） ========== */
#panel-settings {
  width: 210px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.settings-block {
  padding: 12px 14px;
  border-bottom: 1px solid #e8d0a0;
}
.settings-block:last-child { border-bottom: none; }
.settings-block h3 {
  font-size: 0.88rem;
  color: var(--text-mid);
  margin-bottom: 8px;
}

.mode-btns, .diff-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-mode, .btn-diff {
  padding: 7px 10px;
  border: 1px solid #c49a3a;
  border-radius: var(--radius);
  background: var(--bg-panel-alt);
  color: var(--text-dark);
  cursor: pointer;
  font-size: 0.85rem;
  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: 0.88rem;
  color: var(--text-mid);
  margin-bottom: 8px;
}
.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.85rem;
  border-bottom: 1px dashed #e0c88a;
}
.score-row:last-child { border-bottom: none; }
.score-label { color: var(--text-mid); }
.score-val {
  font-weight: bold;
  color: var(--brown-deep);
  min-width: 28px;
  text-align: right;
}

.sound-toggle {
  padding: 8px 14px;
  border-top: 1px solid #e8d0a0;
}
.btn-sound-toggle {
  width: 100%;
  padding: 6px;
  border: 1px solid #c49a3a;
  border-radius: var(--radius);
  background: var(--bg-panel-alt);
  color: var(--text-dark);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: all 0.18s;
}
.btn-sound-toggle:hover { background: #f0ddb0; }

/* ========== 中部棋盘区 ========== */
#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: 540px;
  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: 1rem;
  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-container {
  width: 100%;
  max-width: 540px;
  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;
}

#gomoku-board {
  display: block;
  width: 100%;
  height: 100%;
}

.action-bar {
  width: 100%;
  max-width: 540px;
  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: 0.88rem;
  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); }
.btn-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ========== 右侧落子记录 ========== */
#panel-kifu {
  width: 190px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: 580px;
}

.move-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.move-list-wrap::-webkit-scrollbar { width: 4px; }
.move-list-wrap::-webkit-scrollbar-track { background: #f0ddb0; }
.move-list-wrap::-webkit-scrollbar-thumb { background: #c49a3a; border-radius: 2px; }

#move-list { list-style: none; }

.move-item {
  display: flex;
  align-items: center;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-mid);
  border-bottom: 1px dashed #f0ddb0;
  transition: background 0.15s;
}
.move-item:hover { background: #f0ddb0; }
.move-item.current { background: #f0ddb0; font-weight: bold; color: var(--text-dark); }
.move-item .piece-dot { margin-right: 6px; font-size: 0.95rem; }

.kifu-footer {
  padding: 8px;
  border-top: 1px solid #e8d0a0;
}
.btn-full {
  width: 100%;
  padding: 7px;
  font-size: 0.82rem;
}

/* ========== 教程面板（手机 tab 用，桌面隐藏） ========== */
#panel-tutorial {
  display: none;
}

/* ========== 广告位（棋盘下方，首屏内） ========== */
.ad-row {
  width: 100%;
  max-width: 540px;
  padding: 4px 0;
  min-height: var(--ad-h);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ad-banner {
  min-height: 60px;
  width: 100%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========== SEO 内容区 ========== */
.page-content {
  max-width: 860px;
  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.1rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 8px;
  margin-bottom: 14px;
}
.content-section p {
  font-size: 0.9rem;
  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: 0.9rem;
  color: var(--text-dark);
  margin-bottom: 6px;
}
.faq-item { margin-bottom: 14px; }
.faq-q {
  font-weight: bold;
  color: var(--brown-deep);
  font-size: 0.92rem;
  margin-bottom: 4px;
}
.faq-a {
  font-size: 0.88rem;
  color: var(--text-dark);
  padding-left: 1em;
}
.extra-content {
  font-size: 0.82rem;
  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.82rem;
  margin-top: auto;
}
footer a { color: #f0c88a; }

/* ========== 游戏结束弹层 ========== */
.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: 320px;
  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.88rem;
  color: var(--text-mid);
  margin-bottom: 20px;
  line-height: 1.6;
}
.overlay-btns { display: flex; gap: 12px; justify-content: center; }
.btn-primary {
  padding: 9px 22px;
  background: var(--btn-bg);
  color: #fff8e8;
  border: 1px solid #6a2e08;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
  box-shadow: var(--btn-shadow);
  transition: all 0.18s;
}
.btn-primary:hover { background: var(--btn-hover); }
.btn-secondary {
  padding: 9px 22px;
  background: var(--bg-panel-alt);
  color: var(--text-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: "KaiTi", "楷体", "STKaiti", Georgia, serif;
  transition: all 0.18s;
}
.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;
}
.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-btn:hover { background: rgba(255,255,255,0.07); }
.tab-icon { font-size: 1.1rem; line-height: 1; }
.tab-label { font-size: 0.68rem; letter-spacing: 0.05em; }

/* ========== 移动端响应式 ========== */
@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.15rem; }
  .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;
  }

  /* 游戏面板（棋盘）在移动端
     必须显式 display:none，覆盖基础 CSS 中 #panel-game { display:flex } 的 ID 规则 */
  #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);
    border-radius: var(--radius);
    box-shadow: none;
  }

  #board-container {
    flex: 1;
    max-width: none;
    aspect-ratio: unset;
    min-height: 0;
    border-radius: 4px;
    box-shadow: none; /* 移除阴影使边缘更自然 */
  }

  .action-bar {
    max-width: none;
    flex-shrink: 0;
    gap: 6px;
    padding-bottom: 4px;
  }

  .btn-action {
    padding: 8px 12px;
    font-size: 0.82rem;
    flex: 1;
    min-width: 60px;
  }

  /* 设置面板在移动端 */
  #panel-settings {
    width: auto;
    overflow-y: auto;
  }

  /* 落子记录在移动端
     必须显式 display:none，覆盖基础 CSS 中 #panel-kifu { display:flex } 的 ID 规则 */
  #panel-kifu {
    display: none;
    width: auto;
    max-height: none;
  }
  #panel-kifu.tab-active {
    display: flex;
    flex-direction: column;
  }

  /* 设置面板激活态 */
  #panel-settings.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-row {
    max-width: none;
    min-height: 70px;
    padding: 4px 8px;
  }

  /* SEO 内容区在移动端（不在首屏，用于爬虫） */
  .page-content {
    padding: 16px;
    margin-top: 0;
    padding-bottom: calc(var(--tabbar-total-h) + 8px);
  }

  footer {
    padding-bottom: calc(var(--tabbar-total-h) + 8px);
  }
}

/* ========== 中等屏幕适配（769-1000px）========== */
@media (min-width: 769px) and (max-width: 1000px) {
  #panel-settings { width: 175px; }
  #panel-kifu { width: 160px; }
  .game-section { gap: 10px; padding: 0 10px; }
}

/* ========== 大屏限制棋盘尺寸 & 保证首屏充满 ========== */
@media (min-width: 769px) {
  /* 棋盘最大高度：扣除 header、game-section 上下边距(16px×2)、状态栏(~36px)、
     gap(10px×3)、操作栏(~38px)、广告区(--ad-h)、底部留白(8px) */
  #board-container {
    max-height: calc(100vh - var(--header-h) - var(--ad-h) - 156px);
  }
  /* 游戏区撑满视口剩余空间（扣除 header），SEO 内容折叠到屏幕以下 */
  .game-section {
    min-height: calc(100vh - var(--header-h) - 8px);
  }
}

/* ========== 滚动条美化 ========== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #f0ddb0; }
::-webkit-scrollbar-thumb { background: #c49a3a; border-radius: 3px; }

/* ========== 其他工具类 ========== */
.about-block {
  padding: 12px 14px;
  border-top: 1px solid #e8d0a0;
  font-size: 0.82rem;
  color: var(--text-mid);
  line-height: 1.7;
}
.about-block h3 {
  font-size: 0.88rem;
  color: var(--text-mid);
  margin-bottom: 6px;
}
.about-block p { margin-bottom: 4px; }

.tutorial-content { padding: 0; }
.tutorial-content h3 {
  font-size: 1rem;
  color: var(--brown-deep);
  margin-bottom: 10px;
}
.tutorial-content p {
  font-size: 0.87rem;
  color: var(--text-dark);
  margin-bottom: 8px;
}
.tutorial-content ul {
  padding-left: 1.3em;
  margin-bottom: 8px;
}
.tutorial-content li {
  font-size: 0.87rem;
  color: var(--text-dark);
  margin-bottom: 5px;
}
