/*
 * Shared primitives for the MCP Azure Security Guide on mkdocs-shadcn, at the look of the Sherpa workshop docs:
 * focus, the page column and the guide's chrome (skip link, site title, header tabs, search dialog, sidebar items, page
 * header and dates, bottom navigation), typography, code, tables and their scroll cue, admonitions and collapsible
 * blocks, content tabs, task lists, and the reduced-motion rule. Text, links, lists, inline code, and buttons keep
 * shadcn's article styles, as Sherpa's do; these rules set the rhythm and the parts the theme leaves out. The component
 * files build on these. Every color and size comes from tokens.css.
 *
 * Portions adapted from Sherpa, the MCP Security Summit Workshop (https://github.com/Azure-Samples/sherpa): the
 * page width and spacing, the header tab colors, the section rhythm, code blocks, card admonitions with one accent
 * variable per type, and the collapsible cards.
 *
 * MIT License
 *
 * Copyright (c) 2026 Azure Samples
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/* ---------------------------------------------------------------- Focus */

/* Visible focus on every interactive element. shadcn's buttons and sidebar items set outline: none and draw a faint
   ring instead, so this wins. */
:focus-visible {
  outline: var(--g-focus-width) solid var(--guide-focus) !important;
  outline-offset: 2px !important;
}

/* Focus takes the primary color, which is near black in the light scheme and would vanish on the dark gradients
   of the hero, the banners, and the specification bar, so focus turns white there. */
.typography :is(.g-hero, .g-banner),
.g-announce {
  --guide-focus: #ffffff;
}

/* ---------------------------------------------------------------- Page column */

/* One column holds every block of a page, so all of them share both edges at every width. --g-column sets it: the
   reading measure on a page with navigation, and 56rem on the home page, which has no sidebar or table of contents
   and fills its column with cards. The bottom navigation takes the same width. Like Sherpa's layout, the sidebar
   narrows from 1024px and the table of contents from 1280px; shadcn caps the article at 42rem (672px). Between 768px
   and 1279px shadcn drops inline padding while the page's right edge still meets the viewport (from 1280px the table
   of contents sits there), so the page keeps 1rem inline padding on top of the main wrapper's 0.5rem to match the
   header's 24px gutter. The page starts close under the header, as Sherpa's does. */
[data-slot="docs"] {
  --g-column: var(--g-measure);
}

[data-slot="docs"]:has(.g-hero) {
  --g-column: 56rem;
}

.g-page {
  max-width: min(100%, var(--g-column));
  padding-top: 1.25rem;
}

@media screen and (min-width: 48rem) and (max-width: 79.984375rem) {
  .g-page {
    max-width: min(100%, calc(var(--g-column) + 2rem));
    padding-inline: 1rem;
  }
}

/* The page's last block drops its bottom margin, so a page that ends in a list, a table, or a card leaves the same
   space under it as one that ends in a paragraph: the article's padding and the pager's margin. The rule weighs an
   element more than a component's own margin, such as .typography .g-incident's. */
article .typography > :last-child {
  margin-bottom: 0;
}

/* Short landscape viewports (phones turned sideways) have little vertical height; trim the space above the page
   head and between the page head and the banner while keeping the sticky header intact. */
@media (max-height: 30rem) and (orientation: landscape) {
  .g-page {
    gap: 0.5rem;
    padding-top: 0.375rem;
  }

  .g-page > .g-page-head {
    margin-bottom: 0;
  }
}

@media (min-width: 64rem) {
  [data-slot="sidebar-wrapper"] {
    --sidebar-width: 15rem !important;
    --top-spacing: 0.25rem;
  }

  [data-slot="sidebar"] {
    --sidebar-menu-width: 13.5rem;
  }
}

@media (min-width: 80rem) {
  /* Reserve the right table-of-contents column from first paint whenever page.html marks the article with
     data-has-toc, so the article does not jump left when #toc streams in after </article>. */
  [data-slot="docs"]:has(> div > article[data-has-toc]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 13rem;
  }

  [data-slot="docs"]:has(> div > article[data-has-toc]) > div:first-child {
    grid-column: 1;
  }

  [data-slot="docs"] > .sticky {
    grid-column: 2;
    width: 13rem;
  }
}

/* A page whose front matter hides its navigation or its table of contents, such as the home page, would leave
   that column empty; the column closes instead, and the page centers in the width left. */
