/*
Theme Name: CREDI-NF
Theme URI: https://credi-nf.ca
Author: CREDI-NF
Description: Native block theme for the CREDI-NF consortium. Every visible section is built from core blocks, so headers, footers and pages stay editable in the Site Editor.
Requires at least: 6.6
Tested up to: 6.8
Requires PHP: 8.0
Version: 0.1.0
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: credi-nf
*/

/*
 * Colours, type, spacing and radii live in theme.json so editors can pick
 * them. This file only holds what theme.json cannot express: focus rings,
 * page sections and the motion preference. The site chrome (header,
 * footer, partners band) is in assets/css/header.css. Token values mirror
 * src/styles/global.css in the Astro site; change both together.
 */

body {
	-webkit-font-smoothing: antialiased;
}

html {
	scroll-behavior: smooth;
}

/* Header, main and footer meet edge to edge, as the Astro sections do.
   Core puts the root block gap between them. */
.wp-site-blocks > * {
	margin-block-start: 0;
}

/* Brand ring with a white halo, so one band clears 3:1 on white, navy-800
   and navy-900 alike. Forced-colors mode drops the shadow, keeps the outline. */
:focus-visible {
	outline: var(--wp--custom--focus--ring-width) solid var(--wp--custom--focus--ring-color);
	outline-offset: var(--wp--custom--focus--ring-offset);
	box-shadow: 0 0 0
		calc(var(--wp--custom--focus--ring-offset) + var(--wp--custom--focus--ring-width) + var(--wp--custom--focus--halo-width))
		var(--wp--custom--focus--halo-color);
}

/* Header, navigation, skip link, footer and partners band:
   assets/css/header.css (inc/header.php). */

/* ------------------------------------------------------------------
 * Page sections
 *
 * Pages are a stack of full-width section groups. Each section's own
 * padding sets the rhythm, so the block gap between them is removed.
 * Scoped to page.html: other templates keep their gaps.
 * ------------------------------------------------------------------ */
.credi-page-content > .alignfull,
.credi-page-main > * {
	margin-block-start: 0;
	margin-block-end: 0;
}

.credi-measure {
	max-width: var(--wp--custom--measure);
}

/* theme.json cannot pair a line height or tracking with a font size
   preset; these match the --text-* tokens in src/styles/global.css.
   Only body and the headings are tracked there, so the smaller and larger
   text sizes reset the -0.015em the root sets, which otherwise changes
   where descriptions wrap. */
.has-caption-font-size {
	line-height: 1.25rem;
	letter-spacing: normal;
}

.has-body-sm-font-size {
	line-height: 1.4375rem;
	letter-spacing: normal;
}

.has-body-lg-font-size {
	line-height: 1.75rem;
	letter-spacing: normal;
}

/* The tracked sizes keep their token pair too, so a block with one of these
   presets renders as text-<size> does on Astro whatever its tag: an h3 set
   to the h4 size (the home axis rows) no longer takes the h3 element's 1.375
   and -0.025em, and a paragraph set to nav no longer inherits the root 1.625. */
.has-body-font-size {
	line-height: 1.625rem;
	letter-spacing: -0.015em;
}

.has-nav-font-size {
	line-height: 1.625rem;
	letter-spacing: -0.015em;
}

.has-h-4-font-size {
	line-height: 1.25;
	letter-spacing: -0.015em;
}

.has-quote-font-size {
	line-height: 1.375;
}

.has-h-2-font-size {
	line-height: 1.1;
	letter-spacing: -0.025em;
}

.has-display-font-size {
	line-height: 1.08;
	letter-spacing: -0.03em;
}

.has-stat-font-size {
	line-height: 1;
	letter-spacing: -0.03em;
}

/* Tracked uppercase label. It takes 70% of the surrounding text colour,
   which gives navy-label on light bands and white/70 on navy ones. */
:root .is-style-eyebrow {
	font-size: var(--wp--preset--font-size--eyebrow);
	font-weight: 500;
	line-height: 1.2;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: color-mix(in srgb, currentColor 70%, transparent);
}

