/* ==========================================================================
   public/css/mobile.css — GIAO DIỆN ĐIỆN THOẠI TỐI GIẢN (nạp sau main.css)
   Nguyên tắc: 1 màn hình = không cuộn trang. Mọi quy tắc bố cục nằm trong @media (max-width: 600px);
   máy tính giữ nguyên. Phần đầu file là thành phần dùng chung (ui-kit.js) — dùng được ở mọi kích thước.
   ========================================================================== */
:root {
  --top-h: 44px; /* thanh trên */
  --bot-h: 56px; /* thanh dưới */
  --bars-h: 0px; /* tổng chiều cao thanh người chơi trên + dưới bàn (game cờ) */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ---------- Thành phần dùng chung (UIKit) ---------- */
.m-only,
.m-info {
  display: none !important;
}
.ui-icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 4px 8px;
  font-size: 18px;
  line-height: 1;
}
.ui-badge,
.mobile-bar .badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 17px;
  font-weight: 700;
}
.ui-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}
.ui-chips::-webkit-scrollbar {
  display: none;
}
.ui-chip {
  flex: none;
  min-height: 40px;
  min-width: 40px;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.ui-chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.ui-swatches {
  display: flex;
  gap: 10px;
}
.ui-swatch {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  font-size: 20px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
}
.ui-swatch.on {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}
html.sheet-lock,
html.sheet-lock body {
  overflow: hidden;
}
.ui-sheet-back {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(15, 20, 15, 0);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: background 0.2s;
}
.ui-sheet-back.show {
  background: rgba(15, 20, 15, 0.38);
}
.ui-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--card);
  color: var(--text);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
  padding: 0 14px calc(14px + var(--safe-b));
  transform: translateY(105%);
  transition: transform 0.22s ease;
}
.ui-sheet-back.show .ui-sheet {
  transform: none;
}
.ui-sheet-head,
.side-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  background: inherit;
  touch-action: none;
}
.ui-sheet-grip {
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
  width: 42px;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
}
.ui-sheet-title,
.side-head b {
  flex: 1;
  font-size: 15px;
  padding-top: 8px;
}
.ui-sheet-x,
.side-head button {
  margin-top: 6px;
  min-width: 40px;
  min-height: 40px;
  border: 0;
  background: var(--card-2);
  border-radius: 50%;
  padding: 0;
}

/* ==========================================================================
   ĐIỆN THOẠI (≤ 600px)
   ========================================================================== */
