/* ==========================================================================
   EVIL — standalone dark design system. Pure CSS, no build step.
   ========================================================================== */

:root {
  --radius: 0.9rem;
  --font-sans: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --background: oklch(0.145 0.012 264);
  --foreground: oklch(0.955 0.005 264);
  --surface: oklch(0.185 0.014 264);
  --surface-2: oklch(0.225 0.016 264);

  --primary: oklch(0.78 0.2 145);
  --primary-foreground: oklch(0.16 0.03 145);
  --muted-foreground: oklch(0.68 0.015 264);
  --accent: oklch(0.7 0.19 25);
  --destructive: oklch(0.62 0.23 25);
  --destructive-foreground: oklch(0.98 0.01 25);

  --border: oklch(1 0 0 / 9%);
  --glow-primary: 0 0 0 1px oklch(0.78 0.2 145 / 30%), 0 0 28px -6px oklch(0.78 0.2 145 / 45%);
  --gradient-evil: linear-gradient(135deg, oklch(0.78 0.2 145), oklch(0.7 0.19 25));
}

* { box-sizing: border-box; border-color: var(--border); }
html, body {
  height: 100%; margin: 0; background: var(--background); color: var(--foreground);
  font-family: var(--font-sans); -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
body { overflow: hidden; }
button { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; padding: 0; }
textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------- App shell ---------- */
.app { position: fixed; inset: 0; display: flex; background: var(--background); color: var(--foreground); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; display: flex; flex-direction: column;
  width: 86%; max-width: 320px; background: var(--surface); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .3s ease;
}
.sidebar.open { transform: translateX(0); }
@media (min-width: 768px) {
  .sidebar { position: static; transform: none; width: 280px; }
  .menu-btn, .sidebar-close, .mobile-mark { display: none !important; }
  .backdrop { display: none !important; }
}
.backdrop {
  position: fixed; inset: 0; z-index: 30; background: oklch(0.145 0.012 264 / 0.7);
  backdrop-filter: blur(6px); display: none;
}
.backdrop.show { display: block; }

.sidebar-head {
  display: flex; align-items: center; gap: 10px; padding: 16px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px;
  background: var(--surface-2); color: var(--primary); box-shadow: var(--glow-primary);
}
.brand-text { min-width: 0; flex: 1; }
.brand-name {
  font-family: var(--font-mono); font-size: 15px; font-weight: 700; letter-spacing: -.01em;
  background: var(--gradient-evil); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .18em; color: var(--muted-foreground);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; color: var(--muted-foreground);
}
.icon-btn:hover { background: var(--surface-2); }

.new-chat-wrap { padding: 12px 12px 0; }
.new-chat {
  width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 12px; border-radius: 12px; border: 1px solid oklch(0.78 0.2 145 / 0.4);
  background: oklch(0.78 0.2 145 / 0.1); color: var(--primary); font-weight: 600; font-size: 14px;
  box-shadow: var(--glow-primary);
}
.new-chat:hover { background: oklch(0.78 0.2 145 / 0.2); }

.history { flex: 1; overflow-y: auto; padding: 8px; margin-top: 16px;
  scrollbar-width: thin; scrollbar-color: var(--surface-2) transparent;
}
.history-label {
  padding: 4px 8px 6px; font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .18em; color: var(--muted-foreground);
}
.thread-row {
  display: flex; align-items: center; gap: 4px; padding-left: 10px; padding-right: 4px;
  border-radius: 8px; color: var(--muted-foreground); transition: background .15s;
}
.thread-row:hover { background: oklch(0.225 0.016 264 / 0.6); }
.thread-row.active { background: var(--surface-2); color: var(--foreground); }
.thread-link {
  flex: 1; min-width: 0; padding: 8px 0; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-del {
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px;
  color: var(--muted-foreground); opacity: 0; transition: opacity .15s, background .15s, color .15s;
}
.thread-row:hover .thread-del { opacity: 1; }
.thread-del:hover { background: oklch(0.62 0.23 25 / 0.2); color: var(--destructive); }

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 16px; }
.status {
  display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted-foreground);
}
.status .dot {
  position: relative; width: 6px; height: 6px;
}
.status .dot::before, .status .dot::after {
  content: ""; position: absolute; inset: 0; border-radius: 999px; background: var(--primary);
}
.status .dot::before { opacity: .6; animation: evil-pulse 1.6s ease-in-out infinite; }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.header {
  display: flex; align-items: center; gap: 8px; padding: 12px;
  padding-top: max(env(safe-area-inset-top, 0px), 12px);
  background: oklch(0.185 0.014 264 / 0.8); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.menu-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; color: var(--muted-foreground); }
