.app { min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-size: 19px; flex-shrink: 0; }
.topbar .brand img { width: 28px; height: 28px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 7px 12px; border-radius: 999px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 15px; }
.topbar nav a.active { background: #ecfdf5; color: var(--brand); }
.topbar .who { color: var(--muted); font-size: 14px; }
.page { max-width: 1080px; margin: 0 auto; padding: 24px 20px; }
.card { background: #fff; border: 2px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: 0 4px 0 var(--line); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
input, textarea, select { font: inherit; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); }
textarea { resize: vertical; }
.error { color: #b91c1c; }
.ok { color: #15803d; }
h1, h2, h3 { margin: 0; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: #ecfdf5; color: var(--brand); font-size: 12px; font-weight: 600; }
.login { max-width: 400px; margin: 10vh auto; }
.code-label { font-weight: 800; }
.code-boxes { position: relative; display: flex; gap: 8px; justify-content: center; }
.code-boxes .box { width: 48px; height: 58px; border: 2px solid var(--line); border-radius: 14px; box-shadow: 0 3px 0 var(--line);
  display: grid; place-items: center; font-size: 28px; font-weight: 800; background: #fff; }
.code-boxes .box.active { border-color: var(--brand); box-shadow: 0 3px 0 var(--brand-d); }
.code-boxes .code { position: absolute; inset: 0; opacity: 0; width: 100%; font-size: 16px; cursor: text; }

/* chat */
.chat-layout { display: grid; grid-template-columns: 280px 1fr; height: calc(100vh - 61px); }
.chat-list { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: #fff; }
.chat-list a { display: block; padding: 10px 12px; border-radius: 14px; text-decoration: none; color: var(--ink); border: 2px solid transparent; }
.chat-list a.active { background: #fff; border-color: var(--line); box-shadow: 0 3px 0 var(--line); }
.chat-list .meta { color: var(--muted); font-size: 12px; }
.conv { display: flex; flex-direction: column; min-height: 0; }
.conv-head { padding: 12px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 760px; padding: 12px 16px; border-radius: 18px; line-height: 1.5; position: relative; }
.msg.user { align-self: flex-end; background: var(--soft); color: var(--ink); font-weight: 600; border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant { align-self: stretch; background: transparent; padding: 0 4px; font-size: 17px; }
.msg.assistant .katex-display { background: #fafaf9; border-radius: 14px; padding: 10px 6px; }
.who { display: flex; gap: 8px; align-items: center; font-weight: 800; margin-bottom: 4px; }
.who img { width: 28px; height: 28px; }
.steps { display: flex; gap: 4px; width: 220px; } .steps i { flex: 1; height: 8px; border-radius: 9px; background: var(--line); transition: background .3s; }
.steps i.f { background: var(--brand); } .steps.done i { background: var(--ok); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: #fff; border: 2px solid var(--line); border-radius: 12px; box-shadow: 0 3px 0 var(--line); padding: 7px 12px; font-weight: 800; cursor: pointer; font-size: 14px; }
.chip:active { transform: translateY(3px); box-shadow: none; }
.solved { border-top: 2px solid #86efac; background: var(--ok-bg); padding: 16px 20px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.solved .h { color: var(--ok); font-weight: 900; font-size: 24px; }
.solved img { width: 48px; height: 48px; }
.streak { font-weight: 800; font-size: 14px; color: #c2410c; background: #fff7ed; border: 2px solid #fed7aa; border-radius: 999px; padding: 3px 10px; }
.thinking img { width: 28px; height: 28px; vertical-align: middle; animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-4deg); } }
.msg.assistant p:first-child { margin-top: 0; } .msg.assistant p:last-child { margin-bottom: 0; }
.msg .thumbs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.msg .thumbs img { height: 120px; border-radius: 10px; background: #fff; }
.msg .actions { display: flex; gap: 6px; margin-top: 8px; }
.reasoning { align-self: flex-start; color: var(--muted); font-size: 13px; max-width: 760px; }
.reasoning summary { cursor: pointer; }
.msg.error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.typing { align-self: flex-start; color: var(--muted); font-size: 14px; }
.composer { border-top: 1px solid var(--line); padding: 12px 20px; display: flex; flex-direction: column; gap: 8px; background: #fff; }
.composer textarea { width: 100%; min-height: 54px; }
.pending { display: flex; gap: 8px; }
.pending img { height: 64px; border-radius: 8px; }
.empty { color: var(--muted); text-align: center; margin: auto; }

/* highlights */
mark.hl, mark { border-radius: 3px; padding: 0 1px; color: inherit; background: var(--hl-yellow); }
mark.green { background: var(--hl-green); } mark.pink { background: var(--hl-pink); } mark.blue { background: var(--hl-blue); }
u.ul, span.ul { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
span.ul.yellow { text-decoration-color: #d97706; } span.ul.green { text-decoration-color: #16a34a; }
span.ul.pink { text-decoration-color: #db2777; } span.ul.blue { text-decoration-color: #059669; }
.selbar { position: fixed; z-index: 20; display: flex; gap: 4px; background: var(--ink); padding: 6px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.selbar button { border: 0; border-radius: 8px; padding: 6px 9px; cursor: pointer; font-weight: 600; font-size: 13px; }
.selbar .sw { width: 26px; } .sw.yellow { background: var(--hl-yellow); } .sw.green { background: var(--hl-green); }
.sw.pink { background: var(--hl-pink); } .sw.blue { background: var(--hl-blue); }
.selbar .txt { background: #fff; color: var(--ink); }

/* notes */
.notes-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
.note-item { padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.note-item.active { border-color: var(--brand); }
.note-item .meta { color: var(--muted); font-size: 12px; }
.note-body { line-height: 1.6; }
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; }
.toolbar button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 9px; cursor: pointer; }
@media (max-width: 760px) {
  .chat-layout { grid-template-columns: 1fr; }
  .chat-list { display: none; }
  .notes-layout { grid-template-columns: 1fr; }
}
.lang-switch { display: inline-flex; gap: 2px; background: var(--soft); border-radius: 10px; padding: 3px; }
.lang-switch a { font: 800 12px ui-monospace, Menlo, monospace; padding: 4px 8px; border-radius: 8px; color: var(--muted); text-decoration: none; }
.lang-switch a.on { background: #fff; color: var(--ink); box-shadow: 0 2px 0 var(--line); }
.engine-switch { font-weight: 800; font-size: 13px; padding: 6px 10px; }
.switch { align-self: center; font-weight: 800; font-size: 12.5px; color: var(--muted); background: var(--soft);
  border: 2px solid var(--line); border-radius: 999px; padding: 4px 12px; }