/* Two-column bands (hero, direction) stack below 64rem, as on the Astro
   site, instead of at the 782px core default. */
@media (max-width: 63.999rem) {
	.wp-block-columns.credi-split {
		flex-wrap: wrap !important;
	}

	.wp-block-columns.credi-split > .wp-block-column {
		flex-basis: 100% !important;
	}
}

/* Hero */
.credi-hero .wp-block-columns.credi-split {
	gap: 2.5rem 4rem;
}

/* Text columns of the hero and the direction band: gap-6 lg:gap-7, so the
   24px block gap opens to 28px on wide screens. The direction action keeps
   its auto margin (below). */
@media (min-width: 64rem) {
	.credi-hero .credi-hero__text > * + *,
	.credi-direction .wp-block-column.credi-direction__text > * + *:not(.credi-direction__action) {
		margin-block-start: 1.75rem;
	}
}

.credi-hero h1 {
	max-width: 18ch;
}

.credi-hero__main {
	max-width: 360px;
}

.credi-hero__main img,
.credi-hero__inset img {
	width: 100%;
	border-radius: var(--wp--custom--radius--card);
}

.credi-hero__main img {
	box-shadow: var(--wp--preset--shadow--figure);
}

/* The overlap is a desktop composition: on a narrow column the inset would
   cover the portrait, so only the main image shows below 64rem. */
.credi-hero__inset {
	display: none;
}

@media (min-width: 64rem) {
	.credi-split > .credi-hero__media {
		position: relative;
		flex: 0 0 540px !important;
		height: 500px;
	}

	.credi-hero__media > .wp-block-image {
		position: absolute;
		margin: 0;
	}

	.credi-hero__main {
		top: 0;
		right: 0;
		max-width: none;
	}

	.credi-hero__main img {
		width: 404px;
		height: 500px;
	}

	.credi-hero__inset {
		display: block;
		top: 180px;
		left: 0;
	}

	.credi-hero__inset img {
		width: 212px;
		height: 264px;
		border: 4px solid var(--wp--preset--color--brand);
	}
}

/* Numbered axis rows. The heading link is stretched over the row, so the
   whole row is one target with one accessible name. The negative inline
   margin lets the hover tint and the hairline overhang the text column
   while the content stays on the grid. */
.credi-axis-list .credi-axis-row {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	margin: 0 -1rem;
	padding: 1.75rem 1rem;
	transition: background-color 150ms;
}

.credi-axis-list .credi-axis-row > * {
	margin: 0;
}

.credi-axis-list .credi-axis-row + .credi-axis-row {
	border-top: 1px solid var(--wp--custom--color--navy-hairline);
}

.credi-axis-row:hover {
	background-color: color-mix(in srgb, var(--wp--preset--color--navy-800) 3%, transparent);
}

.credi-axis-row:has(a:focus-visible) {
	outline: var(--wp--custom--focus--ring-width) solid var(--wp--custom--focus--ring-color);
	outline-offset: var(--wp--custom--focus--ring-offset);
}

.credi-axis-row:has(a:focus-visible) a:focus-visible {
	outline: none;
	box-shadow: none;
}

.credi-axis-row__number {
	font-size: var(--wp--preset--font-size--stat);
	font-weight: 900;
	line-height: 1;
	letter-spacing: -0.03em;
	color: var(--wp--custom--color--navy-rule);
}

.credi-axis-row__body {
	flex: 1;
	min-width: 0;
}

.credi-axis-row h3 a {
	color: inherit;
	text-decoration: none;
}

.credi-axis-row h3 a::after {
	content: "";
	position: absolute;
	inset: 0;
}

/* text-nav: its 26px line, not the root 1.625 of 17px, sets the row
   height where the arrow stacks under the text (below 40rem). */
.credi-axis-row::after {
	content: "→" / "";
	flex-shrink: 0;
	font-size: var(--wp--preset--font-size--nav);
	font-weight: 700;
	line-height: 1.625rem;
}

