@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700&display=swap');
/* ==========================================================================
   game-online — phong cách chung cho mọi trang (sáng / tối, điện thoại)
   Màu định nghĩa bằng biến; chế độ tối theo hệ thống hoặc chọn tay (data-theme).
   ========================================================================== */
:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --card-2: #f0eee8;
  --text: #24272b;
  --muted: #6c7177;
  --border: #e2dfd7;
  --accent: #3b5fa8;
  --accent-ink: #ffffff;
  --accent-soft: rgba(59, 95, 168, 0.12);
  --danger: #c43b3b;
  --warn: #cf861b;
  --ok: #2f8f55;
  --clock-bg: #ebe9e3;
  --clock-run: #3b5fa8;
  --clock-low: #c43b3b;
  --shadow: 0 2px 12px rgba(30, 30, 20, 0.08);
  --radius: 12px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #17191c;
    --card: #212428;
    --card-2: #2a2e33;
    --text: #e7e9eb;
    --muted: #9ba3aa;
    --border: #353a40;
    --accent: #7f9fe0;
    --accent-ink: #0e1420;
    --accent-soft: rgba(127, 159, 224, 0.16);
    --danger: #ef6b6b;
    --warn: #f0a640;
    --ok: #5cc27e;
    --clock-bg: #2a2e33;
    --clock-run: #5a7fcc;
    --clock-low: #e05555;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #17191c;
  --card: #212428;
  --card-2: #2a2e33;
  --text: #e7e9eb;
  --muted: #9ba3aa;
  --border: #353a40;
  --accent: #7f9fe0;
  --accent-ink: #0e1420;
  --accent-soft: rgba(127, 159, 224, 0.16);
  --danger: #ef6b6b;
  --warn: #f0a640;
  --ok: #5cc27e;
  --clock-bg: #2a2e33;
  --clock-run: #5a7fcc;
  --clock-low: #e05555;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
a {
  color: var(--accent);
}
h1,
h2,
h3 {
  line-height: 1.25;
}
.hidden {
  display: none !important;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}

/* ---------- Nút, ô nhập ---------- */
button,
.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  min-height: 40px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover:not(:disabled),
.btn:hover {
  background: var(--card-2);
}
button:active:not(:disabled) {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.primary,
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button.primary:hover:not(:disabled),
.btn.primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}
button.danger,
.btn.danger {
  color: var(--danger);
}
button.icon {
  padding: 7px 10px;
  min-width: 40px;
}
.btn-block {
  width: 100%;
}
input[type='text'],
input[type='password'],
input[type='search'],
input[type='date'],
select,
textarea {
  font: inherit;
  width: 100%;
  padding: 9px 12px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}
