/* All of the site's styling. The tokens in :root are the knobs. */

/* Crimson Pro (SIL OFL 1.1, see /fonts/OFL.txt): the wordmark and headings. */
@font-face {
  font-family: 'Crimson Pro';
  src: url('/fonts/crimson-pro-latin-wght.woff2') format('woff2');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-display: 'Crimson Pro', ui-serif, Georgia, serif;
  --font-body: ui-serif, Charter, 'Bitstream Charter', 'Iowan Old Style', Georgia, serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --bg: #ffffff;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --rule: #e5e5e5;
  --accent: #2554c7;
  --code-bg: #f4f4f5;

  --measure: 38rem;
  --space: 1rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --text: #e6e6e6;
    --muted: #9a9a9a;
    --rule: #2e2e2e;
    --accent: #8fb0ff;
    --code-bg: #222222;
  }
}

* {
  box-sizing: border-box;
}

html {
  font-size: 112.5%;
  -webkit-text-size-adjust: 100%;
  /* Keep room for the scrollbar even when there's nothing to scroll, so the
     page doesn't shift sideways when it appears (e.g. opening the discussion). */
  scrollbar-gutter: stable;
}

body {
  margin: 0 auto;
  max-width: calc(var(--measure) + 2 * var(--space));
  padding: calc(2 * var(--space)) var(--space) calc(4 * var(--space));
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
  text-decoration-thickness: 1px;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  line-height: 1.15;
  font-weight: 600;
}

h1 {
  font-size: 1.95rem;
  margin: 0 0 0.5rem;
}

h2 {
  font-size: 1.4rem;
  margin: 2.5rem 0 0.75rem;
}

.muted {
  color: var(--muted);
}

/* ---- header / footer ---- */

.site-header,
.site-footer {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.site-header {
  align-items: center;
  margin-bottom: 3rem;
}

.site-header nav {
  display: flex;
  gap: 1rem;
  margin-left: auto;
}

.site-name {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 400;
  color: var(--text);
  text-decoration: none;
}

.site-footer {
  margin-top: 4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  gap: 0.9rem;
}

.site-footer a,
.site-header nav a {
  color: var(--muted);
}

.site-header nav a[aria-current='page'] {
  color: var(--text);
  text-decoration: none;
}

.site-footer a:hover,
.site-header nav a:hover {
  color: var(--accent);
}

.icon {
  display: block;
}

.site-footer a {
  display: inline-flex;
  padding: 0.15rem;
}

/* ---- home / lists ---- */

.intro > :first-child {
  margin-top: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 500;
  line-height: 1.25;
}

.page-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0;
}

.feed-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  text-decoration: none;
}

.feed-link:hover {
  color: var(--accent);
}

.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-list li {
  display: flex;
  gap: 1rem;
  margin: 0.9rem 0;
}

