/* Design language follows www.wangvc.com: paper background, ink text, orange accent,
   Instrument Serif headings, Inter body, JetBrains Mono labels, square 1px-line UI. */
:root {
  --bg: #f5f3ee;
  --paper: #fffdf9;
  --ink: #0e0e0e;
  --ink2: #2a2a2a;
  --dim: #6b6760;
  --line: #d9d5cc;
  --acc: #ff5b1f;
  --green: #1a7f37;
  --red: #c4321a;
  --code-bg: #111010;
  --code-ink: #e6e2d8;
  --serif: "Instrument Serif", Georgia, "Songti SC", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --header-h: 74px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
::selection { background: var(--acc); color: var(--bg); }

/* ---------- header ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 40px;
  background: rgba(245, 243, 238, .9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.title { display: flex; align-items: center; gap: 16px; min-width: 0; }
/* Same as the wangvc.com logo */
.brand { font-family: var(--serif); font-style: italic; font-size: 36px; letter-spacing: -.01em; white-space: nowrap; }
.brand a { color: inherit; text-decoration: none; }
.actions { display: flex; align-items: center; gap: 10px; }

/* Home link + EN | 中 switch, matching ai.dfmi.app */
.home-link { font-family: var(--mono); font-size: 13px; letter-spacing: .04em; color: var(--ink2); text-decoration: none; margin: 0 4px 0 8px; }
.home-link:hover { color: var(--acc); }
.langsw { display: inline-flex; }
.lang-btn { font-family: var(--mono); font-size: 12px; letter-spacing: .08em; line-height: 1; color: var(--ink); background: transparent; border: 1px solid var(--ink); padding: 5px 11px; }
.langsw .lang-btn + .lang-btn { border-left: none; }
.lang-btn:hover, .lang-btn.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- buttons ---------- */
button {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1;
  padding: 11px 18px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
button:hover { background: var(--acc); border-color: var(--acc); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
button.ghost { background: transparent; color: var(--ink); }
button.ghost:hover { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button.danger { color: var(--red); border-color: var(--red); }
button.danger:hover { background: var(--red); color: var(--bg); border-color: var(--red); }
button.small { font-size: 12px; padding: 8px 12px; }
button.icon { padding: 9px 12px; font-size: 16px; }

/* ---------- labels ---------- */
.eyebrow {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 14px;
}
.kick { color: var(--acc); }
.muted { font-family: var(--mono); font-size: 12px; color: var(--dim); margin: 4px 0; }
.error { font-family: var(--mono); font-size: 13px; color: var(--red); margin: 0; min-height: 1.6em; }

/* ---------- personas ---------- */
.avatar {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1;
  color: var(--bg);
  border: 1px solid var(--ink);
}
.avatar.star { background: var(--acc); border-color: var(--acc); }
.avatar.lin { background: var(--green); border-color: var(--green); }

/* ---------- login ---------- */
#login {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 48px;
  padding: 40px 22px;
  overflow-y: auto;
}
.meet { width: min(760px, 100%); }
.meet-cards { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--ink); }
.meet-card { display: flex; gap: 16px; padding: 22px 22px 6px 0; }
.meet-card + .meet-card { border-left: 1px solid var(--line); padding-left: 22px; }
.meet-card .avatar { width: 40px; height: 40px; font-size: 24px; }
.meet-card h3 { font-family: var(--serif); font-weight: 400; font-size: 28px; line-height: 1.1; margin: 0 0 8px; }
.meet-card.star h3 .it { font-style: italic; color: var(--acc); }
.meet-card.lin h3 .it { font-style: italic; color: var(--green); }
.meet-card p { font-size: 14.5px; color: var(--ink2); margin: 0; }
.meet-card p.role { font-family: var(--mono); font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); margin: 0 0 8px; }
@media (max-width: 760px) {
  #login { justify-content: flex-start; gap: 36px; }
  .meet-cards { grid-template-columns: 1fr; }
  .meet-card + .meet-card { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); }
}
#login-form {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--ink);
  padding-top: 28px;
}
#login-form h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1.1;
  letter-spacing: -.01em;
  margin: 0 0 8px;
}
#login-form h2 .it { font-style: italic; color: var(--acc); }
input, textarea {
  font-family: var(--sans);
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 14px;
}
input:focus, textarea:focus { border-color: var(--ink); outline: none; }
#login-form button[type="submit"] { align-self: flex-start; padding: 14px 22px; }

