/*
 * The Freebies library.
 *
 * A code-first surface, so it deliberately does less than the blog: no reading rail, no author
 * column, no table of contents. The snippet is the subject and everything here defers to it.
 */

.sgf-page { background: var(--sq-paper, var(--wp--preset--color--base)); }

.sgf-wrap {
	max-width: 1180px;
	margin-inline: auto;
	padding: clamp(28px, 5vw, 56px) clamp(16px, 4vw, 32px) 72px;
}

/* ── Masthead ───────────────────────────────────────────────────────────────── */

.sgf-head { max-width: 720px; margin-bottom: clamp(28px, 4vw, 40px); }

.sgf-head__eyebrow {
	margin: 0 0 10px;
	font-size: var(--sq-t-eyebrow);
	font-weight: var(--sq-w-bold);
	letter-spacing: var(--sq-ls-eyebrow);
	text-transform: uppercase;
	color: var(--wp--preset--color--brand);
}

.sgf-head__title {
	margin: 0 0 12px;
	font-size: var(--sq-t-h1);
	line-height: var(--sq-lh-h2);
	letter-spacing: var(--sq-ls-h3);
}

.sgf-head__lede {
	margin: 0 0 22px;
	max-width: 62ch;
	font-size: var(--sq-t-p1);
	line-height: var(--sq-lh-body);
	color: var(--sq-muted);
}

.sgf-search {
	display: flex;
	align-items: center;
	gap: 8px;
	max-width: 520px;
	padding: 6px 6px 6px 12px;
	border: 1px solid var(--sq-line);
	border-radius: 999px;
	background: var(--sq-sheet);
}

.sgf-search__i { flex: none; color: var(--sq-muted); }

.sgf-search input {
	flex: 1 1 auto;
	min-width: 0;
	border: 0;
	background: none;
	padding: 8px 0;
	font: inherit;
	font-size: var(--sq-t-p2);
	color: inherit;
}

.sgf-search input:focus { outline: none; }
.sgf-search:focus-within { border-color: var(--wp--preset--color--brand); }

.sgf-search__go {
	flex: none;
	border: 0;
	border-radius: 999px;
	padding: 9px 18px;
	font: inherit;
	font-size: var(--sq-t-p3);
	font-weight: var(--sq-w-semibold);
	cursor: pointer;
	background: var(--wp--preset--color--brand);
	color: var(--wp--preset--color--accent-contrast);
}

.sgf-search__go:hover { background: var(--wp--preset--color--signal-ink); }

.sgf-head__count {
	margin: 14px 0 0;
	font-size: var(--sq-t-p3);
	color: var(--sq-muted);
}

/* ── Filters ────────────────────────────────────────────────────────────────── */

.sgf-filters {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 22px;
}

.sgf-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 7px 14px;
	border: 1px solid var(--sq-line);
	border-radius: 999px;
	background: var(--sq-sheet);
	font-size: var(--sq-t-p3);
	font-weight: var(--sq-w-medium);
	line-height: var(--sq-lh-h1);
	text-decoration: none;
	color: inherit;
	transition: border-color .15s, background .15s, color .15s;
}

.sgf-chip:hover { border-color: var(--sq-ink); }

.sgf-chip.is-on {
	background: var(--sq-ink);
	border-color: var(--sq-ink);
	color: var(--sq-paper);
}

.sgf-chip__n { font-size: var(--sq-t-eyebrow); opacity: .6; }
.sgf-chip--reset { border-style: dashed; color: var(--sq-muted); }

/* ── Card grid ──────────────────────────────────────────────────────────────── */

.sgf-grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: clamp(16px, 2vw, 22px);
}

@media (min-width: 560px)  { .sgf-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px)  { .sgf-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1180px) { .sgf-grid { grid-template-columns: repeat(4, 1fr); } }

/* Related uses three at most, so it never reads as a second archive. */
@media (min-width: 900px) { .sgf-grid--3 { grid-template-columns: repeat(3, 1fr); } }

.sgf-card {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border: 1px solid var(--sq-line);
	border-radius: 14px;
	background: var(--sq-sheet);
	transition: border-color .15s, transform .15s, box-shadow .15s;
}

