/* ═══════════════════════════════════════════════════════════════════════════
   TalkVatar AI — Main Stylesheet (Light Theme)
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --tv-accent:        #4f46e5;
    --tv-accent-light:  #e0e7ff;
    --tv-accent-dark:   #3730a3;
    --tv-bg:            #f8fafc;
    --tv-surface:       #ffffff;
    --tv-surface2:      #f1f5f9;
    --tv-border:        #e2e8f0;
    --tv-text:          #1e293b;
    --tv-text-muted:    #64748b;
    --tv-success:       #059669;
    --tv-danger:        #dc2626;
    --tv-warning:       #d97706;
    --tv-shadow-sm:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --tv-shadow:        0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --tv-shadow-lg:     0 10px 24px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.06);
    --tv-radius:        12px;
    --tv-radius-sm:     8px;
    --tv-radius-lg:     18px;
    --tv-font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
.tv-app *, .tv-app *::before, .tv-app *::after { box-sizing: border-box; }
.tv-app { font-family: var(--tv-font); color: var(--tv-text); font-size: 15px; line-height: 1.5; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.tv-app {
    display: flex;
    gap: 16px;
    min-height: 600px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    background: var(--tv-bg);
    position: relative;
}

.tv-panel {
    background: var(--tv-surface);
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius-lg);
    box-shadow: var(--tv-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tv-panel-left {
    width: 240px;
    min-width: 220px;
    flex-shrink: 0;
    padding: 16px;
    gap: 12px;
    overflow-y: auto;
    max-height: 90vh;
}

.tv-panel-main {
    flex: 1;
    min-width: 0;
}

/* ── Panel Headers ─────────────────────────────────────────────────────────── */
.tv-panel-header { margin-bottom: 12px; }
.tv-panel-title {
    font-size: 14px; font-weight: 700; color: var(--tv-accent);
    margin: 0; text-transform: uppercase; letter-spacing: .5px;
}

