/*
 * Blogdan — Vignelli-minded: one typeface, two weights, black on white,
 * flush left / ragged right, a strict two-column grid and plain rules.
 * Tokens live in theme.json; this file only does what theme.json can't.
 */

:root {
	--blogdan-meta-col: 10rem;
	--blogdan-col-gap: 2.5rem;
	--blogdan-rule: 1px solid var(--wp--preset--color--contrast);
	--blogdan-band: 0.75rem solid var(--wp--preset--color--contrast);
}

/* ---- Overlay scrollbar (assets/js/scrollbar.js) ------------------------ */

html.blogdan-overlay-scroll {
	scrollbar-width: none;
}

html.blogdan-overlay-scroll::-webkit-scrollbar {
	display: none;
}

.blogdan-scrollbar {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	z-index: 1000;
	width: 14px;
	mix-blend-mode: difference; /* on the fixed element itself: it isolates its children */
	opacity: 0;
	transition: opacity 0.3s ease;
}

.blogdan-scrollbar.is-visible {
	opacity: 1;
	transition-duration: 0.1s;
}

.blogdan-scrollbar[hidden] {
	display: none;
}

/* White, blended with "difference" by the bar: black on white, white on the black band */
.blogdan-scrollbar__thumb {
	position: absolute;
	top: 0;
	right: 3px;
	width: 4px;
	background: #fff;
	cursor: default;
	transition: width 0.15s ease;
	touch-action: none;
}

.blogdan-scrollbar:hover .blogdan-scrollbar__thumb,
.blogdan-scrollbar.is-dragging .blogdan-scrollbar__thumb {
	width: 8px;
}

@media (prefers-reduced-motion: reduce) {
	.blogdan-scrollbar,
	.blogdan-scrollbar__thumb {
		transition: none;
	}
}

::selection {
	background: var(--wp--preset--color--accent);
	color: var(--wp--preset--color--base);
}

body {
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
	font-feature-settings: "kern", "calt";
}

/* ---- Grid: text column on the left, meta (date) on the right ------------ */
/* Meta comes first in the markup so it sits above the title on mobile. */

.wp-block-group.blogdan-grid {
	grid-template-columns: minmax(0, 1fr);
	column-gap: var(--blogdan-col-gap);
	row-gap: 0.5rem;
	align-items: baseline;
}

@media (min-width: 782px) {
	.wp-block-group.blogdan-grid {
		grid-template-columns: minmax(0, var(--wp--style--global--content-size)) minmax(var(--blogdan-meta-col), 1fr);
	}

	.wp-block-group.blogdan-grid > * {
		grid-column: 1;
		grid-row: 1;
	}

	/*
	 * Cap-align the meta with the lead line (title) in the other column.
	 * Distance from a line box's top to the top of the capitals, in Inter:
	 *   font-size * ((line-height - 1.20996) / 2 + 0.24121)
	 * (ascender 1984 + descender 494 = 2478/2048 = 1.20996; ascender - cap height = 494/2048 = 0.24121)
	 * The meta is pushed down by the lead's offset minus its own.
	 */
	.wp-block-group.blogdan-grid {
		align-items: start;
	}

	.wp-block-group.blogdan-grid > .blogdan-meta {
		grid-column: 2;
		justify-self: end;
		text-align: right;
		line-height: var(--blogdan-meta-lh);
		margin-top: calc(
			var(--blogdan-lead-fs) * ((var(--blogdan-lead-lh) - 1.20996) / 2 + 0.24121)
			- var(--wp--preset--font-size--small) * ((var(--blogdan-meta-lh) - 1.20996) / 2 + 0.24121)
		);
	}
}

/* What the meta column aligns to, per context (must match theme.json) */
.blogdan-grid {
	--blogdan-meta-lh: 1.6;
	--blogdan-lead-fs: var(--wp--preset--font-size--large); /* h2 post titles in lists */
	--blogdan-lead-lh: 1.15;
}

