.hide-py small {
  display: none !important;
}

body {
  font-family: Arial, sans-serif;
  max-width: 680px;
  margin: 20px auto;
  padding: 15px;
  background: #faf5ff;
  color: #2e1065;
}

.box {
  background: #ffffff;
  padding: 20px;
  border-radius: 14px;
  box-shadow: 0 4px 15px rgba(191, 174, 227, 0.35);
  border: 1px solid #DEB5D7;
}

h2 {
  color: #6b21a8 !important;
}

.upload-box {
  border: 2px dashed #BFAEE3;
  background: #fffbeb;
  padding: 16px;
  border-radius: 10px;
  text-align: center;
  margin-bottom: 12px;
}

.status {
  font-weight: bold;
  color: #7e22ce;
  margin: 8px 0;
  text-align: center;
  font-size: 15px;
}

button {
  padding: 12px 18px;
  font-size: 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  margin: 5px 0;
  transition: 0.2s;
}

button:hover {
  filter: brightness(0.95);
}

/* Nút chính (Bắt đầu chơi / Nối thẻ): Vàng mơ #FFD273 */
.btn-red {
  background: #FFD273 !important;
  color: #2e1065 !important;
  width: 100%;
  border: 1px solid #f59e0b;
}

/* Các nút chức năng & Tab: Tím oải hương #BFAEE3 */
.btn-blue {
  background: #BFAEE3 !important;
  color: #2e1065 !important;
}

/* Nút chọn chế độ chơi: Hồng phấn #FEC5E6 */
.btn-mode {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  margin: 6px 0;
  text-align: center;
  background: #FEC5E6 !important;
  color: #2e1065 !important;
}

/* Giữ nguyên màu đỏ cho nút Xóa tất cả */
.btn-danger {
  background: #ef4444 !important;
  color: #ffffff !important;
}

.top-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: space-between;
  margin-bottom: 12px;
  border-bottom: 1px solid #DEB5D7;
  padding-bottom: 12px;
}

.top-bar button {
  flex: 1;
  min-width: 130px;
  margin: 0;
  font-size: 14px;
  padding: 10px 8px;
}

textarea {
  width: 100%;
  height: 150px;
  font-size: 14px;
  padding: 10px;
  box-sizing: border-box;
  margin-bottom: 10px;
  border: 1px solid #DEB5D7;
  border-radius: 8px;
  background: #ffffff;
  color: #2e1065;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 15px;
}

/* Thẻ từ vựng & Đáp án */
.card {
  padding: 14px 10px;
  border: 2px solid #DEB5D7;
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  background: #fff;
  font-size: 17px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 56px;
  color: #2e1065;
}

.selected {
  background: #FEE686 !important;
  border-color: #FFD273 !important;
}

.done {
  background: #BFAEE3 !important;
  border-color: #9333ea !important;
  opacity: 0.55;
  pointer-events: none;
}

/* Chế độ phóng to bảng toàn màn hình */
#tblWrap.expanded {
  position: fixed;
  inset: 0;
  z-index: 9990;
  max-height: none !important;
  background: #faf5ff;
  padding: 14px;
  margin: 0 !important;
  border-radius: 0 !important;
  display: flex;
  flex-direction: column;
}

#tblWrap.expanded .tbl-scroll {
  flex: 1;
  max-height: none !important;
  overflow-y: auto;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #DEB5D7;
}

#tblWrap .expand-tools {
  display: none;
}

#tblWrap.expanded .expand-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  align-items: center;
}

#tblWrap .col-chk {
  display: none;
}

#tblWrap.expanded .col-chk {
  display: table-cell;
  width: 32px;
  text-align: center;
}

