.markdown-tool-card {
	padding: 24px;
}

.markdown-workspace {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
	gap: 20px;
	margin-top: 20px;
}

.markdown-panel {
	display: flex;
	flex-direction: column;
	min-width: 0;
	border: 1px solid var(--line);
	border-radius: 12px;
	overflow: hidden;
	background: var(--surface);
}

.markdown-panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 10px;
	min-height: 54px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--line);
	background: var(--bg);
}

.markdown-panel-header label,
.markdown-panel-header>span {
	font-size: 14px;
	font-weight: 600;
	color: var(--ink);
}

.markdown-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.markdown-tool-card .secondary-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 36px;
	padding: 7px 14px;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: var(--surface);
	color: var(--ink);
	font-family: inherit;
	font-size: 13px;
	font-weight: 500;
	line-height: 1.4;
	cursor: pointer;
	transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.markdown-tool-card .secondary-button:hover {
	background: var(--soft);
	border-color: var(--blue);
	color: var(--blue);
}

.markdown-tool-card .secondary-button:active {
	transform: translateY(1px);
}

.markdown-tool-card .secondary-button:focus-visible {
	outline: 2px solid var(--blue);
	outline-offset: 2px;
}

.markdown-textarea {
	display: block;
	width: 100%;
	min-height: 480px;
	padding: 18px;
	border: 0;
	outline: none;
	resize: vertical;
	background: var(--surface);
	color: var(--ink);
	font-family: Consolas, Monaco, "Courier New", monospace;
	font-size: 14px;
	line-height: 1.7;
	tab-size: 4;
}

.markdown-textarea:focus {
	box-shadow: inset 0 0 0 2px var(--blue);
}

.markdown-stats {
	padding: 10px 16px;
	border-top: 1px solid var(--line);
	color: var(--muted);
	font-size: 12px;
	text-align: right;
}

.markdown-preview {
	min-height: 480px;
	padding: 24px;
	overflow-wrap: anywhere;
	color: var(--ink);
	font-size: 14px;
	line-height: 1.8;
}

.markdown-preview> :first-child {
	margin-top: 0;
}

.markdown-preview> :last-child {
	margin-bottom: 0;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
	margin: 1.2em 0 0.6em;
	color: var(--ink);
	line-height: 1.35;
}

.markdown-preview h1 {
	font-size: 2em;
}

.markdown-preview h2 {
	font-size: 1.6em;
}

.markdown-preview h3 {
	font-size: 1.3em;
}

.markdown-preview p {
	margin: 0 0 1em;
}

.markdown-preview a {
	color: var(--blue);
	text-decoration: underline;
}

.markdown-preview ul,
.markdown-preview ol {
	padding-left: 26px;
	margin: 0 0 1em;
}

.markdown-preview li {
	margin: 4px 0;
}

.markdown-preview blockquote {
	margin: 1em 0;
	padding: 10px 16px;
	border-left: 4px solid var(--blue);
	background: var(--bg);
	color: var(--muted);
}

.markdown-preview pre {
	max-width: 100%;
	margin: 1em 0;
	padding: 16px;
	overflow-x: auto;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: var(--bg);
	font-family: Consolas, Monaco, "Courier New", monospace;
	font-size: 13px;
	line-height: 1.6;
}

.markdown-preview code {
	padding: 2px 5px;
	border-radius: 4px;
	background: var(--bg);
	font-family: Consolas, Monaco, "Courier New", monospace;
	font-size: 0.9em;
}

.markdown-preview pre code {
	padding: 0;
	background: transparent;
}

.markdown-preview table {
	width: 100%;
	margin: 1em 0;
	border-collapse: collapse;
	font-size: 13px;
}

.markdown-preview th,
.markdown-preview td {
	padding: 9px 12px;
	border: 1px solid var(--line);
	text-align: left;
}

.markdown-preview th {
	background: var(--bg);
	font-weight: 600;
}

