:root {
	--font-family:
		system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	--font-mono:
		ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Monaco, Consolas,
		monospace;
	--color-bg: #f4f6f9;
	--color-bg-top: #f8fafc;
	--color-surface: #ffffff;
	--color-surface-muted: #f7f9fc;
	--color-surface-hover: #eef3fa;
	--color-text: #1e293b;
	--color-text-muted: #64748b;
	--color-accent: #1665d8;
	--color-accent-soft: rgba(22, 101, 216, 0.14);
	--color-danger: #b42318;
	--color-border: #d6dce7;
	--color-border-strong: #bfccdc;
	--focus-ring: 0 0 0 2px rgba(22, 101, 216, 0.22);
	--shadow-overlay: 0 14px 34px rgba(15, 23, 42, 0.14);
	--radius: 8px;
	--control: 34px;
	color-scheme: light;
}

:root[data-theme="dark"] {
	--color-bg: #0b0d10;
	--color-bg-top: #0b0d10;
	--color-surface: #121417;
	--color-surface-muted: #1a1d22;
	--color-surface-hover: #23272e;
	--color-text: #e2e8f0;
	--color-text-muted: #94a3b8;
	--color-accent: #60a5fa;
	--color-accent-soft: rgba(96, 165, 250, 0.22);
	--color-danger: #f87171;
	--color-border: #2b3038;
	--color-border-strong: #3a414d;
	--focus-ring: 0 0 0 2px rgba(96, 165, 250, 0.34);
	--shadow-overlay: 0 20px 40px rgba(2, 6, 23, 0.45);
	color-scheme: dark;
}

* {
	box-sizing: border-box;
}

html,
body {
	width: 100%;
	height: 100%;
	margin: 0;
	overflow: hidden;
}

body {
	font-family: var(--font-family);
	color: var(--color-text);
	background: linear-gradient(180deg, var(--color-bg-top), var(--color-bg));
}

button,
input,
select,
textarea {
	font: inherit;
	color: inherit;
}

button {
	cursor: pointer;
}

h2 {
	margin: 0;
	font-size: 16px;
	font-weight: 650;
}

.icon-sprite {
	position: absolute;
	width: 0;
	height: 0;
	overflow: hidden;
}

.icon {
	width: 16px;
	height: 16px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	flex: none;
	pointer-events: none;
}

.app-shell {
	position: relative;
	width: 100vw;
	height: 100vh;
}

.top-bar,
.tool-dock,
.zoom-cluster,
.context-toolbar,
.floating-menu,
.toast {
	position: fixed;
	z-index: 20;
}

.top-bar {
	top: 12px;
	left: 50%;
	width: min(1120px, calc(100vw - 24px));
	min-height: 46px;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 6px;
	border: 1px solid color-mix(in srgb, var(--color-border) 82%, transparent);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--color-surface) 88%, transparent);
	box-shadow: var(--shadow-overlay);
	backdrop-filter: blur(18px);
}

.brand-cluster,
.action-cluster,
.dialog-head,
.zoom-cluster,
.context-toolbar,
.selection-chip,
.color-group,
.font-size-control,
.line-style-control,
.route-control,
.context-actions {
	display: flex;
	align-items: center;
}

.brand-cluster {
	min-width: 0;
	flex: 1;
	gap: 10px;
}

.brand-name {
	flex: none;
	padding-left: 8px;
	font-size: 13px;
	font-weight: 650;
}

.board-title-input {
	width: min(360px, 42vw);
	min-width: 120px;
	height: 32px;
	padding: 0 10px;
	border: 1px solid transparent;
	border-radius: var(--radius);
	background: transparent;
	font-size: 14px;
	font-weight: 600;
}

.board-title-input:hover,
.board-title-input:focus {
	border-color: var(--color-border);
	background: var(--color-surface-muted);
}

.action-cluster {
	flex: none;
	gap: 5px;
}

.button,
.tool-button {
	height: var(--control);
	min-width: var(--control);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 0 10px;
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	background: var(--color-surface);
	color: var(--color-text);
}