/* Tối ưu giao diện siêu gọn cho màn hình điện thoại */
/* Tự động co giãn vừa khít 100% chiều cao của mọi loại điện thoại */
@media (max-width: 600px) {
  @media (max-width: 600px) {

    /* Cho phép vuốt lên xuống tự do khi đang ở màn hình nhập từ vựng (#s1) hoặc Menu (#sMenu) */
    html:has(#s1:not([style*="display: none"]):not([style*="display:none"])),
    body:has(#s1:not([style*="display: none"]):not([style*="display:none"])),
    html:has(#sMenu:not([style*="display: none"]):not([style*="display:none"])),
    body:has(#sMenu:not([style*="display: none"]):not([style*="display:none"])) {
      overflow-y: auto !important;
      height: auto !important;
      touch-action: pan-y !important;
    }
  }

  body {
    height: 100dvh !important;
    /* Khóa chiều cao bằng đúng màn hình điện thoại */
    margin: 0 !important;
    padding: 6px !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    /* Chống cuộn trang ngoài ý muốn */
  }

  /* 1. Thanh Xu và Năng lượng cố định kích thước gọn ở trên cùng */
  #globalCurrencyBar {
    flex-shrink: 0 !important;
    margin-bottom: 4px !important;
    gap: 6px !important;
    font-size: 12px !important;
  }

  #globalCurrencyBar span {
    padding: 2px 10px !important;
  }

  /* 2. Khung game chính (#sRest) tự động chiếm toàn bộ phần chiều cao còn lại */
  #sRest {
    flex: 1 !important;
    min-height: 0 !important;
    display: flex;
    /* Lưu ý: JS sẽ bật/tắt block/none, CSS bên dưới sẽ lo phần layout */
    flex-direction: column !important;
    padding: 8px !important;
  }

  /* Đảm bảo khi JS set display:block thì vẫn xếp dọc linh hoạt */
  #sRest[style*="display: block"],
  #sRest[style*="display:block"] {
    display: flex !important;
  }

  /* Thanh điều hướng & chọn Tầng giữ nguyên chiều cao vừa đủ */
  #sRest>div:nth-child(1),
  #sRest>div:nth-child(2) {
    flex-shrink: 0 !important;
    margin-bottom: 6px !important;
  }

  #sRest>div:first-child button,
  #sRest #restModeSelect {
    padding: 5px 8px !important;
    font-size: 12.5px !important;
  }

  #floorTabsBar {
    width: 100%;
    justify-content: space-between;
  }

  #floorTabsBar button {
    flex: 1;
    padding: 5px 6px !important;
    font-size: 12px !important;
    white-space: nowrap !important;
  }

  /* 3. KHUNG QUÁN ĂN TỰ ĐỘNG GIÃN NỞ THEO CHIỀU DÀI TỪNG ĐIỆN THOẠI */
  #restViewport {
    flex: 1 !important;
    /* Tự động phình to hoặc thu nhỏ để lấp đầy màn hình */
    height: auto !important;
    min-height: 180px !important;
    margin-bottom: 8px !important;
  }

  /* Điều chỉnh quầy & khách hàng bên trong cho cân đối */
  #restCounterBar {
    height: 58px !important;
    padding: 0 10px !important;
  }

  #actorCustomer {
    bottom: 50px !important;
  }

  #actorCustSprite {
    width: 86px !important;
    height: 88px !important;
  }

  #actorCustBubble {
    padding: 4px 12px !important;
    font-size: 14.5px !important;
  }

  /* 4. Cụm 4 nút đáp án luôn nằm cố định gọn gàng ở phía dưới */
  #restDishesGrid {
    flex-shrink: 0 !important;
    gap: 8px !important;
    margin-bottom: 8px !important;
  }

  #restDishesGrid button {
    min-height: 52px !important;
    padding: 6px 8px !important;
    flex-direction: row !important;
    gap: 6px !important;
  }

  #restDishesGrid button span:first-child {
    font-size: 20px !important;
    margin-bottom: 0 !important;
  }

  #restDishesGrid button span:last-child {
    font-size: 15.5px !important;
  }

  /* 5. Thanh nút Trang Trí & Quét Dọn luôn nằm sát đáy màn hình */
  #sRest>div:last-child {
    flex-shrink: 0 !important;
  }

  #sRest>div:last-child button {
    padding: 9px !important;
    font-size: 13px !important;
  }

  /* Tự động giãn khung Menu và Game Luyện Phản Xạ Pinyin vừa khít 100% màn hình điện thoại */
  #sPinyinMenu[style*="display: block"],
  #sPinyinMenu[style*="display:block"],
  #sPinyinGame[style*="display: block"],
  #sPinyinGame[style*="display:block"] {
    flex: 1 !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 12px !important;
  }

  /* Giữ thanh tiêu đề trên cùng 1 hàng gọn gàng, không bị rớt chữ */
  #sPinyinMenu>div:first-child button,
  #sPinyinGame>div:first-child button {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 6px 10px !important;
    font-size: 13px !important;
  }

  #sPinyinMenu>div:first-child h2,
  #sPinyinGame>div:first-child h2 {
    font-size: 15px !important;
    white-space: nowrap !important;
  }

  /* 4 nút chọn trò chơi tự động giãn đều để lấp đầy chiều cao màn hình */
  #sPinyinMenu>div:last-child {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    gap: 10px !important;
  }

  #sPinyinMenu>div:last-child .btn-mode {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    margin: 0 !important;
    padding: 12px 14px !important;
  }

  /* Giữ nhãn "Đúng: 0" nằm gọn 1 dòng như một huy hiệu nhỏ */
  #pyGameScore {
    white-space: nowrap !important;
    background: #dcfce7 !important;
    border: 1.5px solid #16a34a !important;
    padding: 4px 10px !important;
    border-radius: 14px !important;
    font-size: 13px !important;
    flex-shrink: 0 !important;
  }

  /* Khu vực chơi game Pinyin căn giữa cân đối, không bị kéo dãn quá mức */
  #pyGameBody {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-evenly !important;
    align-items: center !important;
    min-height: 0 !important;
    padding: 4px 0 8px !important;
  }

  /* Nút "Nghe lại" giữ dáng viên thuốc gọn gàng, nổi khối 3D nhẹ */
  #pyGameBody>button {
    width: auto !important;
    min-width: 180px !important;
    align-self: center !important;
    box-shadow: 0 4px 0 #d97706, 0 6px 12px rgba(245, 158, 11, 0.25) !important;
    margin: 4px 0 10px !important;
  }

  /* Lưới 4 thẻ đáp án có chiều cao vừa vặn, cân đối */
  #pyOptGrid,
  #pyToneGrid,
  #pyGameBody>div[style*="grid-template-columns"] {
    width: 100% !important;
    flex: 0 1 auto !important;
    gap: 12px !important;
    margin-top: 4px !important;
  }

  #pyOptGrid .card,
  #pyToneGrid .card,
  #pyMatchLeft .card,
  #pyMatchRight .card {
    min-height: 115px !important;
    height: auto !important;
    border-radius: 16px !important;
    border: 2px solid #DEB5D7 !important;
    box-shadow: 0 4px 0 #DEB5D7, 0 6px 12px rgba(107, 33, 168, 0.08) !important;
    transition: transform 0.12s ease, box-shadow 0.12s ease !important;
  }

  #pyOptGrid .card:active,
  #pyToneGrid .card:active,
  #pyMatchLeft .card:active,
  #pyMatchRight .card:active {
    transform: translateY(3px) !important;
    box-shadow: 0 1px 0 #DEB5D7 !important;
  }

  #pyOptGrid .card strong,
  #pyMatchRight .card strong {
    font-size: 32px !important;
  }


  /* Mở lại cuộn trang bình thường cho màn hình Nạp từ vựng (#s1) và Menu (#sMenu) */
  body:has(#s1[style*="display: block"]),
  body:has(#sMenu[style*="display: block"]),
  body:has(#s2[style*="display: block"]) {
    height: auto !important;
    overflow-y: auto !important;
    display: block !important;
  }

  /* Ép phần trên (#pyGameBody) phóng to nút Nghe lại cân đối với 4 thẻ đáp án */
  #pyGameBody {
    justify-content: stretch !important;
    gap: 12px !important;
  }

  #pyGameBody>p {
    flex-shrink: 0 !important;
    font-size: 16px !important;
    margin: 4px 0 0 !important;
  }

  #pyGameBody>button {
    flex: 1 !important;
    width: 100% !important;
    min-height: 75px !important;
    max-height: 115px !important;
    font-size: 24px !important;
    border-radius: 18px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin: 0 !important;
  }

  #pyOptGrid,
  #pyToneGrid,
  #pyGameBody>div[style*="grid-template-columns"] {
    flex: 1.5 !important;
    width: 100% !important;
    margin-top: 0 !important;
  }

}

