.wp-block-freeform.block-library-rich-text__tinymce {
	p,
	li {
		line-height: $editor-line-height;
	}

	ul,
	ol {
		padding-left: 2.5em;
		margin-left: 0;
	}

	blockquote {
		margin: 0;
		box-shadow: inset 0 0 0 0 $light-gray-500;
		border-left: 4px solid $black;
		padding-left: 1em;
	}

	pre {
		white-space: pre-wrap;
		font-family: $editor-html-font;
		font-size: $text-editor-font-size;
		color: $dark-gray-800;
	}

	h1 {
		font-size: 2em;
	}

	h2 {
		font-size: 1.6em;
	}

	h3 {
		font-size: 1.4em;
	}

	h4 {
		font-size: 1.2em;
	}

	h5 {
		font-size: 1.1em;
	}

	h6 {
		font-size: 1em;
	}

	> *:first-child {
		margin-top: 0;
	}

	> *:last-child {
		margin-bottom: 0;
	}

	&.mce-edit-focus {
		outline: none;
	}

	a {
		color: $blue-medium-700;
	}

	&:focus a[data-mce-selected] {
		padding: 0 2px;
		margin: 0 -2px;
		border-radius: 2px;
		box-shadow: 0 0 0 $border-width $blue-medium-100;
		background: $blue-medium-100;
	}

	code {
		padding: 2px;
		border-radius: 2px;
		color: $dark-gray-800;
		background: $light-gray-200;
		font-family: $editor-html-font;
		font-size: 14px;
	}

	&:focus code[data-mce-selected] {
		background: $light-gray-400;
	}

	.alignright {
		/*rtl:ignore*/
		float: right;
		/*rtl:ignore*/
		margin: 0.5em 0 0.5em 1em;
	}

	.alignleft {
		/*rtl:ignore*/
		float: left;
		/*rtl:ignore*/
		margin: 0.5em 1em 0.5em 0;
	}

	.aligncenter {
		display: block;
		margin-left: auto;
		margin-right: auto;
	}

	.wp-more-tag {
		width: 96%;
		height: 20px;
		display: block;
		margin: 15px auto;
		outline: 0;
		cursor: default;
		background-image: url(/wp-includes/js/tinymce/skins/wordpress/images/more-2x.png);
		background-size: 1900px 20px;
		background-repeat: no-repeat;
		background-position: center;
	}

	/* Remove blue highlighting of selected images in WebKit */
	img::selection {
		background-color: transparent;
	}

	div.mceTemp {
		-ms-user-select: element;
	}

	/* Image captions */
	dl.wp-caption {
		margin: 0; /* dl browser reset */
		max-width: 100%;

		a,
		img {
			display: block;
		}

		&,
		& * {
			-webkit-user-drag: none;
		}

		.wp-caption-dd {
			padding-top: 0.5em;
			margin: 0; /* browser dd reset */
		}
	}

	/* WP Views */
	.wpview {
		width: 99.99%; /* All IE need hasLayout, incl. 11 (ugh, not again!!) */
		position: relative;
		clear: both;
		margin-bottom: 16px;
		border: 1px solid transparent;

		iframe {
			display: block;
			max-width: 100%;
			background: transparent;
		}

		.mce-shim {
			position: absolute;
			top: 0;
			right: 0;
			bottom: 0;
			left: 0;
		}

		&[data-mce-selected="2"] .mce-shim {
			display: none;
		}

		.loading-placeholder {
			border: 1px dashed $light-gray-400;
			padding: 10px;
		}

		.wpview-error {
			border: 1px solid $light-gray-400;
			padding: 1em 0;
			margin: 0;
			word-wrap: break-word;

			p {
				margin: 0;
				text-align: center;
			}
		}

		&[data-mce-selected] .loading-placeholder,
		&[data-mce-selected] .wpview-error {
			border-color: transparent;
		}

		.dashicons {
			display: block;
			margin: 0 auto;
			width: 32px;
			height: 32px;
			font-size: 32px;
		}

		// The following gallery styles were replicated
		// from the styles applied in the tinymce skin,
		// /wp-includes/js/tinymce/skins/wordpress/wp-content.css.
		&.wpview-type-gallery::after {
			content: "";
			display: table;
			clear: both;
		}
	}

	.gallery img[data-mce-selected]:focus {
		outline: none;
	}

	.gallery a {
		cursor: default;
	}

	.gallery {
		margin: auto -6px;
		padding: 6px 0;
		line-height: 1;
		overflow-x: hidden;
	}

	.gallery .gallery-item {
		float: left;
		margin: 0;
		text-align: center;
		padding: 6px;
		-webkit-box-sizing: border-box;
		-moz-box-sizing: border-box;
		box-sizing: border-box;
	}

	.gallery .gallery-caption,
	.gallery .gallery-icon {
		margin: 0;
	}

	.gallery .gallery-caption {
		font-size: 13px;
		margin: 4px 0;
	}

	@for $i from 1 through 9 {
		.gallery-columns-#{ $i } .gallery-item {
			width: #{ (100 / $i) + "%" };
		}
	}

	.gallery img {
		max-width: 100%;
		height: auto;
		border: none;
		padding: 0;
	}
}

