:root {
    --bg-color: #f4f7f9;
    --sidebar-bg: #ffffff;
    --content-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --accent-color: #3b82f6; /* Blue 500 */
    --accent-hover: #2563eb; /* Blue 600 */
    --danger-color: #ef4444;   /* Red 500 */
    --success-color: #22c55e; /* Green 500 */
    --warning-color: #f59e0b;  /* Amber 500 */
    --record-active-color: var(--danger-color);
    --highlight-bg: #eff6ff;   /* Blue 50 */

    --font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --border-radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-size: 16px;
}

i { margin-right: 8px; }

.app-container {
    display: grid;
    height: 100vh;
    grid-template-columns: 380px 1fr;
}

/* --- Cột Sidebar (Bên trái) --- */
.sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 30px;
    overflow-y: auto;
}

.app-header h1 { font-size: 1.8rem; font-weight: 700; color: var(--text-primary); }
.app-header p { color: var(--text-secondary); font-size: 1rem; }

.section-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}
.section-header h2 { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }

#playlist {
    list-style-type: none; counter-reset: playlist-counter;
    max-height: 60vh; overflow-y: auto;
	margin-top: 30px;
}

#playlist li {
    padding: 10px 12px; border: 1px solid transparent; border-bottom: 1px solid var(--border-color);
    cursor: pointer; transition: all 0.2s ease-in-out;
    font-weight: 500; border-radius: 8px; margin-bottom: 6px;
    display: flex; gap: 12px; align-items: center;
}
#playlist li::before {
    counter-increment: playlist-counter; content: counter(playlist-counter);
    font-weight: 600; color: var(--accent-color); background-color: var(--highlight-bg);
    border-radius: 50%; width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
#playlist li:hover { background-color: var(--highlight-bg); }
#playlist li.active {
    background-color: var(--accent-color); color: white; border-color: var(--accent-hover);
    transform: translateY(-2px); box-shadow: var(--shadow-md);
}
#playlist li.active::before { background-color: white; color: var(--accent-color); }
#playlist li.active .track-duration { color: white; }

.track-details { flex-grow: 1; min-width: 0; }
.track-name { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-duration { font-size: 0.9rem; color: var(--text-secondary); flex-shrink: 0; }

#playlist li.completed {
    background-color: #f3f4f6; color: var(--text-secondary); cursor: not-allowed;
    opacity: 0.8; text-decoration: line-through;
}
#playlist li.completed::before{ background-color: #e5e7eb; color: var(--text-secondary); }

/* --- Khu vực Nội dung chính --- */
.main-content-area {
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.main-content {
    padding: 24px 32px;
    flex-grow: 1;
}

.player-wrapper, .subtitle-display-wrapper {
    background: var(--content-bg); border-radius: var(--border-radius);
    border: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
    padding: 24px; margin-bottom: 24px;
}

#current-track-title { font-size: 1.5rem; font-weight: 600; margin-bottom: 16px; }
#audio-player { width: 100%; }

.speaking-practice-controls {
    display: flex; gap: 20px; justify-content: space-between;
    margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--border-color);
}
.control-group { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.step-label { font-size: 0.9rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; }

/* --- Khu vực Phụ đề --- */
.subtitle-display-wrapper { padding: 0; overflow: hidden; }
.subtitle-tabs { display: flex; border-bottom: 1px solid var(--border-color); padding: 0 24px; }
.tab-button {
    padding: 14px 20px; cursor: pointer; background: none; border: none;
    font-size: 1rem; font-weight: 600; color: var(--text-secondary);
    border-bottom: 3px solid transparent; transition: all 0.2s;
}
.tab-button.active { color: var(--accent-color); border-bottom-color: var(--accent-color); }

#comparison-container { height: 400px; position: relative; padding: 10px; }
.subtitle-box {
    position: absolute; top: 10px; left: 10px; right: 10px; bottom: 10px;
    overflow-y: auto; font-size: 1.25rem; line-height: 1.8; padding: 20px;
    opacity: 0; visibility: hidden; transition: opacity 0.2s, transform 0.2s;
    transform: translateY(10px);
}
.subtitle-box.active { opacity: 1; visibility: visible; transform: translateY(0); }
.subtitle-box p { margin-bottom: 12px; padding: 8px 12px; border-radius: 8px; transition: background-color 0.3s ease; }
.subtitle-box p.highlight { background-color: var(--highlight-bg); color: var(--text-primary); font-weight: 600; }

/* --- Giao diện Kết quả AI --- */
#gemini-result-container {
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}
#gemini-result-container:empty { display: none; }

.gemini-result-header { margin-bottom: 24px; }
.gemini-result-header h2 { font-size: 1.8rem; font-weight: 700; margin-bottom: 4px; }
.gemini-result-header p { color: var(--text-secondary); font-size: 1rem; }