/* Đồng bộ thanh chọn phần học theo bảng màu Vàng Mơ & Tím Oải Hương */
#presetSubSelect {
  background: linear-gradient(180deg, #FEE686 0%, #FFD273 100%) !important;
  color: #2e1065 !important;
  border: 2px solid #BFAEE3 !important;
  border-radius: 10px !important;
  padding: 10px 12px !important;
  font-weight: bold !important;
  box-shadow: 0 2px 6px rgba(191, 174, 227, 0.35);
  cursor: pointer;
  outline: none;
}

#presetSubSelect:focus {
  border-color: #9333ea !important;
}

/* Màu nền các mục bên trong danh sách xổ xuống */
#presetSubSelect option {
  background-color: #faf5ff !important;
  color: #2e1065 !important;
  font-weight: bold;
  padding: 8px;
}

/* Đổi màu vệt chọn từ xanh dương mặc định sang Vàng Mơ (#FFD273) */
#presetSubSelect option:checked,
#presetSubSelect option:hover {
  background: #FFD273 linear-gradient(0deg, #FFD273 0%, #FFD273 100%) !important;
  color: #2e1065 !important;
}

/* Phóng to phần đầu của trang Menu Luyện Phản Xạ Pinyin (#sPinyinMenu) */
#sPinyinMenu>div:first-child {
  padding-bottom: 14px !important;
  margin-bottom: 16px !important;
}

