/* Trò chơi trí tuệ (/cong-cu/tri-tue). Tệp nạp ở mọi trang → mọi lớp có tiền tố ttr-; id của mã gốc Tatham (#puzzle, #dlgform…) chỉ viết dưới .ttr-choi. */
.chinh:has(> .ttr) { max-width: 1240px; }
.ttr-ve { margin: 0 0 4px; font-size: .875rem; }
.ttr-ve a { text-decoration: none; font-weight: 600; }
.ttr-ve a::before { content: "‹ "; }
.ttr-dau { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
.ttr-dau h1 { margin: 0; }
.ttr-dau .phu { margin: 2px 0 0; max-width: 48rem; }
.ttr-nguon { margin-top: 18px; }

/* Danh mục */
.ttr-nhom { font-size: 1.05rem; margin: 18px 0 8px; color: var(--c-dam); }
.ttr-ds { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
a.ttr-o { display: flex; flex-direction: column; gap: 4px; margin: 0; text-decoration: none; color: var(--chu); transition: border-color .15s, box-shadow .15s; }
.ttr-o:hover { border-color: var(--c-vien); box-shadow: var(--bong); }
.ttr-o__h { font-weight: 700; font-size: 1.08rem; color: var(--c-dam); }
.ttr-o__m { color: var(--phu); font-size: .9375rem; }
.ttr-o__kl { font-size: .8125rem; color: var(--nhan-dam); font-weight: 600; }
.ttr-o__kl:empty { display: none; }

/* Khung chơi */
.ttr-bo { display: grid; gap: 16px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 1000px) { .ttr-bo { grid-template-columns: minmax(0, 1fr) 330px; } }
.ttr-san { background: var(--the); border: 1px solid var(--vien); border-radius: var(--r); padding: 12px; min-width: 0; }
.ttr-cong-cu { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; margin-bottom: 8px; }
.ttr-muc { margin: 0; min-width: 200px; flex: 1 1 200px; max-width: 340px; }
.ttr-muc select { width: 100%; }
.ttr-nut { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.ttr-nut .nut:disabled { opacity: .45; cursor: default; }
.ttr-trang-thai { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-height: 34px; margin-bottom: 6px; font-size: .9375rem; }
.ttr-gio { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; color: var(--c-dam); min-width: 4.2em; }
.ttr-tt { color: var(--phu); flex: 1 1 auto; min-width: 0; }
.ttr-dd { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; padding: 6px 12px; border: 1px solid var(--vien); border-radius: 999px; cursor: pointer; user-select: none; }
.ttr-dd:has(input:checked) { background: var(--nhan-nhat); border-color: var(--nhan); }
.ttr-dd input { width: 18px; height: 18px; margin: 0; }
.ttr-khung { width: 100%; height: min(70vh, 700px); display: flex; justify-content: center; align-items: center; min-width: 0; }
@media (max-width: 640px) { .ttr-khung { height: min(calc(100vw - 30px), 62vh); } .ttr-san { padding: 8px; }
  .ttr-nut .nut { min-height: 40px; padding: 6px 11px; font-size: .875rem; } .ttr-muc { max-width: none; } }
.ttr-choi #puzzlecanvas { display: block; max-width: 100%; max-height: 100%; touch-action: none; font-family: var(--font); background: #fff; }
.ttr-choi #puzzlecanvas:focus { outline: none; }
.ttr-choi #puzzlecanvas:focus-visible { outline: 3px solid var(--c-vien); }
.ttr-xin-loi { margin: 12px 0; }
.ttr-xong { margin: 10px 0 0; padding: 10px 14px; border-radius: var(--r-nho); background: var(--xanh-la-nhat); color: var(--xanh-la); font-weight: 700; text-align: center; }
.ttr-ban-so { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; }
.ttr-so { min-width: 48px; min-height: 48px; border-radius: 10px; border: 1px solid var(--c-vien); background: var(--c-nhat); color: var(--c-dam);
  font: inherit; font-size: 1.25rem; font-weight: 700; cursor: pointer; }
.ttr-so:hover { background: var(--c-vien); }
.ttr-so--xoa { font-size: 1rem; padding: 0 14px; background: var(--the); }
.ttr-ben { display: grid; gap: 12px; }
.ttr-ben .the { margin: 0; }
.ttr-ben h2 { font-size: 1.02rem; margin: 0 0 6px; color: var(--c-dam); }
.ttr-luat ul { margin: 0 0 12px; padding-left: 20px; }
.ttr-luat li { margin-bottom: 5px; font-size: .9375rem; }
.ttr-bang-kl { width: 100%; border-collapse: collapse; font-size: .9375rem; margin-bottom: 6px; }
.ttr-bang-kl th, .ttr-bang-kl td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--vien); }
.ttr-bang-kl td:nth-child(2), .ttr-bang-kl td:nth-child(3) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ttr-lk { display: flex; gap: 6px; }
.ttr-lk input { flex: 1; min-width: 0; min-height: 40px; padding: 6px 10px; border: 1px solid var(--vien); border-radius: var(--r-nho); font: inherit; font-size: .875rem; }

/* Chiếu lên lớp (toàn màn hình) */
.ttr-san--chieu { border-radius: 0; border: 0; padding: 18px 24px; display: flex; flex-direction: column; overflow: auto; }
.ttr-san--chieu .ttr-khung { flex: 1 1 auto; height: auto; min-height: 0; }
.ttr-san--chieu .ttr-puzzle { flex: 1 1 auto; display: flex !important; flex-direction: column; min-height: 0; }
.ttr-san--chieu .ttr-gio { font-size: 1.6rem; }
.ttr-san--chieu .ttr-tt { font-size: 1.1rem; }

/* Hộp thoại Tùy chỉnh của mã gốc (gắn vào body) */
body:has(.ttr-choi) #dlgdimmer { position: fixed; inset: 0; background: rgba(9, 25, 50, .45); z-index: 99; }
body:has(.ttr-choi) #dlgform { position: fixed; z-index: 100; top: 10vh; left: 50%; transform: translateX(-50%); width: min(92vw, 460px); max-height: 80vh; overflow: auto;
  background: var(--the); color: var(--chu); border-radius: var(--r); box-shadow: 0 12px 40px rgba(0,0,0,.25); padding: 18px 20px; }
