/*
 * Costume preview.
 *
 * Square by design like the rest of the panel: radii come from the theme
 * tokens, which are 0. Colours come from the --mr-* tokens with translucent
 * grey fallbacks so the page still reads if it is ever rendered under the
 * stock theme.
 */

.csim {
	--csim-radius: var(--radius-md, 6px);
	--csim-line: var(--mr-border, rgba(127, 127, 127, 0.35));
	--csim-line-strong: var(--mr-border-strong, rgba(127, 127, 127, 0.5));
	--csim-surface: rgba(127, 127, 127, 0.08);
	--csim-surface-2: rgba(127, 127, 127, 0.14);
	--csim-accent: var(--mr-primary, #7c5cff);
	--csim-warn: var(--mr-warning, #c88a00);
	font-size: 14px;
	line-height: 1.45;
	/* The column count follows the room the page actually has, not the viewport. */
	container-type: inline-size;
	container-name: csim;
}

.csim *,
.csim *::before,
.csim *::after {
	box-sizing: border-box;
}

.csim-head h2 {
	margin: 0 0 6px;
}

.csim-sub {
	margin: 0 0 18px;
	max-width: 70ch;
	opacity: 0.85;
}

.csim-grid {
	display: grid;
	grid-template-columns: minmax(320px, 1.1fr) minmax(300px, 1fr);
	gap: 16px;
	align-items: start;
}

/*
 * The panels sit in the order they appear in the page, and the visitor can
 * change that order, so placement goes by position rather than by panel.
 * Two columns: the first panel on the left across both rows, the other two
 * stacked on the right. Three columns when the page has room for them, with
 * the wider column following the preview wherever it sits.
 */
.csim-grid > :nth-child(1) {
	grid-column: 1;
	grid-row: 1 / span 2;
}

.csim-grid > :nth-child(2) {
	grid-column: 2;
	grid-row: 1;
}

.csim-grid > :nth-child(3) {
	grid-column: 2;
	grid-row: 2;
}

@container csim (min-width: 980px) {
	.csim-grid,
	.csim-grid[data-stage-at="1"] {
		grid-template-columns: minmax(320px, 1.3fr) minmax(280px, 1fr) minmax(280px, 1fr);
	}
	.csim-grid[data-stage-at="2"] {
		grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.3fr) minmax(280px, 1fr);
	}
	.csim-grid[data-stage-at="3"] {
		grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr) minmax(320px, 1.3fr);
	}
	.csim-grid > :nth-child(1) {
		grid-column: 1;
		grid-row: 1;
	}
	.csim-grid > :nth-child(2) {
		grid-column: 2;
		grid-row: 1;
	}
	.csim-grid > :nth-child(3) {
		grid-column: 3;
		grid-row: 1;
	}
}

@media (max-width: 900px) {
	.csim-grid {
		grid-template-columns: 1fr;
	}
	.csim-grid > :nth-child(1) {
		grid-column: 1;
		grid-row: 1;
	}
	.csim-grid > :nth-child(2) {
		grid-column: 1;
		grid-row: 2;
	}
	.csim-grid > :nth-child(3) {
		grid-column: 1;
		grid-row: 3;
	}
}

.csim-layoutbar {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: -8px 0 14px;
	font-size: 12px;
	opacity: 0.85;
}

/* ------------------------------------------------------------ panel head */

.csim-panel__head {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: -2px 0 10px;
}

.csim-panel__head .csim-panel__title {
	flex: 1 1 auto;
	margin: 0;
}

/* Six dots drawn in CSS, so the file stays plain ASCII. */
.csim-grip {
	flex: none;
	width: 10px;
	height: 14px;
	background-image: radial-gradient(currentColor 1px, transparent 1.6px);
	background-size: 5px 5px;
	opacity: 0.45;
	cursor: grab;
}

.csim-panel__head[draggable="true"] {
	cursor: grab;
}

.csim-panel__tools {
	flex: none;
	display: flex;
	gap: 3px;
	opacity: 0.55;
}

.csim-panel__head:hover .csim-panel__tools {
	opacity: 1;
}

.csim-move {
	width: 22px;
	height: 22px;
	padding: 0;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background: var(--csim-surface-2);
	color: inherit;
	font: inherit;
	font-size: 12px;
	line-height: 1;
	cursor: pointer;
}

.csim-move:disabled {
	opacity: 0.3;
	cursor: default;
}

.csim-grid > .is-dragging {
	opacity: 0.4;
}

.csim-grid > .is-dropzone {
	outline: 2px dashed var(--csim-accent);
	outline-offset: 2px;
}

