:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232735;
  --border: #2e3345;
  --text: #e8eaef;
  --text-muted: #9aa3b8;
  --accent: #5b8def;
  --accent-dim: #3d5a9e;
  --thought: #a78bfa;
  --action: #f59e0b;
  --observation: #34d399;
  --answer: #60a5fa;
  --warn: #f87171;
  --ok: #4ade80;
  --radius: 10px;
  --font: 'Noto Sans SC', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Consolas', monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

#root {
  min-height: 100vh;
}

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

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

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

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: -0.5px;
}

.header-brand h1 {
  font-size: 1.15rem;
  font-weight: 600;
}

.header-brand p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.api-key-box {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 280px;
  flex: 1;
  max-width: 420px;
}

.api-key-box label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.api-key-box input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.api-key-box input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Layout */
.main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 960px) {
  .main {
    grid-template-columns: 1fr;
  }
}

/* Concept panel */
.concept-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: sticky;
  top: 90px;
}

.concept-panel h2 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.concept-panel h3 {
  font-size: 0.9rem;
  margin: 1.25rem 0 0.5rem;
  color: var(--text-muted);
}

.concept-lead {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.react-flow {
  margin: 1rem 0;
}

.flow-step {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  font-size: 0.85rem;
}

.flow-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
}

.flow-step strong {
  display: block;
  font-size: 0.85rem;
}

.flow-step p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.flow-arrow {
  text-align: left;
  padding-left: 0.5rem;
  color: var(--border);
  font-size: 0.9rem;
  line-height: 1.2;
}

.tool-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tool-list li {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.8rem;
}

.tool-list code {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--action);
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  width: fit-content;
}

.tool-list span {
  color: var(--text-muted);
  padding-left: 0.25rem;
}

/* Workspace */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.control-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.control-panel h2 {
  font-size: 1rem;
  margin-bottom: 1rem;
}

.label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.5rem;
}

.preset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.preset-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font);
}

.preset-btn:hover {
  border-color: var(--accent-dim);
}

.preset-btn.active {
  border-color: var(--accent);
  background: rgba(91, 141, 239, 0.12);
}

.preset-btn .tag {
  font-size: 0.65rem;
  background: rgba(245, 158, 11, 0.2);
  color: var(--action);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.question-input {
  margin-bottom: 1rem;
}

.question-input label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.35rem;
}

.question-input textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  resize: vertical;
}

.question-input textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.control-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.run-btn {
  background: linear-gradient(135deg, var(--accent), #7c6df0);
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.5rem;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s;
}

.run-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.run-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error-banner {
  margin-top: 1rem;
  padding: 0.65rem 1rem;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 8px;
  color: var(--warn);
  font-size: 0.85rem;
}

/* Compare section */
.compare-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.compare-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.summary-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  font-size: 0.85rem;
}

.summary-card strong {
  display: block;
  font-size: 0.9rem;
}

.summary-card p {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 0.1rem;
}

.summary-icon {
  font-size: 1.4rem;
}

.summary-plain {
  justify-content: flex-end;
  text-align: right;
}

.summary-react {
  justify-content: flex-start;
}

.summary-vs {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  background: var(--surface-2);
  border-radius: 6px;
}

.verdict-banner {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.75rem 1rem;
  background: rgba(91, 141, 239, 0.1);
  border: 1px solid rgba(91, 141, 239, 0.25);
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.65;
}

.verdict-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.compare-answer-snippet {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--border);
}

.snippet-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: block;
  margin-bottom: 0.4rem;
}

.compare-answer-snippet pre {
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
}

.snippet-ok pre {
  color: var(--text);
}

/* ReAct chain */
.react-chain,
.plain-chain {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.chain-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.chain-empty-formula {
  margin-top: 0.35rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
}

.chain-round {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.chain-round-badge {
  align-self: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(91, 141, 239, 0.12);
  border: 1px solid rgba(91, 141, 239, 0.25);
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}

.chain-round-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chain-arrow {
  text-align: center;
  color: var(--border);
  font-size: 1rem;
  line-height: 1;
  padding: 0.35rem 0;
}

.chain-mini-arrow {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.chain-node {
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.chain-node-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
}

.chain-node-icon {
  font-size: 0.95rem;
}

.chain-node-body,
.chain-node-meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.65;
  padding: 0.65rem 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
  margin: 0;
}

.chain-node-meta {
  border-top: 1px solid var(--border);
  color: var(--action);
}

.chain-node-input .chain-node-head {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-muted);
}

.chain-node-thought .chain-node-head {
  background: rgba(167, 139, 250, 0.15);
  color: var(--thought);
}

.chain-node-action .chain-node-head {
  background: rgba(245, 158, 11, 0.15);
  color: var(--action);
}

.chain-node-observation .chain-node-head {
  background: rgba(52, 211, 153, 0.15);
  color: var(--observation);
}

.chain-node-answer .chain-node-head {
  background: rgba(96, 165, 250, 0.15);
  color: var(--answer);
}

.chain-node-plain .chain-node-head {
  background: rgba(248, 113, 113, 0.12);
  color: var(--warn);
}

.chain-node-answer-warn .chain-node-head {
  background: rgba(248, 113, 113, 0.15);
  color: var(--warn);
}

.chain-node-pending .chain-node-head {
  background: rgba(52, 211, 153, 0.08);
  color: var(--observation);
  opacity: 0.85;
}

.chain-loading {
  text-align: center;
  padding: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 720px) {
  .compare-grid {
    grid-template-columns: 1fr;
  }
}

.compare-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
}

.compare-without {
  border-top: 3px solid var(--warn);
}

.compare-with {
  border-top: 3px solid var(--ok);
}

.compare-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.compare-header h3 {
  font-size: 0.95rem;
}

.compare-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
}

.badge-warn {
  background: rgba(248, 113, 113, 0.15);
  color: var(--warn);
}

.badge-ok {
  background: rgba(74, 222, 128, 0.15);
  color: var(--ok);
}

.compare-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.compare-result {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  min-height: 100px;
}

.compare-result pre {
  font-family: var(--font);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
}

.compare-result .placeholder,
.compare-result .loading-text {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Timeline */
.timeline-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.timeline-panel h3 {
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

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

.timeline {
  display: flex;
  flex-direction: column;
}

.timeline-item {
  display: flex;
  gap: 1rem;
}

.timeline-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 32px;
  flex-shrink: 0;
}

.timeline-icon {
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.25rem 0;
}

.timeline-line {
  flex: 1;
  width: 2px;
  background: var(--border);
  min-height: 16px;
  margin: 4px 0;
}

.timeline-body {
  flex: 1;
  padding-bottom: 1.25rem;
}

.timeline-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.timeline-type {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.step-thought .timeline-type {
  background: rgba(167, 139, 250, 0.15);
  color: var(--thought);
}

.step-action .timeline-type {
  background: rgba(245, 158, 11, 0.15);
  color: var(--action);
}

.step-observation .timeline-type {
  background: rgba(52, 211, 153, 0.15);
  color: var(--observation);
}

.step-answer .timeline-type {
  background: rgba(96, 165, 250, 0.15);
  color: var(--answer);
}

.timeline-title {
  font-size: 0.85rem;
  font-weight: 500;
}

.timeline-content,
.timeline-meta {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  color: var(--text);
}

.timeline-meta {
  margin-top: 0.4rem;
  color: var(--action);
  border-color: rgba(245, 158, 11, 0.2);
}

.pulse {
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  text-align: center;
}

.footer p {
  font-size: 0.75rem;
  color: var(--text-muted);
}