.icon-button {
	width: var(--control);
	padding: 0;
}

.button:hover,
.tool-button:hover,
.button.is-active,
.tool-button.is-active {
	border-color: var(--color-border-strong);
	background: var(--color-accent-soft);
	color: var(--color-accent);
}

.button:disabled {
	cursor: default;
	opacity: 0.48;
}

.danger-button:hover {
	color: var(--color-danger);
	border-color: color-mix(
		in srgb,
		var(--color-danger) 42%,
		var(--color-border)
	);
}

.canvas-stage {
	position: absolute;
	inset: 0;
	background-color: var(--color-bg);
	background-image: radial-gradient(
		circle,
		color-mix(in srgb, var(--color-text-muted) 36%, transparent) 1px,
		transparent 1px
	);
	touch-action: none;
}

.canvas-stage.is-panning,
.canvas-stage[data-tool="hand"] {
	cursor: grab;
}

.canvas-stage.is-dragging,
.canvas-stage.is-panning:active {
	cursor: grabbing;
}

.canvas-stage[data-tool="draw"] {
	cursor: crosshair;
}

.canvas-svg {
	width: 100%;
	height: 100%;
	display: block;
	user-select: none;
}

.diagram-element {
	cursor: default;
}

.element-outline {
	display: none;
	pointer-events: none;
	fill: none;
	stroke: var(--color-accent);
	stroke-width: 1.5;
	stroke-dasharray: 5 4;
	vector-effect: non-scaling-stroke;
}

.line-selection-path {
	pointer-events: none;
	fill: none;
	stroke: var(--color-accent);
	stroke-width: 8;
	stroke-linecap: round;
	stroke-linejoin: round;
	opacity: 0.28;
	vector-effect: non-scaling-stroke;
}

.line-selection-core {
	pointer-events: none;
	fill: none;
	stroke: var(--color-accent);
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	opacity: 0.95;
	vector-effect: non-scaling-stroke;
}

.diagram-element.is-selected .element-outline {
	display: block;
}

.resize-handle,
.arrow-handle {
	fill: var(--color-surface);
	stroke: var(--color-accent);
	stroke-width: 1.6;
	vector-effect: non-scaling-stroke;
	cursor: nwse-resize;
}

.arrow-handle {
	cursor: grab;
}

.selection-marquee {
	fill: rgba(22, 101, 216, 0.08);
	stroke: var(--color-accent);
	stroke-width: 1.4;
	stroke-dasharray: 6 4;
	vector-effect: non-scaling-stroke;
}

.connection-hint {
	fill: var(--color-surface);
	stroke: var(--color-accent);
	stroke-width: 2;
	vector-effect: non-scaling-stroke;
}

.connection-target {
	fill: rgba(22, 101, 216, 0.08);
	stroke: var(--color-accent);
	stroke-width: 1.5;
	stroke-dasharray: 5 4;
	vector-effect: non-scaling-stroke;
}

.element-text {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 12px;
	color: var(--element-text-color);
	font-size: var(--element-font-size);
	font-weight: 650;
	line-height: 1.22;
	text-align: center;
	overflow: hidden;
	overflow-wrap: anywhere;
	pointer-events: none;
}

.element-text.is-free-text {
	justify-content: flex-start;
	align-items: flex-start;
	padding: 0;
	font-weight: 650;
	text-align: left;
}

.element-text.is-comment {
	justify-content: flex-start;
	align-items: flex-start;
	padding: 0;
	font-size: var(--element-font-size);
	font-weight: 500;
	text-align: left;
}

.element-text.is-arrow-label {
	padding: 4px;
	text-align: center;
}

.arrow-label-hitbox {
	cursor: grab;
	pointer-events: all;
}

.tool-dock {
	left: 50%;
	bottom: 18px;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 6px;
	border: 1px solid color-mix(in srgb, var(--color-border) 82%, transparent);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--color-surface) 90%, transparent);
	box-shadow: var(--shadow-overlay);
	backdrop-filter: blur(18px);
}