.csim-col {
	display: flex;
	flex-direction: column;
	gap: 16px;
	min-width: 0;
}

.csim-panel {
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background: var(--csim-surface);
	padding: 14px;
}

.csim-panel__title {
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	font-size: 12px;
	opacity: 0.8;
	margin-bottom: 10px;
}

/* ------------------------------------------------------------------ stage */

.csim-stage {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 380px;
	padding: 12px;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background-color: rgba(0, 0, 0, 0.25);
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	overflow: auto;
}

/* With a scene behind it the character stands on the ground rather than
   floating in the middle, and grows upward from its feet when zoomed. */
.csim-stage.has-scene {
	align-items: flex-end;
	padding-bottom: 54px;
}

.csim-stage.has-scene .csim-image {
	transform-origin: center bottom;
}

.csim-hint {
	font-size: 12px;
	opacity: 0.7;
}

.csim-stage.is-checkered {
	background-image:
		linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.05) 75%),
		linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.05) 75%);
	background-size: 16px 16px;
	background-position: 0 0, 8px 8px;
	/* The scenes turn repeating off on the stage; the tile needs it back. */
	background-repeat: repeat;
}

.csim-image {
	display: block;
	image-rendering: pixelated;
	image-rendering: crisp-edges;
	transform-origin: center center;
}

.csim-image.is-stale {
	opacity: 0.45;
}

