/* 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: 75px;
}

* { 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, .92);
  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; }

/* ---------- 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; }

/* ---------- login ---------- */
#login { flex: 1; display: grid; place-items: center; padding: 40px 22px; }
#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; }
.side-nav { display: none; flex-direction: column; gap: 2px; margin: 0 0 14px; padding: 0 0 12px; border-bottom: 1px solid var(--line); }
.side-nav a { font-family: var(--mono); font-size: 14px; color: var(--ink2); text-decoration: none; padding: 8px 2px; }
.side-nav a:hover { color: var(--acc); }
.side-nav a.active { color: var(--acc); text-decoration: underline; text-decoration-color: var(--acc); text-underline-offset: 5px; }
#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 {
  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; }
.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 .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: center;
  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; min-height: 46px; padding: 10px 14px; }
#send, #stop { height: 44px; padding: 0 22px; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  header { padding: 0 22px; --header-h: 75px; }
  .brand { font-size: 30px; }
  #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 .2s ease;
  }
  body.sidebar-open #sidebar { transform: none; box-shadow: 0 0 0 1px var(--line), 12px 0 32px rgba(14, 14, 14, .12); }
  .conv-delete { opacity: 1; }
  .msg-delete { opacity: .7; }
  #log { padding: 26px 22px 16px; }
  #composer { padding: 12px 22px 20px; }
  #delete-chat { padding: 9px 12px; }
  #logout { padding: 9px 12px; }
  .actions .menu-wrap { display: none; }
  .actions .home-link { display: none; }
  .side-nav { display: flex; }
}

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

/* repo names inside the empty-state lede */
.empty .lede strong { color: var(--ink); font-weight: 600; }
.empty .lede code { font-family: var(--mono); font-size: 14px; background: var(--line); color: var(--ink); padding: 1px 6px; border-radius: 4px; }

/* language / home nav in the header — matches dfmi.app */
.actions { display: flex; align-items: center; gap: 12px; }
.lang-nav { display: inline-flex; align-items: center; gap: 18px; }
.lang-nav a { font-family: var(--mono); font-size: 12px; letter-spacing: .06em; color: var(--ink2); text-decoration: none; }
.lang-nav a:hover { color: var(--ink); }
.langsw { display: inline-flex; }
.lang-btn { font-family: var(--mono); font-size: 12px; letter-spacing: .08em; color: var(--ink); background: transparent; border: 1px solid var(--ink); padding: 5px 11px; cursor: pointer; transition: .15s; }
.langsw .lang-btn + .lang-btn { border-left: none; }
.lang-btn:hover { background: var(--ink); color: var(--bg); }
.lang-btn.active { background: var(--ink); color: var(--bg); }

/* section nav (Overview / Guide / Q&A) next to the brand */
.section-nav { display: inline-flex; align-items: center; gap: 16px; }
.section-nav a { font-family: var(--mono); font-size: 13px; letter-spacing: .04em; color: var(--ink2); text-decoration: none; transition: .15s; }
.section-nav a:hover { color: var(--ink); }
.section-nav a.active { color: var(--acc); border-bottom: 1.5px solid var(--acc); padding-bottom: 2px; }
@media (max-width: 720px) { .section-nav { display: none; } }

/* space between section-nav and the Home/lang group on the right */
.actions .lang-nav { margin-left: 16px; }

/* header sandwich menu */
.menu-wrap { position: relative; display: inline-flex; }
.menu-panel { position: absolute; top: calc(100% + 8px); right: 0; min-width: 190px; background: var(--paper); border: 1px solid var(--ink); display: flex; flex-direction: column; z-index: 60; box-shadow: 0 12px 30px rgba(14,14,14,.16); }
.menu-panel a { font-family: var(--mono); font-size: 13px; letter-spacing: .04em; color: var(--ink2); text-decoration: none; padding: 12px 16px; }
.menu-panel a:hover { background: var(--line); color: var(--ink); }
.menu-panel a.active { color: var(--acc); }
.menu-panel .langsw { margin: 10px 16px 14px; }

/* responsive header nav: inline on desktop, hamburger dropdown on mobile */
#menu-toggle { display: none; }
.nav-group { display: inline-flex; align-items: center; gap: 16px; }
.nav-group a { font-family: var(--mono); font-size: 13px; color: var(--ink2); text-decoration: none; transition: .15s; }
.nav-group a:hover { color: var(--acc); }
.nav-group a.active { color: var(--acc); text-decoration: underline; text-decoration-color: var(--acc); text-underline-offset: 5px; }
.nav-group .langsw { margin-left: 4px; }
@media (max-width: 760px) {
  #menu-toggle { display: inline-flex; }
  .nav-group { display: none; position: absolute; top: calc(100% + 8px); right: 0; flex-direction: column; align-items: stretch; gap: 0; min-width: 190px; padding-bottom: 10px; background: var(--paper); border: 1px solid var(--ink); z-index: 60; box-shadow: 0 12px 30px rgba(14,14,14,.16); }
  .nav-group.open { display: flex; }
  .nav-group a { padding: 12px 16px; }
  .nav-group a.active { color: var(--acc); border-bottom: none; text-decoration: underline; text-decoration-color: var(--acc); text-underline-offset: 5px; }
  .nav-group .langsw { margin: 10px 16px 14px; }
}

/* Home link stays outside the hamburger (visible on desktop + mobile) */
.home-link { font-family: var(--mono); font-size: 13px; letter-spacing: .04em; color: var(--ink2); text-decoration: none; margin-left: 8px; }
.home-link:hover { color: var(--acc); }

/* mobile: show Home before the ☰ menu */
@media (max-width: 760px) {
  .actions .home-link { order: 1; }
  .actions .menu-wrap { order: 2; }
  .actions .langsw { order: 3; }
}

/* hamburger matching dfmi.me/guide.html (38x38 box, 3 bars, X on open) */
#menu-toggle.burger { display: none; flex-direction: column; justify-content: center; gap: 5px; width: 38px; height: 38px; padding: 0; background: none; border: 1px solid var(--line); border-radius: 0; cursor: pointer; }
#menu-toggle.burger:hover { background: none; border-color: var(--ink); }
#menu-toggle.burger span { display: block; width: 18px; height: 1.5px; background: var(--ink); margin: 0 auto; transition: .2s; }
#menu-toggle.burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
#menu-toggle.burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
#menu-toggle.burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }
@media (max-width: 760px) { #menu-toggle.burger { display: flex; } }

/* touch screens: :hover sticks after a tap, so keep buttons in their resting state */
@media (hover: none) {
  button:hover { background: var(--ink); border-color: var(--ink); }
  button.ghost:hover { background: transparent; color: var(--ink); border-color: var(--ink); }
  button.ghost.danger:hover { background: transparent; color: var(--red); border-color: var(--red); }
  .lang-btn:not(.active):hover { background: transparent; color: var(--ink); }
}
#toggle-sidebar[aria-expanded="true"] { background: var(--ink); color: var(--bg); }