@media (min-width: 40rem) {
	.credi-axis-list .credi-axis-row {
		flex-direction: row;
		align-items: flex-start;
		gap: 2.5rem;
		margin: 0 -1.5rem;
		padding-inline: 1.5rem;
	}

	.credi-axis-row__number {
		flex: 0 0 7rem;
	}
}

/* Latest news */
.credi-news__header > * {
	margin: 0;
}

.credi-news__intro {
	max-width: 46ch;
}

/* lg:flex-row lg:items-baseline: from lg the title and intro stay on one
   row, both shrinking near 1024px instead of wrapping, and share a baseline
   (the layout's own alignment is bottom). */
@media (min-width: 64rem) {
	.credi-news__intro {
		text-align: right;
	}

	.credi-news .credi-news__header {
		flex-wrap: nowrap;
		align-items: baseline;
	}
}

.wp-block-post-template.credi-teasers {
	gap: 2.5rem 4rem;
}

@media (max-width: 47.999rem) {
	.wp-block-post-template.credi-teasers {
		grid-template-columns: minmax(0, 1fr);
	}
}

.credi-teasers > li {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
}

.credi-teasers > li > * {
	margin: 0;
}

.credi-teasers .wp-block-post-featured-image img {
	transition: opacity 150ms;
}

.credi-teasers > li:hover .wp-block-post-featured-image img {
	opacity: 0.9;
}

.credi-teasers .wp-block-post-title,
.credi-teasers .wp-block-post-excerpt__excerpt {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	overflow: hidden;
	margin: 0;
}

.credi-teasers .wp-block-post-title {
	-webkit-line-clamp: 2;
	line-clamp: 2;
	line-height: 1.25;
	letter-spacing: -0.015em;
}

.credi-teasers .wp-block-post-excerpt__excerpt {
	-webkit-line-clamp: 3;
	line-clamp: 3;
}

.credi-teasers .wp-block-post-title a {
	color: inherit;
	text-decoration: none;
}

.credi-teasers .wp-block-post-title a::after {
	content: "";
	position: absolute;
	inset: 0;
}

/* Scientific direction. The 5% grain is decoration, so it stays here
   rather than in the editable content. */
.credi-direction {
	position: relative;
	isolation: isolate;
	overflow: hidden;
}

.credi-direction::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background: url("assets/images/direction-watermark.jpg") center / cover no-repeat;
	opacity: 0.05;
}

.wp-block-columns.credi-direction__columns {
	gap: 2.5rem 5rem;
}

.credi-direction__title {
	max-width: 30ch;
	letter-spacing: -0.025em;
}

.credi-direction__text {
	display: flex;
	flex-direction: column;
}

/* On wide screens the action closes the text column at the bottom, level
   with the end of the portrait. */
@media (min-width: 64rem) {
	.credi-direction__text > .credi-direction__action {
		margin-top: auto;
		justify-content: flex-end;
	}
}

.credi-direction .is-style-outline > .wp-block-button__link {
	padding: 0.75rem 1.375rem;
	border: 2px solid currentColor;
	background: transparent;
}

/* variant="ghost": hover:bg-white hover:text-navy-800 keeps border-white,
   so the border must not follow the text colour to navy. */
.credi-direction .is-style-outline > .wp-block-button__link:hover {
	border-color: var(--wp--preset--color--white);
	background: var(--wp--preset--color--white);
	color: var(--wp--preset--color--navy-800) !important;
}

/* variant="inactive" (the hero action): bg-grey-300 hover:bg-grey-300/80.
   The preset class paints its background with !important, which kept the
   theme's navy hover off and the button unchanged under the pointer. */
.wp-block-button__link.has-grey-300-background-color:hover {
	background-color: color-mix(in oklab, var(--wp--preset--color--grey-300) 80%, transparent) !important;
}

.credi-direction__portrait {
	max-width: 360px;
}

.credi-direction__portrait figure {
	margin: 0;
}

