@import url("https://fonts.googleapis.com/css?family=Victor+Mono:700&subset=latin,latin-ext&display=swap");

:root {
	--top-panel-height: 58px;
	--ui-inset: 16px;
	--ui-surface: rgba(255, 255, 255, 0.92);
	--ui-surface-solid: #ffffff;
	--ui-text: #101828;
	--ui-accent: #175cd3;
	--ui-border: 1px solid rgba(16, 24, 40, 0.08);
	--ui-shadow: 0 4px 16px rgba(16, 24, 40, 0.1);
	--ui-backdrop: blur(12px);
	--toolbar-panel-width: 139px;
	--ui-gap: 16px;
	--navigation-shadow-space: 16px;
	--navigation-top: var(--ui-inset);
	--navigation-group-gap: 8px;
	--measurements-panel-tab-height: 72px;
	--floating-panel-top: calc(
		var(--navigation-top) + var(--top-panel-height) + var(--ui-gap)
	);
	--top-control-radius: 7px;
	--top-control-line-height: 1;
	font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	background: #f2f4f7;
	font-synthesis: none;
}

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

* {
	box-sizing: border-box;
}

.toolbar {
	position: fixed;
	top: var(--ui-inset);
	left: var(--ui-inset);
	z-index: 20;
	z-index: 1000;
	width: max-content;
	max-width: calc(100vw - (var(--ui-inset) * 2));
	height: var(--top-panel-height);
	display: flex;
	align-items: center;
	justify-content: flex-start;
	gap: 8px;
	padding: 12px 14px 12px 16px;
	border: var(--ui-border);
	border-radius: 12px;
	background: var(--ui-surface);
	box-shadow: var(--ui-shadow);
	-webkit-backdrop-filter: var(--ui-backdrop);
	backdrop-filter: blur(12px);
}

.toolbar > div {
	display: flex;
	min-width: 0;
	flex-direction: column;
	gap: 2px;
}

.brand h1 {
	margin: 0;
	color: #555555;
	font-family: "Victor Mono", monospace;
	font-size: 18px;
	font-weight: 700;
	line-height: 1;
}

.brand h1 span {
	color: #ff6600;
}

.brand h1 a {
	color: inherit;
	text-decoration: none;
}

.toolbar > .language-picker {
	position: relative;
	display: block;
	min-width: 0;
	flex: 0 0 auto;
	gap: 0;
}

.language-selector {
	display: inline-flex;
	flex: 0 0 auto;
	min-width: 44px;
	min-height: 0;
	align-items: center;
	justify-content: center;
	padding: 7px 9px;
	border: 0;
	border-radius: var(--top-control-radius);
	appearance: none;
	color: #175cd3;
	background: #eaf2ff;
	cursor: pointer;
	font-family: "Victor Mono", monospace;
	font-size: 11px;
	font-weight: 700;
	line-height: var(--top-control-line-height);
	text-align: center;
}

.language-options {
	position: absolute;
	z-index: 1001;
	top: calc(100% + 6px);
	left: 50%;
	display: grid;
	min-width: 100%;
	gap: 2px;
	margin: 0;
	padding: 4px 2px;
	border: 0;
	border-radius: var(--top-control-radius);
	background: var(--ui-surface-solid);
	box-shadow: 0 10px 24px rgba(16, 24, 40, 0.16);
	list-style: none;
	transform: translateX(-50%);
}

.language-options[hidden] {
	display: none;
}

.language-options li {
	display: contents;
}

.language-option {
	display: flex;
	width: 100%;
	min-width: 0;
	min-height: 34px;
	align-items: center;
	justify-content: center;
	padding: 8px 6px;
	border: 0;
	border-radius: calc(var(--top-control-radius) - 2px);
	color: var(--ui-text);
	background: transparent;
	cursor: pointer;
	font-family: "Victor Mono", monospace;
	font-size: 11px;
	font-weight: 700;
	line-height: 1;
	text-align: center;
}

.language-option:hover,
.language-option:focus-visible {
	outline: 0;
	color: #ff6600;
	background: #fff7ed;
}

.language-option.is-selected,
.language-option[aria-selected="true"] {
	color: #175cd3;
	background: #eaf2ff;
}

