/* ============================================================
   PHẦN 1: CẤU TRÚC CHÍNH (WRAPPER, BOOK, PAGE, HOTSPOTS)
   ============================================================ */

/* Container chính */
.iaib-wrapper {
    position: relative; width: 100%; margin: 20px auto; max-width: 1000px;
    background: #f0f0f0; padding: 10px; border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    overflow: hidden; box-sizing: border-box;
    touch-action: pan-y; 
}

/* Khung Sách */
.iaib-book {
    width: 100%;
    aspect-ratio: 3 / 2; /* Tỷ lệ 2 trang */
    position: relative;
    background: #fff;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

/* Trang Sách */
.iaib-page {
    display: none; height: 100%; flex-shrink: 0;
    background-color: #fff;
    border-right: 1px solid #eee;
    box-sizing: border-box; position: relative;
    transition: opacity 0.3s ease;
}
.iaib-page.active { display: block; animation: iaibFadeIn 0.4s ease; }
@keyframes iaibFadeIn { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: translateX(0); } }

.iaib-page-content {
    width: 100%; height: 100%; position: relative; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
}

/* Ảnh nền */
.iaib-page-bg {
    width: 100%; height: 100%;
    object-fit: contain; object-position: center;
    pointer-events: none; user-select: none;
    position: absolute; top: 0; left: 0; z-index: 1;
}

/* SVG Layer */
.iaib-svg-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 10; pointer-events: auto;
}

/* --- HOTSPOTS (Vùng chọn) --- */
.iaib-hotspot {
    fill: transparent; stroke: transparent; cursor: pointer;
    transition: fill 0.2s, stroke 0.2s;
    vector-effect: non-scaling-stroke;
}
.iaib-hotspot:hover {
    stroke: rgba(255, 255, 255, 0.8); stroke-width: 2px;
    fill: rgba(255, 255, 255, 0.1);
}
.iaib-hotspot.active {
    fill: rgba(255, 235, 59, 0.3) !important;
    stroke: #fdd835 !important; stroke-width: 2px;
}

/* Tùy chỉnh Hotspot Info (Tàng hình) */
.iaib-hotspot.type-info { stroke: transparent; fill: transparent; pointer-events: auto; cursor: pointer; }
.iaib-page.show-info .iaib-hotspot.type-info:hover { stroke: transparent; fill: transparent; }

