/* © 2026 Đổi chữ (doichu.fun), bảo lưu mọi quyền — xem LICENSE.
 * Đổi chữ — giao diện “vở ô li”: giấy kẻ ô, mực tím, bút đỏ chấm bài.
 * Xem DESIGN.md cho bảng màu, chữ và quy ước từng màn hình. */

:root {
  --paper: #fdfdf7;
  --grid: #dbe8ee;
  --grid-strong: #a8c6d4;
  --page-line: #dcebf1;      /* kẻ ô của nền trang: nhạt hơn ô chữ để không tranh với nội dung */
  --page-line-fine: #eff6f8;
  --ink: #3b2f9b;        /* mực tím: chữ chính, nút */
  --ink-deep: #231b5e;   /* chữ thân bài */
  --pencil: #5c6070;     /* chữ phụ */
  --red: #cf2f2a;        /* bút đỏ: lỗi, gấp, kết quả */
  --mark: #ffe96b;       /* bút dạ quang: chữ vừa đổi, lượt đang đi */
  --green: #1c7448;
  --cell: 32px;
  --tile: min(88px, calc((100vw - 64px) / 5));
  --hand: "Playwrite VN", "Segoe Script", "Bradley Hand", cursive;
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --step: 2400ms;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--paper);
  scroll-behavior: smooth;
  scroll-padding-top: 16px;
}
/* DJO-39: ẩn nội dung đến khi biết session — tránh nháy landing khi đã đăng nhập. */
html.booting #noi-dung,
html.booting .foot { visibility: hidden; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink-deep);
  font: 400 17px/1.65 var(--sans);
  /* Giấy ô li: ô lớn 32px, mỗi ô chia bốn dòng kẻ mờ. */
  background:
    linear-gradient(var(--page-line) 1px, transparent 1px) 0 0 / var(--cell) var(--cell),
    linear-gradient(90deg, var(--page-line) 1px, transparent 1px) 0 0 / var(--cell) var(--cell),
    linear-gradient(var(--page-line-fine) 1px, transparent 1px) 0 0 / calc(var(--cell) / 4) calc(var(--cell) / 4),
    linear-gradient(90deg, var(--page-line-fine) 1px, transparent 1px) 0 0 / calc(var(--cell) / 4) calc(var(--cell) / 4),
    var(--paper);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 0 20px 64px;
}
/* Sảnh ngắn vẫn giữ footer ở cuối màn hình; sảnh dài cuộn tự nhiên. */
body:has(#lobby:not([hidden])) .page { min-height: 100dvh; display: flex; flex-direction: column; }
body:has(#lobby:not([hidden])) #noi-dung { flex: 1 0 auto; }
/* Lề đỏ của trang vở. */
@media (min-width: 760px) {
  .page {
    padding: 0 40px 64px 56px;
    border-left: 2px solid rgb(207 47 42 / .45);
    min-height: 100dvh;
  }
}

h1, h2, h3, p, ol, ul, figure { margin: 0; }
h1 {
  font: 400 clamp(24px, 4.2vw, 34px)/1.7 var(--hand);
  color: var(--ink);
}
h1[tabindex="-1"]:focus { outline: none; }
h2 { font: 600 17px/1.4 var(--sans); }
strong { font-weight: 600; }
code { font-size: .9em; background: #fff; padding: 1px 5px; border: 1px solid var(--grid-strong); border-radius: 4px; }
a { color: var(--ink); }

.skip {
  position: absolute; left: 16px; top: -60px; z-index: 10;
  padding: 10px 14px; border-radius: 8px;
  background: var(--ink); color: var(--paper); text-decoration: none; font-weight: 600;
}
.skip:focus { top: 12px; }
.visually-hidden, .sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important; min-width: 0 !important; min-height: 0 !important; padding: 0 !important; margin: -1px !important;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0 !important;
}

/* ── Thanh trên ───────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px 16px;
  padding: 18px 0;
}
.logo, .brand {
  font: 400 26px/1.7 var(--hand);
  color: var(--ink);
  text-decoration: none;
}
.logo { border-bottom: 2px solid var(--red); }
.logo small { font: 500 12px var(--sans); color: var(--pencil); margin-left: 8px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.brand img, .brand svg { width: 34px; height: 34px; flex: none; }
.brand span { border-bottom: 2px solid var(--red); font: 400 24px/1.7 var(--hand); color: var(--ink); }
.brand span { white-space: nowrap; }
.top-end { display: flex; align-items: center; gap: 10px 12px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.gate-nav { display: flex; align-items: center; gap: 22px; }
.gate-nav a:not(.submit) {
  font-size: 15px; font-weight: 500;
  text-decoration: underline; text-decoration-color: var(--grid-strong);
  text-decoration-thickness: 2px; text-underline-offset: 5px;
}
.gate-nav a:not(.submit):hover { text-decoration-color: var(--ink); }
.gate-nav .submit--small.is-covered { visibility: hidden; }
@media (max-width: 759px) {
  .gate-nav a:not(.submit) { display: none; }
}
/* Sau đăng nhập gate-view ẩn: ẩn luôn nav landing trên thanh trên. */
body:is(:has(#gate-view[hidden]), .account-page) .gate-nav { display: none; }
.flag-toggle {
  display: inline-grid; place-items: center; width: 36px; height: 30px; padding: 0;
  border: 2px solid transparent; border-radius: 6px; background: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.flag-toggle:hover { border-color: var(--grid-strong); }
.flag-toggle:focus-visible { border-color: var(--ink); background: rgb(59 47 155 / .06); }
.flag-toggle svg { display: block; width: 24px; height: 16px; border-radius: 2px; box-shadow: 0 0 0 1px rgb(35 27 94 / .12); }
.flag-toggle[data-ui-lang="vi"] .flag-en,
.flag-toggle[data-ui-lang="en"] .flag-vi { display: none; }
.icon-button {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 8px; background: none; color: var(--ink); cursor: pointer;
  text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.icon-button:hover { background: rgb(59 47 155 / .07); }
.icon-button[aria-pressed="false"] { color: var(--pencil); }
.icon-button svg { width: 22px; height: 22px; }
.icon-button[aria-pressed="true"] .sound-off,
.icon-button[aria-pressed="false"] .sound-on { display: none; }
.menu-only { display: none !important; }
#top-actions .menu-only[hidden] { display: none !important; }
.desktop-only { display: none; }
@media (min-width: 641px) {
  .desktop-only.user-chip { display: inline-flex; }
  .desktop-only.icon-button { display: inline-grid; }
  .lang-switch--menu { display: none; }
}
@media (max-width: 640px) {
  /* DJO-54: ẩn cờ desktop chỉ sau đăng nhập (menu có cờ riêng); landing mobile vẫn hiện cờ trái cụm. */
  body:is(:has(#gate-view[hidden]), .account-page) .lang-switch--desktop { display: none; }
}
.account { position: relative; }
.account-toggle { display: none; }
.account-name { display: none; }
.top-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.user-label { display: none !important; }
a.user-chip { text-decoration: none; }
.profile-form {
  display: grid;
  gap: 8px;
}
.profile-form label { font-size: 13px; margin-bottom: 2px; }
.profile-form label span { color: var(--pencil); font-weight: 400; }
.profile-form input[type="text"],
.profile-form input[type="url"] {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1.5px solid var(--grid-strong);
  border-radius: 8px;
  background: var(--paper);
}
.profile-form .hint { margin: 0; font-size: 12px; color: var(--pencil); text-align: center; }
#hoso-form.profile-form { margin-bottom: 16px; }
.avatar-frame {
  position: relative;
  justify-self: center;
  width: 160px;
  height: 160px;
  margin-bottom: 20px;
  border-radius: 50%;
}
.avatar-view { display: block; padding: 0; border: 0; border-radius: 50%; background: none; cursor: zoom-in; }
.avatar-view:disabled { opacity: 1; cursor: default; }
.avatar.hoso-preview {
  display: grid;
  place-items: center;
  width: 160px;
  height: 160px;
  overflow: hidden;
  border-radius: 50%;
  border: 1.5px solid var(--grid-strong);
  background: var(--ink);
  color: var(--paper);
  font: 600 56px/1 var(--sans);
  justify-self: center;
}
.avatar-tools {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.avatar-frame:hover .avatar-tools,
.avatar-frame:focus-within .avatar-tools { opacity: 1; }
.avatar-frame:hover .avatar-tool,
.avatar-frame:focus-within .avatar-tool { pointer-events: auto; }
.avatar-tool {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--grid-strong);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.avatar-tool svg { width: 20px; height: 20px; }
.avatar-tool.danger { color: var(--red); }
.avatar-tool:hover { background: #fff; }
@media (hover: none) {
  #avatar-frame { height: auto; margin-bottom: 8px; }
  .avatar-tools { position: static; margin-top: 8px; opacity: 1; }
  .avatar-tool { pointer-events: auto; }
}
.avatar-lightbox {
  max-width: min(900px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 52px 12px 12px; border: 1.5px solid var(--grid-strong); border-radius: 12px;
  background: var(--paper);
}
.avatar-lightbox::backdrop { background: rgb(35 27 94 / .65); }
.avatar-lightbox > .icon-button { position: absolute; right: 4px; top: 4px; width: 44px; height: 44px; font-size: 28px; }
.avatar-lightbox img { display: block; max-width: 100%; max-height: calc(100dvh - 112px); object-fit: contain; }
@media (prefers-reduced-motion: reduce) { .avatar-tools { transition: none; } }
@media (max-width: 480px) {
  .avatar-frame,
  .avatar.hoso-preview { width: 128px; height: 128px; }
  .avatar.hoso-preview { font-size: 48px; }
}
.crop-modal .hint { margin: 0 0 12px; text-align: center; }
.crop-viewport:focus-within { outline: 3px solid var(--ink); outline-offset: 2px; }
.crop-modal {
  border: 1.5px solid var(--grid-strong);
  border-radius: 12px;
  padding: 18px;
  background: var(--paper);
  color: var(--ink);
  max-width: min(360px, calc(100vw - 32px));
}
.crop-modal::backdrop { background: color-mix(in srgb, var(--ink) 35%, transparent); }
.crop-modal h2 { margin: 0 0 12px; font-size: 18px; }
.crop-viewport {
  width: min(280px, 80vw);
  height: min(280px, 80vw);
  margin: 0 auto 14px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid var(--grid-strong);
  background: #fff;
  touch-action: none;
}
.crop-viewport canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.crop-modal label { display: block; margin-bottom: 6px; font-size: 13px; }
.crop-modal input[type="range"] { width: 100%; margin-bottom: 14px; }
.crop-modal .lobby-actions { justify-content: flex-end; }
.avatar {
  flex: none; display: inline-grid; place-items: center; overflow: hidden;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--mark); color: var(--ink-deep); border: 1.5px solid var(--grid-strong);
  font: 600 13px/1 var(--sans);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Thanh trên / menu tài khoản theo lobby Opus: avatar mực tím. */
.topbar .avatar {
  width: 30px; height: 30px;
  background: var(--ink); color: var(--paper); border-color: transparent;
}

/* ── Nút, ô nhập, thông báo ──────────────────────────────────────────────── */
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 24px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 0 var(--ink-deep);
  transform: translateY(0);
  transition: background-color 140ms ease, transform 90ms cubic-bezier(.22, 1, .36, 1), box-shadow 90ms cubic-bezier(.22, 1, .36, 1);
}
.submit:hover:not(:disabled) { background: var(--ink-deep); }
.submit:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--ink-deep);
  transition-duration: 50ms;
}
.submit:disabled { box-shadow: none; }
.submit--small { min-height: 40px; padding: 0 16px; font-size: 15px; }
.submit--wide { width: 100%; min-height: 48px; }

.text-button {
  position: relative;
  isolation: isolate;
  display: inline-block;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  background-image: linear-gradient(var(--grid-strong), var(--grid-strong));
  background-repeat: no-repeat;
  background-position: 50% calc(50% + .78em);
  background-size: 100% 2px;
  transition: transform 90ms cubic-bezier(.22, 1, .36, 1);
}
.text-button::before, .text-button::after {
  content: ""; position: absolute; left: -5px; right: -5px; top: 50%; z-index: -1; pointer-events: none;
  clip-path: inset(0 100% 0 0); transition: clip-path 240ms cubic-bezier(.22, 1, .36, 1);
}
.text-button::before {
  height: 1.38em;
  background: linear-gradient(96deg, rgb(255 233 107 / .45), rgb(255 233 107 / .88) 16%, rgb(255 233 107 / .78) 84%, rgb(255 233 107 / .35));
  border-radius: 10px 4px 12px 5px / 6px 5px 6px 4px;
  transform: translateY(-50%) skewX(-13deg) rotate(-1.1deg);
}
.text-button::after {
  height: 0.92em;
  background: linear-gradient(92deg, rgb(255 224 62 / .2), rgb(255 224 62 / .62) 25%, rgb(255 224 62 / .48) 85%, transparent);
  border-radius: 6px 10px 4px 8px;
  transform: translateY(-42%) skewX(-8deg) rotate(0.6deg); transition-delay: 25ms;
}
.text-button.danger::before { background: linear-gradient(96deg, rgb(207 47 42 / .08), rgb(207 47 42 / .18) 20%, rgb(207 47 42 / .13) 85%, rgb(207 47 42 / .05)); }
.text-button.danger::after { background: linear-gradient(92deg, transparent, rgb(207 47 42 / .10) 25%, rgb(207 47 42 / .08) 85%, transparent); }
.text-button:hover:not(:disabled):not([aria-disabled="true"]):not([aria-current="page"])::before,
.text-button:hover:not(:disabled):not([aria-disabled="true"]):not([aria-current="page"])::after,
.text-button:focus-visible:not(:disabled):not([aria-disabled="true"]):not([aria-current="page"])::before,
.text-button:focus-visible:not(:disabled):not([aria-disabled="true"]):not([aria-current="page"])::after { clip-path: inset(0 0% 0 0); }
.text-button:active:not(:disabled):not([aria-disabled="true"]):not([aria-current="page"]) {
  transform: translateY(1px);
  transition-duration: 50ms;
}
.text-button.danger { color: var(--red); }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 4px; }
.submit:focus-visible { outline-color: var(--red); }

input[type=text], input[type=password], input[type=email], input:not([type]), select {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background-color: #fff;
}
input::placeholder { color: #8589a0; }
input:disabled { border-color: var(--grid-strong); background: rgb(255 255 255 / .6); }
input[aria-invalid="true"] { border-color: var(--red); }
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
label span { font-weight: 400; color: var(--pencil); margin-left: 6px; }

.input-row { display: flex; gap: 10px; }
.input-row input { flex: 1; min-width: 0; font-size: 18px; }

.message { min-height: 1.6em; margin-top: 10px; font-size: 14px; color: var(--pencil); }
.message:empty { min-height: 0; margin-top: 0; }
.message.error { color: var(--red); font-weight: 500; }
.message.success { color: var(--green); font-weight: 500; }
.hint { font-size: 13px; color: var(--pencil); }

.panel {
  padding: 22px;
  background: #fff;
  border: 1.5px solid var(--grid-strong);
  border-radius: 12px;
}

/* ── Khung màn hình ──────────────────────────────────────────────────────── */
.view { padding-top: 24px; }
.view--narrow { max-width: 640px; }
.view--medium { max-width: 760px; }
.view-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* ── Ô chữ (dùng chung cho ví dụ ở trang đầu và bàn chơi) ─────────────────── */
.tiles { display: flex; justify-content: center; gap: 8px; }
.tile {
  display: grid;
  place-items: center;
  width: var(--tile);
  height: var(--tile);
  font: 600 calc(var(--tile) * .58)/1 var(--sans);
  color: var(--ink);
  /* Một ô li: viền đậm, bên trong chia bốn. */
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 -1px / 25% 25%,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) -1px 0 / 25% 25%,
    #fff;
  border: 1.5px solid var(--grid-strong);
  border-radius: 4px;
}
/* Chữ vừa đổi ở nước đi mới: vàng thoáng qua rồi về trắng, không giữ màu (vàng chỉ là dấu “vừa đổi”, không phải trạng thái). */
@media (prefers-reduced-motion: no-preference) {
  /* Chỉ chạy khi có nước đi mới; vẽ lại cùng trạng thái không làm ô nháy lại. */
  .tile.changed.pop { animation: tile-flash .9s ease-out both; }
  @keyframes tile-flash {
    0% { transform: translateY(-5px); background-color: var(--mark); }
    28% { transform: none; background-color: var(--mark); }
    78% { transform: none; background-color: var(--mark); }
    100% { transform: none; background-color: #fff; }
  }
}
@media (prefers-reduced-motion: reduce) {
  .tile.changed.pop { animation: tile-flash-still .9s ease-out both; }
  @keyframes tile-flash-still {
    0%, 78% { background-color: var(--mark); }
    100% { background-color: #fff; }
  }
}

/* ── Landing (gate-view): hero, bàn thử, FAQ, đăng nhập ───────────────────── */
#gate-view { padding-top: 0; }
#gate-view .hero { padding: 28px 0 88px; text-align: center; }
#gate-view .ladder { margin: 40px auto 0; width: max-content; max-width: 100%; }
#gate-view .ladder-turn {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 16px; margin-bottom: 10px; font-size: 15px; color: var(--pencil);
}
#gate-view .ladder-turn b {
  font-weight: 600; color: var(--ink-deep); background: var(--mark);
  padding: 1px 6px; border-radius: 3px;
}
#gate-view .hero .tiles {
  --tile: min(132px, calc((100vw - 76px) / 4));
  gap: clamp(6px, 1.4vw, 14px);
}
#gate-view .track {
  height: 6px; margin-top: 18px; border-radius: 3px;
  background: var(--grid); overflow: hidden;
}
#gate-view .track i {
  display: block; height: 100%; width: 62%;
  background: var(--ink); border-radius: inherit;
}
@media (prefers-reduced-motion: no-preference) {
  #gate-view .track i.run { animation: drain var(--step) linear both; }
  @keyframes drain { from { width: 100%; } to { width: 0; } }
}
#gate-view .chain {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 2px 10px; min-height: 1.7em; margin-top: 16px;
  list-style: none; padding: 0; font-size: 18px; color: var(--pencil);
}
#gate-view .chain li + li::before { content: "→"; margin-right: 10px; color: var(--grid-strong); }
#gate-view .chain li:last-child { color: var(--ink); font-weight: 600; }
#gate-view .hero h1 {
  margin: 44px auto 0; max-width: 16em;
  font: 400 clamp(34px, 5.8vw, 62px)/1.55 var(--hand);
  color: var(--ink); text-wrap: balance;
}
#gate-view .lead {
  margin: 18px auto 0; max-width: 34em;
  font-size: clamp(17px, 1.9vw, 19px); color: var(--pencil); text-wrap: pretty;
}
#gate-view .hero-actions {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: 14px 26px; margin-top: 30px;
}
#gate-view .fine { margin-top: 14px; font-size: 14px; color: var(--pencil); }
#gate-view .ladder-pause { margin-top: 6px; font-size: 13px; color: var(--pencil); }

