/* ===== 重置与基础 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --board-bg: #f4e4c1;
  --board-line: #8b4513;
  --red-piece: #c0392b;
  --black-piece: #1a1a1a;
  --gold: #f8d568;
  --primary: #8b4513;
  --primary-hover: #6b3410;
  --secondary: #5a6e7f;
  --secondary-hover: #445566;
  --bg: #faf6ee;
  --text: #2c1a0e;
  --text-light: #7a5c3c;
  --border: #d4b483;
  --shadow: rgba(0,0,0,0.15);
  --radius: 8px;
  --tab-active: #8b4513;
  --tab-bg: #f0e0c0;
  --header-h: 46px;
  --chrome-top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  --chrome: #8b4513;
  --panel: #fff;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  background-color: var(--bg);
  color-scheme: light;
}

html[data-night] {
  color-scheme: dark;
  --bg: #151311;
  --text: #eee7dc;
  --text-light: #b9aa98;
  --border: #4a4035;
  --shadow: rgba(0, 0, 0, 0.5);
  --tab-bg: #1c1916;
  --tab-active: #d49a55;
  --chrome: #211914;
  --panel: #24201c;
  --primary: #b86e2e;
  --primary-hover: #ce8240;
  --red-piece: #ff7865;
  --black-piece: #c5b8a5;
}

body {
  font-family: 'PingFang SC', 'Microsoft YaHei', 'SimHei', sans-serif;
  font-size: 15px;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  border: none;
  border-radius: var(--radius);
  transition: background 0.2s, transform 0.1s;
}
button:active {
  transform: scale(0.97);
}

select {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 5px 10px;
  cursor: pointer;
}

@supports (appearance: base-select) {
  .control-section select,
  .control-section select::picker(select) {
    appearance: base-select;
  }
  .control-section select {
    display: flex;
    align-items: center;
    justify-content: space-between;
    overflow: hidden;
    white-space: nowrap;
    padding-right: 10px;
  }
  .control-section select::picker-icon {
    flex: 0 0 auto;
    margin-inline-start: auto;
    color: var(--text-light);
  }
  .control-section select::picker(select) {
    position-area: block-end span-inline-end;
    position-try-fallbacks: none;
    margin-top: 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    box-shadow: 0 8px 24px rgba(44, 26, 14, 0.18);
    max-height: min(280px, 50vh);
    overflow-y: auto;
  }
  .control-section select option {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
  }
  .control-section select option::checkmark {
    display: none;
  }
  .control-section select option:hover,
  .control-section select option:focus {
    background: #f0e8d8;
  }
  .control-section select option:checked {
    background: var(--primary);
    color: #fff;
  }
}

/* ===== 通栏顶部导航 ===== */
.site-header {
  width: 100%;
  background: var(--chrome);
  color: #fff;
  flex-shrink: 0;
  box-sizing: border-box;
  height: var(--chrome-top);
  padding-top: env(safe-area-inset-top, 0px);
  overflow: hidden;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: #fff;
  text-decoration: none;
}

.brand-link:hover {
  color: #fff;
  text-decoration: none;
}

.logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.logo img {
  display: block;
}

.site-name {
  font-size: 17px;
  font-weight: bold;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-right a {
  color: #f8d568;
  font-size: 13px;
  padding: 4px 10px;
  border: 1px solid rgba(248,213,104,0.7);
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.2s;
}
.header-right a:hover {
  background: rgba(248,213,104,0.2);
  text-decoration: none;
}

.header-install {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  flex-shrink: 0;
  border: 1px solid rgba(248, 213, 104, 0.7);
  border-radius: 4px;
  background: transparent;
  color: #f8d568;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.header-install:hover {
  background: rgba(248, 213, 104, 0.2);
}
.header-install:active {
  transform: translateY(1px);
}
.header-install svg {
  width: 16px;
  height: 16px;
}
.header-install[hidden] {
  display: none;
}

#soundBtn[aria-pressed="false"] .sound-icon--on,
#soundBtn[aria-pressed="true"] .sound-icon--off {
  display: none;
}

#soundBtn[aria-pressed="true"] {
  background: rgba(248, 213, 104, 0.2);
}

#nightBtn[aria-pressed="false"] .night-icon--sun,
#nightBtn[aria-pressed="true"] .night-icon--moon {
  display: none;
}

#nightBtn[aria-pressed="true"] {
  background: rgba(248, 213, 104, 0.2);
}

/* ===== 整体容器 ===== */
.app-container {
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 8px;
  background: var(--bg);
}

/* ===== 首屏区（棋盘+广告，撑满视口高度） ===== */
.game-screen {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--chrome-top));
  flex-shrink: 0;
}

/* ===== 第二屏区（信息面板+页脚，撑满视口高度） ===== */
.second-screen {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(139, 69, 19, 0.10);
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 6px 0 8px;
}

/* ===== 主内容区 ===== */
.main-content {
  display: flex;
  flex-direction: row;
  gap: 50px;
  padding: 10px 0 0;
  flex: 1 1 auto;
  min-height: 0;
  align-items: stretch;
}

/* ===== 棋盘区 ===== */
.board-section {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 0;
}

.board-section h1 {
  font-size: 18px;
  color: var(--primary);
  text-align: center;
  font-weight: bold;
  flex-shrink: 0;
}

.board-subtitle {
  font-size: 14px;
  color: var(--text-light);
  text-align: center;
  font-weight: normal;
  margin-top: -2px;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-stage {
  position: relative;
  width: max-content;
  height: max-content;
  flex: 0 0 auto;
}

#chessCanvas {
  position: relative;
  z-index: 0;
  width: auto;
  height: auto;
  display: block;
  border-radius: 6px;
  box-shadow: 0 4px 16px var(--shadow);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.piece-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
  border-radius: 6px;
}

