/*
 * KituAZ – sửa lỗi giao diện dùng chung.
 */

:root {
    --kz-pink: #d10f47;
    --kz-pink-soft: #fff0f5;
    --kz-pink-line: #f7c6d4;
    --kz-green: #1e8449;
    --kz-line: #e4e4ea;
    --kz-ink: #2b2d31;
}

/* Header: logo và menu dính sát mép màn hình khi trang hẹp hơn 1180px. */
.inside-header,
.footer-widgets-container {
    padding-left: 20px;
    padding-right: 20px;
}

/*
 * "Cập nhật lúc:" luôn trống vì theme ẩn time.updated (mặc định của
 * GeneratePress khi có cả ngày đăng). Ở đây chỉ in ngày cập nhật nên cho hiện.
 */
.entry-meta time.updated {
    display: inline;
}

/*
 * Tab ký tự trang chủ (#symbols-content-container) dùng class kiểu Bootstrap 3
 * ("fade active in") nhưng site nạp Bootstrap 4, nơi .fade:not(.show) có
 * opacity: 0 → toàn bộ bảng ký tự bị ẩn. Hiện lại tab đang active.
 */
.tab-content > .tab-pane.fade.active.in {
    opacity: 1;
}

/*
 * Bảng #main_symbols bị ép min-width 800px + float bằng inline style, nên trên
 * điện thoại phải cuộn ngang trong khung hẹp. Các ô .cs vốn là inline-block,
 * nên cho bảng/hàng thành block để ô tự xuống dòng theo bề rộng khung.
 */
#main_symbols {
    display: block;
    min-width: 0 !important;
    float: none !important;
    width: 100%;
    margin: 0 !important;
    border: 0;
}
/* Các hàng gốc chảy liền nhau để không còn hàng lẻ 1–2 ô. */
#main_symbols > tbody {
    display: flex;
    flex-wrap: wrap;
}
#main_symbols tr {
    display: contents;
}
#main_symbols td.cs {
    border: 1px solid #d3d3d3;
}

/*
 * Bảng ký tự trong bài (table.sym): hàng dài ngắn lệch nhau, ký tự nhỏ, sát
 * mép trái. Chuyển thành lưới ô vuông đều nhau, bấm ô để sao chép (ui-fixes.js).
 */
.entry-content table.sym:not(#main_symbols) {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 6px;
    width: 100%;
    margin: 0 0 1.5em;
    border: 0;
}
.entry-content table.sym:not(#main_symbols) > tbody,
.entry-content table.sym:not(#main_symbols) tr {
    display: contents;
}
.entry-content table.sym:not(#main_symbols) td {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    padding: 4px;
    border: 1px solid var(--kz-line);
    border-radius: 8px;
    background: #fff;
    color: var(--kz-ink);
    font-size: 22px;
    line-height: 1.2;
    text-align: center;
    overflow-wrap: anywhere;
    /* Một số ký tự tổ hợp (vd. ҉) vẽ tràn rất rộng ra ngoài ô. */
    overflow: hidden;
    cursor: pointer;
    transition: background-color .15s, border-color .15s;
}
.entry-content table.sym:not(#main_symbols) td:hover {
    background: var(--kz-pink-soft);
    border-color: var(--kz-pink-line);
}
.entry-content table.sym:not(#main_symbols) td:focus-visible {
    outline: 2px solid #0b6bd3;
    outline-offset: 2px;
}
.entry-content table.sym:not(#main_symbols) td.kz-copied {
    background: #eafaf1;
    border-color: var(--kz-green);
}
.entry-content table.sym:not(#main_symbols) td:empty {
    display: none;
}
.entry-content table.sym td img.emoji {
    width: 1em !important;
    height: 1em !important;
}

/* Thông báo "Đã sao chép" nổi ở cuối màn hình. */
.kz-toast {
    position: fixed;
    left: 50%;
    bottom: 96px;
    z-index: 10000;
    max-width: calc(100vw - 32px);
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--kz-ink);
    color: #fff;
    font-size: 15px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 8px);
    transition: opacity .2s, transform .2s;
}
.kz-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Trang 404: căn giữa, ảnh co theo khung, nút về trang chủ rõ ràng. */
.error-404 {
    max-width: 560px;
    margin: 40px auto;
    padding: 32px 20px;
    border-radius: 14px;
    background: #fff;
    text-align: center;
}
.error-404 img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto 16px;
}
.error-404 .page-title {
    margin-bottom: 20px;
    font-size: 26px;
}
.error-404 .btn-go-home {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 24px;
    border-radius: 999px;
    background: var(--kz-pink);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}
