/**
 * QLPATC — app.css
 *
 * Design system: Dark mode, màu chủ đạo đỏ-vàng (phong cách Trung Hoa),
 * glassmorphism, animations, pitch chart styles.
 *
 * Font: Inter (Latin) + Noto Sans SC (Hán tự)
 *
 * @author  ThS. Ngô Đức Toàn
 * @since   v1.0
 */

/* ── Google Fonts ──────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Noto+Sans+SC:wght@300;400;500;700&display=swap');

/* ── CSS Custom Properties ─────────────────────────────────────────────────── */
:root {
    /* Màu chủ đạo */
    --primary:          #e74c3c;
    --primary-dark:     #c0392b;
    --primary-light:    #ff6b5b;
    --secondary:        #f39c12;
    --secondary-dark:   #d68910;
    --accent:           #e91e63;

    /* Nền / Surface */
    --bg-base:          #0d1117;
    --bg-surface:       #161b22;
    --bg-elevated:      #21262d;
    --bg-glass:         rgba(22, 27, 34, 0.8);

    /* Text */
    --text-primary:     #e6edf3;
    --text-secondary:   #8b949e;
    --text-muted:       #484f58;
    --text-on-primary:  #ffffff;

    /* Border */
    --border:           rgba(255,255,255,0.08);
    --border-focus:     rgba(231,76,60,0.5);

    /* Thanh điệu màu */
    --tone-1:           #3498db;
    --tone-2:           #27ae60;
    --tone-3:           #9b59b6;
    --tone-4:           #e74c3c;
    --tone-0:           #95a5a6;

    /* Trạng thái */
    --success:          #27ae60;
    --warning:          #f39c12;
    --error:            #e74c3c;
    --info:             #3498db;

    /* Kích thước */
    --radius-sm:        6px;
    --radius-md:        10px;
    --radius-lg:        16px;
    --radius-xl:        24px;

    /* Shadow */
    --shadow-sm:        0 1px 3px rgba(0,0,0,0.4);
    --shadow-md:        0 4px 12px rgba(0,0,0,0.5);
    --shadow-lg:        0 8px 32px rgba(0,0,0,0.6);
    --shadow-glow:      0 0 30px rgba(231,76,60,0.25);

    /* Transition */
    --transition:       all 0.25s cubic-bezier(0.4,0,0.2,1);
    --transition-fast:  all 0.15s ease;
}

/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Typography ─────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
    font-weight: 700;
    color: var(--text-primary);
}

h1 { font-size: clamp(1.8rem, 4vw, 2.8rem); }
h2 { font-size: clamp(1.4rem, 3vw, 2rem); }
h3 { font-size: clamp(1.1rem, 2.5vw, 1.4rem); }

a {
    color: var(--primary-light);
    text-decoration: none;
    transition: var(--transition-fast);
}
a:hover { color: var(--primary); text-decoration: underline; }

.hanzi {
    font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', serif;
    font-weight: 700;
}

/* ── Glassmorphism Cards ────────────────────────────────────────────────────── */
.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    transition: var(--transition);
}

.glass-card:hover {
    border-color: rgba(255,255,255,0.15);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

/* ── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
    background: rgba(13,17,23,0.95) !important;
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.navbar-brand {
    font-weight: 800;
    font-size: 1.3rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.navbar .nav-link {
    color: var(--text-secondary) !important;
    font-weight: 500;
    transition: var(--transition-fast);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
}

.navbar .nav-link:hover,
.navbar .nav-link.active {
    color: var(--text-primary) !important;
    background: rgba(255,255,255,0.05);
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    font-weight: 600;
    border-radius: var(--radius-md);
    padding: 0.6rem 1.4rem;
    transition: var(--transition);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 4px 15px rgba(231,76,60,0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(231,76,60,0.45);
    color: #fff;
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.2);
    color: var(--text-primary);
}

.btn-success {
    background: linear-gradient(135deg, #27ae60, #1a8a47);
    color: #fff;
    box-shadow: 0 4px 15px rgba(39,174,96,0.3);
}
.btn-success:hover {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    transform: translateY(-1px);
    color: #fff;
}

.btn-record {
    background: linear-gradient(135deg, var(--primary), #ff4444);
    color: #fff;
    font-size: 1.1rem;
    padding: 1rem 2rem;
    border-radius: var(--radius-xl);
    box-shadow: 0 4px 20px rgba(231,76,60,0.4);
    min-width: 160px;
    justify-content: center;
}

.btn-record:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 30px rgba(231,76,60,0.55);
    color: #fff;
}

.btn-record.recording {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    animation: pulse-record 1s ease infinite;
}

@keyframes pulse-record {
    0%, 100% { box-shadow: 0 4px 20px rgba(231,76,60,0.4); }
    50%       { box-shadow: 0 4px 35px rgba(231,76,60,0.8); }
}

.btn-lg  { padding: 0.8rem 2rem; font-size: 1.05rem; }
.btn-sm  { padding: 0.35rem 0.9rem; font-size: 0.85rem; }
.btn-icon { padding: 0.6rem; min-width: 40px; justify-content: center; }

/* ── Form Controls ──────────────────────────────────────────────────────────── */
.form-control, .form-select {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-md) !important;
    padding: 0.7rem 1rem !important;
    transition: var(--transition-fast) !important;
}