.dock-separator {
	width: 1px;
	height: 22px;
	margin: 0 3px;
	background: var(--color-border);
}

.zoom-cluster {
	right: 16px;
	bottom: 18px;
	gap: 5px;
	padding: 6px;
	border: 1px solid color-mix(in srgb, var(--color-border) 82%, transparent);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--color-surface) 90%, transparent);
	box-shadow: var(--shadow-overlay);
	backdrop-filter: blur(18px);
}

.zoom-readout {
	width: 62px;
	font-variant-numeric: tabular-nums;
	font-size: 12px;
	font-weight: 650;
}

.context-toolbar {
	top: 70px;
	left: 50%;
	transform: translateX(-50%);
	max-width: min(1120px, calc(100vw - 24px));
	gap: 12px;
	padding: 0;
	border: 0;
	background: transparent;
	box-shadow: none;
	backdrop-filter: none;
	overflow-x: auto;
	pointer-events: none;
}

.context-toolbar[hidden] {
	display: none;
}

.text-edit-button {
	font-weight: 800;
}

.context-separator {
	display: none;
}

.color-group,
.font-size-control,
.line-style-control,
.route-control,
.context-actions {
	flex: none;
	gap: 7px;
}

.selection-chip,
.color-group,
.font-size-control,
.line-style-control,
.route-control,
.context-actions {
	min-height: 40px;
	padding: 5px 10px;
	border: 1px solid color-mix(in srgb, var(--color-border) 76%, transparent);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--color-surface) 92%, transparent);
	box-shadow: var(--shadow-overlay);
	backdrop-filter: blur(18px);
	pointer-events: auto;
}

.export-menu {
	display: grid;
	gap: 6px;
	padding: 6px;
	border: 1px solid color-mix(in srgb, var(--color-border) 76%, transparent);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--color-surface) 94%, transparent);
	box-shadow: var(--shadow-overlay);
	backdrop-filter: blur(18px);
}

.export-menu[hidden] {
	display: none;
}

.menu-button {
	min-width: 74px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: flex-start;
	padding: 0 10px;
	border: 1px solid transparent;
	border-radius: var(--radius);
	background: transparent;
	color: var(--color-text);
	text-align: left;
	font-size: 12px;
	font-weight: 800;
	letter-spacing: 0;
}

.menu-button:hover {
	border-color: var(--color-border);
	background: var(--color-accent-soft);
	color: var(--color-accent);
}

.color-group-icon {
	width: 22px;
	height: 22px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: var(--color-text-muted);
	font-size: 13px;
	font-weight: 800;
}

.fill-icon,
.stroke-icon {
	border: 2px solid currentColor;
	border-radius: var(--radius);
}