@media (max-width: 600px) {
  .site-header .m-only,
  .m-info {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
  .side-head.m-only {
    display: flex !important;
  }
  .mobile-bar .m-only {
    display: flex !important;
  }
  #mGameBtns.m-only {
    display: contents !important;
  }
  .site-header .m-only.hidden,
  .mobile-bar .m-only.hidden {
    display: none !important;
  }

  /* ---------- Trang chơi: thanh trên (44px) · bàn chơi · thanh dưới (56px), không cuộn ---------- */
  html:has(body.play-page) {
    height: 100%;
    overflow: hidden;
  }
  body.play-page {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-t);
    overscroll-behavior: none;
  }
  body.play-page .site-header {
    flex: none;
    height: var(--top-h);
    min-height: var(--top-h);
    padding: 0 4px;
    gap: 4px;
    position: relative;
    top: auto;
  }
  body.play-page .site-header .brand,
  body.play-page #copyLinkBtn,
  body.play-page #userMenu,
  body.play-page .room-word {
    display: none !important;
  }
  body.play-page .site-header button.icon {
    min-width: 40px;
    min-height: 40px;
    padding: 0 8px;
    font-size: 18px;
  }
  body.play-page .room-code {
    cursor: pointer;
    font-size: 16px;
    letter-spacing: 1px;
    padding: 6px 10px;
    border-radius: 10px;
    background: var(--card-2);
  }
  body.play-page .room-code::after {
    content: ' 🔗';
    font-size: 13px;
  }
  body.play-page .play {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0 0 calc(var(--bot-h) + var(--safe-b));
    gap: 0;
    max-width: none;
    margin: 0;
  }
  body.play-page .board-col {
    flex: 1;
    min-height: 0;
    width: 100% !important;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0;
    gap: 2px;
    background: transparent;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    position: relative;
    container-type: size; /* bàn tính kích thước theo đúng phần còn lại của cột (cqw / cqh) */
  }
  body.play-page.layout-bars {
    --bars-h: 80px;
  }
  /* Bàn chơi: to nhất có thể trong phần còn lại, giữ tỉ lệ của game (--board-ratio).
     Dòng đầu: dự phòng cho trình duyệt cũ (tính theo màn hình); dòng sau: theo khung thật (container query). */
  body.play-page .board-wrap {
    flex: none;
    width: min(100vw, calc((100vh - var(--top-h) - var(--bot-h) - var(--bars-h) - var(--safe-t) - var(--safe-b) - 6px) * var(--board-ratio)));
    width: min(100vw, calc((100dvh - var(--top-h) - var(--bot-h) - var(--bars-h) - var(--safe-t) - var(--safe-b) - 6px) * var(--board-ratio)));
    width: min(100cqw, calc((100cqh - var(--bars-h) - 4px) * var(--board-ratio)));
    border-radius: 0;
  }
  /* Thẻ người chơi (game cờ): 1 dòng — tên + đồng hồ; lượt hiện tại = viền sáng */
  body.play-page .board-col .player-bar {
    width: 100%;
    flex: none;
    min-height: 38px;
    height: 38px;
    padding: 0 6px 0 10px;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    background: var(--card);
  }
  body.play-page .board-col .player-bar.active {
    box-shadow: inset 0 0 0 2px var(--ok), 0 0 10px rgba(47, 143, 85, 0.35);
    background: var(--card);
  }
  body.play-page .player-bar .sub {
    display: none;
  }
  body.play-page .player-bar[data-status='offline'] .pname::after {
    content: ' 📶✕';
    font-size: 12px;
  }
  body.play-page .player-bar[data-status='left'] .pname {
    opacity: 0.5;
    text-decoration: line-through;
  }
  body.play-page .player-bar .clock {
    font-size: 17px;
    padding: 3px 8px;
    min-width: 66px;
  }
  /* Thông báo: nổi trên bàn, không chiếm chỗ; thông tin phụ → toast */
  body.play-page .notices {
    position: absolute;
    top: 4px;
    left: 6px;
    right: 6px;
    z-index: 25;
    padding: 0;
  }
  body.play-page #infoBanner,
  body.play-page .disclaimer {
    display: none !important;
  }
  body.play-page .banner {
    padding: 6px 10px;
    font-size: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    background: var(--card);
  }

  /* Cột bên → bottom sheet, mở theo phần: chat / info / menu / lobby */
  body.play-page .side {
    position: fixed !important;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    z-index: 45;
    max-height: 78dvh;
    overflow-y: auto;
    padding: 0 10px calc(12px + var(--safe-b));
    gap: 10px;
    background: var(--bg);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s;
  }
  body.play-page .side.open {
    transform: none;
    visibility: visible;
  }
  body.play-page .side .drawer {
    display: contents !important;
    visibility: inherit; /* ngăn kéo cũ (≤ 860px) ẩn bằng visibility — không để con của nó bị ẩn theo */
    transform: none;
  }
  body.play-page .drawer .sheet-head {
    display: none !important;
  }
  body.play-page .side[data-mode='chat'] .panel:not(.p-tabs),
  body.play-page .side[data-mode='info'] .panel:not(.p-tabs):not(.p-status),
  body.play-page .side[data-mode='menu'] .panel:not(.p-actions):not(.p-status),
  body.play-page .side[data-mode='lobby'] .panel:not(.p-lobby) {
    display: none !important;
  }
  body.play-page .side[data-mode='chat'] .side-tabs {
    display: none;
  }
  body.play-page .side .p-tabs {
    min-height: 0;
    flex: none;
  }
  body.play-page .side .tab-pane {
    max-height: 55dvh;
  }
  body.play-page .side .tab-pane.chat .chat-log {
    min-height: 32dvh;
    max-height: 46dvh;
  }
  body.play-page .side .actions button,
  body.play-page .side .actions .btn {
    min-height: 44px;
  }

  /* Thanh dưới: chỉ icon (chữ rất nhỏ), nút chính theo ngữ cảnh */
  body.play-page .mobile-bar {
    display: flex;
    gap: 4px;
    height: calc(var(--bot-h) + var(--safe-b));
    padding: 4px 6px calc(4px + var(--safe-b));
    align-items: stretch;
  }
  body.play-page .mobile-bar button {
    flex: 1 1 0;
    min-width: 40px;
    min-height: 44px;
    padding: 3px 2px;
    gap: 1px;
    font-size: 10px;
    justify-content: center;
    border-radius: 12px;
  }
  body.play-page .mobile-bar button > span:not(.ic) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    opacity: 0.85;
  }
  body.play-page .mobile-bar button .ic {
    font-size: 20px;
  }
  body.play-page .mobile-bar .m-off {
    display: none !important;
  }
  body.play-page .mobile-bar button.primary {
    flex: 1.6 1 0;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 12px;
    font-weight: 700;
  }
  body.play-page .mobile-bar button.primary.on {
    background: var(--ok);
  }
  body.play-page .mobile-bar .badge {
    top: 2px;
    right: calc(50% - 20px);
  }
  /* Game kiểu bàn (bài, cá ngựa): bàn chiếm trọn phần còn lại giữa 2 thanh — không bỏ phí chỗ trên / dưới */
  body.play-page.layout-table:not([data-game='poker']) .board-wrap {
    width: 100vw;
    height: calc(100vh - var(--top-h) - var(--bot-h) - var(--safe-t) - var(--safe-b));
    height: calc(100dvh - var(--top-h) - var(--bot-h) - var(--safe-t) - var(--safe-b));
    width: 100cqw;
    height: 100cqh;
    aspect-ratio: auto;
  }
  /* Poker: bàn bầu dục giữ đúng tỉ lệ; số phỉnh trên thanh trên không cần chữ "phỉnh" */
  body.play-page .pk-wallet .muted {
    display: none;
  }
  body.play-page .tl-rotate {
    display: none !important; /* gợi ý "xoay ngang": giao diện dọc đã gọn */
  }
  /* ---------- Trang chủ: vừa 1 màn hình (banner mảnh, 4 nút nhanh, lưới game nhỏ) ---------- */
  html:has(body.home-v2) {
    height: 100%;
    overflow: hidden;
  }
  body.home-v2 {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  body.home-v2 .home-header {
    flex: none;
    min-height: var(--top-h);
    padding: 2px 10px;
  }
  body.home-v2 .ltk-text {
    font-size: 22px;
  }
  body.home-v2 .home2 {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 4px 10px calc(62px + var(--safe-b));
  }
  body.home-v2 .site-footer {
    display: none; /* dòng "Game giải trí…" → ⓘ trong popup tạo phòng / sảnh */
  }
  .hero2 {
    flex: none;
    aspect-ratio: auto;
    height: 92px;
    min-height: 0;
    border-radius: 12px;
  }
  .hero2-l1 {
    font-size: 15px;
  }
  .hero2-l2 {
    font-size: 26px;
  }
  .hero2-ribbon {
    display: none;
  }
  .quick4 {
    flex: none;
    gap: 6px;
    margin: 8px 0 2px;
  }
  .q-item {
    padding: 5px 2px 4px;
    gap: 3px;
    font-size: 11.5px;
    white-space: nowrap;
    border-radius: 12px;
  }
  .q-ic {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }
  .q-ic svg {
    width: 20px;
    height: 20px;
  }
  /* 5 nút nhanh trên 1 hàng: thu nhỏ biểu tượng + chữ */
  .quick5 {
    gap: 4px;
  }
  .quick5 .q-item {
    padding: 5px 1px 4px;
    font-size: 10.5px;
    letter-spacing: -0.1px;
  }
  .quick5 .q-ic {
    width: 30px;
    height: 30px;
    border-radius: 9px;
  }
  .quick5 .q-ic svg {
    width: 18px;
    height: 18px;
  }
  .sec-head {
    flex: none;
    margin: 8px 0 6px;
  }
  .sec-head h2 {
    font-size: 16px;
  }
  .see-all {
    display: none;
  }
  .hot-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }
  .hot-tile,
  .hot-tile.wide {
    grid-column: span 1;
    border-radius: 12px;
  }
  .hot-art,
  .hot-tile.wide .hot-art {
    aspect-ratio: 1 / 0.8;
  }
  .hot-art .art-icon {
    font-size: 30px;
  }
  .hot-art .check {
    width: 16px;
    height: 16px;
    top: 3px;
    right: 3px;
  }
  .hot-name {
    font-size: 11px;
    padding: 4px 2px 5px;
  }
  .bottom-nav {
    padding: 2px 4px calc(2px + var(--safe-b));
  }
  .bottom-nav a,
  .bottom-nav button {
    min-height: 48px;
    justify-content: center;
    font-size: 10.5px;
  }

  /* ---------- Popup tạo phòng: bottom sheet ≤ ~70% màn hình, không cuộn bên trong ---------- */
  .modal.sheet .box {
    max-height: 86dvh;
    padding: 10px 12px calc(10px + var(--safe-b));
  }
  #createModal .create-head h2 {
    font-size: 17px;
    margin: 0;
  }
  #createModal #createDesc {
    display: none; /* mô tả dài → nút ⓘ */
  }
  #createModal .create-head {
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
  }
  .create-close {
    width: 40px;
    height: 40px;
  }
  .create-games {
    margin: 0 0 6px;
    gap: 6px;
  }
  .create-games button {
    width: 50px;
    height: 50px;
    min-width: 0;
  }
  #createModal .options-grid {
    display: none; /* đủ luật nằm trong "⚙ Luật chi tiết" */
  }
  .ui-sheet .options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .compact-opts {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .c-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }
  .c-ic {
    flex: none;
    width: 30px;
    text-align: center;
    font-size: 20px;
  }
  .c-row .ui-chips {
    flex: 1;
    min-width: 0;
  }
  .c-more {
    align-self: flex-start;
    min-height: 40px;
    border-radius: 999px;
    margin-left: 38px;
  }
  #createModal .create-foot {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: stretch;
    margin: 8px 0 0;
    padding: 10px 0 0;
    position: static;
  }
  #createModal .create-foot .big-btn {
    min-width: 0;
    width: auto;
  }
  #createModal .create-foot .msg-error {
    flex-basis: 100%;
  }
  #createModal .create-foot:has(.msg-error:not(:empty)) {
    flex-wrap: wrap;
  }
  #createModal .create-foot #createBtn,
  #createModal .create-foot #lobbyBtn {
    flex: 1;
    order: -1;
    min-height: 48px;
  }
  #createModal .create-foot .big-btn .lbl {
    display: none; /* 🤖 / 👨‍👩‍👧: chỉ icon */
  }
  #createModal .create-foot #botBtn,
  #createModal .create-foot #vsBotsBtn,
  #createModal .create-foot #localBtn {
    flex: none;
    width: 52px;
    min-height: 48px;
    padding: 0;
    font-size: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  #createModal .create-foot .hidden {
    display: none !important;
  }

  /* Kết quả ván: khối gọn nằm ngay trên thanh dưới, không che giữa bàn. */
  body.play-page .result-bubble {
    position: fixed;
    top: auto;
    bottom: calc(var(--bot-h) + var(--safe-b) + 6px);
    transform: translateX(-50%);
    min-width: 0;
    width: calc(100% - 16px);
    max-width: 420px;
    padding: 8px 10px 10px;
    border-radius: 14px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    z-index: 30;
  }
  body.play-page .result-bubble .big {
    font-size: 18px;
    line-height: 1.25;
  }
  body.play-page .result-bubble .small {
    font-size: 12px;
    margin: 1px 0 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body.play-page .result-bubble .row {
    gap: 6px;
  }
  body.play-page .result-bubble .row button {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 36px;
    padding: 4px 8px;
    font-size: 13px;
    white-space: nowrap;
  }
  body.bot-page .result-bubble {
    position: static;
    transform: none;
    flex: none;
    width: calc(100% - 16px);
    max-width: none;
    margin: 4px 8px 0;
    padding: 6px 8px;
  }
  body.bot-page .result-bubble .big {
    font-size: 16px;
  }
  body.bot-page .board-col:has(> .result-bubble:not(.hidden)) {
    --bars-h: 140px;
  }
  body.play-page .toast {
    top: calc(var(--top-h) + var(--safe-t) + 4px);
  }
  /* Chơi với máy (bot.html): thanh đánh giá + bàn cờ nằm giữa, cùng công thức kích thước */
  body.bot-page .board-row {
    flex: none;
    width: 100%;
    justify-content: center;
  }
  body.bot-page .board-row .board-wrap {
    flex: none;
  }
  body.bot-page .eval-bar:not(.hidden) ~ .board-wrap {
    width: min(calc(100cqw - 12px), calc((100cqh - var(--bars-h) - 4px) * var(--board-ratio)));
  }
  .bot-setup {
    padding: 14px !important;
  }
  .bot-setup .field {
    margin-bottom: 8px;
  }
  .bot-setup .chips.levels label {
    min-width: 40px;
    padding: 6px 10px;
  }
  .chips.swatch-chips label {
    width: 42px;
    height: 42px;
    min-width: 42px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border: 2px solid var(--border);
  }
  .chips.swatch-chips input:checked + label {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
  }

  /* Bàn bài: thông tin quanh bàn chỉ avatar + số lá / phỉnh — bỏ nhãn chữ thừa ("Máy" đã có avatar 🤖, "Ghế trống") */
  body.play-page .tl-sub .tag:not(.turn):not(.warn):not(.ok):not(.pass):not(.host) {
    display: none;
  }
}

/* Điện thoại rất hẹp (≤ 360px): 5 nút nhanh vẫn vừa 1 hàng */
@media (max-width: 360px) {
  .quick5 .q-item {
    font-size: 9.5px;
    letter-spacing: -0.2px;
  }
  .quick5 .q-ic {
    width: 26px;
    height: 26px;
  }
  .quick5 .q-ic svg {
    width: 16px;
    height: 16px;
  }
}

/* Điện thoại cao (≥ 760px): ô game to hơn — 3 cột */
@media (max-width: 600px) and (min-height: 760px) {
  .hot-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .hot-name {
    font-size: 13px;
  }
  .hero2 {
    height: 110px;
  }
}

/* Khung chat (mọi kích thước): cao vừa ~5 tin, tin cũ hơn cuộn lên xem.
   1 tin = dòng chữ (1.4em) + đệm 12px + cách 6px; khung có đệm 10px trên/dưới. */
body.play-page .side .tab-pane.chat .chat-log {
  flex: none;
  height: calc(5 * (1.4em + 18px) + 20px);
  min-height: 0;
  max-height: none;
}
