/* Mega menu trên máy tính cho header của theme Trình Giải Toán. Điện thoại vẫn dùng menu con cũ. */
.tgt-mega { display: none; }

@media (min-width: 961px) {
	/* Bảng mega rộng hết header: mục cấp 1 không làm mốc định vị nữa, header (sticky/relative) làm mốc. */
	.tgtt-header { position: sticky; }
	.tgtt-no-sticky .tgtt-header { position: relative; }
	.tgtt-menu > li.tgt-mega-item { position: static; }
	.tgtt-menu > li.tgt-mega-item > .sub-menu { display: none !important; }

	.tgt-mega {
		display: block; position: absolute; left: 0; right: 0; top: 100%; z-index: 20;
		background: var(--surface, #fff); border-top: 1px solid var(--line, #e3e8f4); border-bottom: 1px solid var(--line, #e3e8f4);
		box-shadow: 0 24px 40px -18px rgba(35, 49, 77, .28);
		opacity: 0; visibility: hidden; transform: translateY(-4px);
		transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s;
	}
	/* Cầu nối vô hình giữa chữ trên menu và bảng để rê chuột xuống không bị tắt. */
	.tgt-mega::before { content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 18px; }
	.tgtt-menu > li.tgt-mega-item:hover > .tgt-mega,
	.tgtt-menu > li.tgt-mega-item:focus-within > .tgt-mega,
	.tgtt-menu > li.tgt-mega-item.is-open > .tgt-mega {
		opacity: 1; visibility: visible; transform: none;
		transition: opacity .16s ease .06s, transform .16s ease .06s, visibility 0s linear .06s;
	}
	/* Bàn phím: hiện ngay, không chờ, để phím mũi tên xuống đưa được tiêu điểm vào bảng. */
	.tgtt-menu > li.tgt-mega-item:focus-within > .tgt-mega { transition: none; }
	.tgtt-menu > li.tgt-mega-item.tgt-mega-hide > .tgt-mega { opacity: 0; visibility: hidden; transition: none; }
	/* Đang mở một bảng (bằng nút hoặc bàn phím) mà rê chuột sang mục khác thì chỉ hiện bảng của mục đó. */
	.tgtt-menu:hover > li.tgt-mega-item:not(:hover) > .tgt-mega { opacity: 0; visibility: hidden; transition: none; }

	.tgt-mega__inner {
		display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 28px;
		max-width: var(--wrap, 1200px); margin: 0 auto; padding: 24px 20px 26px;
		max-height: calc(100vh - var(--header-h, 76px) - 40px); overflow-y: auto; overscroll-behavior: contain;
	}
	.tgt-mega__inner--full { grid-template-columns: minmax(0, 1fr); }

	.tgt-mega__cols { display: grid; grid-template-columns: repeat(var(--tgt-mega-cols, 3), minmax(0, 1fr)); gap: 8px 22px; align-content: start; }
	.tgt-mega__col { min-width: 0; }
	.tgt-mega__col--wide { grid-column: 1 / -1; }
	.tgt-mega__col--wide .tgt-mega__list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 22px; }
	.tgt-mega__col + .tgt-mega__col:not(.tgt-mega__col--wide) { border-left: 1px solid var(--line, #e3e8f4); padding-left: 22px; }
	.tgt-mega__col--wide + .tgt-mega__col { border-left: 0; padding-left: 0; }

	.tgt-mega__head {
		display: flex; align-items: center; gap: 8px; margin: 0 0 8px; padding: 0 10px;
		font-size: .78rem; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; color: var(--muted, #5d6b86);
	}
	.tgt-mega__head a { color: inherit; text-decoration: none; }
	.tgt-mega__head a:hover { color: var(--primary-dark, #e85d27); }
	.tgt-mega__head-icon { font-size: 1rem; }
	.tgt-mega__head-sub {
		margin-left: auto; padding: 2px 8px; border-radius: 999px; background: var(--surface-2, #eef2fd);
		font-size: .72rem; letter-spacing: 0; text-transform: none; font-weight: 800; white-space: nowrap;
	}

	.tgt-mega__list { list-style: none; margin: 0; padding: 0; }
	.tgt-mega__list > li { margin: 0; min-width: 0; }

	/* Đặt lại kiểu của ".tgtt-menu a" trong theme (bo tròn kiểu viên thuốc, không xuống dòng). */
	.tgtt-menu .tgt-mega a { white-space: normal; font-size: inherit; padding: 0; border-radius: 0; background: none; }
	.tgtt-menu .tgt-mega .tgt-mega__link {
		display: flex; align-items: flex-start; gap: 12px; padding: 9px 10px; border-radius: 14px;
		color: var(--ink, #23314d); text-decoration: none; transition: background .12s;
	}
	.tgtt-menu .tgt-mega .tgt-mega__link:hover,
	.tgtt-menu .tgt-mega .tgt-mega__link:focus-visible,
	.tgtt-menu .tgt-mega .tgt-mega__link.is-current { background: var(--surface-2, #eef2fd); color: var(--ink, #23314d); }
	.tgtt-menu .tgt-mega .tgt-mega__link:hover .tgt-mega__name,
	.tgtt-menu .tgt-mega .tgt-mega__link.is-current .tgt-mega__name { color: var(--primary-dark, #e85d27); }

	.tgt-mega__ico {
		flex: none; display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px;
		border-radius: 12px; background: var(--surface-2, #eef2fd); font-size: 1.2rem; line-height: 1;
	}
	.tgt-mega__ico--num { font-weight: 900; font-size: 1rem; color: var(--primary-dark, #e85d27); background: var(--primary-soft, #fff1e8); }
	.tgt-mega__ico--orange { background: #fff1e6; }
	.tgt-mega__ico--green { background: #e6f7ef; }
	.tgt-mega__ico--pink { background: #fde8f1; }
	.tgt-mega__ico--purple { background: #f0eafe; }
	.tgt-mega__ico--blue { background: #e7effe; }
	.tgt-mega__ico--teal { background: #e3f6f8; }
	.tgt-mega__ico--red { background: #fde9e9; }
	.tgt-mega__ico--yellow { background: #fff6da; }

	.tgt-mega__txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding-top: 1px; }
	.tgt-mega__name { font-weight: 800; font-size: .95rem; line-height: 1.3; color: var(--ink, #23314d); overflow-wrap: anywhere; }
	.tgt-mega__tag {
		display: inline-block; margin-right: 2px; padding: 0 7px; border-radius: 999px; vertical-align: 1px;
		background: var(--primary-soft, #fff1e8); color: var(--primary-dark, #e85d27); font-size: .7rem; font-weight: 800; line-height: 1.5; white-space: nowrap;
	}
	:root[data-mode="dark"] .tgt-mega__tag { color: #ffb08f; }
	.tgt-mega__desc {
		font-size: .82rem; font-weight: 600; line-height: 1.4; color: var(--muted, #5d6b86);
		display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
	}

	.tgt-mega__subs { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: -2px 0 6px 60px; }
	.tgtt-menu .tgt-mega .tgt-mega__subs a {
		padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line, #e3e8f4);
		font-size: .76rem; font-weight: 700; color: var(--muted, #5d6b86); text-decoration: none;
	}
	.tgtt-menu .tgt-mega .tgt-mega__subs a:hover { border-color: var(--primary, #ff7a45); color: var(--primary-dark, #e85d27); }

	.tgt-mega__aside {
		align-self: start; padding: 20px; border-radius: var(--radius, 18px);
		background: linear-gradient(150deg, var(--primary-soft, #fff1e8), var(--surface-2, #eef2fd));
	}
	.tgt-mega__aside-icon { display: block; font-size: 2rem; line-height: 1; margin-bottom: 10px; }
	.tgt-mega__aside-title { margin: 0 0 6px; font-weight: 900; font-size: 1.08rem; color: var(--ink, #23314d); }
	.tgt-mega__aside-text { margin: 0 0 14px; font-size: .86rem; line-height: 1.5; color: var(--muted, #5d6b86); }
	.tgtt-menu .tgt-mega .tgt-mega__cta {
		display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 999px;
		background: var(--primary, #ff7a45); color: #fff; font-weight: 800; font-size: .9rem; text-decoration: none;
	}
	.tgtt-menu .tgt-mega .tgt-mega__cta:hover { background: var(--primary-dark, #e85d27); color: #fff; }

	.tgt-mega a:focus-visible { outline: 3px solid var(--primary, #ff7a45); outline-offset: 2px; }

	/* Giao diện tối */
	:root[data-mode="dark"] .tgt-mega { box-shadow: 0 24px 40px -18px rgba(0, 0, 0, .7); }
	:root[data-mode="dark"] .tgt-mega__ico:not(.tgt-mega__ico--num) { background: var(--surface-2, #1a2342); }
	:root[data-mode="dark"] .tgt-mega__ico--num { color: #ffb08f; }
	:root[data-mode="dark"] .tgtt-menu .tgt-mega .tgt-mega__link:hover .tgt-mega__name,
	:root[data-mode="dark"] .tgtt-menu .tgt-mega .tgt-mega__link.is-current .tgt-mega__name,
	:root[data-mode="dark"] .tgt-mega__head a:hover { color: #ffb08f; }
	:root[data-mode="dark"] .tgt-mega__aside { background: linear-gradient(150deg, var(--primary-soft, #2a1d1c), var(--surface-2, #1a2342)); }
}

@media (min-width: 961px) and (max-width: 1180px) {
	.tgt-mega__inner { grid-template-columns: minmax(0, 1fr) 210px; gap: 20px; }
	.tgt-mega__cols { gap: 8px 14px; }
	.tgt-mega__col + .tgt-mega__col:not(.tgt-mega__col--wide) { padding-left: 14px; }
	.tgt-mega__col--wide .tgt-mega__list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.tgt-mega__desc { -webkit-line-clamp: 1; }
}

@media (prefers-reduced-motion: reduce) {
	.tgt-mega { transition: none !important; transform: none !important; }
}

/* Laptop 961–1320px: header cũ tràn ra ngoài màn hình (cuộn ngang). Thu gọn nút đăng nhập và tên website. */
@media (min-width: 961px) and (max-width: 1320px) {
	.tgtt-header .tgtt-header__bar { gap: 10px; }
	.tgtt-header .tgc-head-login { width: 42px; padding: 0; justify-content: center; }
	.tgtt-header .tgc-head-login span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
@media (min-width: 961px) and (max-width: 1180px) {
	.tgtt-header .tgtt-brand__name, .tgtt-header .tgtt-brand__tag { display: none; }
	.tgtt-header .tgtt-menu > li > a { padding-left: 9px; padding-right: 9px; }
	.tgtt-header .tgtt-menu > .menu-item-has-children > a { padding-right: 2px; }
}

/* Điện thoại: danh sách công cụ 2 cột cho chữ dài khỏi bị bẻ vụn. */
@media (max-width: 600px) {
	.tgtt-header .tgtt-menu > li > .sub-menu:has(> li:nth-child(12)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