.error-404 .btn-go-home:hover,
.error-404 .btn-go-home:focus-visible {
    background: #a80c39;
    color: #fff;
}

@media (max-width: 767px) {
    /*
     * Một số ký tự tổ hợp (vd. ҉) vẽ tràn rất xa ra ngoài dòng chữ và làm cả
     * trang cuộn ngang. Cắt phần tràn ở vùng nội dung; các khối có thanh cuộn
     * riêng (overflow: auto) vẫn cuộn bình thường.
     */
    .entry-content {
        overflow-x: clip;
    }

    /* Tiêu đề 30px chiếm 4 dòng trên điện thoại – thu gọn cho dễ đọc. */
    h1.entry-title,
    .page-header h1,
    .entry-header h1 {
        font-size: 24px;
        line-height: 1.3;
    }
    .entry-content h2 {
        font-size: 21px;
        line-height: 1.3;
    }
    .entry-content h3 {
        font-size: 18px;
        line-height: 1.35;
    }

    .entry-content table.sym:not(#main_symbols) {
        grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
        gap: 4px;
    }
    .entry-content table.sym:not(#main_symbols) td {
        min-height: 48px;
        font-size: 20px;
    }

    /* Link footer chỉ cao 20px – nới vùng chạm cho dễ bấm trên điện thoại. */
    .footer-widgets .widget li {
        margin-bottom: 0;
    }
    .footer-widgets .widget li a,
    .footer-widgets .widget p > a {
        display: inline-block;
        padding: 10px 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kz-toast,
    .entry-content table.sym:not(#main_symbols) td {
        transition: none;
    }
}


/* Wiki archive */
.category-wiki .site-main > .page-header {
    margin-bottom: 20px;
    padding: 20px clamp(16px, 3vw, 28px);
    border-radius: 12px;
}
.category-wiki .site-main > .page-header h1 {
    font-size: clamp(1.75rem, 4vw, 2.25rem);
    font-weight: 700;
    line-height: 1.2;
}
.kz-wiki-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.kz-wiki-grid .kz-wiki-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    border: 1px solid #e0e3e9;
    border-radius: 12px;
    background: #fff;
}
.kz-wiki-card__image {
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #f3f4f6;
}
.kz-wiki-card__image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.kz-wiki-card__body {
    flex: 1;
    padding: 16px 18px 18px;
}
.kz-wiki-card__body time {
    display: block;
    margin-bottom: 6px;
    color: #535e6a;
    font-size: .82rem;
}
.kz-wiki-card__title {
    margin: 0;
    font-size: clamp(1rem, .88rem + .5vw, 1.25rem);
    font-weight: 700;
    line-height: 1.4;
    overflow-wrap: anywhere;
}
.kz-wiki-card__title a { color: #222a36; }
.kz-wiki-card__title a::after {
    position: absolute;
    inset: 0;
    content: '';
}
.kz-wiki-card__title a:hover { color: #a20c3a; text-decoration: underline; }
.kz-wiki-card:focus-within { outline: 2px solid #a20c3a; outline-offset: 2px; }
.kz-wiki-card__body p {
    margin: 8px 0 0;
    color: #495260;
    font-size: .91rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}
.kz-wiki-pagination { margin: 20px 0 0; }
.kz-wiki-pagination .nav-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.kz-wiki-pagination .page-numbers {
    display: inline-grid;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    padding: 4px 12px;
    border: 1px solid #e0e3e9;
    border-radius: 8px;
    background: #fff;
    color: #222a36;
}
.kz-wiki-pagination a:hover { border-color: #a20c3a; color: #a20c3a; }
.kz-wiki-pagination .current { border-color: #a20c3a; background: #a20c3a; color: #fff; }
.kz-wiki-pagination a:focus-visible { outline: 2px solid #a20c3a; outline-offset: 2px; }
@media (max-width: 600px) {
    .kz-wiki-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}


/* Related articles on single-post templates. */
.tin-lien-quan {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, max(220px, calc((100% - 32px) / 3))), 1fr));
    gap: 16px;
    margin-top: 24px;
}
.tin-lien-quan:not(:has(> .list-post)) { display: none; }
.tin-lien-quan > .title { grid-column: 1 / -1; }
.tin-lien-quan > .title > .list-entry-title {
    margin: 0;
    font-size: clamp(1.25rem, 1.1rem + .7vw, 1.6rem);
    font-weight: 700;
    line-height: 1.3;
}
.tin-lien-quan > .list-post {
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid #e0e3e9;
    border-radius: 12px;
    background: #fff;
}
.tin-lien-quan .list-tpost-thumb:has(img) {
    width: 100%;
    min-width: 0;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #f3f4f6;
}
.tin-lien-quan .list-tpost-thumb:not(:has(img)) { display: none; }
.tin-lien-quan .list-tpost-thumb-img,
.tin-lien-quan .list-tpost-thumb-img img {
    display: block;
    width: 100%;
    height: 100%;
}
.tin-lien-quan .list-tpost-thumb-img img { object-fit: cover; }
.tin-lien-quan .list-tpost-content {
    min-width: 0;
    margin: 0;
    padding: 14px 16px 16px;
}
.tin-lien-quan .list-tpost-content .list-entry-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.4;
    overflow-wrap: anywhere;
}
.tin-lien-quan .list-tpost-content .list-entry-title a { color: #222a36; }
.tin-lien-quan .list-tpost-content .list-entry-title a:hover { color: #a20c3a; text-decoration: underline; }
.tin-lien-quan > .list-post:focus-within { outline: 2px solid #a20c3a; outline-offset: 2px; }
.tin-lien-quan .list-tpost-content p {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    margin: 8px 0 0;
    color: #495260;
    font-size: .9rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}
@media (max-width: 600px) {
    .tin-lien-quan { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .tin-lien-quan > .list-post:has(img) {
        display: grid;
        grid-template-columns: minmax(84px, 30%) minmax(0, 1fr);
        align-items: start;
    }
    .tin-lien-quan .list-tpost-thumb:has(img) { aspect-ratio: 1; }
    .tin-lien-quan .list-tpost-content { padding: 10px 12px; }
    .tin-lien-quan .list-tpost-content p { -webkit-line-clamp: 2; margin-top: 4px; }
}


/* Single article header */
.single .site-main > article > .inside-article {
    padding: clamp(16px, 4vw, 28px);
    border: 1px solid #e0e3e9;
    border-radius: 12px;
}
.single .inside-article > .kituaz-breadcrumbs {
    margin: 0 0 16px;
    padding: 0 0 12px;
    border-bottom: 1px solid #e0e3e9;
    color: #535e6a;
    font-size: .85rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}
.single .kituaz-breadcrumbs a { color: #495260; text-underline-offset: .2em; }
.single .kituaz-breadcrumbs a:hover { color: #a20c3a; text-decoration: underline; }
.single .kituaz-breadcrumbs .breadcrumb_last { color: #222a36; }
.single .inside-article > .entry-header .entry-title {
    margin: 0;
    color: #222a36;
    font-size: clamp(1.5rem, 1rem + 2vw, 2.25rem);
    font-weight: 700;
    line-height: 1.25;
    overflow-wrap: anywhere;
}
.single .entry-header > .entry-meta:has(.avatar-user) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-top: 12px;
    color: #535e6a;
    font-size: .875rem;
    line-height: 1.5;
}
.single .entry-header .avatar-user {
    display: inline-flex;
    float: none;
    flex: 0 0 auto;
    align-items: center;
    margin: 0;
}
.single .entry-header .avatar-user img {
    display: block;
    box-sizing: border-box;
    width: 34px;
    height: 34px;
    margin: 0;
    padding: 2px;
    object-fit: cover;
    border: 1px solid #e0e3e9;
    border-radius: 50%;
    background: #fff;
}
.single .entry-header .entry-meta:has(.avatar-user) .byline,
.single .entry-header .entry-meta:has(.avatar-user) .posted-on {
    margin: 0;
}
.single .entry-header .entry-meta:has(.avatar-user) .byline + span:not(.posted-on) {
    display: none !important;
}
.single .entry-header .byline a { color: #222a36; font-weight: 650; }
.single .entry-header .byline a:hover { color: #a20c3a; text-decoration: underline; }
.single .inside-article > .entry-header + .entry-content { margin-top: 20px; }

@media (max-width: 600px) {
    .single .inside-article > .kituaz-breadcrumbs { margin-bottom: 12px; padding-bottom: 10px; }
    .single .entry-header > .entry-meta:has(.avatar-user) .posted-on { flex-basis: 100%; }
    .single .inside-article > .entry-header + .entry-content { margin-top: 16px; }
}
