/* Nút chụp màn hình chính - sử dụng ảnh thay vì màu nền */
#screenshot-btn {
    position: fixed;
    width: 60px;
    height: 60px;
    background: url('https://edus.vn/wp-content/uploads/2025/09/icon-giai1.png') no-repeat center center;
    background-size: contain;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
    z-index: 9999;
    font-size: 0; /* Ẩn text emoji */
}

/* Vị trí nút - sẽ được điều chỉnh bằng JavaScript */
#screenshot-btn.bottom-right {
    bottom: 20px;
    right: 20px;
}

#screenshot-btn.bottom-left {
    bottom: 20px;
    left: 20px;
}

#screenshot-btn.top-right {
    top: 20px;
    right: 20px;
}

#screenshot-btn.top-left {
    top: 20px;
    left: 20px;
}

#screenshot-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

#screenshot-btn.active {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
    background-color: rgba(255,255,255,0.1);
}

/* Menu popup */
.screenshot-menu {
    position: fixed;
    display: none;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    padding: 8px;
    z-index: 10000;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s ease;
    min-width: 120px;
}

.screenshot-menu.show {
    opacity: 1;
    transform: translateY(0);
}

/* Vị trí menu dựa trên vị trí nút */
.screenshot-menu.bottom-right {
    bottom: 90px;
    right: 20px;
}

.screenshot-menu.bottom-left {
    bottom: 90px;
    left: 20px;
}

.screenshot-menu.top-right {
    top: 90px;
    right: 20px;
}

.screenshot-menu.top-left {
    top: 90px;
    left: 20px;
}

/* Menu items */
.menu-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 2px 0;
    font-size: 14px;
    color: #333;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.menu-item:hover {
    background: #f5f5f5;
    transform: translateX(2px);
}

.menu-item:active {
    background: #e8e8e8;
    transform: scale(0.98);
}

.menu-icon {
    font-size: 16px;
    margin-right: 8px;
    width: 20px;
    text-align: center;
}

.menu-text {
    font-weight: 500;
    white-space: nowrap;
}

/* Nút inline cho shortcode */
.screenshot-btn-inline {
    background: url('https://edus.vn/wp-content/uploads/2025/09/icon-giai1.png') no-repeat center center;
    background-size: contain;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
}

.screenshot-btn-inline:hover {
    opacity: 0.8;
}

/* Lớp phủ tối */
#screenshot-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    z-index: 10000;
    cursor: crosshair;
    display: none;
    transition: background 0.3s ease;
}

#screenshot-overlay.active {
    background: rgba(0, 0, 0, 0.5);
}

/* Vùng chọn */
#selection-area {
    position: absolute;
    border: 2px dashed #00ff00;
    background: rgba(0, 255, 0, 0.1);
    display: none;
    pointer-events: none;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
}

/* Thông tin kích thước */
#selection-info {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 12px;
    font-family: monospace;
    pointer-events: none;
    display: none;
    z-index: 10001;
}

/* Popup hiển thị ảnh */
#screenshot-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    z-index: 10002;
    display: none;
    max-width: 90%;
    max-height: 90%;
    transition: all 0.3s ease;
}

#screenshot-popup.show {
    transform: translate(-50%, -50%) scale(1);
}

#screenshot-popup img {
    max-width: 100%;
    max-height: 60vh;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

#screenshot-popup h3 {
    margin: 0 0 15px 0;
    color: #333;
    text-align: center;
}

/* Nút popup - chỉ viền, không màu nền, không icon */
.popup-buttons {
    display: flex;
    gap: 10px;
    margin: 15px 0;
    justify-content: center;
    flex-wrap: nowrap;
}

.popup-btn {
    padding: 8px 16px;
    background: transparent;
    border: 2px solid #333;
    border-radius: 4px;
    cursor: pointer;
    font-weight: normal;
    transition: all 0.3s ease;
    min-width: auto;
    color: #333;
    white-space: nowrap;
    font-size: 14px;
}

.popup-btn:hover {
    background: #f0f0f0;
    border-color: #666;
}

/* Thông báo dưới các nút */
.popup-notice {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    text-align: center;
    font-size: 12px;
    line-height: 1.4;
    color: #666;
}

.popup-notice a {
    color: #0073aa;
    text-decoration: none;
    font-weight: bold;
}

.popup-notice a:hover {
    text-decoration: underline;
}

/* Toast notification */
#screenshot-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #4CAF50;
    color: white;
    padding: 12px 20px;
    border-radius: 5px;
    z-index: 10003;
    display: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

#screenshot-toast.show {
    transform: translateX(0);
}

#screenshot-toast.error {
    background: #f44336;
}

/* Loading spinner */
.screenshot-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px;
    border-radius: 10px;
    z-index: 10004;
    display: none;
    text-align: center;
}

.spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* FIXED: Math rendering improvements for screenshots */
.screenshot-preparing {
    /* Tạm thời ẩn các elements không cần thiết */
    overflow: hidden;
}

