/* atproto-comments — base styles
   Theming: override --atproto-* custom properties to match your site.
   All structural classes use the .atproto- prefix to avoid collisions.
   The element also carries the class .atproto-comments, so the styles apply
   under any tag name. :where() keeps that class at zero specificity, so
   `atproto-comments { … }` overrides keep winning as before. */

atproto-comments,
:where(.atproto-comments) {
  --atproto-font-family: system-ui, -apple-system, sans-serif;
  --atproto-font-size: 0.875rem;
  --atproto-color-text: inherit;
  --atproto-color-muted: oklch(50% 0 0);
  --atproto-color-border: oklch(85% 0 0);
  --atproto-color-surface: oklch(97% 0 0);
  --atproto-avatar-size: 2rem;
  --atproto-avatar-bg: oklch(60% 0.1 250);
  --atproto-avatar-color: white;

  display: block;
  color: var(--atproto-color-text);
}

/* Lists */
.atproto-comments__list,
.atproto-reply__replies {
  list-style: none;
  margin: 0;
  padding: 0;
}

.atproto-comments__error {
  margin: 0;
  font-family: var(--atproto-font-family);
  font-size: var(--atproto-font-size);
  color: var(--atproto-color-muted);
}

/* Reply: grid layout
   col 1 = avatar-wrap, col 2 = content
   row 1 = main content, row 2 = nested replies */
.atproto-reply {
  display: grid;
  grid-template-columns: var(--atproto-avatar-size) 1fr;
  column-gap: 0.5rem;
  font-family: var(--atproto-font-family);
  line-height: 1.5;
}

/* Avatar column — thread line extends downward when replies exist */
.atproto-reply__avatar-wrap {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.atproto-reply:has(> .atproto-reply__replies) .atproto-reply__avatar-wrap::after {
  content: '';
  flex: 1;
  width: 2px;
  background: var(--atproto-color-border);
  position: absolute;
  top: var(--atproto-avatar-size);
  bottom: 0;
}

.atproto-reply__replies > li {
  position: relative;
}

.atproto-reply__item--last > .atproto-reply:not(:has(> .atproto-reply__replies)) > .atproto-reply__avatar-wrap::after {
  display: none;
}

/* Avatar image */
.atproto-reply__avatar {
  width: var(--atproto-avatar-size);
  height: var(--atproto-avatar-size);
  border-radius: 50%;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

/* Avatar placeholder */
.atproto-reply__avatar--placeholder {
  width: var(--atproto-avatar-size);
  height: var(--atproto-avatar-size);
  border-radius: 50%;
  background: var(--atproto-avatar-bg);
  color: var(--atproto-avatar-color);
  font-family: var(--atproto-font-family);
  font-size: calc(var(--atproto-font-size) * 0.9);
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
}

/* Content column */
.atproto-reply__content {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  margin-bottom: 0.75rem;
}

/* Nested replies span full grid width */
.atproto-reply__replies {
  grid-column: 1 / -1;
  grid-row: 2;
}

.atproto-reply__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.25rem;
  /* Name, handle and time share one size; the name stands out by weight only. */
  font-size: var(--atproto-font-size);
}

/* Name and handle share one flex item so the space between them is rendered
   text (otherwise iOS reads "Name@handle.domain" as an email). */
.atproto-reply__byline {
  min-width: 0;
  overflow-wrap: anywhere;
}

.atproto-reply__handle,
.atproto-reply__time {
  color: var(--atproto-color-muted);
}

/* Author and date link to the profile and the reply; they look as in 1.x
   until hovered or focused. */
a.atproto-reply__byline {
  color: inherit;
  text-decoration: none;
}

.atproto-reply__permalink {
  color: var(--atproto-color-muted);
  text-decoration: none;
}

a.atproto-reply__byline:hover,
a.atproto-reply__byline:focus-visible,
.atproto-reply__permalink:hover,
.atproto-reply__permalink:focus-visible {
  text-decoration: underline;
}

/* Outside the <time>, inside the link's box. Inline-block keeps the hover
   underline off the separator; the non-breaking space survives it. Without a
   link (no author DID) it goes on the <time>. */
.atproto-reply__permalink::before,
.atproto-reply__header > .atproto-reply__time::before {
  content: "\00b7\00a0";
  display: inline-block;
}

.atproto-reply__more {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: var(--atproto-font-size);
  color: var(--atproto-color-muted);
}

.atproto-reply__text {
  font-family: var(--atproto-font-family);
  font-size: var(--atproto-font-size);
  margin: 0.25rem 0 0;
}

/* App action (the button that opens the app picker) */
.atproto-app-action {
  margin-top: 0.25rem;
}

.atproto-app-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--atproto-font-family);
  font-size: var(--atproto-font-size);
  color: var(--atproto-color-muted);
  padding: 0;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: color 0.15s, text-decoration-color 0.15s;
}

