/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #22263a;
    --border: #2e334d;
    --accent: #6c63ff;
    --accent-soft: #8b85ff;
    --accent-glow: rgba(108, 99, 255, 0.25);
    --user-bubble: #6c63ff;
    --ai-bubble: #22263a;
    --text: #e8eaf0;
    --muted: #7b80a0;
    --danger: #ff5f7e;
    --success: #43d98e;
    --radius: 14px;
    --transition: 0.22s ease;
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ─── Header ─────────────────────────────────────────────────── */
header {
    width: 100%;
    background: linear-gradient(135deg, #1a1d27 0%, #12142080 100%);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 0 18px var(--accent-glow);
}

.brand h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.brand p {
    font-size: 11px;
    color: var(--muted);
    margin-top: 1px;
}

/* ─── Main layout ────────────────────────────────────────────── */
main {
    width: 100%;
    max-width: 820px;
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px 16px 0;
    gap: 18px;
}

/* ─── Teacher Selector ───────────────────────────────────────── */
.teacher-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}

.teacher-card label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
}

.teacher-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

/* Each teacher option is a styled radio button */
.teacher-option input[type="radio"] {
    display: none;
}

.teacher-option label {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 10px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--surface2);
    transition: var(--transition);
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
}

.teacher-option input[type="radio"]:checked + label {
    border-color: var(--accent);
    background: linear-gradient(135deg, rgba(108, 99, 255, 0.15), rgba(108, 99, 255, 0.05));
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.teacher-option label:hover {
    border-color: var(--accent-soft);
}

.teacher-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    font-size: 24px;
    display: grid;
    place-items: center;
}

.avatar-sarah { background: linear-gradient(135deg, #f9a8d4, #fbcfe8); }
.avatar-mark  { background: linear-gradient(135deg, #93c5fd, #bfdbfe); }
.avatar-emma  { background: linear-gradient(135deg, #6ee7b7, #a7f3d0); }

.teacher-name {
    font-size: 13px;
    font-weight: 600;
}

.teacher-style {
    font-size: 10px;
    color: var(--muted);
}

/* ─── Chat Window ────────────────────────────────────────────── */
.chat-window {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    min-height: 420px;
    overflow: hidden;
}

.chat-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

/* Scrollable message area */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

/* Custom scrollbar */
#messages::-webkit-scrollbar        { width: 5px; }
#messages::-webkit-scrollbar-track  { background: transparent; }
#messages::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 4px; }

/* ─── Message Bubbles ────────────────────────────────────────── */
.message {
    display: flex;
    gap: 10px;
    max-width: 82%;
    animation: fadeUp 0.3s ease both;
}

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

/* AI message – left aligned */
.message.ai   { align-self: flex-start; flex-direction: row; }

/* User message – right aligned */
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 2px;
}

.msg-avatar.ai-av   { background: var(--surface2); border: 1px solid var(--border); }
.msg-avatar.user-av { background: var(--user-bubble); }

.bubble {
    padding: 11px 15px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.65;
}

.message.ai .bubble {
    background: var(--ai-bubble);
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
}

.message.user .bubble {
    background: var(--user-bubble);
    color: #fff;
    border-top-right-radius: 4px;
}

/* Error bubble */
.message.error .bubble {
    background: rgba(255, 95, 126, 0.12);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* ─── Typing Indicator ───────────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 15px;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%            { transform: scale(1);   opacity: 1; }
}

/* ─── Input Bar ──────────────────────────────────────────────── */
.input-bar {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#userInput {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 15px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    line-height: 1.5;
    max-height: 130px;
    transition: border-color var(--transition);
    outline: none;
}

#userInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#userInput::placeholder { color: var(--muted); }

#sendBtn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: 0 4px 14px var(--accent-glow);
}

#sendBtn:hover  { transform: translateY(-1px); box-shadow: 0 6px 18px var(--accent-glow); }
#sendBtn:active { transform: translateY(1px); }
#sendBtn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ─── Footer ─────────────────────────────────────────────────── */
footer {
    padding: 16px;
    text-align: center;
    font-size: 11px;
    color: var(--muted);
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 520px) {
    .teacher-name  { font-size: 11px; }
    .teacher-style { display: none; }

    .teacher-avatar {
        width: 42px;
        height: 42px;
        font-size: 20px;
    }

    .message { max-width: 92%; }
}