#gate-view .section { padding: 72px 0; }
#gate-view .section-head { max-width: 40em; margin-bottom: 36px; }
#gate-view .section-head h2 {
  font: 600 clamp(24px, 3.2vw, 32px)/1.3 var(--sans);
  color: var(--ink-deep); text-wrap: balance;
}
#gate-view .section-head p { margin-top: 12px; color: var(--pencil); text-wrap: pretty; }
#gate-view .split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 40px; align-items: start; }
@media (min-width: 900px) {
  #gate-view .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 56px; }
}
#gate-view .try-example { margin-top: 14px; font-size: 15px; color: var(--pencil); }
#gate-view .ex { font-weight: 600; color: var(--ink); white-space: nowrap; }

#try-board {
  margin-top: 0;
  padding: 24px 24px 22px;
  border-color: var(--ink);
}
#try-board .board-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; margin-bottom: 18px; font-size: 14px; color: var(--pencil);
}
#try-board .board-head strong { color: var(--ink-deep); font-weight: 600; }
#try-board .tiles {
  --tile: min(76px, calc((100vw - 120px) / 5));
  margin: 0;
}
#try-board .field { margin-top: 24px; }
#try-board .message { font-size: 15px; }
#try-board .try-history {
  margin-top: 18px; padding-top: 14px;
  border-top: 1px solid var(--grid);
}
#try-board .try-history h3 { font-size: 14px; font-weight: 600; color: var(--pencil); }
#try-board .try-history ol {
  display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 6px;
  list-style: none; padding: 0; color: var(--pencil);
}
#try-board .try-history li + li::before { content: "→"; margin-right: 10px; color: var(--grid-strong); }
#try-board .try-history li:last-child { color: var(--ink); font-weight: 600; }
#try-board .try-board-foot {
  display: flex; flex-wrap: wrap; gap: 4px 22px; margin-top: 14px;
}

#gate-view .faq { max-width: 46em; }
#gate-view .faq details { border-bottom: 1px solid var(--grid-strong); }
#gate-view .faq details:first-child { border-top: 1px solid var(--grid-strong); }
#gate-view .faq summary {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 16px 0; list-style: none; cursor: pointer;
  font-weight: 600; font-size: 18px; color: var(--ink-deep);
}
#gate-view .faq summary::-webkit-details-marker { display: none; }
#gate-view .faq summary::after {
  content: "+"; flex: none; font-weight: 500; font-size: 24px; line-height: 1; color: var(--ink);
}
#gate-view .faq details[open] summary::after { content: "−"; }
#gate-view .faq details p { padding: 0 0 18px; color: var(--pencil); max-width: 40em; }

#gate-view .closing { padding: 88px 0 64px; text-align: center; }
#gate-view .closing h2 {
  font: 400 clamp(28px, 4.6vw, 46px)/1.6 var(--hand);
  color: var(--ink); text-wrap: balance;
}
#gate-view .closing > p { margin: 12px auto 28px; max-width: 32em; color: var(--pencil); text-wrap: balance; }
/* Lời mời chỉ hiện khi mở link vào phòng. */
#gate-view .closing .gate-lead { margin: 0 auto 18px; max-width: 32em; }
#gate-view .closing .gate .submit { width: auto; }

.gate {
  max-width: 560px;
  margin: 0 auto;
  text-align: center;
}
.gate-heading { font-size: 20px; }
.gate-lead { margin: 6px 0 18px; color: var(--pencil); }
.gate .submit { width: min(320px, 100%); }
.gate.error { text-align: left; }

.foot {
  display: grid; gap: 10px; margin-top: 28px; padding-top: 28px;
  border-top: 1px solid var(--grid-strong); font-size: 14px; color: var(--pencil);
}
.foot nav { display: flex; flex-wrap: wrap; gap: 4px 22px; }
.foot a { color: inherit; display: inline-flex; align-items: center; min-height: 44px; }
.legal a[href^="mailto:"] { display: inline-flex; align-items: center; min-height: 44px; }
body:has(#room-waiting:not([hidden])) .foot,
body:has(#game-shell:not([hidden])) .foot { display: none; }

/* ── Sảnh (design/lobby-opus.html) ───────────────────────────────────────── */
#lobby { padding-top: 0; }
#lobby .view-head {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 4px 20px; margin-top: 4px;
}
#lobby .view-head h1 { font: 400 clamp(30px, 4.6vw, 44px)/1.6 var(--hand); color: var(--ink); }
#lobby .refresh { display: flex; align-items: baseline; gap: 12px; }
#lobby .lobby-message {
  margin-top: 6px; padding: 10px 14px; border-radius: 8px;
  background: #fff; border: 1.5px solid var(--grid-strong); min-height: 0;
}
#lobby .lobby-message:empty { display: none; padding: 0; border: 0; background: none; }
#lobby .lobby-message.error { border-color: var(--red); }

.lobby-body { display: grid; gap: 32px; margin-top: 28px; align-items: start; }
#admin-app { display: grid; gap: 28px; }

/* DJO-53 — bảng đề xuất từ (admin) */
#admin-app .suggest-section h2 { font-size: 17px; margin: 0; }
#admin-app .section-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 16px; margin-bottom: 10px;
}
#admin-app .section-head p { margin: 0; font-size: 13px; color: var(--pencil); }
#admin-app .bulk { display: flex; gap: 8px; }
#admin-app .table-wrap {
  overflow-x: auto; padding: 4px 16px 8px; background: #fff;
  border: 1.5px solid var(--grid-strong); border-radius: 12px;
}
#admin-app .suggest-table { width: 100%; border-collapse: collapse; min-width: 560px; }
#admin-app .suggest-table th,
#admin-app .suggest-table td {
  padding: 10px 12px 10px 0; text-align: left; font-size: 14px;
  border-top: 1px solid var(--grid); vertical-align: middle;
}
#admin-app .suggest-table thead th {
  border-top: 0; color: var(--pencil); font-weight: 500; font-size: 13px;
}
#admin-app .suggest-table td.word { font-weight: 700; color: var(--ink); font-size: 16px; }
#admin-app .who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
#admin-app .who .avatar {
  width: 26px; height: 26px; background: var(--ink); color: var(--paper);
  border: 0; font-size: 12px;
}
#admin-app .who strong { font-weight: 600; color: var(--ink-deep); }
#admin-app .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
#admin-app .icon-button.ok { color: var(--green); }
#admin-app .icon-button.no { color: var(--red); }
#admin-app .suggest-empty { margin: 0; padding: 18px 4px; color: var(--pencil); font-size: 15px; }
/* DJO-127 — danh sách admin dạng thẻ; nút Thu hồi là hành động rời (đỏ), vùng bấm 44px. */
#admin-app .lobby-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
#admin-app .lobby-list li {
  display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: #fff; border: 1.5px solid var(--grid-strong); border-radius: 12px;
}
#admin-app .lobby-list .admin-name { min-width: 0; overflow-wrap: anywhere; font-weight: 600; color: var(--ink-deep); }
#admin-app .lobby-list .text-button { flex: none; min-height: 44px; }
#admin-app .ai-section .table-wrap { border-color: var(--ink); }
#admin-app .ai-badge {
  display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
}
#admin-app .ai-badge--approved { color: var(--green); background: rgba(27, 122, 68, 0.1); }
#admin-app .ai-badge--rejected { color: var(--red); background: rgba(181, 43, 43, 0.1); }
#admin-app .ai-note { margin-top: 3px; font-size: 12.5px; color: var(--pencil); line-height: 1.35; }
#admin-app .ai-meaning { margin-top: 4px; font-size: 13px; color: var(--ink-deep); line-height: 1.35; }
#admin-app .icon-button.flip { color: var(--ink); }
/* DJO-125 — khối AI lên trước hàng chờ; ✓ ✕ cách xa, vùng bấm 44px; màn hẹp: nút lên đầu dòng. */
#admin-app > .suggest-section:not(.ai-section) { order: 1; }
#admin-app .row-actions { gap: 12px; }
#admin-app .row-actions .icon-button { width: 44px; height: 44px; }
#admin-app .queue-pager { margin-top: 12px; }
@media (max-width: 640px) {
  #admin-app .table-wrap { padding: 4px 12px 8px; }
  #admin-app .suggest-table { display: block; min-width: 0; }
  #admin-app .suggest-table thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
  }
  #admin-app .suggest-table tbody { display: block; }
  #admin-app .suggest-table tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
    padding: 10px 0; border-top: 1px solid var(--grid);
  }
  #admin-app .suggest-table th,
  #admin-app .suggest-table td { padding: 0; border: 0; }
  #admin-app .suggest-table td:last-child { order: -1; width: 100%; }
}
#admin-app .top-actions .text-button[aria-current="page"] {
  background-image: linear-gradient(var(--ink), var(--ink)); background-size: 100% 2px; font-weight: 700;
}
/* Rà soát UI quản trị: hàng rỗng không chiếm khoảng cách lưới; bảng con không đẩy tràn khung; nút chữ vùng chạm 44px. */
#admin-app > * { min-width: 0; }
#admin-app > .message:empty { display: none; }
#admin-app .text-button { min-height: 44px; display: inline-flex; align-items: center; }
@media (min-width: 641px) {
  .admin-nav #admin-sign-out { margin-left: auto; }
}
/* Quyền admin: ô nhập + nút cấp; danh sách có tiêu đề; Thu hồi xác nhận tại chỗ. */
#admin-app .lobby-create { display: grid; gap: 10px; }
#admin-app .lobby-create label { margin-bottom: 0; }
@media (max-width: 520px) {
  #admin-app .lobby-create .input-row { flex-direction: column; }
  #admin-app .lobby-create .submit { width: 100%; }
}
#admin-app .lobby-list-wrap { display: grid; gap: 10px; }
#admin-app .lobby-list-wrap h2 { margin: 0; font-size: 17px; }
#admin-app .admin-row-actions { display: inline-flex; align-items: center; gap: 12px; flex: none; }
/* Người dùng: ? nằm cạnh tiêu đề trong vòng tròn mảnh; số căn phải, cùng độ rộng chữ số. */
#admin-app .view-head-title { display: inline-flex; align-items: center; gap: 8px; }
#admin-app #heartbeat-help { position: relative; width: 44px; height: 44px; }
#admin-app #heartbeat-help::before {
  content: ""; position: absolute; inset: 6px; border: 1.5px solid var(--grid-strong); border-radius: 50%; pointer-events: none;
}
.users-table :is(th, td):nth-child(n+3):nth-child(-n+6) { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .users-table th:first-child { max-width: 145px; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--grid); }
}
/* Thống kê: tiêu đề mục sát bảng; cột số căn phải. */
#admin-app .stats-section { display: grid; gap: 10px; min-width: 0; }
.stats-table.stats-table--compact { min-width: 0; }
.stats-table--compact :is(th, td):nth-child(n+2),
.stats-table--rooms :is(th, td):nth-child(n+4):nth-child(-n+6) { text-align: right; font-variant-numeric: tabular-nums; }
/* Đề xuất từ: bảng 5 cột vừa khung rộng 760px; dòng đầu trên mobile không có viền thừa. */
@media (max-width: 640px) {
  #admin-app .suggest-table tbody tr:first-child { border-top: 0; }
}
@media (min-width: 900px) {
  .lobby-body { grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 48px; }
  #lobby .side { position: sticky; top: 24px; }
}
@media (max-width: 899px) {
  #lobby .side { order: -1; }
}

