/* Bingo — trên nền shared/css/app.css: bảng, các số đã bốc, popup người thắng, và các mục của trò chơi
   trên trang Admin (bảng điều khiển phòng, bảng thắng trong lịch sử). */

/* Khi đang chơi, toàn bộ giao diện vừa một màn hình: không cuộn trang, không nảy đàn hồi. */
body[data-screen="game"] { overflow: hidden; overscroll-behavior: none; }
body[data-screen="game"] .app { height: 100vh; height: 100dvh; }
/* Điện thoại ở chế độ "trang web cho máy tính" (shared/js/fit-phone.js): chiều cao đo được, như .phone-fit .app. */
.phone-fit body[data-screen="game"] .app { height: var(--app-height); }
/* Bảng chiếm toàn bộ chiều cao khi đang chơi. */
body[data-screen="game"] .player-nav { display: none; }
/* Người thắng đang nhường lượt (js/player.js). */
.notice-card.is-winner { border-color: var(--hint); background: var(--hint-soft); font-size: 15px; }
/* "Cách chơi": màu của bảng dưới dạng các ô chú thích nhỏ (.key trong shared/css/app.css). */
.key-free { border-style: dashed; border-color: var(--accent-dark); background: var(--sand); color: var(--accent-dark); font-size: 13px; letter-spacing: 0.06em; }
.key-hint { border-color: var(--hint); background: var(--hint-soft); color: #8a6212; }
.key-ready { border-color: var(--green); background: var(--green-soft); color: var(--green-text); }
/* Danh sách con trong 1 bước (mục "Chiến thắng"): chấm tròn, sát dưới dòng nhãn. */
.guide-steps ul { display: grid; gap: 4px; margin: 4px 0 0; padding-left: 18px; list-style: disc; }
.guide-steps ul li::marker { color: var(--muted); }
/* Bảng ví dụ: bảng mini của lịch sử ở cỡ nhỏ hơn, chú thích bên cạnh khi đủ chỗ. */
.guide-sample { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 16px; margin-top: 14px; }
.lobby-guide .mini-board { width: 150px; gap: 4px; margin: 0; }
.lobby-guide .mini-board span { border-radius: 7px; font-size: 12px; }
.lobby-guide .mini-board .is-free { font-size: 8px; }
.lobby-guide .mini-board .is-line { border-style: solid; }
.lobby-guide .guide-legend { flex-direction: column; align-items: flex-start; gap: 6px; }

/* --- Ván của người chơi: trạng thái / bảng / BINGO, theo cỡ màn hình --- */

.game {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  min-height: 0;
  max-width: 560px;
  padding-top: 10px;
  padding-bottom: 0;
}

/* Số và nhãn của nó giữ nguyên chiều rộng ("Số vừa bốc" trên một dòng); dòng của phòng bên phải thì xuống dòng. */
.game-status { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px 12px; min-width: 0; }
.now { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.now-label { color: var(--muted); font-size: 14px; }
.now-label.is-paused { color: var(--accent-dark); font-weight: 700; }
.now-number {
  color: var(--accent);
  font-size: 46px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1;
}
.game-meta { display: grid; justify-items: end; gap: 4px; color: var(--muted); font-size: 13px; text-align: right; }

/* Các số đã bốc ở trên bảng, theo hàng như danh sách của Admin (mới nhất trước). Bảng giữ hình vuông
   lớn nhất mà vẫn chừa cho chúng hai hàng, ở đáy khoảng trống; khung số cao bằng các số của nó, lớn lên
   phía trên vào phần chiều cao còn thừa rồi cuộn bên trong, nên không bao giờ là một ô trống, không bao giờ
   che bảng, và bảng không bao giờ xê dịch khi có thêm số. */
.play-area {
  --draws-min: 88px; /* hai hàng số 34px + padding và viền của khung */
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  min-height: 0;
  container-type: size;
}
.game .draw-list {
  display: grid;
  flex: 0 1 auto;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  align-content: start;
  justify-items: center;
  min-height: var(--draws-min);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgb(255 255 255 / 0.6);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.game .draw-list li { flex: none; width: 34px; height: 34px; font-size: 14px; }
.game .draw-list li.empty { grid-column: 1 / -1; justify-self: start; }

/* Bảng là hình vuông lớn nhất vừa khoảng trống còn lại (đơn vị container query). */
.board-area {
  display: grid;
  flex: none;
  place-items: center;
  height: min(100cqw, 100cqh - var(--draws-min) - 10px);
  min-height: 0;
  container-type: size;
}
.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 1.8cqmin;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
}
@supports not (width: 1cqmin) {
  .board { width: min(100%, 58vh); gap: 6px; }
}
.board.is-locked { opacity: 0.75; }

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 22%;
  background: var(--white);
  color: var(--ink);
  font-size: 7.5cqmin;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.cell:active:not(:disabled) { transform: scale(0.93); }
.cell:disabled { cursor: default; }
.cell.is-free {
  border-style: dashed;
  background: var(--sand);
  color: var(--accent-dark);
  font-size: 4.2cqmin;
  letter-spacing: 0.06em;
}
.cell.is-hint { border-color: var(--hint); background: var(--hint-soft); animation: hint-pulse 1s ease-in-out infinite; }
.cell.is-marked { border-style: solid; border-color: var(--green); background: var(--green); color: var(--white); }
.cell.is-wrong { border-color: var(--red); background: var(--red); color: var(--white); animation: shake 0.3s; }
/* Một phần của hàng / cột / đường chéo đã hoàn thành. */
.cell.is-line {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
  color: var(--white);
  box-shadow: 0 0 0 2px var(--hint);
  animation: line-pop 0.4s ease-out;
}
@supports not (width: 1cqmin) {
  .cell { font-size: clamp(16px, 5.5vw, 28px); }
  .cell.is-free { font-size: clamp(11px, 3.2vw, 16px); }
}

.bingo-bar { display: grid; gap: 6px; padding-bottom: calc(12px + var(--safe-bottom)); }
.bingo-feedback { min-height: 20px; color: var(--red); font-size: 14px; font-weight: 700; text-align: center; }
.bingo-feedback[data-tone="ready"] {
  color: var(--green-text);
  font-size: 16px;
  font-weight: 800;
  line-height: 20px; /* cùng chiều cao với ô chứa, để bảng không bị xê dịch */
  animation: ready-blink 0.9s ease-in-out infinite;
}
.btn-bingo {
  width: 100%;
  min-height: 64px;
  border-radius: 18px;
  background: var(--ink);
  color: var(--white);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.12em;
}
/* Đã có người thắng: nút chỉ nói điều gì xảy ra tiếp theo. */
.btn-bingo.is-waiting { font-size: 17px; letter-spacing: 0; }
.bingo-feedback[data-tone="finished"] { color: var(--ink); }
/* Đủ số đường cho chế độ của phòng: nhấp nháy cho tới khi người chơi bấm. */
.btn-bingo.is-ready {
  background: var(--green);
  animation: bingo-ready 0.9s ease-in-out infinite;
}

/* Màn hình thấp (iPhone SE / mini, Android 16:9): thu gọn phần khung để bảng vẫn lớn.
   Đo theo chiều cao của chính màn hình chơi, cũng đúng với điện thoại ở chế độ máy tính bị phóng to. */
body[data-screen="game"] .app { container: app / size; }
@container app (max-height: 700px) {
  .now-number { font-size: 38px; }
  .play-area { --draws-min: 72px; }
  .game .draw-list { grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); padding: 2px 6px; }
  .game .draw-list li { width: 30px; height: 30px; font-size: 13px; }
  .btn-bingo { min-height: 56px; font-size: 22px; }
}

/* Điện thoại nằm ngang: bảng bên trái, mọi thứ khác bên phải. */
@media (orientation: landscape) and (max-height: 520px) {
  .game {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 38%);
    grid-template-rows: auto minmax(0, 1fr) auto;
    max-width: none;
    column-gap: 20px;
  }
  .play-area { display: contents; }
  .board-area { grid-column: 1; grid-row: 1 / -1; height: auto; padding-bottom: calc(8px + var(--safe-bottom)); }
  .game .draw-list { grid-column: 2; grid-row: 2; min-height: 0; }
  .game-status { grid-column: 2; grid-row: 1; }
  .bingo-bar { grid-column: 2; grid-row: 3; }
}