.sgf-card:hover {
	border-color: var(--sq-ink);
	transform: translateY(-2px);
	box-shadow: var(--wp--custom--shadow--sm, 0 6px 18px rgba(0,0,0,.06));
}

.sgf-card__media {
	display: block;
	aspect-ratio: 16 / 10;
	overflow: hidden;
	background: var(--sq-soft);
}

.sgf-card__img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.sgf-card__img--none { display: block; }

.sgf-card__body {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	gap: 8px;
	padding: 16px 16px 18px;
}

.sgf-card__tags {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 0;
}

.sgf-card__plat,
.sgf-card__topic {
	font-size: var(--sq-t-eyebrow);
	font-weight: var(--sq-w-bold);
	letter-spacing: var(--sq-ls-eyebrow);
	text-transform: uppercase;
	padding: 3px 8px;
	border-radius: 4px;
}

.sgf-card__plat { background: var(--sq-ink); color: var(--sq-paper); }
.sgf-card__topic { background: var(--sq-soft); color: var(--sq-muted); }

.sgf-card__title {
	margin: 0;
	font-size: var(--sq-t-p2);
	line-height: var(--sq-lh-h4);
	letter-spacing: var(--sq-ls-h4);
	/* Two lines everywhere, so every card in a row starts its body at the same place. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.sgf-card__title a { color: inherit; text-decoration: none; }
.sgf-card__title a:hover { color: var(--wp--preset--color--brand); }

.sgf-card__desc {
	margin: 0;
	font-size: var(--sq-t-p3);
	line-height: var(--sq-lh-supporting);
	color: var(--sq-muted);
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* Pushes the action row down so it sits on one line across the whole row. */
.sgf-card__foot {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 10px;
	margin: auto 0 0;
	padding-top: 10px;
	border-top: 1px solid var(--sq-line);
	font-size: var(--sq-t-p3);
}

.sgf-card__langs { color: var(--sq-muted); font-variant-numeric: tabular-nums; }
.sgf-card__go { font-weight: var(--sq-w-semibold); color: var(--wp--preset--color--brand); }

.sgf-empty {
	padding: 40px 0;
	font-size: var(--sq-t-p2);
	color: var(--sq-muted);
}

/* ── Pagination ─────────────────────────────────────────────────────────────── */

.sgf-pager { margin-top: 40px; }

.sgf-pager ul {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	justify-content: center;
	list-style: none;
	margin: 0;
	padding: 0;
}

.sgf-pager a,
.sgf-pager span {
	display: inline-flex;
	align-items: center;
	min-width: 38px;
	height: 38px;
	padding: 0 12px;
	justify-content: center;
	border: 1px solid var(--sq-line);
	border-radius: 8px;
	font-size: var(--sq-t-p3);
	text-decoration: none;
	color: inherit;
}

.sgf-pager a:hover { border-color: var(--sq-ink); }

.sgf-pager .current {
	background: var(--sq-ink);
	border-color: var(--sq-ink);
	color: var(--sq-paper);
}

/* ── Resource page ──────────────────────────────────────────────────────────── */

.sgf-single { max-width: 860px; }

.sgf-crumbs ol {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	list-style: none;
	margin: 0 0 18px;
	padding: 0;
	font-size: var(--sq-t-p3);
	color: var(--sq-muted);
}

.sgf-crumbs li + li::before { content: "/"; margin-right: 6px; opacity: .5; }
.sgf-crumbs a { color: inherit; }

.sgf-labels { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }

.sgf-label {
	font-size: var(--sq-t-eyebrow);
	font-weight: var(--sq-w-bold);
	letter-spacing: var(--sq-ls-eyebrow);
	text-transform: uppercase;
	padding: 4px 9px;
	border-radius: 4px;
	text-decoration: none;
}

.sgf-label--plat { background: var(--sq-ink); color: var(--sq-paper); }
.sgf-label--topic { background: var(--sq-soft); color: var(--sq-muted); }

.sgf-title {
	margin: 0 0 12px;
	font-size: var(--sq-t-h2);
	line-height: var(--sq-lh-h3);
	letter-spacing: var(--sq-ls-h3);
}

.sgf-dek {
	margin: 0 0 20px;
	font-size: var(--sq-t-p1);
	line-height: var(--sq-lh-body);
	color: var(--sq-muted);
}

.sgf-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 18px;
	margin: 0 0 28px;
	padding: 14px 0;
	border-block: 1px solid var(--sq-line);
	list-style: none;
	font-size: var(--sq-t-p3);
	color: var(--sq-muted);
}