#lobby .list-head {
  display: flex; align-items: baseline; justify-content: flex-end;
  gap: 12px; margin-bottom: 10px; min-height: 0;
}
#lobby .list-head:empty { display: none; margin: 0; }
#lobby .rooms { border-top: 1.5px solid var(--grid-strong); list-style: none; margin: 0; padding: 0; }
#lobby .rooms[hidden] { display: none !important; }
#lobby .room {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 20px; align-items: center;
  padding: 14px 4px 16px; border-bottom: 1.5px solid var(--grid-strong);
}
#lobby .room h3 { font: 400 21px/1.75 var(--hand); color: var(--ink); overflow-wrap: anywhere; margin: 0; }
#lobby .facts {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  font-size: 14px; color: var(--pencil);
}
#lobby .fact { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
#lobby .actions {
  display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px 16px;
}
#lobby .actions .submit,
#lobby .mine-actions .submit { min-height: 44px; padding: 0 20px; }
#lobby .note { font-size: 14px; color: var(--pencil); }
#lobby input[type=text] { min-height: 44px; padding: 8px 12px; font-size: 16px; }

#lobby .empty {
  display: grid; justify-items: start; gap: 14px; padding: 28px 24px;
  border: 1.5px dashed var(--grid-strong); border-radius: 12px; background: rgb(255 255 255 / .7);
}
/* DJO-105: sảnh trống hiện một bậc thang chữ mèo → méo → mép làm ví dụ đổi một chữ. */
#lobby .empty-ladder { display: grid; gap: 8px; justify-items: start; }
#lobby .empty-row { display: flex; align-items: center; gap: 6px; }
#lobby .empty-row i {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 1.5px solid var(--grid-strong); border-radius: 4px; background: #fff;
  font: 600 20px/1 var(--sans); font-style: normal; color: var(--ink-deep);
}
#lobby .empty-row i.ch { background: var(--mark); border-color: var(--ink); }
#lobby .empty-row.ghost i { border-style: dashed; color: transparent; }
#lobby .empty-ladder .arrow { margin-left: 8px; font: 400 15px var(--hand); color: var(--red); }
#lobby .empty .sub { color: var(--pencil); }
@media (max-width: 400px) {
  #lobby .empty-row i { width: 34px; height: 34px; font-size: 17px; }
}
#lobby .empty p { max-width: 30em; margin: 0; }
#lobby .empty strong { display: block; font-size: 17px; color: var(--ink-deep); }
#lobby .empty span { color: var(--pencil); }

#lobby .panel { padding: 22px; background: #fff; border: 1.5px solid var(--grid-strong); border-radius: 12px; }
#lobby .panel h2 { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
#lobby .create { display: grid; gap: 14px; }
#lobby .create h2 { margin-bottom: 0; }

#lobby .mine { border-color: var(--ink); }
#lobby .mine .room-name {
  font: 400 26px/1.7 var(--hand); color: var(--ink); overflow-wrap: anywhere; margin: 0 0 10px;
}
#lobby .mine .room-name { margin-bottom: 18px; }
#lobby .mine-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 20px; }
#lobby .mine .hint { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--grid); }
#lobby .mine .clock { margin-top: 10px; font-size: 14px; color: var(--ink-deep); }

/* Phòng cũ còn mật khẩu: ô nhập gọn trong hàng action, không có trên form tạo phòng. */
#lobby .join-inline { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
#lobby .join-password { width: 150px !important; min-height: 44px; }
#lobby .join-inline-error { flex: 1 1 100%; margin: 0; text-align: right; }

.lobby-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 18px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.room-meta { color: var(--pencil); font-size: 14px; }
.room-name { font: 400 22px/1.7 var(--hand); color: var(--ink); overflow-wrap: anywhere; margin: 4px 0 8px; }

@media (max-width: 640px) {
  html { scroll-padding-top: 76px; }
  .topbar {
    flex-wrap: nowrap; gap: 8px;
  }
  .top-end { flex-wrap: nowrap; flex: 1; justify-content: flex-end; min-width: 0; gap: 8px; }
  .topbar .brand { min-width: 0; flex-shrink: 1; }
  .gate-nav .submit--small { flex-shrink: 0; padding: 0 12px; min-height: 40px; font-size: 14px; }
  .account { flex-shrink: 0; }
  body:is(:has(#gate-view[hidden]), .account-page) .topbar {
    position: sticky; top: 0; z-index: 15; flex-wrap: nowrap;
    margin: 0 -20px; padding: 8px 20px;
    background: rgb(253 253 247 / .94); backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--grid-strong);
  }
  body:is(:has(#gate-view[hidden]), .account-page) .brand img,
  body:is(:has(#gate-view[hidden]), .account-page) .brand svg { width: 30px; height: 30px; }
  body:is(:has(#gate-view[hidden]), .account-page) .brand span { font-size: 21px; }
  .account-toggle {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; max-width: 46vw;
    padding: 4px 14px 4px 5px; border: 1.5px solid var(--grid-strong); border-radius: 999px; background: #fff;
    color: var(--ink-deep); font-size: 14px; font-weight: 500; -webkit-tap-highlight-color: transparent;
  }
  .account-toggle .avatar {
    width: 30px; height: 30px; background: var(--ink); color: var(--paper); border-color: transparent;
  }
  .account-toggle[aria-expanded="true"] { border-color: var(--ink); background: rgb(59 47 155 / .07); }
  .account-toggle .account-name {
    display: inline !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  /* Landing/gate: chỉ avatar trên toggle để giữ “Vào chơi” một hàng. */
  body:has(#gate-view:not([hidden])) .account-toggle .account-name { display: none !important; }
  body:has(#gate-view:not([hidden])) .account-toggle { gap: 0; max-width: none; padding: 4px; border-radius: 50%; }
  .account .top-actions {
    display: none; position: absolute; right: 0; top: calc(100% + 8px); width: min(240px, calc(100vw - 40px));
    flex-direction: column; align-items: stretch; gap: 0; padding: 6px; margin-left: 0;
    background: #fff; border: 1.5px solid var(--ink); border-radius: 12px; box-shadow: 0 10px 28px rgb(35 27 94 / .14);
  }
  .account.open .top-actions { display: flex; }
  #top-actions .menu-only {
    display: flex !important; align-items: center; min-height: 44px; padding: 0 10px; border-radius: 8px;
    font-size: 15px; text-align: left; text-decoration: underline; text-decoration-color: var(--grid-strong);
    text-decoration-thickness: 2px; text-underline-offset: 5px; background-image: none;
  }
  #top-actions .menu-only:hover { background: rgb(59 47 155 / .07); }
  #top-actions .menu-lang-row.menu-only { justify-content: flex-start; gap: 10px; text-decoration: none; }
  .menu-lang-label {
    font-size: 15px; font-weight: 500; color: var(--ink);
    text-decoration: underline; text-decoration-color: var(--grid-strong);
    text-decoration-thickness: 2px; text-underline-offset: 5px;
  }
  #top-actions .desktop-only { display: none !important; }
  #top-actions #admin-link { order: 1; align-self: flex-end; }
  #top-actions #sign-out-menu { order: 2; }
  #top-actions > .text-button:not(.menu-only) {
    display: flex; align-items: center; min-height: 44px; padding: 0 10px; border-radius: 8px;
    font-size: 15px; text-align: left; background-image: none; text-decoration: underline;
    text-decoration-color: var(--grid-strong); text-decoration-thickness: 2px; text-underline-offset: 5px;
  }
  #top-actions > .text-button:not(.menu-only):hover { background-color: rgb(59 47 155 / .07); }
  #top-actions .menu-only::before, #top-actions .menu-only::after,
  #top-actions > .text-button:not(.menu-only)::before, #top-actions > .text-button:not(.menu-only)::after { content: none; }

  #lobby .view-head { flex-wrap: nowrap; align-items: center; margin-top: 0; }
  #lobby .view-head h1 { font-size: 30px; line-height: 1.5; }
  #lobby .refresh .hint { display: none; }
  #lobby .refresh .text-button { min-height: 44px; padding: 0 2px; }
  #lobby .lobby-body { margin-top: 18px; }
  #lobby .room { grid-template-columns: minmax(0, 1fr); }
  #lobby .actions { justify-content: flex-start; }
  #lobby .panel { padding: 18px 16px; }
}

/* ── Phòng chờ (design/waiting-opus.html) ────────────────────────────────── */
body:has(#room-waiting:not([hidden])) .page { padding-bottom: 120px; }
#room-waiting { padding-top: 0; }
#room-waiting .view-head { align-items: flex-start; gap: 4px 20px; margin-top: 8px; }
#room-waiting .view-head h1 {
  min-width: 0; padding-bottom: .22em;
  font: 400 clamp(30px, 4.6vw, 44px)/1.6 var(--hand); color: var(--ink); overflow-wrap: anywhere;
}
#room-waiting .view-head .text-button { flex: none; margin-top: 14px; }
#room-waiting .room-title-tail { display: inline-flex; align-items: center; vertical-align: baseline; max-width: 100%; }
#room-waiting .room-title-tail > span { min-width: 0; overflow-wrap: anywhere; }
#room-waiting .room-message { margin-top: 2px; font-size: 15px; min-height: 0; }
#room-waiting .room-message:empty { display: none; }
#room-waiting .room-message.error {
  padding: 10px 14px; border-radius: 8px; background: #fff; border: 1.5px solid var(--red);
}

#room-waiting .waiting-body {
  display: grid; gap: 0 48px; margin-top: 26px; align-items: start;
  grid-template-areas: "side" "seats" "queue" "bar" "start" "rules";
}
#room-waiting .side { grid-area: side; display: grid; gap: 16px; align-content: start; }
/* DJO-51: hàng icon thông số — chỉ hiện trên mobile (JS + media). */
#room-waiting .room-facts { display: none; }
#room-waiting .room-settings-card { display: contents; }
#room-waiting .seats-section { grid-area: seats; margin-top: 28px; }
#room-waiting .queue-section { grid-area: queue; }
#room-waiting .start-bar {
  grid-area: bar; margin-top: 24px;
  display: flex; align-items: center; flex-wrap: wrap; gap: 12px 16px;
}
#room-waiting .start { grid-area: start; margin-top: 16px; }
#room-waiting .rules { grid-area: rules; margin-top: 32px; }
@media (min-width: 900px) {
  #room-waiting .waiting-body {
    grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr);
    grid-template-areas: "seats side" "queue side" "bar side" "start side" "rules side";
    grid-template-rows: auto auto auto auto 1fr;
  }
  #room-waiting .side { position: sticky; top: 24px; }
  #room-waiting .seats-section { margin-top: 0; }
}

/* Trò chuyện phòng: trong .side (chờ) / dưới BXH (ván). */
.room-chat {
  display: grid; gap: 10px; margin: 0; padding: 16px 18px;
  background: #fff; border: 1.5px solid var(--grid-strong); border-radius: 12px;
}
.room-chat h2 { margin: 0; font-size: 16px; font-weight: 600; }
.room-chat .chat-sub { font-size: 13px; font-weight: 400; color: var(--pencil); }
.chat-log {
  display: grid; gap: 10px; max-height: min(220px, 34vh); overflow: auto;
  padding: 2px 4px 2px 0; font-size: 14px; overscroll-behavior: contain;
}
.chat-msg { display: grid; gap: 2px; }
.chat-msg .head { font-size: 13px; line-height: 1.35; }
.chat-msg .who { font-weight: 600; color: var(--ink); }
.chat-msg.me .who { color: var(--ink-deep); }
.chat-msg time { margin-left: 6px; font-size: 12px; font-weight: 400; color: var(--pencil); }
.chat-msg p { margin: 0; color: var(--ink-deep); line-height: 1.4; overflow-wrap: anywhere; }
.chat-compose { display: flex; gap: 8px; align-items: stretch; }
.chat-compose input {
  flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px;
  border: 1.5px solid var(--grid-strong); border-radius: 8px; background: #fff; font-size: 16px;
}
.chat-compose input:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgb(59 47 155 / .12); }
.room-chat .message:empty { display: none; }
#eliminated-chat { margin-top: 20px; gap: 0; }
/* Khung chat thu được như BXH: nội dung xếp dọc trong .side-panel-inner. */
#eliminated-chat .side-panel-inner { display: grid; gap: 10px; }
#eliminated-chat .chat-log { max-height: min(200px, 30vh); }
/* DJO-84: đến lượt mình thì chỉ làm mờ từng tin nhắn; khung log (focus ring, cuộn), tiêu đề và ô nhập vẫn rõ. */
#eliminated-chat .chat-msg { transition: filter 240ms ease; }
#game-shell.my-turn #eliminated-chat .chat-msg { filter: blur(4px); }
/* DJO-87: vệt mờ lan sang trái bị khung cuộn cắt; chừa lề trái để không bị cắt. */
#game-shell.my-turn #eliminated-chat .chat-log { padding-left: 8px; }
@media (prefers-reduced-motion: reduce) {
  #eliminated-chat .chat-msg { transition: none; }
}
@media (max-width: 640px) {
  .room-chat { padding: 14px; }
  .chat-log { max-height: 132px; }
  #eliminated-chat .chat-log { max-height: 120px; }
  .game-side:has(#eliminated-chat:not([hidden])) { margin-top: 22px; }
}

#room-waiting .section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px;
}
#room-waiting .section-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
#room-waiting .section-head .hint { font-size: 15px; font-weight: 600; color: var(--ink-deep); }

#room-waiting .seats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
  list-style: none; margin: 0; padding: 0;
}
#room-waiting .seat {
  position: relative;
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px;
  min-height: 64px; padding: 10px 12px; border-radius: 10px;
  background: #fff; border: 1.5px solid var(--grid-strong);
}
#room-waiting .seat .avatar { width: 38px; height: 38px; font-size: 15px; background: var(--ink); color: var(--paper); border-color: transparent; }
#room-waiting .seat .name { display: flex; align-items: center; gap: 6px; min-width: 0; }
#room-waiting .seat strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
#room-waiting .crown { width: 18px; height: 15px; flex: none; }
#room-waiting .tag {
  justify-self: start; display: inline-block; margin-top: 2px; padding: 0 6px; border-radius: 4px;
  font-size: 12px; font-weight: 600; line-height: 1.6;
}
#room-waiting .tag.me { background: var(--ink); color: var(--paper); }
#room-waiting .seat.me { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
#room-waiting .seat.joined { animation: waiting-joined .6s ease-out; }
@keyframes waiting-joined { from { background: var(--mark); } to { background: #fff; } }
#room-waiting .seat.empty {
  border-style: dashed; color: var(--pencil); font-size: 14px;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 -1px / 16px 16px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) -1px 0 / 16px 16px,
    rgb(255 255 255 / .75);
}
#room-waiting .seat.empty i {
  width: 38px; height: 38px; border-radius: 50%; border: 1.5px dashed var(--grid-strong); background: #fff;
}
#room-waiting .seat.empty.holding { border-style: solid; color: var(--ink); }
@media (prefers-reduced-motion: reduce) { #room-waiting .seat.joined { animation: none; } }

#room-waiting .player-name {
  display: block; min-width: 0; max-width: 100%; padding: 0; border: 0; background: none;
  color: inherit; text-align: left; cursor: help;
  text-decoration: underline dotted var(--grid-strong); text-decoration-thickness: 2px; text-underline-offset: 4px;
}
#room-waiting .player-name strong { display: block; }
#room-waiting .player-name::after { content: ""; position: absolute; inset: -1.5px; border-radius: 10px; }
#room-waiting .player-name:focus-visible { outline: none; }
#room-waiting .seat:has(.player-name:focus-visible) { outline: 3px solid var(--ink); outline-offset: 3px; }
#room-waiting .seat:has(.player-name):hover,
#room-waiting .seat.stats-open { border-color: var(--ink); }
#room-waiting .seat:has(.player-name):hover .player-name,
#room-waiting .seat.stats-open .player-name { text-decoration-color: var(--ink); }
/* Nút mời khách ra nằm giữa cạnh phải của ghế. */
#room-waiting .seat:has(.kick) { padding-right: 52px; }
#room-waiting .kick { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); z-index: 1; width: 44px; height: 44px; border: 0; background: transparent; color: var(--red, #aa3535); font-size: 24px; cursor: pointer; }
#room-waiting .kick:hover { background: rgb(170 53 53 / .08); border-radius: 8px; }
.chat-compose .chat-send { display: grid; place-items: center; width: 44px; flex: none; border: 1.5px solid var(--ink); border-radius: 8px; color: var(--ink); background: transparent; cursor: pointer; }
.chat-compose .chat-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-compose .chat-send:disabled { opacity: .5; cursor: default; }