/* ── Character Cards ───────────────────────────────────────────────────────── */
.tv-char-grid {
    display: flex; flex-direction: column; gap: 8px;
    margin-bottom: 16px;
}
.tv-char-card {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border: 2px solid var(--tv-border);
    border-radius: var(--tv-radius);
    cursor: pointer;
    transition: all .18s ease;
    background: var(--tv-surface2);
}
.tv-char-card:hover {
    border-color: var(--tv-accent);
    background: var(--tv-accent-light);
    transform: translateX(2px);
}
.tv-char-card.active {
    border-color: var(--tv-accent);
    background: var(--tv-accent-light);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.tv-char-thumb {
    width: 44px; height: 44px;
    border-radius: 50%; overflow: hidden;
    background: var(--tv-border);
    flex-shrink: 0;
}
.tv-char-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tv-char-name { font-weight: 700; font-size: 14px; color: var(--tv-text); line-height: 1.2; }
.tv-char-desc { font-size: 11px; color: var(--tv-text-muted); line-height: 1.3; }

/* ── Settings Sections ─────────────────────────────────────────────────────── */
.tv-settings-section { margin-bottom: 16px; }
.tv-section-label { font-size: 12px; font-weight: 700; color: var(--tv-text-muted);
    text-transform: uppercase; letter-spacing: .4px; margin: 0 0 8px; }
.tv-label { display: block; font-size: 12px; color: var(--tv-text-muted); margin: 8px 0 2px; }
.tv-select {
    width: 100%; padding: 7px 10px; font-size: 13px;
    border: 1.5px solid var(--tv-border); border-radius: var(--tv-radius-sm);
    background: var(--tv-surface); color: var(--tv-text); cursor: pointer;
    transition: border-color .15s;
}
.tv-select:focus { outline: none; border-color: var(--tv-accent); }
.tv-slider {
    width: 100%; margin: 4px 0;
    accent-color: var(--tv-accent);
}

/* ── Mini Stats ────────────────────────────────────────────────────────────── */
.tv-mini-stats { display: flex; gap: 6px; }
.tv-mini-stat {
    flex: 1; text-align: center; background: var(--tv-surface2);
    border-radius: var(--tv-radius-sm); padding: 8px 4px;
}
.tv-mini-stat span { display: block; font-size: 20px; font-weight: 800; color: var(--tv-accent); line-height: 1; }
.tv-mini-stat small { font-size: 10px; color: var(--tv-text-muted); }

/* ── Avatar Section ────────────────────────────────────────────────────────── */
.tv-avatar-section {
    background: linear-gradient(135deg, #f0f4ff 0%, #fafaff 100%);
    border-bottom: 1px solid var(--tv-border);
    padding: 16px 20px;
}
.tv-avatar-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px; flex-wrap: wrap; gap: 8px;
}
.tv-char-nameplate { display: flex; flex-direction: column; }
.tv-char-display-name { font-size: 20px; font-weight: 800; color: var(--tv-accent); line-height: 1.2; }
.tv-char-display-desc { font-size: 12px; color: var(--tv-text-muted); }
.tv-session-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tv-timer-label { font-size: 16px; font-weight: 700; color: var(--tv-text-muted); }

/* ── Avatar Canvas / Wrap ──────────────────────────────────────────────────── */
.tv-avatar-wrap {
    display: flex; justify-content: center; align-items: center;
    height: 280px;
    position: relative;
}

.tv-canvas {
    height: 100%; width: auto;
    border-radius: var(--tv-radius);
    /* Glow that matches accent color */
    filter: drop-shadow(0 8px 24px rgba(79,70,229,.18));
    transition: filter .3s;
}
.tv-canvas.tv-gif-canvas {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    height: 100%; width: auto; z-index: 0;
    opacity: 0.08; /* canvas just provides glow for gif mode */
}
.tv-gif-img {
    height: 100%; width: auto;
    border-radius: var(--tv-radius);
    position: relative; z-index: 1;
    filter: drop-shadow(0 8px 24px rgba(79,70,229,.18));
}

.tv-avatar-placeholder {
    text-align: center; color: var(--tv-text-muted);
}
.tv-avatar-placeholder-icon { font-size: 64px; display: block; margin-bottom: 8px; }

/* Typing dots */
.tv-typing {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px; background: var(--tv-accent-light);
    border-radius: 20px; margin-top: 8px;
    width: fit-content;
}
.tv-typing-dot {
    width: 8px; height: 8px; background: var(--tv-accent);
    border-radius: 50%; animation: tv-bounce .9s infinite ease-in-out;
}
.tv-typing-dot:nth-child(2) { animation-delay: .2s; }
.tv-typing-dot:nth-child(3) { animation-delay: .4s; }
.tv-typing-label { font-size: 12px; color: var(--tv-accent); }
@keyframes tv-bounce {
    0%,80%,100% { transform: scale(.6); opacity:.6; }
    40% { transform: scale(1); opacity:1; }
}

/* ── Chat Section ──────────────────────────────────────────────────────────── */
.tv-chat-section { display: flex; flex-direction: column; flex: 1; padding: 0; }

.tv-chat-messages {
    flex: 1; overflow-y: auto;
    padding: 16px 20px;
    display: flex; flex-direction: column; gap: 10px;
    min-height: 200px; max-height: 320px;
    background: var(--tv-surface);
}

/* ── Messages ──────────────────────────────────────────────────────────────── */
.tv-msg { max-width: 82%; word-break: break-word; }
.tv-msg-name { display: block; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .5px; margin-bottom: 3px; }
.tv-msg-body { padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.55; }

.tv-msg-user { align-self: flex-end; }
.tv-msg-user .tv-msg-name { color: var(--tv-accent); text-align: right; }
.tv-msg-user .tv-msg-body {
    background: var(--tv-accent); color: #fff;
    border-bottom-right-radius: 4px;
}

.tv-msg-ai { align-self: flex-start; }
.tv-msg-ai .tv-msg-name { color: var(--tv-success); }
.tv-msg-ai .tv-msg-body {
    background: var(--tv-surface2); color: var(--tv-text);
    border: 1px solid var(--tv-border);
    border-bottom-left-radius: 4px;
}

.tv-msg-system { align-self: center; font-size: 12px; color: var(--tv-text-muted);
    font-style: italic; }
.tv-msg-error { align-self: flex-start; }
.tv-msg-error .tv-msg-body { background: #fef2f2; color: var(--tv-danger);
    border: 1px solid #fecaca; }
.tv-msg-correction {
    align-self: flex-start; max-width: 90%;
    background: #fffbeb; border: 1px dashed var(--tv-warning);
    border-radius: var(--tv-radius-sm); padding: 8px 12px;
    font-size: 13px; color: var(--tv-warning);
}
.tv-correction-icon { margin-right: 6px; }

/* Clickable word highlighting */
.tv-word {
    cursor: pointer; border-radius: 3px;
    transition: background .15s;
}
.tv-word:hover { background: var(--tv-accent-light); }

/* ── Interim text ──────────────────────────────────────────────────────────── */
.tv-interim {
    font-size: 13px; color: var(--tv-text-muted); font-style: italic;
    padding: 4px 20px;
}

/* ── Input Row ─────────────────────────────────────────────────────────────── */
.tv-input-row {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--tv-border);
    background: var(--tv-surface2);
}
.tv-textarea {
    flex: 1; resize: none; padding: 10px 14px;
    border: 1.5px solid var(--tv-border); border-radius: var(--tv-radius);
    font-size: 14px; font-family: var(--tv-font);
    background: var(--tv-surface); color: var(--tv-text);
    transition: border-color .15s; line-height: 1.4;
}
.tv-textarea:focus { outline: none; border-color: var(--tv-accent); }
.tv-textarea:disabled { background: #f8fafc; cursor: not-allowed; }

/* ── Action Row ────────────────────────────────────────────────────────────── */
.tv-action-row {
    display: flex; gap: 6px; align-items: center;
    padding: 8px 16px 12px;
    background: var(--tv-surface2);
    flex-wrap: wrap;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.tv-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 4px; padding: 9px 18px; border-radius: var(--tv-radius-sm);
    font-size: 14px; font-weight: 600; cursor: pointer;
    border: none; text-decoration: none;
    transition: all .18s ease; white-space: nowrap;
    font-family: var(--tv-font);
}
.tv-btn:focus-visible { outline: 3px solid var(--tv-accent); outline-offset: 2px; }
.tv-btn:disabled { opacity: .45; cursor: not-allowed; }

.tv-btn-primary {
    background: var(--tv-accent); color: #fff;
    box-shadow: 0 2px 8px rgba(79,70,229,.3);
}
.tv-btn-primary:hover:not(:disabled) {
    background: var(--tv-accent-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(79,70,229,.4);
}

.tv-btn-danger { background: var(--tv-danger); color: #fff; }
.tv-btn-danger:hover:not(:disabled) { background: #b91c1c; }

.tv-btn-outline {
    background: transparent; color: var(--tv-accent);
    border: 1.5px solid var(--tv-accent);
}
.tv-btn-outline:hover:not(:disabled) { background: var(--tv-accent-light); }

.tv-btn-ghost {
    background: transparent; color: var(--tv-text-muted);
    border: 1.5px solid var(--tv-border);
}
.tv-btn-ghost:hover:not(:disabled) { background: var(--tv-surface2); }

.tv-btn-sm { padding: 6px 12px; font-size: 12px; }
.tv-full-width { width: 100%; }

.tv-btn-mic {
    flex-direction: column; padding: 8px 12px; gap: 2px;
    border: 2px solid var(--tv-border); background: var(--tv-surface);
    color: var(--tv-text); min-width: 60px;
    border-radius: var(--tv-radius);
    transition: all .2s;
}
.tv-btn-mic:hover:not(:disabled) { border-color: var(--tv-accent); background: var(--tv-accent-light); }
.tv-btn-mic.listening {
    border-color: var(--tv-danger); background: #fef2f2; color: var(--tv-danger);
    animation: tv-pulse-mic 1.2s infinite;
}
.tv-mic-icon { font-size: 18px; }
.tv-btn-label { font-size: 10px; }

.tv-btn-send { padding: 10px 20px; }

.tv-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 6px;
    background: var(--tv-accent); color: #fff;
    border-radius: 10px; font-size: 11px; font-weight: 700;
    margin-left: 4px;
}

@keyframes tv-pulse-mic {
    0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.35); }
    50% { box-shadow: 0 0 0 6px rgba(220,38,38,.0); }
}

/* ── Vocabulary Panel ──────────────────────────────────────────────────────── */
.tv-vocab-panel {
    position: fixed; right: 0; top: 0; bottom: 0;
    width: 320px; max-width: 90vw;
    background: var(--tv-surface);
    border-left: 1px solid var(--tv-border);
    box-shadow: var(--tv-shadow-lg);
    z-index: 9999;
    display: flex; flex-direction: column;
    padding: 16px;
}
.tv-vocab-header { display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px; }
.tv-vocab-header h3 { margin: 0; font-size: 16px; color: var(--tv-text); }
.tv-close-btn { background: none; border: none; font-size: 18px; cursor: pointer;
    color: var(--tv-text-muted); padding: 4px; }
.tv-vocab-tip { font-size: 12px; color: var(--tv-text-muted); margin: 0 0 12px; }
.tv-vocab-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.tv-vocab-item {
    padding: 10px 12px; background: var(--tv-surface2);
    border-radius: var(--tv-radius-sm); border-left: 3px solid var(--tv-accent);
}
.tv-vocab-item strong { display: block; font-size: 15px; color: var(--tv-accent); margin-bottom: 3px; }
.tv-vocab-item p { margin: 0 0 4px; font-size: 13px; }
.tv-vocab-item em { font-size: 12px; color: var(--tv-text-muted); }

/* ── Popups ─────────────────────────────────────────────────────────────────── */
.tv-popup {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,.35); z-index: 10000;
    backdrop-filter: blur(3px);
}
.tv-popup-content {
    background: var(--tv-surface); border-radius: var(--tv-radius-lg);
    box-shadow: var(--tv-shadow-lg);
    padding: 28px 32px; max-width: 420px; width: 90%;
}
.tv-popup-word { font-size: 22px; color: var(--tv-accent); margin: 0 0 10px; }
.tv-popup-def { font-size: 15px; margin: 0 0 8px; }
.tv-popup-example { font-size: 13px; color: var(--tv-text-muted); }
.tv-mt-8 { margin-top: 8px; }
.tv-pron-phrase {
    font-size: 18px; font-weight: 600; color: var(--tv-text);
    background: var(--tv-accent-light); padding: 16px;
    border-radius: var(--tv-radius-sm); margin: 12px 0;
    line-height: 1.4;
}
.tv-pron-tip { font-size: 13px; color: var(--tv-text-muted); margin: 0 0 12px; }
.tv-pron-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tv-pron-result {
    margin-top: 12px; padding: 12px; border-radius: var(--tv-radius-sm);
    background: var(--tv-accent-light); color: var(--tv-accent);
    font-weight: 600; font-size: 14px;
}

/* ── Session Summary Modal ─────────────────────────────────────────────────── */
.tv-modal {
    position: fixed; inset: 0; display: flex; align-items: center;
    justify-content: center; background: rgba(0,0,0,.4); z-index: 10001;
    backdrop-filter: blur(4px);
}
.tv-modal-content {
    background: var(--tv-surface); border-radius: var(--tv-radius-lg);
    box-shadow: var(--tv-shadow-lg); padding: 36px 40px;
    max-width: 500px; width: 90%; text-align: center;
}
.tv-modal-content h2 { margin: 0 0 20px; font-size: 24px; color: var(--tv-text); }
.tv-summary-grid {
    display: flex; flex-wrap: wrap; gap: 12px; justify-content: center;
    margin-bottom: 8px;
}
.tv-sum-box {
    background: var(--tv-surface2); border-radius: var(--tv-radius);
    padding: 16px 20px; min-width: 90px; border: 1.5px solid var(--tv-border);
}
.tv-sum-box span { display: block; font-size: 28px; font-weight: 800; color: var(--tv-accent); }
.tv-sum-box label { font-size: 12px; color: var(--tv-text-muted); }
.tv-sum-score span { color: var(--tv-success); font-size: 32px; }

/* ── Stats Widget (shortcode) ──────────────────────────────────────────────── */
.tv-stats-widget { padding: 16px; }
.tv-stats-grid {
    display: flex; flex-wrap: wrap; gap: 12px;
}
.tv-stat-box {
    background: var(--tv-surface2); border-radius: var(--tv-radius);
    padding: 16px; text-align: center; min-width: 100px;
    border: 1px solid var(--tv-border);
}
.tv-stat-box span { display: block; font-size: 28px; font-weight: 800; color: var(--tv-accent); }
.tv-stat-box label { font-size: 12px; color: var(--tv-text-muted); }
.tv-stats-loading { color: var(--tv-text-muted); font-style: italic; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .tv-app { flex-direction: column; padding: 8px; gap: 8px; }
    .tv-panel-left { width: 100%; max-height: none; }
    .tv-char-grid { flex-direction: row; flex-wrap: wrap; }
    .tv-char-card { flex-direction: column; text-align: center; width: calc(50% - 4px); }
    .tv-char-thumb { margin: 0 auto; }
    .tv-avatar-wrap { height: 200px; }
    .tv-chat-messages { max-height: 220px; }
    .tv-vocab-panel { width: 100%; right: 0; top: 0; }
}

@media (max-width: 480px) {
    .tv-char-card { width: 100%; flex-direction: row; }
    .tv-avatar-section { padding: 10px 12px; }
    .tv-input-row { padding: 8px; }
    .tv-btn-send { padding: 10px 14px; }
}

/* ── Auto-Listen Toggle ──────────────────────────────────────────────────────── */
.tv-auto-listen-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--tv-border, #e2e8f0);
    background: var(--tv-surface, #f8fafc);
    font-size: 0.78rem;
    color: var(--tv-text-muted, #64748b);
    user-select: none;
    transition: background 0.2s, border-color 0.2s;
}
.tv-auto-listen-label:hover {
    background: var(--tv-bg, #f1f5f9);
    border-color: var(--tv-accent, #4f46e5);
}
.tv-auto-listen-label input[type="checkbox"] {
    accent-color: var(--tv-accent, #4f46e5);
    width: 15px;
    height: 15px;
    cursor: pointer;
}
.tv-auto-listen-label input:checked + .tv-auto-listen-text {
    color: var(--tv-accent, #4f46e5);
    font-weight: 600;
}
/* Pulse animation on mic button when auto-listen kicks in */
#tv-mic-btn.listening {
    animation: tv-mic-pulse 1.2s ease-in-out infinite;
    border-color: #ef4444 !important;
    background: #fef2f2 !important;
}
@keyframes tv-mic-pulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.35); }
    50%      { box-shadow: 0 0 0 7px rgba(239,68,68,0); }
}

/* ── Back Button ─────────────────────────────────────────────────────────────── */
.tv-btn-back {
    background: #f1f5f9;
    color: #475569;
    border: 1.5px solid #cbd5e1;
    font-size: 0.82rem;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, color 0.18s;
}
.tv-btn-back:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
    color: #1e293b;
}

/* ── Stop Speaking button — visual feedback when stopping ────────────────────── */
#tv-stop-speech-btn:disabled {
    opacity: 0.55;
    cursor: wait;
}

