/* ============================================================
   全局与国风主题
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: "KaiTi", "STKaiti", "SimSun", "Microsoft YaHei", serif;
  color: #3d2a16;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(ellipse at 15% 10%, rgba(255,240,210,.55), transparent 50%),
    radial-gradient(ellipse at 85% 90%, rgba(200,160,100,.25), transparent 45%),
    linear-gradient(165deg, #efe3cc 0%, #ddc9a3 45%, #c9ad7c 100%);
  background-attachment: fixed;
  display: flex;
  justify-content: center;
}

#app { width: 100%; max-width: 1180px; padding: 14px 12px 34px; animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 顶栏 ---------- */
.topbar { text-align: center; padding: 6px 0 14px; }
.topbar h1 {
  font-size: 34px;
  letter-spacing: 12px;
  text-indent: 12px;
  color: #4a2e10;
  text-shadow: 0 1px 0 rgba(255,255,255,.5), 0 3px 10px rgba(80,45,15,.25);
}
.topbar .sub {
  margin-top: 4px;
  font-size: 13px;
  letter-spacing: 4px;
  color: #7a5a36;
  opacity: .85;
}

/* ---------- 主布局：棋盘 + 侧栏 ---------- */
#gameArea {
  display: flex;
  gap: 22px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

#boardZone { flex: 0 0 auto; }
#boardWrap {
  position: relative;
  width: min(94vw, 640px);
  touch-action: manipulation;
  border-radius: 14px;
  box-shadow:
    0 12px 32px rgba(45,25,8,.42),
    0 0 0 1px rgba(255,235,190,.45),
    0 0 0 4px rgba(120,75,30,.12),
    inset 0 0 0 1px rgba(90,55,20,.20);
}
canvas { display: block; border-radius: 14px; }

#pieces, #markers { position: absolute; inset: 0; pointer-events: none; }
#pieces { pointer-events: auto; }

/* ---------- 棋子 ---------- */
.piece {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--piece-size);
  height: var(--piece-size);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  font-weight: 700;
  font-size: calc(var(--piece-size) * 0.5);
  line-height: 1;
  border: 1px solid rgba(80,45,15,.50);
  box-shadow:
    0 4px 8px rgba(0,0,0,.32),
    0 1px 2px rgba(0,0,0,.18),
    inset 0 -4px 8px rgba(0,0,0,.12),
    inset 0 3px 8px rgba(255,255,255,.55);
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .15s ease;
  will-change: transform;
}
.piece.red {
  background: radial-gradient(circle at 36% 28%, #fff3d4, #f5d49a 55%, #ddb06a 85%, #c99a55);
  border-color: rgba(160,90,30,.50);
}
.piece.black {
  background: radial-gradient(circle at 36% 28%, #faf3e4, #e8d5b0 55%, #cfb482 85%, #b89a6a);
  border-color: rgba(70,50,25,.50);
}
.piece.red span { color: #9b2214; text-shadow: 0 1px 1px rgba(255,255,255,.40); }
.piece.black span { color: #1a1208; text-shadow: 0 1px 1px rgba(255,255,255,.35); }
.piece:hover {
  box-shadow:
    0 5px 12px rgba(0,0,0,.38),
    0 0 0 2px rgba(240,200,100,.80),
    0 0 12px rgba(240,200,100,.25),
    inset 0 -4px 8px rgba(0,0,0,.12),
    inset 0 3px 8px rgba(255,255,255,.55);
  transform: scale(1.04);
}
.piece.selected {
  box-shadow:
    0 0 0 3px #f5c542,
    0 0 0 6px rgba(245,197,66,.30),
    0 6px 14px rgba(0,0,0,.40),
    inset 0 -4px 8px rgba(0,0,0,.12),
    inset 0 3px 8px rgba(255,255,255,.55);
  z-index: 3;
  transform: scale(1.06);
}
.piece.check { animation: checkPulse .75s ease-in-out infinite; z-index: 4; }
@keyframes checkPulse {
  0%, 100% {
    box-shadow:
      0 0 0 3px rgba(214,38,25,.90),
      0 0 18px rgba(214,38,25,.55),
      0 4px 8px rgba(0,0,0,.32),
      inset 0 -4px 8px rgba(0,0,0,.12),
      inset 0 3px 8px rgba(255,255,255,.55);
  }
  50% {
    box-shadow:
      0 0 0 3px rgba(214,38,25,.25),
      0 0 4px rgba(214,38,25,.15),
      0 4px 8px rgba(0,0,0,.32),
      inset 0 -4px 8px rgba(0,0,0,.12),
      inset 0 3px 8px rgba(255,255,255,.55);
  }
}

/* ---------- 合法落点标记 ---------- */
.marker {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(40,120,50,.35) 0%, rgba(40,120,50,.15) 100%);
  border: 2px solid rgba(40,120,50,.60);
  box-shadow: 0 0 8px rgba(40,120,50,.30), inset 0 0 6px rgba(255,255,255,.15);
  transition: transform .15s ease;
}
.marker.cap {
  background: radial-gradient(circle, rgba(180,45,30,.25) 0%, rgba(180,45,30,.10) 100%);
  border: 2px solid rgba(180,45,30,.65);
  box-shadow: 0 0 8px rgba(180,45,30,.30), inset 0 0 6px rgba(255,255,255,.10);
}

/* ---------- 提示与弹窗 ---------- */
#toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 8px 28px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(78,34,10,.92), rgba(58,28,8,.92));
  color: #ffe9c0;
  font-size: 18px;
  letter-spacing: 5px;
  text-indent: 5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35), 0 0 0 1px rgba(255,220,160,.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 7;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(45,25,8,.48);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
  z-index: 8;
}
#overlay.show { opacity: 1; pointer-events: auto; }
#overlayBox {
  min-width: 220px;
  background: linear-gradient(180deg, #faf0d8, #eedcb8);
  border: 2px solid #8a5a2a;
  border-radius: 16px;
  padding: 28px 40px 24px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0,0,0,.42), 0 0 0 1px rgba(255,240,200,.3);
  transform: scale(.95);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
}
#overlay.show #overlayBox { transform: scale(1); }
#overlayTitle { font-size: 26px; letter-spacing: 6px; color: #4a2e10; }
#overlayDesc  { margin-top: 8px; font-size: 14px; color: #7a5430; letter-spacing: 2px; }
#overlayRestart {
  margin-top: 18px;
  width: 100%;
}

