/* 路墙棋 — 清新现代风 */

:root {
  --bg: #edf1ec;
  --ink: #24352e;
  --ink-soft: #5c6f66;
  --card: #ffffff;
  --accent: #1f8a70;
  --accent-deep: #14664f;
  --accent-soft: #d9ece5;
  --clay: #c96a45;          /* AI 方 */
  --clay-soft: #f4ddd2;
  --board: #e3ddcd;         /* 棋盘底（缝隙色） */
  --cell: #faf7ef;
  --danger: #c0453e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(36, 53, 46, .06), 0 8px 24px rgba(36, 53, 46, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  /* 低调纹理背景：棋格、短墙、圆点的抽象散布 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'%3E%3Cg fill='none' stroke='%231f8a70' stroke-opacity='.055' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M24 38h30M39 23v30'/%3E%3Crect x='130' y='24' width='40' height='8' rx='4'/%3E%3Ccircle cx='190' cy='96' r='9'/%3E%3Cpath d='M60 132h26M60 146h26'/%3E%3Crect x='150' y='160' width='8' height='40' rx='4'/%3E%3Ccircle cx='34' cy='196' r='7'/%3E%3Cpath d='M96 78l14 14M110 78l-14 14'/%3E%3Crect x='88' y='182' width='30' height='30' rx='9'/%3E%3C/g%3E%3C/svg%3E");
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px 10px;
}

.brand { display: flex; align-items: center; gap: 9px; }

.brand h1 { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: .5px; }

