:root {
  --ink: #1c1410;
  --ink-soft: #3d2f26;
  --paper: #f3e2c2;
  --wood-deep: #8b5a2b;
  --wood-mid: #c48a3a;
  --wood-light: #e2b56a;
  --line: rgba(40, 24, 12, 0.78);
  --black-stone: #1a1a1a;
  --white-stone: #f7f1e6;
  --accent: #0f5c4c;
  --accent-soft: #1a7a66;
  --danger: #8b2e2e;
  --panel: rgba(255, 248, 235, 0.88);
  --shadow: 0 24px 60px rgba(28, 20, 16, 0.28);
  --radius: 18px;
  --font-display: "ZCOOL XiaoWei", "Noto Serif SC", serif;
  --font-body: "Noto Serif SC", "Songti SC", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 背景与顶栏由 shared.css / game-page.css 统一提供 */
body.game-page {
  overflow-x: hidden;
}

.app {
  display: grid;
  gap: 1.25rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: 1.25rem;
  align-items: start;
  animation: rise 900ms 80ms ease both;
}

.layout > .board-wrap {
  width: max-content;
  max-width: 100%;
  justify-self: center;
}

.board-wrap {
  position: relative;
  background:
    linear-gradient(145deg, rgba(255, 236, 200, 0.14), transparent 40%),
    linear-gradient(180deg, #d29a4a 0%, #b87932 45%, #9a5f24 100%);
  border-radius: var(--radius);
  padding: clamp(0.75rem, 2vw, 1.25rem);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 230, 180, 0.25);
}

.board-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.12), transparent 35%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 11px,
      rgba(80, 40, 10, 0.03) 11px,
      rgba(80, 40, 10, 0.03) 12px
    );
}

#board {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  cursor: crosshair;
  touch-action: none;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 240, 200, 0.35), transparent 40%),
    linear-gradient(180deg, var(--wood-light), var(--wood-mid));
  box-shadow: inset 0 0 0 1px rgba(70, 40, 10, 0.2);
}

.panel {
  display: grid;
  gap: 0.9rem;
}

.card {
  background: var(--panel);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: 0 10px 28px rgba(20, 12, 8, 0.18);
  border: 1px solid rgba(255, 245, 220, 0.55);
}

.card h2 {
  margin: 0 0 0.65rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  white-space: nowrap;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.turn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 1.05rem;
  white-space: nowrap;
}

#turnLabel,
#moveCount,
.badge {
  white-space: nowrap;
}

.badge {
  flex-shrink: 0;
}

.stone-dot {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  box-shadow: inset -2px -2px 3px rgba(0, 0, 0, 0.35),
    inset 2px 2px 3px rgba(255, 255, 255, 0.25);
}