.field {
  margin-bottom: 14px;
}
.field > label,
.field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field .hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  user-select: none;
}
.check input {
  margin-top: 3px;
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}
.check small {
  display: block;
  color: var(--muted);
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row > input {
  flex: 1;
}
.msg-error {
  color: var(--danger);
  font-size: 14px;
  min-height: 20px;
  margin-top: 8px;
}
.msg-ok {
  color: var(--ok);
  font-size: 14px;
  min-height: 20px;
  margin-top: 8px;
}

/* Nhóm lựa chọn dạng "chip" (radio) */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chips input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.chips label {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  background: var(--card);
}
.chips input:checked + label {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.chips input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Tab */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  overflow-x: auto;
}
.tabs button {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  padding: 8px 12px;
  min-height: 38px;
  white-space: nowrap;
}
.tabs button.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Đầu trang ---------- */
.site-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}
.site-header .brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.site-header .spacer {
  flex: 1;
}
.site-header .room-code {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.site-header .room-code b {
  color: var(--text);
  letter-spacing: 1px;
}
.user-menu {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}
.user-menu .who {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu .dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
}
.user-menu .dropdown a,
.user-menu .dropdown button {
  justify-content: flex-start;
  border: 0;
  text-align: left;
  width: 100%;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
  min-height: 0;
}
.user-menu .dropdown a:hover,
.user-menu .dropdown button:hover {
  background: var(--card-2);
}
.badge-role {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  padding: 1px 6px;
  font-weight: 600;
}

/* ---------- Khung trang + thẻ ---------- */
.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.page.narrow {
  max-width: 440px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 17px;
  margin: 0 0 12px;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ---------- Trang chủ ---------- */
.hero {
  text-align: center;
  margin: 6px 0 20px;
}
.hero h1 {
  margin: 0;
  font-size: 32px;
}
.hero p {
  color: var(--muted);
  margin: 6px 0 0;
}
.game-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
.game-card {
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: var(--card);
  min-height: 112px;
  box-shadow: var(--shadow);
}
.game-card .icon {
  font-size: 30px;
  line-height: 1;
}
.game-card .title {
  font-weight: 700;
  font-size: 17px;
}
.game-card .desc {
  color: var(--muted);
  font-size: 13px;
}
.game-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.invite {
  margin-top: 14px;
  padding: 14px;
  border: 1px dashed var(--accent);
  border-radius: 12px;
  background: var(--card-2);
  text-align: center;
}
.invite .code {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 5px;
}
.invite .link {
  font-size: 13px;
  color: var(--muted);
  word-break: break-all;
  margin: 6px 0 10px;
}
.invite .row button {
  flex: 1;
}
.code-input {
  text-transform: uppercase;
  letter-spacing: 3px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.stat {
  text-align: center;
  background: var(--card-2);
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 13px;
  color: var(--muted);
}
.stat b {
  display: block;
  font-size: 22px;
  color: var(--text);
}
.stat.win b {
  color: var(--ok);
}
.stat.loss b {
  color: var(--danger);
}
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
}
.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.list li:first-child {
  border-top: 0;
}
.list .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  padding: 2px 8px;
  background: var(--card-2);
  color: var(--muted);
}
.tag.win {
  background: rgba(47, 143, 85, 0.15);
  color: var(--ok);
}
.tag.loss {
  background: rgba(196, 59, 59, 0.15);
  color: var(--danger);
}
.rank {
  width: 22px;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
}
.credits {
  margin-top: 24px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

/* Bảng (hồ sơ, quản trị) */
.table-wrap {
  overflow-x: auto;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th,
table.data td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data th {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}
table.data tr:hover td {
  background: var(--card-2);
}

/* ---------- Thông báo nhanh, hộp thoại ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  background: #2a2e31;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 100;
  max-width: 92vw;
  text-align: center;
  box-shadow: var(--shadow);
}
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}
.modal .box {
  background: var(--card);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.modal h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

/* ==========================================================================
   Trang chơi (play.html) — phần chung cho mọi game
   ========================================================================== */
.play {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 14px;
  align-items: start;
}
.board-col {
  --board-ratio: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Bàn cờ vừa chiều cao màn hình; tỉ lệ rộng/cao do game đặt qua --board-ratio */
  width: min(100%, calc((100vh - 220px) * var(--board-ratio)));
  width: min(100%, calc((100dvh - 220px) * var(--board-ratio)));
  min-width: 300px;
  justify-self: center;
}
.notices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.notices:empty {
  display: none;
}
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: rgba(207, 134, 27, 0.12);
  border: 1px solid rgba(207, 134, 27, 0.4);
}
.banner .text {
  flex: 1;
  min-width: 150px;
}
.banner.info {
  background: var(--accent-soft);
  border-color: rgba(59, 95, 168, 0.35);
}
.banner.conn {
  background: rgba(196, 59, 59, 0.12);
  border-color: rgba(196, 59, 59, 0.4);
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--card);
  border: 2px solid var(--border);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.player-bar.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.player-bar .who {
  flex: 1;
  min-width: 0;
}
.player-bar .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-bar .side-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
}
.player-bar .you {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  padding: 1px 6px;
  font-weight: 600;
}
.player-bar .sub {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 20px;
  flex-wrap: wrap;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #aaa;
  flex: none;
  display: inline-block;
}
.dot.online {
  background: var(--ok);
}
.dot.offline {
  background: var(--warn);
}
.dot.left {
  background: var(--danger);
}
.clock {
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--clock-bg);
  min-width: 92px;
  text-align: center;
  transition: background 0.2s, color 0.2s;
}
.clock.running {
  background: var(--clock-run);
  color: #fff;
}
.clock.low {
  background: var(--clock-low);
  color: #fff;
}
.clock.pulse {
  animation: pulse 1s infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.6;
  }
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: var(--board-ratio);
  touch-action: none; /* không cuộn trang khi kéo quân */
  user-select: none;
  -webkit-user-select: none;
}
.board-wrap.viewing::after {
  content: 'Đang xem lại';
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 12;
}
.result-bubble {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border-radius: 16px;
  padding: 16px 22px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  z-index: 15;
  min-width: 250px;
  max-width: 92%;
}
.result-bubble .big {
  font-size: 26px;
  font-weight: 800;
}
.result-bubble .big.win {
  color: var(--ok);
}
.result-bubble .big.loss {
  color: var(--danger);
}
.result-bubble .small {
  color: var(--muted);
  margin: 4px 0 12px;
}
.result-bubble .row {
  justify-content: center;
  flex-wrap: wrap;
}
/* Thanh "Sửa nước" (game có đồng hồ theo lượt) */
.edit-bar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 14;
  background: var(--card);
  padding: 6px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.edit-bar button {
  background: #fff8e8;
  border-color: #f1c66b;
  color: #8a5a00;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Cột bên */
.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.drawer {
  display: contents; /* máy tính: các panel bên trong nằm chung cột bên */
}
.sheet-head {
  display: none;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.panel h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.p-status {
  order: 1;
}
.p-actions {
  order: 2;
}
.p-game {
  order: 3;
}
.p-meta {
  order: 4;
}
.p-chat {
  order: 5;
}
.status-line {
  font-weight: 600;
}
.status-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}
.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.actions button,
.actions .btn {
  padding: 8px 6px;
  font-size: 14px;
}
.meta {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
}
.meta b {
  color: var(--text);
}
.settings {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.settings label {
  white-space: nowrap;
}
.settings select {
  min-height: 34px;
  padding: 5px 8px;
}
.moves-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.moves-nav button {
  padding: 6px;
  min-height: 36px;
}
.move-list {
  max-height: 260px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 38px 1fr 1fr;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.move-list .num {
  color: var(--muted);
  padding: 4px 6px;
  text-align: right;
}
.move-list .mv {
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.move-list .mv:hover {
  background: var(--card-2);
}
.move-list .mv.current {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.move-list .empty {
  grid-column: 1 / -1;
  color: var(--muted);
  padding: 6px;
}
.chat-log {
  height: 170px;
  overflow-y: auto;
  font-size: 14px;
  margin-bottom: 8px;
  word-wrap: break-word;
}
.chat-log .m {
  margin: 3px 0;
}
.chat-log .m b {
  font-weight: 600;
}
.chat-log .sys {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}
.chat form {
  display: flex;
  gap: 6px;
}

/* Các phần chỉ dùng trên điện thoại */
.mobile-bar,
.sheet-backdrop {
  display: none;
}

/* ---------- Điện thoại / màn hình hẹp ---------- */
@media (max-width: 860px) {
  .grid-2,
  .game-cards {
    grid-template-columns: 1fr;
  }
  .game-card {
    min-height: 0;
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }
  html,
  body {
    overflow-x: hidden; /* không bao giờ cuộn ngang trên điện thoại */
  }
  .site-header {
    padding: 6px 8px;
    gap: 6px;
  }
  .site-header > * {
    flex-shrink: 0;
  }
  .site-header .label-long,
  .site-header .game-name {
    display: none;
  }
  .site-header .room-code {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .site-header button.icon,
  .user-menu .btn,
  .user-menu > button {
    padding: 6px 8px;
    min-width: 36px;
    min-height: 36px;
  }
  .user-menu .who {
    max-width: 80px;
  }
  .user-menu .reg-btn {
    display: none; /* màn hình hẹp: chỉ để nút Đăng nhập (trang đăng nhập có link Đăng ký) */
  }
  .page {
    padding: 14px 10px 30px;
  }
  .play {
    grid-template-columns: 1fr;
    padding: 0 0 calc(76px + env(safe-area-inset-bottom));
    gap: 10px;
  }
  .board-col {
    width: 100%;
    min-width: 0;
    gap: 0;
  }
  .notices {
    padding: 6px;
  }
  .player-bar {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    min-height: 48px;
  }
  .clock {
    font-size: 20px;
    min-width: 84px;
  }
  .side {
    padding: 0 10px;
  }
  .move-list {
    max-height: 150px;
  }
  input[type='text'],
  input[type='password'] {
    font-size: 16px; /* tránh iOS tự phóng to */
  }

  /* Thanh thao tác dưới cùng */
  .mobile-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--border);
  }
  .mobile-bar button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 2px;
    min-height: 52px;
    font-size: 12px;
    border-color: transparent;
    background: transparent;
  }
  .mobile-bar button .ic {
    font-size: 20px;
    line-height: 1;
  }
  .mobile-bar .badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 22px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    line-height: 18px;
  }

  /* Ngăn kéo: điều khiển đầy đủ + chat */
  .drawer {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    max-height: 82dvh;
    overflow-y: auto;
    padding: 6px 10px calc(12px + env(safe-area-inset-bottom));
    background: var(--bg);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
    transform: translateY(105%);
    transition: transform 0.22s ease;
    visibility: hidden;
  }
  .drawer.open {
    transform: none;
    visibility: visible;
  }
  .drawer .panel {
    margin-bottom: 10px;
  }
  .sheet-head {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 30px;
  }
  .sheet-grip {
    width: 42px;
    height: 5px;
    border-radius: 3px;
    background: var(--border);
  }
  .sheet-head button {
    position: absolute;
    right: 0;
    top: 0;
  }
  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(20, 25, 20, 0.3);
  }
  .sheet-backdrop.hidden {
    display: none;
  }
  .chat-log {
    height: auto;
    max-height: 32dvh;
    min-height: 100px;
  }
}
@media (max-width: 860px) and (max-height: 500px) {
  .mobile-bar button {
    min-height: 40px;
  }
  .mobile-bar button span:not(.ic) {
    display: none;
  }
}

/* ==========================================================================
   Trang chơi — bố cục mới: cột bên = trạng thái · điều khiển · khung tab (chat / nước đi / thông tin)
   Điện thoại: chat nằm ngay dưới bàn cờ; nút "Thêm" mở ngăn kéo điều khiển.
   ========================================================================== */
.play {
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  padding: 16px 18px 20px;
  align-items: stretch;
}
.board-col {
  align-self: start;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.board-col .player-bar {
  border-radius: 12px;
  background: var(--card-2);
  border-color: transparent;
}
.board-col .player-bar.active {
  background: var(--card);
  border-color: var(--accent);
}
.player-bar .pname {
  font-size: 15px;
}
.board-wrap {
  border-radius: 10px;
  overflow: hidden;
}
.side {
  gap: 12px;
  max-height: calc(100dvh - 92px);
  position: sticky;
  top: 12px;
}
.side .panel {
  border-radius: 16px;
  box-shadow: var(--shadow);
}
/* Trạng thái */
.p-status {
  order: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.side.my-turn .p-status {
  border-color: var(--ok);
  box-shadow: 0 0 0 3px rgba(47, 143, 85, 0.15);
}
.status-text {
  min-width: 0;
}
.status-line {
  font-size: 16px;
}
.status-dot {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
}
.status-dot.playing {
  background: var(--accent);
}
.status-dot.myturn {
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(47, 143, 85, 0.6);
  animation: ping 1.4s infinite;
}
.status-dot.win {
  background: var(--ok);
}
.status-dot.loss {
  background: var(--danger);
}
.status-dot.finished {
  background: var(--warn);
}
@keyframes ping {
  70% {
    box-shadow: 0 0 0 8px rgba(47, 143, 85, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(47, 143, 85, 0);
  }
}
/* Điều khiển */
.p-actions {
  order: 2;
  padding: 10px;
}
.actions {
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.actions button,
.actions .btn {
  justify-content: flex-start;
  gap: 8px;
  padding: 7px 10px;
  min-height: 38px;
  font-size: 14px;
  background: var(--card-2);
  border-color: transparent;
}
.actions button:hover:not(:disabled),
.actions .btn:hover {
  border-color: var(--border);
  background: var(--card);
}
.actions button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  justify-content: center;
}
.actions .ic {
  width: 18px;
  text-align: center;
  font-weight: 700;
}
/* Khung tab */
.p-tabs {
  order: 3;
  flex: 1;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.side-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--card-2);
}
.side-tabs button {
  flex: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  border-bottom: 3px solid transparent;
  padding: 10px 6px;
  min-height: 44px;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  gap: 6px;
}
.side-tabs button:hover:not(:disabled) {
  background: transparent;
  color: var(--text);
}
.side-tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--card);
  font-weight: 600;
}
.tab-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
}
.tab-pane {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}
.tab-pane.active {
  display: flex;
  flex-direction: column;
}
.tab-pane h3 {
  display: none; /* tiêu đề đã có trên tab */
}
.tab-pane .move-list {
  max-height: none;
  flex: 1;
}
.tab-pane.chat {
  padding: 0;
}
.tab-pane.chat .chat-log {
  flex: 1;
  height: auto;
  min-height: 160px;
  margin: 0;
  padding: 10px 12px;
}
.tab-pane.chat form {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--card-2);
}
.chat-log .m {
  margin: 0 0 6px;
  padding: 6px 10px;
  background: var(--card-2);
  border-radius: 10px;
  line-height: 1.4;
}
.chat-log .m.sys {
  background: transparent;
  padding: 2px 4px;
  text-align: center;
  font-size: 12px;
}
.tab-pane.meta {
  line-height: 1.9;
}

