/*
 * links.css — text link styles. Same idea as buttons.css.
 *
 * 1. Links in running text (blog posts, page and home content)
 *    No class needed. Links inside paragraphs and lists are berry and underlined.
 *    Hover darkens them at once, with no motion.
 *
 * 2. Links that act as a button ("Keep reading →", "See all events")
 *    Add the classes on the link itself or on a wrapper:
 *      - Editor: Paragraph / List / Group → Advanced → Additional CSS class(es).
 *        WordPress puts the class on the <p>, so every link inside it gets the style:
 *        p.link > a > [strong] > text + icon. Button-block links are left alone.
 *      - Templates or the editor's HTML view: <a class="link link-secondary" href="…">
 *    Always underlined. On hover the text and the underline darken with a short fade.
 *
 *    Classes:
 *      link             base (required)
 *      link-primary     berry (the default)
 *      link-secondary   green
 *
 * Size: links take the font size of the text around them. Change it with the
 * block's Typography size or the parent's font size, not here.
 *
 * Icons: Font Awesome icons added with the plugin (span.wp-font-awesome-icon > svg),
 * Font Awesome <i class="fa-…">, or an inline <svg class="link-icon"> work before or
 * after the words, also inside <strong>. The space next to the icon is replaced by a
 * gap, so the underline stays under the words only.
 *
 * Adding a color: one rule with --link-color and --link-color-hover (both at least
 * 4.5:1 on the background they sit on).
 */

/* ------------------------------------------------------------------ */
/* 1. Links in running text                                            */
/* ------------------------------------------------------------------ */

/* Wrapped in :where() so this is only a default: a link color picked in the block's
   settings (has-link-color) or a component's own link style still wins. */
:where(.post-single__content, .entry-content, .front-page__content, .is-root-container)
:where(p, .wp-block-list li, ul:not([class]) li, ol:not([class]) li):where(:not(.link))
a:where(:not(.wp-block-button__link, .btn, .link)) {
	color: var(--berry-button);
	text-decoration-line: underline;
	text-decoration-color: currentColor;
	text-decoration-thickness: max(1px, 0.0625em);
	text-underline-offset: 0.2em;
}

:where(.post-single__content, .entry-content, .front-page__content, .is-root-container)
:where(p, .wp-block-list li, ul:not([class]) li, ol:not([class]) li):where(:not(.link))
a:where(:not(.wp-block-button__link, .btn, .link)):where(:hover) {
	color: var(--berry-600);
}

:where(.post-single__content, .entry-content, .front-page__content, .is-root-container)
:where(p, .wp-block-list li, ul:not([class]) li, ol:not([class]) li):where(:not(.link))
a:where(:not(.wp-block-button__link, .btn, .link)):where(:focus-visible) {
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 2px;
}

/* ------------------------------------------------------------------ */
/* 2. Links that act as a button: .link                                */
/* ------------------------------------------------------------------ */

/* Color settings. Set on the link or on a wrapper, inherited by links inside. */
.link {
	--link-color: var(--berry-button);
	--link-color-hover: var(--berry-600);
	--link-line: max(1px, 0.08em);
	--link-offset: 0.2em;
}

.link-primary {
	--link-color: var(--berry-button);
	--link-color-hover: var(--berry-600);
}

.link-secondary {
	--link-color: var(--green-600);
	--link-color-hover: var(--green-700);
}

/* The link itself: a link/button with .link, or any link inside a wrapper with .link */
:is(a, button).link,
.link:not(a, button) a:not(.wp-block-button__link, .btn) {
	color: var(--link-color);
	font-weight: var(--link-font-weight);
	text-decoration-line: underline;
	text-decoration-color: currentColor;
	text-decoration-thickness: var(--link-line);
	text-underline-offset: var(--link-offset);
	cursor: pointer;
	transition: color 150ms ease;
}

button.link {
	padding: 0;
	border: 0;
	background: none;
	font: inherit;
	font-weight: var(--link-font-weight);
}

:is(a, button).link:hover,
.link:not(a, button) a:not(.wp-block-button__link, .btn):hover {
	color: var(--link-color-hover);
}

:is(a, button).link:focus-visible,
.link:not(a, button) a:not(.wp-block-button__link, .btn):focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
	border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
	:is(a, button).link,
	.link:not(a, button) a {
		transition: none;
	}
}

/* Icons. The link (or the <strong> holding the icon) lines its parts up in a row
   with a gap, so the typed space before or after the icon isn't underlined. */
:is(a, button).link:has(> :is(.link-icon, .wp-font-awesome-icon, .svg-inline--fa, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands)),
:is(a, button).link :has(> :is(.link-icon, .wp-font-awesome-icon, .svg-inline--fa, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands)),
.link:not(a, button) a:not(.wp-block-button__link, .btn):has(> :is(.link-icon, .wp-font-awesome-icon, .svg-inline--fa, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands)),
.link:not(a, button) a:not(.wp-block-button__link, .btn) :has(> :is(.link-icon, .wp-font-awesome-icon, .svg-inline--fa, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands)) {
	display: inline-flex;
	align-items: center;
	gap: 0.35em;
}

:is(a, button).link :is(.link-icon, .wp-font-awesome-icon, .svg-inline--fa, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands),
.link:not(a, button) a :is(.link-icon, .wp-font-awesome-icon, .svg-inline--fa, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands) {
	flex: none;
}

/* A <strong> (or other wrapper) holding the icon becomes its own row, and an underline
   doesn't reach inside such a box from the link, so it draws its own. */
:is(a, button).link :has(> :is(.link-icon, .wp-font-awesome-icon, .svg-inline--fa, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands)),
.link:not(a, button) a:not(.wp-block-button__link, .btn) :has(> :is(.link-icon, .wp-font-awesome-icon, .svg-inline--fa, .fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands)) {
	text-decoration: inherit;
}

/* The theme's own icon (an inline <svg class="link-icon">). Font Awesome sizes itself. */
.link-icon {
	width: 1em;
	height: 1em;
}
