:root {
  --node-width: 300px;
}

body {
  height: 100dvh;
  min-height: 600px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.document-title {
  width: auto;
  min-width: 0;
  max-width: 300px;
  padding: .25rem 0;
  border: 0;
  border-bottom: 1px solid var(--bs-border-color);
  border-radius: 0;
  background: transparent;
  color: inherit;
}

.document-title[readonly] {
  pointer-events: none;
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-title:focus {
  outline: none;
  box-shadow: none;
  border-bottom-color: var(--bs-primary);
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(300px, 1fr);
  flex: 1;
  min-height: 0;
}

.editor-layout.inspector-open {
  grid-template-columns: minmax(300px, 1fr) 350px;
}

#app-menu {
  top: calc(100% + .5rem);
  right: 0;
  left: auto;
  min-width: 14rem;
  max-height: calc(100dvh - 100px);
  overflow-y: auto;
}

#validation-panel {
  position: absolute;
  z-index: 4;
  top: 5rem;
  left: 1rem;
  width: min(320px, calc(100% - 1rem));
  max-height: calc(100% - 10rem);
  overflow-y: auto;
}

.optional-field>summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding: .75rem 0;
  cursor: pointer;
  list-style: none;
}

.optional-field>summary::-webkit-details-marker {
  display: none;
}

.optional-field>summary::after {
  content: '';
  width: .5rem;
  height: .5rem;
  flex-shrink: 0;
  margin-right: .25rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.optional-field[open]>summary::after {
  transform: rotate(225deg);
}

.info-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  padding: 0;
  font-size: .875rem;
  font-weight: 600;
  line-height: 1;
}

.icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.icon-action:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.help-tooltip {
  position: fixed;
  z-index: 2000;
  width: max-content;
  max-width: calc(100vw - 1rem);
  pointer-events: auto;
}

.help-tooltip .tooltip-inner {
  max-width: min(22rem, calc(100vw - 1rem));
  text-align: left;
}

.inspector {
  overflow-y: auto;
}

.diagram-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#connection-status {
  position: absolute;
  top: 7.5rem;
  left: .5rem;
  right: .5rem;
  z-index: 3;
  pointer-events: none;
}

#viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  background-color: #f8f9fa;
  background-image: radial-gradient(#ced4da 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: grab;
}

#viewport:focus-visible {
  outline: 3px solid #0d6efd;
  outline-offset: -3px;
}

#world {
  position: absolute;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
}

#connections {
  position: absolute;
  inset: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  color: #6c757d;
}

.edge {
  pointer-events: stroke;
  cursor: pointer;
}

.edge-line {
  stroke: #6c757d;
  stroke-width: 2;
  fill: none;
}

.edge-hit {
  stroke: transparent;
  stroke-width: 18;
  fill: none;
}

.edge.selected .edge-line {
  stroke: #0d6efd;
  stroke-width: 4;
}

.diagram-node {
  position: absolute;
  width: var(--node-width);
  user-select: none;
  cursor: default;
  box-shadow: 0 2px 6px #00000012;
}

.diagram-node.is-dimmed,
.edge.is-dimmed {
  opacity: .5;
}

.diagram-node.selected {
  outline: 3px solid #0d6efd;
  outline-offset: 2px;
}

.diagram-node.drop-target {
  outline: 3px dashed #0d6efd;
  outline-offset: 4px;
}

.diagram-node.has-error {
  border-color: #dc3545;
}

.node-head {
  cursor: move;
  touch-action: none;
}

.node-title {
  font-weight: 600;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.node-choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: .5rem;
  height: 58px;
  padding: .5rem .75rem;
  border-top: 1px solid #dee2e6;
  font-size: .875rem;
}

.node-choice-label {
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.output-port {
  position: relative;
  width: 18px;
  height: 18px;
  min-width: 18px;
  border: 2px solid #0d6efd;
  background: #fff;
  border-radius: 50%;
  padding: 0;
  cursor: crosshair;
  touch-action: none;
}

.output-port.connected {
  background: #0d6efd;
}

.output-port.connected:is(:hover, :focus-visible) {
  background: #dc3545;
  border-color: #dc3545;
  cursor: pointer;
}

.output-port.connected:is(:hover, :focus-visible)::before,
.output-port.connected:is(:hover, :focus-visible)::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  border-top: 2px solid #fff;
  transform: translate(-50%, -50%) rotate(45deg);
}

.output-port.connected:is(:hover, :focus-visible)::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.output-port:focus-visible {
  outline: 3px solid #9ec5fe;
}

.node-target {
  position: absolute;
  top: 20px;
  left: -9px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #6c757d;
  background: #fff;
}

.choice-editor.dragging {
  opacity: .45;
}

.choice-editor.drag-over {
  outline: 2px dashed #0d6efd;
}

.app-dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: 90dvh;
  padding: 0;
}

.app-dialog::backdrop {
  background: #0008;
}

#preview-dialog {
  height: min(48rem, 90dvh);
}

.preserve-line-breaks {
  white-space: pre-line;
}

.preview-choice {
  flex: 1 0 12rem;
  min-height: 180px;
}

.preview-choice:hover {
  background-color: var(--bs-tertiary-bg);
}

.preview-choice img {
  width: 3rem;
  height: 3rem;
  object-fit: contain;
}

#notice {
  z-index: 1100;
  max-width: min(650px, 90vw);
}

[hidden] {
  display: none !important;
}

@media (max-width: 1150px) {
  .editor-layout.inspector-open {
    grid-template-columns: minmax(280px, 1fr) 300px;
  }
}

@media (max-width: 850px) {
  body {
    height: auto;
    overflow: auto;
  }

  .editor-layout,
  .editor-layout.inspector-open {
    grid-template-columns: minmax(280px, 1fr);
  }

  #viewport {
    min-height: 520px;
  }

  .inspector {
    max-height: none;
    border-top: 1px solid #dee2e6;
  }
}
