/* thx-ec-english-tools.css */
/* Base Variables & Modern Styling */
.thx-ec-en-tools-wrapper {
    --primary: #4A5D23;
    --primary-hover: #334018;
    --consonant: #2a225e;
    --vowel-border: #f8b16a;
    --cons-border: #7dbf8c;
    --text-main: #1d1d1f;
    --bg-glass: rgba(255, 255, 255, 0.85);
    
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-main);
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* MAIN TABS (top-level) */
.thx-en-main-tabs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: -10px;
}
.thx-en-main-tab {
    padding: 12px 28px;
    font-size: 15px;
    font-weight: 700;
    border: 2px solid #e0e0e0;
    border-radius: 30px;
    background: #fff;
    color: #666;
    cursor: pointer;
    transition: all 0.25s;
}
.thx-en-main-tab:hover {
    background: #f3f4e8 !important;
    border-color: #f3f4e8 !important;
    color: var(--primary) !important;
}
.thx-en-main-tab.active {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
    box-shadow: 0 4px 14px rgba(74, 93, 35, 0.3) !important;
}
.thx-en-main-tab.active:hover {
    background: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    color: #fff !important;
}

/* CARDS */
.thx-en-search-card,
.thx-en-ipa-card {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease, padding 0.3s ease;
}

.thx-en-search-card:hover,
.thx-en-ipa-card:hover {
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.08);
}

.thx-en-title {
    text-align: center;
    font-size: 28px;
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 25px;
    letter-spacing: -0.5px;
    color: #000;
}

/* SEARCH AREA */
.thx-en-search-box {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

#thx-en-input,
#thx-en-grammar-input {
    flex: 1;
    padding: 16px 20px;
    font-size: 16px;
    border: 2px solid #eaeaea;
    border-radius: 12px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: rgba(255,255,255,0.9);
}

#thx-en-input:focus,
#thx-en-grammar-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(242, 102, 34, 0.1);
}

#thx-en-btn-search,
#thx-en-btn-grammar {
    padding: 0 30px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#thx-en-btn-search:hover,
#thx-en-btn-grammar:hover {
    background: var(--primary-hover);
}

#thx-en-btn-search:active,
#thx-en-btn-grammar:active {
    transform: scale(0.96);
}

/* TAB SYSTEM */
#thx-en-dict-tabs {
    margin-top: 16px;
}
.thx-en-tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #eaeaea;
    margin-bottom: 0;
}
.thx-en-tab {
    flex: 1;
    padding: 12px 8px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 14px;
    font-weight: 600;
    color: #888;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: -2px;
}
.thx-en-tab:hover {
    color: var(--primary);
    background: #f3f4e8;
}
.thx-en-tab.active {
    background: var(--primary);
    color: #fff;
    border-bottom-color: var(--primary);
}
.thx-en-tab-content {
    padding: 20px;
    background: #fafafa;
    border-radius: 0 0 12px 12px;
    border: 1px solid #eaeaea;
    border-top: none;
    min-height: 100px;
    animation: thx-fadein 0.3s ease-out forwards;
}
.thx-en-tab-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px;
    color: #888;
    font-size: 14px;
}
.thx-en-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #eaeaea;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: thx-spin 0.6s linear infinite;
}
@keyframes thx-spin {
    to { transform: rotate(360deg); }
}
.thx-en-no-result {
    text-align: center;
    color: #888;
    padding: 20px;
    font-size: 14px;
}
.thx-en-laban-content {
    font-size: 15px;
    line-height: 1.7;
    word-break: break-word;
    overflow-wrap: break-word;
    overflow-x: auto;
    max-width: 100%;
    box-sizing: border-box;
}
.thx-en-laban-content * {
    max-width: 100% !important;
}

/* RESULTS */
#thx-en-result {
    margin-top: 20px;
    padding: 20px;
    background: #fafafa;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
    animation: thx-fadein 0.3s ease-out forwards;
}

.dict-word-head {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}

.dict-word {
    font-size: 32px;
    font-weight: 800;
    color: #000;
    margin: 0;
}

.dict-ipa {
    font-size: 20px;
    color: #555;
    font-family: Arial, "Lucida Sans Unicode", sans-serif; /* Best for IPA */
}