@media (min-width: 64rem) {
  [data-slot="sidebar-wrapper"]:not(:has(> [data-slot="sidebar"] nav)) {
    grid-template-columns: minmax(0, 1fr);
  }

  [data-slot="sidebar"]:not(:has(nav)) {
    display: none;
  }
}

[data-slot="docs"] > .sticky:not(:has(#toc)) {
  display: none;
}

#toc {
  overscroll-behavior: contain;
}

#toc[data-overflow-bottom="true"] {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 3rem), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 3rem), transparent 100%);
}

/* Phone and tablet menu dialog: sits flush under the header from first paint, with an opaque panel, a transparent
   backdrop so the header stays unshaded, contained overscroll, and no focus ring on its non-interactive wrapper. */
#bottom-sidebar {
  position: fixed;
  top: var(--g-menu-top, var(--header-height));
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  max-width: 100%;
  height: calc(100dvh - var(--g-menu-top, var(--header-height)));
  max-height: none;
  margin: 0;
  padding: 0;
  z-index: 50;
}

body:has(.g-announce:not([hidden])) #bottom-sidebar {
  --g-menu-top: calc(var(--header-height) + 1.875rem);
}

#bottom-sidebar::backdrop {
  background: transparent;
}

#bottom-sidebar [data-slot="popover-content"] {
  background-color: var(--background);
  overscroll-behavior: contain;
}

#bottom-sidebar [data-slot="popover-content"]:focus-visible {
  outline: none !important;
}

#bottom-sidebar nav {
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
}

/* shadcn lays out every article as the page column: a flex column with 2rem gaps, at most 42rem wide, in the
   article text color. An article inside the page, such as an incident card, is a block in that column. */
article article {
  display: block;
  flex: none;
  width: auto;
  max-width: none;
  min-width: 0;
  margin-inline: 0;
  padding: 0;
  color: inherit;
}

/* ---------------------------------------------------------------- Page header */

/* The page tools and the date sit close together above the content, as Sherpa's page header does. */
.g-page-head {
  gap: 0;
  margin-bottom: 0.25rem;
}

.g-page-date {
  padding-top: 0.25rem;
}

.g-page-tools {
  position: relative;
}

.g-copy-page {
  cursor: pointer;
}

/* The vendored icons have no fill of their own, so they would stay black on the dark scheme's buttons. */
.g-page-tool svg {
  fill: currentColor;
}

.g-copy-page__status {
  position: absolute;
  top: 50%;
  right: calc(100% + 0.5rem);
  transform: translateY(-50%);
  white-space: nowrap;
  color: var(--guide-muted);
  font-size: var(--g-text-xs);
  line-height: 1.2;
  pointer-events: none;
}

@media (max-width: 23.984375rem) {
  .g-copy-page__status {
    max-width: calc(100vw - 12rem);
    white-space: normal;
    text-align: right;
  }
}

/* ---------------------------------------------------------------- Skip link */

.g-skip {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 60;
  padding: 0.5rem 0.75rem;
  color: var(--guide-fg);
  font-size: var(--g-text-sm);
  border-radius: var(--g-radius);
  background: var(--guide-bg);
  transform: translateY(-200%);
}

.g-skip:focus {
  transform: none;
}

/* ---------------------------------------------------------------- Header */

/* The site title gives way first when the header runs out of room, so the header never scrolls sideways. */
.g-site-title {
  min-width: 0;
}

.g-site-title > .button {
  flex-shrink: 1;
  min-width: 0;
}

.g-site-title__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The vendored icon has no fill of its own, so it would stay black in the dark scheme. */
.g-site-title svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

/* The header tabs, as Sherpa's header navigation draws them: muted text on no fill, with the open section's tab, which
   the template marks aria-current, in the text color. The two text colors are close in the dark scheme, so that tab
   is semibold too. */
.g-header nav[aria-label="Tabs"] a {
  color: var(--guide-muted);
}

.g-header nav[aria-label="Tabs"] a[aria-current] {
  color: var(--guide-fg);
  font-weight: 600;
}

/* ---------------------------------------------------------------- Search */

/* The theme narrows button.search to 10rem (160px) from 1024px to 1279px and widens it to 16rem (256px) at 1280px,
   so the long label only fits from 1280px up. */
.g-search__long {
  display: none;
}

.g-search__short {
  display: inline-flex;
}

@media (min-width: 80rem) {
  .g-search__long {
    display: inline-flex;
  }

  .g-search__short {
    display: none;
  }
}

