/*
Theme Name: Global Chinese Press
Theme URI: https://gcpnews.ca
Description: Child theme of Twenty Twenty-Five for Global Chinese Press (环球华报). Classic broadsheet layout in black, white and grey. China-safe: fonts are self-hosted and nothing loads from outside services.
Author: Global Chinese Press
Template: twentytwentyfive
Version: 0.1.0
Requires at least: 6.7
Requires PHP: 7.2
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: gcpnews
*/

/*
 * Colours, fonts and sizes live in theme.json.
 * This file only holds layout details theme.json cannot express,
 * such as thin dividers between grid columns.
 */

/* ---------- Shared ---------- */

/* Hidden on screen, still read by search engines and screen readers. */
.gcp-visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

/*
 * Links: while a mouse or trackpad pointer is over a link, its text fades
 * to the logo's red, and fades back as soon as the pointer leaves (buttons
 * keep their own colours). No link is underlined on hover, including the
 * underlines WordPress and the parent theme add.
 * The red needs a pointer that can hover. On a touch screen a tap counts
 * as hover until the next tap elsewhere, which would leave the link red,
 * so the red is skipped on devices without a mouse (any-hover) and, on
 * devices with both, after a finger tap (.gcp-touch, set by
 * gcpnews_touch_flag_script() in functions.php).
 * Ticker headlines move under a still pointer, and browsers only re-check
 * what is under the pointer when it moves, so in the ticker a script marks
 * the headline really under the pointer (.is-pointed) instead.
 * The red (#C5161D) is "logo-red" in theme.json.
 */
.wp-site-blocks a {
	transition: color 0.15s ease;
}

.wp-site-blocks a:not(.wp-element-button):hover {
	text-decoration-line: none;
}

@media (any-hover: hover) {
	:where(html:not(.gcp-touch)) .wp-site-blocks a:not(.wp-element-button):hover,
	.wp-site-blocks .gcp-ticker__list a.is-pointed {
		color: var(--wp--preset--color--logo-red);
	}
}

/*
 * The parent theme outlines anything that has focus, so a mouse click left
 * a black box around links and buttons. Keep that outline only for keyboard
 * users (:focus-visible), who need it to see where they are. Text boxes
 * (like search) show a darker border instead of the box.
 */
.wp-site-blocks :focus:not(:focus-visible),
.wp-site-blocks :is(input, textarea, select):focus {
	outline: none;
}

.wp-site-blocks :is(input, textarea, select):focus {
	border-color: var(--wp--preset--color--contrast);
}

/* Small bold label above each block, e.g. 财经, with a heavy rule on top. */
.gcp-section-label {
	font-family: var(--wp--preset--font-family--sans);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 700;
	letter-spacing: 0.1em;
	line-height: 1.4;
	margin: 0 0 0.75rem;
	padding-top: 0.5rem;
	border-top: 2px solid var(--wp--preset--color--contrast);
}

.gcp-section-label a {
	color: inherit;
	text-decoration: none;
}

/* Headline-only lists: a thin grey rule between items. */
.gcp-titles .wp-block-post-template > li + li {
	border-top: 1px solid var(--wp--preset--color--accent-6);
	padding-top: 0.6rem;
	margin-top: 0.6rem;
}

/* ---------- Masthead ---------- */

/*
 * The logo: at most 300px wide on a laptop, shrinking to 165px on phones
 * (25% smaller than the first version, at the owner's request).
 * aspect-ratio reserves its space before the file loads, so nothing jumps.
 */
.gcp-logo {
	margin-bottom: 0;
	text-align: center;
}

.gcp-logo img {
	display: block;
	width: clamp(165px, 25.5vw, 300px);
	height: auto;
	aspect-ratio: 433.8 / 142.9;
	margin: 0 auto;
}

/* WordPress makes the logo link inline-block, which sits it on a text line
 * and adds about 10px under the logo; a block link removes that gap. */
.gcp-logo a,
.gcp-footer-logo a {
	display: block;
}

.gcp-dateline {
	margin: 0;
}

/*
 * Phones: the section menu stays one row of links, as on a computer (no ☰
 * button; that is switched off in parts/header.html). The seven sections are
 * spread evenly across the full width with a small minimum gap, so they fit
 * on one line down to a 320px-wide phone.
 */
@media (max-width: 600px) {
	.gcp-navband > .gcp-sections {
		flex: 1 1 auto;
	}

	.gcp-sections .wp-block-navigation__container {
		width: 100%;
		justify-content: space-between;
		column-gap: 0.5rem;
	}
}