@media (max-width: 860px) {
  .play {
    grid-template-columns: minmax(0, 1fr);
    padding: 0 0 calc(76px + env(safe-area-inset-bottom));
    gap: 10px;
  }
  .board-col {
    padding: 0;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
  }
  .board-col .player-bar {
    border-radius: 0;
    background: var(--card);
  }
  .board-wrap {
    border-radius: 0;
  }
  .side {
    position: static;
    max-height: none;
    padding: 0 10px;
    gap: 10px;
  }
  .p-status {
    padding: 10px 14px;
  }
  /* Chat ngay dưới bàn cờ, cao vừa phải */
  .p-tabs {
    min-height: 0;
  }
  .tab-pane {
    max-height: 46dvh;
  }
  .tab-pane.chat .chat-log {
    min-height: 140px;
    max-height: 32dvh;
  }
  .drawer .p-actions {
    box-shadow: none;
  }
  .actions {
    grid-template-columns: repeat(2, 1fr);
  }
  .actions button,
  .actions .btn {
    min-height: 46px;
  }
  .sheet-title {
    font-size: 14px;
    color: var(--muted);
    position: absolute;
    left: 4px;
    top: 6px;
  }
}

/* ==========================================================================
   Trang chủ — giao diện mới
   ========================================================================== */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}
