@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&display=swap');

#codePanel,
#tutorial {
	--black: #333;
	--white: #f5f5f5;
	--bg: #222;
	--grey-light: #999;
	--grey: #5e5e5e;
	--grey-dark: #4d4d4d;
	--blue-light: #b7e8fe;
	--blue-op: #73c1e8;
	--blue: #0088dd;
	--blue-dark: #006eb2;
	--pink: #ed7b7b;
	--selection: #bee9ff;
	--selection-match: hsl(199 44% 90% / 1);
	--salmon: #f8d7d6;
	--green: #009424;
	--salmon: #bb7f42;
	--p5js-color: #DA3B73;

	/* CodeMirror tag-based color variables */
	--cm-comment: var(--grey8);
	--cm-blockComment: var(--grey);
	--cm-variableName: inherit;
	--cm-string: var(--blue);
	--cm-number: var(--blue);
	--cm-bool: var(--blue);
	--cm-propertyName: inherit;
	--cm-null: var(--pink);
	--cm-keyword: var(--salmon);
	--cm-bracket: var(--salmon);
	--cm-function: var(--green);
	--cm-separator: var(--grey);
	--cm-punctuation: var(--grey);
	--cm-typeName: var(--blue);
	--cm-tagName: var(--green);
	/*html tags*/
	--cm-attributeName: var(--salmon);
	/*html attributes*/
}


/* Code Control Mode when Alt key is pressed */
#codePanel.codeControl .cmt-p5js,
#codePanel.codeControl .cmt-number {
	cursor: pointer;
	text-decoration: underline;
	text-decoration-style: dotted;
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
}

/* p5.js syntax highlighting */
#codePanel.codeControl .cmt-p5js * {
	color: var(--p5js-color) !important;
}

#codePanel.codeControl .cmt-p5js:hover *,
#codePanel.codeControl .cmt-number:hover  {
	text-decoration-style: solid;
}
#codePanel.codeControl .cmt-number:hover {
	cursor: col-resize;	
}

#codemirror {
	overflow: hidden;
	width: 100%;
	height: 100%;
	position: relative;
	/* needed for absolutely positioned .cm-panels-top */
	display: flex;
	flex-direction: column;
}


.cm-content {
	font-family: "Fira Code", monospace;
	font-optical-sizing: auto;
	font-weight: 400;
	font-style: normal;
	tab-size: 3 !important;
	line-height: 1.4;

}

#codePanel .cm-line span {
	transition: color 200ms;
}

#codemirror.readOnly::after {
	background-color: #eee6;
	content: '';
	position: absolute;
	width: 100%;
	height: 100%;
	z-index: 5;
	pointer-events: none;
}

#codemirror .cm-scroller {
	/* Standard scrollbars when needed */
	overscroll-behavior: contain;
	/* Prevent page scroll chaining */
	-webkit-overflow-scrolling: touch;
	/* Smooth momentum on iOS */
	height: 100%;
	min-height: 100%;
}

#codemirror .cm-editor {
	height: 100%;
}

#codemirror .cm-line {
	/* horizontal padding */
	padding: 0px 30px 0px 0px;
	padding-right: 30px;
	overflow: hidden;
}

#codemirror .cm-content {
	/* vertical padding */
	padding-top: 15px;
	padding-bottom: 120px;
}

#codemirror .cm-gutters {
	/* background-color: #f5f5f5; */
	border: none;
	background-color: transparent !important;
	z-index: 2;
	padding-right: 7px;
	color: #aaa;
	padding-left: 0;
	font-size: 14px;

}

#codemirror .cm-gutters::after {
	content: "";
	position: absolute;
	top: 0;
	left: 0;
	width: calc(100% - 6px);
	height: 100%;
	background-color: #f5f5f5ee;
	backdrop-filter: blur(10px);
	/* -webkit-mask-image: linear-gradient(to right, black, black, transparent); */
	/* mask-image: linear-gradient(to right, black, black, transparent); */
}

#codemirror .cm-gutter {
	z-index: 1;
}

#codemirror .cm-activeLineGutter {
	background-color: var(--greyD);
}