#sPinyinMenu>div:first-child button {
  padding: 10px 18px !important;
  font-size: 16px !important;
  border-radius: 12px !important;
}

#sPinyinMenu>div:first-child h2 {
  font-size: 22px !important;
  font-weight: 800 !important;
}

#pyMenuInfo {
  font-size: 16.5px !important;
  padding: 14px 16px !important;
  margin-bottom: 16px !important;
  border-width: 2px !important;
  border-radius: 14px !important;
  line-height: 1.5 !important;
}

/* Phóng to đồng bộ phần đầu của trang chơi game Pinyin (#sPinyinGame) */
#sPinyinGame>div:first-child {
  padding-bottom: 14px !important;
  margin-bottom: 14px !important;
}

#sPinyinGame>div:first-child button {
  padding: 10px 18px !important;
  font-size: 16px !important;
  border-radius: 12px !important;
}

#sPinyinGame>div:first-child h2 {
  font-size: 21px !important;
  font-weight: 800 !important;
}

#pyGameScore {
  font-size: 16px !important;
  padding: 6px 14px !important;
  border-radius: 14px !important;
}

#btnTogglePyRead {
  font-size: 16px !important;
  padding: 10px 22px !important;
  border-radius: 24px !important;
}

#pyReadDisplay {
  font-size: 16.5px !important;
  padding: 8px 16px !important;
  border-radius: 14px !important;
}

#pyGameBody>p {
  font-size: 19px !important;
  margin: 6px 0 10px !important;
}

/* Đưa tên game Pinyin xuống dòng dưới để hiển thị đầy đủ 100%, không bị cắt dấu ... */
#sPinyinGame>div:first-child {
  flex-wrap: wrap !important;
  row-gap: 10px !important;
}

#sPinyinGame>div:first-child button {
  order: 1 !important;
}

#pyGameScore {
  order: 2 !important;
}

#sPinyinGame>div:first-child h2 {
  order: 3 !important;
  flex-basis: 100% !important;
  width: 100% !important;
  text-align: center !important;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  margin-top: 2px !important;
}

/* 1. Đẩy thanh "Hiện âm máy đọc" thấp xuống, tạo khoảng thở với tiêu đề phía trên */
#sPinyinGame>div:nth-child(2) {
  margin-top: 8px !important;
  margin-bottom: 16px !important;
}

/* 2. Căn chỉnh khu vực chơi game thoáng đãng, không dính sát nhau */
#pyGameBody {
  justify-content: space-evenly !important;
  align-items: center !important;
  gap: 14px !important;
  padding: 4px 0 12px !important;
}

#pyGameBody>p {
  font-size: 15.5px !important;
  margin: 0 0 2px !important;
}

