:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --ink: #1f1d1b;
  --muted: #6b6661;
  --line: #e4dfd8;
  --accent: #a70e16;
  --accent-ink: #ffffff;
  --accent-soft: #f7ecec;
  --user-bubble: #f0ece6;
  --warn-bg: #fff6dc;
  --warn-line: #ecd58a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); display: flex; flex-direction: column; }
a { color: var(--accent); }
h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; font-size: 1.9rem; margin: 0 0 .5rem; }
h2 { font-size: 1rem; margin: 0 0 .5rem; }
button, select, textarea, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex: none;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: .6rem; text-decoration: none; color: var(--ink); }
.brand-mark { width: .8rem; height: .8rem; background: var(--accent); border-radius: 2px; align-self: center; }
.brand-name { font-family: Georgia, serif; font-weight: 600; font-size: 1.1rem; }
.brand-sub { color: var(--muted); font-size: .85rem; }
.nav { display: flex; gap: .25rem; }
.nav a { padding: .3rem .7rem; border-radius: 6px; text-decoration: none; color: var(--muted); font-size: .95rem; }
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--bg); font-weight: 600; }
.account { margin-left: auto; display: flex; align-items: center; gap: 1rem; font-size: .9rem; }
.switcher { display: flex; align-items: center; gap: .5rem; }
.switcher label { color: var(--muted); }
select { padding: .3rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
button.link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; }

/* ---- simple pages ---- */
.center { width: 100%; max-width: 40rem; margin: 0 auto; padding: 4rem 1.25rem; }
.center.wide { max-width: 48rem; }
.lede { color: var(--muted); margin: 0 0 2rem; }
.fine { color: var(--muted); font-size: .9rem; }
.muted { color: var(--muted); font-size: .9rem; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 1rem; }
.account-card {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: .3rem;
  padding: 1.5rem 1rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.account-card:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.avatar {
  width: 3rem; height: 3rem; border-radius: 50%; display: grid; place-items: center;
  font-weight: 600; font-size: 1.2rem; background: var(--user-bubble); margin-bottom: .4rem;
}
.avatar.instructor { background: var(--accent); color: var(--accent-ink); }
.account-name { font-weight: 600; }
.account-role { color: var(--muted); font-size: .9rem; }
.empty-card {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 1.5rem 1.75rem; margin: 1.5rem 0;
}
.empty-card p { margin: .5rem 0; color: var(--muted); }

/* ---- chat ---- */
.chat-layout { flex: 1; min-height: 0; display: flex; }
.sidebar {
  width: 17rem; flex: none; overflow-y: auto; padding: 1rem;
  border-right: 1px solid var(--line); background: var(--surface);
}
.sidebar h2 { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; margin: 1.25rem 0 .5rem; }
.new-chat {
  display: block; text-align: center; padding: .5rem; border-radius: 8px; text-decoration: none;
  border: 1px solid var(--line); color: var(--ink); font-weight: 600; font-size: .95rem;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent); }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-list li { display: flex; align-items: center; border-radius: 6px; }