.credi-direction__portrait figcaption {
	margin: 1.25rem 0 0;
	text-align: left;
	font-size: var(--wp--preset--font-size--caption);
	font-weight: 500;
	line-height: 1.25rem;
	letter-spacing: normal;
	color: color-mix(in srgb, currentColor 80%, transparent);
}

@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}

	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}

/* ------------------------------------------------------------------
 * Inner pages: page header, editorial sections, the axes and
 * partnership pages, and the 404. New rules only; the shared pieces
 * above (eyebrow, measure, split columns, axis rows, direction band)
 * are reused as they are.
 * ------------------------------------------------------------------ */

/* Page header. The 8% photographic wash is decoration, so it stays here
   rather than in the editable content, as the direction grain does. */
.credi-page-header {
	position: relative;
	isolation: isolate;
	overflow: hidden;
}

.credi-page-header::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background: url("assets/images/page-header-bg.jpg") center / cover no-repeat;
	opacity: 0.08;
}

/* A word too long for a 320px screen breaks instead of overflowing.
   Hyphenation follows the Astro title, which declares French; it only
   applies once the document language is French, so English rules never
   hyphenate French words. */
.credi-page-header h1 {
	overflow-wrap: break-word;
}

.credi-page-header h1:lang(fr) {
	hyphens: auto;
}

/* Short-label measure, max-w-measure-sm on the Astro site. */
.credi-measure-sm {
	max-width: var(--wp--custom--measure-sm);
}

/* Editorial sections: prose beside one oversized anchor, split 717/442 as
   in the design. The anchor leads on narrow screens; from 64rem it sits
   beside the prose, where assets/js/editorial-anchor.js fits it and clips
   it at its column. Without the script it may bleed toward the page edge,
   which the band clips (clip rather than hidden: it creates no scroll
   container). */
.credi-editorial {
	overflow-x: clip;
}

.wp-block-columns.credi-editorial__columns {
	gap: 2rem clamp(2.5rem, 5vw, 5.5rem);
}

.credi-editorial__anchor {
	white-space: nowrap;
}

@media (max-width: 63.999rem) {
	.credi-editorial__aside {
		order: -1;
	}
}

@media (min-width: 64rem) {
	.wp-block-column.credi-editorial__aside > * + * {
		margin-block-start: 1rem;
	}
}

/* Direction band without portrait: its text group opens up from 1.5rem to
   1.75rem on wide screens, as gap-7 does on the Astro band. Only the
   text-only pattern puts this group directly in the band. */
@media (min-width: 64rem) {
	.credi-direction > .wp-block-group.credi-direction__text {
		gap: 1.75rem;
	}
}

/* Numbered rows without a link (axes projects, partnership values): the
   axis row minus the hover tint, the arrow and the overhang that only a
   whole-row link needs. */
.credi-axis-list .credi-axis-row.credi-axis-row--static {
	margin-inline: 0;
	padding-inline: 0;
}

.credi-axis-row--static:hover {
	background-color: transparent;
}

.credi-axis-row--static::after {
	content: none;
}

/* Axes page: the jump links to each axis, and room above the heading
   they land on. */
/* Each link is a box, as FilterList's flex items are (stacked, items-start):
   a label that wraps keeps one hover and click area and one focus ring
   across its lines, not one per line fragment. */
.credi-filter-list a {
	display: block;
	width: fit-content;
	font-weight: 500;
	color: var(--wp--custom--color--navy-label);
	text-decoration: none;
}

.credi-filter-list a:hover {
	color: var(--wp--preset--color--navy-800);
}

.credi-axes-panel h3[id] {
	scroll-margin-top: 3rem;
}

/* Partnership introduction: text and illustration side by side from 64rem,
   the illustration capped at 568px. The file bakes its corners in at 40px
   of 1137 x 861, so a percentage radius (40/1137 across, 40/861 down)
   clips the same circular curve at any rendered size. */
