:root {
  --forum-navbar-h: 3.5rem;
  --forum-composer-h: 0px;
  --forum-embed-max-h: min(
    72dvh,
    calc(100dvh - var(--forum-navbar-h) - var(--forum-composer-h) - 4.25rem)
  );
}

html {
  scroll-padding-top: calc(var(--forum-navbar-h) + 0.5rem);
  scroll-padding-bottom: calc(var(--forum-composer-h) + 0.5rem);
}

html:has(.forum-composer) {
  --forum-composer-h: 3.25rem;
}

html:has(.forum-composer:not(.is-collapsed)) {
  --forum-composer-h: 14rem;
}

.forum-shell {
  --forum-gap: 0.75rem;
}

.forum-nav {
  padding-top: 0.75rem;
}

.forum-line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.forum-category-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.forum-category-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.08);
}

.forum-topic-row {
  min-width: 0;
}

.forum-post-card .forum-post-body {
  line-height: 1.68;
}

.forum-post-body h1,
.forum-post-body h2,
.forum-post-body h3,
.forum-reply-quote h1,
.forum-reply-quote h2,
.forum-reply-quote h3 {
  margin: 0 0 0.6rem;
  line-height: 1.25;
}

.forum-post-body h1,
.forum-reply-quote h1 { font-size: 1.5rem; }
.forum-post-body h2,
.forum-reply-quote h2 { font-size: 1.25rem; }
.forum-post-body h3,
.forum-reply-quote h3 { font-size: 1.1rem; }

.forum-post-body code,
.forum-reply-quote code {
  padding: 0.1rem 0.3rem;
  border-radius: 0.25rem;
  background: var(--bs-tertiary-bg);
  font-size: 0.9em;
}

.forum-post-body pre,
.forum-reply-quote pre {
  margin: 0 0 0.75rem;
  padding: 0.75rem 0.9rem;
  overflow: auto;
  border-radius: 0.35rem;
  background: var(--bs-tertiary-bg);
}

.forum-post-body pre code,
.forum-reply-quote pre code {
  padding: 0;
  background: transparent;
}

.forum-post-body table,
.forum-reply-quote table {
  width: 100%;
  margin: 0 0 0.75rem;
  border-collapse: collapse;
}

.forum-post-body th,
.forum-post-body td,
.forum-reply-quote th,
.forum-reply-quote td {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--bs-border-color);
  vertical-align: top;
}

.forum-post-body img,
.forum-reply-quote img {
  display: block;
  max-width: 100%;
  max-height: var(--forum-embed-max-h);
  width: auto;
  height: auto;
  object-fit: contain;
  margin: 0.35rem auto;
  scroll-margin-top: calc(var(--forum-navbar-h) + 0.5rem);
  scroll-margin-bottom: calc(var(--forum-composer-h) + 3.5rem);
}

.forum-post-body iframe,
.forum-reply-quote iframe {
  display: block;
  width: 100%;
  max-width: min(100%, calc(var(--forum-embed-max-h) * 16 / 9));
  max-height: var(--forum-embed-max-h);
  aspect-ratio: 16 / 9;
  height: auto;
  margin: 0.35rem auto;
  border: 0;
  scroll-margin-top: calc(var(--forum-navbar-h) + 0.5rem);
  scroll-margin-bottom: calc(var(--forum-composer-h) + 3.5rem);
}

.forum-post-body .responsive-object,
.forum-reply-quote .responsive-object {
  position: relative;
  width: 100%;
  max-width: min(100%, calc(var(--forum-embed-max-h) * 16 / 9));
  max-height: var(--forum-embed-max-h);
  height: auto;
  aspect-ratio: 16 / 9;
  padding-bottom: 0 !important;
  margin: 0.35rem auto;
  overflow: hidden;
  scroll-margin-top: calc(var(--forum-navbar-h) + 0.5rem);
  scroll-margin-bottom: calc(var(--forum-composer-h) + 3.5rem);
}

.forum-post-body .responsive-object iframe,
.forum-reply-quote .responsive-object iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  margin: 0;
}

.forum-reply-quote {
  position: relative;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem 0.75rem 2.75rem;
  border-left: 4px solid var(--bs-primary);
  background: var(--bs-tertiary-bg);
  color: var(--bs-secondary-color);
}

.forum-reply-quote::before {
  position: absolute;
  top: 0.2rem;
  left: 0.75rem;
  color: var(--bs-primary);
  content: "\201C";
  font-family: Georgia, serif;
  font-size: 2.5rem;
  line-height: 1;
}

.forum-reply-children {
  margin: 0 0 0 1.5rem;
  padding-left: 1rem;
  border-left: 3px solid var(--bs-info);
}

.forum-reply-card {
  border-color: var(--bs-info-border-subtle);
}

.forum-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bs-secondary-bg);
  font-weight: 600;
}

.forum-avatar img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.forum-fab {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 1030;
}

.forum-post-card .card-body {
  padding-bottom: 0.75rem;
}

.forum-post-actions {
  scroll-margin-bottom: calc(var(--forum-composer-h) + 0.5rem);
}

.forum-composer {
  position: sticky;
  bottom: 0;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bs-body-bg);
  box-shadow: 0 -0.35rem 0.85rem rgba(0, 0, 0, 0.06);
}

.forum-composer-toolbar {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
}

.forum-composer-toggle-label-close {
  display: none;
}

.forum-composer:not(.is-collapsed) .forum-composer-toggle-label-open {
  display: none;
}

.forum-composer:not(.is-collapsed) .forum-composer-toggle-label-close {
  display: inline;
}

.forum-composer.is-collapsed .forum-composer-body {
  display: none;
}

.forum-composer .card-body {
  padding: 0 1rem 0.75rem;
}

.forum-composer .form-label {
  margin-bottom: 0.35rem;
}

.forum-composer .forum-editor {
  gap: 0.35rem;
}

.forum-composer .forum-editor-surface {
  min-height: 4.25rem;
  max-height: min(28vh, 12rem);
  overflow: auto;
}

.forum-composer .forum-editor-surface .ProseMirror {
  min-height: 3.25rem;
}

.forum-autogrow {
  min-height: 120px;
  resize: vertical;
}

@media (prefers-reduced-motion: reduce) {
  .forum-category-card,
  .forum-fab {
    transition: none !important;
    animation: none !important;
  }
}

.forum-avatar-lg {
  width: 64px;
  height: 64px;
  font-size: 1.5rem;
}

.forum-follow-icon {
  min-width: 44px;
  min-height: 44px;
  padding-inline: 0.35rem;
}

.forum-follow-block .btn {
  min-height: 44px;
}

.forum-poll-option,
.forum-poll-option-row .form-control,
.forum-poll-vote-form .btn,
.forum-poll .btn {
  min-height: 44px;
}

.forum-poll-option:hover,
.forum-poll-option:focus-within {
  border-color: var(--bs-primary) !important;
}

.forum-poll-option:focus-within {
  outline: 2px solid var(--bs-primary);
  outline-offset: 2px;
}

.forum-poll .progress {
  height: 0.5rem;
}

.forum-poll-result--chosen {
  border-color: var(--bs-primary);
}

.forum-poll-builder .form-check-input {
  margin-inline-end: 0.5rem;
}

@media (prefers-reduced-motion: reduce) {
  .forum-poll .progress-bar {
    transition: none;
  }
}