.piece-layer img {
  position: absolute;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.capture-flash {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  display: none;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.06em 0 0;
  border-radius: 50%;
  border: 2px solid #f4d7b4;
  background: radial-gradient(circle at 34% 30%, #ff6a4a 0%, #c41e1a 72%, #8e1210 100%);
  box-shadow: 0 3px 10px rgba(40, 8, 4, 0.45);
  font-family: "STKaiti", "Kaiti SC", "KaiTi", "SimSun", serif;
  font-weight: 700;
  line-height: 1;
  color: #fff8e8;
  text-shadow: 0 1px 0 rgba(80, 10, 8, 0.45);
  transform-origin: center center;
}
.capture-flash.is-on {
  display: flex;
  animation: capture-flash-pop 0.8s ease-out forwards;
}
@keyframes capture-flash-pop {
  0% { opacity: 0; transform: scale(0.42); }
  14% { opacity: 1; transform: scale(1); }
  62% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

html[data-night] .capture-flash {
  border-color: #f0c9a0;
  color: #fff8e8;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}

.board-info {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 6px 10px;
  width: 100%;
  height: 18px;
  min-height: 18px;
  padding: 0 8px;
  flex-shrink: 0;
  overflow: hidden;
  line-height: 18px;
}

.turn-indicator,
.game-status {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text-light);
  padding: 0;
  background: none;
  border: none;
  line-height: 18px;
  white-space: nowrap;
}

.board-info:has(.game-status:not(:empty)) .turn-indicator {
  display: none;
}

.game-status.check {
  color: var(--text-light);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.12em;
  padding: 0;
  border-radius: 0;
  animation: none;
}

.canvas-wrapper.in-check #chessCanvas {
  animation: checkBorder 0.55s ease-in-out infinite alternate;
}

@keyframes checkBorder {
  from { box-shadow: 0 4px 16px var(--shadow); }
  to   { box-shadow: 0 0 0 4px #e74c3c, 0 4px 20px rgba(231,76,60,0.45); }
}

/* ===== 控制区 ===== */
.control-section {
  flex: 0 0 380px;
  width: 380px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 380px;
  min-height: 0;
  overflow: hidden;
}

/* 玩家信息 */
.player-info {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s, box-shadow 0.2s;
}

.player-row.active {
  background: #fff7e6;
  box-shadow: inset 2.5px 0 0 var(--primary);
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.red-dot { background: var(--red-piece); }
.black-dot { background: var(--black-piece); }

.player-label {
  flex: 1;
  font-size: 14px;
}

.player-timer {
  font-size: 14px;
  font-family: monospace;
  color: var(--text-light);
}

/* 控制组 */
.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.control-group:not(.btn-group) select {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
}

.control-group label {
  font-size: 14px;
  color: var(--text-light);
  white-space: nowrap;
}

.btn-group {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  align-items: stretch;
}
.btn-group .btn {
  width: 100%;
  min-width: 0;
  padding: 7px 4px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  white-space: nowrap;
}
.btn-group .btn[hidden] {
  display: none;
}
.btn-group .btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  opacity: 0.85;
}
.btn-group .btn-primary svg {
  opacity: 1;
}

.btn {
  padding: 7px 14px;
  font-size: 14px;
  border-radius: var(--radius);
  font-weight: 500;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #f0e8d8;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: #e8d8c0;
}

.btn-danger {
  background: #fdecea;
  color: #c0392b;
  border: 1px solid #e6b0aa;
}
.btn-danger:hover {
  background: #f8d7d3;
}
.btn-danger:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.play-side {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px 10px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.play-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0 0 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.play-tabs__btn {
  min-height: 30px;
  padding: 4px 2px 8px;
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  color: var(--text-light);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
}

.play-tabs__btn:hover {
  color: var(--primary);
}

.play-tabs__btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.play-stack {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.play-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}

.play-pane[data-play-pane="info"] {
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.play-pane[hidden] {
  display: none;
}

.play-pane.is-off {
  visibility: hidden;
  pointer-events: none;
}

.play-pane[data-play-pane="history"]:not([hidden]) {
  position: absolute;
  inset: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.captured-tray {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
  min-height: 0;
}

.captured-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.captured-row__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
}

.captured-row__pieces {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 34px;
}

.captured-stack {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.captured-empty {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-light);
  opacity: 0.55;
}

.captured-piece {
  width: 35px;
  height: 35px;
  flex: 0 0 auto;
  display: block;
}

.captured-count {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  box-shadow: 0 0 0 1.5px #fff;
  pointer-events: none;
}

/* 引擎实时分析卡片 */
.engine-card {
  flex: 0 0 auto;
  margin-top: 16px;
  padding: 12px 14px;
  background: #f7f3ea;
  border: 1px solid #dfcfba;
  border-radius: 10px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(139, 69, 19, 0.05);
}

.engine-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 26px;
}

.engine-card__title-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.engine-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #27ae60;
  box-shadow: 0 0 5px rgba(39, 174, 96, 0.6);
  animation: pulse-live 2s infinite ease-in-out;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.85); }
}

.engine-card__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.3px;
}

.engine-card__note {
  margin: 0;
  font-size: 11px;
  color: var(--text-light);
  margin-left: 2px;
}

.engine-card__note:empty {
  display: none;
}

.engine-card__score {
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 2.5px 12px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  line-height: 1.35;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: all 0.15s ease;
}

.engine-card__score.score-black {
  background: #3c2f24;
  color: #fdfaf5;
  border: 1px solid #544333;
}

.engine-card__score.score-red {
  background: #c0392b;
  color: #ffffff;
  border: 1px solid #a32e22;
}

.engine-card__score.score-even {
  background: #e6d6c2;
  color: #61462d;
  border: 1px solid #ceb89f;
}

.engine-card__pv-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.engine-card__pv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.engine-card__sublabel {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  letter-spacing: 0.3px;
}

.engine-card__pv {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
  padding: 0;
  background: transparent;
  border: none;
  min-height: 28px;
}

.engine-card__empty {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 13px;
  color: var(--text-light);
  opacity: 0.6;
  line-height: 26px;
}

