:root {
  --emalm-post-preview-bg: color-mix(in srgb, var(--emalm-ui-surface-1) 78%, transparent);
  --emalm-post-preview-border: color-mix(in srgb, var(--emalm-ui-border) 62%, transparent);
  --emalm-post-preview-hover-bg: color-mix(in srgb, var(--emalm-ui-surface-1) 72%, var(--emalm-ui-accent-soft) 28%);
  --emalm-post-preview-hover-border: color-mix(in srgb, var(--emalm-ui-accent) 48%, var(--emalm-ui-border) 52%);
  --emalm-post-preview-shadow: var(--emalm-ui-shadow-soft);
  --emalm-post-status-pending: #2f80ed;
  --emalm-post-status-flagged: #d23b3b;
  --emalm-post-status-deleted: var(--emalm-ui-text-muted);
  --emalm-post-status-has-children: #2e9d45;
  --emalm-post-status-has-parent: #f3a51c;
}

.post-gallery {
  max-width: 100%;
}

.media-results-grid > .post-gallery {
  grid-column: 1 / -1;
  width: 100%;
}

.post-gallery .posts-container {
  align-items: start;
  gap: 8px;
}

.post-gallery-grid .posts-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--post-preview-grid-size, 180px), var(--post-preview-grid-size, 180px)));
  justify-content: start;
}

.post-gallery-inline .posts-container {
  display: flex;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 6px;
}

.post-gallery-150 { --post-preview-size: 150px; --post-preview-grid-size: 150px; }
.post-gallery-180 { --post-preview-size: 180px; --post-preview-grid-size: 180px; }
.post-gallery-225 { --post-preview-size: 225px; --post-preview-grid-size: 225px; }
.post-gallery-270 { --post-preview-size: 270px; --post-preview-grid-size: 270px; }
.post-gallery-360 { --post-preview-size: 360px; --post-preview-grid-size: 360px; }
.post-gallery-540 { --post-preview-size: 540px; --post-preview-grid-size: 540px; }
.post-gallery-720 { --post-preview-size: 720px; --post-preview-grid-size: 720px; }

.post-preview {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  box-sizing: border-box;
  color: inherit;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  min-width: 0;
  padding: 6px;
  position: relative;
  transition: background-color 130ms ease, border-color 130ms ease, box-shadow 130ms ease, transform 130ms ease;
}

.post-gallery-inline .post-preview {
  flex: 0 0 var(--post-preview-size, 180px);
  width: var(--post-preview-size, 180px);
}

.post-preview:hover,
.post-preview:focus-within {
  background: var(--emalm-post-preview-hover-bg);
  border-color: var(--emalm-post-preview-hover-border);
  box-shadow: var(--emalm-post-preview-shadow);
  transform: translateY(-2px);
}

.post-preview.card-outlined {
  background: var(--emalm-post-preview-bg);
  border-color: var(--emalm-post-preview-border);
}

.post-preview.card-outlined:hover,
.post-preview.card-outlined:focus-within {
  background: var(--emalm-post-preview-hover-bg);
  border-color: var(--emalm-post-preview-hover-border);
}

.post-preview-container,
.post-preview-link {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: var(--post-preview-size, 180px);
  min-width: 0;
  overflow: hidden;
  width: 100%;
}

.post-preview-link {
  color: inherit;
  text-decoration: none;
}

.post-preview-fit-compact .post-preview-image,
.post-preview-fit-compact picture,
.post-preview-fit-compact video,
.post-preview-fit-compact .audio-thumb-visual,
.post-preview-fit-compact .blender-thumb-visual,
.post-preview-fit-compact .document-thumb-visual,
.post-preview-fit-compact .image-thumb-placeholder,
.post-preview-fit-compact .swf-thumb-visual,
.post-preview-fit-compact .midi-thumb-visual {
  display: block;
  height: auto;
  max-height: var(--post-preview-size, 180px);
  max-width: 100%;
  object-fit: contain;
}

