/* 步步为营 · Quoridor —— 平面化设计系统
 * 棋盘网格：repeat(8, 1fr 0.32fr) 1fr —— 0.32 槽宽比例必须与 js/ui.js 的 GAP 一致。
 */

/* ---------- 基础与设计令牌 ---------- */

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

:root {
  --bg: #efe9dd;
  --surface: #fbf8f2;
  --surface2: #f2ede1;
  --line: #e3dbc9;
  --text: #2c261d;
  --muted: #8f8677;
  --cell: #e9e1cf;
  --wall: #4a4036;
  --ink: #332d24;
  --ink-text: #f7f3ea;
  --danger: #dd5044;
  --p1: #4b7bf5;
  --p2: #e79f35;
  --p3: #35a97a;
  --p4: #e15b70;
  --pawn-ring: rgba(255, 255, 255, 0.85);
  --radius: 16px;
  --shadow-pop: 0 24px 80px rgba(46, 36, 18, 0.28);
}

:root[data-theme="dark"] {
  --bg: #131217;
  --surface: #1d1b21;
  --surface2: #26232c;
  --line: #34303b;
  --text: #ebe7de;
  --muted: #96909a;
  --cell: #2b2833;
  --wall: #e6d8bc;
  --ink: #ece7dd;
  --ink-text: #22201a;
  --danger: #ff6b5e;
  --p1: #6f96ff;
  --p2: #f2b455;
  --p3: #45c48f;
  --p4: #f47d90;
  --pawn-ring: rgba(19, 18, 23, 0.55);
  --shadow-pop: 0 24px 80px rgba(0, 0, 0, 0.5);
}

html { height: 100%; }

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system,
    "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s;
}

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--p1); outline-offset: 2px; border-radius: 8px; }

/* ---------- 顶栏 ---------- */

.app { max-width: 1080px; margin: 0 auto; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 22px 10px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand-text { line-height: 1.22; }
.brand-text h1 { font-size: 19px; letter-spacing: 0.5px; }
.brand-text span { font-size: 10.5px; letter-spacing: 3.5px; color: var(--muted); font-weight: 700; }

.top-actions { display: flex; gap: 8px; }

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s, transform 0.06s;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--ink); color: var(--ink-text); }
.btn.primary:hover { opacity: 0.88; }
.btn.ghosty { border-color: var(--line); background: var(--surface); }
.btn.ghosty:hover { background: var(--surface2); }
.btn.icon { padding: 9px; border-color: var(--line); background: var(--surface); }
.btn.icon:hover { background: var(--surface2); }
.btn:disabled { opacity: 0.42; cursor: default; pointer-events: none; }
.btn.big { width: 100%; justify-content: center; padding: 12px; font-size: 15px; border-radius: 13px; }

:root[data-theme="light"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* ---------- 页面布局 ---------- */

.layout {
  display: flex;
  gap: 30px;
  justify-content: center;
  align-items: flex-start;
  padding: 8px 22px 34px;
}

.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.hint { font-size: 12.5px; color: var(--muted); text-align: center; }

.side {
  width: 272px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 14px;
}

.side-foot { font-size: 11.5px; color: var(--muted); line-height: 1.7; padding: 2px 4px 0; }

/* ---------- 状态条 ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 700;
}
.status .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--pc, var(--muted));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc, var(--muted)) 18%, transparent);
}
.status.thinking .dot { animation: blink 1.1s ease-in-out infinite; }
.status.thinking #statusText::after { content: "…"; }

/* ---------- 玩家卡片 ---------- */

.cards { display: flex; flex-direction: column; gap: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.2s, background-color 0.2s;
}
.card.active {
  border-color: color-mix(in srgb, var(--pc) 55%, var(--line));
  background: color-mix(in srgb, var(--pc) 7%, var(--surface));
}
.card.won { border-color: var(--pc); }

.cav {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex: none;
  background: var(--pc);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pc) 20%, transparent);
}

.cmain { flex: 1; min-width: 0; }
.cname { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--line);
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.you { color: #fff; background: var(--pc); border-color: transparent; }

.cticks { display: flex; gap: 3px; margin-top: 7px; flex-wrap: wrap; }
.tick {
  width: 12px;
  height: 5px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--pc) 75%, var(--surface));
  transition: background-color 0.3s;
}
.tick.off { background: var(--line); }

.ccount {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--pc) 80%, var(--text));
}

/* ---------- 棋盘 ---------- */