.sgf-meta strong { color: var(--wp--preset--color--brand); }

/* Capped rather than full-bleed: these are screenshots, not hero art. */
.sgf-hero { margin: 0 0 30px; }

.sgf-hero__img {
	display: block;
	width: 100%;
	max-height: 420px;
	object-fit: cover;
	border-radius: 12px;
	border: 1px solid var(--sq-line);
}

.sgf-body { font-size: var(--sq-t-p2); line-height: var(--sq-lh-body); }
.sgf-body > * + * { margin-top: 1.05em; }
.sgf-body h2 { margin-top: 1.9em; font-size: var(--sq-t-h3); line-height: var(--sq-lh-ui); letter-spacing: var(--sq-ls-h4); }
.sgf-body h3 { margin-top: 1.5em; font-size: var(--sq-t-p1); line-height: var(--sq-lh-h4); }
.sgf-body ol, .sgf-body ul { padding-left: 1.3em; }
.sgf-body li + li { margin-top: .4em; }
.sgf-body a { color: var(--wp--preset--color--signal-ink); }

.sgf-body img {
	max-width: 100%;
	height: auto;
	border-radius: 10px;
	border: 1px solid var(--sq-line);
}

/* ── The code component ─────────────────────────────────────────────────────── */

.sgf-code {
	margin: 26px 0;
	border: 1px solid var(--sq-line);
	border-radius: 12px;
	overflow: hidden;
	background: var(--sq-sheet);
}

.sgf-code__bar {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 9px 10px 9px 14px;
	background: var(--sq-soft);
	border-bottom: 1px solid var(--sq-line);
	/* The body sets a measure on figcaption; code needs the full width. */
	max-width: none;
	font-size: var(--sq-t-p3);
	color: var(--sq-muted);
}

.sgf-code__lang {
	font-weight: var(--sq-w-bold);
	letter-spacing: var(--sq-ls-eyebrow);
	text-transform: uppercase;
	color: var(--sq-ink);
}

.sgf-code__lines { font-variant-numeric: tabular-nums; opacity: .75; }

.sgf-code__copy {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin-left: auto;
	padding: 6px 12px;
	border: 1px solid var(--sq-line);
	border-radius: 7px;
	background: var(--sq-sheet);
	font: inherit;
	font-size: var(--sq-t-p3);
	font-weight: var(--sq-w-semibold);
	line-height: var(--sq-lh-h1);
	color: inherit;
	cursor: pointer;
	transition: border-color .15s, background .15s, color .15s;
}

.sgf-code__copy:hover {
	border-color: var(--sq-ink);
	background: var(--sq-paper);
}

.sgf-code__copy:focus-visible {
	outline: 2px solid var(--wp--preset--color--brand);
	outline-offset: 2px;
}

.sgf-code__i { flex: none; }
.sgf-code__i--done { display: none; }

.sgf-code.is-copied .sgf-code__copy {
	border-color: var(--sq-good);
	color: var(--sq-good);
}

.sgf-code.is-copied .sgf-code__i--copy { display: none; }
.sgf-code.is-copied .sgf-code__i--done { display: inline; }

.sgf-code__scroll { overflow-x: auto; }

.sgf-code__pre {
	margin: 0;
	padding: 16px;
	background: none;
	font-family: var(--sq-font-mono);
	font-size: var(--sq-t-p3);
	line-height: var(--sq-lh-body);
	/* Long lines scroll rather than reflow: a wrapped selector is a misread selector. */
	white-space: pre;
	tab-size: 2;
}

.sgf-code__pre code {
	background: none;
	padding: 0;
	font: inherit;
	color: inherit;
}

/* Collapsed until asked, so a 146-line snippet does not bury the instructions. */
.sgf-code.is-long .sgf-code__scroll { max-height: 340px; overflow-y: hidden; }
.sgf-code.is-long.is-open .sgf-code__scroll { max-height: none; overflow-y: auto; }

