:root {
    --bg-color: #0b0f17;
    --card-bg: #141a23;
    --card-border: #222d3d;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --accent: #10b981;
    --accent-glow: rgba(16, 185, 129, 0.4);
    --accent-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gold: #f59e0b;
    --gold-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --danger: #ef4444;
    --danger-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --thinking-gradient: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    --font-ui: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-arabic: 'Noto Naskh Arabic', 'Amiri', 'Traditional Arabic', serif;
    --shadow-glow: 0 0 35px rgba(16, 185, 129, 0.35);
}

body.tg-theme {
    --bg-color: var(--tg-theme-bg-color, #0b0f17);
    --card-bg: var(--tg-theme-secondary-bg-color, #141a23);
    --text-primary: var(--tg-theme-text-color, #f0f6fc);
    --text-secondary: var(--tg-theme-hint-color, #8b949e);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-ui);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    position: relative;
    background: var(--bg-color);
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    z-index: 20;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-badge {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}

.header-title-box {
    display: flex;
    flex-direction: column;
}

.header-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge-live {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(16, 185, 129, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 8px #34d399;
    animation: blinkDot 1.4s infinite;
}

@keyframes blinkDot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.3; transform: scale(0.8); }
}

.header-sub {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* --- Topics Pills --- */
.topics-bar-wrap {
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding: 8px 16px;
    z-index: 10;
}

.topics-bar-wrap::-webkit-scrollbar {
    display: none;
}

.topics-bar {
    display: flex;
    gap: 8px;
    width: max-content;
}

.topic-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    border-radius: 20px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.topic-pill:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.topic-pill.active {
    background: var(--accent-gradient);
    color: #ffffff;
    border-color: transparent;
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.4);
}

.topic-pill.gold.active {
    background: var(--gold-gradient);
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.4);
}

/* ======================================================== */
/* --- REALTIME LIVE CALL VIEW --- */
/* ======================================================== */
.live-call-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px 20px 24px;
    overflow-y: auto;
    position: relative;
}

.call-header-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 10px 16px;
}

.teacher-tag {
    display: flex;
    align-items: center;
    gap: 10px;
}

.teacher-avatar {
    font-size: 24px;
}

.teacher-meta {
    display: flex;
    flex-direction: column;
}

.teacher-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.voice-badge {
    font-size: 11px;
    color: #34d399;
    font-weight: 600;
}

.call-timer {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}

/* --- CENTRAL AI VOICE ORB --- */
.orb-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    min-height: 200px;
}

.orb-halo {
    position: absolute;
    width: 210px;
    height: 210px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.25) 0%, rgba(16, 185, 129, 0) 70%);
    transition: all 0.5s ease;
    filter: blur(12px);
    pointer-events: none;
}

.voice-orb {
    width: 135px;
    height: 135px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #34d399, #059669 65%, #064e3b 100%);
    box-shadow: 0 0 40px rgba(16, 185, 129, 0.45), inset 0 2px 10px rgba(255, 255, 255, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 2;
}

.orb-icon {
    font-size: 34px;
    color: #ffffff;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
    transition: all 0.3s ease;
}

/* Orb States: */
/* 1. IDLE */
.voice-orb.idle {
    background: radial-gradient(circle at 35% 35%, #4b5563, #1f2937 65%, #111827 100%);
    box-shadow: 0 0 20px rgba(75, 85, 99, 0.3);
}

.orb-halo.idle {
    background: radial-gradient(circle, rgba(75, 85, 99, 0.2) 0%, rgba(75, 85, 99, 0) 70%);
}

/* 2. LISTENING (Continuous Wait) */
.voice-orb.listening {
    animation: orbPulse 2s infinite ease-in-out;
}

@keyframes orbPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 35px rgba(16, 185, 129, 0.4); }
    50% { transform: scale(1.05); box-shadow: 0 0 55px rgba(16, 185, 129, 0.7); }
}