body:has(.ttr-choi) #dlgform h2 { margin: 0 0 12px; font-size: 1.15rem; }
body:has(.ttr-choi) #dlgform label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; margin-bottom: 4px; }
body:has(.ttr-choi) #dlgform label:has(input[type="checkbox"]) { flex-direction: row; align-items: center; gap: 8px; }
body:has(.ttr-choi) #dlgform input[type="text"], body:has(.ttr-choi) #dlgform select { min-height: 42px; padding: 6px 10px; border: 1px solid var(--vien); border-radius: var(--r-nho); font: inherit; font-weight: 400; }
body:has(.ttr-choi) #dlgform input[type="button"] { min-height: 44px; padding: 8px 20px; margin: 10px 8px 0 0; border-radius: 999px; border: 1px solid var(--c-dam);
  background: var(--c-dam); color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
body:has(.ttr-choi) #dlgform input[type="button"] + input[type="button"] { background: var(--the); color: var(--c-dam); }
.ttr-xoa { margin: 18px 0 0; }

/* 2048 — các lớp game-*, grid-*, tile-* là lớp của mã gốc (html_actuator.js), chỉ viết dưới .ttr-2048 */
.ttr-diem { position: relative; display: flex; flex-direction: column; align-items: center; min-width: 96px; padding: 6px 14px; border-radius: var(--r-nho);
  background: var(--c-dam); color: #fff; line-height: 1.25; }
.ttr-diem span { font-size: .75rem; opacity: .9; }
.ttr-diem b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.ttr-2048 .ttr-cong-cu { align-items: stretch; }
.ttr-2048 .ttr-nut { align-items: center; margin-left: auto; }
.ttr-2048 .score-addition { position: absolute; right: 8px; top: 18px; color: var(--nhan); font-weight: 700; pointer-events: none; animation: ttr-bay .6s ease-in both; }
@keyframes ttr-bay { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-34px); } }
.ttr-2048 .game-container { position: relative; width: min(100%, 500px, 62vh); aspect-ratio: 1; margin: 10px auto 4px; background: #bbada0; border-radius: 10px;
  touch-action: none; user-select: none; -webkit-user-select: none; container-type: inline-size; }
