:root {
	color-scheme: dark;
	accent-color: #ececec;
	--bg: #070707;
	--stage: #040404;
	--chrome: #0d0d0d;
	--panel: #101010;
	--surface: #181818;
	--surface-hover: #242424;
	--line: #232323;
	--line-strong: #444444;
	--text: #efefef;
	--muted: #7f7f7f;
	--accent: #ffffff;
	--top-h: 38px;
	--rail-w: 44px;
	--panel-w: min(312px, 90vw);
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
	overflow: hidden;
	background: var(--bg);
	color: var(--text);
	font: 12px/1.4 system-ui, -apple-system, sans-serif;
	-webkit-font-smoothing: antialiased;
}

/* ---------- Top Workspace Bar ---------- */
#topbar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	height: var(--top-h);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 0 12px;
	background: var(--chrome);
	border-bottom: 1px solid var(--line);
	overflow-x: auto;
	scrollbar-width: none;
	z-index: 30;
}

#topbar::-webkit-scrollbar {
	display: none;
}

.brand {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--accent);
	white-space: nowrap;
}

.brand-mark {
	width: 14px;
	height: 14px;
	border: 1px solid var(--accent);
	border-radius: 50%;
	position: relative;
}

.brand-mark::after {
	content: '';
	position: absolute;
	inset: 3px;
	border-radius: 50%;
	background: var(--accent);
}

.brand-ver {
	color: var(--muted);
	font-weight: 500;
	font-size: 10px;
	letter-spacing: 0.06em;
}

.top-group {
	display: flex;
	align-items: center;
	gap: 4px;
	flex-shrink: 0;
}

.pill-group {
	display: inline-flex;
	flex-shrink: 0;
	background: var(--bg);
	border: 1px solid var(--line);
	border-radius: 4px;
	padding: 2px;
	gap: 2px;
}

.pill-group button {
	padding: 2px 7px;
	border: 0;
	background: transparent;
	color: var(--muted);
	font-size: 11px;
	border-radius: 3px;
}

.pill-group button:hover {
	color: var(--text);
	background: var(--surface);
}

.pill-group button.active {
	background: var(--text);
	color: #080808;
	font-weight: 600;
}

/* ---------- Left Vertical Tool Rail ---------- */
#rail {
	position: fixed;
	top: var(--top-h);
	left: 0;
	bottom: 0;
	width: var(--rail-w);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	padding: 8px 4px;
	background: var(--chrome);
	border-right: 1px solid var(--line);
	z-index: 25;
}

.rail-btn {
	width: 32px;
	height: 32px;
	padding: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: transparent;
	border: 1px solid transparent;
	border-radius: 4px;
	color: var(--muted);
}

.rail-btn svg {
	width: 15px;
	height: 15px;
	stroke: currentColor;
	fill: none;
	stroke-width: 1.6;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.rail-btn:hover {
	color: var(--text);
	background: var(--surface);
	border-color: var(--line);
}

.rail-btn.active {
	background: var(--text);
	color: #080808;
	border-color: var(--text);
}

.rail-sep {
	width: 20px;
	height: 1px;
	background: var(--line);
	margin: 4px 0;
}

/* ---------- Stage & Artboard ---------- */
#stage {
	position: fixed;
	top: var(--top-h);
	left: var(--rail-w);
	bottom: 0;
	right: var(--panel-w);
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--stage);
	overflow: hidden;
}

.hide-ui #topbar,
.hide-ui #rail,
.hide-ui #panel,
.hide-ui #stats {
	display: none;
}

.hide-ui #stage {
	top: 0;
	left: 0;
	right: 0;
}

.frame {
	position: relative;
	width: 100%;
	height: 100%;
	touch-action: none;
	user-select: none;
	cursor: grab;
	overflow: hidden;
}

.frame.dragging {
	cursor: grabbing;
}

.frame.tool-draw,
.frame.tool-slice,
.frame.tool-light {
	cursor: crosshair;
}

.frame.boxed {
	outline: 1px solid var(--line-strong);
	box-shadow: 0 0 0 1px #000000;
}

.snap-overlay {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
	z-index: 6;
}

.draw-overlay {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
	z-index: 7;
}

.coord-hud {
	position: absolute;
	left: 50%;
	bottom: 14px;
	transform: translateX(-50%);
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 4px 10px;
	background: rgba(10, 10, 10, 0.84);
	border: 1px solid var(--line-strong);
	border-radius: 999px;
	color: var(--text);
	font-size: 11px;
	font-variant-numeric: tabular-nums;
	letter-spacing: 0.04em;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.2s;
	z-index: 9;
	white-space: nowrap;
}