.navigation-scroll-shell {
	--navigation-marker-width: 50px;
	position: fixed;
	top: calc(var(--navigation-top) - var(--navigation-shadow-space));
	left: calc(var(--ui-inset) + var(--toolbar-panel-width) + var(--ui-gap));
	z-index: 20;
	height: calc(var(--top-panel-height) + (var(--navigation-shadow-space) * 2));
	width: calc(
		100vw - var(--ui-inset) - var(--toolbar-panel-width) -
			(var(--ui-gap) * 2)
	);
	display: flex;
	max-width: calc(
		100vw - var(--ui-inset) - var(--toolbar-panel-width) -
			(var(--ui-gap) * 2)
	);
	align-items: center;
	gap: 8px;
	min-width: 0;
	padding: 0;
	pointer-events: none;
}

.navigation-panel {
	display: flex;
	width: 100%;
	height: calc(var(--top-panel-height) + (var(--navigation-shadow-space) * 2));
	min-width: 0;
	align-items: flex-start;
	gap: var(--navigation-group-gap);
	padding-block: var(--navigation-shadow-space);
	padding-inline: 0;
	overflow-x: auto;
	scrollbar-width: none;
	-ms-overflow-style: none;
	pointer-events: auto;
	mask-image: none;
	mask-mode: alpha;
	-webkit-mask-image: none;
}

.navigation-panel::-webkit-scrollbar {
	display: none;
}

.navigation-scroll-edge {
	position: absolute;
	top: var(--navigation-shadow-space);
	bottom: var(--navigation-shadow-space);
	z-index: 2;
	display: flex;
	width: var(--navigation-marker-width);
	align-items: center;
	justify-content: center;
	padding: 0;
	color: #175cd3;
	border: 0;
	appearance: none;
	background: transparent;
	cursor: pointer;
	font: inherit;
	font-size: 18px;
	font-weight: 700;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.18s ease;
}

.navigation-scroll-edge > span {
	color: inherit;
	mix-blend-mode: normal;
}

.navigation-scroll-edge:disabled {
	cursor: default;
}

.navigation-scroll-edge--left {
	left: 0;
	justify-content: flex-start;
	padding-left: 5px;
}

.navigation-scroll-edge--right {
	right: 0;
	justify-content: flex-end;
	padding-right: 5px;
}

.navigation-scroll-shell.can-scroll-left .navigation-scroll-edge--left,
.navigation-scroll-shell.can-scroll-right .navigation-scroll-edge--right {
	opacity: 1;
	pointer-events: auto;
}

.navigation-scroll-shell.can-scroll-left:not(.can-scroll-right) .navigation-panel {
	mask-image: linear-gradient(
		to right,
		transparent 0,
		transparent 18px,
		black var(--navigation-marker-width)
	);
	-webkit-mask-image: linear-gradient(
		to right,
		transparent 0,
		transparent 18px,
		black var(--navigation-marker-width)
	);
}

.navigation-scroll-shell.can-scroll-right:not(.can-scroll-left) .navigation-panel {
	mask-image: linear-gradient(
		to right,
		black 0,
		black calc(100% - var(--navigation-marker-width)),
		transparent calc(100% - 18px),
		transparent 100%
	);
	-webkit-mask-image: linear-gradient(
		to right,
		black 0,
		black calc(100% - var(--navigation-marker-width)),
		transparent calc(100% - 18px),
		transparent 100%
	);
}

.navigation-scroll-shell.can-scroll-left.can-scroll-right .navigation-panel {
	mask-image: linear-gradient(
		to right,
		transparent 0,
		transparent 18px,
		black var(--navigation-marker-width),
		black calc(100% - var(--navigation-marker-width)),
		transparent calc(100% - 18px),
		transparent 100%
	);
	-webkit-mask-image: linear-gradient(
		to right,
		transparent 0,
		transparent 18px,
		black var(--navigation-marker-width),
		black calc(100% - var(--navigation-marker-width)),
		transparent calc(100% - 18px),
		transparent 100%
	);
}

.nav-group {
	display: flex;
	align-items: center;
	gap: 3px;
}

.nav-label {
	flex: 0 0 auto;
	padding: 7px 9px;
	color: #475467;
	font-size: 11px;
	font-weight: 600;
	line-height: var(--top-control-line-height);
}

.nav-section {
	height: var(--top-panel-height);
	flex: 0 0 auto;
	padding: 10px;
	border: var(--ui-border);
	border-radius: 12px;
	background: var(--ui-surface);
	box-shadow: var(--ui-shadow);
	-webkit-backdrop-filter: var(--ui-backdrop);
	backdrop-filter: var(--ui-backdrop);
}

.navigation-panel button {
	min-width: 24px;
	flex: 0 0 auto;
	padding: 7px 9px;
	border: 0;
	border-radius: var(--top-control-radius);
	color: #475467;
	background: transparent;
	cursor: pointer;
	font: inherit;
	font-size: 11px;
	font-weight: 600;
	line-height: var(--top-control-line-height);
}

