/* ============================================================
   KHO HỌC LIỆU TOÁN LỚP 4
   GIAO DIỆN: 1648 × 928
============================================================ */

:root {
    --design-width: 1648;
    --design-height: 928;

    --ratio: 1.775862069;

    --blue: #0759b8;
    --dark-blue: #083e88;
    --green: #169447;
    --purple: #7138bd;
    --orange: #f59c00;
    --text: #193c59;

    font-family:
        "Segoe UI",
        Arial,
        Helvetica,
        sans-serif;

    color-scheme: light;

    font-synthesis: none;

    -webkit-tap-highlight-color: transparent;
}


/* ============================================================
   RESET
============================================================ */

*,
*::before,
*::after {
    box-sizing: border-box;
}


html,
body {
    width: 100%;
    height: 100%;

    margin: 0;
    padding: 0;

    overflow: hidden;
}


html {
    background: #dff6ff;
}


body {
    min-width: 320px;

    background: #dff6ff;

    color: var(--text);
}


button,
input {
    font: inherit;
}


button {
    touch-action: manipulation;
}


/* ============================================================
   ACCESSIBILITY
============================================================ */

.sr-only {
    position: absolute !important;

    width: 1px !important;
    height: 1px !important;

    padding: 0 !important;
    margin: -1px !important;

    overflow: hidden !important;

    clip: rect(0, 0, 0, 0) !important;

    white-space: nowrap !important;

    border: 0 !important;
}


/* ============================================================
   TOÀN MÀN HÌNH
============================================================ */

.home {
    position: fixed;

    inset: 0;

    width: 100vw;
    height: 100vh;
    height: 100dvh;

    overflow: hidden;

    background: #dff6ff;
}


/* ============================================================
   COVER-STAGE

   Đây là điểm quan trọng nhất.

   KHÔNG dùng:
   width:min(...)

   Mà dùng:
   width:max(...)

   Ý nghĩa:
   - nếu màn hình rộng → lấy chiều rộng màn hình;
   - nếu màn hình cao → phóng theo chiều cao;
   - ảnh luôn phủ hết viewport;
   - stage giữ nguyên tỷ lệ 1648:928;
   - hotspot nằm trong stage nên không bao giờ lệch ảnh.

   Trên màn hình khác tỷ lệ ảnh, phần thừa sẽ bị crop
   ở hai bên hoặc trên/dưới. Đây là cơ chế giống
   background-size: cover.
============================================================ */

.site-shot {
    position: absolute;

    z-index: 1;

    left: 50%;
    top: 50%;

    width:
        max(
            100vw,
            calc(
                100dvh * var(--ratio)
            )
        );

    aspect-ratio: 1648 / 928;

    transform:
        translate(
            -50%,
            -50%
        );

    overflow: hidden;

    isolation: isolate;
}


/* ============================================================
   ẢNH
============================================================ */

.site-shot__image {
    position: absolute;

    inset: 0;

    z-index: 1;

    display: block;

    width: 100%;
    height: 100%;

    object-fit: fill;

    object-position: center;

    pointer-events: none;

    user-select: none;

    -webkit-user-drag: none;
}


/* ============================================================
   LỚP BUTTON

   Chính xác bằng kích thước site-shot.
============================================================ */

.click-layer {
    position: absolute;

    z-index: 5;

    inset: 0;

    width: 100%;
    height: 100%;

    pointer-events: none;
}


/* ============================================================
   HOTSPOT
============================================================ */

.hotspot {
    position: absolute;

    z-index: 10;

    display: block;

    padding: 0;
    margin: 0;

    border: 0;

    border-radius: 10px;

    background: transparent;

    cursor: pointer;

    pointer-events: auto;

    outline: none;

    -webkit-tap-highlight-color: transparent;

    transition:
        background-color 150ms ease,
        box-shadow 150ms ease;
}


.hotspot:hover {
    background:
        rgba(
            255,
            255,
            255,
            0.10
        );

    box-shadow:
        inset
        0
        0
        0
        2px
        rgba(
            15,
            102,
            178,
            0.18
        );
}


.hotspot-nav {
    border-radius: 9px;
}


.hotspot-card {
    border-radius: 22px;
}