/* ---------- 侧栏面板 ---------- */
#panel {
  width: 302px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(140,95,45,.45) transparent;
}
#panel::-webkit-scrollbar { width: 6px; }
#panel::-webkit-scrollbar-thumb { background: rgba(140,95,45,.40); border-radius: 3px; }
#panel::-webkit-scrollbar-track { background: transparent; }
.card {
  background: linear-gradient(180deg, rgba(255,250,238,.96), rgba(242,228,200,.94));
  border: 1px solid rgba(200,170,110,.55);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 4px 16px rgba(80,50,15,.14), 0 0 0 1px rgba(255,248,230,.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.card h2 {
  font-size: 15px;
  font-weight: 700;
  color: #5d3d18;
  letter-spacing: 4px;
  border-bottom: 1px solid rgba(200,170,110,.40);
  padding-bottom: 7px;
  margin-bottom: 10px;
}
.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 14px;
}
.status-row b { font-weight: 700; }
.cap-line { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.cap-line b { font-weight: 700; letter-spacing: 2px; }

.btn-group { display: flex; gap: 8px; }
.eg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.eg-grid button { padding: 8px 4px; font-size: 13px; }
.eg-hint { margin-top: 8px; font-size: 12px; color: #8a6a3e; line-height: 1.7; letter-spacing: 1px; }
button {
  font-family: inherit;
  touch-action: manipulation;
  border: 1px solid rgba(155,115,61,.60);
  background: linear-gradient(180deg, #faf0d4, #ecd3a2);
  color: #4c3314;
  border-radius: 9px;
  padding: 9px 6px;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all .15s ease;
  box-shadow: 0 2px 4px rgba(100,60,20,.10);
}
button:hover {
  background: linear-gradient(180deg, #fdf6e4, #f2dcae);
  box-shadow: 0 3px 10px rgba(120,70,20,.20);
  transform: translateY(-1px);
}
button:active { transform: translateY(1px); box-shadow: 0 1px 3px rgba(100,60,20,.15); }
button.active {
  background: linear-gradient(180deg, #d4944a, #b06820);
  color: #fff8e8;
  border-color: #8a4d12;
  box-shadow: 0 3px 8px rgba(120,60,10,.30), inset 0 1px 2px rgba(255,255,255,.20);
}
button:disabled { opacity: .40; cursor: not-allowed; box-shadow: none; transform: none; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions button:nth-child(3) { grid-column: 1 / -1; }

.thinking {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: #8a5a1e;
  font-size: 14px;
  letter-spacing: 1px;
}
.thinking.show { display: flex; }
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(200,170,110,.40);
  border-top-color: #8a5a1e;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.dot { opacity: 0; animation: blink 1.2s infinite; }
.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }

.hint {
  font-size: 12px;
  color: #8a6a3e;
  line-height: 1.8;
  letter-spacing: 1px;
  opacity: .9;
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 920px) {
  #gameArea { flex-direction: column; align-items: center; }
  #panel {
    width: 100%;
    max-width: 640px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
  }
  .card { flex: 1 1 calc(50% - 10px); min-width: 230px; }
}
@media (max-width: 520px) {
  .topbar h1 { font-size: 28px; letter-spacing: 8px; text-indent: 8px; }
  .card { flex: 1 1 100%; }
  .piece { font-size: calc(var(--piece-size) * 0.48); }
  #overlayBox { padding: 22px 28px 18px; }
}
/* 矮窗口：压缩顶栏，给棋盘留出更多纵向空间 */
@media (max-height: 720px) {
  .topbar h1 { font-size: 24px; letter-spacing: 8px; text-indent: 8px; }
  .topbar { padding: 2px 0 8px; }
  .topbar .sub { font-size: 11px; letter-spacing: 3px; }
  #app { padding-bottom: 16px; }
}
@media (max-height: 480px) {
  .topbar h1 { font-size: 20px; letter-spacing: 5px; text-indent: 5px; }
  .topbar .sub { display: none; }
}
/* 矮桌面窗口：压缩侧栏卡片，使整页尽量收进一屏（棋盘高度自适应的配套措施） */
@media (min-width: 921px) and (max-height: 780px) {
  #panel { gap: 8px; }
  .card { padding: 10px 12px; }
  .card h2 { padding-bottom: 5px; margin-bottom: 7px; letter-spacing: 2px; }
  .status-row { padding: 2px 0; font-size: 13px; }
  .cap-line { padding: 1px 0; font-size: 12px; }
  .hint { line-height: 1.55; }
}
@media (min-width: 921px) and (max-height: 620px) {
  #panel .card:last-child { display: none; }   /* 收起操作提示卡片 */
  button { padding: 7px 6px; font-size: 13px; }
}
@media (min-width: 921px) and (max-height: 500px) {
  .cap-line { display: none; }                 /* 收起吃子记录 */
}
