/* =============================================================================
   BLOG PAPER SKIN
   -----------------------------------------------------------------------------
   Applied to the /blog/, /newsletter/ and /models/ listings and every post (`layout: post`,
   which newsletter editions also use).
   `_layouts/default.html` adds `ts-paper` to <body> and `_includes/head.html`
   loads this file, both gated on the same condition.

   The site forces `dark-mode` on every page, which remaps the typesafe theme
   to black. This skin flips the blog back to the light typesafe.ai palette:

     paper  #e5e5e5     panel  #dedede     panel-2 #c4c4c4
     ink    #1e1e1e     soft   #1e1e1edb   faint   #5c5c5c
     green  #03aa5c     teal   #09aea1     magenta #d45bb6

   Scoped as body.theme-typesafe.ts-paper (three classes), which outranks both
   the `body.theme-typesafe.dark-mode` remap and style.css's `body.dark-mode`
   rules without !important.
   ========================================================================== */

body.theme-typesafe.ts-paper {
  --ts-bg: var(--ts-paper);
  --ts-surface: var(--ts-panel);
  --ts-surface-2: var(--ts-panel-2);
  --ts-fg: var(--ts-ink);
  --ts-fg-soft: var(--ts-ink-soft);
  --ts-fg-faint: #5c5c5c;
  --ts-line: var(--ts-ink);
  --ts-accent: var(--ts-green);
  --ts-rule: 1.2px;

  background: var(--ts-bg);
  color: var(--ts-fg);
}

body.theme-typesafe.ts-paper ::selection {
  background: var(--ts-green);
  color: var(--ts-light);
}

/* -----------------------------------------------------------------------------
   Nav: paper bar, ink rule, green active marker
   -------------------------------------------------------------------------- */

body.theme-typesafe.ts-paper .topnav {
  background: var(--ts-bg);
  border-bottom: var(--ts-rule) solid var(--ts-line);
}

body.theme-typesafe.ts-paper .topnav-brand {
  color: var(--ts-fg);
}

body.theme-typesafe.ts-paper .topnav-link {
  color: var(--ts-fg-soft);
  border-radius: 0;
}

body.theme-typesafe.ts-paper.dark-mode .topnav-link:hover {
  background: var(--ts-surface);
  color: var(--ts-fg);
}

body.theme-typesafe.ts-paper.dark-mode .topnav-link.active {
  background: var(--ts-ink);
  color: var(--ts-light);
}

body.theme-typesafe.ts-paper .topnav-hamburger span {
  background: var(--ts-ink);
}

body.theme-typesafe.ts-paper .topnav-links.open {
  background: var(--ts-bg);
  border: var(--ts-rule) solid var(--ts-line);
}

/* -----------------------------------------------------------------------------
   Listing: big inked title + a numbered index of rows instead of cards
   -------------------------------------------------------------------------- */

body.theme-typesafe.ts-paper .articles-section .section-title {
  font-family: var(--ts-display);
  font-weight: 500;
  font-size: clamp(3rem, 9vw, 5.8rem);
  line-height: 0.9;
  color: var(--ts-fg-soft);
  -webkit-text-stroke: 0.5px var(--ts-fg-soft);
  margin-bottom: 0.8rem;
}

body.theme-typesafe.ts-paper .articles-section .research-intro {
  font-family: var(--ts-term);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ts-fg-faint);
  padding-bottom: 1.6rem;
  border-bottom: var(--ts-rule) solid var(--ts-line);
  margin-bottom: 0;
}

body.theme-typesafe.ts-paper .articles-grid {
  display: block;
  counter-reset: blog-index;
}

body.theme-typesafe.ts-paper .articles-grid .article-card {
  counter-increment: blog-index;
  display: grid;
  grid-template-columns: 4.2rem 1fr;
  column-gap: 1.4rem;
  margin: 0;
  padding: 1.6rem 0.4rem 1.7rem;
  background: transparent;
  border: 0;
  border-bottom: var(--ts-rule) solid var(--ts-line);
  transition: background-color 0.35s var(--ts-ease);
}

body.theme-typesafe.ts-paper .articles-grid .article-card > * {
  grid-column: 2;
}