#room-waiting .start { display: grid; gap: 14px; }
#room-waiting .start-bar .submit { min-height: 50px; padding: 0 26px; font-size: 17px; }
#room-waiting .start-bar .submit:disabled { opacity: 1; background: #6f68b5; }
#room-waiting .invite-message { overflow-wrap: anywhere; min-height: 0; margin: 4px 0 0; font-size: 14px; }
#room-waiting .invite-message:empty { display: none; }
/* DJO-61: cùng một vùng bấm, hai nét icon; không đổi kích thước khi copy. */
#room-waiting .invite-button {
  position: relative; display: inline-grid; place-items: center; flex: none; vertical-align: middle; margin-left: 8px;
  width: 44px; height: 44px; padding: 10px; border: 0; border-radius: 8px;
  color: var(--ink); background: transparent; cursor: pointer;
}
#room-waiting .invite-button:hover { background: rgb(59 47 155 / .07); }
#room-waiting .invite-button svg {
  position: absolute; width: 22px; height: 22px; fill: none;
  stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  transition: opacity 180ms ease-out, transform 240ms cubic-bezier(.22, 1, .36, 1);
}
#room-waiting .invite-button .link-icon { opacity: 1; transform: scale(1); }
#room-waiting .invite-button .check-icon { opacity: 0; transform: scale(.72); }
#room-waiting .invite-button.is-copied .link-icon { opacity: 0; transform: scale(.8); }
#room-waiting .invite-button.is-copied .check-icon { opacity: 1; transform: scale(1); }
@media (prefers-reduced-motion: reduce) {
  #room-waiting .invite-button svg { transition: none; }
}
#room-waiting .start-bar > .submit:not([hidden]) { flex: 0 0 auto; width: auto; }
#room-waiting .waiting-note { display: inline-flex; align-items: center; gap: 10px; margin: 0; font-weight: 500; }
#room-waiting .waiting-note i {
  width: 10px; height: 10px; border-radius: 50%; background: var(--ink); animation: waiting-breathe 1.8s ease-in-out infinite;
}
@keyframes waiting-breathe { 50% { opacity: .25; } }
#room-waiting .waiting-note.full i { animation: none; opacity: 1; }
@media (prefers-reduced-motion: reduce) { #room-waiting .waiting-note i { animation: none; } }

/* DJO-50: Luật chơi collapsible trên mọi viewport (không force open desktop). */
#room-waiting .rules { padding-top: 8px; border-top: 1.5px solid var(--grid-strong); margin-top: 32px; }
#room-waiting .rules > summary {
  cursor: pointer; list-style: none; font-size: 16px; font-weight: 600; margin: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; color: var(--ink-deep);
}
#room-waiting .rules > summary::-webkit-details-marker { display: none; }
#room-waiting .rules > summary::after {
  content: ""; width: 10px; height: 10px; flex: 0 0 auto; margin-right: 4px;
  border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink);
  transform: rotate(45deg) translateY(-2px); transition: transform .15s ease;
}
#room-waiting .rules[open] > summary::after { transform: rotate(225deg) translateY(-2px); }
#room-waiting .rules[open] > summary { margin-bottom: 4px; }
@media (prefers-reduced-motion: reduce) {
  #room-waiting .rules > summary::after { transition: none; }
}
#room-waiting .rules .rule-list { margin-top: 4px; padding-bottom: 8px; }
#room-waiting .rule-list { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; counter-reset: rule; }
#room-waiting .rule-list li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 0 12px; counter-increment: rule; }
#room-waiting .rule-list li::before {
  content: counter(rule); display: grid; place-items: center; width: 26px; height: 26px; margin-top: 1px;
  border: 1.5px solid var(--ink); border-radius: 4px; background: #fff; color: var(--ink); font-size: 13px; font-weight: 700;
}
#room-waiting .rule-list strong { display: block; font-size: 15px; color: var(--ink-deep); }
#room-waiting .rule-list li > div > span { display: block; font-size: 14px; color: var(--pencil); }
#room-waiting .rule-list li > div > span:empty { display: none; }
#room-waiting .example { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 8px; }
#room-waiting .example figure { display: grid; justify-items: start; gap: 2px; margin: 0; }
#room-waiting .example .tiles { display: flex; gap: 3px; }
#room-waiting .example .tiles i {
  display: grid; place-items: center; width: 28px; height: 30px; border: 1.5px solid var(--ink); border-radius: 4px;
  background: #fff; color: var(--ink-deep); font: 600 16px/1 var(--sans); font-style: normal;
}
#room-waiting .example .tiles i.changed { background: var(--mark); }
#room-waiting .example figcaption { font-size: 12px; color: var(--pencil); }

#room-waiting .panel { padding: 22px; }
#room-waiting .panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px;
}
#room-waiting .panel-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
#room-waiting .save-state { margin: 0; font-size: 13px; color: var(--pencil); text-align: right; transition: opacity .3s ease, transform .3s ease; }
#room-waiting .save-state.fading { opacity: 0; transform: translateY(-4px); }
@media (prefers-reduced-motion: reduce) { #room-waiting .save-state { transition: opacity .3s ease; } #room-waiting .save-state.fading { transform: none; } }
#room-waiting .save-state.saving { color: var(--ink-deep); }
#room-waiting .save-state.success { color: var(--green); }
#room-waiting .save-state.error { flex-basis: 100%; color: var(--red); text-align: left; }
#room-waiting .edit .panel-head { flex-wrap: wrap; row-gap: 4px; margin-bottom: 0; }
#room-waiting .edit { display: grid; gap: 14px; border-color: var(--ink); margin: 0; }
#room-waiting .edit select {
  width: 100%; min-height: 48px; padding: 10px 36px 10px 14px;
  border: 1.5px solid var(--ink); border-radius: 8px; color: var(--ink-deep); font-size: 16px;
  appearance: none; -webkit-appearance: none; text-overflow: ellipsis;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1.2 1.2 6 6l4.8-4.8' fill='none' stroke='%233b2f9b' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center / 12px 8px;
}
#room-waiting .edit option:disabled { color: #a2a6b4; }
#room-waiting .series-hint { margin: -4px 0 0; font-size: 13px; color: var(--pencil); }
#room-waiting .series-hint:empty { display: none; }
/* Thời gian vừa tự đổi theo số chữ: loé vàng và nảy nhẹ một nhịp. */
#room-waiting .edit select.auto-picked { animation: auto-picked 1.2s ease-out; }
@keyframes auto-picked {
  0% { background-color: var(--mark); transform: scale(1); }
  18% { background-color: var(--mark); transform: scale(1.05); }
  40% { transform: scale(1); }
  100% { background-color: #fff; }
}
@media (prefers-reduced-motion: reduce) {
  #room-waiting .edit select.auto-picked { animation: auto-picked-still 1.2s step-end; }
  @keyframes auto-picked-still { 0% { background-color: var(--mark); } 100% { background-color: #fff; } }
}
#room-waiting .info dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 16px; margin: 0; }
#room-waiting .info dt { color: var(--pencil); font-size: 14px; }
#room-waiting .info dd { margin: 0; font-weight: 600; text-align: right; }
#room-waiting .info .info-item { display: contents; }

@media (max-width: 640px) {
  #room-waiting .view-head { margin-top: 12px; }
  #room-waiting .view-head h1 { font-size: 30px; line-height: 1.5; }
  #room-waiting .view-head .text-button { min-height: 44px; margin-top: 2px; padding: 0 2px; }
  #room-waiting .waiting-body { margin-top: 18px; }
  #room-waiting .seats-section { margin-top: 24px; }
  #room-waiting .seats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  #room-waiting .seat { gap: 8px; padding: 8px 10px; }
  #room-waiting .seat .avatar,
  #room-waiting .seat.empty i { width: 32px; height: 32px; }
  /* DJO-48: mobile chỉ hiện ghế có người. */
  #room-waiting .seat.empty { display: none !important; }
  #room-waiting .seat.empty.holding { display: grid !important; }
  #room-waiting .panel { padding: 18px 16px; }
  #room-waiting .edit { gap: 10px; padding: 14px 14px 16px; }
  #room-waiting .edit .panel-head h2 { font-size: 16px; }
  #room-waiting .edit .field-pair { gap: 10px; }
  #room-waiting .edit label { margin-bottom: 4px; font-size: 13px; }
  #room-waiting .edit select {
    min-height: 44px; padding: 8px 30px 8px 12px; font-size: 15px; background-position: right 10px center;
  }
  #room-waiting .series-hint { margin-top: -2px; }
  #room-waiting .room-settings-card {
    display: block; position: relative; border: 1.5px solid var(--grid-strong); border-radius: 12px; background: #fff;
  }
  #room-waiting .room-settings-card.is-editing { border-color: var(--ink); }
  #room-waiting .room-facts {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 6px 8px 6px 12px; min-height: 52px; background: none; border: 0; border-radius: 0;
  }
  #room-waiting .room-settings-card.is-open .room-facts {
    position: absolute; top: 4px; right: 4px; padding: 0; min-height: 0; z-index: 2;
  }
  #room-waiting .room-settings-card.is-open #fact-row { display: none; }
  #room-waiting .room-settings-card .panel { border: 0; background: none; box-shadow: none; }
  #room-waiting .room-settings-card .panel-head { padding-right: 44px; }
  #room-waiting .room-settings-card .info dl { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
  #room-waiting .room-settings-card .info .info-item { display: grid; gap: 2px; }
  #room-waiting .room-settings-card .info dt { font-size: 12px; }
  #room-waiting .room-settings-card .info dd { font-size: 14px; text-align: left; }
  #room-waiting .facts-more, #room-waiting #facts-edit {
    width: 44px; height: 44px; flex: none;
  }
  #room-waiting #facts-edit[aria-expanded="true"] { background: var(--page-line-fine); }
  #room-waiting #facts-edit[aria-expanded="true"] svg { display: none; }
  #room-waiting #facts-edit[aria-expanded="true"]::before { content: '×'; font: 400 28px/1 var(--sans); }
  #room-waiting .fact-row {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0;
    flex: 1; align-self: stretch; margin: 0; padding: 0; list-style: none;
  }
  #room-waiting .fact-row .fact {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 13px; font-weight: 600; color: var(--ink);
  }
  #room-waiting .fact-row .fact svg { display: block; width: 18px; height: 18px; flex: none; }
  #room-waiting .fact-row .fact .flag { width: 20px; height: 14px; }
  #room-waiting .room-facts .fact-row { cursor: pointer; }
  #room-waiting .room-facts.is-guest .fact-row { cursor: pointer; }
  #room-waiting .facts-more svg { transition: transform .15s ease; }
  #room-waiting .facts-more[aria-expanded="true"] svg { transform: rotate(180deg); }
  @media (prefers-reduced-motion: reduce) {
    #room-waiting .facts-more svg { transition: none; }
  }
  /* DJO-49: không sticky trên mobile — invite (và cả start-bar) scroll bình thường. */
  #room-waiting .start-bar {
    margin-top: 28px; padding: 0 0 calc(13px + env(safe-area-inset-bottom));
  }
  #room-waiting .start-bar > .submit:not([hidden]) { flex: 1 1 100%; width: 100%; }
}

