:root {
  --bg-01: #0b1220;
  --bg-02: #111827;
  --bg-03: #1f2937;
  --accent: #7c3aed;
  --accent-hover: #8b5cf6;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --msg-user: #334155;
  --msg-ai: #1e40af;
  --border: #223047;
  --shadow: rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-01);
  color: var(--text);
  font: 14px/1.6 "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column;
}

.app-header {
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  background: var(--bg-01);
  position: sticky; top: 0; z-index: 10;
}

.title-wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.app-title { margin: 0; font-size: 18px; color: var(--accent); }

.menu { position: relative; }
.menu-btn {
  background: transparent; border: none; color: var(--text);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 4px 8px;
  border-radius: 10px;
}
.menu-btn:hover { background: #0e1627; }

.menu-dropdown {
  position: absolute; right: 0; top: 28px; min-width: 160px;
  background: var(--bg-02); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 12px 28px var(--shadow);
  padding: 6px; display: none;
}
.menu-dropdown.open { display: block; }
.menu-item {
  width: 100%; text-align: left; padding: 8px 10px;
  background: transparent; border: none; color: var(--text);
  border-radius: 10px; cursor: pointer;
}
.menu-item:hover { background: #151e2f; }

.chat-container {
  flex: 1; display: flex; flex-direction: column; max-width: 920px;
  width: 100%; margin: 0 auto; padding: 12px;
}

.chat-messages {
  flex: 1; overflow-y: auto; background: var(--bg-03);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 12px; box-shadow: 0 8px 24px var(--shadow);
}

.message {
  max-width: 76%; margin-bottom: 10px; padding: 8px 12px;
  border-radius: 12px; line-height: 1.5; word-wrap: break-word;
  white-space: pre-wrap;
}
.message.user { margin-left: auto; background: var(--msg-user); }
.message.ai { margin-right: auto; background: var(--msg-ai); }

.message a {
  color: #a5b4fc; text-decoration: underline; word-break: break-all;
}

/* code block */
.message pre {
  background: #0f172a; color: #f9fafb;
  border-radius: 12px; padding: 10px; overflow-x: auto;
  font: 13px/1.5 Consolas, Menlo, monospace; position: relative;
}
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--accent); color: #fff; border: none;
  border-radius: 8px; padding: 4px 8px; cursor: pointer; font-size: 12px;
}
.copy-btn:hover { background: var(--accent-hover); }

/* typing indicator */
.typing {
  display: none; align-items: center; gap: 8px;
  color: var(--text-dim); padding: 8px 4px;
}
.typing.show { display: flex; }
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim); display: inline-block; animation: blink 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 20% { opacity: 0.2; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
  100% { opacity: 0.2; transform: translateY(0); }
}
.typing-text { font-size: 12px; }

/* input area */
.message-input {
  display: flex; gap: 8px; padding: 12px; margin-top: 10px;
  background: var(--bg-02); border: 1px solid var(--border);
  border-radius: 16px;
}
#user-input {
  flex: 1; min-height: 40px; max-height: 160px; resize: vertical;
  background: #1b2334; color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px;
}
#user-input::placeholder { color: var(--text-dim); }
.send-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 12px; padding: 8px 14px; cursor: pointer;
  font-weight: 600;
}
.send-btn:hover { background: var(--accent-hover); }

/* modal system */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 20;
}
.modal-root {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 30;
}
.modal {
  width: min(520px, 94vw); background: var(--bg-02); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px; padding: 16px;
  box-shadow: 0 10px 36px var(--shadow);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 16px; color: var(--accent); margin: 0; }
.modal-close {
  background: transparent; border: none; color: var(--text); font-size: 18px;
  cursor: pointer; border-radius: 10px; padding: 2px 6px;
}
.modal-close:hover { background: #151e2f; }
.modal-body { margin-top: 10px; color: var(--text-dim); font-size: 14px; }
.modal-actions { margin-top: 12px; display: flex; gap: 8px; }
.btn {
  background: #1b2334; color: var(--text); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 12px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; border: none; }
.btn.primary:hover { background: var(--accent-hover); }