/* Index number in the left gutter, set in the terminal face. */
body.theme-typesafe.ts-paper .articles-grid .article-card::before {
  content: counter(blog-index, decimal-leading-zero);
  grid-column: 1;
  grid-row: 1 / span 5;
  font-family: var(--ts-term);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--ts-fg-faint);
  padding-top: 0.45rem;
}

body.theme-typesafe.ts-paper .articles-grid .article-card:hover {
  background: var(--ts-surface);
  border-color: var(--ts-line);
}

body.theme-typesafe.ts-paper .articles-grid .article-card:hover::before {
  color: var(--ts-green);
}

body.theme-typesafe.ts-paper .article-title {
  font-size: clamp(1.45rem, 3.2vw, 2.1rem);
  line-height: 1;
  margin: 0 0 0.7rem;
}

body.theme-typesafe.ts-paper .article-title a {
  color: var(--ts-fg-soft);
  -webkit-text-stroke: 0.3px var(--ts-fg-soft);
}

body.theme-typesafe.ts-paper .article-title a:hover {
  color: var(--ts-green);
  -webkit-text-stroke-color: var(--ts-green);
}

body.theme-typesafe.ts-paper .article-date {
  margin: 0 0 0.35rem;
}

body.theme-typesafe.ts-paper .article-tags {
  font-family: var(--ts-term);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ts-green);
  margin: 0 0 0.8rem;
}

body.theme-typesafe.ts-paper .article-preview {
  max-width: 68ch;
  color: var(--ts-fg-soft);
  margin: 0 0 1rem;
}

body.theme-typesafe.ts-paper .article-read-more {
  justify-self: start;
  color: var(--ts-fg);
}

/* Pagination: square ink boxes, active page filled ink. */
body.theme-typesafe.ts-paper .article-pagination {
  margin-top: 2.2rem;
}

body.theme-typesafe.ts-paper .article-pagination a,
body.theme-typesafe.ts-paper .article-pagination span {
  border: var(--ts-rule) solid var(--ts-line);
  border-radius: 0;
  background: transparent;
  color: var(--ts-fg);
}

body.theme-typesafe.ts-paper .article-pagination a:hover {
  background: var(--ts-green);
  border-color: var(--ts-green);
  color: var(--ts-light);
}

body.theme-typesafe.ts-paper .article-pagination .active {
  background: var(--ts-ink);
  border-color: var(--ts-ink);
  color: var(--ts-light);
}

body.theme-typesafe.ts-paper .article-pagination .disabled {
  opacity: 0.35;
}

/* -----------------------------------------------------------------------------
   Models listing (/models/): the blog's numbered rows, plus a totals strip
   under the intro and a row of key/value facts on each model.
   -------------------------------------------------------------------------- */

body.theme-typesafe.ts-paper .models-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  border-bottom: var(--ts-rule) solid var(--ts-line);
}

body.theme-typesafe.ts-paper .models-stat {
  padding: 1.3rem 0.4rem 1.4rem;
}

body.theme-typesafe.ts-paper .models-stat + .models-stat {
  padding-left: 1.4rem;
  border-left: var(--ts-rule) solid var(--ts-line);
}

body.theme-typesafe.ts-paper .models-stat dt {
  font-family: var(--ts-term);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ts-fg-faint);
  margin-bottom: 0.5rem;
}

body.theme-typesafe.ts-paper .models-stat dd {
  margin: 0;
  font-family: var(--ts-display);
  font-weight: 500;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  line-height: 1;
  color: var(--ts-fg-soft);
}

body.theme-typesafe.ts-paper .models-stat [data-hf-total] {
  color: var(--ts-green);
}

body.theme-typesafe.ts-paper .models-grid .model-card::before {
  grid-row: 1 / span 8;
}

body.theme-typesafe.ts-paper .model-id {
  font-family: var(--ts-term);
  font-size: 0.75rem;
  color: var(--ts-fg-faint);
  word-break: break-all;
}

body.theme-typesafe.ts-paper .model-detail {
  color: var(--ts-fg-faint);
}

body.theme-typesafe.ts-paper .model-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 1.6rem;
  list-style: none;
  margin: 0 0 1.1rem;
  padding: 0;
  font-size: 0.9rem;
  color: var(--ts-fg);
}

body.theme-typesafe.ts-paper .model-meta span {
  font-family: var(--ts-term);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ts-fg-faint);
  margin-right: 0.45rem;
}

body.theme-typesafe.ts-paper .model-meta b {
  font-weight: 600;
  color: var(--ts-green);
}

