/**
 * Foliora: site-wide layout settings (Customizer > Foliora Options > General).
 *
 * Container width, corner style and button shape are CSS variables set by
 * the Customizer; the fallbacks below are the defaults. Corner radii in the
 * other files are written as calc(Npx * var(--foliora-corner-scale, 1)).
 */

/* ---------- Writing direction (left-to-right and right-to-left) ----------
   Spacing and positions use logical properties (margin-inline-start, ...),
   which follow the page direction by themselves. What they can't flip
   (sideways movement, shadow offsets) is multiplied by --foliora-dir:
   1 in left-to-right, -1 in right-to-left (WordPress puts dir="rtl" on
   <html> for RTL languages). */
:root {
	--foliora-dir: 1;
	--foliora-start: left; /* The start side, for transform-origin etc. */
}

[dir="rtl"] {
	--foliora-dir: -1;
	--foliora-start: right;
}

/* Arrows that mean "forward" or "back" point the other way in RTL. Uses
   the scale property, so a transform on the icon (a hover nudge) still
   applies. */
[dir="rtl"] .foliora-icon--chevron-right,
[dir="rtl"] .foliora-icon--chevron-left,
[dir="rtl"] .foliora-icon--arrow-right,
[dir="rtl"] .foliora-icon--arrow-left {
	scale: -1 1;
}

/* Container width on wide screens (Bootstrap uses 1320px from 1400px). */
@media (min-width: 1400px) {
	.container {
		max-width: var(--foliora-container, 1320px);
	}
}

/* Phones: 16px side space on every page, the same as the story text
   (Bootstrap's 12px left the header, lists and story at different edges). */
@media (max-width: 575.98px) {
	.container {
		--bs-gutter-x: 32px;
	}
}

/* ---------- Keyboard focus ---------- */
/* One visible ring for every link, button and field reached by keyboard
   (the template switched focus outlines off). Mouse clicks show none. */
:focus-visible {
	outline: 2px solid var(--foliora-link);
	outline-offset: 2px;
}

:focus:not(:focus-visible) {
	outline: none;
}

/* The sticky desktop header must not cover what keyboard focus or an anchor
   link scrolls to. --foliora-sticky-h is the header's visible height when
   stuck, measured by navigation.js (0 when the header isn't sticky). */
@media (min-width: 992px) {
	html {
		scroll-padding-top: calc(var(--foliora-sticky-h, 107px) + 13px);
	}

	html:has(body.admin-bar) {
		scroll-padding-top: calc(var(--foliora-sticky-h, 107px) + 45px);
	}
}

/* ---------- Icons (inc/icons.php) ---------- */
/* Inline SVGs sized like the icon font they replaced: 1em, on the baseline. */
.foliora-icon {
	display: inline-block;
	width: 1em;
	height: 1em;
	vertical-align: -0.125em;
	flex-shrink: 0;
	/* The stroke below draws half its width outside the 16x16 box; without
	   this the browser clips the icon's outer edges. */
	overflow: visible;
}

/* Thin line icons: Bootstrap's outlines (1px at 16px) with a light
   stroke in the icon's colour, about 1.25px in all. */
.foliora-icon path {
	stroke: currentColor;
	stroke-width: 0.25;
	stroke-linejoin: round;
}

/* The menu's small dropdown arrow (0.7em) would fade at that weight. */
#inner-navigation .foliora-icon--chevron-down {
	width: 0.7em;
	height: 0.7em;
	vertical-align: 0;
}

#inner-navigation .foliora-icon--chevron-down path {
	stroke-width: 0.8;
}

/* ---------- Page loader (off by default) ---------- */
/* Covers the page only until it can be read: main.js fades it out as soon
   as the HTML, CSS and fonts are ready, without waiting for images, ads or
   embeds. Customizer > General > Extras. */
#preloader {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
	/* Safety net: hide the loader even if JavaScript never runs. */
	animation: foliora-loader-out 0.3s ease 2.5s forwards;
}

#preloader.is-loaded {
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.foliora-loader__spinner {
	width: 40px;
	height: 40px;
	border: 3px solid var(--foliora-line);
	border-top-color: var(--foliora-accent);
	border-radius: 50%;
	animation: foliora-spin 0.8s linear infinite;
}

@keyframes foliora-spin {
	to {
		transform: rotate(360deg);
	}
}

@keyframes foliora-loader-out {
	to {
		opacity: 0;
		visibility: hidden;
	}
}

/* Without JavaScript nothing would take it away early: don't show it. */
html:not(.foliora-js) #preloader {
	display: none;
}

/* A spinner is motion: visitors who ask for less never see the loader. */
@media (prefers-reduced-motion: reduce) {
	#preloader {
		display: none;
	}
}

/* ---------- Sidebar width ----------
   Customizer > Sidebar > Sidebar width sets --foliora-sidebar-w (300, 340
   or 380px; inc/customizer/layout.php). Laptops (992-1199px) get half of
   it + 130px: 280, 300 or 320px. Used by posts.css and single.css. */
:root {
	--foliora-sidebar-w-md: calc(var(--foliora-sidebar-w, 340px) * 0.5 + 130px);
}

/* ---------- Back-to-top button ---------- */
/* A <button> named "foliora-up", with its label as hidden text instead of an
   aria-label: ad blockers' annoyance lists hide elements called back-to-top
   or labelled "Back to top". Shown with the "is-visible" class (main.js) and
   a CSS transition, not jQuery fades. */
