
/* =========================================
   ENGLISHUP GRAMMAR – DANH SÁCH CHUYÊN ĐỀ
   ========================================= */

.grammar-page {
    width: 100%;
    min-width: 0;
    color: var(--text, #183151);
}

.grammar-page .grammar-catalog {
    padding: 30px;
    border: 1px solid #dce6f6;
    border-radius: 22px;
    background: #f6f9ff;
    box-shadow: 0 12px 34px rgba(27, 64, 120, .04);
}

.grammar-catalog-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 22px;
}

.grammar-catalog-eyebrow {
    display: block;
    margin-bottom: 8px;
    color: #315fd1;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .09em;
}

.grammar-catalog-heading h2 {
    margin: 0 0 8px;
    color: #142f56;
    font-size: 27px;
    line-height: 1.3;
}

.grammar-catalog-heading p {
    margin: 0;
    color: #61738f;
    line-height: 1.65;
}

.grammar-total {
    flex-shrink: 0;
    padding: 8px 12px;
    border: 1px solid #cbdafa;
    border-radius: 99px;
    background: #eaf1ff;
    color: #2958c5;
    font-size: 13px;
    font-weight: 700;
}

/* Tìm kiếm */

.grammar-filters {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0 0 24px;
}

.grammar-filters label {
    display: flex;
    flex: 1 1 250px;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    color: #304665;
    font-size: 14px;
    font-weight: 700;
}

.grammar-filters input[type="search"] {
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    border: 1px solid #cbd8ed;
    border-radius: 11px;
    background: #fff;
    color: #1b3458;
    font: inherit;
    font-weight: 400;
}

.grammar-filters input[type="search"]:focus-visible {
    border-color: #3869df;
    outline: 3px solid rgba(56, 105, 223, .15);
}

.grammar-filters .btn {
    min-height: 46px;
    padding: 10px 22px;
    border-radius: 11px;
}

.grammar-reset {
    align-self: center;
    color: #315fcd;
    font-size: 14px;
}

/* Mỗi chuyên đề là một hàng riêng */

.grammar-page .grammar-topic-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.grammar-page .grammar-topic-list > li {
    display: block;
    margin: 0;
    padding: 0;
    list-style: none;
}

.grammar-page .grammar-topic-list > li::marker {
    content: "";
}

.grammar-page .grammar-topic-row {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: center;
    gap: 16px;
    padding: 20px;
    border: 1px solid #dce5f3;
    border-radius: 14px;
    background: #fff;
    color: #193350;
    text-decoration: none;
    transition:
        background .2s,
        border-color .2s,
        box-shadow .2s,
        transform .2s;
}

.grammar-page .grammar-topic-row:hover,
.grammar-page .grammar-topic-row:focus-visible {
    background: #fafdff;
    border-color: #92b1ee;
    box-shadow: 0 7px 20px rgba(40, 82, 152, .08);
    transform: translateY(-1px);
    outline: none;
}

/* Số thứ tự */

.grammar-topic-number {
    flex: 0 0 36px;
    width: 36px;
    color: #2860b8;
    font-size: 19px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

/* Biểu tượng A */

.grammar-topic-icon {
    display: flex;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #eaf3ff;
    color: #2275bf;
    font-size: 19px;
    font-weight: 800;
}

.grammar-topic-icon svg {
    width: 22px;
    height: 22px;
}

.grammar-topic-list li:nth-child(4n+2) .grammar-topic-icon {
    background: #ecf9f4;
    color: #18836b;
}

.grammar-topic-list li:nth-child(4n+3) .grammar-topic-icon {
    background: #fff3e7;
    color: #bd662c;
}

.grammar-topic-list li:nth-child(4n) .grammar-topic-icon {
    background: #f1ecff;
    color: #7950bc;
}

/* Tên và mô tả */

.grammar-page .grammar-topic-copy {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    gap: 5px;
}

.grammar-topic-name {
    color: #193451;
    font-size: 17px;
    font-weight: 800;
    line-height: 1.4;
}

.grammar-topic-summary {
    display: inline-flex;
    width: fit-content;
    max-width: 100%;
    padding: 5px 10px;
    border-radius: 8px;
    background: #E8F7EE;
    color: #237A4B;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
}

.grammar-topic-arrow {
    flex: 0 0 auto;
    margin-left: auto;
    color: #3971d4;
    font-size: 30px;
    line-height: 1;
}

/* Phân trang */

.grammar-page .grammar-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 9px;
    margin-top: 26px;
}

