/* --- RESET & BACKGROUND --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    background-color: var(--bg);
    /*background-image: radial-gradient(#d1d1d1 1px, transparent 1px);*/
    background-size: 24px 24px;
    min-height: 100vh;
     padding: 20px 20px;
}


/* --- MATH HEADER (BLUE BACKGROUND) --- */
.math-header {
    background-color: var(--text-color);
    color: white;
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}



.page-title h2 {
    font-size: 40px;
    font-weight: 400;
    color: var(--text-color);
}


/* --- LAYOUT GRID (LEFT CONTENT + RIGHT STICKY SIDEBAR) --- */
.main-container {
    width: min(1600px, calc(100% - 40px));
    margin: 30px auto;
    padding: 0;

    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 50px;

    align-items: start;
}

.content-left {
    min-width: 0;
}

.sidebar-right {
    min-width: 0;
}

/* --- GENERAL SECTION TITLES --- */
.section-title {
    font-size: 32px;
    color: var(--text-color);
    font-family: 'Georgia', serif;
    position: relative;
    padding-bottom: 5px;
    display: inline-block;
}

/* Đường gạch chân dưới tiêu đề */
.section-title::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 3px;
    background-color: #4a7bb0;
}

/* --- SECTION 1: READING --- */
.section-reading {
    margin-bottom: 50px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.btn-more {
    background: #fff;
    border: 1px solid #4a7bb0;
    color: #4a7bb0;
    padding: 4px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.reading-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.reading-card {
    background-color: var(--card-bg);
    border-radius: 24px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;


    border: 1px solid var(--card-border);

    gap: 12px;

    /* Dùng biến shadow ở đây */
    box-shadow: var(--card-shadow);

    /* Chỉ nên transition các thuộc tính cần thiết để tối ưu hiệu năng */
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
    box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
    background-color 0.3s ease,
    border-color 0.3s ease;
}

.reading-card .image-placeholder {
    background: #fff;
    width: 100%;
    height: 180px;
    border-radius: 16px;
    overflow: hidden;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    color: #333;
    margin-bottom: 15px;
}
/* 2. Ép tấm ảnh chui tọt vào trong khung chứa */
.reading-card .image-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: cover;       /* Tự động co giãn & cắt ảnh vừa khít khung mà KHÔNG BỊ MÓM/MÉO */
    object-position: center; /* Căn giữa tấm ảnh */
    display: block;
}

.reading-card .article-title {
    font-size: 19px;
    text-align: center;
    color: var(--text-color);
}

.reading-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* --- SECTION 2: TOOLBOX & SEARCH --- */
.toolbox-header-flex {
    justify-content: space-between;
    align-items: flex-end;
}

.search-box input {
    border: 1.5px solid #4a7bb0;
    border-radius: 6px;
    padding: 6px 12px;
    width: 250px;
    font-size: 15px;
    outline: none;
    background-color: var(--card-bg);
    color: var(--text-color);
}

/* Toolbox Grid chia làm 4 cột (tự rơi xuống hàng khi có nhiều item) */
.toolbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    row-gap: 22px;
}

.tool-card {
    position: relative;
    background-color: var(--card-bg);
    border-radius: 16px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 15px;
    /*height: 20%;
    max-height: 300px;*/
    /*transition: transform 0.2s ease, box-shadow 0.2s ease;*/


    border: 1px solid var(--card-border);

    gap: 12px;

    /* Dùng biến shadow ở đây */
    box-shadow: var(--card-shadow);

    /* Chỉ nên transition các thuộc tính cần thiết để tối ưu hiệu năng */
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
    box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
    background-color 0.3s ease,
    border-color 0.3s ease;
}

.tool-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.tool-card.hidden {
    display: none;
}

.tool-card .custom-link::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1; /* This invisibly stretches the clickable link over the whole card */
}

.tool-img {
    background: rgba(0, 0, 0, 0.0);
    width: 45px;
    height: auto;
    min-width: 45px;
    border-radius: 8px;
    display: block;
    justify-content: center;
    align-items: center;
    font-size: 9px;
    text-align: center;
    color: rgba(0, 0, 0, 0.0);
}

.tool-img img {
    max-width: 100%;
    max-height: 100%;
    height: auto;
    display: block; /* Removes unwanted bottom whitespace */
}



.tool-card .custom-link {
    color: var(--text-color);            /* Inherit the text color from the h3 parent */
    text-decoration: none;     /* Remove the default underline */
    display: inline-block;     /* Allows for proper padding and click area mapping */
}
.tool-card .custom-link:hover {
    text-decoration: underline; /* Bring back the underline on hover */
    color: #007bff;            /* Change color on hover if desired */
}

.card-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    font-size: 13px;
}

.cicon {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    font-size: 13px;
}


.tool-info h3 {
    font-size: 18px;
    color: #222;
}

.tool-info p {
    font-size: 14px;
    color: var(--text-color);
}