.foliora-up {
	position: fixed;
	inset-inline-end: 20px; /* Bottom right; bottom left in RTL. */
	bottom: 20px;
	z-index: 1020;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 45px;
	height: 45px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	background: var(--foliora-accent);
	color: var(--foliora-on-accent);
	font-size: 18px;
	text-decoration: none;
	box-shadow: 0 4px 14px color-mix(in srgb, var(--foliora-shade) 25%, transparent);
	opacity: 0;
	visibility: hidden;
	transform: translateY(8px);
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease, background-color 0.2s ease;
}

/* Customizer > General > Extras: bottom left, or not on phones. */
.foliora-up--left {
	inset-inline-end: auto;
	inset-inline-start: 20px;
}

@media (max-width: 767px) {
	.foliora-up--wide-only {
		display: none;
	}
}

/*
 * "Hide on phones" switches (slider, featured links, related stories):
 * same breakpoint as the back-to-top switch. !important because each
 * block sets its own display later in its own file.
 */
@media (max-width: 767px) {
	.foliora-hide-phone {
		display: none !important;
	}
}

.foliora-up.is-visible {
	opacity: 1;
	visibility: visible;
	transform: none;
}

.foliora-up:hover,
.foliora-up:focus-visible {
	background: var(--foliora-accent-hover);
	color: var(--foliora-on-accent);
}

.foliora-up:focus-visible {
	outline: 2px solid var(--foliora-accent);
	outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
	.foliora-up {
		transition: none;
	}
}

/* ---------- Very long words ---------- */
/* A long word or URL (a place name like Taumatawhakatangihanga..., a pasted
   link) wraps instead of pushing the page sideways. Titles may break
   anywhere; other text only when a word doesn't fit on its own line. */
body {
	overflow-wrap: break-word;
}

h1,
h2,
h3,
h4,
h5,
h6,
[class*="__title"] {
	overflow-wrap: anywhere;
}

/* ---------- Page background (boxed) ----------
   WordPress adds .custom-background to <body> when Customizer > Page
   background has a colour or an image (printed by WordPress on <body>).
   From 1200px the site becomes a centred sheet in the page colour and the
   background shows around it; the sheet is the container plus 48px a side,
   and never closer than 32px to the window edges. Below 1200px the site is
   full width and the sheet still paints the page colour, so text never sits
   on the image. --foliora-page-w is the width full-width blocks use
   (single.css). No overflow or transform on the sheet: either would break
   the sticky header or fixed panels inside it. */
.foliora-site {
	background: var(--foliora-bg);
}

/* The window's width without its scrollbar (measured in foliora_js_class(),
   functions.php; 0 without JavaScript or with overlay scrollbars). 100vw
   alone includes the scrollbar, so full-width blocks stuck out under it. */
:root {
	--foliora-vw: calc(100vw - var(--foliora-scrollbar, 0px));
}

@media (min-width: 1200px) {
	body:is(.custom-background, .foliora-bg-pattern) {
		--foliora-page-w: min(calc(var(--foliora-vw) - 64px), 1236px);
	}

	body:is(.custom-background, .foliora-bg-pattern) .foliora-site {
		width: var(--foliora-page-w);
		margin: 0 auto;
		box-shadow: 0 0 0 1px rgb(0 0 0 / 0.04), 0 12px 48px rgb(0 0 0 / 0.12);
	}

	/* Back to top stays in the sheet's corner, not on the background (where
	   it looked detached and could clash with the colour or image). 100% is
	   the window without its scrollbar, like the sheet's centring. */
	body:is(.custom-background, .foliora-bg-pattern) .foliora-up {
		inset-inline-end: calc((100% - var(--foliora-page-w)) / 2 + 20px);
	}
}

@media (min-width: 1400px) {
	body:is(.custom-background, .foliora-bg-pattern) {
		--foliora-page-w: min(calc(var(--foliora-vw) - 64px), calc(var(--foliora-container, 1320px) + 96px));
	}
}

/* Predefined pattern around the page (Page Background, printed by
   foliora_bg_pattern_css() in inc/customizer/background.php). The tile is a
   mask, so the lines take a colour: a tint of the heading colour (follows
   the scheme and dark mode), or white or black over a custom colour
   (--foliora-pattern-base). Without a custom colour the page sits on the
   soft background. A fixed layer behind the sheet: it doesn't scroll, and
   the body is isolated so the layer paints above the body's background.
   Below 1200px the sheet covers it, so it isn't drawn at all. */
@media (min-width: 1200px) {
	body:where(.foliora-bg-pattern) {
		background-color: var(--foliora-surface);
	}

	body.foliora-bg-pattern {
		isolation: isolate;
	}

	body.foliora-bg-pattern::before {
		content: "";
		position: fixed;
		inset: 0;
		z-index: -1;
		background-color: color-mix(in srgb, var(--foliora-pattern-base, var(--foliora-text)) var(--foliora-pattern-strength, 7%), transparent);
		-webkit-mask: var(--foliora-pattern) 0 0 / var(--foliora-pattern-size) repeat;
		mask: var(--foliora-pattern) 0 0 / var(--foliora-pattern-size) repeat;
		pointer-events: none;
	}

	/* Customizer preview: an image was just chosen (it replaces the pattern
	   after the next reload; customize-preview.js). */
	body.foliora-bg-pattern.foliora-bg-pattern--off::before {
		display: none;
	}
}