.top-nav {
  display: flex;
  gap: 2px;
  margin-left: 12px;
}
.top-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
}
.top-nav a:hover {
  background: var(--card-2);
  color: var(--text);
}
.home-page .site-header {
  position: sticky;
  top: 0;
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--card) 88%, transparent);
}

/* Hero */
.hero-band {
  background: radial-gradient(1200px 400px at 85% -20%, rgba(255, 255, 255, 0.14), transparent 60%),
    linear-gradient(135deg, #1b2440 0%, #2c4486 55%, #3b5fa8 100%);
  color: #fff;
}
.hero-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 48px 16px 56px;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 32px;
  align-items: center;
}
.hero-kicker {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 4px 10px;
  border-radius: 999px;
}
.hero-text h1 {
  font-size: 42px;
  line-height: 1.12;
  margin: 14px 0 12px;
  letter-spacing: -0.5px;
}
.hero-text p {
  color: rgba(255, 255, 255, 0.82);
  font-size: 16px;
  max-width: 480px;
  margin: 0 0 22px;
  line-height: 1.55;
}
.hero-join {
  display: flex;
  gap: 8px;
  max-width: 440px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 6px;
  border-radius: 14px;
}
.hero-join input {
  flex: 1;
  border: 0;
  background: #fff;
  color: #1b2440;
  font-weight: 600;
  min-height: 46px;
}
.hero-join button {
  min-height: 46px;
  padding: 0 20px;
  background: #ffcf4a;
  border-color: #ffcf4a;
  color: #1b2440;
}
.hero-join button:hover:not(:disabled) {
  background: #ffd96e;
  filter: none;
}
.hero-points {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 18px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
}
.hero-art {
  position: relative;
  height: 300px;
}
.hero-tile {
  position: absolute;
  width: 62%;
  aspect-ratio: 16 / 10;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  border: 3px solid rgba(255, 255, 255, 0.85);
}
.hero-tile svg {
  display: block;
  width: 100%;
  height: 100%;
}
.hero-tile.t1 {
  left: 0;
  top: 0;
  transform: rotate(-6deg);
}
.hero-tile.t2 {
  right: 0;
  top: 40px;
  transform: rotate(5deg);
  z-index: 2;
}
.hero-tile.t3 {
  left: 14%;
  bottom: 0;
  transform: rotate(-2deg);
  z-index: 3;
}