.menu-btn:hover { background: var(--surface-2); }
.mobile-mark {
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px;
  background: var(--surface-2); color: var(--primary);
}
.header-title { min-width: 0; flex: 1; }
.header-title .t {
  font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-title .s {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .16em; color: var(--muted-foreground);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.regen {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; color: var(--muted-foreground);
}
.regen:hover { background: var(--surface-2); }
.regen:disabled { opacity: .4; cursor: not-allowed; }

.scroll { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--surface-2) transparent; }
.container { max-width: 768px; margin: 0 auto; padding: 16px 12px; }
@media (min-width: 768px) { .container { padding: 24px; } }

/* ---------- Empty state ---------- */
.empty { min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 8px; }
.empty .mark {
  width: 64px; height: 64px; display: grid; place-items: center; border-radius: 16px;
  background: var(--surface-2); color: var(--primary); box-shadow: var(--glow-primary);
}
.empty h1 {
  margin: 20px 0 4px; font-size: 28px; font-weight: 900; letter-spacing: -.02em;
}
.empty h1 span {
  background: var(--gradient-evil); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.empty p { color: var(--muted-foreground); font-size: 14px; max-width: 28rem; margin: 0; }
.suggests { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 28px; max-width: 32rem; width: 100%; }
@media (min-width: 640px) { .suggests { grid-template-columns: 1fr 1fr; } }
.suggest {
  display: flex; align-items: center; gap: 12px; padding: 12px; text-align: left; font-size: 13.5px;
  border: 1px solid var(--border); border-radius: 12px; background: oklch(0.225 0.016 264 / 0.4);
  transition: border-color .15s, background .15s;
}
.suggest:hover { border-color: oklch(0.78 0.2 145 / 0.5); background: var(--surface-2); }
.suggest .ic {
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px;
  background: var(--background); color: var(--primary); flex-shrink: 0;
}
.suggest .lbl { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Messages ---------- */
.messages { display: flex; flex-direction: column; gap: 20px; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  max-width: 85%; padding: 10px 16px; border-radius: 16px; border-bottom-right-radius: 6px;
  background: var(--primary); color: var(--primary-foreground); font-size: 14.5px; line-height: 1.55;
  box-shadow: 0 10px 25px -12px rgba(0,0,0,.6); word-wrap: break-word; white-space: pre-wrap;
}
.msg-ai { display: flex; gap: 12px; }
.msg-ai .avatar {
  width: 32px; height: 32px; flex-shrink: 0; display: grid; place-items: center; border-radius: 8px;
  background: var(--surface-2); color: var(--primary);
}
.msg-ai .body { min-width: 0; flex: 1; }
.md { font-size: 14.5px; line-height: 1.65; color: var(--foreground); }
.md p { margin: 0 0 12px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; font-weight: 700; letter-spacing: -.01em; }
.md h1 { font-size: 22px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin-bottom: 4px; }
.md a { color: var(--primary); text-decoration: underline; }
.md blockquote {
  margin: 0 0 12px; padding: 8px 12px; border-left: 3px solid var(--primary);
  background: var(--surface); border-radius: 6px; color: var(--muted-foreground);
}
.md code:not(pre code) {
  font-family: var(--font-mono); font-size: 13px; padding: 1px 6px; border-radius: 6px;
  background: var(--surface-2); color: var(--primary);
}
.md table { border-collapse: collapse; width: 100%; margin: 0 0 12px; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface-2); }

/* code block */
.code-block {
  margin: 12px 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background: oklch(0.13 0.012 264);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 11px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .1em;
}
.code-copy {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 6px;
  color: var(--muted-foreground); font-size: 11px; text-transform: none; letter-spacing: 0;
}
.code-copy:hover { background: var(--surface-2); color: var(--foreground); }
.code-body { display: flex; overflow-x: auto; scrollbar-width: thin; }
.code-lines {
  padding: 12px 8px 12px 12px; text-align: right; user-select: none; color: oklch(0.5 0.02 264);
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; border-right: 1px solid var(--border);
  background: oklch(0.16 0.012 264);
}
.code-lines div { white-space: pre; }
.code-body pre {
  margin: 0; padding: 12px 14px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55;
  color: var(--foreground); flex: 1; min-width: 0; overflow: visible;
}
.code-body pre code { background: none; padding: 0; }

.msg-tools { margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 6px;
  font-size: 11px; color: var(--muted-foreground);
}
.tool-btn:hover { background: var(--surface-2); color: var(--foreground); }
.tool-btn .ok { color: var(--primary); }

.typing { display: flex; gap: 6px; padding-top: 8px; }
.typing span {
  width: 8px; height: 8px; border-radius: 999px; background: var(--primary); display: inline-block;
  animation: evil-pulse 1.1s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }

/* ---------- Composer ---------- */
.composer {
  border-top: 1px solid var(--border); background: oklch(0.185 0.014 264 / 0.8); backdrop-filter: blur(6px);
  padding: 12px 12px 0; padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (min-width: 768px) { .composer { padding-left: 24px; padding-right: 24px; } }
.composer-inner { max-width: 768px; margin: 0 auto; }
.input-box {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 16px; background: oklch(0.225 0.016 264 / 0.6);
  transition: border-color .15s, box-shadow .15s;
}
.input-box:focus-within { border-color: oklch(0.78 0.2 145 / 0.6); box-shadow: var(--glow-primary); }
.input-box textarea {
  flex: 1; min-width: 0; min-height: 36px; max-height: 200px; resize: none; background: transparent;
  border: 0; outline: none; padding: 6px 0; font-size: 15px; line-height: 24px; color: var(--foreground);
}
.input-box textarea::placeholder { color: oklch(0.68 0.015 264 / 0.7); }
.send, .stop {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
  box-shadow: 0 10px 25px -12px rgba(0,0,0,.6); transition: transform .1s;
}
.send { background: var(--primary); color: var(--primary-foreground); }
.send:disabled { opacity: .4; cursor: not-allowed; }
.send:not(:disabled):active { transform: scale(.95); }
.stop { background: var(--destructive); color: var(--destructive-foreground); }
.stop:active { transform: scale(.95); }
.legal {
  padding: 6px 4px 8px; text-align: center; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .15em; color: var(--muted-foreground);
}

@keyframes evil-pulse {
  0%, 100% { opacity: .35; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1); }
}