.post-preview-fit-fixed .post-preview-image,
.post-preview-fit-fixed video {
  height: var(--post-preview-size, 180px);
  object-fit: cover;
  width: var(--post-preview-size, 180px);
}

.post-preview-image {
  background: #fff;
  border: 2px solid transparent;
  box-sizing: border-box;
}

.image-thumb-placeholder {
  align-items: center;
  aspect-ratio: 1 / 1;
  background: var(--emalm-ui-surface-2);
  border: 1px solid var(--emalm-ui-border);
  color: var(--emalm-ui-text-muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  justify-content: center;
  letter-spacing: 0;
  max-width: 100%;
  min-width: 96px;
}

.post-status-pending .post-preview-image {
  border-color: var(--emalm-post-status-pending);
}

.post-status-flagged .post-preview-image {
  border-color: var(--emalm-post-status-flagged);
}

.post-status-deleted .post-preview-image {
  border-color: var(--emalm-post-status-deleted);
}

.post-status-has-children .post-preview-container {
  border: 4px solid var(--emalm-post-status-has-children);
}

.post-status-has-parent .post-preview-container {
  border: 4px solid var(--emalm-post-status-has-parent);
}

.post-status-has-parent.post-status-has-children .post-preview-container {
  border-top-color: var(--emalm-post-status-has-parent);
  border-bottom-color: var(--emalm-post-status-has-children);
  border-left-color: color-mix(in srgb, var(--emalm-post-status-has-parent) 50%, var(--emalm-post-status-has-children) 50%);
  border-right-color: color-mix(in srgb, var(--emalm-post-status-has-parent) 50%, var(--emalm-post-status-has-children) 50%);
}

.post-preview-placeholder {
  align-items: center;
  background: color-mix(in srgb, var(--emalm-ui-surface-2) 76%, transparent);
  border: 1px solid var(--emalm-ui-border);
  color: var(--emalm-ui-text-muted);
  display: flex;
  font-size: 12px;
  justify-content: center;
  min-height: var(--post-preview-size, 180px);
  padding: 10px;
  text-align: center;
  width: 100%;
}

.post-preview-score {
  font-size: 12px;
  margin-top: 4px;
  text-align: center;
}

.post-votes {
  align-items: center;
  display: inline-flex;
  gap: 4px;
  justify-content: center;
}

.post-vote-button {
  background: color-mix(in srgb, var(--emalm-ui-surface, #fff) 88%, var(--emalm-ui-text-muted, #777));
  border: 1px solid color-mix(in srgb, var(--emalm-ui-border, #d6d6d6) 82%, transparent);
  border-radius: 999px;
  color: var(--emalm-ui-text-muted);
  cursor: pointer;
  font-weight: 800;
  min-width: 22px;
  line-height: 1;
  padding: 3px 6px;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, color 140ms ease, transform 140ms ease;
}

.post-vote-button:hover,
.post-vote-button.active-link,
.post-vote-button.is-active {
  color: var(--emalm-ui-link);
  transform: translateY(-1px);
}

.post-upvote-link.active-link,
.post-upvote-link.is-active {
  background: linear-gradient(135deg, #16883a, #35c96f);
  border-color: #11732f;
  box-shadow: 0 0 0 3px rgba(22, 136, 58, 0.26), 0 8px 18px rgba(22, 136, 58, 0.36);
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 74, 24, 0.38);
}

.post-downvote-link.active-link,
.post-downvote-link.is-active {
  background: linear-gradient(135deg, #c92a2a, #ff6b6b);
  border-color: #aa1f1f;
  box-shadow: 0 0 0 3px rgba(201, 42, 42, 0.26), 0 8px 18px rgba(201, 42, 42, 0.34);
  color: #fff;
  text-shadow: 0 1px 1px rgba(99, 13, 13, 0.38);
}

.post-vote-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.post-vote-button.emalm-interaction-pop {
  animation: emalm-interaction-pop 520ms cubic-bezier(.2, 1.4, .4, 1);
}

.post-preview-container {
  position: relative;
}

.post-preview-favorite-badge {
  align-items: center;
  background: linear-gradient(135deg, #ff4f8b, #ff8a4f);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(166, 30, 77, 0.28);
  color: #fff;
  display: none;
  font-size: 11px;
  font-weight: 800;
  gap: 4px;
  line-height: 1;
  padding: 5px 7px;
  pointer-events: none;
  position: absolute;
  right: 6px;
  text-shadow: 0 1px 1px rgba(90, 0, 25, 0.32);
  top: 6px;
  z-index: 2;
}

.post-preview[data-is-favorited="true"] .post-preview-favorite-badge {
  display: inline-flex;
}

.post-preview[data-is-favorited="true"] .post-preview-container {
  border-radius: 10px;
  box-shadow: 0 0 0 3px rgba(255, 79, 139, 0.28), 0 10px 22px rgba(166, 30, 77, 0.18);
}

.post-preview[data-is-favorited="true"] .post-preview-link {
  border-radius: inherit;
}

.post-preview[data-is-favorited="true"] .post-preview-favorite-badge {
  background: linear-gradient(135deg, #ff2f77, #ff8a4f);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.72), 0 8px 20px rgba(166, 30, 77, 0.36);
  padding: 6px 9px;
}

.emalm-interaction-burst {
  animation: emalm-interaction-burst 700ms ease-out forwards;
  color: #ff78a5;
  font-size: 18px;
  font-weight: 900;
  left: 0;
  line-height: 1;
  pointer-events: none;
  position: absolute;
  text-shadow: 0 1px 0 #fff, 0 6px 12px rgba(0, 0, 0, 0.16);
  top: 0;
  transform: translate(-50%, -50%);
  z-index: 9999;
}

.emalm-interaction-burst--upvote {
  color: #24b84f;
}

.emalm-interaction-burst--downvote {
  color: #7c6cff;
}

@keyframes emalm-interaction-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22) rotate(-4deg); }
  100% { transform: scale(1); }
}

@keyframes emalm-interaction-burst {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5) rotate(0deg); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -185%) scale(1.55) rotate(20deg); }
}

.post-preview-title {
  font-size: 12px;
  line-height: 1.18;
  margin-top: 6px;
  overflow-wrap: anywhere;
  text-align: center;
}

.post-preview-title a {
  color: var(--text-color, var(--emalm-ui-text));
  text-decoration: none;
}

.post-preview-title a:hover,
.post-preview-title a:focus {
  color: var(--link-hover-color, var(--emalm-ui-link-hover));
  text-decoration: underline;
}

.post-preview .pool-preview-cover {
  align-items: center;
  display: flex;
  height: var(--post-preview-size, 180px);
  justify-content: center;
  max-width: 100%;
  width: 100%;
}

.post-preview .pool-preview-cover img,
.post-preview .pool-preview-cover svg {
  max-height: var(--post-preview-size, 180px);
  max-width: 100%;
  object-fit: contain;
}

@media (prefers-reduced-motion: reduce) {
  .post-preview {
    transition: none;
  }

  .post-preview:hover,
  .post-preview:focus-within {
    transform: none;
  }
}

@media (max-width: 660px) {
  .post-gallery-270 { --post-preview-grid-size: 160px; --post-preview-size: 180px; }
  .post-gallery-225 { --post-preview-grid-size: 150px; --post-preview-size: 180px; }
  .post-gallery-360,
  .post-gallery-540,
  .post-gallery-720 { --post-preview-grid-size: min(100vw, 360px); --post-preview-size: 360px; }

  .post-gallery-grid .posts-container {
    grid-template-columns: repeat(auto-fill, minmax(min(150px, 48vw), 1fr));
  }
}