div[data-type="core/freeform"] {
	.block-editor-block-list__block-edit::before {
		transition: border-color 0.1s linear, box-shadow 0.1s linear;
		border: $border-width solid $light-gray-500;

		// Windows High Contrast mode will show this outline.
		outline: $border-width solid transparent;
	}

	&.is-selected .block-editor-block-list__block-edit::before {
		border-color: $light-gray-800;
		border-left-color: transparent;
	}

	// Don't show block type label for classic block
	&.is-hovered .block-editor-block-list__breadcrumb {
		display: none;
	}

	.editor-block-contextual-toolbar + div {
		margin-top: 0;
		padding-top: 0;
	}

	// Ensure aligned blocks at end are within the selected block.
	&.is-selected .block-library-rich-text__tinymce::after {
		content: "";
		display: table;
		clear: both;
	}
}

// mce global styles: the toolbars may get appended to <body>
.mce-toolbar-grp {
	// Not sure why this is necessary, there seems to be a skin file that
	// overrides this upstream.
	.mce-btn.mce-active button,
	.mce-btn.mce-active:hover button,
	.mce-btn.mce-active i,
	.mce-btn.mce-active:hover i {
		color: $dark-gray-800;
	}

	// Prevent toolbar clipping on heading style in RTL languages
	.mce-rtl .mce-flow-layout-item.mce-last {
		margin-right: 0;
		margin-left: 8px;
	}

	// Prevent i tags in buttons from picking up theme editor styles.
	.mce-btn i {
		font-style: normal;
	}
}

.block-library-classic__toolbar {
	width: auto;
	margin: 0 #{ -$block-padding };
	position: sticky;
	z-index: z-index(".block-library-classic__toolbar");
	top: $block-padding;
	transform: translateY(-$block-padding);
	border: $border-width solid $light-gray-500;
	border-bottom: none;

	// On mobile, toolbars go edge to edge.
	padding: 0 $block-padding;

	.is-selected & {
		border-color: $light-gray-800;
		border-left-color: transparent;
	}

	@include break-small() {
		padding: 0;
	}

	&:empty {
		height: $block-toolbar-height;
		background: #f5f5f5;
		border-bottom: $border-width solid #e2e4e7;

		&::before {
			font-family: $default-font;
			font-size: $default-font-size;
			content: attr(data-placeholder);
			color: #555d66;
			line-height: 37px;
			padding: $block-padding;
		}
	}

	// Overwrite inline styles.
	.mce-tinymce-inline,
	.mce-tinymce-inline > div,
	div.mce-toolbar-grp,
	div.mce-toolbar-grp > div,
	.mce-menubar,
	.mce-menubar > div {
		height: auto !important;
		width: 100% !important;
	}

	.mce-container-body.mce-abs-layout {
		overflow: visible;
	}

	.mce-menubar,
	div.mce-toolbar-grp {
		position: static;
	}

	// Adjust padding to not cause a jump.
	.mce-toolbar-grp > div {
		padding: 1px 3px;
	}

	.mce-toolbar-grp .mce-toolbar:not(:first-child) {
		display: none;
	}

	&.has-advanced-toolbar .mce-toolbar-grp .mce-toolbar {
		display: block;
	}
}

// We don't want the ellipsis to overlap the classic toolbar, which it will due to position sticky.
// So we move it to the right, and make room for it.
@include break-small() {
	.block-editor-block-list__block[data-type="core/freeform"] {
		.block-editor-block-switcher__no-switcher-icon {
			display: none;
		}
		.block-editor-block-contextual-toolbar {
			float: right;
			margin-right: $icon-button-size - $block-padding + ($border-width * 3);
			transform: translateY(-#{ $block-padding - $border-width });
			top: $block-padding;

			.block-editor-block-toolbar {
				border: none;
				box-shadow: none;

				// Match the TinyMCE "mobile" breakpoint buttons alignment.
				margin-top: 3px;
				@include break-medium() {
					margin-top: 0;
				}

				&::before {
					content: "";
					display: block;
					border-left: 1px solid $light-gray-500;
					margin-top: $grid-size-small;
					margin-bottom: $grid-size-small;
				}

				.components-toolbar__control.components-button:hover {
					background-color: transparent;
				}
			}

			.components-toolbar {
				background: transparent;
				border: none;
			}
		}

		.mce-container.mce-toolbar.mce-stack-layout-item {
			padding-right: $icon-button-size;
		}
	}
}