@media (max-width: 640px) {
  body.theme-typesafe.ts-paper .models-stats {
    grid-template-columns: 1fr;
  }

  body.theme-typesafe.ts-paper .models-stat + .models-stat {
    padding-left: 0.4rem;
    border-left: 0;
    border-top: var(--ts-rule) solid var(--ts-line);
  }
}

/* -----------------------------------------------------------------------------
   Newsletter listing: same numbered rows, but each edition is a boxed card
   with a hard ink border, and the whole card is the link.
   -------------------------------------------------------------------------- */

body.theme-typesafe.ts-paper .articles-section.newsletter-section .research-intro {
  border-bottom: 0;
}

body.theme-typesafe.ts-paper .newsletter-grid {
  display: grid;
  gap: 1.1rem;
}

body.theme-typesafe.ts-paper .newsletter-grid .article-card {
  position: relative;
  padding: 1.5rem 1.4rem 1.4rem;
  border: 2px solid var(--ts-ink);
  border-radius: 0;
  box-shadow: 6px 6px 0 var(--ts-ink);
  transition: background-color 0.2s var(--ts-ease), transform 0.2s var(--ts-ease),
    box-shadow 0.2s var(--ts-ease);
}

body.theme-typesafe.ts-paper .newsletter-grid .article-card::before {
  padding-top: 0.3rem;
}

body.theme-typesafe.ts-paper .newsletter-grid .article-card:hover {
  border-color: var(--ts-ink);
  transform: translate(-2px, -2px);
  box-shadow: 8px 8px 0 var(--ts-green);
}

/* Stretch the title link over the card so a click anywhere opens the edition. */
body.theme-typesafe.ts-paper .newsletter-grid .article-title a::after {
  content: "";
  position: absolute;
  inset: 0;
}

body.theme-typesafe.ts-paper .newsletter-grid .article-card:focus-within {
  outline: 2px solid var(--ts-green);
  outline-offset: 3px;
}

/* Byline under the title ("by Trisham Patil"): its own line, smaller. */
body.theme-typesafe.ts-paper .article-subtitle,
body.theme-typesafe.ts-paper .post-header .post-subtitle {
  display: block;
  margin-top: 0.35em;
  font-size: 0.5em;
}

body.theme-typesafe.ts-paper .newsletter-grid .article-date {
  margin: 0;
}

/* -----------------------------------------------------------------------------
   Newsletter modal (assets/js/newsletter-modal.js): the same hard-bordered,
   offset-shadow box as the listing cards, opened from an ink button.
   -------------------------------------------------------------------------- */

body.theme-typesafe.ts-paper .nl-modal-open {
  font-family: var(--ts-term);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.75rem 1.1rem;
  background: var(--ts-bg);
  color: var(--ts-ink);
  border: 2px solid var(--ts-ink);
  border-radius: 0;
  box-shadow: 4px 4px 0 var(--ts-ink);
  cursor: pointer;
  transition: transform 0.2s var(--ts-ease), box-shadow 0.2s var(--ts-ease),
    background-color 0.2s var(--ts-ease);
}

body.theme-typesafe.ts-paper .nl-modal-open:hover,
body.theme-typesafe.ts-paper .nl-modal-open:focus-visible {
  background: var(--ts-surface);
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--ts-green);
  outline: none;
}

/* Source link under a news item: small terminal caps, like the dates. */
body.theme-typesafe.ts-paper .post-content .nl-source {
  display: inline-block;
  font-family: var(--ts-term);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ts-ink);
  border-bottom: 2px solid var(--ts-green);
  text-decoration: none;
}

body.theme-typesafe.ts-paper .post-content .nl-source:hover {
  color: var(--ts-green);
}

/* Company logo in the spotlight section: a white panel (so it survives
   dark-mode email clients) framed like the cards. */
body.theme-typesafe.ts-paper .post-content img.nl-logo {
  display: block;
  width: min(16rem, 70%);
  height: auto;
  margin: 0.6rem 0 1.2rem;
  border: 2px solid var(--ts-ink);
  box-shadow: 4px 4px 0 var(--ts-ink);
  background: #fff;
}

