/* ============================================================
   Article detail page — editorial reading experience
   Loads after ../articles.css and ../../style.css
   Reuses the same design tokens and vocabulary as the homepage.
   ============================================================ */

/* ---------- Reading progress bar ---------- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: calc(var(--z-header) + 30);
  width: 100%;
  height: 3px;
  pointer-events: none;
  background: transparent;
}

.reading-progress::before {
  content: "";
  display: block;
  height: 100%;
  width: var(--progress, 0%);
  background: var(--accent);
}

/* ---------- Shell and layout ---------- */
.article-shell {
  max-width: 1160px;
  margin: 0 auto;
}

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 720px) minmax(0, 1fr);
  justify-content: space-between;
  gap: clamp(40px, 6vw, 72px);
  margin-top: 48px;
}

.article-layout.rail-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.article-body {
  max-width: 720px;
}

/* ---------- Article header ---------- */
.article-head {
  max-width: 760px;
}

.article-head .chip {
  display: inline-block;
  margin-bottom: 20px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--accent-text);
  font: 500 10.5px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.article-head h1 {
  margin-bottom: 22px;
  font-size: clamp(32px, 4.6vw, 54px);
  line-height: 1.05;
  letter-spacing: -0.025em;
  font-weight: 900;
  text-wrap: balance;
}

.article-head .article-lede {
  max-width: 640px;
  color: var(--section-copy);
  font-size: clamp(16.5px, 1.5vw, 19px);
  line-height: 1.65;
  text-wrap: pretty;
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 30px;
}

.article-meta .avatar {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 50%;
  flex: none;
}

.article-meta .meta-name {
  display: block;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: none;
  transition: color 0.2s;
}

.article-meta .meta-name:hover {
  color: var(--accent-text);
}

.article-meta .meta-details {
  display: block;
  color: var(--muted);
  font: 400 11px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.article-meta .meta-details time,
.article-meta .meta-details .byline-label {
  color: var(--muted);
}

/* ---------- Share controls ---------- */
.article-share {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--ink);
  font: 600 10.5px "DM Mono", monospace;
  letter-spacing: 0.6px;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    translate 0.2s var(--ease-out),
    border-color 0.2s,
    color 0.2s,
    background 0.2s;
}

.share-btn .icon {
  font-size: 13px;
}

.share-btn:hover {
  translate: 0 -2px;
  border-color: var(--accent-text);
  color: var(--accent-text);
}

.share-btn[data-state="copied"] {
  border-color: var(--accent-text);
  color: var(--accent-text);
  background: color-mix(in srgb, var(--accent-text) 8%, var(--surface));
}

.share-btn:focus-visible,
.toc-list a:focus-visible,
.pn-cell:focus-visible,
.related-grid .card:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 3px;
}

/* ---------- Featured image ---------- */
.article-featured {
  max-width: 820px;
  margin-top: 44px;
}

.article-featured img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--soft);
}

.article-featured figcaption {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  justify-content: space-between;
  padding: 12px 2px 0;
  color: var(--muted);
  font: 400 10.5px "DM Mono", monospace;
  letter-spacing: 0.4px;
}

/* ---------- Anchor offsets ---------- */
.article-body [id],
.pn-grid[id],
.related[id] {
  scroll-margin-top: calc(var(--header-h) + 26px);
}

/* ---------- Article body prose ---------- */
.article-body > * + * {
  margin-top: 1.15em;
}

.article-body p {
  color: var(--copy);
  font-size: 17px;
  line-height: 1.78;
  text-wrap: pretty;
}

.article-body p a,
.article-body li a {
  color: var(--accent-text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.2s;
}

.article-body p a:hover,
.article-body li a:hover {
  color: var(--ink);
}

.article-body strong {
  color: var(--ink);
  font-weight: 650;
}

/* Prose headings (override style.css .content-section h2) */
.article-body h2 {
  margin-top: 2.1em;
  margin-bottom: 0.65em;
  font-size: clamp(23px, 2.5vw, 29px);
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 800;
  scroll-margin-top: calc(var(--header-h) + 30px);
}

.article-body h2::after {
  content: "";
  display: block;
  margin-top: 14px;
  width: 34px;
  height: 2px;
  background: var(--accent);
}

.article-body h3 {
  margin-top: 1.9em;
  margin-bottom: 0.4em;
  font-size: 18.5px;
  letter-spacing: -0.01em;
  font-weight: 750;
}

.article-body ul,
.article-body ol {
  padding-left: 1.25em;
}

.article-body li {
  margin-top: 0.5em;
  color: var(--copy);
  font-size: 16.5px;
  line-height: 1.7;
}

.article-body li::marker {
  color: var(--accent-text);
  font: 500 10px "DM Mono", monospace;
  letter-spacing: 0.5px;
}

.article-body blockquote {
  position: relative;
  margin: 1.9em 0;
  padding: 0.2em 0 0.2em 26px;
  border-left: 3px solid var(--accent);
  color: var(--ink);
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.article-body blockquote p + p {
  margin-top: 0.8em;
}

.article-body code {
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--soft);
  color: var(--ink);
  font: 500 13px "DM Mono", monospace;
}

.article-body pre {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--soft);
  overflow-x: auto;
}

.article-body pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: 12.5px;
  line-height: 1.7;
}

.article-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.6em auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.article-body .table-wrap {
  margin: 1.8em 0;
  overflow-x: auto;
}

.article-body table {
  min-width: 540px;
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
}