.game-main { max-width: 640px; }
.game-side { display: grid; gap: 12px; margin-top: 24px; }
@media (min-width: 900px) {
  .game-layout:has(.game-side > :not([hidden])) {
    display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start;
  }
  .game-side { margin-top: 0; padding-top: 24px; }
}
/* DJO-58: Xếp hạng / Phản xạ thu được (mặc định thu); Chat luôn mở. */
.side-panel {
  margin: 0;
  padding: 12px 16px;
  background: #fff;
  border: 1.5px solid var(--grid-strong);
  border-radius: 12px;
}
.side-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-deep);
  text-align: left;
  cursor: pointer;
}
.side-panel-head:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
/* Tiêu đề bên trái; số đếm và mũi tên chevron dồn về bên phải. */
.side-panel-head > :first-child { margin-right: auto; }
.side-panel-head .count {
  font-size: 13px;
  font-weight: 500;
  color: var(--pencil);
}
.side-panel-head::after {
  content: ""; width: 16px; height: 16px; flex: none;
  background: var(--pencil);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform .22s ease;
}
.side-panel.is-open .side-panel-head::after { transform: rotate(180deg); background: var(--ink); }
.side-panel-body {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition:
    grid-template-rows .24s cubic-bezier(.4, 0, .2, 1),
    opacity .16s ease-out;
}
.side-panel.is-open .side-panel-body {
  grid-template-rows: 1fr;
  opacity: 1;
  transition:
    grid-template-rows .36s cubic-bezier(.22, 1, .36, 1),
    opacity .24s ease-out;
}
.side-panel-inner { overflow: hidden; min-height: 0; }
.side-panel table { width: 100%; margin: 4px 0; border-collapse: collapse; }
.side-panel th, .side-panel td {
  padding: 7px 0;
  border-top: 1px solid var(--grid);
  font-size: 15px;
}
.side-panel thead th {
  border-top: 0;
  padding-top: 0;
  font-size: 12px;
  color: var(--pencil);
  font-weight: 500;
}
.side-panel th[scope="row"] { text-align: left; font-weight: 500; overflow-wrap: anywhere; }
.side-panel th[scope="col"]:not(:first-child),
.side-panel td { width: 3.6em; text-align: center; font-variant-numeric: tabular-nums; }
.side-panel .me th, .side-panel .me td { font-weight: 700; color: var(--ink); }
/* Đổi thứ tự BXH / Phản xạ: box nháy vàng một nhịp (bootstrap.js flashSidePanel). */
.side-panel.is-reordered {
  animation: side-panel-flash .75s ease-out 1;
}
@keyframes side-panel-flash {
  0% { background-color: #fff; border-color: var(--grid-strong); }
  24% { background-color: var(--mark); border-color: var(--ink); }
  100% { background-color: #fff; border-color: var(--grid-strong); }
}
@media (prefers-reduced-motion: reduce) {
  .side-panel .side-panel-body,
  .side-panel.is-open .side-panel-body,
  .side-panel-head::after { transition: none; }
  .side-panel.is-reordered { animation-duration: .4s; }
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-weight: 600;
  font-size: 14px;
}
.checkbox-label input {
  width: auto;
  min-height: 0;
  margin: 0;
}

/* ── Bàn chơi ────────────────────────────────────────────────────────────── */
.roster { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 12px;
  background: #fff;
  border: 1.5px solid var(--grid-strong);
  border-radius: 8px;
  font-size: 14px;
}
.player strong { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.player-name {
  min-width: 0; padding: 0; border: 0; background: none; text-align: left; cursor: help;
  text-decoration: underline dotted var(--grid-strong); text-decoration-thickness: 2px; text-underline-offset: 4px;
}
.player-name:hover { text-decoration-color: var(--ink); }
.word-current {
  display: grid; justify-items: center; margin: 0; padding: 2px 4px;
  border: 0; border-radius: 8px; background: none; font: inherit; color: inherit;
}
.word-current .tiles { pointer-events: none; }
.word-meaning {
  min-height: 1.6em; max-width: 52ch; margin: 0; text-align: center;
  font-size: 14px; color: var(--pencil); line-height: 1.45;
}
.word-meaning[hidden] { display: none; }
.word-trigger {
  padding: 0 1px; border: 0; background: none; font: inherit; color: inherit; cursor: help;
  text-decoration: underline dotted var(--grid-strong); text-decoration-thickness: 2px; text-underline-offset: 4px;
}
.word-trigger:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
.history-list li:last-child .word-trigger,
.history-list li:last-child > span { font-weight: 700; }
.player-stats,
.word-meaning-tip {
  position: fixed; z-index: 25; width: max-content; min-width: 216px; max-width: min(300px, calc(100vw - 16px));
  padding: 12px 16px 14px; background: #fff; border: 1.5px solid var(--grid-strong); border-radius: 12px;
  box-shadow: 0 8px 22px rgb(35 27 94 / .16); color: var(--ink-deep);
  animation: stats-in .14s cubic-bezier(.32,.72,0,1);
}
.player-stats { border-color: var(--ink); }
.word-meaning-tip { max-width: min(340px, calc(100vw - 16px)); }
.word-meaning-tip-word { margin: 0 0 6px; font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.word-meaning-tip-body { margin: 0; font-size: 14px; line-height: 1.45; }
.word-meaning-tip-note { margin: 0; font-size: 14px; color: var(--pencil); }
.word-meaning-tip-note.error { color: var(--red); }
.word-meaning-tip .skeleton {
  display: block; height: 14px; margin-top: 6px; border-radius: 4px;
  background: linear-gradient(90deg, var(--grid) 0%, var(--page-line) 50%, var(--grid) 100%);
  background-size: 200% 100%;
  animation: meaning-shimmer 1.2s ease-in-out infinite;
}
@keyframes meaning-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.player-stats-name { margin: 0 0 8px; font-weight: 700; overflow-wrap: anywhere; }
.player-stats-note { margin: 0; font-size: 14px; color: var(--pencil); }
.player-stats-note.error { color: var(--red); }
.player-stats dl { display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 2px 20px; margin: 0; }
.player-stats dt { font-size: 12px; color: var(--pencil); }
.reaction th[scope="col"] { white-space: nowrap; }
.player-stats dd { margin: 0; font-size: 21px; font-weight: 600; line-height: 1.4; font-variant-numeric: tabular-nums; white-space: nowrap; }
.player-stats dd small { font-size: 12px; font-weight: 400; color: var(--pencil); }
.player-stats .skeleton {
  display: inline-block; width: 2.4em; height: .7em; border-radius: 4px; vertical-align: middle;
  background: var(--grid); animation: stats-skeleton 1s ease-in-out infinite alternate;
}
@keyframes stats-in { from { opacity: 0; transform: translateY(-4px); } }
.player-stats.is-closing { animation: stats-out .14s cubic-bezier(.32,.72,0,1) both; pointer-events: none; }
@keyframes stats-out { to { opacity: 0; } }
@keyframes stats-skeleton { to { background: var(--page-line-fine); } }
@media (prefers-reduced-motion: reduce) {
  .player-stats, .player-stats .skeleton, .word-meaning-tip, .word-meaning-tip .skeleton { animation: none; }
}
.player.me strong { font-weight: 700; }
.you-label { font-size: 12px; color: var(--pencil); }
.turn-badge { font-size: 12px; color: var(--pencil); }
.turn-badge:empty { display: none; }
.player.active { background: var(--mark); border-color: var(--ink); }
.player.active .turn-badge { color: var(--ink-deep); font-weight: 600; }
.player.eliminated { background: transparent; border-style: dashed; color: var(--pencil); }
.player.eliminated strong { text-decoration: line-through; }
.player.winner { border: 2px solid var(--red); }
.player.winner .turn-badge { color: var(--red); font-weight: 700; }

.board {
  margin-top: 16px;
  padding: 20px 22px 22px;
  background: #fff;
  border: 1.5px solid var(--grid-strong);
  border-radius: 12px;
}
.my-turn .board { border-color: var(--ink); box-shadow: 0 0 0 3px rgb(59 47 155 / .12); }
.mode-info { margin: 0 0 2px; text-align: center; font-size: 13px; font-weight: 600; color: var(--pencil); }
.mode-info[hidden] { display: none; }
.turn-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.turn-status { font-weight: 600; font-size: 17px; }
.my-turn .turn-status { color: var(--ink); }
@media (prefers-reduced-motion: no-preference) {
  /* DJO-122: đến lượt mình nháy nền 200ms một lần; chỉ chạy khi class my-turn được thêm mới. */
  .my-turn .turn-status { animation: turn-flash .2s ease-out; }
  @keyframes turn-flash { from { background-color: var(--mark); } to { background-color: transparent; } }
}
.timer { display: flex; align-items: baseline; gap: 5px; color: var(--ink-deep); }
.timer strong { font: 700 34px/1 var(--sans); font-variant-numeric: tabular-nums; }
.timer span { font-size: 13px; color: var(--pencil); }
.timer-track { height: 6px; margin-top: 8px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.timer-bar { height: 100%; width: 100%; background: var(--ink); transform-origin: 0 50%; transition: transform .2s linear; }
.urgent .timer, .urgent .timer span { color: var(--red); }
.urgent .timer-bar { background: var(--red); }
/* DJO-85: chế độ tập thể — "+5" xanh bên trái số giây, trôi từ dưới lên, dừng một nhịp, rồi bay lên và mờ.
   Thanh do JS nội suy theo khung hình nên tắt transition của CSS để không chồng lên nhau. */
.team-mode .timer-bar { transition: none; }
.team-bonus {
  align-self: center; margin-right: 6px;
  font: 700 15px/1 var(--sans); font-style: normal; color: var(--green);
  animation: team-bonus-rise 1.6s ease-out both;
}
.team-bonus[hidden] { display: none; }
@keyframes team-bonus-rise {
  0% { opacity: 0; transform: translateY(14px); }
  30% { opacity: 1; transform: translateY(0); }
  55% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-18px); }
}
@media (prefers-reduced-motion: reduce) {
  .team-bonus { animation: none; }
}

.board .tiles { margin: 28px 0 8px; }

.series-line { margin: 0 0 6px; text-align: center; font-size: 14px; font-weight: 600; color: var(--ink-deep); }
#move-form { margin-top: 18px; }
#move-form .submit { min-width: 108px; }

.result { margin-top: 18px; text-align: center; }
.result h2 { font: 400 clamp(24px, 5vw, 32px)/1.7 var(--hand); color: var(--red); }
.result p { margin: 4px 0 18px; }
.result p:empty { margin: 0 0 18px; }
.result-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 22px; }
/* Đếm ngược trên nút Chơi ván mới (design/game-opus.html). */
.reset { position: relative; display: inline-grid; place-items: center; min-width: 176px; overflow: hidden; isolation: isolate; }
.reset > span { grid-area: 1 / 1; }
.reset-count { visibility: hidden; font-variant-numeric: tabular-nums; }
.reset-count b { display: inline-block; min-width: .7em; font-weight: 700; }
.reset.counting .reset-label { visibility: hidden; }
.reset.counting .reset-count { visibility: visible; }
.reset.counting, .reset.counting:hover { background: var(--ink-deep); cursor: default; }
.reset::after {
  content: ""; position: absolute; z-index: -1; left: 0; right: 0; bottom: 0; height: 4px;
  background: var(--mark); transform-origin: left; transform: scaleX(0);
}
.reset.counting::after { transform: scaleX(calc(var(--count-left, 3) / 3)); }
@media (prefers-reduced-motion: no-preference) {
  .reset.counting.tick::after { animation: reset-drain 1s linear forwards; }
  .reset.counting.tick .reset-count b { animation: reset-pop .4s cubic-bezier(.22, 1, .36, 1); }
  @keyframes reset-drain {
    from { transform: scaleX(calc(var(--count-left, 3) / 3)); }
    to { transform: scaleX(calc((var(--count-left, 3) - 1) / 3)); }
  }
  @keyframes reset-pop { from { opacity: 0; transform: translateY(-5px); } }
}
.text-button[aria-disabled="true"] { color: var(--pencil); background-image: none; cursor: default; }
.result .reset-note { margin: 12px 0 0; font-size: 14px; color: var(--pencil); }
.result .reset-audio {
  display: inline-block; margin: 10px 0 0; padding: 4px 12px; border-radius: 999px;
  background: #fff; border: 1px solid var(--grid-strong); color: var(--pencil); font-size: 13px;
}
.result .reset-audio[hidden], .result .reset-note[hidden] { display: none; }
/* DJO-123: kết quả hiện thay chỗ ô nhập — tiêu đề trôi lên 8px, nút vào sau 90ms. Chạy khi #result được hiện. */
@media (prefers-reduced-motion: no-preference) {
  .result h2 { animation: result-in .3s ease-out both; }
  .result .result-actions { animation: result-in .3s ease-out .09s both; }
  @keyframes result-in { from { opacity: 0; transform: translateY(8px); } }
}

/* Đếm ngược phủ lên phòng chờ / bàn chơi khi bắt đầu ván. */
.countdown {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 24px;
  background: rgb(253 253 247 / .76); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: countdown-in .25s ease-out;
}
.countdown[hidden] { display: none; }
.countdown.leaving { opacity: 0; pointer-events: none; transition: opacity .18s ease-in; }
.countdown-card { display: grid; justify-items: center; gap: 14px; text-align: center; outline: none; }
.countdown-title { font-size: 20px; font-weight: 600; color: var(--ink-deep); }
.countdown-dial { position: relative; width: 220px; height: 220px; }
.countdown-dial svg { display: block; width: 100%; height: 100%; overflow: visible; }
.countdown-dial circle { fill: rgb(255 255 255 / .55); stroke-width: 6; }
.countdown-dial .track { stroke: var(--grid-strong); }
.countdown-dial .drain { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-dasharray: 597; }
.countdown-dial .drain.run { animation: countdown-drain 1s linear forwards; }
.countdown-number {
  font: 400 60px var(--hand); fill: var(--ink);
  text-anchor: middle; dominant-baseline: central;
  transform-box: fill-box; transform-origin: center;
}
.countdown-number.pop { animation: countdown-pop .3s cubic-bezier(.32, .72, 0, 1); }
.countdown-audio {
  display: inline-flex; align-items: center; gap: 8px; max-width: min(380px, 100%); text-wrap: balance;
  padding: 6px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--grid-strong);
  color: var(--pencil); font-size: 14px;
}
.countdown-audio svg { flex: none; width: 18px; height: 18px; }
.countdown-audio:empty, .countdown-audio[hidden] { display: none; }
@keyframes countdown-in { from { opacity: 0; } }
@keyframes countdown-drain { from { stroke-dashoffset: 0; } to { stroke-dashoffset: 597; } }
@keyframes countdown-pop { 0% { opacity: 0; transform: scale(1.5); } 100% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .countdown, .countdown-number.pop, .countdown-dial .drain.run { animation: none; }
  .countdown.leaving { transition: none; }
}
@media (max-width: 640px) {
  .countdown-dial { width: 184px; height: 184px; }
  .countdown-title { font-size: 18px; }
  .countdown-card { gap: 22px; }
  .countdown-audio { font-size: 13px; padding: 4px 10px; }
}

.history { margin-top: 24px; }
.history h2 { display: flex; align-items: baseline; gap: 8px; }
.count { font-weight: 400; font-size: 14px; color: var(--pencil); }
.history-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 0;
  font-size: 17px;
  color: var(--ink);
}
.history-list li + li::before { content: "→"; margin: 0 8px; color: var(--grid-strong); }
.board-foot { margin-top: 28px; }