.coord-hud.show {
	opacity: 1;
}

.coord-hud .badge {
	padding: 1px 6px;
	border-radius: 999px;
	background: var(--text);
	color: #080808;
	font-size: 9.5px;
	font-weight: 700;
	letter-spacing: 0.08em;
}

.drop-veil {
	position: absolute;
	inset: 10px;
	display: none;
	align-items: center;
	justify-content: center;
	border: 1px dashed var(--accent);
	background: rgba(8, 8, 8, 0.84);
	color: var(--accent);
	font-size: 12px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	pointer-events: none;
	z-index: 15;
}

.stage-drop .drop-veil {
	display: flex;
}

#stats {
	position: fixed;
	left: calc(var(--rail-w) + 12px);
	bottom: 10px;
	padding: 3px 8px;
	background: rgba(12, 12, 12, 0.76);
	border: 1px solid var(--line);
	border-radius: 4px;
	color: var(--muted);
	font-size: 10.5px;
	font-variant-numeric: tabular-nums;
	letter-spacing: 0.03em;
	pointer-events: none;
	z-index: 10;
}

/* ---------- Right Tabbed Inspector ---------- */
#panel {
	position: fixed;
	top: var(--top-h);
	right: 0;
	bottom: 0;
	width: var(--panel-w);
	display: flex;
	flex-direction: column;
	background: var(--panel);
	border-left: 1px solid var(--line);
	z-index: 25;
}

.tab-bar {
	display: grid;
	grid-template-columns: repeat(6, 1fr);
	border-bottom: 1px solid var(--line);
	background: var(--chrome);
	flex: 0 0 auto;
}

.tab-btn {
	border: 0;
	border-bottom: 2px solid transparent;
	border-radius: 0;
	background: transparent;
	color: var(--muted);
	padding: 9px 1px;
	font-size: 9.5px;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.tab-btn:hover {
	background: var(--surface);
	color: var(--text);
}

.tab-btn.active {
	background: transparent;
	color: var(--accent);
	border-bottom-color: var(--accent);
}

.tab-body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 10px 12px 18px;
	scrollbar-color: #343434 var(--panel);
	scrollbar-width: thin;
}

.tab-pane {
	display: none;
}

.tab-pane.active {
	display: block;
}

.sec {
	border-top: 1px solid var(--line);
	padding: 10px 0;
}

.sec:first-child {
	border-top: 0;
	padding-top: 2px;
}

.sec-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 7px;
	color: var(--text);
	font-size: 10.5px;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

.hint {
	margin: 4px 0 6px;
	color: var(--muted);
	font-size: 11px;
	line-height: 1.35;
}

.row {
	display: grid;
	grid-template-columns: 78px 1fr 44px;
	gap: 7px;
	align-items: center;
	margin: 5px 0;
}

.row.tone-row {
	grid-template-columns: 78px 15px 1fr 38px;
	gap: 6px;
}

.row.full-row {
	grid-template-columns: 1fr;
}

.row span {
	color: var(--muted);
	font-size: 11.5px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.swatch {
	width: 15px;
	height: 15px;
	border-radius: 3px;
	border: 1px solid var(--line-strong);
	background: #000000;
}

.row input[type='range'],
.row select,
.row input[type='number'],
.row input[type='text'],
.row textarea {
	width: 100%;
}

.row input[type='checkbox'] {
	justify-self: start;
	width: 13px;
	height: 13px;
	cursor: pointer;
}

/* Custom hairline monochrome slider */
input[type='range'] {
	-webkit-appearance: none;
	appearance: none;
	height: 2px;
	background: var(--line-strong);
	border-radius: 1px;
	cursor: pointer;
	outline: none;
}

input[type='range']::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--text);
	border: 1px solid #000000;
	cursor: pointer;
}

input[type='range']::-moz-range-thumb {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--text);
	border: 1px solid #000000;
	cursor: pointer;
}

.row output {
	text-align: right;
	font-variant-numeric: tabular-nums;
	font-size: 11px;
	color: var(--muted);
	cursor: ew-resize;
	user-select: none;
	padding: 1px 3px;
	border-radius: 3px;
}

.row output:hover {
	color: var(--text);
	background: var(--surface);
}

.row.locked {
	opacity: 0.45;
}

.row.locked output {
	cursor: default;
}

.row.locked output:hover {
	color: var(--muted);
	background: transparent;
}

select,
input[type='number'],
input[type='text'],
textarea,
button {
	background: var(--surface);
	color: var(--text);
	border: 1px solid var(--line);
	border-radius: 4px;
	padding: 5px 7px;
	font: inherit;
}

textarea {
	resize: vertical;
	min-height: 54px;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 11px;
}