.hotspot-card:hover {
    background:
        rgba(
            255,
            255,
            255,
            0.08
        );

    box-shadow:
        inset
        0
        0
        0
        3px
        rgba(
            255,
            255,
            255,
            0.42
        );
}


.hotspot:focus-visible {
    outline:
        3px solid
        #ffb000;

    outline-offset: -3px;
}


/* ============================================================
   NHÃN ĐỘNG CHỦ ĐỀ / BÀI GIẢNG

   Icon của ảnh nằm bên trái.

   Lớp này chỉ phủ phần chữ:
   "Chủ đề" → "Chủ đề 10"
   "Bài giảng" → "Bài 58"
============================================================ */

.hotspot-menu {
    overflow: visible;
}


.dynamic-menu-label {
    position: absolute;

    z-index: 20;

    left: 38%;
    right: 1%;

    top: 7%;
    bottom: 7%;

    display: flex;

    align-items: center;
    justify-content: center;

    padding:
        2px
        3px;

    border-radius: 6px;

    /*
       Gần màu nền thanh điều hướng trong ảnh.
       Chỉ che chữ cũ, không che icon.
    */

    background:
        linear-gradient(
            180deg,
            rgba(247, 252, 255, 0.995),
            rgba(232, 247, 254, 0.995)
        );

    color: #073f90;

    font-size:
        clamp(
            9px,
            1vw,
            17px
        );

    font-weight: 900;

    line-height: 1;

    white-space: nowrap;

    text-align: center;

    pointer-events: none;

    box-shadow: none;
}


.dynamic-menu-label[hidden] {
    display: none !important;
}


/*
   Chừa riêng vùng icon cho từng nút.
*/

#topicMenuLabel {
    left: 40%;
}


#lessonMenuLabel {
    left: 39%;
}


#topicHotspot.has-selection,
#lessonHotspot.has-selection {
    background: transparent;
}


#topicHotspot.has-selection:hover,
#lessonHotspot.has-selection:hover {
    background:
        rgba(
            255,
            255,
            255,
            0.07
        );
}


/* ============================================================
   DIALOG
============================================================ */

.app-dialog {
    width:
        min(
            94vw,
            1000px
        );

    max-width: 1000px;

    max-height: 92dvh;

    padding: 0;

    border:
        1px solid
        #cce6f3;

    border-radius: 24px;

    background: #ffffff;

    color: #183c5d;

    overflow: hidden;

    box-shadow:
        0
        25px
        90px
        rgba(
            0,
            32,
            70,
            0.35
        );
}


.app-dialog::backdrop {
    background:
        rgba(
            5,
            30,
            65,
            0.62
        );

    backdrop-filter: blur(5px);

    -webkit-backdrop-filter: blur(5px);
}


.dialog-shell {
    display: flex;

    flex-direction: column;

    max-height: 92dvh;

    min-height: 210px;
}


.dialog-header {
    position: relative;

    flex: 0 0 auto;

    padding:
        20px
        70px
        18px
        25px;

    border-bottom:
        1px solid
        #d8eaf3;

    background:
        linear-gradient(
            110deg,
            #eefaff,
            #edf8ff,
            #f4fdf0
        );
}


.dialog-heading-wrap {
    min-width: 0;
}


.dialog-title {
    margin: 0;

    color: #073f8a;

    font-size:
        clamp(
            21px,
            3vw,
            30px
        );

    line-height: 1.3;

    font-weight: 900;
}


.dialog-subtitle {
    margin:
        6px
        0
        0;

    color: #58758c;

    font-size: 13px;

    line-height: 1.5;
}


.dialog-close {
    /*
    BẮT BUỘC:
    đặt nút theo góc của dialog-header
    */
    position: absolute;

    top: 14px;
    right: 16px;

    z-index: 20;

    width: 50px;
    height: 50px;

    padding: 0;
    margin: 0;

    display: grid;
    place-items: center;

    border: 0;

    background: transparent;

    cursor: pointer;

    /*
    Không cho nút bị ảnh hưởng
    bởi flex của header
    */
    flex: none;

    transform-origin: center;

    transition:
        transform 160ms ease,
        filter 160ms ease;
}


.dialog-close:hover {
    transform:
        scale(1.10)
        rotate(-5deg);

    filter:
        drop-shadow(
            0 6px 8px
            rgba(187, 0, 0, 0.28)
        );
}


