.diagram-card {
  margin: var(--component-gap) 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--input-background);
}
.diagram-preview {
  height: auto;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 130px;
  padding: 16px;
  margin: 0;
  border-radius: 0;
  cursor: zoom-in;
}
.diagram-preview img {
  display: block;
  max-width: 100%;
  max-height: 360px;
  width: auto;
  height: auto;
}
.diagram-card figcaption {
  padding: 9px 12px;
  color: var(--muted-text);
  font-size: 12px;
  border-top: 1px solid var(--border);
}
.diagram-card > :is(details, p, .diagram-actions) {
  margin: 10px 12px;
}
.diagram-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--component-gap);
}
.diagram-card details {
  font-size: 12px;
  color: var(--muted-text);
}
.diagram-card summary {
  cursor: pointer;
}
.diagram-card pre {
  max-height: 280px;
  overflow: auto;
}
.diagram-card[data-diagram-state='error'] .diagram-preview {
  height: auto;
  display: none;
}
.diagram-card[data-diagram-state='error'] > p {
  color: var(--warning);
}
.diagram-render-frame {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 2048px;
  height: 2048px;
  visibility: hidden;
  border: 0;
  pointer-events: none;
}
#diagram-viewer {
  width: min(1200px, calc(100vw - 24px));
  height: min(900px, calc(100dvh - 24px));
  max-width: none;
  max-height: none;
  padding: 14px;
  color: var(--text);
  background: var(--card-background);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
#diagram-viewer[open] {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: var(--component-gap);
}
#diagram-viewer::backdrop {
  background: #000b;
}
#diagram-viewer:fullscreen,
#diagram-viewer.diagram-expanded {
  width: 100vw;
  height: 100dvh;
  border-radius: 0;
}
.diagram-open {
  overflow: hidden;
}
.diagram-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--component-gap);
}
#diagram-title {
  font-size: 17px;
  font-weight: 500;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.diagram-tools svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.diagram-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--component-gap);
}
.block-tools.diagram-tools {
  position: static;
  flex-shrink: 0;
}
.diagram-tools > button {
  width: 40px;
  height: var(--control-height);
  flex-basis: 40px;
}
.diagram-tools > .diagram-percent {
  width: 62px;
  flex-basis: 62px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.diagram-tools > .diagram-download {
  width: 62px;
  flex-basis: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
}
.diagram-body {
  position: relative;
  min-width: 0;
  min-height: 0;
}
.diagram-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.diagram-viewport.is-dragging {
  cursor: grabbing;
}
.diagram-viewport:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -3px;
}
.diagram-viewport img {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  max-height: none;
  transform-origin: 0 0;
  pointer-events: none;
  user-select: none;
  will-change: transform;
}
.diagram-source-text {
  height: 100%;
  resize: none;
  font:
    13px/1.5 ui-monospace,
    monospace;
  white-space: pre;
}
.diagram-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted-text);
}
@media (max-width: 600px) {
  #diagram-viewer {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding: 10px;
    border-radius: 0;
  }
  .diagram-controls {
    justify-content: center;
  }
  .diagram-preview img {
    max-height: 280px;
  }
}