/* Admin từ điển (DJO-11): danh sách gọn, một dòng mỗi từ + Loại / Duyệt lại */
#dict-heading { font-family: inherit; font-size: clamp(20px, 3vw, 24px); font-weight: 600; line-height: 1.35; color: var(--ink-deep); }
.dict-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px;
  padding-bottom: 12px; border-bottom: 1px solid var(--grid);
}
.dict-toolbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.dict-toolbar-label {
  font-size: 12px; font-weight: 600; color: var(--pencil);
}
.dict-search { width: min(100%, 280px); min-height: 44px; font-size: 16px; }
.dict-pager { margin-top: 12px; }
.dict-toolbar .lobby-actions { gap: 4px 12px; }
.dict-toolbar .lobby-actions .text-button[aria-pressed="true"] {
  color: var(--ink-deep); font-weight: 700; background-image: linear-gradient(var(--ink), var(--ink)); background-size: 100% 2px;
}
.top-actions .text-button[aria-current="page"] {
  color: var(--ink-deep); font-weight: 700; background-image: linear-gradient(var(--ink), var(--ink)); background-size: 100% 2px;
}
/* Thanh trên các trang x/ (quản trị): một hàng nav, cuộn ngang khi màn hẹp. */
.admin-topbar .logo { white-space: nowrap; }
.admin-nav {
  flex: 1 1 auto; min-width: 0; max-width: 100%; padding-inline: 6px;
  flex-wrap: nowrap; overflow-x: auto; gap: 4px 18px; scrollbar-width: none;
}
.admin-nav::-webkit-scrollbar { display: none; }
.admin-nav > .text-button { flex: none; white-space: nowrap; padding-block: 12px; }
@media (max-width: 640px) {
  .admin-topbar { flex-wrap: wrap; }
  .admin-nav { flex-basis: 100%; }
}
.dict-wrap.panel { padding: 0; overflow: hidden; }
.dict-entries { list-style: none; margin: 0; padding: 0; }
.dict-entry {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 16px; align-items: center;
  padding: 12px 16px; border-top: 1px solid var(--grid);
}
.dict-entry:first-child { border-top: 0; }
.dict-entry-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.dict-entry-word { margin: 0; font-size: 17px; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.dict-entry.is-inactive .dict-entry-word {
  color: var(--pencil); font-weight: 600;
  text-decoration: line-through; text-decoration-color: var(--grid-strong);
}
.dict-entry-meta { display: flex; align-items: center; font-size: 12px; color: var(--pencil); }
.dict-badge { font-size: 12px; font-weight: 600; color: var(--pencil); }
.dict-entry-body { grid-column: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-width: 0; }
.dict-meaning { margin: 0; font-size: 14px; line-height: 1.45; color: var(--ink-deep); }
.dict-meaning.is-empty { color: var(--pencil); font-style: italic; }
.dict-source { margin: 0; font-size: 12px; color: var(--pencil); }
.dict-source::before { content: "· "; }
.dict-entry-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; }
.dict-entry-actions .submit {
  min-height: 40px; padding: 0 14px; font-size: 14px; font-weight: 600;
  background: transparent; border: 1.5px solid var(--grid-strong); color: var(--ink); box-shadow: none;
}
.dict-entry-actions .submit:active:not(:disabled) { transform: none; box-shadow: none; }
.dict-entry-actions .submit:hover:not(:disabled) { background: var(--paper); border-color: var(--ink); }
.dict-entry-actions .submit--danger { color: var(--red); }
.dict-entry-actions .submit--danger:hover:not(:disabled) { background: var(--paper); border-color: var(--red); }

@media (prefers-reduced-motion: reduce) {
  .submit, .text-button { transition: none; }
  .text-button::before, .text-button::after { transition: none; }
  .submit:active:not(:disabled) { transform: none; box-shadow: 0 2px 0 var(--ink-deep); }
  .text-button:active:not(:disabled):not([aria-disabled="true"]):not([aria-current="page"]) { transform: none; }
}

