* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --wood-panel: #f3e2c0;
  --wood-panel-2: #ecd6ad;
  --wood-dark: #4a3320;
  --wood-deep: #2e1f12;
  --accent: #7a4a25;
  --accent-strong: #6b3f1d;
  --ink: #3d2b16;
  --muted: #8a7355;
  --green: #4caf50;
  --panel-w: 320px;
  --gap: 20px;
  /* 棋盘边长:取可用高/宽的较小值,预留顶部标题与背景留白,最大 600px */
  --board-size: min(calc(100vh - 80px), calc(100vw - var(--panel-w) - var(--gap) - 160px), 600px);
}

html, body {
  height: 100%;
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  background:
    linear-gradient(rgba(20, 12, 6, 0.35), rgba(20, 12, 6, 0.55)),
    url("assets/background.png") center / cover no-repeat fixed,
    #241812;
}

.table {
  width: 100%;
  height: 100%;
  max-width: 1180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
}

/* 顶部标题(已从信息栏移出,置于棋盘上方) */
.app-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #f0d9a7;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  flex: 0 0 auto;
}
.app-title .logo { display: inline-flex; }
.app-title h1 { font-size: 22px; font-weight: 800; letter-spacing: 3px; }
.app-title .size-badge {
  font-size: 12px;
  background: rgba(240, 217, 167, 0.16);
  color: #f0d9a7;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.game-layout {
  display: flex;
  gap: var(--gap);
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
}

/* ===== 棋盘卡片 ===== */
.board-card {
  width: var(--board-size);
  height: var(--board-size);
  flex: 0 0 auto;
  background: linear-gradient(160deg, #e8d4a6, #d9c088);
  border-radius: 16px;
  padding: 12px;
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.5),
    inset 0 0 0 2px rgba(255, 255, 255, 0.22);
}

.board-inner {
  position: relative;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  cursor: pointer;
}

/* ===== 侧边面板 ===== */
.side-panel {
  width: var(--panel-w);
  min-height: min(var(--board-size), calc(100vh - 80px));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(122, 74, 37, 0.4) transparent;
  background: linear-gradient(165deg, var(--wood-panel), var(--wood-panel-2));
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 6px;
}

.side-panel::-webkit-scrollbar { width: 6px; }
.side-panel::-webkit-scrollbar-thumb {
  background: rgba(122, 74, 37, 0.4);
  border-radius: 999px;
}
.side-panel::-webkit-scrollbar-track { background: transparent; }

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(122, 74, 37, 0.25);
}

.panel-head .logo { font-size: 22px; }

.panel-head h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--accent-strong);
  flex: 1;
}

.size-badge {
  font-size: 12px;
  background: rgba(122, 74, 37, 0.12);
  color: var(--accent-strong);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.panel-block { display: flex; flex-direction: column; gap: 6px; }

.block-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* 对战模式切换 */
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(122, 74, 37, 0.1);
  border-radius: 10px;
  padding: 4px;
}

.mode-btn {
  border: none;
  background: transparent;
  padding: 6px 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s ease;
}

.mode-btn.active {
  background: linear-gradient(160deg, #7a4a25, #5f3719);
  color: #fbe7c9;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
}

/* 局域网状态 */
.lan-flag {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #bbb;
  display: inline-block;
}

.dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }

.lan-join { display: flex; gap: 8px; }

.lan-join input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(122, 74, 37, 0.3);
  background: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  color: var(--ink);
  outline: none;
}

.lan-join input:focus { border-color: var(--accent); }

.lan-info { display: flex; flex-direction: column; gap: 8px; }

.lan-wait {
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  color: var(--green);
}

.lan-hint { font-size: 11px; color: var(--muted); text-align: center; }

.addr-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(122, 74, 37, 0.1);
  border-radius: 8px;
  padding: 8px 12px;
}

.addr-box span {
  flex: 1;
  font-size: 13px;
  color: var(--accent-strong);
  font-weight: 600;
  word-break: break-all;
}

.addr-box button {
  border: none;
  background: rgba(122, 74, 37, 0.18);
  color: var(--accent-strong);
  border-radius: 6px;
  width: 30px; height: 30px;
  cursor: pointer;
  font-size: 15px;
}

/* 对局信息 */
.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.35);
  transition: box-shadow 0.2s ease, background 0.2s ease;
}

.player-row.active {
  background: rgba(255, 248, 230, 0.85);
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.stone-ico {
  width: 20px; height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stone-ico.black { background: radial-gradient(circle at 35% 30%, #666, #000); }
.stone-ico.white { background: radial-gradient(circle at 35% 30%, #fff, #c8c8c8); border: 1px solid #bbb; }

.player-name { flex: 1; font-size: 14px; font-weight: 600; }

.player-state { font-size: 13px; color: var(--muted); font-weight: 600; }
.player-state.turn { color: var(--accent-strong); }

/* 统计 */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stat {
  background: rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  padding: 6px;
  text-align: center;
}

.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 20px; font-weight: 800; color: var(--accent-strong); margin-top: 1px; font-variant-numeric: tabular-nums; }
.stat-note { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* 提示 */
.tip-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  padding: 7px 12px;
}

.tip-ico { font-size: 20px; }
.tip-main { font-size: 14px; font-weight: 700; color: var(--accent-strong); }
.tip-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 操作按钮 */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.actions button {
  border: none;
  padding: 9px 0;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.2s ease;
}

.actions button:active { transform: scale(0.97); }
.actions button:disabled { opacity: 0.45; cursor: not-allowed; }

.actions .ghost { background: rgba(122, 74, 37, 0.14); color: var(--accent-strong); }
.actions .primary { background: linear-gradient(160deg, #7a4a25, #5f3719); color: #fbe7c9; }

.rule-foot {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding-top: 4px;
  border-top: 1px solid rgba(122, 74, 37, 0.2);
}

/* ===== 胜利弹层 ===== */
.win-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 12, 6, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fadeIn 0.35s ease;
}

.win-modal {
  background: linear-gradient(165deg, #fff6e2, #f0d9a7);
  border-radius: 18px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: popIn 0.5s cubic-bezier(0.18, 1.4, 0.4, 1);
}

.win-trophy {
  font-size: 64px;
  animation: bounce 1s ease infinite;
}

.win-title {
  font-size: 30px;
  font-weight: 900;
  color: var(--accent-strong);
  margin-top: 8px;
  letter-spacing: 2px;
}

.win-sub { font-size: 15px; color: var(--muted); margin-top: 6px; }

.win-modal button {
  margin-top: 20px;
  border: none;
  padding: 12px 32px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(160deg, #7a4a25, #5f3719);
  color: #fbe7c9;
  transition: transform 0.08s ease;
}

.win-modal button:active { transform: scale(0.96); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.hidden { display: none !important; }

/* ===== 响应式:窄屏改为纵向堆叠并允许滚动 ===== */
@media (max-width: 820px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .table { height: auto; }
  .game-layout {
    flex-direction: column;
    height: auto;
  }
  .board-card {
    width: min(92vw, 92vh);
    height: min(92vw, 92vh);
    order: 1;
  }
  .side-panel {
    width: min(92vw, 420px);
    height: auto;
    max-height: none;
    order: 2;
  }
}
