main:has(.svugy-playground) {
  max-width: min(1100px, calc(100% - 160px));
}

/* side by side: the source on the left, the diagram it renders on the right */
.svugy-playground {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 16px;
  align-items: stretch;
  margin: 1em 0;
}

.svugy-preview {
  display: grid;
  min-height: 280px;
}

.svugy-preview > object {
  grid-area: 1 / 1;
  align-self: center;
}

.svugy-editor {
  position: relative;
  min-height: 280px;
  border-radius: 14px;
  background: var(--quote-bg);
  overflow: hidden;
}

@media (max-width: 900px) {
  .svugy-playground {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* opt-in with data-svugy-curtain: the diagram fills the playground; the source is a curtain over its left part, as wide as --svugy-curtain */
[data-svugy-curtain] .svugy-playground {
  --svugy-curtain: 0%;
  display: block;
  position: relative;
}

[data-svugy-curtain] .svugy-editor {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  width: var(--svugy-curtain);
  min-height: 0;
  border-radius: 14px 0 0 14px;
}

.svugy-curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  left: clamp(0px, calc(var(--svugy-curtain) - 8px), calc(100% - 16px));
  z-index: 2;
  width: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: col-resize;
  touch-action: none;
  outline: none;
}

.svugy-curtain::before {
  content: "";
  width: 4px;
  height: 48px;
  border-radius: 2px;
  background: #5b6170;
}

.svugy-curtain:hover::before,
.svugy-curtain:focus-visible::before,
.svugy-playground[data-svugy-curtain-moving] .svugy-curtain::before {
  background: #3478f6;
}

/* the diagram's own document would swallow the drag */
.svugy-playground[data-svugy-curtain-moving] {
  user-select: none;
}
.svugy-playground[data-svugy-curtain-moving] object {
  pointer-events: none;
}

/* phones stack the source above the diagram */
@media (max-width: 900px) {
  [data-svugy-curtain] .svugy-playground {
    display: grid;
    gap: 16px;
  }

  [data-svugy-curtain] .svugy-editor {
    position: relative;
    width: auto;
    min-height: 280px;
    border-radius: 14px;
  }

  .svugy-curtain {
    display: none;
  }
}

.svugy-editor textarea,
.svugy-editor .svugy-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 14px 16px;
  border: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  font-family: var(--mono-font, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 13px;
  line-height: 1.5;
  tab-size: 2;
  /* both layers wrap at the curtain's edge, the same way, so the caret stays on its highlighted text */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.svugy-editor .svugy-highlight {
  pointer-events: none;
  color: var(--fg);
  background: transparent;
}

.svugy-editor .svugy-highlight code {
  font: inherit;
  white-space: inherit;
  padding: 0;
  background: none;
}

.svugy-editor textarea {
  resize: none;
  color: transparent;
  background: transparent;
  caret-color: var(--fg);
  outline: none;
}

.svugy-editor textarea::selection {
  background: rgba(120, 160, 255, 0.35);
}

.svugy-preview object.svugy {
  margin: 0;
}

.svugy-token-comment { color: #7d8799; font-style: italic; }
.svugy-token-string { color: #7fd17f; }
.svugy-token-keyword { color: #c792ea; }
.svugy-token-key { color: #82aaff; }
.svugy-token-number { color: #f78c6c; }
.svugy-token-arrow { color: #ffcb6b; font-weight: bold; }
.svugy-token-punctuation { color: #89a0b8; }

.svugy-diagnostics {
  list-style: none;
  padding: 0;
  margin: 0 0 1em;
  font-family: var(--mono-font, ui-monospace, monospace);
  font-size: 12.5px;
}

.svugy-diagnostics li {
  padding: 4px 8px;
  border-left: 3px solid transparent;
}

.svugy-diagnostics li[data-line] {
  cursor: pointer;
}

.svugy-diagnostics .svugy-diagnostic-error { border-color: #ff5370; }
.svugy-diagnostics .svugy-diagnostic-warning { border-color: #ffcb6b; }
.svugy-diagnostics .svugy-diagnostic-status { color: #7d8799; }