.markdown-preview hr {
	margin: 1.5em 0;
	border: 0;
	border-top: 1px solid var(--line);
}

.markdown-preview img {
	max-width: 100%;
	height: auto;
	border-radius: 6px;
}

.markdown-preview input[type="checkbox"] {
	margin-right: 7px;
}

.markdown-tool-card .status-message {
	margin-top: 14px;
}

@media (max-width: 850px) {
	.markdown-workspace {
		grid-template-columns: 1fr;
	}

	.markdown-textarea,
	.markdown-preview {
		min-height: 360px;
	}
}

@media (max-width: 520px) {
	.markdown-tool-card {
		padding: 14px;
	}

	.markdown-panel-header {
		align-items: flex-start;
		flex-direction: column;
	}

	.markdown-actions {
		width: 100%;
	}

	.markdown-actions button {
		flex: 1;
	}

	.markdown-textarea,
	.markdown-preview {
		min-height: 300px;
		padding: 14px;
	}
}


/* Full Screen Preview Modal */
.markdown-modal {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 9999;
	width: 100%;
	height: 100%;
	height: 100dvh;
	background: var(--surface);
	flex-direction: column;
}

.markdown-modal.active {
	display: flex;
}

.markdown-modal-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	flex-shrink: 0;
	min-height: 64px;
	padding: 12px 24px;
	border-bottom: 1px solid var(--line);
	background: var(--bg);
}

.markdown-modal-header h2 {
	margin: 0;
	color: var(--ink);
	font-size: 18px;
	font-weight: 600;
}

.markdown-modal-content {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 32px 24px;
	overscroll-behavior: contain;
	scroll-behavior: smooth;
}

.markdown-modal-header {
	position: sticky;
	top: 0;
	z-index: 2;
}

.markdown-modal-content .markdown-preview {
	width: 100%;
	max-width: 1100px;
	min-height: auto;
	margin: 0 auto;
	padding: 20px 32px 60px;
	font-size: 16px;
	line-height: 1.9;
}

.markdown-modal-content .markdown-preview pre {
	max-width: 100%;
	overflow-x: auto;
	white-space: pre;
}

.markdown-modal-content .markdown-preview table {
	display: block;
	max-width: 100%;
	overflow-x: auto;
}

.markdown-modal-content .markdown-preview {
	width: 100%;
	max-width: 1100px;
	min-height: auto;
	margin: 0 auto;
	padding: 20px 32px 60px;
	font-size: 16px;
	line-height: 1.9;
}

.markdown-modal-content .markdown-preview h1 {
	font-size: 2.2em;
}

.markdown-modal-content .markdown-preview h2 {
	font-size: 1.7em;
}

.markdown-modal-content .markdown-preview pre {
	white-space: pre;
}

body.markdown-modal-open {
	overflow: hidden;
}

@media (max-width: 600px) {
	.markdown-modal-header {
		min-height: 56px;
		padding: 10px 14px;
	}

	.markdown-modal-header h2 {
		font-size: 16px;
	}

	.markdown-modal-content {
		padding: 12px 8px;
	}

	.markdown-modal-content .markdown-preview {
		padding: 12px 8px 40px;
		font-size: 14px;
	}
}

/* Limit the live preview height to the browser viewport */
.markdown-panel:has(#markdownPreview) {
	height: min(600px, calc(100vh - 180px));
	min-height: 0;
}

.markdown-panel:has(#markdownPreview) .markdown-preview {
	flex: 1;
	min-height: 0;
	max-height: 100%;
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* Keep editor and preview heights consistent */
.markdown-panel:has(#markdownInput) {
	height: min(600px, calc(100vh - 180px));
}

.markdown-panel:has(#markdownInput) .markdown-textarea {
	flex: 1;
	min-height: 0;
	height: 100%;
}

/* Mobile */
@media (max-width: 850px) {

	.markdown-panel:has(#markdownPreview),
	.markdown-panel:has(#markdownInput) {
		height: 500px;
		max-height: calc(100vh - 140px);
	}
}