/* --- ICON INFO HTML (RESPONSIVE) --- */
.iaib-info-icon {
    position: absolute;
    width: clamp(18px, 4%, 30px); height: clamp(18px, 5%, 30px);
    font-size: clamp(14px, 2.5vw, 20px);
    border: 1.5px solid #333; border-radius: 50%;
    background: #fff; color: #333;
    font-weight: bold; font-family: "Times New Roman", serif; font-style: italic;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 20;
    transform: translate(-50%, -50%);
    opacity: 0; pointer-events: none; transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.iaib-info-icon::before { content: "i"; margin-top: -1px; }
.iaib-page.show-info .iaib-info-icon { opacity: 1; pointer-events: auto; }
.iaib-page.show-info .iaib-info-icon:hover {
    transform: translate(-50%, -50%) scale(1.15);
    background: #2271b1; color: #fff; border-color: #2271b1;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

/* Layout Modes & Footer */
.iaib-layout-double .iaib-page.active { width: 50%; border-right: 1px solid #eee; }
.iaib-layout-double .iaib-page.active:nth-of-type(even) { border-right: none; }
.iaib-layout-single .iaib-book { aspect-ratio: 4 / 3; }
.iaib-layout-single .iaib-page.active { width: 100%; border-right: none; }
.iaib-page-footer { position: absolute; bottom: 5px; width: 100%; text-align: center; font-size: 12px; color: #999; pointer-events: none; z-index: 20; }

/* Media Bar & Toolbar */
.iaib-media-container { display: flex; width: 100%; background: #f9f9f9; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; flex-shrink: 0; min-height: 50px; }
.iaib-media-bar { flex: 1; padding: 10px; display: flex; gap: 10px; align-items: center; justify-content: center; visibility: hidden; }
.iaib-bar-left { border-right: 1px solid #eee; }
.iaib-media-btn { width: 32px; height: 32px; border-radius: 50%; border: 1px solid #ccc; background: #fff; color: #333; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.iaib-media-btn:hover { background: #e0e0e0; }
.iaib-btn-info.active { background-color: #333; color: #fff; border-color: #333; }
.iaib-audio-player { width: 100%; height: 32px; max-width: 250px; }
.iaib-layout-single .iaib-bar-right { display: none !important; }
.iaib-layout-single .iaib-bar-left { border-right: none; width: 100%; justify-content: center; }

.iaib-toolbar { background: #333; padding: 10px; display: flex; justify-content: space-between; align-items: center; color: #fff; flex-shrink: 0; width: 100%; box-sizing: border-box; }
.iaib-tool-group { display: flex; gap: 10px; align-items: center; }
.iaib-ctrl-btn { background: rgba(255,255,255,0.15); border: none; color: #fff; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.iaib-ctrl-btn:hover { background: rgba(255,255,255,0.3); }

/* ============================================================
   PHẦN 2: POPUP TỪ ĐIỂN, TOC & FULLSCREEN
   ============================================================ */

/* --- STYLE CHO POPUP TỪ ĐIỂN (Copy chuẩn từ HFB) --- */
.iaib-tooltip-overlay {
    display: none;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    /* Nền đen đậm hơn giống HFB */
    background: rgba(0,0,0,0.85); 
    /* Z-index cực cao để đè lên mọi thứ */
    z-index: 2147483647; 
    justify-content: center; align-items: center;
    opacity: 0; transition: opacity 0.3s ease;
}
.iaib-tooltip-overlay.active { display: flex; opacity: 1; }

.iaib-tooltip-box {
    background: #fff;
    width: 90%; max-width: 400px;
    /* Padding lớn ở trên (35px) để tránh nút đóng */
    padding: 35px 20px 20px 20px; 
    border-radius: 12px; /* Bo góc mềm mại hơn */
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); /* Bóng đổ sâu */
    font-family: sans-serif; text-align: left;
    max-height: 80vh; overflow-y: auto;
}

/* Nút đóng tròn xoe */
.iaib-close-tooltip {
    position: absolute; top: 8px; right: 8px;
    font-size: 24px; cursor: pointer;
    color: #555; padding: 5px;
    line-height: 1; background: rgba(0,0,0,0.05);
    border-radius: 50%;
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
}
.iaib-close-tooltip:hover { background: #eee; color: red; }

/* Nội dung bên trong Popup */
#iaib-tooltip-content {
    padding-top: 5px; line-height: 1.5;
}

.iaib-def-word {
    font-size: 32px; font-weight: bold; color: #d32f2f;
    margin-bottom: 5px; text-transform: capitalize;
    text-align: center;
}
.iaib-def-ipa {
    font-size: 18px; color: #888; font-style: italic; margin-bottom: 15px;
    font-family: sans-serif;
    text-align: center;
}
.iaib-def-section {
    text-align: left; margin-bottom: 10px; padding: 10px;
    background: #f9f9f9; border-radius: 8px; font-size: 16px; line-height: 1.5;
    border-left: 4px solid #ddd;
}
.iaib-def-label {
    font-weight: bold; display: block; font-size: 12px; color: #555;
    text-transform: uppercase; margin-bottom: 4px;
}
.iaib-def-en { color: #0056b3; }
.iaib-def-vi { color: #333; font-weight: 500; }

.iaib-def-meta { display: inline-block; margin-left: 10px; font-size: 14px; font-style: normal; }
.iaib-tag {
    display: inline-block; padding: 2px 6px; border-radius: 4px;
    background: #eee; color: #555; font-size: 12px; margin-right: 5px;
    vertical-align: middle;
}
.iaib-tag.level { background: #e3f2fd; color: #1976d2; border: 1px solid #bbdefb; }


/* --- TOC (MỤC LỤC) --- */
.iaib-toc-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 89; opacity: 0; visibility: hidden; transition: opacity 0.3s ease; pointer-events: none; }
.iaib-toc-overlay.active { opacity: 1; visibility: visible; pointer-events: auto; }
.iaib-toc-sidebar { position: absolute; top: 0; right: 0; bottom: 0; width: 250px; background: #fff; border-left: 1px solid #eee; z-index: 90; display: flex; flex-direction: column; box-shadow: -2px 0 5px rgba(0,0,0,0.1); transform: translateX(100%); transition: transform 0.3s ease; }
.iaib-toc-open .iaib-toc-sidebar { transform: translateX(0); }
.iaib-toc-header { padding: 15px; background: #f5f5f5; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #eee; }
.iaib-toc-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }
.iaib-toc-list li { padding: 10px 15px; border-bottom: 1px solid #eee; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.iaib-toc-list li:hover { background: #f9f9f9; }
.iaib-toc-num { background: #333; color: #fff; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; }
.iaib-toc-close { font-size: 18px; cursor: pointer; }

/* Utilities */
.iaib-hidden { display: none !important; }

/* --- FULLSCREEN & RESPONSIVE --- */
.iaib-wrapper:fullscreen { background: #222; padding: 0; margin: 0; max-width: none; height: 100vh; display: flex; flex-direction: column; }
.iaib-wrapper:fullscreen .iaib-book { flex: 1; background: #222; aspect-ratio: unset; }
.iaib-wrapper:fullscreen .iaib-page.active { height: 100%; }
.iaib-wrapper:fullscreen .iaib-media-container, .iaib-wrapper:fullscreen .iaib-toolbar { background: #222; border-color: #444; }
.iaib-wrapper:fullscreen .iaib-media-btn { background: #333; border-color: #555; color: #fff; }

/* Fix Object-fit khi Fullscreen (Dùng class JS thêm vào) */
.iaib-fullscreen .iaib-page-bg {
    object-fit: unset !important;
    width: 100% !important;
    height: 100% !important;
    top: 0 !important; left: 0 !important;
    transform: none !important;
}

/* Ẩn nút Fullscreen trên Mobile (Dưới 768px) */
@media (max-width: 767px) {
    .iaib-btn-fullscreen { display: none !important; }
}
@media (max-width: 600px) { 
    .iaib-layout-double .iaib-book { aspect-ratio: 4 / 3; } 
}