/* ==========================================================================
   Blog — index, archive and post
   Loaded only on blog routes. Built on the same tokens as the portfolio, so
   the reading experience and the marketing pages share one system.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Shells
   -------------------------------------------------------------------------- */

.sd-blogmain__inner,
.sd-postmain__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-9) var(--gutter-inline) var(--space-10);
}

/* Measure cap: 65–75 characters for anything read as prose. The ch unit is
   the width of "0", which is wider than the average glyph, so these values
   measure ~10% narrower than they read. */
.sd-postmain__inner {
  max-width: 82ch;
}

.sd-blogmain__head {
  display: grid;
  gap: var(--space-4);
  padding-bottom: var(--space-7);
  border-bottom: 1px solid var(--border-hairline);
  margin-bottom: var(--space-7);
}

/* --------------------------------------------------------------------------
   2. Breadcrumbs
   -------------------------------------------------------------------------- */

.sd-crumbs {
  margin-bottom: var(--space-6);
}

.sd-crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--text-muted);
}

.sd-crumbs li + li::before {
  content: "/";
  margin-right: var(--space-2);
  opacity: .5;
}

.sd-crumbs a {
  color: var(--text-muted);
  text-decoration: none;
}

.sd-crumbs a:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.sd-crumbs [aria-current="page"] {
  color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   3. Post listing
   -------------------------------------------------------------------------- */

.sd-postlist {
  display: grid;
  gap: var(--space-7);
}

.sd-postcard {
  display: grid;
  gap: var(--space-3);
  padding-bottom: var(--space-7);
  border-bottom: 1px solid var(--border-hairline);
}

.sd-postcard:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.sd-postcard__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--weight-regular);
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.1;
  letter-spacing: var(--tracking-display);
}

.sd-postcard__title a {
  color: var(--text-primary);
  text-decoration: none;
}

.sd-postcard__title a:hover {
  color: var(--text-highlight);
}

.sd-postcard__desc {
  margin: 0;
  max-width: 68ch;
  font-size: 17px;
  line-height: 1.65;
  color: var(--text-secondary);
  text-wrap: pretty;
}

.sd-postcard__meta,
.sd-post__meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: 13px;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   4. Tags
   -------------------------------------------------------------------------- */

.sd-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.sd-tags a {
  display: inline-block;
  font-size: var(--text-xs);
  letter-spacing: .06em;
  text-transform: lowercase;
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid rgba(200, 228, 255, .20);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  transition: color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.sd-tags a:hover {
  color: var(--text-primary);
  border-color: var(--border-brand);
}

.sd-tags--post {
  margin-top: var(--space-7);
}

/* --------------------------------------------------------------------------
   5. Post header and table of contents
   -------------------------------------------------------------------------- */

.sd-post__head {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-7);
}

.sd-post__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--weight-regular);
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1.02;
  letter-spacing: var(--tracking-display);
  color: var(--text-primary);
  text-wrap: balance;
}

.sd-toc {
  margin: 0 0 var(--space-8);
  padding: var(--space-5) var(--space-6);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.sd-toc__title {
  margin: 0 0 var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sd-toc ol {
  margin: 0;
  padding: 0 0 0 1.2em;
  display: grid;
  gap: var(--space-2);
  font-size: 15px;
}

.sd-toc li {
  color: var(--text-muted);
}

.sd-toc a {
  color: var(--text-secondary);
  text-decoration: none;
}

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

/* --------------------------------------------------------------------------
   6. Article body
   -------------------------------------------------------------------------- */

.sd-post {
  font-size: 19px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.sd-post > * {
  max-width: 76ch;
}

.sd-post p {
  margin: 0 0 var(--space-5);
  text-wrap: pretty;
}

.sd-post__lede {
  font-size: 21px;
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: var(--space-6);
}

/* Headings belong to the text that follows: generous above, tight below. */
.sd-post h2 {
  margin: var(--space-9) 0 var(--space-4);
  font-family: var(--font-display);
  font-weight: var(--weight-regular);
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.15;
  letter-spacing: var(--tracking-display);
  color: var(--text-primary);
  scroll-margin-top: 90px;
}

.sd-post h3 {
  margin: var(--space-7) 0 var(--space-3);
  font-size: 20px;
  font-weight: var(--weight-semibold);
  line-height: 1.3;
  color: var(--text-primary);
  scroll-margin-top: 90px;
}

.sd-post ul,
.sd-post ol {
  margin: 0 0 var(--space-5);
  padding-left: 1.4em;
  display: grid;
  gap: var(--space-2);
}

.sd-post li {
  padding-left: var(--space-1);
}

.sd-post strong {
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
}

/* Underlined, not colour-only — the distinction must survive colour blindness. */
.sd-post a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--action-primary);
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}

.sd-post a:hover {
  color: var(--text-highlight);
  text-decoration-color: var(--text-highlight);
}

.sd-post code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
  color: var(--text-primary);
  background: var(--surface-inset);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
  padding: .12em .4em;
}

