/* ============================================================
 * 五子棋大师 · 样式
 * 布局：桌面三栏（信息 / 棋盘 / 操作），移动端单栏
 * 主题：由 JS 注入 CSS 变量，canvas 与页面同步换色
 * ============================================================ */

:root {
  /* 主题变量（JS applyTheme 会覆盖这些值） */
  --page-bg: linear-gradient(160deg, #fdf8f0 0%, #f2ebdf 100%);
  --panel: #ffffff;
  --panel-alt: #faf7f1;
  --ink: #2d2a26;
  --muted: #8a8378;
  --faint: #c3bbb0;
  --border: #ece5d9;
  --accent: #ef9c33;
  --accent-dark: #d4831b;
  --accent-soft: #fdf2e2;
  --green: #3d9c6b;
  --red: #e05a4b;
  --board-glow: rgba(90, 61, 26, .28);

  --radius: 16px;
  --shadow-sm: 0 2px 8px rgba(90, 61, 26, .07);
  --shadow: 0 8px 24px rgba(90, 61, 26, .10);
  --shadow-lg: 0 18px 46px var(--board-glow);

  --rail-left: 226px;
  --rail-right: 214px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--page-bg);
  background-attachment: fixed;
  color: var(--ink);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background .35s ease, color .35s ease;
}
button { font-family: inherit; }

.hidden { display: none !important; }
.screen { animation: fadeIn .28s ease; }

/* ============================================================
 * 首页
 * ============================================================ */
.home-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 32px 20px 24px;
  gap: 22px;
}
.home-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 620px;
}
.home-head { text-align: center; display: flex; flex-direction: column; gap: 10px; }
.hero-logo {
  font-size: 46px;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent) 60%, #e8663c);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.15;
}
.hero-sub {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  max-width: 420px;
  margin: 0 auto;
}

.diff-cards { display: flex; flex-direction: column; gap: 11px; width: 100%; }
.diff-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 15px 18px;
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-align: left;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.diff-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 12px 28px rgba(90, 61, 26, .14);
}
.diff-card:active { transform: translateY(-1px) scale(.995); }
.dc-icon { font-size: 30px; flex-shrink: 0; line-height: 1; }
.dc-text { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.dc-title { font-size: 16px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; }
.dc-title em {
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 20px;
  padding: 2px 8px;
}
.dc-desc { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.dc-go { font-size: 18px; color: var(--faint); flex-shrink: 0; transition: transform .18s, color .18s; }
.diff-card:hover .dc-go { transform: translateX(4px); color: var(--accent); }

.home-tips {
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: var(--shadow-sm);
  width: 100%;
}

/* ============================================================
 * 对弈页：三栏 grid
 * ============================================================ */
.board-screen {
  height: 100dvh;
  overflow: hidden;
}
@supports not (height: 100dvh) {
  .home-screen { min-height: 100vh; }
  .board-screen { height: 100vh; }
}

.app {
  display: grid;
  grid-template-columns: var(--rail-left) minmax(0, 1fr) var(--rail-right);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "brand   board  diff"
    "status  board  actions"
    "coach   board  actions"
    "coach   board  utility";
  gap: 11px;
  padding: 13px;
  height: 100%;
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 0;
}
.brand-dot {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #6a6a6a, #0d0d0d);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .3);
  flex-shrink: 0;
}
.brand-name {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .5px;
  color: var(--accent-dark);
}

.block {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px;
  transition: background .35s ease;
}
.block-status  { grid-area: status; }
.block-diff    { grid-area: diff; }
.block-actions { grid-area: actions; }
.block-utility {
  grid-area: utility;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 8px;
  background: transparent;
  box-shadow: none;
}
.block-coach {
  grid-area: coach;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}

.rail-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--faint);
  margin-bottom: 9px;
  text-transform: uppercase;
}