.form-control:focus, .form-select:focus {
    border-color: var(--border-focus) !important;
    box-shadow: 0 0 0 3px rgba(231,76,60,0.15) !important;
    outline: none !important;
}

.form-control::placeholder { color: var(--text-muted) !important; }

.form-label {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
    display: block;
}

.form-check-input {
    background-color: var(--bg-elevated) !important;
    border-color: var(--border) !important;
}
.form-check-input:checked {
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}

/* ── Hero Section ───────────────────────────────────────────────────────────── */
.hero {
    min-height: 80vh;
    display: flex;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 60% 50% at 20% 40%, rgba(231,76,60,0.15) 0%, transparent 60%),
        radial-gradient(ellipse 50% 60% at 80% 60%, rgba(243,156,18,0.1) 0%, transparent 60%);
    pointer-events: none;
}

.hero-bg-hanzi {
    position: absolute;
    right: 5%;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20vw;
    font-family: 'Noto Sans SC', serif;
    font-weight: 900;
    color: rgba(255,255,255,0.025);
    pointer-events: none;
    user-select: none;
    line-height: 1;
}

/* ── Test Card ──────────────────────────────────────────────────────────────── */
.word-display {
    text-align: center;
    padding: 2.5rem 1rem;
}

.word-hanzi {
    font-size: clamp(4rem, 12vw, 8rem);
    font-family: 'Noto Sans SC', serif;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 30px rgba(231,76,60,0.3));
}

