/*
 * WP Ar-Poem – front-end styles
 */

.arpoem {
	--arpoem-space: 2;
	--arpoem-gap: 3em;
	direction: rtl;
	unicode-bidi: isolate;
	position: relative;
	margin: 1.5em auto;
	max-width: 100%;
	font-family: var(--arpoem-font, inherit);
	font-size: var(--arpoem-size, 1.15em);
	font-weight: var(--arpoem-weight, 400);
	color: var(--arpoem-color, inherit);
	line-height: var(--arpoem-space);
	text-align: right;
	overflow-wrap: normal;
	box-sizing: border-box;
}
.arpoem *,
.arpoem *::before,
.arpoem *::after {
	box-sizing: border-box;
}
.arpoem-center {
	text-align: center;
}

/* header */
.arpoem-header {
	margin-bottom: 0.5em;
	line-height: 1.6;
}
.arpoem-title {
	font-size: 1.15em;
	font-weight: 700;
	color: var(--arpoem-title-color, inherit);
}
.arpoem-meta {
	font-size: 0.8em;
	opacity: 0.75;
}
.arpoem-meta > span + span::before {
	content: "\00a0\2014\00a0";
}

/* verses block: shrink-to-fit so centring works */
.arpoem-verses {
	display: inline-block;
	max-width: 100%;
	text-align: right;
	vertical-align: top;
	padding: 0.25em 0;
}
.arpoem-loading .arpoem-verses {
	visibility: hidden;
	animation: arpoem-reveal 0s linear 2.5s forwards;
}
@keyframes arpoem-reveal {
	to {
		visibility: visible;
	}
}
.arpoem-narrow .arpoem-verses {
	display: block;
}

/* a verse */
.arpoem-bayt {
	display: flex;
	flex-wrap: nowrap;
	justify-content: flex-start;
	align-items: baseline;
	gap: var(--arpoem-gap);
	position: relative;
	white-space: nowrap;
}
.arpoem-single {
	justify-content: center;
	white-space: normal;
}

/* a hemistich */
.arpoem-shatr {
	display: inline-block;
	flex: 0 0 auto;
	width: var(--arpoem-w, auto);
	max-width: 100%;
	text-align: justify;
	text-align-last: justify;
	-moz-text-align-last: justify;
	white-space: nowrap;
}
.arpoem-mufrad {
	width: auto;
	max-width: 100%;
	text-align: center;
	text-align-last: center;
	-moz-text-align-last: center;
	white-space: normal;
}

/* measuring pass: natural widths */
.arpoem-measuring .arpoem-shatr {
	display: inline-block !important;
	width: auto !important;
	max-width: none !important;
	margin: 0 !important;
	white-space: nowrap !important;
	text-align-last: auto !important;
}
.arpoem-measuring .arpoem-bayt {
	display: flex !important;
}

/* interlaced layout (type 2) and responsive fallback */
.arpoem-type-2 .arpoem-bayt,
.arpoem-stacked .arpoem-bayt {
	display: block;
}
.arpoem-type-2 .arpoem-single,
.arpoem-stacked .arpoem-single {
	text-align: center;
}
.arpoem-type-2 .arpoem-shatr,
.arpoem-stacked .arpoem-shatr {
	display: block;
}
.arpoem-type-2 .arpoem-ajuz,
.arpoem-stacked .arpoem-ajuz {
	margin-inline-start: calc(var(--arpoem-w, 0px) / 2);
}
.arpoem-type-2 .arpoem-mufrad,
.arpoem-stacked .arpoem-mufrad {
	display: inline-block;
	max-width: calc(var(--arpoem-w, 100%) * 1.5);
}

/* very narrow: one hemistich per line, natural wrapping */
.arpoem-narrow .arpoem-bayt {
	display: block;
	white-space: normal;
	margin-bottom: 0.35em;
}
.arpoem-narrow .arpoem-shatr {
	display: block;
	width: auto;
	margin: 0;
	white-space: normal;
	text-align: right;
	text-align-last: auto;
}
.arpoem-narrow .arpoem-ajuz {
	padding-inline-start: 1.5em;
}
.arpoem-narrow .arpoem-mufrad {
	text-align: center;
	max-width: none;
}

/* تخميس / تسبيع: units of 5 or 7 hemistichs */
.arpoem-band {
	margin-bottom: 0.9em;
}
.arpoem-band:last-child {
	margin-bottom: 0;
}
/* a hemistich on its own line keeps the common hemistich width, so the columns stay aligned */
.arpoem-shatr.arpoem-band-shatr {
	width: var(--arpoem-w, auto);
	max-width: 100%;
	white-space: nowrap;
	text-align: justify;
	text-align-last: justify;
	-moz-text-align-last: justify;
}
.arpoem-type-2 .arpoem-band-line,
.arpoem-stacked .arpoem-band-line {
	text-align: center;
}
.arpoem-narrow .arpoem-shatr.arpoem-band-shatr {
	display: block;
	width: auto;
	white-space: normal;
	text-align: center;
	text-align-last: center;
	-moz-text-align-last: center;
}

