/*
 * Rust Electricity Simulator. Builds on tools.css (tokens --t-*).
 */

.bgl-tool--wide {
	max-width: none;
}

.bgl-elec {
	--ce-h: clamp(560px, 74vh, 900px);
	position: relative;
	background: var(--t-panel);
	border: 1px solid var(--t-line);
	user-select: none;
	-webkit-user-select: none;
}

.bgl-elec:not(.is-ready) {
	min-height: 300px;
}

/* toolbar */

.ce-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px 16px;
	padding: 10px 12px;
	background: #20201e;
	border-bottom: 1px solid var(--t-line);
}

.ce-bar__g {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 10px;
}

.ce-bar__env label,
.ce-speed {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: var(--t-dim);
	font-size: 13px;
	text-transform: uppercase;
	letter-spacing: .04em;
}

.ce-bar__env img {
	width: 22px;
	height: 22px;
}

.ce-bar__env input[type="range"] {
	width: 110px;
	accent-color: var(--t-gold);
}

.ce-bar__env output {
	min-width: 38px;
	color: #fff;
	font-size: 13px;
}

.ce-clock {
	color: var(--t-dim);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}

.ce-b,
.ce-sel,
.ce-speed select {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 34px;
	padding: 0 12px;
	border: 0;
	background: var(--t-slot);
	color: var(--t-text);
	font-family: inherit;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: .03em;
	text-transform: uppercase;
	cursor: pointer;
}

.ce-speed select {
	padding: 0 6px;
}

.ce-b:hover,
.ce-sel:hover {
	background: var(--t-slot-hi);
	color: #fff;
}

.ce-b--play {
	min-width: 78px;
	justify-content: center;
	background: var(--t-slot);
}

.ce-b--play.is-on {
	background: var(--t-green);
	color: #fff;
}

.ce-b.is-danger:hover {
	background: #6b2219;
}

.ce-file {
	position: relative;
	overflow: hidden;
	margin: 0;
	line-height: 34px;
}

.ce-file input {
	position: absolute;
	inset: 0;
	opacity: 0;
	cursor: pointer;
}

/* three columns */

.ce-main {
	display: grid;
	grid-template-columns: 250px minmax(0, 1fr) 290px;
	height: var(--ce-h);
}

.ce-pal,
.ce-insp {
	overflow-y: auto;
	background: #191918;
	scrollbar-width: thin;
	scrollbar-color: #444 transparent;
}

.ce-pal {
	border-right: 1px solid var(--t-line);
}

.ce-insp {
	padding: 14px;
	border-left: 1px solid var(--t-line);
}

.ce-pal__head {
	position: sticky;
	top: 0;
	z-index: 2;
	padding: 10px;
	background: #191918;
}

.ce-pal__head input {
	width: 100%;
	height: 34px;
	padding: 0 10px;
	border: 1px solid #333;
	background: #121211;
	color: var(--t-text);
	font-family: inherit;
	font-size: 14px;
}

.ce-pal details {
	border-top: 1px solid var(--t-line);
}

.ce-pal summary {
	padding: 9px 12px;
	color: var(--t-gold);
	font-size: 12px;
	font-weight: 700;
	letter-spacing: .08em;
	text-transform: uppercase;
	cursor: pointer;
	list-style: none;
}

.ce-pal summary::-webkit-details-marker {
	display: none;
}

.ce-pal summary::after {
	content: "▾";
	float: right;
	color: var(--t-dim);
}

.ce-pal details:not([open]) summary::after {
	content: "▸";
}

.ce-pal__grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 4px;
	padding: 0 8px 10px;
}

.ce-part {
	position: relative;
	display: grid;
	justify-items: center;
	gap: 2px;
	padding: 6px 2px 5px;
	border: 1px solid transparent;
	background: var(--t-slot);
	color: var(--t-text);
	font-family: inherit;
	font-size: 10.5px;
	line-height: 1.15;
	text-align: center;
	cursor: grab;
	touch-action: none;
}

.ce-part:hover {
	background: var(--t-slot-hi);
	border-color: rgba(207, 156, 66, .4);
}

