/* stylelint-disable no-duplicate-selectors */
/* stylelint-disable font-family-no-missing-generic-family-keyword */
// styles for icons

.icon {
	&::before {
		display: inline-block;
		text-rendering: auto;
		-webkit-font-smoothing: antialiased;
	}
}

// workaround to make FA easier to use as button decorations without adding a whole extra element. the pseudo-element is already there, and can be simply be attached to the parent element rather than it being an <i> element
.fa,
.fa-brands,
.fa-classic,
.fa-duotone,
.fa-light,
.fa-regular,
.fa-sharp,
.fa-sharp-solid,
.fa-solid,
.fa-thin,
.fab,
.fad,
.fal,
.far,
.fas,
.fass,
.fat {
	&:not(i) {
		text-rendering: inherit;
		line-height: inherit;
		font-family: inherit;
		font-weight: inherit;
		-moz-osx-font-smoothing: inherit;
		font-variant: inherit;
		font-style: inherit;
		speak: inherit;

		&::before {
			display: var(--fa-display, inline-block);
			text-rendering: auto;
			line-height: 1;
			-moz-osx-font-smoothing: grayscale;
			-webkit-font-smoothing: antialiased;
			font-variant: normal;
			font-style: normal;
		}
	}
}

.fa-thin,
.fat {
	&:not(i) {
		font-weight: unset;

		&::before {
			font-weight: 100;
		}
	}
}

.fa-light,
.fal {
	&:not(i) {
		font-weight: unset;

		&::before {
			font-weight: 300;
		}
	}
}

.fa-regular,
.far {
	&:not(i) {
		font-weight: unset;

		&::before {
			font-weight: 400;
		}
	}
}

.fa-solid,
.fas {
	&:not(i) {
		font-weight: unset;

		&::before {
			font-weight: 900;
		}
	}
}

.fa-classic,
.fa-light,
.fa-regular,
.fa-solid,
.fa-thin,
.fal,
.far,
.fas,
.fat {
	&:not(i) {
		&::before {
			font-family: 'Font Awesome 6 Pro';
		}
	}
}

[class^='isicon-']::before,
[class*=' isicon-']::before {
	display: inline-block;
	background-color: currentcolor; // inherits text color by default. any valid background is fine if you want to get fancy, though.
	width: var(--ironsworn-icon-size);
	height: var(--ironsworn-icon-size);
	content: '';
	mask-repeat: no-repeat;
	mask-position: center;
	mask-size: contain;

	.vertical-text& {
		transform: rotateZ(90deg);
	}
}

[class^='isiconbg-'],
[class*=' isiconbg-'],
[class^='isicon-'],
[class*=' isicon-'],
[class^='fa-'],
[class*=' fa-'] {
	i.juicy&,
	&:not(i).juicy::before {
		font-size: 120%;
	}
}

// BACKGROUND ICONS

[class^='isiconbg-'],
[class*=' isiconbg-'] {
	position: relative; // required for the pseudo-element's position to function
	z-index: 1;

	&::before {
		box-sizing: border-box;
		display: inline-block;
		position: absolute;
		top: 0;
		left: 0;
		z-index: var(--ironsworn-z-index-low);
		background-color: var(--ironsworn-color-fg-30);
		width: 100%;
		height: 100%;
		content: '';
		mask-repeat: no-repeat;
		mask-position: center;
		mask-size: contain;
		mask-origin: content-box; // this + above make this sensitive to padding on the :before pseudo-element.
	}
}

// additional CSS to maintain compatibility with FVTT's icon fonts until FVTT drops icon fonts
// if the icon needs to be clickable, IronBtn + FontIcon/IronIcon should be preferred instead
[class^='isicon-'],
[class*=' isicon-'] {
	i& {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 1em;
		height: 1em;
		vertical-align: inherit;

		&::before {
			width: 100%;
			height: 100%;
		}
	}
}

i {
	&[class^='isicon-'],
	&[class*=' isicon-'] {
		display: flex;
		&.inline {
			display: inline-block;
			&::before {
				display: inline-block;
			}
		}
		align-items: center;
		align-self: center;
		justify-content: center;
		font-size: inherit;
		aspect-ratio: 1;

		&::before {
			display: flex;
			width: var(--ironsworn-icon-size);
			height: var(--ironsworn-icon-size);
		}
	}
}

// these are configured to make adding them from game-icons.net take as little effort as possible
// HOW TO ADD AN ICON FROM GAME-ICONS.NET
// 1) use the game-icons studio, turn off the black background
// 2) download the icon as an svg and place it in system/assets/icons
// 3) add an entry to @icons hash object below

// alternatively, you can remove the black background element manually by editing the SVG's source
// generally it will be the first path element, and it'll look like one of the following, e.g.:
// <path d="M0 0h512v512H0z" fill="#000" fill-opacity="1"></path>
// <path fill-rule="nonzero" d="M0 0h512v512H0z"/>