/* The browser keeps a dialog 38px narrower than the screen, so below 552px the search dialog is narrower than
   shadcn's 32rem search panel and clipped its sides. Flex sizing keeps the results list inside the dynamic viewport
   height so landscape phones do not clip the last result. */
#search-dialog {
  max-height: calc(100dvh - 1.5rem);
}

#search-dialog[open] {
  display: flex;
  flex-direction: column;
}

#search-dialog > div {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 100%;
  min-height: 0;
  max-height: 100%;
}

#search-dialog > div > :first-child {
  flex: 0 0 auto;
  height: auto;
}

#search-dialog [data-slot="command-input-wrapper"] {
  height: 2.5rem;
}

#search-dialog [data-slot="command-input"] {
  height: 100%;
  min-width: 0;
  padding-block: 0;
}

/* The panel around the row clips its content, so the box's focus ring lost its top and bottom and showed as two bars
   at its ends. The row draws the ring inside its own edges instead while the search box itself has focus. */
#search-dialog [data-slot="command-input"]:focus-visible {
  outline: none !important;
}

#search-dialog [data-slot="command-input-wrapper"]:has([data-slot="command-input"]:focus) {
  outline: var(--g-focus-width) solid var(--guide-focus);
  outline-offset: calc(-1 * var(--g-focus-width));
}

#properdocs-search-results {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(18.75rem, calc(100dvh - 5rem));
  overscroll-behavior: contain;
}

#properdocs-search-results .g-search__status {
  margin: 0;
  padding: 0.75rem 1rem;
  color: var(--guide-muted);
  font-size: var(--g-text-sm);
}

.g-search__close {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-right: -0.25rem;
  padding: 0;
  color: var(--guide-muted);
  background: transparent;
  border: 0;
  border-radius: var(--g-radius-sm);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.g-search__close svg {
  width: 1.125rem;
  height: 1.125rem;
  fill: currentColor;
}

.g-search__close:active {
  background: var(--guide-accent-surface);
  color: var(--guide-fg);
}

@media (hover: hover) and (pointer: fine) {
  .g-search__close:hover {
    background: var(--guide-accent-surface);
    color: var(--guide-fg);
  }
}

/* On coarse pointers (phones and tablets), use 16px input text so iOS Safari does not zoom on focus, match the row
   height, and show the close button. */
@media (pointer: coarse) {
  #search-dialog [data-slot="command-input-wrapper"] {
    height: 2.75rem;
  }

  #search-dialog [data-slot="command-input"] {
    font-size: var(--g-text-base);
  }

  .g-search__close {
    display: inline-flex;
  }
}

/* On phones and short landscape viewports, anchor the dialog near the top so it stays above the software keyboard. */
@media (max-width: 47.984375rem), (max-height: 30rem) {
  #search-dialog {
    top: max(0.75rem, env(safe-area-inset-top));
    bottom: auto;
    margin: 0;
    width: min(32rem, calc(100vw - 1.5rem));
    max-height: calc(100dvh - 1.5rem);
    translate: -50% 0;
  }
}

/* ---------------------------------------------------------------- Sidebar */

/* The theme fades the top of the sidebar's list with a blurred gradient, and overrides/templates/sidebar.html leaves
   out its fade at the bottom. The guide's sections run past the screen, so the fades sat over links the sidebar shows
   whole, washing them out and taking their clicks. Every link shows at full contrast, as on Sherpa. */
[data-slot="sidebar"] > .blur-xs {
  display: none;
}

/* A long page title wraps inside its item instead of running into the next one; shadcn fixes items at 30px.
   Sherpa's sidebar does the same. */
[data-sidebar="menu"] [data-sidebar="menu-button"],
[data-sidebar="menu-sub"] [data-sidebar="menu-button"] {
  align-items: flex-start;
  width: 100%;
  max-width: 100%;
  height: auto;
  min-height: 1.9rem;
  padding: 0.45rem 0.5rem;
  line-height: 1.25;
  white-space: normal;
}

/* ---------------------------------------------------------------- Bottom navigation */

/* The row under the page takes the page column's width, and its 1rem inline padding across 768 to 1279px so it
   lines up with the article column at every width. */
#bottom-navigation {
  max-width: min(100%, var(--g-column));
}

@media screen and (min-width: 48rem) and (max-width: 79.984375rem) {
  #bottom-navigation {
    max-width: min(100%, calc(var(--g-column) + 2rem));
    padding-inline: 1rem;
  }
}