.board-frame {
  --bp: 10px; /* 与 .board 内边距、.pawns 定位共用 */
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  grid-template-areas: "ranks board" ". files";
  justify-content: center;
}

.board {
  grid-area: board;
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr 0.32fr) 1fr;
  grid-template-rows: repeat(8, 1fr 0.32fr) 1fr;
  width: min(88vw, 600px, calc(100dvh - 255px));
  min-width: 288px;
  aspect-ratio: 1 / 1;
  padding: var(--bp);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background-color 0.25s, border-color 0.25s;
}

.coords {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  user-select: none;
  display: grid;
}
#coordFiles {
  grid-area: files;
  grid-template-columns: repeat(8, 1fr 0.32fr) 1fr;
  padding: 0 calc(var(--bp) + 1px);
  margin-top: 6px;
}
#coordFiles span { text-align: center; }
#coordRanks {
  grid-area: ranks;
  grid-template-rows: repeat(8, 1fr 0.32fr) 1fr;
  padding: calc(var(--bp) + 1px) 0;
  margin-right: 8px;
}
#coordRanks span { display: flex; align-items: center; justify-content: flex-end; }

.cell {
  position: relative;
  background: var(--cell);
  border-radius: 16%;
  transition: background-color 0.15s;
}
.cell.target { cursor: pointer; }
.cell.target::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 27%;
  height: 27%;
  border-radius: 50%;
  background: var(--tc);
  opacity: 0.9;
  animation: dot-in 0.16s ease-out;
  transition: transform 0.12s;
}
.cell.target:hover { background: color-mix(in srgb, var(--tc) 14%, var(--cell)); }
.cell.target:hover::after { transform: scale(1.28); }

/* 放板感应槽（比可见格线略宽，便于命中） */
.slot { z-index: 5; border-radius: 6px; cursor: pointer; }
.slot.zh { margin: -5px 0; }
.slot.zv { margin: 0 -5px; }
.board.locked .slot, .board.locked .cell { cursor: default; }

/* 终点提示条：贴在棋盘内边距中的细色条，指示该颜色玩家的目标底线 */
.goal-strip {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  border-radius: 99px;
  background: color-mix(in srgb, var(--pc) 50%, transparent);
}
.goal-strip.top    { top: 3px;    left: 14%; right: 14%; height: 4px; }
.goal-strip.bottom { bottom: 3px; left: 14%; right: 14%; height: 4px; }
.goal-strip.left   { left: 3px;   top: 14%; bottom: 14%; width: 4px; }
.goal-strip.right  { right: 3px;  top: 14%; bottom: 14%; width: 4px; }

/* 挡板 */
.wall {
  z-index: 3;
  background: var(--wall);
  border-radius: 99px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  animation: wall-in 0.22s cubic-bezier(0.25, 1.4, 0.5, 1);
}
.wall.recent { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22), 0 0 0 3px color-mix(in srgb, var(--wall) 22%, transparent); }

/* 放板预览 */
.ghost { display: none; z-index: 4; border-radius: 99px; pointer-events: none; }
.ghost.show { display: block; }
.ghost.ok { background: color-mix(in srgb, var(--wall) 55%, transparent); }
.ghost.bad { background: color-mix(in srgb, var(--danger) 50%, transparent); }
.ghost.pending { animation: blink 1s ease-in-out infinite; }

/* 棋子 */
.pawns { position: absolute; inset: var(--bp, 10px); z-index: 6; pointer-events: none; }
.pawn {
  position: absolute;
  display: grid;
  place-items: center;
  transition: left 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), top 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.pawn::after {
  content: "";
  width: 66%;
  height: 66%;
  border-radius: 50%;
  background: var(--pc);
  box-shadow:
    inset 0 0 0 2.5px var(--pawn-ring),
    0 2px 8px color-mix(in srgb, var(--pc) 45%, transparent);
  transition: box-shadow 0.2s;
}
.pawn.active::after {
  box-shadow:
    inset 0 0 0 2.5px var(--pawn-ring),
    0 2px 8px color-mix(in srgb, var(--pc) 45%, transparent),
    0 0 0 5px color-mix(in srgb, var(--pc) 22%, transparent);
}
.pawn.thinking::after { animation: pawn-breathe 1.3s ease-in-out infinite; }
.pawn.winner::after { animation: win-pop 0.55s cubic-bezier(0.3, 1.6, 0.5, 1); }

/* ---------- 弹窗 ---------- */