.stone-dot.black {
  background: radial-gradient(circle at 35% 30%, #555, var(--black-stone));
}

.stone-dot.white {
  background: radial-gradient(circle at 35% 30%, #fff, var(--white-stone));
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.badge {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: rgba(15, 92, 76, 0.1);
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
}

.meta {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.capture-note,
.score-preview {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.score-preview:empty {
  display: none;
}

.game-page button[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.meta strong {
  color: var(--ink);
  font-weight: 600;
}

.message {
  min-height: 1.4em;
  max-height: 12rem;
  overflow: auto;
  margin-top: 0.7rem;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--danger);
}

.message.info {
  color: var(--accent-soft);
}

.panel,
.card,
.field,
.controls,
.ai-options,
.kifu-playbar {
  min-width: 0;
  max-width: 100%;
}

.game-page .panel {
  overflow-x: hidden;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.55rem;
}

.controls > *,
.kifu-playbar > * {
  min-width: 0;
}

button,
select,
input {
  font-family: inherit;
}

button {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, opacity 160ms ease;
}

button:hover:not(:disabled):not(.secondary):not(.danger) {
  background: var(--accent-soft);
  color: #fff;
  transform: translateY(-1px);
}

button:focus-visible:not(.secondary):not(.danger),
button:active:not(:disabled):not(.secondary):not(.danger) {
  color: #fff;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible,
#board:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid rgba(61, 47, 38, 0.28);
}

button.secondary:hover:not(:disabled),
button.secondary:focus-visible {
  background: rgba(61, 47, 38, 0.06);
  color: var(--ink-soft);
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button.danger:hover:not(:disabled),
button.danger:focus-visible {
  background: var(--danger);
  color: #fff;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
}

.field label {
  font-size: 0.85rem;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

.field select,
.field input,
.coord-row input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid rgba(61, 47, 38, 0.25);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
  font-size: 0.95rem;
}

.coord-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.65rem;
}

.coord-row label {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.coord-row button {
  padding: 0.55rem 0.75rem;
}

.start-row {
  grid-template-columns: 1fr;
}

.game-page .card-setup {
  position: static;
}

.ai-options {
  display: grid;
  gap: 0;
  margin-bottom: 0.15rem;
  padding: 0.55rem 0.65rem 0.15rem;
  border-radius: 12px;
  background: rgba(15, 92, 76, 0.07);
  border: 1px solid rgba(15, 92, 76, 0.12);
  animation: pulseIn 360ms ease both;
}

.ai-options[hidden] {
  display: none !important;
}

#matchFields[hidden],
.field[hidden] {
  display: none !important;
}

.drill-note,
.drill-progress,
.drill-source {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.drill-progress {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.drill-source {
  margin: 0.65rem 0 0;
  font-size: 0.78rem;
  line-height: 1.45;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.7rem 0 0.15rem;
  font-size: 0.92rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.inline-check[hidden],
.card[hidden] {
  display: none !important;
}

.inline-check input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

.kifu-slider-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.kifu-playbar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
}

.kifu-playbar button {
  flex: 1;
}

.kifu-playbar label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.kifu-playbar select {
  width: auto;
  min-width: 0;
  max-width: 5.2rem;
}

.teach-note {
  margin: 0.35rem 0 0;
  min-height: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
}

.teach-note:empty {
  display: none;
}

.help {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.help li {
  margin-bottom: 0.25rem;
}

.result-banner {
  display: none;
  margin-top: 0.75rem;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: linear-gradient(120deg, rgba(15, 92, 76, 0.14), rgba(196, 138, 58, 0.18));
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  animation: pulseIn 420ms ease both;
}

.result-banner.show {
  display: block;
}

.footer-note {
  color: rgba(248, 236, 214, 0.65);
  font-size: 0.82rem;
  text-align: center;
  letter-spacing: 0.04em;
  animation: rise 1s 120ms ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulseIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 桌面侧栏：新对局（贴目、开始）排在操作前面，不依赖矮屏压缩。 */
@media (min-width: 901px) {
  .game-page .panel {
    display: flex;
    flex-direction: column;
  }

  .game-page #setupCard {
    order: -1;
  }

  .game-page #actionCard {
    order: 1;
  }

  .game-page .card-help {
    order: 2;
  }
}

@media (max-height: 860px) and (min-width: 901px) {
  .game-page .panel {
    position: relative;
    display: flex;
    flex-direction: column;
    padding-bottom: 2.7rem;
  }

  .game-page #setupCard {
    order: -1;
  }

  .game-page #actionCard {
    order: 1;
  }

  .game-page .card {
    padding: 0.5rem 0.65rem;
  }

  .game-page .card h2,
  .game-page .card-help summary {
    margin-bottom: 0.3rem;
  }

  .game-page button {
    padding: 0.42rem 0.55rem;
  }

  .game-page .field {
    margin-bottom: 0.32rem;
  }

  .game-page .message {
    margin-top: 0.35rem;
    max-height: none;
    overflow: visible;
  }

  .game-page .capture-note {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .game-page .start-row {
    position: static;
    margin-bottom: 0.35rem;
  }

  .game-page .card-help {
    position: absolute;
    left: 0;
    right: 0.15rem;
    bottom: 0;
    z-index: 6;
    max-height: 55%;
    overflow: auto;
    margin: 0;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  #btnScore,
  #btnAutoDead {
    grid-column: span 1;
  }
}

@media (max-width: 480px) {
  .board-wrap {
    padding: 0.45rem;
  }
}

/* 盖过 board-shell：矮桌面不再把围棋侧栏压到 220–280px。 */
@media (min-width: 901px) {
  body.game-page .layout {
    grid-template-columns: minmax(0, 1fr) minmax(20rem, 24rem);
  }
}

/*
 * 够宽且够高时，侧栏加宽并排成两列，让新对局、局势、操作（含点目）
 * 落在视口里，不必在侧栏里滚。更窄或更矮的屏幕仍用单列；手机可以整页滚动。
 */
@media (min-width: 1000px) and (min-height: 700px) {
  body.game-page .layout {
    grid-template-columns: minmax(0, 1fr) minmax(34rem, 36rem);
    align-items: start;
  }

  body.game-page .panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "setup status"
      "setup actions"
      "help help";
    align-items: start;
    align-content: start;
    gap: 0.5rem 0.65rem;
    max-height: calc(100dvh - 7.4rem);
    overflow-x: hidden;
    overflow-y: auto;
    padding-bottom: 0;
  }

  body.game-page #setupCard {
    grid-area: setup;
  }

  body.game-page #statusCard {
    grid-area: status;
  }

  body.game-page #actionCard {
    grid-area: actions;
  }

  body.game-page .card-help {
    grid-area: help;
    position: static;
    max-height: none;
    overflow: visible;
    margin: 0;
    left: auto;
    right: auto;
    bottom: auto;
  }

  body.game-page .card {
    padding: 0.55rem 0.7rem;
  }

  body.game-page .card h2,
  body.game-page .card-help summary {
    font-size: 1.05rem;
    margin-bottom: 0.28rem;
  }

  body.game-page .panel button:not(.ui-button) {
    padding: 0.45rem 0.55rem;
  }

  body.game-page .field {
    margin-bottom: 0.32rem;
    gap: 0.2rem;
  }

  body.game-page .field select,
  body.game-page .field input,
  body.game-page .coord-row input {
    padding: 0.4rem 0.55rem;
  }

  body.game-page .status-row {
    margin-bottom: 0.35rem;
  }

  body.game-page .meta {
    gap: 0.2rem;
  }

  /* 局势提示（点目说明、题面、批注）完整显示，不再压成 3.4rem 的小滚动框；侧栏整体可滚。 */
  body.game-page .message {
    margin-top: 0.35rem;
    max-height: none;
    overflow: visible;
    overflow-wrap: anywhere;
  }

  body.game-page .result-banner {
    font-size: 1rem;
    line-height: 1.55;
    letter-spacing: 0.03em;
    overflow-wrap: anywhere;
  }

  body.game-page .score-preview,
  body.game-page .teach-note {
    overflow-wrap: anywhere;
  }

  body.game-page .capture-note {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  body.game-page .inline-check {
    margin-top: 0.4rem;
  }

  body.game-page .coord-row {
    margin-top: 0.4rem;
  }

  body.game-page .ai-options {
    padding: 0.4rem 0.5rem 0.1rem;
  }
}

/* 矮桌面顶栏更短，侧栏可以再用回那一截高度，避免只差十几像素又出现滚动条。 */
@media (min-width: 1000px) and (min-height: 700px) and (max-height: 860px) {
  body.game-page .panel {
    max-height: calc(100dvh - 5.4rem);
  }
}

/*
 * 竖屏桌面（高大于等于宽，且宽过了手机断点）：棋盘铺满宽度放在上面，
 * 侧栏整段接到棋盘下面，棋盘才能做大。横屏仍左右并排；宽屏侧栏在够高时
 * 继续两列。宽度不超过 900px 的手机保持原来的单列。
 */
@media (min-width: 901px) and (orientation: portrait) {
  body.game-page .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  body.game-page .layout > .board-wrap {
    width: max-content;
    max-width: 100%;
    justify-self: center;
  }

  body.game-page .board-wrap {
    position: static;
    top: auto;
    max-height: none;
  }

  body.game-page .panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "setup status"
      "setup actions"
      "help help";
    align-items: start;
    align-content: start;
    gap: 0.65rem 0.75rem;
    max-height: none;
    overflow: visible;
    padding-bottom: 0;
  }

  body.game-page #setupCard {
    grid-area: setup;
  }

  body.game-page #statusCard {
    grid-area: status;
  }

  body.game-page #actionCard {
    grid-area: actions;
  }

  body.game-page .card-help {
    grid-area: help;
    position: static;
    max-height: none;
    overflow: visible;
    margin: 0;
    left: auto;
    right: auto;
    bottom: auto;
  }
}

