*,
*::before,
*::after {
	box-sizing: border-box;
}

:root {
	--bg: #f5f5f7;
	--surface: #ffffff;
	--surface-muted: #f8f8fb;
	--border: #d9dbe3;
	--text: #1f2430;
	--text-muted: #62697a;
	--accent: #2563eb;
	--accent-strong: #1d4ed8;
	--danger: #b91c1c;
	--shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

[data-theme='dark'] {
	--bg: #0f131a;
	--surface: #171c24;
	--surface-muted: #10161f;
	--border: #2d3643;
	--text: #edf2f7;
	--text-muted: #9ca8ba;
	--accent: #60a5fa;
	--accent-strong: #93c5fd;
	--danger: #fca5a5;
	--shadow: 0 14px 36px rgba(0, 0, 0, 0.32);
}

html,
body {
	margin: 0;
	min-height: 100%;
}

body {
	font-family:
		-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
	background: var(--bg);
	color: var(--text);
}

[hidden] {
	display: none !important;
}

button,
textarea {
	font: inherit;
}

button {
	cursor: pointer;
}

.workspace {
	min-height: 100vh;
	display: grid;
	grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
	grid-template-areas: 'editor preview';
	align-items: stretch;
	gap: 16px;
	padding: 16px;
}

.workspace.panel-collapsed {
	grid-template-columns: minmax(0, 1fr);
	grid-template-areas: 'preview';
}

.editor-panel {
	grid-area: editor;
	display: flex;
	flex-direction: column;
	gap: 12px;
	padding: 16px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 16px;
	box-shadow: var(--shadow);
	min-height: calc(100vh - 32px);
	max-height: calc(100vh - 32px);
	overflow: auto;
}

.workspace.panel-collapsed .editor-panel {
	display: none;
}

.selection-card {
	padding: 12px 14px;
	border: 1px solid var(--border);
	border-radius: 12px;
	background: var(--surface-muted);
}

.selection-note {
	margin: 0;
	line-height: 1.5;
	color: var(--text-muted);
}

.selection-preview {
	margin: 12px 0 0;
	padding: 12px;
	max-height: 120px;
	overflow: auto;
	border-radius: 10px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text-muted);
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 0.74rem;
	line-height: 1.45;
	white-space: pre-wrap;
	word-break: break-word;
}

.editor-form {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.editor-form textarea {
	width: 100%;
	min-height: 108px;
	padding: 14px;
	border: 1px solid var(--border);
	border-radius: 12px;
	background: var(--surface);
	color: var(--text);
	resize: vertical;
	outline: none;
}

.editor-form textarea:focus {
	border-color: var(--accent);
	box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.editor-form__footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	flex-wrap: wrap;
}

.apply-button {
	padding: 0.72rem 1rem;
	border: none;
	border-radius: 10px;
	background: var(--accent);
	color: #ffffff;
	font-weight: 600;
}

.apply-button:hover:not(:disabled) {
	background: var(--accent-strong);
}

.apply-button:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.editor-help {
	font-size: 0.82rem;
	color: var(--text-muted);
}

.request-error,
.error-banner {
	display: none;
	padding: 12px 14px;
	border-radius: 12px;
	border: 1px solid rgba(185, 28, 28, 0.22);
	background: rgba(185, 28, 28, 0.08);
	color: var(--danger);
	line-height: 1.45;
}

.request-error.visible,
.error-banner.visible {
	display: block;
}

.preview-panel {
	grid-area: preview;
	position: relative;
	min-height: 0;
	min-height: calc(100vh - 32px);
	border: 1px solid var(--border);
	border-radius: 16px;
	background: var(--surface);
	box-shadow: var(--shadow);
	overflow: hidden;
}

#previewFrame {
	display: block;
	width: 100%;
	height: 100%;
	min-height: 58vh;
	border: none;
	background: #ffffff;
}

.preview-empty,
.loading-overlay {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 24px;
	text-align: center;
	background: color-mix(in srgb, var(--surface), var(--bg) 18%);
}

.preview-empty {
	z-index: 2;
}

.preview-empty h2 {
	margin: 0 0 8px;
	font-size: 1.35rem;
}

.preview-empty p,
.loading-overlay p {
	margin: 0;
	color: var(--text-muted);
	line-height: 1.5;
}

.loading-overlay {
	z-index: 3;
	gap: 12px;
	opacity: 0;
	pointer-events: none;
	transition: opacity 160ms ease;
}

.loading-overlay.visible {
	opacity: 1;
	pointer-events: auto;
}

.spinner {
	width: 34px;
	height: 34px;
	border: 3px solid rgba(37, 99, 235, 0.18);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

.error-banner {
	position: absolute;
	left: 16px;
	right: 16px;
	bottom: 16px;
	z-index: 4;
}

.locked-state {
	min-height: 100vh;
	display: grid;
	place-items: center;
	padding: 20px;
}

.locked-card {
	max-width: 460px;
	padding: 24px;
	border-radius: 16px;
	border: 1px solid var(--border);
	background: var(--surface);
	box-shadow: var(--shadow);
}

.locked-card h1 {
	margin: 0 0 10px;
	font-size: 1.5rem;
}

.locked-card p {
	margin: 0;
	color: var(--text-muted);
	line-height: 1.5;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

@media (max-width: 720px) {
	.workspace {
		grid-template-columns: 1fr;
		grid-template-areas:
			'preview'
			'editor';
		padding: 12px;
		gap: 12px;
	}

	.workspace.panel-collapsed {
		grid-template-columns: 1fr;
		grid-template-areas: 'preview';
	}

	.editor-panel {
		min-height: auto;
		max-height: none;
		overflow: visible;
	}

	.editor-form__footer {
		align-items: stretch;
	}

	.apply-button {
		width: 100%;
	}

	.preview-panel {
		min-height: 52vh;
	}

	#previewFrame {
		min-height: 50vh;
	}
}