.grammar-pagination a,
.grammar-pagination span {
    display: inline-flex;
    min-width: 36px;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    padding: 5px 10px;
    border: 1px solid #dce5f2;
    border-radius: 9px;
    background: #fff;
    color: #3560ba;
    text-decoration: none;
}

.grammar-pagination a[aria-current="page"] {
    background: #315cce;
    color: #fff;
    border-color: #315cce;
}

/* =========================================
   TRANG CHI TIẾT – MỤC LỤC + BÀI ĐỌC
   ========================================= */

.grammar-back-link {
    display: inline-flex;
    margin-bottom: 16px;
    color: #315fce;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}

.grammar-topic-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 20px;
}

.grammar-topic-nav a {
    padding: 11px 19px;
    border: 1px solid #d3dff5;
    border-radius: 11px;
    background: #fff;
    color: #31549a;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.grammar-topic-nav a[aria-current="page"] {
    background: #2f5fe0;
    border-color: #2f5fe0;
    color: #fff;
}

/* Chia hai cột */

.grammar-page .grammar-reader {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: flex-start;
    gap: 24px;
}

/* Mục lục bên trái */

.grammar-page .grammar-toc {
    flex: 0 0 255px;
    width: 255px;
    max-width: 255px;
    min-width: 0;
    position: sticky;
    top: 110px;
    max-height: calc(100vh - 130px);
    overflow-y: auto;
    padding: 16px;
    border: 1px solid #dce5f2;
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 5px 20px rgba(24, 54, 103, .04);
}

.grammar-page .grammar-toc summary {
    cursor: pointer;
    color: #203d65;
    font-size: 14px;
    font-weight: 800;
}