.result-summary-card {
    background: linear-gradient(135deg, #4385f6, #3b74e0);
    color: white; border-radius: 16px; padding: 32px;
    display: grid; grid-template-columns: 1fr 2fr;
    align-items: center; gap: 32px; margin-bottom: 24px;
}
.score-display { text-align: center; }
.score-display .score {
    font-size: 6rem; font-weight: 800; line-height: 1;
    text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
}
.score-display .band {
    font-size: 1.2rem; font-weight: 600; margin-top: 8px;
    background-color: rgba(255, 255, 255, 0.2);
    display: inline-block; padding: 4px 12px; border-radius: 99px;
}
.summary-comment h3 {
    font-size: 1.2rem; font-weight: 600; margin-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3); padding-bottom: 8px;
}
.summary-comment p { font-size: 1rem; line-height: 1.6; opacity: 0.9; }

.feedback-section > h3 {
    font-size: 1.25rem; font-weight: 600; margin-top: 32px;
    margin-bottom: 16px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px;
}
.feedback-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.feedback-card {
    background-color: var(--content-bg); border: 1px solid var(--border-color);
    border-radius: var(--border-radius); padding: 20px; transition: all 0.2s;
}
.feedback-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.feedback-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.feedback-card-header .title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
.feedback-card-header .percentage {
    font-size: 1.1rem; font-weight: 700;
    padding: 4px 8px; border-radius: 6px; color: white;
}
.feedback-card.pronunciation .percentage { background-color: #ef4444; } /* Red */
.feedback-card.fluency .percentage { background-color: #3b82f6; } /* Blue */
.feedback-card.lexical .percentage { background-color: #f97316; } /* Orange */
.feedback-card.grammar .percentage { background-color: #8b5cf6; } /* Violet */
.feedback-card .comment { color: var(--text-secondary); line-height: 1.6; }
.feedback-card ul { list-style-position: inside; padding-left: 10px; line-height: 1.7; color: var(--text-secondary); }

/* --- Khu vực Lịch sử (Dưới cùng) --- */
.results-history-section {
    background-color: var(--sidebar-bg);
    padding: 24px 32px;
    border-top: 1px solid var(--border-color);
}

.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}
.chart-wrapper {
    background: var(--content-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    height: 350px;
}

#history-table-container { max-height: 300px; overflow-y: auto; }
#history-table { width: 100%; border-collapse: collapse; }
#history-table th, #history-table td { border: 1px solid var(--border-color); padding: 12px; text-align: left; font-size: 0.9rem; }
#history-table th { background-color: var(--bg-color); position: sticky; top: 0; font-weight: 600; }
#history-table tbody tr.has-feedback { cursor: pointer; }
#history-table tbody tr.has-feedback:hover { background-color: var(--highlight-bg); }

/* --- Components chung --- */
.button, .button-outline, .button-record {
    padding: 10px 16px; border-radius: 8px; cursor: pointer; font-weight: 600;
    font-family: inherit; border: 2px solid transparent; transition: all 0.2s;
    font-size: 0.95rem; text-align: center; width: 100%;
}
.button { background-color: var(--accent-color); color: white; }
.button:hover { background-color: var(--accent-hover); }
.button-outline { background-color: transparent; color: var(--accent-color); border-color: var(--accent-color); }
.button-outline:hover { background-color: var(--accent-color); color: white; }
.button-record { background-color: var(--success-color); color: white; }
.button-record.recording { background-color: var(--record-active-color); animation: pulse-record 1.2s infinite; }
.button-gemini { background-color: var(--warning-color); color: var(--text-primary); }
.button-gemini:disabled { background-color: #e5e7eb; color: var(--text-secondary); cursor: not-allowed; }
.button-danger {
    background: transparent; color: var(--danger-color);
    border: none; font-size: 0.9rem; padding: 5px 10px;
    cursor: pointer; border-radius: 6px; display: none;
}
.button-danger:hover { background-color: #fee2e2; }
.filename-display { font-weight: 500; color: var(--success-color); font-size: 0.9rem; }
.hidden { display: none !important; }

@keyframes pulse-record {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* --- Responsive --- */
@media (max-width: 1200px) {
    .app-container { grid-template-columns: 1fr; height: auto; }
    .sidebar { border-right: none; border-bottom: 1px solid var(--border-color); }
}
@media (max-width: 768px) {
    .main-content, .results-history-section { padding: 16px; }
    .speaking-practice-controls, .feedback-grid, .charts-container {
        flex-direction: column;
        grid-template-columns: 1fr;
    }
    .result-summary-card { grid-template-columns: 1fr; text-align: center; }
    .summary-comment { text-align: left; }
}