.ttr-2048 .game-container:focus { outline: none; }
.ttr-2048 .game-container:focus-visible { outline: 3px solid var(--c-vien); }
.ttr-2048 .grid-container { position: absolute; left: 3%; top: 3%; width: 94%; height: 94%; display: flex; flex-direction: column; justify-content: space-between; }
.ttr-2048 .grid-row { display: flex; justify-content: space-between; height: 22.606%; }
.ttr-2048 .grid-cell { width: 22.606%; height: 100%; border-radius: 6px; background: rgba(238, 228, 218, .35); }
.ttr-2048 .tile-container { position: absolute; inset: 0; }
.ttr-2048 .tile { position: absolute; width: 21.25%; height: 21.25%; transition: left .1s ease-in-out, top .1s ease-in-out; }
.ttr-2048 .tile-position-1-1 { left: 3%; top: 3%; } .ttr-2048 .tile-position-1-2 { left: 3%; top: 27.25%; }
.ttr-2048 .tile-position-1-3 { left: 3%; top: 51.5%; } .ttr-2048 .tile-position-1-4 { left: 3%; top: 75.75%; }
.ttr-2048 .tile-position-2-1 { left: 27.25%; top: 3%; } .ttr-2048 .tile-position-2-2 { left: 27.25%; top: 27.25%; }
.ttr-2048 .tile-position-2-3 { left: 27.25%; top: 51.5%; } .ttr-2048 .tile-position-2-4 { left: 27.25%; top: 75.75%; }
.ttr-2048 .tile-position-3-1 { left: 51.5%; top: 3%; } .ttr-2048 .tile-position-3-2 { left: 51.5%; top: 27.25%; }
.ttr-2048 .tile-position-3-3 { left: 51.5%; top: 51.5%; } .ttr-2048 .tile-position-3-4 { left: 51.5%; top: 75.75%; }
.ttr-2048 .tile-position-4-1 { left: 75.75%; top: 3%; } .ttr-2048 .tile-position-4-2 { left: 75.75%; top: 27.25%; }
.ttr-2048 .tile-position-4-3 { left: 75.75%; top: 51.5%; } .ttr-2048 .tile-position-4-4 { left: 75.75%; top: 75.75%; }
.ttr-2048 .tile-inner { width: 100%; height: 100%; display: grid; place-items: center; border-radius: 6px; background: #eee4da; color: #5f574f;
  font-weight: 800; font-size: clamp(1.3rem, 7vw, 2.9rem); font-size: 11cqw; line-height: 1; }