.navigation-panel button:hover {
	color: var(--ui-accent);
	background: #f2f4f7;
}

.navigation-panel button.is-active {
	color: var(--ui-accent);
	background: #eaf2ff;
}

:where(button, a, input, select, [tabindex]):focus-visible {
	outline: 3px solid #75a7f5;
	outline-offset: 2px;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
	.toolbar {
		background: var(--ui-surface-solid);
	}
}

.touch-navigation {
	position: fixed;
	bottom: max(18px, env(safe-area-inset-bottom));
	z-index: 1000;
	display: grid;
	justify-items: center;
	gap: 9px;
	user-select: none;
}

@media (max-width: 760px) {
	:root {
		--navigation-top: calc(
			var(--ui-inset) + var(--top-panel-height) + var(--ui-gap)
		);
	}

	.navigation-scroll-shell {
		top: calc(var(--navigation-top) - var(--navigation-shadow-space));
		left: var(--ui-inset);
		width: calc(100vw - (var(--ui-inset) * 2));
		max-width: calc(100vw - (var(--ui-inset) * 2));
	}
}

@media (max-width: 520px) {
	:root {
		--ui-inset: 10px;
	}

	.toolbar {
		top: var(--ui-inset);
		left: var(--ui-inset);
		max-width: calc(100vw - (var(--ui-inset) * 2));
	}
}

.touch-navigation[data-side="left"] {
	left: max(18px, env(safe-area-inset-left));
}

.touch-navigation[data-side="right"] {
	right: max(18px, env(safe-area-inset-right));
}

#joystick-side-toggle,
.point-measurement-label {
	min-height: 32px;
	padding: 6px 10px;
	border: 1px solid rgba(218, 222, 226, 0.96);
	border-radius: 8px;
	color: #475467;
	background: rgba(242, 244, 247, 0.92);
	box-shadow: 0 4px 16px rgba(71, 84, 103, 0.14);
	font: inherit;
	font-size: 11px;
	font-weight: 650;
	touch-action: manipulation;
	backdrop-filter: blur(10px);
	cursor: pointer;
}

.point-measurement-labels {
	position: fixed;
	inset: 0;
	z-index: 10;
	pointer-events: none;
}

.point-measurement-label {
	position: absolute;
	white-space: pre-line;
	line-height: 1.35;
	cursor: default;
}

