:root {
  --bg: #17110e;
  --bg2: #241a14;
  --ink: #f5ead9;
  --muted: #b5a38c;
  --line: rgba(255, 226, 180, .12);
  --panel: rgba(255, 244, 225, .045);
  --gold: #d9a649;
  --gold2: #f0c36d;
  --red: #b8221b;
  --red-soft: #e0584c;
  --wood-line: #6b3f1d;
  --radius: 18px;
  --board-reserve: 210px; /* chiều cao dành cho thanh trên + 2 thanh người chơi */
  --board-max: 680px;
  --pad-x: clamp(14px, 3vw, 28px);
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --cjk: 'LXGW WenKai TC', 'Noto Serif CJK TC', 'Noto Serif TC', 'KaiTi', 'STKaiti', 'BiauKai', 'Songti TC', 'PMingLiU', serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; max-width: 100%; }
/* Lưới an toàn chống cuộn ngang (clip không phá position: sticky) */
html { overflow-x: hidden; overflow-x: clip; }
body { overflow-x: clip; }
/* iOS tự phóng to khi focus ô nhập có cỡ chữ < 16px – luôn để >= 16px */
input, textarea, select { font-size: 16px; }
body {
  font-family: var(--font); color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
.bg-deco {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(217, 166, 73, .16), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(184, 34, 27, .18), transparent 60%),
    linear-gradient(180deg, var(--bg2), var(--bg));
}
.bg-deco::after { /* hoa văn chìm */
  content: ''; position: absolute; inset: 0; opacity: .05;
  background-image: radial-gradient(circle at 1px 1px, #f0c36d 1px, transparent 1.4px);
  background-size: 22px 22px;
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }

/* ---------- Thanh trên ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px var(--pad-x); max-width: 1320px; margin: 0 auto;
  padding-left: max(var(--pad-x), env(safe-area-inset-left)); padding-right: max(var(--pad-x), env(safe-area-inset-right));
  padding-top: max(12px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--cjk); font-weight: 700; font-size: 21px; color: var(--red);
  background: radial-gradient(circle at 35% 30%, #fff8e8, #f1dcb0 60%, #d4a865);
  box-shadow: 0 2px 0 #9b6a36, 0 4px 10px rgba(0, 0, 0, .4), inset 0 0 0 3px #f6e6c4, inset 0 0 0 4.5px var(--red);
}
.brand-text { font-weight: 800; font-size: 19px; letter-spacing: .2px; line-height: 1; }
.brand-text small { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: 3px; text-transform: uppercase; color: var(--gold); margin-top: 3px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); padding: 6px 12px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: #e0a03a; animation: pulse 1.2s infinite; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  display: inline-grid; place-items: center; transition: .15s; flex: none;
}
.icon-btn:hover { background: rgba(255, 244, 225, .1); }
.icon-btn.solid { background: var(--gold); color: #2a1a0c; border: none; }
.icon-btn svg, .btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 11px 16px;
  font-weight: 600; font-size: 14.5px; transition: transform .12s, background .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { background: rgba(255, 244, 225, .1); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #2a1a0c; border: none;
  box-shadow: 0 6px 18px rgba(217, 166, 73, .28), inset 0 1px 0 rgba(255, 255, 255, .45);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: #ffb4ab; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Sảnh ---------- */
.view { max-width: 1320px; margin: 0 auto; padding: 8px var(--pad-x) 40px; min-width: 0;
  padding-left: max(var(--pad-x), env(safe-area-inset-left)); padding-right: max(var(--pad-x), env(safe-area-inset-right));
  padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.hero { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 30px; align-items: center; padding: 26px 0 30px; }
.hero h1 { font-size: clamp(36px, 6vw, 62px); line-height: 1.05; margin: 0 0 14px; font-weight: 800; letter-spacing: -1px; }
.hero h1 span { background: linear-gradient(90deg, var(--gold2), #e3793a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); font-size: 17px; line-height: 1.6; max-width: 520px; margin: 0 0 22px; }
/* Tài khoản */
.account { max-width: 520px; margin: 0 0 18px; }
.acc-guest { display: flex; flex-direction: column; gap: 10px; }
.acc-status { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); }
.acc-status i { width: 8px; height: 8px; border-radius: 50%; background: #8a7a66; box-shadow: 0 0 0 3px rgba(138, 122, 102, .2); }
.acc-btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 228px), 1fr)); gap: 10px; }
.acc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  font-weight: 600; font-size: 15px; text-decoration: none; white-space: nowrap; transition: transform .12s, filter .15s;
}
.acc-btn:hover { filter: brightness(1.06); } .acc-btn:active { transform: scale(.98); }
.acc-btn svg { width: 20px; height: 20px; flex: none; }
.acc-btn.google { background: #fff; color: #1f1f1f; border: 1px solid #dadce0; }
.acc-btn.facebook { background: #1877F2; color: #fff; border: 1px solid #1877F2; }
.acc-user { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); }
.acc-avatar { position: relative; flex: none; width: 46px; height: 46px; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #2a1a0c; font-weight: 800; font-size: 19px; box-shadow: 0 0 0 2px rgba(217, 166, 73, .5); }
.acc-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.acc-avatar i { font-style: normal; }
.acc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.acc-info b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-stats { font-size: 13px; color: var(--muted); }
.acc-stats em { font-style: normal; font-weight: 700; color: var(--ink); }
.acc-out { flex: none; padding: 9px 13px; font-size: 14px; }
.name-field { display: flex; flex-direction: column; gap: 7px; max-width: 360px; }
.name-field span, .field > span { font-size: 12.5px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
input#nameInput, .join-form input, .chat-form input, .modal input {
  width: 100%; padding: 13px 15px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, .25); color: var(--ink); outline: none; font-size: 16px; transition: border .15s, box-shadow .15s;
}
input:focus { border-color: var(--gold) !important; box-shadow: 0 0 0 3px rgba(217, 166, 73, .18); }
.hero-pieces { position: relative; height: 260px; }
.hp {
  position: absolute; width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--cjk); font-weight: 700; font-size: 56px;
  background: radial-gradient(circle at 35% 30%, #fffaf0, #f2ddb2 55%, #d6ad6c);
  box-shadow: 0 5px 0 #9b6a36, 0 18px 30px rgba(0, 0, 0, .45), inset 0 0 0 6px #f6e6c4, inset 0 0 0 8px currentColor;
  animation: float 6s ease-in-out infinite;
}
.hp.r { color: var(--red); } .hp.b { color: #222; }
.hp:nth-child(1) { left: 8%; top: 18%; transform: rotate(-8deg); }
.hp:nth-child(2) { left: 42%; top: 2%; width: 124px; height: 124px; font-size: 68px; animation-delay: -1.5s; }
.hp:nth-child(3) { left: 70%; top: 34%; width: 88px; height: 88px; font-size: 46px; animation-delay: -3s; }
.hp:nth-child(4) { left: 30%; top: 56%; width: 92px; height: 92px; font-size: 48px; animation-delay: -4s; }
.hp:nth-child(5) { left: 58%; top: 70%; width: 76px; height: 76px; font-size: 40px; animation-delay: -2.2s; }
@keyframes float { 50% { translate: 0 -10px; } }

.resume {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 14px 18px; margin-bottom: 18px; border-radius: var(--radius);
  background: linear-gradient(90deg, rgba(217, 166, 73, .16), rgba(217, 166, 73, .04)); border: 1px solid rgba(217, 166, 73, .35);
}
.resume b { color: var(--gold2); }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 22px;
  display: flex; flex-direction: column; gap: 14px; backdrop-filter: blur(6px);
}
.card h2 { margin: 0; font-size: 21px; }
.card p { margin: -6px 0 0; color: var(--muted); font-size: 14.5px; line-height: 1.55; }
.card .btn.block { margin-top: auto; padding: 14px; font-size: 15.5px; }
.card-icon {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-family: var(--cjk); font-weight: 700; font-size: 28px;
  background: radial-gradient(circle at 35% 30%, #fffaf0, #f2ddb2 55%, #d6ad6c);
  box-shadow: 0 3px 0 #9b6a36, 0 8px 16px rgba(0, 0, 0, .35), inset 0 0 0 3px #f6e6c4, inset 0 0 0 4.5px currentColor;
}
.card-icon.r { color: var(--red); } .card-icon.b { color: #222; }
.field { display: flex; flex-direction: column; gap: 8px; }
.seg { display: flex; padding: 4px; gap: 4px; border-radius: 12px; background: rgba(0, 0, 0, .28); border: 1px solid var(--line); }
.seg button { flex: 1; min-width: 0; border: none; background: none; padding: 9px 6px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); transition: .15s; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: rgba(255, 244, 225, .12); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(217, 166, 73, .5); }
.seg.levels button { font-size: 12.5px; padding: 9px 2px; }
.join-form { display: flex; gap: 8px; }
.join-form input, .chat-form input { min-width: 0; }
.join-form input { text-transform: uppercase; letter-spacing: 4px; font-weight: 700; text-align: center; font-size: 18px; }
/* Chữ gợi ý mã phòng mờ: darkgray #a9a9a9 (mặc định Safari/iOS) alpha .4 (= .5 × 0.8).
   opacity:1 để Firefox không nhân thêm .54; -webkit-text-fill-color để iOS không lấy màu chữ nhập. */
.join-form input::placeholder { color: rgba(169, 169, 169, .4); -webkit-text-fill-color: rgba(169, 169, 169, .4); opacity: 1; }
.join-form input::-webkit-input-placeholder { color: rgba(169, 169, 169, .4); -webkit-text-fill-color: rgba(169, 169, 169, .4); opacity: 1; }
.howto { display: grid; gap: 10px; margin-top: auto; padding-top: 6px; }
.howto div { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14.5px; }
.howto b { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: rgba(217, 166, 73, .15); color: var(--gold2); font-size: 13px; }
.foot { text-align: center; color: #7f6f5c; font-size: 13px; margin-top: 34px; line-height: 1.6; }

/* ---------- Ván cờ ---------- */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 26px; align-items: start; }
.game > *, .board-col, .side, .panel { min-width: 0; }
.board-col { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
/* Kích thước bàn cờ = min(bề ngang khả dụng, chiều cao khả dụng × 0.9) – svh = chiều cao nhỏ nhất (khi thanh công cụ Safari hiện) */
.board-wrap, .player-bar {
  width: 100%; max-width: var(--board-max);
  width: min(100%, calc((100vh - var(--board-reserve)) * .9), var(--board-max));
  width: min(100%, calc((100svh - var(--board-reserve)) * .9), var(--board-max));
}
.board-wrap { flex: none; }
.player-bar {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 8px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line); transition: box-shadow .25s, border-color .25s;
}
.player-bar.active { border-color: rgba(217, 166, 73, .6); box-shadow: 0 0 0 3px rgba(217, 166, 73, .12); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-family: var(--cjk); font-weight: 700; font-size: 22px;
  background: radial-gradient(circle at 35% 30%, #fffaf0, #f2ddb2 55%, #d6ad6c);
  box-shadow: 0 2px 0 #9b6a36, inset 0 0 0 2.5px #f6e6c4, inset 0 0 0 4px currentColor;
}
.avatar.r { color: var(--red); } .avatar.b { color: #222; }
.pinfo { flex: 1; min-width: 0; }
.pname { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px; }
.pname .dot { width: 8px; height: 8px; border-radius: 50%; background: #6b6b6b; flex: none; }
.pname .dot.on { background: #4cc46b; box-shadow: 0 0 8px #4cc46b; }
.psub { font-size: 12.5px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; align-items: center; min-height: 18px; }
.captured { font-family: var(--cjk); font-size: 14px; letter-spacing: 1px; }
.captured .r { color: var(--red-soft); } .captured .b { color: #d8cdbd; }
.clock {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; padding: 7px 12px; border-radius: 10px;
  background: rgba(0, 0, 0, .3); min-width: 82px; text-align: center; color: var(--muted); transition: .2s;
}
.player-bar.active .clock { background: var(--ink); color: #1d140e; }
.clock.low { color: #fff !important; background: #c0392b !important; animation: pulse 1s infinite; }
.sit-btn { padding: 7px 12px; font-size: 13px; }

/* Bàn cờ */
.board {
  position: relative; width: 100%; aspect-ratio: 960 / 1060; border-radius: 14px; container-type: inline-size;
  background:
    repeating-linear-gradient(91deg, rgba(110, 60, 15, .055) 0 2px, transparent 2px 7px, rgba(110, 60, 15, .03) 7px 8px, transparent 8px 15px),
    repeating-linear-gradient(89.3deg, rgba(255, 255, 255, .05) 0 1px, transparent 1px 23px),
    radial-gradient(ellipse 120% 80% at 30% 15%, #f6d9a2, #e7bb73 50%, #d29d55);
  box-shadow:
    inset 0 0 0 .8cqw #8a5426, inset 0 0 0 1.15cqw #c58b4a, inset 0 0 30px rgba(90, 45, 10, .35),
    0 2px 0 #5c3415, 0 30px 60px -10px rgba(0, 0, 0, .65), 0 10px 20px rgba(0, 0, 0, .3);
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.grid { position: absolute; inset: 0; width: 100%; height: 100%; }
.grid .l { stroke: var(--wood-line); stroke-width: 2.4; fill: none; vector-effect: non-scaling-stroke; }
.grid .frame { stroke: var(--wood-line); stroke-width: 3.4; fill: none; vector-effect: non-scaling-stroke; }
.grid .river { font-family: var(--cjk); font-weight: 700; fill: rgba(107, 63, 29, .82); font-size: 56px; }
.grid .river-vn { font-family: var(--font); font-weight: 600; fill: rgba(107, 63, 29, .62); font-size: 15px; letter-spacing: 4px; text-transform: uppercase; }
.grid .num { font-family: var(--font); font-weight: 600; fill: rgba(107, 63, 29, .55); font-size: 18px; }
.layer { position: absolute; inset: 0; }
.hints, .marks { pointer-events: none; }

.piece {
  position: absolute; width: 9.9%; aspect-ratio: 1; border-radius: 50%; translate: -50% -50%;
  display: grid; place-items: center; font-family: var(--cjk); font-weight: 700; font-size: 6cqw; line-height: 1;
  background: radial-gradient(circle at 36% 30%, #fffaf0 0%, #f4e2bb 45%, #dfba7c 85%, #c99d5c 100%);
  box-shadow: 0 .45cqw 0 #94622f, 0 .9cqw 1.4cqw rgba(40, 20, 5, .45), inset 0 -.3cqw .6cqw rgba(120, 70, 20, .25);
  transition: left .28s cubic-bezier(.3, .7, .3, 1), top .28s cubic-bezier(.3, .7, .3, 1), transform .15s, box-shadow .15s, opacity .25s;
  cursor: default; will-change: left, top; z-index: 2;
}
.piece::before { content: ''; position: absolute; inset: 8%; border-radius: 50%; border: .32cqw solid currentColor; opacity: .85; }
.piece::after { content: ''; position: absolute; inset: 13%; border-radius: 50%; border: .12cqw solid currentColor; opacity: .35; }
.piece.r { color: var(--red); }
.piece.b { color: #1e1e1e; }
.piece span { position: relative; top: -.15cqw; text-shadow: 0 1px 0 rgba(255, 255, 255, .55); }
.piece.mine { cursor: pointer; }
.piece.mine:hover { transform: translateY(-.35cqw); }
.piece.sel { transform: translateY(-.7cqw) scale(1.06); z-index: 5; box-shadow: 0 1.1cqw 0 #94622f, 0 2.2cqw 2.6cqw rgba(40, 20, 5, .45), 0 0 0 .55cqw rgba(255, 210, 90, .9); }
.piece.drag { transition: none; z-index: 10; transform: scale(1.12); }
.piece.last { box-shadow: 0 .45cqw 0 #94622f, 0 .9cqw 1.4cqw rgba(40, 20, 5, .45), 0 0 0 .5cqw rgba(66, 160, 255, .75); }
.piece.checked { animation: checkPulse 1s ease-in-out infinite; }
.piece.captured-out { opacity: 0; transform: scale(.6); }
.piece.enter { animation: pop .3s ease-out; }
@keyframes checkPulse { 0%, 100% { box-shadow: 0 .45cqw 0 #94622f, 0 0 0 .5cqw rgba(230, 40, 30, .95), 0 0 2.5cqw rgba(255, 40, 30, .8); } 50% { box-shadow: 0 .45cqw 0 #94622f, 0 0 0 .9cqw rgba(230, 40, 30, .6), 0 0 4cqw rgba(255, 40, 30, .5); } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.mark-from {
  position: absolute; width: 8.4%; aspect-ratio: 1; translate: -50% -50%; border-radius: 50%;
  border: .45cqw dashed rgba(40, 110, 200, .7); background: rgba(66, 160, 255, .12);
}
.hint {
  position: absolute; width: 3%; aspect-ratio: 1; translate: -50% -50%; border-radius: 50%;
  background: rgba(30, 110, 50, .75); box-shadow: 0 0 0 .5cqw rgba(255, 255, 255, .35); animation: dotIn .18s ease-out;
}
.hint.cap { width: 11.1%; background: none; box-shadow: inset 0 0 0 .6cqw rgba(200, 40, 30, .85); z-index: 3; }
@keyframes dotIn { from { transform: scale(0); } }
.board-flash {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; pointer-events: none; z-index: 20;
  font-weight: 800; font-size: 7cqw; color: #fff; padding: 1.6cqw 5cqw; border-radius: 99px; white-space: nowrap;
  background: rgba(184, 34, 27, .92); box-shadow: 0 10px 30px rgba(120, 10, 0, .5); opacity: 0; transform: scale(.7);
}
.board-flash.show { animation: flash 1.3s ease forwards; }
@keyframes flash { 15% { opacity: 1; transform: scale(1.05); } 25% { transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: scale(1); } }

/* Bảng bên */
.side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.room-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.room-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 600; }
.room-code { font-size: 26px; font-weight: 800; letter-spacing: 5px; color: var(--gold2); }
.room-meta { font-size: 13px; color: var(--muted); margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; }
.share-row { display: flex; gap: 8px; margin-top: 12px; }
.share-row .link { flex: 1 1 0; width: 0; min-width: 0; font-size: 13px; padding: 10px 12px; border-radius: 10px; background: rgba(0, 0, 0, .28); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid var(--line); }
.status { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 10px; min-height: 26px; }
.status .turn-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 0 3px rgba(255, 255, 255, .1); }
.turn-dot.r { background: var(--red-soft); } .turn-dot.b { background: #111; border: 1px solid #777; }
.status.check { color: #ff8a7a; }
.status .thinking { display: inline-flex; gap: 3px; }
.status .thinking i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: blink 1s infinite; }
.status .thinking i:nth-child(2) { animation-delay: .2s; } .status .thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }
.offer { margin-top: 12px; padding: 12px; border-radius: 12px; background: rgba(217, 166, 73, .12); border: 1px solid rgba(217, 166, 73, .4); font-size: 14.5px; }
.offer .row { display: flex; gap: 8px; margin-top: 10px; }
.offer .btn { flex: 1; padding: 9px; }
.controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.controls .btn { padding: 10px 8px; font-size: 13.5px; min-width: 0; white-space: normal; text-align: center; line-height: 1.2; }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(0, 0, 0, .25); margin-bottom: 12px; }
.tab { flex: 1; border: none; background: none; padding: 9px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); position: relative; }
.tab.on { background: rgba(255, 244, 225, .1); color: var(--ink); }
.badge {
  display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin-left: 7px; vertical-align: 1px;
  border-radius: 99px; background: #e5483b; color: #fff; font: 800 11px/1 var(--font); font-style: normal;
  box-shadow: 0 0 0 2px rgba(20, 12, 8, .55); animation: badgePop .3s ease-out;
}
@keyframes badgePop { from { transform: scale(.4); } 60% { transform: scale(1.15); } }

/* Thông báo tin nhắn mới (nổi trên mép trên bàn cờ) */
.chat-toast {
  position: fixed; z-index: 70; left: 50%; translate: -50% 0;
  top: max(calc(env(safe-area-inset-top) + 8px), var(--toast-top, 0px));
  width: min(420px, calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  display: flex; align-items: stretch; border-radius: 16px; overflow: hidden;
  background: rgba(36, 26, 20, .94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(217, 166, 73, .45); box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
  opacity: 0; transform: translateY(-14px) scale(.98); transition: opacity .22s, transform .22s cubic-bezier(.2, .8, .3, 1.2);
}
.chat-toast.in { opacity: 1; transform: none; }
.chat-toast.out { opacity: 0; transform: translateY(-10px); transition-duration: .2s; }
.ct-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 11px; padding: 10px 6px 10px 11px; border: none; background: none; text-align: left; }
.ct-main .avatar { width: 34px; height: 34px; font-size: 18px; }
.avatar.spec { color: #5b4a3a; }
.ct-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ct-text b { font-size: 13px; color: var(--gold2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-text span { font-size: 14.5px; color: var(--ink); line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.ct-count { flex: none; font-size: 12px; font-weight: 800; color: #fff; background: #e5483b; border-radius: 99px; padding: 3px 7px; }
.ct-close { flex: none; width: 40px; border: none; background: none; color: var(--muted); font-size: 22px; line-height: 1; }
.ct-close:hover { color: var(--ink); }

/* Nút chat nổi trên điện thoại */
.chat-fab {
  position: fixed; z-index: 40; width: 54px; height: 54px; border-radius: 50%; border: none; display: grid; place-items: center;
  right: calc(env(safe-area-inset-right) + 14px); bottom: calc(env(safe-area-inset-bottom) + 18px);
  background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #2a1a0c;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .45);
  opacity: 0; transform: scale(.6); pointer-events: none; transition: opacity .2s, transform .2s;
}
.chat-fab.show { opacity: 1; transform: none; pointer-events: auto; }
.chat-fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chat-fab .badge { position: absolute; top: -3px; right: -3px; margin: 0; }
@media (min-width: 1021px) { .chat-fab { display: none; } }
.moves { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; font-variant-numeric: tabular-nums; }
.moves li { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px; padding: 5px 6px; border-radius: 8px; font-size: 14.5px; }
.moves li:nth-child(odd) { background: rgba(255, 255, 255, .025); }
.moves .no { color: #7f6f5c; }
.moves .mv { font-weight: 600; padding: 1px 6px; border-radius: 6px; }
.moves .mv.r { color: #ff9d8f; } .moves .mv.b { color: #e9dfd0; }
.moves .mv.cur { background: rgba(217, 166, 73, .25); }
.moves .mv .chk { color: #ff7262; margin-left: 2px; }
.moves .empty { display: block; color: var(--muted); font-size: 14px; text-align: center; padding: 18px 0; }
.chat-list { height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }
.msg { font-size: 14px; line-height: 1.45; background: rgba(0, 0, 0, .2); padding: 7px 11px; border-radius: 12px; align-self: flex-start; max-width: 90%; word-wrap: break-word; }
.msg b { font-size: 12px; display: block; color: var(--gold2); }
.msg b.r { color: #ff9d8f; }
.msg.me { align-self: flex-end; background: rgba(217, 166, 73, .18); }
.msg.sys { align-self: center; background: none; color: var(--muted); font-size: 12.5px; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { padding: 10px 13px; font-size: 16px; }

/* Modal & toast */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(10, 6, 4, .6); backdrop-filter: blur(4px); animation: fade .2s; }
.modal-card { width: min(420px, 100%); background: linear-gradient(180deg, #2c211a, #1f1712); border: 1px solid rgba(217, 166, 73, .3); border-radius: 22px; padding: 26px; text-align: center; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); animation: rise .3s cubic-bezier(.2, .8, .3, 1.2); }
.modal-card h3 { margin: 10px 0 6px; font-size: 26px; }
.modal-card p { color: var(--muted); margin: 0 0 20px; line-height: 1.5; }
.modal-card .row { display: flex; gap: 10px; }
.modal-card .row .btn { flex: 1; }
.modal-card .big-piece { margin: 0 auto; width: 84px; height: 84px; font-size: 46px; position: relative; translate: none; }
.modal-card input { margin-bottom: 14px; text-align: center; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(20px) scale(.96); opacity: 0; } }
.toasts { position: fixed; left: 50%; bottom: 22px; translate: -50% 0; z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #f5ead9; color: #22170f; padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: 14.5px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); animation: rise .25s; max-width: 90vw; text-align: center; }
.toast.err { background: #c0392b; color: #fff; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  :root { --board-max: 640px; --board-reserve: 190px; }
  .game { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .side { position: static; width: min(100%, 640px); margin: 0 auto; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards .card:last-child { grid-column: span 2; }
}
@media (max-width: 680px) {
  :root { --pad-x: 8px; --board-reserve: 184px; }
  .hero { grid-template-columns: minmax(0, 1fr); padding: 10px 0 20px; }
  .hero-pieces { display: none; }
  .hero p { font-size: 15.5px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .cards .card:last-child { grid-column: auto; }
  .side { width: 100%; }
  .game { gap: 12px; }
  .board-col { gap: 8px; }
  .player-bar { padding: 6px 8px 6px 6px; border-radius: 14px; }
  .avatar { width: 34px; height: 34px; font-size: 19px; }
  .clock { font-size: 17px; min-width: 70px; padding: 6px 9px; }
  .controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .controls .btn { font-size: 12.5px; padding: 9px 4px; flex-direction: column; gap: 3px; }
  .brand-text { font-size: 17px; }
  .topbar { padding: 8px 12px; }
}
/* Điện thoại xoay ngang: bàn cờ bên trái theo chiều cao, thông tin bên phải */
@media (orientation: landscape) and (max-height: 600px) {
  :root { --board-reserve: 74px; }
  .topbar { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; }
  .game {
    grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto 1fr;
    grid-template-areas: "board top" "board bottom" "board side"; gap: 8px 14px; align-items: start;
  }
  .board-col { display: contents; }
  .board-wrap {
    grid-area: board; max-width: none;
    width: min(58vw, calc((100vh - var(--board-reserve) - env(safe-area-inset-bottom)) * .9));
    width: min(58vw, calc((100svh - var(--board-reserve) - env(safe-area-inset-bottom)) * .9));
  }
  #barTop { grid-area: top; } #barBottom { grid-area: bottom; }
  .player-bar { width: 100%; max-width: none; }
  .side { grid-area: side; width: 100%; margin: 0; position: static; }
  .view { padding-top: 4px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Liên kết chân trang sảnh + trang pháp lý (bảo mật, điều khoản, xoá dữ liệu) ---------- */
.foot-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin-top: 8px; }
.foot-links a { color: var(--muted); text-decoration: none; padding: 6px 2px; }
.foot-links a:hover { color: var(--gold2); text-decoration: underline; }
a.btn { color: inherit; text-decoration: none; }
a.btn.primary { color: #2a1a0c; }
.legal-home { padding: 9px 14px; font-size: 14px; }
.legal { max-width: 820px; margin: 0 auto; padding: 8px var(--pad-x) 48px; min-width: 0;
  padding-left: max(var(--pad-x), env(safe-area-inset-left)); padding-right: max(var(--pad-x), env(safe-area-inset-right));
  padding-bottom: max(48px, env(safe-area-inset-bottom)); }
.legal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(18px, 4vw, 36px); overflow-wrap: anywhere; }
.legal h1 { font-size: clamp(28px, 5vw, 40px); line-height: 1.15; margin: 0 0 8px; font-weight: 800; letter-spacing: -.5px; }
.legal h2 { font-size: 19px; margin: 28px 0 8px; color: var(--gold2); }
.legal p, .legal li { color: #e6d8c3; font-size: 16px; line-height: 1.7; }
.legal ul, .legal ol { padding-left: 22px; margin: 8px 0; }
.legal li { margin: 4px 0; }
.legal b { color: var(--ink); }
.legal a { color: var(--gold2); }
.legal code { font-size: .9em; background: rgba(0, 0, 0, .3); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; word-break: break-all; }
.legal-meta { color: var(--muted) !important; font-size: 14px !important; margin: 0 0 18px; }
.legal-en { margin-top: 36px; padding-top: 8px; border-top: 1px solid var(--line); }
.legal-en h2:first-child { margin-top: 20px; }
.legal-box { margin: 14px 0; padding: 14px 16px; border-radius: 14px; background: rgba(217, 166, 73, .08); border: 1px solid rgba(217, 166, 73, .35); }
.legal-box p { margin: 0 0 12px; }
.legal-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin-top: 22px; font-size: 14px; }
.legal-nav a { color: var(--muted); text-decoration: none; padding: 8px 2px; }
.legal-nav a:hover, .legal-nav a[aria-current] { color: var(--gold2); }

/* ---------- Cờ úp ---------- */
/* Quân úp: mặt lưng gỗ sẫm, viền theo màu quân, hoa văn ô trám ở giữa */
.piece.hidden {
  background: radial-gradient(circle at 36% 30%, #e7c58c 0%, #c9955a 48%, #a8733d 85%, #8d5d2e 100%);
}
.piece.hidden .back {
  position: relative; top: 0; width: 58%; height: 58%; border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 240, 210, .55) 0 14%, transparent 15%),
    repeating-linear-gradient(45deg, rgba(90, 50, 18, .32) 0 1px, transparent 1px 22%),
    repeating-linear-gradient(-45deg, rgba(90, 50, 18, .32) 0 1px, transparent 1px 22%),
    radial-gradient(circle at 40% 35%, #d9ab6c, #b27c43);
  box-shadow: inset 0 0 0 .28cqw currentColor, inset 0 .3cqw .6cqw rgba(60, 30, 5, .35);
  opacity: .9;
}
.piece.hidden::before { opacity: .7; }
.piece.hidden::after { opacity: .2; }
.piece.flip { animation: flipIn .42s ease-out; }
@keyframes flipIn { 0% { transform: rotateY(90deg) scale(1.08); } 60% { transform: rotateY(-12deg) scale(1.04); } 100% { transform: none; } }
.modal-card .big-piece.hidden .back { width: 58%; height: 58%; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.help-link {
  border: none; background: none; padding: 4px 0; font: inherit; font-size: 13px; font-weight: 600;
  text-transform: none; letter-spacing: 0; color: var(--gold2); text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.room-meta .help-link { padding: 0; font-size: 13px; }
.variant-tag { color: var(--gold2); font-weight: 700; }
.variant-tag.std { color: var(--muted); font-weight: 600; }
.jq-rules { text-align: left; margin: 6px 0 14px; padding-left: 20px; display: grid; gap: 7px; font-size: 15px; line-height: 1.5; color: #e6d8c3; }
.jq-rules b { color: var(--ink); }
@media (prefers-reduced-motion: reduce) { .piece.flip { animation: none; } }
.modal-card { max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow-y: auto; overscroll-behavior: contain; }

/* ---------- Ủng hộ (Zelle) ---------- */
.donate-btn {
  height: 40px; padding: 0 13px 0 11px; border-radius: 12px; border: 1px solid rgba(224, 88, 76, .35);
  background: rgba(184, 34, 27, .14); color: #f6cfc3; display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 14px; flex: none; transition: background .15s; white-space: nowrap;
}
.donate-btn:hover { background: rgba(184, 34, 27, .26); }
.donate-btn svg, .foot-donate svg { fill: var(--red-soft); stroke: none; }
.donate-btn svg { width: 17px; height: 17px; }
@media (max-width: 359px) { .donate-btn { width: 40px; padding: 0; justify-content: center; } .donate-btn span { display: none; } }
@media (orientation: landscape) and (max-height: 600px) { .donate-btn { height: 36px; } }
.foot-donate { border: 0; background: none; color: var(--muted); padding: 6px 2px; font-size: inherit; display: inline-flex; align-items: center; gap: 5px; }
.foot-donate:hover { color: var(--gold2); text-decoration: underline; }
.foot-donate svg { width: 13px; height: 13px; }
/* Hộp Ủng hộ: chỉ mã QR Zelle (ảnh thường để nhấn giữ lưu được trên điện thoại) */
.modal[data-kind="donate"] { padding: 10px; }
.modal[data-kind="donate"] .modal-card { width: min(440px, 100%); padding: 18px 16px 16px; max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); }
.modal-card h3.donate-title { font-size: 22px; line-height: 1.25; margin: 2px 0 4px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.donate-ic { width: 22px; height: 22px; flex: none; fill: var(--red-soft); stroke: none; }
.modal-card .donate-lead { margin: 0 0 12px; font-size: 14.5px; }
.donate-lead span, .donate-how span, .donate-note span { display: block; font-size: 13px; opacity: .85; margin-top: 3px; }
.zelle-qr { margin: 0 auto 12px; padding: 10px; background: #fff; border-radius: 14px; display: flex; justify-content: center; box-shadow: 0 6px 18px rgba(0, 0, 0, .35); }
.zelle-qr img {
  display: block; width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 44px); max-height: calc(100dvh - 44px);
  background: #fff; image-rendering: auto; -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto;
}
.modal-card .zelle-to { margin: 0 0 10px; color: var(--ink); }
.zelle-to .k { display: block; font-size: 11.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--gold); }
.zelle-to b { font-size: 19px; letter-spacing: .6px; }
.modal-card .donate-how { margin: 0 0 10px; font-size: 15px; font-weight: 700; color: #f1e4cf; }
.modal-card .donate-how span { font-weight: 400; color: var(--muted); }
.modal-card .donate-save { font-size: 13px; margin: 0 0 12px; }
.donate-save a { color: var(--gold2); font-weight: 700; white-space: nowrap; }
.modal-card .donate-note { font-size: 13px; text-align: left; margin: 0 0 14px; padding: 10px 12px; border-radius: 12px; background: rgba(217, 166, 73, .1); border: 1px solid rgba(217, 166, 73, .22); color: #e6d8c3; }
@media (max-width: 360px) { .modal-card { padding: 22px 16px; } .modal[data-kind="donate"] { padding: 6px; } .modal[data-kind="donate"] .modal-card { padding: 14px 10px 12px; } .zelle-qr { padding: 8px; } }

/* ---------- Ghép trận tự động ---------- */
.quick {
  display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 430px); align-items: center; gap: 14px 20px;
  padding: 18px 20px; margin: 0 0 18px; border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(217, 166, 73, .14), rgba(184, 34, 27, .1)); border: 1px solid rgba(217, 166, 73, .32);
}
.quick-icon { margin: 0; }
.quick h2 { margin: 0; font-size: 20px; }
.quick p { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.quick-ctl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; align-items: center; min-width: 0; }
.quick-ctl .btn { padding: 12px 18px; }
.quick-note { grid-column: 1 / -1; font-size: 13.5px; color: var(--muted); min-height: 20px; }
.quick-note b { color: var(--gold2); }
.quick-note .help-link { font-size: 13.5px; padding: 0; }
.mm-wait { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 6px 4px; }
.mm-wait-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mm-wait-text b { font-size: 15.5px; }
.mm-wait-text span { font-size: 13px; color: var(--muted); }
.mm-time { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 19px; color: var(--gold2); padding-left: 6px; }
.spinner { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 3px solid rgba(217, 166, 73, .25); border-top-color: var(--gold2); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
@media (max-width: 1000px) { .quick { grid-template-columns: auto minmax(0, 1fr); } .quick-ctl { grid-column: 1 / -1; } }
@media (max-width: 480px) {
  .quick { padding: 16px 14px; gap: 12px 14px; }
  .quick h2 { font-size: 18px; }
  .quick-ctl { grid-template-columns: minmax(0, 1fr); }
  .quick-ctl .btn { width: 100%; }
}
.elo { color: var(--gold2); font-weight: 700; font-size: 12px; margin-left: 2px; font-variant-numeric: tabular-nums; }
.rated-tag { color: #9fe3a8; font-weight: 700; }
.acc-elo { font-size: 13px; color: var(--muted); }
.acc-elo em { font-style: normal; font-weight: 700; color: var(--gold2); }
.modal-card p.end-elo { margin: -10px 0 18px; color: #e6d8c3; font-size: 15px; }
.modal-card p.end-elo b { color: var(--gold2); }
.acc-elo > span { white-space: nowrap; }

/* ---------- Đang trực tuyến ---------- */
.live {
  display: flex; align-items: center; gap: 10px 20px; padding: 12px 16px; margin: 0 0 18px;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--line); transition: opacity .3s;
}
.live.stale { opacity: .55; }
.live-head { flex: none; display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #4cd17a; box-shadow: 0 0 0 0 rgba(76, 209, 122, .6); animation: livePulse 2s infinite; }
.live.stale .live-dot { background: #8a7a66; animation: none; }
@keyframes livePulse { 0% { box-shadow: 0 0 0 0 rgba(76, 209, 122, .55); } 70% { box-shadow: 0 0 0 8px rgba(76, 209, 122, 0); } 100% { box-shadow: 0 0 0 0 rgba(76, 209, 122, 0); } }
.live-stats { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, .8fr) minmax(0, 1.4fr) minmax(0, 1.4fr); gap: 8px; }
.live-stat { min-width: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 6px; padding: 6px 10px; border-radius: 12px; background: rgba(0, 0, 0, .18); }
.live-stat b { display: inline-block; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); }
.live-stat b.bump { animation: liveBump .5s; }
@keyframes liveBump { 30% { color: var(--gold2); transform: scale(1.15); } }
.live-stat span { font-size: 13px; color: var(--muted); }
.live-stat small { flex-basis: 100%; font-size: 11.5px; color: var(--gold); }
.live-stat small:empty { display: none; }
.live-var { min-width: 0; display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; padding: 6px 10px; border-radius: 12px; border: 1px solid; }
.live-var.std { background: rgba(184, 34, 27, .16); border-color: rgba(232, 96, 80, .45); }
.live-var.jq { background: rgba(70, 110, 230, .16); border-color: rgba(120, 160, 255, .5); }
.live-var-h { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 14px; white-space: nowrap; }
.live-var.std .live-var-h { color: #ffd2c4; } .live-var.jq .live-var-h { color: #d3dfff; }
.live-var-h i { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 12px; font-weight: 800; flex: none; }
.live-var.std .live-var-h i { background: #f1dcb0; color: var(--red); font-family: var(--cjk); }
.live-var.jq .live-var-h i { background: #2f4380; color: #dce6ff; box-shadow: inset 0 0 0 1.5px #8fa9ff; }
.live-var-n { display: flex; flex-wrap: wrap; gap: 0 10px; min-width: 0; }
.live-var-n span { font-size: 13px; color: var(--muted); white-space: nowrap; }
.live-var-n b { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); display: inline-block; }
.live-var-n b.bump { animation: liveBump .5s; }
@media (max-width: 760px) {
  .live { flex-direction: column; align-items: stretch; padding: 12px; }
  .live-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { .live-dot, .live-stat b.bump, .live-var-n b.bump { animation: none; } }

/* ---------- Nhãn kiểu cờ: Cờ tướng (đỏ) / Cờ úp (xanh) ---------- */
.vchip { display: inline-flex; align-items: center; padding: 1px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 800; line-height: 1.5; white-space: nowrap; border: 1px solid; }
.vchip.std { color: #ffd2c4; background: rgba(184, 34, 27, .22); border-color: rgba(232, 96, 80, .6); }
.vchip.jq { color: #d6e2ff; background: rgba(70, 110, 230, .24); border-color: rgba(120, 160, 255, .65); }
.room-meta .variant-tag.vchip { font-weight: 800; }
.resume .vchip { margin-right: 4px; vertical-align: 1px; }
.toast.has-v .vchip { margin-right: 8px; vertical-align: 1px; }
.vbadge {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px 0 5px; border-radius: 99px; border: 1.5px solid;
  min-width: 0; flex: none; margin: 0 10px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); animation: vbIn .35s cubic-bezier(.2, .8, .3, 1.2);
}
.vbadge[hidden] { display: none; }
.vbadge i { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-weight: 800; font-size: 15px; flex: none; }
.vbadge.std i { font-family: var(--cjk); }
.vbadge b { font-size: 15.5px; font-weight: 800; letter-spacing: .2px; }
.vbadge small { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; opacity: .8; padding-left: 7px; border-left: 1px solid currentColor; }
.vbadge.std { color: #ffd9cf; background: linear-gradient(180deg, rgba(196, 44, 34, .45), rgba(150, 26, 20, .35)); border-color: rgba(240, 110, 92, .75); }
.vbadge.std i { background: radial-gradient(circle at 35% 30%, #fff8e8, #f1dcb0 60%, #d4a865); color: var(--red); box-shadow: inset 0 0 0 1.5px var(--red); }
.vbadge.jq { color: #dde7ff; background: linear-gradient(180deg, rgba(76, 118, 240, .45), rgba(44, 72, 170, .38)); border-color: rgba(140, 175, 255, .8); }
.vbadge.jq i { background: radial-gradient(circle at 35% 30%, #4d66b8, #2a3c78); color: #e6edff; box-shadow: inset 0 0 0 1.5px #9bb4ff; }
@keyframes vbIn { from { opacity: 0; transform: scale(.85); } }
@media (max-width: 560px) {
  body.vb-on .brand-text { display: none; }
  .vbadge { height: 34px; margin: 0 6px; }
  body.vb-on .conn span { display: none; }
  body.vb-on .conn { padding: 6px 8px; }
}
@media (max-width: 420px) { .vbadge small { display: none; } .vbadge { padding-right: 11px; } }
@media (orientation: landscape) and (max-height: 600px) { .vbadge { height: 32px; } .vbadge i { width: 24px; height: 24px; font-size: 14px; } }
.toast.has-v .vchip { color: #fff; border-color: transparent; }
.toast.has-v .vchip.std { background: #b8221b; }
.toast.has-v .vchip.jq { background: #3b5fd0; }

/* ---------- Thẻ "Thông tin người chơi" ---------- */
button.avatar.pbtn { border: 0; padding: 0; cursor: pointer; color: inherit; transition: transform .12s, filter .15s; }
button.avatar.pbtn.r { color: var(--red); } button.avatar.pbtn.b { color: #2b2018; }
button.avatar.pbtn:hover { filter: brightness(1.06); } button.avatar.pbtn:active { transform: scale(.94); }
button.avatar.pbtn:focus-visible, button.acc-avatar:focus-visible { outline: 2px solid var(--gold2); outline-offset: 2px; }
button.acc-avatar { border: 0; padding: 0; cursor: pointer; font-family: inherit; }
.acc-user { flex-wrap: wrap; }
.acc-acts { display: flex; gap: 8px; flex: none; align-items: center; }
.acc-inbox { padding: 9px 12px; font-size: 14px; gap: 6px; position: relative; }
.acc-inbox svg { width: 17px; height: 17px; }
.acc-inbox .badge { margin-left: 2px; }
@media (max-width: 520px) { .acc-acts { flex-basis: 100%; } .acc-acts .btn { flex: 1; justify-content: center; } }
.inbox-btn { position: relative; }
.inbox-btn .badge { position: absolute; top: -5px; right: -6px; margin: 0; }
.toast.clickable, .toast.dm-toast { pointer-events: auto; cursor: pointer; }
.toast.dm-toast { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; font: inherit; font-weight: 600; font-size: 14.5px; max-width: min(92vw, 420px); }
.toast.dm-toast svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }
.toast.dm-toast span { min-width: 0; overflow-wrap: anywhere; }
.toast.dm-toast b { display: block; font-size: 12.5px; color: #8a5a1c; }

.modal[data-kind="player"] .modal-card { width: min(400px, 100%); padding: 22px 18px 18px; }
.pcard { display: flex; flex-direction: column; align-items: center; text-align: center; }
.pc-av, .dm-av { position: relative; flex: none; border-radius: 50%; overflow: hidden; display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #2a1a0c; box-shadow: 0 0 0 3px rgba(217, 166, 73, .45); }
.pc-av { width: 76px; height: 76px; font-size: 32px; }
.pc-av img, .dm-av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pc-av i, .dm-av i { font-style: normal; }
.pc-av.ai { font-family: var(--cjk); background: radial-gradient(circle at 35% 30%, #fffaf0, #f2ddb2 55%, #d6ad6c); color: #2b2018; }
.modal-card h3.pc-name { margin: 12px 0 4px; font-size: 22px; overflow-wrap: anywhere; }
.pc-name small { font-size: 14px; color: var(--gold2); font-weight: 600; }
.pc-kind { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--muted); margin-bottom: 14px; }
.pc-prov { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: #fff; flex: none; }
.pc-prov svg { width: 14px; height: 14px; }
.pc-prov.facebook { background: #1877F2; color: #fff; }
.pc-guest { padding: 3px 12px; border-radius: 99px; background: rgba(255, 244, 225, .08); border: 1px solid var(--line); color: var(--ink); font-weight: 700; }
.pc-loading { color: var(--muted); font-size: 14px; margin: 6px 0 16px; }
.pc-loading.err { color: #f0a090; }
.pc-elo { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; margin-bottom: 8px; }
.pc-v { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 6px; border-radius: 14px; border: 1px solid; min-width: 0; }
.pc-v.std { background: rgba(184, 34, 27, .14); border-color: rgba(232, 96, 80, .4); }
.pc-v.jq { background: rgba(70, 110, 230, .14); border-color: rgba(120, 160, 255, .45); }
.pc-v b { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.pc-v small { font-size: 11.5px; color: var(--muted); }
.pc-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; margin-bottom: 8px; }
.pc-stats div { padding: 8px 4px; border-radius: 12px; background: rgba(0, 0, 0, .2); display: flex; flex-direction: column; gap: 1px; }
.pc-stats b { font-size: 19px; font-variant-numeric: tabular-nums; }
.pc-stats span { font-size: 12px; color: var(--muted); }
.pc-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; font-size: 13px; color: var(--muted); margin: 4px 0 14px; }
.pc-meta b { color: var(--ink); }
.pc-actions { display: flex; gap: 8px; width: 100%; margin-bottom: 10px; }
.pc-actions .btn { flex: 1; justify-content: center; gap: 7px; }
.pc-actions .btn:first-child:last-child { flex: 1; }
.modal-card .pc-note { font-size: 13.5px; margin: 0 0 14px; }
.pcard .row { width: 100%; }

/* ---------- Tin nhắn riêng ---------- */
.modal[data-kind="inbox"] .modal-card, .modal[data-kind="thread"] .modal-card { width: min(460px, 100%); padding: 0; text-align: left; display: flex; flex-direction: column; overflow: hidden; }
.modal[data-kind="thread"] .modal-card { height: min(640px, calc(100vh - 40px)); height: min(640px, calc(100dvh - 40px)); }
.modal[data-kind="inbox"] .modal-card { max-height: min(640px, calc(100dvh - 40px)); }
@media (max-width: 520px) {
  .modal[data-kind="inbox"], .modal[data-kind="thread"] { padding: 8px; }
  .modal[data-kind="thread"] .modal-card { height: calc(100vh - 16px); height: calc(100dvh - 16px); }
  .modal[data-kind="inbox"] .modal-card { max-height: calc(100dvh - 16px); }
}
.dm { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.dm-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--line); flex: none; }
.dm-head h3 { margin: 0; flex: 1; font-size: 20px; }
.dm.thread .dm-head { padding-left: 10px; }
.dm-head .icon-btn { font-size: 20px; line-height: 1; color: var(--ink); }
.dm-peer { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; border: 0; background: none; color: inherit; padding: 2px; text-align: left; cursor: pointer; font: inherit; }
.dm-peer b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-av { width: 40px; height: 40px; font-size: 17px; box-shadow: 0 0 0 2px rgba(217, 166, 73, .4); }
.dm-blockbtn { flex: none; padding: 7px 11px; font-size: 13px; }
.dm-convs { overflow-y: auto; overscroll-behavior: contain; padding: 6px; min-height: 120px; }
.dm-conv { display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px; border: 0; border-radius: 14px; background: none; color: inherit; text-align: left; cursor: pointer; font: inherit; }
.dm-conv:hover { background: rgba(255, 244, 225, .06); }
.dm-cmain { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dm-cname { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.dm-cname b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.dm-cname time { margin-left: auto; font-size: 12px; color: var(--muted); flex: none; }
.dm-blk { font-style: normal; font-size: 11px; padding: 0 6px; border-radius: 99px; background: rgba(229, 72, 59, .2); color: #f3a59a; flex: none; }
.dm-snip { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-conv.unread .dm-snip { color: var(--ink); font-weight: 600; }
.dm-unread { font-style: normal; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: #e5483b; color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center; flex: none; }
.dm-empty { padding: 28px 18px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.6; }
.dm-empty.err { color: #f0a090; }
.dm-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.dm-msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 82%; }
.dm-msg.me { align-self: flex-end; align-items: flex-end; }
.dm-bubble { padding: 8px 12px; border-radius: 16px 16px 16px 5px; background: rgba(255, 244, 225, .1); color: var(--ink); font-size: 15px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.dm-msg.me .dm-bubble { border-radius: 16px 16px 5px 16px; background: linear-gradient(180deg, #e2ae55, #c98f34); color: #24160a; }
.dm-msg time { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.dm-form { flex: none; border-top: 1px solid var(--line); padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.dm-inrow { display: flex; gap: 8px; align-items: flex-end; }
.dm-form textarea { flex: 1; min-width: 0; resize: none; max-height: 120px; padding: 10px 13px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0, 0, 0, .25); color: var(--ink); font: 16px/1.35 var(--font); outline: none; }
.dm-form textarea:focus { border-color: rgba(217, 166, 73, .6); }
.dm-form textarea:disabled { opacity: .5; }
.dm-form .icon-btn { width: 44px; height: 44px; }
.dm-count { font-size: 11.5px; color: var(--muted); text-align: right; margin-top: 3px; }
.dm-err, .dm-blocked { font-size: 13px; padding: 7px 10px; border-radius: 10px; margin-bottom: 8px; }
.dm-err { background: rgba(229, 72, 59, .16); color: #f6b2a8; }
.dm-blocked { background: rgba(217, 166, 73, .12); color: #ead7b4; }
@media (max-width: 560px) { body.vb-on .donate-btn { width: 40px; padding: 0; justify-content: center; } body.vb-on .donate-btn span { display: none; } }
@media (max-width: 359px) { body.vb-on .inbox-btn { display: none; } }

/* ---------- Nút ngôn ngữ VI / EN + thanh trên khi chật (chuỗi tiếng Anh dài hơn, thêm một nút) ---------- */
.lang-btn { font-family: inherit; font-size: 13px; font-weight: 800; letter-spacing: .6px; color: var(--ink); cursor: pointer; }
.lang-btn span { line-height: 1; }
@media (max-width: 420px) { .topbar-actions { gap: 8px; } }
@media (max-width: 400px) { body.acc-on:not(.vb-on) .brand-text { display: none; } }
@media (max-width: 700px) {
  body.vb-on .brand-text { display: none; }
  body.vb-on .donate-btn { width: 40px; padding: 0; justify-content: center; }
  body.vb-on .donate-btn span { display: none; }
  body.vb-on .conn span { display: none; }
  body.vb-on .conn { padding: 6px 8px; }
}
@media (max-width: 560px) { .vbadge small { display: none; } .vbadge { padding-right: 11px; } body.vb-on .topbar-actions { gap: 8px; } }
@media (max-width: 420px) {
  body.vb-on .brand { display: none; }
  body.vb-on .vbadge { margin-left: 0; }
  body.vb-on .topbar-actions .icon-btn, body.vb-on .topbar-actions .donate-btn { width: 36px; height: 36px; }
}
/* chữ tiếng Anh dài hơn: nút / ô chọn được xuống dòng thay vì tràn */
.seg button { overflow-wrap: break-word; line-height: 1.2; }
.controls .btn span { overflow-wrap: break-word; text-align: center; }
.moves-legend { margin: 8px 2px 0; font-size: 11.5px; line-height: 1.45; color: var(--muted); opacity: .85; }
/* mức độ máy bằng tiếng Anh ("Beginner", "Medium"…) dài hơn: nút co theo chữ, chữ nhỏ hơn ở màn hẹp — không bẻ đôi từ */
html[lang="en"] .seg.levels button { flex: 1 1 auto; padding-left: 3px; padding-right: 3px; }
@media (max-width: 380px) { html[lang="en"] .seg.levels button { font-size: 11.5px; padding-left: 2px; padding-right: 2px; } html[lang="en"] .seg.levels { gap: 2px; } }
/* Chia sẻ: Zalo / Messenger / Facebook / Khác / Sao chép (khung phòng + hộp "Chia sẻ web") */
.share-btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(54px, 1fr)); gap: 6px; margin-top: 10px; }
.sh-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 0; min-height: 58px; padding: 7px 2px 6px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .22); color: var(--ink); font: inherit; font-size: 11.5px; font-weight: 600; line-height: 1.15; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s, transform .1s; -webkit-tap-highlight-color: transparent; }
.sh-btn:hover { background: rgba(255, 244, 225, .08); border-color: rgba(217, 166, 73, .45); }
.sh-btn:active { transform: scale(.96); }
.sh-btn:focus-visible { outline: 2px solid var(--gold2); outline-offset: 2px; }
.sh-btn svg { width: 26px; height: 26px; flex: none; }
.sh-btn svg.sh-line { fill: none; stroke: var(--gold2); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; padding: 2px; }
.sh-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-modal .sm-icon { width: 54px; height: 54px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; background: rgba(217, 166, 73, .14); color: var(--gold2); }
.share-modal .sm-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.share-modal p { margin-bottom: 14px; }
.share-modal .sm-link { font-size: 13px; padding: 10px 12px; border-radius: 10px; background: rgba(0, 0, 0, .28); color: var(--muted); border: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-modal .share-btns { margin: 12px 0 18px; }
.share-strip { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px 14px; margin-top: 22px; padding: 14px 16px; border-radius: var(--radius); border: 1px dashed rgba(217, 166, 73, .35); background: var(--panel); text-align: center; }
.share-strip p { margin: 0; color: var(--muted); font-size: 14.5px; }
.share-strip .btn { width: auto; }
@media (max-width: 360px) { .share-btns { gap: 4px; } .sh-btn { font-size: 10.5px; padding-left: 1px; padding-right: 1px; } .sh-btn svg { width: 24px; height: 24px; } }
/* hộp chia sẻ trên màn hẹp: bớt lề hai bên để 5 nút (… "Messenger") vừa một hàng */
.modal[data-kind="shareweb"] .modal-card { padding: 22px 18px 18px; }
@media (max-width: 420px) { .modal[data-kind="shareweb"] { padding: 12px; } .modal[data-kind="shareweb"] .modal-card { padding: 20px 12px 14px; } .share-modal h3 { font-size: 22px; } }
/* 5 nút (có "Khác…" = bảng chia sẻ của máy) trên màn hẹp: 3 + 2, căn giữa */
@media (max-width: 420px) { .share-btns.n5 { display: flex; flex-wrap: wrap; justify-content: center; } .share-btns.n5 .sh-btn { flex: 0 0 calc((100% - 12px) / 3); } }
