.graph-block {
  width: 100%;
  min-width: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
  border-radius: 6px;
  background: transparent;
}

.graph-block .graph-block-preview {
  display: block;
  position: relative;
  width: 100%;
  height: 320px;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  padding: 0;
  margin: 0;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  outline: none;
  background: transparent;
  cursor: pointer;
  box-sizing: border-box;
}

.graph-block-canvas {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
}

.graph-content {
  position: relative;
  display: flex;
  flex: 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.graph-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--background);
}

.graph-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  touch-action: none;
  cursor: grab;
}

.graph-canvas.dragging {
  cursor: grabbing;
}

.graph-window .sketch-toolbar-dock {
  pointer-events: none;
}

.graph-window .sketch-history-toolbar {
  pointer-events: auto;
}

.graph-window .sketch-zoom-label {
  pointer-events: none;
}

.graph-sidebar {
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  box-sizing: border-box;
}

.graph-sidebar::-webkit-scrollbar {
  display: none;
}

.graph-section {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 12px;
  padding: 0 0 16px;
  margin: 0 0 16px;
  border-bottom: 2px solid var(--border);
}

.graph-section:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.graph-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  min-height: 28px;
  gap: 8px;
}

.graph-section-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  color: var(--text);
  font-size: 12px;
}

.graph-section-title strong {
  font-weight: 600;
}

.graph-section-title .icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--secondary);
}

.graph-section-title .icon svg {
  width: 16px;
  height: 16px;
}

.graph-section-header .icon-button,
.graph-expression-main .icon-button,
.graph-variable-header .icon-button {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 6px;
}

.graph-section-header .icon-button svg,
.graph-expression-main .icon-button svg,
.graph-variable-header .icon-button svg {
  width: 16px;
  height: 16px;
}

.graph-expression-row,
.graph-variable-row {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 8px;
  padding: 8px 0;
}

.graph-expression-row + .graph-expression-row,
.graph-variable-row + .graph-variable-row {
  padding-top: 16px;
  border-top: 2px solid var(--border);
}

.graph-expression-main,
.graph-variable-header {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 4px;
}

.graph-expression-options,
.graph-variable-fields {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 8px;
}

.graph-sidebar input:not([type="range"]):not([type="color"]) {
  display: block;
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 8px;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--background);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  box-sizing: border-box;
  transition: border-color 160ms ease;
}

.graph-sidebar input:not([type="range"]):not([type="color"]):focus {
  border-color: var(--brand);
}

.graph-expression-input {
  flex: 1;
}

.graph-expression-options input[type="number"] {
  width: 80px;
  max-width: 80px;
}

.graph-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  min-height: 28px;
  gap: 8px;
}

.graph-field-label {
  flex-shrink: 0;
  color: var(--secondary);
  font-size: 12px;
}

.graph-variable-fields .graph-field {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
}

.graph-variable-header .graph-variable-name {
  flex: 1;
  max-width: 48px;
}

.graph-variable-header input[type="number"] {
  flex: 1;
  min-width: 40px;
}

.graph-variable-header .icon-button.active {
  background: var(--brand);
  color: var(--black);
}

.graph-color-control {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  gap: 8px;
}

.graph-color-picker {
  display: block;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 2px;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--background);
  box-sizing: border-box;
  cursor: pointer;
}

.graph-color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.graph-color-picker::-webkit-color-swatch {
  border: 0;
  border-radius: 4px;
}

.graph-color-picker::-moz-color-swatch {
  border: 0;
  border-radius: 4px;
}

.graph-color-hex {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
}

.graph-toggle {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  width: 44px;
  height: 26px;
  padding: 2px;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 16px;
  outline: none;
  background: var(--background);
  box-sizing: border-box;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.graph-toggle-thumb {
  display: block;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--secondary);
  transform: translateX(0);
  transition: transform 160ms ease, background 160ms ease;
}

.graph-toggle.active {
  border-color: var(--brand);
  background: var(--brand);
}

.graph-toggle.active .graph-toggle-thumb {
  transform: translateX(18px);
  background: var(--black);
}

.graph-toggle:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.graph-variable-slider {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 4px;
  padding: 0;
  margin: 12px 0;
  border: 0;
  border-radius: 4px;
  outline: none;
  background: linear-gradient(
    to right,
    var(--brand) 0%,
    var(--brand) var(--graph-slider-progress, 0%),
    var(--border) var(--graph-slider-progress, 0%),
    var(--border) 100%
  );
  cursor: pointer;
}

.graph-variable-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
}

.graph-variable-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
}

.graph-expression-error {
  color: var(--danger);
  font-size: 12px;
  line-height: 18px;
  overflow-wrap: anywhere;
}

.graph-expression-error:empty {
  display: none;
}

.graph-expression-row.invalid .graph-expression-input {
  border-color: var(--danger);
}

.graph-variable-row.invalid input:not([type="range"]):not([type="color"]) {
  border-color: var(--danger);
}

.graph-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.graph-preview-settings {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 8px;
  padding-top: 16px;
  margin-top: 4px;
  border-top: 2px solid var(--border);
}

.graph-preview-settings-title {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.graph-preview-coordinates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.graph-preview-coordinates .graph-field {
  position: relative;
  min-width: 0;
  gap: 0;
}

.graph-preview-coordinates .graph-field-label {
  position: absolute;
  left: 8px;
  z-index: 1;
  pointer-events: none;
}

.graph-sidebar .graph-preview-coordinates input[type="number"] {
  padding-left: 28px;
}

.graph-preview-settings > .graph-field input[type="number"] {
  width: 100%;
  min-width: 0;
}

.graph-preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.graph-preview-action {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 2px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--background);
  color: var(--secondary);
  font-family: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.graph-preview-action:hover {
  background: var(--hover);
  color: var(--text);
}

.graph-preview-action:focus-visible {
  border-color: var(--brand);
}

@media (max-width: 768px) {
  .graph-preview-settings {
    padding-top: 12px;
  }

  .graph-preview-action {
    height: 32px;
    font-size: 10px;
  }
}

@media (max-width: 768px) {
  .graph-block .graph-block-preview {
    height: 240px;
  }

  .graph-content {
    flex-direction: row;
  }

  .graph-section {
    gap: 8px;
    padding-bottom: 12px;
    margin-bottom: 12px;
  }

  .graph-sidebar input:not([type="range"]):not([type="color"]) {
    height: 32px;
    font-size: 12px;
  }

  .graph-expression-main,
  .graph-variable-header {
    gap: 4px;
  }

  .graph-variable-header .icon-button {
    width: 24px;
    height: 24px;
    padding: 4px;
  }

  .graph-variable-fields .graph-field {
    grid-template-columns: 56px minmax(0, 1fr);
  }
}