/* =========================================================
   五子棋 · 联机对弈  —  简约柔美主题
   设计：暖奶油 / 淡薰衣草渐变 + 毛玻璃卡片 + 柔和阴影
   暗色模式（frosted）为品牌偏好，默认跟随系统，可手动切换
   ========================================================= */

:root {
  --bg1: #fbf3ee;
  --bg2: #f0eaf7;
  --bg3: #eef5f2;
  --text: #4a4350;
  --muted: #9a8f9c;
  --panel: rgba(255, 253, 250, 0.66);
  --panel-solid: #fffdfa;
  --border: rgba(180, 160, 140, 0.30);
  --border-strong: rgba(150, 130, 110, 0.45);
  --board-bg: linear-gradient(160deg, #fdf8f1 0%, #f6efe4 100%);
  --grid: rgba(150, 128, 104, 0.55);
  --star: rgba(120, 100, 80, 0.75);
  --stone-black: radial-gradient(circle at 34% 30%, #5d5763 0%, #2c2a33 72%);
  --stone-white: radial-gradient(circle at 34% 30%, #ffffff 0%, #e9e2d6 78%);
  --stone-shadow: rgba(120, 100, 80, 0.28);
  --accent: #cf8fb0;
  --accent-2: #9b8cd4;
  --accent-soft: rgba(207, 143, 176, 0.18);
  --win: #e0a93f;
  --shadow: 0 14px 40px rgba(150, 120, 100, 0.18);
  --shadow-sm: 0 6px 18px rgba(150, 120, 100, 0.14);
  --radius: 20px;
  --radius-sm: 14px;
}

[data-theme="dark"] {
  --bg1: #17141f;
  --bg2: #1d1830;
  --bg3: #15201f;
  --text: #ece8f2;
  --muted: #9b93ad;
  --panel: rgba(42, 37, 58, 0.55);
  --panel-solid: #221d30;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --board-bg: linear-gradient(160deg, #2a2636 0%, #211d2e 100%);
  --grid: rgba(206, 196, 224, 0.22);
  --star: rgba(220, 210, 240, 0.55);
  --stone-black: radial-gradient(circle at 34% 30%, #3c3848 0%, #1f1f29 72%);
  --stone-white: radial-gradient(circle at 34% 30%, #f4f1f8 0%, #cdc6db 80%);
  --stone-shadow: rgba(0, 0, 0, 0.40);
  --accent: #e0a3c2;
  --accent-2: #b3a4e6;
  --accent-soft: rgba(224, 163, 194, 0.16);
  --win: #f0c150;
  --shadow: 0 16px 46px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 8px 22px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(120% 90% at 12% 8%, var(--bg2) 0%, transparent 55%),
    radial-gradient(120% 90% at 92% 96%, var(--bg3) 0%, transparent 55%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  transition: color .3s ease;
  -webkit-font-smoothing: antialiased;
}
.app { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }

/* ---------- 屏幕切换 ---------- */
.screen { width: 100%; max-width: 560px; display: flex; flex-direction: column; align-items: center; gap: 18px; animation: fadeIn .35s ease; }
.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 大厅 ---------- */
.brand { text-align: center; }
.brand .logo { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.brand .logo .dot { width: 16px; height: 16px; border-radius: 50%; box-shadow: var(--shadow-sm); }
.brand .logo .dot.black { background: var(--stone-black); }
.brand .logo .dot.white { background: var(--stone-white); }
.brand h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: .5px; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- 毛玻璃卡片 ---------- */
.glass {
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.card { width: 100%; padding: 22px; display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; color: var(--muted); }
.input {
  width: 100%; padding: 12px 14px; font-size: 15px; color: var(--text);
  background: rgba(255, 255, 255, 0.35); border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none; transition: border-color .2s, box-shadow .2s;
}
[data-theme="dark"] .input { background: rgba(255, 255, 255, 0.06); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.avatars { display: flex; flex-wrap: wrap; gap: 8px; }
.avatars .av {
  width: 40px; height: 40px; font-size: 20px; display: grid; place-items: center;
  border-radius: 50%; cursor: pointer; border: 1px solid var(--border); background: rgba(255,255,255,.3);
  transition: transform .15s, border-color .2s, box-shadow .2s;
}
[data-theme="dark"] .avatars .av { background: rgba(255,255,255,.06); }
.avatars .av:hover { transform: translateY(-2px); }
.avatars .av.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- 按钮 ---------- */
.actions { display: flex; gap: 12px; }
.actions.col { flex-direction: column; }
.row { display: flex; gap: 10px; }
.row .input { flex: 1; }
.btn {
  flex: 1; padding: 13px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
  color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.4); transition: transform .12s, box-shadow .2s, background .2s, border-color .2s;
}
[data-theme="dark"] .btn { background: rgba(255, 255, 255, 0.07); }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { color: #fff; border: none; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 22px var(--accent-soft); }
[data-theme="dark"] .btn.primary { color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.hint { color: var(--muted); font-size: 13px; min-height: 18px; text-align: center; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(30, 24, 36, 0.35); backdrop-filter: blur(4px); z-index: 50; animation: fadeIn .25s ease; }
.modal-card { max-width: 380px; }
.modal-card h2 { margin: 0; font-size: 19px; }

/* ---------- 对局顶栏 ---------- */
#game { max-width: 580px; }
.topbar { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); }
.status { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 0; }
.status #turn-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: var(--shadow-sm); }
.chip.black { background: var(--stone-black); }
.chip.white { background: var(--stone-white); border: 1px solid var(--border-strong); }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 38px; height: 38px; font-size: 18px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--border); border-radius: 50%; background: rgba(255,255,255,.35); color: var(--text);
  transition: background .2s, transform .12s;
}
[data-theme="dark"] .icon-btn { background: rgba(255,255,255,.06); }
.icon-btn:hover { transform: translateY(-1px); }

/* ---------- 对局顶栏：房间号（好友房常驻） ---------- */
.room-code {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 5px 6px 5px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.35); border: 1px solid var(--border);
  font-size: 13px; font-weight: 700; letter-spacing: .6px; color: var(--text);
  backdrop-filter: blur(8px) saturate(140%); -webkit-backdrop-filter: blur(8px) saturate(140%);
}
[data-theme="dark"] .room-code { background: rgba(255, 255, 255, 0.07); }
.room-code #room-code-text { min-width: 0; }
.copy-btn {
  flex: none; width: 28px; height: 28px; font-size: 14px; cursor: pointer;
  display: grid; place-items: center; border: none; border-radius: 50%;
  background: rgba(255, 255, 255, 0.4); color: var(--text);
  transition: transform .12s, background .2s;
}
[data-theme="dark"] .copy-btn { background: rgba(255, 255, 255, 0.08); }
.copy-btn:hover { transform: translateY(-1px); }
.copy-btn:active { transform: scale(.92); }

/* ---------- 棋盘 ---------- */
.board-wrap { width: 100%; display: flex; justify-content: center; }
.board {
  position: relative; width: min(92vw, 520px); aspect-ratio: 1 / 1;
  background: var(--board-bg); border: 1px solid var(--border-strong);
  border-radius: 18px; box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.4);
  overflow: hidden; touch-action: manipulation;
}
.grid {
  position: absolute; inset: 0; margin: auto;
  /* 网格线落在交叉点：周期 1/15，偏移 1/30（即单元格中心） */
  background-image:
    linear-gradient(var(--grid) 1.3px, transparent 1.3px),
    linear-gradient(90deg, var(--grid) 1.3px, transparent 1.3px);
  background-size: calc(100% / 15) calc(100% / 15);
  background-position: calc(100% / 30) calc(100% / 30);
}
.stars { position: absolute; inset: 0; pointer-events: none; }
.stars .star { position: absolute; width: 7px; height: 7px; border-radius: 50%; background: var(--star); transform: translate(-50%, -50%); }
.stones { position: absolute; inset: 0; pointer-events: none; }
.cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr); z-index: 4; }
.cells .cell { border: none; background: transparent; padding: 0; cursor: pointer; }

.stone {
  position: absolute; width: calc(100% / 15 * 0.82); height: calc(100% / 15 * 0.82);
  border-radius: 50%; transform: translate(-50%, -50%) scale(.4); opacity: 0;
  box-shadow: 0 3px 7px var(--stone-shadow); animation: pop .18s cubic-bezier(.2,.8,.3,1.2) forwards;
}
.stone.black { background: var(--stone-black); }
.stone.white { background: var(--stone-white); }
.stone.last::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  border: 2px solid var(--accent); opacity: .9; animation: pulse 1.4s ease-in-out infinite;
}
.stone.win { box-shadow: 0 0 0 3px var(--win), 0 0 16px var(--win); animation: pop .18s forwards, glow 1.2s ease-in-out infinite; }
@keyframes pop { to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes pulse { 0%,100% { opacity: .35; } 50% { opacity: .95; } }
@keyframes glow { 0%,100% { box-shadow: 0 0 0 3px var(--win), 0 0 10px var(--win); } 50% { box-shadow: 0 0 0 3px var(--win), 0 0 20px var(--win); } }

/* ---------- 选手条 ---------- */
.players { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius-sm); }
.player { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.player .avatar { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 18px; background: rgba(255,255,255,.35); border: 1px solid var(--border); }
[data-theme="dark"] .player .avatar { background: rgba(255,255,255,.06); }
.pname { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ptag { font-size: 11px; color: var(--muted); }
.vs { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: 1px; }
.player.active .pname { color: var(--accent); }

/* ---------- 控制 / 结算 ---------- */
.controls { display: flex; gap: 12px; width: 100%; }
.controls .btn { flex: 1; }
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(30, 24, 36, 0.4); backdrop-filter: blur(5px); z-index: 60; animation: fadeIn .25s ease; }
.result-card { max-width: 360px; text-align: center; align-items: center; }
.result-card h2 { margin: 0; font-size: 22px; }
.result-emoji { font-size: 46px; animation: pop .3s ease; }
.result-card .actions { margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--border);
  padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow-sm); font-size: 14px;
  z-index: 70; animation: fadeIn .25s ease; max-width: 90vw; text-align: center;
}
/* ---------- 公告栏 ---------- */
.announcement {
  width: 100%; max-width: 560px; display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.5;
  background: var(--panel); border: 1px solid var(--border);
  backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow-sm); color: var(--text); animation: fadeIn .3s ease;
}
.announcement .ann-text { flex: 1; min-width: 0; }
.announcement .ann-close {
  flex: none; width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.3); color: var(--muted);
  font-size: 18px; line-height: 1; display: grid; place-items: center; transition: color .2s, background .2s;
}
[data-theme="dark"] .announcement .ann-close { background: rgba(255, 255, 255, 0.06); }
.announcement .ann-close:hover { color: var(--text); }

@media (max-width: 380px) { .brand h1 { font-size: 22px; } .actions { flex-direction: column; } }