.dict-audio-btn {
    background: #f0f0f0;
    border: none;
    width: 36px;
    height: 36px;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.dict-audio-btn:hover {
    background: #e0e0e0;
}

/* TTS Button for sentence/word IPA result */
.thx-tts-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    width: 36px;
    height: 36px;
    padding: 0 !important;
    margin-left: 10px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    transition: background 0.2s, transform 0.15s;
    box-shadow: 0 2px 8px rgba(74, 93, 35, 0.25);
}
.thx-tts-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}
.thx-tts-btn:active {
    transform: scale(0.92);
}

.dict-meanings {
    margin-top: 20px;
}
.dict-pos {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin: 15px 0 5px 0;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}
.dict-def-list {
    list-style: disc;
    padding-left: 20px;
    margin: 10px 0;
    line-height: 1.6;
}
.dict-example {
    color: #666;
    font-style: italic;
    display: block;
    margin-top: 4px;
}

/* ERROR or TRANSLATION */
#thx-en-ipa-result {
    margin-top: 15px;
    padding: 15px;
    background: rgba(242, 102, 34, 0.05);
    border: 1px solid rgba(242, 102, 34, 0.2);
    border-radius: 12px;
    font-family: Arial, sans-serif;
    font-size: 22px;
    color: #444;
    word-break: break-word;
    animation: thx-fadein 0.3s ease-out forwards;
}

/* QUICK LINKS */
.thx-en-quick-links {
    margin-top: 25px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: #666;
    border-top: 1px solid #eee;
    padding-top: 15px;
}

.btn-quick-link {
    background: #f4f4f5;
    border: 1px solid #e4e4e7;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #3f3f46;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-quick-link:hover {
    background: #fff;
    border-color: #d4d4d8;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}


/* NEW IPA CHART SECTION (Adrian Underhill Phonemic Chart) */
.thx-en-ipa-card {
    position: relative;
}

.thx-u-grid-container {
    padding: 12px;
    background: linear-gradient(135deg, rgba(248, 249, 250, 0.95) 0%, rgba(233, 236, 239, 0.95) 100%);
    border-radius: 16px;
    display: inline-block;
    position: relative;
    overflow: hidden; /* Cắt phần logo tràn nếu có */
    user-select: none;
    -webkit-user-select: none;
}

/* Watermark/Logo mờ ảo dưới nền */
.thx-u-grid-container::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 95%;
    height: 95%;
    background-image: var(--bg-logo);
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.3; /* Tăng độ đậm đặc để khi có thẻ đè lên vẫn hiện */
    pointer-events: none;
    z-index: 0;
}

.thx-u-grid {
    display: grid;
    gap: 6px;
    position: relative;
    z-index: 1; /* Nổi lên trên logo */
}

.thx-u-cell {
    background: rgba(255, 255, 255, 0.7); /* Nền trắng trong suốt (glass effect) */
    backdrop-filter: blur(4px); /* Hiệu ứng kính hội tụ nhẹ */
    border-radius: 10px;
    padding: 12px 4px 10px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 2px solid transparent;
    position: relative;
}

.thx-u-cell:not(.thx-u-empty):hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.1);
}

