/* =========================================================
   Tượng Kỳ — giao diện sáng (kem / đỏ son / đen nâu)
   Token theo tài liệu nhận diện: Đỏ son #C61D1D · Ngà #F2D7A6 · Đen nâu #1B1612 · Vàng đồng (tiết chế)
   ========================================================= */
:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --sunken: #f3efe8;
  --line: #ebe5db;
  --line-2: #ddd4c6;
  --text: #1b1612;
  --text-2: #4a4038;
  --muted: #7d7268;
  --faint: #a69c92;
  --red: #c61d1d;
  --red-600: #a81717;
  --red-50: #fcefed;
  --red-100: #f6d9d5;
  --ivory: #f2d7a6;
  --ivory-50: #fbf3e4;
  --ink: #1b1612;
  --ink-2: #2b231d;
  --gold: #b8862b;
  --gold-50: #fbf2de;
  --green: #2e9e5b;
  --green-50: #e7f5ec;
  --blue: #2f6fd6;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(27, 22, 18, 0.04), 0 6px 20px rgba(27, 22, 18, 0.04);
  --sidebar: 232px;
  --av-r: 24%; /* avatar: hình vuông bo góc (theo % cạnh) — khớp vòng đếm giờ .pc-ring */
  --topbar: 64px;
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.ico.sm { width: 14px; height: 14px; }
.ico.xl { width: 40px; height: 40px; stroke-width: 1.4; }
.ico.flip { transform: scaleX(-1); }
.ico.accent { color: var(--red); width: 22px; height: 22px; margin-bottom: 8px; }

/* ---------- Nút, ô nhập ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text);
  border-radius: var(--r-sm); padding: 9px 16px; font-weight: 600; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--faint); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-600); border-color: var(--red-600); }
.btn.light { background: #fff; border-color: #fff; color: var(--ink); }
.btn.light:hover { background: var(--ivory-50); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--sunken); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); background: var(--red-50); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.lg { padding: 12px 18px; font-size: 15px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none; padding: 0;
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); cursor: pointer; color: var(--text-2);
}
.icon-btn:hover:not(:disabled) { border-color: var(--line-2); background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--red); cursor: pointer; font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link-more { display: inline-flex; align-items: center; gap: 4px; color: var(--red); font-weight: 600; font-size: 13px; text-decoration: none; white-space: nowrap; }
.link-more:hover { text-decoration: underline; }
.link-more.back { margin-bottom: 4px; }

input:not([type="radio"]):not([type="checkbox"]):not([type="file"]), select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  padding: 10px 12px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(198, 29, 29, 0.12); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237d7268' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; padding-right: 34px; }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input, .row > select { flex: 1; min-width: 0; }
.row.tight { gap: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.err { color: var(--red); font-size: 13px; margin: 0; }
.err.info { color: var(--green); }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  background: var(--red-50); color: var(--red); font-size: 12px; font-weight: 700; white-space: nowrap;
}
.tag.soft { background: var(--sunken); color: var(--muted); }
.tag.green { background: var(--green-50); color: var(--green); }
.tag.gold { background: var(--gold-50); color: var(--gold); }
.tag.dark { background: var(--ink); color: #fff; }
.tag.on-dark { background: rgba(198, 29, 29, 0.9); color: #fff; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot.green { background: #3ccf7a; box-shadow: 0 0 0 3px rgba(60, 207, 122, 0.2); }
.side-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid #e6c991; flex: none; vertical-align: -1px; }
.side-dot.r { background: var(--red); }
.side-dot.b { background: var(--ink); }
.side-dot.rnd { background: linear-gradient(90deg, var(--red) 50%, var(--ink) 50%); }
.side-dot.lg { width: 28px; height: 28px; border-width: 3px; }

/* Chuyển tab dạng viên */
.seg-tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); flex-wrap: wrap; }
.seg-tabs.block { display: flex; width: 100%; }
.seg-tabs.block > * { flex: 1; }
.seg-tabs button { border: 0; background: none; padding: 7px 14px; border-radius: var(--r-sm); font-weight: 600; color: var(--muted); cursor: pointer; }
.seg-tabs button:hover { color: var(--text); }
.seg-tabs button.active { background: var(--red-50); color: var(--red); box-shadow: inset 0 0 0 1px var(--red-100); }
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 10px 2px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--red); border-bottom-color: var(--red); }

/* Lựa chọn dạng nút liền */
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; }
.seg input, .side-pick input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 6px; text-align: center;
  border: 1px solid var(--line-2); border-radius: var(--r-sm); cursor: pointer; font-weight: 600; background: var(--surface);
}
.seg small { color: var(--muted); font-weight: 500; }
.seg input:checked + span { border-color: var(--red); background: var(--red-50); color: var(--red); }
.seg input:focus-visible + span, .side-pick input:focus-visible + span { outline: 2px solid var(--red); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line-2); background: var(--surface); padding: 7px 14px; border-radius: 999px; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--faint); }
.chip.active { border-color: var(--red); background: var(--red-50); color: var(--red); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; }
.toggle-row b { display: block; }
.toggle-row small { color: var(--muted); }
.toggle { appearance: none; width: 40px; height: 22px; border-radius: 999px; background: var(--line-2); position: relative; cursor: pointer; flex: none; transition: background 0.2s; margin: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.toggle:checked { background: var(--red); }
.toggle:checked::after { transform: translateX(18px); }

/* ---------- Khung chính: menu trái + nội dung ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: none; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40;
  background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px 16px; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 18px; text-decoration: none; color: var(--text); }
.brand-mark { width: 44px; height: 44px; flex: none; object-fit: contain; filter: drop-shadow(0 3px 4px rgba(80, 40, 10, 0.22)); }
.brand-mark.sm { width: 32px; height: 32px; }
.brand-mark.lg { width: 72px; height: 72px; }
.brand-mark.xl { width: 84px; height: 84px; }
.brand-text b { display: block; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; }
.brand-text small { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--red); margin-top: 3px; }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); padding: 4px 10px 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text-2); font-weight: 600; cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--sunken); color: var(--text); }
.nav-item.active { background: var(--red-50); color: var(--red); }
.nav-item .ico { width: 19px; height: 19px; }
.sb-promo { margin-top: auto; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.sb-promo .ico { color: var(--red); }
.sb-promo b { font-size: 13.5px; }
.sb-promo p { font-size: 12px; color: var(--muted); line-height: 1.5; }
.sb-promo a { display: inline-flex; align-items: center; gap: 2px; color: var(--red); font-weight: 700; font-size: 12.5px; text-decoration: none; }
.sb-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 14px 8px 0; font-size: 12px; color: var(--muted); }
.sb-foot a { color: var(--muted); text-decoration: none; }
.sb-foot a:hover, .sb-foot .link:hover { color: var(--red); }
.sb-foot .link { color: var(--muted); font-weight: 500; }
.sb-foot small { width: 100%; color: var(--faint); font-size: 11px; }
.sb-backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar); display: flex; align-items: center; gap: 14px; padding: 0 32px;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.menu-btn, .topbar-brand { display: none; }
.topbar-brand { align-items: center; gap: 8px; text-decoration: none; font-weight: 800; }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--faint); min-width: 0; overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--faint); text-decoration: none; }
.crumbs a:hover { color: var(--red); }
.crumbs b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.coin-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--gold-50); color: #8a6214; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.coin-pill .ico { width: 16px; height: 16px; color: var(--gold); }
.user-chip { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 4px 6px 4px 4px; border-radius: 999px; cursor: pointer; text-align: left; }
.user-chip:hover { background: var(--sunken); }
.user-chip .avatar { width: 36px; height: 36px; font-size: 14px; }
.user-chip b { display: block; font-size: 13.5px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip small { display: block; font-size: 11.5px; color: var(--muted); }
.user-chip .ico { color: var(--faint); }

.avatar {
  display: grid; place-items: center; flex: none; overflow: hidden; border-radius: var(--av-r); font-weight: 700;
  background: var(--red-50); color: var(--red); width: 40px; height: 40px; font-size: 15px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.dark { background: var(--ink); color: #fff; }
.avatar.ai { background: linear-gradient(135deg, #46526e, #232a3d); color: #e8eefc; letter-spacing: 0.5px; }

/* ---------- Trang ---------- */
.page-msg { margin: 0 auto; max-width: 1216px; width: 100%; padding: 0 32px; }
.page-msg:not(:empty) { padding-top: 14px; }
.screen.page { width: 100%; max-width: 1216px; margin: 0 auto; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--red); margin-bottom: 6px; }
.page-head h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.lead { color: var(--muted); margin-top: 6px; font-size: 14.5px; }
.section-title { font-size: 15px; font-weight: 700; margin-top: 4px; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) 408px; gap: 24px; align-items: start; }
.col-main, .col-side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.card h3 { font-size: 15.5px; font-weight: 700; }
.card.dark { background: var(--ink); border-color: var(--ink); color: #f3ebe1; }
.card.dark p { color: #bfb3a6; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-head.pad { padding: 18px 20px 12px; }
.card-head.plain { align-items: center; }
.note { color: var(--muted); font-size: 12.5px; }
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); font-size: 13px; }
.callout .ico { color: var(--red); margin-top: 1px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--text-2); }
.steps li::marker { color: var(--red); font-weight: 700; }
.bullets { padding-left: 18px; line-height: 1.7; color: var(--text-2); }
.empty { color: var(--muted); text-align: center; padding: 22px 10px; font-size: 13px; }
.empty .btn { margin-top: 10px; }
.empty-card { align-items: center; text-align: center; padding: 40px 24px; color: var(--muted); }
.empty-card .ico { color: var(--faint); }
.empty-card b { color: var(--text); font-size: 15px; }
.prose { line-height: 1.7; }
.rules { padding-left: 18px; margin: 0; }
.rules li { margin-bottom: 6px; }

