/* ==========================================================================
   1. VARIABLES & THEME CONFIGURATION
   ========================================================================== */

:root {
    /* Fonts */
    --font-ui: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-mono: 'PT Mono', 'Consolas', 'Monaco', monospace;

    /* Colors - Light Theme (Default) */
    --bg-primary: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    --container-bg: rgba(255, 255, 255, 0.96);
    --header-bg: linear-gradient(to right, #4a00e0, #8e2de2);

    --text-primary: #333;
    --text-secondary: #666;
    --text-light: #fff;
    --text-muted: #888;

    --accent-color: #4a00e0;
    --accent-gradient: linear-gradient(to right, #4a00e0, #8e2de2);

    --correct-color: #28a745;
    --incorrect-color: #e74c3c;
    --incorrect-bg: rgba(231, 76, 60, 0.15);

    --section-bg: #f8f9fa;
    --border-color: #e9ecef;
    --shadow-color: rgba(0, 0, 0, 0.15);

    --toggle-bg: #dfe6e9;
    --toggle-checked-bg: #4a00e0;
}

/* ==========================================================================
   2. THEME VARIATIONS
   ========================================================================== */

[data-theme="dark"] {
    --bg-primary: linear-gradient(135deg, #2d0b59 0%, #0d2f6c 100%);
    --container-bg: rgba(30, 30, 40, 0.96);
    --header-bg: linear-gradient(to right, #3a0080, #6a1b9a);
    --text-primary: #f0f0f0;
    --text-secondary: #b0b0b0;
    --text-muted: #666;
    --accent-color: #8e2de2;
    --accent-gradient: linear-gradient(to right, #6a1b9a, #8e2de2);
    --correct-color: #4caf50;
    --incorrect-color: #f44336;
    --incorrect-bg: rgba(244, 67, 54, 0.15);
    --section-bg: #2a2a3a;
    --border-color: #444;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --toggle-bg: #555;
    --toggle-checked-bg: #8e2de2;
}

[data-theme="idm"] {
    --bg-primary: #212121;
    --container-bg: rgba(30, 30, 40, 0.96);
    --header-bg: rgba(30, 30, 40, 0.96);
    --text-primary: #f0f0f0;
    --text-secondary: #b0b0b0;
    --text-muted: #666;
    --accent-color: #8e2de2;
    --accent-gradient: linear-gradient(to right, #6a1b9a, #8e2de2);
    --correct-color: #4caf50;
    --incorrect-color: #f44336;
    --incorrect-bg: rgba(244, 67, 54, 0.15);
    --section-bg: #2a2a3a;
    --border-color: #444;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --toggle-bg: #555;
    --toggle-checked-bg: #8e2de2;
}

[data-theme="korean"] {
    --bg-primary: #212121;
    --container-bg: rgba(30, 30, 40, 0.96);
    --header-bg: rgba(30, 30, 40, 0.96);
    --text-primary: #f0f0f0;
    --text-secondary: #b0b0b0;
    --text-muted: #666;
    --accent-color: #8e2de2;
    --accent-gradient: linear-gradient(to right, #6a1b9a, #8e2de2);
    --correct-color: #4caf50;
    --incorrect-color: #f44336;
    --incorrect-bg: rgba(244, 67, 54, 0.15);
    --section-bg: #2a2a3a;
    --border-color: #444;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --toggle-bg: #555;
    --toggle-checked-bg: #8e2de2;
}

[data-theme="mandarin"] {
    --bg-primary: #212121;
    --container-bg: rgba(30, 30, 40, 0.96);
    --header-bg: rgba(30, 30, 40, 0.96);
    --text-primary: #f0f0f0;
    --text-secondary: #b0b0b0;
    --text-muted: #666;
    --accent-color: #8e2de2;
    --accent-gradient: linear-gradient(to right, #6a1b9a, #8e2de2);
    --correct-color: #4caf50;
    --incorrect-color: #f44336;
    --incorrect-bg: rgba(244, 67, 54, 0.15);
    --section-bg: #2a2a3a;
    --border-color: #444;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --toggle-bg: #555;
    --toggle-checked-bg: #8e2de2;
    /* --font-ui: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Heiti SC", sans-serif; */
    /* Dùng font monospace hoặc font CJK tiêu chuẩn để các chữ thẳng hàng dọc */
    --font-mono: "Noto Sans Mono CJK SC", "Microsoft YaHei", "SimHei", monospace;
}

[data-theme="mandarin"] .text-display {
    /* Font chữ */
    font-family: var(--font-mono);
    /* Tăng khoảng cách giữa các chữ một chút cho thoáng */
    letter-spacing: 0.05em;
    /* Căn đều 2 bên */
    text-align: justify;
    /* QUAN TRỌNG: Ngắt dòng ở bất kỳ ký tự nào để tránh rách dòng */
    word-break: break-all;
}

/* Chữ hiện tại đang gõ (Cursor) */
[data-theme="mandarin"] .current {
    /* Viền bao quanh ký tự vuông vức hơn */
    border-radius: 4px;
    /* Padding nhẹ để background không dính sát nét chữ */
    padding: 2px 0;
}

/* Chữ gõ sai */
[data-theme="mandarin"] .incorrect {
    /* Đẩy gạch chân xuống thấp hơn để không cắt vào nét chữ Hán */
    text-underline-offset: 0.25em;
    text-decoration-thickness: 2px;
}

/* Tooltip hiển thị Pinyin/Nghĩa */
[data-theme="mandarin"] .tooltip-word {
    /* Đẩy đường chấm chấm xuống */
    border-bottom: 2px dotted rgba(255, 255, 255, 0.3);
}

[data-theme="coffee"] {
    --bg-primary: #d5cabd;
    --container-bg: #fdf6e3;
    --header-bg: #5d4037;
    --text-primary: #3e2723;
    --text-secondary: #6d4c41;
    --text-muted: #a1887f;
    --text-light: #efebe9;
    --accent-color: #8d6e63;
    --accent-gradient: linear-gradient(to right, #8d6e63, #6d4c41);
    --section-bg: #efebe9;
    --border-color: #d7ccc8;
    --toggle-bg: #d7ccc8;
    --toggle-checked-bg: #5d4037;
}

[data-theme="cyberpunk"] {
    --bg-primary: #000000;
    --container-bg: rgba(10, 10, 10, 0.95);
    --header-bg: linear-gradient(to right, #ff00cc, #333399);
    --text-primary: #00ff00;
    --text-secondary: #00ccff;
    --text-muted: #ff00cc;
    --accent-color: #ff0099;
    --accent-gradient: linear-gradient(to right, #ff00cc, #333399);
    --correct-color: #00ff00;
    --incorrect-color: #ff0000;
    --incorrect-bg: rgba(255, 0, 0, 0.3);
    --section-bg: #111;
    --border-color: #333;
    --toggle-bg: #333;
    --toggle-checked-bg: #ff0099;
    --font-ui: 'Courier New', Courier, monospace;
}

[data-theme="dracula"] {
    --bg-primary: #282a36;
    --container-bg: #44475a;
    --header-bg: #6272a4;
    --text-primary: #f8f8f2;
    --text-secondary: #bd93f9;
    --text-muted: #6272a4;
    --accent-color: #ff79c6;
    --accent-gradient: linear-gradient(to right, #bd93f9, #ff79c6);
    --correct-color: #50fa7b;
    --incorrect-color: #ff5555;
    --incorrect-bg: rgba(255, 85, 85, 0.2);
    --section-bg: #282a36;
    --border-color: #6272a4;
    --toggle-checked-bg: #bd93f9;
}

/* ==========================================================================
   3. GLOBAL RESET & BASE STYLES
   ========================================================================== */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #6262625c;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #62626291;
}

/* Hidden Elements */
.hidden {
    display: none !important;
}

/* styles.css */
/* styles.css */
.input-area {
    position: fixed;
    top: 0;
    left: 0;
    /* Đủ rộng để hiển thị Pinyin đang gõ */
    width: 250px;
    height: 1.5em;
    opacity: 0;
    /* Ẩn đi khi dùng thật */
    z-index: 9999;
    pointer-events: none;
    transition: none !important;
}

.input-area textarea {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: transparent;
    padding: 0;
    margin: 0;
    resize: none;
    font-family: inherit;
    /* Không cần white-space pre nữa vì ta luôn clear text */
}

strong {
    font-weight: normal;
}

/* ==========================================================================
   4. LAYOUT COMPONENTS
   ========================================================================== */

/* Main Container */
.container {
    width: 100%;
    max-width: 850px;
    background-color: var(--container-bg);
    border-radius: 16px;
    box-shadow: 0 15px 35px var(--shadow-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

/* Header */
header {
    background: var(--header-bg);
    color: var(--text-light);
    padding: 25px 20px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2rem;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.subtitle {
    font-size: 1rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Stats Dashboard */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background-color: var(--section-bg);
    margin: 20px 25px 10px;
    border-radius: 12px;
    padding: 15px;
    gap: 15px;
    border: 1px solid var(--border-color);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.stat-item:not(:last-child)::after {
    content: "";
    position: absolute;
    right: -7px;
    height: 60%;
    width: 1px;
    background-color: var(--border-color);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-color);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}

/* Text Display Area */
.text-display-container {
    background-color: var(--section-bg);
    border-radius: 12px;
    margin: 15px 25px;
    border: 2px solid transparent;
    height: 50vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: border-color 0.2s;
    scroll-behavior: smooth;
}

.text-display {
    padding: 25px;
    line-height: 1.8;
    font-size: 1.2rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.text-display p {
    margin: 1em 0;
}

.text-display span {
    transition: background-color 0.1s;
    border-radius: 2px;
}

.skipped-text {
    background: rgb(74 74 74 / 35%);
}

/* Text States */
.correct {
    color: var(--correct-color);
}

.incorrect {
    color: var(--incorrect-color);
    background-color: var(--incorrect-bg);
    text-decoration: underline wavy;
}

.current {
    background-color: var(--accent-color);
    color: var(--text-light) !important;
    border-radius: 2px;
    animation: softPulse 2s infinite;
}

/* Special Characters */
.newline-char {
    color: transparent;
    display: inline-block;
    min-width: 0.5em;
    height: 1.2em;
    vertical-align: text-bottom;
    margin-left: 1px;
    user-select: none;
    line-height: 1;
}

.newline-char.current {
    color: var(--text-light) !important;
    background-color: var(--accent-color);
    opacity: 1;
    padding: 0 2px;
}

.newline-char.incorrect {
    color: var(--incorrect-color);
    background-color: var(--incorrect-bg);
}

.newline-char .correct {
    color: transparent;
}

br.visual-break {
    user-select: none;
}

p .visual-break:last-child {
    display: none;
}

/* Visual Header */
.visual-header {
    color: var(--accent-color);
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 1.3rem;
    margin-top: 30px;
    margin-bottom: 5px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
    line-height: 1.2;
    user-select: none;
}

.visual-header+p {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Blind Mode */
.blind-mode .blind-hidden {
    color: transparent !important;
    background: transparent;
    text-shadow: none;
}

/* [FIX] Ensure typed characters remain visible in Blind Mode */
.blind-mode .correct {
    color: var(--correct-color) !important;
    opacity: 1 !important;
}

.blind-mode .incorrect {
    color: var(--incorrect-color) !important;
    background-color: var(--incorrect-bg) !important;
    text-decoration: underline wavy !important;
    opacity: 1 !important;
}

.blind-mode .current {
    color: transparent !important;
    background-color: var(--accent-color);
    /* [MODIFIED] Bỏ width cố định để tránh vỡ layout khi gõ */
    /* width: 10px; */
    /* display: inline-block; */
}

.blind-mode .newline-char.current {
    color: var(--text-light) !important;
    background-color: var(--accent-color);
    width: auto;
    min-width: 14px;
}

/* Speaker Label */
.speaker-label {
    font-weight: 700;
    color: var(--accent);
    margin-right: 8px;
    /* user-select: none; */
    /* Không cho bôi đen */
    pointer-events: none;
    /* Không cho click vào để tránh lỗi cursor */
    display: inline-block;
    font-size: 0.9em;
    background: rgba(0, 0, 0, 0.03);
    padding: 2px 6px;
    border-radius: 4px;
    vertical-align: middle;
}

.speaker-label span {
    color: inherit !important;
    background: none !important;
}

.blind-mode .speaker-label span.blind-hidden {
    color: inherit !important;
    background: transparent !important;
    text-shadow: none !important;
}

[data-theme="dark"] .speaker-label {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="idm"] .speaker-label {
    background: rgba(117, 117, 117, 0.1);
}

/* ==========================================================================
   5. CONTROLS & INTERACTIVE ELEMENTS
   ========================================================================== */

/* Toolbar */
.toolbar {
    padding: 0 25px;
    margin-bottom: 20px;
}

.toolbar-left {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
    width: 100%;
}

/* Toggle Switch */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.toggle-switch {
    position: relative;
    width: 46px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--toggle-bg);
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s cubic-bezier(0.4, 0.0, 0.2, 1);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
    background-color: var(--toggle-checked-bg);
}

input:checked+.slider:before {
    transform: translateX(22px);
}

/* Volume Control */
.mini-volume-control {
    display: flex;
    align-items: center;
    height: 24px;
    padding-left: 10px;
    margin-left: 5px;
    border-left: 1px solid var(--border-color);
}

.mini-volume-control input[type="range"] {
    -webkit-appearance: none;
    width: 80px;
    background: transparent;
    cursor: pointer;
}

.mini-volume-control input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: var(--toggle-bg);
    border-radius: 2px;
}

.mini-volume-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 14px;
    width: 14px;
    border-radius: 50%;
    background: var(--toggle-checked-bg);
    margin-top: -5px;
    border: 2px solid var(--container-bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Footer */
footer {
    border-top: 1px solid var(--border-color);
    padding: 20px 25px;
    background-color: var(--container-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

/* Buttons */
.btn-icon {
    background: var(--section-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.btn-icon:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background: var(--container-bg);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Special Buttons */
#fileLoaderBtn,
#dictationBtn {
    background: var(--accent-gradient);
    color: white;
    border: none;
    box-shadow: 0 4px 10px rgba(74, 0, 224, 0.3);
    min-width: 130px;
    max-width: 220px;
    text-overflow: ellipsis;
    overflow: hidden;
}

#fileLoaderBtn:hover,
#dictationBtn:hover {
    background: linear-gradient(to right, #5e00ff, #a745ff);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(74, 0, 224, 0.4);
    color: white;
}

#fileLoaderBtn.dragging,
#dictationBtn.dragging {
    background: white;
    color: var(--accent-color);
    border: 2px dashed var(--accent-color);
    box-shadow: none;
    transform: scale(1.05);
}

/* Select Inputs */
select {
    padding: 8px 15px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--section-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
    max-width: 250px;
}

select:hover,
select:focus {
    border-color: var(--accent-color);
}

/* ==========================================================================
   6. CUSTOM DROPDOWN (TREE VIEW)
   ========================================================================== */

.custom-dropdown {
    position: relative;
    min-width: 250px;
    font-size: 0.9rem;
    user-select: none;
}

.dropdown-trigger {
    background: var(--section-bg);
    border: 1px solid var(--border-color);
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-primary);
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-trigger:hover {
    border-color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.dropdown-trigger .arrow {
    font-size: 0.7em;
    margin-left: 10px;
    color: var(--text-muted);
}

.dropdown-content {
    position: absolute;
    bottom: 110%;
    left: 0;
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--container-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    padding: 10px;
    z-index: 5000;
    backdrop-filter: blur(10px);
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.2s, transform 0.2s;
}

.dropdown-content.hidden {
    display: none;
    opacity: 0;
    transform: translateY(10px);
}

/* Tree Structure */
.tree-ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.tree-ul .tree-ul {
    padding-left: 18px;
    border-left: 1px solid var(--border-color);
    margin-left: 7px;
    display: none;
}

.tree-ul .tree-ul.expanded {
    display: block;
}

.tree-item {
    margin: 2px 0;
}

.tree-label {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.1s;
}

.tree-label:hover {
    background: var(--section-bg);
    color: var(--accent-color);
}

.tree-label.is-folder {
    font-weight: 600;
    color: var(--text-secondary);
}

.tree-label.is-file {
    font-family: var(--font-ui);
}

.tree-label.active {
    background: var(--accent-gradient);
    color: white !important;
}

/* Icons */
.tree-icon {
    margin-right: 8px;
    font-size: 1rem;
    display: inline-block;
    width: 16px;
    text-align: center;
    transition: transform 0.2s;
}

.expanded>.tree-label .tree-arrow {
    transform: rotate(90deg);
}

.tree-arrow {
    display: inline-block;
    font-size: 0.7rem;
    margin-right: 5px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.dropdown-content::-webkit-scrollbar {
    width: 6px;
}

.dropdown-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* ==========================================================================
   7. MODAL
   ========================================================================== */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.modal-content {
    background: var(--container-bg);
    color: var(--text-primary);
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    width: 450px;
    max-width: 90%;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid var(--border-color);
    text-align: center;
}

.modal.hidden .modal-content {
    transform: translateY(30px) scale(0.95);
}

.modal h2 {
    color: var(--accent-color);
    font-size: 1.5rem;
    margin-bottom: 20px;
}

.modal input[type="file"] {
    width: 100%;
    padding: 10px;
    background: var(--section-bg);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    margin-bottom: 15px;
    cursor: pointer;
    color: var(--text-primary);
}

.modal input[type="file"]:hover {
    border-color: var(--accent-color);
}

.modal button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--text-secondary);
}

/* ==========================================================================
   8. TOOLTIP
   ========================================================================== */

.tooltip-word {
    border-bottom: 1px dotted var(--text-secondary);
    cursor: help;
    position: relative;
}

#globalTooltip {
    position: fixed;
    padding: 12px 16px;
    background: linear-gradient(135deg, #4a00e0, #8e2de2);
    color: white;
    border-radius: 10px;
    font-size: 1rem;
    pointer-events: none;
    opacity: 0;
    transform: translateY(5px) scale(0.95);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
    box-shadow: 0 8px 24px rgba(74, 0, 224, 0.35);
    z-index: 2000;
    max-width: 320px;
    line-height: 1.5;
}

#globalTooltip.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Tooltip Arrows */
#globalTooltip::after {
    content: "";
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}

#globalTooltip.pos-top::after {
    bottom: -8px;
    left: var(--arrow-left, 50%);
    border-width: 8px 8px 0 8px;
    border-color: #8e2de2 transparent transparent transparent;
}

#globalTooltip.pos-bottom::after {
    top: -8px;
    left: var(--arrow-left, 50%);
    border-width: 0 8px 8px 8px;
    border-color: transparent transparent #8e2de2 transparent;
}

/* 2. Thêm Style cho Tooltip IME (Hiển thị "nihao") */
.ime-tooltip {
    position: fixed;
    z-index: 10000;
    background-color: #2d3436;
    /* Nền đen mờ */
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-family: var(--font-ui);
    font-size: 1.1rem;
    pointer-events: none;
    /* Không chặn click chuột */
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);

    /* Ẩn mặc định */
    opacity: 0;
    transform: translateY(5px);
    transition: opacity 0.1s, transform 0.1s;
}

.ime-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Thêm mũi tên nhỏ chỉ xuống dưới (nếu muốn) */
.ime-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 10px;
    border-width: 5px;
    border-style: solid;
    border-color: #2d3436 transparent transparent transparent;
}

/* DEBUG CSS: Xóa đi sau khi sửa xong */
/* .input-area {
    opacity: 1 !important;
    background: rgba(255, 0, 0, 0.2);
    border: 1px solid red;
    z-index: 10000;
}

.input-area textarea {
    color: red !important;
    caret-color: red !important;
} */

/* ==========================================================================
   9. ANIMATIONS
   ========================================================================== */

@keyframes softPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(74, 0, 224, 0.4);
    }

    70% {
        box-shadow: 0 0 0 4px rgba(74, 0, 224, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(74, 0, 224, 0);
    }
}

/* ==========================================================================
   10. RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 768px) {
    .container {
        border-radius: 0;
        min-height: 100vh;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .stat-item:nth-child(2)::after {
        display: none;
    }

    .text-display-container {
        height: 35vh;
        margin: 10px 15px;
    }

    .text-display {
        padding: 15px;
        font-size: 1.1rem;
    }

    .toolbar {
        padding: 0 15px;
    }

    .toolbar-left {
        justify-content: space-between;
    }

    .btn-icon {
        width: 100%;
        justify-content: center;
        margin-top: 10px;
    }

    .mini-volume-control {
        border-left: none;
        padding-left: 0;
        margin-left: 0;
    }
}

/* ==========================================================================
   11. MEDIA CONTROLS
   ========================================================================== */

.btn-media {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    line-height: 1;
}

.btn-media:hover {
    background-color: var(--toggle-bg);
    color: var(--accent-color);
    transform: scale(1.1);
}

.btn-media:active {
    transform: scale(0.95);
}

/* Ẩn hiện class hidden */
.media-controls.hidden {
    display: none !important;
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 768px) {

    /* Trên điện thoại, bỏ dấu gạch ngăn cách để đỡ rối */
    .media-controls {
        border-left: none;
        padding-left: 0;
        margin-left: 0;
        margin-top: 5px;
        /* Tách ra một chút nếu bị xuống dòng */
    }
}