/* ---------- chat layout ---------- */
#chat { flex: 1; display: flex; min-height: 0; position: relative; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

#sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: var(--bg);
  overflow-y: auto;
}
#sidebar .eyebrow { margin: 10px 0 0; }
#new-chat { width: 100%; padding: 14px 18px; text-align: left; }
#conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--ink);
}
#conv-list li {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  transition: background .15s;
}
#conv-list li:hover { background: var(--paper); }
#conv-list li.active { background: var(--paper); box-shadow: inset 3px 0 0 var(--acc); }
.conv-open .avatar { width: 20px; height: 20px; font-size: 12px; margin-right: 8px; vertical-align: -4px; }
.conv-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink2);
  background: transparent;
  border: 0;
  padding: 11px 10px 11px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-open:hover { background: transparent; color: var(--acc); }
#conv-list li.active .conv-open { color: var(--ink); }
.conv-delete {
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1;
  color: var(--dim);
  background: transparent;
  border: 0;
  padding: 8px 10px;
  opacity: 0;
}
.conv-delete:hover { background: transparent; color: var(--red); }
#conv-list li:hover .conv-delete,
#conv-list li.active .conv-delete,
.conv-delete:focus-visible { opacity: 1; }
#delete-all { margin-top: auto; align-self: flex-start; }
#toggle-sidebar { display: none; }

/* ---------- conversation ---------- */
#log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 26px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 40px 24px;
}

.empty { padding-top: 6vh; }
.empty h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(34px, 5.4vw, 60px);
  line-height: 1.06;
  letter-spacing: -.01em;
  margin: 0 0 18px;
}
.empty h2 .it { font-style: italic; color: var(--acc); }
.empty .lede { font-size: 18px; line-height: 1.55; color: var(--ink2); margin: 0 0 30px; max-width: 640px; }
.persona-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 720px; margin-bottom: 34px; }
.persona-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  text-align: left;
  font-family: var(--sans);
  line-height: 1.45;
  color: var(--ink2);
  background: transparent;
  border: 1px solid var(--line);
  padding: 16px;
}
.persona-card:hover { background: var(--paper); border-color: var(--ink); color: var(--ink2); }
.persona-card[aria-pressed="true"] { background: var(--paper); border-color: var(--ink); }
.persona-card.star[aria-pressed="true"] { box-shadow: inset 3px 0 0 var(--acc); }
.persona-card.lin[aria-pressed="true"] { box-shadow: inset 3px 0 0 var(--green); }
.persona-card .avatar { width: 36px; height: 36px; font-size: 21px; }
.persona-cell { display: flex; flex-direction: column; gap: 8px; }
.persona-cell .persona-card { flex: 1; }
.persona-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: .02em;
  text-decoration: none;
  color: var(--bg);
  background: var(--ink);
  border: 1px solid var(--ink);
  transition: background .15s, border-color .15s;
}
.persona-link.star:hover { background: var(--acc); border-color: var(--acc); }
.persona-link.lin:hover { background: var(--green); border-color: var(--green); }
.persona-link-domain { opacity: .75; white-space: nowrap; }
.persona-link:hover .persona-link-domain { opacity: 1; }
.persona-text { display: flex; flex-direction: column; gap: 4px; }
.persona-name { font-family: var(--serif); font-size: 22px; line-height: 1.1; color: var(--ink); }
.persona-tag { font-size: 13.5px; }
@media (max-width: 760px) { .persona-pick { grid-template-columns: 1fr; } }
.empty ul { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--ink); max-width: 720px; }
.empty li { border-bottom: 1px solid var(--line); }
.suggestion {
  width: 100%;
  text-align: left;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink2);
  background: transparent;
  border: 0;
  padding: 16px 4px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}