/* ---------- H01 Trang chủ ---------- */
.hero { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.8fr); border-radius: 16px; overflow: hidden; background: var(--ink); color: #fff; min-height: 260px; }
.hero::after { content: ""; position: absolute; inset: 0; background: radial-gradient(60% 90% at 78% 50%, rgba(198, 29, 29, 0.28), rgba(198, 29, 29, 0) 70%); pointer-events: none; }
.hero-body { position: relative; z-index: 1; padding: 30px 32px; display: flex; flex-direction: column; align-items: flex-start; gap: 14px; justify-content: center; }
.hero h2 { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 18px; color: #cbbfb2; font-size: 13px; }
.hero-meta span { display: inline-flex; align-items: center; gap: 6px; }
.hero-meta b { color: #fff; }
.hero-sub { color: #cbbfb2; max-width: 520px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.hero-art { position: relative; z-index: 1; display: grid; place-items: center; padding: 18px; }
.hero-art img { width: min(100%, 300px); height: auto; transform: rotate(-8deg); filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.55)); }
.hero.slim { grid-template-columns: minmax(0, 1fr) auto; min-height: 0; }
.hero.slim::after { display: none; }
.hero-side { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px 32px; }
.link-light { color: #cbbfb2; font-size: 13px; text-decoration: none; }
.link-light:hover { color: #fff; }
.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.quick-card {
  display: flex; flex-direction: column; gap: 6px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: border-color 0.15s, transform 0.15s;
}
.quick-card:hover { border-color: var(--red-100); transform: translateY(-2px); }
.qc-ico { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--red-50); color: var(--red); margin-bottom: 6px; }
.quick-card b { font-size: 15px; }
.quick-card p { color: var(--muted); font-size: 13px; flex: 1; }
.quick-card .more { display: inline-flex; align-items: center; gap: 2px; color: var(--red); font-size: 12.5px; font-weight: 700; margin-top: 6px; }
.form-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-stats div { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.form-stats small { display: block; color: var(--muted); font-size: 12px; }
.form-stats b { display: block; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.form-stats em { font-style: normal; font-size: 12px; color: var(--muted); }
.up { color: var(--green) !important; }
.down { color: var(--red) !important; }

/* Danh sách trận hot */
.live-list { display: flex; flex-direction: column; gap: 8px; }
.live-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); text-decoration: none; color: var(--text); }
.live-item:hover { border-color: var(--red-100); background: var(--red-50); }
.live-item .vs { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.live-item .pl { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; min-width: 0; }
.live-item .pl span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-item .pl em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 12px; flex: none; }
.live-item .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.live-item .meta b { color: var(--red); font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.live-empty { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; border: 1px dashed var(--line-2); border-radius: var(--r); }
.live-empty a { color: var(--red); font-weight: 700; text-decoration: none; }

.mini-board { border-radius: 10px; overflow: hidden; background: #e9c98f; box-shadow: inset 0 0 0 1px rgba(120, 75, 35, 0.15); }
.mini-board svg { display: block; width: 100%; height: auto; }

/* ---------- Q01 Chơi nhanh ---------- */
.tc-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.tc-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 16px 18px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); transition: border-color 0.15s, background 0.15s;
}
.tc-card:hover { border-color: var(--line-2); }
.tc-card .tc-top { display: flex; width: 100%; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; font-weight: 600; }
.tc-card b { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.tc-card small { color: var(--text-2); font-size: 12.5px; }
.tc-card em { font-style: normal; color: var(--faint); font-size: 12px; margin-top: 8px; }
.tc-card.active { border-color: var(--red); background: var(--red-50); box-shadow: 0 0 0 3px rgba(198, 29, 29, 0.08); }
.tc-card.active b, .tc-card.active .tc-top { color: var(--red); }
.ranked-card { gap: 16px; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-row {
  display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  text-decoration: none; color: var(--text); box-shadow: var(--shadow);
}
a.mode-row:hover { border-color: var(--red-100); }
.mode-row > span:nth-child(2) { flex: 1; min-width: 0; }
.mode-row b { display: block; font-size: 14px; }
.mode-row small { display: block; color: var(--muted); font-size: 12.5px; }
.mode-row .chev { color: var(--faint); }
.mode-row.locked { opacity: 0.75; cursor: default; }
.mr-ico { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--red-50); color: var(--red); flex: none; }
.mr-ico.gold { background: var(--gold-50); color: var(--gold); }

/* ---------- Q02 Tìm đối thủ ---------- */
.search-card { align-items: stretch; gap: 16px; }
.search-ring { position: relative; width: 132px; height: 132px; margin: 6px auto 0; display: grid; place-items: center; border-radius: 50%; background: var(--red-50); }
.search-ring::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid var(--red-100); border-top-color: var(--red); animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.search-title { text-align: center; font-size: 22px; font-weight: 800; }
.stat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.stat-row small { display: block; color: var(--muted); font-size: 12px; }
.stat-row b { display: block; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-row.plain { background: none; border: 0; padding: 0; }
.search-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; padding-top: 12px; border-top: 1px solid var(--line); }
.search-foot span { display: inline-flex; align-items: center; gap: 6px; }
.opp-card { align-items: center; text-align: center; }
.opp-card .card-head { width: 100%; }
.opp-avatar { width: 72px; height: 72px; border-radius: var(--av-r); display: grid; place-items: center; background: var(--sunken); color: var(--faint); font-size: 26px; font-weight: 800; border: 2px dashed var(--line-2); }
.opp-avatar.found { background: var(--ink); color: #fff; border: 0; }
.opp-name { font-size: 16px; }
.tip-card .ico { color: var(--ivory); width: 22px; height: 22px; }
.tip-card b { font-size: 15px; }

/* ---------- Đấu máy ---------- */
.level-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.level {
  position: relative; display: flex; flex-direction: column; gap: 1px; padding: 12px; text-align: left; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r);
}
.level:hover { border-color: var(--line-2); }
.level small { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.level b { font-size: 14px; }
.level em { font-style: normal; color: var(--faint); font-size: 12px; }
.level.active { background: var(--red-50); border-color: var(--red); }
.level.active small, .level.active b { color: var(--red); }
.level.active::after { content: ""; position: absolute; top: 10px; right: 10px; width: 16px; height: 16px; border-radius: 50%; background: var(--red) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 11px no-repeat; }
.side-pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.side-pick span { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); cursor: pointer; text-align: center; }
.side-pick small { color: var(--muted); font-size: 12px; }
.side-pick input:checked + span { border-color: var(--red); background: var(--red-50); }
.side-pick input:checked + span b { color: var(--red); }
.ai-panel { display: flex; flex-direction: column; gap: 20px; }
.history-list { display: flex; flex-direction: column; }

/* Cờ thế */
.pz-toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.pz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.pz-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: transform 0.15s, border-color 0.15s; }
.pz-card:hover { transform: translateY(-2px); border-color: var(--red-100); }
.pz-card svg { display: block; width: 100%; height: auto; background: #e9c98f; }
.pz-info { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.pz-info b { font-size: 14px; }
.pz-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.diff { padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 11.5px; }
.diff.easy { background: var(--green-50); color: var(--green); }
.diff.medium { background: var(--gold-50); color: var(--gold); }
.diff.hard { background: var(--red-50); color: var(--red); }
.solved-tag { color: var(--green); font-weight: 700; }
.pz-empty { grid-column: 1 / -1; }
.pz-solve { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.board-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); display: flex; justify-content: center; }
.pz-board-frame { width: min(100%, calc((100dvh - var(--topbar) - 120px) * var(--pz-ar, 1))); aspect-ratio: var(--pz-ar, 1); border-radius: 10px; overflow: hidden; background: #e9c98f; }
#pz-board { display: block; width: 100%; height: 100%; }
.pz-title { font-size: 20px; font-weight: 800; }
.pz-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); }
.pz-desc { color: var(--text-2); }
.pz-moves { list-style: none; margin: 0; padding: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); min-height: 46px;
  display: grid; grid-template-columns: 30px 1fr 1fr; gap: 3px 6px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.pz-moves li { display: contents; }
.pz-moves .no { color: var(--faint); text-align: right; }
.pz-moves .r { color: var(--red); }
.pz-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Xếp hạng ---------- */
.tabs-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.podium-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.podium-card.first { background: var(--ink); border-color: var(--ink); color: #fff; }
.podium-card .pc-top { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700; color: var(--muted); }
.podium-card.first .pc-top { color: var(--ivory); }
.podium-card .who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.podium-card .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.podium-card .who small { color: var(--muted); font-size: 12px; }
.podium-card.first .who small { color: #bfb3a6; }
.podium-card .val { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.podium-card .val small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.podium-card.first .avatar { background: var(--red); color: #fff; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.me td { background: var(--red-50); }
.table th.num, .table td.num { text-align: right; }
.table .w-rank { width: 64px; }
.table .rank-no { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.player-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.player-cell b { display: block; font-weight: 600; }
.player-cell small { display: block; color: var(--muted); font-size: 12px; }
.table .player-cell .avatar { width: 32px; height: 32px; font-size: 13px; }
.table-foot { display: flex; justify-content: center; padding: 10px; }
.table-foot:empty { display: none; }
.rank-me { align-items: flex-start; }
.rank-me .big { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }
.res { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.res.win { background: var(--green-50); color: var(--green); }
.res.loss { background: var(--red-50); color: var(--red); }
.res.draw { background: var(--sunken); color: var(--muted); }

/* ---------- Bạn bè ---------- */
.search-bar { display: flex; gap: 10px; }
.search-input { position: relative; flex: 1; }
.search-input .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search-input input { padding-left: 38px !important; }
.fr-list { display: flex; flex-direction: column; gap: 8px; }
.fr-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); cursor: pointer; text-align: left; width: 100%; }
.fr-row:hover { border-color: var(--line-2); }
.fr-row.active { background: var(--red-50); border-color: var(--red-100); }
.fr-row .info { flex: 1; min-width: 0; }
.fr-row b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fr-row small { color: var(--muted); font-size: 12px; }
.fr-row .rec { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.fr-detail { align-items: center; text-align: center; }
.fr-detail .avatar { width: 72px; height: 72px; font-size: 26px; }
.fr-detail .h2h { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; gap: 8px; }
.fr-detail .h2h div { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; }
.fr-detail .h2h b { display: block; font-size: 22px; font-weight: 800; }
.fr-detail .h2h small { color: var(--muted); font-size: 12px; }
.fr-detail .recent { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.fr-detail .recent div { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---------- Túi đồ ---------- */
.inv-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.inv-item { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); cursor: pointer; text-align: left; box-shadow: var(--shadow); }
.inv-item:hover { border-color: var(--line-2); }
.inv-item.selected { border-color: var(--red); box-shadow: 0 0 0 3px rgba(198, 29, 29, 0.1); }
.inv-thumb { aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; display: grid; place-items: center; background: var(--surface-2); }
.inv-thumb svg { width: 100%; height: 100%; display: block; }
.inv-meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.inv-meta b { font-size: 13.5px; }
.inv-meta small { display: block; color: var(--muted); font-size: 12px; }
.inv-preview .mini-board { margin: 0 auto; width: 100%; }
.clock-demo { display: flex; justify-content: center; }

/* ---------- Hồ sơ ---------- */
.pf-header { flex-direction: row; align-items: center; gap: 18px; }
.pf-avatar { width: 80px; height: 80px; font-size: 28px; }
.pf-lines { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pf-name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pf-name-row h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.pf-acts { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-card small { display: block; color: var(--muted); font-size: 12.5px; }
.stat-card b { display: block; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.stat-card em { font-style: normal; font-size: 12px; color: var(--muted); }
.line-chart { width: 100%; height: 180px; display: block; overflow: visible; }
.line-chart .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.line-chart .area { fill: rgba(198, 29, 29, 0.07); }
.line-chart .line { fill: none; stroke: var(--red); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.line-chart text { font-size: 11px; fill: var(--faint); }
.chart-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 40px 10px; }
.ach-list { display: flex; flex-direction: column; gap: 10px; }
.ach { display: flex; gap: 12px; align-items: center; }
.ach-ico { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--gold-50); color: var(--gold); }
.ach.locked .ach-ico { background: var(--sunken); color: var(--faint); }
.ach b { display: block; font-size: 13.5px; }
.ach small { color: var(--muted); font-size: 12px; }
.goal-card b { font-size: 15px; color: #fff; }
.progress { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ivory); border-radius: inherit; }
.menu-list { display: flex; flex-direction: column; }
.menu-list button { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; font-weight: 600; color: var(--text-2); text-align: left; }
.menu-list button:last-child { border-bottom: 0; }
.menu-list button:hover { color: var(--red); }
.menu-list .chev { margin-left: auto; color: var(--faint); }
.pf-pass { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.elo-chg { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Modal, toast ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(27, 22, 18, 0.45); backdrop-filter: blur(2px); }
.modal-card { position: relative; width: 100%; max-width: 400px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 16px; padding: 24px; box-shadow: 0 24px 60px rgba(27, 22, 18, 0.25); display: flex; flex-direction: column; gap: 14px; }
.modal-card.wide { max-width: 560px; }
.modal-card h2 { font-size: 20px; font-weight: 800; }
.modal-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: 8px; cursor: pointer; }
.modal-close:hover { background: var(--sunken); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 20px; font-weight: 800; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.form-sec { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.form-sec h3 { font-size: 14px; }
.feedback-form { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.feedback-form h3 { font-size: 14px; }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 80;
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 32px); text-align: center;
  box-shadow: 0 10px 30px rgba(27, 22, 18, 0.25);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =========================================================
   G01 · Bàn cờ online
   ========================================================= */
.screen.game { max-width: 1320px; gap: 16px; padding-top: 20px; padding-bottom: 24px; }
.game-head h1 { font-size: 22px; }
.game-head .eyebrow { margin-bottom: 4px; }
.game-head .eyebrow b { letter-spacing: 0.1em; }
.game-head .lead { margin-top: 2px; font-size: 13px; }
.head-acts { display: flex; gap: 8px; }
.game-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-areas: "board side"; gap: 24px; align-items: start; }
.board-col {
  grid-area: board; display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0;
  --bw: min(100%, max(300px, calc((100dvh - var(--topbar) - 300px) * var(--board-ar, 1))));
}
.board-col > .player, .board-col > .board-frame { width: var(--bw); }
.board-frame { position: relative; aspect-ratio: var(--board-ar, 1); border-radius: 10px; overflow: hidden; background: #e9c98f; box-shadow: 0 14px 40px rgba(80, 45, 15, 0.18), 0 0 0 1px rgba(120, 75, 35, 0.12); transition: width 0.35s ease; }
#board { display: block; width: 100%; height: 100%; cursor: pointer; user-select: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.game-side { grid-area: side; display: flex; flex-direction: column; gap: 14px; min-width: 0; max-height: calc(100dvh - var(--topbar) - 130px); position: sticky; top: calc(var(--topbar) + 16px); }
.game-side .card { padding: 16px; gap: 10px; }

/* Thẻ người chơi: ảnh (viền chạy theo giờ) · tên · đồng hồ */
.player { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-height: 62px; }
.player.me { background: var(--red-50); border-color: var(--red-100); }
.player.turn { border-color: var(--red); box-shadow: 0 0 0 3px rgba(198, 29, 29, 0.1); }
.pc-avatar { position: relative; width: 42px; height: 42px; flex: none; }
.pc-avatar img, .pc-initial { width: 100%; height: 100%; border-radius: var(--av-r); object-fit: cover; display: grid; place-items: center; background: var(--ink); color: #fff; font-weight: 800; font-size: 16px; }
.player.me .pc-initial { background: var(--red); }
.pc-initial.ai { background: linear-gradient(135deg, #46526e, #232a3d); color: #e8eefc; font-size: 13px; }
.pc-initial.empty { background: var(--sunken); color: var(--faint); border: 2px dashed var(--line-2); }
.pc-ring { position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px); overflow: visible; pointer-events: none; }
.pc-ring rect { fill: none; stroke-width: 5; }
.pc-ring .track { stroke: transparent; }
.pc-ring .bar { stroke: var(--green); stroke-dasharray: 100; stroke-dashoffset: 0; stroke-linecap: round; opacity: 0; transition: stroke-dashoffset 0.2s linear, stroke 0.4s, opacity 0.2s; }
.player.ring-on .pc-ring .track { stroke: rgba(27, 22, 18, 0.08); }
.player.ring-on .pc-ring .bar { opacity: 1; }
.pc-side { position: absolute; right: -4px; bottom: -4px; width: 15px; height: 15px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }
.pc-side.r { background: var(--red); }
.pc-side.b { background: var(--ink); }
.pc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pc-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 1.2em; }
.pc-sub .off { color: var(--red); font-weight: 600; }

/* Đồng hồ (4 kiểu trong Túi đồ) */
.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; font-variant-numeric: tabular-nums; flex: none; }
.clock b { font-size: 22px; font-weight: 800; padding: 6px 12px; border-radius: var(--r-sm); background: var(--sunken); color: var(--text); border: 1px solid var(--line); min-width: 92px; text-align: center; }
.clock small { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.clock.running b { background: var(--red); border-color: var(--red); color: #fff; }
.clock.low b { animation: clock-pulse 1s steps(2) infinite; }
.clock.low small { color: var(--red); font-weight: 700; }
@keyframes clock-pulse { 50% { opacity: 0.55; } }
.clock-demo b { font-size: 22px; font-weight: 800; padding: 6px 14px; border-radius: var(--r-sm); background: var(--sunken); border: 1px solid var(--line); font-variant-numeric: tabular-nums; min-width: 100px; text-align: center; }
.clock-demo.running b { background: var(--red); border-color: var(--red); color: #fff; }
body.clock-digital .clock b, :not(body).clock-digital .clock-demo b { background: #10140f; border-color: #10140f; color: #58e08a; font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.04em; }
body.clock-digital .clock.running b, :not(body).clock-digital .clock-demo.running b { background: #10140f; color: #8dffb4; box-shadow: 0 0 0 2px #58e08a; }
body.clock-wood .clock b, :not(body).clock-wood .clock-demo b { background: linear-gradient(180deg, #f5dfb5, #e2bd82); border-color: #c99461; color: #5a3416; }
body.clock-wood .clock.running b, :not(body).clock-wood .clock-demo.running b { background: linear-gradient(180deg, #8a4d2b, #5c2c16); border-color: #5c2c16; color: #ffe9c4; }
body.clock-minimal .clock b, :not(body).clock-minimal .clock-demo b { background: none; border-color: transparent; font-size: 24px; padding: 4px 6px; }
body.clock-minimal .clock.running b, :not(body).clock-minimal .clock-demo.running b { background: none; color: var(--red); border-color: transparent; box-shadow: inset 0 -3px 0 var(--red); border-radius: 0; }

/* Cột phải */
.moves-card { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.moves-card .card-head { align-items: center; }
.moves-card h3 { white-space: nowrap; }
.moves-card select { padding: 6px 28px 6px 10px; font-size: 12.5px; width: 124px; }
.mv-head { display: grid; grid-template-columns: 40px 1fr 1fr; padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: var(--r-sm); }
#move-list {
  list-style: none; margin: 0; padding: 0 0 4px; flex: 1 1 auto; min-height: 60px; overflow-y: auto;
  display: grid; grid-template-columns: 40px 1fr 1fr; align-content: start; font-variant-numeric: tabular-nums; font-size: 13.5px;
}
#move-list li { display: contents; }
#move-list li:nth-child(even) > * { background: var(--surface-2); }
#move-list li.result-line, #move-list li.empty { display: block; grid-column: 1 / -1; background: none; }
#move-list .no { color: var(--faint); padding: 6px 8px; }
#move-list button { background: none; border: 0; padding: 6px 8px; text-align: left; cursor: pointer; font-family: ui-monospace, "SF Mono", Menlo, monospace; border-radius: 0; }
#move-list li:nth-child(even) button { background: var(--surface-2); }
#move-list button:hover:not(:disabled) { color: var(--red); }
#move-list button:disabled { cursor: default; }
#move-list button.r { color: var(--red); }
#move-list button.current { background: var(--red) !important; color: #fff; border-radius: 6px; }
#move-list.locked button.current { background: var(--red-50) !important; color: var(--red); }
#move-list .empty { color: var(--muted); font-size: 13px; padding: 14px 8px; text-align: center; }
.result-line { color: var(--muted); font-size: 12.5px; padding: 8px 4px 2px; text-align: center; }
.replay-bar { display: flex; align-items: center; gap: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.replay-bar .icon-btn { width: 34px; height: 32px; }
.rp-label { flex: 1; text-align: center; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rp-label.review { color: var(--red); font-weight: 600; }
.chat-card { flex: 0 3 auto; min-height: 130px; overflow: hidden; }
.actions-card { flex: none; }
#chat-log { flex: 1 1 auto; overflow-y: auto; min-height: 36px; max-height: 150px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
#chat-log .msg b.r { color: var(--red); }
#chat-log .msg b.b { color: var(--ink); }
#chat-log .msg b.s { color: var(--muted); }
#chat-log .sys { color: var(--muted); font-size: 12px; background: var(--surface-2); border-radius: 8px; padding: 6px 10px; }
#chat-log .empty { padding: 8px; }
.chat-form { display: flex; gap: 6px; }
.chat-form input { padding: 8px 12px !important; }
.status-box { padding: 11px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; line-height: 1.4; }
.status-box.check { border-color: var(--red); background: var(--red-50); color: var(--red); }
.status-box.ok { border-color: #bfe5cc; background: var(--green-50); color: var(--green); }
.status-box.bad { border-color: var(--red-100); background: var(--red-50); color: var(--red); }
.status-box .hint { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.status-box .turn-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.status-box .turn-dot.r { background: var(--red); } .status-box .turn-dot.b { background: var(--ink); }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-radius: var(--r); background: var(--gold-50); border: 1px solid #ecd9ad; font-weight: 600; }
.banner div { display: flex; gap: 6px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .btn { padding: 9px 10px; }

/* Phân tích */
.an-box { display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; flex: none; }
.an-progress { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.an-bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.an-bar i { display: block; height: 100%; width: 0; background: var(--red); transition: width 0.2s; }
.an-summary { display: grid; gap: 4px; font-size: 12.5px; }
.an-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.an-row .who { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; flex: 1; }
.an-row .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-row .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.an-row .dot.r { background: var(--red); } .an-row .dot.b { background: var(--ink); }
.an-row .acc { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--red); }
.an-row .counts { display: flex; gap: 6px; font-size: 11.5px; color: var(--muted); }
.an-chart { width: 100%; height: 56px; display: block; cursor: pointer; background: var(--surface); border-radius: 6px; border: 1px solid var(--line); }
.an-chart .zero { stroke: var(--line-2); stroke-width: 1; }
.an-chart .area { fill: rgba(198, 29, 29, 0.12); }
.an-chart .line { fill: none; stroke: var(--red); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.an-chart .cursor { stroke: var(--ink); stroke-width: 1; vector-effect: non-scaling-stroke; opacity: 0.6; }
.an-detail { font-size: 12.5px; line-height: 1.5; min-height: 2.6em; }
.q { display: inline-block; min-width: 18px; padding: 0 4px; margin-left: 4px; border-radius: 5px; font-size: 11px; font-weight: 800; text-align: center; line-height: 16px; color: #fff; font-family: system-ui, sans-serif; }
.q-best { background: #2e9e5b; } .q-good { background: #7cb342; } .q-inacc { background: #d9a520; }
.q-mistake { background: #e8772e; } .q-blunder { background: var(--red); }
.q-brilliant { background: #1f8fb3; } .q-missed { background: #8e44ad; }
.best-arrow { stroke: rgba(46, 158, 91, 0.85); stroke-linecap: round; fill: none; pointer-events: none; }
.best-arrow-head { fill: rgba(46, 158, 91, 0.85); pointer-events: none; }
.hint-arrow { stroke: rgba(47, 111, 214, 0.85); stroke-linecap: round; fill: none; pointer-events: none; }
.hint-arrow-head { fill: rgba(47, 111, 214, 0.85); pointer-events: none; }

/* Bàn cờ SVG */
.piece.selected { filter: drop-shadow(0 0 10px rgba(198, 29, 29, 0.6)); }
.target { fill: rgba(198, 29, 29, 0.55); }
.target-cap { fill: none; stroke: rgba(198, 29, 29, 0.8); stroke-width: 6; }
.last-from { fill: rgba(47, 111, 214, 0.14); stroke: rgba(47, 111, 214, 0.55); stroke-width: 3; stroke-dasharray: 8 6; }
.last-to { fill: none; stroke: #2f6fd6; stroke-width: 5; }
.check-glow { fill: none; stroke: #e0281b; stroke-width: 7; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { stroke-opacity: 0.25; } }

/* =========================================================
   G02 · Kết thúc ván (bàn cờ thu nhỏ sang phải, kết quả bên trái)
   ========================================================= */
.result-view, .end-board-head, .end-insight { display: none; }
#game.ended .game-grid { grid-template-columns: minmax(0, 1fr) 400px; grid-template-areas: "result board"; }
#game.ended .game-side, #game.ended .player, #game.ended .head-acts { display: none; }
#game.ended .result-view { grid-area: result; display: flex; flex-direction: column; gap: 16px; min-width: 0; animation: rise 0.35s ease-out; }
#game.ended .board-col { --bw: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow); align-items: stretch; gap: 14px; }
#game.ended .board-frame { box-shadow: 0 0 0 1px rgba(120, 75, 35, 0.12); }
#game.ended .end-board-head, #game.ended .end-insight { display: flex; flex-direction: column; gap: 8px; }
#game.ended #board { cursor: default; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.result-card { align-items: center; text-align: center; padding: 28px 24px 20px; }
.result-ico { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--red-50); color: var(--red); box-shadow: 0 0 0 8px rgba(198, 29, 29, 0.05); }
.result-ico .ico { width: 30px; height: 30px; }
.result-title { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; color: var(--red); }
.result-card.lose .result-title { color: var(--ink); }
.result-card.lose .result-ico { background: var(--sunken); color: var(--text-2); box-shadow: 0 0 0 8px rgba(27, 22, 18, 0.04); }
.result-card.draw .result-title { color: var(--gold); }
.result-card.draw .result-ico { background: var(--gold-50); color: var(--gold); box-shadow: 0 0 0 8px rgba(184, 134, 43, 0.06); }
.vs-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; width: 100%; max-width: 460px; margin: 8px 0 4px; }
.vs-side { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.vs-side .avatar { width: 52px; height: 52px; font-size: 18px; }
.vs-side b { font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-side small { color: var(--muted); font-size: 12.5px; }
.vs-score { font-size: 32px; font-weight: 800; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.delta-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; background: var(--sunken); color: var(--text-2); }
.delta.up { background: var(--green-50); }
.delta.down { background: var(--red-50); }
.delta.coin { background: var(--gold-50); color: #8a6214 !important; }
.result-hint { min-height: 1.2em; color: var(--muted); font-size: 13px; }
.result-hint.ask { color: var(--red); font-weight: 700; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; width: 100%; }
.result-actions .btn { min-width: 180px; }
.result-links { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--line); width: 100%; }
.radar-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 12px; align-items: center; }
#radar { width: 100%; height: auto; max-height: 260px; display: block; overflow: visible; }
#radar .web { fill: none; stroke: var(--line); }
#radar .axis { stroke: var(--line); }
#radar .shape { fill: rgba(198, 29, 29, 0.16); stroke: var(--red); stroke-width: 2; stroke-linejoin: round; }
#radar .pt { fill: var(--red); }
#radar text { font-size: 11.5px; fill: var(--text-2); font-weight: 600; }
.radar-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.radar-legend li { display: flex; justify-content: space-between; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.radar-legend b { font-variant-numeric: tabular-nums; }

/* =========================================================
   Tính năng: nhiệm vụ, Tranh xu, ghép trận, giải đấu, bạn bè, thông báo, cửa hàng
   ========================================================= */
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; align-items: start; }
.row.wrap { flex-wrap: wrap; }
.sel-sm { width: auto !important; padding: 6px 30px 6px 10px !important; font-size: 13px; }
.count-dot { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; margin-left: 4px; }

/* Thanh trên: chuông thông báo */
.bell-btn { position: relative; }
.bell-btn .badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; border: 2px solid #fff; }
.notif-panel { position: fixed; top: calc(var(--topbar) - 4px); right: 24px; z-index: 70; width: min(380px, calc(100vw - 24px)); max-height: min(560px, calc(100vh - 90px)); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: 0 20px 50px rgba(27, 22, 18, 0.18); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.notif-list { display: flex; flex-direction: column; gap: 4px; }
.notif-item { display: flex; gap: 10px; padding: 10px; border-radius: var(--r); align-items: flex-start; }
.notif-item.unread { background: var(--red-50); }
.notif-item .ni-ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--sunken); color: var(--text-2); }
.notif-item.unread .ni-ico { background: #fff; color: var(--red); }
.notif-item .ni-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.notif-item small { color: var(--muted); font-size: 11.5px; }
.notif-item .row { gap: 6px; }

/* Trang chủ: nhiệm vụ */
.mission { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mission:last-child { border-bottom: 0; }
.mission-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13.5px; }
.mission-top b { font-weight: 600; }
.mission .bar { height: 6px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.mission .bar i { display: block; height: 100%; background: var(--red); border-radius: inherit; }
.mission.done .bar i { background: var(--green); }
.reward { display: inline-flex; align-items: center; gap: 4px; color: var(--gold); font-weight: 700; font-size: 12.5px; white-space: nowrap; }

/* Tranh xu */
.coin-card .chips .chip small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.chip:disabled { opacity: 0.45; cursor: not-allowed; }
.chip.gold.active { border-color: var(--gold); background: var(--gold-50); color: #8a6214; }
.rule-list { margin: 0; padding: 10px 14px 10px 30px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); color: var(--text-2); font-size: 13px; display: flex; flex-direction: column; gap: 4px; }

/* Ghép trận: chấp nhận */
.accept-box { display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; padding: 16px; border-radius: var(--r); background: var(--red-50); border: 1px solid var(--red-100); animation: rise 0.3s ease-out; }
.accept-box b { font-size: 18px; color: var(--red); }
.accept-bar { width: 100%; height: 6px; border-radius: 999px; background: #fff; overflow: hidden; }
.accept-bar i { display: block; height: 100%; background: var(--red); transition: width 0.25s linear; }

/* Bàn cờ: sẵn sàng, mất kết nối */
.ready-box { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: var(--r); background: var(--gold-50); border: 1px solid #ecd9ad; }
.ready-box p { font-weight: 600; font-size: 13.5px; }
.banner.warn { background: var(--red-50); border-color: var(--red-100); color: var(--red); }
.pc-ready { font-size: 11.5px; font-weight: 700; color: var(--green); }
.conn-banner { position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 0 0 12px 12px; background: var(--ink); color: #fff; font-weight: 600; font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }
.share-canvas { width: 100%; height: auto; border-radius: var(--r); border: 1px solid var(--line); background: var(--sunken); }

/* Cờ thế: tổng kết */
.pz-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 12px; border-radius: var(--r); background: var(--green-50); border: 1px solid #bfe5cc; }
.pz-summary div { text-align: center; }
.pz-summary small { display: block; color: var(--muted); font-size: 11.5px; }
.pz-summary b { font-size: 18px; font-variant-numeric: tabular-nums; }

/* Giải đấu */
.tour-list { display: flex; flex-direction: column; gap: 12px; }
.tour-card { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); text-decoration: none; color: var(--text); }
.tour-card:hover { border-color: var(--red-100); }
.tour-ico { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; background: var(--ink); color: var(--ivory); }
.tour-ico .ico { width: 26px; height: 26px; }
.tour-card h3 { font-size: 15.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tour-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.tour-meta span { display: inline-flex; align-items: center; gap: 4px; }
.tour-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; }
.tour-side b { font-size: 18px; font-variant-numeric: tabular-nums; }
.tour-head { flex-direction: row; align-items: center; gap: 18px; background: var(--ink); border-color: var(--ink); color: #fff; }
.tour-head h1 { font-size: 24px; font-weight: 800; }
.tour-head .tour-meta { color: #cbbfb2; }
.tour-head .acts { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.tour-head .muted { color: #cbbfb2; }
.bracket { display: flex; gap: 18px; overflow-x: auto; padding-bottom: 6px; }
.bracket-round { display: flex; flex-direction: column; justify-content: space-around; gap: 12px; min-width: 190px; }
.bracket-round h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.match-box { border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); font-size: 13px; }
.match-box div { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; }
.match-box div + div { border-top: 1px solid var(--line); }
.match-box .win { font-weight: 700; background: var(--green-50); }
.match-box .me { box-shadow: inset 3px 0 0 var(--red); }
.pairing { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.pairing:last-child { border-bottom: 0; }
.pairing .p2 { text-align: right; }
.pairing .score { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 54px; text-align: center; }
.pairing .win { font-weight: 700; }
.round-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 10px 0 2px; }

/* Bạn bè */
.fr-row { cursor: default; }
.fr-row .acts { display: flex; gap: 6px; flex: none; }
.fr-row .status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.fr-row .status.on { color: var(--green); font-weight: 600; }
.fr-row button.fr-open { border: 0; background: none; padding: 0; text-align: left; cursor: pointer; flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.activity { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.activity:last-child { border-bottom: 0; }

/* Cửa hàng */
.coin-pill.big { padding: 8px 14px; font-size: 15px; }
.inv-item.locked .inv-thumb { filter: saturate(0.7); }
.price { display: inline-flex; align-items: center; gap: 4px; color: #8a6214; font-weight: 700; font-size: 12.5px; }
.inv-item .tag.new { background: var(--green-50); color: var(--green); }
body.clock-cinnabar .clock b, :not(body).clock-cinnabar .clock-demo b { background: linear-gradient(180deg, #b52121, #7c1010); border-color: #5c0b0b; color: #ffe2b3; }
body.clock-cinnabar .clock.running b, :not(body).clock-cinnabar .clock-demo.running b { background: linear-gradient(180deg, #e0392f, #a81717); color: #fff; box-shadow: 0 0 0 2px #f2cf72; }
body.clock-tournament .clock b, :not(body).clock-tournament .clock-demo b { background: #1f2933; border-color: #1f2933; color: #f5f7fa; font-family: ui-monospace, "SF Mono", Menlo, monospace; border-radius: 4px; }
body.clock-tournament .clock.running b, :not(body).clock-tournament .clock-demo.running b { background: #f5f7fa; color: #1f2933; border-color: #1f2933; }

/* Hồ sơ: theo chế độ */
.mode-stat { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.mode-stat:last-child { border-bottom: 0; }
.mode-stat .bar { grid-column: 1 / -1; height: 5px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.mode-stat .bar i { display: block; height: 100%; background: var(--green); }

/* Giải đấu: chi tiết */
.grow { flex: 1; min-width: 0; }
.medal { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-weight: 800; font-size: 12px; background: var(--sunken); }
.medal.m1 { background: #f6d36b; color: #6b4a00; }
.medal.m2 { background: #dfe3e8; color: #45505c; }
.medal.m3 { background: #e9b48a; color: #6a3410; }
.pairing span.me { color: var(--red); }
#td-players .player-cell { padding: 7px 0; border-bottom: 1px solid var(--line); }
#td-players .player-cell:last-child { border-bottom: 0; }
#td-players .player-cell.me b { color: var(--red); }
.hero .prize { text-align: center; }
.hero .prize small { display: block; color: #cbbfb2; font-size: 12px; }
.hero .prize b { display: inline-flex; align-items: center; gap: 6px; font-size: 24px; color: #f2cf72; }
.tour-head .eyebrow { color: #f2cf72; }
.tour-head .btn.ghost { color: #cbbfb2; }
.tour-head .btn.ghost:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tour-head > div:nth-child(2) { min-width: 0; }

/* Hồ sơ: lịch sử ván */
.chg-cell { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.coin-chg { font-size: 11.5px; font-weight: 600; }
.coin-chg.up { color: #8a6214; }
.coin-chg.down { color: var(--muted); }
.table small.sub { display: block; font-size: 11.5px; }
.table td.nowrap { white-space: nowrap; }
.btn.icon-only { padding: 6px 8px; }
.ach.season .ach-ico { background: var(--red-50); color: var(--red); }

/* Cờ thế: chủ đề */
.topic { display: inline-flex; padding: 1px 8px; border-radius: 999px; background: var(--sunken); color: var(--text-2); font-weight: 600; font-size: 11.5px; }

/* Phân tích: tổng kết ván */
.an-review { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12.5px; }
.an-rv-title { font-size: 13px; }
.an-rv small { display: block; font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.an-rv.good small { color: var(--green); }
.an-rv.bad small { color: #c25e15; }
.an-rv ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; color: var(--text-2); }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1180px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: minmax(0, 1fr) 340px; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #game.ended .game-grid { grid-template-columns: minmax(0, 1fr) 340px; }
  .radar-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 1000px) {
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .cols, .pz-solve { grid-template-columns: minmax(0, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "board" "side"; }
  .game-side { position: static; max-height: none; }
  .actions-card { order: -1; }
  .board-col { --bw: min(100%, 640px); }
  #game.ended .game-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "result" "board"; }
  #game.ended .board-col { max-width: 560px; width: 100%; justify-self: center; }
  #chat-log { max-height: 220px; }
  #move-list { max-height: 260px; }
}
/* Điện thoại / máy tính bảng: menu trái thành ngăn kéo */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(27, 22, 18, 0.25); }
  .sidebar.open + .sb-backdrop { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(27, 22, 18, 0.4); }
  .menu-btn, .topbar-brand { display: inline-flex; }
  .crumbs { display: none; }
  .topbar { padding: 0 16px; gap: 10px; }
  .user-chip > span:not(.avatar), .user-chip > .ico { display: none; }
  .screen.page { padding: 20px 16px 36px; }
  .page-msg { padding: 0 16px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-head h1 { font-size: 23px; }
  .hero { grid-template-columns: 1fr; }
  .hero-art { display: none; }
  .hero::after { display: none; }
  .hero.slim { grid-template-columns: 1fr; }
  .hero-side { align-items: flex-start; padding: 0 32px 24px; }
  .hero h2 { font-size: 24px; }
  .tc-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .tc-card { padding: 12px; }
  .tc-card b { font-size: 22px; }
  .tc-card em { display: none; }
  .mode-grid { grid-template-columns: 1fr; }
  .podium { grid-template-columns: 1fr; }
  .pf-header { flex-direction: column; align-items: flex-start; }
  .pf-pass { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .tour-card { grid-template-columns: 44px minmax(0, 1fr); }
  .tour-ico { width: 44px; height: 44px; }
  .tour-side { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .tour-head { flex-direction: column; align-items: flex-start; }
  .tour-head .acts { margin-left: 0; align-items: flex-start; }
  .pz-summary { grid-template-columns: 1fr 1fr; }
  .notif-panel { right: 12px; }
  .game-head h1 { font-size: 18px; }
  .board-col { --bw: 100%; }
  .player { min-height: 54px; padding: 8px 10px; }
  .clock b { font-size: 18px; min-width: 76px; padding: 5px 8px; }
}
@media (max-width: 520px) {
  .quick-grid, .stat-grid, .inv-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .level-grid { grid-template-columns: 1fr 1fr; }
  .tc-card .tc-top .ico { display: none; }
  .coin-pill { display: none; }
  .seg small { display: none; }
  .result-actions .btn { min-width: 0; flex: 1; }
  .vs-score { font-size: 24px; }
  .table td, .table th { padding: 9px 10px; }
}
/* Màn hình thấp: cột phải không bó theo chiều cao */
@media (max-height: 760px) and (min-width: 1001px) {
  .game-side { position: static; max-height: none; }
  .actions-card { order: -1; }
  #move-list { max-height: 240px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Cấp 9 "Vô đối" (Pikafish) chiếm cả hàng */
.level.boss { grid-column: 1 / -1; }
.level.boss b { color: var(--red, #c0392b); }

/* Máy phân tích (đấu máy): điểm thế cờ + 3 nước tốt nhất */
.eval-card { flex: none; gap: 10px; }
.eval-card .card-head p { font-size: 12.5px; }
.eval-body { display: flex; flex-direction: column; gap: 8px; }
.eval-score { display: flex; align-items: baseline; gap: 10px; }
.eval-score b { font-size: 22px; font-variant-numeric: tabular-nums; min-width: 64px; }
.eval-score span { color: var(--muted); font-size: 13px; }
.eval-bar { height: 6px; border-radius: 999px; background: var(--ink, #2b2622); overflow: hidden; }
.eval-bar i { display: block; height: 100%; width: 50%; background: var(--red); transition: width 0.4s; }
.eval-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.eval-line {
  display: grid; grid-template-columns: 18px auto 1fr; grid-template-areas: "rank move score" "rank pv pv";
  column-gap: 8px; align-items: baseline; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface-2);
}
.eval-line.clickable { cursor: pointer; }
.eval-line.clickable:hover { border-color: var(--line-2); }
.eval-line.active { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.el-rank { grid-area: rank; color: var(--muted); font-size: 12px; font-weight: 700; }
.el-move { grid-area: move; font-size: 14px; }
.el-score { grid-area: score; justify-self: end; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13px; }
.el-pv { grid-area: pv; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eval-meta { color: var(--muted); font-size: 11.5px; }
/* Cột phải có thêm thẻ Máy phân tích: giữ chỗ cho lịch sử nước đi, màn hình thấp thì cuộn cả cột */
.game-side:has(.eval-card:not(.hidden)) { overflow-y: auto; }
.game-side:has(.eval-card:not(.hidden)) .moves-card { min-height: 190px; }

/* ---------- Tab Phân tích (analysis.js) ---------- */
.ab-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start; }
.ab-main { display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 0; }
.ab-board-row { display: flex; gap: 10px; align-items: stretch; justify-content: center; width: 100%; }
.ab-frame { flex: 0 1 auto; }
.ab-evalbar {
  position: relative; width: 22px; flex: none; border-radius: 6px; overflow: hidden;
  background: var(--ink); border: 1px solid var(--line-2);
}
.ab-evalbar i { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: var(--red); transition: height 0.35s; }
.ab-evalbar span {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-90deg); white-space: nowrap;
  font-size: 11px; font-weight: 700; color: #fff; mix-blend-mode: difference;
}
.ab-status { font-weight: 600; color: var(--muted); font-size: 13.5px; text-align: center; }
.ab-toolbar, .ab-edit-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.ab-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.ab-editbar { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.ab-palette { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.ab-chip {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line-2); background: #f3e2c1; cursor: pointer;
  font: 700 19px "LXGW WenKai TC", "Noto Serif TC", serif; display: grid; place-items: center;
}
.ab-chip.r { color: var(--red); }
.ab-chip.b { color: var(--ink); }
.ab-chip.x { color: var(--muted); font-family: inherit; font-size: 16px; background: var(--surface-2); }
.ab-chip.active { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47, 111, 214, 0.25); }
.ab-edit-tip { font-size: 12.5px; text-align: center; }
.ab-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ab-card { gap: 10px; }
.ab-card .card-head p { font-size: 12.5px; }
.ab-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ab-controls .sel-sm { padding: 6px 28px 6px 10px; font-size: 12.5px; }
.ab-scorebox { display: flex; align-items: baseline; gap: 10px; }
.ab-score { font-size: 28px; font-variant-numeric: tabular-nums; }
.ab-score.red, .ab-lscore.red { color: var(--red); }
.ab-score.black, .ab-lscore.black { color: var(--ink); }
.ab-verdict { color: var(--muted); font-weight: 600; }
.ab-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ab-state { margin-left: auto; font-weight: 700; }
.ab-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.ab-line {
  display: grid; grid-template-columns: 62px 1fr auto; gap: 8px; align-items: baseline; padding: 7px 10px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2);
}
.ab-line:hover { border-color: var(--blue); }
.ab-lscore { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 13.5px; }
.ab-pv { font-size: 13px; line-height: 1.45; color: var(--muted); word-break: break-word; }
.ab-pv b { color: var(--text); }
.ab-ldepth { color: var(--muted); font-size: 11px; }
.ab-msg { color: var(--red); font-size: 12.5px; }
.ab-msg:empty { display: none; }
.ab-moves { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; display: grid; gap: 2px; }
.ab-moves li { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px; align-items: center; }
.ab-moves li.ab-empty { display: block; padding: 6px 0; font-size: 13px; }
.ab-no { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ab-mv { text-align: left; padding: 4px 8px; border-radius: 6px; border: 0; background: none; cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600; }
.ab-mv:hover { background: var(--surface-2); }
.ab-mv.cur { background: var(--red-50); color: var(--red); }
.ab-mv.empty { cursor: default; color: var(--muted); }
.ab-fen { width: 100%; font: 12.5px ui-monospace, SFMono-Regular, Consolas, monospace; padding: 8px 10px; }
.alt-arrow { stroke: rgba(46, 158, 91, 0.45); stroke-linecap: round; fill: none; pointer-events: none; }
.alt-arrow-head { fill: rgba(46, 158, 91, 0.45); pointer-events: none; }
@media (max-width: 1100px) {
  .ab-layout { grid-template-columns: minmax(0, 1fr); }
}
.ab-frame { width: min(100%, calc((100dvh - var(--topbar) - 170px) * var(--pz-ar, 1))); }

/* Danh sách nước của engine: nhãn chất lượng, thanh mạnh/yếu, diễn biến mẫu */
.ab-filter { color: var(--muted); font-size: 12px; }
.ab-filter:empty { display: none; }
.ab-lines { max-height: 460px; overflow-y: auto; padding-right: 2px; }
.ab-line {
  display: flex; flex-direction: column; align-items: stretch; gap: 5px; padding: 8px 10px 8px 12px;
  border-left: 4px solid var(--q, var(--line-2));
}
.ab-lhead { display: flex; align-items: baseline; gap: 8px; }
.ab-lmove { font-size: 15px; min-width: 52px; }
.ab-qtag { font-size: 11.5px; font-weight: 700; color: var(--q, var(--muted)); }
.ab-lhead .ab-lscore { margin-left: auto; }
.ab-strength { position: relative; height: 14px; border-radius: 999px; background: var(--line); overflow: hidden; }
.ab-strength i { position: absolute; inset: 0 auto 0 0; background: var(--q, var(--muted)); opacity: 0.85; transition: width 0.3s; }
.ab-strength span { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 10px; font-weight: 700; color: var(--text); }
.ab-sample { font-size: 12px; color: var(--muted); line-height: 1.45; }
.ab-line .ab-ldepth { font-size: 10.5px; }
.q-best { --q: #1f9d55; }
.q-good { --q: #4caf7a; }
.q-ok { --q: #6b8fbf; }
.q-inacc { --q: #d9a400; }
.q-mistake { --q: #e07a1f; }
.q-blunder { --q: #d63a2f; }
.ab-badge { fill: var(--q); stroke: #fff; stroke-width: 1.5; pointer-events: none; }
.ab-badge-text { fill: #fff; font-weight: 800; font-family: "Be Vietnam Pro", system-ui, sans-serif; pointer-events: none; }

/* =====================================================================
   Giao diện "thuỷ mặc": sidebar tối + trang Chơi nhanh 4 thẻ
   ===================================================================== */
:root { --serif: "Noto Serif", "Times New Roman", Georgia, serif; --ink-bg: #17110e; }

/* ---------- Sidebar tối ---------- */
.sidebar {
  background:
    radial-gradient(120% 60% at 0% 100%, rgba(140, 30, 22, 0.28), transparent 60%),
    linear-gradient(180deg, #1d1612 0%, #140f0c 100%);
  border-right: 1px solid #2a201a; color: #e9dfd3;
}
.sidebar::after { /* núi xa mờ ở chân sidebar */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 260px; pointer-events: none; opacity: 0.35;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 240 260'%3E%3Cpath d='M0 170c30-40 50-30 70-60s40-10 60 10 40-30 60-20 30 30 50 20v140H0z' fill='%23544036'/%3E%3Cpath d='M0 210c40-30 70-10 100-30s50 0 80 10 40-10 60-10v80H0z' fill='%233a2b23'/%3E%3Cg fill='%23544036'%3E%3Cpath d='M150 120h40l-6-5h-28z'/%3E%3Crect x='158' y='120' width='24' height='9'/%3E%3Cpath d='M154 110h32l-5-5h-22z'/%3E%3C/g%3E%3C/svg%3E") bottom / 100% auto no-repeat;
}
.sidebar > * { position: relative; z-index: 1; }
.brand { color: #f6eee4; }
.brand-text b { font-family: var(--serif); font-size: 22px; font-weight: 700; }
.brand-text small { color: #e0614f; }
.nav-label { color: #8a7b6e; }
.nav-item { color: #cbbfb2; font-weight: 500; }
.nav-item .ico { color: #a89887; }
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.active {
  background: linear-gradient(90deg, #b3201a, #8a1712); color: #fff; font-weight: 700;
  box-shadow: 0 6px 16px rgba(160, 25, 18, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.nav-item.active .ico { color: #ffd27a; }
.sb-promo { background: rgba(255, 255, 255, 0.05); border-color: #3a2c24; }
.sb-promo p { color: #a8998a; }
.sb-promo a, .sb-promo .ico { color: #ff8a6e; }
.sb-foot, .sb-foot a, .sb-foot .link { color: #8a7b6e; }
.sb-foot small { color: #6c5f54; }
.sb-user { margin-top: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid #3a2c24; border-radius: var(--r); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.sb-user:empty { display: none; }
.sb-user p { font-size: 12px; color: #a8998a; }
.sb-user-main { display: flex; align-items: center; gap: 10px; background: none; border: 0; color: #f3e9dd; cursor: pointer; text-align: left; padding: 0; }
.sb-user-main .avatar { width: 38px; height: 38px; border: 2px solid #c99a45; }
.sb-user-main span { flex: 1; min-width: 0; }
.sb-user-main b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-main small { color: #a8998a; font-size: 11.5px; }
.sb-user-stats { display: flex; gap: 8px; }
.sb-coin, .sb-elo { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px; background: rgba(0, 0, 0, 0.35); color: #f3e9dd; font-size: 12.5px; font-weight: 700; text-decoration: none; }
.sb-coin .ico { color: #f2c25c; }
.sb-elo .ico { color: #6fd39b; }

/* ---------- Trang Chơi nhanh ---------- */
#page-play.play2 { position: relative; }
.p2-head { position: relative; padding: 18px 0 30px; min-height: 190px; }
.p2-eyebrow { display: flex; align-items: center; gap: 12px; color: var(--red); font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; font-size: 13px; position: relative; }
.p2-eyebrow i { width: 70px; height: 2px; background: linear-gradient(90deg, var(--red), transparent); }
.p2-head h1 { position: relative; font-family: var(--serif); font-size: clamp(32px, 4.2vw, 52px); font-weight: 700; letter-spacing: -0.01em; margin: 6px 0 8px; color: #1b1310; }
.p2-lead { position: relative; color: var(--text-2); font-size: 17px; }

.p2-grid { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; align-items: stretch; }
.p2-card {
  position: relative; display: flex; flex-direction: column; gap: 12px; padding: 20px 18px 16px; border-radius: 16px; overflow: hidden; min-width: 0;
  background: linear-gradient(180deg, #fffaf1, #f6ead6); border: 1px solid #e3cfa9;
  box-shadow: 0 12px 30px rgba(60, 35, 15, 0.12), inset 0 0 0 4px rgba(255, 255, 255, 0.35);
}
.p2-card::before { /* viền trong kiểu khung tranh */
  content: ""; position: absolute; inset: 6px; border-radius: 12px; pointer-events: none;
  border: 1px solid rgba(201, 154, 69, 0.45);
}
.p2-card-head { display: flex; align-items: flex-start; gap: 12px; position: relative; }
.p2-card-head > div { flex: 1; min-width: 0; }
.p2-head-ico { width: 46px; height: 46px; flex: none; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.25)); }
.p2-card h2 { font-family: var(--serif); font-size: 26px; font-weight: 700; line-height: 1.15; }
.p2-card-head p { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.45; }
.p2-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 14px 16px; border-radius: 12px; border: 0; cursor: pointer;
  font: 700 17px var(--serif); text-decoration: none; position: relative; transition: transform 0.15s, filter 0.15s;
}
.p2-btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.05); }
.p2-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.p2-btn.gold { background: linear-gradient(180deg, #ffe39b, #e9ae45); color: #5a1a0e; box-shadow: 0 6px 18px rgba(233, 174, 69, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.12); }
.p2-btn.red { background: linear-gradient(180deg, #c42a1f, #8f1610); color: #fff; box-shadow: 0 6px 18px rgba(160, 25, 18, 0.35), inset 0 -2px 0 rgba(0, 0, 0, 0.18); }
.p2-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; font-size: 12.5px; color: var(--muted); align-items: center; position: relative; }
.p2-foot span { display: inline-flex; align-items: center; gap: 6px; }
.p2-foot .dot { width: 8px; height: 8px; }

/* 1 · Xếp hạng (đỏ) */
.p2-ranked {
  background:
    radial-gradient(90% 50% at 50% 38%, rgba(255, 190, 90, 0.28), transparent 70%),
    linear-gradient(180deg, #a31b14 0%, #7d120d 55%, #4c0b08 100%);
  border-color: #d39a4a; color: #fff5e6;
}
.p2-ranked::before { border-color: rgba(240, 190, 100, 0.55); }
.p2-ranked::after { /* đồi & cờ xí phía sau cúp */
  content: ""; position: absolute; left: 0; right: 0; top: 150px; height: 170px; pointer-events: none; opacity: 0.45;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 170'%3E%3Cpath d='M0 110c40-30 70-20 100-40s60 10 90 0 60-30 110-10v110H0z' fill='%23300605'/%3E%3Cg stroke='%23300605' stroke-width='3'%3E%3Cpath d='M40 120V40M70 110V30M240 115V35M265 120V45'/%3E%3C/g%3E%3Cg fill='%23300605'%3E%3Cpath d='M40 40l22 8-22 8zM70 30l22 8-22 8zM240 35l-22 8 22 8zM265 45l-22 8 22 8z'/%3E%3C/g%3E%3C/svg%3E") center / cover no-repeat;
}
.p2-ranked > * { position: relative; z-index: 1; }
.p2-ranked h2 { color: #fff3dc; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.p2-ranked .p2-card-head p { color: #f3d2c2; }
.p2-fee { background: rgba(0, 0, 0, 0.3); color: #ffd98a; border: 1px solid rgba(255, 217, 138, 0.4); white-space: nowrap; }
.p2-trophy { display: grid; place-items: center; margin: -6px 0 -10px; }
.p2-trophy svg { width: min(220px, 90%); height: auto; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45)); }
.p2-tc { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.p2-tc .tc-card {
  display: flex; flex-direction: column; align-items: center; gap: 0; padding: 7px 4px; border-radius: 10px; cursor: pointer;
  background: rgba(0, 0, 0, 0.28); border: 1px solid rgba(255, 217, 138, 0.25); color: #f3d2c2; min-height: 0;
}
.p2-tc .tc-card b { font-size: 15px; color: #fff; }
.p2-tc .tc-card small { font-size: 11px; }
.p2-tc .tc-card.active { background: linear-gradient(180deg, rgba(255, 217, 138, 0.3), rgba(255, 217, 138, 0.12)); border-color: #ffd98a; color: #ffe9b8; }
.p2-time {
  display: flex; flex-direction: column; align-items: center; padding: 10px 12px 12px; border-radius: 14px;
  background: linear-gradient(180deg, #2a1410, #1a0b08); border: 2px solid #c99a45; box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.4);
}
.p2-time small { font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: #e9c27a; }
.p2-time b { font-family: var(--serif); font-size: 34px; color: #fff3dc; line-height: 1.1; }
.p2-feats { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: #f3d2c2; }
.p2-feats span { display: inline-flex; align-items: center; gap: 6px; }
.p2-ranked .p2-guest span { color: #f3d2c2; }
.p2-ranked .p2-foot { color: #f3d2c2; }

/* 2 · Tranh xu (giấy) */
.p2-balance { display: inline-flex; align-self: flex-start; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: #fff3d6; border: 1px solid #ecd39b; font-size: 12.5px; color: #7a5212; }
.p2-balance .ico { color: #d39a2a; }
.p2-opts { display: flex; flex-direction: column; gap: 8px; }
.p2-opt {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; cursor: pointer;
  background: #fffdf8; border: 1px solid #ead9b9; box-shadow: 0 2px 6px rgba(60, 35, 15, 0.05);
}
.p2-opt.static { cursor: default; }
.p2-opt.active { border-color: #c42a1f; box-shadow: 0 0 0 1px #c42a1f inset; }
.p2-opt-ico { width: 30px; height: 30px; flex: none; color: #b3201a; }
.p2-opt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.p2-opt-text b { font-size: 15px; }
.p2-opt-text small { font-size: 12px; color: var(--muted); }
.p2-tcs { display: flex; flex-wrap: wrap; gap: 4px; }
.p2-tcchip { border: 1px solid #e3d2b2; background: #fff; border-radius: 999px; padding: 2px 8px; font-size: 12px; color: var(--muted); cursor: pointer; font-family: inherit; }
.p2-tcchip.active { background: #c42a1f; border-color: #c42a1f; color: #fff; font-weight: 700; }
.p2-radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #cdbb9a; flex: none; position: relative; }
.p2-opt.active .p2-radio { border-color: #c42a1f; }
.p2-opt.active .p2-radio::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: #c42a1f; }
.p2-stakes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: -4px; }
.p2-stake { padding: 8px 4px; border-radius: 10px; border: 1px solid #ecd39b; background: #fff8e6; color: #7a5212; font-weight: 700; font-size: 13px; cursor: pointer; font-family: inherit; }
.p2-stake.active { background: linear-gradient(180deg, #ffe39b, #e9ae45); border-color: #c98a22; color: #5a1a0e; }
.p2-stake:disabled { opacity: 0.45; cursor: not-allowed; }
.p2-coin .p2-btn { margin-top: auto; }
.p2-coin-art { width: calc(100% + 36px); margin: -4px -18px -16px; height: auto; display: block; }

/* 3 · Bàn đấu (tối) */
.p2-tables { background: linear-gradient(180deg, #2a221d, #17110e); border-color: #4a3a2e; color: #f1e7da; }
.p2-tables::before { border-color: rgba(201, 154, 69, 0.3); }
.p2-tables h2 { color: #fff3dc; }
.p2-tables .p2-card-head p { color: #b8a898; }
.p2-all { align-self: flex-end; display: inline-flex; align-items: center; gap: 2px; color: #e9c27a; font-size: 12.5px; font-weight: 700; text-decoration: underline; white-space: nowrap; }
.p2-table-list { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.p2-table {
  display: grid; grid-template-columns: 66px 1fr; grid-template-areas: "thumb info" "thumb watch"; gap: 4px 12px; align-items: start;
  padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid #3d3027;
}
.p2-thumb { grid-area: thumb; width: 66px; aspect-ratio: 0.9; border-radius: 6px; overflow: hidden; background: #e9c98f; border: 2px solid #8a6a3e; }
.p2-thumb svg { width: 100%; height: 100%; display: block; }
.p2-tinfo { grid-area: info; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.p2-trow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.p2-trow b { font-family: var(--serif); font-size: 16px; color: #fff3dc; }
.p2-count { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; color: #b8a898; }
.p2-live { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: #ff7b6b; margin-left: auto; }
.p2-live i { width: 7px; height: 7px; border-radius: 50%; background: #ff4b3a; box-shadow: 0 0 0 3px rgba(255, 75, 58, 0.2); }
.p2-pl { display: flex; align-items: center; gap: 6px; font-size: 13px; min-width: 0; }
.p2-pl span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p2-pl em { font-style: normal; color: #b8a898; font-size: 11.5px; margin-left: auto; }
.p2-side { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font: 700 11px "LXGW WenKai TC", "Noto Serif TC", serif; flex: none; background: #f3e2c1; border: 1.5px solid #b98d4f; font-style: normal; }
.p2-side.r { color: #c42a1f; }
.p2-side.b { color: #1b1310; }
.p2-tmeta { color: #8f8072; font-size: 11px; }
.p2-watch {
  grid-area: watch; justify-self: end; display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  background: transparent; color: #f1e7da; border: 1px solid #6a5848; font-size: 12.5px; font-family: inherit;
}
.p2-watch:hover { background: rgba(255, 255, 255, 0.08); }
.p2-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 30px 10px; color: #b8a898; font-size: 13px; border: 1px dashed #4a3a2e; border-radius: 12px; }
.p2-empty b { color: #f1e7da; font-size: 14px; }
.p2-empty-ico { width: 44px; height: 44px; opacity: 0.8; }
.p2-foot.light { color: #b8a898; }

/* 4 · Đánh với bạn (giấy + tranh) */
.p2-friend-art { width: calc(100% + 36px); margin: -6px -18px 0; height: auto; display: block; }
.p2-code { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 12px; background: #fffdf8; border: 1px solid #ead9b9; }
.p2-code label { font-size: 11.5px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: #b36a1f; }
.p2-code-row { display: flex; gap: 6px; }
.p2-code-row input { flex: 1; min-width: 0; font: 700 22px var(--serif); letter-spacing: 0.12em; border: 0; background: transparent; padding: 2px 0; text-transform: uppercase; color: #1b1310; }
.p2-code-row input:focus { outline: none; }
.p2-mini { width: 38px; height: 38px; border-radius: 10px; border: 1px solid #ead9b9; background: #fff; display: grid; place-items: center; cursor: pointer; color: #b3201a; }
.p2-friend-acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.p2-ghost { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 8px; border-radius: 10px; border: 1px solid #ead9b9; background: #fffdf8; color: var(--text-2); font-size: 12.5px; font-weight: 600; text-decoration: none; }
.p2-ghost:hover { border-color: #c99a45; }
.p2-friend .p2-btn { margin-top: auto; }

@media (max-width: 1280px) {
  .p2-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .p2-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Tinh chỉnh khi thẻ hẹp */
.p2-card-head { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; }
.p2-card-head > div { display: contents; }
.p2-card-head h2 { grid-column: 2; white-space: nowrap; font-size: clamp(20px, 1.7vw, 26px); }
.p2-card-head p { grid-column: 1 / -1; margin-top: 8px; }
.p2-head-ico { width: 40px; height: 40px; grid-row: 1; }
.p2-fee, .p2-all { position: absolute; top: -4px; right: -4px; font-size: 11.5px; }
.p2-tcs { gap: 4px; }
.p2-tcchip { padding: 2px 7px; white-space: nowrap; }
.p2-stakes { grid-template-columns: repeat(auto-fit, minmax(58px, 1fr)); }
.p2-stake { white-space: nowrap; }
.p2-opt { padding: 10px 12px; gap: 10px; }
.p2-opt-ico { width: 24px; height: 24px; }
.p2-ranked .p2-guest input { background: rgba(255, 255, 255, 0.92); }

/* ---------- Bố cục đóng khung: cả web (menu + nội dung) nằm giữa, hai bên là khoảng trống ---------- */
:root { --frame: 1440px; }
@media (min-width: 1500px) {
  body {
    background:
      radial-gradient(60% 50% at 0% 0%, rgba(160, 30, 22, 0.10), transparent 70%),
      radial-gradient(60% 50% at 100% 100%, rgba(160, 30, 22, 0.08), transparent 70%),
      repeating-linear-gradient(45deg, rgba(60, 40, 25, 0.035) 0 2px, transparent 2px 14px),
      #e9e2d6;
    background-attachment: fixed;
  }
  .shell {
    max-width: var(--frame); margin: 0 auto; background: var(--bg);
    box-shadow: 0 0 0 1px rgba(60, 40, 25, 0.08), 0 20px 60px rgba(40, 25, 15, 0.18);
  }
}

/* ---------- Tranh thuỷ mặc nền chung cho mọi trang ---------- */
.main { position: relative; }
.ink-scene { position: absolute; top: 0; right: 0; width: min(760px, 70%); height: 340px; pointer-events: none; z-index: 0; overflow: hidden; }
.ink-svg {
  position: absolute; top: 0; right: 0; width: 100%; height: 100%; opacity: 0.8;
  /* mờ dần ở mép trái và mép dưới để không có đường cắt cứng */
  -webkit-mask-image: linear-gradient(to right, transparent 0%, #000 35%), linear-gradient(to bottom, #000 55%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to right, transparent 0%, #000 35%), linear-gradient(to bottom, #000 55%, transparent 100%);
  mask-composite: intersect;
}
@media (max-width: 1200px) { .ink-svg { opacity: 0.55; } }
.ink-vtext { position: absolute; right: 18px; top: calc(var(--topbar) + 14px); writing-mode: vertical-rl; font: 600 18px/1.3 "LXGW WenKai TC", "Noto Serif TC", serif; color: #3a2a22; letter-spacing: 4px; opacity: 0.7; }
.ink-vtext i { display: block; width: 16px; height: 16px; margin-top: 8px; border: 2px solid var(--red); border-radius: 3px; }
.main > .page-msg, .main > .screen { position: relative; z-index: 1; }
body[data-screen="game"] .ink-scene { display: none; }
/* chừa chỗ để tiêu đề trang không đè lên cột chữ dọc */
.screen.page > .page-head, .p2-head { padding-right: 48px; }
@media (max-width: 860px) {
  .ink-scene { width: 100%; opacity: 0.55; height: 260px; }
  .ink-vtext { display: none; }
}

/* ---------- Chơi nhanh: thẻ là lối vào (bấm cả thẻ để mở trang riêng) ---------- */
a.p2-entry { text-decoration: none; color: inherit; cursor: pointer; transition: transform 0.18s, box-shadow 0.18s; }
a.p2-entry:hover { transform: translateY(-4px); box-shadow: 0 18px 40px rgba(60, 35, 15, 0.22), inset 0 0 0 4px rgba(255, 255, 255, 0.35); }
a.p2-entry:focus-visible { outline: 3px solid #e9ae45; outline-offset: 3px; }
a.p2-entry .p2-btn { margin-top: auto; pointer-events: none; }
a.p2-ranked { color: #fff5e6; }
a.p2-tables { color: #f1e7da; }
.p2-points { margin: 0; padding: 0 0 0 18px; display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-2); }
.p2-points.light { color: #f3d2c2; }
.p2-points li::marker { color: #c99a45; }
.p2-btn.dark { background: linear-gradient(180deg, #4a3a2e, #2e231c); color: #f3e2c1; border: 1px solid #6a5848; }
.p2-entry .p2-table { grid-template-areas: "thumb info"; }
.p2-entry .p2-empty { padding: 22px 10px; }

/* ---------- Trang chi tiết: Xếp hạng / Tranh xu ---------- */
.p2-detail { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; align-items: start; position: relative; }
.p2-panel {
  position: relative; display: flex; gap: 24px; padding: 26px; border-radius: 18px; overflow: hidden;
  background: linear-gradient(180deg, #fffaf1, #f6ead6); border: 1px solid #e3cfa9; box-shadow: 0 12px 30px rgba(60, 35, 15, 0.12);
}
.p2-panel::before { content: ""; position: absolute; inset: 7px; border-radius: 13px; border: 1px solid rgba(201, 154, 69, 0.45); pointer-events: none; }
.p2-panel-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; position: relative; z-index: 1; }
.p2-panel h3 { font-family: var(--serif); font-size: 20px; }
.p2-ranked-panel {
  background: radial-gradient(70% 60% at 22% 40%, rgba(255, 190, 90, 0.25), transparent 70%), linear-gradient(160deg, #a31b14, #7d120d 55%, #4c0b08);
  border-color: #d39a4a; color: #fff5e6;
}
.p2-ranked-panel::before { border-color: rgba(240, 190, 100, 0.55); }
.p2-ranked-panel h3 { color: #fff3dc; }
.p2-panel-art { flex: 0 0 34%; display: grid; place-items: center; position: relative; z-index: 1; }
.p2-panel-art svg { width: 100%; max-width: 280px; height: auto; filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.45)); }
.p2-tc.big { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.p2-tc.big .tc-card { padding: 14px 8px; gap: 4px; }
.p2-tc.big .tc-card b { font-size: 24px; font-family: var(--serif); }
.p2-tc.big .tc-card small { font-size: 12px; text-align: center; }
.p2-ranked-panel .p2-time b { font-size: 40px; }
.p2-elo { font-size: 13.5px; color: #f3d2c2; }
.p2-ranked-panel .p2-foot { justify-content: flex-start; color: #f3d2c2; }
.p2-ranked-panel .p2-fee { position: static; }
.p2-ranked-panel .p2-guest span { color: #f3d2c2; }
.p2-row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.p2-coin-panel { flex-direction: column; gap: 0; padding-bottom: 0; }
.p2-coin-panel .p2-coin-art { width: calc(100% + 52px); margin: 10px -26px 0; }
.p2-coin-panel .p2-stakes { grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 0; }
.p2-coin-panel .p2-stake { padding: 12px 6px; font-size: 15px; }
.p2-coin-panel .p2-opt { padding: 14px 16px; }
.p2-coin-panel .p2-opt-text b { font-size: 16px; }
.p2-coin-panel .p2-tcchip { padding: 4px 12px; font-size: 13px; }
.p2-coin-panel .p2-foot { justify-content: flex-start; }
.p2-aside { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.p2-aside .card h3 { font-family: var(--serif); font-size: 18px; }
.p2-back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; font-size: 13.5px; text-decoration: none; align-self: flex-start; position: relative; }
.p2-back:hover { color: var(--red); }

/* ---------- Trang Bàn đấu ---------- */
.p2-tables-page {
  position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px;
  padding: 18px; border-radius: 18px; background: linear-gradient(180deg, #2a221d, #17110e); border: 1px solid #4a3a2e; color: #f1e7da;
  box-shadow: 0 12px 30px rgba(60, 35, 15, 0.18);
}
.p2-tables-page .p2-table { grid-template-columns: 96px 1fr; }
.p2-tables-page .p2-thumb { width: 96px; }
.p2-tables-page .p2-empty { grid-column: 1 / -1; padding: 50px 10px; }

@media (max-width: 1000px) {
  .p2-detail { grid-template-columns: minmax(0, 1fr); }
  .p2-panel { flex-direction: column; }
  .p2-panel-art { flex-basis: auto; }
  .p2-panel-art svg { max-width: 200px; }
}
@media (max-width: 520px) {
  .p2-tc.big { grid-template-columns: 1fr; }
  .p2-coin-panel .p2-stakes { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Thẻ bậc rank (trang Xếp hạng) ---------- */
.p2-rankcard {
  --rank: #c9d3df;
  display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "badge info elo" "next next next"; gap: 12px 16px; align-items: center;
  padding: 16px 18px; border-radius: 14px; background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.2));
  border: 1px solid rgba(255, 217, 138, 0.3);
}
.p2-rank-badge {
  grid-area: badge; width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; position: relative;
  background: radial-gradient(circle at 35% 30%, #fff 0%, var(--rank) 45%, color-mix(in srgb, var(--rank) 55%, #000) 100%);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.35), 0 0 0 5px var(--rank), 0 8px 18px rgba(0, 0, 0, 0.45), 0 0 26px color-mix(in srgb, var(--rank) 60%, transparent);
}
.p2-rank-badge span {
  width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; background: #f4e2bd; border: 2px solid #8f5a12;
  font: 700 26px "LXGW WenKai TC", "Noto Serif TC", serif; color: #8a1712;
}
.p2-rank-info { grid-area: info; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.p2-rank-info small, .p2-rank-elo small { font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: #e9c27a; }
.p2-rank-info b { font-family: var(--serif); font-size: 26px; color: var(--rank); line-height: 1.15; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.p2-rank-stars { display: flex; gap: 3px; font-size: 16px; }
.p2-rank-stars i { font-style: normal; color: rgba(255, 255, 255, 0.22); }
.p2-rank-stars i.on { color: #ffd27a; text-shadow: 0 0 8px rgba(255, 210, 122, 0.6); }
.p2-rank-elo { grid-area: elo; display: flex; flex-direction: column; align-items: flex-end; }
.p2-rank-elo b { font-family: var(--serif); font-size: 38px; color: #fff3dc; line-height: 1; }
.p2-rank-next { grid-area: next; display: flex; flex-direction: column; gap: 6px; }
.p2-rank-bar { height: 8px; border-radius: 999px; background: rgba(0, 0, 0, 0.4); overflow: hidden; }
.p2-rank-bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #e9ae45, var(--rank)); transition: width 0.4s; }
.p2-rank-next small { font-size: 12.5px; color: #f3d2c2; }
.p2-ranked-panel .p2-time span { font-size: 12px; color: #c9a87a; }
@media (max-width: 520px) {
  .p2-rankcard { grid-template-columns: auto 1fr; grid-template-areas: "badge info" "elo elo" "next next"; }
  .p2-rank-elo { align-items: flex-start; }
}

/* ---------- Tranh xu: bàn đang chờ ---------- */
.p2-note { font-size: 12.5px; color: var(--muted); text-align: center; margin-top: -4px; }
.p2-waiting { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow-y: auto; }
.p2-wait-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.p2-wait-row .avatar { width: 32px; height: 32px; font-size: 12px; }
.p2-wait-info { min-width: 0; display: flex; flex-direction: column; }
.p2-wait-info b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p2-wait-info small { color: var(--muted); font-size: 12px; }
.p2-wait-stake { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: #9c6421; font-size: 13px; }
.p2-wait-stake .ico { color: #d39a2a; }
.p2-wait-empty { font-size: 13px; }

/* =====================================================================
   Bàn đấu kiểu "sân cờ": đối thủ & nút thao tác bên trái, bàn cờ ở giữa,
   biên bản · trò chuyện · thẻ của bạn bên phải (màn hình ≥ 1100px, khi đang chơi / xem)
   ===================================================================== */
@media (min-width: 1100px) {
  #game:not(.ended) { max-width: none; padding: 8px 16px 12px; gap: 6px; }
  #game:not(.ended) .game-head .lead { font-size: 12px; }
  #game:not(.ended) .head-acts .btn { padding: 5px 10px; font-size: 12.5px; }
  #game:not(.ended) .game-head h1 { display: none; }
  #game:not(.ended) .game-head { align-items: center; }
  #game:not(.ended) .game-head > div { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
  #game:not(.ended) .game-head .eyebrow { margin: 0; }
  #game:not(.ended) .game-head .lead { margin: 0; }

  /* Gỡ 2 khung bọc để các thẻ con xếp thẳng vào lưới 3 cột */
  #game:not(.ended) .board-col, #game:not(.ended) .game-side { display: contents; }
  #game:not(.ended) .board-col { --bw: var(--arena-bw); } /* khung cũ tự đặt --bw riêng → ghi đè bằng độ rộng của lưới */
  #game:not(.ended) .game-grid {
    --side-l: 184px; --side-r: 270px;
    --arena-bw: min(calc(min(100vw, var(--frame, 1440px)) - var(--sidebar) - var(--side-l) - var(--side-r) - 84px),
              calc((100dvh - var(--topbar) - 66px) * var(--board-ar, 1)));
    grid-template-columns: var(--side-l) var(--arena-bw) var(--side-r);
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: calc(var(--arena-bw) / var(--board-ar, 1)); /* lưới cao đúng bằng bàn cờ → các ô hai bên tự co, cuộn bên trong */
    grid-template-areas:
      "opp  board moves"
      "eval board chat"
      "acts board me";
    gap: 14px 18px; justify-content: center; align-items: stretch;
  }
  #game:not(.ended) .board-frame { grid-area: board; width: var(--bw); align-self: start; border: 6px solid #b98a4e; border-radius: 12px; box-shadow: 0 18px 40px rgba(60, 35, 15, 0.28), inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
  #game:not(.ended) .board-col > .player { width: auto; min-width: 0; }
  #game:not(.ended) #p-top { grid-area: opp; }
  #game:not(.ended) #p-bottom { grid-area: me; }
  #game:not(.ended) .moves-card { grid-area: moves; min-height: 0; max-height: 210px; }
  /* Đấu máy không có trò chuyện → thẻ Máy phân tích nằm ở ô giữa bên phải, cuộn bên trong */
  #game:not(.ended) .eval-card { grid-area: chat; align-self: stretch; min-height: 0; overflow-y: auto; }
  #game:not(.ended) .chat-card { grid-area: chat; align-self: stretch; min-height: 0; }
  #game:not(.ended) .actions-card { grid-area: acts; align-self: end; }
  #game:not(.ended) .moves-card, #game:not(.ended) .chat-card, #game:not(.ended) .eval-card { padding: 12px; gap: 8px; }
  #game:not(.ended) .chat-card #chat-log { max-height: 160px; }

  /* Thẻ người chơi dạng chân dung (khung gỗ sẫm) */
  #game:not(.ended) .player {
    flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; min-height: 0; text-align: center;
    background: linear-gradient(180deg, #5a3622, #3a2216); border: 2px solid #b98a4e; border-radius: 10px;
    box-shadow: 0 10px 24px rgba(40, 20, 10, 0.3), inset 0 0 0 2px rgba(0, 0, 0, 0.25); color: #f6e7cf;
  }
  #game:not(.ended) .player.turn { border-color: #ffd27a; box-shadow: 0 0 0 3px rgba(255, 210, 122, 0.35), 0 10px 24px rgba(40, 20, 10, 0.3); }
  #game:not(.ended) .player.me { background: linear-gradient(180deg, #6a2a1c, #3e1910); }
  #game:not(.ended) .pc-avatar { width: 100%; height: auto; aspect-ratio: 1; max-height: 96px; margin: 0 auto; max-width: 96px; }
  #game:not(.ended) .pc-avatar img, #game:not(.ended) .pc-initial {
    border-radius: var(--av-r); font-size: 44px; font-family: var(--serif); border: 2px solid #c99a45;
    background: radial-gradient(circle at 40% 30%, #8a5a3a, #2b1a12); color: #f3dfb8;
  }
  #game:not(.ended) .player.me .pc-initial { background: radial-gradient(circle at 40% 30%, #b3372a, #4a120c); }
  #game:not(.ended) .pc-initial.ai { background: radial-gradient(circle at 40% 30%, #4d5f84, #1c2335); font-size: 36px; }
  #game:not(.ended) .pc-ring { inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); }
  #game:not(.ended) .pc-side { width: 22px; height: 22px; right: 4px; bottom: 4px; border-color: #f6e7cf; }
  #game:not(.ended) .pc-info { align-items: center; }
  #game:not(.ended) .pc-name { font-family: var(--serif); font-size: 19px; color: #fff3dc; max-width: 100%; }
  #game:not(.ended) .pc-sub { color: #d9bf98; white-space: normal; font-size: 12px; line-height: 1.35; }
  #game:not(.ended) .pc-sub .off { color: #ff9b8a; }
  #game:not(.ended) .player .clock { align-items: center; }
  #game:not(.ended) .player .clock b {
    background: transparent; border: 0; color: #ffe2a8; font-family: var(--serif); font-size: 30px; font-weight: 700; padding: 0; min-width: 0;
  }
  #game:not(.ended) .player .clock.running b { color: #fff; text-shadow: 0 0 12px rgba(255, 210, 122, 0.8); background: transparent; }
  #game:not(.ended) .player .clock small { color: #d9bf98; }

  /* Nút thao tác kiểu nút gỗ (cột trái, dưới) */
  #game:not(.ended) .actions-card { background: transparent; border: 0; box-shadow: none; padding: 0; gap: 8px; }
  #game:not(.ended) .actions-card .status-box { font-size: 12.5px; padding: 8px 10px; }
  #game:not(.ended) .actions { grid-template-columns: 1fr; gap: 8px; }
  #game:not(.ended) .actions .btn {
    justify-content: center; padding: 9px 10px; border-radius: 10px; font-weight: 700; font-family: var(--serif);
    background: linear-gradient(180deg, #f0cf96, #c99550); border: 1px solid #8a5a2b; color: #4a2410;
    box-shadow: 0 3px 0 #8a5a2b, 0 6px 12px rgba(60, 35, 15, 0.2);
  }
  #game:not(.ended) .actions .btn:hover:not(:disabled) { filter: brightness(1.06); }
  #game:not(.ended) .actions .btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #8a5a2b; }
  #game:not(.ended) .actions .btn.danger { background: linear-gradient(180deg, #d9573f, #a3261a); color: #fff; border-color: #6e160e; box-shadow: 0 3px 0 #6e160e, 0 6px 12px rgba(60, 35, 15, 0.2); }
  #game:not(.ended) .actions .btn.ghost { background: linear-gradient(180deg, #e9dcc6, #cdbb9c); }
  #game:not(.ended) .actions .btn .ico { color: inherit; }
}

/* ---------- Vào bàn cờ: menu trái thu gọn thành cột biểu tượng ---------- */
@media (min-width: 861px) {
  body[data-screen="game"] { --sidebar: 76px; }
  .sidebar { transition: width 0.25s ease, padding 0.25s ease; }
  body[data-screen="game"] .sidebar { padding: 14px 10px; overflow-x: hidden; }
  body[data-screen="game"] .brand { justify-content: center; padding: 2px 0 14px; }
  body[data-screen="game"] .brand-mark { width: 40px; height: 40px; }
  body[data-screen="game"] .brand-text,
  body[data-screen="game"] .nav-label,
  body[data-screen="game"] .nav-item > span,
  body[data-screen="game"] .sb-promo,
  body[data-screen="game"] .sb-foot,
  body[data-screen="game"] .sb-user-main > span,
  body[data-screen="game"] .sb-user-main > .ico,
  body[data-screen="game"] .sb-user-stats,
  body[data-screen="game"] .sb-user p { display: none; }
  body[data-screen="game"] .nav { margin-top: 6px; }
  body[data-screen="game"] .nav-item { justify-content: center; padding: 12px 0; position: relative; }
  body[data-screen="game"] .nav-item .ico { width: 21px; height: 21px; }
  body[data-screen="game"] .sb-user { margin-top: auto; padding: 6px; align-items: center; background: none; border: 0; }
  body[data-screen="game"] .sb-user .btn { padding: 8px 0; font-size: 0; }
  body[data-screen="game"] .sb-user .btn::before { content: "↪"; font-size: 16px; }
  body[data-screen="game"] .sb-user-main { justify-content: center; }
  body[data-screen="game"] .sidebar::after { opacity: 0.18; }
}

/* Ván tranh xu đang chơi: bỏ lịch sử nước đi, ô trò chuyện chiếm cả phần trên cột phải */
@media (min-width: 1100px) {
  #game[data-live="coin"]:not(.ended) .moves-card { display: none; }
  #game[data-live="coin"]:not(.ended) .game-grid {
    grid-template-areas:
      "opp  board chat"
      "eval board chat"
      "acts board me";
  }
}
@media (max-width: 1099px) {
  #game[data-live="coin"]:not(.ended) .moves-card { display: none; }
}

/* ---------- Đầu trang thống nhất: gọn, cùng cỡ ở mọi mục để nội dung chính hiện ngay ---------- */
.screen.page { padding-top: 18px; gap: 14px; }
.page-head, .p2-head { min-height: 0; padding: 0; }
.page-head h1, .p2-head h1 {
  font-family: var(--serif); font-size: 26px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; margin: 2px 0 0; color: var(--text);
}
.eyebrow, .p2-eyebrow { font-size: 11.5px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--red); margin: 0; }
.p2-eyebrow i { width: 48px; }
.lead, .p2-lead { color: var(--muted); font-size: 13.5px; margin-top: 3px; line-height: 1.45; }
.p2-head { padding-right: 48px; }

/* Thẻ trang Chơi nhanh gọn hơn để nút bấm cuối thẻ hiện trong một màn hình */
.p2-card { padding: 16px 16px 14px; gap: 10px; }
.p2-card-head p { margin-top: 4px; }
.p2-trophy { margin: -8px 0 -12px; }
.p2-trophy svg { width: min(150px, 70%); }
.p2-time { padding: 8px 10px 10px; }
.p2-time b { font-size: 28px; }
.p2-friend-art { margin-top: -10px; max-height: 120px; }
.p2-coin-art { max-height: 64px; }
.p2-entry .p2-btn { padding: 12px 14px; font-size: 16px; }
.p2-entry .p2-opt { padding: 9px 12px; }
.p2-entry .p2-table { padding: 8px; }

/* ---------- Nút Quay lại: luôn ở góc trên bên trái (thanh trên cùng) ---------- */
.top-back {
  display: inline-flex; align-items: center; gap: 6px; flex: none; height: 36px; padding: 0 12px 0 8px; border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--text-2); font-weight: 600; font-size: 13px;
}
.top-back:hover { border-color: var(--red); color: var(--red); }
.top-back .ico { width: 18px; height: 18px; }
@media (max-width: 860px) {
  .top-back { padding: 0 8px; }
  .top-back span { display: none; }
}
/* Nút Quay lại đặt ở đầu nội dung: cùng hàng với dòng chữ đỏ phía trên tiêu đề */
.top-back.in-page { height: 26px; padding: 0 10px 0 6px; font-size: 12px; border-radius: 8px; vertical-align: middle; margin-right: 10px; }
.top-back.in-page .ico { width: 15px; height: 15px; }
.top-back.in-page + .eyebrow, .top-back.in-page + .p2-eyebrow { display: inline-flex; vertical-align: middle; }

/* ---------- Tab Phân tích: bố cục giống bàn đấu (biên bản | bàn cờ | engine) ---------- */
.ab-layout { grid-template-columns: 230px minmax(0, auto) 330px; justify-content: center; gap: 18px; align-items: start; }
.ab-left, .ab-right { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ab-left .ab-moves { max-height: calc(100dvh - var(--topbar) - 480px); min-height: 140px; }
.ab-right .ab-lines { max-height: calc(100dvh - var(--topbar) - 520px); min-height: 160px; }
/* Bàn cờ cao gần hết màn hình (trừ đầu trang, thanh tab, thanh công cụ) */
.ab-frame {
  width: min(calc(min(100vw, var(--frame, 1440px)) - var(--sidebar) - 230px - 330px - 120px),
             calc((100dvh - var(--topbar) - 290px) * var(--pz-ar, 1)));
  border: 6px solid #b98a4e; border-radius: 12px; box-shadow: 0 18px 40px rgba(60, 35, 15, 0.28);
}
.ab-board-row { width: auto; }
.ab-evalbar { width: 18px; }
@media (max-width: 1200px) {
  .ab-layout { grid-template-columns: minmax(0, 1fr) 320px; grid-template-areas: "main right" "left right"; }
  .ab-left { grid-area: left; }
  .ab-main { grid-area: main; }
  .ab-right { grid-area: right; }
  .ab-frame { width: min(100%, calc((100dvh - var(--topbar) - 250px) * var(--pz-ar, 1))); }
}
@media (max-width: 860px) {
  .ab-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "right" "left"; }
  .ab-frame { width: 100%; }
}
.ab-left .card-head { flex-direction: column; align-items: flex-start; gap: 2px; }

/* "Quay lại" chỉ hiện như dòng chữ (không khung nút), vẫn bấm được */
.top-back, .top-back.in-page {
  background: none; border: 0; box-shadow: none; padding: 0; height: auto; border-radius: 0;
  color: var(--muted); font-weight: 600; font-size: 12.5px; gap: 3px;
}
.top-back:hover, .top-back.in-page:hover { color: var(--red); background: none; }
.top-back.in-page { margin-right: 12px; }
.top-back.in-page .ico, .top-back .ico { width: 14px; height: 14px; }

/* Hàng tab: bỏ thanh cuộn (▲●▼) ở cuối hàng */
.tabs { overflow-y: hidden; scrollbar-width: none; -ms-overflow-style: none; }
.tabs::-webkit-scrollbar { display: none; }

/* Bỏ phần giới thiệu (tiêu đề lớn + mô tả) ở đầu các trang — chỉ giữ dòng mục nhỏ & "Quay lại" để nội dung lên cao.
   Màn hình bàn cờ giữ tiêu đề (dùng để báo kết quả ván). */
.screen.page:not(#game) > header h1,
.screen.page:not(#game) > header .lead,
.screen.page:not(#game) > header .p2-lead { display: none; }
.screen.page:not(#game) > header { padding-bottom: 2px; }
.ab-saverow { display: flex; justify-content: center; }
.ab-saverow .btn { min-width: 180px; justify-content: center; }
/* Bàn cờ phân tích không bao giờ co về 0: hàng bàn cờ rộng hết cột, bàn tối thiểu 280px */
.ab-board-row { width: 100%; justify-content: center; }
.ab-frame { width: min(calc(100% - 28px), max(280px, calc((100dvh - var(--topbar) - 235px) * var(--pz-ar, 1)))); flex: none; }
@media (min-width: 1201px) {
  .ab-frame {
    width: min(calc(min(100vw, var(--frame, 1440px)) - var(--sidebar) - 230px - 330px - 120px),
               max(280px, calc((100dvh - var(--topbar) - 235px) * var(--pz-ar, 1))));
  }
}

/* Phân tích: nút Lưu cùng hàng với các nút khác (nhấn mạnh nhẹ), thanh thế trận ngang dưới Biên bản */
.ab-toolbar .ab-save { background: var(--red); border-color: var(--red); color: #fff; }
.ab-toolbar .ab-save:hover { background: var(--red-600); }
.ab-evalcard .card-head { align-items: center; }
.ab-evalcard .card-head span { font-weight: 800; font-variant-numeric: tabular-nums; }
.ab-evalbar.h { position: relative; width: 100%; height: 14px; border-radius: 999px; background: var(--ink); border: 1px solid var(--line-2); overflow: hidden; }
.ab-evalbar.h i { position: absolute; left: 0; top: 0; bottom: 0; right: auto; height: 100%; width: 50%; background: var(--red); transition: width 0.35s; }
.ab-evalbar.h::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: rgba(255, 255, 255, 0.7); }
/* Bàn cờ to hơn: không còn thanh dọc & khung FEN */
@media (min-width: 1201px) {
  .ab-layout { grid-template-columns: 220px minmax(0, auto) 320px; gap: 16px; }
  .ab-frame {
    width: min(calc(min(100vw, var(--frame, 1440px)) - var(--sidebar) - 220px - 320px - 96px),
               max(280px, calc((100dvh - var(--topbar) - 200px) * var(--pz-ar, 1))));
  }
}
/* Hàng nút dưới bàn cờ phân tích: một dòng, các nút cùng cỡ */
.ab-toolbar { flex-wrap: nowrap; gap: 5px; }
.ab-toolbar .btn { height: 32px; padding: 0 10px; font-size: 12.5px; white-space: nowrap; }
.ab-toolbar .ab-sep { margin: 0 2px; }
@media (max-width: 1200px) { .ab-toolbar { flex-wrap: wrap; } }
.ab-left .ab-evalcard .card-head { flex-direction: row; justify-content: space-between; align-items: center; }

/* Biểu đồ thế trận theo từng nước (tab Phân tích) */
.ab-chart { position: relative; height: 110px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line-2); cursor: pointer; }
.ab-chart svg { display: block; width: 100%; height: 100%; }
.ab-chart .ch-red-bg { fill: #fdf1ee; }
.ab-chart .ch-black-bg { fill: #f1ece6; }
.ab-chart .ch-red { fill: rgba(198, 29, 29, 0.55); }
.ab-chart .ch-black { fill: rgba(27, 22, 18, 0.55); }
.ab-chart .ch-line { fill: none; stroke: #5a3622; stroke-width: 1.6; stroke-linejoin: round; }
.ab-chart .ch-mid { stroke: rgba(0, 0, 0, 0.35); stroke-width: 1; stroke-dasharray: 3 3; }
.ab-chart .ch-cur { stroke: var(--blue); stroke-width: 1.5; }
.ab-chart .ch-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--blue); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); pointer-events: none; }
.ab-chart[data-pending]:not([data-pending=""])::after { content: attr(data-pending); position: absolute; right: 6px; bottom: 4px; font-size: 10.5px; color: var(--muted); background: rgba(255, 255, 255, 0.8); padding: 0 4px; border-radius: 4px; }
.ab-chart-note { color: var(--muted); font-size: 11px; line-height: 1.35; }
/* Lưới & nhãn của biểu đồ thế trận */
.ab-chart { height: 140px; }
.ab-chart .ch-grid { stroke: rgba(90, 54, 34, 0.18); stroke-width: 1; }
.ab-chart .ch-grid.v { stroke: rgba(90, 54, 34, 0.12); }
.ab-chart .ch-ylab {
  position: absolute; left: 3px; transform: translateY(-50%); font-size: 9.5px; font-weight: 700; line-height: 1;
  color: var(--muted); background: rgba(255, 255, 255, 0.75); padding: 1px 3px; border-radius: 3px; pointer-events: none;
}
.ab-chart .ch-ylab.red { color: var(--red); }
.ab-chart .ch-ylab.black { color: var(--ink); }
.ab-chart .ch-xlab {
  position: absolute; bottom: 2px; transform: translateX(-50%); font-size: 9.5px; color: var(--muted); line-height: 1;
  background: rgba(255, 255, 255, 0.7); padding: 0 2px; border-radius: 3px; pointer-events: none;
}
.sb-credits { line-height: 1.4; }
.sb-credits a { color: #a8998a; text-decoration: underline; }

/* Trang Xếp hạng / Tranh xu khi hẹp: cột phụ xuống dưới, cúp nhỏ lại, thẻ rank tự xếp dọc theo bề rộng thật */
@media (max-width: 1200px) {
  .p2-detail { grid-template-columns: minmax(0, 1fr); }
}
.p2-panel-body { container-type: inline-size; }
@media (max-width: 1300px) {
  .p2-panel-art { flex: 0 0 150px; }
  .p2-panel-art svg { max-width: 150px; }
}
@container (max-width: 440px) {
  .p2-rankcard { grid-template-columns: auto 1fr; grid-template-areas: "badge info" "elo elo" "next next"; }
  .p2-rank-elo { flex-direction: row; align-items: baseline; gap: 8px; }
  .p2-rank-elo b { font-size: 28px; }
  .p2-rank-info b { font-size: 22px; }
  .p2-ranked-panel .p2-time b { font-size: 30px; }
}
.p2-rank-info small { white-space: nowrap; }
.p2-time b { white-space: nowrap; }

/* ---------- Cộng đồng (trang chủ) ---------- */
.cm-card { gap: 12px; }
.cm-feed {
  display: flex; flex-direction: column; gap: 10px; max-height: 420px; min-height: 160px; overflow-y: auto;
  padding: 10px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line);
}
.cm-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 8px; }
.cm-msg { display: flex; gap: 10px; align-items: flex-start; }
.cm-msg .avatar { width: 34px; height: 34px; flex: none; font-size: 13px; }
.cm-body { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; padding: 8px 12px; }
.cm-msg.mine .cm-body { background: var(--red-50); border-color: var(--red-100, #f3cfc9); }
.cm-meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.cm-meta b { font-size: 13.5px; }
.cm-elo { color: var(--muted); font-size: 11.5px; }
.cm-meta small { color: var(--faint); font-size: 11.5px; }
.cm-del { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 11.5px; cursor: pointer; padding: 0; }
.cm-del:hover { color: var(--red); }
.cm-text { margin-top: 3px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.cm-pos { display: flex; gap: 12px; align-items: center; margin-top: 8px; padding: 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.cm-board { width: 120px; flex: none; aspect-ratio: 0.9; border-radius: 6px; overflow: hidden; background: #e9c98f; border: 2px solid #b98a4e; }
.cm-board.sm { width: 64px; }
.cm-board svg { display: block; width: 100%; height: 100%; }
.cm-pos-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; align-items: flex-start; }
.cm-pos-info small { color: var(--muted); font-size: 12px; }
.cm-compose { display: flex; flex-direction: column; gap: 8px; }
.cm-row { display: flex; gap: 8px; align-items: stretch; }
.cm-row textarea { flex: 1; min-width: 0; resize: vertical; min-height: 44px; max-height: 160px; font: inherit; padding: 8px 10px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); }
.cm-row textarea:disabled { background: var(--sunken); }
.cm-actions { display: flex; flex-direction: column; gap: 6px; }
.cm-attach { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; border: 1px dashed var(--line-2); background: var(--surface-2); }
.cm-attach .cm-del { margin-left: auto; }
.cm-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; max-height: 220px; overflow-y: auto; }
.cm-pick-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font: inherit; }
.cm-pick-item:hover { border-color: var(--red); }
.cm-pick-item small { color: var(--muted); font-size: 11.5px; }
.cm-login { font-size: 13px; color: var(--muted); }
.cm-login .link { color: var(--red); font-weight: 700; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; }
@media (max-width: 520px) {
  .cm-row { flex-direction: column; }
  .cm-actions { flex-direction: row; justify-content: flex-end; }
  .cm-board { width: 96px; }
}

/* =====================================================================
   Trong trận & lúc hết ván — đồng bộ phong cách thuỷ mặc / bàn gỗ
   ===================================================================== */

/* Quân đã ăn được (trong thẻ người chơi) */
.pc-caps { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; min-height: 22px; align-items: center; }
.pc-caps .cap {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-style: normal;
  font: 700 12px "LXGW WenKai TC", "Noto Serif TC", serif; background: #f3e2c1; border: 1.5px solid #b98d4f;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.pc-caps .cap.r { color: #c42a1f; }
.pc-caps .cap.b { color: #1b1310; }
.pc-caps small { font-size: 11px; color: var(--muted); }

@media (min-width: 1100px) {
  /* Nền "mặt bàn gỗ" phía sau khu thi đấu */
  #game:not(.ended) .game-grid {
    padding: 14px; border-radius: 18px;
    background:
      radial-gradient(120% 80% at 50% 0%, rgba(255, 240, 210, 0.35), transparent 60%),
      repeating-linear-gradient(92deg, rgba(90, 54, 34, 0.06) 0 2px, transparent 2px 9px),
      linear-gradient(180deg, #d8bf96, #c4a479);
    box-shadow: inset 0 0 0 1px rgba(90, 54, 34, 0.25), inset 0 2px 14px rgba(60, 35, 15, 0.25), 0 14px 34px rgba(60, 35, 15, 0.18);
    --arena-bw: min(calc(min(100vw, var(--frame, 1440px)) - var(--sidebar) - var(--side-l) - var(--side-r) - 112px),
                    calc((100dvh - var(--topbar) - 94px) * var(--board-ar, 1)));
  }
  #game:not(.ended) .board-frame { border-color: #8a5a2b; box-shadow: 0 18px 40px rgba(40, 20, 10, 0.4), inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
  #game:not(.ended) .player .pc-caps small { color: #c9a87a; }
  #game:not(.ended) .player { justify-content: space-between; min-height: 0; }
  #game:not(.ended) #p-top, #game:not(.ended) #p-bottom { align-self: stretch; }

  /* Tấm biển báo lượt */
  #game:not(.ended) .actions-card .status-box {
    font-family: var(--serif); font-size: 14px; font-weight: 700; text-align: center; padding: 10px 12px;
    background: linear-gradient(180deg, #fff8ea, #f1e1c3); border: 1px solid #b98a4e; color: #4a2410;
    box-shadow: 0 3px 0 rgba(138, 90, 43, 0.5);
  }
  #game:not(.ended) .actions-card .status-box.check { background: linear-gradient(180deg, #ffe3dc, #f7c3b7); color: #8a1712; border-color: #c42a1f; }
  #game:not(.ended) .actions-card .status-box .hint { font-family: inherit; font-weight: 500; color: #7a5a3a; }
  #game:not(.ended) .moves-card, #game:not(.ended) .chat-card, #game:not(.ended) .eval-card { box-shadow: 0 8px 20px rgba(60, 35, 15, 0.18); }
}

/* ---------- Hết ván: thẻ kết quả kiểu thuỷ mặc ---------- */
.result-card { position: relative; overflow: hidden; align-items: center; text-align: center; padding: 26px 22px 20px; border-radius: 18px; }
.result-card::before { content: ""; position: absolute; inset: 7px; border-radius: 13px; border: 1px solid rgba(201, 154, 69, 0.5); pointer-events: none; }
.result-card > * { position: relative; }
.result-card .result-ico { width: auto; height: auto; background: none; border: 0; box-shadow: none; }
.result-card .seal {
  display: grid; place-items: center; width: 84px; height: 84px; border-radius: 14px; transform: rotate(-6deg);
  font: 700 54px "LXGW WenKai TC", "Noto Serif TC", serif; color: #fff4e0; background: #b3201a;
  box-shadow: inset 0 0 0 4px rgba(255, 244, 224, 0.85), inset 0 0 0 7px #b3201a, 0 10px 22px rgba(120, 20, 10, 0.4);
}
.result-card .result-title { font-family: var(--serif); font-size: 34px; font-weight: 700; margin-top: 8px; }
.result-card .result-sub { font-size: 13.5px; }
.result-card.win {
  background: radial-gradient(90% 60% at 50% 20%, rgba(255, 200, 100, 0.35), transparent 70%), linear-gradient(180deg, #a31b14, #6e100b);
  border-color: #d39a4a; color: #fff3dc;
}
.result-card.win .result-title { color: #ffe39b; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.result-card.win .muted, .result-card.win .result-hint { color: #f3d2c2; }
.result-card.win .seal { background: #e9ae45; color: #6e100b; box-shadow: inset 0 0 0 4px rgba(110, 16, 11, 0.85), inset 0 0 0 7px #e9ae45, 0 10px 24px rgba(0, 0, 0, 0.45); }
.result-card.lose { background: linear-gradient(180deg, #3a322c, #1f1915); border-color: #5a4a3c; color: #e9dfd3; }
.result-card.lose .result-title { color: #f3e9dd; }
.result-card.lose .muted, .result-card.lose .result-hint { color: #b8a898; }
.result-card.lose .seal { background: #5a4a3c; color: #e9dfd3; box-shadow: inset 0 0 0 4px rgba(233, 223, 211, 0.6), inset 0 0 0 7px #5a4a3c, 0 10px 22px rgba(0, 0, 0, 0.45); }
.result-card.draw { background: linear-gradient(180deg, #fff7e8, #ecd9b6); border-color: #c99a45; color: #3a2a1c; }
.result-card.draw .seal { background: #9c6421; }
/* Hai bên & tỉ số */
.result-card .vs-row { max-width: 420px; }
.result-card .vs-side b { font-family: var(--serif); font-size: 15px; }
.result-card .vs-score { font-family: var(--serif); font-size: 34px; font-weight: 700; }
.result-card.win .vs-side small, .result-card.lose .vs-side small { color: inherit; opacity: 0.75; }
.result-card .delta-row .delta { border-radius: 999px; font-weight: 800; }
.result-card.win .delta, .result-card.lose .delta { background: rgba(0, 0, 0, 0.3); color: #fff3dc; border: 1px solid rgba(255, 217, 138, 0.35); }
.result-card.win .delta.up { color: #b9f5c8; }
.result-card .delta.coin { color: #ffd98a; }
/* Nút: chính = nút gỗ vàng, phụ = viền */
.result-card .result-actions .btn.primary {
  background: linear-gradient(180deg, #ffe39b, #e9ae45); color: #5a1a0e; border: 0; font-family: var(--serif); font-size: 16px;
  box-shadow: 0 4px 0 #a8742a, 0 8px 18px rgba(0, 0, 0, 0.25); min-width: 220px;
}
.result-card.draw .result-actions .btn.primary { background: linear-gradient(180deg, #c42a1f, #8f1610); color: #fff; box-shadow: 0 4px 0 #6e100b; }
.result-card .result-links { flex-wrap: wrap; justify-content: center; }
.result-card.win .result-links .btn, .result-card.lose .result-links .btn { color: #f3e2c1; }
.result-card.win .result-links .btn:hover, .result-card.lose .result-links .btn:hover { background: rgba(255, 255, 255, 0.1); }
/* Bàn cờ cuối ván to hơn, nằm bên phải */
@media (min-width: 1100px) {
  #game.ended .game-grid { grid-template-columns: minmax(380px, 460px) minmax(0, 1fr); grid-template-areas: "result board"; gap: 20px; }
  #game.ended .board-col { --bw: 100%; max-width: calc((100dvh - var(--topbar) - 150px) * var(--board-ar, 1) + 36px); justify-self: center; width: 100%; }
}
#game.ended .board-col { background: linear-gradient(180deg, #fffaf1, #f3e6cf); border-color: #e3cfa9; }
#game.ended .board-frame { border: 5px solid #b98a4e; }
#game.ended .end-board-head h3, #game.ended .end-insight h3 { font-family: var(--serif); }
.result-card.win .result-ico, .result-card.lose .result-ico, .result-card.draw .result-ico { background: none; box-shadow: none; width: auto; height: auto; }

/* ---------- Hết ván: gói trọn trong một khung màn hình (≥ 1100px) ----------
   Trái: thẻ kết quả · Giữa: bàn cờ cuối ván · Phải: nhận xét, thống kê, biểu đồ chỉ số */
@media (min-width: 1100px) {
  #game.ended { max-width: none; padding: 8px 16px 10px; gap: 8px; }
  #game.ended .game-head h1, #game.ended .game-head .lead, #game.ended .end-board-head { display: none; }
  #game.ended .result-view, #game.ended .board-col { display: contents; }
  #game.ended .game-grid {
    --res-w: 330px; --side-w: 290px;
    --end-bw: min(calc(min(100vw, var(--frame, 1440px)) - var(--sidebar) - var(--res-w) - var(--side-w) - 120px),
                  calc((100dvh - var(--topbar) - 70px) * var(--board-ar, 1)));
    grid-template-columns: var(--res-w) var(--end-bw) var(--side-w);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
      "res board ins"
      "res board stats"
      "res board radar";
    height: calc(100dvh - var(--topbar) - 52px);
    gap: 10px 16px; justify-content: center; align-items: stretch;
  }
  #game.ended #result-card { grid-area: res; overflow-y: auto; justify-content: center; gap: 10px; padding: 18px 16px 14px; animation: rise 0.35s ease-out; }
  #game.ended .board-frame { grid-area: board; width: var(--end-bw); align-self: center; }
  #game.ended .end-insight {
    grid-area: ins; display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: var(--r-lg);
    background: linear-gradient(180deg, #fffaf1, #f3e6cf); border: 1px solid #e3cfa9; box-shadow: var(--shadow);
  }
  #game.ended .end-insight h3 { font-size: 15px; }
  #game.ended .end-insight p { font-size: 12.5px; }
  #game.ended .end-insight .btn { padding: 8px 10px; }
  #game.ended .result-view > .card:nth-child(2) { grid-area: stats; padding: 12px 14px; gap: 8px; }
  #game.ended .radar-card { grid-area: radar; min-height: 0; overflow: hidden; padding: 12px 14px; gap: 6px; }
  #game.ended .result-view > .card h3 { font-size: 15px; }
  #game.ended .radar-card .card-head p { font-size: 11.5px; }
  #game.ended .radar-wrap { grid-template-columns: minmax(0, 1fr); gap: 4px; min-height: 0; }
  #game.ended #radar { max-height: calc(100dvh - var(--topbar) - 470px); min-height: 120px; width: 100%; }
  #game.ended .radar-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; font-size: 11.5px; }
  #game.ended .stat-row.plain { gap: 6px; }

  /* Thẻ kết quả gọn hơn */
  #game.ended .result-card .seal { width: 64px; height: 64px; font-size: 42px; }
  #game.ended .result-card .result-title { font-size: 28px; margin-top: 2px; }
  #game.ended .result-card .vs-row { margin: 4px 0 0; }
  #game.ended .result-card .vs-side .avatar { width: 40px; height: 40px; }
  #game.ended .result-card .vs-score { font-size: 28px; }
  #game.ended .result-card .result-actions .btn.primary { min-width: 0; width: 100%; }
  #game.ended .result-card .result-actions { width: 100%; }
  #game.ended .result-card .result-links { gap: 2px 6px; }
  #game.ended .result-card .result-links .btn { padding: 6px 8px; font-size: 12.5px; }
}


/* ---------- Ảnh nền chung (phong cảnh thuỷ mặc: lầu gác, đèn lồng, núi sông) ---------- */
body {
  background: #efe4d0 url("assets/bg-scene.webp") center / cover no-repeat fixed;
}
.shell, .main { background: transparent; }
/* Thay cho tranh thuỷ mặc vẽ bằng SVG trước đây */
.ink-scene, .ink-vtext { display: none; }
/* Lớp sáng mờ phía dưới nội dung để chữ & thẻ luôn dễ đọc, vẫn thấy cảnh hai bên */
.main::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background: linear-gradient(90deg, rgba(250, 244, 233, 0.15) 0%, rgba(250, 244, 233, 0.55) 22%, rgba(250, 244, 233, 0.55) 78%, rgba(250, 244, 233, 0.15) 100%);
}
@media (min-width: 1500px) {
  body { background: #efe4d0 url("assets/bg-scene.webp") center / cover no-repeat fixed; }
  .shell { background: transparent; box-shadow: 0 0 0 1px rgba(60, 40, 25, 0.08), 0 20px 60px rgba(40, 25, 15, 0.12); }
}

/* ---------- Điểm nhấn khung web: bên ngoài mờ & tối nhẹ, khung giữa rõ nét có viền vàng ---------- */
@media (min-width: 1500px) {
  body::before {
    content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background: rgba(45, 28, 16, 0.28);
    backdrop-filter: blur(7px) saturate(0.85); -webkit-backdrop-filter: blur(7px) saturate(0.85);
  }
  .shell {
    position: relative; z-index: 1;
    /* nền cố định theo màn hình → khớp liền với ảnh bên ngoài, chỉ khác là rõ nét */
    background: #efe4d0 url("assets/bg-scene.webp") center / cover no-repeat fixed;
    box-shadow: 0 0 0 1px rgba(201, 154, 69, 0.7), 0 0 0 6px rgba(255, 244, 222, 0.18), 0 30px 90px rgba(20, 10, 5, 0.5);
  }
}

/* ---------- Trang chủ: banner + (xếp hạng · trận hot) bên trái, chat cộng đồng cao hết cột phải ---------- */
.btn.ghost-light { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.35); color: #fff; }
.btn.ghost-light:hover { background: rgba(255, 255, 255, 0.16); }
/* Thẻ thông tin xếp hạng */
.hr-rank { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: var(--r); background: linear-gradient(135deg, #2a1c15, #47281b); color: #f6e7cf; }
.hr-badge {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: radial-gradient(circle at 35% 30%, #fff 0%, var(--rank, #c9b79c) 45%, color-mix(in srgb, var(--rank, #c9b79c) 55%, #000) 100%);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3), 0 0 0 5px var(--rank, #c9b79c), 0 0 22px color-mix(in srgb, var(--rank, #c9b79c) 55%, transparent);
}
.hr-badge span { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: #f4e2bd; border: 2px solid #8f5a12; font: 700 23px "LXGW WenKai TC", "Noto Serif TC", serif; color: #8a1712; }
.hr-main { display: grid; gap: 2px; min-width: 0; }
.hr-name { font-family: var(--serif); font-size: 20px; color: var(--rank, #f6e7cf); line-height: 1.1; }
.hr-stars { display: flex; gap: 2px; font-size: 13px; color: rgba(255, 255, 255, 0.22); }
.hr-stars i { font-style: normal; }
.hr-stars i.on { color: #ffd27a; }
.hr-elo { display: flex; align-items: baseline; gap: 6px; }
.hr-elo small { color: #c9a87a; font-size: 12px; }
.hr-elo strong { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; color: #fff3dc; }
.hr-progress { display: grid; gap: 4px; }
.hr-progress .bar { height: 8px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.hr-progress .bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--red)); }
.form-stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.form-stats.three div { padding: 8px 10px; }
.form-stats.three b { font-size: 20px; }

@media (min-width: 1100px) {
  #lobby {
    display: grid; max-width: none;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(330px, 1.1fr);
    grid-template-areas:
      "head head head"
      "hero hero chat"
      "form live chat"
      "more more more";
    gap: 16px; align-items: stretch;
  }
  #lobby > .page-head { grid-area: head; }
  #lobby > .hero { grid-area: hero; min-height: 236px; }
  #lobby .hero h2 { font-size: 27px; }
  #lobby > .quick-grid { display: none; } /* đã có nút trong banner & menu trái */
  #lobby > .cols { display: contents; }
  #lobby #home-form { grid-area: form; gap: 12px; }
  #lobby #home-live-card { grid-area: live; min-height: 0; }
  #lobby #home-live-card .live-list { max-height: 420px; overflow-y: auto; }
  #lobby > .grid-3 { grid-area: more; }
  /* Chat cao đúng bằng banner + hàng dưới (không tự kéo dài trang) */
  #lobby > #community { grid-area: chat; contain: size; display: flex; flex-direction: column; min-height: 0; }
  #lobby > #community .cm-feed { flex: 1; max-height: none; min-height: 0; }
}

/* ---------- Hồ sơ kỳ thủ: trái (thẻ · chỉ số · nút) — phải (nội dung theo nút) ---------- */
.pf-layout { display: grid; gap: 16px; }
.pf-left { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
#profile .pf-header { display: flex; flex-direction: column; align-items: stretch; gap: 14px; padding: 18px; }
.pf-top { display: flex; align-items: center; gap: 16px; }
#profile .pf-avatar { width: 96px; height: 96px; font-size: 32px; }
#profile .pf-lines { gap: 3px; align-items: flex-start; }
#profile .pf-lines h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
#profile .pf-lines .muted { font-size: 13px; }
.pf-info { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.pf-info-item { display: grid; gap: 1px; padding-bottom: 6px; border-bottom: 2px solid var(--line-2); }
.pf-info-item small { font-size: 11.5px; color: var(--muted); }
.pf-info-item b { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pf-info-item.elo { border-bottom-color: var(--red); }
.pf-info-item.coin { border-bottom-color: var(--gold); }
.pf-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pf-stat { padding: 14px 16px; gap: 6px; }
.pf-stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pf-stat small { display: block; font-size: 12px; color: var(--muted); }
.pf-stat b { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pf-stat em { font-style: normal; font-size: 12px; color: var(--muted); }
.pf-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 12px; }
.pf-menu button {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-2); font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; text-align: left;
}
.pf-menu button:hover { border-color: var(--line-2); background: var(--surface); color: var(--text); }
.pf-menu button.active { background: var(--red); border-color: var(--red); color: #fff; }
.pf-menu button.active .ico { color: #fff; }
.pf-menu button.danger { color: var(--red); }
.pf-menu-sep { grid-column: 1 / -1; height: 1px; background: var(--line); margin: 4px 0; }
.pf-panel { min-width: 0; padding: 18px; }
.pf-pane { display: flex; flex-direction: column; gap: 12px; }
.pf-pane .table { width: 100%; }
@media (min-width: 1000px) {
  .pf-layout { grid-template-columns: minmax(380px, 0.9fr) minmax(0, 1.1fr); align-items: stretch; }
  /* Ô bên phải cao bằng cột trái, nội dung dài thì cuộn bên trong */
  .pf-panel { contain: size; min-height: 520px; overflow-y: auto; }
}

/* ---------- Thông báo đầu trang (admin → Cài đặt hệ thống → Nội dung trang chủ) ---------- */
.announce {
  position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; margin: 12px 32px 0; padding: 10px 14px;
  border-radius: var(--r); background: linear-gradient(90deg, #8f1610, #c42a1f); color: #fff7ea; font-weight: 600; font-size: 13.5px;
  box-shadow: 0 6px 18px rgba(140, 25, 18, 0.25);
}
.announce .ico { color: #ffd27a; flex: none; }
.announce span { flex: 1; min-width: 0; }
.announce-x { border: 0; background: rgba(255, 255, 255, 0.15); color: #fff; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 16px; line-height: 1; flex: none; }
.announce-x:hover { background: rgba(255, 255, 255, 0.3); }
body[data-screen="game"] .announce { display: none; }
@media (max-width: 900px) { .announce { margin: 10px 16px 0; } }

/* Dòng phụ thẻ người chơi: các phần nối bằng " · " */
.pc-sub > span + span::before { content: " · "; color: var(--faint); font-weight: 400; }

/* ---------- Bàn đấu (≥1100px): trái = đối thủ + nút · giữa = bàn cờ · phải = chat + bạn ---------- */
@media (min-width: 1100px) {
  #game:not(.ended) .game-grid {
    --side-l: var(--arena-left, 260px); --side-r: var(--arena-right, 280px);
    grid-template-areas:
      "opp   board chat"
      "moves board chat"
      "acts  board me";
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  #game:not(.ended) #p-top { grid-area: opp; }
  #game:not(.ended) #p-bottom { grid-area: me; }
  #game:not(.ended) .moves-card { grid-area: moves; max-height: none; min-height: 0; overflow: hidden; align-self: stretch; }
  #game:not(.ended) .moves-card #move-list { min-height: 0; overflow-y: auto; }
  #game:not(.ended) .chat-card, #game:not(.ended) .eval-card { grid-area: chat; }
  #game:not(.ended) .chat-card #chat-log { flex: 1; max-height: none; min-height: 0; overflow-y: auto; }
  #game:not(.ended) .actions-card { grid-area: acts; align-self: end; }

  /* Thẻ người chơi nằm ngang: ảnh vuông bên trái · tên / Elo / rank bên phải · đồng hồ bên dưới */
  #game:not(.ended) .player {
    display: grid; grid-template-columns: 84px minmax(0, 1fr); grid-template-areas: "av info" "clock clock" "caps caps";
    align-items: center; gap: 10px 12px; padding: 12px; text-align: left;
  }
  #game:not(.ended) .pc-avatar { grid-area: av; width: 84px; height: 84px; max-width: none; max-height: none; margin: 0; aspect-ratio: 1; }
  #game:not(.ended) .pc-avatar img, #game:not(.ended) .pc-initial { font-size: 32px; }
  #game:not(.ended) .pc-initial.ai { font-size: 26px; }
  #game:not(.ended) .pc-ring { inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); }
  #game:not(.ended) .pc-side { width: 18px; height: 18px; right: -3px; bottom: -3px; }
  #game:not(.ended) .pc-info { grid-area: info; align-items: flex-start; gap: 2px; min-width: 0; }
  #game:not(.ended) .pc-name { font-size: 18px; line-height: 1.2; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #game:not(.ended) .pc-sub { white-space: normal; font-size: 13px; line-height: 1.45; text-align: left; }
  #game:not(.ended) .pc-sub > span { display: block; }
  #game:not(.ended) .pc-sub > span + span::before { content: none; }
  #game:not(.ended) .pc-sub .pc-handle { display: none; }
  #game:not(.ended) .pc-sub .pc-elo { color: #ffe2a8; font-weight: 700; }
  #game:not(.ended) .pc-sub .pc-rank { color: #d9bf98; }
  #game:not(.ended) .player .clock {
    grid-area: clock; align-items: center; padding: 6px 10px; border-radius: 8px;
    background: rgba(0, 0, 0, 0.28); box-shadow: inset 0 0 0 1px rgba(255, 210, 122, 0.25);
  }
  #game:not(.ended) .player .clock b { font-size: 30px; line-height: 1.1; }
  #game:not(.ended) .player .pc-caps { grid-area: caps; justify-content: flex-start; min-height: 0; }
}
@media (min-width: 1100px) {
  /* Mặt bàn gỗ có đệm 14px mỗi phía (box-sizing: border-box) → cao = bàn cờ + 2 × đệm, bàn cờ không lòi ra ngoài */
  #game:not(.ended) .game-grid { height: calc(var(--arena-bw) / var(--board-ar, 1) + 28px); }
}

/* =====================================================================
   Màn hình kết thúc ván (Chiến Thắng / Thất Bại / Hoà Cờ)
   Trái: biên bản trận đấu · Giữa: thẻ kết quả (2 kỳ thủ, tỉ số, thế cờ cuối, nút) · Phải: biểu đồ, thống kê, chỉ số
   ===================================================================== */
.mv-title-end { display: none; }
#game.ended .mv-title-live { display: none; }
#game.ended .mv-title-end { display: inline; }
.res-crown, .res-fx, .res-board-wrap { display: none; }
#res-again.ask { color: var(--green); font-weight: 800; }

/* Thẻ kết quả: dùng ở mọi kích thước màn hình */
#game.ended .result-card { position: relative; overflow: hidden; isolation: isolate; text-align: center; align-items: center; }
#game.ended .result-card .result-ico { display: none; }
#game.ended .res-crown { display: block; width: 74px; height: auto; margin: 0 auto -6px; fill: #f2c45a; filter: drop-shadow(0 2px 0 #8a4b10) drop-shadow(0 0 10px rgba(255, 200, 90, 0.5)); }
#game.ended .result-card .result-title {
  font-family: "Dancing Script", var(--serif); font-weight: 700; font-size: 54px; line-height: 1.05; letter-spacing: 0.5px; margin: 0;
  background: linear-gradient(180deg, #fff6c8 0%, #ffd56a 40%, #e19a24 70%, #fff0b0 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(90, 20, 10, 0.55)) drop-shadow(0 0 14px rgba(255, 190, 80, 0.35));
}
#game.ended .result-card .vs-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px; width: 100%; margin: 6px 0 0; }
#game.ended .result-card .vs-side { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
#game.ended .result-card .vs-side b { font-family: var(--serif); font-size: 17px; color: #fff3dc; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#game.ended .result-card .vs-side small { color: #f1d3ad; font-size: 12.5px; }
#game.ended .vs-ring { position: relative; padding: 5px; border-radius: calc(var(--av-r) + 6px); background: linear-gradient(145deg, #e9edf3, #9aa4b2 50%, #dfe4ea); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35); margin-bottom: 4px; }
#game.ended .vs-side.winner .vs-ring { background: conic-gradient(from 200deg, #fff2b8, #e3a23a, #ffe08a, #b8741d, #fff2b8); box-shadow: 0 0 0 2px rgba(255, 220, 140, 0.4), 0 0 26px rgba(255, 190, 70, 0.55), 0 6px 16px rgba(0, 0, 0, 0.35); }
#game.ended .vs-side.winner .vs-ring::before { content: "\265B"; position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 22px; color: #ffd36b; text-shadow: 0 2px 0 #8a4b10; }
#game.ended .result-card .vs-side .avatar { width: 76px; height: 76px; font-size: 26px; border: 2px solid rgba(0, 0, 0, 0.25); }
#game.ended .result-card .vs-score { font-family: var(--serif); font-size: 40px; font-weight: 700; color: #ffe08a; text-shadow: 0 3px 0 rgba(70, 15, 8, 0.6); padding-top: 26px; }
#game.ended .elo-chg { margin-top: 4px; padding: 3px 14px; border-radius: 999px; font-weight: 800; font-size: 13px; border: 2px solid; background: rgba(0, 0, 0, 0.25); }
#game.ended .elo-chg.up { color: #5fe08d; border-color: #3fbf6e; }
#game.ended .elo-chg.down { color: #ff7a6b; border-color: #e0483a; }
#game.ended .result-card #result-sub { color: #f1d3ad; font-size: 13px; margin: 0; }
#game.ended .res-board-wrap {
  display: block; width: min(100%, 300px); margin: 4px auto 0; padding: 6px; border-radius: 10px;
  background: linear-gradient(180deg, #e8c27a, #b8873f); box-shadow: 0 0 0 2px #6e3b12, 0 10px 22px rgba(0, 0, 0, 0.35);
}
#game.ended #res-board { display: block; width: 100%; height: auto; border-radius: 6px; }
#game.ended .result-card .delta-row { justify-content: center; }
#game.ended .result-card .result-hint { color: #ffe08a; margin: 0; }
#game.ended .result-card .result-actions { width: 100%; }
#game.ended .result-card .result-actions .btn.primary {
  width: 100%; min-width: 0; font-family: var(--serif); font-size: 19px; padding: 12px 16px; border-radius: 12px;
  background: linear-gradient(180deg, #fff1b3, #f2c45a 45%, #d89a2a); color: #5a1a0e; border: 0;
  box-shadow: 0 4px 0 #8a5a12, 0 10px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
#game.ended .result-card .result-links { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; width: 100%; border-top: 1px solid rgba(255, 220, 160, 0.25); padding-top: 8px; }
#game.ended .result-card .result-links .btn { color: #fff3dc; justify-content: center; font-weight: 700; }
#game.ended .result-card .result-links .btn:hover { background: rgba(255, 255, 255, 0.1); }
#game.ended .result-card .result-links .btn .ico { color: #ffd36b; }
#game.ended .result-links #res-board { display: none; }

/* Chủ đề màu */
#game.ended .result-card.win {
  background:
    radial-gradient(120% 50% at 50% 0%, rgba(255, 196, 90, 0.35), transparent 60%),
    radial-gradient(90% 60% at 50% 100%, rgba(0, 0, 0, 0.35), transparent 70%),
    linear-gradient(180deg, #a8160f, #7d0e0a 55%, #5c0906);
  border: 3px solid #e2ad4c; box-shadow: inset 0 0 0 3px #7a0d08, inset 0 0 0 5px rgba(255, 210, 120, 0.55), 0 20px 50px rgba(80, 10, 5, 0.45);
}
#game.ended .result-card.lose {
  background:
    radial-gradient(120% 50% at 50% 0%, rgba(160, 180, 210, 0.25), transparent 60%),
    linear-gradient(180deg, #3a4150, #262b36 55%, #1a1e26);
  border: 3px solid #8e98a8; box-shadow: inset 0 0 0 3px #1c2029, inset 0 0 0 5px rgba(200, 210, 225, 0.35), 0 20px 50px rgba(10, 15, 25, 0.45);
}
#game.ended .result-card.lose .res-crown { fill: #9aa4b2; opacity: 0.55; transform: rotate(-8deg); filter: none; }
#game.ended .result-card.lose .result-title {
  background: linear-gradient(180deg, #ffffff 0%, #c9d2de 45%, #7c8796 75%, #e4e9f0 100%); -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.55));
}
#game.ended .result-card.lose .vs-score, #game.ended .result-card.lose .result-hint { color: #d6dde7; }
#game.ended .result-card.lose .vs-side small, #game.ended .result-card.lose #result-sub { color: #b7c0cc; }
#game.ended .result-card.lose .result-links .btn .ico { color: #c9d2de; }
#game.ended .result-card.lose .result-actions .btn.primary { background: linear-gradient(180deg, #f3f6fa, #c7cfda 50%, #9aa5b4); color: #1f2530; box-shadow: 0 4px 0 #5d6675, 0 10px 24px rgba(0, 0, 0, 0.35); }
#game.ended .result-card.draw {
  background: radial-gradient(120% 50% at 50% 0%, rgba(150, 230, 200, 0.25), transparent 60%), linear-gradient(180deg, #1f6b58, #134a3d 55%, #0d3329);
  border: 3px solid #d8c07a; box-shadow: inset 0 0 0 3px #0e3a30, inset 0 0 0 5px rgba(240, 220, 150, 0.4), 0 20px 50px rgba(5, 30, 25, 0.45);
}
#game.ended .result-card.draw .res-crown { display: none; }

/* Hiệu ứng rơi */
#game.ended .res-fx { display: block; position: absolute; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
#game.ended .res-fx i { position: absolute; top: -20px; display: block; }
#game.ended .result-card.win .res-fx i {
  width: 12px; height: 9px; border-radius: 60% 0 60% 0; background: linear-gradient(135deg, #ff6b4a, #c4160c); opacity: 0.85;
  animation: petal-fall linear infinite;
}
#game.ended .result-card.win .res-fx i:nth-child(3n) { background: linear-gradient(135deg, #ffe08a, #e39a24); width: 8px; height: 8px; border-radius: 50%; }
#game.ended .result-card.lose .res-fx i { width: 1.5px; height: 18px; background: linear-gradient(180deg, transparent, rgba(210, 222, 240, 0.55)); animation: rain-fall linear infinite; }
@keyframes petal-fall {
  0% { transform: translate(0, -20px) rotate(0deg); }
  50% { transform: translate(28px, 50vh) rotate(200deg); }
  100% { transform: translate(-10px, 110vh) rotate(420deg); }
}
@keyframes rain-fall { from { transform: translate(0, -20px); } to { transform: translate(-30px, 110vh); } }
@media (prefers-reduced-motion: reduce) { #game.ended .res-fx { display: none; } }

/* Nền trang khi hết ván */
#game.ended[data-result]::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#game.ended[data-result="win"]::before { background: radial-gradient(70% 60% at 50% 40%, rgba(255, 120, 60, 0.12), rgba(120, 10, 5, 0.35)); }
#game.ended[data-result="lose"]::before { background: radial-gradient(70% 60% at 50% 40%, rgba(40, 50, 70, 0.10), rgba(15, 20, 30, 0.45)); }
#game.ended[data-result="draw"]::before { background: radial-gradient(70% 60% at 50% 40%, rgba(40, 120, 100, 0.08), rgba(10, 40, 35, 0.3)); }
#game.ended > * { position: relative; z-index: 1; }

/* Bố cục 3 cột (≥ 1100px) */
@media (min-width: 1100px) {
  #game.ended .game-grid {
    --rec-w: 290px; --res-w: 440px; --side-w: 320px;
    grid-template-columns: var(--rec-w) var(--res-w) var(--side-w);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
      "rec res ins"
      "rec res stats"
      "rec res radar";
    height: calc(100dvh - var(--topbar) - 52px);
    gap: 12px 18px; justify-content: center; align-items: stretch;
  }
  #game.ended .board-frame { display: none; }
  #game.ended .game-side { display: contents; }
  #game.ended .chat-card, #game.ended .eval-card, #game.ended .actions-card { display: none; }
  #game.ended .moves-card { display: flex; grid-area: rec; min-height: 0; overflow: hidden; padding: 14px; gap: 8px; background: rgba(255, 252, 245, 0.96); }
  #game.ended .moves-card #move-list { flex: 1; min-height: 0; overflow-y: auto; max-height: none; }
  #game.ended .moves-card h3 { font-family: var(--serif); }
  #game.ended #result-card { grid-area: res; overflow-y: auto; justify-content: flex-start; gap: 8px; padding: 14px 20px 12px; }
  #game.ended .end-insight { grid-area: ins; gap: 6px; padding: 12px 14px; }
  #game.ended .end-insight .end-ins-title { font-size: 13.5px; margin-top: 2px; }
  #game.ended .end-insight p { font-size: 12px; }
}
@media (min-width: 1100px) and (max-height: 820px) {
  #game.ended .result-card .result-title { font-size: 44px; }
  #game.ended .res-crown { width: 56px; }
  #game.ended .result-card .vs-side .avatar { width: 60px; height: 60px; }
  #game.ended .res-board-wrap { width: min(100%, 230px); }
}

/* Biểu đồ trận đấu */
.end-chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.end-chart-head h3 { font-family: var(--serif); font-size: 15px; }
.end-chart-head small { color: var(--muted); font-size: 11.5px; }
.end-chart { width: 100%; height: 110px; display: block; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.end-chart .grid { stroke: rgba(0, 0, 0, 0.06); stroke-width: 1; vector-effect: non-scaling-stroke; }
.end-chart .zero { stroke: rgba(0, 0, 0, 0.25); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.end-chart .up { fill: rgba(198, 29, 29, 0.28); }
.end-chart .down { fill: rgba(27, 22, 18, 0.22); }
.end-chart .line { fill: none; stroke: #7a2a16; stroke-width: 1.8; vector-effect: non-scaling-stroke; stroke-linejoin: round; }

/* Tinh chỉnh thẻ kết quả: vương miện có chiều cao cố định, gọn để vừa một khung màn hình */
#game.ended .res-crown { width: 68px; height: 34px; flex: none; }
#game.ended .result-card .result-hint:empty { display: none; }
#game.ended .res-board-wrap { width: min(100%, 260px); }
#game.ended .result-card .result-links .btn { padding: 5px 8px; }
@media (min-width: 1100px) and (max-height: 820px) { #game.ended .res-crown { width: 52px; height: 26px; } #game.ended .res-board-wrap { width: min(100%, 210px); } }

/* ---------- Thẻ kết quả bản 2: khung vàng, ruy băng đỏ, mây vàng, nguyệt quế (theo mẫu) ---------- */
.res-deco, .res-flourish { display: none; }
#game.ended[data-result]::before { display: none; } /* giữ nguyên ảnh nền phong cảnh như mẫu */
#game.ended .result-card { border-radius: 22px; }
#game.ended .result-card.win, #game.ended .result-card.draw {
  border: 4px solid #e8b75a;
  box-shadow: 0 0 0 2px #8a4b10, inset 0 0 0 3px #5e0a07, inset 0 0 0 5px rgba(255, 214, 128, 0.7), 0 24px 60px rgba(80, 10, 5, 0.45);
}
#game.ended .result-card.lose {
  background: radial-gradient(90% 40% at 70% 6%, rgba(160, 30, 25, 0.35), transparent 70%), linear-gradient(180deg, #1d1416, #141012 60%, #0f0c0d);
  border: 4px solid #d9a94e;
  box-shadow: 0 0 0 2px #6a3a10, inset 0 0 0 3px #0c0909, inset 0 0 0 5px rgba(230, 180, 90, 0.45), 0 24px 60px rgba(10, 8, 8, 0.5);
}
#game.ended .res-deco { display: block; position: absolute; inset: 0; z-index: -1; pointer-events: none; }
/* Ruy băng đỏ uốn lượn hai bên */
#game.ended .res-ribbon { position: absolute; top: 34px; width: 56px; height: 72%; opacity: 0.95; }
#game.ended .res-ribbon.l { left: -16px; }
#game.ended .res-ribbon.r { right: -16px; transform: scaleX(-1); }
#game.ended .res-ribbon .rb { fill: none; stroke: #c8161a; stroke-width: 20; stroke-linecap: round; }
#game.ended .res-ribbon .rh { fill: none; stroke: #ff6a55; stroke-width: 3; opacity: 0.55; transform: translateX(-5px); }
#game.ended .result-card.lose .res-ribbon { top: 150px; height: 62%; opacity: 0.8; }
#game.ended .result-card.lose .res-ribbon .rb { stroke: #9e1712; }
#game.ended .result-card.draw .res-ribbon .rb { stroke: #1d7a62; }
#game.ended .result-card.draw .res-ribbon .rh { stroke: #7fe0c0; }
/* Đèn lồng hai bên bàn cờ (thắng) */
#game.ended .res-lantern { position: absolute; top: 52%; width: 26px; filter: drop-shadow(0 0 10px rgba(255, 170, 60, 0.75)); display: none; }
#game.ended .res-lantern.l { left: 10px; }
#game.ended .res-lantern.r { right: 10px; }
#game.ended .result-card.win .res-lantern { display: block; }
/* Mây vàng ở đáy */
#game.ended .res-clouds { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 64px; }
#game.ended .res-clouds .cl-fill { fill: url(#rc-gold); stroke: #7a4510; stroke-width: 1.5; }
#game.ended .res-clouds .cl-curl path { fill: none; stroke: #8a5214; stroke-width: 1.6; opacity: 0.7; }
/* Cảnh trăng đỏ & lầu gác (thua) */
#game.ended .res-scene { display: none; position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 46%; }
#game.ended .result-card.lose .res-scene { display: block; }
#game.ended .res-scene .mt { fill: #1c1517; opacity: 0.9; }
#game.ended .res-scene .mt2 { fill: #141012; }
#game.ended .res-scene .pg { fill: #0d0a0b; }
#game.ended .result-card.lose .res-crown { display: none; }

/* Tiêu đề & đường hoa văn */
#game.ended .result-card .result-title { font-size: 60px; margin-top: -4px; }
#game.ended .result-card.lose .result-title {
  background: linear-gradient(180deg, #ffffff 0%, #e9e2e2 40%, #a79c9c 70%, #f1e7e7 100%); -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 3px 0 rgba(120, 15, 10, 0.75)) drop-shadow(0 0 16px rgba(200, 40, 30, 0.35));
}
#game.ended .res-flourish { display: block; position: relative; width: 62%; height: 10px; margin: -2px auto 2px; }
#game.ended .res-flourish::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1.5px; background: linear-gradient(90deg, transparent, #f2c45a 30%, #f2c45a 70%, transparent); }
#game.ended .res-flourish i { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; background: #f2c45a; transform: translate(-50%, -50%) rotate(45deg); box-shadow: 0 0 8px rgba(255, 200, 90, 0.8); }
#game.ended .result-card.lose .res-flourish { display: none; }

/* Hai kỳ thủ */
#game.ended .result-card .vs-side .avatar { width: 84px; height: 84px; font-size: 30px; font-weight: 800; border: 0; }
#game.ended .result-card .vs-side .avatar:not(.ai) { background: linear-gradient(180deg, #fff, #f3e4e0); color: #c42a1f; }
#game.ended .result-card .vs-side .avatar.ai { background: linear-gradient(180deg, #34405a, #1c2335); color: #f3f6fb; }
#game.ended .vs-ring { padding: 5px; }
#game.ended .vs-side.loser .vs-ring { background: linear-gradient(145deg, #ffffff, #d9dde3 50%, #f4f6f8); }
#game.ended .vs-side.winner .vs-ring::before { content: none; }
#game.ended .mini-crown { position: absolute; left: 50%; top: -26px; width: 40px; height: 22px; transform: translateX(-50%); fill: #f2c45a; filter: drop-shadow(0 2px 0 #8a4b10) drop-shadow(0 0 6px rgba(255, 200, 90, 0.7)); z-index: 2; }
#game.ended .laurel { position: absolute; inset: -24px; width: calc(100% + 48px); height: calc(100% + 48px); pointer-events: none; z-index: -1; }
#game.ended .laurel .lf { fill: #e8b13e; stroke: #7a4a0e; stroke-width: 0.8; }
#game.ended .vs-side.winner .vs-ring { z-index: 0; }
#game.ended .result-card .vs-side b { font-size: 19px; }
#game.ended .result-card .vs-score { display: flex; flex-direction: column; align-items: center; gap: 22px; padding-top: 24px; }
#game.ended .result-card .vs-score span { font-size: 46px; line-height: 1; color: #fff3dc; text-shadow: 0 3px 0 rgba(70, 15, 8, 0.6), 0 0 18px rgba(255, 200, 120, 0.35); }
#game.ended .vs-div { display: block; position: relative; width: 84px; height: 8px; }
#game.ended .vs-div::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: linear-gradient(90deg, transparent, #e8b75a, transparent); }
#game.ended .vs-div::after { content: ""; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; border: 1.5px solid #e8b75a; transform: translate(-50%, -50%) rotate(45deg); background: #7d0e0a; }
#game.ended .result-card.lose .vs-div::after { background: #141012; border-color: #c0392b; }
#game.ended .result-card.lose .vs-div::before { background: linear-gradient(90deg, transparent, #c0392b, transparent); }
#game.ended .result-card #result-sub { font-family: var(--serif); font-size: 16px; font-weight: 700; color: #ffe08a; }
#game.ended .result-card.lose #result-sub { color: #ff7a5a; }

/* Bàn cờ cuối ván có quầng sáng */
#game.ended .res-board-wrap { width: min(100%, 320px); box-shadow: 0 0 0 2px #6e3b12, 0 0 28px rgba(255, 190, 90, 0.45), 0 12px 24px rgba(0, 0, 0, 0.4); }
#game.ended .result-card.lose .res-board-wrap { box-shadow: 0 0 0 2px #4a2a10, 0 0 24px rgba(255, 140, 60, 0.25), 0 12px 24px rgba(0, 0, 0, 0.5); }

/* Nút chính & các link */
#game.ended .result-card .result-actions .btn.primary { font-size: 22px; padding: 12px 16px; border-radius: 14px; }
#game.ended .result-card.lose .result-actions .btn.primary {
  background: linear-gradient(180deg, #ef4a3a, #c4160c 55%, #9a0f08); color: #fff;
  box-shadow: 0 4px 0 #6e0a05, 0 10px 24px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
#game.ended .result-card .result-links {
  grid-template-columns: 1fr 1fr; gap: 0; padding: 8px 0 54px; border-top: 1px solid rgba(255, 220, 160, 0.22);
  background: linear-gradient(rgba(255, 220, 160, 0.3), rgba(255, 220, 160, 0.3)) center 8px / 1px 34px no-repeat;
}
#game.ended .result-card .result-links .btn { font-size: 16px; justify-content: center; }
#game.ended .result-card.lose .result-links .btn .ico { color: #fff; }

/* Biên bản trống: biểu tượng cuộn giấy */
#game.ended #move-list li.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 40px; color: var(--muted); }
#game.ended #move-list li.empty::before {
  content: ""; width: 96px; height: 80px; opacity: 0.35;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 96 80' fill='none' stroke='%237d7268' stroke-width='3' stroke-linecap='round'%3E%3Crect x='14' y='8' width='50' height='62' rx='6'/%3E%3Cpath d='M24 24h30M24 34h30M24 44h22'/%3E%3Cpath d='M58 66 86 14l6 4-28 52-8 4z'/%3E%3Cpath d='M8 70h40'/%3E%3C/svg%3E") center / contain no-repeat;
}
@media (min-width: 1100px) {
  #game.ended .game-grid { --res-w: 470px; --rec-w: 300px; --side-w: 330px; }
  #game.ended #result-card { padding: 16px 26px 0; gap: 8px; }
}
@media (min-width: 1100px) and (max-height: 860px) {
  #game.ended .result-card .result-title { font-size: 48px; }
  #game.ended .result-card .vs-side .avatar { width: 66px; height: 66px; font-size: 24px; }
  #game.ended .result-card .vs-score span { font-size: 38px; }
  #game.ended .res-board-wrap { width: min(100%, 236px); }
  #game.ended .result-card .result-links { padding-bottom: 44px; }
  #game.ended .res-clouds { height: 50px; }
}

/* Bàn cờ cuối ván tự lớn theo chiều cao màn hình để thẻ kết quả kín khung (≈ 500px là phần chữ, nút, mây) */
@media (min-width: 1100px) {
  #game.ended .res-board-wrap, #game.ended .result-card.lose .res-board-wrap { width: min(100%, max(190px, calc((100dvh - var(--topbar) - 52px - 510px) / 1.03))); }
}
@media (min-width: 1100px) {
  /* Ba cột co giãn theo bề rộng màn hình (không tràn ở khổ ~1180px) */
  #game.ended .game-grid { grid-template-columns: minmax(200px, var(--rec-w)) minmax(360px, var(--res-w)) minmax(240px, var(--side-w)); }
}
@media (min-width: 1100px) {
  /* Thắng/hoà có thêm vương miện & đường hoa văn trên tiêu đề → bàn cờ nhỏ hơn một chút để vẫn vừa khung */
  #game.ended .res-board-wrap { width: min(100%, max(190px, calc((100dvh - var(--topbar) - 52px - 570px) / 1.03))); }
}
/* Chừa chỗ cho vòng nguyệt quế, không đè lên tên */
#game.ended .vs-side.winner .vs-ring { margin-bottom: 14px; }

/* Bảng Nhiệm vụ hôm nay (nút quà cạnh chuông thông báo) */
.mission-panel .mission-box { display: flex; flex-direction: column; gap: 12px; }
.mission-btn .badge { background: var(--green); }

/* ---------- Trang chủ vừa đúng một màn hình (≥1100px): không cuộn trang, nội dung dài cuộn bên trong từng ô ---------- */
@media (min-width: 1100px) {
  body[data-screen="home"] .main { height: 100dvh; overflow: hidden; }
  body[data-screen="home"] #lobby { flex: 1 1 0; min-height: 0; padding-bottom: 16px; gap: 14px; }
  #lobby { grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "head head head" "hero hero chat" "form live chat"; }
  #lobby > .grid-3 { display: none; }
  #lobby #home-form, #lobby #home-live-card { min-height: 0; overflow-y: auto; }
  #lobby #home-live-card .live-list { max-height: none; }
  #lobby > .hero { min-height: 0; }
}
@media (min-width: 1100px) and (max-height: 820px) {
  #lobby > .hero { min-height: 0; }
  #lobby .hero h2 { font-size: 23px; }
  #lobby .hero-body { padding: 20px 26px; gap: 10px; }
  #lobby .hero-art img { width: min(100%, 200px); }
}
@media (min-width: 1100px) and (max-height: 820px) {
  /* Màn thấp: thẻ xếp hạng chỉ giữ huy hiệu, thanh tiến độ & nút — 3 ô số liệu xem ở Hồ sơ */
  #lobby #home-form .form-stats.three { display: none; }
  #lobby #home-form { gap: 10px; }
  #lobby #home-form .hr-rank { padding: 10px; }
  #lobby .hero-actions .btn { padding-top: 8px; padding-bottom: 8px; }
}

/* =====================================================================
   Chơi nhanh: 4 lối vào là 4 cờ phướn (ảnh khung vàng), cuộn ngang
   Ảnh 1024×1536: khung nằm ở x 126–898, y 17–1475 (772×1458); hoa văn đáy bắt đầu ~y 1090
   → mọi kích thước tính theo --bn-w (bề rộng khung), giữ đúng tỉ lệ ảnh
   ===================================================================== */
#page-play { --bn-w: clamp(260px, calc((100dvh - var(--topbar) - 150px) / 1.8886), 330px); position: relative; }
#page-play .p2-grid {
  display: flex; gap: 26px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-behavior: smooth;
  padding: 10px 6px 16px; margin: 0 -6px; grid-template-columns: none;
  scrollbar-width: thin; scrollbar-color: #d9a94e transparent;
}
#page-play .p2-grid::-webkit-scrollbar { height: 8px; }
#page-play .p2-grid::-webkit-scrollbar-thumb { background: linear-gradient(90deg, #f2c45a, #c98a22); border-radius: 999px; }
#page-play .p2-grid::-webkit-scrollbar-track { background: rgba(120, 80, 30, 0.08); border-radius: 999px; }
#page-play .p2-entry {
  flex: 0 0 var(--bn-w); width: var(--bn-w); height: calc(var(--bn-w) * 1.8886); scroll-snap-align: start;
  position: relative; isolation: isolate; overflow: visible;
  background: none !important; border: 0 !important; border-radius: 0; box-shadow: none !important;
  padding: calc(var(--bn-w) * 0.075) calc(var(--bn-w) * 0.085) calc(var(--bn-w) * 0.52);
  gap: calc(var(--bn-w) * 0.03); filter: drop-shadow(0 12px 18px rgba(60, 35, 15, 0.28));
}
#page-play .p2-entry::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: var(--bn-img) no-repeat; background-size: calc(var(--bn-w) * 1.3264) auto;
  background-position: calc(var(--bn-w) * -0.1632) calc(var(--bn-w) * -0.022);
  border: 0; border-radius: 0; opacity: 1; inset: 0; transform: none;
}
#page-play .p2-entry::after { content: none !important; }
#page-play a.p2-entry:hover { transform: translateY(-6px); box-shadow: none; filter: drop-shadow(0 18px 24px rgba(60, 35, 15, 0.35)); }
#page-play .p2-ranked { --bn-img: url("assets/banner-red.webp"); color: #fff5e6; }
#page-play .p2-coin { --bn-img: url("assets/banner-ivory.webp"); color: #3a2416; }
#page-play .p2-tables { --bn-img: url("assets/banner-black.webp"); color: #f1e7da; }
#page-play .p2-friend { --bn-img: url("assets/banner-beige.webp"); color: #3a2416; }

/* Nội dung gọn để nằm trong phần thân cờ phướn */
#page-play .p2-entry .p2-card-head { gap: 10px; }
#page-play .p2-entry .p2-card-head h2 { font-size: calc(var(--bn-w) * 0.075); }
#page-play .p2-entry .p2-card-head p { font-size: 12.5px; }
#page-play .p2-entry .p2-head-ico { width: calc(var(--bn-w) * 0.14); height: calc(var(--bn-w) * 0.14); }
#page-play .p2-entry .p2-trophy { margin: 0 auto; }
#page-play .p2-entry .p2-trophy svg { width: calc(var(--bn-w) * 0.42); height: auto; }
#page-play .p2-entry .p2-points { font-size: 12.5px; gap: 4px; }
#page-play .p2-entry .p2-btn { padding: 10px 12px; font-size: 15px; }
#page-play .p2-entry .p2-foot { font-size: 12px; margin: 0; }
#page-play .p2-entry .p2-coin-art { display: none; }
#page-play .p2-entry .p2-friend-art { width: 100%; height: auto; max-height: calc(var(--bn-w) * 0.45); }
#page-play .p2-entry .p2-table-list { min-height: 0; overflow: hidden; flex: 1; }
#page-play .p2-entry .p2-opt { padding: 7px 10px; }
#page-play .p2-tables .p2-card-head p, #page-play .p2-ranked .p2-card-head p { color: rgba(255, 240, 220, 0.8); }

/* Nút cuộn trái / phải */
.p2-scroll {
  position: absolute; top: 50%; z-index: 5; width: 44px; height: 44px; border-radius: 50%; border: 2px solid #e8b75a; cursor: pointer;
  display: grid; place-items: center; background: linear-gradient(180deg, #fff6dc, #f1d9a4); color: #7a3d0e;
  box-shadow: 0 6px 16px rgba(60, 35, 15, 0.3); transition: opacity 0.2s, transform 0.2s;
}
.p2-scroll:hover { transform: scale(1.08); }
.p2-scroll.prev { left: 6px; }
.p2-scroll.next { right: 6px; }
.p2-scroll.prev .ico { transform: rotate(180deg); }
.p2-scroll[disabled] { opacity: 0; pointer-events: none; }
#page-play .p2-grid { scroll-padding-left: 6px; }

/* Cờ phướn co giãn: thiết kế ở 300px, phóng theo --bn-k (JS tính để 4 lá vừa một khung hình) */
#page-play { --bn-w: 300px; }
#page-play .p2-entry { zoom: var(--bn-k, 1); }
#page-play .p2-grid { justify-content: safe center; }

/* Cờ phướn dài theo màn hình: cắt ảnh 3 phần (đầu 60px · thân · đuôi hoa văn 446px) — chỉ kéo dãn phần thân
   Tỉ lệ theo ảnh gốc 1024×1536, khung thấy được rộng 772px (x 126–898) → đơn vị theo --bn-w */
#page-play .p2-entry { height: var(--bn-h, calc(var(--bn-w) * 1.8886)); }
#page-play .p2-entry::before {
  background: none;
  top: calc(var(--bn-w) * -0.022); bottom: calc(var(--bn-w) * -0.079); left: calc(var(--bn-w) * -0.1632); right: calc(var(--bn-w) * -0.1632);
  border-style: solid; border-color: transparent;
  border-image-source: var(--bn-img); border-image-slice: 60 169 446 170 fill; border-image-repeat: stretch;
  border-image-width: calc(var(--bn-w) * 0.0777) calc(var(--bn-w) * 0.2189) calc(var(--bn-w) * 0.5777) calc(var(--bn-w) * 0.2202);
}
#page-play { padding-bottom: 20px; }
/* Phần trong suốt hai bên ảnh vẽ bằng border-image-outset (chỉ tràn hình, không làm dãy cờ tưởng bị tràn → không hiện thanh cuộn thừa) */
#page-play .p2-entry::before {
  inset: 0;
  border-image-outset: calc(var(--bn-w) * 0.022) calc(var(--bn-w) * 0.1632) calc(var(--bn-w) * 0.079) calc(var(--bn-w) * 0.1632);
}

/* Đầu trang Xếp hạng & Túi đồ cùng khoảng cách như trang AI (mẫu gốc): đầu trang 23px · thanh tab ở 119px · nội dung từ 196px */
#page-ranking > .tabs-row { margin-bottom: 18px; } /* thanh tab dạng nút cao 45px (AI 43px) → bù 2px */
#page-inventory > .page-head .coin-pill { margin-block: -9px; } /* ô xu không làm đầu trang cao thêm */

/* =====================================================================
   AI · Xếp hạng · Túi đồ/Cửa hàng vừa một màn hình (≥1100px): không cuộn trang,
   phần dài cuộn bên trong khung, bàn cờ xem trước tự nhỏ lại theo chiều cao
   Nội dung các trang này bắt đầu ở ~196px (đầu trang + thanh tab), chừa 30px lề dưới
   ===================================================================== */
@media (min-width: 1100px) {
  /* Đấu với AI: cột trái (cấp độ, màu quân...) cuộn bên trong; bàn cờ luyện tập vừa chiều cao */
  #ai-panel-ai > .cols { height: calc(100dvh - 226px); align-items: stretch; }
  #ai-panel-ai > .cols > .card { min-height: 0; overflow-y: auto; gap: 12px; }
  #ai-panel-ai > .cols > .col-side { min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 14px; }
  #ai-panel-ai > .cols > .col-side > .card:first-child { flex: 1 1 auto; min-height: 0; }
  #ai-panel-ai .col-side .mini-board { width: min(100%, calc((100dvh - 470px) * 0.9)); margin: 0 auto; }

  /* Lịch sử luyện tập / Cờ thế: danh sách dài cuộn trong khung */
  #ai-panel-history, #ai-panel-puzzles { max-height: calc(100dvh - 226px); overflow-y: auto; }

  /* Xếp hạng: bảng dài cuộn trong khung */
  #page-ranking > .cols { height: calc(100dvh - 226px); align-items: stretch; }
  #page-ranking > .cols > * { min-height: 0; overflow-y: auto; }

  /* Túi đồ & Cửa hàng: lưới vật phẩm cuộn bên trong, khung xem trước co theo chiều cao */
  #page-inventory > .cols { height: calc(100dvh - 285px); align-items: stretch; }
  #page-inventory .col-main { display: flex; flex-direction: column; min-height: 0; }
  #page-inventory .col-main .inv-grid { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 4px 8px 2px; align-content: start; }
  #page-inventory .col-side { min-height: 0; }
  #page-inventory .inv-preview { height: 100%; overflow: hidden; gap: 8px; padding: 14px 16px; }
  #page-inventory .inv-preview .mini-board { width: min(100%, calc((100dvh - 285px - 330px) * 0.9)); }
  #page-inventory .inv-preview .kv { margin: 0; }
  #page-inventory .inv-preview .note { margin: 0; font-size: 12px; }
  #page-inventory .inv-preview .btn { margin-top: auto; }
}
@media (min-width: 1100px) { #page-ai, #page-ranking, #page-inventory { padding-bottom: 30px; } }
@media (min-width: 1201px) {
  /* Phân tích vừa một màn hình: bàn cờ nhỏ hơn 10px theo chiều cao để chừa lề dưới */
  .ab-frame { width: min(calc(min(100vw, var(--frame, 1440px)) - var(--sidebar) - 230px - 330px - 120px), max(280px, calc((100dvh - var(--topbar) - 245px) * var(--pz-ar, 1)))); }
}

/* Đồng hồ: tổng thời gian + thời gian nước đi bên cạnh (ván giới hạn mỗi nước) */
.clock .clock-move { display: none; }
.clock.dual { flex-direction: row; align-items: stretch; gap: 6px; }
.clock.dual .clock-move { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 58px; padding: 2px 8px; border-radius: var(--r-sm); background: var(--sunken); border: 1px solid var(--line); line-height: 1.1; }
.clock.dual .clock-move i { font-style: normal; font-size: 10.5px; color: var(--muted); font-weight: 600; }
.clock.dual .clock-move em { font-style: normal; font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.clock.dual.running .clock-move { border-color: var(--red); color: var(--red); }
.clock.dual.move-low .clock-move { background: var(--red); color: #fff; animation: clock-pulse 1s steps(2) infinite; }
.clock.dual.move-low .clock-move i { color: rgba(255, 255, 255, 0.85); }
@media (min-width: 1100px) {
  #game:not(.ended) .player .clock.dual { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
  #game:not(.ended) .player .clock.dual b { font-size: 28px; text-align: left; }
  #game:not(.ended) .player .clock.dual .clock-move { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 210, 122, 0.35); color: #ffe2a8; min-width: 64px; padding: 4px 8px; }
  #game:not(.ended) .player .clock.dual .clock-move i { color: #d9bf98; }
  #game:not(.ended) .player .clock.dual .clock-move em { font-size: 17px; font-family: var(--serif); }
  #game:not(.ended) .player .clock.dual.running .clock-move { border-color: #ffd27a; color: #fff; box-shadow: 0 0 10px rgba(255, 210, 122, 0.35); }
  #game:not(.ended) .player .clock.dual.move-low .clock-move { background: #c42a1f; border-color: #ff8a6e; color: #fff; }
}

/* ---------- Đồng hồ kiểu mới: ⏳ tổng thời gian (xanh lá) · 🕒 thời gian nước đi (cam), trên nền sẫm ---------- */
.clock.pair {
  display: inline-flex; flex-direction: row; align-items: center; gap: 12px; padding: 5px 10px; border-radius: 8px;
  background: rgba(24, 18, 14, 0.82); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06); line-height: 1;
}
.clock.pair > span { display: inline-flex; align-items: center; gap: 5px; }
.clock.pair > span[hidden] { display: none; }
.clock.pair svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.clock.pair b, .clock.pair em {
  font: 700 15px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-style: normal; font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
  background: none; border: 0; padding: 0; min-width: 0; color: inherit; text-shadow: none; animation: none;
}
.clock.pair .ck-total { color: #5fd38a; }
.clock.pair .ck-move { color: #f2a03d; }
/* Bên không đến lượt: mờ đi */
.clock.pair:not(.running) { opacity: 0.62; }
.clock.pair.running { box-shadow: inset 0 0 0 1px rgba(242, 160, 61, 0.45), 0 0 10px rgba(242, 160, 61, 0.18); }
.clock.pair.running b, .clock.pair.running em { background: none; color: inherit; }
/* Sắp hết giờ: phần tương ứng chuyển đỏ và nhấp nháy */
.clock.pair.total-low .ck-total, .clock.pair.move-low .ck-move { color: #ff5a4a; animation: clock-pulse 1s steps(2) infinite; }
.clock.pair.low b { animation: none; }

/* Trên bàn đấu (thẻ người chơi ngang): đồng hồ to, chiếm hết bề ngang thẻ */
@media (min-width: 1100px) {
  #game:not(.ended) .player .clock.pair { display: flex; justify-content: space-around; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.42); }
  #game:not(.ended) .player .clock.pair svg { width: 20px; height: 20px; }
  #game:not(.ended) .player .clock.pair b, #game:not(.ended) .player .clock.pair em { font-size: 24px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: inherit; text-shadow: none; }
  #game:not(.ended) .player .clock.pair.running b, #game:not(.ended) .player .clock.pair.running em { color: inherit; text-shadow: 0 0 10px currentColor; }
}

/* Bàn đấu: nhãn trạng thái & bàn có ghế trống */
.p2-live.ready { color: #e9b44c; }
.p2-live.ready i { background: #e9b44c; box-shadow: 0 0 0 3px rgba(233, 180, 76, 0.22); }
.p2-live.wait { color: #7fd6a4; }
.p2-live.wait i { background: #3fbf6e; box-shadow: 0 0 0 3px rgba(63, 191, 110, 0.22); }
.p2-pl.empty span { font-style: italic; opacity: 0.6; }
.p2-watch.join { background: linear-gradient(180deg, #3fbf6e, #23854a); border-color: #23854a; color: #fff; }
.p2-watch.off { opacity: 0.55; cursor: default; font-size: 11.5px; }

/* Bàn Tranh xu trong danh sách Bàn đấu: huy hiệu mức cược */
.p2-thumb { position: relative; }
.p2-stake-badge { position: absolute; left: 4px; bottom: 4px; display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 800; color: #5a1a0e; background: linear-gradient(180deg, #ffe39b, #e9ae45); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
.p2-stake-badge .ico { width: 12px; height: 12px; }
.p2-table.is-coin { box-shadow: inset 0 0 0 1px rgba(233, 174, 69, 0.55); }

/* =====================================================================
   MÀN HÌNH KẾT QUẢ — BẢN 3 (thay toàn bộ phong cách trước)
   Cả khu vực một tông: nền sơn mài (thắng: đỏ son · thua: mực xám · hoà: ngọc bích),
   thẻ hai bên trong suốt viền chỉ vàng; thẻ giữa: triện 勝/敗/和, tiêu đề in hoa, góc hoa văn mảnh
   ===================================================================== */
#game.ended {
  --rs-bg1: #5a0d08; --rs-bg2: #250403; --rs-acc: #f0c463; --rs-acc2: #b8862b; --rs-text: #fff4e2; --rs-muted: #e2c7a4;
  --rs-panel: rgba(255, 236, 205, 0.06); --rs-line: rgba(240, 196, 99, 0.3); --rs-seal: #c8241a; --rs-btn1: #ffe7a6; --rs-btn2: #e2a43a; --rs-btn-text: #4a1508;
}
#game.ended[data-result="lose"] {
  --rs-bg1: #2c303a; --rs-bg2: #111318; --rs-acc: #d5dce6; --rs-acc2: #8b95a5; --rs-text: #eef1f6; --rs-muted: #a9b2c0;
  --rs-panel: rgba(220, 228, 240, 0.05); --rs-line: rgba(200, 210, 225, 0.22); --rs-seal: #4b515d; --rs-btn1: #f4f6f9; --rs-btn2: #c3cad5; --rs-btn-text: #1d222b;
}
#game.ended[data-result="draw"] {
  --rs-bg1: #11473b; --rs-bg2: #061c17; --rs-acc: #e8d18a; --rs-acc2: #a8924a; --rs-text: #f1f7f2; --rs-muted: #b9d3c8;
  --rs-panel: rgba(220, 245, 235, 0.05); --rs-line: rgba(232, 209, 138, 0.28); --rs-seal: #1f7a62; --rs-btn1: #fbefc2; --rs-btn2: #d9b961; --rs-btn-text: #1e2a20;
}

/* Bỏ các trang trí cũ */
#game.ended .res-crown, #game.ended .laurel, #game.ended .res-scene, #game.ended .res-ribbon, #game.ended .res-lantern, #game.ended .res-clouds { display: none !important; }

/* ---------- Khung chung (≥1100px): một tấm sơn mài chứa 3 cột ---------- */
@media (min-width: 1100px) {
  #game.ended .game-grid {
    padding: 16px; border-radius: 20px; gap: 14px 16px;
    height: calc(100dvh - var(--topbar) - 52px);
    grid-template-columns: minmax(210px, 280px) minmax(380px, 460px) minmax(270px, 340px);
    background:
      radial-gradient(70% 55% at 50% 0%, color-mix(in srgb, var(--rs-acc) 16%, transparent), transparent 70%),
      repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 12px),
      linear-gradient(180deg, var(--rs-bg1), var(--rs-bg2));
    box-shadow: 0 24px 60px rgba(20, 8, 4, 0.35), inset 0 0 0 1px var(--rs-line);
  }
  /* Thẻ hai bên: trong suốt, viền chỉ vàng, chữ sáng */
  #game.ended .moves-card, #game.ended .end-insight, #game.ended .result-view > .card:nth-child(2), #game.ended .radar-card {
    background: var(--rs-panel) !important; border: 1px solid var(--rs-line) !important; box-shadow: none !important;
    color: var(--rs-text); border-radius: 14px; backdrop-filter: blur(2px);
  }
  #game.ended .moves-card h3, #game.ended .end-insight h3, #game.ended .result-view > .card h3 {
    font-family: var(--serif); color: var(--rs-acc); font-size: 15px; letter-spacing: 0.02em;
  }
  #game.ended .moves-card .muted, #game.ended .end-insight .muted, #game.ended .end-insight p, #game.ended .end-chart-head small,
  #game.ended .radar-card .card-head p, #game.ended .result-view .stat-row small { color: var(--rs-muted) !important; }
  #game.ended .result-view .stat-row b { color: var(--rs-text); }
  #game.ended .end-insight .tag { background: rgba(255, 255, 255, 0.08); color: var(--rs-muted); border: 1px solid var(--rs-line); }
  #game.ended .end-insight .btn.primary { background: transparent; border: 1px solid var(--rs-acc); color: var(--rs-acc); box-shadow: none; }
  #game.ended .end-insight .btn.primary:hover { background: color-mix(in srgb, var(--rs-acc) 16%, transparent); }
  #game.ended .end-insight .btn.primary .ico { color: var(--rs-acc); }
  /* Biên bản */
  #game.ended .moves-card select, #game.ended .moves-card .icon-btn { background: rgba(255, 255, 255, 0.06); border-color: var(--rs-line); color: var(--rs-text); }
  #game.ended .moves-card select option { color: #222; }
  #game.ended #move-list { color: var(--rs-text); }
  #game.ended #move-list li:nth-child(even) > *, #game.ended #move-list li:nth-child(even) button { background: rgba(255, 255, 255, 0.04); }
  #game.ended #move-list button { color: var(--rs-text); }
  #game.ended #move-list button.r { color: #ff9a86; }
  #game.ended #move-list li.result-line, #game.ended #move-list li.empty { color: var(--rs-muted); }
  #game.ended #move-list li.empty::before { filter: invert(1); opacity: 0.25; }
  #game.ended .moves-card .replay-bar, #game.ended .moves-card .rp-label { color: var(--rs-muted); border-color: var(--rs-line); }
  #game.ended .moves-card thead th, #game.ended .moves-card .mv-head { color: var(--rs-muted); }
  /* Biểu đồ trận đấu */
  #game.ended .end-chart { background: rgba(0, 0, 0, 0.18); border-color: var(--rs-line); }
  #game.ended .end-chart .grid { stroke: rgba(255, 255, 255, 0.07); }
  #game.ended .end-chart .zero { stroke: rgba(255, 255, 255, 0.28); }
  #game.ended .end-chart .up { fill: color-mix(in srgb, var(--rs-acc) 32%, transparent); }
  #game.ended .end-chart .down { fill: rgba(255, 255, 255, 0.1); }
  #game.ended .end-chart .line { stroke: var(--rs-acc); }
  /* Chỉ số ván đấu: chữ không bị cắt */
  #game.ended .radar-card { overflow: hidden; }
  #game.ended #radar { overflow: visible; max-height: calc(100dvh - var(--topbar) - 500px); min-height: 130px; }
  #game.ended #radar .web, #game.ended #radar .axis { stroke: rgba(255, 255, 255, 0.14); }
  #game.ended #radar text { fill: var(--rs-muted); font-size: 12.5px; }
  #game.ended #radar .shape { fill: color-mix(in srgb, var(--rs-acc) 22%, transparent); stroke: var(--rs-acc); }
  #game.ended #radar .pt { fill: var(--rs-acc); }
  #game.ended .radar-legend li { border-color: rgba(255, 255, 255, 0.08); color: var(--rs-muted); }
  #game.ended .radar-legend b { color: var(--rs-text); }
}

/* ---------- Thẻ kết quả ở giữa ---------- */
#game.ended #result-card {
  position: relative; isolation: isolate; overflow: hidden; text-align: center; align-items: center; justify-content: center;
  gap: 10px; padding: 26px 26px 20px; border-radius: 16px;
  background: radial-gradient(80% 45% at 50% 0%, color-mix(in srgb, var(--rs-acc) 14%, transparent), transparent 70%),
              linear-gradient(180deg, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.28)) !important;
  border: 1px solid var(--rs-acc) !important;
  box-shadow: inset 0 0 0 5px rgba(0, 0, 0, 0.18), inset 0 0 0 6px var(--rs-line), 0 18px 40px rgba(0, 0, 0, 0.35) !important;
  color: var(--rs-text); animation: rise 0.35s ease-out;
}
/* Góc hoa văn */
#game.ended .res-deco { display: block; position: absolute; inset: 10px; z-index: -1; pointer-events: none; }
#game.ended .res-deco .rc { position: absolute; width: 34px; height: 34px; color: var(--rs-acc); opacity: 0.85; }
#game.ended .res-deco .rc svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.6; }
#game.ended .res-deco .rc.tl { left: 0; top: 0; }
#game.ended .res-deco .rc.tr { right: 0; top: 0; transform: scaleX(-1); }
#game.ended .res-deco .rc.bl { left: 0; bottom: 0; transform: scaleY(-1); }
#game.ended .res-deco .rc.br { right: 0; bottom: 0; transform: scale(-1, -1); }
/* Triện 勝 / 敗 / 和 */
#game.ended #result-card .result-ico { display: grid !important; place-items: center; width: auto; height: auto; background: none; box-shadow: none; margin: 0; }
#game.ended #result-card .seal {
  display: grid; place-items: center; width: 62px; height: 62px; border-radius: 10px; transform: rotate(-6deg);
  font: 700 38px/1 "LXGW WenKai TC", "Noto Serif TC", serif; color: #fff7ea;
  background: var(--rs-seal); box-shadow: inset 0 0 0 3px var(--rs-seal), inset 0 0 0 4px rgba(255, 255, 255, 0.55), 0 8px 18px rgba(0, 0, 0, 0.35);
}
/* Tiêu đề */
#game.ended #result-card .result-title {
  font: 800 32px/1.1 var(--serif); letter-spacing: 0.16em; text-transform: uppercase; margin: 4px 0 0;
  background: linear-gradient(180deg, #fff, var(--rs-acc) 55%, var(--rs-acc2)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
}
#game.ended #result-card .res-flourish { display: block; position: relative; width: 58%; height: 10px; margin: 0 auto; }
#game.ended #result-card .res-flourish::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: linear-gradient(90deg, transparent, var(--rs-acc), transparent); }
#game.ended #result-card .res-flourish i { position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; transform: translate(-50%, -50%) rotate(45deg); background: var(--rs-acc); box-shadow: none; }
#game.ended #result-card #result-sub { font: 600 14px/1.4 var(--serif); color: var(--rs-muted) !important; margin: 0; }
/* Hai kỳ thủ */
#game.ended #result-card .vs-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; width: 100%; margin: 6px 0 0; }
#game.ended #result-card .vs-side { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
#game.ended #result-card .vs-ring { position: relative; padding: 3px; border-radius: calc(var(--av-r) + 4px); background: rgba(255, 255, 255, 0.18); box-shadow: none; margin: 14px 0 6px; }
#game.ended #result-card .vs-side.winner .vs-ring { background: linear-gradient(145deg, #fff3c4, var(--rs-acc) 45%, var(--rs-acc2)); box-shadow: 0 0 18px color-mix(in srgb, var(--rs-acc) 45%, transparent); }
#game.ended #result-card .vs-side .avatar { width: 64px; height: 64px; font-size: 22px; border: 0; }
#game.ended #result-card .mini-crown { top: -18px; width: 30px; height: 17px; fill: var(--rs-acc); filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.4)); }
#game.ended #result-card .vs-side b { font: 700 15px/1.25 var(--serif); color: var(--rs-text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#game.ended #result-card .vs-side small { color: var(--rs-muted); font-size: 12px; }
#game.ended #result-card .vs-score { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0; }
#game.ended #result-card .vs-score span { font: 700 40px/1 var(--serif); color: var(--rs-text); text-shadow: none; }
#game.ended #result-card .vs-div { width: 46px; }
#game.ended #result-card .vs-div::before { background: linear-gradient(90deg, transparent, var(--rs-acc), transparent); }
#game.ended #result-card .vs-div::after { background: var(--rs-bg1); border-color: var(--rs-acc); }
#game.ended #result-card .elo-chg { margin-top: 4px; padding: 2px 10px; font-size: 12px; border-width: 1px; background: rgba(0, 0, 0, 0.2); }
#game.ended #result-card .delta-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
#game.ended #result-card .delta-row .delta { background: rgba(0, 0, 0, 0.22); border: 1px solid var(--rs-line); color: var(--rs-acc); }
#game.ended #result-card .result-hint { color: var(--rs-acc); font-size: 13px; margin: 0; }
/* Thế cờ cuối ván */
#game.ended #result-card .res-board-wrap {
  display: block; margin: 2px auto 0; padding: 5px; border-radius: 10px; background: linear-gradient(180deg, #d9b07a, #a8793f);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 10px 24px rgba(0, 0, 0, 0.35) !important;
  width: min(100%, max(180px, calc((100dvh - var(--topbar) - 52px - 32px - 560px) / 1.03)));
}
#game.ended #res-board { border-radius: 6px; }
/* Nút */
#game.ended #result-card .result-actions { width: 100%; margin-top: 4px; }
#game.ended #result-card .result-actions .btn.primary {
  width: 100%; min-width: 0; padding: 12px 16px; border-radius: 12px; border: 0;
  font: 700 18px/1.2 var(--serif); letter-spacing: 0.02em; color: var(--rs-btn-text);
  background: linear-gradient(180deg, var(--rs-btn1), var(--rs-btn2)) !important;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 10px 22px rgba(0, 0, 0, 0.3) !important;
}
#game.ended #result-card .result-actions .btn.primary .ico { color: var(--rs-btn-text); }
#game.ended #result-card .result-links {
  display: flex !important; flex-wrap: wrap; justify-content: center; gap: 2px 4px; width: 100%;
  padding: 8px 0 0 !important; background: none !important; border-top: 1px solid var(--rs-line);
}
#game.ended #result-card .result-links .btn { color: var(--rs-text); font: 600 13.5px/1 inherit; padding: 7px 10px; background: none; border: 0; }
#game.ended #result-card .result-links .btn:hover { background: rgba(255, 255, 255, 0.08); }
#game.ended #result-card .result-links .btn .ico { color: var(--rs-acc) !important; }
#game.ended #result-card .result-links .btn.hidden, #game.ended #result-card .result-links #res-board { display: none !important; }
#game.ended #result-card #res-again.ask { color: #7ee0a3; }
/* Lấp lánh nhẹ khi thắng (thay cánh hoa) — thua & hoà không có hiệu ứng */
#game.ended #result-card .res-fx { display: block; position: absolute; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
#game.ended #result-card.win .res-fx i {
  position: absolute; top: auto; bottom: -10px; width: 4px; height: 4px; border-radius: 50%; background: var(--rs-acc); opacity: 0;
  box-shadow: 0 0 8px var(--rs-acc); animation: rs-spark linear infinite; transform: none;
}
#game.ended #result-card.lose .res-fx i, #game.ended #result-card.draw .res-fx i { display: none; }
@keyframes rs-spark { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 0.9; } 100% { transform: translateY(-90vh); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #game.ended #result-card .res-fx { display: none; } }
@media (min-width: 1100px) {
  #game.ended #result-card { grid-area: res; overflow: hidden; }
}
@media (min-width: 1100px) and (max-height: 820px) {
  #game.ended #result-card { gap: 7px; padding: 18px 22px 14px; }
  #game.ended #result-card .seal { width: 50px; height: 50px; font-size: 30px; }
  #game.ended #result-card .result-title { font-size: 26px; }
  #game.ended #result-card .vs-side .avatar { width: 54px; height: 54px; }
  #game.ended #result-card .vs-score span { font-size: 34px; }
  #game.ended #result-card .res-board-wrap { width: min(100%, max(160px, calc((100dvh - var(--topbar) - 52px - 32px - 480px) / 1.03))); }
}
@media (min-width: 1100px) {
  /* Bàn cờ cuối ván to hơn: phần chữ & nút trong thẻ chiếm ~470px */
  #game.ended #result-card .res-board-wrap { width: min(100%, max(180px, calc((100dvh - var(--topbar) - 52px - 32px - 470px) / 1.03))); }
  #game.ended .moves-card .mv-head { background: rgba(255, 255, 255, 0.06); color: var(--rs-muted); }
  #game.ended .radar-wrap { gap: 2px; }
}
@media (min-width: 1100px) and (max-height: 820px) {
  #game.ended #result-card .res-board-wrap { width: min(100%, max(160px, calc((100dvh - var(--topbar) - 52px - 32px - 410px) / 1.03))); }
}

/* Kết quả: bỏ triện chữ Hán trên tiêu đề; bàn cờ cuối ván chiếm phần chỗ còn lại (co giãn) để nút luôn hiện đủ */
#game.ended #result-card .result-ico { display: none !important; }
#game.ended #result-card > * { flex-shrink: 0; }
#game.ended #result-card .res-board-wrap {
  flex: 1 1 0; min-height: 110px; width: 100% !important; display: flex !important; justify-content: center; align-items: center;
  padding: 0; margin: 2px 0; background: none !important; box-shadow: none !important; border-radius: 0;
}
#game.ended #res-board {
  height: 100%; width: auto; max-width: 100%; max-height: 330px; display: block; box-sizing: border-box; padding: 5px; border-radius: 10px;
  background: linear-gradient(180deg, #d9b07a, #a8793f); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 10px 24px rgba(0, 0, 0, 0.35);
}
#game.ended #result-card { justify-content: flex-start; }
#game.ended #result-card .result-title { margin-top: 6px; }
@media (min-width: 1100px) { #game.ended .radar-card { overflow-y: auto !important; } }

/* Khách chưa đăng nhập: ổ khoá nhỏ ở các mục cần tài khoản (chỉ Trang chủ & AI dùng tự do) */
body.is-guest .nav-item[data-go]:not([data-go="home"]):not([data-go="ai"]) { opacity: 0.72; }
body.is-guest .nav-item[data-go]:not([data-go="home"]):not([data-go="ai"])::after, body.is-guest #ai-tabs .tab[data-ai-tab="puzzles"]::after, body.is-guest #ai-tabs .tab[data-ai-tab="history"]::after {
  content: ""; width: 13px; height: 13px; margin-left: auto; flex: none; opacity: 0.8; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27 fill=%27none%27 stroke=%27black%27 stroke-width=%272.4%27 stroke-linecap=%27round%27%3E%3Crect x=%275%27 y=%2711%27 width=%2714%27 height=%279%27 rx=%272%27/%3E%3Cpath d=%27M8 11V8a4 4 0 0 1 8 0v3%27/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27 fill=%27none%27 stroke=%27black%27 stroke-width=%272.4%27 stroke-linecap=%27round%27%3E%3Crect x=%275%27 y=%2711%27 width=%2714%27 height=%279%27 rx=%272%27/%3E%3Cpath d=%27M8 11V8a4 4 0 0 1 8 0v3%27/%3E%3C/svg%3E") center / contain no-repeat;
}
body.is-guest #ai-tabs .tab[data-ai-tab="puzzles"], body.is-guest #ai-tabs .tab[data-ai-tab="history"] { display: inline-flex; align-items: center; gap: 6px; }

/* =====================================================================
   Theo Figma (14/10): trang Bàn đấu — thẻ bàn tối, 3 thẻ mỗi hàng trong khung viền đứt
   ===================================================================== */
.p2-tables-page { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; padding: 40px; align-content: start; min-height: calc(100dvh - 190px); }
.p2-tables-page::before { content: ""; position: absolute; inset: 20px; border: 1px dashed #4a3a30; border-radius: 10px; pointer-events: none; }
.tk-table {
  display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 14px; position: relative;
  background: linear-gradient(180deg, #2a1f19, #1a130f); border: 1px solid #4a3a30; min-width: 0;
}
.tk-thumb { width: 84px; flex: none; aspect-ratio: 1; border-radius: 4px; overflow: hidden; background: #e9c98f; }
.tk-thumb svg { width: 100%; height: 100%; display: block; }
.tk-tinfo { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.tk-tstatus { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: #f1e7da; }
.tk-tstatus i { width: 7px; height: 7px; border-radius: 50%; background: #3fbf6e; }
.tk-tstatus.wait i { background: #e9b44c; }
.tk-tstatus.ready i { background: #5b8def; }
.tk-tstatus em { display: inline-flex; align-items: center; gap: 3px; font-style: normal; font-weight: 500; color: #b8a898; margin-left: 6px; }
.tk-tstatus em .ico { width: 12px; height: 12px; }
.tk-tnames { font-size: 14.5px; color: #fff; white-space: pre; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tk-tinfo small { font-size: 12.5px; color: #cbbfb2; }
.tk-tbtn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; cursor: pointer; font: 700 13px var(--serif);
  background: linear-gradient(180deg, #3a2c24, #1d1612); color: #f6e1b0; border: 1px solid #8a6a3a;
}
.tk-tbtn:hover { filter: brightness(1.15); }
.tk-tbtn.join { background: linear-gradient(180deg, #d93a2b, #a3150f); color: #fff; border-color: #8a1712; }
.tk-tbtn.off { opacity: 0.55; cursor: default; font: 600 12px inherit; }
.tk-tbtn .ico { width: 13px; height: 13px; }

/* Theo Figma (14/10): Chơi với bạn — nhịp chơi là 3 ô chọn cùng hàng */
.room-tc-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.room-tc-row .field { margin: 0; }
.room-tc-row select:disabled { opacity: 0.55; }
@media (max-width: 560px) { .room-tc-row { grid-template-columns: 1fr; } }

/* Theo Figma (14/10): Đấu với AI — lưới cấp độ 3 × 3, cấp 9 nằm trong lưới, tên đỏ */
@media (min-width: 900px) {
  .level-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .level.boss { grid-column: auto; }
}
.level.boss b { color: var(--red); }

/* Theo Figma (14/10): menu Hồ sơ xếp theo cột — trái 5 mục xem, phải Mục tiêu + 4 thao tác, không vạch ngăn */
.pf-menu { grid-template-rows: repeat(5, auto); grid-auto-flow: column; }
.pf-menu-sep { display: none; }

/* Sửa lỗi (khổ < 1100px): thẻ kết quả không có tấm sơn mài phía sau → nền sáng, chữ trắng khó đọc.
   Thêm nền sơn mài ngay trên thẻ */
@media (max-width: 1099px) {
  #game.ended #result-card {
    background: radial-gradient(80% 45% at 50% 0%, color-mix(in srgb, var(--rs-acc) 14%, transparent), transparent 70%),
                linear-gradient(180deg, var(--rs-bg1), var(--rs-bg2)) !important;
  }
}

/* =====================================================================
   GIAO DIỆN ĐIỆN THOẠI theo Figma (14/10) — chỉ áp dụng khi màn ≤ 760px
   ===================================================================== */
.bottom-nav, .g-chat-btn, .g-mbar { display: none; }
@media (max-width: 760px) {
  /* ---- Thanh tab dưới cùng ---- */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: #0e0b09; padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.25);
  }
  .bottom-nav .bnav-item {
    display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; cursor: pointer;
    color: #a89887; font: 500 12px/1.2 inherit; padding: 2px 0;
  }
  .bottom-nav .bnav-item .ico { width: 23px; height: 23px; stroke-width: 1.6; }
  .bottom-nav .bnav-item.active { color: #fff; }
  .bottom-nav .bnav-item.active .ico { color: #ff6b57; }
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  body[data-screen="game"] .bottom-nav { display: none; }
  body[data-screen="game"] { padding-bottom: 0; }

  /* ---- Trang chủ: bỏ 4 ô lối tắt và gợi ý Cửa hàng ---- */
  #lobby .quick-grid, #lobby .grid-3:has(#home-shop) { display: none; }

  /* ---- Bảng xếp hạng: tab một hàng cuộn ngang, top 3 cùng một hàng ---- */
  #rank-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  #rank-tabs::-webkit-scrollbar { display: none; }
  #rank-tabs button { flex: none; white-space: nowrap; }
  #page-ranking .podium { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  #page-ranking .podium-card { align-items: center; text-align: center; padding: 12px 6px; gap: 6px; }
  #page-ranking .podium-card .pc-top { justify-content: center; }
  #page-ranking .podium-card .pc-top svg { display: none; }
  #page-ranking .podium-card .who { flex-direction: column; gap: 6px; }
  #page-ranking .podium-card .who small { display: none; }
  #page-ranking .podium-card .who b { font-size: 13px; max-width: 100%; }
  #page-ranking .podium-card .val { font-size: 20px; }
  #page-ranking .podium-card .val small { display: none; }
  #page-ranking #rank-me { display: none; }

  /* ---- AI · Phân tích: bàn cờ · điều hướng · thao tác · [engine | biên bản] ---- */
  .ab-layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) !important;
    grid-template-areas: "main main" "eng moves" "chart moves" !important; gap: 10px !important;
  }
  .ab-left, .ab-right { display: contents !important; }
  .ab-main { grid-area: main; }
  .ab-engcard { grid-area: eng; }
  .ab-movescard { grid-area: moves; align-self: stretch; }
  .ab-evalcard { grid-area: chart; display: none !important; }
  .ab-chart-mode .ab-evalcard { display: flex !important; border-top-left-radius: 0 !important; border-top-right-radius: 0 !important; margin-top: -10px; border-top: 0 !important; }
  .ab-chart-mode .ab-engcard { border-bottom-left-radius: 0 !important; border-bottom-right-radius: 0 !important; }
  .ab-chart-mode .ab-engcard > :not(.ab-controls) { display: none !important; }
  .ab-chart-mode .ab-chart-note { display: none; }
  .ab-card { padding: 10px !important; gap: 8px !important; border-radius: 14px; }
  .ab-engcard .card-head, .ab-engcard .ab-stats, .ab-engcard .ab-filter, .ab-engcard .ab-controls .check,
  .ab-engcard .ab-controls select:not(.ab-view):not(:first-child) { display: none !important; }
  .ab-controls { flex-wrap: nowrap; gap: 4px; }
  .ab-controls .sel-sm { min-width: 0; flex: 1 1 0; padding: 4px 20px 4px 8px !important; font-size: 11.5px !important; border-radius: 999px; }
  .ab-score { font-size: 22px; }
  .ab-lines { max-height: none !important; min-height: 0 !important; gap: 2px; }
  .ab-line { padding: 3px 4px 3px 8px !important; border: 0 !important; border-left: 3px solid #2e9e5b !important; border-radius: 4px !important; background: none !important; }
  .ab-line:not(.q-best):not(.q-good) { border-left-color: transparent !important; }
  .ab-line .ab-strength, .ab-line .ab-sample, .ab-line .ab-ldepth { display: none !important; }
  .ab-line .ab-lhead { gap: 6px; font-size: 13px; }
  .ab-line .ab-qtag { font-size: 11px; }
  .ab-line:not(.q-best):not(.q-good) .ab-qtag { display: none; }
  .ab-movescard .card-head small { display: none; }
  .ab-movescard .ab-moves { max-height: 260px !important; min-height: 0 !important; }
  .ab-toolbar { flex-direction: column; flex-wrap: nowrap !important; gap: 8px !important; width: 100%; }
  .ab-toolbar .ab-sep { display: none; }
  .ab-navgrp, .ab-actgrp { display: flex; gap: 6px; justify-content: center; width: 100%; }
  .ab-navgrp .btn { height: 26px !important; width: 30px; padding: 0 !important; font-size: 10px !important; }
  .ab-actgrp .btn { flex: 1 1 0; min-width: 0; padding: 0 4px !important; font-size: 12px !important; }
  .ab-actgrp .ab-new { order: 1; }
  .ab-actgrp .ab-setup { order: 2; }
  .ab-actgrp .ab-flip { order: 3; }
  .ab-actgrp .ab-save { order: 4; }
  .ab-actgrp .ab-share { order: 5; }

  /* ---- Bàn cờ trong trận: thẻ kỳ thủ gọn, menu thao tác bật lên, trò chuyện dạng khung nổi ---- */
  body #game:not(.ended) .game-head .lead, body #game:not(.ended) .head-acts { display: none; }
  body #game:not(.ended) .game-grid { display: flex !important; flex-wrap: wrap; align-items: center; gap: 10px; height: auto !important; grid-template-areas: none; }
  body #game:not(.ended) .board-col, body #game:not(.ended) .game-side { display: contents !important; }
  body #game:not(.ended) .end-board-head, body #game:not(.ended) .end-insight, body #game:not(.ended) .moves-card { display: none !important; }
  body #game:not(.ended) #p-top { order: 1; }
  body #game:not(.ended) .g-chat-btn { order: 2; }
  body #game:not(.ended) .board-frame { order: 3; width: 100% !important; max-width: none !important; margin: 0 !important; }
  body #game:not(.ended) .eval-card { order: 4; width: 100%; }
  body #game:not(.ended) .g-mbar { order: 5; }
  body #game:not(.ended) #p-bottom { order: 6; margin-left: auto; }
  body #game:not(.ended) .actions-card { order: 7; width: 100%; }
  body #game:not(.ended) .chat-card { order: 8; }

  body #game:not(.ended) .player {
    display: grid !important; grid-template-columns: 40px auto; grid-template-areas: "av info" "clock clock"; gap: 6px 8px; align-items: center;
    width: auto !important; max-width: 62%; min-height: 0 !important; padding: 7px 9px !important; border-radius: 6px !important;
    background: linear-gradient(180deg, #7a2418, #4a120c) !important; border: 1px solid #a9562f !important; color: #fff3dc;
    box-shadow: 0 6px 14px rgba(60, 20, 10, 0.28) !important;
  }
  body #game:not(.ended) #p-bottom { grid-template-columns: auto 40px; grid-template-areas: "info av" "clock clock"; text-align: right; }
  body #game:not(.ended) .player .pc-avatar { grid-area: av; width: 40px !important; height: 40px !important; max-width: none; max-height: none; margin: 0; }
  body #game:not(.ended) .player .pc-initial { font-size: 14px !important; }
  body #game:not(.ended) .player .pc-info { grid-area: info; min-width: 0; }
  body #game:not(.ended) .player .pc-name { font: 700 12.5px/1.2 var(--serif); color: #fff3dc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body #game:not(.ended) .player .pc-sub { font-size: 10.5px; color: #e3cbb5; display: flex; flex-direction: column; }
  body #game:not(.ended) .player .pc-sub .pc-elo { color: #f9dc8a; font-weight: 700; }
  body #game:not(.ended) .player .pc-sub .pc-handle { display: none; }
  body #game:not(.ended) .player .pc-caps { display: none !important; }
  body #game:not(.ended) .player .clock { grid-area: clock; justify-self: start; }
  body #game:not(.ended) #p-bottom .clock { justify-self: end; }
  body #game:not(.ended) .player .clock.pair { gap: 6px; padding: 0; background: none; box-shadow: none; opacity: 1; }
  body #game:not(.ended) .player .clock.pair > span { padding: 2px 6px; border-radius: 4px; }
  body #game:not(.ended) .player .clock.pair b, body #game:not(.ended) .player .clock.pair em { font-size: 11px; }
  body #game:not(.ended) .player .clock.pair .ck-total { color: #1f8a4c; background: #e6f6ec; }
  body #game:not(.ended) .player .clock.pair .ck-move { color: #d9730d; background: #fff1e2; }
  body #game:not(.ended) .player .clock.pair svg { width: 11px; height: 11px; }

  .g-chat-btn {
    display: grid; place-items: center; margin-left: auto; width: 44px; height: 38px; border-radius: 8px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--line); color: var(--text); box-shadow: var(--shadow);
  }
  body #game:has(#chat-card.hidden) .g-chat-btn { display: none; }
  body #game.ended .g-chat-btn, body #game.ended .g-mbar { display: none !important; }

  .g-mbar { display: flex; align-items: center; gap: 10px; }
  .g-mbtn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; min-width: 52px; padding: 0 12px; cursor: pointer;
    border-radius: 8px; background: var(--surface); border: 1px solid var(--line); color: var(--text); font: 700 13px inherit; box-shadow: var(--shadow);
  }
  .g-mbtn.gold { background: linear-gradient(180deg, #f6d98c, #e2b75a); border-color: #c99a3a; color: #4a2c0c; font-family: var(--serif); }
  body #game:has(#btn-hint.hidden) #g-hint-btn { display: none; }
  body #game.acts-open #g-menu-btn { background: var(--ink); color: #fff; }

  /* Thẻ máy phân tích: chỉ điểm số + thanh thế trận */
  body #game:not(.ended) .eval-card { padding: 10px 14px !important; gap: 6px; }
  body #game:not(.ended) .eval-card .card-head, body #game:not(.ended) .eval-card .eval-lines, body #game:not(.ended) .eval-card .eval-meta { display: none !important; }

  /* Thẻ thao tác: chỉ hiện lời mời (xin hoà, đi lại, sẵn sàng); các nút nằm trong menu bật lên */
  body #game:not(.ended) .actions-card { background: none !important; border: 0 !important; box-shadow: none !important; padding: 0 !important; gap: 8px; }
  body #game:not(.ended) .actions-card .status-box { display: none; }
  body #game:not(.ended) .actions-card .actions { display: none; }
  body #game.acts-open:not(.ended) .actions-card .actions {
    display: flex; flex-direction: column; gap: 8px; position: fixed; left: var(--acts-left, 16px); bottom: var(--acts-bottom, 74px); z-index: 70; width: 170px;
    padding: 10px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  }
  body #game.acts-open .actions .btn { width: 100%; justify-content: center; }
  body #game.acts-open .actions #btn-hint { display: none; }
  body #game.acts-open .actions #btn-draw { background: linear-gradient(180deg, #f6d98c, #e2b75a); border-color: #c99a3a; color: #4a2c0c; }
  body #game.acts-open .actions #btn-resign { background: linear-gradient(180deg, #d93a2b, #a3150f); border-color: #8a1712; color: #fff; }

  /* Trò chuyện: khung nổi phía dưới khi bấm nút chat */
  body #game:not(.ended) .chat-card { display: none !important; }
  body #game.chat-open:not(.ended) .chat-card:not(.hidden) {
    display: flex !important; flex-direction: column; position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 70; max-height: 60dvh;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  }

  /* ---- Kết quả: chỉ thẻ kết quả, biểu đồ chỉ số nằm trong thẻ thay cho bàn cờ ---- */
  body #game.ended .board-col, body #game.ended .game-side { display: none !important; }
  body #game.ended .result-view > .card:not(#result-card) { display: none !important; }
  body #game.ended #result-card .res-board-wrap { display: none !important; }
  body #game.ended #result-card .radar-wrap { width: 100%; background: #fff; border-radius: 8px; padding: 6px; color: var(--text); }
  body #game.ended #result-card .radar-wrap .radar-legend { display: none; }
}

/* Ô chọn "Nước đi / Thế trận" chỉ dùng trên điện thoại */
.ab-controls .ab-view { display: none; }
@media (max-width: 760px) { .ab-controls .ab-view { display: block; } }
@media (max-width: 760px) {
  .ab-line .ab-lhead { flex-wrap: nowrap; white-space: nowrap; }
  .ab-line .ab-lscore { margin-left: auto; font-size: 12.5px; }
}
@media (max-width: 760px) {
  body #game:not(.ended) .player .pc-sub > span::before { content: none !important; }
}
@media (max-width: 760px) {
  body #game .game-head .lead { display: none; }
}

/* =====================================================================
   Điện thoại (bổ sung): thanh tab luôn hiện; Phân tích & bàn cờ đang đánh vừa đúng một màn hình (không cuộn)
   ===================================================================== */
@media (max-width: 760px) {
  :root { --tabbar: calc(66px + env(safe-area-inset-bottom)); }
  body[data-screen="game"] .bottom-nav { display: grid; }
  body[data-screen="game"] { padding-bottom: var(--tabbar); }

  /* Màn cố định: trang cao đúng phần còn lại giữa thanh trên và thanh tab */
  body:has(#page-ai:not(.hidden) #ai-panel-analysis:not(.hidden)),
  body:has(#game:not(.hidden):not(.ended)) { padding-bottom: 0; overflow: hidden; }
  body:has(#page-ai:not(.hidden) #ai-panel-analysis:not(.hidden)) .shell,
  body:has(#game:not(.hidden):not(.ended)) .shell { min-height: 0; height: 100dvh; overflow: hidden; }

  /* ---- Phân tích ---- */
  #page-ai:has(#ai-panel-analysis:not(.hidden)) {
    height: calc(100dvh - var(--topbar, 64px)); overflow: hidden; padding-bottom: calc(var(--tabbar) + 10px) !important;
    display: flex; flex-direction: column; gap: 8px;
  }
  #page-ai:has(#ai-panel-analysis:not(.hidden)) .page-head { margin: 0; }
  #page-ai:has(#ai-panel-analysis:not(.hidden)) #ai-tabs { margin: 0; flex: none; }
  #ai-panel-analysis:not(.hidden) { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  #ai-panel-analysis .ab-layout { flex: 1 1 auto; min-height: 0; height: 100%; grid-template-rows: auto minmax(0, 1fr) 0 !important; row-gap: 8px !important; }
  #ai-panel-analysis .ab-layout.ab-chart-mode { grid-template-rows: auto auto minmax(0, 1fr) !important; }
  #ai-panel-analysis .ab-main { gap: 8px; }
  /* bàn cờ thu theo chiều cao còn lại (chừa ~150px cho hai khung bên dưới) */
  #ai-panel-analysis .ab-frame { width: min(100%, calc((100dvh - var(--topbar, 64px) - var(--tabbar) - 330px) * var(--pz-ar, 1))) !important; }
  #ai-panel-analysis .ab-engcard, #ai-panel-analysis .ab-movescard, #ai-panel-analysis .ab-evalcard { min-height: 0; overflow-y: auto; }
  #ai-panel-analysis .ab-movescard .ab-moves { max-height: none !important; }
  #ai-panel-analysis .ab-evalcard .ab-chart { height: auto; flex: 1 1 auto; min-height: 60px; }

  /* ---- Bàn cờ đang đánh ---- */
  body #game:not(.hidden):not(.ended) {
    height: calc(100dvh - var(--topbar, 64px)); overflow: hidden; padding-bottom: calc(var(--tabbar) + 8px) !important;
    display: flex; flex-direction: column; gap: 6px;
  }
  body #game:not(.ended) .game-head { margin: 0; flex: none; }
  body #game:not(.ended) .game-head h1 { font-size: 22px; line-height: 1.2; }
  body #game:not(.ended) .game-grid { flex: 1 1 auto; min-height: 0; align-content: space-between; row-gap: 8px !important; }
  /* bàn cờ thu theo chiều cao: phần cố định ≈ đầu trang 70 + thẻ đối thủ 72 + thanh thế trận 50 + hàng dưới 78 + khoảng cách */
  /* cỡ bàn do JS đo phần còn trống (--m-board-w), chưa đo thì dùng ước lượng */
  body #game:not(.ended) .board-frame {
    width: var(--m-board-w, min(100%, calc((100dvh - var(--topbar, 64px) - var(--tabbar) - 320px) * var(--board-ar, 1)))) !important;
    margin: 0 auto !important; flex: none;
  }
  body #game:not(.ended) .eval-card { padding: 8px 12px !important; }
  body #game:not(.ended) .eval-card .eval-score b { font-size: 20px; }
  body #game.chat-open:not(.ended) .chat-card:not(.hidden) { bottom: calc(var(--tabbar) + 8px); }
  /* lời mời (xin hoà, đi lại, sẵn sàng) nổi phía trên thanh tab để không đẩy bố cục */
  body #game:not(.ended) .actions-card { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar) + 8px); z-index: 65; width: auto !important; pointer-events: none; }
  body #game:not(.ended) .actions-card > * { pointer-events: auto; }
  body #game:not(.ended) .actions-card .banner, body #game:not(.ended) .actions-card .ready-box { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); background: var(--surface); }
}

/* Điện thoại: lúc đánh cờ và lúc phân tích ẩn thanh tab để bàn cờ rộng hơn (phần còn lại giữ thanh tab) */
@media (max-width: 760px) {
  body[data-screen="game"] .bottom-nav,
  body:has(#page-ai:not(.hidden) #ai-panel-analysis:not(.hidden)) .bottom-nav { display: none !important; }
  body[data-screen="game"],
  body:has(#page-ai:not(.hidden) #ai-panel-analysis:not(.hidden)) { --tabbar: env(safe-area-inset-bottom); padding-bottom: 0 !important; }
}

/* Điện thoại: thanh thế trận dọc bên trái bàn cờ thay cho khung "Máy phân tích"; đầu trang AI gọn hơn */
.g-evalv { display: none; }
@media (max-width: 760px) {
  body #game:not(.ended) .eval-card { display: none !important; }
  body #game:not(.ended) .g-evalv:not(.hidden) {
    display: block; order: 3; align-self: stretch; position: relative; width: 12px; flex: none; padding: 0; cursor: pointer;
    border-radius: 6px; overflow: hidden; background: #2a2420; border: 1px solid rgba(0, 0, 0, 0.25);
    box-shadow: 0 4px 10px rgba(60, 35, 15, 0.2);
  }
  body #game:not(.ended) .g-evalv i {
    position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: linear-gradient(180deg, #e04a3a, #b3160f);
    transition: height 0.4s ease;
  }
  /* giữa thanh: vạch cân bằng */
  body #game:not(.ended) .g-evalv::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(255, 255, 255, 0.55); }
  body #game:not(.ended) .g-evalv.off { opacity: 0.35; }
  body #game:not(.ended) .g-evalv.off i { height: 50% !important; }
  body #game:not(.ended):has(.g-evalv:not(.hidden)) .board-frame { margin: 0 !important; }
  body #game:not(.ended):has(.g-evalv:not(.hidden)) .game-grid { column-gap: 8px; }

  /* Đầu trang AI (Quay lại · tab) nhỏ lại để dành chỗ cho bàn cờ */
  #page-ai .page-head { margin: 0 0 2px !important; }
  #page-ai .page-head .eyebrow { font-size: 11.5px; margin: 0; }
  #page-ai #ai-tabs { gap: 18px; margin-bottom: 6px !important; }
  #page-ai #ai-tabs .tab { font-size: 13.5px; padding: 6px 1px; }
  #page-ai:has(#ai-panel-analysis:not(.hidden)) { padding-top: 10px !important; gap: 4px !important; }
}
@media (max-width: 760px) {
  body #game:not(.ended):has(.g-evalv:not(.hidden)) .board-frame { width: var(--m-board-w, min(calc(100% - 20px), calc((100dvh - var(--topbar, 64px) - var(--tabbar) - 260px) * var(--board-ar, 1)))) !important; }
}
@media (max-width: 760px) {
  /* ngắt dòng: thanh thế trận + bàn cờ luôn nằm chung một hàng riêng */
  body #game:not(.ended) .game-grid::before { content: ""; order: 3; flex-basis: 100%; height: 0; }
  body #game:not(.ended) .board-frame, body #game:not(.ended) .g-evalv:not(.hidden) { order: 4 !important; }
  body #game:not(.ended) .game-grid { row-gap: 6px !important; }
}

/* Điện thoại · bàn cờ đang đánh: lưới cố định — thẻ đối thủ ngay trên bàn cờ, hàng nút + thẻ của bạn sát đáy */
@media (max-width: 760px) {
  body #game:not(.ended) .game-grid {
    display: grid !important; grid-template-columns: 12px minmax(0, 1fr) auto; column-gap: 8px !important; row-gap: 8px !important;
    grid-template-areas: "top top chat" "bar board board" "mbar mbar me"; grid-template-rows: auto auto minmax(0, 1fr);
    align-content: stretch; align-items: start;
  }
  body #game:not(.ended) .game-grid::before { display: none; }
  body #game:not(.ended) #p-top { grid-area: top; justify-self: start; }
  body #game:not(.ended) .g-chat-btn { grid-area: chat; align-self: center; }
  body #game:not(.ended) .g-evalv:not(.hidden) { grid-area: bar; align-self: stretch; width: 12px; }
  body #game:not(.ended) .board-frame { grid-area: board; justify-self: center; }
  body #game:not(.ended):not(:has(.g-evalv:not(.hidden))) .board-frame { grid-column: 1 / -1; }
  body #game:not(.ended) .g-mbar { grid-area: mbar; align-self: end; }
  body #game:not(.ended) #p-bottom { grid-area: me; align-self: end; justify-self: end; margin: 0 !important; }
  body #game:not(.ended) .eval-card, body #game:not(.ended) .actions-card, body #game:not(.ended) .chat-card { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  body #game:not(.ended) #p-top, body #game:not(.ended) #p-bottom { width: max-content !important; max-width: 100% !important; }
  body #game:not(.ended) #p-bottom { max-width: 64vw !important; }
}

/* Điện thoại: banner trang chủ gọn lại (ít khoảng trên/dưới, chữ nhỏ hơn) */
@media (max-width: 760px) {
  #lobby > .hero { min-height: 0 !important; border-radius: 14px; }
  #lobby .hero-body { padding: 16px 18px !important; gap: 8px !important; }
  #lobby .hero h2 { font-size: 21px !important; line-height: 1.25; margin: 0; }
  #lobby .hero-meta { font-size: 12.5px; gap: 4px 14px; margin: 0; }
  #lobby .hero-actions { gap: 8px; margin-top: 2px; }
  #lobby .hero-actions .btn { padding-top: 7px !important; padding-bottom: 7px !important; font-size: 14px; }
  #lobby .hero .tag { font-size: 11px; padding: 3px 9px; }
}
/* Điện thoại: hiện logo 象 ở góc phải banner */
@media (max-width: 760px) {
  #lobby > .hero { grid-template-columns: minmax(0, 1fr) 118px !important; align-items: center; }
  #lobby .hero-art { display: grid !important; padding: 8px 10px 8px 0; }
  #lobby .hero-art img { width: 108px !important; }
}
@media (max-width: 760px) {
  #lobby > .hero { grid-template-columns: minmax(0, 1fr) 86px !important; }
  #lobby .hero-art img { width: 72px !important; }
}
