/*
 * Feature guide_reading (default off, inc/features/guide-reading.php). Loaded on a single post only while the switch is on.
 *
 * 1. The "In this guide" contents as a closed native details control (markup from blocks/guide-contents/render.php, which adds
 *    the class cc-guide-contents--details only while the switch is on, so every rule below is inert with the switch off).
 *    Same pattern as the .cc-faq summary rules in base.css: a 44 px target, the plus and minus sign, and the global focus ring
 *    from base.css (near black on the light reading panel, Highlight in forced colours).
 * 2. The breadcrumb inside the article header (markup unchanged, blocks/breadcrumbs/render.php):
 *    a. the separator moves from the start of each item (::before, which base.css draws) to the end of the item before it
 *       (::after), so when a long title wraps the trail onto a second line that line never starts with a slash;
 *    b. on a phone the last item (the current page, which the H1 right below already says) is taken out of sight so the trail
 *       fits one row, but it stays in the accessibility tree (visually hidden, not display none) so a screen reader still
 *       hears the current page with aria-current; the item before it loses its separator so no slash is left at the end.
 *    The rules sit under the body class cc-feature-guide_reading and inside .cc-article-header.
 * 3. A little air above a heading that a contents link jumps to (scroll-margin-top), so the heading box no longer lands exactly on
 *    the top edge of the screen. Under the body class cc-feature-guide_reading, only for the headings of a guide that prints the
 *    contents control.
 */

/* ------------------------------------------------------------------ 1. contents control */

/* The panel keeps its border and background; the summary carries the padding so the whole row is the tap target. */
.cc-guide-contents--details {
	margin-bottom: var(--cc-space-l);
	padding: 0;
}

.cc-guide-contents--details .cc-guide-contents__summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--cc-space-m);
	box-sizing: border-box;
	min-height: var(--cc-target-min);
	padding: var(--cc-space-xs) var(--cc-space-l);
	/* Transparent here so nothing changes on screen; the forced colours rule below turns it into a visible border. */
	border: 1px solid transparent;
	cursor: pointer;
	list-style: none;
}

.cc-guide-contents--details .cc-guide-contents__summary::-webkit-details-marker {
	display: none;
}

.cc-guide-contents--details .cc-guide-contents__summary:hover .cc-guide-contents__title {
	text-decoration: underline;
	text-underline-offset: 0.25em;
}

.cc-guide-contents--details .cc-guide-contents__title {
	margin: 0;
	font-size: var(--cc-font-size-s);
	font-weight: 600;
	letter-spacing: 0;
	text-transform: none;
}

/* The sign says what the control will do, so the state is never shown by colour alone. It is decoration: the open or closed
   state is announced by the details element itself, so the sign has an empty text alternative. */
.cc-guide-contents--details .cc-guide-contents__summary::after {
	content: "+";
	content: "+" / "";
	flex: none;
	font-size: 1.5rem;
	line-height: 1;
}

.cc-guide-contents--details .cc-guide-contents__details[open] > .cc-guide-contents__summary::after {
	content: "\2212";
	content: "\2212" / "";
}

.cc-guide-contents--details .cc-guide-contents__details[open] > .cc-guide-contents__summary {
	border-bottom-color: var(--cc-color-panel-line);
}

.cc-guide-contents--details .cc-guide-contents__list {
	margin: 0;
	padding: var(--cc-space-xs) var(--cc-space-l) var(--cc-space-m) calc(var(--cc-space-l) * 2);
	/* The list is a grid from 48em (resource-centre.css): each row starts at its top edge, so the two columns line up and a tall
	   item next to a short one is not stretched or centred against it. */
	align-items: start;
}

/* The ordinal of an ordered list item sits beside the first line of the item only when the link is a block level box. The base
   stylesheet makes these links inline-block, whose baseline is its LAST line, so when a long title wrapped onto a second line
   the number was drawn beside that second line, with the text starting on the line above it. At every width the link is a block
   here, with no extra height: the number sits beside the first line and the row keeps its own height. The 44 px rule for touch
   screens and narrow windows follows and takes over below 48em. */
.cc-guide-contents--details .cc-guide-contents__list a {
	display: block;
}

/* Once opened, the links are comfortable to tap on a touch screen (the same 44 px rule the breadcrumb and footer links follow).
   A block level row, so the whole line is the target and the list rows keep an even rhythm. */
@media (pointer: coarse), (max-width: 48em) {
	.cc-guide-contents--details .cc-guide-contents__list a {
		display: flex;
		align-items: center;
		box-sizing: border-box;
		min-height: 2.75rem;
	}
}

