:root {
	color-scheme: dark;
	--bg: #0b0d12;
	--bg-elev: #121521;
	--panel: #151a28;
	--border: #242b3a;
	--text: #e6eefc;
	--muted: #9bb0d3;
	--accent: #3391ff;
	--accent-2: #78b3ff;
	--ok: #15cc7e;
	--warn: #ffcc66;
	--err: #ff6b6b;
	--shadow: 0 8px 24px rgba(0,0,0,0.4);
	--code-font-size: 15px;
	--code-font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
	margin: 0;
	background: linear-gradient(180deg, var(--bg) 0%, #0c0f17 100%);
	color: var(--text);
	font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell,
		Noto Sans, Helvetica Neue, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

.app-header {
	position: sticky;
	top: 0;
	z-index: 10;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background: rgba(18, 21, 33, 0.8);
	border-bottom: 1px solid var(--border);
	backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
	width: 28px; height: 28px;
	border-radius: 8px;
	display: inline-grid; place-items: center;
	background: linear-gradient(135deg, var(--accent), var(--accent-2));
	color: white; font-weight: 800;
}
.title { font-weight: 600; letter-spacing: 0.2px; }
.status { color: var(--muted); font-size: 12px; }

.layout {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
	gap: 12px;
	padding: 12px;
	max-width: 1400px;
	margin: 0 auto;
}

.panel {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 12px;
	box-shadow: var(--shadow);
	min-height: 260px;
	min-width: 0; /* allow grid item to shrink and not force track wider */
	display: flex;
	flex-direction: column;
}

/* Ensure content doesn't render outside the rounded corners for the editor */
.editor-panel { overflow: hidden; }

.toolbar, .panel-header {
	display: flex; align-items: center; gap: 8px;
	padding: 10px 12px;
	border-bottom: 1px solid var(--border);
}
.panel-header { justify-content: space-between; }
.panel-header .actions { display: inline-flex; gap: 8px; }
.spacer { flex: 1; }

textarea#editor {
	width: 100%;
	height: clamp(280px, 60vh, 680px);
	resize: none; /* hide handle to avoid fake-resizable UI */
	background: #0e1320;
	color: var(--text);
	border: 0;
	outline: none;
	padding: 12px;
	font-family: var(--code-font-family);
	font-size: var(--code-font-size);
	overflow: auto;            /* scrolling container */
	white-space: pre;          /* preserve long lines; no soft wrap */
}

.editor-wrap {
	position: relative;
	border-radius: 12px;
	overflow: hidden;          /* clip overlay and textarea to rounded corners */
	background: #0e1320;       /* unify background for overlay/textarea */
}
.editor-highlight,
textarea#editor {
	font-family: var(--code-font-family);
	font-size: var(--code-font-size);
	line-height: 1.5;
	tab-size: 2;
	white-space: pre;
	word-break: break-word;
}
.editor-highlight {
	position: absolute;
	inset: 0;
	pointer-events: none;
	padding: 12px;
	color: var(--text); /* default visible for non-token text */
	margin: 0; /* avoid default <pre> margins causing vertical offset */
	overflow: hidden;          /* overlay itself never scrolls */
}
.editor-wrap textarea#editor {
	position: relative;
	background: transparent;
	color: transparent;           /* hide raw text to avoid double rendering */
	caret-color: var(--text);     /* keep caret visible */
}
.tok-comment { color: #6b86b3; }
.tok-string { color: #9ae6b4; }
.tok-kw1 { color: #79a8ff; font-weight: 600; }
.tok-kw2 { color: #9d87ff; font-weight: 600; }
.tok-kw3 { color: #ffb86b; font-weight: 600; }
.tok-ident { color: var(--text); }
.tok-todo { color: #ffd166; text-decoration: underline; }
.tok-ok { color: var(--ok); font-weight: 600; }
.tok-err { color: var(--err); font-weight: 600; }

.examples { display: contents; }
.examples .menu-wrapper { position: relative; }
.examples .btn.small .btn-icon { margin-right: 4px; font-size: 10px; }

.dropdown-menu {
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	min-width: 220px;
	background: #0e1320;
	border: 1px solid var(--border);
	border-radius: 10px;
	box-shadow: var(--shadow);
	padding: 6px 0;
	z-index: 20;
}
.dropdown-menu.hidden { display: none; }
.dropdown-menu .item {
	display: flex; align-items: center;
	width: 100%;
	background: transparent; color: var(--text);
	border: none; text-align: left;
	padding: 8px 12px; cursor: pointer;
	font-size: 13px;
}
.dropdown-menu .item:hover { background: #151a28; }

.output-panel { overflow: visible; position: relative; }
.output {
	margin: 0;
	padding: 12px;
	background: #0e1320;
	height: clamp(160px, 60vh, 680px);
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	overflow-y: auto;
	white-space: pre; /* don't wrap to keep formatting aligned */
	font-family: var(--code-font-family);
	font-size: var(--code-font-size);
	line-height: 1.5;
}
.hidden { display: none; }

/* Indent popover */
.indent-wrapper { position: relative; z-index: 1000; }
.popover {
	position: absolute;
	top: calc(100% + 4px);
	left: 0;
	min-width: 180px;
	background: #0e1320;
	border: 1px solid var(--border);
	border-radius: 10px;
	box-shadow: var(--shadow);
	padding: 10px 12px;
	z-index: 999; /* ensure on top of dropdowns and headers */
}
.popover.hidden { display: none; }
.popover input[type="range"] { width: 100%; }
.popover input[type="range"] {
	-webkit-appearance: none;
	appearance: none;
	height: 6px;
	background: #243049;
	border-radius: 4px;
	outline: none;
}
.popover input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: #8fb5ff; /* solid to avoid transparency */
	border: 1px solid #4976c6;
	box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.popover input[type="range"]::-moz-range-thumb {
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: #8fb5ff;
	border: 1px solid #4976c6;
	box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.popover input[type="range"]::-moz-range-track {
	height: 6px;
	background: #243049;
	border: none;
	border-radius: 4px;
}
.popover .row input.num { width: 80px; background: #0e1320; color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; }
.popover .row.end { justify-content: flex-end; }

.btn {
	--bg-btn: #1c2333;
	--bg-btn-hover: #232c41;
	background: var(--bg-btn);
	color: var(--text);
	border: 1px solid var(--border);
	padding: 8px 12px;
	border-radius: 9px;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.04s ease;
}
.btn:hover { background: var(--bg-btn-hover); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }
.btn.primary {
	--bg-btn: linear-gradient(135deg, #2e6efb, #1a9bff);
	--bg-btn-hover: linear-gradient(135deg, #2b68ee, #1a90ef);
	border: none;
	font-weight: 600;
}
.btn.small { padding: 6px 10px; font-size: 12px; height: 28px; display: inline-flex; align-items: center; }
.btn-icon { margin-right: 6px; }

.link { color: var(--accent-2); text-decoration: none; }
.link:hover { text-decoration: underline; }

.app-footer {
	color: var(--muted);
	text-align: center;
	padding: 12px 16px 24px;
	border-top: 1px solid var(--border);
	margin-top: 8px;
}

@media (max-width: 960px) {
	.layout { grid-template-columns: 1fr; }
	.output { height: clamp(160px, 38vh, 520px); }
	.toolbar { flex-wrap: wrap; row-gap: 8px; }
}