/* ---------- Ticker (scrolling headlines under the menu) ---------- */

.gcp-ticker {
	position: relative;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.45rem 0;
	border-bottom: 1px solid var(--wp--preset--color--accent-6);
	font-family: var(--wp--preset--font-family--sans);
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.5;
}

/* Fixed label on the left, e.g. 房产 or 最新. */
.gcp-ticker__label {
	flex: none;
	font-weight: 700;
	white-space: nowrap;
	padding-right: 0.75rem;
	border-right: 1px solid var(--wp--preset--color--accent-6);
}

/*
 * The window the headlines scroll through, with soft fades at both edges.
 * The whole strip shows the hand cursor: headlines slide under a still
 * pointer, and browsers only update the cursor when the mouse moves.
 */
.gcp-ticker__viewport {
	order: 1;
	flex: 1;
	min-width: 0;
	position: relative; /* Keeps the hidden screen-reader colons inside the bar. */
	overflow: hidden;
	cursor: pointer;
	scroll-padding-inline: 2rem; /* Keyboard focus scrolls a headline fully into view. */
	-webkit-mask-image: linear-gradient(to right, transparent, #000 1.5rem, #000 calc(100% - 1.5rem), transparent);
	mask-image: linear-gradient(to right, transparent, #000 1.5rem, #000 calc(100% - 1.5rem), transparent);
}

/*
 * The motion is two layers, one inside the other (.gcp-ticker__track holds
 * .gcp-ticker__belt), each sliding left at half speed: together they make
 * full speed. Under the mouse the inner layer pauses, so the strip slows
 * to exactly half speed, and when the mouse leaves it carries on from
 * where it was. Pausing never jumps, so neither does the slow-down, and
 * no script is needed for it.
 * The loop is written three times in a row (functions.php). Each layer
 * slides left by one loop and starts again; the copies are identical, so
 * the restart cannot be seen. --gcp-ticker-duration is the time one layer
 * takes for one loop (set by functions.php).
 */
.gcp-ticker__track,
.gcp-ticker__belt {
	display: flex;
	width: max-content;
	animation: gcp-ticker-scroll var(--gcp-ticker-duration, 80s) linear infinite;
}

.gcp-ticker__list {
	display: flex;
	flex: none;
	gap: 2.5rem;
	margin: 0;
	padding: 0 2.5rem 0 0; /* Same as the gap, so the seam between copies matches. */
	list-style: none;
}

.gcp-ticker__list li {
	white-space: nowrap;
}

.gcp-ticker__list a {
	color: inherit;
	text-decoration: none;
}

/*
 * While the ticker script follows the pointer, only the headline really
 * under it is red (.is-pointed, see the Links rules); a headline that has
 * slid away is not left red.
 */
.gcp-ticker.is-tracking .gcp-ticker__list a:not(.is-pointed) {
	color: inherit;
}

.gcp-ticker__tag {
	font-weight: 700;
}

@keyframes gcp-ticker-scroll {
	from {
		transform: translateX(0);
	}
	to {
		transform: translateX(calc(-100% / 3)); /* One loop of the three. */
	}
}

/*
 * Under a mouse or trackpad pointer: half speed (the inner layer pauses).
 * Not after a finger tap (see the Links rules), so a tap on a phone does
 * not leave the strip slowed.
 */
@media (any-hover: hover) {
	:where(html:not(.gcp-touch)) .gcp-ticker:hover .gcp-ticker__belt {
		animation-play-state: paused;
	}
}

/*
 * Stop when paused with the button. A headline clicked with the mouse no
 * longer stops it: that left the strip stopped after the mouse moved away
 * and after coming Back to the page. Keyboard focus is handled below.
 */
.gcp-ticker__toggle:checked ~ .gcp-ticker__viewport .gcp-ticker__track,
.gcp-ticker__toggle:checked ~ .gcp-ticker__viewport .gcp-ticker__belt {
	animation-play-state: paused;
}

/*
 * Keyboard users: while a headline has keyboard focus, the strip stops,
 * returns to the start and becomes a still row that scrolls to the
 * focused headline, so focus never sits on something off-screen.
 * (:focus-visible, so a mouse click on a headline does not reset it.)
 */
.gcp-ticker__viewport:has(a:focus-visible) :is(.gcp-ticker__track, .gcp-ticker__belt) {
	animation: none;
}

.gcp-ticker__viewport:has(a:focus-visible) .gcp-ticker__list[aria-hidden="true"],
.gcp-ticker__viewport:has(a:focus-visible) li[aria-hidden="true"] {
	display: none;
}

/* Pause / play button on the right, drawn with borders (no emoji). */
.gcp-ticker__pause {
	order: 2;
	flex: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.75rem;
	height: 1.75rem;
	cursor: pointer;
	color: var(--wp--preset--color--accent-4);
}

.gcp-ticker__pause:hover {
	color: var(--wp--preset--color--contrast);
}

.gcp-ticker__pause::before {
	content: "";
	box-sizing: border-box;
	width: 8px;
	height: 10px;
	border-left: 3px solid currentColor;
	border-right: 3px solid currentColor;
}

.gcp-ticker__toggle:checked + .gcp-ticker__pause::before {
	width: 0;
	height: 0;
	border-right: 0;
	border-left: 9px solid currentColor;
	border-top: 6px solid transparent;
	border-bottom: 6px solid transparent;
}

.gcp-ticker__toggle:focus-visible + .gcp-ticker__pause {
	outline: 2px solid var(--wp--preset--color--contrast);
	outline-offset: 2px;
}

/*
 * Keep the invisible checkbox on top of its visible button (right end),
 * so screen magnifiers and screen readers point at the right place.
 */
.gcp-ticker__toggle {
	top: 50%;
	right: 0.875rem;
}

/* Windows high-contrast themes: keep the play icon a triangle. */
@media (forced-colors: active) {
	.gcp-ticker__toggle:checked + .gcp-ticker__pause::before {
		border-top-color: Canvas;
		border-bottom-color: Canvas;
	}
}

/* Readers who ask their device for less motion get a still, swipeable row. */
@media (prefers-reduced-motion: reduce) {
	.gcp-ticker__track,
	.gcp-ticker__belt {
		animation: none;
	}

	.gcp-ticker__viewport {
		overflow-x: auto;
		cursor: auto;
		-webkit-mask-image: none;
		mask-image: none;
	}

	.gcp-ticker__list[aria-hidden="true"],
	.gcp-ticker__list li[aria-hidden="true"],
	.gcp-ticker__toggle,
	.gcp-ticker__pause {
		display: none;
	}
}

/* ---------- Homepage ---------- */

.gcp-lead .wp-block-post-title {
	line-height: 1.25;
	margin-top: 0.5rem;
}

.gcp-grid {
	border-top: 1px solid var(--wp--preset--color--accent-6);
	padding-top: var(--wp--preset--spacing--30);
	margin-top: var(--wp--preset--spacing--40);
}

.gcp-sections-row {
	margin-top: var(--wp--preset--spacing--60);
}

/* A section block with no stories left to show (all already appear higher
 * up the homepage) is hidden instead of leaving a bare heading. */
.gcp-sections-row > .gcp-section-block:not(:has(.wp-block-post)) {
	display: none;
}

/*
 * Thin vertical dividers between the 3 grid columns (tablet and up).
 * The columns stay exactly equal: each divider is drawn in the middle of
 * the gap between two columns instead of taking space from inside one.
 */
@media (min-width: 601px) {
	.gcp-grid .wp-block-post-template {
		column-gap: 2.5rem;
	}

	.gcp-grid .wp-block-post-template > li {
		position: relative;
	}

	.gcp-grid .wp-block-post-template > li:not(:nth-child(3n+1))::before {
		content: "";
		position: absolute;
		top: 0;
		bottom: 0;
		left: -1.25rem; /* Half the gap. */
		border-left: 1px solid var(--wp--preset--color--accent-6);
	}
}

/* Desktop: divider beside the side column, and equal section blocks
 * with dividers drawn in the gaps between them (same idea as the grid). */
@media (min-width: 782px) {
	.gcp-side-col {
		border-left: 1px solid var(--wp--preset--color--accent-6);
		padding-left: var(--wp--preset--spacing--40);
	}

	.gcp-sections-row.wp-block-columns {
		column-gap: 2.5rem;
	}

	.gcp-sections-row > .wp-block-column {
		position: relative;
	}

	.gcp-sections-row > .wp-block-column + .wp-block-column::before {
		content: "";
		position: absolute;
		top: 0;
		bottom: 0;
		left: -1.25rem; /* Half the gap. */
		border-left: 1px solid var(--wp--preset--color--accent-6);
	}
}

/* ---------- 最多阅读 / 更多新闻 (homepage side column) ---------- */

.gcp-most-read {
	list-style: none;
	margin: 0;
	padding: 0;
	counter-reset: gcp-rank;
}

.gcp-most-read li {
	padding: 0.6rem 0;
	border-top: 1px solid var(--wp--preset--color--accent-6);
}

.gcp-most-read li:first-child {
	padding-top: 0;
	border-top: 0;
}

.gcp-most-read a {
	color: inherit;
	text-decoration: none;
	font-family: var(--wp--preset--font-family--serif);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 600;
	line-height: 1.5;
}

.gcp-most-read__date {
	display: block;
	margin-top: 0.25rem;
	font-family: var(--wp--preset--font-family--sans);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--accent-4);
}

/* 最多阅读: a bold rank number beside each headline, the same size as the headline
 * and level with its first line (owner found the larger number too big). */
.gcp-most-read.is-ranked li {
	display: grid;
	grid-template-columns: 1.5rem minmax(0, 1fr);
	column-gap: 0.5rem;
	counter-increment: gcp-rank;
}

.gcp-most-read.is-ranked li::before {
	content: counter(gcp-rank);
	font-family: var(--wp--preset--font-family--serif);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 700;
	line-height: 1.5;
	color: var(--wp--preset--color--accent-1);
}

/* ---------- Section pages (加拿大, 国际, 财经, 房产, 教育, 生活) ---------- */

/* Big centred section name with a rule under it. */
.gcp-section-head {
	text-align: center;
	padding-bottom: var(--wp--preset--spacing--20);
	margin-bottom: var(--wp--preset--spacing--30);
	border-bottom: 1px solid var(--wp--preset--color--contrast);
}

.gcp-section-head .gcp-section-title {
	margin: 0;
	font-size: var(--wp--preset--font-size--xx-large);
	font-weight: 700;
	letter-spacing: 0.08em;
}

.gcp-section-head .gcp-section-desc {
	margin: 0.25rem 0 0;
	color: var(--wp--preset--color--accent-4);
	font-size: var(--wp--preset--font-size--medium);
}

/* The list of stories: a thin grey rule between rows. */
.gcp-river .wp-block-post-template > li + li {
	border-top: 1px solid var(--wp--preset--color--accent-6);
	padding-top: var(--wp--preset--spacing--30);
	margin-top: var(--wp--preset--spacing--30);
}

.gcp-river .gcp-river-item > *,
.gcp-river .gcp-river-text > * {
	margin-block-start: 0;
}

.gcp-river .gcp-river-title {
	margin: 0 0 0.5rem;
	font-size: var(--wp--preset--font-size--x-large);
	line-height: 1.3;
}

.gcp-river .gcp-river-excerpt {
	margin: 0 0 0.5rem;
}

.gcp-river .gcp-river-date {
	margin: 0;
}

/* Phones: picture above the text. */
.gcp-river .gcp-river-image {
	margin: 0 0 0.75rem;
}

/* The lead (first story on page 1 only; pages 2+ carry the "paged" class). */
body:not(.paged) .gcp-section-front .gcp-river .wp-block-post-template > li:first-child .gcp-river-title {
	font-size: var(--wp--preset--font-size--xx-large);
}

/* Tablets and up: text on the left, picture on the right. */
@media (min-width: 782px) {
	.gcp-river .gcp-river-item {
		display: grid;
		grid-template-columns: minmax(0, 1fr) 280px;
		column-gap: var(--wp--preset--spacing--40);
		align-items: start;
	}

	.gcp-river .gcp-river-image {
		grid-column: 2;
		grid-row: 1;
		margin: 0;
	}

	.gcp-river .gcp-river-text {
		grid-column: 1;
		grid-row: 1;
	}

	/* The lead: big picture on the left, big headline on the right. */
	body:not(.paged) .gcp-section-front .gcp-river .wp-block-post-template > li:first-child .gcp-river-item {
		grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
	}

	body:not(.paged) .gcp-section-front .gcp-river .wp-block-post-template > li:first-child .gcp-river-image {
		grid-column: 1;
	}

	body:not(.paged) .gcp-section-front .gcp-river .wp-block-post-template > li:first-child .gcp-river-text {
		grid-column: 2;
	}

	/* A story with no picture uses the full width (lead included). */
	.gcp-river .gcp-river-item:not(:has(.gcp-river-image)),
	body:not(.paged) .gcp-section-front .gcp-river .wp-block-post-template > li:first-child .gcp-river-item:not(:has(.gcp-river-image)) {
		grid-template-columns: minmax(0, 1fr);
	}

	.gcp-river .gcp-river-item:not(:has(.gcp-river-image)) .gcp-river-text,
	body:not(.paged) .gcp-section-front .gcp-river .wp-block-post-template > li:first-child .gcp-river-item:not(:has(.gcp-river-image)) .gcp-river-text {
		grid-column: 1;
	}
}

/* "No articles yet" message for an empty section. */
.gcp-river .gcp-river-empty {
	text-align: center;
	color: var(--wp--preset--color--accent-4);
	padding: var(--wp--preset--spacing--50) 0;
}

/* Page links: 上一页 1 2 3 下一页 */
.gcp-river .gcp-pagination {
	margin-top: var(--wp--preset--spacing--50);
	padding-top: var(--wp--preset--spacing--30);
	border-top: 1px solid var(--wp--preset--color--contrast);
	font-family: var(--wp--preset--font-family--sans);
	font-size: var(--wp--preset--font-size--small);
}

.gcp-river .gcp-pagination a {
	text-decoration: none;
}

.gcp-river .gcp-pagination .current {
	font-weight: 700;
}

/* ---------- Article pages ---------- */

/* Section label, big headline and date, in the reading column. */
.gcp-article .gcp-article-head > * {
	margin-block-start: 0;
}

.gcp-article .gcp-article-section {
	margin: 0 0 0.5rem;
}

.gcp-article .gcp-article-title {
	margin: 0 0 0.75rem;
	font-size: var(--wp--preset--font-size--xx-large);
	font-weight: 700;
	line-height: 1.3;
}

.gcp-article .gcp-article-date {
	margin: 0;
}

/* Lead picture: wider than the text, but never more than 960px. */
.gcp-article > .gcp-article-image.alignwide {
	max-width: 960px;
	margin-top: var(--wp--preset--spacing--40);
}

/* Photo caption and credit under the lead picture. */
.gcp-article .gcp-article-caption {
	margin: 0.5rem 0 0;
	text-align: left;
}

/* Credit links in the caption stay in the line of text. (WordPress makes
 * every link inside the photo frame a full-width block, which is meant
 * for the photo's own link.) */
.gcp-article .gcp-article-caption a {
	display: inline;
	height: auto;
}

/* The story text. */
.gcp-article .gcp-article-body {
	margin-top: var(--wp--preset--spacing--40);
}

/* "更多…新闻": other stories from the same section, in the 3-column grid. */
.gcp-article .gcp-article-more {
	margin-top: var(--wp--preset--spacing--60);
}

.gcp-article .gcp-article-more > * {
	margin-block-start: 0;
}

.gcp-article .gcp-article-more .gcp-grid {
	border-top: 0;
	padding-top: 0;
	margin-top: 0;
}

/* ---------- Plain pages, search results and "page not found" ---------- */

/* Page title (关于我们, 联系我们 …) with a rule under it. */
.gcp-page .gcp-page-head {
	padding-bottom: var(--wp--preset--spacing--20);
	margin-bottom: var(--wp--preset--spacing--30);
	border-bottom: 1px solid var(--wp--preset--color--contrast);
}

.gcp-page .gcp-page-head > * {
	margin-block-start: 0;
}

.gcp-page .gcp-page-title {
	margin: 0;
	font-size: var(--wp--preset--font-size--xx-large);
	font-weight: 700;
	line-height: 1.3;
}

/* Search box on the search and "not found" pages. */
.gcp-search {
	margin-bottom: var(--wp--preset--spacing--40);
}

.gcp-search .wp-block-search__input {
	font-family: var(--wp--preset--font-family--sans);
}

/* "Not found": the six sections as a row of bold links. */
.gcp-not-found .gcp-404-sections {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1.5rem;
	margin: 0 0 var(--wp--preset--spacing--50);
	padding: 0;
	list-style: none;
	font-family: var(--wp--preset--font-family--sans);
	font-weight: 700;
}

.gcp-not-found .gcp-404-sections li {
	margin: 0;
}

.gcp-not-found .gcp-404-sections a {
	text-decoration: none;
}

/* ---------- Footer ---------- */

.gcp-footer {
	border-top: 1px solid var(--wp--preset--color--contrast);
}

/* Footer logo: a smaller copy of the masthead logo (about two-thirds). */
.gcp-footer-logo {
	margin: 0;
}

.gcp-footer-logo img {
	display: block;
	width: clamp(140px, 16vw, 200px);
	height: auto;
	aspect-ratio: 433.8 / 142.9;
}

.gcp-copyright {
	margin: 0;
}