.ce-part img {
	width: 44px;
	height: 44px;
	object-fit: contain;
	pointer-events: none;
}

.ce-part span {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	min-height: 2.3em;
	pointer-events: none;
}

.ce-part em {
	position: absolute;
	top: 3px;
	right: 3px;
	color: #b9cf8e;
	font-size: 10px;
	font-style: normal;
	font-weight: 700;
	pointer-events: none;
}

.ce-pal__tip {
	margin: 0;
	padding: 10px 12px 14px;
	color: var(--t-dim);
	font-size: 12px;
	line-height: 1.4;
}

.ce-ghost {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 100000;
	width: 48px;
	height: 48px;
	pointer-events: none;
	filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .6));
}

.ce-ghost img {
	width: 48px;
	height: 48px;
}

/* board */

.ce-board {
	position: relative;
	overflow: hidden;
	background-color: #141413;
	background-image:
		linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
		linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
	cursor: grab;
	touch-action: none;
	outline: none;
}

.ce-board.is-panning {
	cursor: grabbing;
}

.ce-world {
	position: absolute;
	top: 0;
	left: 0;
	width: 1px;
	height: 1px;
	transform-origin: 0 0;
}

.ce-wires {
	position: absolute;
	top: 0;
	left: 0;
	width: 1px;
	height: 1px;
	overflow: visible !important; /* the theme clips every svg */
}

.ce-bar select,
.ce-bar input[type="range"] {
	width: auto !important;
	max-width: none;
	min-width: 0;
	margin: 0;
}

.ce-bar select {
	height: 34px !important;
	padding: 0 28px 0 10px !important;
	border: 0 !important;
	border-radius: 0 !important;
	background-color: var(--t-slot) !important;
	color: var(--t-text) !important;
	font-size: 13px !important;
	line-height: 34px !important;
}

.ce-w__hit {
	fill: none;
	stroke: transparent;
	stroke-width: 14;
	cursor: pointer;
	pointer-events: stroke;
}

.ce-w__line {
	fill: none;
	stroke-width: 3;
	opacity: .45;
	pointer-events: none;
	stroke-linecap: round;
}

.ce-w.is-live .ce-w__line {
	opacity: 1;
	filter: drop-shadow(0 0 3px currentColor);
}

.ce-w__flow {
	fill: none;
	stroke: rgba(255, 255, 255, .75);
	stroke-width: 1.6;
	stroke-dasharray: 3 14;
	pointer-events: none;
	animation: ce-flow 0.9s linear infinite;
}

@keyframes ce-flow {
	to {
		stroke-dashoffset: -17;
	}
}

.ce-w.is-sel .ce-w__line {
	stroke-width: 5;
	opacity: 1;
}

.ce-w text {
	fill: #ece6de;
	font-size: 11px;
	font-weight: 700;
	text-anchor: middle;
	paint-order: stroke;
	stroke: #141413;
	stroke-width: 3px;
	pointer-events: none;
}

.ce-w:not(.is-live) text {
	fill: #6f6a64;
}

.ce-w__ghost {
	fill: none;
	stroke: var(--t-gold);
	stroke-width: 2.5;
	stroke-dasharray: 6 6;
	pointer-events: none;
}

/* node */

.ce-node {
	position: absolute;
	min-width: 180px;
	max-width: 240px;
	background: #262624;
	border: 1px solid #3a3a37;
	box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
	color: var(--t-text);
	font-size: 12px;
	cursor: move;
	touch-action: none;
}

.ce-node.is-sel {
	border-color: var(--t-gold);
	box-shadow: 0 0 0 1px var(--t-gold), 0 6px 18px rgba(0, 0, 0, .5);
}

.ce-node__head {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 8px;
	background: #1d1d1b;
	border-bottom: 1px solid #3a3a37;
	border-left: 3px solid #4b4843;
}

.ce-node.is-live .ce-node__head {
	border-left-color: #8fb94b;
}

.ce-node__head img {
	width: 34px;
	height: 34px;
	object-fit: contain;
	pointer-events: none;
}

.ce-node__head b {
	flex: 1;
	font-size: 12.5px;
	line-height: 1.15;
	text-transform: uppercase;
	letter-spacing: .02em;
}