/* 回合徽章 */
.turn-badge {
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14.5px;
  text-align: center;
  background: var(--panel-alt);
  color: var(--ink);
  transition: background .2s, color .2s;
}
.turn-badge.black    { background: #2c2c2c; color: #fff; }
.turn-badge.white    { background: #fff; color: #2c2c2c; border: 2px solid var(--border); }
.turn-badge.thinking { background: var(--accent); color: #fff; }
.turn-badge.win      { background: var(--green); color: #fff; animation: pop .4s ease; }
.turn-badge.lose     { background: var(--red); color: #fff; animation: pop .4s ease; }
.turn-badge.draw     { background: #8d8577; color: #fff; }

.meta-list { margin-top: 11px; display: flex; flex-direction: column; gap: 2px; }
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  padding: 5px 2px;
  border-bottom: 1px dashed var(--border);
}
.meta-row:last-child { border-bottom: none; }
.meta-row span { color: var(--muted); }
.meta-row b { font-weight: 700; }

/* 助教 */
.coach-head { display: flex; align-items: center; gap: 9px; }
.coach-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #ffeccb, #f6c98c);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  border: 2.5px solid #fff;
  box-shadow: 0 4px 12px rgba(240, 162, 58, .32);
  flex-shrink: 0;
  transition: transform .25s ease;
}
.coach-avatar.pulse { animation: coachPulse .55s ease; }
.coach-name { font-weight: 700; font-size: 13.5px; color: var(--accent-dark); }
.coach-bubble {
  position: relative;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--ink);
  flex: 1;
  min-height: 60px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .28s ease, transform .28s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.coach-bubble.show { opacity: 1; transform: translateY(0); }
.coach-bubble b { color: var(--accent-dark); }
.coach-bubble .pt {
  display: inline-block;
  background: var(--accent); color: #fff;
  border-radius: 6px; padding: 0 6px; 
  font-weight: 700; font-size: 12px;
  margin: 0 1px;
}

/* 助教气泡：消息列表样式（2026-09-13）
   支持多条连续指令同时显示，新消息在底部，旧的可滚走 */
.coach-bubble {
  scrollbar-width: thin;
  scrollbar-color: rgba(180, 130, 60, 0.35) transparent;
}
.coach-bubble::-webkit-scrollbar { width: 5px; }
.coach-bubble::-webkit-scrollbar-track { background: transparent; }
.coach-bubble::-webkit-scrollbar-thumb {
  background: rgba(180, 130, 60, 0.35);
  border-radius: 3px;
}
.coach-bubble::-webkit-scrollbar-thumb:hover { background: rgba(180, 130, 60, 0.55); }
.coach-msg {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  animation: msgIn .35s ease;
  flex-shrink: 0;
}
.coach-msg .msg-face {
  flex-shrink: 0;
  font-size: 16px;
  line-height: 1.55;
}
.coach-msg .msg-text {
  flex: 1;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}

/* 棋盘舞台 */
.board-stage {
  grid-area: board;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: #e8cf9c;
}
#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: pointer;
}

/* 难度按钮 */
.diff-select { display: grid; grid-template-columns: 1fr; gap: 6px; }
.diff-btn {
  padding: 9px 10px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--ink);
  text-align: left;
  transition: all .15s ease;
  white-space: nowrap;
}
.diff-btn:hover { border-color: var(--accent); }
.diff-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
  box-shadow: 0 4px 12px rgba(239, 156, 51, .32);
}

/* 操作按钮 */
.action-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ctl-btn {
  padding: 9px 8px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--panel-alt);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  transition: all .15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ctl-btn:hover { background: var(--accent-soft); transform: translateY(-1px); }
.ctl-btn:active { transform: scale(.97); }
.ctl-btn.toggle.on  { background: var(--green); color: #fff; }
.ctl-btn.toggle.off { color: var(--faint); }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font-size: 17px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.icon-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.icon-btn:active { transform: scale(.94); }

/* ============================================================
 * 弹窗
 * ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(35, 28, 20, .5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 18px;
  animation: fadeIn .22s ease;
}
.modal {
  background: var(--panel);
  border-radius: 20px;
  padding: 24px;
  max-width: 520px;
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
  animation: pop .28s ease;
}
.modal h3 { font-size: 20px; text-align: center; margin-bottom: 7px; }
.modal .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 18px; line-height: 1.6; }
.modal-section { margin-bottom: 18px; }
.modal-section h4 { font-size: 14px; margin-bottom: 10px; color: var(--accent-dark); }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.modal-actions button {
  padding: 10px 22px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: transform .15s ease, filter .15s ease;
}
.modal-actions button:hover { transform: translateY(-2px); filter: brightness(1.04); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--panel-alt); color: var(--ink); }

.tp-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  margin-bottom: 7px;
  cursor: pointer;
  font-size: 13px;
  transition: all .15s ease;
}
.tp-row:hover { background: var(--accent-soft); border-color: var(--accent); transform: translateX(3px); }
.tp-row .tp-why { color: var(--muted); font-size: 12px; }
.tp-row .tp-arrow { color: var(--red); flex-shrink: 0; }
/* 方位小标签：左上角 / 中腹 之类，帮用户在盘边坐标上快速定位 */
.tp-row .tp-where {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  margin-left: 3px;
  white-space: nowrap;
}
.review-note {
  background: #edf8f1;
  color: var(--green);
  padding: 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
}

.chart-wrap {
  position: relative;
  height: 96px;
  display: flex;
  align-items: flex-end;
  gap: 1px;
  background: var(--panel-alt);
  border-radius: 10px;
  padding: 6px;
  overflow: hidden;
}
.chart-col {
  flex: 1;
  min-width: 2px;
  border-radius: 2px 2px 0 0;
  transition: height .3s ease;
}
.chart-note { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }

/* 皮肤面板 */
.skin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; }
.skin-card {
  border: 2px solid var(--border);
  border-radius: 13px;
  background: var(--panel);
  cursor: pointer;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  transition: all .16s ease;
}
.skin-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.skin-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.skin-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 9px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .07);
}
.skin-preview::before,
.skin-preview::after {
  content: '';
  position: absolute;
  background: currentColor;
  opacity: .55;
}
.skin-preview::before { left: 0; right: 0; top: 50%; height: 1px; }
.skin-preview::after  { top: 0; bottom: 0; left: 50%; width: 1px; }
.skin-dot-b, .skin-dot-w {
  position: absolute;
  width: 26%; height: 26%;
  border-radius: 50%;
  z-index: 1;
}
.skin-dot-b { left: 13%; top: 13%;   background: radial-gradient(circle at 33% 28%, #6d6d6d, #0c0c0c); }
.skin-dot-w { right: 13%; bottom: 13%; background: radial-gradient(circle at 33% 28%, #fff, #cfcfcf); box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.skin-name { font-size: 12px; font-weight: 700; }
.skin-card.active .skin-name { color: var(--accent-dark); }

/* ============================================================
 * 页脚备案信息
 * ============================================================ */
.site-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, .07);
  text-align: center;
  font-size: 12px;
  color: #9a8f82;
  line-height: 1.9;
  width: 100%;
  max-width: 640px;
}
.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}
.footer-links a, .footer-links span { color: #9a8f82; text-decoration: none; }
.footer-links a:hover { color: var(--accent-dark); text-decoration: underline; }
.footer-sep { opacity: .45; }
.footer-copy { font-size: 11px; opacity: .75; margin-top: 2px; }
.footer-gongan-icon { width: 14px; height: 14px; vertical-align: -2px; margin-right: 3px; }

/* ============================================================
 * 动画
 * ============================================================ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  0%   { transform: scale(.86); opacity: 0; }
  60%  { transform: scale(1.03); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes coachPulse {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.16) rotate(-5deg); }
  100% { transform: scale(1); }
}

/* ============================================================
 * 响应式：平板 / 手机
 * ============================================================ */
@media (max-width: 980px) {
  :root { --rail-left: 200px; --rail-right: 190px; }
  .app { gap: 9px; padding: 10px; }
  .block { padding: 10px; }
  .brand-name { font-size: 15px; }
  .ctl-btn { font-size: 11px; padding: 8px 6px; }
  .diff-btn { font-size: 11.5px; padding: 8px; }
}

/* 手机：单栏，棋盘尽量占满宽度 */
@media (max-width: 820px) {
  /* 竖屏：让内容撑满一屏，棋盘吃掉多余空间，避免底部大片留白 */
  .board-screen {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  .app {
    grid-template-columns: minmax(0, 1fr) auto;
    /* board 用 1fr：把所有剩余高度都给棋盘 */
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
    grid-template-areas:
      "brand   utility"
      "status  status"
      "board   board"
      "actions actions"
      "diff    diff"
      "coach   coach";
    gap: 8px;
    padding: 8px;
    height: 100%;
    min-height: 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .brand { padding: 2px 4px; }
  .brand-name { font-size: 15px; }
  .block-utility { padding: 0; grid-area: utility; }
  .icon-btn { width: 36px; height: 36px; font-size: 15px; }

  /* 状态区压成一行 */
  .block-status { display: flex; align-items: center; gap: 10px; padding: 9px 12px; }
  .turn-badge { padding: 7px 14px; font-size: 13.5px; flex-shrink: 0; }
  .meta-list {
    margin-top: 0;
    flex-direction: row;
    gap: 14px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .meta-list::-webkit-scrollbar { display: none; }
  .meta-row { border-bottom: none; padding: 0; font-size: 12px; gap: 5px; white-space: nowrap; }
  .meta-row:first-child { display: none; }

  /* 棋盘：居中，尽量占满可用空间 */
  .board-stage { padding: 0; min-height: 0; }
  .board-wrap { aspect-ratio: 1 / 1; }

  /* 难度横向 */
  .block-diff { padding: 9px 10px; }
  .block-diff .rail-label { display: none; }
  .diff-select { grid-template-columns: repeat(4, 1fr); gap: 5px; }
  .diff-btn { text-align: center; padding: 8px 2px; font-size: 11.5px; }

  /* 操作按钮：改成 3 列网格，全部可见，不再横向滚动截断 */
  .block-actions { padding: 9px 10px; }
  .block-actions .rail-label { display: none; }
  .action-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    overflow: visible;
  }
  .ctl-btn {
    padding: 9px 4px;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 助教紧凑 */
  .block-coach {
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    padding: 11px;
    overflow: visible;
  }
  .coach-head { flex-direction: column; gap: 3px; }
  .coach-avatar { width: 38px; height: 38px; font-size: 21px; }
  .coach-name { font-size: 10.5px; }
  .coach-bubble { min-height: 44px; font-size: 12.5px; padding: 9px 11px; }

  .hero-logo { font-size: 34px; }
  .home-screen { padding: 24px 14px 20px; gap: 18px; }
  .home-inner { gap: 18px; }
  .site-footer { font-size: 11px; }
  .modal { padding: 20px; }
}

@media (max-width: 380px) {
  .diff-btn { font-size: 11px; padding: 7px 1px; }
  .dc-desc { font-size: 12px; }
  .dc-icon { font-size: 26px; }
}

/* 手机横屏：回到三栏，棋盘按高度撑满（此时左右能放文字） */
@media (orientation: landscape) and (max-height: 620px) and (max-width: 980px) {
  .board-screen { height: 100dvh; overflow: hidden; }
  .app {
    grid-template-columns: minmax(150px, 190px) minmax(0, 1fr) minmax(130px, 168px);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand   board  diff"
      "status  board  actions"
      "coach   board  actions"
      "coach   board  utility";
    height: 100%;
    padding: 8px;
    gap: 8px;
  }
  .block-utility { grid-area: utility; padding: 0; }
  .icon-btn { width: 34px; height: 34px; font-size: 14px; }
  .block-status { display: block; padding: 10px; }
  .meta-list { flex-direction: column; gap: 0; }
  .meta-row { border-bottom: 1px dashed var(--border); font-size: 11.5px; padding: 3px 2px; }
  .meta-row:first-child { display: flex; }
  .diff-select { grid-template-columns: 1fr; }
  .diff-btn { font-size: 11px; padding: 7px 8px; text-align: left; }
  .action-list { display: grid; grid-template-columns: 1fr 1fr; }
  .ctl-btn { font-size: 10.5px; padding: 7px 4px; }
  .block-coach { flex-direction: column; overflow-y: auto; }
  .coach-head { flex-direction: row; }
  .coach-avatar { width: 36px; height: 36px; font-size: 20px; }
  .coach-bubble { font-size: 11.5px; min-height: 0; }
  .brand-name { font-size: 13px; }
  .rail-label { font-size: 10px; margin-bottom: 6px; }
}