/* 3. Thu gọn nút "Nghe lại" cho nhỏ nhắn, thanh thoát */
#pyGameBody>button {
  flex: 0 0 auto !important;
  width: 60% !important;
  max-width: 220px !important;
  min-height: 46px !important;
  max-height: 52px !important;
  font-size: 17.5px !important;
  border-radius: 26px !important;
  margin: 4px 0 !important;
}

/* 4. Thu thấp chiều cao các thẻ đáp án và tăng khoảng cách giữa các ô */
#pyOptGrid,
#pyToneGrid,
#pyGameBody>div[style*="grid-template-columns"] {
  flex: 0 1 auto !important;
  width: 94% !important;
  gap: 14px !important;
  margin-top: 6px !important;
}

#pyOptGrid .card,
#pyToneGrid .card,
#pyMatchLeft .card,
#pyMatchRight .card {
  min-height: 120px !important;
  max-height: 82px !important;
  height: auto !important;
  padding: 8px !important;
  border-radius: 14px !important;
}

#pyOptGrid .card strong,
#pyMatchRight .card strong {
  font-size: 25px !important;
}

/* Tự động giãn trang Kho Từ Vựng / Học Pinyin (#sPreset) vừa khít 100% màn hình điện thoại */
#sPreset[style*="display: block"],
#sPreset[style*="display:block"] {
  flex: 1 !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 12px !important;
}


/* Màn hình 2: Danh sách từ vựng / Pinyin tự động kéo dài lấp đầy phần trống */
#presetStep2[style*="display: block"],
#presetStep2[style*="display:block"] {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
}

#presetStep2>div:first-child,
#customSubDropdown,
#presetStep2>div:last-child {
  flex-shrink: 0 !important;
}

/* Khung danh sách #presetWordList tự động co giãn theo chiều cao màn hình điện thoại */
#presetWordList {
  flex: 1 !important;
  height: auto !important;
  min-height: 150px !important;
  margin-bottom: 10px !important;
}

/* ==========================================================================
       TỰ ĐỘNG CO GIÃN VỪA KHÍT MỌI MÀN HÌNH CHO BẮT NHỊP THANH ĐIỆU & GHÉP CẶP
       ========================================================================== */
@media (max-width: 600px) {

  /* 1. Khóa khung game vừa khít chiều cao màn hình điện thoại hiện tại */
  #sPinyinGame[style*="display: block"],
  #sPinyinGame[style*="display:block"] {
    height: calc(100dvh - 54px) !important;
    max-height: calc(100dvh - 54px) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  /* 2. Khu vực nội dung chính tự động nhận toàn bộ phần không gian còn lại */
  #pyGameBody {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    gap: clamp(6px, 1.5vh, 12px) !important;
    overflow: hidden !important;
    padding: 4px 0 !important;
  }

  #pyGameBody>p,
  #pyGameBody>button,
  #toneRevealHint {
    flex-shrink: 0 !important;
  }

  /* Thu gọn nút Nghe lại theo tỷ lệ màn hình (vh) */
  #pyGameBody>button {
    min-height: clamp(38px, 6vh, 48px) !important;
    max-height: 50px !important;
    font-size: clamp(15px, 2.2vh, 18px) !important;
    padding: 6px 18px !important;
  }

  /* 3. CHẾ ĐỘ BẮT NHỊP THANH ĐIỆU (Chia đều 3 hàng tự động co giãn) */
  #pyToneGrid {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    width: 96% !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-template-rows: repeat(3, minmax(0, 1fr)) !important;
    gap: clamp(6px, 1.2vh, 10px) !important;
    margin-top: 0 !important;
  }

  #pyToneGrid .card {
    min-height: 0 !important;
    max-height: none !important;
    height: 100% !important;
    padding: 4px 6px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
  }

  #pyToneGrid .card strong {
    font-size: clamp(14px, 2.1vh, 17px) !important;
    line-height: 1.2 !important;
  }

  #pyToneGrid .card small {
    font-size: clamp(10.5px, 1.5vh, 12px) !important;
    line-height: 1.15 !important;
    margin-top: 2px !important;
  }

  /* 4. CHẾ ĐỘ GHÉP CẶP ÂM THANH (Chia đều 4 hàng tự động co giãn) */
  #pyGameBody>div:has(#pyMatchLeft) {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    width: 96% !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: clamp(8px, 1.5vh, 12px) !important;
    margin-top: 0 !important;
  }

  #pyMatchLeft,
  #pyMatchRight {
    height: 100% !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: clamp(6px, 1.2vh, 10px) !important;
  }

  #pyMatchLeft .card,
  #pyMatchRight .card {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    padding: 4px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  #pyMatchLeft .card span {
    font-size: clamp(16px, 2.4vh, 21px) !important;
  }

  #pyMatchRight .card strong {
    font-size: clamp(19px, 2.8vh, 25px) !important;
  }
}