.wp-block-columns.credi-partnership-intro__columns {
	gap: 2.5rem 4rem;
}

.credi-partnership-intro__title {
	max-width: 24ch;
}

.credi-partnership-intro__image img {
	width: 100%;
	border-radius: 3.518% / 4.646%;
}

@media (min-width: 64rem) {
	.credi-partnership-intro__media {
		max-width: 568px;
	}
}

/* 404: the site sections as a hairline-separated list of large links. */
.credi-sitemap-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

/* The item's own line height sets the strut the large link sits on; 1.5
   is the Astro base, which keeps each row at its height. */
.credi-sitemap-list > li {
	padding-block: 1rem;
	line-height: 1.5;
}

.credi-sitemap-list > li + li {
	border-top: 1px solid var(--wp--custom--color--navy-hairline);
}

.credi-sitemap-list a {
	font-size: var(--wp--preset--font-size--h-4);
	font-weight: 600;
	line-height: 1.25;
	letter-spacing: -0.015em;
	color: var(--wp--preset--color--navy-800);
	text-decoration: underline;
	text-underline-offset: 4px;
}

/* ------------------------------------------------------------------
 * Axes tablist (assets/js/axes-filter.js, WP-2c). New rules only. The
 * script turns the axes jump links into tabs; these rules give the tabs
 * their states, hide the groups it hides and cover the moment before it
 * runs. Mirrors FilterList and the axes rules in the Astro global.css.
 * ------------------------------------------------------------------ */

/* The selected tab takes the bold underline of an active filter option,
   driven by aria-selected so the script only sets the attribute. Focus
   keeps the theme ring from :focus-visible above. */
.credi-axes-filter [role="tab"][aria-selected="true"] {
	font-weight: 700;
	color: var(--wp--preset--color--navy-800);
	text-decoration-line: underline;
}

/* Hidden axis groups. The groups are flex layouts, and an author display
   outranks the browser's own [hidden] rule, so plain `hidden` needs this.
   hidden="until-found" keeps a box for find-in-page; taking it out of the
   flow stops the empty box from adding a column gap. */
.credi-axes-panel[hidden]:not([hidden="until-found"]) {
	display: none;
}

.credi-axes-panel[hidden="until-found"] {
	position: absolute;
}

/* Hidden visually only, so the text still reaches screen readers
   (Tailwind's sr-only): the directory heading while one axis shows, so its
   h2 still heads the section, and any block an editor gives the class. The
   heading group is a wrapping flex column, which at 1px tall would wrap
   each child into a column of its own width; nowrap keeps them 1px wide.
   Kept apart from the :has() rule below, which a browser without :has()
   drops whole. */
.credi-visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
	flex-wrap: nowrap;
}

/* If the script fails after `credi-js` is set. The `credi-nf-scripted`
   mark sets the class just ahead of the deferred script, so without
   JavaScript nothing here applies and every axis stays. Chrome resolves
   :target only once deferred scripts have run, so these rules do not stop
   a slow load from showing every axis first; they keep a fragment naming
   an axis showing only that axis when the script never runs, as on Astro.
   The script marks a strip ready once it has run, which retires them on
   the whole page, a duplicated strip included: replaceState leaves
   :target stale. The anchor sits on the axis heading, or on the group when
   an editor moves it there. */
.credi-js:not(:has(.credi-axes-filter[data-ready])):has(.credi-axes-panel:target, .credi-axes-panel :target)
	.credi-axes-heading {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
	flex-wrap: nowrap;
}

.credi-js:not(:has(.credi-axes-filter[data-ready])):has(.credi-axes-panel:target, .credi-axes-panel :target)
	.credi-axes-panel:not(:target):not(:has(:target)) {
	display: none;
}

/* Arriving by fragment on a group that holds the anchor itself: the
   browser focuses it and draws the ring for a reader who never used the
   keyboard. The script marks that one arrival and clears it on blur. */
.credi-axes-panel[data-arrived]:focus-visible {
	outline: none;
	box-shadow: none;
}