.dlg {
  margin: auto; /* 全局 reset 清掉了 dialog 默认居中，这里补回 */
  border: none;
  padding: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  width: min(92vw, 430px);
  box-shadow: var(--shadow-pop);
}
.dlg::backdrop { background: rgba(22, 18, 12, 0.5); }
.dlg-body { position: relative; padding: 24px; max-height: 86dvh; overflow: auto; }
.dlg h2 { font-size: 18px; margin-bottom: 18px; }

.dlg-x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.dlg-x:hover { color: var(--text); }

.field { margin-bottom: 15px; }
.field > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; font-weight: 600; }
[hidden] { display: none !important; }

.seg {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.seg button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 6px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14); }
.seg.mini button { padding: 5px 10px; font-size: 12.5px; }

.seat-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.seat-row .sname { flex: 1; font-size: 13.5px; font-weight: 600; }
.seat-row .seg { flex: none; }

.dlg .btn.primary.big { margin-top: 6px; }

/* 规则弹窗 */
.rules h3 { font-size: 14px; margin: 15px 0 5px; }
.rules h3:first-of-type { margin-top: 0; }
.rules p, .rules li { font-size: 13.5px; line-height: 1.8; }
.rules ul { padding-left: 19px; }
.rules .tip { color: var(--muted); }

/* 胜利弹窗 */
.win-body { text-align: center; padding: 32px 24px 24px; }
#winDot {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  margin: 0 auto 14px;
  background: var(--pc, var(--p1));
  box-shadow: 0 0 0 9px color-mix(in srgb, var(--pc, var(--p1)) 14%, transparent);
  animation: win-pop 0.5s cubic-bezier(0.3, 1.6, 0.5, 1);
}
#winTitle { font-size: 20px; margin-bottom: 18px; }
#winStats { display: flex; gap: 10px; margin-bottom: 22px; }
.stat { flex: 1; background: var(--surface2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); }
.win-actions { display: flex; gap: 10px; }
.win-actions .btn { flex: 1; justify-content: center; }

/* ---------- 提示气泡 ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 16px);
  background: var(--ink);
  color: var(--ink-text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 99;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  max-width: 88vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 联机对战 ---------- */

.online-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 9px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}
.online-bar .odot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--p3);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--p3) 20%, transparent);
}
.online-bar .odot.off {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent);
  animation: blink 1.2s ease-in-out infinite;
}
.online-bar .oinfo { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.small { padding: 6px 12px; font-size: 12.5px; border-radius: 999px; flex: none; }

.room-input {
  width: 100%;
  margin-top: 10px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
}
.room-input::placeholder { letter-spacing: 0; font-size: 13.5px; font-weight: 500; color: var(--muted); }

.online-body { text-align: center; }
.online-tip { font-size: 13px; color: var(--muted); line-height: 1.7; margin-bottom: 16px; text-align: left; }
.room-code {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 10px;
  padding: 18px 6px 18px 16px;   /* 右侧少 10px 抵消末字符字距 */
  background: var(--surface2);
  border: 1px dashed var(--line);
  border-radius: 14px;
  margin-bottom: 12px;
  user-select: all;
  font-variant-numeric: tabular-nums;
}
.online-wait { font-size: 13px; color: var(--muted); margin-top: 14px; }
.online-wait .dots { animation: blink 1.2s ease-in-out infinite; }

/* ---------- 动画 ---------- */

@keyframes dot-in { from { transform: scale(0.3); opacity: 0; } }
@keyframes wall-in { from { transform: scale(0.55); opacity: 0.4; } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes pawn-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.09); } }
@keyframes win-pop {
  0% { transform: scale(0.4); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ---------- 响应式 ---------- */

@media (max-width: 900px) {
  .layout { flex-direction: column; align-items: center; gap: 16px; }
  .side { width: 100%; max-width: 560px; position: static; }
  .cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 10px 12px; }
  .board { width: min(92vw, 560px, calc(100dvh - 300px)); }
}

@media (max-width: 520px) {
  .topbar { padding: 12px 14px 8px; }
  .layout { padding: 4px 12px 26px; }
  .btn.ghosty .lbl, .btn.primary .lbl { display: none; }
  .btn { padding: 9px 11px; }
  .board { width: 92vw; min-width: 0; }
  .cticks { display: none; } /* 小屏用数字即可 */
}

/* ---------- 动效关闭 ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.no-anim *, .no-anim *::before, .no-anim *::after { animation: none !important; transition: none !important; }
