:root {
  --bg: #1c1a17;
  --panel: #2a2622;
  --line: #3a352f;
  --text: #f1ebe2;
  --muted: #a39a8e;
  --accent: #e0a44c;
  --accent-2: #c9853a;
  --good: #5fbf7a;
  --bad: #e06a5a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input { font: inherit; -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }

.page { min-height: 100vh; min-height: 100dvh; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px;
  padding: 10px 16px; transition: transform .08s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: transparent; color: #1c1409; font-weight: 600; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.btn.small { padding: 6px 12px; border-radius: 10px; font-size: 14px; }
.btn:disabled { opacity: .45; }

/* ---------- 首页 ---------- */
#home { display: grid; place-items: center; padding: calc(24px + var(--sat)) 20px calc(24px + var(--sab)); }
.home-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.logo { display: flex; justify-content: center; gap: 6px; margin-bottom: 4px; }
.logo .stone { width: 44px; height: 44px; }
h1 { margin: 0; text-align: center; font-size: 30px; letter-spacing: 6px; }
.sub { margin: -6px 0 10px; text-align: center; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.field input, .join-row input {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: var(--text);
  padding: 12px 14px; outline: none; font-size: 16px;
}
.field input:focus, .join-row input:focus { border-color: var(--accent); }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 2px; }

.stone { display: inline-block; border-radius: 50%; flex: none; }
.stone.b { background: radial-gradient(circle at 35% 30%, #666, #111 60%, #000); box-shadow: 0 1px 2px #0008; }
.stone.w { background: radial-gradient(circle at 35% 30%, #fff, #e6e1d8 60%, #bdb6aa); box-shadow: 0 1px 2px #0006; }

/* ---------- 房间 ---------- */
#room {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  height: 100vh; height: 100dvh; overflow: hidden;
  padding: calc(6px + var(--sat)) 10px calc(8px + var(--sab));
}
.topbar { width: 100%; max-width: 640px; display: flex; align-items: center; gap: 10px; }
.icon-btn { background: none; border: none; font-size: 30px; line-height: 1; padding: 0 8px 4px 2px; color: var(--muted); }
.room-title { flex: 1; color: var(--muted); font-size: 14px; }
.room-title b { color: var(--text); letter-spacing: 2px; font-size: 16px; }
#specCount { margin-left: 8px; font-size: 12px; }
.net { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); transition: background .3s; }
.net.ok { background: var(--good); }

.player {
  width: 100%; max-width: 640px; display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px;
  transition: border-color .2s, box-shadow .2s;
}
.player.turn { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.player .stone { width: 22px; height: 22px; }
.player .stone.none { background: #444; }
.player .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .name small { color: var(--muted); margin-left: 4px; }
.player .tag { font-size: 12px; color: var(--muted); }
.player .tag.off { color: var(--bad); }
.player .mic { font-size: 14px; opacity: .25; }
.player .mic.on { opacity: 1; }
.player .score { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 1.5em; text-align: right; }

.status { min-height: 22px; text-align: center; color: var(--muted); font-size: 14px; }
.status.hot { color: var(--accent); font-weight: 600; }
.status.win { color: var(--good); font-weight: 700; }
.status.lose { color: var(--bad); font-weight: 700; }

.board-wrap { position: relative; flex: 1; width: 100%; min-height: 0; display: grid; place-items: center; }
#board { touch-action: none; border-radius: 6px; box-shadow: 0 6px 24px #0008; }
.confirm {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #1c1409; border: none; border-radius: 999px;
  padding: 10px 22px; font-weight: 700; box-shadow: 0 4px 16px #0009;
}

.controls { width: 100%; max-width: 640px; display: flex; gap: 6px; }
.ctl {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 7px 2px;
  font-size: 12px; color: var(--muted);
}
.ctl i { font-style: normal; font-size: 18px; line-height: 1.2; filter: grayscale(1); opacity: .7; }
.ctl.on { border-color: var(--accent); color: var(--text); }
.ctl.on i { filter: none; opacity: 1; }
.ctl:disabled { opacity: .35; }
.ctl.hl { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #1c1409; border-color: transparent; }
.ctl.hl i { filter: none; opacity: 1; }

/* ---------- 弹窗 / 提示 ---------- */
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; padding: 20px; z-index: 10; }
.modal-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-text { font-size: 16px; text-align: center; white-space: pre-line; }
.modal-btns { display: flex; gap: 10px; }
.modal-btns .btn { flex: 1; }
#modalExtra input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text); padding: 11px 12px; font-size: 16px; outline: none; }

.toast {
  position: fixed; left: 50%; top: calc(60px + var(--sat)); transform: translateX(-50%);
  background: #000d; color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px;
  z-index: 20; max-width: 90vw; text-align: center; pointer-events: none;
}

@media (min-width: 700px) {
  #room { gap: 10px; padding-top: 14px; }
}