.post-desc {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.post-list time {
  flex: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding-top: 0.2rem;
}

/* ---- post body ---- */

.post header {
  margin-bottom: 2rem;
}

main > .back,
.post .back {
  display: inline-block;
  margin-bottom: 1.25rem;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  text-decoration: none;
}

main > .back:hover,
.post .back:hover {
  color: var(--accent);
}

.post .cover {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 0 2rem;
  border-radius: 6px;
  background: var(--code-bg);
}

.post header p {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.tags a {
  color: inherit;
  text-decoration-color: var(--rule);
  text-underline-offset: 0.2em;
}

.tags a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

.prose img {
  max-width: 100%;
  height: auto;
}

.prose blockquote {
  margin: 1.5rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

.prose pre {
  background: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  border-radius: 4px;
  line-height: 1.45;
}

.prose pre code {
  background: none;
  padding: 0;
}

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

.prose table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}

.prose th,
.prose td {
  border: 1px solid var(--rule);
  padding: 0.3rem 0.6rem;
}

/* ---- discussion (laid out like bsky.app's thread view) ---- */

/*
 * The post's last line, between two rules, is also the toggle for the
 * thread: the butterfly and the Bluesky post's counts on the left,
 * "Discussion" with a few repliers' avatars and an arrow on the right.
 * Ending the article with its own footer is what says "the end".
 */
.discussion {
  margin-top: 2.5rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  --avatar: 36px;
}

.bsky-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.7rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  list-style: none;
  /* It's a button: a quick double-click shouldn't select its words. */
  -webkit-user-select: none;
  user-select: none;
}

.bsky-footer::-webkit-details-marker {
  display: none;
}

.bsky-footer strong {
  color: var(--text);
}

/* Counts: words ("12 likes") where there's room, icons ("♡ 12") on the
   narrowest phones. The words stay for screen readers either way. */
.total {
  white-space: nowrap;
}

.total .icon {
  display: none;
}

/* Phones: tighter gaps, so the words still fit beside the faces. */
@media (max-width: 30rem) {
  .bsky-footer {
    gap: 0.7rem;
  }

  .open-discussion {
    gap: 0.45rem;
  }
}

/* The narrowest phones (320px): icons instead of words. Anything narrower
   wraps onto a second line rather than cutting off the arrow. */
@media (max-width: 22.5rem) {
  .bsky-footer {
    gap: 0.55rem;
  }

  .open-discussion {
    gap: 0.35rem;
  }

  .bsky-footer .total {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
  }

  .bsky-footer .total .icon {
    display: inline;
    color: var(--muted);
  }

  .bsky-footer .total-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

.bsky-mark {
  display: inline-flex;
  margin-right: -0.1rem;
  color: var(--muted);
}

.open-discussion {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
}

.open-discussion h2:not(.sr) {
  margin: 0;
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

/* Only where there's a real pointer: on touch screens a tap leaves the row
   "hovered" until you tap elsewhere, so the blue would stick. */
@media (hover: hover) {
  .bsky-footer:hover .bsky-mark {
    color: var(--accent);
  }

  .bsky-footer:hover::after {
    border-color: var(--accent);
  }
}

/* The arrow: down when folded, up when open. */
.bsky-footer::after {
  content: '';
  width: 0.4rem;
  height: 0.4rem;
  margin: 0 0.2rem 0 -0.4rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.15s;
}

details.discussion[open] > .bsky-footer::after {
  transform: rotate(-135deg) translate(-2px, -2px);
}

details.discussion[open] > .bsky-footer {
  margin-bottom: 1.5rem;
}

.bsky-footer:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.facepile {
  display: inline-flex;
}

.facepile img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--code-bg);
  box-shadow: 0 0 0 2px var(--bg);
}

.facepile img + img {
  margin-left: -6px;
}

/* When the thread couldn't be loaded, just a heading and a note. */
section.discussion {
  margin-top: 3rem;
}

section.discussion h2 {
  margin: 0 0 1rem;
}

.discussion .name {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.discussion .handle,
.discussion .dot,
.discussion .when {
  color: var(--muted);
}

.discussion .when {
  text-decoration: none;
}

.discussion .name:hover,
.discussion .when:hover {
  text-decoration: underline;
}

.avatar {
  flex: none;
  display: inline-block;
  border-radius: 50%;
  object-fit: cover;
  background: var(--code-bg);
}

.avatar.placeholder {
  background: linear-gradient(135deg, var(--rule), var(--muted));
  opacity: 0.6;
}

.post-text {
  margin: 0.15rem 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.thread-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0 0.3rem;
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.5;
  vertical-align: 0.1em;
}

/* The linked post: Bluesky's "main post" in a thread. */
.anchor {
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--rule);
}

.anchor-author {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.anchor-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.anchor-text {
  margin-top: 0.6rem;
  font-size: 1.05rem;
}

.anchor-time {
  margin: 0.75rem 0 0;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule);
  font-size: 0.8rem;
}

.anchor-time a {
  color: var(--muted);
  text-decoration: none;
}

.view-on-bsky {
  margin-left: auto;
  font-weight: 600;
}

.anchor-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  align-items: baseline;
  padding: 0.65rem 0;
  color: var(--muted);
}

.anchor-counts:empty {
  display: none;
}

.anchor-counts strong {
  color: var(--text);
}

.no-replies {
  margin-top: 1rem;
}

