/*
 * Guide library — /guides/ and the guide detail page.
 *
 * Loaded only on the guide archive and the guide single (inc/assets.php), so
 * nothing here can reach another archive. House tokens only: no parallel
 * palette, no second set of spacing values. Ported from the v4 prototypes,
 * minus the prototype-only scaffolding (racked test rows, demo scroll states,
 * the header stub and a second copy of the button styles).
 */

/* =========================================================
   ARCHIVE HERO — the library's front door.
   Dark band (the house cab-header pattern), with the honest
   library count, and START HERE breaking out below the edge.
   ========================================================= */
.lib-hero {
	background: var(--color-dark);
	color: #fff;
	padding-block: clamp(3rem, 6vw, 5.5rem) clamp(5.5rem, 9vw, 8.5rem);
}

.lib-hero__inner {
	max-width: 46rem;
}

/* the topic pages: same band, no START HERE card breaking out of it */
.lib-hero--compact {
	padding-block: clamp(2.5rem, 5vw, 4rem) clamp(2rem, 4vw, 3rem);
}

.lib-hero .eyebrow {
	color: var(--color-accent-light);
}

.lib-hero__title {
	margin-top: 0.85rem;
	font-size: clamp(2.1rem, 4.6vw, 3.3rem);
	line-height: 1.08;
	color: #fff;
}

.lib-hero__lead {
	margin-top: 1.1rem;
	max-width: 38rem;
	font-size: clamp(1rem, 1.3vw, 1.1rem);
	line-height: 1.7;
	color: var(--color-dark-text);
}

.lib-hero__stats {
	display: flex;
	flex-wrap: wrap;
	gap: 0.6rem 1.6rem;
	margin-top: 1.6rem;
	font-family: var(--font-mono);
	font-size: 0.72rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-accent-light);
}

/* START HERE — the feature breaks out of the dark band. */
.start-card-wrap {
	margin-top: clamp(-6rem, -7vw, -5rem);
}

.start-card {
	display: grid;
	gap: 1.5rem;
	align-items: center;
	background: var(--color-bg-card);
	border: 1px solid var(--color-border-soft);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-lg);
	padding: clamp(1.5rem, 3vw, 2.5rem);
	text-decoration: none;
	color: inherit;
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.start-card__frame {
	transition: transform 0.18s ease;
}

/* The frame lifts, so the credit beside the link moves with the card. */
.start-card__frame:hover {
	transform: translateY(-2px);
}

.start-card:hover {
	box-shadow: 0 16px 40px rgba(31, 36, 32, 0.14);
}

.start-card__eyebrow {
	font-family: var(--font-mono);
	font-size: 0.7rem;
	letter-spacing: var(--hk-tracking-kicker);
	text-transform: uppercase;
	color: var(--color-accent);
}

.start-card__title {
	margin-top: 0.6rem;
	font-size: clamp(1.5rem, 2.6vw, 2.1rem);
	line-height: 1.15;
}

.start-card__excerpt {
	margin-top: 0.7rem;
	max-width: 36rem;
	color: var(--color-text-muted);
}

.start-card__meta {
	margin-top: 1rem;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 1.2rem;
	font-family: var(--font-mono);
	font-size: 0.72rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

.start-card__go {
	margin-top: 1rem;
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	font-weight: 600;
	color: var(--color-green);
}

.start-card__go svg {
	width: 18px;
	height: 18px;
}

.start-card__media {
	position: relative;
	aspect-ratio: 16 / 10;
	border-radius: var(--radius-card);
	overflow: hidden;
	background: var(--color-hero-placeholder);
}

.start-card__media img,
.lib-card__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

@media (min-width: 900px) {
	.start-card {
		grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
	}
}

/* --- topics row: term links, one row at four and at seventeen --- */
.lib-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.7rem 1rem;
	padding-block: clamp(2rem, 4vw, 3rem) 1.25rem;
}