.grammar-page .grammar-toc ol {
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

.grammar-page .grammar-toc li {
    margin: 2px 0;
    list-style: none;
}

.grammar-page .grammar-toc li a {
    display: block;
    padding: 8px 10px;
    border-radius: 8px;
    color: #4f617e;
    font-size: 13px;
    line-height: 1.45;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.grammar-page .grammar-toc li.grammar-toc-level-3 a {
    padding-left: 22px;
    font-size: 12.5px;
}

.grammar-page .grammar-toc li a:hover,
.grammar-page .grammar-toc li a[aria-current="location"] {
    background: #e9e7ff;
    color: #5935cb;
}

/* Nội dung bên phải */

.grammar-page .grammar-article {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
    padding: 30px;
    border: 1px solid #dce6f5;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 10px 30px rgba(32, 67, 132, .04);
}

.grammar-page .grammar-article-header {
    margin-bottom: 24px;
    padding-bottom: 22px;
    border-bottom: 1px solid #e5ebf4;
}

.grammar-page .grammar-article-header .section-label {
    display: inline-block;
    margin-bottom: 8px;
    color: #2f64ce;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
}

.grammar-page .grammar-article-header h1 {
    margin: 0 0 10px;
    color: #173151;
    font-size: 32px;
    line-height: 1.25;
}

.grammar-page .grammar-article-description {
    color: #60728d;
    font-size: 15px;
    line-height: 1.7;
}

.grammar-page .grammar-article-body {
    min-width: 0;
    overflow-wrap: anywhere;
}

.grammar-page .grammar-section-heading {
    scroll-margin-top: 110px;
}

.grammar-page .grammar-article-body h2.grammar-section-heading {
    margin: 30px 0 14px;
    color: #2254b4;
    font-size: 22px;
}

.grammar-page .grammar-article-body h3.grammar-section-heading {
    margin: 22px 0 12px;
    color: #203a5f;
    font-size: 17px;
}

/* =========================================
   CÁC KHUNG MÀU KIẾN THỨC
   ========================================= */

.grammar-page .grammar-block,
.grammar-page .grammar-summary,
.grammar-page .grammar-illustration {
    margin: 14px 0;
}

.grammar-page .grammar-callout {
    padding: 18px 20px;
    border: 1px solid #d8c4ff;
    border-radius: 12px;
    background: #f4edff;
}

/* Định nghĩa: tím */
/* Ví dụ: cam */
.grammar-page .grammar-callout--example,
.grammar-page .grammar-callout--bilingual {
    background: #fff4e8;
    border-color: #f5d0aa;
}

/* Công thức: xanh */
.grammar-page .grammar-callout--formula {
    background: #ebf3ff;
    border-color: #bed4fa;
}

/* Mẹo: xanh lá */
.grammar-page .grammar-callout--tip {
    background: #eaf8f2;
    border-color: #ade2c8;
}

/* Lưu ý: đỏ pastel */
.grammar-page .grammar-callout--note {
    background: #fff1f2;
    border-color: #f4b6be;
}

.grammar-page .grammar-callout .grammar-block-label {
    display: block;
    margin: 0 0 10px;
    padding: 4px 9px;
    border-radius: 6px;
    background: #e8d9ff;
    color: #632c9b;
    font-size: 13px;
    font-weight: 800;
}

.grammar-page .grammar-callout--example .grammar-block-label,
.grammar-page .grammar-callout--bilingual .grammar-block-label {
    background: #ffdfc2;
    color: #95521d;
}

.grammar-page .grammar-callout--formula .grammar-block-label {
    background: #d5e5ff;
    color: #245ab2;
}

.grammar-page .grammar-callout--tip .grammar-block-label {
    background: #cfefe1;
    color: #176b4c;
}

.grammar-page .grammar-callout--note .grammar-block-label {
    background: #ffd9de;
    color: #a5273d;
}

.grammar-page .grammar-prose {
    line-height: 1.75;
    color: #273c59;
    overflow-wrap: anywhere;
}

.grammar-page .grammar-prose p {
    margin: 0 0 10px;
}

.grammar-page .grammar-prose p:last-child {
    margin-bottom: 0;
}

.grammar-page .grammar-prose ul,
.grammar-page .grammar-prose ol {
    margin: 8px 0;
    padding-left: 22px;
}

/* Grouped topic theory keeps one label and a compact, continuous reading flow. */
.grammar-page .grammar-reader--main-topic .grammar-callout {
    padding: 14px 17px;
    margin: 12px 0;
}

.grammar-page .grammar-callout .grammar-prose > :first-child {
    margin-top: 0;
}

.grammar-page .grammar-callout .grammar-prose > :last-child {
    margin-bottom: 0;
}

.grammar-page .grammar-reader--main-topic .grammar-prose li > p {
    margin: 0;
}

.grammar-page .grammar-reader--main-topic .grammar-prose li + li {
    margin-top: 3px;
}

.grammar-page .grammar-reader--main-topic .grammar-callout--example .grammar-prose > p + p,
.grammar-page .grammar-reader--main-topic .grammar-callout--bilingual .grammar-prose > p + p,
.grammar-page .grammar-reader--main-topic .grammar-callout--example .grammar-prose li + li,
.grammar-page .grammar-reader--main-topic .grammar-callout--bilingual .grammar-prose li + li {
    margin-top: 12px;
}

.grammar-page .grammar-reader--main-topic .grammar-translation {
    margin-top: 8px;
}

.grammar-page .grammar-reader--main-topic .grammar-translation-label {
    display: block;
    margin-bottom: 3px;
    font-size: 12px;
    font-weight: 700;
    color: #60728d;
}

/* Bảng tổng hợp và ảnh */

.grammar-page .grammar-summary {
    padding: 16px;
    border: 1px solid #d7e5fb;
    border-radius: 12px;
    background: #f4f8ff;
}

.grammar-page .grammar-summary h2 {
    margin: 0 0 12px;
    color: #244f98;
}

.grammar-page .grammar-summary img,
.grammar-page .grammar-illustration img,
.grammar-page .grammar-summary-gallery img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 10px;
}

.grammar-quick-import .grammar-import-source-image {
    display: block;
    max-width: min(100%, 560px);
    max-height: 360px;
    height: auto;
    margin: 10px 0;
    object-fit: contain;
}

.grammar-import-image-preview {
    display: block;
    max-width: min(100%, 560px);
    max-height: 360px;
    height: auto;
    margin: 10px 0;
    object-fit: contain;
}

.grammar-page .grammar-summary-gallery {
    margin-top: 30px;
    padding: 18px;
    border: 1px solid #d7e5fb;
    border-radius: 14px;
    background: #f4f8ff;
}

.grammar-page .grammar-summary-gallery h2 {
    margin: 0 0 16px;
    color: #244f98;
    font-size: 19px;
    letter-spacing: .04em;
}

.grammar-page .grammar-summary-gallery-grid {
    display: grid;
    gap: 16px;
}

.grammar-page .grammar-summary-gallery .grammar-summary-image-link {
    display: block;
    width: fit-content;
    max-width: 100%;
    margin-inline: auto;
}

.grammar-page .grammar-summary-gallery img {
    width: auto;
    object-fit: contain;
}

.grammar-page .grammar-summary-table,
.grammar-page .grammar-table-scroll {
    max-width: 100%;
    overflow-x: auto;
}

.grammar-page table {
    width: 100%;
    border-collapse: collapse;
}

.grammar-page th,
.grammar-page td {
    padding: 10px;
    border: 1px solid #dbe5f4;
    text-align: left;
}

.grammar-page th {
    background: #eaf2ff;
}

/* Giữ màn hình chọn 12 thì */

.grammar-page .grammar-reader.grammar-reader--chapter-home {
    display: block;
}

.grammar-page .grammar-reader--chapter-home .grammar-toc {
    display: none !important;
}

.grammar-page .grammar-reader--chapter-home .grammar-article {
    width: 100%;
    max-width: none;
}

.grammar-page .grammar-tense-chooser {
    max-width: 100%;
}

/* =========================================
   RESPONSIVE
   ========================================= */

@media (max-width: 980px) {
    .grammar-page .grammar-reader {
        flex-direction: column;
    }

    .grammar-page .grammar-toc {
        position: static;
        width: 100%;
        max-width: none;
        flex: none;
        max-height: none;
    }

    .grammar-page .grammar-article {
        width: 100%;
        flex: none;
    }
}

@media (max-width: 640px) {
    .grammar-page .grammar-catalog {
        padding: 16px;
    }

    .grammar-catalog-heading {
        flex-direction: column;
    }

    .grammar-page .grammar-topic-row {
        gap: 10px;
        padding: 14px 12px;
    }

    .grammar-topic-number {
        width: 26px;
        flex-basis: 26px;
        font-size: 15px;
    }

    .grammar-topic-icon {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
        font-size: 16px;
    }

    .grammar-topic-name {
        font-size: 15px;
    }

    .grammar-topic-summary {
        font-size: 12px;
    }

    .grammar-page .grammar-article {
        padding: 16px;
    }

    .grammar-page .grammar-callout {
        padding: 14px;
    }
}

/* =========================================
   DARK MODE
   ========================================= */

html[data-theme="dark"] .grammar-page .grammar-catalog,
html[data-theme="dark"] .grammar-page .grammar-article,
html[data-theme="dark"] .grammar-page .grammar-toc {
    background: #172338;
    border-color: #34445f;
}

html[data-theme="dark"] .grammar-page .grammar-topic-row,
html[data-theme="dark"] .grammar-pagination a,
html[data-theme="dark"] .grammar-topic-nav a:not([aria-current="page"]) {
    background: #202d43;
    border-color: #40516b;
}

html[data-theme="dark"] .grammar-catalog-heading h2,
html[data-theme="dark"] .grammar-topic-name,
html[data-theme="dark"] .grammar-page .grammar-article-header h1,
html[data-theme="dark"] .grammar-page .grammar-toc summary {
    color: #eef4ff;
}

html[data-theme="dark"] .grammar-page .grammar-prose {
    color: #d7e1f1;
}

html[data-theme="dark"] .grammar-page .grammar-callout {
    background: #312447;
    border-color: #664b88;
}

html[data-theme="dark"] .grammar-page .grammar-callout--example,
html[data-theme="dark"] .grammar-page .grammar-callout--bilingual {
    background: #3d2d25;
    border-color: #816348;
}

html[data-theme="dark"] .grammar-page .grammar-callout--formula {
    background: #20344d;
    border-color: #47698b;
}

html[data-theme="dark"] .grammar-page .grammar-callout--tip {
    background: #1b3b32;
    border-color: #396b59;
}

html[data-theme="dark"] .grammar-page .grammar-callout--note {
    background: #413925;
    border-color: #75633a;
}


/* Grammar - danh sách bài học con */

.grammar-sublesson-catalog {
    padding: 28px;
    border: 1px solid #dce5f6;
    border-radius: 18px;
    background: #f5f8ff;
}

.grammar-sublesson-catalog h2 {
    margin: 0 0 8px;
    color: #17355f;
}

.grammar-sublesson-catalog > p {
    margin: 0 0 22px;
    color: #61738e;
}

.grammar-sublesson-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.grammar-sublesson-list li {
    list-style: none;
}

.grammar-sublesson-list a {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    border: 1px solid #d8e4f6;
    border-radius: 13px;
    background: #fff;
    color: #1c385f;
    text-decoration: none;
    transition: background .2s, border-color .2s;
}

.grammar-sublesson-list a:hover,
.grammar-sublesson-list a:focus-visible {
    background: #edf4ff;
    border-color: #779ced;
}

.grammar-sublesson-list strong {
    flex: 1;
}

.grammar-sublesson-number {
    display: inline-flex;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    background: #e9f0ff;
    color: #315ed2;
    font-weight: 800;
}

@media (max-width: 640px) {
    .grammar-sublesson-catalog {
        padding: 15px;
    }

    .grammar-sublesson-list a {
        padding: 14px;
        gap: 10px;
    }
}
