:root {
  --ink: #171321;
  --muted: #665f75;
  --line: #ebe7f4;
  --paper: #ffffff;
  --soft: #fff8ef;
  --pink: #ff4f8b;
  --orange: #ff9f1c;
  --cyan: #00bcd4;
  --green: #28c76f;
  --violet: #7c3aed;
  --shadow: 0 18px 60px rgba(42, 24, 84, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 79, 139, 0.12), transparent 30%),
    linear-gradient(225deg, rgba(0, 188, 212, 0.16), transparent 34%),
    #fffdf8;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--orange));
  border-radius: 8px;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

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

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.toolbar button,
.chat-form button {
  padding: 0 14px;
}

.toolbar button:first-child,
.chat-form button {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--orange));
  border-color: transparent;
}

.studio-shell {
  display: grid;
  grid-template-columns: 180px minmax(280px, 1fr) minmax(330px, 0.95fr);
  grid-template-rows: minmax(340px, 1fr) minmax(260px, 0.72fr);
  gap: 14px;
  height: calc(100svh - 68px);
  padding: 14px;
}

.panel {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.panel h2 {
  margin: 0;
  font-size: 16px;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.palette-panel {
  grid-row: 1 / span 2;
  padding-bottom: 10px;
}

.block {
  display: block;
  width: calc(100% - 20px);
  min-height: 46px;
  margin: 10px;
  color: #fff;
  border: 0;
  text-align: left;
  padding: 0 14px;
  box-shadow: 0 10px 20px rgba(42, 24, 84, 0.13);
}

.block-agent {
  background: var(--violet);
}

.block-discover {
  background: var(--cyan);
}

.block-build {
  background: var(--pink);
}

.block-verify {
  background: var(--green);
}

.block-publish {
  background: var(--orange);
}

.block-custom {
  color: var(--ink);
  background: #ffe66d;
}

.canvas {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: calc(100% - 48px);
  padding: 14px;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
}

.task-card {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
}

.task-color {
  width: 10px;
  min-height: 100%;
  border-radius: 999px;
  background: var(--pink);
}

.task-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.task-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.task-card button {
  width: 34px;
  min-height: 34px;
}

.editor-panel textarea,
.chat-form textarea {
  width: 100%;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.editor-panel textarea {
  height: calc(100% - 48px);
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.62;
}

.chat-panel,
.ir-panel {
  display: grid;
  grid-template-rows: 48px 1fr auto;
}

.chat-log {
  overflow: auto;
  padding: 12px;
}

.message {
  max-width: 92%;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--ink);
  background: #f4f0ff;
  font-size: 14px;
  line-height: 1.45;
}

.message.user {
  margin-left: auto;
  color: #fff;
  background: var(--violet);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.chat-form textarea {
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ir-panel {
  grid-column: 2 / span 2;
}

#ir {
  overflow: auto;
  margin: 0;
  padding: 14px;
  color: #f7f5ff;
  background: #171321;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 980px) {
  .studio-shell {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }

  .palette-panel,
  .ir-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .palette-panel {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .palette-panel .panel-head {
    grid-column: 1 / -1;
  }

  .editor-panel textarea,
  .canvas,
  #ir {
    min-height: 320px;
  }
}

@media (max-width: 640px) {
  .topbar,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .palette-panel {
    grid-template-columns: 1fr;
  }
}