.blogdan-article {
	--blogdan-lead-fs: var(--wp--preset--font-size--x-large); /* h1 */
	--blogdan-lead-lh: 1.05;
}

.blogdan-footer .blogdan-grid {
	--blogdan-lead-fs: var(--wp--preset--font-size--small); /* site title */
	--blogdan-lead-lh: 1.6;
}

/* Small uppercase labels in the meta column */
.blogdan-meta {
	margin: 0;
	font-size: var(--wp--preset--font-size--small);
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

.wp-block-post-date {
	font-variant-numeric: tabular-nums;
}

/* Date, then tags: stacked in the meta column, one line on phones.
 * The date stays the first line, so the cap alignment above still holds. */
.blogdan-meta > * {
	margin-block: 0;
}

.blogdan-meta .wp-block-post-terms {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	font-weight: 400;
}

/* "Written / Edited with AI" (functions.php): under the tags, a little apart */
.blogdan-meta .blogdan-ai-note {
	margin-top: 0.75rem;
	font-weight: 400;
}

.blogdan-meta .wp-block-post-terms__separator {
	display: none;
}

.blogdan-meta .wp-block-post-terms a {
	text-decoration: none;
}

.blogdan-meta .wp-block-post-terms a:hover {
	color: inherit;
	text-decoration: underline;
	text-decoration-color: var(--wp--preset--color--accent);
	text-decoration-thickness: 2px;
	text-underline-offset: 0.35em;
}

@media (max-width: 781px) {
	.blogdan-meta:has(.wp-block-post-terms) {
		display: flex;
		flex-wrap: wrap;
		column-gap: 1rem;
	}

	.blogdan-meta .wp-block-post-terms {
		flex-direction: row;
		flex-wrap: wrap;
		column-gap: 1rem;
	}

	.blogdan-meta .blogdan-ai-note {
		margin-top: 0;
	}
}

/* ---- Header ------------------------------------------------------------ */
/*
 * A thin black band, then the name and menu. The header scrolls away;
 * the band stays fixed at the top, and once it reaches the page title it
 * grows to show it (.has-page-title, set by header.js).
 */

:root {
	--blogdan-band-h: 0.75rem;
	--blogdan-band-h-title: 2.75rem;
	--blogdan-fixed-top: 0px;
}

/* On body: WordPress defines the root padding variables there, not on :root.
   100% resolves where it's used (the fixed band/menu), i.e. the viewport. */
body {
	--blogdan-edge: max(var(--wp--style--root--padding-left), calc((100% - var(--wp--style--global--wide-size)) / 2));
}

@media (min-width: 601px) {
	.admin-bar {
		--blogdan-fixed-top: var(--wp-admin--admin-bar--height, 0px);
	}
}

.blogdan-header {
	--blogdan-band-now: var(--blogdan-band-h);
	padding-top: calc(var(--blogdan-band-h) + 1.5rem);
	padding-bottom: 1.5rem;
}

.blogdan-header.has-page-title {
	--blogdan-band-now: var(--blogdan-band-h-title);
}

.blogdan-header .wp-block-site-title {
	margin: 0;
	font-size: calc(var(--wp--preset--font-size--medium) * 1.2);
}

/* Wordmark (header + footer): Sora caps, BLOG in the logo's red, DAN in black */
:where(.blogdan-header, .blogdan-footer) .wp-block-site-title {
	font-family: var(--wp--preset--font-family--logo);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.01em;
}

.blogdan-wordmark__a {
	color: var(--wp--preset--color--accent);
}

.blogdan-wordmark__b {
	color: var(--wp--preset--color--contrast);
}

/* Current page and hover: same mark as the page numbers in pagination */
.blogdan-header nav a[aria-current="page"],
.blogdan-header nav a:hover {
	color: inherit;
	text-decoration: underline;
	text-decoration-color: var(--wp--preset--color--accent);
	text-decoration-thickness: 2px;
	text-underline-offset: 0.35em;
}

/* ---- The band ---- */

.blogdan-header > .blogdan-band {
	position: fixed;
	top: var(--blogdan-fixed-top);
	left: 0;
	right: 0;
	z-index: 100;
	max-width: none;
	height: var(--blogdan-band-now);
	margin: 0;
	display: flex;
	align-items: center;
	padding: 0 var(--blogdan-edge);
	overflow: hidden;
	background: var(--wp--preset--color--contrast);
	color: var(--wp--preset--color--base);
	transition: height 0.2s ease;
	/* Not interactive: no text cursor, no selecting the copied title */
	cursor: default;
	user-select: none;
}

.blogdan-band__title {
	position: relative;
	min-width: 0;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	font-size: var(--wp--preset--font-size--small);
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	opacity: 0;
	transition: opacity 0.2s ease;
	pointer-events: none;
}

.has-page-title .blogdan-band__title {
	opacity: 1;
}

/* Date and tags on the right, like the meta column: bold date, plain tags */
.blogdan-band__meta {
	position: relative;
	display: flex;
	flex-shrink: 0;
	gap: 1rem;
	margin-left: auto;
	padding-left: var(--blogdan-col-gap);
	white-space: nowrap;
	font-size: var(--wp--preset--font-size--small);
	font-weight: 400;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	opacity: 0;
	transition: opacity 0.2s ease;
	pointer-events: none;
}

.blogdan-band__meta:empty {
	display: none;
}

.blogdan-band__date {
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.has-page-title .blogdan-band__meta {
	opacity: 1;
}

/* Phones: the title needs the room, keep only the date */
@media (max-width: 600px) {
	.blogdan-band__meta {
		padding-left: 1rem;
	}

	.blogdan-band__tag {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.blogdan-header > .blogdan-band,
	.blogdan-band__title,
	.blogdan-band__meta {
		transition: none !important;
	}
}

/* ---- Main -------------------------------------------------------------- */

.blogdan-main {
	padding-top: clamp(2rem, 6vw, 5rem);
	padding-bottom: clamp(3rem, 8vw, 7rem);
}

.blogdan-main > * + * {
	margin-block-start: 0;
}

/* 404: the random post continues the message, no rule. Spacing matches
 * h1 baseline -> message x-height, from the message baseline to the post title's
 * x-height (desktop) or the date's cap top (phones, where the date comes first).
 *   gap = h1 * 0.16123 (h1 baseline -> box bottom, lh 1.05) + block gap
 *         + text * 0.61787 (box top -> x-height, lh 1.6)
 * then minus the message's descent (text * 0.43623) and the target's offset. */
.blogdan-random .wp-block-group.blogdan-entry {
	border-top: 0;
	padding-top: 0;
}

.blogdan-main > .blogdan-random {
	--blogdan-404-gap: calc(
		var(--wp--preset--font-size--x-large) * 0.16123
		+ var(--wp--style--block-gap, 1.5rem)
		+ var(--wp--preset--font-size--medium) * 0.61787
		- var(--wp--preset--font-size--medium) * 0.43623
	);
	margin-top: calc(var(--blogdan-404-gap) - var(--wp--preset--font-size--large) * ((1.15 - 1.20996) / 2 + 0.42285));
}

@media (max-width: 781px) {
	.blogdan-main > .blogdan-random {
		margin-top: calc(var(--blogdan-404-gap) - var(--wp--preset--font-size--small) * ((1.6 - 1.20996) / 2 + 0.24121));
	}
}

/* Archive / search heading sits above the list like a section label */
.blogdan-list-title {
	padding-bottom: 1rem;
}

/* ---- Post list: each entry hangs from a rule --------------------------- */

.blogdan-list .wp-block-post-template {
	margin: 0;
}

.blogdan-list .wp-block-post-template > li {
	margin: 0;
}

/*
 * Entry rhythm, measured to the lowercase letters (x-height), not the boxes:
 *   rule -> title x-height top          = 2u
 *   title baseline -> excerpt x-height  = 1u
 *   excerpt last baseline -> next rule  = 2u
 * Inter, per em: content area 1.20996, ascender 0.96875, descender 0.24121,
 * x-height 0.54590. For a line box of size f and line-height L:
 *   top -> x-height top    = f * ((L - 1.20996) / 2 + 0.42285)
 *   baseline -> box bottom = f * ((L - 1.20996) / 2 + 0.24121)
 */
.blogdan-entry {
	--blogdan-entry-u: 1.5rem;
	--blogdan-text-fs: var(--wp--preset--font-size--medium); /* excerpt */
	--blogdan-text-lh: 1.6;
	border-top: var(--blogdan-rule);
	padding-top: calc(
		2 * var(--blogdan-entry-u)
		- var(--blogdan-lead-fs) * ((var(--blogdan-lead-lh) - 1.20996) / 2 + 0.42285)
	);
	padding-bottom: calc(
		2 * var(--blogdan-entry-u)
		- var(--blogdan-text-fs) * ((var(--blogdan-text-lh) - 1.20996) / 2 + 0.24121)
	);
}

.blogdan-entry .wp-block-post-title {
	margin: 0;
}

/* Phones: the date stacks above the title.
 *   rule -> date cap top             = 2u   (top -> cap top = f * ((L - 1.20996) / 2 + 0.24121))
 *   date baseline -> title x-height  = 1u */
@media (max-width: 781px) {
	.wp-block-group.blogdan-entry {
		--blogdan-meta-fs: var(--wp--preset--font-size--small);
		padding-top: calc(
			2 * var(--blogdan-entry-u)
			- var(--blogdan-meta-fs) * ((var(--blogdan-meta-lh) - 1.20996) / 2 + 0.24121)
		);
		row-gap: calc(
			var(--blogdan-entry-u)
			- var(--blogdan-meta-fs) * ((var(--blogdan-meta-lh) - 1.20996) / 2 + 0.24121)
			- var(--blogdan-lead-fs) * ((var(--blogdan-lead-lh) - 1.20996) / 2 + 0.42285)
		);
	}

	.blogdan-entry > .blogdan-meta {
		line-height: var(--blogdan-meta-lh);
	}
}

.blogdan-entry .wp-block-post-excerpt {
	margin-top: calc(
		var(--blogdan-entry-u)
		- var(--blogdan-lead-fs) * ((var(--blogdan-lead-lh) - 1.20996) / 2 + 0.24121)
		- var(--blogdan-text-fs) * ((var(--blogdan-text-lh) - 1.20996) / 2 + 0.42285)
	);
}

.blogdan-entry .wp-block-post-excerpt__excerpt {
	margin: 0;
}

/* Same as the post nav: labels as far below the rule as above the footer rule */
.blogdan-pagination {
	border-top: var(--blogdan-rule);
	padding-block: 1.25rem;
	line-height: 1.6;
	margin-top: 0;
	column-gap: 2rem;
}

/* Page numbers on the left, Newer / Older pushed to the right */
.blogdan-pagination .wp-block-query-pagination-numbers {
	margin-right: auto;
	display: flex;
	gap: 1rem;
}

.blogdan-pagination a {
	text-decoration: none;
}

.blogdan-pagination a:hover,
.blogdan-pagination .page-numbers.current {
	text-decoration: underline;
	text-decoration-color: var(--wp--preset--color--accent);
	text-decoration-thickness: 2px;
	text-underline-offset: 0.35em;
}

/* ---- Single post / page ------------------------------------------------ */

/* Newer on the left, older on the right, between two rules (this one and
 * the footer's). Label caps sit as far below the top rule as the baseline
 * sits above the footer rule:
 *   rule -> cap top = baseline -> rule = u + f * ((L - 1.20996) / 2 + 0.24121) */
.blogdan-main > .blogdan-postnav {
	--blogdan-postnav-u: 1.25rem;
	margin-top: clamp(3rem, 8vw, 6rem);
	padding-block: var(--blogdan-postnav-u);
	border-top: var(--blogdan-rule);
	gap: var(--blogdan-col-gap);
}

/* A post list or the post nav ends the page: the footer rule closes it.
 * After the last entry that leaves its own 2u (baseline -> rule), the same
 * as rule -> title above every entry. */
.blogdan-main:has(> .blogdan-postnav a),
.blogdan-main:has(> .blogdan-list) {
	padding-bottom: 0;
}

.blogdan-main:has(> .blogdan-postnav a) + *,
.blogdan-main:has(> .blogdan-list) + * {
	margin-block-start: 0;
}

.blogdan-postnav:not(:has(a)) {
	display: none;
}

.blogdan-postnav > * {
	flex: 1 1 0;
	min-width: 0;
	font-size: var(--wp--preset--font-size--small);
	font-weight: 700;
	line-height: 1.6;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

/* Like the pagination: no underline until hover, then the red mark */
.blogdan-postnav a {
	text-decoration: none;
}

.blogdan-postnav a:hover {
	color: inherit;
	text-decoration: underline;
	text-decoration-color: var(--wp--preset--color--accent);
	text-decoration-thickness: 2px;
	text-underline-offset: 0.35em;
}

.blogdan-article .wp-block-post-title {
	margin: 0 0 clamp(2.5rem, 4vw, 3rem);
}

/* Looser leading for long reading (lists and excerpts keep 1.6) */
.blogdan-article .wp-block-post-content {
	line-height: 1.8;
}

.blogdan-article .wp-block-post-content > * {
	max-width: 100%;
}

.wp-block-post-content a {
	text-decoration-color: var(--wp--preset--color--accent);
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

.wp-block-post-content :where(h2, h3, h4) {
	margin-top: 2.5em;
}

.wp-block-post-content hr,
.wp-block-separator,
.wp-block-separator:not(.is-style-wide):not(.is-style-dots) {
	width: 100%;
	max-width: none;
	margin-left: 0;
	margin-right: 0;
	border: 0;
	border-top: var(--blogdan-rule);
	opacity: 1;
}

/* Pull quote: flush left between a heavy and a thin rule */
.wp-block-pullquote {
	padding: 1.5rem 0;
	text-align: left;
}

.wp-block-pullquote blockquote,
.wp-block-pullquote p {
	margin: 0;
	font-size: inherit;
	line-height: inherit;
}

/* Tables: horizontal rules only, no boxes */
.wp-block-table table {
	border-collapse: collapse;
}

.wp-block-table th,
.wp-block-table td {
	border: 0;
	border-bottom: var(--blogdan-rule);
	padding: 0.625rem 1rem 0.625rem 0;
	text-align: left;
	vertical-align: baseline;
}

.wp-block-table thead {
	border-bottom: 0;
}

.wp-block-table thead th {
	font-size: var(--wp--preset--font-size--small);
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	border-bottom-width: 2px;
}

.wp-element-caption,
.wp-block-table figcaption {
	color: inherit;
	text-align: left;
	margin-top: 0.75rem;
}

.wp-block-code {
	tab-size: 4;
}

.wp-block-post-content :not(pre) > code {
	font-family: var(--wp--preset--font-family--mono);
	font-size: 0.9em;
}

/* ---- Forms ------------------------------------------------------------- */

input:not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
textarea {
	border: var(--blogdan-rule);
	border-radius: 0;
	padding: 0.625rem 0.75rem;
	font: inherit;
	background: var(--wp--preset--color--base);
	color: var(--wp--preset--color--contrast);
}

input:focus-visible,
textarea:focus-visible,
a:focus-visible,
button:focus-visible {
	outline: 2px solid var(--wp--preset--color--accent);
	outline-offset: 2px;
}

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

.blogdan-footer {
	padding-bottom: 200px;
}

.blogdan-footer > .blogdan-grid {
	border-top: var(--blogdan-rule);
	padding-top: 1.25rem;
	font-size: var(--wp--preset--font-size--small);
}

.blogdan-footer .wp-block-site-title {
	font-size: var(--wp--preset--font-size--small);
	margin: 0;
}

.blogdan-footer .wp-block-site-tagline {
	margin: 0;
}