/* Replies: avatar column on the left, like the app. */
.replies,
.chain {
  list-style: none;
  margin: 0;
  padding: 0;
}

.reply-group {
  border-bottom: 1px solid var(--rule);
}

.replies.nested {
  margin-top: 0.25rem;
}

.replies.nested > .reply-group,
.reply-group:last-child {
  border-bottom: none;
}

.reply {
  position: relative;
  display: flex;
  gap: 0.65rem;
  padding: 0.8rem 0;
}

.reply.continues {
  padding-bottom: 0.35rem;
}

.reply.continues + .reply {
  padding-top: 0.35rem;
}

/* The line joining a reply to the one directly beneath it. */
.reply.continues::before {
  content: '';
  position: absolute;
  left: calc(var(--avatar) / 2 - 1px);
  top: calc(0.8rem + var(--avatar) + 4px);
  bottom: -0.35rem;
  border-left: 2px solid var(--rule);
}

.reply-avatar .avatar {
  display: block;
}

.reply-main {
  flex: 1;
  min-width: 0;
}

/*
 * Name · handle · time on one line, as on bsky.app. A long handle (or
 * name) is cut off with an ellipsis rather than pushing past the screen's
 * edge; the handle gives way, and the time never does.
 */
.reply-meta,
.quote-meta {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}

.reply-meta > *,
.quote-meta > * {
  flex: none;
}

.reply-meta .name,
.quote-meta .name,
.reply-meta .handle,
.quote-meta .handle,
.anchor-names .name,
.anchor-names .handle {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The name keeps its full width unless it's very long (then it's capped and
   cut), so only the handle shrinks for ordinary names. */
.reply-meta .name,
.quote-meta .name {
  flex: none;
  max-width: 65%;
}

.reply-meta .handle,
.quote-meta .handle {
  flex: 0 1000 auto;
}

.counts {
  display: flex;
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.count {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: 4.5rem;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.more {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
}

/* ---- embeds in replies ---- */

.embeds {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
  max-width: 28rem;
}

.embed-images {
  display: grid;
  gap: 4px;
  border-radius: 8px;
  overflow: hidden;
}

.embed-images.n2,
.embed-images.n4 {
  grid-template-columns: 1fr 1fr;
}

.embed-images.n3 {
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.embed-images.n3 a:first-child {
  grid-row: span 2;
}

.embed-images a {
  display: block;
  min-height: 0;
}

.embed-images img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--code-bg);
}

.embed-images.n1 img {
  height: auto;
  max-height: 22rem;
}

.embed-images.n2 img,
.embed-images.n4 img {
  aspect-ratio: 1;
}

.embed-images.n3 img {
  aspect-ratio: auto;
  min-height: 7rem;
}

.embed-video {
  position: relative;
  display: block;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

.embed-video img,
.embed-video-blank {
  display: block;
  width: 100%;
  max-height: 22rem;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.embed-video .play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
}

.embed-video .play .icon {
  padding: 0.7rem;
  box-sizing: content-box;
  border-radius: 50%;
  background: rgb(0 0 0 / 55%);
}

.embed-card {
  display: block;
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
}

.embed-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1.91 / 1;
  object-fit: cover;
  border-bottom: 1px solid var(--rule);
  background: var(--code-bg);
}

.embed-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.75rem;
}

.embed-card-title {
  font-weight: 600;
}

.embed-card-desc {
  color: var(--muted);
  font-size: 0.8rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.embed-card-domain {
  color: var(--muted);
  font-size: 0.75rem;
}

.embed-card:hover .embed-card-title {
  color: var(--accent);
}

.embed-quote {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  font-size: 0.85rem;
}

.quote-meta {
  font-size: 0.8rem;
}

/* A quoted post Bluesky won't show (blocked, deleted, detached, hidden). */
.embed-quote.unavailable {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  background: var(--code-bg);
}

/* A quoted post's media is a preview, not the main event. */
.embed-quote .embed-images img,
.embed-quote .embed-video img,
.embed-quote .embed-card img {
  max-height: 9rem;
}

.embed-quote .embed-images.n1 img {
  width: auto;
  max-width: 100%;
}

.embed-other {
  font-size: 0.8rem;
}
