/* ==========================================
   CHAT TUTOR "سقراط" — chat-style lesson overlay
   Colors come from the theme variables in styles.css (light + dark).
   ========================================== */

.chat-tutor {
    position: fixed;
    inset: 0;
    z-index: 4900; /* above app modals (≤3200), below playful.js confetti/toasts (≥5000) */
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    color: var(--text-primary);
    direction: rtl;
    animation: ct-in 0.22s ease-out;
}
@keyframes ct-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.ct-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(var(--safe-top, 0px) + 10px) 14px 10px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
}
.ct-avatar {
    width: 40px; height: 40px; flex: none;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    background: var(--accent-gold-bg);
    border: 1px solid var(--accent-gold-border);
}
.ct-titles { flex: 1; min-width: 0; }
.ct-titles b { display: block; font-size: 15px; }
.ct-titles small {
    display: flex; gap: 4px; font-size: 12px; color: var(--text-secondary);
    white-space: nowrap;
}
.ct-lesson-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ct-step { flex: none; }
.chat-tutor-close {
    width: 36px; height: 36px; flex: none;
    border: none; border-radius: 50%;
    background: var(--bg-elevated); color: var(--text-secondary);
    font-size: 16px; cursor: pointer;
}

.ct-prog { height: 4px; background: var(--border-subtle); }
.ct-prog i {
    display: block; height: 100%; width: 0;
    background: var(--accent-gold);
    transition: width 0.4s ease;
}

.ct-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

/* Bubbles — in RTL flex-start is the right edge */
.ct-b {
    max-width: 86%;
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.75;
    word-wrap: break-word;
    animation: ct-pop 0.2s ease-out;
}
@keyframes ct-pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }

.ct-bot {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-top-right-radius: 4px;
    box-shadow: var(--shadow-sm);
}
.ct-me {
    align-self: flex-end;
    background: var(--accent-indigo);
    color: #fff;
    border-top-left-radius: 4px;
}
.ct-speakerA, .ct-speakerB {
    font-size: 14px;
    border: 1px dashed;
}
.ct-speakerA {
    align-self: flex-start;
    margin-right: 18px;
    background: var(--state-inquiry-bg);
    border-color: var(--state-inquiry-border);
}
.ct-speakerB {
    align-self: flex-end;
    margin-left: 18px;
    background: var(--accent-gold-bg);
    border-color: var(--accent-gold-border);
}
.ct-who {
    display: block;
    font-size: 12px;
    font-weight: 800;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.ct-ctx {
    margin-top: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    font-size: 13px;
    color: var(--text-secondary);
}
.ct-quote {
    display: block;
    margin-top: 6px;
    padding: 6px 10px;
    border-right: 3px solid var(--state-flaw);
    background: var(--state-flaw-bg);
    border-radius: var(--radius-sm);
    font-style: normal;
}
.ct-quote::before, .ct-quote::after { content: none; }
.ct-model {
    margin-top: 6px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--state-valid-bg);
    border: 1px solid var(--state-valid-border);
}
.ct-tag {
    align-self: flex-start;
    padding: 4px 14px;
    border-radius: var(--radius-full);
    background: var(--state-valid-bg);
    border: 1px solid var(--state-valid-border);
    color: var(--state-valid);
    font-weight: 800;
}
.ct-xp {
    align-self: center;
    padding: 4px 16px;
    border-radius: var(--radius-full);
    background: var(--accent-gold);
    color: #2b2000;
    font-weight: 800;
}

/* Typing indicator */
.ct-typing {
    align-self: flex-start;
    display: flex; gap: 4px;
    padding: 12px 14px;
    border-radius: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
}
.ct-typing.ct-typing-end { align-self: flex-end; }
.ct-typing i {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-muted);
    animation: ct-dot 1s infinite ease-in-out;
}
.ct-typing i:nth-child(2) { animation-delay: 0.15s; }
.ct-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ct-dot { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Bottom dock */
.ct-dock {
    max-height: 48vh;
    overflow-y: auto;
    padding: 10px 14px calc(var(--safe-bottom, 0px) + 10px);
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
}
.ct-dock:empty { display: none; }

.ct-choices { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ct-choices.ct-stacked { flex-direction: column; }
.ct-chip {
    padding: 10px 16px;
    border-radius: 18px;
    border: 1.5px solid var(--accent-indigo-border);
    background: var(--accent-indigo-bg);
    color: var(--text-primary);
    font: inherit;
    font-size: 14px;
    line-height: 1.6;
    cursor: pointer;
    text-align: center;
}
.ct-stacked .ct-chip { text-align: right; border-radius: var(--radius-md); }
.ct-chip:active { transform: scale(0.98); }
.ct-chip:disabled { opacity: 0.4; text-decoration: line-through; }
.ct-chip.ct-primary {
    background: var(--accent-indigo);
    border-color: var(--accent-indigo);
    color: #fff;
    font-weight: 700;
}

.ct-input-row { display: flex; gap: 8px; align-items: flex-end; }
.ct-input textarea {
    flex: 1;
    resize: none;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-medium);
    background: var(--bg-card);
    color: var(--text-primary);
    font: inherit;
    font-size: 14.5px;
}
.ct-send {
    width: 44px; height: 44px; flex: none;
    border: none; border-radius: 50%;
    background: var(--accent-indigo); color: #fff;
    font-size: 18px; cursor: pointer;
    transform: scaleX(-1);
}
.ct-send:disabled { opacity: 0.4; }
.ct-skip {
    display: block;
    margin: 8px auto 0;
    border: none; background: none;
    color: var(--accent-indigo-light);
    font: inherit; font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}

/* Entry button inside the lesson player */
.ct-entry-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%;
    margin: 0 0 14px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--accent-gold-border);
    background: var(--accent-gold-bg);
    color: var(--text-primary);
    font: inherit; font-size: 15px; font-weight: 800;
    cursor: pointer;
}
.ct-entry-btn:active { transform: scale(0.98); }
