:root {
	--bg: #f2f4f8;
	--panel: #ffffff;
	--ink: #1d2430;
	--muted: #5c6878;
	--line: #d6deea;
	--editor-gutter-bg: #f3f7fc;
	--editor-gutter-ink: #7c8897;
	--accent: #0d6efd;
	--header-bg-start: #ffffff;
	--header-bg-end: #f8fbff;
	--editor-shell-bg: #fbfdff;
	--highlight-ink: #6b7788;
	--highlight-text: #2d3848;
	--highlight-operator: #0d6efd;
	--highlight-comment: #7a8799;
	--highlight-unknown: #b34a63;
	--caret: #111827;
	--canvas-bg: #fafcff;
	--radius: 14px;
}

:root[data-theme="dark"] {
	--bg: #12161b;
	--panel: #1d2228;
	--ink: #e3e9f1;
	--muted: #99a3b0;
	--line: #303842;
	--editor-gutter-bg: #181d24;
	--editor-gutter-ink: #77818d;
	--accent: #7fb5ff;
	--header-bg-start: #232932;
	--header-bg-end: #1a2027;
	--editor-shell-bg: #151a21;
	--highlight-ink: #98a2af;
	--highlight-text: #d7dee7;
	--highlight-operator: #89bbff;
	--highlight-comment: #7f8793;
	--highlight-unknown: #f2a0af;
	--caret: #f3f7ff;
	--canvas-bg: #141920;
}

* {
	box-sizing: border-box;
}

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

body {
	font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
	color: var(--ink);
	background: var(--bg);
}

.layout {
	min-height: 100vh;
	height: 100vh;
	display: grid;
	grid-template-columns: minmax(300px, 1.1fr) minmax(300px, 0.9fr);
	gap: 16px;
	padding: 16px;
	overflow: hidden;
}

.panel {
	display: flex;
	flex-direction: column;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background: var(--panel);
	min-height: 0;
	overflow: hidden;
}

.panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 14px;
	border-bottom: 1px solid var(--line);
	background: var(--panel);
}

.panel-header h1,
.panel-header h2 {
	margin: 0;
	font-size: 0.95rem;
	font-weight: 650;
	letter-spacing: 0.02em;
}

.hint {
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--accent);
	background: color-mix(in oklab, var(--accent) 16%, transparent);
	border: 1px solid color-mix(in oklab, var(--accent) 35%, transparent);
	border-radius: 999px;
	padding: 0.2rem 0.55rem;
}

.header-controls {
	display: flex;
	align-items: center;
	gap: 8px;
}

.theme-toggle {
	appearance: none;
	border: 1px solid var(--line);
	background: color-mix(in oklab, var(--panel) 84%, var(--accent) 16%);
	color: var(--ink);
	font: 600 0.75rem/1 "IBM Plex Sans", "Segoe UI", sans-serif;
	padding: 0.45rem 0.62rem;
	border-radius: 9px;
	cursor: pointer;
	transition: transform 120ms ease, filter 120ms ease;
}

.theme-toggle:hover {
	filter: brightness(1.05);
}

.theme-toggle:active {
	transform: translateY(1px);
}

.editor-shell {
	position: relative;
	flex: 1;
	min-height: 0;
	background: var(--editor-shell-bg);
}

#line-number-gutter,
#highlight-layer,
#editor {
	margin: 0;
	position: absolute;
	inset: 0 auto 0 0;
	height: 100%;
	padding: 14px;
	font: 500 14px/1.55 "IBM Plex Mono", "Consolas", monospace;
	white-space: pre;
	overflow: auto;
	tab-size: 2;
}

#line-number-gutter {
	width: 3.75rem;
	padding-right: 0.75rem;
	border-right: 1px solid var(--line);
	background: var(--editor-gutter-bg);
	color: var(--editor-gutter-ink);
	text-align: right;
	pointer-events: none;
	user-select: none;
	scrollbar-width: none;
}

#line-number-gutter::-webkit-scrollbar {
	display: none;
}

#highlight-layer,
#editor {
	left: 3.75rem;
	width: calc(100% - 3.75rem);
}

#highlight-layer {
	pointer-events: none;
	color: var(--highlight-ink);
}

#highlight-layer.ends-with-newline {
	padding-bottom: calc(14px + 1.55em);
}

.token-text {
	color: var(--highlight-text);
}

.token-operator {
	color: var(--highlight-operator);
}

.token-comment {
	color: var(--highlight-comment);
	font-style: italic;
}

.token-unknown {
	color: var(--highlight-unknown);
}

#editor {
	border: 0;
	resize: none;
	outline: none;
	background: transparent;
	color: transparent;
	caret-color: var(--caret);
}

#preview-canvas {
	flex: 1;
	width: 100%;
	height: 100%;
	min-height: 300px;
	display: block;
	background: var(--canvas-bg);
}

.token-debug {
	margin: 0;
	padding: 14px;
	flex: 1;
	overflow: auto;
	font: 500 13px/1.5 "IBM Plex Mono", "Consolas", monospace;
	color: var(--ink);
	background: var(--editor-shell-bg);
	white-space: pre;
	border-top: 1px solid var(--line);
}

@media (max-width: 900px) {
	.layout {
		grid-template-columns: 1fr;
		grid-template-rows: 4fr 3.5fr;
	}
}