/* The pager (overrides/templates/bottom_navigation.html) fills that row. On a phone the link to the previous page
   sits over the next page's card; from 768px the link takes the left and the card the right, where it stays when a
   page has no previous page. It sits nearer the page it continues than the footer under it. */
.g-pager {
  display: grid;
  gap: 1rem;
  margin-block: 0.5rem 2rem;
}

@media screen and (min-width: 48rem) {
  .g-pager {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    align-items: center;
    column-gap: 2rem;
  }

  .g-pager > .g-pager__next {
    grid-column: 2;
  }
}

/* ---------------------------------------------------------------- Typography */

/* Components size themselves by the column, not the viewport. Every block takes the column's full width; the column
   holds the reading measure (Page column). */
.typography {
  container: g-content / inline-size;
}

/* shadcn hides the h1s of the content and titles the page itself. The guide's h1 is in the content, in the banner,
   the hero, or the Markdown, and overrides/templates/page.html draws no other. A Markdown h1 is a page title of
   Sherpa's size. */
article .typography h1 {
  display: block;
  margin: 0 0 1rem;
  font-size: var(--g-text-2xl);
  font-weight: 600;
  line-height: 2rem;
  letter-spacing: -0.025em;
}

/* Sections: a rule over each h2, as Sherpa's pages put a --- before theirs, and Sherpa's closer spacing in place
   of shadcn's reference-docs gaps (3rem, 5rem from 1024px). The theme sets the sizes and weights. */
article .typography h2 {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--guide-border);
}

/* The first h2 under the banner, the hero, or the journey needs no rule; the banner's margin spaces it. */
article .typography :is(.g-banner, .g-hero, .g-journey) + h2 {
  padding-top: 0;
  border-top-width: 0;
}

article .typography :is(h3, h4) {
  margin-top: 1.5rem;
}

/* shadcn draws h4 as large as h3. */
article .typography h4 {
  font-size: var(--g-text-base);
}

/* shadcn styles #summary as its page header's summary, which overrides/templates/page.html leaves out. A section
   heading whose slug is summary keeps a heading's color, spacing, and width instead. */
article .typography :is(h2, h3, h4)#summary {
  max-width: none;
  margin-top: 1.5rem;
  color: inherit;
}

article .typography h2#summary {
  line-height: var(--text-2xl--line-height);
}

article .typography :is(h3, h4)#summary {
  line-height: var(--text-xl--line-height);
}

.typography :is(h1, h2, h3, h4) {
  text-wrap: balance;
}

.typography p,
.typography :is(ul, ol) {
  text-wrap: pretty;
}

/* Component links that read as cards, chips, or steps drop the theme's underline. */
.typography :is(.g-chip, .g-risk-card__link, .g-path-card__link, .g-journey a) {
  text-decoration: none;
}

.typography dl dt {
  font-weight: 620;
}

.typography img {
  border-radius: var(--g-radius);
}

/* The risk pages' illustrations are drawn on white paper, which glares on the dark page; the dark scheme dims them.
   Paper keeps them as drawn. */
@media screen {
  .dark .typography img:not([src$=".svg"]) {
    filter: brightness(0.8) contrast(1.1);
  }
}

/* Component lists drop shadcn's list indent, bullets, and item spacing. */
.typography :is(ul, ol):is(.g-banner__meta, .g-risk-grid, .g-path-grid, .g-next__risks, .g-incident__risks, .g-incident__sources),
.typography :is(.g-journey, .g-handson) > :is(ul, ol) {
  margin-left: 0;
  margin-right: 0;
  padding: 0;
  list-style: none;
}

.typography :is(ul, ol):is(.g-banner__meta, .g-risk-grid, .g-path-grid, .g-next__risks, .g-incident__risks, .g-incident__sources) > li,
.typography :is(.g-journey, .g-handson) > :is(ul, ol) > li {
  margin: 0;
}

/* ---------------------------------------------------------------- Code */

/* Inline code is shadcn's. A long identifier breaks rather than widen a phone's page. */
.typography :not(pre) > code {
  word-break: normal;
  overflow-wrap: anywhere;
}

/* Geist Mono joins characters such as <!-- and --> into arrows; code shows them as typed. */
.typography code {
  font-variant-ligatures: none;
}