// icons require a key (the file name without the extension) and a value (a string describing the source information/credit).
// the value isn't used by any LESS functions, it's just to make it harder to forget to include source/credit info.
@icons: {
	// game logos
	logo-delve-dk: 'original icon by Shawn Tomkin; minor adjustments for FVTT format by rsek';
	logo-ironsworn-dk: 'original icon by Shawn Tomkin; minor adjustments for FVTT format by rsek';
	logo-starforged-dk: 'icon by rsek, based on illustrations by Joshua Meehan and icons Nathan Graey';
	logo-sunderedisles-dk: 'icon by game-icons.net';
	// dice
	d6-blank: ''; // FIXME
	d10-blank: ''; // FIXME
	d10-tilt: ''; //
	oracle: 'icon by rsek';
	// PC sheets
	sheet-character: 'https://game-icons.net/1x1/delapouite/skills.html';
	sheet-shared: 'https://game-icons.net/1x1/delapouite/three-friends.html';
	// PC stats
	stat-edge: 'https://game-icons.net/1x1/delapouite/liberty-wing.html';
	stat-heart: 'https://game-icons.net/1x1/lorc/crowned-heart.html';
	stat-iron: 'https://game-icons.net/1x1/lorc/swords-emblem.html';
	stat-shadow: 'https://game-icons.net/1x1/lorc/double-face-mask.html';
	stat-wits: 'https://game-icons.net/1x1/lorc/star-pupil.html';
	// canvas tools
	creature: 'https://game-icons.net/1x1/lorc/dna1.html'; // Starforged. see 'monstrosity' for Delve creatures
	delve-site: 'https://game-icons.net/1x1/delapouite/dungeon-gate.html';
	derelict: 'https://game-icons.net/1x1/delapouite/crime-scene-tape.html';
	faction: 'https://game-icons.net/1x1/delapouite/vertical-banner.html';
	island: 'https://game-icons.net/1x1/delapouite/island.html';
	monstrosity: 'https://game-icons.net/1x1/lorc/beast-eye.html'; // AKA the creature oracles from delve
	npc: 'https://game-icons.net/1x1/lorc/drama-masks.html';
	precursor-vault: 'https://game-icons.net/1x1/lorc/moebius-triangle.html';
	region-sf: 'https://game-icons.net/1x1/delapouite/galaxy.html';
	region-si: 'https://game-icons.net/1x1/lorc/treasure-map.html';
	sector: 'https://game-icons.net/1x1/skoll/hexes.html';
	settlement-is: 'https://game-icons.net/1x1/delapouite/huts-village.html';
	settlement-sf: 'https://game-icons.net/1x1/delapouite/modern-city.html';
	settlement-si: 'https://game-icons.net/1x1/delapouite/village.html';
	starship: 'https://game-icons.net/1x1/delapouite/spaceship.html';
	stellar-object: 'https://game-icons.net/1x1/lorc/star-prominences.html';
	waypoint: 'https://game-icons.net/1x1/delapouite/position-marker.html';
	world: 'https://game-icons.net/1x1/lorc/ringed-planet.html';
};

each(@icons, {
  @iconName: e(%('isicon-%s', @key));
  @iconNameBg: e(%('isiconbg-%s', @key));
  @var: e(%('var(--%s)', @iconName));
  .@{iconName}, .@{iconNameBg} {
      &::before {
      // FIXME: workaround to avoid vite inlining these as base64. can be done the normal way once this issue is resolved: https://github.com/vitejs/vite/pull/9734

      mask-image: @var;
    }
  }
  // :root {
    // this gets rendered within another selector
  --@{iconName}: e(%('url(/assets/icons/%a.svg)', @key));
  // }
});

// FVTT doesn't get subtype icons from items in compendium packs, so we override them depending on the pack

// NPC actor
a[data-pack='foundry-ironsworn.foeactorsis'],
a[data-pack='foundry-ironsworn.foeactorssf'] {
	i::before {
		content: '\f630';
	}
}

// Assets
a[data-pack='foundry-ironsworn.starforgedassets'],
a[data-pack='foundry-ironsworn.ironswornassets'] {
	i::before {
		content: '\e4df';
	}
}

// Delve site themes + domains
a[data-pack='foundry-ironsworn.ironsworndelvedomains'],
a[data-pack='foundry-ironsworn.ironsworndelvethemes'] {
	i {
		&::before {
			position: absolute;
			opacity: var(--fa-primary-opacity, 1);
			color: var(--fa-primary-color, inherit);
			content: '\e4df';
		}

		&::after {
			opacity: var(--fa-secondary-opacity, 0.4);
			color: var(--fa-secondary-color, inherit);
			content: '\e4df\e4df';
		}
	}
}

// Moves
a[data-pack='foundry-ironsworn.ironswornmoves'],
a[data-pack='foundry-ironsworn.starforgedmoves'] {
	& > i {
		align-self: center;
		width: var(--ironsworn-icon-size);
		height: var(--ironsworn-icon-size);

		&::before {
			display: inline-block;
			background-color: currentcolor;
			width: var(--ironsworn-icon-size);
			height: var(--ironsworn-icon-size);
			content: '';
			mask-repeat: no-repeat;
			mask-position: center;
			mask-size: contain;
			mask-image: var(--isicon-d10-tilt);
		}
	}
}

// NPC progress track
a[data-pack='foundry-ironsworn.ironswornfoes'],
a[data-pack='foundry-ironsworn.starforgedencounters'] {
	i::before {
		content: '\2a';
	}
}