.engine-card__ply {
  width: 100%;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px 0;
  border-radius: 6px;
  background: #ffffff;
  color: #3c2f24;
  border: 1px solid rgba(198, 166, 122, 0.45);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  letter-spacing: 0.25px;
  box-shadow: 0 1px 2px rgba(139, 69, 19, 0.04);
  transition: all 0.15s ease;
}

.engine-card__ply--first {
  background: #fdf8f0;
  border-color: rgba(139, 69, 19, 0.55);
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(139, 69, 19, 0.08);
}

.engine-card__stats {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  background: rgba(139, 69, 19, 0.04);
  border: 1px solid rgba(198, 166, 122, 0.22);
  border-radius: 7px;
  padding: 6px 2px;
}

.engine-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.engine-stat:not(:last-child)::after {
  display: none !important;
}

.engine-stat dt {
  color: var(--text-light);
  font-size: 10.5px;
  line-height: 1.1;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0.85;
}

.engine-stat dd {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.move-history-scroll {
  flex: 0 0 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 8px 0 0;
  scroll-snap-type: y mandatory;
  scrollbar-gutter: stable;
}

.move-list {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 6px;
  list-style: none;
}

.move-list > li {
  width: 100%;
  height: 56px;
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.move-row {
  width: 100%;
  height: 56px;
  min-height: 56px;
  box-sizing: border-box;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  font-variant-numeric: tabular-nums;
}

.move-row__play {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
}

.move-row__num {
  font-size: 12px;
  color: var(--text-light);
  min-width: 16px;
}

.move-row__san {
  font-weight: 600;
  min-width: 0;
  font-size: 13.5px;
}

.move-row__san.move-red {
  color: #c0392b;
}

.move-row__san.move-black {
  color: #1a1a1a;
}

.move-row__cap {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-radius: 6px;
  background: rgba(192, 57, 43, 0.08);
  border: 1px dashed rgba(192, 57, 43, 0.28);
  height: 44px;
  min-height: 44px;
  box-sizing: border-box;
}

.move-row__cap-label {
  font-size: 12px;
  letter-spacing: 0.03em;
  opacity: 0.8;
  line-height: 1;
  color: var(--text);
}

.move-row__cap-piece {
  width: 40px;
  height: 40px;
  display: block;
}

.move-list > li.active .move-row {
  background: var(--primary);
  border-color: var(--primary);
}

.move-list > li.active .move-row__num,
.move-list > li.active .move-row__san,
.move-list > li.active .move-row__cap-label {
  color: #fff;
  opacity: 1;
}

.move-list > li.active .move-row__cap {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.38);
}

.empty-hint {
  font-size: 13px;
  color: #aaa;
  text-align: center;
  padding: 10px 0 2px;
}

@media (min-width: 768px) {
  .app-container {
    width: max-content;
    max-width: min(1100px, 100%);
  }

  .game-screen,
  .main-content {
    width: max-content;
    max-width: 100%;
  }

  .board-section {
    flex: 0 0 auto;
  }

  .game-screen {
    height: calc(100dvh - var(--chrome-top));
  }

  /* 第二屏撑满视口 */
  .second-screen {
    width: 0;
    min-width: 100%;
    height: calc(100dvh - var(--chrome-top));
  }

  .second-screen .content-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
    overflow: hidden;
  }

  .second-screen .hero-cont {
    flex-shrink: 0;
  }

  .second-screen .info-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .second-screen .info-panel .bottom-tabs {
    flex-shrink: 0;
  }

  .second-screen .info-panel .tab-content.active {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  .second-screen .site-footer {
    flex-shrink: 0;
    margin-top: 0;
  }

  body.focus-mode {
    overflow: hidden;
    background: var(--bg);
  }

  body.focus-mode .second-screen,
  body.focus-mode .ad-placeholder,
  body.focus-mode .hero-cont,
  body.focus-mode .info-panel,
  body.focus-mode .site-footer,
  body.focus-mode .board-section h1,
  body.focus-mode .board-subtitle {
    display: none;
  }

  body.focus-mode .site-header {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 10px);
    right: 8px;
    width: auto;
    height: auto;
    background: transparent;
    padding: 0;
    overflow: visible;
    z-index: 40;
  }

  body.focus-mode .header-inner {
    max-width: none;
    padding: 0;
    height: auto;
  }

  body.focus-mode .header-left,
  body.focus-mode .header-right a,
  body.focus-mode #xq-install {
    display: none;
  }

  body.focus-mode #soundBtn,
  body.focus-mode #nightBtn {
    background: rgba(255, 250, 238, 0.94);
    color: var(--primary);
    border-color: rgba(139, 69, 19, 0.28);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  }

  body.focus-mode .app-container {
    width: 100%;
    max-width: none;
    align-self: stretch;
    height: 100dvh;
    padding: 0;
  }

  body.focus-mode .game-screen {
    width: 100%;
    max-width: none;
    height: 100dvh;
    min-height: 100dvh;
    justify-content: stretch;
  }

  body.focus-mode .main-content {
    position: relative;
    display: block;
    width: 100%;
    max-width: none;
    height: 100dvh;
    margin: 0;
    padding: 0;
  }

  body.focus-mode .board-section {
    position: absolute;
    inset: 12px calc(8px + 380px) 12px 0;
    width: auto;
    flex: none;
    min-width: 0;
    min-height: 0;
    justify-content: center;
    align-items: center;
  }

  body.focus-mode .canvas-wrapper {
    max-width: none;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
  }

  body.focus-mode .control-section {
    position: absolute;
    top: 12px;
    right: 8px;
    bottom: 12px;
    flex: none;
    width: 380px;
    min-width: 380px;
    height: auto;
    max-height: none;
    z-index: 2;
    padding: 14px;
    border: 1px solid rgba(139,69,19,0.22);
    border-radius: 14px;
    background: rgba(255,250,238,0.94);
    box-shadow: 0 12px 36px rgba(0,0,0,0.16);
  }

  body.focus-mode .engine-card__pv {
    max-height: none;
    overflow: visible;
  }

  body.focus-mode .play-pane[data-play-pane="info"] {
    overflow: hidden;
  }

  body.focus-mode .btn-group .btn {
    width: 100%;
  }

  body.focus-mode #focusModeBtn {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
  }

  body.focus-mode .play-side {
    flex: 1 1 auto;
    min-height: 120px;
    max-height: none;
  }

  body.focus-mode .move-history-scroll {
    min-height: 0;
  }
}