/* Code blocks as on Sherpa: a muted block with a border, and room on the right for the theme's copy button. */
article .codehilite {
  background: var(--g-code-bg);
  border: 1px solid var(--guide-border);
}

article .codehilite pre {
  padding: 1rem 3.25rem 1rem 1.1rem;
  background: transparent;
}

/* The copy button floats over the block's top right corner. It is painted in the block's color, with a fade on its
   left and the strip to its right covered, so a line that scrolls under it slides behind it instead of running
   through the icon. shadcn's ghost button turns see-through under the pointer in the dark scheme; this one darkens
   and stays solid. */
article .codehilite > button {
  background-color: var(--g-code-bg);
  box-shadow: -0.625rem 0 0.5rem -0.125rem var(--g-code-bg), 0.5rem 0 0 var(--g-code-bg);
}

@media (hover: hover) and (pointer: fine) {
  article .codehilite > button.ghost:hover {
    background-color: color-mix(in srgb, var(--guide-fg) 6%, var(--g-code-bg));
  }
}

/* A collapsible block shows its code at full height once a reader opens it; shadcn caps a code block at 650px. */
article .typography details .codehilite pre {
  max-height: none;
}

/* Highlighting takes the guide's code colors, which meet 4.5:1 on the code background in both schemes; the comments
   of the theme's light Pygments style do not. The Pygments stylesheets load before this one, so these win at equal
   weight. */
.codehilite {
  color: var(--guide-fg);
}

.codehilite :is(.c, .ch, .cm, .c1, .cs, .cpf, .p, .pm, .gp, .go) {
  color: var(--guide-muted);
}

.codehilite :is(.k, .kd, .kn, .kp, .kr, .kt, .ow, .cp, .ne) {
  color: var(--g-code-keyword);
}

.codehilite :is(.s, .sa, .sb, .sc, .dl, .sd, .s2, .sh, .si, .sx, .sr, .s1, .ss, .nt, .gi) {
  color: var(--g-code-string);
}

.codehilite :is(.nf, .fm, .nc, .nd, .na, .py, .no, .kc, .nb, .bp, .gh, .gu) {
  color: var(--g-code-function);
}

.codehilite :is(.m, .mb, .mf, .mh, .mi, .mo, .il, .l, .ld) {
  color: var(--g-code-number);
}

.codehilite :is(.err, .gr, .gt, .gd, .se, .ni) {
  color: var(--g-code-special);
}

.codehilite :is(.n, .nn, .nx, .nl, .nv, .vc, .vg, .vi, .vm, .o, .w, .esc, .g, .x) {
  color: inherit;
}

/* ---------------------------------------------------------------- Tables */

/* A Markdown table is shadcn's, as on Sherpa: rows divided by rules under a plain header row. Its cells hold
   sentences, so they wrap and align to the top; a header label stays in the middle of its row, as shadcn draws it,
   and keeps the row's padding when it wraps. */
article .typography table:not([class]) :is(th, td) {
  white-space: normal;
}

article .typography table:not([class]) td {
  vertical-align: top;
}

article .typography table:not([class]) th {
  height: auto;
  padding-block: 0.625rem;
}

/* A code id in a row's first cell, such as a control's, stays on one line. */
article .typography table:not([class]) td:first-child > code:only-child {
  white-space: nowrap;
}

.typography .table-wrapper {
  margin: 1.5rem 0;
}

.g-table-wrap {
  margin: 1.5rem 0;
  overflow-x: auto;
  border-radius: var(--g-radius-lg);
  scrollbar-width: thin;
}

/* Scroll cue: a shade on each edge that still has table behind it. The shades stay at the scroller's edges,
   and covers that move with the table hide them once that edge of the table is in view. guide.js gives a
   scrolling wrapper a tab stop, so a keyboard can scroll it. */
.g-table-wrap,
.typography .table-wrapper {
  --g-scroll-cover: var(--guide-bg);
  --g-scroll-shade: color-mix(in srgb, var(--guide-fg) 24%, transparent);
  background:
    linear-gradient(to right, var(--g-scroll-cover) 35%, transparent) left / 3rem 100% no-repeat local,
    linear-gradient(to left, var(--g-scroll-cover) 35%, transparent) right / 3rem 100% no-repeat local,
    linear-gradient(to right, var(--g-scroll-shade), transparent) left / 1.125rem 100% no-repeat scroll,
    linear-gradient(to left, var(--g-scroll-shade), transparent) right / 1.125rem 100% no-repeat scroll;
  background-color: var(--g-scroll-cover);
}