.fill-icon {
	background: linear-gradient(135deg, #fde68a 0 50%, #dbeafe 50%);
}

.stroke-icon {
	background: transparent;
}

.text-color-icon {
	border-bottom: 3px solid currentColor;
	line-height: 1;
}

.font-size-input {
	width: 54px;
	height: var(--control);
	padding: 0 4px;
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	background: var(--color-surface);
	text-align: center;
	font-size: 12px;
	font-weight: 700;
}

.line-style-button {
	width: 42px;
	padding: 0 8px;
}

.line-style-preview {
	width: 24px;
	height: 0;
	border-top: 3px solid currentColor;
	border-radius: 999px;
}

.dashed-preview {
	border-top-style: dashed;
}

.swatch {
	width: 26px;
	height: 26px;
	flex: none;
	padding: 0;
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	background: var(--swatch);
}

.stroke-swatch {
	background:
		linear-gradient(var(--swatch), var(--swatch)) center / 18px 3px no-repeat,
		var(--color-surface);
}

.no-fill-swatch {
	position: relative;
	background:
		linear-gradient(135deg, transparent 0 44%, #ef4444 44% 56%, transparent 56%),
		var(--color-surface);
}

.text-swatch {
	position: relative;
	background: var(--color-surface);
}

.text-swatch::after {
	position: absolute;
	left: 6px;
	right: 6px;
	bottom: 5px;
	height: 4px;
	border-radius: 999px;
	background: var(--swatch);
	content: "";
}

.swatch:hover {
	border-color: var(--color-border-strong);
	box-shadow: var(--focus-ring);
}

.swatch.is-active {
	border-color: color-mix(
		in srgb,
		var(--color-accent) 64%,
		var(--color-border)
	);
	box-shadow: var(--focus-ring);
}

.line-style-button.is-active {
	border-color: color-mix(
		in srgb,
		var(--color-accent) 64%,
		var(--color-border)
	);
	background: var(--color-accent-soft);
	color: var(--color-accent);
	box-shadow: var(--focus-ring);
}

.custom-color {
	width: 26px;
	height: 26px;
	position: relative;
	display: inline-flex;
	overflow: hidden;
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	background:
		linear-gradient(
			45deg,
			transparent 0 46%,
			currentColor 46% 54%,
			transparent 54%
		),
		conic-gradient(#ef4444, #f59e0b, #10b981, #3b82f6, #8b5cf6, #ef4444);
	color: var(--color-text-muted);
	cursor: pointer;
}

.custom-color input {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	cursor: pointer;
}

.inline-editor {
	position: fixed;
	z-index: 40;
	display: none;
	padding: 10px;
	border: 2px solid var(--color-accent);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--color-surface) 96%, transparent);
	color: var(--color-text);
	box-shadow: var(--shadow-overlay);
	line-height: 1.25;
	pointer-events: auto;
	resize: none;
	touch-action: auto;
	user-select: text;
	-webkit-user-select: text;
}

.inline-editor.is-open {
	display: block;
}

.side-dialog {
	width: min(360px, calc(100vw - 24px));
	max-height: calc(100vh - 36px);
	margin: 18px 18px 18px auto;
	padding: 12px;
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	background: var(--color-surface);
	color: var(--color-text);
	box-shadow: var(--shadow-overlay);
}

.side-dialog::backdrop {
	background: rgba(15, 23, 42, 0.18);
}

.dialog-head {
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 12px;
}

.board-list {
	display: grid;
	gap: 8px;
}

.board-row {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: 8px;
	padding: 8px;
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	background: var(--color-surface-muted);
}

.board-row[data-active="true"] {
	border-color: color-mix(
		in srgb,
		var(--color-accent) 44%,
		var(--color-border)
	);
	background: var(--color-accent-soft);
}

.board-open {
	min-width: 0;
	border: 0;
	background: transparent;
	text-align: left;
}

.board-name {
	display: block;
	overflow: hidden;
	color: var(--color-text);
	font-size: 13px;
	font-weight: 700;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.board-meta {
	display: block;
	margin-top: 3px;
	color: var(--color-text-muted);
	font-size: 11px;
}

.board-actions {
	display: flex;
	gap: 4px;
}

.toast {
	left: 50%;
	bottom: 76px;
	transform: translateX(-50%);
	max-width: min(460px, calc(100vw - 32px));
	padding: 8px 12px;
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	background: var(--color-surface);
	box-shadow: var(--shadow-overlay);
	color: var(--color-text);
	font-size: 13px;
	opacity: 0;
	pointer-events: none;
	transition: opacity 140ms ease;
}

.toast.is-visible {
	opacity: 1;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
	outline: none;
	box-shadow: var(--focus-ring);
}

button[hidden],
input[hidden],
textarea[hidden],
.selection-chip[hidden],
.line-style-control[hidden],
.context-toolbar[hidden],
.route-control[hidden],
.export-menu[hidden] {
	display: none;
}

@media (max-width: 760px) {
	.brand-name,
	#theme-btn {
		display: none;
	}

	.top-bar {
		align-items: stretch;
	}

	.tool-dock {
		max-width: calc(100vw - 24px);
		overflow-x: auto;
	}

	.context-toolbar {
		top: 66px;
		justify-content: flex-start;
	}

	.zoom-cluster {
		bottom: 76px;
	}
}