.sgf-code__more {
	display: block;
	width: 100%;
	padding: 10px;
	border: 0;
	border-top: 1px solid var(--sq-line);
	background: var(--sq-soft);
	font: inherit;
	font-size: var(--sq-t-p3);
	font-weight: var(--sq-w-semibold);
	color: var(--sq-muted);
	cursor: pointer;
}

.sgf-code__more:hover { color: var(--sq-ink); }

.sgf-code__more:focus-visible {
	outline: 2px solid var(--wp--preset--color--brand);
	outline-offset: -2px;
}

.sgf-code__status {
	margin: 0;
	padding: 0;
	border: 0;
	height: 1px;
	width: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	position: absolute;
}

/* ── Related and prev/next ──────────────────────────────────────────────────── */

.sgf-related { margin-top: 56px; }

.sgf-related h2 {
	margin: 0 0 18px;
	font-size: var(--sq-t-h4);
	letter-spacing: var(--sq-ls-h4);
}

.sgf-pn {
	display: grid;
	gap: 12px;
	margin-top: 40px;
	padding-top: 24px;
	border-top: 1px solid var(--sq-line);
}

@media (min-width: 700px) { .sgf-pn { grid-template-columns: 1fr 1fr; } }

.sgf-pn__a {
	display: block;
	padding: 14px 16px;
	border: 1px solid var(--sq-line);
	border-radius: 10px;
	text-decoration: none;
	color: inherit;
	font-size: var(--sq-t-p3);
	font-weight: var(--sq-w-semibold);
	line-height: var(--sq-lh-eyebrow);
}

.sgf-pn__a:hover { border-color: var(--sq-ink); }
.sgf-pn__a--next { text-align: right; }

.sgf-pn__a span {
	display: block;
	margin-bottom: 4px;
	font-size: var(--sq-t-p3);
	font-weight: var(--sq-w-bold);
	letter-spacing: var(--sq-ls-eyebrow);
	text-transform: uppercase;
	color: var(--sq-muted);
}

/* ── Support note ───────────────────────────────────────────────────────────── */

.sgf-support {
	margin: 34px 0 0;
	padding: 16px 18px;
	border: 1px dashed var(--sq-line);
	border-radius: 10px;
	background: var(--sq-soft);
	font-size: var(--sq-t-p3);
	line-height: var(--sq-lh-supporting);
	color: var(--sq-muted);
}

.sgf-support strong { color: var(--sq-ink); }

@media (prefers-reduced-motion: reduce) {
	.sgf-card { transition: none; }
	.sgf-card:hover { transform: none; }
}

/* ── FAQ ────────────────────────────────────────────────────────────────────── */

.sgf-faq {
	margin: 26px 0;
	border: 1px solid var(--sq-line);
	border-radius: 12px;
	overflow: hidden;
}

.sgf-faq__item + .sgf-faq__item { border-top: 1px solid var(--sq-line); }

.sgf-faq__item summary {
	padding: 15px 18px;
	font-size: var(--sq-t-p2);
	font-weight: var(--sq-w-semibold);
	line-height: var(--sq-lh-eyebrow);
	cursor: pointer;
	list-style: none;
	position: relative;
	padding-right: 46px;
}

.sgf-faq__item summary::-webkit-details-marker { display: none; }

.sgf-faq__item summary::after {
	content: "+";
	position: absolute;
	right: 18px;
	top: 50%;
	transform: translateY(-50%);
	font-size: var(--sq-t-h4);
	font-weight: var(--sq-w-regular);
	color: var(--sq-muted);
}

.sgf-faq__item[open] summary::after { content: "\2212"; }

.sgf-faq__item summary:focus-visible {
	outline: 2px solid var(--wp--preset--color--brand);
	outline-offset: -2px;
}

.sgf-faq__a {
	padding: 0 18px 18px;
	font-size: var(--sq-t-p3);
	line-height: var(--sq-lh-body);
	color: var(--sq-muted);
}

.sgf-faq__a > * + * { margin-top: .8em; }
.sgf-faq__a ul, .sgf-faq__a ol { padding-left: 1.25em; }