.atproto-app-btn:hover {
  color: var(--atproto-color-text);
  text-decoration-color: currentColor;
}

.atproto-app-btn--xl {
  font-size: 1rem;
}

/* App picker: a modal <dialog> anchored to the bottom of the viewport, full
   width, with its content in a centred column. It lives in the light DOM, so
   every element resets what page styles for p, ul, a, button and input could
   change. */
.atproto-app-sheet {
  position: fixed;
  inset: auto 0 0 0;
  box-sizing: border-box;
  margin: 0;
  width: 100%;
  max-width: 100%;
  max-height: 85vh;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 0 env(safe-area-inset-bottom);
  border: 0;
  border-top: 1px solid var(--atproto-color-border);
  border-radius: 0.75rem 0.75rem 0 0;
  background: Canvas;
  color: CanvasText;
  font-family: var(--atproto-font-family);
  font-size: var(--atproto-font-size);
  line-height: 1.5;
  text-align: start;
}

@supports (max-height: 85dvh) {
  .atproto-app-sheet {
    max-height: 85dvh;
  }
}

.atproto-app-sheet:not([open]) {
  display: none;
}

.atproto-app-sheet::backdrop {
  background: oklch(0% 0 0 / 40%);
}

.atproto-app-sheet__body {
  box-sizing: border-box;
  max-width: 36rem;
  margin-inline: auto;
  padding: 1rem;
}

.atproto-app-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
}

/* Inherited text styles the page may set on p, li, a, label, button or input. */
.atproto-app-sheet,
.atproto-app-sheet__title,
.atproto-app-sheet__note,
.atproto-app-sheet__list,
.atproto-app-sheet__list > li,
.atproto-app-sheet__app,
.atproto-app-sheet__label,
.atproto-app-sheet__input,
.atproto-app-sheet__close,
.atproto-app-sheet__go {
  text-transform: none;
  letter-spacing: normal;
  text-shadow: none;
  text-indent: 0;
}

.atproto-app-sheet__title,
.atproto-app-sheet__note {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
}

.atproto-app-sheet__title {
  font-size: 1rem;
  font-weight: 600;
}

.atproto-app-sheet__note {
  margin: 0 0 0.75rem;
  color: var(--atproto-color-muted);
}

.atproto-app-sheet__close,
.atproto-app-sheet__go {
  box-sizing: border-box;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  min-height: 2.25rem;
  margin: 0;
  padding: 0 0.5rem;
  border: 1px solid var(--atproto-color-border);
  border-radius: 0.5em;
  background: none;
  box-shadow: none;
  color: inherit;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  cursor: pointer;
}

.atproto-app-sheet__close {
  border-color: transparent;
}

.atproto-app-sheet__close:hover,
.atproto-app-sheet__go:hover {
  background: var(--atproto-color-surface);
}

.atproto-app-sheet__list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}

.atproto-app-sheet__list > li {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  list-style: none;
}

.atproto-app-sheet__list > li::before,
.atproto-app-sheet__list > li::marker {
  content: none;
}

.atproto-app-sheet__app {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--atproto-color-border);
  border-radius: 0.5em;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: none;
}

.atproto-app-sheet__app:hover,
.atproto-app-sheet__app:focus-visible,
.atproto-app-sheet__app--last-used {
  background: var(--atproto-color-surface);
  color: inherit;
  text-decoration: none;
}

.atproto-app-sheet__name {
  font-weight: 600;
}

.atproto-app-sheet__badge {
  padding: 0 0.5em;
  border: 1px solid var(--atproto-color-border);
  border-radius: 999px;
  color: var(--atproto-color-muted);
  font-size: 0.75rem;
}

.atproto-app-sheet__arrow {
  margin-inline-start: auto;
  color: var(--atproto-color-muted);
}

.atproto-app-sheet__custom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0 0;
  padding: 0;
}

.atproto-app-sheet__label {
  flex-basis: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--atproto-color-muted);
  font: inherit;
}

.atproto-app-sheet__input {
  box-sizing: border-box;
  flex: 1;
  min-width: 0;
  width: auto;
  height: auto;
  min-height: 2.25rem;
  margin: 0;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--atproto-color-border);
  border-radius: 0.5em;
  background: Canvas;
  box-shadow: none;
  color: CanvasText;
  font: inherit;
}

/* Slides in from the bottom where @starting-style exists; elsewhere it just appears. */
@media (prefers-reduced-motion: no-preference) {
  .atproto-app-sheet[open] {
    transform: translateY(0);
    transition: transform 0.2s ease-out;
  }

  @starting-style {
    .atproto-app-sheet[open] {
      transform: translateY(100%);
    }
  }
}