.dialog-close:active {
    transform:
        scale(0.90)
        rotate(3deg);
}


.dialog-close:focus-visible {
    outline:
        3px solid
        rgba(35, 132, 255, 0.35);

    outline-offset: 3px;

    border-radius: 14px;
}


.dialog-close__icon {
    display: block;

    width: 46px;
    height: 46px;

    pointer-events: none;

    user-select: none;
}


/* ============================================================
   MOBILE
============================================================ */

@media (max-width: 520px) {

    .dialog-close {
        top: 10px;
        right: 10px;

        width: 46px;
        height: 46px;
    }


    .dialog-close__icon {
        width: 41px;
        height: 41px;
    }

}


.dialog-close:hover {
    background: #fff0f3;

    color: #c42d55;
}


.dialog-body {
    flex: 1;

    min-height: 150px;

    padding: 24px;

    overflow-y: auto;

    overscroll-behavior: contain;
}


/* ============================================================
   INTRO
============================================================ */

.intro {
    margin:
        0
        0
        20px;

    color: #536c80;

    font-size: 15px;

    line-height: 1.7;
}


/* ============================================================
   CHỦ ĐỀ
============================================================ */

.topic-grid {
    display: grid;

    grid-template-columns:
        repeat(
            3,
            minmax(0, 1fr)
        );

    gap: 13px;
}


.topic-button {
    min-height: 122px;

    padding: 16px;

    border:
        1px solid
        #d4e7f1;

    border-radius: 18px;

    background: #ffffff;

    color: #164c7b;

    cursor: pointer;

    text-align: left;

    transition:
        transform 140ms ease,
        box-shadow 140ms ease,
        border-color 140ms ease;
}


.topic-button:hover {
    transform:
        translateY(-2px);

    border-color: #73bde1;

    box-shadow:
        0
        8px
        22px
        rgba(
            14,
            81,
            127,
            0.12
        );
}


.topic-button.is-selected {
    border:
        2px solid
        #22a463;

    background: #effcf3;
}


.topic-number {
    display: inline-grid;

    place-items: center;

    width: 38px;
    height: 38px;

    margin-bottom: 10px;

    border-radius: 50%;

    background: #e9f6ff;

    color: #0863ad;

    font-weight: 900;
}


.topic-button.is-selected
.topic-number {
    background: #1a9e5e;

    color: #ffffff;
}


.topic-button strong {
    display: block;

    color: #164c7b;

    font-size: 15px;

    font-weight: 850;

    line-height: 1.42;
}


.topic-button small {
    display: block;

    margin-top: 7px;

    color: #748b9d;

    font-size: 12px;
}


/* ============================================================
   BÀI HỌC
============================================================ */

.lesson-list {
    display: grid;

    grid-template-columns:
        repeat(
            2,
            minmax(0, 1fr)
        );

    gap: 11px;
}


.lesson-button {
    width: 100%;

    display: flex;

    align-items: center;

    gap: 12px;

    padding: 13px;

    border:
        1px solid
        #d9e7ef;

    border-radius: 14px;

    background: #ffffff;

    color: #28506f;

    cursor: pointer;

    text-align: left;
}


.lesson-button:hover {
    border-color: #72b9db;

    background: #f1faff;
}


.lesson-button.is-selected {
    border:
        2px solid
        #15905b;

    background: #effbf3;
}


.lesson-number {
    flex:
        0 0 auto;

    width: 54px;
    height: 50px;

    display: grid;

    place-items: center;

    border-radius: 13px;

    background: #e8f5ff;

    color: #0761ae;

    font-size: 13px;

    font-weight: 900;
}


.lesson-button.is-selected
.lesson-number {
    background: #16955d;

    color: #ffffff;
}


.lesson-name {
    font-size: 14px;

    line-height: 1.45;

    font-weight: 750;
}


/* ============================================================
   PANEL
============================================================ */

.panel {
    margin:
        17px
        0;

    padding: 18px;

    border:
        1px solid
        #d9eaf3;

    border-radius: 17px;

    background: #f5fbff;
}


.panel-green {
    border-color: #d0ead6;

    background: #f1fbf3;
}


.panel-yellow {
    border-color: #f0ddaa;

    background: #fff9e9;
}


.panel-purple {
    border-color: #ded0f3;

    background: #f7f2ff;
}


