/* Small orange labels: the brand orange is a touch under 4.5:1 at label
   sizes, so text uses a deeper step in light mode and a lighter one in dark. */
:root {
  --orange-text: hsl(19, 62%, 41%);
}
html.dark {
  --orange-text: hsl(19, 70%, 62%);
}

/* ============================================================
   Content pages: posts, hubs, the guides library and the blog index.
   Loaded after main.css by every template under src/blog/ and
   src/guides/, and only there. Tokens come from main.css.
   ============================================================ */

/* ---------------------------------------------------------------------------
   Articles: narrow container, post prose, post CTA
   ------------------------------------------------------------------------- */

.container-narrow {
  max-width: 760px;
}

/* Single post --------------------------------------------------------------- */

.post {
  padding: 3rem 0 5rem;
}

.post-title {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  line-height: 1.15;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.post-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 3rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.post-meta-sep {
  color: var(--border-color);
}

/* Prose: rendered Markdown body */

.prose {
  font-size: 1.1rem;
  line-height: 1.75;
  color: var(--text-primary);
}

.prose h2 {
  font-size: 1.6rem;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.prose h2::after {
  content: "";
  display: block;
  width: 3.25rem;
  height: 0.5rem;
  margin-top: 0.45rem;
  background: url("/assets/brush/underline-1.png") left center / 100% 100% no-repeat;
}

html.dark .prose h2::after {
  background-image: url("/assets/brush/underline-1-dark.png");
}

/* Lead: the opening paragraph of the article */
.prose-lead > p:first-child {
  font-size: 1.25rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.prose h3 {
  font-size: 1.3rem;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.prose h4 {
  font-size: 1.1rem;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.prose p {
  margin-bottom: 1.25rem;
  color: var(--text-primary);
}

.prose a {
  color: var(--primary-orange);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose a:hover {
  color: var(--primary-orange-light);
}

.prose a[href^="http"]::after {
  content: "\2197";
  font-size: 0.7em;
  margin-left: 0.15em;
  vertical-align: super;
}

.prose ul,
.prose ol {
  margin: 0 0 1.25rem 0;
  padding-left: 1.5rem;
}

.prose li {
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.prose blockquote {
  margin: 1.5rem 0;
  padding: 0.5rem 1.25rem;
  border-left: 3px solid var(--primary-orange);
  color: var(--text-secondary);
  font-style: italic;
}

.prose blockquote p {
  margin: 0;
  color: var(--text-secondary);
}

.prose code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9em;
  background: hsl(19, 60%, 96%);
  padding: 0.15em 0.35em;
  border-radius: 0.25rem;
  color: var(--text-primary);
}

.prose pre {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--dark-blue);
  border-radius: 0.5rem;
  overflow-x: auto;
}

.prose pre code {
  background: none;
  padding: 0;
  color: #f1f1f1;
  font-size: 0.9rem;
  line-height: 1.5;
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 1.5rem 0;
}

/* Figures: standalone image + italic caption, built by enhancePostHtml() */
.prose figure {
  margin: 2.25rem 0;
}

/* <picture> wraps the img whenever a WebP derivative exists; keep it out of
   the inline formatting context so it does not add a baseline gap. */
.prose figure picture {
  display: block;
}

/* Charts ship a light and a dark rendering (see darkVariant() in
   build/markdown.mjs); show the one that matches the theme. The theme is the
   .dark class on <html>, not prefers-color-scheme, so this has to be a CSS
   swap rather than a media attribute on a <source>. */
.prose figure .fig-dark,
.pic .fig-dark {
  display: none;
}

html.dark .prose figure .fig-light,
html.dark .pic .fig-light {
  display: none;
}

html.dark .prose figure .fig-dark,
html.dark .pic .fig-dark {
  display: block;
}

.prose figure img {
  margin: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  background: var(--background);
}

.prose figcaption {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 0.75rem;
  line-height: 1.5;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2.5rem 0;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.prose th,
.prose td {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-color);
  text-align: left;
}

.prose th {
    font-weight: 600;
  color: var(--text-primary);
}

/* On a phone, tighten the cells so a four-column table fits, and let a wider
   one scroll inside its own box instead of pushing the page sideways. */
@media (max-width: 640px) {
  .prose table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.82rem;
  }

  .prose th,
  .prose td {
    padding: 0.45rem 0.5rem;
  }
}

/* Post extras: progress bar, stat strip, pull quote, footnote box ----------- */

.post-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: var(--primary-orange);
  z-index: 1000;
}

.post-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 2.25rem 0;
}

/* Four numbers, not three: without this the fourth stat orphans onto a row of
   its own at full width. */
.post-stats-4 {
  grid-template-columns: repeat(4, 1fr);
}

.post-stat {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem 1rem;
  text-align: center;
}

.post-stat-value {
  display: block;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--primary-orange);
  line-height: 1.2;
}

.post-stat-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.post-pullquote {
  margin: 2.5rem auto;
  max-width: 34rem;
  text-align: center;
  font-size: 1.35rem;
  line-height: 1.5;
  font-weight: 600;
  color: var(--text-primary);
}

.post-pullquote::before {
  content: "";
  display: block;
  width: 2.5rem;
  height: 3px;
  background: var(--primary-orange);
  border-radius: 2px;
  margin: 0 auto 1rem;
}

.post-footnote {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.75rem 2rem;
  margin-top: 3rem;
}

.post-footnote h2 {
  font-size: 1.15rem;
  margin-top: 0;
}

.post-footnote h2::after {
  display: none;
}

.post-footnote p {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

.post-footnote p:last-child {
  margin-bottom: 0;
}

@media (max-width: 700px) {
  .post-stats {
    grid-template-columns: 1fr;
  }

  /* Four short numbers still pair up on a phone; stacking all four costs most
     of a screen. */
  .post-stats-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Post CTA ------------------------------------------------------------------ */

/* Table of contents, built from the post's h2 ids by enhancePostHtml() */

.post-toc {
  margin: 0 0 2.5rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
}

.post-toc-heading {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 0.75rem;
}

.post-toc ol {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.post-toc a {
  color: var(--text-primary);
  text-decoration: none;
}

.post-toc a:hover {
  color: var(--primary-orange);
  text-decoration: underline;
}

/* Section permalink: hidden until the heading is hovered or the link itself
   is focused, so it never competes with the heading text. */
.heading-anchor {
  margin-left: 0.4rem;
  color: var(--primary-orange);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.heading-anchor:focus {
  opacity: 1;
}

/* Headings sit clear of the top edge when reached through a TOC link. */
.prose h2,
.prose h3 {
  scroll-margin-top: 5rem;
}

.post-updated {
  font-style: italic;
}

/* CJK has no italic: the browser would fake a slant. */
:lang(ja) .post-updated {
  font-style: normal;
}

/* "Keep reading": the other posts, at the end of the article */

.post-related {
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

.post-related-heading {
  font-size: 1.15rem;
  margin: 0 0 1.25rem;
  color: var(--text-primary);
}

.post-related ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1rem;
}

.post-related a {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.post-related a:hover {
  border-color: var(--primary-orange);
}

.post-related-thumb {
  flex: 0 0 5.25rem;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: 0.35rem;
  background: var(--surface);
}

.post-related-thumb picture,
.post-related-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.post-related-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.post-related-title {
  font-size: 0.98rem;
  line-height: 1.35;
  color: var(--text-primary);
}

.post-related-meta {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.post-cta {
  margin: 3rem 0;
  padding: 2.5rem 2rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
}

.post-cta h2 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}

.post-cta p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.post-cta .btn {
  font-size: 1.05rem;
  padding: 0.85rem 2rem;
}

html.dark .prose code {
  background: var(--surface-sunken);
}


/* ---------------------------------------------------------------------------
   Brand rules for everything below (docs/content-system.md, "Brand"):
   - surfaces are var(--surface) with a 1px border, as on the About page:
     a plain card that covers the dot grid, no tinted fill
   - orange is the only accent, and only in small things: a kicker, a brush
     underline, a hover border, an arrow
   - a language shows as painted dabs (public/assets/brush/dabs-*.png),
     never as a coloured background, border or text
   ------------------------------------------------------------------------- */

/* Brush underline under a heading: three strokes so neighbours differ. */
.brush-heading {
  display: inline-block;
  padding-bottom: 0.6rem;
  background: url("/assets/brush/underline-1.png") left bottom / 100% 0.62rem no-repeat;
}

.brush-heading.brush-2 { background-image: url("/assets/brush/underline-2.png"); }
.brush-heading.brush-3 { background-image: url("/assets/brush/underline-3.png"); }
html.dark .brush-heading { background-image: url("/assets/brush/underline-1-dark.png"); }
html.dark .brush-heading.brush-2 { background-image: url("/assets/brush/underline-2-dark.png"); }
html.dark .brush-heading.brush-3 { background-image: url("/assets/brush/underline-3-dark.png"); }

/* Language dabs, sized by height; the PNG carries the width. */
.dabs {
  display: inline-block;
  height: 1.05em;
  width: auto;
  vertical-align: -0.2em;
  flex-shrink: 0;
}

/* Breadcrumbs (posts and hubs) */
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  font-size: 0.9rem;
}

.breadcrumbs li + li::before {
  content: "›";
  margin-right: 0.4rem;
  color: var(--text-muted);
}

.breadcrumbs a {
  color: var(--text-secondary);
}

.breadcrumbs a:hover {
  color: var(--primary-orange);
}

.breadcrumbs .dabs {
  margin-right: 0.35rem;
}

/* ---------------------------------------------------------------------------
   Cards: one post. Blog index, guides library, hubs.
   ------------------------------------------------------------------------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: calc(var(--border-radius) * 1.25);
  overflow: hidden;
  color: inherit;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  text-decoration: none;
  border-color: var(--primary-orange);
  transform: translateY(-2px);
  box-shadow: var(--box-shadow);
}

.card:focus-visible {
  outline: 2px solid var(--primary-orange);
  outline-offset: 3px;
}

.card[hidden] {
  display: none;
}

.card .pic {
  display: block;
  aspect-ratio: 1200 / 630;
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);
}

.card .pic picture,
.card .pic img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: 1;
  padding: 1.15rem 1.35rem 1.25rem;
}

.card-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--orange-text);
}

.card-title {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.38;
  color: var(--text-primary);
}

/* The title gets painted on hover: the brush stroke grows from the left. */
.card-title span {
  background: url("/assets/brush/underline-2.png") left 100% / 0% 0.5em no-repeat;
  padding-bottom: 0.36em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-size 0.35s ease;
}

html.dark .card-title span {
  background-image: url("/assets/brush/underline-2-dark.png");
}

.card:hover .card-title span,
.card:focus-visible .card-title span {
  background-size: 100% 0.5em;
}

.card-excerpt {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.55;
  font-size: 0.95rem;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  margin-top: auto;
  padding-top: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.card-meta .sep {
  color: var(--border-strong);
}

.card-arrow {
  margin-left: auto;
  color: var(--primary-orange);
  font-weight: 700;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.card:hover .card-arrow,
.card:focus-visible .card-arrow {
  opacity: 1;
  transform: none;
}

.draft-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary-orange);
  border: 1px solid var(--primary-orange);
  padding: 0.05em 0.5em;
  border-radius: 999px;
}

/* Hub rows: wide card, cover left, text right. */
.card-stack {
  display: grid;
  gap: 1.25rem;
}

.card-wide {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
}

.card-wide .pic {
  border-bottom: 0;
  border-right: 1px solid var(--border-color);
}

.card-wide .card-body {
  justify-content: center;
  padding: 1.25rem 1.75rem;
}

.card-wide .card-meta {
  margin-top: 0.25rem;
}

/* ---------------------------------------------------------------------------
   Library pages: /guides.html and /blog.html
   ------------------------------------------------------------------------- */

.library {
  padding: 4rem 0 5rem;
}

.library-header {
  max-width: 46rem;
  margin-bottom: 2rem;
}

.library-header h1 {
  margin-bottom: 0.5rem;
}

.library-lead {
  color: var(--text-secondary);
  font-size: 1.15rem;
  line-height: 1.55;
  margin-bottom: 0.75rem;
}

.library-crosslink a {
  font-weight: 600;
}

.library-crosslink-end {
  margin-top: 3.5rem;
}

/* Jump links to each language section */
.lang-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.lang-jump a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.95rem 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 0.92rem;
  font-weight: 600;
  transition: border-color 0.2s ease;
}

.lang-jump a:hover {
  text-decoration: none;
  border-color: var(--primary-orange);
}

.lang-jump .count {
  color: var(--text-muted);
  font-weight: 500;
}

.lang-section {
  margin-top: 3.5rem;
  scroll-margin-top: 5rem;
}

.lang-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

.lang-section-head h2 {
  margin: 0;
  font-size: 1.55rem;
  color: var(--text-primary);
}

.lang-section-head .dabs {
  height: 1.3rem;
}

.lang-section-head .hub-open {
  margin-left: auto;
}

.lang-section-lead {
  max-width: 46rem;
  margin: 0.25rem 0 1.4rem;
  color: var(--text-secondary);
}

.hub-open {
  font-weight: 600;
  color: var(--primary-orange);
  white-space: nowrap;
}

/* Blog index type filter */
.type-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.75rem;
}

.type-chip {
  font: inherit;
  font-size: 0.88rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.type-chip:hover {
  border-color: var(--primary-orange);
}

.type-chip[aria-pressed="true"] {
  border-color: var(--orange-text);
  color: var(--orange-text);
  font-weight: 600;
}

/* ---------------------------------------------------------------------------
   Hub page
   ------------------------------------------------------------------------- */

.hub {
  padding: 3rem 0 5rem;
}

.hub-header {
  max-width: 46rem;
  margin-bottom: 1rem;
}

.hub-kicker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--orange-text);
}

.hub-kicker .dabs {
  height: 1.15rem;
}

.hub-header h1 {
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  line-height: 1.2;
  margin-bottom: 1rem;
}

.hub-section {
  margin-top: 2.75rem;
  scroll-margin-top: 5rem;
}

.hub-section h2 {
  font-size: 1.3rem;
  margin-bottom: 1.1rem;
  color: var(--text-primary);
}

.hub-outro {
  max-width: 46rem;
  margin-top: 3.5rem;
}

/* "Part of" link at the end of a guide */
.post-hub-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 3rem;
  padding: 1rem 1.3rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: calc(var(--border-radius) * 1.25);
  color: var(--text-primary);
  transition: border-color 0.2s ease;
}

.post-hub-link:hover {
  text-decoration: none;
  border-color: var(--primary-orange);
}

.post-hub-link .dabs {
  height: 1.25rem;
}

.post-hub-kicker {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.post-hub-title {
  font-weight: 600;
}

/* Post meta: type as an orange kicker */
.post-meta .type-kicker {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--orange-text);
}

/* ---------------------------------------------------------------------------
   Markdown components (build/markdown.mjs): ```answer, ```example, ```letter
   ------------------------------------------------------------------------- */

.prose .answer-box {
  margin: 1.5rem 0 2rem;
  padding: 1.1rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--primary-orange);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.prose .answer-box > :last-child {
  margin-bottom: 0;
}

.prose figure.ex {
  margin: 1.75rem 0;
  padding: 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: calc(var(--border-radius) * 1.25);
  display: grid;
  gap: 0.7rem;
}

.ex-row {
  display: grid;
  grid-template-columns: 2.6rem 1fr;
  gap: 0.75rem;
  align-items: baseline;
}

.ex-lang {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.prose .ex-text {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--text-primary);
}

.ex-target .ex-text {
  font-size: 1.15rem;
}

.prose .ex-reading {
  margin: 0.15rem 0 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
  font-style: italic;
}

.ex-back .ex-text {
  color: var(--text-secondary);
}

.ex-text strong {
  color: var(--primary-orange);
}

/* The verdict: a small status dot, as in the app, and a muted label. */
.ex-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  justify-self: start;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.ex-label::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--border-strong);
}