/* --- Các mục của trò chơi trên trang Admin: bảng điều khiển phòng --- */

.draws-card { order: 1; }
.admin .now { flex-wrap: wrap; }
.admin .now-number { font-size: 56px; }

.winner-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--green-soft);
  color: var(--green-text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.telegram-note {
  display: block;
  margin-top: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.telegram-note.is-error {
  color: var(--red);
}

.draw-grid { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.draw-grid li {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--sand);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.draw-grid li.is-latest { background: var(--accent); color: var(--white); }

/* Phân bố số đã tích: mỗi nhóm một thanh mảnh, độ dài = số người chơi trong nhóm. */
.mark-stats { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.mark-stats li:not(.empty) {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}
.stat-label { font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-bar { height: 10px; }
.stat-bar::before {
  content: "";
  display: block;
  width: calc(var(--share) * 100%);
  min-width: 4px;
  height: 100%;
  border-radius: 0 4px 4px 0; /* vuông ở đường gốc, bo tròn ở đầu dữ liệu */
  background: var(--accent);
}
.stat-value { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Một ván trong lịch sử (hộp thoại nằm trong shared/css/app.css): bảng của người thắng và thứ tự bốc. */
.detail-empty { margin-top: 16px; padding: 12px; border-radius: 12px; background: var(--cream); color: var(--muted); font-size: 14px; }
.mini-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: min(100%, 300px);
  margin: 16px auto 10px;
}
.mini-board span {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}
.mini-board .is-free { border-style: dashed; background: var(--sand); color: var(--accent-dark); font-size: 10px; letter-spacing: 0.06em; }
.mini-board .is-marked { border-color: var(--green); background: var(--green); color: var(--white); }
.mini-board .is-line { border-color: var(--accent-dark); background: var(--accent-dark); color: var(--white); }
.mini-board .is-missed { border-color: var(--hint); background: var(--hint-soft); }
.detail-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 13px; }
.detail-legend li { display: flex; align-items: center; gap: 6px; }
.detail-legend li::before { content: ""; width: 12px; height: 12px; border-radius: 4px; }
.detail-legend .key-line::before { background: var(--accent-dark); }
.detail-legend .key-marked::before { background: var(--green); }
.detail-legend .key-missed::before { border: 2px solid var(--hint); background: var(--hint-soft); }
.detail-draws li { width: 34px; height: 34px; font-size: 14px; }
.detail-draws li.is-ticked { background: var(--green); color: var(--white); }
.detail-draws li.is-line { background: var(--accent-dark); color: var(--white); }
.detail-draws li.is-missed { background: var(--hint-soft); box-shadow: inset 0 0 0 2px var(--hint); }
/* Dòng trống của một danh sách số, đặt sau các quy tắc ở trên (li.empty trong shared/css/app.css được nạp trước). */
.draw-grid li.empty {
  width: auto;
  height: auto;
  padding: 0;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}
#admin-primary.is-paused { background: var(--green); } /* "Tiếp tục chia số" */

#bingo-room-name { min-width: 0; overflow-wrap: anywhere; }

.winner-exclude { display: block; margin-top: 10px; }
.excluded-list { display: grid; gap: 6px; margin: 0 0 12px; padding: 0; list-style: none; font-size: 14px; }
.excluded-list li:not(.empty) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border-radius: 10px;
  background: var(--hint-soft);
}
.excluded-list li span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Popup người thắng --- */

.winner-dialog {
  width: min(calc(100% - 32px), 420px); /* % của màn hình, cũng đúng trên điện thoại ở chế độ máy tính bị phóng to */
  max-width: none;
  padding: 28px 20px 20px;
  border: 0;
  border-radius: 24px;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}
.winner-dialog::backdrop { background: rgb(43 35 30 / 0.55); }
.winner-emoji { font-size: 52px; line-height: 1; }
.winner-title { justify-content: center; margin: 12px 0 8px; font-size: 26px; }
.winner-title:focus { outline: none; } /* được focus khi mở để trình đọc màn hình đọc nó */
.winner-line { font-size: 17px; }
.winner-email { color: var(--accent); font-weight: 800; overflow-wrap: anywhere; }
.winner-meta { margin-top: 8px; color: var(--muted); font-size: 14px; }
.winner-countdown { margin-top: 14px; color: var(--muted); font-size: 13px; }

@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgb(224 165 38 / 0.6); }
  50% { box-shadow: 0 0 0 5px rgb(224 165 38 / 0); }
}
@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@keyframes line-pop {
  50% { transform: scale(1.08); }
}
@keyframes bingo-ready {
  0%, 100% { background: var(--green); box-shadow: 0 0 0 0 rgb(63 143 90 / 0.6); }
  50% { background: var(--green-text); box-shadow: 0 0 0 10px rgb(63 143 90 / 0); }
}

@keyframes ready-blink {
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .cell.is-hint, .cell.is-wrong, .cell.is-line, .btn-bingo.is-ready, .bingo-feedback { animation: none; }
}
