@layer app {
  /* ============================================================
     Feed and post styles
     ============================================================ */

  .feed-post {
    --feed-reaction-size: 1.85rem;

    position: relative;
    border-color: color-mix(in srgb, var(--color-dark) 8%, transparent) !important;
  }

  .feed-post__header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .feed-post__meta {
    min-width: 0;
    flex: 1 1 auto;
  }

  .feed-post__author {
    line-height: 1.2;
  }

  .feed-post__time {
    display: inline-block;
    margin-top: 0.2rem;
    font-size: 0.875rem;
    color: color-mix(in srgb, var(--color-dark) 55%, transparent);
  }

  .feed-post__context {
    align-items: center;
    color: color-mix(in srgb, var(--color-dark) 45%, transparent);
    display: flex;
    flex-wrap: wrap;
    font-size: 0.82rem;
    gap: 0.35rem;

    .feed-post__time {
      font-size: inherit;
      margin-top: 0.15rem;
    }
  }

  .feed-post__location-context {
    display: none;
  }

  .feed-post__location {
    color: color-mix(in srgb, var(--color-dark) 64%, transparent);
    font-weight: 600;
    margin-top: 0.15rem;
    text-decoration: none;

    &:hover {
      color: var(--color-primary);
    }
  }

  .feed-post--preview {
    background: rgba(255, 255, 255, 0.62) !important;
  }

  .media-preview {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .media-preview-thumb {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--color-dark) 12%, transparent);
  }

  .media-preview-file {
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 4rem;
    padding: 0.65rem;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--color-dark) 12%, transparent);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.72);
    font-size: 0.82rem;
    text-overflow: ellipsis;
  }

  .feed-post-media {
    --feed-post-image-columns: minmax(0, 1fr);
    --feed-post-image-max-height: 520px;
    --feed-post-image-ratio: auto;

    display: grid;
    grid-template-columns: var(--feed-post-image-columns);
    gap: 0.4rem;

    &.feed-post-media--grid {
      --feed-post-image-columns: repeat(3, minmax(0, 1fr));
      --feed-post-image-max-height: none;
      --feed-post-image-ratio: 1 / 1;
    }
  }

  .feed-post-image-button {
    border: 0;
    padding: 0;
    background: transparent;
    border-radius: 10px;
    overflow: hidden;
    cursor: zoom-in;
  }

  .feed-post-media-item {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    max-height: var(--feed-post-image-max-height);
    aspect-ratio: var(--feed-post-image-ratio);
  }

  .feed-post-video {
    background: color-mix(in srgb, var(--color-dark) 92%, transparent);
  }

  .feed-post-video-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 8rem;
    background: color-mix(in srgb, var(--color-dark) 8%, transparent);
    color: color-mix(in srgb, var(--color-dark) 58%, transparent);
    font-size: 2rem;
  }

  .feed-post-file {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    min-height: 5rem;
    padding: 0.75rem;
    border: 1px solid color-mix(in srgb, var(--color-dark) 12%, transparent);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.72);
    color: color-mix(in srgb, var(--color-dark) 82%, transparent);
    text-decoration: none;
  }

  .feed-post-file__name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .feed-post-file--preview {
    color: color-mix(in srgb, var(--color-dark) 58%, transparent);
  }

  .feed-post-media--grid .feed-post-file {
    flex-direction: column;
    justify-content: center;
    aspect-ratio: 1 / 1;
    text-align: center;
  }

  .lightbox-modal {
    background: rgba(12, 18, 36, 0.86);

    .modal-content {
      box-shadow: none;
    }
  }

  .lightbox-image {
    width: 100%;
    /* Cap tall images against the dynamic viewport so the allowance adjusts as
       mobile browser chrome expands or retracts. */
    max-height: 85vh;
    max-height: 85dvh;
    object-fit: contain;
    border-radius: 12px;
    filter: none !important;
  }

  .modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    background-color: rgba(0, 0, 0, 0.45);
    border-radius: 999px;
    padding: 0.6rem;
  }

  .feed-post__body {
    p {
      margin-bottom: 0.5rem;
    }

    p:last-child {
      margin-bottom: 0;
    }
  }

  .feed-post__content {
    position: relative;
  }

  .feed-post__tags {
    margin-top: 0.55rem;
  }

  .post-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.35rem;
    max-width: 100%;

    &:not(:has(.post-tag, .post-tags__editor)) {
      display: none;
    }
  }

  .post-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.08rem;
    min-height: 1.75rem;
    max-width: 100%;
    padding: 0.12rem 0.58rem;
    border: 1px solid color-mix(in srgb, var(--color-primary) 18%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--color-primary) 7%, transparent);
    color: color-mix(in srgb, var(--color-dark) 72%, transparent);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.4;

    &:disabled {
      opacity: 1;
      cursor: default;
    }
  }

  .post-tag__name {
    max-width: 28ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .post-tags__editor {
    max-width: 100%;

    &:has(.tags-form) {
      flex: 1 1 15rem;
    }
  }

  .tags-form {
    width: min(100%, 29rem);
    margin: 0;
  }

  .tags-form__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--color-primary) 20%, transparent);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.96);
    color: color-mix(in srgb, var(--color-primary) 70%, transparent);
    box-shadow: 0 1px 2px color-mix(in srgb, var(--color-dark) 5%, transparent);
    transition: border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;

    &:hover {
      border-color: color-mix(in srgb, var(--color-primary) 50%, transparent);
      color: var(--color-primary);
      box-shadow: 0 4px 10px color-mix(in srgb, var(--color-dark) 9%, transparent);
      transform: translateY(-1px);
    }
  }

  .tags-form__shell {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    width: 100%;
    padding: 0.12rem 0.4rem 0.12rem 0.55rem;
    border: 1px solid color-mix(in srgb, var(--color-primary) 70%, transparent);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 6px 20px color-mix(in srgb, var(--color-dark) 10%, transparent);
  }

  .tags-form:focus-within .tags-form__shell {
    border-color: color-mix(in srgb, var(--color-primary) 90%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 14%, transparent);
  }

  .tags-form__icon {
    flex: 0 0 auto;
    color: color-mix(in srgb, var(--color-primary) 70%, transparent);
  }

  .tags-form__input {
    --color-body-bg: transparent;

    flex: 1 1 8rem;
    min-width: 0;
    padding: 0 0.1rem;
    border: 0;
    background: transparent;
    box-shadow: none !important;
    font-size: 16px;

    &::placeholder {
      color: color-mix(in srgb, var(--color-dark) 35%, transparent);
    }
  }

  .tags-form__action {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    transition: transform 0.2s ease;

    &:hover {
      transform: scale(1.05);
    }
  }

  .tags-form__action--submit {
    color: var(--color-success);
  }

  .tags-form__action--close {
    color: #d95f0e;
  }

  .tags-form__hint {
    margin: 0.28rem 0.2rem 0;
    color: color-mix(in srgb, var(--color-dark) 50%, transparent);
    font-size: 0.75rem;
    line-height: 1.35;
  }

  .tags-form__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    max-height: 8rem;
    margin-top: 0.4rem;
    padding: 0.5rem;
    overflow-y: auto;
    border: 1px solid color-mix(in srgb, var(--color-dark) 10%, transparent);
    border-radius: 0.85rem;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 10px 24px color-mix(in srgb, var(--color-dark) 8%, transparent);
  }

  .tags-form__suggestion {
    padding: 0.18rem 0.55rem;
    border: 1px solid color-mix(in srgb, var(--color-primary) 16%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--color-primary) 6%, transparent);
    color: color-mix(in srgb, var(--color-dark) 75%, transparent);
    font-size: 0.78rem;
    font-weight: 600;

    &:hover,
    &:focus-visible {
      border-color: color-mix(in srgb, var(--color-primary) 45%, transparent);
      background: color-mix(in srgb, var(--color-primary) 12%, transparent);
      color: var(--color-primary);
    }
  }

  .feed-post:not(.feed-post--preview):has(.reactions:not(:has(.reaction))) .post-tags {
    padding-inline-end: calc(var(--feed-reaction-size) + 0.55rem);
  }

  .feed-post__reactions {
    margin-top: 0.45rem;
  }

  .reactions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
  }

  /* Anchored to the bottom of the content box, which is where the spacer
     reserved for it sits — it trails the last line of the post rather than
     covering the first one. */
  .reactions:not(:has(.reaction)) {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 2;
    margin-top: 0;
    width: auto;
  }

  .reactions:has(.reaction-form) {
    position: static;
    margin-top: 0.55rem;
  }

  .feed-post:has(.reactions:not(:has(.reaction))) .feed-post__body {
    padding-inline-end: calc(var(--feed-reaction-size) + 0.55rem);
  }

  .feed-post:has(.reactions:not(:has(.reaction))) .feed-post__body p:last-child::after {
    content: "";
    display: inline-block;
    inline-size: calc(var(--feed-reaction-size) + 0.35rem);
  }

  .reactions__list {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;

    &:not(:has(.reaction)) {
      display: none;
    }
  }

  .reaction {
    display: inline-flex;
  }

  .reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    min-height: var(--feed-reaction-size);
    max-width: 100%;
    padding: 0.16rem 0.4rem 0.16rem 0.12rem;
    border: 1px solid color-mix(in srgb, var(--color-dark) 12%, transparent);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    color: color-mix(in srgb, var(--color-dark) 90%, transparent);
    font-size: 0.92rem;
    line-height: 1.5;
    text-decoration: none;
    box-shadow: 0 1px 2px color-mix(in srgb, var(--color-dark) 5%, transparent);
  }

  .reaction--deletable .reaction-chip {
    transition: opacity 0.15s ease, transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;

    &:hover {
      border-color: color-mix(in srgb, var(--color-primary) 35%, transparent);
      box-shadow: 0 4px 10px color-mix(in srgb, var(--color-dark) 9%, transparent);
    }
  }

  .reaction:not(.reaction--deletable) .reaction-chip__content-button,
  .reaction:not(.reaction--deletable) .reaction-chip__delete-form {
    display: none;
  }

  .reaction--deletable .reaction-chip__content-static {
    display: none;
  }

  .reaction-chip__content-button {
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    min-height: inherit;
    max-width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: inherit;
  }

  .reaction-chip__content-static {
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    line-height: 1.5;
  }

  .reaction-chip__delete-form {
    display: none;
    margin: 0;
  }

  .reaction--expanded .reaction-chip {
    padding-right: 0.16rem;
  }

  .reaction--expanded .reaction-chip__delete-form {
    display: inline-flex;
  }

  .reaction-chip__delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.2rem;
    height: 1.2rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: var(--color-danger);
    color: #fff;
    box-shadow: 0 1px 2px color-mix(in srgb, var(--color-dark) 14%, transparent);

    .icon {
      font-size: 0.75rem;
      line-height: 1;
    }
  }

  .reaction-chip__avatars {
    display: inline-flex;
    align-items: center;
  }

  .reaction-chip__avatar {
    display: inline-flex;
    margin-left: -0.4rem;

    &:first-child {
      margin-left: 0;
    }

    .avatar {
      box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.96);
    }
  }

  .reaction-chip__content {
    max-width: 16ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.5;
  }

  .feed-post__replies {
    margin-top: 0.85rem;
  }

  .reply-thread {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
  }

  .reply-thread__list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .reply-thread__list:not(:has(> *)) {
    display: none;
  }

  .reply-thread__list > turbo-frame[role="presentation"] {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .reply-thread__list > turbo-frame[role="presentation"][complete] {
    animation: reply-page-appear 440ms ease-out;
  }

  .pagination-link {
    align-self: center;
  }

  .pagination-link--active-when-observed {
    display: block;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
  }

  .reply-thread__list .pagination-link {
    display: none;
  }

  .reply-thread__list > turbo-frame:first-of-type .pagination-link {
    display: inline;
  }

  @keyframes reply-page-appear {
    from {
      opacity: 0;
      transform: translateY(-0.35rem) scale(0.995);
    }

    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .reply-thread__list > turbo-frame[role="presentation"][complete] {
      animation: none;
    }
  }

  .separator {
    width: 100%;
    height: 1px;
    background: color-mix(in srgb, var(--color-dark) 8%, transparent);
  }

  .reply-thread__item {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
  }

  .reply-thread__avatar {
    display: inline-flex;
    flex-shrink: 0;
    padding-top: 0.05rem;
  }

  .reply-thread__bubble {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.72rem 0.85rem;
    border: 1px solid color-mix(in srgb, var(--color-dark) 8%, transparent);
    border-radius: 1.1rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), color-mix(in srgb, var(--color-light) 85%, transparent));
    box-shadow: 0 10px 24px color-mix(in srgb, var(--color-dark) 5%, transparent);
  }

  .reply-thread__meta {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.3rem 0.6rem;
    margin-bottom: 0.3rem;
  }

  .reply-thread__author {
    font-size: 0.96rem;
    font-weight: 600;
    line-height: 1.2;
    color: color-mix(in srgb, var(--color-dark) 92%, transparent);
  }

  .reply-thread__time {
    font-size: 0.82rem;
    color: color-mix(in srgb, var(--color-dark) 50%, transparent);
  }

  .reply-thread__content {
    color: color-mix(in srgb, var(--color-dark) 82%, transparent);
    font-size: 0.85rem;
    line-height: 1.55;

    p {
      margin-bottom: 0.35rem;
    }

    p:last-child {
      margin-bottom: 0;
    }
  }

  .reply-composer {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .reply-composer__form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .reply-composer__form > .field_with_errors {
    flex: 1 1 auto;
    min-width: 0;
  }

  .reply-composer__input {
    --color-body-bg: transparent;

    flex: 1 1 auto;
    width: 100%;
    height: 22px !important;
    min-height: 22px !important;
    max-height: 8rem;
    padding: 0;
    border: 0;
    border-radius: 0;
    resize: none;
    background: inherit;
    color: inherit;
    box-shadow: none !important;
    font-size: 16px;
    line-height: 22px;
    overflow-y: hidden;

    &:focus {
      background: inherit;
    }

    &.is-invalid {
      background-image: none;
      border: 0;
    }

    &::placeholder {
      color: color-mix(in srgb, var(--color-dark) 35%, transparent);
    }
  }

  .reply-composer__form .reply-composer__submit {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    height: 22px;
    padding-block: 0;
    padding-inline: 0.55rem;
    font-size: 0.75rem;
    line-height: 1;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 1s ease, visibility 1s ease;
  }

  .reply-composer__form:has(.reply-composer__input:valid) .reply-composer__submit {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .reaction-form {
    display: inline-flex;
    position: relative;
    z-index: 3;
  }

  .reaction-form--expanded {
    display: block;
  }

  .reaction-form__panel {
    width: min(100%, 29rem);
    max-width: 100%;
    position: relative;
  }

  .reaction-form__controls {
    margin: 0;
  }

  .reaction-form__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--feed-reaction-size);
    height: var(--feed-reaction-size);
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--color-dark) 12%, transparent);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.96);
    color: color-mix(in srgb, var(--color-dark) 55%, transparent);
    box-shadow: 0 1px 2px color-mix(in srgb, var(--color-dark) 5%, transparent);
    transition: border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;

    &:hover {
      color: color-mix(in srgb, var(--color-dark) 80%, transparent);
      border-color: color-mix(in srgb, var(--color-primary) 35%, transparent);
      box-shadow: 0 4px 10px color-mix(in srgb, var(--color-dark) 9%, transparent);
      transform: translateY(-1px);
    }

    .icon {
      font-size: 0.98rem;
    }
  }

  .reaction-form__shell {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    width: min(100%, 29rem);
    padding: 0.1rem 0.4rem 0.1rem 0.12rem;
    border: 1px solid color-mix(in srgb, var(--color-primary) 70%, transparent);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 6px 20px color-mix(in srgb, var(--color-dark) 12%, transparent);
  }

  .reaction-form__controls:focus-within .reaction-form__shell {
    border-color: color-mix(in srgb, var(--color-primary) 90%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 14%, transparent);
  }

  .reaction-form__avatar {
    display: inline-flex;
    flex-shrink: 0;
  }

  .reaction-form__input {
    --color-body-bg: transparent;

    flex: 1 1 5rem;
    min-width: 0;
    max-width: 16ch;
    padding: 0 0.1rem;
    border: 0;
    background: transparent;
    box-shadow: none !important;
    font-size: 16px;

    &::placeholder {
      color: color-mix(in srgb, var(--color-dark) 35%, transparent);
    }
  }

  .reaction-form__emoji-toggle {
    color: color-mix(in srgb, var(--color-dark) 86%, transparent);
  }

  .reaction-form__picker-wrap {
    display: inline-flex;
  }

  .reaction-form__emoji-toggle,
  .reaction-form__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    transition: transform 0.2s ease, opacity 0.2s ease;

    &:hover {
      transform: scale(1.05);
    }

    .icon {
      font-size: 1.25rem;
      line-height: 1;
    }
  }

  .reaction-form__action--submit {
    color: var(--color-success);
  }

  .reaction-form__action--close {
    color: #d95f0e;
  }

  .reaction-form__picker {
    position: absolute;
    top: calc(100% + 0.3rem);
    left: 0;
    right: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.25rem;
    width: 100%;
    padding: 0.65rem;
    border: 1px solid color-mix(in srgb, var(--color-dark) 12%, transparent);
    border-radius: 1.2rem;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 18px 36px color-mix(in srgb, var(--color-dark) 14%, transparent);
  }

  .reaction-form__panel:not(.reaction-form__panel--picker-visible) .reaction-form__picker {
    display: none;
  }

  .reaction-form__emoji {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.9rem;
    min-height: 1.9rem;
    padding: 0 0.1rem;
    border: 0;
    border-radius: 999px;
    background: transparent;
    font-size: 1.2rem;
    transition: background-color 0.2s ease, transform 0.2s ease;

    &:hover {
      background: color-mix(in srgb, var(--color-primary) 8%, transparent);
      transform: scale(1.14);
    }
  }

  @media (max-width: 640px) {
    .feed-post {
      --feed-reaction-size: 2rem;
    }

    .reply-thread__item,
    .reply-composer {
      gap: 0.2rem;
    }

    .reply-thread__bubble {
      padding: 0.68rem 0.75rem;
    }

    .reaction-form__shell {
      width: min(100vw - 2rem, 100%);
    }

    .reaction-form__picker {
      width: 100%;
      grid-template-columns: repeat(6, minmax(0, 1fr));
    }
  }

  .feed-post--preview {
    .feed-post__tags {
      margin-top: 0.4rem;
    }

    .post-tag {
      min-height: 1.55rem;
      padding: 0.1rem 0.45rem;
      font-size: 0.75rem;
    }

    .feed-post__reactions {
      margin-top: 0.4rem;
    }

    .reaction-chip {
      min-height: 1.65rem;
      padding: 0.14rem 0.32rem 0.14rem 0.12rem;
      font-size: 0.8rem;
    }

    .reaction-chip__delete {
      width: 1.05rem;
      height: 1.05rem;

      .icon {
        font-size: 0.68rem;
      }
    }

    .reaction-form {
      display: none;
    }
  }
}