.screenshot-preparing .MathJax, 
.screenshot-preparing .katex, 
.screenshot-preparing mjx-container, 
.screenshot-preparing .mjx-chtml, 
.screenshot-preparing [data-mathml] {
    /* Đảm bảo math elements được render hoàn toàn */
    visibility: visible !important;
    opacity: 1 !important;
    display: inline-block !important;
    font-family: 'STIX Two Math', 'Times New Roman', serif !important;
    font-size: 18px !important;
    line-height: 1.5 !important;
    color: #000000 !important;
    background-color: transparent !important;
    text-rendering: optimizeLegibility !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* Đặc biệt cho MathJax SVG */
.screenshot-preparing .MathJax svg, 
.screenshot-preparing mjx-container svg {
    display: inline-block !important;
    vertical-align: middle !important;
    max-width: none !important;
    max-height: none !important;
}

/* Display math (block) */
.screenshot-preparing .MathJax_Display, 
.screenshot-preparing mjx-container[display="block"] {
    display: block !important;
    text-align: center !important;
    margin: 1em 0 !important;
    width: auto !important;
}

/* Inline math */
.screenshot-preparing .MathJax:not(.MathJax_Display), 
.screenshot-preparing mjx-container:not([display="block"]) {
    display: inline !important;
    vertical-align: baseline !important;
    margin: 0 !important;
}

/* Ẩn preview khi chụp */
.screenshot-preparing .MathJax_Preview {
    display: none !important;
}

/* Cải thiện SVG paths */
.screenshot-preparing svg path,
.screenshot-preparing svg rect,
.screenshot-preparing svg circle,
.screenshot-preparing svg ellipse,
.screenshot-preparing svg line,
.screenshot-preparing svg polyline,
.screenshot-preparing svg polygon {
    stroke: #000000 !important;
    fill: #000000 !important;
    stroke-width: 1 !important;
}

/* Responsive cho mobile */
@media (max-width: 768px) {
    #screenshot-btn {
        width: 50px;
        height: 50px;
    }
    
    .screenshot-menu {
        min-width: 100px;
        padding: 6px;
    }
    
    .menu-item {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .menu-icon {
        font-size: 14px;
        margin-right: 6px;
        width: 18px;
    }
    
    /* Điều chỉnh vị trí menu cho mobile */
    .screenshot-menu.bottom-right {
        bottom: 80px;
        right: 10px;
    }
    
    .screenshot-menu.bottom-left {
        bottom: 80px;
        left: 10px;
    }
    
    .screenshot-menu.top-right {
        top: 80px;
        right: 10px;
    }
    
    .screenshot-menu.top-left {
        top: 80px;
        left: 10px;
    }
    
    #screenshot-popup {
        padding: 15px;
        max-width: 95%;
        max-height: 95%;
    }
    
    #screenshot-popup img {
        max-height: 50vh;
    }
    
    .popup-btn {
        padding: 6px 12px;
        font-size: 12px;
        min-width: auto;
    }
    
    .popup-buttons {
        gap: 8px;
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    
    .popup-notice {
        font-size: 11px;
        margin-top: 10px;
        padding-top: 10px;
    }
    
    #screenshot-toast {
        right: 10px;
        top: 10px;
        font-size: 14px;
    }
    
    #selection-info {
        font-size: 11px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .screenshot-menu {
        background: #2d2d2d;
        box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    }
    
    .menu-item {
        color: #fff;
    }
    
    .menu-item:hover {
        background: #404040;
    }
    
    .menu-item:active {
        background: #555;
    }
    
    #screenshot-popup {
        background: #2d2d2d;
        color: white;
    }
    
    #screenshot-popup img {
        border-color: #555;
    }
    
    #screenshot-popup h3 {
        color: white;
    }
    
    .popup-btn {
        border-color: #ccc;
        color: #ccc;
    }
    
    .popup-btn:hover {
        background: #444;
        border-color: #fff;
        color: #fff;
    }
    
    .popup-notice {
        border-top-color: #555;
        color: #ccc;
    }
    
    .popup-notice a {
        color: #66b3ff;
    }
}

/* Hiệu ứng animation cho menu */
.menu-item {
    position: relative;
    overflow: hidden;
}

.menu-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.menu-item:hover::before {
    left: 100%;
}

/* Cải thiện rendering tổng thể */
body {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Tăng z-index để đảm bảo menu luôn ở trên */
.screenshot-menu {
    z-index: 10001;
}
.screenshot-menu {
    min-width: 140px;
    max-height: 400px;
    overflow-y: auto;
}

/* Responsive cho mobile với menu dài hơn */
@media (max-width: 768px) {
    .screenshot-menu {
        max-height: 60vh;
        min-width: 120px;
    }
    
    .menu-item {
        padding: 6px 8px;
        font-size: 12px;
    }
}