.home-main {
  padding-top: 28px;
}
.section-title {
  font-size: 20px;
  margin: 8px 0 14px;
  scroll-margin-top: 70px;
}

/* Thẻ game */
.game-cards {
  gap: 16px;
  margin-bottom: 28px;
}
.game-card {
  padding: 0;
  overflow: hidden;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  min-height: 0;
  border-radius: 18px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.game-card:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px rgba(20, 30, 60, 0.16);
  background: var(--card);
}
.game-art {
  position: relative;
  aspect-ratio: 16 / 9;
  border-bottom: 1px solid var(--border);
}
.game-art svg {
  display: block;
  width: 100%;
  height: 100%;
}
.game-art .art-icon {
  display: grid;
  place-items: center;
  height: 100%;
  font-size: 48px;
  background: var(--card-2);
}
.game-art .check {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  display: none;
}
.game-card.active .check {
  display: inline-block;
}
.game-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}
.game-body .title {
  font-weight: 700;
  font-size: 18px;
}
.game-body .desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.game-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.game-tags span {
  font-size: 11.5px;
  background: var(--card-2);
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 6px;
}

/* Khung tạo phòng */
.create-card {
  padding: 22px;
  margin-bottom: 28px;
}
.create-head h2 {
  font-size: 19px;
  margin: 0 0 2px;
}
.create-head p {
  margin: 0 0 16px;
}
.options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 24px;
}
.options-grid .check {
  grid-column: 1 / -1;
  padding: 12px 14px;
  background: var(--card-2);
  border-radius: 12px;
}
.create-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 6px;
}
.create-foot .msg-error {
  flex: 1;
  margin: 0;
}
.big-btn {
  min-width: 200px;
  min-height: 48px;
  font-size: 16px;
  border-radius: 12px;
}
.invite {
  margin-top: 18px;
  text-align: left;
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
}
.invite-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
}
.invite .link {
  text-align: left;
  margin: 0 0 8px;
}
.invite-right .row {
  justify-content: flex-start;
}
.invite-right .row button {
  flex: 0 1 auto;
}

