/*
 * Elastos Blog Design System
 * Tokens (--ela-*) are printed inline from includes/tokens.php, the single source.
 *
 * 1. Site-wide base
 * 2. Prose: article body (.ela-prose, added around the main post content)
 * 3. Components: code, callout, figure, embeds
 * 4. Tables (responsive region and mobile cards)
 * 5. Archive cards (Blocksy fallback templates)
 * 6. Site chrome (header and footer)
 * 7. Classic editor
 */

/* 1. Site-wide base ------------------------------------------------------- */

body {
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

::selection {
	background: color-mix(in srgb, var(--ela-accent) 35%, transparent);
	color: var(--ela-text);
}

:where(a, button, [role="button"], input, select, textarea, summary, [tabindex]):focus-visible {
	outline: 2px solid var(--ela-accent);
	outline-offset: 2px;
}

.ela-text-accent {
	color: var(--ela-accent);
}

.ela-reading-time {
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

/* Blocksy paints code with palette colour 6 (light grey) under the site's white text.
   The palette itself stays as is because legacy pages use that slot, so code is fixed
   here, everywhere, at the same specificity and later in the cascade. */
pre,
code,
kbd,
samp {
	background-color: var(--ela-inset);
	color: var(--ela-text);
}

pre code {
	background-color: transparent;
}

/* Core's striped table style paints odd rows #f0f0f0 under the site's white text. */
.wp-block-table.is-style-stripes tbody tr:nth-child(odd) {
	background-color: var(--ela-surface);
}

.wp-block-table.is-style-stripes {
	border-bottom-color: var(--ela-border);
}

/* 2. Prose ------------------------------------------------------------------ */

.ela-prose {
	font-family: var(--ela-font-sans);
	font-size: var(--ela-text-base);
	font-weight: 400;
	line-height: var(--ela-leading-body);
	letter-spacing: 0;
	color: var(--ela-text);
	overflow-wrap: break-word;
	font-kerning: normal;
}

/* Every block sits in the reading measure, left-aligned so it shares an edge with the
   title and featured image above it. Wide content opts out below. */
.ela-prose > * {
	max-width: var(--ela-measure);
	margin-block: 0;
	margin-inline: 0 auto;
}

.ela-prose > * + * {
	margin-block-start: 1.25em;
}

.ela-prose > :first-child {
	margin-block-start: 0;
}

.ela-prose :is(p, li, dd, blockquote) {
	font-size: inherit;
	font-weight: inherit;
	line-height: inherit;
	letter-spacing: inherit;
	color: inherit;
	text-wrap: pretty;
}

.ela-prose :is(h1, h2, h3, h4, h5, h6) {
	font-family: var(--ela-font-sans);
	color: var(--ela-text);
	text-wrap: balance;
	margin-block-end: 0;
}

.ela-prose h2 {
	font-size: var(--ela-text-h2);
	font-weight: 400;
	line-height: 1.25;
	letter-spacing: -0.005em;
}

.ela-prose h3 {
	font-size: var(--ela-text-h3);
	font-weight: 700;
	line-height: 1.35;
	letter-spacing: 0;
}

.ela-prose :is(h4, h5, h6) {
	font-size: var(--ela-text-base);
	font-weight: 700;
	line-height: 1.4;
	letter-spacing: 0;
}

/* Space above a heading is relative to its own size; space below is tight so the
   heading reads as belonging to what follows. */
.ela-prose > h2 {
	margin-block-start: 1.75em;
}

.ela-prose > h3 {
	margin-block-start: 1.6em;
}

.ela-prose > :is(h4, h5, h6) {
	margin-block-start: 1.5em;
}

.ela-prose > :is(h2, h3, h4, h5, h6) + * {
	margin-block-start: 0.5em;
}

.ela-prose :is(strong, b) {
	font-weight: 700;
}

.ela-prose a {
	color: var(--ela-accent);
	text-decoration-line: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
	text-decoration-color: color-mix(in srgb, var(--ela-accent) 55%, transparent);
	transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.ela-prose a:hover {
	color: var(--ela-accent-hover);
	text-decoration-color: currentColor;
	text-decoration-thickness: 2px;
}

.ela-prose a:focus-visible {
	border-radius: 2px;
}

.ela-prose :is(ul, ol) {
	padding-inline-start: 1.25em;
}

.ela-prose ul {
	list-style: disc;
}

.ela-prose ol {
	list-style: decimal;
}

.ela-prose li + li,
.ela-prose li > :is(ul, ol) {
	margin-block-start: 0.4em;
}

.ela-prose li > p {
	margin-block: 0;
}

.ela-prose ul > li::marker {
	color: var(--ela-accent);
}

.ela-prose ol > li::marker {
	color: var(--ela-text-muted);
	font-variant-numeric: tabular-nums;
}

.ela-prose blockquote {
	border: 0;
	border-inline-start: 3px solid var(--ela-accent);
	padding: 0 0 0 1.25em;
	font-style: normal;
	background: none;
}

.ela-prose blockquote > * + * {
	margin-block-start: 0.75em;
}

.ela-prose blockquote > * {
	margin-block-end: 0;
}

.ela-prose blockquote cite {
	display: block;
	margin-block-start: 0.5em;
	font-size: var(--ela-text-small);
	font-style: normal;
	color: var(--ela-text-muted);
}

.ela-prose hr {
	height: 0;
	border: 0;
	border-block-start: 1px solid var(--ela-border);
	margin-block: 3em;
}

.ela-prose sup {
	font-size: 0.75em;
	line-height: 0;
	vertical-align: super;
}

.ela-prose sup a {
	text-decoration: none;
	padding-inline: 0.15em;
}

/* 3. Components ------------------------------------------------------------- */

/* Media and code may run wider than the text measure. */
.ela-prose > :is(figure, pre, .wp-block-image, .wp-block-gallery, .wp-block-embed, .wp-block-media-text, .wp-caption, video, iframe),
.ela-prose > p:has(> img:only-child),
.ela-prose > p:has(> a:only-child > img:only-child) {
	max-width: min(100%, var(--ela-wide));
}

.ela-prose img {
	max-width: 100%;
	height: auto;
	border-radius: var(--ela-radius);
}

.ela-prose img.emoji {
	border-radius: 0;
}

.ela-prose a:has(> img) {
	text-decoration: none;
}

.ela-prose a.ela-zoom {
	cursor: zoom-in;
}

.ela-prose :is(figure, .wp-caption) {
	width: auto !important; /* the [caption] shortcode writes a fixed inline width */
}

.ela-prose :is(figcaption, .wp-caption-text, .wp-element-caption) {
	margin-block-start: 0.75em;
	font-size: var(--ela-text-small);
	line-height: 1.5;
	color: var(--ela-text-muted);
	text-align: center;
}

.ela-prose :is(iframe[src*="youtube"], iframe[src*="youtu.be"], iframe[src*="vimeo"]) {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 16 / 9;
	border: 0;
	border-radius: var(--ela-radius);
}

.ela-prose video {
	display: block;
	width: 100%;
	height: auto;
	border-radius: var(--ela-radius);
}

.ela-prose pre {
	box-sizing: border-box;
	padding: 1rem 1.25rem;
	border: 1px solid var(--ela-border);
	border-radius: var(--ela-radius);
	background: var(--ela-inset);
	color: var(--ela-text);
	font-family: var(--ela-font-mono);
	font-size: var(--ela-text-code);
	line-height: 1.6;
	tab-size: 4;
	white-space: pre;
	overflow-x: auto;
	overflow-wrap: normal;
	word-break: normal;
	overscroll-behavior-x: contain;
	scrollbar-width: thin;
	scrollbar-color: var(--ela-border-strong) transparent;
}

.ela-prose pre code {
	padding: 0;
	border: 0;
	border-radius: 0;
	background: none;
	color: inherit;
	font-family: inherit;
	font-size: inherit;
	white-space: inherit;
	overflow-wrap: normal;
	word-break: normal;
}

.ela-prose :is(:not(pre) > code, kbd, samp) {
	padding: 0.1em 0.35em;
	border: 1px solid var(--ela-border);
	border-radius: var(--ela-radius-sm);
	background: rgb(255 255 255 / 0.06);
	color: var(--ela-text);
	font-family: var(--ela-font-mono);
	font-size: 0.875em;
	overflow-wrap: anywhere;
}

.ela-callout {
	--ela-callout-tone: var(--ela-accent);
	box-sizing: border-box;
	padding: 1.25rem 1.5rem;
	border: 1px solid var(--ela-border);
	border-inline-start: 3px solid var(--ela-callout-tone);
	border-radius: var(--ela-radius);
	background: var(--ela-surface);
	background: color-mix(in srgb, var(--ela-callout-tone) 8%, var(--ela-surface));
	color: var(--ela-text);
}

.ela-callout--warning {
	--ela-callout-tone: var(--ela-warning);
}

.ela-callout > * {
	margin-block: 0;
}

.ela-callout > * + * {
	margin-block-start: 0.75em;
}

.ela-prose .ela-callout__title,
.ela-callout__title {
	font-weight: 700;
}

/* 4. Tables ----------------------------------------------------------------- */

.ela-table-scroll {
	max-width: 100%;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: var(--ela-border-strong) transparent;
}

.ela-prose > .ela-table-scroll {
	max-width: 100%;
}

.ela-table-scroll::-webkit-scrollbar {
	height: 6px;
	-webkit-appearance: none;
}

.ela-table-scroll::-webkit-scrollbar-thumb {
	border-radius: 3px;
	background: var(--ela-border-strong);
}

.ela-table-scroll::-webkit-scrollbar-track {
	background: var(--ela-surface);
}

/* Fallback for tables Elementor renders outside the_content (Text Editor widgets),
   which the PHP filter never sees: the table itself becomes the scroller. */
.elementor-widget-theme-post-content table,
.elementor-widget-text-editor table {
	display: block;
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	overscroll-behavior-x: contain;
}

.ela-table-scroll > table {
	display: table;
	width: 100%;
	max-width: none;
	margin: 0;
	overflow: visible;
}

.ela-prose table {
	border: 0;
	border-collapse: collapse;
	border-spacing: 0;
	font-size: var(--ela-text-table);
	line-height: 1.55;
	font-variant-numeric: tabular-nums;
	color: var(--ela-text);
}

.ela-prose :is(th, td) {
	padding: 0.75rem 1rem;
	border: 0;
	border-block-end: 1px solid var(--ela-border);
	vertical-align: top;
	text-align: start;
}

.ela-prose thead th,
.ela-prose tr.ela-head > * {
	font-size: var(--ela-text-small);
	font-weight: 700;
	color: var(--ela-text-muted);
	border-block-end-color: var(--ela-border-strong);
}

.ela-table-hint {
	margin: 0 0 0.5rem;
	font-size: 0.8125rem;
	line-height: 1.4;
	color: var(--ela-text-muted);
}

@media (min-width: 768px) {
	.ela-table-hint {
		display: none;
	}
}

@media (max-width: 767px) {
	.ela-table-scroll :is(th, td) {
		min-width: 11ch;
		white-space: normal;
		overflow-wrap: normal;
		hyphens: none;
	}

	.ela-table-scroll :is(th, td):last-child {
		min-width: 22ch;
	}

	/* Mobile cards: each row becomes a card with its column headers repeated as
	   labels. ARIA roles from the PHP step keep the table semantics. */
	.ela-table-scroll.ela-stack {
		overflow-x: visible;
	}

	.ela-stack > table,
	.ela-stack > table > tbody,
	.ela-stack > table > tbody > tr,
	.ela-stack > table > tbody > tr > :is(td, th) {
		display: block;
		width: auto;
		min-width: 0;
	}

	/* Hidden visually, not removed: screen readers still reach the header row. */
	.ela-stack > table .ela-head {
		position: absolute;
		width: 1px;
		height: 1px;
		margin: -1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	.ela-stack > table > tbody > tr {
		margin: 0 0 0.75rem;
		padding: 0.125rem 1rem;
		border: 1px solid var(--ela-border-strong);
		border-radius: var(--ela-radius);
		background: var(--ela-surface);
	}

	.ela-stack > table > tbody > tr > :is(td, th) {
		display: grid;
		grid-template-columns: 7.5rem minmax(0, 1fr);
		gap: 0.25rem 1rem;
		align-items: baseline;
		padding: 0.625rem 0;
		border: 0;
		border-block-end: 1px solid var(--ela-border);
		overflow-wrap: anywhere;
		/* Authors right-aligned some numeric cells inline; in a card every value
		   starts at the same edge, so the inline alignment has to yield. */
		text-align: start !important;
	}

	.ela-stack > table > tbody > tr > :is(td, th):last-child {
		border-block-end: 0;
	}

	.ela-stack > table > tbody > tr > :is(td, th)::before {
		content: attr(data-label);
		font-size: 0.75rem;
		font-weight: 700;
		line-height: 1.5;
		letter-spacing: 0.04em;
		text-transform: uppercase;
		text-align: start;
		color: var(--ela-text-muted);
	}

	/* Prose and 64-character hashes take the full card width under their label. */
	.ela-stack > table > tbody > tr > td[data-long] {
		display: block;
	}

	.ela-stack > table > tbody > tr > td[data-long]::before {
		display: block;
		margin-block-end: 0.25rem;
	}
}

/* 5. Archive cards (Blocksy fallback templates) ---------------------------- */

/* Blocksy gives archive cards palette colour 8 (white) under white text. Its rule
   ([data-prefix="..."] .entry-card) is printed inline after this file, so the html
   type selector adds the one point of specificity needed to win regardless of order. */
html [data-prefix] .entry-card {
	border: 1px solid var(--ela-border);
	border-radius: var(--ela-radius-lg);
	background-color: var(--ela-surface);
	font-family: var(--ela-font-sans);
	overflow: hidden;
}

/* Blocksy's current page number is white on its orange (2.96:1); dark text gives 6:1. */
html .ct-pagination .page-numbers.current {
	color: var(--ela-bg);
}

html [data-prefix] .entry-card .entry-title {
	font-family: var(--ela-font-sans);
	font-weight: 400;
	letter-spacing: 0;
}

.entry-card :is(.entry-title, .entry-title a) {
	color: var(--ela-text);
}

.entry-card :is(.entry-excerpt, .entry-meta) {
	color: var(--ela-text-muted);
}

/* 6. Site chrome: header and footer (structure lives in Elementor templates) */

.ela-site-header {
	position: relative;
	z-index: 50;
}

.ela-site-logo a {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
}

.ela-site-logo img {
	display: block;
}

.ela-site-nav .elementor-nav-menu--main .elementor-item {
	color: var(--ela-text-muted);
	letter-spacing: 0;
}

.ela-site-nav .elementor-nav-menu--main .elementor-item:is(:hover, :focus-visible, .elementor-item-active) {
	color: var(--ela-text);
}

.ela-site-nav .elementor-menu-toggle {
	box-sizing: border-box;
	width: 44px;
	height: 44px;
	padding: 10px;
	border-radius: var(--ela-radius);
	background: transparent;
	color: var(--ela-text);
}

.ela-site-nav .elementor-menu-toggle:hover {
	background: var(--ela-surface);
}

.ela-site-nav .elementor-nav-menu--dropdown {
	border-block: 1px solid var(--ela-border);
	background: var(--ela-surface);
}

.ela-site-nav .elementor-nav-menu--dropdown .elementor-item {
	min-height: 44px;
	align-items: center;
}

.ela-pill .elementor-button {
	min-height: 40px;
	padding: 10px 20px;
	border: 1px solid color-mix(in srgb, var(--ela-accent) 50%, transparent);
	border-radius: var(--ela-radius-pill);
	background: color-mix(in srgb, var(--ela-accent) 5%, transparent);
	color: var(--ela-text);
	font-family: var(--ela-font-sans);
	font-size: var(--ela-text-small);
	font-weight: 400;
	line-height: 1.2;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}

.ela-pill .elementor-button:hover {
	border-color: var(--ela-accent);
	background: color-mix(in srgb, var(--ela-accent) 14%, transparent);
	color: var(--ela-text);
}

.ela-footer-title .elementor-heading-title {
	font-family: var(--ela-font-sans);
	font-size: var(--ela-text-small);
	font-weight: 700;
	line-height: 1.4;
	letter-spacing: 0;
	color: var(--ela-text);
}

.ela-footer-links .elementor-icon-list-text {
	font-family: var(--ela-font-sans);
	font-size: var(--ela-text-small);
	font-weight: 400;
	line-height: 1.5;
	letter-spacing: 0;
	color: var(--ela-text-muted);
	transition: color 0.15s ease;
}

.ela-footer-links a:is(:hover, :focus-visible) .elementor-icon-list-text {
	color: var(--ela-text);
}

.ela-footer-links .elementor-icon-list-item > a {
	min-height: 24px;
}

.ela-footer-legal,
.ela-footer-legal p {
	margin: 0;
	font-size: var(--ela-text-small);
	line-height: 1.5;
	color: var(--ela-text-muted);
	text-align: center;
}

/* 7. Classic editor --------------------------------------------------------- */

body.ela-editor {
	margin: 0;
	padding: 1.5rem;
	background: var(--ela-bg);
}

@media (prefers-reduced-motion: reduce) {
	.ela-prose a {
		transition: none;
	}
}