.article-body th {
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  font: 500 10.5px "DM Mono", monospace;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  white-space: nowrap;
}

.article-body td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--copy);
  font-size: 14.5px;
  line-height: 1.6;
  vertical-align: top;
}

.article-body tr:last-child td {
  border-bottom: 0;
}

.article-body td:first-child {
  color: var(--ink);
  font-weight: 600;
}

.article-body hr {
  margin: 2.6em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

/* ---------- Sticky table of contents rail ---------- */
.sticky-rail {
  position: sticky;
  top: calc(var(--header-h) + 44px);
  align-self: start;
}

.rail-label {
  display: block;
  margin-bottom: 16px;
  color: var(--accent-text);
  font: 500 10.5px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 1.1px;
}

.toc-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 1px solid var(--line);
}

.toc-list a {
  display: block;
  padding: 7px 0 7px 14px;
  border-left: 2px solid transparent;
  margin-left: -1.5px;
  color: var(--muted);
  font: 400 11px "DM Mono", monospace;
  letter-spacing: 0.3px;
  line-height: 1.5;
  text-decoration: none;
  transition:
    color 0.2s,
    border-color 0.2s,
    translate 0.2s var(--ease-out);
}

.toc-list a:hover {
  color: var(--ink);
}

.toc-list a[aria-current="location"] {
  border-color: var(--accent-text);
  color: var(--accent-text);
}

/* ---------- Article footer: tags, author, prev/next ---------- */
.article-foot {
  max-width: 820px;
  margin-top: 56px;
}

.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.article-tags span {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  color: var(--muted);
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Author box */
.author-box {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  margin-top: 40px;
  padding: 26px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.author-box .avatar {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.author-box .author-name {
  display: block;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
}

.author-box .author-role {
  display: block;
  margin-top: 3px;
  color: var(--accent-text);
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.author-box .author-bio {
  max-width: 560px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.65;
}

.author-box .author-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 14px;
}

.author-box .author-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font: 600 10.5px "DM Mono", monospace;
  letter-spacing: 0.5px;
  text-decoration: none;
  text-transform: uppercase;
  transition: color 0.2s;
}

.author-box .author-links a .icon {
  font-size: 12px;
  transition: translate 0.2s var(--ease-out);
}

.author-box .author-links a:hover {
  color: var(--accent-text);
}

.author-box .author-links a:hover .icon {
  translate: 2px -2px;
}

/* Prev / next navigation */
.pn-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin-top: 40px;
  background: var(--line);
  border: 1px solid var(--line);
}

.pn-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 108px;
  padding: 22px 24px;
  background: var(--surface);
  text-decoration: none;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    translate 0.25s var(--ease-out);
}

.pn-cell:hover {
  position: relative;
  z-index: 1;
  translate: 0 -4px;
  background: var(--paper);
  box-shadow: var(--shadow-2);
}

.pn-cell .pn-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent-text);
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.pn-cell .pn-label .icon {
  font-size: 12px;
  transition: translate 0.2s var(--ease-out);
}

.pn-cell h3 {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.3;
  letter-spacing: -0.015em;
  font-weight: 800;
}

.pn-cell.prev .pn-label .icon {
  transition-duration: 0.2s;
}

.pn-cell.prev:hover .pn-label .icon {
  translate: -2px 0;
}

.pn-cell.next {
  text-align: right;
}

.pn-cell.next .pn-label {
  justify-content: flex-end;
}

.pn-cell.next:hover .pn-label .icon {
  translate: 2px 0;
}

.pn-placeholder {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 108px;
  padding: 22px 24px;
  background: var(--surface);
  color: var(--muted);
  font: 400 11px "DM Mono", monospace;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ---------- Related articles ---------- */
.related h2 {
  font-size: clamp(24px, 2.8vw, 34px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 900;
}

.related-grid {
  margin-top: 40px;
}

.related-grid .card .card-date {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font: 400 10.5px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.related-grid .card:last-child {
  grid-column: 1 / -1;
}

/* ---------- Responsive ---------- */
@media (max-width: 1079px) {
  .article-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sticky-rail {
    display: none;
  }
}

@media (max-width: 760px) {
  .article-body p,
  .article-body li {
    font-size: 16px;
  }

  .article-body blockquote {
    font-size: 18px;
    padding-left: 20px;
  }

  .pn-grid {
    grid-template-columns: 1fr;
  }

  .pn-cell.next {
    text-align: left;
  }

  .pn-cell.next .pn-label {
    justify-content: flex-start;
  }

  .author-box {
    padding: 20px;
  }

  .related-grid .card:last-child {
    grid-column: auto;
  }

  .article-meta {
    align-items: flex-start;
  }

  .article-meta .meta-details {
    max-width: 46ch;
  }
}

@media (max-width: 430px) {
  .article-head h1 {
    font-size: clamp(26px, 7.4vw, 32px);
  }

  .article-share .share-btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .article-featured figcaption {
    flex-direction: column;
    gap: 4px;
  }

  .article-tags span {
    font-size: 9.5px;
    padding: 5px 8px;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .share-btn,
  .pn-cell,
  .toc-list a,
  .article-meta .meta-name,
  .article-body p a,
  .article-body li,
  .author-box .author-links a,
  .author-box .author-links a .icon,
  .pn-cell .pn-label .icon,
  .article-body h2 {
    transition: none;
  }

  .pn-cell:hover,
  .share-btn:hover {
    translate: 0;
  }

  html {
    scroll-behavior: auto;
  }
}