.suggestion::after { content: "→"; font-family: var(--mono); color: var(--acc); }
.suggestion:hover { background: var(--paper); color: var(--ink); }

.msg { overflow-wrap: anywhere; position: relative; }
.msg-delete {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--dim);
  background: var(--bg);
  border: 1px solid var(--line);
  opacity: 0;
}
.msg-delete:hover { color: var(--bg); background: var(--red); border-color: var(--red); }
.msg:hover .msg-delete, .msg-delete:focus-visible { opacity: 1; }
body.busy .msg-delete { display: none; }
.msg.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 12px 16px;
  white-space: pre-wrap;
  color: var(--ink);
}
.msg.assistant {
  border-left: 3px solid var(--acc);
  padding: 2px 0 2px 22px;
  color: var(--ink2);
}
.msg.assistant.lin { border-left-color: var(--green); }
.who {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .08em;
  color: var(--dim);
}
.who .avatar { width: 24px; height: 24px; font-size: 14px; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.msg h1, .msg h2, .msg h3 {
  font-family: var(--serif);
  font-weight: 400;
  color: var(--ink);
  line-height: 1.15;
  margin: 1.2em 0 .4em;
}
.msg h1 { font-size: 30px; }
.msg h2 { font-size: 26px; }
.msg h3 { font-size: 22px; font-style: italic; }
.msg strong, .msg b { color: var(--ink); }
.msg a { color: var(--acc); }
.msg code { font-family: var(--mono); font-size: 13px; background: #ebe8e1; padding: 1px 5px; }
.msg pre {
  background: var(--code-bg);
  color: var(--code-ink);
  border: 1px solid #000;
  padding: 16px 18px;
  overflow-x: auto;
  line-height: 1.7;
}
.msg pre code { background: none; padding: 0; color: inherit; }
.msg blockquote { border-left: 1px solid var(--line); margin: 0; padding-left: 16px; color: var(--dim); }
.msg table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.msg th, .msg td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.msg th { font-family: var(--mono); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); font-weight: 500; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tools:empty { display: none; }
.tool {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .04em;
  color: var(--dim);
  border: 1px solid var(--line);
  padding: 3px 10px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool.running { color: var(--ink2); border-color: var(--ink2); }
.tool.running::before { content: "● "; color: var(--acc); animation: pulse 1.2s ease-in-out infinite; }
.tool.ok::before { content: "✓ "; color: var(--green); }
.tool.failed { color: var(--red); border-color: var(--red); }
.tool.failed::before { content: "✗ "; }
@keyframes pulse { 50% { opacity: .25; } }
.msg .error { margin-top: 10px; }
.typing { font-family: var(--mono); font-size: 13px; color: var(--dim); }
.typing::after { content: "▍"; color: var(--acc); animation: pulse 1s steps(1) infinite; }

/* ---------- composer ---------- */
#composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 40px 26px;
}
#input { flex: 1; resize: none; max-height: 40vh; line-height: 1.5; }
#send, #stop { padding: 14px 22px; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  header { padding: 0 22px; --header-h: 64px; }
  .brand { font-size: 28px; }
  #toggle-sidebar:not([hidden]) { display: inline-block; }
  #sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 0 1px var(--line), 12px 0 32px rgba(14, 14, 14, .12);
  }
  body.sidebar-open #sidebar { transform: none; }
  .conv-delete { opacity: 1; }
  .msg-delete { opacity: .7; }
  #log { padding: 26px 22px 16px; }
  #composer { padding: 12px 22px 20px; }
  /* Narrow header: per-conversation × in the sidebar covers deleting */
  #delete-chat { display: none !important; }
  .actions { gap: 8px; }
  .home-link { margin: 0; font-size: 12px; }
  .lang-btn { padding: 5px 8px; }
  #logout { padding: 7px 9px; font-size: 12px; }
}
@media (max-width: 400px) {
  .brand { font-size: 24px; }
  .title { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .tool.running::before, .typing::after { animation: none; }
  #sidebar { transition: none; }
}