/* verse numbers */
.arpoem-num {
	position: absolute;
	top: 0;
	inset-inline-end: calc(100% + 0.9em);
	font-size: 0.7em;
	line-height: inherit;
	opacity: 0.6;
	font-weight: 400;
	font-variant-numeric: tabular-nums;
	user-select: none;
	-webkit-user-select: none;
}
.arpoem-narrow.arpoem-numbered .arpoem-bayt {
	padding-inline-end: 1.8em;
}
.arpoem-narrow .arpoem-num {
	inset-inline-end: 0;
	top: 0;
}

/* footnote markers */
.arpoem-fn {
	font-size: 0.65em;
	font-weight: 700;
	line-height: 0;
	vertical-align: super;
	position: relative;
	color: var(--arpoem-sup-color, #c0392b);
	margin-inline-start: 1px;
	white-space: nowrap;
}
.arpoem-fn[data-tip] {
	cursor: pointer;
	outline: none;
}
.arpoem-fn[data-tip]::after {
	content: attr(data-tip);
	position: absolute;
	bottom: 100%;
	inset-inline-start: 50%;
	transform: translateX(50%) translateY(-0.5em);
	background: #1f2933;
	color: #fff;
	padding: 0.45em 0.8em;
	border-radius: 6px;
	font-size: 0.9rem;
	font-weight: 400;
	line-height: 1.6;
	text-align: right;
	white-space: normal;
	width: max-content;
	max-width: min(320px, 80vw);
	direction: rtl;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.15s ease;
	pointer-events: none;
	z-index: 50;
	text-align-last: auto;
}
.arpoem-fn[data-tip]::before {
	content: "";
	position: absolute;
	bottom: 100%;
	inset-inline-start: 50%;
	transform: translateX(50%);
	border: 6px solid transparent;
	border-top-color: #1f2933;
	margin-bottom: -0.5em;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.15s ease;
	z-index: 50;
}
.arpoem-fn[data-tip]:hover::after,
.arpoem-fn[data-tip]:hover::before,
.arpoem-fn[data-tip]:focus-visible::after,
.arpoem-fn[data-tip]:focus-visible::before,
.arpoem-fn.arpoem-open::after,
.arpoem-fn.arpoem-open::before {
	opacity: 1;
	visibility: visible;
}
.arpoem-no-tips .arpoem-fn::after,
.arpoem-no-tips .arpoem-fn::before {
	display: none;
}

/* footnotes list */
.arpoem-footnotes {
	display: block;
	margin-top: 0.75em;
	font-size: 0.78em;
	line-height: 1.8;
	color: var(--arpoem-fn-color, inherit);
	text-align: right;
}
.arpoem-center .arpoem-footnotes {
	max-width: 42em;
	margin-inline: auto;
}
.arpoem-footline {
	width: 40%;
	max-width: 14em;
	height: 0;
	border: 0;
	border-top: 1px dotted currentColor;
	margin: 0 0 0.4em;
	opacity: 0.7;
}
.arpoem-footnote-list {
	list-style: none;
	margin: 0;
	padding: 0;
}
.arpoem-footnote {
	margin: 0;
	padding: 0;
}
.arpoem-footnote-key {
	font-weight: 700;
	color: var(--arpoem-sup-color, #c0392b);
}

/* tools */
.arpoem-tools {
	margin-top: 0.6em;
	font-size: 0.75em;
	line-height: 1.5;
}
.arpoem-copy {
	font: inherit;
	font-family: inherit;
	cursor: pointer;
	background: transparent;
	border: 1px solid currentColor;
	border-radius: 4px;
	padding: 0.25em 0.9em;
	color: inherit;
	opacity: 0.7;
	transition: opacity 0.15s ease;
}
.arpoem-copy:hover,
.arpoem-copy:focus-visible {
	opacity: 1;
}
.arpoem-copy.arpoem-copied {
	opacity: 1;
	border-style: dashed;
}

/* spinner shown while fonts load */
.arpoem-spinner {
	display: none;
	width: 28px;
	height: 28px;
	margin: 0.5em auto;
	border: 3px solid rgba(120, 120, 120, 0.25);
	border-top-color: currentColor;
	border-radius: 50%;
	animation: arpoem-spin 0.9s linear infinite;
	position: absolute;
	inset-inline-start: calc(50% - 14px);
	top: 1em;
}
.arpoem-loading .arpoem-spinner {
	display: block;
}
@keyframes arpoem-spin {
	to {
		transform: rotate(360deg);
	}
}
@media (prefers-reduced-motion: reduce) {
	.arpoem-spinner {
		animation: none;
	}
}

/* no-JS fallback: show verses as simple lines */
.no-js .arpoem-loading .arpoem-verses,
.arpoem-nojs .arpoem-verses {
	visibility: visible;
}

@media print {
	.arpoem-tools,
	.arpoem-spinner {
		display: none !important;
	}
	.arpoem-loading .arpoem-verses {
		visibility: visible;
	}
}

/* block editor niceties */
.editor-styles-wrapper .arpoem {
	margin-left: auto;
	margin-right: auto;
}
.arpoem-empty {
	opacity: 0.6;
	font-style: italic;
}