.panel h3 {
    margin:
        0
        0
        12px;

    color: #164d7b;

    font-size: 17px;
}


.panel p {
    margin:
        8px
        0;

    line-height: 1.65;
}


/* ============================================================
   VIDEO
============================================================ */

.video-frame {
    display: block;

    width: 100%;

    aspect-ratio: 16 / 9;

    border: 0;

    border-radius: 15px;

    background: #0b1720;
}


.video-player {
    display: block;

    width: 100%;

    max-height: 570px;

    border-radius: 15px;

    background: #000000;
}


/* ============================================================
   KIẾN THỨC
============================================================ */

.knowledge-list {
    margin: 0;

    padding-left: 22px;

    line-height: 1.75;
}


.knowledge-list li {
    margin:
        8px
        0;
}


/* ============================================================
   RESOURCE
============================================================ */

.resource-grid {
    display: grid;

    grid-template-columns:
        repeat(
            3,
            minmax(0, 1fr)
        );

    gap: 13px;
}


.resource-card {
    padding: 17px;

    border:
        1px solid
        #dae8ef;

    border-radius: 17px;

    background: #ffffff;
}


.resource-card h3 {
    margin:
        0
        0
        8px;

    color: #17517e;

    font-size: 16px;
}


.resource-card p {
    color: #637b8c;

    font-size: 13px;

    line-height: 1.6;
}


.resource-status {
    margin:
        10px
        0;

    color: #768a99;

    font-size: 12px;
}


/* ============================================================
   BUTTON POPUP
============================================================ */

.btn {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    gap: 6px;

    min-height: 41px;

    padding:
        9px
        14px;

    border:
        1px solid
        transparent;

    border-radius: 11px;

    background: #0870bd;

    color: #ffffff;

    font-size: 13px;

    font-weight: 750;

    text-decoration: none;

    cursor: pointer;
}


.btn:hover {
    background: #075695;
}


.btn-green {
    background: #178c59;
}


.btn-green:hover {
    background: #106c45;
}


.btn-light {
    border-color: #cce3ef;

    background: #edf8fd;

    color: #135888;
}


.btn-light:hover {
    background: #dceff8;
}


.btn-purple {
    background: #7442bd;
}


.btn-purple:hover {
    background: #5d339b;
}


.btn-disabled {
    background: #e7ecef;

    color: #8a969e;

    cursor: not-allowed;
}


.btn-disabled:hover {
    background: #e7ecef;
}


.button-row {
    display: flex;

    flex-wrap: wrap;

    gap: 8px;

    margin-top: 12px;
}


/* ============================================================
   EMPTY STATE
============================================================ */

.empty-state {
    padding: 25px;

    border:
        2px dashed
        #ccdde6;

    border-radius: 16px;

    background: #f8fbfc;

    color: #688294;

    text-align: center;

    line-height: 1.7;
}


/* ============================================================
   STATUS
============================================================ */

.study-status {
    display: grid;

    grid-template-columns:
        repeat(
            2,
            minmax(0, 1fr)
        );

    gap: 12px;
}


.status-card {
    padding: 17px;

    border:
        1px solid
        #d9e7ef;

    border-radius: 16px;

    background: #ffffff;
}


.status-card strong {
    display: block;

    margin-bottom: 7px;

    color: #164e7b;
}


/* ============================================================
   SEARCH
============================================================ */

.search-box {
    width: 100%;

    padding:
        14px
        16px;

    border:
        2px solid
        #c9e0eb;

    border-radius: 14px;

    background: #f9fcfe;

    color: #173c56;

    font-size: 16px;
}


.search-box:focus {
    border-color: #379bd1;

    outline:
        3px solid
        rgba(
            55,
            155,
            209,
            0.17
        );
}


.search-results {
    display: grid;

    gap: 9px;

    margin-top: 15px;
}


.search-result {
    width: 100%;

    padding:
        13px
        15px;

    border:
        1px solid
        #dae8ef;

    border-radius: 12px;

    background: #ffffff;

    color: #1d5079;

    text-align: left;

    cursor: pointer;
}


.search-result:hover {
    background: #f0f9ff;
}


.search-result small {
    display: block;

    margin-top: 4px;

    color: #71889a;
}


/* ============================================================
   TOOLTIP
============================================================ */