/* ==========================================================================
       ĐỒNG BỘ GIAO DIỆN ĐẸP MẮT CHO "BẮT NHỊP THANH ĐIỆU" GIỐNG NGHE ÂM CHỌN NHANH
       ========================================================================== */
@media (max-width: 600px) {

  /* 1. Tạo khoảng thở đều đặn giữa câu hỏi, nút Nghe lại và cụm thẻ bên dưới */
  #pyGameBody {
    justify-content: space-evenly !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 4px 0 10px !important;
  }

  /* Ẩn dòng gợi ý khi chưa bấm đáp án để không chiếm chỗ trống */
  #toneRevealHint:empty {
    display: none !important;
  }

  #toneRevealHint {
    margin: 0 !important;
    min-height: 0 !important;
    font-size: 13.5px !important;
  }

  /* 2. Giữ nút "🔊 Nghe lại" dáng viên thuốc nổi khối nằm thoáng ở giữa */
  #pyGameBody>button {
    flex: 0 0 auto !important;
    width: 58% !important;
    max-width: 220px !important;
    min-height: 46px !important;
    max-height: 50px !important;
    font-size: 17.5px !important;
    border-radius: 25px !important;
    margin: 6px 0 !important;
  }

  /* 3. Khung lưới 5 thẻ thanh điệu nằm gọn đẹp ở nửa dưới màn hình */
  #pyToneGrid {
    flex: 0 1 auto !important;
    width: 94% !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-template-rows: auto !important;
    gap: 10px !important;
    margin-top: 4px !important;
  }

  /* 4. Thiết kế từng thẻ thanh điệu bo tròn, viền tím nhạt & đổ bóng đồng bộ */
  #pyToneGrid .card {
    min-height: 62px !important;
    max-height: 74px !important;
    height: auto !important;
    padding: 8px 6px !important;
    border-radius: 16px !important;
    background: #ffffff !important;
    border: 2px solid #DEB5D7 !important;
    box-shadow: 0 4px 0 #DEB5D7, 0 4px 10px rgba(107, 33, 168, 0.06) !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
  }

  #pyToneGrid .card strong {
    font-size: 16px !important;
    color: #6b21a8 !important;
    line-height: 1.25 !important;
  }

  #pyToneGrid .card small {
    font-size: 11.5px !important;
    color: #64748b !important;
    margin-top: 2px !important;
    line-height: 1.2 !important;
  }
}

/* ==========================================================================
       TỰ ĐỘNG CO CHIỀU CAO THẺ ĐÁP ÁN KHI BẬT "HIỆN ÂM MÁY ĐỌC"
       ========================================================================== */
@media (max-width: 600px) {

  /* Khi thẻ #pyReadDisplay đang hiển thị -> Tự động thu gọn khoảng cách và chiều cao các thẻ */
  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyGameBody {
    gap: 6px !important;
    padding: 2px 0 6px !important;
  }

  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyGameBody>button {
    min-height: 40px !important;
    max-height: 44px !important;
    font-size: 16px !important;
    margin: 2px 0 !important;
  }

  /* Co gọn thẻ của Chế độ 1 (Nghe âm chọn nhanh) */
  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyOptGrid {
    gap: 10px !important;
  }

  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyOptGrid .card {
    min-height: 72px !important;
    max-height: 86px !important;
    padding: 6px !important;
  }

  /* Co gọn thẻ của Chế độ 2 (Bắt nhịp thanh điệu - 5 ô) */
  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyToneGrid {
    gap: 8px !important;
  }

  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyToneGrid .card {
    min-height: 50px !important;
    max-height: 60px !important;
    padding: 5px 6px !important;
  }

  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyToneGrid .card strong {
    font-size: 15px !important;
  }

  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyToneGrid .card small {
    font-size: 11px !important;
  }

  /* Co gọn khung chữ của Chế độ 3 (Phản xạ Đúng / Sai) */
  #sPinyinGame:has(#pyReadDisplay:not([style*="display: none"]):not([style*="display:none"])) #pyGameBody>div[style*="font-size:38px"] {
    padding: 16px 10px !important;
    font-size: 32px !important;
    margin-bottom: 10px !important;
  }
}