.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background:
    radial-gradient(circle at 50% 26%, #fff 0 3.2px, transparent 3.5px),
    radial-gradient(circle at 50% 74%, #f3c0a9 0 3.2px, transparent 3.5px),
    linear-gradient(#fff 0 0) 50% 50% / 14px 3px no-repeat,
    var(--accent);
  box-shadow: 0 2px 6px rgba(20, 102, 79, .35);
}

.brand-mark-lg { width: 52px; height: 52px; border-radius: 15px;
  background:
    radial-gradient(circle at 50% 26%, #fff 0 6px, transparent 6.6px),
    radial-gradient(circle at 50% 74%, #f3c0a9 0 6px, transparent 6.6px),
    linear-gradient(#fff 0 0) 50% 50% / 27px 6px no-repeat,
    var(--accent);
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.level-badge {
  font-size: 13px; font-weight: 600; color: var(--accent-deep);
  background: var(--accent-soft);
  padding: 4px 10px; border-radius: 999px;
}

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

button { font: inherit; cursor: pointer; border: none; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; color: var(--ink-soft);
  font-size: 14px; font-weight: 600;
  padding: 7px 10px; border-radius: 10px;
  transition: background .15s, color .15s, opacity .15s;
}
.btn-ghost:active { background: rgba(36, 53, 46, .07); }
.btn-ghost:disabled { opacity: .35; cursor: default; }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 600;
  padding: 12px 22px; border-radius: 999px;
  box-shadow: 0 3px 12px rgba(20, 102, 79, .3);
  transition: transform .12s, background .15s, opacity .15s;
}
.btn-primary:active { transform: scale(.97); background: var(--accent-deep); }
.btn-primary:disabled { opacity: .4; box-shadow: none; cursor: default; }

.btn-wide { width: 100%; }

.icon { width: 17px; height: 17px; }

/* ---------- 对局双方信息行 ---------- */

.side-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px;
}

/* 棋盘块整体垂直居中于顶栏与屏幕底部之间 */
.side-row-ai { margin-top: auto; }

.side-id { display: flex; align-items: center; gap: 8px; min-width: 86px; }

.side-name { font-size: 14px; font-weight: 600; color: var(--ink-soft); }

.pawn-dot { width: 16px; height: 16px; border-radius: 50%; }
.pawn-dot-me { background: radial-gradient(circle at 34% 30%, #4fae94, var(--accent-deep)); }
.pawn-dot-ai { background: radial-gradient(circle at 34% 30%, #e09a77, #b05430); }

.wall-ticks { display: flex; gap: 4px; flex: 1; }
.wall-ticks i {
  width: 13px; height: 5px; border-radius: 3px;
  background: var(--accent-deep); opacity: .85;
  transition: opacity .2s, transform .2s;
}
.wall-ticks i.used { opacity: .16; transform: scaleX(.7); }
.side-row-ai .wall-ticks { justify-content: flex-end; }
.side-row-ai .wall-ticks i { background: #b3592f; }

.thinking { display: inline-flex; gap: 3px; margin-left: 2px; }
.thinking span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--clay); opacity: .3;
  animation: think 1.1s infinite;
}
.thinking span:nth-child(2) { animation-delay: .18s; }
.thinking span:nth-child(3) { animation-delay: .36s; }
@keyframes think { 0%, 60%, 100% { opacity: .25; } 30% { opacity: .95; } }

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

.board-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
}

#board { display: block; width: 100%; height: auto; touch-action: none; }

.cell { fill: var(--cell); }
.cell-goal-me { fill: #f2f7ee; }
.cell-goal-ai { fill: #faf3ec; }

.move-target { fill: var(--accent); opacity: .16; rx: 9; animation: breathe 1.8s ease-in-out infinite; cursor: pointer; }
@keyframes breathe { 0%, 100% { opacity: .13; } 50% { opacity: .26; } }
.move-dot { fill: var(--accent-deep); opacity: .55; pointer-events: none; }

.pawn { filter: drop-shadow(0 2px 3px rgba(36, 53, 46, .3)); transition: cx .28s cubic-bezier(.3, 1.2, .4, 1), cy .28s cubic-bezier(.3, 1.2, .4, 1); }

.wall-piece { rx: 3.5; filter: drop-shadow(0 1px 2px rgba(60, 38, 15, .35)); }
.wall-p0 { fill: var(--accent-deep); }
.wall-p1 { fill: #b3592f; }
.wall-piece.wall-new { animation: wallDrop .3s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes wallDrop { from { opacity: 0; transform: scale(1.25); transform-origin: center; transform-box: fill-box; } }

.wall-preview { rx: 3.5; fill: var(--accent); opacity: .8; animation: previewPulse 1.2s ease-in-out infinite; pointer-events: none; }
.wall-preview.invalid { fill: var(--danger); }
@keyframes previewPulse { 0%, 100% { opacity: .82; } 50% { opacity: .5; } }

/* ---------- 提示与确认条 ---------- */

.hint {
  text-align: center; font-size: 12.5px; color: var(--ink-soft);
  margin: 12px 4px auto; opacity: .8; min-height: 17px;
  padding-bottom: 4px;
}

.confirm-bar {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px));
  display: flex; align-items: center; gap: 14px;
  background: var(--card);
  padding: 10px 12px 10px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 24px rgba(36, 53, 46, .22);
  animation: riseIn .22s cubic-bezier(.2, 1.2, .4, 1);
  z-index: 30;
}
.confirm-bar span { font-size: 14px; font-weight: 600; color: var(--ink); white-space: nowrap; }
@keyframes riseIn { from { opacity: 0; transform: translate(-50%, 14px); } }

/* ---------- 遮罩面板 ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(30, 44, 38, .38);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 20px;
  animation: fadeIn .2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }

.panel {
  width: 100%; max-width: 360px;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
  text-align: center;
  animation: panelIn .26s cubic-bezier(.2, 1.15, .4, 1);
}
@keyframes panelIn { from { opacity: 0; transform: translateY(18px) scale(.97); } }

.panel h2 { margin: 0; font-size: 24px; font-weight: 700; }

.panel-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 20px; }

.panel-sub { margin: 2px 0 0; font-size: 13.5px; color: var(--ink-soft); }

.group-label {
  text-align: left; font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  margin: 0 0 8px; letter-spacing: .5px;
}
.group-label-ai { color: #b3592f; margin-top: 14px; }

.level-grid {
  display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px;
  margin-bottom: 6px;
}

.level-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, transform .12s;
  padding: 0;
}
.level-cell:active { transform: scale(.93); }
.level-cell.selected { background: var(--accent); color: #fff; box-shadow: 0 3px 10px rgba(20, 102, 79, .35); }
.level-cell.lv-ai.selected { background: #b3592f; box-shadow: 0 3px 10px rgba(176, 84, 48, .35); }

.level-note { font-size: 13px; color: var(--ink-soft); margin: 8px 0 16px; min-height: 18px; }

/* ---------- 起名 ---------- */

.name-input {
  width: 100%;
  font: inherit; font-size: 16px; text-align: center;
  padding: 12px 14px;
  border: 2px solid var(--accent-soft);
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  margin-bottom: 16px;
  transition: border-color .15s;
}
.name-input:focus { border-color: var(--accent); }

/* ---------- 排行榜 ---------- */

.panel-rank h2 { margin-bottom: 2px; }

.rank-list {
  margin: 16px 0 18px;
  max-height: 46vh;
  overflow-y: auto;
  text-align: left;
}

.rank-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
}
.rank-row:nth-child(odd) { background: var(--bg); }
.rank-row.rank-me { background: var(--accent-soft); }

.rank-no { width: 22px; font-weight: 700; color: var(--ink-soft); text-align: center; flex: none; }
.rank-row:nth-child(1) .rank-no { color: #c9973a; }
.rank-row:nth-child(2) .rank-no { color: #9aa3ad; }
.rank-row:nth-child(3) .rank-no { color: #b3592f; }
.rank-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-rate { font-weight: 700; color: var(--accent-deep); flex: none; }
.rank-games { font-size: 12px; color: var(--ink-soft); flex: none; }

.rank-empty { text-align: center; font-size: 13.5px; color: var(--ink-soft); padding: 18px 6px; line-height: 1.7; }

.panel-end h2 { font-size: 26px; }
.panel-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }

/* 桌面端微调 */
@media (min-width: 700px) {
  .app { padding-top: 32px; }
  .hint { font-size: 13px; }
}