/* ── Color Coding (soft pastel palette with transparency) ── */
.thx-u-mono {
    background: linear-gradient(135deg, rgba(240, 253, 244, 0.85) 0%, rgba(220, 252, 231, 0.85) 100%);
    border-color: #86efac; /* Mảng viền xanh lá đậm hơn */
}
.thx-u-mono .thx-u-sym { color: #16a34a; }
.thx-u-mono .thx-u-words { color: #15803d; }

.thx-u-diph {
    background: linear-gradient(135deg, rgba(239, 246, 255, 0.85) 0%, rgba(219, 234, 254, 0.85) 100%);
    border-color: #93c5fd; /* Viền xanh dương */
}
.thx-u-diph .thx-u-sym { color: #2563eb; }
.thx-u-diph .thx-u-words { color: #1d4ed8; }

.thx-u-unvoiced {
    background: linear-gradient(135deg, rgba(253, 242, 248, 0.85) 0%, rgba(252, 231, 243, 0.85) 100%);
    border-color: #f9a8d4; /* Viền hồng */
}
.thx-u-unvoiced .thx-u-sym { color: #db2777; }
.thx-u-unvoiced .thx-u-words { color: #9d174d; }

.thx-u-voiced {
    background: linear-gradient(135deg, rgba(245, 243, 255, 0.85) 0%, rgba(237, 233, 254, 0.85) 100%);
    border-color: #c4b5fd; /* Viền tím */
}
.thx-u-voiced .thx-u-sym { color: #7c3aed; }
.thx-u-voiced .thx-u-words { color: #5b21b6; }

/* ── Accent Switch Effects ── */
.thx-u-sym {
    transition: opacity 0.15s ease;
}

/* Cells that have different US/UK symbols */
.thx-u-cell[data-us-sym] {
    position: relative;
}

/* Flash effect when symbol changes */
.thx-accent-changed {
    animation: accent-border-flash 0.8s ease-out;
}
@keyframes accent-border-flash {
    0% { border-color: #4A5D23; box-shadow: 0 0 0 3px rgba(74, 93, 35, 0.35); }
    100% { border-color: transparent; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
}

/* Persistent subtle indicator for accent-specific cells */
.accent-us .thx-u-cell[data-us-sym],
.accent-uk .thx-u-cell[data-us-sym] {
    border-color: rgba(249, 115, 22, 0.3);
}

/* ── Cell Content ── */
.thx-u-sym {
    font-size: 34px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin-bottom: 4px;
    line-height: 1.1;
}

.thx-u-words {
    font-size: 11.5px;
    line-height: 1.3;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 3px;
    margin-top: 4px;
}

.thx-u-words .w-word {
    transition: color 0.2s, background 0.2s, transform 0.1s;
    border-radius: 4px;
    padding: 2px 5px;
    display: inline-block;
    background: rgba(0,0,0,0.04);
    cursor: pointer;
    font-weight: 500;
}

.thx-u-words .w-word:hover {
    background: rgba(0,0,0,0.1);
    transform: scale(1.05);
}

.thx-u-words b {
    font-weight: 800;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
}

/* ── IPA Legend ── */
.thx-ipa-legend {
    display: flex;
    justify-content: center;
    gap: 18px;
    margin-bottom: 18px;
    flex-wrap: wrap;
    font-size: 13px;
    color: #555;
    font-weight: 500;
}

.thx-ipa-legend .leg-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 5px;
    vertical-align: middle;
}

.leg-dot.leg-mono { background: #16a34a; }
.leg-dot.leg-diph { background: #2563eb; }
.leg-dot.leg-unvoiced { background: #db2777; }
.leg-dot.leg-voiced { background: #7c3aed; }

/* ── Responsive ── */
@media (max-width: 850px) {
    .thx-u-grid-container {
        padding-bottom: 10px;
    }
}

@media (max-width: 768px) {
    .thx-u-sym { font-size: 22px; }
    .thx-u-words { font-size: 10px; }
    .thx-u-cell { min-height: 70px; min-width: 42px; padding: 8px 3px; }

    /* Fix top tabs wrapping */
    .thx-en-main-tabs {
        flex-wrap: wrap;
        gap: 6px;
    }
    .thx-en-main-tab {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    /* Title size reduction */
    .thx-en-title {
        font-size: 24px;
        margin-bottom: 20px;
    }

    /* Cards padding wrapper */
    .thx-en-search-card,
    .thx-en-ipa-card {
        padding: 20px 16px;
    }

    /* Redesign IPA Chart for Tablets & Mobile */
    .thx-u-grid-container {
        overflow-x: hidden; 
    }
    .thx-ipa-vowels-wrapper {
        flex-direction: column;
        gap: 12px !important;
        margin-bottom: 12px !important;
    }
    .thx-grid-mono, .thx-grid-diph, .thx-grid-cons {
        width: 100%;
        min-width: unset !important;
    }
    .thx-grid-cons {
        grid-template-columns: repeat(4, 1fr) !important;
    }
    .thx-u-words span:not(:first-child) {
        display: none; /* Hide 2nd and 3rd example word to save space */
    }
}

@media (max-width: 480px) {
    /* Extreme Mobile adjustments */
    .thx-u-grid {
        gap: 6px;
    }
    .thx-u-sym { font-size: 20px; }
    .thx-u-words { font-size: 11px; }
    .thx-u-cell { min-height: 60px; padding: 6px 2px; }
    .thx-en-main-tab {
        padding: 8px 12px;
        font-size: 13px;
    }
    .thx-en-title {
        font-size: 22px;
    }
    /* Stack search box and button */
    .thx-en-search-box {
        flex-direction: column;
        gap: 12px;
    }
    #thx-en-btn-search,
    #thx-en-btn-grammar {
        width: 100%;
        padding: 14px 20px;
        font-size: 16px;
    }
    /* Inner Tabs text wrap */
    .thx-en-tab {
        font-size: 13px;
        padding: 10px 6px;
    }
    /* Grammar legend */
    #thx-en-grammar-legend {
        gap: 6px;
    }
    .thx-pos-badge {
        font-size: 11px;
        padding: 3px 6px;
    }
}

/* ── Toggle Switch ── */
.thx-ipa-toggle-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 22px;
}

.thx-ipa-lbl {
    font-size: 14px;
    font-weight: 500;
    transition: color 0.3s, font-weight 0.3s;
}

.thx-ipa-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    margin: 0;
}

.thx-ipa-switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.thx-ipa-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--primary);
    transition: .3s;
}

.thx-ipa-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .thx-ipa-slider {
    background-color: #4A5D23;
}

input:focus + .thx-ipa-slider {
    box-shadow: 0 0 2px #4A5D23;
}

input:checked + .thx-ipa-slider:before {
    transform: translateX(22px);
}

.thx-ipa-slider.round {
    border-radius: 34px;
}

.thx-ipa-slider.round:before {
    border-radius: 50%;
}

/* =========================================================================
   7. WORD & IPA STACKED LAYOUT (Ruby-style)
   ========================================================================= */

.thx-en-ipa-header {
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.08);
    padding-bottom: 8px;
    margin-bottom: 12px;
    font-size: 16px;
    color: #475569;
}

.thx-en-ipa-header strong {
    /* Auto margin removed so it doesn't push the TTS button far right */
}

/* Container chứa cả câu, tự rớt dòng */
.thx-ipa-sentence-display {
    display: flex;
    flex-wrap: wrap;
    column-gap: 8px;
    row-gap: 16px;
    align-items: flex-end; /* Căn đáy dòng IPA cho bằng nhau */
}

/* Khối từng từ */
.thx-ipa-word-block {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.thx-original-word {
    font-size: 13px;
    color: #94a3b8;
    margin-bottom: 2px;
    transition: all 0.2s;
    font-family: inherit;
}

.thx-original-word.is-highlighted {
    color: #4A5D23;
    font-weight: bold;
    transform: translateY(-2px);
}

.thx-ipa-text {
    font-size: 19px;
    color: #0f172a;
}

/* =========================================================================
   8. WORD-LEVEL PHONEME ANIMATIONS (In Search Result)
   ========================================================================= */

.thx-ipa-word {
    position: relative;
    cursor: pointer;
    display: inline-block;
    border-bottom: 2px dotted rgba(64, 156, 255, 0.5);
    transition: all 0.2s ease;
    white-space: nowrap !important;
}

.thx-ipa-word:hover {
    color: #4A5D23;
    border-bottom-color: #4A5D23;
}

/* Kí tự IPA cấu thành từ (chỉ có tính nhận diện, không tự sinh tooltip nữa) */
.thx-ipa-phoneme {
    display: inline-block;
    transition: color 0.1s;
}

/* Container chứa nguyên dải cell (hiện khi hover vào từ) */
.thx-word-tooltip-container {
    display: none;
    position: absolute;
    bottom: calc(100% + 35px); /* Nâng cao lên thẳng qua đầu tầng chữ gốc tiếng Anh để không bị che */
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none; /* Tooltip doesn't block hover */
    background: #fff; /* Nền trắng đỡ hụt màu gradient */
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    
    /* Layout dàn hàng ngang cho các cells */
    flex-direction: row;
    flex-wrap: wrap; /* Cho phép xuống dòng nếu từ siêu dài */
    justify-content: center;
    gap: 3px;
    min-width: max-content;
    max-width: 250px; /* Giảm max-width để fit điện thoại */
}

/* Hover vào từ -> Hiện nguyên dải cell ( Bị chặn lại nếu hệ thống đang phát âm từ khác ) */
.thx-ec-en-tools-wrapper:not(.is-global-playing) .thx-ipa-word:hover .thx-word-tooltip-container,
.thx-ipa-word.is-playing .thx-word-tooltip-container,
.thx-ipa-word.is-finished .thx-word-tooltip-container {
    display: flex;
    animation: tooltip-fade-in 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes tooltip-fade-in {
    0% { opacity: 0; transform: translate(-50%, 10px); }
    100% { opacity: 1; transform: translate(-50%, 0); }
}

/* Style cho các cell trong dải */
.thx-word-tooltip-container .thx-u-cell {
    margin: 0;
    min-width: 42px; /* Thu nhỏ gọn hẳn lại để tránh tràn màn hình */
    padding: 5px 2px 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.thx-word-tooltip-container .thx-u-sym {
    font-size: 19px; /* Giảm size kí hiệu IPA để ôm vừa cell gọn gàng */
}
.thx-word-tooltip-container .thx-u-words {
    display: none; /* Ẩn ví dụ đi cho gọn, chỉ để lại ký hiệu âm */
}

/* === PLAYBACK SEQUENCING STATES === */

/* Khi đang play -> Tất cả các cell tàng hình (ẩn nhưng vẫn chiếm chỗ) */
.thx-ipa-word.is-playing .thx-word-tooltip-container .thx-u-cell {
    opacity: 0;
    transform: scale(0.8) translateY(10px);
}

/* Cell đang "cầm mic" hát -> Hiện rõ và to lên */
.thx-ipa-word.is-playing .thx-word-tooltip-container .thx-u-cell.is-active {
    opacity: 1;
    transform: scale(1.1) translateY(0);
    box-shadow: 0 8px 16px rgba(0,0,0,0.2) !important;
    z-index: 2; /* Nổi lên trên */
}

/* Text phiên âm hiện tại cũng nhảy màu theo cell */
.thx-ipa-phoneme.is-active-text {
    color: #4A5D23;
    font-weight: bold;
}

/* ========================================================================= */
/* 5. GRAMMAR ANALYZER STYLES */
/* ========================================================================= */

.thx-pos-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    cursor: default;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.thx-pos-word {
    display: inline-block;
    padding: 4px 8px;
    margin: 4px 2px;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: default;
}

.thx-pos-word:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.thx-pos-word.pos-none {
    color: #475569;
    background: #e2e8f0;
    padding: 4px 6px;
    border-radius: 4px;
}

/* POS Colors */
.pos-noun, .thx-pos-badge.pos-noun { background: #3b82f6; color: #fff; } /* Blue */
.pos-verb, .thx-pos-badge.pos-verb { background: #ef4444; color: #fff; } /* Red */
.pos-adj, .thx-pos-badge.pos-adj { background: #10b981; color: #fff; } /* Green */
.pos-adv, .thx-pos-badge.pos-adv { background: #8b5cf6; color: #fff; } /* Purple */
.pos-prep, .thx-pos-badge.pos-prep { background: #64748b; color: #fff; } /* Slate */
.pos-pron, .thx-pos-badge.pos-pron { background: #f59e0b; color: #fff; } /* Amber */
.pos-det, .thx-pos-badge.pos-det { background: #14b8a6; color: #fff; } /* Teal */
.pos-conj, .thx-pos-badge.pos-conj { background: #ec4899; color: #fff; } /* Pink */
.pos-intj, .thx-pos-badge.pos-intj { background: #eab308; color: #fff; } /* Yellow */

/* Chunk Blocks */
/* Sentence Box Level */
.thx-en-grammar-sentence-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 8px;
}
.thx-sentence-tab {
    padding: 6px 16px;
    background: #f1f5f9;
    color: #64748b;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}
.thx-sentence-tab:hover {
    background: #e2e8f0;
    color: #475569;
}
.thx-sentence-tab.active {
    background: #4A5D23;
    color: #fff;
    box-shadow: 0 4px 10px rgba(74, 93, 35, 0.3);
}

.thx-sentence-original-text {
    font-size: 15px;
    color: #334155;
    background: #fff;
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 4px solid #4A5D23;
    margin-bottom: 20px;
}

.thx-grammar-sentence-box {
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px 16px 16px;
    margin-bottom: 24px;
    background: #f8fafc;
    position: relative;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}
.thx-grammar-sentence-box .thx-sentence-label {
    position: absolute;
    top: -12px;
    left: 16px;
    background: #fff;
    padding: 2px 12px;
    font-size: 13px;
    font-weight: 800;
    color: #475569;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
}
.thx-grammar-chunks-wrapper {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding-top: 8px;
}

.thx-grammar-chunk {
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    padding: 18px 12px 10px;
    margin: 4px 0;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    background: rgba(248, 250, 252, 0.4);
    width: 100%;
}

.thx-grammar-word-group {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
}

.thx-grammar-chunk .thx-chunk-label {
    position: absolute;
    top: -10px;
    left: 8px;
    font-size: 11px;
    background: #fff;
    padding: 0 4px;
    color: #64748b;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Specific Chunk Colors */
.thx-grammar-chunk.chunk-compound {
    border-color: #94a3b8;
    background: rgba(241, 245, 249, 0.4);
}
.thx-grammar-chunk.chunk-compound > .thx-chunk-label {
    color: #475569;
    background: #e2e8f0;
}

.thx-grammar-chunk.chunk-noun { border-color: #93c5fd; }
.thx-grammar-chunk.chunk-noun > .thx-chunk-label { color: #3b82f6; }

.thx-grammar-chunk.chunk-verb { border-color: #fca5a5; }
.thx-grammar-chunk.chunk-verb > .thx-chunk-label { color: #ef4444; }

.thx-grammar-chunk.chunk-unknown { border-color: #cbd5e1; }
.thx-grammar-chunk.chunk-unknown > .thx-chunk-label { color: #94a3b8; }

/* Sub-chunk Level (Determiner / Nominal Split) */
.thx-grammar-subchunk {
    border: 1.5px dotted #94a3b8;
    border-radius: 6px;
    padding: 10px 4px 4px;
    margin: 2px 0 2px 10px; /* Thụt lề nhẹ vào tạo bậc thang */
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.6);
    position: relative;
    max-width: 100%;
}
.thx-grammar-subchunk .thx-subchunk-label {
    position: absolute;
    top: -8px;
    left: 4px;
    font-size: 9px;
    background: #cbd5e1;
    color: #334155;
    padding: 0 4px;
    border-radius: 4px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 2;
}
.thx-grammar-subchunk.chunk-conj-wrapper {
    border: none;
    background: transparent;
    padding: 8px 2px 2px;
    margin-left: 20px; /* Thụt sâu thêm cho Liên từ */
    align-self: flex-start;
}
.thx-grammar-subchunk.chunk-conj-wrapper .thx-subchunk-label {
    background: #f87171;
    color: #fff;
    left: 0;
    transform: none;
}

/* ?n n�t d?c c? c�u khi dang ph�t �m t?ng t? l? */
.thx-ec-en-tools-wrapper.is-global-playing .thx-tts-controls { opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }





/* Sentence Tabs */
.thx-ipa-tab {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.25s ease;
    background: #f8fafc;
    color: #64748b;
}
.thx-ipa-tab:hover { background: #e2e8f0; color: #334155; border-color: #cbd5e1; }
.thx-ipa-tab.active { background: var(--primary) !important; color: #ffffff !important; border-color: var(--primary) !important; box-shadow: 0 2px 8px rgba(74, 93, 35, 0.2); }
.thx-ipa-tab.active:hover { background: var(--primary-hover) !important; border-color: var(--primary-hover) !important; }



.thx-en-laban-content .slide_select { display: none !important; }

.thx-en-clickable-word { cursor: pointer; transition: color 0.2s, background-color 0.2s; border-radius: 4px; padding: 0 2px; }
.thx-en-clickable-word:hover { color: var(--primary) !important; text-decoration: underline; background-color: #f3f4e8; }



.thx-en-laban-content a.thx-en-clickable-word,
.thx-en-laban-content .thx-en-laban-link { color: #1e88e5 !important; text-decoration: underline !important; cursor: pointer !important; background: transparent !important; }
.thx-en-laban-content a.thx-en-clickable-word:hover,
.thx-en-laban-content .thx-en-laban-link:hover { color: var(--primary) !important; background-color: #f3f4e8 !important; }


/* Recent Lookups */
.thx-recent-pill { display: inline-block; padding: 4px 10px; background-color: #fff; border: 1px solid #cdd6a5; border-radius: 20px; color: #4A5D23; font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.2s ease-in-out; }
.thx-recent-pill:hover { background-color: #4A5D23; color: #fff; transform: translateY(-1px); box-shadow: 0 2px 4px rgba(74,93,35,0.2); }

/* ── Vocab Sub-Tabs ── */
.thx-vocab-subtabs {
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    background: #f0f0e6;
}
.thx-vocab-subtab {
    flex: 1;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #666;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}
.thx-vocab-subtab:hover {
    color: var(--primary);
    background: #e8e8d8;
}
.thx-vocab-subtab.active {
    color: var(--primary);
    background: #fafaf5;
    border-bottom-color: var(--primary);
    font-weight: 700;
}

/* ── Vocab Topics ── */
.thx-vocab-field-group {
    margin-bottom: 24px;
}
.thx-vocab-field-group:last-child {
    margin-bottom: 0;
}
.thx-vocab-field-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #d4d9b6;
}
.thx-vocab-topic-block {
    margin-bottom: 16px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e8e8e0;
    overflow: visible;
}
.thx-vocab-topic-header {
    padding: 8px 14px;
    background: #f6f6ee;
    border-bottom: 1px solid #e8e8e0;
}
.thx-vocab-word-type {
    display: inline-block;
    padding: 2px 10px;
    background: var(--primary);
    color: #fff;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

/* Vocab Table */
.thx-vocab-topic-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    overflow: visible;
}
.thx-vocab-topic-table thead th {
    background: #f8f8f2;
    padding: 8px 12px;
    text-align: left;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    color: #666;
    border-bottom: 2px solid #e8e8e0;
}
.thx-vocab-topic-table thead th.col-stt {
    width: 40px;
    text-align: center;
}
.thx-vocab-topic-table tbody td {
    padding: 7px 12px;
    border-bottom: 1px solid #f0f0ea;
    vertical-align: middle;
    overflow: visible;
}
.thx-vocab-topic-table tbody td.col-stt {
    text-align: center;
    color: #aaa;
    font-size: 12px;
}
.thx-vocab-topic-table tbody td.col-word {
    font-weight: 600;
    color: #1d1d1f;
}
.thx-vocab-topic-table tbody td.col-word .thx-en-clickable-word {
    cursor: pointer;
    color: var(--primary);
    text-decoration: underline;
    text-decoration-color: transparent;
    transition: text-decoration-color 0.2s;
}
.thx-vocab-topic-table tbody td.col-word .thx-en-clickable-word:hover {
    text-decoration-color: var(--primary);
}
.thx-vocab-topic-table tbody td.col-ipa {
    font-family: 'Segoe UI', 'Times New Roman', serif;
    color: #7c3aed;
    font-size: 13px;
}
.thx-vocab-topic-table tbody td.col-meaning {
    color: #555;
}
.thx-vocab-topic-table tbody tr:hover {
    background: #fafaf5;
}

/* Admin Actions */
.thx-vocab-admin-actions {
    display: flex;
    gap: 8px;
    padding: 8px 14px;
    background: #faf8f0;
    border-top: 1px solid #e8e8e0;
}
.thx-vocab-btn-edit,
.thx-vocab-btn-delete {
    padding: 4px 12px;
    font-size: 13px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s;
}
.thx-vocab-btn-edit:hover { background: #e8f5e9; border-color: #4A5D23; }
.thx-vocab-btn-delete:hover { background: #ffebee; border-color: #ef4444; color: #ef4444; }

/* Admin Form */
.thx-vocab-admin-form {
    margin-top: 20px;
    padding: 20px;
    background: #fff;
    border-radius: 10px;
    border: 2px dashed #cdd6a5;
}
.thx-vocab-form-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    margin: 0 0 16px 0;
}
.thx-vocab-form-row {
    margin-bottom: 12px;
}
.thx-vocab-form-row label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #444;
}
.thx-vocab-form-row input[type="text"],
.thx-vocab-form-row textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #eaeaea;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
.thx-vocab-form-row input[type="text"]:focus,
.thx-vocab-form-row textarea:focus {
    border-color: var(--primary);
}
.thx-vocab-form-row textarea {
    font-family: 'Consolas', 'Menlo', monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
}
.thx-vocab-form-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}
.thx-vocab-btn-primary {
    padding: 10px 24px;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.thx-vocab-btn-primary:hover { background: var(--primary-hover); }
.thx-vocab-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.thx-vocab-btn-secondary {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: #666;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.thx-vocab-btn-secondary:hover { background: #e0e0e0; }

/* Tooltip position override for vocab table items without dual-layer texts */
.thx-vocab-topic-table .thx-word-tooltip-container,
.thx-single-layer .thx-word-tooltip-container {
    bottom: calc(100% + 8px) !important;
}

/* Desktop: hide inline mobile IPA clone */
.thx-vocab-ipa-mobile {
    display: none;
}

@media (max-width: 768px) {
    /* Prevent tooltip from clipping the left edge */
    /* Tooltip mobile: JS handles viewport-centering via left offset */
    .thx-vocab-topic-table .thx-word-tooltip-container,
    .thx-single-layer .thx-word-tooltip-container {
        white-space: nowrap !important;
        min-width: auto;
        max-width: none;
        flex-wrap: nowrap !important;
        bottom: calc(100% + 12px) !important;
    }
    
    /* Shrink the tooltip cells on mobile globally so all IPA tooltips fit */
    .thx-word-tooltip-container .thx-u-cell {
        min-width: 33px;
        min-height: 30px;
        padding: 4px 1px 2px;
        margin: 0;
    }
    
    .thx-word-tooltip-container .thx-u-sym {
        font-size: 16px;
    }

    /* Hide the separate IPA column on mobile */
    .thx-vocab-topic-table th.col-ipa-hdr,
    .thx-vocab-topic-table td.col-ipa {
        display: none !important;
    }

    /* Show the inline IPA clone under the English word */
    .thx-vocab-ipa-mobile {
        display: block;
        margin-top: 3px;
    }

    /* Fix table wrappers */
    .thx-table-responsive-wrapper {
        overflow: visible !important;
    }
}

/* Force hide class to break mobile sticky hover gracefully */
.thx-force-hide-tooltip .thx-word-tooltip-container,
.thx-force-hide-tooltip > .thx-word-tooltip-container {
    display: none !important;
}

/* Responsive overrides for vocab section */
@media (max-width: 480px) {
    .thx-vocab-subtab {
        font-size: 13px;
        padding: 9px 8px;
    }
    .thx-vocab-topic-table {
        font-size: 13px;
    }
    .thx-vocab-topic-table thead th,
    .thx-vocab-topic-table tbody td {
        padding: 6px 8px;
    }
    .thx-vocab-field-title {
        font-size: 16px;
    }
}

/* === Library Search Tab (Tài liệu trong thư viện) === */
#thx-en-tab-lib-search .tv-match-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
#thx-en-tab-lib-search .tv-match-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
}
#thx-en-tab-lib-search .tv-match-item:last-child {
    border-bottom: none;
}
#thx-en-tab-lib-search .tv-match-content-row {
    align-items: center !important;
}
#thx-en-tab-lib-search .tv-match-play-tts {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: #e2e8f0 !important;
    color: #334155 !important;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
#thx-en-tab-lib-search .tv-match-play-tts:hover {
    background: var(--primary, #4A5D23) !important;
    color: #fff !important;
}
#thx-en-tab-lib-search .tv-match-play-tts.is-playing {
    background: #dc2626 !important;
    color: #fff !important;
}
#thx-en-tab-lib-search .tv-match-link {
    text-decoration: none;
    color: inherit;
}
#thx-en-tab-lib-search .tv-match-link:hover .tv-match-text {
    color: var(--primary, #4A5D23);
}
#thx-en-tab-lib-search .tv-match-text {
    font-size: 15px;
    line-height: 1.6;
    transition: color 0.15s;
}
#thx-en-tab-lib-search .tv-match-footer {
    margin-top: 6px;
    font-size: 12px;
    color: #94a3b8;
}
#thx-en-tab-lib-search .tv-match-pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
}
#thx-en-tab-lib-search .tv-match-page-btn {
    min-width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    color: #475569;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
#thx-en-tab-lib-search .tv-match-page-btn:hover {
    border-color: var(--primary, #4A5D23);
    color: var(--primary, #4A5D23);
}
#thx-en-tab-lib-search .tv-match-page-btn.is-active {
    background: var(--primary, #4A5D23);
    border-color: var(--primary, #4A5D23);
    color: #fff;
}
#thx-en-tab-lib-search .tv-match-list-container {
    max-height: none;
    overflow-y: visible;
}
