:root {
  --bg: #0b0d0b;
  --panel: #101410;
  --panel-2: #0f130f;
  --text: #e6f3e6;
  --muted: #a9c9a9;
  --accent: #76ff7a;
  --accent-dim: rgba(118, 255, 122, 0.18);
  --border: rgba(118, 255, 122, 0.28);
  --user-bg: #141a14;
  --ai-bg: #0f1510;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, #0d120d 0%, #0b0d0b 100%);
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.title {
  grid-column: 2 / 3;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
  font-size: 20px;
}

.top-actions {
  grid-column: 3 / 4;
  justify-self: end;
  font-size: 14px;
  opacity: 0.9;
}

.chat-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 140px; /* leave room for inputbar */
  display: flex;
  flex-direction: column;
  align-items: center;
}

.notice {
  width: 100%;
  max-width: 980px;
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 10px;
  padding: 0 6px;
}

.chat {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* message rows produced by app.js are .msg-row.user / .msg-row.ai */
.msg-row {
  display: flex;
  align-items: flex-start;
}

.msg-row.user { justify-content: flex-end; }
.msg-row.ai { justify-content: flex-start; }

/* backward-compat (old markup) */
.msg { display: flex; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.msg.ai { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3) inset;
}

.msg-row.user .bubble,
.msg.user .bubble {
  background: var(--user-bg);
  border-color: rgba(118, 255, 122, 0.35);
  border-top-right-radius: 6px;
}

.msg-row.ai .bubble,
.msg.ai .bubble {
  background: var(--ai-bg);
  border-top-left-radius: 6px;
}

.role {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.6px;
}

.content {
  font-size: 15px;
  line-height: 1.7;
  word-wrap: break-word;
  white-space: normal;
}

.content p {
  margin: 0 0 8px 0;
}
.content p:last-child { margin-bottom: 0; }

.inputbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(11, 13, 11, 0.98);
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#input {
  width: min(980px, 100%);
  margin: 0 auto;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  min-height: 48px;
  max-height: 140px;
  box-shadow: 0 0 0 2px transparent;
}
#input:focus {
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.input-actions {
  width: min(980px, 100%);
  margin: 0 auto;
  display: flex;
  justify-content: flex-end; /* bottom right */
  gap: 8px;
}

button {
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}
button:hover { filter: brightness(1.1); }

button.primary {
  background: var(--accent);
  color: #0a120a;
  font-weight: 700;
  border-color: rgba(0,0,0,0.2);
}

button.ghost {
  background: transparent;
  color: var(--text);
}

@media (max-width: 640px) {
  .bubble { max-width: 92%; }
  .title { font-size: 18px; }
  .content { font-size: 14px; }
  .input-actions { flex-wrap: wrap; justify-content: flex-end; }
}