/* YouTube thumbnail linking to the video (works in email, unlike iframes). */
body.theme-typesafe.ts-paper .post-content img.nl-video-thumb {
  display: block;
  width: min(32rem, 100%);
  height: auto;
  margin: 0.4rem 0 1rem;
  border: 2px solid var(--ts-ink);
  box-shadow: 6px 6px 0 var(--ts-ink);
  transition: box-shadow 0.2s var(--ts-ease), transform 0.2s var(--ts-ease);
}

body.theme-typesafe.ts-paper .post-content a:hover img.nl-video-thumb {
  transform: translate(-2px, -2px);
  box-shadow: 8px 8px 0 var(--ts-green);
}

/* Star count / language / licence line under each GitHub repo heading. */
body.theme-typesafe.ts-paper .post-content .nl-repo-meta {
  font-family: var(--ts-term);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ts-green);
  margin: -0.2rem 0 0.8rem;
}

/* Tech Brew badge above the newsletter issue title. */
body.theme-typesafe.ts-paper .post--newsletter .post-header .nl-masthead-logo {
  display: block;
  width: 120px;
  height: 120px;
  margin: 0 0 1rem;
}

/* Newsletter story headlines (H4 under a theme H3) read as headlines, not
   as the small terminal labels H4 is in articles. */
body.theme-typesafe.ts-paper .post--newsletter .post-content h4 {
  font-family: var(--ts-display);
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.25;
  color: var(--ts-fg);
  margin-top: 1.6rem;
  margin-bottom: 0.45rem;
}

/* Subscribe box (_includes/newsletter-subscribe.html): the same hard ink
   border and offset shadow as the edition cards. */
body.theme-typesafe.ts-paper .nl-subscribe {
  margin: 2rem 0 2.4rem;
  padding: 1.5rem 1.4rem 1.3rem;
  background: var(--ts-surface);
  border: 2px solid var(--ts-ink);
  box-shadow: 6px 6px 0 var(--ts-ink);
}

body.theme-typesafe.ts-paper .post--newsletter .nl-subscribe {
  margin-top: 3.4rem;
}

body.theme-typesafe.ts-paper .nl-subscribe .nl-subscribe-title {
  margin: 0 0 0.5rem;
  padding: 0;
  border: 0;
  font-family: var(--ts-display);
  font-weight: 500;
  font-size: clamp(1.3rem, 3vw, 1.75rem);
  line-height: 1.05;
  color: var(--ts-fg-soft);
}

body.theme-typesafe.ts-paper .nl-subscribe-text {
  margin: 0 0 1rem;
  max-width: 60ch;
  color: var(--ts-fg-soft);
}

body.theme-typesafe.ts-paper .nl-subscribe-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

/* Visually hidden, still read by screen readers. */
body.theme-typesafe.ts-paper .nl-subscribe-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

body.theme-typesafe.ts-paper .nl-subscribe-input {
  flex: 1 1 16rem;
  min-width: 0;
  padding: 0.75rem 0.9rem;
  font: inherit;
  color: var(--ts-ink);
  background: var(--ts-light);
  border: 2px solid var(--ts-ink);
  border-radius: 0;
}

body.theme-typesafe.ts-paper .nl-subscribe-input:focus {
  outline: 2px solid var(--ts-green);
  outline-offset: 2px;
}

body.theme-typesafe.ts-paper .nl-subscribe-button {
  flex: 0 0 auto;
  padding: 0.75rem 1.3rem;
  font-family: var(--ts-term);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ts-light);
  background: var(--ts-ink);
  border: 2px solid var(--ts-ink);
  border-radius: 0;
  cursor: pointer;
  transition: background-color 0.2s var(--ts-ease), border-color 0.2s var(--ts-ease);
}

body.theme-typesafe.ts-paper .nl-subscribe-button:hover,
body.theme-typesafe.ts-paper .nl-subscribe-button:focus-visible {
  background: var(--ts-green);
  border-color: var(--ts-green);
  outline: none;
}

body.theme-typesafe.ts-paper .nl-unsubscribe-link {
  color: var(--ts-fg);
  text-decoration: underline;
  text-decoration-color: var(--ts-green);
}

/* Google Form mode: the same ink button, as a link. */
body.theme-typesafe.ts-paper a.nl-subscribe-link {
  display: inline-block;
  color: var(--ts-light);
  text-decoration: none;
}

