:root {
  --bg: #0c0d10;
  --bg-raised: #13141a;
  --border: #23252e;
  --text: #e8e9ef;
  --muted: #8b8f9c;
  --accent: #5b8cff;
  --accent-dim: #3a59a8;
  --user-bubble: #1a1f2e;
  --assistant: #0f131c;
  --error: #ff6b6b;
  --radius: 12px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

body {
  background: radial-gradient(
      1200px 600px at 10% 0%,
      rgba(91, 140, 255, 0.12),
      transparent
    ),
    var(--bg);
}

.app {
  min-height: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.brand h1 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}

.sub {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  background: linear-gradient(145deg, #2a2f3d, #14161d);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 1.1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
}

.badge.ok {
  color: #7dffb0;
  border-color: #2a4a3a;
}

.badge.err {
  color: var(--error);
  border-color: #4a2a2a;
}

.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.45rem 0.9rem;
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #1a1b22;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #fff;
}

.btn.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 0.75rem;
}

.log {
  flex: 1;
  min-height: 220px;
  max-height: min(60vh, 640px);
  overflow-y: auto;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  scroll-behavior: smooth;
}

.msg {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.msg:last-child {
  margin-bottom: 0;
}

.msg-role {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.msg-bubble {
  white-space: pre-wrap;
  word-break: break-word;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.msg.user .msg-bubble {
  background: var(--user-bubble);
  align-self: flex-end;
  max-width: 92%;
}

.msg.assistant .msg-bubble {
  background: var(--assistant);
  max-width: 100%;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  background: var(--bg-raised);
}

#input {
  width: 100%;
  min-height: 2.5rem;
  max-height: 12rem;
  resize: vertical;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  outline: none;
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.typing {
  color: var(--muted);
  font-size: 0.85rem;
}

.error-box {
  color: var(--error);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 2rem 0.5rem;
}

.assistant-block {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 100%;
}

.trace-wrap {
  border: 1px solid #2a3040;
  border-radius: 10px;
  background: #0a0b0f;
  padding: 0.55rem 0.65rem 0.65rem;
  max-height: 320px;
  overflow-y: auto;
}

.trace-head {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #9aa3b2;
  margin-bottom: 0.35rem;
}

.trace-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.trace-item {
  border-left: 2px solid var(--accent);
  padding: 0.35rem 0 0.2rem 0.55rem;
}

.trace-item-meta {
  font-size: 0.78rem;
  color: #b8c0d4;
  font-weight: 500;
  margin-bottom: 0.2rem;
}

.trace-pre {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  padding: 0.45rem 0.5rem;
  max-height: 180px;
  overflow-y: auto;
}

.answer-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #9aa3b2;
}

.msg.assistant .msg-bubble.answer {
  border-color: #2e3544;
  background: linear-gradient(180deg, #10131c, #0c0e14);
}

/* Markdown (답변) */
.md-content {
  min-height: 0.5rem;
}
.md-content :first-child {
  margin-top: 0;
}
.md-content :last-child {
  margin-bottom: 0;
}
.md-content p {
  margin: 0.5rem 0;
}
.md-content h1,
.md-content h2,
.md-content h3,
.md-content h4 {
  margin: 0.9rem 0 0.45rem;
  line-height: 1.3;
  font-weight: 600;
  color: #f0f2f6;
  letter-spacing: -0.02em;
}
.md-content h1 {
  font-size: 1.25rem;
}
.md-content h2 {
  font-size: 1.1rem;
}
.md-content h3,
.md-content h4 {
  font-size: 1rem;
}
.md-content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-dim);
}
.md-content a:hover {
  border-bottom-color: var(--accent);
}
.md-content ul,
.md-content ol {
  margin: 0.45rem 0;
  padding-left: 1.25rem;
}
.md-content li {
  margin: 0.2rem 0;
}
.md-content blockquote {
  margin: 0.6rem 0;
  padding: 0.4rem 0 0.4rem 0.9rem;
  border-left: 3px solid var(--accent-dim);
  color: #b4bac8;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0 6px 6px 0;
}
.md-content pre {
  margin: 0.55rem 0;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: #07080c;
  border: 1px solid var(--border);
  overflow-x: auto;
  line-height: 1.45;
  font-size: 0.85rem;
}
.md-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}
.md-content :not(pre) > code {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 0.88em;
  background: #1a1d28;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  border: 1px solid #2a2f3d;
  color: #d8dce8;
}
.md-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0.6rem 0;
}
.md-content th,
.md-content td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
  text-align: left;
}
.md-content th {
  background: #12151d;
  font-weight: 600;
}
.md-content tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.12);
}
.md-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8rem 0;
}
.md-content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.md-fallback,
.md-fallback code {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}