.word-pinyin {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.word-translation {
    font-size: 1rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ── Pitch Chart ────────────────────────────────────────────────────────────── */
.pitch-chart-container {
    position: relative;
    height: 180px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow: hidden;
}

.pitch-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ── Tone Score Bars ────────────────────────────────────────────────────────── */
.tone-score-bar {
    margin-bottom: 0.8rem;
}

.tone-score-bar .label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.tone-score-bar .bar {
    height: 8px;
    background: var(--bg-elevated);
    border-radius: 4px;
    overflow: hidden;
}

.tone-score-bar .fill {
    height: 100%;
    border-radius: 4px;
    transition: width 1s cubic-bezier(0.4,0,0.2,1);
}

.fill-tone-1 { background: linear-gradient(90deg, var(--tone-1), #5dade2); }
.fill-tone-2 { background: linear-gradient(90deg, var(--tone-2), #58d68d); }
.fill-tone-3 { background: linear-gradient(90deg, var(--tone-3), #c39bd3); }
.fill-tone-4 { background: linear-gradient(90deg, var(--tone-4), #f1948a); }
.fill-tone-0 { background: linear-gradient(90deg, var(--tone-0), #bfc9ca); }

/* ── Score Circle ───────────────────────────────────────────────────────────── */
.score-circle {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0 auto;
}

.score-circle svg { transform: rotate(-90deg); }

.score-circle .score-number {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.score-circle .score-number small {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    -webkit-text-fill-color: var(--text-muted);
}

/* ── Feedback Badge ─────────────────────────────────────────────────────────── */
.feedback-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
}

/* ── Progress Bar ───────────────────────────────────────────────────────────── */
.test-progress {
    display: flex;
    gap: 6px;
    margin-bottom: 1.5rem;
}

.test-progress-dot {
    height: 6px;
    flex: 1;
    border-radius: 3px;
    background: var(--bg-elevated);
    transition: var(--transition);
}
.test-progress-dot.done    { background: var(--success); }
.test-progress-dot.current { background: var(--primary); animation: blink 1s ease infinite; }
.test-progress-dot.correct { background: var(--success); }
.test-progress-dot.wrong   { background: var(--error); }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

/* ── Mic Status ─────────────────────────────────────────────────────────────── */
.mic-wave {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 40px;
    justify-content: center;
    padding: 4px 0;
}

.mic-wave span {
    width: 4px;
    background: var(--primary);
    border-radius: 2px;
    transition: height 0.1s ease;
}

.mic-wave.active span { animation: wave 0.8s ease-in-out infinite; }
.mic-wave span:nth-child(1) { animation-delay: 0s; }
.mic-wave span:nth-child(2) { animation-delay: 0.1s; }
.mic-wave span:nth-child(3) { animation-delay: 0.2s; }
.mic-wave span:nth-child(4) { animation-delay: 0.3s; }
.mic-wave span:nth-child(5) { animation-delay: 0.2s; }
.mic-wave span:nth-child(6) { animation-delay: 0.1s; }

@keyframes wave {
    0%, 100% { height: 6px; }
    50%       { height: 32px; }
}

/* ── Alerts / Toast ─────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast-msg {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.8rem 1.2rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    box-shadow: var(--shadow-md);
    animation: slideInRight 0.3s ease;
    max-width: 320px;
}

.toast-msg.success { border-left: 3px solid var(--success); }
.toast-msg.error   { border-left: 3px solid var(--error); }
.toast-msg.warning { border-left: 3px solid var(--warning); }

@keyframes slideInRight {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0);   opacity: 1; }
}

/* ── Stepper ────────────────────────────────────────────────────────────────── */
.stepper {
    display: flex;
    gap: 0;
    margin-bottom: 2rem;
    position: relative;
}

.stepper::before {
    content: '';
    position: absolute;
    top: 16px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--border);
    z-index: 0;
}

.stepper-step {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    z-index: 1;
    position: relative;
}

.stepper-step .dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition);
}

.stepper-step.active .dot  { background: var(--primary); border-color: var(--primary); color: #fff; }
.stepper-step.done .dot    { background: var(--success); border-color: var(--success); color: #fff; }

.stepper-step .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    white-space: nowrap;
}
.stepper-step.active .label { color: var(--primary); }
.stepper-step.done .label   { color: var(--success); }

/* ── Level Badge ────────────────────────────────────────────────────────────── */
.level-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.2rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 1rem;
}

.level-so-cap-1  { background: rgba(231,76,60,0.2);  color: #e74c3c; border: 1px solid rgba(231,76,60,0.3); }
.level-so-cap-2  { background: rgba(243,156,18,0.2); color: #f39c12; border: 1px solid rgba(243,156,18,0.3); }
.level-trung-cap { background: rgba(52,152,219,0.2); color: #3498db; border: 1px solid rgba(52,152,219,0.3); }
.level-cao-cap-1 { background: rgba(39,174,96,0.2);  color: #27ae60; border: 1px solid rgba(39,174,96,0.3); }
.level-cao-cap-2 { background: rgba(155,89,182,0.2); color: #9b59b6; border: 1px solid rgba(155,89,182,0.3); }

/* ── Table ──────────────────────────────────────────────────────────────────── */
.table-dark-custom {
    --bs-table-bg: var(--bg-elevated);
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border);
    --bs-table-hover-bg: rgba(255,255,255,0.04);
    border-radius: var(--radius-md);
    overflow: hidden;
}

/* ── Spinner / Loading ──────────────────────────────────────────────────────── */
.spinner-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    z-index: 10;
}

/* ── Countdown Timer ────────────────────────────────────────────────────────── */
.countdown-timer {
    font-size: 1.5rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--primary);
}

.countdown-timer.warning { color: var(--warning); animation: blink 0.5s ease infinite; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .glass-card { padding: 1rem; }
    .word-hanzi { font-size: 4rem; }
    .pitch-chart-container { height: 140px; }
    .score-circle { width: 120px; height: 120px; }
    .score-circle .score-number { font-size: 1.8rem; }
    .stepper-step .label { display: none; }
    .toast-container { bottom: 1rem; right: 1rem; left: 1rem; }
    .toast-msg { max-width: 100%; }
}

/* ── Print ──────────────────────────────────────────────────────────────────── */
@media print {
    .navbar, .btn, .toast-container { display: none !important; }
    body { background: #fff; color: #000; }
    .glass-card, .card { border: 1px solid #ddd; background: #fff; }
}

/* ── Utility ────────────────────────────────────────────────────────────────── */
.text-gradient {
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.border-gradient {
    border: 1px solid transparent;
    background: linear-gradient(var(--bg-elevated), var(--bg-elevated)) padding-box,
                linear-gradient(135deg, var(--primary), var(--secondary)) border-box;
}

.pulse { animation: pulse-glow 2s ease infinite; }
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0); }
    50%       { box-shadow: 0 0 0 10px rgba(231,76,60,0.15); }
}

.fade-in  { animation: fadeIn 0.4s ease; }
.slide-up { animation: slideUp 0.4s ease; }

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Scrollbar */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