.ad-placeholder {
  position: relative;
  height: 90px;
  border: 1px solid #ebd4af;
  background: linear-gradient(135deg, #fffbf2 0%, #fef5de 100%);
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  border-radius: var(--radius);
  margin: 8px 0 0;
  padding: 0;
  flex-shrink: 0;
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(139, 69, 19, 0.08);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.ad-placeholder:hover {
  border-color: #dfba7c;
  box-shadow: 0 4px 14px rgba(139, 69, 19, 0.14);
}

.xq-ad {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  height: 100%;
  padding: 0 16px 0 10px;
  color: var(--text);
  text-decoration: none;
  box-sizing: border-box;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.xq-ad:hover,
.xq-ad:focus-visible {
  text-decoration: none;
}

.xq-ad__media {
  position: relative;
  flex: 0 0 68px;
  width: 68px;
  height: 68px;
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid rgba(139, 69, 19, 0.15);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
}
.xq-ad__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}
.xq-ad:hover .xq-ad__img {
  transform: scale(1.05);
}
.xq-ad__media-tag {
  position: absolute;
  top: 0;
  left: 0;
  background: linear-gradient(135deg, #e4393c 0%, #d81e06 100%);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 5px;
  border-bottom-right-radius: 5px;
  letter-spacing: 0.02em;
}

.xq-ad__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  text-align: left;
}
.xq-ad__row-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  line-height: 1.25;
}
.xq-ad__jd-tag {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  background: #e4393c;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 3px;
  line-height: 1.2;
  letter-spacing: 0.02em;
}
.xq-ad__title {
  font-family: "STKaiti", "Kaiti SC", "KaiTi", serif;
  font-size: 16px;
  font-weight: 700;
  color: #3b1d0a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
}
.xq-ad__pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  background: rgba(184, 115, 51, 0.12);
  color: #8f4b14;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  line-height: 1.2;
}
.xq-ad__badge {
  flex-shrink: 0;
  display: inline-block;
  padding: 0 4px;
  border: 1px solid #d4b483;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.2;
  color: #a88755;
  letter-spacing: 0.04em;
}