.ce-node__head em {
	color: #b9cf8e;
	font-size: 11px;
	font-style: normal;
	font-weight: 700;
	white-space: nowrap;
}

.ce-node__io {
	display: flex;
	justify-content: space-between;
	gap: 6px;
	padding: 6px 0;
}

.ce-ports {
	display: grid;
	gap: 4px;
	align-content: start;
}

.ce-port {
	display: flex;
	align-items: center;
	gap: 5px;
	min-height: 20px;
	color: var(--t-dim);
	font-size: 11px;
	cursor: crosshair;
	white-space: nowrap;
}

.ce-port i {
	flex: 0 0 auto;
	width: 13px;
	height: 13px;
	border: 2px solid #6a655f;
	border-radius: 50%;
	background: #151514;
	transition: background .15s, border-color .15s, transform .15s;
}

.ce-port--in i {
	margin-left: -7px;
}

.ce-port--out {
	justify-content: flex-end;
}

.ce-port--out i {
	margin-right: -7px;
}

.ce-port b {
	min-width: 14px;
	color: #6f6a64;
	font-size: 11px;
}

.ce-port.is-live b {
	color: #fff;
}

.ce-port.is-wired i {
	border-color: #bdb6ad;
}

.ce-port.is-live i {
	border-color: #8fb94b;
	background: #8fb94b;
	box-shadow: 0 0 6px #8fb94b;
}

.ce-port:hover i {
	transform: scale(1.35);
	border-color: var(--t-gold);
}

.ce-port.is-pending i {
	border-color: var(--t-gold);
	background: var(--t-gold);
	box-shadow: 0 0 8px var(--t-gold);
}

.is-wiring .ce-port--in i {
	border-color: var(--t-gold);
	animation: ce-pulse 1s ease-in-out infinite;
}

@keyframes ce-pulse {
	50% {
		transform: scale(1.3);
	}
}

.ce-node__foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 5px;
	padding: 0 8px 7px;
}

.ce-node__foot:empty {
	display: none;
}

.ce-node__foot small {
	color: var(--t-dim);
	font-size: 11px;
}

.ce-tog {
	padding: 4px 9px;
	border: 0;
	background: #3a3a37;
	color: #ddd;
	font-family: inherit;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: .04em;
	cursor: pointer;
}

.ce-tog:hover {
	background: #4a4a46;
}

.ce-tog.is-on {
	background: var(--t-green);
	color: #fff;
}

.ce-count {
	color: #fff;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.ce-state {
	margin-left: auto;
	padding: 2px 6px;
	background: #3a2320;
	color: #e6a397;
	font-size: 10.5px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .04em;
}

.ce-state.is-on {
	background: #2b3a1c;
	color: #b9cf8e;
}

.ce-batt {
	width: 100%;
	height: 8px;
	background: #151514;
	border: 1px solid #3a3a37;
}