/* --- SIDEBAR CỐ ĐỊNH KHI SCROLL (STICKY) --- */
.sidebar-right {
    position: relative;
    height: 100%; /* Cần thiết để bám theo cột chính */
}

.sticky-wrapper {
    position: sticky;
    top: 50px; /* Cách mép trên màn hình 20px khi scroll */
    border-radius: 24px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;

    background-color: var(--card-bg);
    /*height: 20%;
     m ax-height: 300px;*/
     /*transition: transform 0.2s ease, box-shadow 0.2s ease;*/


     border: 1px solid var(--card-border);
     /* Dùng biến shadow ở đây */
     box-shadow: var(--card-shadow);

     /* Chỉ nên transition các thuộc tính cần thiết để tối ưu hiệu năng */
     transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
     box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
     background-color 0.3s ease,
     border-color 0.3s ease;
}

.ad-box, .extra-box {
    background: #fff;
    border-radius: 16px;
    padding: 35px 20px;
    text-align: center;
    font-size: 18px;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-box { min-height: 120px; }
.extra-box { min-height: 200px; }
/* ==========================================
 *  SIDEBAR
 *  ========================================== */

.article-layout .sidebar-right {
    min-width: 0;
}

.article-layout .sticky-wrapper {
    position: sticky;
    top: 30px;

    padding: 20px;

    display: flex;
    flex-direction: column;

    gap: 20px;

    border-radius: 22px;

    background: var(--card-bg);

    border: 1px solid var(--card-border);

    box-shadow: var(--card-shadow);
}


/* ==========================================
 *  AD
 *  ========================================== */

.article-layout .ad-box {
    min-height: 130px;

    display: flex;

    align-items: center;
    justify-content: center;

    border-radius: 15px;

    background: var(--bg);

    color: var(--text-color);
}


/* ==========================================
 *  EXTRA BOX
 *  ========================================== */

.article-layout .extra-box {
    min-height: 220px;

    display: flex;

    align-items: center;
    justify-content: center;

    border-radius: 15px;

    background: var(--bg);

    color: var(--text-color);
}

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

@media (max-width: 1100px) {

    .main-container {
        width: min(100% - 30px, 1000px);
        grid-template-columns: minmax(0, 1fr) 280px;
        gap: 30px;
    }

    .reading-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}


@media (max-width: 800px) {

    body {
        padding: 15px;
    }

    .main-container {
        width: 100%;
        margin: 20px auto;

        grid-template-columns: 1fr;
        gap: 30px;
    }

    .reading-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sidebar-right {
        order: 2;
    }

    .sticky-wrapper {
        position: static;
    }
}


@media (max-width: 550px) {

    body {
        padding: 12px;
    }

    .main-container {
        width: 100%;
        margin-top: 15px;
    }

    .reading-grid {
        grid-template-columns: 1fr;
    }

    .section-header {
        flex-wrap: wrap;
    }

    .toolbox-header-flex {
        align-items: flex-start;
    }

    .search-box {
        width: 100%;
    }

    .search-box input {
        width: 100%;
    }

    .reading-card {
        padding: 15px;
        border-radius: 20px;
    }

    .reading-card .image-placeholder {
        height: 200px;
    }

    .sidebar-right {
        width: 100%;
    }

    .sticky-wrapper {
        padding: 15px;
    }
}

.reading-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.reading-card-link:hover {
    text-decoration: none;
}

/* ==========================================
 * MOBILE SETTINGS TOGGLE
 * ========================================== */

.mobile-settings-toggle {
    display: none;
}

@media (max-width: 600px) {

    .mobile-settings-toggle {
        position: fixed;
        right: 16px;
        bottom: 16px;

        width: 48px;
        height: 48px;

        display: flex;
        align-items: center;
        justify-content: center;

        border: 1px solid var(--card-border);
        border-radius: 14px;

        background: var(--card-bg);
        color: var(--text-color);

        box-shadow: var(--card-shadow);

        font-size: 28px;
        cursor: pointer;

        z-index: 9998;

        transition:
        transform 0.2s ease,
        background-color 0.2s ease;
    }

    .mobile-settings-toggle:hover {
        transform: translateY(-2px);
    }

    .mobile-settings-toggle:active {
        transform: scale(0.92);
    }
}


/* ==========================================
 * MOBILE FLOATING PANEL
 * ========================================== */

@media (max-width: 600px) {

    .floating-panel {
        position: fixed !important;

        right: 16px !important;
        bottom: 76px !important;

        top: auto !important;
        left: auto !important;

        z-index: 9997 !important;

        opacity: 0;
        visibility: hidden;
        pointer-events: none;

        transform: translateY(10px);

        transition:
        opacity 0.2s ease,
        transform 0.2s ease,
        visibility 0.2s ease;
    }

    .floating-panel.mobile-open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;

        transform: translateY(0);
    }
}