#codemirror .cm-activeLine {
	background-color: transparent !important;
}

.cm-gutter-lint {
	width: 5px !important;
}

.cm-gutterElement {
	display: flex;
	align-items: center;
}

.cm-gutterElement span[title="Fold line"] {
	margin-top: -7px;
}

.cm-gutter.cm-comment-gutter {
	min-width: 24px;
	align-items: center;
}


#codemirror .cm-gutter-lint .cm-gutterElement {
	padding: 0;
	;
}

#codemirror .cm-lintRange {
	/* border-bottom: 1px solid #a00; */
	background-image: none;
}

#codemirror .cm-lintRange>* {
	border-bottom: 1px solid #a005;
	transition: border-color 200ms;
	/* background-image: none; */
}

#codemirror .cm-lintRange:hover>* {
	border-bottom: 1px solid #a00;
	/* background-image: none; */
}


#codemirror .cm-gutter-lint .cm-lint-marker {
	width: 5px;
	height: 100%;
	content: none;
	background-color: transparent;
	/* transition n/a since marker is removed  */
	transition: background-color 0.8s;
	cursor: pointer;
}

#codemirror .cm-gutter-lint .cm-lint-marker-error {
	background-color: #f54949;
}

#codemirror .cm-gutter-lint .cm-lint-marker-warning {
	background-color: #ecff3e;
}


#codemirror .cm-gutter-lint .cm-lint-marker-info {

	background-color: #73C1E8;

}

/* CodeMirror v6 UI Elements */

/* Place the CM6 panels at the top as a floating container */
#app.layout_split #codemirror .cm-panels-top {
	position: absolute;
	top: 15px !important;
	right: 10px !important;
}

#codemirror .cm-panels-top {
	position: fixed;
	top: 95px !important;
	right: 10px;
	width: auto;
	border: none;
	border-radius: 0;
	background: transparent;
	z-index: 1000;
	/* ensure it doesn't reserve space in layout */
	left: auto;
	bottom: auto;
	display: flex;
	flex-direction: column;
	pointer-events: auto;
	transition: right 400ms;
}

#app.showCodeOptions #codemirror .cm-panels-top {
	right: 310px;
}

/* Search Panel - Custom Simplified Design (Dark Theme) */
#codemirror .cm-search {
	background: #2a2a2a;
	border: none;
	border-radius: 15px;
	padding: 0 7px;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
	display: flex;
	align-items: center;
	column-gap: 12px;
	flex-wrap: wrap;
	position: relative;
	flex-direction: row;
	width: 280px;
}

#app.fullscreen #codemirror .cm-panels-top {
	top: 45px !important;
}

/* Hide the "all" button completely */
#codemirror .cm-search button[name="select"] {
	display: none !important;
}

/* Input fields styling */
#codemirror .cm-search input[type="text"],
#codemirror .cm-search .cm-textfield {
	border-color: transparent;
	background: transparent;
	color: var(--white);
	font-family: inherit;
	font-size: 16px;
	width: 166px;
	outline: none;
	padding: 7px 0px;
	flex: 0 0 auto;
	margin: 0;
}


/* Circular icon buttons */
#codemirror .cm-search button {
	background: transparent;
	border: none;
	border-radius: 15px;
	width: 21px;
	height: 21px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: all 0.2s ease;
	font-size: 0;
	position: relative;
}

#codemirror .cm-search button:focus {
	/* box-shadow: 0 0 5px var(--OP-blue); */
	outline: 2px solid var(--OP-blue) !important;
}

#codemirror .cm-search button {
	position: relative;
}

#codemirror .cm-search button:hover {
	background: #333;
	border-color: #666;
	/* transform: translateY(-1px); */
}

#codemirror .cm-search button:hover::after,
#codemirror .cm-search button:focus::after {
	content: attr(title);
	position: absolute;
	bottom: calc(100% + 6px);
	left: 50%;
	transform: translateX(-50%);
	background: var(--grey2);
	color: #fff;
	padding: 6px 10px;
	border-radius: 4px;
	font-size: 12px;
	white-space: nowrap;
	pointer-events: none;
	z-index: 1000;
	animation: tooltipFadeIn 0.2s ease-in-out;
	text-transform: initial;
	font-size: 0.85rem;
}