body.theme-typesafe.ts-paper a.nl-subscribe-link:hover,
body.theme-typesafe.ts-paper a.nl-subscribe-link:focus-visible {
  color: var(--ts-light);
}

body.theme-typesafe.ts-paper .nl-subscribe-fine {
  margin: 0.8rem 0 0;
  font-family: var(--ts-term);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ts-fg-faint);
}

/* Section hero image (All About AI Agents): full content width. The PNG
   draws its own ink frame and offset shadow, so no CSS frame here. */
body.theme-typesafe.ts-paper .post-content img.nl-hero {
  display: block;
  width: 100%;
  height: auto;
  margin: 0.4rem 0 1.1rem;
  border: 0;
  box-shadow: none;
}

/* Expandable story (<details class="nl-expand">): the first paragraph stays
   visible, the rest opens in place. The toggle uses the card language (ink
   border, offset shadow); "+" becomes "×" when open. */
body.theme-typesafe.ts-paper .post-content .nl-expand {
  margin: 0.4rem 0 1.6rem;
}

body.theme-typesafe.ts-paper .post-content .nl-expand > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  list-style: none;
  padding: 0.5rem 0.95rem 0.5rem 0.6rem;
  font-family: var(--ts-term);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ts-ink);
  background: var(--ts-bg);
  border: 2px solid var(--ts-ink);
  box-shadow: 3px 3px 0 var(--ts-ink);
  cursor: pointer;
  user-select: none;
  transition: transform 0.2s var(--ts-ease), box-shadow 0.2s var(--ts-ease),
    background-color 0.2s var(--ts-ease), color 0.2s var(--ts-ease);
}

body.theme-typesafe.ts-paper .post-content .nl-expand > summary::-webkit-details-marker {
  display: none;
}

/* The +/x badge. */
body.theme-typesafe.ts-paper .post-content .nl-expand > summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--ts-light);
  background: var(--ts-green);
  transition: background-color 0.2s var(--ts-ease);
}

body.theme-typesafe.ts-paper .post-content .nl-expand > summary:hover,
body.theme-typesafe.ts-paper .post-content .nl-expand > summary:focus-visible {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ts-green);
  outline: none;
}