.ttr-2048 .tile-4 .tile-inner { background: #ede0c8; }
.ttr-2048 .tile-8 .tile-inner { background: #f2b179; color: #3d2b12; }
.ttr-2048 .tile-16 .tile-inner { background: #f59563; color: #3d2412; }
.ttr-2048 .tile-32 .tile-inner { background: #f67c5f; color: #3d1a12; }
.ttr-2048 .tile-64 .tile-inner { background: #f65e3b; color: #fff; }
.ttr-2048 .tile-128 .tile-inner { background: #edcf72; color: #4a3a05; font-size: clamp(1.1rem, 6vw, 2.4rem); font-size: 9.4cqw; }
.ttr-2048 .tile-256 .tile-inner { background: #edcc61; color: #4a3a05; font-size: clamp(1.1rem, 6vw, 2.4rem); font-size: 9.4cqw; }
.ttr-2048 .tile-512 .tile-inner { background: #edc850; color: #4a3a05; font-size: clamp(1.1rem, 6vw, 2.4rem); font-size: 9.4cqw; }
.ttr-2048 .tile-1024 .tile-inner { background: #edc53f; color: #4a3a05; font-size: clamp(.95rem, 5vw, 1.9rem); font-size: 7.4cqw; }
.ttr-2048 .tile-2048 .tile-inner { background: #edc22e; color: #4a3a05; font-size: clamp(.95rem, 5vw, 1.9rem); font-size: 7.4cqw; box-shadow: 0 0 0 3px var(--nhan); }
.ttr-2048 .tile-super .tile-inner { background: #3c3a32; color: #f9f6f2; font-size: clamp(.9rem, 4.4vw, 1.7rem); font-size: 6.4cqw; }
.ttr-2048 .tile-new .tile-inner { animation: ttr-hien .2s ease .1s both; }
.ttr-2048 .tile-merged { z-index: 20; }
.ttr-2048 .tile-merged .tile-inner { animation: ttr-nay .2s ease .1s both; }
@keyframes ttr-hien { from { opacity: 0; transform: scale(0); } to { opacity: 1; transform: scale(1); } }
@keyframes ttr-nay { 0% { transform: scale(0); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
.ttr-2048 .game-message { display: none; position: absolute; inset: 0; z-index: 100; border-radius: 10px; background: rgba(250, 246, 238, .86);
  flex-direction: column; justify-content: center; align-items: center; gap: 14px; text-align: center; padding: 12px; }
.ttr-2048 .game-message.game-won, .ttr-2048 .game-message.game-over { display: flex; }
.ttr-2048 .game-message p { margin: 0; font-size: 1.6rem; font-weight: 800; color: var(--c-dam); }
.ttr-2048 .game-message .lower { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ttr-2048 .game-message.game-over .keep-playing-button { display: none; }
.ttr-san--chieu .game-container { width: min(100%, 80vh); }
@media (prefers-reduced-motion: reduce) {
  .ttr-2048 .tile, .ttr-2048 .tile-inner, .ttr-2048 .score-addition, .ttr-thap__dia { animation: none !important; transition: none !important; }
}

/* Tháp Hà Nội */
.ttr-thap__ban { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 8px 0 0; }
.ttr-thap__coc { position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: clamp(250px, 50vh, 440px);
  margin: 0; padding: 0 4px; border: 0; border-radius: var(--r-nho); background: none; color: inherit; font: inherit; cursor: pointer; }
.ttr-thap__coc::before { content: ""; position: absolute; left: 50%; bottom: 40px; width: 10px; height: calc(100% - 64px); transform: translateX(-50%);
  border-radius: 5px 5px 0 0; background: #b9a27a; }
.ttr-thap__coc:hover { background: var(--c-nhat); }
.ttr-thap__coc--chon, .ttr-thap__coc--chon:hover { background: var(--nhan-nhat); }
.ttr-thap__dia-khung { position: relative; width: 100%; display: flex; flex-direction: column-reverse; align-items: center; gap: 2px; }
.ttr-thap__dia { display: block; height: clamp(22px, 4.4vh, 38px); line-height: clamp(22px, 4.4vh, 38px); border-radius: 999px; color: #fff; font-weight: 700;
  font-size: .9375rem; text-align: center; transition: transform .12s; }
.ttr-thap__dia--1 { background: #b42318; } .ttr-thap__dia--2 { background: #b4530d; } .ttr-thap__dia--3 { background: #8a6116; }
.ttr-thap__dia--4 { background: #1f7a3a; } .ttr-thap__dia--5 { background: #0f6f69; } .ttr-thap__dia--6 { background: #1d4f91; }
.ttr-thap__dia--7 { background: #5b3fa6; } .ttr-thap__dia--8 { background: #9d2b6b; }
.ttr-thap__dia--nhac { transform: translateY(-16px); box-shadow: 0 0 0 3px var(--nhan); }
.ttr-thap__ten { position: relative; width: 100%; margin-top: 2px; padding: 4px 0 6px; border-top: 8px solid var(--c-dam); border-radius: 3px 3px 0 0;
  text-align: center; font-weight: 800; color: var(--c-dam); }
.ttr-san--chieu .ttr-thap__ban { flex: 1 1 auto; }
.ttr-san--chieu .ttr-thap__coc { height: 100%; min-height: 60vh; }

/* In phiếu Sudoku: xem trước trên màn hình, in A4 dọc */
.ttr-in__form { max-width: 760px; }
.ttr-in__nut { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 14px; }
.ttr-in__giay { margin-top: 16px; overflow-x: auto; }
.ttr-in__trang { width: 210mm; min-height: 297mm; margin: 0 auto 16px; padding: 12mm; background: #fff; color: #000; border: 1px solid var(--vien); box-shadow: var(--bong); }
.ttr-in__dau h2 { margin: 0; font-size: 16pt; text-align: center; }
.ttr-in__phu { margin: 1mm 0 0; font-size: 10pt; text-align: center; }
.ttr-in__ten { margin: 4mm 0 0; font-size: 12pt; white-space: pre-wrap; }
.ttr-in__cac-de { display: grid; gap: 6mm 10mm; justify-content: center; margin-top: 5mm; --o: 9.2mm; grid-template-columns: repeat(2, auto); }
.ttr-in__trang--1 .ttr-in__cac-de { --o: 17mm; grid-template-columns: auto; }
.ttr-in__trang--2 .ttr-in__cac-de { --o: 11.4mm; grid-template-columns: auto; }
.ttr-in__trang--6 .ttr-in__cac-de { --o: 7.6mm; }
.ttr-in__trang--dap-an .ttr-in__cac-de { --o: 5.6mm; grid-template-columns: repeat(3, auto); }
.ttr-in__de { margin: 0; break-inside: avoid; }
.ttr-in__de figcaption { margin-bottom: 1mm; font-size: 10pt; font-weight: 700; }
.ttr-in__luoi { border-collapse: collapse; border: 2pt solid #000; }
.ttr-in__luoi td { width: var(--o); height: var(--o); padding: 0; border: .5pt solid #555; text-align: center; vertical-align: middle;
  font-size: calc(var(--o) * .58); font-weight: 700; line-height: 1; color: #000; }
.ttr-in__luoi td:nth-child(3n) { border-right: 1.6pt solid #000; }
.ttr-in__luoi tr:nth-child(3n) td { border-bottom: 1.6pt solid #000; }
.ttr-in__luoi td.ttr-in__dien { font-weight: 400; color: #333; }
@page ttr-in { size: A4 portrait; margin: 12mm; }
@media print {
  body:has(.ttr-in) .dau, body:has(.ttr-in) .chan, body:has(.ttr-in) .demo-bar, body:has(.ttr-in) .skip, .ttr-in__soan { display: none !important; }
  body:has(.ttr-in) { background: #fff; }
  .chinh:has(> .ttr-in) { max-width: none; padding: 0; }
  .ttr-in__giay { margin: 0; overflow: visible; }
  .ttr-in__trang { page: ttr-in; width: auto; min-height: 0; margin: 0; padding: 0; border: 0; box-shadow: none; break-after: page; }
  .ttr-in__trang:last-child { break-after: auto; }
}