/* On a phone a table with three or more columns scrolls at a readable width instead of squeezing every
   column to a few words; the scroll cue marks the cut edge. */
@container g-content (max-width: 37.5rem) {
  .typography table:not([class]) :is(th, td) {
    min-width: 7.5rem;
  }

  .typography table:not([class]):has(tr > :nth-child(3)) {
    min-width: 35rem;
  }

  .typography table:not([class]):has(tr > :nth-child(4)) {
    min-width: 45rem;
  }

  .typography table:not([class]):has(tr > :nth-child(5)) {
    min-width: 55rem;
  }
}

/* ---------------------------------------------------------------- Admonitions */

/* shadcn's admonition card (rounded, 14px text, a bold title) in one accent per type, as Sherpa colors its blocks:
   a thin edge in the accent on all four sides over a light tint of it. A ??? block takes the same card. The default
   sits at the lowest specificity so every type rule below wins. */
.typography :where(.admonition, details) {
  --g-adm-accent: var(--g-adm-note);
}

.typography .note { --g-adm-accent: var(--g-adm-note); }
.typography :is(.abstract, .summary, .tldr) { --g-adm-accent: var(--g-adm-abstract); }
.typography :is(.info, .todo) { --g-adm-accent: var(--g-adm-info); }
.typography :is(.tip, .hint, .important) { --g-adm-accent: var(--g-adm-tip); }
.typography :is(.success, .check, .done) { --g-adm-accent: var(--g-adm-success); }
.typography :is(.question, .help, .faq) { --g-adm-accent: var(--g-adm-question); }
.typography :is(.warning, .caution, .attention) { --g-adm-accent: var(--g-adm-warning); }
.typography :is(.failure, .fail, .missing) { --g-adm-accent: var(--g-adm-failure); }
.typography :is(.danger, .error) { --g-adm-accent: var(--g-adm-danger); }
.typography .bug { --g-adm-accent: var(--g-adm-bug); }
.typography .example { --g-adm-accent: var(--g-adm-example); }
.typography :is(.quote, .cite) { --g-adm-accent: var(--g-adm-quote); }
.typography .attack { --g-adm-accent: var(--guide-risk); }
.typography .spec { --g-adm-accent: var(--g-adm-spec); }

/* shadcn also pulls an admonition 0.25rem past the column on each side from 768px; it keeps to the column like
   every other block. */
article .typography :is(.admonition, details:not(.g-diagram__desc)) {
  margin-inline: 0;
  border-color: color-mix(in srgb, var(--g-adm-accent) var(--g-adm-edge), var(--guide-bg));
  background-color: color-mix(in srgb, var(--g-adm-accent) var(--g-adm-tint), var(--guide-bg));
}

/* The title is a line of its own; shadcn runs it into the first paragraph. */
article .typography .admonition > .admonition-title {
  display: block;
  margin: 0 0 0.45rem !important;
}

article .typography .admonition > .admonition-title + p {
  display: block;
}

/* Attack scenarios read as the risk: a stronger tint, and an edge between the risk and the border. */
article .typography :is(.admonition, details).attack {
  border-color: color-mix(in srgb, var(--guide-risk) 55%, var(--guide-border));
  background-color: color-mix(in srgb, var(--guide-risk-surface) 55%, var(--guide-bg));
}

/* ---------------------------------------------------------------- Collapsible blocks */

/* A ??? block is an admonition that folds: the type's edge and tint, the title as its summary, and shadcn's chevron
   at the end of the title. The diagram's text description is a details element too and keeps its own look
   (components-b.css). shadcn zeroes the top margin of every details after the first with !important, so these
   restate theirs the same way. */
article .typography details:not(.g-diagram__desc) {
  margin-top: 1.25rem !important;
  padding: 0 1rem;
  border-width: 1px;
  border-style: solid;
  border-radius: var(--g-radius-card);
}

article .typography > details:not(.g-diagram__desc, :first-of-type) {
  margin-top: 0.9rem !important;
}

article .typography details[open]:not(.g-diagram__desc) {
  padding-bottom: 0.75rem;
}

article .typography > details[open]:not(.g-diagram__desc) {
  margin-bottom: 1rem !important;
}

/* The summary spans the card, so the whole title row opens it. Its corners follow the card's, so the focus ring
   does not stick out past them. */