.floating-panel {
	position: fixed;
	top: var(--floating-panel-top);
	z-index: 30;
	width: max-content;
	min-width: 0;
	max-width: calc(100vw - (var(--ui-inset) * 2));
	max-height: calc(100dvh - var(--floating-panel-top) - var(--ui-inset));
	overflow: visible;
	resize: horizontal;
	padding: 0;
	border: var(--ui-border);
	background: var(--ui-surface);
	box-shadow: var(--ui-shadow);
	-webkit-backdrop-filter: var(--ui-backdrop);
	backdrop-filter: var(--ui-backdrop);
	transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.floating-panel-content {
	max-height: calc(100dvh - 110px);
	overflow: auto;
	padding: 14px;
	border-radius: inherit;
}

.floating-panel-toggle {
	position: absolute;
	top: -1px;
	z-index: 1;
	width: 32px;
	min-height: 72px;
	padding: 10px 6px;
	border: 1px solid rgba(16, 24, 40, 0.1);
	color: #475467;
	background: var(--ui-surface);
	cursor: pointer;
	font: inherit;
	font-size: 11px;
	font-weight: 650;
	letter-spacing: 0.03em;
	writing-mode: vertical-rl;
	text-orientation: mixed;
	-webkit-backdrop-filter: var(--ui-backdrop);
	backdrop-filter: var(--ui-backdrop);
}

.floating-panel-toggle:hover {
	color: var(--ui-accent);
	background: #f2f4f7;
}

.measurements-panel {
	right: var(--ui-inset);
	direction: rtl;
	border-radius: 0 12px 12px 12px;
}

.measurements-panel.is-collapsed {
	transform: translateX(calc(100% + var(--ui-inset)));
}

.measurements-panel-content {
	direction: ltr;
}

.measurements-panel-toggle {
	left: -32px;
	border-radius: 9px 0 0 9px;
	box-shadow: -3px 4px 12px rgba(16, 24, 40, 0.1);
}

.sections-panel {
	top: calc(var(--floating-panel-top) + var(--measurements-panel-tab-height));
	right: var(--ui-inset);
	direction: rtl;
	max-height: calc(
		100dvh - var(--floating-panel-top) -
			var(--measurements-panel-tab-height) - var(--ui-inset)
	);
	border-radius: 0 12px 12px 12px;
}

.sections-panel.is-collapsed {
	transform: translateX(calc(100% + var(--ui-inset)));
}

.sections-panel-content {
	direction: ltr;
	max-height: calc(
		100dvh - var(--floating-panel-top) -
			var(--measurements-panel-tab-height) - var(--ui-inset)
	);
}

.sections-panel-toggle {
	left: -32px;
	border-radius: 9px 0 0 9px;
	box-shadow: -3px 4px 12px rgba(16, 24, 40, 0.1);
}

.measurements-panel header,
.measurements-panel header > div,
.measurement-controls,
.measurement-controls label,
.sections-panel header,
.sections-panel header > div,
.sections-list li > div:first-child,
.section-controls,
.section-controls label {
	display: flex;
	align-items: center;
}

.measurements-panel header,
.sections-panel header {
	justify-content: space-between;
	gap: 12px;
}

.measurements-panel header > div,
.sections-panel header > div {
	gap: 8px;
}

.measurements-panel strong,
.sections-panel strong {
	font-size: 13px;
}

.measurement-count,
.section-count {
	min-width: 20px;
	padding: 2px 6px;
	border-radius: 999px;
	color: #344054;
	background: #eaecf0;
	font-size: 11px;
	text-align: center;
}

.text-button {
	border: 0;
	color: #b42318;
	background: transparent;
	cursor: pointer;
	font: inherit;
	font-size: 12px;
	font-weight: 600;
}

.text-button:hover,
.measurement-controls button:hover,
.section-controls button:hover {
	color: #7a271a;
}

.text-button[hidden],
.measurements-empty[hidden],
.sections-empty[hidden] {
	display: none;
}

.measurements-empty,
.sections-empty {
	margin: 14px 0 2px;
	color: #98a2b3;
	font-size: 12px;
}

.measurements-list,
.sections-list {
	display: grid;
	gap: 6px;
	margin: 12px 0 0;
	padding: 0;
	list-style: none;
}

.measurements-list:empty,
.sections-list:empty {
	display: none;
}

.measurements-list li,
.sections-list li {
	display: grid;
	gap: 10px;
	padding: 9px 10px;
	border-radius: 8px;
	background: #f2f4f7;
}

.measurements-list li.is-selected,
.sections-list li.is-selected {
	background: #fffaf5;
}

.point-measurement-label.is-highlighted {
	border-color: rgba(255, 102, 0, 0.42);
	background: rgba(255, 250, 245, 0.96);
}

.measurement-title,
.section-title {
	display: block;
	overflow: hidden;
	color: #101828;
	font-size: 12px;
	font-weight: 600;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sections-list li > div:first-child {
	min-width: 0;
	gap: 8px;
}

.section-kind {
	flex: 0 0 auto;
	color: #667085;
	font-size: 10px;
	white-space: nowrap;
}

.measurement-controls,
.section-controls {
	flex-wrap: wrap;
	gap: 8px 12px;
	padding-top: 6px;
	border-top: 1px solid #e4e7ec;
}

.measurement-controls label,
.section-controls label {
	gap: 5px;
	color: #475467;
	font-size: 11px;
	cursor: pointer;
}

.measurement-controls button,
.section-controls button {
	margin-left: auto;
	border: 0;
	color: #b42318;
	background: transparent;
	cursor: pointer;
	font: inherit;
	font-size: 11px;
	font-weight: 600;
}

.section-controls input[type="checkbox"] {
	width: 14px;
	height: 14px;
	margin: 0;
	accent-color: var(--ui-accent);
}

.touch-joystick {
	position: relative;
	width: 116px;
	height: 116px;
	border: 1px solid rgba(152, 162, 179, 0.38);
	border-radius: 50%;
	background: rgba(218, 222, 226, 0.78);
	box-shadow: 0 8px 24px rgba(71, 84, 103, 0.18);
	cursor: grab;
	touch-action: none;
	backdrop-filter: blur(10px);
}

.touch-joystick:active {
	cursor: grabbing;
}

.touch-joystick-thumb {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 48px;
	height: 48px;
	border: 1px solid rgba(152, 162, 179, 0.5);
	border-radius: 50%;
	background: rgba(242, 244, 247, 0.9);
	box-shadow: 0 2px 8px rgba(71, 84, 103, 0.2);
	transform: translate(-50%, -50%);
	pointer-events: none;
}