.sg-tile {
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px 14px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: transform 0.15s, border-color 0.15s;
  min-width: 75px;
}

.sg-tile:hover {
  transform: translateY(-2px);
  border-color: #9333ea;
}

.sg-tile .t-vi {
  font-size: 12px;
  color: #64748b;
  display: block;
  margin-bottom: 2px;
}

.sg-tile .t-zh {
  font-size: 20px;
  font-weight: bold;
  color: #0f172a;
  display: block;
}

.sg-tile .t-py {
  font-size: 12px;
  color: #7e22ce;
  display: block;
  margin-top: 2px;
}

.sg-tile.in-answer {
  background: #f3e8ff;
  border-color: #9333ea;
}

/* Ẩn nút Quay lại cũ trong màn hình Chọn Trò Chơi và nút Menu trong Ghép Câu Tăng Cấp */
#sMenu>button:first-child,
#stepSentenceGame button[onclick="closeStepSentenceGame()"] {
  display: none !important;
}

/* 1. Khóa khung nhìn cố định, tràn viền cả vùng tai thỏ và thanh vuốt đáy */
html,
body {
  width: 100% !important;
  max-width: 100vw !important;
  height: 100dvh !important;
  margin: 0 !important;
  padding: env(safe-area-inset-top, 6px) 0 env(safe-area-inset-bottom, 6px) 0 !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  display: flex !important;
  flex-direction: column !important;
}

/* 2. Khung bao ngoài: Bung tràn gần sát mép màn hình (chỉ chừa viền mỏng 6px cho đẹp) */
.box,
#sPreset,
#structLearnScreen,
#sPinyinMenu,
#sPinyinGame,
#sMini,
#s2,
#sFish,
#stepSentenceGame {
  width: calc(100% - 12px) !important;
  max-width: 100% !important;
  flex: 1 1 auto !important;
  height: auto !important;
  max-height: none !important;
  margin: 4px auto 6px !important;
  padding: 12px 14px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch !important;
  box-sizing: border-box !important;
}

/* Trên iPad & Máy tính: Giữ khung cân đối giữa màn hình */
@media (min-width: 601px) {

  .box,
  #sPreset,
  #structLearnScreen,
  #sPinyinMenu,
  #sPinyinGame,
  #sMini,
  #s2,
  #sFish,
  #stepSentenceGame {
    width: calc(100% - 32px) !important;
    max-width: 960px !important;
    margin: 12px auto 16px !important;
    padding: 16px 22px 18px !important;
  }
}








/* Khóa không cho hộp Lưu ý bị kéo dãn hay bóp méo */
#slGrammarTip {
  flex: 0 0 auto !important;
  height: auto !important;
  padding: 7px 12px !important;
  font-size: 13px !important;
  margin: 0 !important;
}

#slTargetMeaning {
  flex: 0 0 auto !important;
  font-size: clamp(17px, 2.3dvh, 21px) !important;
  margin: 0 !important;
}

/* Giữ cả ô nét đứt xếp chữ lẫn ô chứa từ bên dưới luôn đủ cao, KHÔNG bao giờ bị ép dẹt */
#slAnswerZone,
#slBankZone,
#structLearnScreen div[style*="dashed"],
#stepSentenceGame div[style*="dashed"] {
  flex: 0 0 auto !important;
  min-height: clamp(78px, 12dvh, 108px) !important;
  height: auto !important;
  padding: 10px !important;
  gap: 8px !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