/* Thành tích + xếp hạng */
.home-bottom .card {
  padding: 20px;
}
.leaderboard .rank {
  width: 28px;
  font-size: 15px;
}
.leaderboard .rank.top {
  font-size: 20px;
}
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 20px 16px 26px;
  margin-top: 20px;
}
.site-footer .credits {
  margin-top: 6px;
}

@media (max-width: 860px) {
  .top-nav {
    display: none;
  }
  .hero-inner {
    grid-template-columns: 1fr;
    padding: 28px 16px 32px;
    gap: 0;
  }
  .hero-text h1 {
    font-size: 30px;
  }
  .hero-text p {
    font-size: 15px;
  }
  .hero-art {
    display: none;
  }
  .game-cards {
    grid-template-columns: 1fr;
  }
  .game-card {
    flex-direction: row;
  }
  .game-art {
    width: 38%;
    flex: none;
    aspect-ratio: auto;
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }
  .game-art .check {
    top: 6px;
    right: 6px;
    font-size: 10px;
    padding: 2px 7px;
  }
  .game-body {
    padding: 12px;
  }
  .game-body .title {
    font-size: 16px;
  }
  .options-grid {
    grid-template-columns: 1fr;
  }
  .create-card {
    padding: 16px;
  }
  .create-foot {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .big-btn {
    width: 100%;
  }
  .invite-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    text-align: center;
  }
  .invite .link,
  .invite-right .row {
    text-align: center;
    justify-content: center;
  }
}

