:root {
  --bg: #f4f1e8;
  --panel: #fbfaf6;
  --card: #ffffff;
  --ink: #1f2420;
  --muted: #7d847f;
  --line: #e4ded1;
  --felt: #1d6b47;
  --felt-d: #14513a;
  --red: #c8372d;
  --gold: #b8862a;
  --wei: #3a64a8;
  --shu: #2c8150;
  --wu: #c0392b;
  --qun: #8a6a3a;
  --top-h: 52px;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* 顶栏 */
.top { flex: none; height: var(--top-h); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--felt-d); color: #fff; }
.brand b { font-size: 18px; letter-spacing: 2px; }
.brand span { margin-left: 8px; font-size: 12px; opacity: .6; }
.me-wrap { position: relative; }
.me-chip { display: flex; align-items: center; gap: 8px; border: 0; background: rgba(255,255,255,.12); color: #fff; border-radius: 999px; padding: 4px 12px 4px 4px; }
.pick-cta { padding: 2px 4px 2px 10px; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; background: #fff; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 6px; min-width: 140px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; color: var(--ink); }
.menu button:hover { background: var(--bg); }
.menu .danger { color: var(--red); }

/* 头像印章：阵营配色 */
.av { flex: none; width: 36px; height: 36px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-family: "STKaiti", "KaiTi", "Kaiti SC", serif; font-size: 20px; font-weight: 700; background: var(--qun); box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.av[data-f="魏"] { background: var(--wei); }
.av[data-f="蜀"] { background: var(--shu); }
.av[data-f="吴"] { background: var(--wu); }
.av[data-f="群"] { background: var(--qun); }
.av.sm { width: 28px; height: 28px; border-radius: 50%; font-size: 15px; }
.av.lg { width: 46px; height: 46px; border-radius: 12px; font-size: 24px; }

.av[data-who] { cursor: pointer; }
.av[data-who]:hover { filter: brightness(1.08); }

/* 头像资料卡 */
.who-card { position: fixed; z-index: 35; width: 248px; background: #fff; border-radius: 14px; padding: 14px; box-shadow: 0 10px 32px rgba(0,0,0,.2); }
.wc-head { display: flex; gap: 12px; align-items: flex-start; }
.wc-head b { font-size: 17px; margin-right: 6px; }
.wc-head b em { font-style: normal; font-size: 11px; font-weight: 500; color: #fff; background: var(--felt); border-radius: 4px; padding: 0 4px; margin-left: 6px; vertical-align: 2px; }
.wc-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.wc-f { font-size: 11px; color: #fff; border-radius: 4px; padding: 1px 5px; background: var(--qun); vertical-align: 2px; }
.wc-f[data-f="魏"] { background: var(--wei); } .wc-f[data-f="蜀"] { background: var(--shu); } .wc-f[data-f="吴"] { background: var(--wu); }
.who-card dl { display: grid; grid-template-columns: 34px 1fr; gap: 4px 10px; margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.who-card dt { color: var(--muted); }
.who-card dd { margin: 0; }
.wc-gone { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.wc-act { margin-top: 10px; display: flex; justify-content: flex-end; }
.wc-act .btn { margin: 0; }

/* 手机：聊天 / 牌桌 切换 */
.ptabs { flex: none; display: flex; background: var(--felt-d); padding: 0 12px 8px; gap: 8px; }
.ptabs button { flex: 1; border: 0; border-radius: 8px; padding: 7px 0; background: rgba(255,255,255,.1); color: rgba(255,255,255,.75); }
.ptabs button.on { background: #fff; color: var(--felt-d); font-weight: 600; }

.main { flex: 1; min-height: 0; display: flex; }
.chat, .tables { flex: 1; min-width: 0; min-height: 0; }
.main[data-panel="chat"] .tables { display: none; }
.main[data-panel="tables"] .chat { display: none; }

/* 聊天 */
.chat { display: flex; flex-direction: column; background: var(--panel); }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 14px 16px; overscroll-behavior: contain; }
.window-tip { text-align: center; font-size: 12px; color: var(--muted); margin: 4px 0 10px; }
.more { display: block; margin: 4px auto; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 14px; font-size: 12px; color: var(--muted); }
.msg { display: flex; gap: 8px; margin: 10px 0; align-items: flex-start; }
.msg .mb { min-width: 0; max-width: 78%; }
.meta { font-size: 12px; color: var(--muted); margin: 0 2px 2px; }
.bubble { display: inline-block; background: #fff; border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; padding: 7px 11px; word-break: break-word; white-space: pre-wrap; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .mb { text-align: right; }
.msg.mine .bubble { background: var(--felt); border-color: var(--felt); color: #fff; border-radius: 12px 4px 12px 12px; text-align: left; }
.sys { text-align: center; margin: 8px 0; }
.sys span { display: inline-block; font-size: 12px; color: var(--muted); background: rgba(0,0,0,.04); border-radius: 999px; padding: 2px 10px; }
.chat-empty { text-align: center; color: var(--muted); padding: 48px 12px; }
.chat-input { flex: none; display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
.chat-input input { flex: 1; min-width: 0; font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--panel); }
.chat-input input:focus { outline: 2px solid var(--felt); outline-offset: -1px; }
.chat-input button { flex: none; border: 0; border-radius: 10px; padding: 0 18px; background: var(--felt); color: #fff; font-weight: 600; }

/* 快捷短语 */
.phrases { flex: none; display: flex; flex-wrap: wrap; gap: 8px; max-height: 40%; overflow-y: auto; padding: 10px 12px; background: #fff; border-top: 1px solid var(--line); }
.ph { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.ph:hover { border-color: var(--felt); color: var(--felt); }
.ph.hot { border-color: var(--red); color: var(--red); background: #fdf2f1; }
.chat-input .ph-btn { padding: 0 10px; background: var(--panel); color: var(--felt); border: 1px solid var(--line); font-weight: 500; font-size: 13px; white-space: nowrap; }
.chat-input .ph-btn i { font-style: normal; display: inline-block; margin-left: 2px; transition: transform .15s; }
.chat-input .ph-btn.on i { transform: rotate(180deg); }

/* 牌桌（紧凑，一列放下三张） */
.tables { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.tcard { flex: none; background: var(--card); border-radius: 12px; padding: 10px 12px 8px; box-shadow: 0 1px 3px rgba(0,0,0,.05); border: 2px solid transparent; }
.tcard.i-sit { border-color: var(--felt); }
.tcard header { display: flex; align-items: center; gap: 8px; }
.tcard h2 { margin: 0; font-size: 18px; letter-spacing: 1px; }
.tcard .sub { flex: 1; font-size: 12px; color: var(--muted); }
.tcard .leave { border: 1px solid var(--red); background: #fff; color: var(--red); border-radius: 999px; font-size: 12px; padding: 0 8px; }
.badge { font-size: 12px; padding: 1px 9px; border-radius: 999px; white-space: nowrap; }
.st-open .badge { background: var(--red); color: #fff; }
.st-full .badge { background: #e3efe8; color: var(--felt); }

.table { position: relative; width: 200px; height: 182px; margin: 2px auto 0; }
.felt { position: absolute; inset: 60px 62px; background: radial-gradient(circle at 50% 40%, #268557, var(--felt-d)); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: rgba(255,255,255,.9); box-shadow: inset 0 0 0 3px #0f3f2c; }
.felt b { font-size: 20px; line-height: 1; font-family: Georgia, serif; }
.felt span { font-size: 10px; opacity: .8; }
.seat { position: absolute; width: 60px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.seat .wind { font-size: 9px; color: var(--gold); line-height: 1.3; }
.seat small { font-size: 11px; color: var(--ink); max-width: 60px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
.seat.mine small { color: var(--felt); font-weight: 600; }
.seat .empty { width: 32px; height: 32px; border-radius: 9px; border: 2px dashed #c4c9c5; background: #fff; color: var(--felt); font-size: 12px; padding: 0; }
.seat .empty:hover { border-color: var(--felt); background: #eef6f1; }
.s0 { left: 50%; bottom: 0; transform: translateX(-50%); }
.s1 { right: -4px; top: 50%; transform: translateY(-50%); }
.s2 { left: 50%; top: 0; transform: translateX(-50%); }
.s3 { left: -4px; top: 50%; transform: translateY(-50%); }
.av.md { width: 32px; height: 32px; border-radius: 9px; font-size: 17px; }

/* 花名选择 */
.picker { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; }
.picker-bd { position: absolute; inset: 0; background: rgba(10,25,18,.55); }
.picker-pn { position: relative; width: min(560px, 100%); max-height: min(720px, 100%); display: flex; flex-direction: column; gap: 12px; background: #fff; border-radius: 18px; padding: 18px 16px 16px; }
.pk-loading { padding: 40px; text-align: center; color: var(--muted); }
.pk-head { display: flex; justify-content: space-between; gap: 12px; }
.pk-head h3 { margin: 0; font-size: 19px; }
.pk-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.pk-head .pk-note { color: var(--red); }
.pk-x { flex: none; border: 0; background: var(--bg); width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; color: var(--muted); }
.pk-tabs { display: flex; gap: 8px; }
.pk-tab { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 0; font-family: "STKaiti", "KaiTi", serif; font-size: 18px; font-weight: 700; color: var(--muted); }
.pk-tab small { font-family: sans-serif; font-size: 11px; font-weight: 400; margin-left: 4px; }
.pk-tab.on[data-f="魏"] { background: var(--wei); border-color: var(--wei); color: #fff; }
.pk-tab.on[data-f="蜀"] { background: var(--shu); border-color: var(--shu); color: #fff; }
.pk-tab.on[data-f="吴"] { background: var(--wu); border-color: var(--wu); color: #fff; }
.pk-tab.on[data-f="群"] { background: var(--qun); border-color: var(--qun); color: #fff; }
.pk-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; padding: 2px; }
.pk-hero { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 4px 8px; }
.pk-hero b { font-weight: 500; font-size: 14px; }
.pk-hero small { position: absolute; top: 3px; right: 4px; font-size: 10px; color: var(--muted); }
.pk-hero.on { border-color: var(--felt); background: #eef6f1; }
.pk-hero.mine small { color: var(--felt); }
.pk-hero.taken { cursor: not-allowed; opacity: .4; filter: grayscale(1); }

.btn { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 12px; padding: 10px 20px; background: var(--felt); color: #fff; font-weight: 600; }
.btn[disabled] { background: #c9cdca; cursor: not-allowed; }
.btn.big { width: 100%; padding: 13px; font-size: 16px; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.sm { padding: 5px 14px; font-size: 13px; margin-top: 10px; }

.toast { position: fixed; left: 50%; top: 30%; transform: translate(-50%, -50%); z-index: 50; background: rgba(0,0,0,.78); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; max-width: 80vw; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }

/* 宽屏：聊天为主，右侧一列牌桌 */
@media (min-width: 880px) {
  .ptabs { display: none; }
  .main { display: grid; grid-template-columns: 1fr 300px; }
  .main[data-panel] .chat { display: flex; border-right: 1px solid var(--line); }
  .main[data-panel] .tables { display: flex; }
  .chat-list { padding: 12px 24px 16px; }
  .msg .mb { max-width: 62%; }
  .chat-input { padding: 12px 24px; }
  .phrases { padding: 12px 24px; }
}
@media (max-width: 879px) {
  .picker { align-items: flex-end; }
  .picker-pn { border-radius: 18px 18px 0 0; max-height: 92%; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}