@keyframes tooltipFadeIn {
	from {
		opacity: 0;
		transform: translateX(-50%) translateY(-4px);
	}

	to {
		opacity: 1;
		transform: translateX(-50%) translateY(0);
	}
}

/* Icon content for buttons using pseudo-elements */
#codemirror .cm-search button[name="next"]::before {
	content: "";
	background: url('../../img/icons/caret_down_circle_white.svg') center center no-repeat;
	width: 21px;
	height: 21px;
}

#codemirror .cm-search button[name="prev"]::before {
	content: "";
	background: url('../../img/icons/caret_up_circle_white.svg') center center no-repeat;
	width: 21px;
	height: 21px;
}

#codemirror .cm-search button[name="replace"]::before {
	content: "";
	background: url('../../img/icons/replace_circle_white.svg') center center no-repeat;
	width: 21px;
	height: 21px;
}

#codemirror .cm-search button[name="replaceAll"]::before {
	content: "";
	background: url('../../img/icons/replaceAll_circle_white.svg') center center no-repeat;
	width: 21px;
	height: 21px;
}

#codemirror .cm-search button[name="close"] {
	display: none;
}

/* Settings (options) button */
/* Settings (options) button */
#codemirror .cm-search button[name="options"] {
	background: url('../../img/icons/settings_circle_white.svg') center center no-repeat;
	width: 21px;
	height: 21px;
	display: block;
}

/* Hide extra option labels by default; show when toggled */
#codemirror .cm-search:not(.options-visible) label {
	/* Aa, .*, \b */
	display: none !important;
}

#codemirror .cm-search.options-visible label {
	display: inline-block !important;
}

#codemirror .cm-search.options-visible button[name="options"] {
	background-image: url('../../img/icons/settings_circle_blue.svg');
}

/* Checkbox labels styling */
#codemirror .cm-search label {
	color: #f5f5f5;
	font-size: 12px;
	margin: 4px 0px;
	display: inline-block;
	cursor: pointer;
	user-select: none;
	background: var(--grey5);
	padding: 4px 8px;
	border-radius: 15px;
	flex: 1 0 auto;
	text-align: center;
}

#codemirror .cm-search label input[type="checkbox"] {
	display: none;
}

#codemirror .cm-search label:has(input[type="checkbox"]:checked) {
	background: var(--blue-op);
}

/* Line break handling */
#codemirror .cm-search br {
	display: none;
}

/* Responsive layout adjustments */
#codemirror .cm-search {
	flex-direction: row;
	justify-content: flex-start;
	/* width: 280px; */
}

/* Search matches */
#codemirror .cm-searchMatch {
	background-color: var(--selection-match) !important;
	box-shadow: 0 0 0 1px inset var(--selection-match);
}

#codemirror .cm-searchMatch-selected {
	background-color: var(--selection) !important;
	box-shadow: 0 0 0 1px inset var(--grey6);
}

#codemirror .cm-selectionBackground {
	background-color: var(--greyD);
	transition: background-color 400ms;
}

#codemirror .cm-focused .cm-selectionBackground {
	background-color: var(--selection) !important;
}

#codemirror .cm-selectionMatch {
	background-color: var(--selection-match) !important;
}

#codemirror .cm-matchingBracket {
	/* background-color: var(--blue-light) !important; */
	background-color: transparent;
}

#codemirror .cm-matchingBracket * {
	color: var(--black);
	font-weight: 700 !important;
}

/* Tooltips */
#codemirror .cm-tooltip {
	background: #222c;
	backdrop-filter: blur(5px);
	color: #fff;
	border: 1px solid #555;
	border-radius: 4px;
	padding: 4px 8px;
	font-size: 15px;
}

/* Autocomplete */
#codemirror .cm-tooltip-autocomplete {
	padding: 0;
	overflow: hidden;
	border-radius: 5px;
	/* border-radius: 0 15px 15px 15px; */
	max-width: 90%;
	border-width: 1px 1px 1px 0;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#codemirror .cm-tooltip-autocomplete li {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 5px 5px 5px 2px;
	flex-wrap: wrap;
	border-left: 3px solid transparent;
	column-gap: 5px;
}