.csim-stage__busy,
.csim-stage__miss {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	padding: 3px 10px;
	border: 1px solid var(--csim-line-strong);
	background: rgba(0, 0, 0, 0.7);
	color: #fff;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

.csim-stage__busy {
	top: 10px;
}

.csim-stage__miss {
	bottom: 10px;
	border-color: var(--csim-warn);
	text-transform: none;
	letter-spacing: 0;
	font-size: 12px;
}

.csim-facing {
	min-width: 34px;
	text-align: center;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.csim-frame {
	min-width: 66px;
	text-align: center;
	font-size: 12px;
	opacity: 0.85;
	font-variant-numeric: tabular-nums;
}

.csim-sep {
	width: 1px;
	height: 22px;
	background: var(--csim-line);
	margin: 0 4px;
}

/* One row of poses when the column is wide enough, two even rows otherwise. */
.csim-col--stage {
	container-type: inline-size;
}

.csim-poses {
	display: grid;
	grid-template-columns: repeat(9, 1fr);
	gap: 6px;
	margin-top: 10px;
}

@container (max-width: 560px) {
	.csim-poses {
		grid-template-columns: repeat(5, 1fr);
	}
}

.csim-pose {
	padding: 5px 4px;
	text-align: center;
	white-space: nowrap;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background: var(--csim-surface-2);
	color: inherit;
	font: inherit;
	font-size: 12px;
	cursor: pointer;
}

.csim-pose.is-active {
	border-color: var(--csim-accent);
	box-shadow: inset 0 0 0 1px var(--csim-accent);
}

.csim-pose.is-missing {
	opacity: 0.4;
}

/* --------------------------------------------------------------- controls */

.csim-field {
	display: block;
	margin-bottom: 10px;
}

.csim-field > span {
	display: block;
	margin-bottom: 3px;
	font-size: 12px;
	opacity: 0.85;
}

.csim-field > span b {
	opacity: 1;
	font-variant-numeric: tabular-nums;
}

/* A slider on one line: its name, the slider, the typed box, and a note if any. */
.csim-field--row {
	display: grid;
	grid-template-columns: 6.5em minmax(0, 1fr) 5.5em auto;
	align-items: center;
	gap: 8px;
	margin-bottom: 8px;
}

.csim-field--row .csim-field__label {
	font-size: 12px;
	opacity: 0.85;
	white-space: nowrap;
}

.csim-field--row .csim-seg {
	grid-column: 2 / -1;
	justify-self: start;
}

.csim-field--row .csim-field__note {
	font-size: 11px;
	font-weight: 400;
	opacity: 0.6;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

.csim-field--row .csim-field__note[hidden] {
	display: none;
}

.csim-note:empty {
	display: none;
}

.csim input[type="number"].csim-num {
	width: 5.5em;
	padding: 2px 6px;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background: var(--csim-surface-2);
	color: inherit;
	font: inherit;
	font-size: 12px;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.csim-field--inline {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 0;
}

.csim-field--inline > span {
	margin: 0;
	white-space: nowrap;
}

.csim select,
.csim input[type="text"] {
	width: 100%;
	padding: 6px 8px;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background: var(--csim-surface-2);
	color: inherit;
	font: inherit;
}

.csim select[size] {
	padding: 2px;
}

.csim select option {
	padding: 2px 4px;
}

.csim input[type="range"] {
	width: 100%;
	accent-color: var(--csim-accent);
}

.csim-check {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 13px;
	cursor: pointer;
	user-select: none;
}

.csim-check input {
	accent-color: var(--csim-accent);
	margin: 0;
}

.csim-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin: 10px 0 0;
}

.csim-row--center {
	justify-content: center;
}

.csim-btn {
	padding: 6px 12px;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background: var(--csim-surface-2);
	color: inherit;
	font: inherit;
	cursor: pointer;
	white-space: nowrap;
}

.csim-btn:hover:not(:disabled) {
	border-color: var(--csim-accent);
}

.csim-btn--sm {
	padding: 4px 9px;
	font-size: 12px;
}

.csim-btn--icon {
	width: 34px;
	padding: 6px 0;
	text-align: center;
	font-weight: 700;
}

.csim-seg {
	display: inline-flex;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	overflow: hidden;
}

.csim-seg__btn {
	padding: 5px 10px;
	border: 0;
	border-right: 1px solid var(--csim-line);
	background: var(--csim-surface-2);
	color: inherit;
	font: inherit;
	font-size: 12px;
	cursor: pointer;
}

.csim-seg__btn:last-child {
	border-right: 0;
}

.csim-seg__btn.is-active {
	background: var(--csim-accent);
	color: #fff;
	font-weight: 600;
}

.csim-picker {
	margin-bottom: 10px;
}

.csim-count {
	opacity: 0.6;
	font-weight: 400;
}

.csim-note {
	margin: 10px 0 0;
	font-size: 12px;
	opacity: 0.7;
}

.csim-warn {
	margin: 0 0 14px;
	padding: 8px 10px;
	border-left: 3px solid var(--csim-warn);
	background: var(--csim-surface-2);
	font-size: 13px;
}

/* ------------------------------------------------------------ equipped list */

.csim-equipped {
	list-style: none;
	margin: 0 0 12px;
	padding: 0;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background: rgba(0, 0, 0, 0.18);
}

.csim-eq {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 5px 7px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.05);
	font-size: 12.5px;
	/* The rows pick which slot the one picker below is filling. */
	cursor: pointer;
}

.csim-eq:hover {
	background: var(--csim-surface);
}

.csim-eq.is-active {
	background: var(--csim-surface-2);
	box-shadow: inset 2px 0 0 var(--csim-accent);
}

.csim-eq:focus-visible {
	outline: 1px solid var(--csim-accent);
	outline-offset: -1px;
}

.csim-eq:last-child {
	border-bottom: 0;
}

.csim-eq__slot {
	flex: none;
	width: 62px;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	opacity: 0.6;
}

.csim-eq__icon {
	flex: none;
	width: 24px;
	height: 24px;
	image-rendering: pixelated;
	background: rgba(255, 255, 255, 0.04);
}

.csim-eq__name {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.csim-eq__name a {
	color: inherit;
	text-decoration: none;
	border-bottom: 1px dotted var(--csim-line-strong);
}

.csim-eq__name a:hover {
	color: var(--csim-accent);
}

.csim-eq__id {
	flex: none;
	font-size: 11px;
	opacity: 0.55;
	font-family: ui-monospace, Consolas, monospace;
}

.csim-eq__empty {
	flex: 1 1 auto;
	opacity: 0.45;
	font-style: italic;
}

/* An empty slot is a place to click, not a row of greyed out buttons. */
.csim-eq.is-empty .csim-eq__btns,
.csim-eq.is-empty .csim-eq__icon {
	display: none;
}

.csim-eq__btns {
	flex: none;
	display: flex;
	gap: 3px;
}

.csim-eq__btn {
	width: 22px;
	height: 22px;
	padding: 0;
	border: 1px solid var(--csim-line);
	border-radius: var(--csim-radius);
	background: var(--csim-surface-2);
	color: inherit;
	font: inherit;
	font-size: 11px;
	line-height: 1;
	cursor: pointer;
}

.csim-eq__btn:hover:not(:disabled) {
	border-color: var(--csim-accent);
}

.csim-eq__btn:disabled {
	opacity: 0.25;
	cursor: default;
}

.csim-lock {
	font-size: 11px;
	opacity: 0.65;
	font-style: italic;
}

.csim-seg__btn:disabled {
	opacity: 0.4;
	cursor: default;
}
