:root {
  --bg: #0f1115;
  --surface: #171a21;
  --line: #262b35;
  --tx: #e8eaed;
  --tx-2: #a9b0bb;
  --tx-3: #737b88;
  --accent: #3c83f5;
  --live: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--tx);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand { display: flex; align-items: center; gap: 8px; }
.name { font-weight: 700; letter-spacing: 0.02em; }
.badge {
  font-size: 11px;
  color: var(--tx-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--tx-3);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.03);
}
.dot.on { background: var(--live); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.status { font-size: 12px; color: var(--tx-3); }

main {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.turn {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.turn .who {
  display: block;
  font-size: 11px;
  color: var(--tx-3);
  margin-bottom: 3px;
  letter-spacing: 0.02em;
}
.turn.them {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
}
.turn.you, .turn.question {
  align-self: flex-end;
  background: rgba(60, 131, 245, 0.18);
  border: 1px solid rgba(60, 131, 245, 0.35);
}
.turn.action {
  align-self: flex-end;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--tx-3);
  font-size: 13px;
}
.turn.dan {
  align-self: stretch;
  max-width: 100%;
  background: rgba(34, 197, 94, 0.07);
  border: 1px solid rgba(34, 197, 94, 0.22);
}
.turn.dan .who { color: rgba(134, 239, 172, 0.75); }
.turn.dan .body { white-space: pre-wrap; word-break: break-word; }
.turn.dan pre {
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: hidden;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.turn.dan code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.94em;
  overflow-wrap: anywhere;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  padding: 1px 4px;
}
.turn.dan pre code { white-space: inherit; background: none; padding: 0; }
.turn.dan strong { color: #fff; }

.answer {
  align-self: stretch;
  background: rgba(34, 197, 94, 0.07);
  border: 1px solid rgba(34, 197, 94, 0.22);
  border-radius: 12px;
  padding: 9px 12px;
}
.answer .who {
  display: block;
  font-size: 11px;
  color: rgba(134, 239, 172, 0.75);
  margin-bottom: 3px;
}
.answer .body { white-space: pre-wrap; word-break: break-word; }
.answer .thinking { color: var(--tx-2); font-style: italic; }
.answer .caret {
  display: inline-block;
  width: 7px; height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--live);
  opacity: 0.6;
  animation: blink 1s steps(2, start) infinite;
}
.answer.error { border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); }
.answer.error .body { color: #fca5a5; }

.answer pre {
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: hidden;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.answer code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.94em;
  overflow-wrap: anywhere;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  padding: 1px 4px;
}
.answer pre code { white-space: inherit; background: none; padding: 0; }
.answer strong { color: #fff; }

.notice {
  align-self: center;
  color: var(--tx-3);
  font-size: 13px;
  padding: 6px 10px;
  text-align: center;
}
.notice.bad { color: #fca5a5; }

footer {
  flex: 0 0 auto;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--tx-3);
  font-size: 12px;
  text-align: center;
}

@keyframes blink { 50% { opacity: 0.1; } }