/* --------------------------------------------------------------------------
   7. Code blocks — scroll, never wrap
   -------------------------------------------------------------------------- */

.sd-post__code {
  position: relative;
  margin: 0 0 var(--space-6);
  padding: var(--space-5);
  background: var(--surface-raised);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.sd-post__code code {
  display: block;
  white-space: pre;
  background: none;
  border: none;
  padding: 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.sd-copy {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  background: var(--surface-inset);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
  padding: 5px 10px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.sd-post__code:hover .sd-copy,
.sd-copy:focus-visible {
  opacity: 1;
}

.sd-copy:hover {
  color: var(--text-primary);
  border-color: var(--border-brand);
}

.sd-copy[data-copied="true"] {
  opacity: 1;
  color: var(--text-highlight);
  border-color: var(--text-highlight);
}

/* --------------------------------------------------------------------------
   8. Tables
   -------------------------------------------------------------------------- */

.sd-post__tablewrap {
  margin: 0 0 var(--space-6);
  overflow-x: auto;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  max-width: 100%;
}

.sd-post__tablewrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
}

.sd-post__tablewrap th,
.sd-post__tablewrap td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
  vertical-align: top;
}

.sd-post__tablewrap th {
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  background: var(--surface-raised);
}

.sd-post__tablewrap tr:last-child td {
  border-bottom: none;
}

/* --------------------------------------------------------------------------
   9. Author and related
   -------------------------------------------------------------------------- */

.sd-author {
  margin-top: var(--space-8);
  padding: var(--space-6);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  display: grid;
  gap: var(--space-1);
}

.sd-author__name {
  margin: 0;
  font-size: 17px;
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.sd-author__role {
  margin: 0;
  font-size: 15px;
  color: var(--text-muted);
}

.sd-author__link {
  margin-top: var(--space-2);
  justify-self: start;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sd-related {
  margin-top: var(--space-9);
  padding-top: var(--space-7);
  border-top: 1px solid var(--border-hairline);
}

.sd-related__title {
  margin: 0 0 var(--space-5);
  font-family: var(--font-display);
  font-weight: var(--weight-regular);
  font-size: 24px;
  letter-spacing: var(--tracking-display);
  color: var(--text-primary);
}

.sd-related__list {
  display: grid;
  gap: var(--space-4);
}

.sd-related__item {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
}

.sd-related__item:hover {
  border-color: var(--border-brand);
  background: rgba(200, 228, 255, .04);
}

.sd-related__name {
  font-size: 17px;
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.sd-related__desc {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   10. Pagination
   -------------------------------------------------------------------------- */

.sd-pagination {
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-hairline);
}

.sd-pagination ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.sd-pagination a,
.sd-pagination span {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
}

.sd-pagination a:hover {
  color: var(--text-primary);
  border-color: var(--border-brand);
}

.sd-pagination .current {
  color: var(--white);
  background: var(--action-primary);
  border-color: var(--action-primary);
}

/* --------------------------------------------------------------------------
   11. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .sd-blogmain__inner,
  .sd-postmain__inner {
    padding: var(--space-8) var(--gutter-inline) var(--space-9);
  }
}

@media (max-width: 560px) {
  .sd-post {
    font-size: 18px;
  }

  .sd-post__lede {
    font-size: 19px;
  }

  .sd-toc {
    padding: var(--space-4);
  }

  /* Touch has no hover, so the copy button must be permanently visible. */
  .sd-copy {
    opacity: 1;
  }
}

@media (hover: none) {
  .sd-copy {
    opacity: 1;
  }
}