/* ==========================================================================
   Game nhiều người (Tá lả): phòng chờ, bảng điểm ảo, bố cục "bàn", xoay ngang điện thoại
   ========================================================================== */
.p-lobby {
  order: 2;
}
.lobby-seats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.lobby-seat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--card-2);
  flex-wrap: wrap;
}
.lobby-seat.me {
  outline: 2px solid var(--accent);
}
.lobby-seat .seat-no {
  font-size: 12px;
  color: var(--muted);
  width: 48px;
}
.lobby-seat .seat-who {
  flex: 1;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lobby-seat .pill {
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--card);
  color: var(--muted);
}
.lobby-seat .pill.ok {
  color: var(--ok);
}
.lobby-seat .pill.accent {
  color: var(--accent);
}
button.mini {
  min-height: 30px;
  padding: 3px 10px;
  font-size: 13px;
}
.lobby-actions {
  display: flex;
  gap: 8px;
}
.lobby-actions button {
  flex: 1;
}
#resumeBtn {
  margin-top: 8px;
}
.disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 0;
}
.tally-title {
  margin: 12px 0 6px;
  font-size: 13px;
}
table.tally {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.tally th,
table.tally td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}
table.tally th:first-child,
table.tally td:first-child {
  text-align: left;
}
table.tally .pos {
  color: var(--ok);
}
table.tally .neg {
  color: var(--danger);
}
table.tally .total {
  font-weight: 700;
}
/* Bố cục "bàn": không dùng 2 thanh người chơi trên/dưới (game tự vẽ ghế quanh bàn) */
body.layout-table .player-bar {
  display: none;
}
body.layout-table .board-col {
  width: min(100%, calc((100dvh - 150px) * var(--board-ratio)));
}
/* Bàn bài rộng: cho trang chơi rộng hơn khung 1240px của game cờ */
body.layout-table .play {
  max-width: 1760px;
}
/* Ẩn nút không dùng trên thanh điện thoại → các nút còn lại chia đều */
.mobile-bar {
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}

@media (max-width: 860px) {
  body.layout-table .board-col {
    width: 100%;
  }
}
/* Điện thoại xoay ngang: bàn chiếm gần hết màn hình, cột bên hẹp, ẩn đầu trang */
@media (orientation: landscape) and (max-height: 540px) {
  body.layout-table .site-header,
  body.layout-table .mobile-bar,
  body.layout-table .sheet-head {
    display: none;
  }
  body.layout-table .play {
    grid-template-columns: minmax(0, 1fr) 240px;
    padding: 4px;
    gap: 6px;
  }
  body.layout-table .board-col {
    width: min(100%, calc((100dvh - 30px) * var(--board-ratio)));
    padding: 4px;
    gap: 2px;
  }
  body.layout-table .side {
    position: static;
    max-height: calc(100dvh - 8px);
    overflow-y: auto;
    padding: 0;
    gap: 6px;
  }
  body.layout-table .drawer {
    display: contents;
    position: static;
    transform: none;
    visibility: visible;
  }
  body.layout-table .side .panel {
    padding: 8px;
  }
  body.layout-table .tab-pane.chat .chat-log {
    min-height: 90px;
  }
}

/* Trang chủ: 4 game trở lên */
.game-cards {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.hero-disclaimer {
  margin: 14px 0 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
}
.footer-disclaimer {
  font-weight: 600;
  margin-bottom: 4px;
}
@media (max-width: 860px) {
  .game-cards {
    grid-template-columns: 1fr;
  }
}

/* Tab phụ của bảng xếp hạng (vd. Tá lả: Điểm ảo / Nhất nhiều nhất) */
.tabs.sub-tabs { margin-top: -4px; }
.tabs.sub-tabs button { font-size: 0.8rem; padding: 3px 10px; }