.ce-batt span {
	display: block;
	height: 100%;
	background: linear-gradient(90deg, #6a8241, #a5c96a);
}

/* lit lights glow */

.ce-node.is-live[class*="consumer"] .ce-node__head img {
	filter: drop-shadow(0 0 6px rgba(255, 220, 120, .65));
}

/* zoom + warning */

.ce-zoom {
	position: absolute;
	right: 10px;
	bottom: 10px;
	display: grid;
	gap: 4px;
}

.ce-zoom button {
	width: 34px;
	height: 34px;
	border: 0;
	background: rgba(40, 40, 38, .92);
	color: #fff;
	font-size: 18px;
	cursor: pointer;
}

.ce-zoom button:hover {
	background: var(--t-slot-hi);
}

.ce-warn {
	position: absolute;
	top: 10px;
	left: 50%;
	display: none;
	max-width: 80%;
	padding: 8px 12px;
	transform: translateX(-50%);
	background: #5a1f17;
	color: #fff;
	font-size: 13px;
}

.ce-warn.is-on {
	display: block;
}

/* inspector */

.ce-insp h3 {
	margin: 0 0 4px;
	color: #ece6de;
	font-size: 17px;
	text-transform: uppercase;
	letter-spacing: .02em;
}

.ce-insp__head {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 10px;
}

.ce-insp__head img {
	width: 56px;
	height: 56px;
	padding: 4px;
	background: var(--t-slot);
	object-fit: contain;
}

.ce-insp__head small {
	color: var(--t-gold);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: .06em;
}

.ce-insp__empty ol {
	margin: 8px 0 12px;
	padding-left: 18px;
	color: #c9c1b7;
	font-size: 14px;
	line-height: 1.5;
}

.ce-insp__empty p,
.ce-note {
	color: var(--t-dim);
	font-size: 13px;
	line-height: 1.45;
}

.ce-dl {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 4px 10px;
	margin: 0 0 12px;
	font-size: 13px;
}

.ce-dl dt {
	color: var(--t-dim);
}

.ce-dl dd {
	margin: 0;
	color: #fff;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.ce-f {
	display: grid;
	gap: 4px;
	margin-bottom: 10px;
	color: var(--t-dim);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: .04em;
}

.ce-f input[type="number"] {
	height: 34px;
	padding: 0 8px;
	border: 1px solid #333;
	background: #121211;
	color: #fff;
	font-family: inherit;
	font-size: 14px;
}

.ce-f input[type="range"] {
	accent-color: var(--t-gold);
}

.ce-checks {
	display: grid;
	gap: 6px;
	margin-bottom: 10px;
	font-size: 13px;
}

.ce-big {
	margin: 4px 0 12px;
	color: #fff;
	font-size: 30px;
	font-weight: 700;
}

.ce-colors {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 14px;
}

.ce-colors button {
	width: 28px;
	height: 28px;
	border: 2px solid transparent;
	cursor: pointer;
}

.ce-colors button.is-on {
	border-color: #fff;
}

.ce-craft {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 5px;
	margin: 6px 0 12px;
	color: var(--t-dim);
	font-size: 12px;
	text-transform: uppercase;
}

.ce-chip {
	position: relative;
	display: inline-grid;
	place-items: center;
	min-width: 38px;
	height: 38px;
	padding: 0 3px;
	background: var(--t-slot);
}

.ce-chip img {
	width: 30px;
	height: 30px;
}

.ce-chip b {
	position: absolute;
	right: 2px;
	bottom: 0;
	color: #fff;
	font-size: 11px;
	text-shadow: 0 1px 2px #000;
}

.ce-insp__acts {
	display: flex;
	gap: 6px;
}

/* stats */

.ce-stats {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 26px;
	padding: 10px 14px;
	background: #20201e;
	border-top: 1px solid var(--t-line);
}

.ce-stats small {
	display: block;
	color: var(--t-dim);
	font-size: 11px;
	letter-spacing: .06em;
	text-transform: uppercase;
}

.ce-stats b {
	color: #fff;
	font-size: 16px;
	font-variant-numeric: tabular-nums;
}

.bgl-elec.is-failed::after {
	content: "The simulator could not load. Refresh the page to try again.";
	display: block;
	padding: 30px;
	text-align: center;
	color: var(--t-dim);
}

/* smaller screens: palette on top, inspector under the board */

@media (max-width: 1100px) {
	.ce-main {
		grid-template-columns: 210px minmax(0, 1fr);
		grid-template-rows: var(--ce-h) auto;
		height: auto;
	}
	.ce-insp {
		grid-column: 1 / -1;
		max-height: none;
		border-left: 0;
		border-top: 1px solid var(--t-line);
	}
}

@media (max-width: 760px) {
	.bgl-elec {
		--ce-h: 62vh;
	}
	.ce-main {
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: auto var(--ce-h) auto;
	}
	.ce-pal {
		max-height: 180px;
		border-right: 0;
		border-bottom: 1px solid var(--t-line);
	}
	.ce-pal {
		max-height: 220px;
		overflow-x: hidden;
	}
	.ce-pal__grid {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
	.ce-part img {
		width: 36px;
		height: 36px;
	}
	.ce-bar__env input[type="range"] {
		width: 80px;
	}
	.ce-node {
		min-width: 160px;
	}
}