.ex-good .ex-label::before { background: hsl(152, 56%, 40%); }
.ex-bad .ex-label::before  { background: var(--severity-critical); }
.ex-warn .ex-label::before { background: var(--severity-major); }

.prose figure.ex .ex-note {
  margin: 0.2rem 0 0;
  padding-top: 0.7rem;
  border-top: 1px dashed var(--border-color);
  text-align: left;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

/* ```letter: a sample letter set as a sheet of paper */
.prose .letter {
  margin: 1.75rem 0;
  padding: 2rem 2.25rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--box-shadow);
  font-size: 0.98rem;
}

.prose .letter p {
  margin-bottom: 0.9rem;
}

.prose .letter > :last-child {
  margin-bottom: 0;
}

@media (max-width: 760px) {
  .card-wide {
    grid-template-columns: 1fr;
  }
  .card-wide .pic {
    border-right: 0;
    border-bottom: 1px solid var(--border-color);
  }
  .lang-section-head .hub-open {
    margin-left: 0;
    width: 100%;
  }
}

@media (max-width: 640px) {
  .prose .letter {
    padding: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .card-title span,
  .card-arrow {
    transition: none;
  }

  .card:hover {
    transform: none;
  }
}

.lang-jump a:focus-visible,
.type-chip:focus-visible,
.post-hub-link:focus-visible,
.hub-open:focus-visible,
.breadcrumbs a:focus-visible {
  outline: 2px solid var(--primary-orange);
  outline-offset: 2px;
}

/* Languages with one or two guides share a row on /guides.html. */
.lang-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0 1.5rem;
  align-items: start;
}