article .typography details:not(.g-diagram__desc) > summary {
  margin: 0 -1rem;
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  border-radius: calc(var(--g-radius-card) - 1px);
  font-weight: 700;
}

article .typography details[open]:not(.g-diagram__desc) > summary {
  padding-bottom: 0.45rem;
}

@media (hover: hover) and (pointer: fine) {
  article .typography details:not(.g-diagram__desc) > summary:hover {
    text-decoration: none;
  }
}

/* The card's padding sets the spacing inside an open block, not shadcn's paragraph padding or its first and last
   children's margins. A list keeps the spacing shadcn gives a list in an admonition. */
article .typography details[open]:not(.g-diagram__desc) > p {
  padding-block: 0;
}

article .typography details[open]:not(.g-diagram__desc) > ul {
  margin-block: 0.25rem;
}

article .typography details[open]:not(.g-diagram__desc) > summary + * {
  margin-top: 0 !important;
}

article .typography details[open]:not(.g-diagram__desc) > :last-child {
  margin-bottom: 0 !important;
}

/* ---------------------------------------------------------------- Content tabs */

/* shadcn's tab strip hides its radio buttons with display: none, which takes the tabs out of the tab order. The
   radios stay focusable here, out of sight, so Tab reaches the selected tab and the arrow keys switch tabs; the
   label of the focused radio shows the focus ring. */
.typography .tabbed-set {
  position: relative;
  margin: 1.5rem 0;
}

article .tabbed-set > input[type="radio"] {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

article .tabbed-set > input[type="radio"]:focus-visible + label {
  outline: var(--g-focus-width) solid var(--guide-focus);
  outline-offset: -2px;
  border-radius: var(--g-radius-sm);
}

/* On a phone the labels of a tab set often take two rows, where an underline under the selected label would float
   between the rows, away from the panel it opens. There the labels are pills and the selected one is filled. */
@container g-content (max-width: 37.5rem) {
  article .typography .tabbed-set {
    gap: 0.5rem 0.375rem;
  }

  article .typography .tabbed-set > label {
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--guide-border);
    border-radius: var(--g-radius-pill);
  }

  article .typography .tabbed-set > input[type="radio"]:checked + label {
    color: var(--guide-accent-fg);
    border-color: var(--guide-accent);
    background: var(--guide-accent);
  }

  article .typography .tabbed-set > input[type="radio"]:focus-visible + label {
    outline-offset: 2px;
    border-radius: var(--g-radius-pill);
  }
}

/* ---------------------------------------------------------------- Task lists */

/* A checklist item shows its checkbox where its bullet would be, and pymdownx's indicator, stacked on the box, draws
   the tick. A reader ticks the box from anywhere on its row (guide.js): the box's 24px label, the text, and half of
   the gap on each side, which the row's ::before claims without moving the text. Links keep working as links. The
   box's edge is darker than the theme's so it meets 3:1, and a ticked row's text turns secondary. */
.typography .task-list-item {
  position: relative;
  z-index: 0;
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.typography .task-list-item::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -0.25rem 0 -0.25rem -1.75rem;
}

.typography .task-list-control {
  position: absolute;
  top: calc(0.75em - 0.75rem);
  left: -1.75rem;
  display: grid;
  padding: 0.25rem;
  cursor: pointer;
}

.typography .task-list-control > :is(input[type="checkbox"], .task-list-indicator) {
  grid-area: 1 / 1;
}

.typography .task-list-control > input[type="checkbox"] {
  display: block;
  margin: 0;
  cursor: pointer;
  border-color: color-mix(in srgb, var(--guide-muted) 75%, var(--guide-bg));
  transition: transform 120ms var(--g-tick-ease);
}

.typography .task-list-control > input[type="checkbox"]:checked {
  border-color: var(--guide-accent);
  background: var(--guide-accent);
}

.typography .task-list-control > input[type="checkbox"]:focus-visible {
  outline: var(--g-focus-width) solid var(--guide-focus);
  outline-offset: 2px;
}

/* The tick, Lucide's check drawn 2px wide, hidden behind a clip that a tick wipes away left to right. */
.typography .task-list-indicator {
  pointer-events: none;
  background: var(--guide-accent-fg);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 100% no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 100% no-repeat;
  clip-path: inset(0 100% 0 0);
  opacity: 0;
}

.typography .task-list-control > input:checked + .task-list-indicator {
  clip-path: inset(0);
  opacity: 1;
}