/* 3. USER SPEAKING (Active input) */
.voice-orb.user-speaking {
    background: radial-gradient(circle at 35% 35%, #60a5fa, #2563eb 65%, #1e3a8a 100%);
    box-shadow: 0 0 60px rgba(37, 99, 235, 0.6);
    transform: scale(1.08);
}

.orb-halo.user-speaking {
    background: radial-gradient(circle, rgba(37, 99, 235, 0.4) 0%, rgba(37, 99, 235, 0) 70%);
}

/* 4. THINKING */
.voice-orb.thinking {
    background: radial-gradient(circle at 35% 35%, #c084fc, #9333ea 65%, #581c87 100%);
    box-shadow: 0 0 55px rgba(147, 51, 234, 0.6);
    animation: orbSpin 2.5s infinite linear;
}

@keyframes orbSpin {
    0% { transform: rotate(0deg) scale(0.98); }
    50% { transform: rotate(180deg) scale(1.04); }
    100% { transform: rotate(360deg) scale(0.98); }
}

.orb-halo.thinking {
    background: radial-gradient(circle, rgba(147, 51, 234, 0.4) 0%, rgba(147, 51, 234, 0) 70%);
}

/* 5. AI SPEAKING */
.voice-orb.ai-speaking {
    background: radial-gradient(circle at 35% 35%, #34d399, #10b981 65%, #047857 100%);
    box-shadow: 0 0 70px rgba(16, 185, 129, 0.8);
    animation: orbAcoustic 1s infinite alternate ease-in-out;
}

@keyframes orbAcoustic {
    0% { transform: scale(1); filter: brightness(1); }
    100% { transform: scale(1.12); filter: brightness(1.2); }
}

/* Visualizer Bars */
.visualizer-bars {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    margin-top: 18px;
}

.visualizer-bars span {
    width: 3.5px;
    height: 4px;
    background: #34d399;
    border-radius: 4px;
    transition: height 0.15s ease;
}

.visualizer-bars.active span {
    animation: barBounce 0.8s infinite alternate ease-in-out;
}

.visualizer-bars.active span:nth-child(2n) { animation-delay: 0.15s; }
.visualizer-bars.active span:nth-child(3n) { animation-delay: 0.3s; }
.visualizer-bars.active span:nth-child(4n) { animation-delay: 0.45s; }

@keyframes barBounce {
    0% { height: 4px; }
    100% { height: 26px; }
}

/* Status Indicator Badge */
.live-status-box {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.status-indicator-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
}

.status-bullet {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6e7681;
}

.status-indicator-badge.listening .status-bullet {
    background: #34d399;
    box-shadow: 0 0 8px #34d399;
}

.status-indicator-badge.user-speaking .status-bullet {
    background: #60a5fa;
    box-shadow: 0 0 8px #60a5fa;
}

.status-indicator-badge.thinking .status-bullet {
    background: #c084fc;
    box-shadow: 0 0 8px #c084fc;
}

.status-indicator-badge.ai-speaking .status-bullet {
    background: #10b981;
    box-shadow: 0 0 10px #10b981;
}

.status-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

/* --- SUBTITLES CARD --- */
.subtitles-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 120px;
}

.subtitle-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-height: 190px;
    overflow-y: auto;
}

.live-arabic-text {
    font-family: var(--font-arabic);
    font-size: 21px;
    line-height: 1.9;
    direction: rtl;
    text-align: right;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.3px;
}

.live-feedback-box {
    background: rgba(245, 158, 11, 0.12);
    border-left: 3px solid var(--gold);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12.5px;
    color: #fbbf24;
    line-height: 1.5;
}

.live-feedback-box.hidden {
    display: none;
}

.live-uzbek-text {
    font-size: 13.5px;
    color: #94a3b8;
    line-height: 1.5;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    padding-top: 8px;
}

/* --- CALL CONTROLS BAR (Hands-Free Call) --- */
.call-controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: 14px;
}

.call-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border-radius: 18px;
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    font-weight: 600;
}

.call-btn:active {
    transform: scale(0.94);
}

.call-btn.primary {
    flex: 1;
    height: 56px;
    background: var(--accent-gradient);
    color: #ffffff;
    font-size: 15px;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    display: flex;
    flex-direction: row;
    gap: 10px;
}

.call-btn.primary.active-call {
    background: var(--danger-gradient);
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.45);
}

.call-btn.secondary {
    width: 58px;
    height: 56px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
    font-size: 16px;
}

.call-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.call-btn.secondary.muted {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
}

.call-btn.secondary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-subtext {
    font-size: 10px;
    font-weight: 600;
}

/* ======================================================== */
/* --- CHAT HISTORY VIEW --- */
/* ======================================================== */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-container.hidden {
    display: none;
}

.live-call-view.hidden {
    display: none;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--card-border);
}

.history-header h3 {
    font-size: 15px;
    font-weight: 700;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.message-card {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: fadeIn 0.25s ease-out;
}

.message-card.assistant { align-self: flex-start; }
.message-card.user { align-self: flex-end; }

.bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.6;
}

.message-card.assistant .bubble {
    background: #141c28;
    border: 1px solid var(--card-border);
    color: var(--text-primary);
}

.message-card.user .bubble {
    background: #0f3426;
    border: 1px solid #10b981;
    color: #e6fffa;
}

.bubble .arabic-text {
    font-family: var(--font-arabic);
    font-size: 18px;
    line-height: 1.8;
    direction: rtl;
    text-align: right;
    font-weight: 600;
    margin-bottom: 6px;
}

.bubble .uzbek-translation {
    font-size: 13px;
    color: #94a3b8;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    padding-top: 6px;
    margin-top: 6px;
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-overlay.hidden { display: none; }

.modal-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--card-border);
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.close-btn {
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.setting-info { display: flex; flex-direction: column; }
.setting-title { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.setting-desc { font-size: 11.5px; color: var(--text-secondary); }

.custom-select {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
}

.speed-selector { display: flex; gap: 5px; }
.speed-btn {
    padding: 6px 9px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}
.speed-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #30363d;
    transition: .3s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider { background-color: #10b981; }
input:checked + .slider:before { transform: translateX(20px); }

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--card-border);
}

.btn-primary {
    background: var(--accent-gradient);
    border: none;
    color: #fff;
    padding: 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary.full-width { width: 100%; }

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