.lib-toolbar__label {
	font-family: var(--font-mono);
	font-size: 0.7rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

.topic-pill {
	display: inline-flex;
	align-items: center;
	min-height: 34px;
	padding: 0.35rem 0.9rem;
	border: 1px solid var(--color-border-tag);
	border-radius: 999px;
	background: var(--color-bg-card);
	font-size: 0.85rem;
	color: var(--color-text);
	text-decoration: none;
	transition: border-color 0.15s ease, color 0.15s ease;
}

.topic-pill:hover {
	border-color: var(--color-green);
	color: var(--color-green);
}

.topic-pill--current {
	background: var(--color-green);
	border-color: var(--color-green);
	color: #fff;
}

.lib-toolbar__count {
	margin-left: auto;
	font-family: var(--font-mono);
	font-size: 0.7rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

/* =========================================================
   LIBRARY CARD — number, topic, title, excerpt, reading time
   and the arrow. No date, so no separator to dangle.
   The image slot is locked at 16/10 and falls back to a quiet
   placeholder when a guide has no image yet.
   ========================================================= */
.lib-grid {
	display: grid;
	gap: 1.25rem;
	padding-bottom: clamp(3rem, 6vw, 5rem);
	grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 640px) {
	.lib-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (min-width: 1024px) {
	.lib-grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

.lib-card {
	display: flex;
	flex-direction: column;
	background: var(--color-bg-card);
	border: 1px solid var(--color-border-soft);
	border-radius: var(--radius-card);
	box-shadow: var(--shadow-sm);
	overflow: hidden;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.lib-card:hover {
	transform: translateY(-2px);
	box-shadow: var(--shadow-md);
}

.lib-card__link {
	display: flex;
	flex-direction: column;
	flex: 1;
	text-decoration: none;
	color: inherit;
}

.lib-card__media {
	position: relative;
	aspect-ratio: 16 / 10;
	background: var(--color-hero-placeholder);
	overflow: hidden;
}

.lib-card__num {
	position: absolute;
	top: 0.75rem;
	left: 0.75rem;
	z-index: 1;
	min-width: 38px;
	height: 38px;
	padding-inline: 0.5rem;
	display: grid;
	place-items: center;
	background: var(--color-green);
	color: #fff;
	border-radius: var(--radius-sm);
	font-family: var(--font-mono);
	font-size: 0.88rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	box-shadow: 0 2px 8px rgba(31, 36, 32, 0.25);
}

.lib-card__body {
	padding: 1.15rem 1.15rem 0.75rem;
	flex: 1;
}

.lib-card__topic {
	font-family: var(--font-mono);
	font-size: 0.66rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-accent);
}

.lib-card__title {
	margin-top: 0.5rem;
	font-size: 1.2rem;
	line-height: 1.25;
}

.lib-card__excerpt {
	margin-top: 0.5rem;
	font-size: 0.9375rem;
	color: var(--color-text-muted);
}

.lib-card__footer {
	margin-top: auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0 1.15rem 1.15rem;
}

.lib-card__read {
	font-family: var(--font-mono);
	font-size: 0.68rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

.lib-card__more {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--color-green);
}

.lib-card__more svg {
	width: 17px;
	height: 17px;
	transition: transform 0.18s ease;
}

.lib-card:hover .lib-card__more svg {
	transform: translateX(4px);
}

/* the honest "no image yet" slot: quiet, and no page collapses */
.lib-card__media--empty {
	display: grid;
	place-items: center;
}

/* planned work — the direction, stated plainly, no fake content */
.lib-planned {
	padding-block: clamp(2rem, 4vw, 3rem);
	border-top: 1px solid var(--color-border);
	background: var(--color-bg-soft);
}

.lib-planned__inner {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 1rem 1.5rem;
	justify-content: space-between;
}

.lib-planned__copy {
	margin-top: 0.5rem;
	max-width: 34rem;
	color: var(--color-text-soft);
}

/* =========================================================
   DETAIL HERO — the guide's own image, which the template
   never rendered before. Locked 3:2 slot: three of the four
   real files are 3:2, so the crop is 0–0.1%; an 8:5 source
   loses 5.4%, where a 4:3 slot would have cut 11–16% off all
   four.
   ========================================================= */
.gd-hero {
	padding-block: clamp(2.5rem, 5vw, 4rem) clamp(2rem, 4vw, 3rem);
	border-bottom: 1px solid var(--color-border);
}

.gd-hero__grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: clamp(1.75rem, 4vw, 3.5rem);
	align-items: center;
}

@media (min-width: 1024px) {
	.gd-hero__grid {
		grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
	}
}

.gd-hero__eyebrow {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.6rem;
}

.gd-hero__num {
	display: inline-grid;
	place-items: center;
	min-width: 40px;
	height: 40px;
	padding-inline: 0.5rem;
	background: var(--color-green);
	color: #fff;
	border-radius: var(--radius-sm);
	font-family: var(--font-mono);
	font-size: 0.85rem;
	font-weight: 600;
}

.gd-hero__topic {
	font-family: var(--font-mono);
	font-size: 0.7rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

.gd-hero__title {
	margin-top: 1rem;
	font-size: clamp(2rem, 4.4vw, 3.1rem);
	line-height: 1.08;
}

.gd-hero__intro {
	margin-top: 1rem;
	max-width: 36rem;
	font-size: clamp(1rem, 1.3vw, 1.1rem);
	color: var(--color-text-soft);
}

.gd-hero__meta {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1.3rem;
	margin-top: 1.3rem;
	font-family: var(--font-mono);
	font-size: 0.7rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

.gd-hero__figure {
	margin: 0;
	border-radius: var(--radius-lg);
	overflow: hidden;
	border: 1px solid var(--color-border-soft);
	box-shadow: var(--shadow-md);
	background: var(--color-hero-placeholder);
}

.gd-hero__figure .frame {
	aspect-ratio: 3 / 2;
	overflow: hidden;
}

.gd-hero__figure img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.gd-hero__figure figcaption {
	padding: 0.6rem 0.9rem;
	background: var(--color-bg-card);
	font-size: 0.8rem;
	color: var(--color-text-muted);
}

/* =========================================================
   MOBILE CONTENTS — designed mobile-first: a panel directly
   under the hero and before the first word of the article,
   opening in place with its own 60vh scroll so a 24-section
   guide is safe; then a sticky bar once it leaves the viewport.
   Desktop hides both and uses the sticky aside.
   ========================================================= */
.gd-contents {
	margin-top: 1.75rem;
	border: 1px solid var(--color-border);
	border-radius: var(--radius-card);
	background: var(--color-bg-card);
	box-shadow: var(--shadow-sm);
}

.gd-contents__toggle {
	display: flex;
	align-items: center;
	gap: 1rem;
	width: 100%;
	padding: 1.05rem 1.15rem;
	min-height: 56px;
	background: none;
	border: 0;
	cursor: pointer;
	text-align: left;
	font-family: var(--font-sans);
	list-style: none;
}

/* the summary carries our own chevron: drop the browser's marker */
.gd-contents__toggle::-webkit-details-marker {
	display: none;
}

.gd-contents__toggle::marker {
	content: '';
}

.gd-contents__toggle:focus-visible {
	outline: 2px solid var(--color-green);
	outline-offset: 2px;
	border-radius: var(--radius-card);
}

.gd-contents__label {
	flex: 1;
	font-family: var(--font-heading);
	font-weight: 600;
	font-size: 1.05rem;
	color: var(--color-text);
}

.gd-contents__count {
	font-family: var(--font-mono);
	font-size: 0.68rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

.gd-contents__chev {
	flex: 0 0 auto;
	width: 18px;
	height: 18px;
	transition: transform 0.2s ease;
	color: var(--color-green);
}

.gd-contents[open] .gd-contents__chev {
	transform: rotate(180deg);
}

/* The panel is a native <details>: the browser opens and closes it, so the
   body is never hidden by our own CSS — display:none here would break the
   open state as well. The cap and its own scroll stay. */
.gd-contents__body {
	padding: 0 0.6rem 0.8rem;
	max-height: 60vh;
	overflow-y: auto;
}

.gd-contents ol {
	margin: 0;
	padding: 0 0.5rem 0 2.1rem;
}

.gd-contents li {
	padding-block: 0.12rem;
}

.gd-contents a {
	display: block;
	padding: 0.45rem 0.4rem;
	min-height: 40px;
	text-decoration: none;
	color: var(--color-text-soft);
	font-size: 0.95rem;
	border-left: 2px solid transparent;
}

.gd-contents a.is-current {
	color: var(--color-green);
	font-weight: 600;
	border-left-color: var(--color-green);
	background: var(--color-bg-soft);
}

@media (min-width: 1024px) {
	.gd-contents {
		display: none;
	}
}

.gd-sticky {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 20;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.7rem var(--hk-gutter);
	min-height: 52px;
	background: var(--color-bg-card);
	border-bottom: 1px solid var(--color-border);
	box-shadow: 0 4px 16px rgba(31, 36, 32, 0.08);
	transform: translateY(-110%);
	transition: transform 0.22s ease;
	font-family: var(--font-sans);
}

.gd-sticky.is-visible {
	transform: translateY(0);
}

.gd-sticky__btn {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	flex: 0 0 auto;
	min-height: 40px;
	background: none;
	border: 0;
	padding: 0;
	cursor: pointer;
	text-align: left;
	color: var(--color-green);
	font-family: var(--font-sans);
	font-weight: 600;
	font-size: 0.9rem;
}

.gd-sticky__btn svg {
	width: 17px;
	height: 17px;
	flex: 0 0 auto;
}

.gd-sticky__now {
	flex: 1;
	min-width: 0;
	font-size: 0.85rem;
	color: var(--color-text-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

@media (min-width: 1024px) {
	.gd-sticky {
		display: none;
	}
}

/* =========================================================
   THE ARTICLE — section rhythm and heading anchors. The
   sections are the stored h2s, so the list and the prose
   cannot drift apart.
   ========================================================= */
.gd-prose > h2 {
	margin-top: clamp(2.25rem, 4vw, 3rem);
	padding-top: clamp(1.5rem, 3vw, 2rem);
	border-top: 1px solid var(--color-border);
	font-size: clamp(1.4rem, 2.4vw, 1.85rem);
	line-height: 1.2;
	scroll-margin-top: 4.5rem;
}

.gd-prose > h2:first-child {
	margin-top: 0;
	padding-top: 0;
	border-top: 0;
}

/* a wide table inside a grid track must not push the page sideways */
.gd-prose table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.925rem;
	background: var(--color-bg-card);
}

.gd-prose table th,
.gd-prose table td {
	text-align: left;
	padding: 0.7rem 0.95rem;
	border-bottom: 1px solid var(--color-border-soft);
}

.gd-prose table th {
	font-family: var(--font-mono);
	font-size: 0.68rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-soft);
	background: var(--color-bg-soft);
}

/* =========================================================
   DESKTOP CONTENTS — the sticky aside, hidden on mobile.
   ========================================================= */
.gd-toc {
	margin-top: 0.9rem;
	list-style: none;
	padding: 0;
}

.gd-toc a {
	display: flex;
	gap: 0.6rem;
	padding: 0.32rem 0.5rem 0.32rem 0.6rem;
	min-height: 30px;
	border-left: 2px solid transparent;
	text-decoration: none;
	color: var(--color-text-soft);
	font-size: 0.875rem;
	transition: color 0.15s ease, border-color 0.15s ease;
}

.gd-toc a span:first-child {
	font-family: var(--font-mono);
	font-size: 0.68rem;
	color: var(--color-text-muted);
	padding-top: 0.12rem;
}

.gd-toc a:hover {
	color: var(--color-green);
}

.gd-toc a.is-current {
	color: var(--color-green);
	border-left-color: var(--color-green);
	font-weight: 600;
	background: var(--color-bg-soft);
}

/* the library number beside a related guide */
.gd-aside__tag {
	font-family: var(--font-mono);
	font-size: 0.64rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-accent);
	margin-right: 0.5rem;
}

/* Sticky on desktop only, and only on guide pages.
   No max-height and no overflow-y here on purpose. A scroll container at this
   position paints a permanent scrollbar gutter on any window shorter than the
   aside, and — worse — it swallows the wheel: measured, scrolling over the
   sidebar moved aside.scrollTop while the page stayed still. The aside now
   flows at its natural height and sticky pins it exactly as before. On a very
   short window the tail sits below the fold while pinned, which is normal and
   far better than a sidebar that hijacks the page. */
@media (min-width: 1024px) {
	.single-entry--guide .single-body__aside {
		position: sticky;
		top: 1.5rem;
	}
}

/* =========================================================
   PAGER — where you are in the library, and what is either
   side of you.
   ========================================================= */
.gd-pager {
	margin-top: clamp(2.5rem, 5vw, 3.5rem);
	padding-top: clamp(1.5rem, 3vw, 2rem);
	border-top: 1px solid var(--color-border);
}

.gd-pager__pos {
	font-family: var(--font-mono);
	font-size: 0.7rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

.gd-pager__row {
	display: grid;
	gap: 0.9rem;
	margin-top: 1rem;
}

@media (min-width: 640px) {
	.gd-pager__row {
		grid-template-columns: 1fr 1fr;
	}
}

.gd-pager__link {
	display: flex;
	flex-direction: column;
	gap: 0.3rem;
	padding: 1.05rem 1.2rem;
	min-height: 44px;
	background: var(--color-bg-card);
	border: 1px solid var(--color-border-soft);
	border-radius: var(--radius-card);
	text-decoration: none;
	transition: border-color 0.15s ease, transform 0.15s ease;
}

.gd-pager__link:hover {
	border-color: var(--color-green);
	transform: translateY(-2px);
}

.gd-pager__link span:first-child {
	font-family: var(--font-mono);
	font-size: 0.66rem;
	letter-spacing: var(--hk-tracking-label);
	text-transform: uppercase;
	color: var(--color-text-muted);
}

.gd-pager__link span:last-child {
	font-family: var(--font-heading);
	font-weight: 600;
	color: var(--color-text);
}

.gd-pager__link--next {
	text-align: right;
	align-items: flex-end;
}

/* Motion is decoration here: the panel, the bar and the cards all work
   without it. */
@media (prefers-reduced-motion: reduce) {
	.start-card,
	.start-card__frame,
	.lib-card,
	.lib-card__more svg,
	.gd-contents__chev,
	.gd-sticky,
	.gd-pager__link {
		transition: none;
	}

	.start-card__frame,
	.start-card__frame:hover,
	.lib-card:hover,
	.gd-pager__link:hover {
		transform: none;
	}

	.lib-card:hover .lib-card__more svg {
		transform: none;
	}
}
