:root {
  color-scheme: light;
  --bg: #f6f6f2;
  --surface: #ffffff;
  --surface-muted: #f1f3ef;
  --text: #171a17;
  --muted: #6f756f;
  --line: #d9ddd6;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --warning: #8b5e24;
  --danger: #9b3030;
  --shadow: 0 16px 44px rgba(20, 25, 20, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-shell {
  width: min(1360px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.15;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  min-width: 88px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.status-pill.busy {
  color: var(--warning);
}

.status-pill.ok {
  color: var(--accent);
}

.hero {
  padding: clamp(38px, 7vw, 82px) 0 18px;
}

.hero-kicker {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.hero h1 {
  margin: 10px 0 22px;
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1.08;
  text-align: center;
}

.composer-panel,
.selector-section,
.agent-debug-panel,
.flow-panel,
.timeline-panel,
.final-panel,
.history-drawer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.composer-panel {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 94, 0.12);
}

#problemInput {
  min-height: 168px;
  border: 0;
  padding: 10px;
  font-size: 19px;
  line-height: 1.65;
  resize: vertical;
}

.custom-prompt-field {
  margin-top: 12px;
}

.custom-prompt-field textarea,
#agentPromptInput,
#agentSystemPromptInput,
#skillPromptInput,
#skillStarterInput {
  min-height: 76px;
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

.controls-row {
  display: grid;
  grid-template-columns: 140px minmax(180px, 260px);
  align-items: end;
  gap: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.control-field {
  display: grid;
  gap: 6px;
}

.control-field span,
.toggle-field span,
.section-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 4px;
}

.toggle-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

#askButton,
.secondary-button {
  height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 800;
  white-space: nowrap;
}

#askButton {
  background: var(--accent);
  color: var(--accent-ink);
  width: 100%;
}

#askButton:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface-muted);
  color: var(--text);
}

.danger-button {
  color: var(--danger);
}

.selector-section,
.agent-debug-panel,
.run-section,
.history-drawer {
  margin-top: 18px;
}

.selector-section {
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.agent-list,
.history-list,
.skill-list {
  display: grid;
  gap: 10px;
}

.agent-list {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.skill-list {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.skill-list.compact {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.agent-item,
.history-item,
.skill-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  text-align: left;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease;
}

.agent-item:hover,
.skill-item:hover,
.history-item:hover {
  border-color: rgba(47, 111, 94, 0.55);
  transform: translateY(-1px);
}

.agent-item.selected,
.skill-item.selected {
  border-color: var(--accent);
  background: #eef5f1;
}

.agent-item.focused,
.skill-item.focused {
  box-shadow: inset 3px 0 0 var(--accent);
}

.agent-item.tuned .agent-name::after {
  content: " 调试";
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.agent-name,
.history-title,
.skill-name {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-desc,
.history-meta,
.agent-meta,
.skill-category {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.42;
}

.agent-meta,
.skill-category {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: #fbfbf8;
}

.agent-debug-panel {
  padding: 16px;
}

.hidden {
  display: none !important;
}

.debug-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.debug-head h2 {
  margin: 4px 0 0;
  font-size: 20px;
  line-height: 1.3;
}

.debug-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.debug-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 140px;
  gap: 12px;
  margin-top: 14px;
}

.editor-grid {
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.55fr);
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.debug-wide {
  grid-column: 1 / -1;
}

.agent-skill-editor {
  margin-top: 14px;
}

.run-section {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.1fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.run-meta {
  font-weight: 600;
}

.flow-list,
.answer,
.turns-list {
  min-height: 300px;
  max-height: calc(100vh - 260px);
  overflow: auto;
  padding: 16px;
  line-height: 1.65;
}

.answer,
.turn-content {
  white-space: pre-wrap;
}

.empty-state {
  color: var(--muted);
}

.flow-step {
  position: relative;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 0;
}

.flow-step::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 38px;
  bottom: -10px;
  width: 1px;
  background: var(--line);
}

.flow-step:last-child::before {
  display: none;
}

.flow-dot {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.flow-step.running .flow-dot {
  border-color: var(--accent);
  background: #eef5f1;
  color: var(--accent);
  animation: pulse 1.2s infinite;
}

.flow-step.done .flow-dot {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.flow-step.failed .flow-dot {
  border-color: var(--danger);
  color: var(--danger);
}

.flow-title {
  font-size: 14px;
  font-weight: 800;
}

.flow-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(47, 111, 94, 0.24);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(47, 111, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(47, 111, 94, 0);
  }
}

.turn {
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
}

.turn:first-child {
  padding-top: 0;
}

.turn:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.turn-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.turn-agent {
  font-size: 14px;
  font-weight: 850;
}

.turn-phase {
  color: var(--muted);
  font-size: 12px;
}

.turn-content {
  color: #262a26;
  font-size: 14px;
  line-height: 1.7;
}

.history-drawer {
  padding: 0;
}

.history-drawer summary {
  cursor: pointer;
  padding: 14px 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.history-list {
  border-top: 1px solid var(--line);
  padding: 12px 16px 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

@media (max-width: 1120px) {
  .controls-row,
  .run-section {
    grid-template-columns: 1fr;
  }

  .flow-list,
  .answer,
  .turns-list {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 24px, 1360px);
    padding-top: 14px;
  }

  .topbar,
  .debug-head,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .section-actions {
    justify-content: flex-start;
  }

  .hero {
    padding-top: 34px;
  }

  #problemInput {
    min-height: 140px;
    font-size: 16px;
  }

  .agent-list,
  .skill-list,
  .debug-grid {
    grid-template-columns: 1fr;
  }
}