select:focus-visible,
input:focus-visible,
textarea:focus-visible,
button:focus-visible {
	outline: 1px solid var(--line-strong);
	outline-offset: 1px;
}

button {
	cursor: pointer;
	transition: background 0.12s, border-color 0.12s, color 0.12s;
}

button:hover {
	background: var(--surface-hover);
	border-color: var(--line-strong);
}

button.active {
	background: var(--text);
	color: #080808;
	border-color: var(--text);
	font-weight: 600;
}

button.primary {
	background: var(--text);
	color: #080808;
	border-color: var(--text);
	font-weight: 600;
}

button.primary:hover {
	background: #d8d8d8;
}

.btns {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 5px;
	margin-top: 6px;
}

.btns-3 {
	grid-template-columns: repeat(3, 1fr);
}

.btns-4 {
	grid-template-columns: repeat(4, 1fr);
}

.btns-6 {
	grid-template-columns: repeat(6, 1fr);
}

.align-bar button {
	padding: 5px 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.align-bar svg {
	width: 14px;
	height: 14px;
	stroke: currentColor;
	fill: none;
	stroke-width: 1.5;
}

.anchor-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 4px;
	width: 114px;
	margin: 6px auto;
	padding: 6px;
	background: var(--bg);
	border: 1px solid var(--line);
	border-radius: 5px;
}

.anchor-dot {
	height: 24px;
	padding: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: var(--surface);
}

.anchor-dot::after {
	content: '';
	width: 5px;
	height: 5px;
	border-radius: 50%;
	background: var(--muted);
}

.anchor-dot:hover::after,
.anchor-dot.active::after {
	background: currentColor;
}

.source-tabs {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 4px;
	margin-bottom: 8px;
}

.source-tabs button {
	padding: 4px 2px;
	font-size: 10.5px;
}

.status-line {
	font-size: 10.5px;
	color: var(--muted);
	margin-top: 4px;
	font-variant-numeric: tabular-nums;
}

.status-line.err {
	color: #ffffff;
	text-decoration: underline;
}

.proj-item {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 4px;
	margin-top: 4px;
}

/* ---------- Modal & Toast ---------- */
.modal-backdrop {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.72);
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 60;
}

.modal-backdrop.show {
	display: flex;
}

.modal-card {
	width: min(460px, 92vw);
	max-height: 82vh;
	overflow-y: auto;
	background: var(--panel);
	border: 1px solid var(--line-strong);
	border-radius: 6px;
	padding: 16px;
}

.modal-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 10px;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.1em;
	text-transform: uppercase;
}

.key-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 6px 14px;
	font-size: 11.5px;
}

.key-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-bottom: 1px solid var(--line);
	padding: 4px 0;
}

kbd {
	padding: 1px 5px;
	border: 1px solid var(--line-strong);
	border-radius: 3px;
	background: var(--bg);
	font-family: ui-monospace, monospace;
	font-size: 10.5px;
	color: var(--accent);
}

.toast {
	position: fixed;
	left: calc(var(--rail-w) + 12px);
	top: calc(var(--top-h) + 10px);
	padding: 6px 12px;
	background: var(--panel);
	color: var(--text);
	border: 1px solid var(--line-strong);
	border-radius: 4px;
	font-size: 11.5px;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s;
	z-index: 50;
}

.toast.show {
	opacity: 1;
}

/* ---------- Light Workstation ---------- */
.light-head {
	display: grid;
	grid-template-columns: 68px 1fr;
	gap: 10px;
	align-items: center;
	margin-bottom: 8px;
}

.matcap-sphere {
	width: 68px;
	height: 68px;
	border-radius: 50%;
	border: 1px solid var(--line-strong);
	background: #050505;
	cursor: grab;
	display: block;
}

.matcap-sphere:active {
	cursor: grabbing;
}

.light-subtabs {
	display: grid;
	grid-template-columns: repeat(5, 1fr);
	gap: 3px;
	margin: 6px 0 8px;
}

.light-subtabs button {
	padding: 4px 2px;
	font-size: 10px;
}

.emitter-bar {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin-bottom: 6px;
}

.emitter-chip {
	padding: 3px 6px;
	font-size: 10.5px;
	display: inline-flex;
	align-items: center;
	gap: 4px;
}

.emitter-chip.muted {
	opacity: 0.45;
	text-decoration: line-through;
}

.emitter-chip.neg {
	border-style: dashed;
}

.lfo-card {
	border: 1px solid var(--line);
	border-radius: 4px;
	padding: 6px 8px;
	margin-top: 6px;
	background: var(--bg);
}

.lfo-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 4px;
	margin-bottom: 4px;
}