.tooltip {
    position: fixed;

    z-index: 10000;

    width: max-content;

    max-width:
        min(
            390px,
            calc(100vw - 24px)
        );

    padding:
        10px
        14px;

    border:
        1px solid
        rgba(
            255,
            255,
            255,
            0.16
        );

    border-radius: 11px;

    background:
        rgba(
            7,
            55,
            105,
            0.97
        );

    color: #ffffff;

    box-shadow:
        0
        8px
        26px
        rgba(
            0,
            30,
            60,
            0.27
        );

    font-size: 13px;

    font-weight: 700;

    line-height: 1.5;

    text-align: center;

    pointer-events: none;

    opacity: 0;

    visibility: hidden;

    transform:
        translateY(4px);

    transition:
        opacity 120ms ease,
        transform 120ms ease,
        visibility 120ms ease;
}


.tooltip.visible {
    opacity: 1;

    visibility: visible;

    transform:
        translateY(0);
}


/* ============================================================
   TOAST
============================================================ */

.toast {
    position: fixed;

    z-index: 15000;

    left: 50%;

    bottom: 24px;

    transform:
        translate(
            -50%,
            15px
        );

    max-width:
        min(
            520px,
            calc(100vw - 30px)
        );

    padding:
        11px
        17px;

    border-radius: 999px;

    background:
        rgba(
            5,
            69,
            120,
            0.97
        );

    color: #ffffff;

    box-shadow:
        0
        10px
        30px
        rgba(
            0,
            30,
            65,
            0.25
        );

    font-size: 13px;

    font-weight: 700;

    text-align: center;

    opacity: 0;

    pointer-events: none;

    transition:
        opacity 200ms ease,
        transform 200ms ease;
}


.toast.visible {
    opacity: 1;

    transform:
        translate(
            -50%,
            0
        );
}


/* ============================================================
   IMAGE ERROR
============================================================ */

.image-error {
    position: fixed;

    z-index: 20000;

    left: 50%;
    top: 50%;

    transform:
        translate(
            -50%,
            -50%
        );

    width:
        min(
            520px,
            calc(100vw - 30px)
        );

    padding: 22px;

    border:
        2px solid
        #df5151;

    border-radius: 18px;

    background: #ffffff;

    color: #394b58;

    text-align: center;

    box-shadow:
        0
        16px
        50px
        rgba(
            0,
            0,
            0,
            0.25
        );
}


.image-error strong {
    display: block;

    margin-bottom: 10px;

    color: #bd2626;

    font-size: 19px;
}


/* ============================================================
   DEBUG

   Mở:
   index.html?debug=1

   Các hotspot sẽ chuyển sang màu đỏ.
============================================================ */

body.debug-hotspots
.hotspot {
    background:
        rgba(
            255,
            0,
            0,
            0.20
        ) !important;

    box-shadow:
        inset
        0
        0
        0
        2px
        rgba(
            255,
            0,
            0,
            0.88
        ) !important;
}


/* ============================================================
   RESPONSIVE POPUP
============================================================ */

@media (max-width: 800px) {

    .topic-grid {
        grid-template-columns:
            repeat(
                2,
                minmax(0, 1fr)
            );
    }


    .lesson-list,
    .resource-grid {
        grid-template-columns: 1fr;
    }


    .dialog-body {
        padding: 17px;
    }


    .dynamic-menu-label {
        font-size:
            clamp(
                7px,
                1.4vw,
                12px
            );
    }

}


@media (max-width: 520px) {

    .topic-grid,
    .study-status {
        grid-template-columns: 1fr;
    }


    .app-dialog {
        width: 96vw;

        border-radius: 18px;
    }


    .dialog-header {
        padding:
            17px
            60px
            15px
            17px;
    }

}


/* ============================================================
   FALLBACK KHI KHÔNG CÓ dvh
============================================================ */

@supports not (height: 100dvh) {

    .home {
        height: 100vh;
    }


    .site-shot {
        width:
            max(
                100vw,
                calc(
                    100vh * var(--ratio)
                )
            );
    }

}


/* ============================================================
   TOUCH
============================================================ */

@media (hover: none) {

    .hotspot:hover {
        background: transparent;

        box-shadow: none;
    }

}


/* ============================================================
   REDUCED MOTION
============================================================ */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        transition: none !important;

        scroll-behavior: auto !important;
    }

}