#slAnswerZone button,
#slBankZone button {
  padding: 5px 9px !important;
  min-width: 60px !important;
  margin: 0 !important;
}

#slCheckBtn {
  flex: 0 0 auto !important;
  min-height: 44px !important;
  padding: 10px 16px !important;
  font-size: 16px !important;
  margin: 0 !important;
}

/* 4. Bảng chọn từ tự kéo giãn vừa khít mọi màn hình để cụm nút dưới nằm sát viền vàng */
#sPreset[style*="display: block"],
#sPreset[style*="display:block"],
#sPreset[style*="display: flex"],
#sPreset[style*="display:flex"] {
  display: flex !important;
  flex-direction: column !important;
}

#presetStep2[style*="display: block"],
#presetStep2[style*="display:block"] {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
}

#presetWordList {
  flex: 1 1 auto !important;
  height: auto !important;
  min-height: 120px !important;
  max-height: none !important;
  overflow-y: auto !important;
}




/* === 1. NỀN PASTEL TRÀN VIỀN 100%, SÁT MÉP TRÊN & MÉP DƯỚI === */
html,
body {
  background: linear-gradient(135deg, #87d1e4 0%, #c6e6da 28%, #fdf9d2 58%, #f8d4cf 82%, #f4a4b8 100%) !important;
  background-attachment: fixed !important;
  padding: env(safe-area-inset-top, 2px) 6px env(safe-area-inset-bottom, 4px) 6px !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

/* Thu gọn thanh Xu & Năng lượng sát lên mép trên */
#globalCurrencyBar {
  margin-top: 2px !important;
  margin-bottom: 6px !important;
  flex: 0 0 auto !important;
}

/* === 2. ÉP TẤT CẢ MÀN HÌNH ĐANG MỞ GIÃN KÍN 100% CHIỀU CAO MÀN HÌNH === */
.box:not([style*="display: none"]):not([style*="display:none"]),
#s1:not([style*="display: none"]):not([style*="display:none"]),
#sFish:not([style*="display: none"]):not([style*="display:none"]),
#s2:not([style*="display: none"]):not([style*="display:none"]),
#sMini:not([style*="display: none"]):not([style*="display:none"]),
#sPreset:not([style*="display: none"]):not([style*="display:none"]),
#structLearnScreen:not([style*="display: none"]):not([style*="display:none"]),
#sPinyinMenu:not([style*="display: none"]):not([style*="display:none"]),
#sPinyinGame:not([style*="display: none"]):not([style*="display:none"]),
#stepSentenceGame:not([style*="display: none"]):not([style*="display:none"]) {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 0 4px 0 !important;
  overflow-y: auto !important;
  box-sizing: border-box !important;
}


/* === 3. TRANG CHỦ (#s1): BẢNG TỪ VỰNG GIÃN VỪA KHÍT MỌI MÀN HÌNH === */
#s1 > div:not(#tblWrap),
#s1 > button {
  flex: 0 0 auto !important;
}

#s1 #tblWrap {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  height: 0 !important;
  min-height: 120px !important;
  overflow: hidden !important;
}

#s1 #tblWrap > div:not(.tbl-scroll) {
  flex: 0 0 auto !important;
}

#s1 #tblWrap .tbl-scroll {
  flex: 1 1 auto !important;
  height: 0 !important;
  max-height: none !important;
  overflow-y: auto !important;
}

/* === 4. CÂU CÁ (#sFish): HỒ NƯỚC TỰ GIÃN HẾT CỠ, KHÔNG CHE KHUẤT CÁ === */
#sFish > div,
#sFish > p {
  flex: 0 0 auto !important;
}

#sFish div:has(> canvas),
#sFish #fishPond,
#sFish .fish-area {
  flex: 1 1 auto !important;
  height: 100% !important;
  min-height: 220px !important;
  max-height: none !important;
  position: relative !important;
  overflow: hidden !important;
}

#sFish canvas {
  width: 100% !important;
  height: 100% !important;
  display: block !important;
}


html,
body {
  background: linear-gradient(135deg, #87d1e4 0%, #c6e6da 28%, #fdf9d2 58%, #f8d4cf 82%, #f4a4b8 100%) !important;
  background-attachment: fixed !important;
}