:root {
    color-scheme: light;
    --bg: #f3f6f2;
    --panel: #ffffff;
    --ink: #18221d;
    --muted: #647067;
    --line: #dbe4dd;
    --accent: #1f7a5a;
    --accent-dark: #155a42;
    --soft: #e8f3ed;
    --user: #203b7a;
    --shadow: 0 18px 45px rgba(24, 34, 29, .12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.chat-panel {
    width: min(980px, 100%);
    height: min(780px, calc(100vh - 48px));
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 24px;
    border-bottom: 1px solid var(--line);
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.15;
}

.status-dot {
    width: 12px;
    height: 12px;
    flex: 0 0 auto;
    background: #28b47c;
    border-radius: 50%;
    box-shadow: 0 0 0 6px rgba(40, 180, 124, .14);
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    padding: 24px;
}

.message {
    display: flex;
}

.message.user {
    justify-content: flex-end;
}

.bubble {
    max-width: min(720px, 92%);
    padding: 14px 16px;
    border-radius: 8px;
    background: var(--soft);
    line-height: 1.5;
}

.message.user .bubble {
    background: var(--user);
    color: #ffffff;
}

.bot-text {
    white-space: pre-line;
}

.message.typing .bubble {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.typing-dots {
    display: inline-flex;
    gap: 3px;
}

.typing-dots i {
    width: 5px;
    height: 5px;
    background: var(--accent);
    border-radius: 50%;
    animation: typingPulse 1s infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
    animation-delay: .15s;
}

.typing-dots i:nth-child(3) {
    animation-delay: .3s;
}

@keyframes typingPulse {
    0%, 80%, 100% {
        opacity: .35;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

.results {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.lesson-card {
    display: grid;
    gap: 6px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    opacity: 1;
    transform: translateY(0);
    transition: opacity .28s ease, transform .28s ease;
}

.lesson-card.entering {
    opacity: 0;
    transform: translateY(8px);
}

.lesson-card strong {
    color: var(--ink);
}

.lesson-meta {
    color: var(--muted);
    font-size: 13px;
}

.lesson-card a {
    width: fit-content;
    color: var(--accent-dark);
    font-weight: 800;
    text-decoration: none;
}

.lesson-card a:hover {
    text-decoration: underline;
}

.segment-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.segment-option {
    align-self: auto;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #ffffff;
    color: var(--ink);
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

.segment-option:hover,
.segment-option.selected {
    border-color: var(--accent);
    background: var(--accent);
    color: #ffffff;
}

.segment-option:disabled {
    cursor: default;
    opacity: 1;
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 18px;
    border-top: 1px solid var(--line);
    background: #fbfdfb;
}

textarea {
    width: 100%;
    min-height: 52px;
    max-height: 160px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    font: inherit;
    color: var(--ink);
    outline: none;
}

textarea:disabled {
    background: #f4f7f5;
    cursor: not-allowed;
}

textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(31, 122, 90, .14);
}

button {
    align-self: end;
    min-height: 52px;
    border: 0;
    border-radius: 8px;
    padding: 0 22px;
    background: var(--accent);
    color: #ffffff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

button:hover {
    background: var(--accent-dark);
}

button:disabled {
    cursor: wait;
    opacity: .65;
}

.segment-option {
    align-self: auto;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #ffffff;
    color: var(--ink);
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

.segment-option:hover,
.segment-option.selected {
    border-color: var(--accent);
    background: var(--accent);
    color: #ffffff;
}

.segment-option:disabled {
    cursor: default;
    opacity: 1;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 680px) {
    .app-shell {
        padding: 0;
    }

    .chat-panel {
        height: 100vh;
        border-radius: 0;
        border: 0;
    }

    .composer {
        grid-template-columns: 1fr;
    }

    button {
        width: 100%;
    }
}
