/**
 * The site footer — the forest band under every page.
 *
 * Four things across the top, laid out on a grid rather than in columns: the
 * menu, the address, the mark, and the link back to the top. The legal line
 * sits under all of them, on the same left edge as the menu.
 *
 * The block markup gives the group a flow layout and this takes it over, so
 * the arrangement lives in one place instead of being split between column
 * widths saved in the database and rules here.
 *
 * @package homewood_theme
 */

.hw-footer {
	--hw-footer-pad-block: clamp(3rem, 6vw, 5rem);
	--hw-footer-gap: clamp(2rem, 6vw, 6rem);
	--hw-footer-text: var(--wp--preset--color--cream, #f6f1ea);

	--hw-footer-logo: clamp(9rem, 14vw, 14rem);

	/*
	 * Wheat rather than the bronze of the logo's house, which the mark can
	 * carry because it is a picture: against forest, bronze is 2.4:1 and wheat
	 * is 5.1:1, and this one is a link with a word in it.
	 */
	--hw-footer-top: var(--wp--preset--color--wheat, #c3a87f);
	--hw-footer-top-hover: var(--hw-footer-text);
	--hw-footer-top-shadow: drop-shadow(0 -1px 2px rgba(37, 43, 35, .5));
	/* How far the arrow reaches up out of the band, as in the design. */
	--hw-footer-top-overhang: clamp(2rem, 4vw, 4rem);
	/* Clear of the right edge once the link is following the page. */
	--hw-footer-top-inset: clamp(1rem, 3vw, 2.5rem);

	position: relative;
	padding-block: var(--hw-footer-pad-block);
}

.hw-footer__inner {
	display: grid;
	grid-template-columns: auto auto 1fr auto;
	align-items: start;
	gap: var(--hw-footer-gap);
}

/* The flow layout the group ships with spaces its children; the grid does now. */
.hw-footer__inner > * {
	margin-block: 0;
}

/* -- The menu ------------------------------------------------------------- */

.hw-footer ul.hw-footer__nav {
	gap: clamp(0.9rem, 1.6vw, 1.4rem);
}

.hw-footer ul.hw-footer__nav .wp-block-navigation-item__content {
	color: var(--hw-footer-text);
	text-decoration: underline;
	text-underline-offset: 0.35em;
}

/* -- The address ---------------------------------------------------------- */

.hw-footer__contact p {
	margin-block: 0;
	color: var(--hw-footer-text);
	line-height: 1.6;
}

.hw-footer__contact p + p {
	margin-top: 1.5em;
}

.hw-footer__contact a {
	color: var(--hw-footer-text);
	text-decoration: underline;
	text-underline-offset: 0.35em;
}

/* -- The mark ------------------------------------------------------------- */

.hw-footer__logo {
	display: block;
	justify-self: end;
	line-height: 0;
}

.hw-footer__logo img {
	display: block;
	width: auto;
	height: var(--hw-footer-logo);
}

/* -- Back to the top ------------------------------------------------------ */

/*
 * The arrow starts above the band and runs down into it, so it is pulled up by
 * its own overhang plus the padding it would otherwise start below.
 */
.hw-footer__top {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.75em;
	margin-top: calc( ( var(--hw-footer-pad-block) + var(--hw-footer-top-overhang) ) * -1 );
	color: var(--hw-footer-top);
	text-decoration: none;
	transition:
		color 0.3s ease,
		filter 0.3s ease;
}

/*
 * drop-shadow rather than box-shadow: the arrow is a stroked line and the word
 * is type, so what wants a shadow is the shape drawn, not the box around it.
 * Ink, which is darker than the forest it falls on, and only once the link has
 * gone cream — a shadow under bronze on forest would have nothing to show.
 */
.hw-footer__top:hover,
.hw-footer__top:focus-visible {
	color: var(--hw-footer-top-hover);
	filter: var(--hw-footer-top-shadow);
}

.hw-footer__top:focus-visible {
	outline: 2px solid var(--hw-footer-top-hover);
	outline-offset: 4px;
}

.hw-footer__top-arrow {
	display: block;
	/* Drawn at its own size: the viewBox is 12 × 210, so nothing is distorted. */
	width: 12px;
	height: 210px;
}

.hw-footer__top-label {
	/* Reading upward, alongside the arrow it belongs to. */
	writing-mode: vertical-rl;
	transform: rotate(180deg);
	text-transform: uppercase;
	letter-spacing: 0.18em;
	font-size: 0.875rem;
	line-height: 1;
}

/* -- Back to the top, following the page ---------------------------------- */

/*
 * `is-floating` is added by assets/js/footer-top.js, never by the markup: with
 * no script running — the site editor canvas above all — the link stays in the
 * footer grid, which is the arrangement above and the one it was drawn for.
 *
 * Fixed to the right edge, and shown only from a screenful down. Nearer the
 * top than that there is nothing for it to do, so it is not offered.
 */
.hw-footer__top.is-floating {
	position: fixed;
	right: var(--hw-footer-top-inset);
	bottom: 13em;
	z-index: 10;

	/* The overhang belongs to the band; out of flow there is nothing to hang over. */
	margin-top: 0;

	/*
	 * Wheat is a colour for forest and the page is cream, so on the page the
	 * link is forest instead, and the shadow — which is there to lift cream
	 * off the band — has nothing to fall on.
	 */
	--hw-footer-top: var(--wp--preset--color--forest, #323a30);
	--hw-footer-top-hover: var(--wp--preset--color--bronze, #896d44);
	--hw-footer-top-shadow: none;

	/*
	 * visibility as well as opacity: hidden it is out of the tab order and out
	 * of the reading of the page, rather than a transparent link over content.
	 * It is held back until the fade out has finished, and dropped at once on
	 * the way in.
	 */
	visibility: hidden;
	opacity: 0;
	transition:
		color 0.3s ease,
		filter 0.3s ease,
		opacity 0.3s ease,
		visibility 0s linear 0.3s;
}

.hw-footer__top.is-floating.is-visible {
	visibility: visible;
	opacity: 1;
	transition:
		color 0.3s ease,
		filter 0.3s ease,
		opacity 0.3s ease,
		visibility 0s;
}

/* Over the band at the end of the page it is back to the colours of the band. */
.hw-footer__top.is-floating.is-on-forest {
	--hw-footer-top: var(--wp--preset--color--wheat, #c3a87f);
	--hw-footer-top-hover: var(--hw-footer-text);
	--hw-footer-top-shadow: drop-shadow(0 -1px 2px rgba(37, 43, 35, .5));
}

/*
 * Out of flow, so the column the grid kept for it holds nothing — and an empty
 * track still takes its gap, which would leave the mark short of the right
 * edge. One track fewer, in both arrangements.
 */
.hw-footer__inner:has( > .hw-footer__top.is-floating ) {
	grid-template-columns: auto auto 1fr;
}

@media (max-width: 940px) {
	.hw-footer__inner:has( > .hw-footer__top.is-floating ) {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* Full length is most of a short window, and the whole of it has to be read past. */
@media (max-height: 640px) {
	.hw-footer__top.is-floating .hw-footer__top-arrow {
		height: 110px;
	}
}

/* No fade for a reader who would rather the page held still. */
@media (prefers-reduced-motion: reduce) {
	.hw-footer__top.is-floating,
	.hw-footer__top.is-floating.is-visible {
		transition: none;
	}
}

/* -- The legal line ------------------------------------------------------- */

.hw-footer__legal {
	margin-top: clamp(2.5rem, 5vw, 4rem);
	margin-bottom: 0;
	color: var(--hw-footer-text);
}

/* -- Narrow --------------------------------------------------------------- */

/*
 * Under 940 the three columns stop being columns: the menu, the address and
 * the mark each take the full width and stack. The link back to the top is the
 * exception — it keeps a column of its own down the right, where it has always
 * been, so every row runs up against it rather than under it.
 *
 * Placed by hand rather than left to auto-flow, which would otherwise fill the
 * gap beside the address with whatever came next.
 */
@media (max-width: 940px) {
	.hw-footer__inner {
		grid-template-columns: minmax(0, 1fr) auto;
		row-gap: clamp(1.75rem, 5vw, 2.5rem);
	}

	.hw-footer__nav {
		grid-area: 1 / 1;
	}

	.hw-footer__contact {
		grid-area: 2 / 1;
	}

	.hw-footer__logo {
		grid-area: 3 / 1;
		justify-self: start;
	}

	.hw-footer__top {
		grid-area: 1 / 2;
	}
}

/* A phone has no room for the full length of it. */
@media (max-width: 600px) {
	.hw-footer__top-arrow {
		height: 120px;
	}
}

/* The link back to the top is a scroll, not a jump — unless that is unwelcome. */
@media (prefers-reduced-motion: no-preference) {
	html {
		scroll-behavior: smooth;
	}
}