@media (forced-colors: active) {
	/* A border on the control itself, so it is recognisable as a control without relying on any colour. */
	.cc-guide-contents--details .cc-guide-contents__summary {
		border: 1px solid ButtonText;
	}
}

/* A contents list is of no use on paper (and a closed one would print only its label). */
@media print {
	.cc-guide-contents--details {
		display: none;
	}
}

/* ------------------------------------------------------------------ 2. breadcrumb in the article header */

/* Every rule here is under the body class the theme adds while the switch is on, and only in the article header. Pages,
   archives, search and the cloud phone legacy template have no .cc-article-header, so they are not touched.

   a. The separator belongs to the END of the item before it. base.css draws it as a ::before on every item after the first, so
      when the trail wraps (the guide title is long, at about 768 px) the item that drops to the second line brings its
      separator with it and the line starts with a stray slash. Here the separator is moved to a ::after on every item except
      the last: it stays on the line of the item it follows, so a wrapped line never begins with one, at any width. Same
      colour, same gap on both sides, same empty text alternative (a screen reader never reads it). */
body.cc-feature-guide_reading .cc-article-header .cc-breadcrumbs__item + .cc-breadcrumbs__item::before {
	content: none;
}

body.cc-feature-guide_reading .cc-article-header .cc-breadcrumbs__item:not(:last-child)::after {
	content: "/";
	content: "/" / "";
	margin-left: var(--cc-space-xs);
	color: var(--cc-color-line-strong);
}

/* b. On a phone the last item (the current page, which the H1 right below already says) is taken out of sight so the trail
      fits one row, and only when the trail has at least three items (Home, the hub, the guide), so it can never be reduced to
      Home alone. It is hidden the visual way, not with display none: display none would also remove the aria-current="page"
      item from the accessibility tree, and a screen reader user on a phone would hear a trail that ends at the parent. The
      same clipping as .cc-visually-hidden in base.css: a 1 px box taken out of the flow (so it takes no room and no gap, and
      cannot add a row or a sideways scroll), clipped to nothing, text kept on one line. It has no link and no focusable
      child, so it cannot be tabbed to. Its own separator is never drawn (the rule in a. above stops at the last item).
      The item before it is then the end of the drawn trail and must not keep a trailing separator. */
@media (max-width: 47.99em) {
	body.cc-feature-guide_reading .cc-article-header .cc-breadcrumbs__item:last-child:nth-child(n + 3) {
		position: absolute;
		width: 1px;
		height: 1px;
		margin: -1px;
		padding: 0;
		overflow: hidden;
		clip: rect(0, 0, 0, 0);
		clip-path: inset(50%);
		white-space: nowrap;
		border: 0;
	}

	/* The item is a flex row, so its text span is a flex item that would keep the full width of the one-line title (min-width
	   auto) and stick out of the 1 px box, to about 400 px from the left edge: clipped away and no sideways scroll, but a
	   measuring tool would count a box past the right edge of a 320 or 375 px screen. min-width 0 lets the span shrink with the
	   box, so every box of the hidden item stays inside the 1 px one. The text is still in the markup and the accessibility tree. */
	body.cc-feature-guide_reading .cc-article-header .cc-breadcrumbs__item:last-child:nth-child(n + 3) > * {
		min-width: 0;
	}

	body.cc-feature-guide_reading .cc-article-header .cc-breadcrumbs__item:nth-last-child(2):nth-child(n + 2)::after {
		content: none;
	}
}

/* ------------------------------------------------------------------ 3. air above a jump target */

/* After a contents link is followed, the browser scrolls the target heading so its box sits exactly on the top edge of the screen.
   A scroll margin leaves a little air above it (1.25rem, about 20 px, so the heading is clearly in view and still well inside the
   first screen). It applies only to the headings the contents can reach: the h2 elements with an id inside the post content of a
   guide whose article carries the contents control (the same headings blocks/guide-contents/render.php lists). Nothing else on
   the page is touched: pages, archives, products and the cloud phone legacy template have no such article, and a post with fewer
   than three linked headings prints no contents, so none of its headings matches.
   No sticky or fixed element exists on these pages at any width (the site header and the breadcrumb scroll away with the page),
   so no header height is added here; if one is ever made sticky, its height has to be added to this value. A browser without
   :has() simply keeps the old landing position, and the page still works. */
body.cc-feature-guide_reading .cc-reading:has(.cc-guide-contents--details) .entry-content h2[id] {
	scroll-margin-top: 1.25rem;
}
