:root {
  --bg: #fcfcfc;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #86868b;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.22);
  --accent: #0071e3;
  --user-bg: #e9f0fb;
  --hover: rgba(0, 0, 0, 0.06);
  --chip: #ffffff;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1b;
    --surface: #242424;
    --text: #ececec;
    --muted: #9b9b9b;
    --line: rgba(255, 255, 255, 0.1);
    --line-strong: rgba(255, 255, 255, 0.26);
    --accent: #2997ff;
    --user-bg: #262626;
    --hover: rgba(255, 255, 255, 0.09);
    --chip: #242424;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  }
  /* Assistant replies in a serif face, like the reference */
  .bot .bubble { font-family: "Tiempos Text", "Iowan Old Style", "Charter", "Georgia", "Times New Roman", serif; font-size: 18px; line-height: 1.55; }
  .bot .bubble b, .bot .bubble strong { font-weight: 650; }
  .user .bubble { border-radius: 20px; }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

/* Header: just a quiet title, no bar */
header { position: sticky; top: 0; z-index: 10; padding: 16px 24px; background: linear-gradient(to bottom, var(--bg) 55%, transparent); }
header h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
header p { display: none; }

/* Conversation */
main { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#thread { max-width: 760px; margin: 0 auto; padding: 16px 24px 32px; }

/* Welcome */
#welcome { text-align: center; padding: 10vh 0 8px; }
#welcome h2 { font-size: 30px; font-weight: 600; letter-spacing: -0.03em; margin: 0 0 8px; }
#welcome p { color: var(--muted); margin: 0 0 30px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--chip); border: 1px solid var(--line);
  padding: 9px 16px; border-radius: 999px; cursor: pointer;
  transition: background .15s ease;
}
.chip:hover { background: var(--hover); }

/* Messages: the student's message is a soft bubble; the assistant's reply is plain text on the page */
.row { display: flex; margin: 26px 0; animation: rise .35s ease both; }
.row.user { justify-content: flex-end; }
.user .bubble { max-width: 80%; padding: 10px 18px; border-radius: 24px; background: var(--user-bg); overflow-wrap: anywhere; }
.bot .bubble { width: 100%; padding: 0; overflow-wrap: anywhere; }
.bubble p { margin: 0 0 14px; } .bubble p:last-child { margin: 0; }
.bubble ul { margin: 4px 0 14px; padding-left: 22px; } .bubble li { margin: 5px 0; }

/* Sources */
details { margin-top: 14px; font-size: 13px; color: var(--muted); }
summary { cursor: pointer; list-style: none; user-select: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: " ›"; display: inline-block; transition: transform .2s; }
details[open] summary::after { transform: rotate(90deg); }
.src { margin: 10px 0 0; padding-left: 10px; border-left: 2px solid var(--line); }
.src b { color: var(--text); font-weight: 500; }

/* Quiet action row under each answer: copy, helpful, not helpful */
.fb { display: flex; align-items: center; gap: 2px; margin: 10px 0 0 -8px; font-size: 13px; color: var(--muted); }
.fb-btn { width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; transition: background .15s, color .15s; }
.fb-btn:hover { background: var(--hover); color: var(--text); }
.fb-btn svg { width: 17px; height: 17px; }
.fb-note { margin-left: 8px; }

/* Thinking indicator */
.dots { display: inline-flex; gap: 5px; padding: 6px 2px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .35; animation: pulse 1.2s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: .15s; } .dots span:nth-child(3) { animation-delay: .3s; }

/* Composer */
footer { padding: 0 24px calc(20px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 75%, transparent); }
.note { max-width: 760px; margin: 0 auto 10px; text-align: center; font-size: 12px; color: var(--muted); }
form {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 6px;
  min-height: 58px; padding: 9px 9px 9px 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 30px; box-shadow: var(--shadow);
  transition: border-color .2s;
}
form:focus-within { border-color: var(--line-strong); }
textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; padding: 8px 0; max-height: 160px; min-height: 28px;
}
textarea::placeholder { color: var(--muted); }
button#send {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--text); color: var(--bg); display: grid; place-items: center;
  transition: opacity .2s, transform .15s;
}
button#send:hover { transform: scale(1.05); }
button#send:disabled { opacity: .18; cursor: default; transform: none; }
button#send svg { width: 18px; height: 18px; }

/* Microphone */
button#mic {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; cursor: pointer;
  background: transparent; color: var(--muted); display: grid; place-items: center;
  transition: background .2s, color .2s;
}
button#mic:hover { background: var(--hover); color: var(--text); }
button#mic svg { width: 20px; height: 20px; }
button#mic.listening { background: var(--accent); color: #fff; animation: ring 1.6s infinite; }
button#mic[hidden] { display: none; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(0,113,227,.45); } 100% { box-shadow: 0 0 0 12px rgba(0,113,227,0); } }

@keyframes rise  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media (max-width: 520px) { #welcome h2 { font-size: 25px; } .user .bubble { max-width: 90%; } #thread, footer { padding-left: 16px; padding-right: 16px; } }