.conv-list li:hover, .conv-list li.active { background: var(--bg); }
.conv-list li.active a { font-weight: 600; }
.conv-list a {
  flex: 1; min-width: 0; padding: .4rem .5rem; color: var(--ink); text-decoration: none;
  font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
button.icon { background: none; border: 0; color: var(--muted); cursor: pointer; padding: .2rem .5rem; opacity: 0; font-size: 1.1rem; }
.conv-list li:hover button.icon, button.icon:focus-visible { opacity: 1; }
button.icon:hover { color: var(--accent); }

.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.banner {
  flex: none; padding: .55rem 1.25rem; background: var(--accent-soft);
  border-bottom: 1px solid var(--line); font-size: .9rem;
}
.banner strong { margin-right: .35rem; }
.notice {
  margin: .75rem auto 0; width: calc(100% - 2.5rem); max-width: 46rem; padding: .6rem .9rem;
  background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; font-size: .9rem;
}
.notice.error { margin: 0 0 .6rem; width: 100%; }
.notice[hidden] { display: none; }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 1.5rem 1.25rem; }
.welcome { max-width: 46rem; margin: 12vh auto 0; text-align: center; color: var(--muted); }
.welcome h1 { color: var(--ink); }
.msg { max-width: 46rem; margin: 0 auto 1.4rem; }
.msg .who { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .2rem; }
.msg.user .body {
  background: var(--user-bubble); padding: .65rem .9rem; border-radius: var(--radius);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .body { overflow-wrap: anywhere; }
.msg .body p { margin: 0 0 .7rem; white-space: pre-wrap; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body ul, .msg .body ol { margin: 0 0 .7rem; padding-left: 1.4rem; }
.msg .body li { margin: .15rem 0; white-space: pre-wrap; }
.msg .body h3, .msg .body h4, .msg .body h5, .msg .body h6 { font-size: 1rem; margin: 1rem 0 .4rem; }
.msg .body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: var(--user-bubble); padding: .1em .3em; border-radius: 4px; }
.msg .body pre { background: #23201d; color: #f3efe9; padding: .8rem 1rem; border-radius: 8px; overflow-x: auto; margin: 0 0 .7rem; }
.msg .body pre code { background: none; padding: 0; color: inherit; }
.pending { color: var(--muted); font-style: italic; }

.composer { flex: none; width: 100%; max-width: 48.5rem; margin: 0 auto; padding: 0 1.25rem 1rem; }
.composer-box {
  display: flex; align-items: flex-end; gap: .5rem; padding: .5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
}
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; resize: none; border: 0; outline: 0; background: none; padding: .45rem .5rem; max-height: 200px; }
.composer button[type="submit"] {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 9px;
  padding: .5rem 1.1rem; font-weight: 600; cursor: pointer;
}
.composer button.stop { background: var(--ink); }
.composer-foot { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem .4rem 0; color: var(--muted); font-size: .8rem; }
.composer-foot { align-items: center; }
.model-picker {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  padding: .25rem .3rem .25rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font-size: .85rem;
}
.model-picker:hover { border-color: var(--accent); }
.model-picker select {
  font-size: .85rem; font-weight: 600; padding: .15rem .3rem; border: 0; background: none; cursor: pointer;
}
/* Once a conversation has started its model is fixed: show it as plain text. */
.model-picker:has(select:disabled) { border-color: transparent; background: none; cursor: default; padding-left: .4rem; color: var(--muted); }
.model-picker select:disabled { -webkit-appearance: none; appearance: none; opacity: 1; color: var(--ink); cursor: default; }
.model-fixed { padding-left: .4rem; }
.model-fixed strong { color: var(--ink); }
.msg .body .katex { font-size: 1.08em; }
.msg .body .katex-display { margin: .8rem 0; overflow-x: auto; overflow-y: hidden; padding: .1rem 0; }

@media (max-width: 760px) {
  .sidebar { display: none; }
  .brand-sub, .switcher label { display: none; }
  .topbar { gap: .75rem; padding: .6rem .8rem; }
}

/* ---- a model's thinking, shown above its reply ---- */
.thoughts { margin: .2rem 0 .7rem; border-left: 3px solid var(--line); padding-left: .8rem; color: var(--muted); font-size: .88rem; }
.thoughts summary { cursor: pointer; font-weight: 600; width: fit-content; }
.thoughts summary:hover { color: var(--ink); }
.thoughts[open] summary { margin-bottom: .3rem; }
.thoughts div { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- tables inside replies ---- */
.msg .body .table-wrap { overflow-x: auto; margin: 0 0 .8rem; }
.msg .body table { border-collapse: collapse; font-size: .95em; }
.msg .body th, .msg .body td { border: 1px solid var(--line); padding: .35rem .7rem; text-align: left; vertical-align: top; }
.msg .body th { background: var(--user-bubble); font-weight: 600; }

/* ---- Milestone 2: courses, assignments, modes ---- */
.crumbs { margin: 0 0 .3rem; font-size: .9rem; color: var(--muted); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.title-row h1, .title-row h2 { margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.5rem; margin: 1.5rem 0; }
.panel > h2, .panel .title-row { margin-bottom: .9rem; }
.panel h2 { font-size: 1.1rem; }
.course-title { font-family: Georgia, serif; font-size: 1.3rem !important; }
.hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
.clip { max-width: 22rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; margin: 1.25rem 0; }
.card { display: flex; flex-direction: column; gap: .3rem; padding: 1.1rem 1.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.card:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.card-title { font-family: Georgia, serif; font-size: 1.15rem; font-weight: 600; }
.card-meta { color: var(--muted); font-size: .88rem; display: flex; gap: .5rem; align-items: center; }

.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.stack label, .stack legend { font-weight: 600; font-size: .95rem; }
.stack label { display: flex; flex-direction: column; gap: .3rem; }
.stack label.check, .stack label.mode-card { flex-direction: row; font-weight: 400; }
.stack .row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.stack fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .45rem; }
.stack legend { padding: 0; margin-bottom: .45rem; }
input[type="text"], input[type="datetime-local"], textarea, .stack select {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-weight: 400;
}
input[type="datetime-local"] { width: auto; }
.stack textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; }
.composer textarea { border: 0; padding: .45rem .5rem; border-radius: 0; }
.check { align-items: center; gap: .5rem !important; }
button.primary, a.button {
  display: inline-block; padding: .5rem 1.1rem; border-radius: 9px; font-weight: 600; font-size: .95rem;
  cursor: pointer; text-decoration: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
a.button:hover { border-color: var(--accent); color: var(--accent); }
.danger-zone { margin-top: 1rem; }
button.danger { color: var(--accent); }

.badge { display: inline-block; padding: .08rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; letter-spacing: .02em; background: var(--user-bubble); color: var(--ink); white-space: nowrap; }
.badge.off, .mode-off { background: #e6e3df; color: #55504a; }
.mode-tutor { background: #dcebfa; color: #154a80; }
.mode-brainstorm { background: #fbeccb; color: #7a5200; }
.mode-feedback { background: #e9e1f7; color: #50308a; }
.mode-open { background: #dcf2e0; color: #1d6030; }
.badge.preview { background: var(--ink); color: #fff; }
.mode-select { border: 0; border-radius: 999px; padding: .2rem .5rem; font-weight: 700; font-size: .85rem; cursor: pointer; }

.mode-cards { display: grid; gap: .5rem; }
.mode-card { align-items: center; gap: .7rem !important; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.mode-card:hover { border-color: var(--accent); }
.mode-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.mode-card .badge { min-width: 5.6rem; text-align: center; }
.mode-desc { color: var(--muted); font-size: .92rem; }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .3rem .6rem .5rem 0; border-bottom: 1px solid var(--line); }
table.grid td { padding: .65rem .6rem .65rem 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.actions { text-align: right; white-space: nowrap; font-size: .9rem; padding-right: 0; }

.switch-form { display: flex; align-items: center; gap: .7rem; font-size: .95rem; }
.switch { width: 3rem; height: 1.7rem; border-radius: 999px; border: 0; background: #c9c4bd; position: relative; cursor: pointer; padding: 0; transition: background .15s; }
.switch span { position: absolute; top: .2rem; left: .2rem; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch.on { background: #2e8b47; }
.switch.on span { left: 1.5rem; }

.assignment-list { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .5rem; }
.assignment { display: grid; grid-template-columns: 1fr auto; gap: .15rem .8rem; align-items: center; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); }
a.assignment:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.assignment.locked { background: var(--bg); color: var(--muted); }
.assignment-title { font-weight: 600; }
.assignment-rule { grid-column: 1 / -1; color: var(--muted); font-size: .9rem; }
details.policy { font-size: .9rem; margin: .3rem 0 .6rem; }
details.policy summary { cursor: pointer; color: var(--muted); width: fit-content; }
details.policy summary:hover { color: var(--ink); }
details.policy p { margin: .4rem 0 0; white-space: pre-wrap; }

.banner-where { margin-bottom: .15rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.banner-model { color: var(--muted); }
.banner.locked { background: #eceae6; }
.banner details.policy { margin: .3rem 0 0; }
.lock-note { padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: #eceae6; font-size: .95rem; }
.conv-where { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.center > .notice { width: 100%; max-width: none; margin: 1rem 0 0; }

/* ---- Milestone 3: sharing ---- */
.nav .count { display: inline-block; min-width: 1.25rem; padding: 0 .35rem; border-radius: 999px; background: var(--accent); color: #fff; font-size: .72rem; font-weight: 700; text-align: center; }
.share-button { margin-left: auto; padding: .25rem .8rem; border-radius: 999px; border: 1px solid var(--accent); background: var(--surface); color: var(--accent); font-size: .82rem; font-weight: 600; cursor: pointer; }
.share-button:hover { background: var(--accent); color: #fff; }
.share-button[hidden] { display: none; }
.shared-note { font-size: .85rem; color: #1d6030; margin: .1rem 0 .2rem; }
.share-note-text { margin-top: .35rem; white-space: pre-wrap; }
.notice.ok { background: #e4f4e7; border-color: #a9d6b2; }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 1.5rem 1.6rem; width: min(32rem, calc(100vw - 2rem)); box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--ink); }
dialog::backdrop { background: rgba(30, 25, 20, .45); }
dialog h2 { font-family: Georgia, serif; font-size: 1.3rem; margin: 0; }
dialog p { margin: 0; }
.button-plain { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; padding: .5rem; }
.badge.new { background: var(--accent); color: #fff; margin-left: .3rem; }
tr.unseen td:first-child a { font-weight: 700; }
/* keep the top bar on one line at laptop-pane widths */
.brand, .nav a, .switcher label, button.link { white-space: nowrap; }
@media (max-width: 1300px) { .brand-sub { display: none; } }
@media (max-width: 1150px) { .switcher label { display: none; } .topbar { gap: 1rem; } }

input[type="password"] { width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