body.theme-typesafe.ts-paper .post-content .nl-expand[open] > summary {
  color: var(--ts-light);
  background: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .nl-expand[open] > summary::before {
  content: "\00d7";
  background: var(--ts-light);
  color: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .nl-expand .nl-expand-less,
body.theme-typesafe.ts-paper .post-content .nl-expand[open] .nl-expand-more {
  display: none;
}

body.theme-typesafe.ts-paper .post-content .nl-expand[open] .nl-expand-less {
  display: inline;
}

/* The opened text: a green rule ties it to its story. */
body.theme-typesafe.ts-paper .post-content .nl-expand-body {
  margin-top: 1.1rem;
  padding-left: 1.1rem;
  border-left: 3px solid var(--ts-green);
}

body.theme-typesafe.ts-paper .post-content .nl-expand-body > :first-child {
  margin-top: 0;
}

body.theme-typesafe.ts-paper .post-content .nl-expand[open] .nl-expand-body {
  animation: nl-expand-in 0.35s var(--ts-ease);
}

@keyframes nl-expand-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Smooth height where the browser can animate to auto. */
@supports (interpolate-size: allow-keywords) {
  body.theme-typesafe.ts-paper .post-content .nl-expand {
    interpolate-size: allow-keywords;
  }

  body.theme-typesafe.ts-paper .post-content .nl-expand::details-content {
    height: 0;
    overflow: clip;
    transition: height 0.35s var(--ts-ease);
  }

  body.theme-typesafe.ts-paper .post-content .nl-expand[open]::details-content {
    height: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.theme-typesafe.ts-paper .post-content .nl-expand[open] .nl-expand-body {
    animation: none;
  }

  body.theme-typesafe.ts-paper .post-content .nl-expand::details-content {
    transition: none;
  }
}

/* Release stack (<details class="nl-expand nl-expand--release">): only the
   numbered heading shows, with a black Expand button under it that opens the
   takeaways, story and Dive deep button. Releases sit close together so the
   list reads as 1, 2, 3, ... */
body.theme-typesafe.ts-paper .post-content .nl-expand--release {
  margin: 0.2rem 0 1.4rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px dashed var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .nl-expand--release > summary {
  color: var(--ts-light);
  background: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .nl-expand--release > summary::before {
  background: var(--ts-light);
  color: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .nl-expand--release[open] > summary {
  color: var(--ts-ink);
  background: var(--ts-bg);
}

body.theme-typesafe.ts-paper .post-content .nl-expand--release[open] > summary::before {
  background: var(--ts-ink);
  color: var(--ts-light);
}

/* "Read the blog" link: same black button as the release Expand, but it
   leaves the newsletter for the full post. */
body.theme-typesafe.ts-paper .post-content a.nl-read-btn {
  display: inline-block;
  padding: 0.5rem 0.95rem;
  font-family: var(--ts-term);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ts-light);
  background: var(--ts-ink);
  border: 2px solid var(--ts-ink);
  box-shadow: 3px 3px 0 var(--ts-ink);
  transition: transform 0.2s var(--ts-ease), box-shadow 0.2s var(--ts-ease);
}

body.theme-typesafe.ts-paper .post-content a.nl-read-btn:hover,
body.theme-typesafe.ts-paper .post-content a.nl-read-btn:focus-visible {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ts-green);
  outline: none;
}

/* Padding lives on the children, so a click on the <dialog> element itself
   can only be a backdrop click (the script closes on that). */
body.theme-typesafe.ts-paper .nl-modal {
  width: min(46rem, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  padding: 0;
  background: var(--ts-paper);
  color: var(--ts-fg);
  border: 2px solid var(--ts-ink);
  border-radius: 0;
  box-shadow: 8px 8px 0 var(--ts-ink);
}

/* Long-read modals (All About AI Agents): wider and taller. */
body.theme-typesafe.ts-paper .nl-modal.nl-modal--wide {
  width: min(64rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
}

body.theme-typesafe.ts-paper .nl-modal::backdrop {
  background: rgba(30, 30, 30, 0.55);
}

body.theme-typesafe.ts-paper .nl-modal-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.4rem;
  background: var(--ts-paper);
  border-bottom: 2px solid var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .nl-modal-head h2 {
  margin: 0;
  padding: 0;
  border: 0;
  font-family: var(--ts-display);
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  line-height: 1.05;
  color: var(--ts-fg-soft);
}

body.theme-typesafe.ts-paper .nl-modal-close {
  flex: none;
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.4rem;
  line-height: 1;
  background: transparent;
  color: var(--ts-ink);
  border: 2px solid var(--ts-ink);
  border-radius: 0;
  cursor: pointer;
}

body.theme-typesafe.ts-paper .nl-modal-close:hover,
body.theme-typesafe.ts-paper .nl-modal-close:focus-visible {
  background: var(--ts-ink);
  color: var(--ts-light);
  outline: none;
}

body.theme-typesafe.ts-paper .nl-modal-body {
  padding: 0.4rem 1.4rem 1.4rem;
}

/* Tables in a modal span the full body width (the post default is a
   shrink-to-fit block). */
body.theme-typesafe.ts-paper .post-content .nl-modal-body table {
  display: table;
  width: 100%;
}

/* Rabbit-holes list: eight themed tables, so pin the columns to line up. */
body.theme-typesafe.ts-paper #rabbit-holes table {
  table-layout: fixed;
}

body.theme-typesafe.ts-paper #rabbit-holes th:nth-child(1) {
  width: 3rem;
}

body.theme-typesafe.ts-paper #rabbit-holes th:nth-child(2) {
  width: 38%;
}

body.theme-typesafe.ts-paper #rabbit-holes td {
  overflow-wrap: anywhere;
}

body.theme-typesafe.ts-paper .nl-modal-body h3 {
  margin: 1.4rem 0 0.5rem;
}

/* -----------------------------------------------------------------------------
   Post body: undo the dark-mode overrides from style.css
   -------------------------------------------------------------------------- */

body.theme-typesafe.ts-paper .post-content {
  color: var(--ts-fg);
}

body.theme-typesafe.ts-paper .post-content h3 {
  color: var(--ts-fg);
}

/* Code stays an ink slab: it reads as a printed block on the paper. */
body.theme-typesafe.ts-paper .post-content pre,
body.theme-typesafe.ts-paper .post-content .highlight pre {
  background: var(--ts-ink);
  color: #e8e8e8;
  border-color: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content :not(pre) > code {
  background: var(--ts-surface);
  border-color: var(--ts-panel-2);
  color: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content table {
  border: var(--ts-rule) solid var(--ts-line);
  background: transparent;
}

body.theme-typesafe.ts-paper .post-content th {
  background: var(--ts-ink);
  color: var(--ts-light);
  font-family: var(--ts-term);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-color: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content td {
  color: var(--ts-fg);
  border-color: var(--ts-line);
  background: transparent;
}

body.theme-typesafe.ts-paper .post-content tbody tr:nth-child(even) td,
body.theme-typesafe.ts-paper .post-content tbody tr:nth-child(even) {
  background: var(--ts-surface);
}

body.theme-typesafe.ts-paper .post-content img {
  background: var(--ts-light);
  border-color: var(--ts-line);
}

body.theme-typesafe.ts-paper .post-content li::marker {
  color: var(--ts-green);
}

body.theme-typesafe.ts-paper.dark-mode .ts-note > .ts-note-title {
  color: var(--ts-fg);
}

body.theme-typesafe.ts-paper .post-content .mermaid-diagram {
  background: var(--ts-light);
  border: var(--ts-rule) solid var(--ts-line);
}

/* Tight 0.9 display leading lets descenders touch the meta line below. */
body.theme-typesafe.ts-paper .post-header h1 {
  line-height: 0.96;
  margin-bottom: 1.4rem;
}

/* Let the intro's rule span the full column like the row rules below it. */
body.theme-typesafe.ts-paper .articles-section .research-intro {
  max-width: none;
}

body.theme-typesafe.ts-paper .post-header .meta {
  padding-top: 1.1rem;
}

/* Release timeline (<ol class="ts-timeline">): an ink rail with square nodes
   and cards in the paper card language (ink border, offset shadow). Tags mark
   the licence: ink = closed, dashed = restricted weights, green = open,
   magenta outline (#b8399a: --ts-magenta is too light for small text on
   paper) = not yet released. The --current item gets a green node. */
body.theme-typesafe.ts-paper .post-content .ts-timeline {
  position: relative;
  list-style: none;
  margin: 1.6rem 0 2rem;
  padding: 0 0 0 2.2rem;
}

body.theme-typesafe.ts-paper .post-content .ts-timeline::before {
  content: "";
  position: absolute;
  top: 0.4rem;
  bottom: 0.4rem;
  left: 0.55rem;
  width: 2px;
  background: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-item {
  position: relative;
  margin: 0 0 1.5rem;
  padding: 0;
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-item:last-child {
  margin-bottom: 0;
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-item::before {
  content: "";
  position: absolute;
  top: 0.15rem;
  left: -2.2rem;
  width: 1.1rem;
  height: 1.1rem;
  background: var(--ts-bg);
  border: 2px solid var(--ts-ink);
  box-sizing: border-box;
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-item--current::before {
  background: var(--ts-green);
  border-color: var(--ts-green);
  box-shadow: 0 0 0 4px rgba(3, 170, 92, 0.22);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-date {
  display: block;
  margin-bottom: 0.45rem;
  font-family: var(--ts-term);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ts-fg-faint);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-card {
  padding: 0.95rem 1.1rem 1rem;
  background: var(--ts-surface);
  border: 2px solid var(--ts-ink);
  box-shadow: 4px 4px 0 var(--ts-ink);
  transition: transform 0.2s var(--ts-ease), box-shadow 0.2s var(--ts-ease);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-item--current .ts-timeline-card {
  box-shadow: 4px 4px 0 var(--ts-green);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-item--current .ts-timeline-card:hover {
  box-shadow: 6px 6px 0 var(--ts-green);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-title {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  color: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-card p {
  margin: 0.6rem 0 0;
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-tag {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  font-family: var(--ts-term);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1.5px solid var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-tag--closed {
  color: var(--ts-light);
  background: var(--ts-ink);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-tag--research {
  color: var(--ts-ink);
  border-style: dashed;
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-tag--open {
  color: var(--ts-light);
  background: var(--ts-green);
  border-color: var(--ts-green);
}

body.theme-typesafe.ts-paper .post-content .ts-timeline-tag--pending {
  color: #b8399a;
  border-color: #b8399a;
}

@media (prefers-reduced-motion: reduce) {
  body.theme-typesafe.ts-paper .post-content .ts-timeline-card {
    transition: none;
  }
}
