/* Trình Giải Toán: bình luận kiểu Threads và trang tài khoản.
   Dùng màu của theme (--surface, --ink, --line...) và có màu dự phòng khi dùng theme khác. */

.tgc, .tgc-account, .tgc-toast, .tgc-head-login, .tgc-head-user {
	--tgc-bg: var(--surface, #fff);
	--tgc-bg2: var(--surface-2, #f2f4f8);
	--tgc-ink: var(--ink, #1c2333);
	--tgc-muted: var(--muted, #687389);
	--tgc-line: var(--line, #e3e7ef);
	--tgc-accent: var(--primary, #ff7a45);
	--tgc-accent-dark: var(--primary-dark, #e85d27);
	--tgc-blue: var(--blue, #3d7bfd);
	--tgc-red: var(--red, #ef4444);
	--tgc-heart: #ff3040;
	--tgc-av: 40px;
	--tgc-gap: 12px;
}

/* ---------- Nút tài khoản trên đầu trang ---------- */
.tgc-head-login {
	display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 999px;
	border: 1.5px solid var(--tgc-line); background: var(--tgc-bg); color: var(--tgc-ink); font-weight: 800; font-size: .92rem;
	text-decoration: none; white-space: nowrap;
}
.tgc-head-login:hover { border-color: var(--tgc-accent); color: var(--tgc-accent-dark); }
.tgc-head-user { display: inline-flex; border-radius: 50%; line-height: 0; }
.tgc-head-user .avatar { width: 36px !important; height: 36px !important; font-size: 16px !important; border-radius: 50%; border: 2px solid var(--tgc-line); object-fit: cover; }
.tgc-head-user:hover .avatar { border-color: var(--tgc-accent); }
@media (max-width: 600px) {
	.tgc-head-login { width: 40px; padding: 0; justify-content: center; }
	.tgc-head-login span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

/* ---------- Khu vực bình luận ---------- */
.tgc { max-width: 760px; margin: 40px auto 0; padding-top: 24px; border-top: 1px solid var(--tgc-line); color: var(--tgc-ink); }
.tgc *, .tgc *::before, .tgc *::after { box-sizing: border-box; }
.tgc-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.tgc-title { font-size: 1.3rem; margin: 0; display: flex; align-items: center; gap: 8px; }
.tgc-total:not(:empty) {
	font-size: .8rem; background: var(--tgc-bg2); color: var(--tgc-muted); border-radius: 999px; padding: 2px 10px; font-weight: 800;
}
.tgc-top__login { font-weight: 800; font-size: .92rem; text-decoration: none; }
.tgc-closed, .tgc-empty { color: var(--tgc-muted); text-align: center; padding: 18px 0; margin: 0; }

.tgc-avatar { width: var(--tgc-av); height: var(--tgc-av); border-radius: 50%; object-fit: cover; display: block; background: var(--tgc-bg2); }
.tgc-letter {
	display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 800; line-height: 1; flex: 0 0 auto;
	font-family: var(--font, inherit); user-select: none; vertical-align: middle;
}
.tgc-avatar--guest {
	display: grid; place-items: center; font-weight: 900; color: var(--tgc-muted); border: 1.5px dashed var(--tgc-line); background: transparent;
}

/* Khung viết */
.tgc-composer {
	display: flex; gap: var(--tgc-gap); padding: 14px 16px; margin: 10px 0 6px; background: var(--tgc-bg);
	border: 1px solid var(--tgc-line); border-radius: 20px; transition: border-color .15s, box-shadow .15s;
}
.tgc-composer:focus-within { border-color: var(--tgc-blue); box-shadow: 0 0 0 4px rgba(61, 123, 253, .12); }
.tgc-composer .tgc-rail { flex: 0 0 var(--tgc-av); }
.tgc-composer .tgc-main { flex: 1; min-width: 0; }
.tgc-composer textarea {
	width: 100%; border: 0; outline: 0; resize: none; background: transparent; padding: 8px 0; height: 40px; min-height: 40px; line-height: 1.5;
	font-size: 1rem; color: var(--tgc-ink); box-shadow: none;
}
.tgc-composer textarea:focus-visible { outline: 0; }
.tgc-composer textarea::placeholder { color: var(--tgc-muted); }
.tgc-replying { margin: 0 0 2px; font-size: .85rem; color: var(--tgc-muted); font-weight: 700; }
.tgc-guest { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 4px; }
.tgc-guest input[type="text"], .tgc-guest input[type="email"] {
	width: 100%; padding: 9px 12px; border: 1.5px solid var(--tgc-line); border-radius: 12px; background: var(--tgc-bg2); font-size: .92rem;
}
.tgc-guest input:focus { border-color: var(--tgc-blue); outline: 0; }
.tgc-guest .tgc-captcha, .tgc-guest .tgc-check, .tgc-guest .tgc-hint { grid-column: 1 / -1; }
.tgc.js-ready .tgc-composer:not(.is-open) [data-tgc-extra] { display: none; }
.tgc-captcha { display: flex; align-items: center; gap: 10px; font-size: .92rem; }
.tgc-captcha input { width: 64px !important; text-align: center; padding: 7px 8px; border: 1.5px solid var(--tgc-line); border-radius: 10px; background: var(--tgc-bg2); }
.tgc-check { display: flex; align-items: flex-start; gap: 8px; font-size: .9rem; color: var(--tgc-muted); font-weight: 600; cursor: pointer; }
.tgc-check input { margin-top: .3em; accent-color: var(--tgc-accent); }
.tgc-hint { font-size: .85rem; color: var(--tgc-muted); margin: 2px 0 0; }
.tgc-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }

.tgc-bar { display: flex; align-items: center; gap: 10px; padding-top: 8px; border-top: 1px solid transparent; }
.tgc-composer.is-open .tgc-bar { border-top-color: var(--tgc-line); margin-top: 6px; }
.tgc-tip { flex: 1; font-size: .78rem; color: var(--tgc-muted); min-width: 0; }
.tgc-tip code { font-size: .78rem; background: var(--tgc-bg2); padding: 1px 5px; border-radius: 6px; }
.tgc.js-ready .tgc-composer:not(.is-open) .tgc-tip { visibility: hidden; }
.tgc-counter { font-size: .8rem; color: var(--tgc-muted); font-weight: 700; }
.tgc-counter.is-over { color: var(--tgc-red); }
.tgc-cancel {
	border: 0; background: none; color: var(--tgc-muted); font-weight: 800; cursor: pointer; padding: 8px 10px; border-radius: 999px;
}
.tgc-cancel:hover { background: var(--tgc-bg2); }
.tgc-submit {
	display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer; border-radius: 999px; padding: 9px 18px;
	background: var(--tgc-ink); color: var(--tgc-bg); font-weight: 800; font-size: .92rem; transition: opacity .15s, transform .1s;
}
.tgc.js-ready .tgc-composer:not(.has-text) .tgc-submit { opacity: .35; }
.tgc-submit:hover { transform: translateY(-1px); }
.tgc-submit:disabled { opacity: .5; cursor: wait; }
.tgc-submit .tgc-ico { width: 16px; height: 16px; }
.tgc-msg { margin: 8px 0 0; font-size: .88rem; font-weight: 700; color: var(--green, #22b07d); }
.tgc-msg.is-error { color: var(--tgc-red); }
.tgc-composer.is-busy { opacity: .75; }

.tgc-composer--reply { margin: 2px 0 10px calc(var(--tgc-av) + var(--tgc-gap)); padding: 10px 12px; border-radius: 16px; --tgc-av: 32px; }

.tgc-gate {
	text-align: center; padding: 22px 18px; margin: 10px 0; border: 1.5px dashed var(--tgc-line); border-radius: 20px; background: var(--tgc-bg);
}
.tgc-gate p { margin: 0 0 12px; color: var(--tgc-muted); }

/* Danh sách */
.tgc-list, .tgc-list .children { list-style: none; margin: 0; padding: 0; }
.tgc-item { position: relative; }
.tgc-list > .tgc-item { border-bottom: 1px solid var(--tgc-line); }
.tgc-list > .tgc-item:last-child { border-bottom: 0; }
.tgc-post { display: flex; gap: var(--tgc-gap); padding: 14px 0 8px; position: relative; border-radius: 14px; }
.tgc-post .tgc-rail { flex: 0 0 var(--tgc-av); position: relative; }
.tgc-main { flex: 1; min-width: 0; }
.tgc-post.is-target { background: linear-gradient(90deg, rgba(255, 122, 69, .12), transparent 70%); box-shadow: -10px 0 0 rgba(255, 122, 69, .12); }
.tgc-item.is-new > .tgc-post { animation: tgc-in .4s ease-out; }
@keyframes tgc-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.tgc-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; line-height: 1.3; }
.tgc-name { font-weight: 800; }
.tgc-handle, .tgc-time { color: var(--tgc-muted); font-size: .88rem; text-decoration: none; }
.tgc-time::before { content: "·"; margin-right: 6px; }
.tgc-time:hover { text-decoration: underline; color: var(--tgc-muted); }
.tgc-badge {
	font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; padding: 2px 7px; border-radius: 999px;
	background: var(--primary-soft, #fff1e8); color: var(--tgc-accent-dark); align-self: center;
}
.tgc-badge--mod { background: rgba(61, 123, 253, .12); color: var(--tgc-blue); }
.tgc-badge--wait { background: rgba(255, 159, 28, .16); color: #b46a00; }
.tgc-pending { font-size: .82rem; color: #b46a00; font-weight: 700; margin: 4px 0 0; }
.tgc-text { margin-top: 3px; overflow-wrap: anywhere; }
.tgc-text p { margin: 0 0 .5em; }
.tgc-text p:last-child { margin-bottom: 0; }
.tgc-text .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.tgc-post.is-deleted .tgc-text { color: var(--tgc-muted); }

.tgc-actions { display: flex; align-items: center; gap: 2px; margin: 6px 0 0 -8px; }
.tgc-act {
	display: inline-flex; align-items: center; gap: 5px; height: 34px; min-width: 34px; padding: 0 8px; border: 0; border-radius: 999px;
	background: none; color: var(--tgc-muted); font-size: .85rem; font-weight: 700; cursor: pointer; text-decoration: none;
	transition: background .15s, color .15s;
}
.tgc-act:hover { background: var(--tgc-bg2); color: var(--tgc-ink); }
.tgc-act .tgc-ico { width: 19px; height: 19px; }
.tgc-like.is-liked { color: var(--tgc-heart); }
.tgc-like.is-liked .tgc-ico { fill: currentColor; }
.tgc-like.is-pop .tgc-ico { animation: tgc-pop .35s ease-out; }
@keyframes tgc-pop { 40% { transform: scale(1.35); } }
.tgc-act--danger:hover { color: var(--tgc-red); }
.tgc-count:empty { display: none; }

/* Đường nối các tầng trả lời */
.tgc-item.has-children > .tgc-post .tgc-rail::after {
	content: ""; position: absolute; left: calc(var(--tgc-av) / 2 - 1px); top: calc(var(--tgc-av) + 6px); bottom: -8px; width: 2px;
	background: var(--tgc-line); border-radius: 2px;
}
.tgc-list .children { padding-left: calc(var(--tgc-av) + var(--tgc-gap)); position: relative; }
.tgc-list .children > li::before {
	content: ""; position: absolute; left: calc(var(--tgc-av) / -2 - var(--tgc-gap) - 1px); top: 0;
	width: calc(var(--tgc-av) / 2 + var(--tgc-gap) - 4px); height: calc(14px + var(--tgc-av) / 2);
	border-left: 2px solid var(--tgc-line); border-bottom: 2px solid var(--tgc-line); border-bottom-left-radius: 14px;
}
.tgc-list .children > li:not(:last-child)::after {
	content: ""; position: absolute; left: calc(var(--tgc-av) / -2 - var(--tgc-gap) - 1px); top: 0; bottom: 0; border-left: 2px solid var(--tgc-line);
}
.tgc-list .children.is-collapsed > li:nth-child(n+3) { display: none; }
.tgc-list .children.is-collapsed > li:nth-child(2)::after { display: none; }
.tgc-more {
	display: block; margin: 0 0 10px calc(var(--tgc-av) + var(--tgc-gap)); padding: 6px 12px; border: 0; border-radius: 999px; cursor: pointer;
	background: var(--tgc-bg2); color: var(--tgc-ink); font-weight: 800; font-size: .85rem;
}
.tgc-more:hover { color: var(--tgc-accent-dark); }

.tgc .nav-links { display: flex; justify-content: center; gap: 8px; margin: 18px 0; }
.tgc .page-numbers { padding: 6px 12px; border-radius: 10px; border: 1px solid var(--tgc-line); text-decoration: none; font-weight: 700; }
.tgc .page-numbers.current { background: var(--tgc-ink); color: var(--tgc-bg); border-color: var(--tgc-ink); }

@media (max-width: 600px) {
	.tgc, .tgc-account { --tgc-av: 34px; --tgc-gap: 10px; }
	.tgc-guest { grid-template-columns: 1fr; }
	.tgc-tip { display: none; }
	.tgc-bar { justify-content: flex-end; }
	/* Từ tầng 3 trở đi không thụt vào nữa để chữ không bị hẹp */
	.tgc-item[data-depth="3"] .children { padding-left: 0; }
	.tgc-item[data-depth="3"] .children > li::before, .tgc-item[data-depth="3"] .children > li::after { display: none; }
	.tgc-item[data-depth="3"] .tgc-item.has-children > .tgc-post .tgc-rail::after { display: none; }
	.tgc-item[data-depth="3"] .tgc-composer--reply, .tgc-item[data-depth="3"] .tgc-more { margin-left: 0; }
}

/* ---------- Thông báo nổi ---------- */
.tgc-toast {
	position: fixed; left: 50%; bottom: 24px; z-index: 9999; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
	background: var(--tgc-ink); color: var(--tgc-bg); padding: 10px 18px; border-radius: 999px; font-weight: 800; font-size: .92rem;
	box-shadow: 0 10px 30px rgba(0, 0, 0, .2); transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); text-align: center;
}
.tgc-toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.tgc-toast.is-error { background: var(--tgc-red); color: #fff; }

/* ---------- Trang tài khoản ---------- */
.tgc-account { color: var(--tgc-ink); margin: 0 auto; }
.tgc-account *, .tgc-account *::before, .tgc-account *::after { box-sizing: border-box; }
.tgc-auth { max-width: 440px; margin: 0 auto; background: var(--tgc-bg); border: 1px solid var(--tgc-line); border-radius: 24px; padding: 24px; box-shadow: var(--shadow, 0 6px 20px rgba(0, 0, 0, .06)); }
.tgc-switch { display: grid; grid-template-columns: 1fr 1fr; background: var(--tgc-bg2); border-radius: 999px; padding: 4px; margin-bottom: 20px; }
.tgc-switch a { text-align: center; padding: 9px 10px; border-radius: 999px; font-weight: 800; text-decoration: none; color: var(--tgc-muted); }
.tgc-switch a.is-active { background: var(--tgc-bg); color: var(--tgc-ink); box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.tgc-switch a:only-child { grid-column: 1 / -1; }

.tgc-form { display: grid; gap: 14px; }
.tgc-form p { margin: 0; }
.tgc-field { display: grid; gap: 6px; }
.tgc-field > span:first-child { font-weight: 800; font-size: .92rem; }
.tgc-field small { color: var(--tgc-muted); font-size: .82rem; }
.tgc-field small.is-error { color: var(--tgc-red); }
.tgc-form input[type="text"], .tgc-form input[type="email"], .tgc-form input[type="password"], .tgc-form textarea {
	width: 100%; padding: 11px 14px; border: 1.5px solid var(--tgc-line); border-radius: 14px; background: var(--tgc-bg); color: var(--tgc-ink); font-size: 1rem;
}
.tgc-form input:focus { border-color: var(--tgc-blue); outline: 0; box-shadow: 0 0 0 4px rgba(61, 123, 253, .12); }
.tgc-form input:disabled { background: var(--tgc-bg2); color: var(--tgc-muted); }
.tgc-at { position: relative; display: block; }
.tgc-at b { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--tgc-muted); pointer-events: none; }
.tgc-form .tgc-at input { padding-left: 32px; }
.tgc-pass { position: relative; display: block; }
.tgc-form .tgc-pass input { padding-right: 64px; }
.tgc-pass__toggle {
	position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: var(--tgc-bg2); color: var(--tgc-muted);
	border-radius: 10px; padding: 5px 10px; font-weight: 800; font-size: .8rem; cursor: pointer;
}
.tgc-form .tgc-captcha input { width: 72px !important; }
.tgc-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .9rem; }
.tgc-center { text-align: center; }

.tgc-btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 20px; border-radius: 999px; border: 1.5px solid transparent;
	background: var(--tgc-accent); color: #fff; font-weight: 800; font-size: .95rem; cursor: pointer; text-decoration: none; line-height: 1.2;
	transition: background .15s, transform .1s;
}
.tgc-btn:hover { background: var(--tgc-accent-dark); color: #fff; transform: translateY(-1px); }
.tgc-btn--block { width: 100%; }
.tgc-btn--ghost { background: var(--tgc-bg); color: var(--tgc-ink); border-color: var(--tgc-line); }
.tgc-btn--ghost:hover { background: var(--tgc-bg); color: var(--tgc-accent-dark); border-color: var(--tgc-accent); }
.tgc-btn--danger { background: var(--tgc-red); }
.tgc-btn--danger:hover { background: #c62828; }
.tgc-btn--sm { padding: 6px 12px; font-size: .85rem; }
.tgc-link-btn { border: 0; background: none; color: var(--tgc-red); font-weight: 700; cursor: pointer; padding: 6px; }

.tgc-alert { padding: 12px 16px; border-radius: 14px; background: var(--tgc-bg2); font-weight: 700; margin: 0 0 16px; }
.tgc-alert--ok { background: rgba(34, 176, 125, .12); color: #137a55; }
.tgc-alert--error { background: rgba(239, 68, 68, .1); color: #c62828; }
:root[data-mode="dark"] .tgc-alert--ok { color: #6ee7b7; }
:root[data-mode="dark"] .tgc-alert--error { color: #fca5a5; }

.tgc-dash { max-width: 760px; margin: 0 auto; }
.tgc-dash__head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.tgc-dash__head .tgc-avatar { --tgc-av: 72px; }
.tgc-dash__who { flex: 1; display: grid; min-width: 0; }
.tgc-dash__who b { font-size: 1.35rem; font-weight: 900; line-height: 1.2; overflow-wrap: anywhere; }
.tgc-dash__who span { color: var(--tgc-muted); font-size: .92rem; }
.tgc-tabs { display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--tgc-line); margin-bottom: 20px; scrollbar-width: none; }
.tgc-tabs a {
	flex: 0 0 auto; padding: 10px 14px; font-weight: 800; color: var(--tgc-muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tgc-tabs a:hover { color: var(--tgc-ink); }
.tgc-tabs a.is-active { color: var(--tgc-ink); border-bottom-color: var(--tgc-ink); }
.tgc-panel .tgc-form { max-width: 480px; }
.tgc-avatar-pick { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tgc-avatar-pick .tgc-avatar { --tgc-av: 64px; }
.tgc-form--danger { border: 1.5px solid rgba(239, 68, 68, .35); border-radius: 18px; padding: 18px; }

.tgc-mine { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.tgc-mine__item { border: 1px solid var(--tgc-line); border-radius: 18px; padding: 14px 16px; background: var(--tgc-bg); }
.tgc-mine__meta { font-size: .85rem; color: var(--tgc-muted); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tgc-mine__meta a { font-weight: 800; text-decoration: none; }
.tgc-mine__text { margin: 6px 0 10px; overflow-wrap: anywhere; }
.tgc-mine__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tgc-mine__actions form { margin: 0; }
.tgc-pages { display: flex; gap: 6px; justify-content: center; margin-top: 18px; }
.tgc-pages a { padding: 6px 12px; border-radius: 10px; border: 1px solid var(--tgc-line); text-decoration: none; font-weight: 800; }
.tgc-pages a.is-active { background: var(--tgc-ink); color: var(--tgc-bg); }

@media (max-width: 600px) {
	.tgc-auth { padding: 18px; border-radius: 20px; }
	.tgc-dash__head { flex-wrap: wrap; }
	.tgc-dash__head .tgc-avatar { --tgc-av: 56px; }
}

/* Ảnh đại diện luôn tròn, kể cả khi theme bo góc ảnh trong nội dung */
.tgc img.avatar, .tgc-account img.avatar, .tgc-head-user img.avatar { border-radius: 50% !important; object-fit: cover; margin: 0; box-shadow: none; }
.tgc-link-btn { font-size: .85rem; }