.xq-ad__row-bottom {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}
.xq-ad__price-group {
  flex-shrink: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.xq-ad__price-label {
  font-size: 11px;
  font-weight: 600;
  color: #e4393c;
  margin-right: 1px;
}
.xq-ad__price-sym {
  font-size: 13px;
  font-weight: 700;
  color: #e4393c;
}
.xq-ad__price-val {
  font-size: 20px;
  font-weight: 800;
  color: #e4393c;
  line-height: 1;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -0.02em;
}
.xq-ad__desc {
  font-size: 12.5px;
  color: #6b4d2e;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xq-ad__action {
  flex: 0 0 auto;
}
.xq-ad__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 38px;
  padding: 0 16px;
  border-radius: 19px;
  background: linear-gradient(135deg, #e4393c 0%, #c91523 100%);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 3px 8px rgba(228, 57, 60, 0.3);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
.xq-ad:hover .xq-ad__cta,
.xq-ad:focus-visible .xq-ad__cta {
  background: linear-gradient(135deg, #f04447 0%, #db1a28 100%);
  box-shadow: 0 5px 12px rgba(228, 57, 60, 0.42);
  transform: translateY(-1px);
}
.xq-ad:active .xq-ad__cta {
  transform: translateY(0) scale(0.98);
}
.xq-ad__cta-arr {
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
  transition: transform 0.16s ease;
}
.xq-ad:hover .xq-ad__cta-arr {
  transform: translateX(2px);
}

/* 统一卡片容器：将 hero-cont 与 info-panel 融为一体 */
.content-card {
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  margin: 0;
}

.hero-cont {
  background: linear-gradient(135deg, #fffaf0 0%, #f6e1b8 100%);
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
}

.hero-cont h2 {
  font-size: 17px;
  color: var(--primary);
  margin-bottom: 8px;
}

.hero-cont p {
  font-size: 14px;
  line-height: 1.85;
  color: var(--text);
}

/* ===== 面包屑导航 ===== */
.breadcrumb {
  padding: 8px 4px 2px;
  font-size: 13px;
  color: var(--text-light);
  flex-shrink: 0;
}

.breadcrumb a {
  color: var(--primary);
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb-sep {
  margin: 0 6px;
  color: #bbb;
}

.breadcrumb-current {
  color: var(--text);
}

/* ===== 信息面板 ===== */
.info-panel {
  background: #fff;
  flex-shrink: 0;
}

/* Bottom Tabs */
.bottom-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  background: var(--tab-bg);
  overflow-x: auto;
  scrollbar-width: none;
}

.bottom-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  flex: 1 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 6px;
  font-size: 14px;
  text-decoration: none;
  background: transparent;
  color: var(--text-light);
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.tab-btn:hover {
  background: rgba(139,69,19,0.08);
  color: var(--primary);
  text-decoration: none;
}

.tab-btn.active {
  color: var(--tab-active);
  font-weight: bold;
  border-bottom-color: var(--tab-active);
  background: #fff;
}

/* Tab 内容 */
.tab-content {
  display: none;
  padding: 18px 20px;
}

.tab-content.active {
  display: block;
}

/* 内容块 */
.content-block {
  margin-bottom: 20px;
}

.content-block:last-child {
  margin-bottom: 0;
}

.content-block p {
  font-size: 14px;
  line-height: 1.85;
  margin-bottom: 10px;
  color: var(--text);
}

.content-block p:last-child {
  margin-bottom: 0;
}

/* 文本列表 */
.text-list {
  padding-left: 18px;
  line-height: 1.85;
  font-size: 14px;
  color: var(--text);
}

.text-list li {
  margin-bottom: 6px;
}

.text-list li:last-child {
  margin-bottom: 0;
}

/* 示例步骤 */
.example-steps {
  padding-left: 22px;
  line-height: 2;
  font-size: 14px;
  color: var(--text);
  background: #fdf9f0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 18px 12px 36px;
  margin: 8px 0;
}

.example-steps li {
  margin-bottom: 3px;
}

/* 棋子卡片网格 */
.piece-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.piece-card {
  background: #fdf9f0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.piece-card h4 {
  font-size: 14px;
  color: var(--primary);
  margin-bottom: 6px;
  font-weight: bold;
}

.piece-card p {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  margin: 0;
}

/* 信息面板标题 */
.info-panel h2 {
  font-size: 18px;
  color: var(--primary);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.info-panel h3 {
  font-size: 15px;
  color: var(--primary);
  margin-bottom: 8px;
}

/* FAQ */
.faq-list {
  font-size: 14px;
  line-height: 1.8;
}

.faq-list dt {
  font-weight: bold;
  color: var(--primary);
  margin-top: 14px;
  margin-bottom: 4px;
}

.faq-list dt:first-child {
  margin-top: 0;
}

.faq-list dd {
  margin-left: 0;
  color: var(--text);
  margin-bottom: 6px;
}

/* 保留旧的规则列表兼容 */
.rule-list {
  padding-left: 16px;
  line-height: 2;
  font-size: 14px;
}

.rule-list li {
  margin-bottom: 4px;
}

.tab-content p {
  font-size: 14px;
  line-height: 1.8;
  margin-bottom: 8px;
  color: var(--text);
}

/* ===== 页脚 ===== */
.site-footer {
  background: var(--chrome);
  color: rgba(255,255,255,0.85);
  text-align: center;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  font-size: 13px;
  border-radius: 0;
  line-height: 2;
  flex-shrink: 0;
  margin-top: auto;
}

.footer-main {
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  margin-bottom: 2px;
}

.footer-links a {
  color: inherit;
  margin: 0 8px;
  font-size: 13px;
}

.footer-links a:hover {
  color: inherit;
}

.footer-copy {
  font-size: 12px;
  color: rgba(255,255,255,0.55);
}

/* ===== 弹窗 ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.visible {
  display: flex;
}

.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  animation: popIn 0.2s ease;
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-title {
  font-size: 20px;
  color: var(--primary);
  margin-bottom: 10px;
}

.modal-result {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 8px;
}

.modal-comment {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 18px;
  line-height: 1.6;
}

.modal-box .btn {
  margin: 4px 6px;
}
/* ===== AI 思考指示 ===== */
.thinking-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-light);
  justify-content: center;
  padding: 4px 0;
}

.thinking-indicator.visible {
  display: flex;
}

.dot-anim span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  margin: 0 2px;
  animation: bounce 1.2s infinite;
}
.dot-anim span:nth-child(2) { animation-delay: 0.2s; }
.dot-anim span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ===== 滚动条美化 ===== */
.move-history-scroll::-webkit-scrollbar,
.play-pane[data-play-pane="info"]::-webkit-scrollbar,
.second-screen .tab-content::-webkit-scrollbar {
  width: 4px;
}
.move-history-scroll::-webkit-scrollbar-thumb,
.play-pane[data-play-pane="info"]::-webkit-scrollbar-thumb,
.second-screen .tab-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ===== 响应式 移动端 ===== */
@media (max-width: 767px) {
  html,
  body {
    background-color: var(--chrome);
  }

  .app-container {
    padding: 0 12px;
  }

  .game-screen {
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 6px 0 0;
  }

  .main-content {
    display: contents;
  }

  .board-section {
    order: 1;
    width: 100%;
    flex: 0 0 auto;
  }

  .board-section h1 {
    font-size: 16px;
  }

  .board-subtitle {
    font-size: 13px;
  }

  /* 单DOM控制区：移动端紧凑两行布局 */
  .control-section {
    order: 3;
    display: flex;
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    overflow: visible;
    padding: 0;
  }

  .control-section .player-info {
    display: none;
  }

  .control-section .play-side {
    flex: 1 1 100%;
    width: 100%;
    min-height: 0;
    max-height: none;
  }

  .control-section .play-pane[data-play-pane="info"] {
    gap: 10px;
  }

  .control-section .play-stack {
    min-height: calc(5 * 56px + 4 * 6px + 36px);
  }

  .control-section .captured-tray {
    flex: 0 0 auto;
  }

  .control-section .captured-row {
    gap: 4px;
  }

  .control-section .captured-row__label {
    font-size: 12px;
  }

  .control-section .captured-row__pieces {
    gap: 3px 4px;
    min-height: 34px;
  }

  .control-section .captured-piece {
    width: 34px;
    height: 34px;
  }

  .control-section .captured-count {
    top: -1px;
    right: -1px;
    min-width: 15px;
    height: 15px;
    font-size: 10px;
    line-height: 15px;
    box-shadow: 0 0 0 1.5px #fff;
  }

  .control-section .engine-card {
    margin-top: 14px;
    padding: 10px;
    gap: 8px;
  }

  .control-section .engine-card__pv {
    max-height: 72px;
  }

  /* 难度 / 执子 各占半行，标签与下拉框保持在同一列内 */
  .control-section .control-group:not(.btn-group) {
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .control-section .control-group:not(.btn-group) label {
    line-height: 1.3;
  }

  .control-section .control-group:not(.btn-group) select {
    width: 100%;
    min-width: 0;
    height: 34px;
    max-height: 34px;
    overflow: hidden;
    white-space: nowrap;
    appearance: auto;
  }
  .control-section .control-group:not(.btn-group) select::picker(select) {
    appearance: auto;
  }

  /* 专注模式按钮在移动端隐藏 */
  #focusModeBtn {
    display: none;
  }

  .control-section .btn-group {
    width: 100%;
    flex-shrink: 0;
    gap: 3px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-section .btn-group > .btn {
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 3px !important;
    font-size: 11.5px !important;
    line-height: 1 !important;
    gap: 2px !important;
    border-radius: 7px;
  }

  .control-section .btn-group > .btn svg {
    width: 13px !important;
    height: 13px !important;
  }

  .control-section .btn {
    font-weight: 600;
  }

  .canvas-wrapper {
    flex: 0 0 auto;
    width: 100%;
    min-height: 0;
    max-width: 100%;
    overflow: visible;
  }

  .ad-placeholder {
    order: 2;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .xq-ad {
    gap: 8px;
    padding: 0 8px 0 6px;
  }
  .xq-ad__media {
    flex-basis: 58px;
    width: 58px;
    height: 58px;
  }
  .xq-ad__title {
    font-size: 13.5px;
  }
  .xq-ad__pill--extra {
    display: none;
  }
  .xq-ad__desc {
    font-size: 11px;
  }
  .xq-ad__price-val {
    font-size: 17px;
  }
  .xq-ad__cta {
    height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }

  .content-card {
    margin: 0;
  }

  .hero-cont {
    padding: 12px 14px;
  }

  .hero-cont h2 {
    font-size: 15px;
  }

  .hero-cont p {
    font-size: 13px;
    line-height: 1.75;
  }

  .header-inner {
    padding: 0 10px;
  }

  .site-name {
    font-size: 15px;
  }

  .site-name-rest {
    display: none;
  }

  .header-right {
    gap: 4px;
    flex-shrink: 0;
  }

  .header-right a {
    font-size: 12px;
    padding: 3px 7px;
    flex-shrink: 0;
  }

  .header-right a:first-child {
    display: none;
  }

  .header-install {
    width: 28px;
    height: 28px;
  }

  .tab-btn {
    font-size: 12px;
    padding: 9px 3px;
    white-space: nowrap;
  }

  .tab-content {
    padding: 14px 12px;
  }

  .board-info {
    gap: 6px;
    padding: 0 6px;
    height: 18px;
    min-height: 18px;
  }

  .modal-box {
    padding: 20px 18px;
  }

  .modal-title {
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  .xq-ad__pill {
    display: none;
  }
}

/* ===== 极小屏适配 ===== */
@media (max-width: 380px) {
  .site-name {
    font-size: 14px;
  }

  .header-right a:nth-child(2) {
    display: none;
  }

  .tab-btn {
    font-size: 11px;
    padding: 8px 2px;
  }

  .xq-ad__desc {
    display: none;
  }
  .xq-ad__media {
    flex-basis: 50px;
    width: 50px;
    height: 50px;
  }
  .xq-ad__cta {
    padding: 0 7px;
  }
  .xq-ad__cta-arr {
    display: none;
  }
}

html[data-night] select,
html[data-night] .player-info,
html[data-night] .play-side,
html[data-night] .modal-box,
html[data-night] .info-panel,
html[data-night] .tab-btn.active,
html[data-night] .xq-pwa-guide__card,
html[data-night] .xq-pwa-guide__icon,
html[data-night] .xq-pwa-guide__ghost {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
}

@supports (appearance: base-select) {
  html[data-night] .control-section select::picker(select) {
    background: var(--panel);
    color: var(--text);
    border-color: var(--border);
  }
}

html[data-night] .control-section select option:hover,
html[data-night] .control-section select option:focus,
html[data-night] .btn-secondary,
html[data-night] .example-steps,
html[data-night] .piece-card {
  background: #302a24;
  color: var(--text);
  border-color: var(--border);
}

html[data-night] .btn-secondary:hover {
  background: #3b332b;
  border-color: #5c4f42;
  color: #fff;
}

html[data-night] .player-row.active {
  background: #2e2822;
  box-shadow: inset 2.5px 0 0 var(--primary);
}

html[data-night] .red-dot {
  box-shadow: 0 0 6px rgba(255, 120, 101, 0.4);
}

/* 棋谱记录夜间专属质感与清晰对比 */
html[data-night] .move-row {
  background: #27221d;
  border-color: #3e352b;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}

html[data-night] .move-row:hover {
  background: #2f2923;
  border-color: #4f4336;
}

html[data-night] .move-row__num {
  color: #c8baa8;
  font-weight: 500;
}

html[data-night] .move-row__san {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

html[data-night] .move-row__san.move-red {
  color: #ff7b72;
}

html[data-night] .move-row__san.move-black {
  color: #f5f5f7;
}

html[data-night] .red-dot {
  background: #ff5442;
  box-shadow: 0 0 6px rgba(255, 84, 66, 0.45);
}

html[data-night] .black-dot {
  background: #0c0a08;
  box-shadow: none;
  border: 1.5px solid #c4b49c;
}

html[data-night] .move-row__cap {
  background: rgba(255, 84, 66, 0.12);
  border: 1px dashed rgba(255, 84, 66, 0.38);
}

html[data-night] .move-row__cap-label {
  color: #ff9688;
}

html[data-night] .move-list > li.active .move-row,
html[data-night] .move-list > li.replay-current .move-row {
  background: linear-gradient(135deg, #c47633, #9e5b22);
  border-color: #d88942;
  box-shadow: 0 2px 8px rgba(184, 110, 46, 0.35);
}

html[data-night] .move-list > li.active .move-row__num,
html[data-night] .move-list > li.active .move-row__san,
html[data-night] .move-list > li.active .move-row__cap-label,
html[data-night] .move-list > li.replay-current .move-row__num,
html[data-night] .move-list > li.replay-current .move-row__san,
html[data-night] .move-list > li.replay-current .move-row__cap-label {
  color: #ffffff;
}

html[data-night] .btn-icon {
  background: #27221d;
  border: 1px solid #4a4035;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

html[data-night] .btn-icon:hover {
  background: #332c25;
  border-color: var(--primary);
  color: #ffffff;
}

html[data-night] .empty-hint {
  color: var(--text-light);
}

html[data-night] .move-history-scroll,
html[data-night] .engine-card__pv {
  scrollbar-color: #4a4035 transparent;
}

/* 顶栏暗夜优雅琥珀金 */
html[data-night] .header-right a,
html[data-night] .header-install {
  color: #d49a55;
  border-color: rgba(212, 154, 85, 0.4);
}

html[data-night] .header-right a:hover,
html[data-night] .header-install:hover {
  background: rgba(212, 154, 85, 0.16);
  border-color: rgba(212, 154, 85, 0.7);
  color: #f5cf9c;
}

/* 引擎面板细节 */
html[data-night] .engine-card {
  background: #1e1915;
  border-color: #3d3328;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

html[data-night] .engine-card__score.score-black {
  background: rgba(245, 238, 226, 0.14);
  color: #f7f2ea;
  border-color: rgba(245, 238, 226, 0.3);
  box-shadow: 0 0 6px rgba(240, 233, 220, 0.08);
}

html[data-night] .engine-card__score.score-red {
  background: rgba(255, 84, 66, 0.18);
  color: #ff7b72;
  border-color: rgba(255, 84, 66, 0.4);
  box-shadow: 0 0 6px rgba(255, 84, 66, 0.15);
}

html[data-night] .engine-card__score.score-even {
  background: rgba(212, 154, 85, 0.16);
  color: #f5cf9c;
  border-color: rgba(212, 154, 85, 0.35);
}

html[data-night] .engine-card__ply {
  background: #251f19;
  color: #eee7dc;
  border-color: #3f3428;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

html[data-night] .engine-card__ply--first {
  background: #33281e;
  border-color: rgba(212, 154, 85, 0.55);
  color: #f5cf9c;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

html[data-night] .engine-card__stats {
  background: #1c1713;
  border-color: #332a21;
}

html[data-night] .engine-stat {
  background: transparent;
  border: none;
  box-shadow: none;
}

html[data-night] .engine-stat dt {
  color: var(--text-light);
}

html[data-night] .engine-stat dd {
  color: #f5f5f7;
}

html[data-night] .captured-count {
  box-shadow: 0 0 0 2px var(--panel);
}

html[data-night] .ad-placeholder {
  background: linear-gradient(135deg, #261f18 0%, #1e1711 100%);
  border-color: #4a3826;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
html[data-night] .ad-placeholder:hover {
  border-color: #6a4f35;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}
html[data-night] .xq-ad__media {
  background: #1a130c;
  border-color: #4a3826;
}
html[data-night] .xq-ad__title {
  color: #f5e4cf;
}
html[data-night] .xq-ad__pill {
  background: rgba(212, 154, 85, 0.15);
  color: #dfaa68;
}
html[data-night] .xq-ad__badge {
  border-color: #5c4731;
  color: #9d8365;
}
html[data-night] .xq-ad__desc {
  color: #b59b80;
}
html[data-night] .xq-ad__price-label,
html[data-night] .xq-ad__price-sym,
html[data-night] .xq-ad__price-val {
  color: #ff5252;
}
html[data-night] .xq-ad__cta {
  background: linear-gradient(135deg, #e4393c 0%, #b81421 100%);
  color: #ffffff;
  box-shadow: 0 3px 8px rgba(228, 57, 60, 0.4);
}
html[data-night] .hero-cont,
html[data-night] .xq-pwa-guide__head {
  background: linear-gradient(135deg, #28231e 0%, #1c1916 100%);
}

html[data-night] .replay-bar {
  background: #24201c;
  border-color: var(--border);
}

html[data-night] .replay-btn,
html[data-night] .replay-btn:hover {
  background: #302a24;
  border-color: var(--border);
  color: var(--text);
}

html[data-night] .replay-progress,
html[data-night] .replay-speed {
  color: var(--text-light);
}

@media (min-width: 768px) {
  html[data-night] body.focus-mode #soundBtn,
  html[data-night] body.focus-mode #nightBtn,
  html[data-night] body.focus-mode .control-section {
    background: rgba(36, 32, 28, 0.96);
    color: var(--text);
    border-color: var(--border);
  }
}

/* ===== 打印 ===== */
@media print {
  .site-header, .control-section, .ad-placeholder,
  .bottom-tabs, .mobile-controls, .site-footer {
    display: none !important;
  }
}

.move-history-header {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 8px;
}

.move-history-header:has(#copyNotationBtn[hidden]) {
  display: none;
}

.btn-icon {
  background: none;
  border: 1px solid #c8a06e;
  border-radius: 6px;
  color: #8b4513;
  font-size: 12px;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: #f4dea8;
  color: #5a2d0c;
}

.replay-bar {
  background: #fdf6e3;
  border: 1px solid #e0c080;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.replay-bar[hidden] {
  display: none;
}

.replay-seek {
  display: flex;
  align-items: center;
}

.replay-seek input[type="range"] {
  flex: 1;
  width: 100%;
  accent-color: #8b4513;
  height: 4px;
  cursor: pointer;
}

.replay-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.replay-btn {
  background: #fff8ee;
  border: 1px solid #c8a06e;
  border-radius: 6px;
  color: #8b4513;
  font-size: 18px;
  line-height: 1;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.replay-btn:hover {
  background: #f4dea8;
}

.replay-btn.replay-play {
  font-size: 14px;
  width: 38px;
}

.replay-progress {
  font-size: 13px;
  color: #8b4513;
  margin-left: 4px;
  white-space: nowrap;
}

.replay-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #8b6030;
}

.replay-speed input[type="range"] {
  flex: 1;
  accent-color: #8b4513;
  height: 4px;
  cursor: pointer;
}

.replay-exit {
  font-size: 12px;
  padding: 5px 10px;
  align-self: flex-start;
}

.move-list > li.replay-current .move-row {
  background: var(--primary);
  border-color: var(--primary);
}

.move-list > li.replay-current .move-row__num,
.move-list > li.replay-current .move-row__san,
.move-list > li.replay-current .move-row__cap-label {
  color: #fff;
  opacity: 1;
}

.move-list > li.replay-current .move-row__cap {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.38);
}

.canvas-wrapper.board-replaying::after {
  content: '复盘中';
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(139, 69, 19, 0.82);
  color: #fff;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 5;
}

.xq-pwa-guide {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.xq-pwa-guide[hidden] { display: none !important; }
.xq-pwa-guide__backdrop {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: rgba(20, 10, 4, 0.5);
  cursor: pointer;
}
.xq-pwa-guide__card {
  position: relative;
  z-index: 1;
  width: min(20.5rem, calc(100vw - 1.5rem));
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 18px 48px rgba(50, 25, 8, 0.28);
}
.xq-pwa-guide__head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px 16px 12px;
  background: linear-gradient(165deg, #faecd4 0%, #fff 60%);
  border-bottom: 1px solid rgba(212, 180, 131, 0.55);
}
.xq-pwa-guide__icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
  background: #fff;
  box-shadow: 0 2px 8px rgba(60, 30, 10, 0.14);
}
.xq-pwa-guide__name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}
.xq-pwa-guide__host {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-light);
  line-height: 1.3;
}
.xq-pwa-guide__kicker {
  margin: 12px 16px 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--primary);
}
.xq-pwa-guide__kicker[hidden],
.xq-pwa-guide__steps[hidden] { display: none !important; }
.xq-pwa-guide__steps {
  list-style: none;
  margin: 10px 16px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.xq-pwa-guide__steps li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text);
}
.xq-pwa-guide__n {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  margin-top: 1px;
}
.xq-pwa-guide__share {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin: 0 2px;
  vertical-align: -2px;
  color: var(--primary);
}
.xq-pwa-guide__actions {
  display: flex;
  gap: 8px;
  padding: 14px 16px 16px;
}
.xq-pwa-guide__primary,
.xq-pwa-guide__ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 5.75rem;
  min-height: 42px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.xq-pwa-guide__primary {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 0 14px;
}
.xq-pwa-guide__primary:hover { filter: brightness(1.08); }
.xq-pwa-guide__ghost {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-light);
  padding: 0 12px;
}
.xq-pwa-guide__ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.footer-legal-row {
  display: block;
  margin: 0 0 14px;
  line-height: 1.9;
}
.site-footer .footer-legal-row a,
.site-footer .footer-legal-row a:visited,
.site-footer .footer-legal-row a:focus {
  color: rgba(255, 255, 255, 0.92);
  text-decoration: none;
}
.site-footer .footer-legal-row a:hover {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.site-footer .footer-legal-row .legal-sep {
  padding: 0 10px;
  color: rgba(255, 255, 255, 0.55);
  user-select: none;
}
.about-site-links .legal-sep {
  padding: 0 10px;
  opacity: 0.65;
  user-select: none;
}
.about-site-links {
  line-height: 1.9;
}
.about-site-links a {
  text-decoration: none;
}
.about-site-links a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
/* footer-stack-spacing */
footer,
.site-footer,
.footer,
#footer,
.app-footer,
.page-footer {
  line-height: 1.8;
}
footer p,
.site-footer p,
.footer p,
#footer p,
.app-footer p,
.page-footer p {
  margin: 0;
}
footer p + p,
.site-footer p + p,
.footer p + p,
#footer p + p,
.app-footer p + p,
.page-footer p + p,
.page-footer .footer-desc {
  margin-top: 10px;
}

body.legal-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f4f6f8;
  color: #334155;
  -webkit-font-smoothing: antialiased;
}

body.legal-page .site-header {
  height: auto;
  overflow: visible;
  padding-top: 0;
  background: #fff;
  color: #1e293b;
  border-bottom: 1px solid #e2e8f0;
}

body.legal-page .header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

body.legal-page .brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #1e293b;
}

body.legal-page .brand-link:hover {
  color: #1e293b;
  text-decoration: none;
}

body.legal-page .logo {
  display: inline-flex;
  flex: 0 0 auto;
}

body.legal-page .logo img {
  display: block;
  border-radius: 8px;
}

body.legal-page .site-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #1e293b;
}

body.legal-page .header-right a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  color: #334155;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

body.legal-page .header-right a:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

body.legal-page .site-footer {
  margin-top: auto;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  padding: 28px 20px calc(28px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 14px;
  color: #64748b;
}

body.legal-page .footer-main {
  margin: 0 0 12px;
  color: #64748b;
}

body.legal-page .legal-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  margin: 0;
  line-height: 1.8;
}

body.legal-page .legal-nav a {
  color: #475569;
  text-decoration: none;
}

body.legal-page .legal-nav a:not(:last-child)::after {
  content: "·";
  padding: 0 12px;
  color: #94a3b8;
}

body.legal-page .legal-nav a:hover,
body.legal-page .legal-nav a[aria-current="page"] {
  color: var(--primary);
}

.legal-main {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

.legal-main h1 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 12px;
  color: #1e293b;
}

.legal-lead {
  font-size: 15px;
  line-height: 1.75;
  color: #64748b;
  margin: 0 0 22px;
}

.legal-updated {
  font-size: 13px;
  color: #64748b;
  margin: 0 0 22px;
}

.legal-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 22px 24px 10px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.legal-card h2 {
  font-size: 17px;
  margin: 0 0 12px;
  color: #1e293b;
}

.legal-card p,
.legal-card li {
  font-size: 15px;
  line-height: 1.8;
  color: #475569;
  margin: 0 0 10px;
}

.legal-card ul {
  padding-left: 1.2em;
  margin: 0 0 10px;
}

.legal-card a {
  color: var(--primary);
}

.legal-contact {
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 8px 0 14px;
}

.legal-contact p {
  margin: 0 0 6px;
  color: #334155;
}

.legal-card code {
  font-size: 13px;
  background: #f1f5f9;
  color: #334155;
  padding: 1px 6px;
  border-radius: 4px;
}

@media (max-width: 640px) {
  body.legal-page .header-inner {
    padding: 12px 16px;
  }

  body.legal-page .site-name {
    font-size: 15px;
    max-width: 52vw;
  }

  body.legal-page .header-right a {
    height: 34px;
    padding: 0 12px;
    font-size: 13px;
  }

  .legal-main {
    padding: 24px 16px 40px;
  }

  .legal-main h1 {
    font-size: 22px;
  }
}