/* /guides.html from tablet width up: every card the same width, two
   columns, then three. A language with more guides than that becomes a
   carousel (below). */
@media (min-width: 640px) {
  .library .lang-section .card-grid,
  .lang-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  .library .lang-section .card-grid,
  .lang-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Arrows for the phone deck and the desktop carousel. The script adds
   them; each layout shows and places them in its media query below. */
.deck-wrap {
  position: relative;
}

.deck-arrow {
  position: absolute;
  z-index: 20;
  display: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  line-height: 0;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--surface);
  color: var(--orange-text);
  box-shadow: 0 4px 12px -4px rgba(36, 40, 70, 0.25);
  cursor: pointer;
}

.deck-arrow svg {
  display: block;
}

.deck-prev svg {
  transform: scaleX(-1);
}

.deck-arrow:hover {
  border-color: var(--primary-orange);
}

.deck-arrow:focus-visible {
  outline: 2px solid var(--primary-orange);
  outline-offset: 2px;
}

/* The script hides an arrow at either end of the row. */
.deck-arrow[hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------------------
   /guides.html from tablet width up: a language with more guides than
   columns scrolls sideways. The row bleeds to the screen edges, so the cards
   outside the focus peek in faded beside the three (or two) in focus.
   ------------------------------------------------------------------------- */

@media (min-width: 640px) {
  .library {
    overflow-x: clip; /* the bleed is a scrollbar's width wider than the page */
  }

  .deck-wrap {
    --cols: 2;
    container-type: inline-size;
  }

  .library .lang-section .card-grid.carousel {
    position: relative; /* offsetParent for the script's measurements */
    display: flex;
    gap: 1.5rem;
    /* cqw is the wrapper's width, the page column; % would mean the
       scroller's own width inside scroll-padding. */
    margin-inline: calc(50cqw - 50vw);
    padding: 0.5rem calc(50vw - 50cqw) 1rem;
    scroll-padding-inline: calc(50vw - 50cqw);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .library .lang-section .card-grid.carousel::-webkit-scrollbar {
    display: none;
  }

  .library .lang-section .card-grid.carousel > .card {
    flex: 0 0 calc((100% - (var(--cols) - 1) * 1.5rem) / var(--cols));
    scroll-snap-align: start;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
  }

  /* Opacity only: Chromium snaps to a card's transformed box, so a card
     scaling back up as it comes into focus would pull the row off its
     snap point. */
  .library .lang-section .card-grid.carousel > .card.is-out,
  .library .lang-section .card-grid.carousel > .card.is-out:hover {
    opacity: 0.4;
    transform: none;
    border-color: var(--border-color);
    box-shadow: none;
  }

  /* On the edges of the focus, level with the middle of the covers. */
  .deck-wrap.is-carousel .deck-arrow {
    display: grid;
    top: calc(0.5rem + 1px + ((100cqw - (var(--cols) - 1) * 1.5rem) / var(--cols) - 2px) * 0.2625 - 1.25rem);
  }

  .deck-wrap.is-carousel .deck-prev {
    left: -1.25rem;
  }

  .deck-wrap.is-carousel .deck-next {
    right: -1.25rem;
  }
}

@media (min-width: 1100px) {
  .deck-wrap {
    --cols: 3;
  }
}

/* ---------------------------------------------------------------------------
   /guides.html on phones: one sideways row per language, the next card
   peeking in at the edge, and the language chips pinned under the header.
   Plain scroll-snap, so touch, trackpad and keyboard all work without JS.
   ------------------------------------------------------------------------- */

@media (max-width: 639px) {
  .library {
    padding-top: 2.5rem;
  }

  .lang-jump-bar {
    position: sticky;
    top: 57px; /* the header's height at this width */
    z-index: 50;
    margin: 0 -24px;
    background: var(--background);
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
  }

  .lang-jump-bar.is-stuck {
    border-bottom-color: var(--border-color);
  }

  .lang-jump {
    position: relative; /* offsetParent for the chip scroll in the script */
    flex-wrap: nowrap;
    gap: 0.5rem;
    margin: 0;
    padding: 0.6rem 24px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .lang-jump::-webkit-scrollbar {
    display: none;
  }

  .lang-jump a {
    white-space: nowrap;
    padding: 0.35rem 0.8rem 0.35rem 0.65rem;
    font-size: 0.88rem;
  }

  .lang-jump a[aria-current="true"] {
    border-color: var(--primary-orange);
    color: var(--orange-text);
  }

  .lang-section {
    margin-top: 2.5rem;
    scroll-margin-top: 7.5rem; /* header + chip bar */
  }

  .lang-section-lead {
    margin-bottom: 1rem;
    font-size: 0.95rem;
  }

  .library .lang-section .card-grid {
    display: flex;
    gap: 0.9rem;
    margin: 0 -24px;
    padding: 0.25rem 24px 0.75rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 24px;
    scrollbar-width: none;
  }

  .library .lang-section .card-grid::-webkit-scrollbar {
    display: none;
  }

  .library .lang-section .card-grid > .card {
    flex: 0 0 82%;
    scroll-snap-align: start;
  }

  /* With the script: a deck. The middle card sits on top at full size; its
     neighbours tuck in behind it, smaller. The script sets --d, the card's
     distance from the middle in card widths (-1 left, 0 centred, 1 right). */
  .library .lang-section .card-grid.deck {
    position: relative; /* offsetParent for the script's measurements */
    gap: 0;
    padding: 0.75rem 14vw 1.5rem;
    scroll-padding-inline: 0;
  }

  .library .lang-section .card-grid.deck {
    /* Middle of a cover, from the top of its card: the 1px border plus half
       of a 1200:630 image inside a 72vw card. The side cards shrink around
       this point, so all three covers share one centre line and the arrows
       can sit on it whatever the card heights. */
    --deck-cover-mid: calc(1px + (72vw - 2px) * 0.2625);
  }

  .library .lang-section .card-grid.deck > .card {
    flex-basis: 72vw;
    scroll-snap-align: center;
    transform-origin: 50% var(--deck-cover-mid);
    --a: max(var(--d, 0), calc(var(--d, 0) * -1));
    transform:
      translateX(calc(var(--d, 0) * -30%))
      scale(calc(1 - min(var(--a), 2) * 0.12));
    transition: border-color 0.2s ease;
    will-change: transform;
  }

  .library .lang-section .card-grid.deck > .card.is-centre {
    box-shadow: 0 12px 28px -12px rgba(36, 40, 70, 0.28);
  }

  html.dark .library .lang-section .card-grid.deck > .card.is-centre {
    box-shadow: 0 12px 28px -10px rgba(0, 0, 0, 0.6);
  }

  /* Swipe hint and tap target: round buttons over the side cards, level
     with the covers. */
  .deck-arrow {
    display: grid;
    /* Deck's top padding + the cover's middle, less half the button. */
    top: calc(0.75rem + 1px + (72vw - 2px) * 0.2625 - 1.25rem);
  }

  /* Centred in the 14vw strip of side card that peeks out past the middle
     card. The wrapper starts 24px in from the screen edge (the container's
     padding, which the deck's -24px margin undoes). */
  .deck-prev {
    left: calc(7vw - 1.25rem - 24px);
  }

  .deck-next {
    right: calc(7vw - 1.25rem - 24px);
  }

  /* Side cards fade with their distance, so the middle one reads first. */
  .library .lang-section .card-grid.deck > .card .card-body,
  .library .lang-section .card-grid.deck > .card .pic {
    opacity: calc(1 - min(var(--a), 1) * 0.6);
  }

  .library .lang-section .card-grid.deck > .card:hover {
    transform:
      translateX(calc(var(--d, 0) * -30%))
      scale(calc(1 - min(var(--a), 2) * 0.12));
  }

  /* The cover and the title carry the card here; the summary would make
     each one a screen tall. */
  .library .lang-section .card-excerpt {
    display: none;
  }

  .library .lang-section .card-body {
    padding: 1rem 1.1rem 1.1rem;
  }

  .library .lang-section .card-title {
    font-size: 1.05rem;
  }

  .lang-row {
    display: block;
  }
}