/* 棋谱：学习方式、揭示、批注放在最上面；选谱放在后面。 */
.kifu-study {
  margin-bottom: 0.55rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed rgba(15, 92, 76, 0.22);
}

.kifu-study .drill-source:empty {
  display: none;
}

.kifu-study .drill-source {
  font-size: 0.86rem;
  color: var(--ink);
}

.kifu-pick {
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px dashed rgba(15, 92, 76, 0.22);
}

.kifu-pick-title {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

/* 窄屏常用操作条：默认不显示，只在手机单列时出现在棋盘正下方。 */
.quickbar {
  display: none;
}

.quickbar button[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .quickbar {
    position: sticky;
    bottom: calc(0.35rem + env(safe-area-inset-bottom));
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0.4rem 0.55rem;
    border-radius: 14px;
    background: var(--panel);
    backdrop-filter: blur(8px);
    box-shadow: 0 8px 22px rgba(20, 12, 8, 0.22);
    border: 1px solid rgba(255, 245, 220, 0.55);
  }

  .quickbar-turn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.92rem;
    color: var(--ink);
    white-space: nowrap;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .quickbar-turn #quickTurnLabel {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .quickbar-buttons {
    display: flex;
    gap: 0.4rem;
    flex: 1 1 auto;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .quickbar-buttons button {
    padding: 0.42rem 0.7rem;
    font-size: 0.88rem;
    border-radius: 10px;
  }

  .game-page .quickbar-buttons button.secondary {
    color: var(--ink-soft);
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(61, 47, 38, 0.32);
  }
}