/* ── Màn hình hẹp ────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  body { font-size: 16px; }
  .page { padding: 0 16px 48px; }
  .board { padding: 16px 14px 18px; }
  .tiles { gap: 6px; }
  .input-row input { font-size: 16px; }
  #move-form .submit { min-width: 0; padding: 0 16px; }
  .lobby-list li { align-items: stretch; flex-direction: column; }
  #gate-view .hero { padding-bottom: 64px; }
  #gate-view .section { padding: 56px 0; }
  #try-board { padding: 18px 16px; }
  #try-board .input-row .submit { padding: 0 16px; }
  .dict-entry { padding: 10px 14px; gap: 2px 12px; }
  .dict-entry-actions .submit { padding: 0 12px; min-height: 44px; }
  .dict-toolbar-group:first-child { flex: 1 1 100%; }
  .dict-search { width: 100%; }
}

/* ── Admin: thống kê ─────────────────────────────────────────────────────── */
.notify-panel { padding: 14px 16px; display: grid; gap: 10px; justify-items: start; }
.notify-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.notify-list label { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; margin: 0; font-weight: 500; cursor: pointer; }
.notify-list input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ink); flex: none; margin: 0; }
.stats-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.stat-tile { padding: 14px 16px; display: grid; gap: 2px; }
.stat-tile strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.stat-tile span { font-size: 13px; color: var(--pencil); }
.stats-title { margin: 0; font-size: 18px; }
.stats-scroll { padding: 8px 16px; overflow-x: auto; }
.stats-table { width: 100%; border-collapse: collapse; min-width: 460px; }
.stats-table th, .stats-table td { padding: 8px 10px 8px 0; text-align: left; font-size: 14px; border-top: 1px solid var(--grid-strong); white-space: nowrap; }
.stats-table thead th { border-top: 0; color: var(--pencil); font-weight: 500; }
.stats-table tbody th { font-weight: 600; }
/* DJO-128 — người dùng: cột Tên dính khi cuộn ngang, màn hẹp ẩn Email. Thống kê: tile nhóm Phòng / Ván / Người. */
.users-table th:first-child { position: sticky; left: 0; background: #fff; }
@media (max-width: 640px) { .users-table .col-email { display: none; } }
#stats-tiles { grid-template-columns: minmax(0, 1fr); gap: 16px; }
.stat-group { display: grid; gap: 8px; }
.stat-group-title { margin: 0; font-size: 13px; font-weight: 600; color: var(--pencil); }
.stat-group-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
@media (min-width: 641px) {
  .stat-group-tiles { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* Thống kê hồ sơ */
.profile-stats { margin-bottom: 0; }
.profile-stats h2 { margin-top: 0; }
.profile-stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.profile-stats-grid dt { font-size: .8rem; }
.profile-stats-grid dd { margin: .5rem 0 0; font-size: 2.1rem; font-weight: 600; }

.profile-stats-grid dd small { font-size: .75rem; font-weight: 400; }

/* DJO-28 — bàn chơi theo design/game-opus.html */
#game-shell .game-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 48px; align-items: start; }
@media (min-width: 900px) {
  #game-shell .game-layout:has(.game-side > :not([hidden])) { grid-template-columns: minmax(0, 680px) minmax(280px, 340px); }
  #game-shell .game-main { max-width: 680px; }
  #game-shell .game-side { position: sticky; top: 24px; padding-top: 86px; }
}
#game-shell .view-head { align-items: flex-start; gap: 4px 20px; margin-top: 4px; }
#game-shell .view-head h1 { min-width: 0; padding-bottom: .2em; font: 400 clamp(26px, 4.2vw, 40px)/1.6 var(--hand); color: var(--ink); overflow-wrap: anywhere; }
#game-shell .view-head .text-button { flex: none; margin-top: 12px; }
#game-shell .series-line { margin-top: -2px; text-align: left; }
#game-shell .player { position: relative; flex: none; min-height: 40px; padding: 5px 12px 5px 6px; border-radius: 999px; }
#game-shell .player .avatar { width: 26px; height: 26px; font-size: 12px; }
#game-shell .player strong { white-space: nowrap; }
#game-shell .player-name::after { content: ''; position: absolute; inset: -1.5px; border-radius: 999px; }
#game-shell .player-name:focus-visible { outline: none; }
#game-shell .player:has(.player-name:focus-visible) { outline: 3px solid var(--ink); outline-offset: 2px; }
#game-shell .you-label { padding: 0 6px; border-radius: 4px; background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 600; line-height: 1.6; }
#game-shell .board { padding: 18px 22px 22px; }
#game-shell .play { display: flex; flex-direction: column; }
#game-shell .word-zone { display: grid; justify-items: center; }
#game-shell .board .tiles { --tile: min(80px, calc((100vw - 76px - (var(--letters, 4) - 1) * 8px) / var(--letters, 4))); margin: 24px 0 8px; }
#game-shell #move-form, #game-shell #revive-guess { margin-top: 16px; }
#game-shell #move-form label { font-size: 14px; }
#game-shell #move { font-size: 18px; }
#game-shell #move[readonly] { border-color: var(--grid-strong); background: rgb(255 255 255 / .6); }
/* DJO-122: từ sai — viền đỏ (mọi chế độ), lắc ngang 360ms khi không bật giảm chuyển động. */
#move.rejected { border-color: var(--red); }
@media (prefers-reduced-motion: no-preference) {
  #move.rejected { animation: move-shake .36s linear; }
  @keyframes move-shake {
    0%, 100% { transform: translateX(0); }
    17% { transform: translateX(-10px); }
    33% { transform: translateX(10px); }
    50% { transform: translateX(-6px); }
    67% { transform: translateX(6px); }
    83% { transform: translateX(-3px); }
  }
}
#game-shell .mini-roster, #game-shell .recent { display: none; }
#game-shell .side-panel { padding: 12px 16px; }
#game-shell .side-panel-head { font-size: 17px; }
@media (max-width: 640px) {
  #game-shell .view-head { margin-top: 10px; align-items: center; }
  #game-shell .view-head h1 { font-size: 24px; line-height: 1.5; padding-bottom: .15em; }
  #game-shell .view-head .text-button { min-height: 44px; margin-top: 0; }
  #game-shell .roster { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; margin: 10px -16px 0; padding: 3px 16px 4px; }
  #game-shell .roster::-webkit-scrollbar { display: none; }
  #game-shell .player { min-height: 44px; }
  #game-shell .board { margin-top: 10px; padding: 14px 14px 16px; }
  #game-shell .board .tiles { --tile: min(72px, calc((100vw - 68px - (var(--letters, 4) - 1) * 6px) / var(--letters, 4))); margin: 16px 0 6px; }
  #game-shell .timer strong { font-size: 30px; }
  #game-shell .turn-status { font-size: 16px; }
  #game-shell #move { font-size: 17px; }
  #game-shell #move-form, #game-shell #revive-guess { margin-top: 12px; }
  #game-shell #move-form .submit { min-width: 96px; padding: 0 16px; }
}
@media (max-width: 640px) and (max-height: 600px) {
  #game-shell .view-head h1 { font-size: 19px; }
  #game-shell .board .tiles { --tile: min(52px, calc((100vw - 68px - (var(--letters, 4) - 1) * 6px) / var(--letters, 4))); margin: 10px 0 4px; }
  #game-shell .word-meaning { min-height: 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #game-shell #move-form { order: 4; margin-top: 8px; }
  #game-shell #revive-guess { margin-top: 8px; }
  #game-shell #move-form label span { display: none; }
  #game-shell .message { order: 3; min-height: 0; margin-top: 8px; }
  #game-shell .message:empty { display: none; }
}
#game-shell .mini-roster { justify-content: center; gap: 6px; flex: none; }
#game-shell .mini-roster span { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 600; }
#game-shell .mini-roster span.active { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--mark), 0 0 0 5px var(--ink); }
#game-shell .mini-roster span.eliminated { background: #b4b7c6; }
#game-shell .recent { align-items: center; justify-content: center; max-width: 100%; overflow: hidden; font-size: 14px; color: var(--pencil); white-space: nowrap; }
#game-shell .recent .word-trigger + .word-trigger::before,
#game-shell .recent .word-trigger + span::before,
#game-shell .recent > span + .word-trigger::before,
#game-shell .recent > span + span::before {
  content: '→'; margin: 0 8px 0 0; padding-right: 0; color: var(--grid-strong); text-decoration: none;
}
#game-shell .recent .word-trigger:last-child,
#game-shell .recent > span:last-child { color: var(--ink); font-weight: 700; }

/* DJO-77: chế độ Không hồi kết, hồi sinh bằng đoán từ. */
.life-row { margin: 0 0 12px; }
.life-row label { display: block; font-size: 14px; font-weight: 600; color: var(--ink-deep); margin: 0 0 6px; }
/* DJO-88: chú thích chế độ chơi, mở khi hover, focus hoặc chạm (không click). Kiểu như thẻ thống kê người chơi. */
.life-head { position: relative; display: flex; align-items: center; gap: 6px; margin: 0 0 6px; }
.life-head label { margin: 0; }
.life-help { display: inline-flex; }
.life-help-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 22px; height: 22px; min-width: 22px; padding: 0;
  border: 1.5px solid var(--ink); border-radius: 50%;
  background: #fff; color: var(--ink); font: 700 13px/1 var(--sans); cursor: help;
}
.life-help-btn:hover { background: var(--page-line-fine); }
.mode-tip {
  display: none; position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 25;
  padding: 12px 16px 14px; background: #fff; border: 1.5px solid var(--ink); border-radius: 12px;
  box-shadow: 0 8px 22px rgb(35 27 94 / .16); color: var(--ink-deep);
  font-size: 14px; font-weight: 400; line-height: 1.45; text-align: left;
}
.life-help:hover .mode-tip,
.life-help:focus-within .mode-tip { display: block; }
.mode-tip-item { display: block; }
.mode-tip-item + .mode-tip-item { margin-top: 8px; }
.mode-tip-name { display: block; font-size: 12px; color: var(--pencil); }
.mode-tip-body { display: block; }
/* Icon chế độ trong dải rút gọn (DJO-88): Mặc định không có icon, Hồi sinh và Tập thể có. */
#room-waiting .fact-row .life-help-btn { position: relative; width: auto; min-width: 0; height: 26px; padding: 0 8px; border: 1px solid var(--grid-strong); border-radius: 999px; background: #fff; color: var(--ink); font-size: 12px; }
#room-waiting .life-help-btn::after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100%; height: 100%; min-width: 44px; min-height: 44px; }
#room-waiting .room-facts { position: relative; }
#room-waiting .fact-row .mode-tip { top: calc(100% + 6px); }
#room-waiting .life-help.is-open .mode-tip { display: block; }
#room-waiting .life-help.is-closed .mode-tip { display: none; }
.revive-banner { margin: 0 0 10px; padding: 8px 12px; border: 1.5px solid var(--green); border-radius: 10px; color: var(--green); font-weight: 600; font-size: 15px; background: #fff; }
.player.revive-flash { animation: revive-flash 1.1s ease-out 1; }
@keyframes revive-flash { from { background-color: #d3efdc; } to { background-color: transparent; } }
@media (prefers-reduced-motion: reduce) { .player.revive-flash { animation: none; background-color: #d3efdc; } }

/* ── Chế độ debug (DJO-78): pill TEST trên thanh trên, trang ẩn /x/test.html ── */
.debug-pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 12px;
  border: 1.5px solid var(--red); border-radius: 999px; color: var(--red);
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.debug-pill b { font-weight: 500; color: var(--ink-deep); }
.debug-gate { max-width: 560px; }
.debug-gate .gate-lead { margin: 6px 0 0; font-size: 15px; }
.debug-gate-panel { margin-top: 24px; display: grid; gap: 16px; }
.debug-gate-panel h2 { margin: 0; font-size: 18px; font-weight: 600; }
.num-row {
  display: flex; align-items: stretch; border: 1.5px solid var(--ink); border-radius: 8px;
  background: #fff; overflow: hidden;
}
.num-row > span {
  display: grid; place-items: center; padding: 0 14px; background: var(--page-line-fine);
  color: var(--ink); font-weight: 700;
}
.num-row input { flex: 1; min-width: 0; min-height: 44px; border: 0; padding: 8px 12px; font-size: 18px; background: transparent; color: var(--ink-deep); }
.num-row input:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }
.num-row:focus-within { box-shadow: 0 0 0 3px rgb(59 47 155 / .18); }
@media (max-width: 640px) {
  .debug-pill { min-height: 28px; padding: 0 10px; font-size: 12px; }
  .debug-gate .view-head { margin-top: 16px; }
  /* Thanh trên điện thoại hẹp: khi có pill TEST, bỏ chữ Đổi chữ và tên trong nút tài khoản (còn logo + avatar). */
  body:has(#debug-pill:not([hidden])) .topbar .brand span,
  body:has(#debug-pill:not([hidden])) .account-toggle .account-name { display: none !important; }
  body:has(#debug-pill:not([hidden])) .account-toggle { gap: 0; max-width: none; padding: 4px; border-radius: 50%; }
}

/* DJO-91: người xem (design/djo-91-spectate-opus.html). */
.facts .fact.live { color: var(--ink); font-weight: 600; }
.facts .fact.viewers { display: inline-flex; align-items: center; gap: 4px; }
.facts .fact.viewers svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.watch-button { min-height: 44px; padding: 0 20px; border: 1.5px solid var(--ink); border-radius: 10px; background: #fff; color: var(--ink); font: 600 16px/1 var(--sans); cursor: pointer; }
.watch-button:hover { background: rgb(59 47 155 / .07); }
.watch-button:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.spectate-line { display: flex; align-items: center; gap: 10px; min-height: 52px; margin: 0; padding: 8px 14px; border: 1px dashed var(--grid-strong); border-radius: 10px; color: var(--pencil); }
.spectate-line[hidden] { display: none; }
.spectate-line .eye { flex: 0 0 44px; height: 44px; display: grid; place-items: center; }
.spectate-line .eye svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.spectate-line strong { color: var(--ink); }
.chat-locked { color: var(--pencil); margin: 2px 0 8px; font-size: 14px; line-height: 1.45; }
.chat-locked[hidden] { display: none; }
.viewers-panel ul { list-style: none; margin: 0; padding: 0 0 4px; display: grid; gap: 6px; }
.viewers-panel li { display: flex; align-items: center; gap: 10px; }
.viewers-panel .avatar { width: 28px; height: 28px; font-size: 13px; }
/* Cùng kiểu #room-waiting .kick: × đỏ trong vùng 44px. */
.viewers-panel .kick { margin-left: auto; width: 44px; height: 44px; border: 0; background: transparent; color: var(--red); font-size: 24px; cursor: pointer; }
.viewers-panel .kick:hover { background: rgb(170 53 53 / .08); border-radius: 8px; }
.queue-section { margin-top: 24px; }
.queue { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.queue li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 52px; padding: 6px 12px; background: #fff; border: 1px solid var(--grid-strong); border-radius: 12px; }
.queue li.me { border-color: var(--ink); }
.queue .pos { width: 24px; text-align: center; font-weight: 700; color: var(--ink); }

/* ── Bảng xếp hạng (bxh.html, theo design/leaderboard-opus.html) ───────── */
.bxh-seg { display: inline-flex; margin-top: 18px; background: #fff; border: 1.5px solid var(--ink); border-radius: 8px; overflow: hidden; }
.bxh-seg button {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 0; background: none;
  color: var(--ink); font-size: 15px; font-weight: 600; white-space: nowrap;
}
.bxh-seg button + button { border-left: 1.5px solid var(--ink); }
.bxh-seg button:hover { background: rgb(59 47 155 / .07); }
.bxh-seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.bxh-seg button:focus-visible { outline-offset: -5px; outline-color: var(--mark); }
.bxh-seg svg { display: block; width: 24px; height: 16px; border-radius: 2px; box-shadow: 0 0 0 1px rgb(35 27 94 / .12); }
.bxh-sheet { margin-top: 22px; background: #fff; border: 1.5px solid var(--grid-strong); border-radius: 12px; overflow-x: auto; }
.bxh-board { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.bxh-board th {
  padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--pencil); text-align: right;
  border-bottom: 1.5px solid var(--grid-strong); white-space: nowrap;
}
.bxh-board th:nth-child(-n+2) { text-align: left; }
.bxh-board th button {
  padding: 0; border: 0; background: none; color: inherit; font: inherit;
  text-decoration: underline; text-decoration-color: var(--grid-strong); text-decoration-thickness: 2px; text-underline-offset: 5px;
}
.bxh-board th button:hover { text-decoration-color: var(--ink); }
.bxh-board th[aria-sort] { color: var(--ink-deep); }
.bxh-board th[aria-sort] button { text-decoration-color: var(--red); }
.bxh-board td { padding: 10px 14px; border-bottom: 1px solid var(--grid); text-align: right; color: var(--pencil); }
.bxh-board tr:last-child td { border-bottom: 0; }
.bxh-board td.sorted { color: var(--ink-deep); font-weight: 600; }
.bxh-board .rank { width: 56px; text-align: left; font: 400 20px/1.6 var(--hand); color: var(--ink); }
.bxh-board .who { text-align: left; color: var(--ink-deep); }
.bxh-board .who-inner { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bxh-board .who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bxh-board .tag { flex: none; padding: 0 8px; border-radius: 4px; font-size: 12px; font-weight: 600; background: var(--ink); color: var(--paper); }
.bxh-board tr.me td { background: rgb(59 47 155 / .06); }
.bxh-board tr.me td:first-child { box-shadow: inset 3px 0 0 var(--ink); }
.bxh-board tr.gap td {
  padding: 6px 14px; text-align: left; font-size: 13px; color: var(--pencil);
  background: rgb(253 253 247 / .8); border-top: 1.5px dashed var(--grid-strong); border-bottom: 1.5px dashed var(--grid-strong);
}
.bxh-board .bxh-skeleton .bar { display: inline-block; width: 3.2em; height: 12px; border-radius: 3px; background: var(--grid); vertical-align: middle; }
.bxh-board .bxh-skeleton .who .bar { width: 7em; }
@media (prefers-reduced-motion: no-preference) {
  .bxh-board .bxh-skeleton .bar { animation: bxh-pulse 1.2s ease-in-out infinite alternate; }
  @keyframes bxh-pulse { to { opacity: .45; } }
}
.bxh-me-note { margin: 12px 0 0; font-size: 14px; color: var(--pencil); }
.bxh-me-note:empty { display: none; }
.bxh-rule { margin: 12px 0 0; }
.bxh-empty, .bxh-failed {
  display: grid; justify-items: start; gap: 14px; margin-top: 22px; padding: 28px 24px;
  border: 1.5px dashed var(--grid-strong); border-radius: 12px; background: rgb(255 255 255 / .7);
}
.bxh-failed { border: 1.5px solid var(--red); background: #fff; }
.bxh-empty p, .bxh-failed p { margin: 0; }
.bxh-empty strong, .bxh-failed strong { display: block; font-size: 17px; color: var(--ink-deep); }
.bxh-empty span, .bxh-failed span { color: var(--pencil); }
@media (max-width: 640px) {
  .bxh-seg { display: flex; }
  .bxh-seg button { flex: 1 1 0; justify-content: center; padding: 0 6px; font-size: 14px; }
  .bxh-sheet { margin-left: -8px; margin-right: -8px; }
  .bxh-board th { padding: 8px 6px; }
  .bxh-board td { padding: 9px 6px; font-size: 15px; }
  .bxh-board th:first-child, .bxh-board td:first-child { padding-left: 12px; }
  .bxh-board th:last-child, .bxh-board td:last-child { padding-right: 12px; }
  .bxh-board .rank { width: 30px; font-size: 18px; }
  .bxh-board .who .avatar { display: none; }
  .bxh-board .who-inner { gap: 6px; }
  .bxh-board .tag { padding: 0 5px; font-size: 11px; }
}

/* DJO-94 — Bạn bè: nút trong thẻ thống kê, panel, thẻ mời vào phòng, chấm đỏ. */
.fr-btn { min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1.5px solid var(--ink); background: #fff; color: var(--ink); font: 600 15px/1 var(--sans); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.fr-btn:disabled { opacity: .6; cursor: default; }
.fr-btn.primary { background: var(--ink); color: var(--paper); }
.fr-btn.ghost { border-color: var(--grid-strong); color: var(--pencil); }
.fr-btn.danger { color: var(--red); border-color: var(--red); }
.fr-btn.ghost.danger { border-color: var(--grid-strong); }
.fr-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.fr-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.player-stats .fr-actions + .player-stats-note { margin-top: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; border: 2px solid var(--pencil); }
.dot.on { background: var(--green); border-color: var(--green); }
.dot.play { background: var(--mark); border-color: #c9a800; }
.fr-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.fr-list li { display: flex; align-items: center; gap: 10px; min-height: 52px; }
.fr-list .avatar { width: 34px; height: 34px; font-size: 14px; flex: none; }
.fr-list .who { flex: 1; min-width: 0; display: grid; line-height: 1.3; }
.fr-list .who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fr-list .who small { color: var(--pencil); font-size: 13px; }
.fr-list .fr-btn { min-height: 36px; padding: 0 12px; font-size: 14px; }
.fr-head { font-size: 13px; color: var(--pencil); font-weight: 600; margin: 14px 0 2px; }
.fr-top { display: flex; align-items: center; justify-content: space-between; }
.fr-top h2 { margin: 0; }
.fr-top .icon-button { width: 44px; height: 44px; font-size: 28px; line-height: 1; }
.fr-empty { margin: 8px 0 0; }
.friends-panel {
  position: fixed; z-index: 30; top: 64px; right: 16px; width: 360px; max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 80px); overflow-y: auto; margin: 0; padding: 16px;
  background: #fff; border: 1.5px solid var(--ink); border-radius: 12px; box-shadow: 0 10px 28px rgb(35 27 94 / .14);
}
.friends-panel { transform-origin: top right; animation: fr-panel-in .2s cubic-bezier(.32,.72,0,1) both; }
.friends-panel.is-closing { animation: fr-panel-out .15s ease-in both; pointer-events: none; }
@keyframes fr-panel-in { from { opacity: 0; transform: scale(.97); } }
@keyframes fr-panel-out { to { opacity: 0; transform: scale(.97); } }
@media (prefers-reduced-motion: reduce) {
  .friends-panel, .friends-panel.is-closing { animation: none; }
}
.friends-toggle { position: relative; }
.has-dot.friends-toggle::after {
  content: ""; position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--red);
}
#friends-menu.has-dot::after {
  content: ""; position: static; inset: auto; z-index: auto;
  display: inline-block; width: 8px; height: 8px; margin-left: 8px; border-radius: 50%; background: var(--red);
  clip-path: none; transform: none; transition: none;
}
.invite-toast {
  position: sticky; top: 8px; z-index: 28; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  width: min(640px, calc(100% - 32px)); margin: 8px auto 0; padding: 12px 14px;
  background: #fff; border: 1.5px solid var(--ink); border-radius: 12px; box-shadow: 0 6px 18px rgb(35 27 94 / .12);
}
.invite-toast .avatar { width: 34px; height: 34px; }
.invite-toast p { flex: 1; margin: 0; min-width: 160px; }
.invite-toast .timer-track { flex-basis: 100%; height: 3px; margin-top: 0; }
@media (max-width: 640px) {
  .friends-panel { top: 56px; right: 8px; left: 8px; width: auto; max-width: none; }
}
/* DJO-90: đấu đội (design/djo-90-team-duel-opus.html). Xanh --team-blue, đỏ --red. */
:root { --team-blue: #2f6db5; }

/* Phòng chờ: hai nửa, xanh trên đỏ dưới, nút xáo ở giữa. */
#room-waiting .teams { display: grid; gap: 0; }
#room-waiting .teams[hidden] { display: none; }
#room-waiting .seats[hidden] { display: none; }
#room-waiting .slot:has(.kick) { padding-right: 52px; }
#room-waiting .team {
  border: 1.5px solid var(--team-c); border-radius: 12px; padding: 12px;
  background: color-mix(in srgb, var(--team-c) 5%, #fff);
}
#room-waiting .team.blue { --team-c: var(--team-blue); }
#room-waiting .team.red { --team-c: var(--red); }
#room-waiting .team h3 {
  margin: 0 0 8px; font: 600 16px/1.4 var(--sans); color: var(--team-c);
  display: flex; justify-content: space-between;
}
#room-waiting .team h3 .hint { color: var(--pencil); font-weight: 500; }
#room-waiting .slots {
  list-style: none; margin: 0; padding: 0; display: grid; gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
#room-waiting .slot {
  position: relative; display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 52px;
  padding: 6px 10px; background: #fff; border: 1px solid var(--grid-strong); border-radius: 10px;
}
#room-waiting .slot strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
#room-waiting .slot .avatar {
  width: 32px; height: 32px; font-size: 13px; flex: none;
  background: var(--team-c); color: #fff; border-color: transparent;
}
#room-waiting .slot.me { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
#room-waiting .slot.empty { border-style: dashed; color: var(--pencil); justify-content: center; background: transparent; font-size: 14px; }
#room-waiting button.slot.empty { width: 100%; cursor: pointer; font: 500 14px var(--sans); }
#room-waiting button.slot.empty:hover { border-color: var(--team-c); color: var(--team-c); }
#room-waiting .slot svg.lock { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--pencil); stroke-width: 2; margin-left: auto; }
#room-waiting .slot .kick { margin-left: auto; }
#room-waiting .shuffle-row { display: flex; justify-content: center; align-items: center; height: 56px; position: relative; }
#room-waiting .shuffle-row::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dashed var(--grid-strong); }
#room-waiting .shuffle {
  position: relative; width: 48px; height: 48px; border-radius: 50%; border: 1.5px solid var(--ink);
  background: #fff; color: var(--ink); display: grid; place-items: center; cursor: pointer; padding: 0;
}
#room-waiting .shuffle[hidden] { display: none; }
#room-waiting .shuffle:hover { background: rgb(59 47 155 / .07); }
#room-waiting .shuffle svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#room-waiting .shuffle.spin svg { animation: team-shuffle-spin 420ms cubic-bezier(.22, 1, .36, 1); }
#room-waiting .vs { position: relative; background: var(--paper); padding: 0 10px; font-family: var(--hand); color: var(--pencil); }
#room-waiting .vs[hidden] { display: none; }
@keyframes team-shuffle-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #room-waiting .shuffle.spin svg { animation: none; } }
#room-waiting .start-bar .message[hidden] { display: none; }
@media (max-width: 640px) {
  #room-waiting .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #room-waiting .slot.empty.hide-m { display: none; }
}

/* Trong ván: hàng đội mình, bàn mình, box đối phương, dòng kết quả, tab chat. */
.roster.duel { flex-direction: column; gap: 6px; }
.roster.duel .team-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.team-line.blue { --team-c: var(--team-blue); }
.team-line.red { --team-c: var(--red); }
.team-line .player { border-color: color-mix(in srgb, var(--team-c) 55%, var(--grid-strong)); }
.team-line .player.active { border-color: var(--ink); }
#game-shell.duel-mode .board.team-board { border-color: var(--team-c); }
#game-shell.duel-mode .board.team-board.blue { --team-c: var(--team-blue); }
#game-shell.duel-mode .board.team-board.red { --team-c: var(--red); }
#game-shell.duel-mode.my-turn .board.team-board { box-shadow: 0 0 0 3px color-mix(in srgb, var(--team-c) 18%, transparent); }
.mine-done {
  margin: 16px 0 0; padding: 10px 14px; border: 1px dashed var(--team-c); border-radius: 12px; color: var(--pencil);
  display: flex; justify-content: space-between; gap: 8px;
}
.mine-done[hidden], .opp[hidden], .score[hidden], .chat-tabs[hidden] { display: none; }
.mine-done b { color: var(--team-c); }
.mine-done.blue { --team-c: var(--team-blue); }
.mine-done.red { --team-c: var(--red); }
.opp {
  margin-top: 16px; padding: 12px 16px; border: 1.5px solid var(--team-c); border-radius: 12px;
  background: color-mix(in srgb, var(--team-c) 4%, #fff);
}
.opp.blue { --team-c: var(--team-blue); }
.opp.red { --team-c: var(--red); }
.opp .tb-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.opp .tb-head b { color: var(--team-c); }
.opp .timer { position: relative; }
.opp .timer strong { font-size: 26px; }
.opp .team-bonus { position: absolute; right: 100%; margin-right: 6px; }
.opp .timer-bar { background: var(--team-c); transition: width .2s linear; }
#game-shell .opp .tiles { --tile: min(44px, calc((100vw - 76px - (var(--letters, 4) - 1) * 8px) / var(--letters, 4))); margin: 14px 0 6px; }
#game-shell .opp.big .tiles { --tile: min(60px, calc((100vw - 76px - (var(--letters, 4) - 1) * 8px) / var(--letters, 4))); }
.opp .tiles.blur .tile { filter: blur(6px); }
.opp .players { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; font-size: 14px; color: var(--pencil); }
.opp .players .on { color: var(--ink-deep); background: var(--mark); padding: 0 4px; border-radius: 4px; font-weight: 600; }
.opp .players .out { text-decoration: line-through; }
.score { display: flex; gap: 12px; margin: 8px 0 18px; }
.score span { flex: 1; padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--team-c); color: var(--team-c); font-weight: 700; }
.score .blue { --team-c: var(--team-blue); }
.score .red { --team-c: var(--red); }
.chat-tabs { display: flex; gap: 4px; margin: 0; }
.chat-tabs button {
  position: relative; min-height: 36px; padding: 0 14px; border: 1px solid var(--grid-strong); border-radius: 8px;
  background: #fff; color: var(--ink-deep); font: 500 14px var(--sans); cursor: pointer;
}
.chat-tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; }
.chat-tabs button.unread::after {
  content: ""; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--red);
}

/* ── Không khí Giáng sinh (tuyết rơi + nhạc nền) ──────────────────────────── */
.christmas-snow-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 14;
}
.christmas-controls {
  display: inline-flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}
/* Đã đăng nhập: cặp nút nằm sau #sound-toggle / #sound-menu, cụm chưa đăng nhập ẩn để không trùng. */
.topbar:has(#account:not([hidden])) .christmas-controls--guest { display: none; }
.christmas-btn-snow.is-active svg {
  animation: christmas-snow-activate .42s cubic-bezier(.22, 1, .36, 1) 1;
}
.christmas-btn-music.is-active svg {
  animation: christmas-music-activate .36s cubic-bezier(.22, 1, .36, 1) 1;
}
@keyframes christmas-snow-activate {
  0% { transform: rotate(-45deg) scale(0.84); }
  60% { transform: rotate(10deg) scale(1.08); }
  100% { transform: rotate(0deg) scale(1); }
}
@keyframes christmas-music-activate {
  0% { transform: scale(0.84); }
  55% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@media (max-width: 640px) {
  /* Màn hẹp ở trang landing/tĩnh: nổi gọn góc dưới phải để giữ "Vào chơi" một hàng. */
  body:not(:has(#gate-view[hidden])):not(.account-page) .christmas-controls--guest {
    position: fixed;
    right: 10px;
    bottom: 18px;
    z-index: 20;
    padding: 2px;
    border-radius: 999px;
    background: rgb(253 253 247 / .92);
    border: 1px solid var(--grid-strong);
    box-shadow: 0 4px 14px rgb(35 27 94 / .12);
    backdrop-filter: blur(6px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .christmas-btn-snow.is-active svg,
  .christmas-btn-music.is-active svg {
    animation: none;
  }
}
/* Mũ Noel trên avatar người chơi (phòng chờ và bàn chơi) khi tuyết đang bật (class do christmas.js đặt trên <html>). Chỉ trang trí, không đổi kích thước avatar. */
html.christmas-festive :is(#room-waiting, #game-shell) .avatar { position: relative; overflow: visible; }
html.christmas-festive :is(#room-waiting, #game-shell) .avatar img { border-radius: 50%; }
html.christmas-festive :is(#room-waiting, #game-shell) .avatar::after {
  content: "";
  position: absolute;
  pointer-events: none;
  top: -36%;
  right: -16%;
  width: 78%;
  height: 66%;
  background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 34'><path d='M6 27C10 15 18 8 31 4C27 13 26 21 34 27Z' fill='%23cf2f2a' stroke='%23a61f1b' stroke-width='1.2' stroke-linejoin='round'/><circle cx='33' cy='5' r='4.2' fill='%23fff' stroke='%23a8c6d4'/><rect x='2' y='24' width='36' height='9' rx='4.5' fill='%23fff' stroke='%23a8c6d4'/></svg>") center / contain no-repeat;
  transform: rotate(12deg);
  transform-origin: center bottom;
}
@media (max-width: 640px) {
  /* Thanh roster cuộn ngang cắt chóp mũ: chừa đỉnh cho mũ. */
  html.christmas-festive #game-shell .roster { padding-top: 10px; }
}

/* ── DJO-142: Góp ý (Feedback Dialog) ────────────────────────────────────────── */
.feedback-dialog {
  border: 1.5px solid var(--grid-strong);
  border-radius: 14px;
  padding: 20px 22px 22px;
  background: #fff;
  color: var(--ink-deep);
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: 0 18px 44px rgb(35 27 94 / .22);
  margin: auto;
  box-sizing: border-box;
}
.feedback-dialog::backdrop {
  background: color-mix(in srgb, var(--ink) 45%, transparent);
}
@media (max-width: 480px) {
  .feedback-dialog {
    padding: 16px 16px 18px;
    width: calc(100vw - 24px);
  }
}

.fb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.fb-title {
  margin: 0;
  font: 400 24px/1.5 var(--hand);
  color: var(--ink);
}
.fb-close {
  width: 44px;
  height: 44px;
  margin: -8px -10px -8px 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--pencil);
  font: 400 26px/1 var(--sans);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 120ms, color 120ms;
}
.fb-close:hover {
  background: rgb(59 47 155 / .08);
  color: var(--ink);
}

.fb-field {
  position: relative;
  margin-bottom: 12px;
}
.fb-textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 116px;
  resize: vertical;
  padding: 11px 13px 28px;
  border: 1.5px solid var(--grid-strong);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink-deep);
  font: 400 16px/1.55 var(--sans);
  transition: border-color 140ms, background 140ms, box-shadow 140ms;
}
.fb-textarea:focus {
  outline: none;
  border-color: var(--ink);
  background: #fff;
  box-shadow: 0 0 0 3px rgb(59 47 155 / .14);
}
.fb-textarea.is-error {
  border-color: var(--red);
}
.fb-textarea:disabled {
  background: #f3f5f8;
  color: var(--pencil);
  cursor: not-allowed;
}
.fb-counter {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 12px;
  color: var(--pencil);
  pointer-events: none;
}
.fb-counter.is-warn {
  color: var(--red);
  font-weight: 600;
}

.fb-dropzone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1.5px dashed var(--grid-strong);
  border-radius: 10px;
  background: var(--paper);
  cursor: pointer;
  transition: border-color 140ms, background 140ms;
  box-sizing: border-box;
}
.fb-dropzone:hover,
.fb-dropzone.is-drag {
  border-color: var(--ink);
  background: rgb(59 47 155 / .05);
}
.fb-dropzone:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
.fb-dropzone.is-disabled {
  opacity: .55;
  pointer-events: none;
}
.fb-drop-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.fb-drop-left svg {
  width: 20px;
  height: 20px;
  color: var(--ink);
  flex: none;
}
.fb-drop-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}
.fb-drop-hint {
  font-size: 12px;
  color: var(--pencil);
  white-space: nowrap;
}

.fb-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  margin-bottom: 14px;
  border: 1.5px solid var(--grid-strong);
  border-radius: 10px;
  background: var(--paper);
  box-sizing: border-box;
}
.fb-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--grid-strong);
  background: #fff;
  flex: none;
}
.fb-file-info {
  flex: 1;
  min-width: 0;
}
.fb-file-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fb-file-meta {
  font-size: 12px;
  color: var(--pencil);
}
.fb-remove-img {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--red);
  font-size: 22px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: none;
  transition: background 120ms;
}
.fb-remove-img:hover {
  background: rgb(207 47 42 / .09);
}

.fb-msg {
  min-height: 22px;
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.45;
}
.fb-msg.error {
  color: var(--red);
  font-weight: 500;
}
.fb-msg.limit {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--paper);
  border: 1.5px solid var(--red);
  color: var(--red);
  font-weight: 500;
}

.fb-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}
@media (max-width: 480px) {
  .fb-actions {
    justify-content: space-between;
  }
  .fb-actions .submit {
    flex: 1;
  }
}

.fb-done {
  text-align: center;
  padding: 14px 6px 6px;
  display: grid;
  justify-items: center;
  gap: 10px;
}
.fb-done-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgb(28 116 72 / .12);
  color: var(--green);
  display: grid;
  place-items: center;
}
.fb-done-icon svg {
  width: 28px;
  height: 28px;
}
.fb-done h3 {
  margin: 0;
  font: 400 22px/1.5 var(--hand);
  color: var(--green);
}
.fb-done p {
  margin: 0;
  color: var(--pencil);
  font-size: 14px;
  max-width: 30ch;
}
@media (prefers-reduced-motion: reduce) {
  .feedback-dialog,
  .fb-close,
  .fb-textarea,
  .fb-dropzone,
  .fb-remove-img {
    transition: none !important;
    animation: none !important;
  }
}