/* Windows High Contrast repaints every background to Canvas, which would erase the masked tick. It keeps its
   CanvasText fill instead, inside the box's CanvasText edge. */
@media (forced-colors: active) {
  .typography .task-list-indicator {
    forced-color-adjust: none;
    background: CanvasText;
  }
}

.typography .task-list-item:has(> .task-list-control > input:checked) {
  color: var(--guide-muted);
}

.typography .task-list-item:has(> .task-list-control > input:checked) > :is(a, code) {
  color: inherit;
  text-decoration-color: currentColor;
}

/* Motion plays only for a tick made with a pointer, which guide.js marks with data-motion: the box fills and the
   tick draws in, then fades out faster than it came. A key press, a reset, and the ticks restored on load change
   at once. Presses take the strong ease-out of the home cards; the tick's stroke draws on easings.net's gentler
   ease-out cubic, so the eye can follow it. */
.typography :is(.task-list, .g-checklist) {
  --g-tick-ease: cubic-bezier(0.23, 1, 0.32, 1);
  --g-draw-ease: cubic-bezier(0.33, 1, 0.68, 1);
}

.typography .task-list-item[data-motion] {
  transition: color 150ms ease;
}

.typography .task-list-item[data-motion] > .task-list-control > input[type="checkbox"] {
  transition: transform 120ms var(--g-tick-ease), background-color 150ms ease;
}

.typography .task-list-item[data-motion] > .task-list-control > .task-list-indicator {
  transition: opacity 100ms ease, clip-path 0s linear 100ms;
}

.typography .task-list-item[data-motion] > .task-list-control > input:checked + .task-list-indicator {
  transition: clip-path 180ms var(--g-draw-ease);
}

/* A press anywhere on the row, other than on a link, sinks the box a little. Space on a focused box does not. */
@media (prefers-reduced-motion: no-preference) {
  .typography .task-list-item:active:not(:has(a:active, .task-list-item:active)) > .task-list-control > input[type="checkbox"]:not(:focus-visible) {
    transform: scale(0.94);
  }
}

/* A fine pointer over a row, other than over a link, darkens an empty box's edge. Touch screens keep a hover after
   a tap, so they get none. */
@media (hover: hover) and (pointer: fine) {
  .typography .task-list-item:hover:not(:has(a:hover, .task-list-item:hover)) > .task-list-control > input[type="checkbox"]:not(:checked) {
    border-color: var(--guide-fg);
  }
}

/* The progress line under a page's last checklist (guide.js): a count that screen readers hear after each tick, and
   a small button that resets the page's ticks and then offers to restore them. It sits 8px under the list, closer
   than the theme's 24px between blocks, so it reads as the list's own line. It keeps the button's height while the
   button is hidden, so the first tick and the last untick move nothing below it. */
article .typography div.g-checklist {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
  min-height: 1.75rem;
  margin: -1rem 0 1.5rem;
  color: var(--guide-muted);
  font-size: var(--g-text-sm);
  font-variant-numeric: tabular-nums;
}

.typography .g-checklist__status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
}

.typography .g-checklist:has(> .g-checklist__reset:not([hidden])) > .g-checklist__status::after {
  content: "\00b7" / "";
}

/* The button is a small shadcn ghost button; only a fine pointer's hover fills it, so a tap leaves no fill behind. */
article .typography button.g-checklist__reset {
  height: 1.75rem;
  margin-inline: -0.25rem -0.5rem;
  padding-inline: 0.5rem;
  border-radius: var(--g-radius-sm);
  color: var(--guide-fg);
  font-size: inherit;
  translate: none;
  transition: transform 160ms var(--g-tick-ease);
}

article .typography button.g-checklist__reset[hidden] {
  display: none;
}

article .typography button.g-checklist__reset:hover {
  background: none;
}

article .typography button.g-checklist__reset:active {
  translate: none;
}

@media (prefers-reduced-motion: no-preference) {
  article .typography button.g-checklist__reset:active {
    transform: scale(0.97);
  }
}

article .typography button.g-checklist__reset:focus-visible {
  outline: var(--g-focus-width) solid var(--guide-focus);
  outline-offset: 2px;
  box-shadow: none;
}

@media (hover: hover) and (pointer: fine) {
  article .typography button.g-checklist__reset:hover {
    background: var(--guide-surface);
  }
}

/* ---------------------------------------------------------------- Motion */

@media (prefers-reduced-motion: reduce) {
  *,
  ::before,
  ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
