body {
  height: auto;
  min-height: 100vh;
  overflow-y: auto;
}

.creator-layout {
  width: min(1440px, calc(100% - 48px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: 26px;
  align-items: start;
}

.creator-panel {
  min-width: 0;
}

.page-wrap {
  padding: 34px 0 76px;
}

.page-title {
  color: var(--text);
  font-size: 24px;
  font-weight: 820;
  line-height: 1.2;
  margin-bottom: 20px;
}

.status-bar,
.tab-bar,
.section,
.chat-panel {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-panel);
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.status-bar label,
.field label {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 720;
}

.status-bar select,
.field input[type="text"],
.field input[type="url"],
.field textarea,
.field select,
.tag-input-row input,
.msg-block select,
.msg-block textarea,
.scenario-header input,
.chat-composer textarea {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition:
    border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    background 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.status-bar select {
  max-width: 180px;
  padding: 8px 11px;
  cursor: pointer;
}

.status-bar select option {
  background: var(--surface-1);
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  border-radius: var(--radius-md);
  padding: 5px;
  margin-bottom: 16px;
}

.tab-btn {
  width: 100%;
  min-height: 40px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 760;
  text-align: center;
  transition:
    background 180ms cubic-bezier(0.22, 1, 0.36, 1),
    color 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.tab-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tab-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.section {
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 14px;
}

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

.section-title {
  color: var(--blue);
  font-size: 12px;
  font-weight: 820;
  letter-spacing: 0;
  margin-bottom: 16px;
}

.field {
  margin-bottom: 14px;
}

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

.field label {
  display: block;
  margin-bottom: 7px;
}

.required-mark {
  color: var(--accent);
}

.field input[type="text"],
.field input[type="url"],
.field textarea,
.field select {
  padding: 11px 12px;
  font-size: 14px;
  line-height: 1.45;
  resize: vertical;
}

.field textarea {
  min-height: 104px;
}

.status-bar select:focus,
.field input[type="text"]:focus,
.field input[type="url"]:focus,
.field textarea:focus,
.field select:focus,
.tag-input-row input:focus,
.msg-block select:focus,
.msg-block textarea:focus,
.scenario-header input:focus,
.chat-composer textarea:focus {
  background: var(--field-focus);
  border-color: var(--accent);
}

.field input::placeholder,
.field textarea::placeholder,
.tag-input-row input::placeholder,
.scenario-header input::placeholder,
.chat-composer textarea::placeholder {
  color: var(--text-soft);
}

.profile-image-wrap {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 12px;
}

.image-preview-box {
  width: min(260px, 100%);
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--line-strong);
  background: var(--image-preview-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.image-preview-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.image-preview-box img.visible {
  display: block;
}

.preview-label {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 720;
  text-align: center;
  line-height: 1.5;
}

.image-url-input {
  font-size: 13px;
}

.chat-panel {
  position: sticky;
  top: 78px;
  height: calc(100svh - 102px);
  min-height: 620px;
  margin-top: 34px;
  border-radius: var(--radius-lg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 15px;
  border-bottom: 1px solid var(--line);
}

.chat-kicker {
  color: var(--blue);
  font-size: 11px;
  font-weight: 820;
  margin-bottom: 6px;
}

.chat-header h2 {
  color: var(--text);
  font-size: 18px;
  font-weight: 820;
  line-height: 1.2;
}

.chat-clear-btn,
.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 740;
  transition:
    background 180ms cubic-bezier(0.22, 1, 0.36, 1),
    border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    color 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.chat-clear-btn {
  padding: 7px 10px;
}

.chat-clear-btn:hover,
.btn-secondary:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface-3);
}

.chat-messages {
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
}

.chat-bubble {
  max-width: 88%;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  padding: 11px 13px;
  font-size: 14px;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
  border-bottom-right-radius: 5px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text);
  border-bottom-left-radius: 5px;
}

.chat-composer {
  border-top: 1px solid var(--line);
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.chat-composer textarea {
  min-height: 78px;
  max-height: 160px;
  resize: vertical;
  padding: 11px 12px;
  font-size: 14px;
  line-height: 1.45;
}

.chat-send-btn,
.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--accent-contrast);
  cursor: pointer;
  font-size: 14px;
  font-weight: 820;
  transition:
    background 180ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.chat-send-btn {
  min-width: 78px;
  height: 42px;
}

.chat-send-btn:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.chat-send-btn:disabled,
.btn-primary:disabled {
  background: var(--surface-3);
  color: var(--text-soft);
  cursor: not-allowed;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}

.tag-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--blue-soft);
  border: 1px solid color-mix(in oklch, var(--blue) 50%, var(--line));
  border-radius: 999px;
  color: var(--blue-text);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 720;
}

.tag-chip button,
.msg-block .remove-btn,
.scenario-header .remove-btn {
  background: transparent;
  border: none;
  color: var(--text-soft);
  cursor: pointer;
  line-height: 1;
}

.tag-chip button:hover,
.msg-block .remove-btn:hover,
.scenario-header .remove-btn:hover {
  color: var(--danger);
}

.tag-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.tag-input-row input {
  padding: 9px 11px;
  font-size: 13px;
}

.block-list,
.scenario-msg-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.block-list {
  margin-bottom: 12px;
}

.msg-block,
.scenario-block {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.msg-block {
  padding: 12px;
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: flex-start;
}

.msg-block select {
  padding: 8px 10px;
  font-size: 13px;
}

.msg-block textarea {
  min-height: 72px;
  padding: 9px 10px;
  font-size: 13px;
  resize: vertical;
}

.msg-block .remove-btn,
.scenario-header .remove-btn {
  font-size: 20px;
  padding: 5px 2px;
}

.scenario-block {
  padding: 14px;
}

.scenario-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.scenario-header input {
  padding: 9px 10px;
  font-size: 13px;
}

.scenario-msg-list {
  margin-bottom: 10px;
}

.add-btn {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
  padding: 9px 14px;
  transition:
    border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    color 180ms cubic-bezier(0.22, 1, 0.36, 1),
    background 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.add-btn:hover {
  background: var(--surface-2);
  border-color: var(--blue);
  color: var(--blue);
}

.submit-area {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.btn-primary,
.btn-secondary {
  min-height: 44px;
  padding: 0 24px;
}

#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(18px);
  background: var(--blue-soft);
  border: 1px solid color-mix(in oklch, var(--blue) 50%, var(--line));
  border-radius: var(--radius-md);
  color: var(--blue-text);
  font-size: 14px;
  line-height: 1.45;
  padding: 13px 20px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 220ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
  white-space: pre-line;
  max-width: min(420px, calc(100vw - 28px));
  text-align: center;
  z-index: 999;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.error {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

@media (max-width: 1080px) {
  .creator-layout {
    width: min(100% - 28px, 820px);
    grid-template-columns: 1fr;
    gap: 0;
  }

  .page-wrap {
    padding: 28px 0 20px;
  }

  .chat-panel {
    position: relative;
    top: auto;
    height: 620px;
    min-height: 0;
    margin: 0 0 40px;
  }
}

@media (max-width: 640px) {
  .creator-layout {
    width: min(100% - 20px, 820px);
  }

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

  .status-bar,
  .tag-input-row,
  .msg-block,
  .chat-composer {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .msg-block select {
    width: 100%;
  }

  .image-preview-box {
    width: 100%;
  }

  .chat-panel {
    height: 560px;
  }

  .submit-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