#codemirror .cm-tooltip-autocomplete ul li[aria-selected] {
	background-color: #222;
	border-left: 3px solid var(--OP-blue);
}

#codemirror .cm-tooltip-autocomplete .cm-completionIcon {
	padding-right: 0px;
}

#codemirror .cm-completionLabel,
#codemirror .cm-completionDetail {
	color: var(--white);
	font-size: 0.9em;
	flex: 1 1 auto;
}

#codemirror .cm-completionDetail {
	color: #9e9e9e;
	font-style: italic;
	margin-left: 0;
	text-align: right;
	overflow: hidden;
	text-overflow: ellipsis;
}

#codemirror .cm-tooltip-autocomplete li:has(.cm-completionIcon-documentation) {
	border-top: 1px solid var(--grey2);
	padding-top: 15px;
	font-family: 'Dosis', sans-serif;
	font-size: 1rem;
}

#codemirror .cm-tooltip-autocomplete li:has(.cm-completionIcon-documentation) .cm-completionLabel {
	font-size: 1em;
	font-weight: bold;
}

#codemirror .cm-tooltip-autocomplete li:has(.cm-completionIcon-documentation) .cm-completionMatchedText {
	text-decoration: none !important;
}

#codemirror .cm-tooltip-autocomplete li:has(.cm-completionIcon-documentation) .cm-completionDetail {
	/* background: var(--p5js-color); */
	color: var(--p5js-color);
	font-style: normal;
	/* margin-left: 15px; */
}

#codemirror .cm-completionIcon-documentation::before {
	content: "i";
}

#codemirror .completion-arrow {
	text-align: right;
}

#codemirror .completion-description {
	flex: 1 0 100%;
	padding: 5px 20px;
	white-space: normal;
}

#codemirror .cm-ySelectionInfo {
	font-size: .9em;
	font-family: "Dosis", Helvetica, sans-serif;
	/* opacity: 1; */
	padding: 2px 4px;
	transform: translateY(-5px);
	border-radius: 0 5px 5px 0px;
}

#codemirror .cm-yLineSelection {
	margin-left: 0px;
}

#codemirror .cmt-lineComment {
	transition: color 200ms;
}

#codemirror .cmt-lineComment:hover,
#codemirror .cm-activeLine .cmt-lineComment {
	color: var(--grey3) !important;
}

#themeOptions .colorPickerRow:hover {
	/* background-color: rgba(255, 255, 255, 0.05); */
}

#themeOptions .colorPickerRow label {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

#themeOptions input[type="color"] {
	cursor: pointer;
	border-radius: 4px;
	transition: transform 0.2s, box-shadow 0.2s;
}

#themeOptions input[type="color"]:hover {
	transform: scale(1.05);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#themeOptions input[type="color"]::-webkit-color-swatch-wrapper {
	padding: 2px;
}

#themeOptions input[type="color"]::-webkit-color-swatch {
	border: none;
	border-radius: 3px;
}

#customThemeColors {
	max-height: 400px;
	overflow-y: auto;
	padding-right: 5px;
	display: flex;
	flex-direction: column;
	gap: 5px;
}

#customThemeColors::-webkit-scrollbar {
	width: 8px;
}

#customThemeColors::-webkit-scrollbar-track {
	background: rgba(255, 255, 255, 0.05);
	border-radius: 4px;
}

#customThemeColors::-webkit-scrollbar-thumb {
	background: rgba(255, 255, 255, 0.2);
	border-radius: 4px;
}

#customThemeColors::-webkit-scrollbar-thumb:hover {
	background: rgba(255, 255, 255, 0.3);
}

#customThemeColors input[type="color"] {
	width: 30px;
	height: 30px;
	border: 1px solid #555;
	border-radius: 5px;
	cursor: pointer;
	background: transparent;
	padding: 0;
}

@media (max-width: 768px) {
	#codemirror .cm-gutters {
		position: relative !important;
	}

}