:root {
  color-scheme: dark;
  --indigo: #0f022b;
  --cream: #f6f1e0;
  --celeste: #79d4fc;
  --muted: #b6adc6;
  --line: rgba(246,241,224,.12);
  font-family: Inter, "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--indigo);
  color: var(--cream);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; transition: background .15s, color .15s; }
button, input, textarea, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--celeste); outline-offset: 4px; }
button:disabled { opacity: .4; cursor: default; }
[hidden] { display: none !important; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link:focus { position: fixed; top: 12px; left: 12px; z-index: 9; padding: 12px 20px; background: var(--celeste); color: var(--indigo); }
.app-shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.topbar { min-height: 84px; padding: 18px 36px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-shrink: 0; }
.brand { display: flex; align-items: baseline; gap: 14px; }
.brand-title { font-size: 16px; font-weight: 550; letter-spacing: -.02em; }
.brand-subtitle { font-size: 12px; color: var(--muted); }
.text-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 10px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: 12px; white-space: nowrap; }
.text-button:hover:not(:disabled) { color: var(--celeste); background: rgba(121,212,252,.05); }
#new-chat > span { font-size: 20px; font-weight: 300; }
#chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-scroll { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; padding: 8px 24px 28px; scrollbar-width: thin; scrollbar-color: #47345e transparent; overscroll-behavior: contain; }
.welcome { margin: auto; padding: 30px 0; text-align: center; }
.welcome h1 { font-size: clamp(22px, 2.4vw, 30px); line-height: 1.4; font-weight: 450; letter-spacing: -.035em; margin: 0; }
#messages, .working { width: min(760px, 100%); margin-left: auto; margin-right: auto; }
.message { margin: 20px 0 36px; }
.message-label { display: block; color: var(--celeste); font-size: 11px; font-weight: 550; margin-bottom: 10px; }
.message-text { font-size: 16px; line-height: 1.85; color: var(--cream); overflow-wrap: anywhere; white-space: pre-wrap; }
.message.user { margin-left: 48px; display: flex; justify-content: flex-end; }
.user .message-body { max-width: 100%; padding: 14px 20px; background: #211339; border-radius: 16px 16px 3px 16px; }
.user .message-label { color: var(--muted); }
.user .message-text { font-size: 15px; }
.working { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; font-size: 12px; color: var(--muted); }
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--celeste); animation: pulse 1.1s ease infinite; }
.thinking-dots i:nth-child(2) { animation-delay: .15s; }
.thinking-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%,70%,100% { opacity: .3; } 35% { opacity: 1; } }
.composer-area { flex-shrink: 0; width: min(808px, 100%); margin: 0 auto; padding: 8px 24px max(12px, env(safe-area-inset-bottom)); }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 12px; border: 1px solid rgba(246,241,224,.22); border-radius: 16px; background: #190c33; }
.composer:focus-within { border-color: rgba(121,212,252,.65); }
.composer textarea { display: block; flex: 1; min-width: 0; min-height: 64px; max-height: 160px; resize: vertical; padding: 7px 6px; color: var(--cream); background: transparent; border: 0; font-size: 16px; line-height: 1.6; }
.composer textarea:focus-visible { outline: none; }
.composer textarea::placeholder { color: var(--muted); }
.attach-button { display: grid; place-items: center; width: 40px; height: 42px; flex-shrink: 0; border: 0; border-radius: 10px; color: var(--muted); background: transparent; }
.attach-button:hover:not(:disabled) { color: var(--celeste); background: rgba(121,212,252,.08); }
.attach-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.attachment-preview { display: flex; align-items: center; gap: 12px; max-width: 100%; margin: 0 0 10px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: #190c33; }
.attachment-preview img { width: 56px; height: 56px; object-fit: contain; background: white; border-radius: 6px; }
#attachment-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }
#remove-image { font-size: 23px; min-width: 44px; }
.message-image { display: block; max-width: min(280px, 100%); max-height: 240px; object-fit: contain; margin: 12px 0 0; border-radius: 8px; background: white; }
.primary { color: var(--indigo); background: var(--celeste); border: 1px solid var(--celeste); border-radius: 10px; font-weight: 600; }
.primary:hover:not(:disabled) { background: #a6e3ff; }
.send-button { display: grid; place-items: center; width: 42px; height: 42px; flex-shrink: 0; border-radius: 12px; }
.send-button svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#exam-mode { padding-left: 3px; font-size: 11px; }
.note { font-size: 11px; color: var(--muted); }
.error { padding: 10px 13px; margin: 0 0 12px; border-radius: 8px; color: #ffc6c6; background: #381532; font-size: 12px; line-height: 1.6; }
 dialog { width: min(390px, calc(100% - 36px)); max-height: calc(100dvh - 40px); padding: 30px; border: 1px solid rgba(246,241,224,.19); border-radius: 16px; background: #190c33; color: var(--cream); box-shadow: 0 24px 100px rgba(0,0,0,.4); }
 dialog::backdrop { background: rgba(8,2,22,.65); }
.close-button { position: absolute; top: 6px; right: 6px; display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 24px; }
.close-button:hover { color: var(--cream); }
 dialog h2 { margin: 5px 0 12px; font-size: 22px; letter-spacing: -.025em; font-weight: 500; }
 dialog > p { margin: 0 0 24px; font-size: 13px; line-height: 1.7; color: var(--muted); }
.code-field { display: flex; border: 1px solid rgba(246,241,224,.25); border-radius: 9px; overflow: hidden; }
.code-field:focus-within { border-color: var(--celeste); }
.code-field input { width: 100%; min-width: 0; padding: 14px 12px; background: var(--indigo); border: 0; color: var(--cream); font-size: 16px; }
.code-field input:focus-visible { outline-offset: -3px; }
#show-code { padding: 0 12px; background: var(--indigo); border: 0; color: var(--muted); font-size: 11px; }
.login-submit { width: 100%; min-height: 46px; margin-top: 14px; font-size: 13px; }
#login-error { margin: 12px 0 0; }
@media (max-width: 600px) {
  .topbar { min-height: 76px; padding: 14px 18px; }
  .brand { flex-direction: column; gap: 5px; }
  .brand-title { font-size: 14px; }
  .brand-subtitle { font-size: 11px; }
  #new-chat { padding-right: 0; }
  .chat-scroll { padding: 8px 20px 16px; }
  .welcome { max-width: 280px; }
  .welcome h1 { font-size: 23px; }
  .composer-area { padding-left: 14px; padding-right: 14px; }
  .composer { padding: 10px; }
  .composer textarea { min-height: 60px; }
  .message.user { margin-left: 22px; }
  .message-text { font-size: 15px; }
  .user .message-text { font-size: 14px; }
  .user .message-body { padding: 12px 16px; }
  dialog { padding: 27px 24px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* Course identity, compact exam control, and readable mathematical answers. */
.brand { visibility: hidden; }
body.has-messages .brand { visibility: visible; }
.welcome h1 { font-size: clamp(30px, 4vw, 46px); letter-spacing: -.045em; font-weight: 500; }
.welcome-course { margin: 12px 0 0; font-size: 18px; color: var(--celeste); }
.welcome-professor { margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.mode-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
#exam-mode { padding: 0 13px; min-height: 36px; border: 1px solid var(--line); border-radius: 30px; font-size: 12px; }
#exam-mode[aria-pressed="true"] { border-color: rgba(121,212,252,.5); color: var(--celeste); background: rgba(121,212,252,.06); }
.mode-dot { width: 5px; height: 5px; border-radius: 50%; border: 1px solid currentColor; }
#exam-mode[aria-pressed="true"] .mode-dot { background: var(--celeste); }
#mode-hint { color: var(--muted); font-size: 11px; }
.composer-footer { justify-content: center; min-height: 38px; }
.stop-button { display: grid; place-items: center; width: 42px; height: 42px; flex-shrink: 0; border: 1px solid var(--celeste); border-radius: 12px; background: transparent; color: var(--celeste); }
.stop-button svg { width: 21px; fill: currentColor; }
.stop-button:hover { background: rgba(121,212,252,.1); }
.message.assistant .message-text { white-space: normal; }
.message-text > :first-child { margin-top: 0; }
.message-text > :last-child { margin-bottom: 0; }
.message-text p { margin: 0 0 16px; }
.message-text h1, .message-text h2, .message-text h3, .message-text h4 { margin: 25px 0 10px; font-size: 17px; font-weight: 600; line-height: 1.5; letter-spacing: -.01em; }
.message-text strong { color: var(--cream); font-weight: 650; }
.message-text ul, .message-text ol { margin: 0 0 16px; padding-left: 24px; }
.message-text li { padding-left: 3px; margin: 6px 0; }
.message-text li > p { margin: 0; }
.message-text blockquote { margin: 18px 0; padding-left: 16px; border-left: 2px solid var(--celeste); color: var(--muted); }
.message-text hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
.message-text code { font-size: .9em; padding: 2px 5px; border-radius: 4px; background: #23133c; }
.message-text pre { overflow-x: auto; padding: 14px; border-radius: 10px; background: #190c33; white-space: pre; }
.message-text pre code { padding: 0; background: transparent; }
.message-text .katex { font-size: 1.08em; }
.message-text .katex-display { overflow-x: auto; overflow-y: hidden; padding: 8px 0; margin: 16px 0; }
.table-scroll { overflow-x: auto; margin: 18px 0; }
.message-text table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.65; }
.message-text th, .message-text td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.message-text th { color: var(--celeste); font-weight: 550; }
.message-status { margin: 12px 0 0; color: var(--muted); font-size: 11px; }
.message-body { min-width: 0; max-width: 100%; }
#messages, .working { flex-shrink: 0; }
@media (max-width: 600px) {
  .welcome { max-width: 100%; }
  .welcome h1 { font-size: 32px; }
  .welcome-course { font-size: 16px; }
  .welcome-professor { font-size: 13px; }
  #mode-hint { font-size: 10px; }
  .message-text table { font-size: 12px; }
  .message-text th, .message-text td { padding: 9px; }
}