/* ── Action row — wrap on small screens ─────────────────────────────────────── */
.tv-action-row {
    flex-wrap: wrap;
    gap: 6px;
}

/* ── Topic Suggestions ──────────────────────────────────────────────────────── */
.tv-topic-suggestions { margin-top: 8px; padding: 8px; background: #f8fafc; border-radius: 8px; border: 1px solid #e2e8f0; }
.tv-topic-label { font-size: 0.75rem; color: #64748b; margin: 0 0 6px 0; }
.tv-topic-chip {
    display: inline-block; padding: 3px 10px; margin: 2px;
    background: #fff; border: 1.5px solid var(--tv-accent,#4f46e5);
    color: var(--tv-accent,#4f46e5); border-radius: 20px;
    font-size: 0.75rem; cursor: pointer; transition: all 0.15s;
}
.tv-topic-chip:hover { background: var(--tv-accent,#4f46e5); color: #fff; }

/* ── User Dashboard ─────────────────────────────────────────────────────────── */
.tv-dashboard { max-width: 1000px; margin: 0 auto; padding: 20px; font-family: inherit; }
.tv-dash-header { margin-bottom: 24px; }
.tv-dash-header h2 { margin: 0 0 4px; font-size: 1.6rem; }
.tv-dash-subtitle { color: #64748b; margin: 0; }
.tv-dash-loading { text-align: center; padding: 40px; color: #64748b; font-style: italic; }
.tv-dash-error { text-align: center; padding: 20px; color: #ef4444; background: #fef2f2; border-radius: 8px; }

.tv-dash-cards { display: grid; grid-template-columns: repeat(auto-fit,minmax(140px,1fr)); gap: 12px; margin-bottom: 28px; }
.tv-dash-card { padding: 20px 16px; border-radius: 12px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.07); }
.tv-dash-card-blue   { background: linear-gradient(135deg,#dbeafe,#eff6ff); }
.tv-dash-card-purple { background: linear-gradient(135deg,#ede9fe,#f5f3ff); }
.tv-dash-card-green  { background: linear-gradient(135deg,#d1fae5,#ecfdf5); }
.tv-dash-card-orange { background: linear-gradient(135deg,#ffedd5,#fff7ed); }
.tv-dash-card-gold   { background: linear-gradient(135deg,#fef9c3,#fefce8); }
.tv-dash-card-teal   { background: linear-gradient(135deg,#ccfbf1,#f0fdfa); }
.tv-dash-card-icon { font-size: 1.6rem; margin-bottom: 6px; }
.tv-dash-card-val { font-size: 1.8rem; font-weight: 700; color: #1e293b; }
.tv-dash-card-label { font-size: 0.75rem; color: #475569; margin-top: 4px; }

.tv-dash-section { margin-bottom: 28px; }
.tv-dash-section h3 { font-size: 1.1rem; margin: 0 0 12px; color: #1e293b; }
.tv-dash-table-wrap { overflow-x: auto; }
.tv-dash-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.tv-dash-table th { background: #f1f5f9; padding: 8px 12px; text-align: left; font-weight: 600; color: #475569; }
.tv-dash-table td { padding: 8px 12px; border-bottom: 1px solid #f1f5f9; }
.tv-dash-table tr:hover td { background: #f8fafc; }
.tv-dash-empty { text-align: center; color: #94a3b8; padding: 20px !important; }

.tv-dash-vocab-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(200px,1fr)); gap: 10px; }
.tv-d-vocab-card { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; }
.tv-d-vocab-card strong { display: block; color: #4f46e5; margin-bottom: 4px; }
.tv-d-vocab-card p { margin: 0; font-size: 0.82rem; color: #475569; }

/* ── Admin KPI Grid ─────────────────────────────────────────────────────────── */
.tva-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(130px,1fr)); gap: 12px; margin-bottom: 24px; }
.tva-kpi-card { padding: 18px 12px; border-radius: 10px; text-align: center; border: 1px solid #e2e8f0; background: #fff; }
.tva-kpi-blue   { border-top: 3px solid #3b82f6; }
.tva-kpi-purple { border-top: 3px solid #8b5cf6; }
.tva-kpi-green  { border-top: 3px solid #10b981; }
.tva-kpi-orange { border-top: 3px solid #f59e0b; }
.tva-kpi-gold   { border-top: 3px solid #eab308; }
.tva-kpi-teal   { border-top: 3px solid #14b8a6; }
.tva-kpi-pink   { border-top: 3px solid #ec4899; }
.tva-kpi-gray   { border-top: 3px solid #6b7280; }
.tva-kpi-val { font-size: 1.9rem; font-weight: 700; color: #1e293b; }
.tva-kpi-lbl { font-size: 0.75rem; color: #64748b; margin-top: 4px; }
.tva-dash-cols { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 0; }
.tva-badge-default { background: #dbeafe; color: #1d4ed8; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; }
.tva-badge-custom  { background: #d1fae5; color: #065f46; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; }
.tva-help { cursor: help; color: #94a3b8; border: 1px solid #94a3b8; border-radius: 50%; padding: 0 5px; font-size: 0.75rem; }

/* ── Inline Correction Cards (in chat) ──────────────────────────────────────── */
.tv-msg-correction {
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
    border-radius: 8px;
    padding: 10px 14px;
    margin: 4px 0;
    font-size: 0.875rem;
}
.tv-correction-row { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.tv-correction-row:last-child { margin-bottom: 0; }
.tv-corr-label {
    font-size: 0.72rem; font-weight: 700; white-space: nowrap;
    padding: 1px 6px; border-radius: 4px; flex-shrink: 0;
}
.tv-corr-wrong  { background: #fee2e2; color: #b91c1c; }
.tv-corr-right  { background: #d1fae5; color: #065f46; }
.tv-corr-text   { color: #374151; line-height: 1.4; }

/* ── Hint Button — badge when corrections exist ──────────────────────────────── */
#tv-hint-btn { position: relative; }

/* ── Session Summary ─────────────────────────────────────────────────────────── */
.tv-sum-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

/* ── Correction Analysis Panel (floating) ────────────────────────────────────── */
.tv-correction-panel {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 99999;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    width: min(680px, 94vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tv-cp-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg,#f0f9ff,#fff);
    flex-shrink: 0;
}
.tv-cp-header h3 { margin: 0; font-size: 1.1rem; color: #1e293b; }
.tv-cp-tip { margin: 0; padding: 10px 20px; font-size: 0.8rem; color: #64748b; background: #f8fafc; flex-shrink: 0; }
.tv-cp-empty { text-align: center; padding: 40px; color: #22c55e; font-weight: 600; font-size: 1rem; }
.tv-cp-list {
    overflow-y: auto; padding: 12px 20px 20px;
    display: flex; flex-direction: column; gap: 12px;
}
.tv-cp-item {
    background: #f8fafc; border: 1px solid #e2e8f0;
    border-radius: 10px; padding: 12px 14px;
}
.tv-cp-num { font-size: 0.75rem; color: #94a3b8; margin-bottom: 8px; font-weight: 600; }
.tv-cp-time { font-weight: 400; margin-left: 4px; }
.tv-cp-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.tv-cp-row:last-child { margin-bottom: 0; }
.tv-cp-badge {
    font-size: 0.7rem; font-weight: 700; padding: 2px 8px;
    border-radius: 4px; white-space: nowrap; flex-shrink: 0;
}
.tv-cp-wrong   { background: #fee2e2; color: #b91c1c; }
.tv-cp-correct { background: #d1fae5; color: #065f46; }
.tv-cp-sentence { flex: 1; font-size: 0.9rem; color: #374151; line-height: 1.5; }
.tv-cp-correct-text { font-weight: 600; color: #065f46; }
.tv-practice-corr-btn {
    padding: 3px 10px !important; font-size: 0.75rem !important;
    border: 1.5px solid #10b981 !important; color: #065f46 !important;
    background: #ecfdf5 !important; border-radius: 6px !important;
    cursor: pointer; flex-shrink: 0;
    transition: background 0.15s;
}
.tv-practice-corr-btn:hover { background: #d1fae5 !important; }

/* ── Back button ─────────────────────────────────────────────────────────────── */
.tv-btn-back {
    background: #f1f5f9; color: #475569;
    border: 1.5px solid #cbd5e1; font-size: 0.82rem;
    padding: 6px 14px; border-radius: 8px; cursor: pointer;
    transition: all 0.18s;
}
.tv-btn-back:hover { background: #e2e8f0; border-color: #94a3b8; color: #1e293b; }

/* ── Stop speaking button disabled state ──────────────────────────────────────── */
#tv-stop-speech-btn:disabled { opacity: 0.55; cursor: wait; }

/* ── Action row wrap ─────────────────────────────────────────────────────────── */
.tv-action-row { flex-wrap: wrap; gap: 6px; }

/* ── Auto-listen toggle ──────────────────────────────────────────────────────── */
.tv-auto-listen-label {
    display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
    padding: 4px 10px; border-radius: 20px; border: 1px solid var(--tv-border,#e2e8f0);
    background: var(--tv-surface,#f8fafc); font-size: 0.78rem; color: var(--tv-text-muted,#64748b);
    user-select: none; transition: all 0.2s;
}
.tv-auto-listen-label:hover { background: #f1f5f9; border-color: var(--tv-accent,#4f46e5); }
.tv-auto-listen-label input[type="checkbox"] { accent-color: var(--tv-accent,#4f46e5); width:15px; height:15px; cursor:pointer; }
.tv-auto-listen-label input:checked + .tv-auto-listen-text { color: var(--tv-accent,#4f46e5); font-weight: 600; }

/* Mic pulse when auto-listening */
#tv-mic-btn.listening {
    animation: tv-mic-pulse 1.2s ease-in-out infinite;
    border-color: #ef4444 !important; background: #fef2f2 !important;
}
@keyframes tv-mic-pulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.35); }
    50%      { box-shadow: 0 0 0 7px rgba(239,68,68,0); }
}

/* ── Pause / Resume Button ──────────────────────────────────────────────────── */
.tv-btn-pause {
    background: #fff7ed;
    color: #c2410c;
    border: 1.5px solid #fed7aa;
    font-size: 0.8rem;
    padding: 5px 13px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.18s;
    font-weight: 600;
}
.tv-btn-pause:hover { background: #ffedd5; border-color: #fb923c; }

.tv-btn-resume {
    background: #f0fdf4;
    color: #15803d;
    border: 1.5px solid #bbf7d0;
    font-size: 0.8rem;
    padding: 5px 13px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.18s;
    font-weight: 600;
}
.tv-btn-resume:hover { background: #dcfce7; border-color: #4ade80; }

/* ── Paused Banner ──────────────────────────────────────────────────────────── */
.tv-paused-banner {
    background: linear-gradient(135deg, #fff7ed, #ffedd5);
    border: 1.5px solid #fb923c;
    border-radius: 8px;
    padding: 10px 16px;
    text-align: center;
    font-weight: 600;
    color: #c2410c;
    font-size: 0.875rem;
    margin: 0 0 8px;
    animation: tv-pulse-border 1.5s ease-in-out infinite;
}
@keyframes tv-pulse-border {
    0%,100% { border-color: #fb923c; }
    50%      { border-color: #f97316; box-shadow: 0 0 8px rgba(249,115,22,0.3); }
}

/* ── Hint Button with corrections badge ─────────────────────────────────────── */
#tv-hint-btn {
    position: relative;
}
#tv-hint-btn[data-count]:not([data-count="0"])::after {
    content: attr(data-count);
    position: absolute;
    top: -6px; right: -6px;
    background: #ef4444;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    width: 16px; height: 16px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
}

/* ── Correction Panel improvements ──────────────────────────────────────────── */
.tv-correction-panel {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 99999;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    width: min(680px, 94vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tv-cp-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, #fff7ed, #fff);
    flex-shrink: 0;
}
.tv-cp-header h3 { margin: 0; font-size: 1.05rem; color: #1e293b; }
.tv-cp-tip {
    margin: 0; padding: 8px 20px;
    font-size: 0.78rem; color: #64748b;
    background: #f8fafc; flex-shrink: 0;
}
.tv-cp-empty {
    text-align: center; padding: 36px 20px;
    color: #22c55e; font-weight: 600; font-size: 0.95rem;
}
.tv-cp-list {
    overflow-y: auto; padding: 12px 20px 20px;
    display: flex; flex-direction: column; gap: 10px;
}
.tv-cp-item {
    background: #f8fafc; border: 1px solid #e2e8f0;
    border-left: 3px solid #f59e0b;
    border-radius: 8px; padding: 10px 14px;
}
.tv-cp-num { font-size: 0.72rem; color: #94a3b8; margin-bottom: 7px; font-weight: 600; }
.tv-cp-time { font-weight: 400; margin-left: 4px; }
.tv-cp-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; flex-wrap: wrap; }
.tv-cp-row:last-child { margin-bottom: 0; }
.tv-cp-badge {
    font-size: 0.68rem; font-weight: 700; padding: 2px 7px;
    border-radius: 4px; white-space: nowrap; flex-shrink: 0;
}
.tv-cp-wrong   { background: #fee2e2; color: #b91c1c; }
.tv-cp-correct { background: #d1fae5; color: #065f46; }
.tv-cp-sentence { flex: 1; font-size: 0.88rem; color: #374151; }
.tv-cp-correct-text { font-weight: 700; color: #065f46; }
.tv-practice-corr-btn {
    padding: 3px 10px !important; font-size: 0.73rem !important;
    border: 1.5px solid #10b981 !important;
    color: #065f46 !important; background: #ecfdf5 !important;
    border-radius: 6px !important; cursor: pointer; flex-shrink: 0;
    transition: background 0.15s !important;
}
.tv-practice-corr-btn:hover { background: #d1fae5 !important; }
