.bbcode-block {
  margin: 0;
}

.bbcode-block > * {
  margin: 0;
}

.bbcode-image {
  display: block;
  max-width: min(100%, 520px);
  max-height: 300px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.bbcode-link {
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.bbcode-link:hover,
.bbcode-link:focus-visible {
  color: #b00000;
  text-decoration: underline;
}

.bbcode-quote {
  padding: 12px 14px;
  margin: 0;
  border: 1px solid var(--border);
  border-left: 4px solid #6b8ca8;
  border-radius: 8px;
  background: linear-gradient(#f8fbff, #eef4f9);
  box-shadow: inset 0 1px 0 #ffffff;
  color: #333;
  font-style: italic;
  line-height: 1.4;
}

.bbcode-code {
  padding: 12px;
  margin: 0;
  border-radius: 8px;
  background: #1f1f1f;
  color: #fff;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--site-font);
  font-size: 14px;
  line-height: 1.4;
}

.bbcode-code code {
  margin: 0;
  padding: 0;
  font-family: inherit;
}

.bbcode-highlight {
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(255, 225, 84, 0.58);
}

.bbcode-time {
  color: var(--primary-dark);
  font-weight: 700;
}

.bbcode-hover {
  position: relative;
  display: inline-block;
  cursor: help;
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: #7fa6c1;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.bbcode-hover::before {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 9px);
  z-index: 10;
  transform: translateX(-50%) translateY(3px);
  padding: 6px 12px;
  border-radius: 6px;
  background: #4a90c2;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.bbcode-hover::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 3px);
  z-index: 10;
  transform: translateX(-50%) translateY(3px);
  border-width: 6px 6px 0;
  border-style: solid;
  border-color: #4a90c2 transparent transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.bbcode-hover:hover::before,
.bbcode-hover:hover::after,
.bbcode-hover:focus::before,
.bbcode-hover:focus::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.bbcode-hover:focus {
  outline: 2px solid rgba(95, 134, 163, 0.35);
  outline-offset: 2px;
}

.bbcode-vibrant {
  font-weight: 700;
  animation: bbcodeVibrantGlow 6s linear infinite;
}

.bbcode-vibrant.custom {
  color: var(--vibrant-color);
  animation: bbcodeCustomGlow 2.8s ease-in-out infinite;
}

@keyframes bbcodeVibrantGlow {
  0% {
    color: #e45555;
    text-shadow: 0 0 7px rgba(228, 85, 85, 0.45);
  }
  33% {
    color: #3a85d7;
    text-shadow: 0 0 7px rgba(58, 133, 215, 0.45);
  }
  66% {
    color: #13a877;
    text-shadow: 0 0 7px rgba(19, 168, 119, 0.45);
  }
  100% {
    color: #e45555;
    text-shadow: 0 0 7px rgba(228, 85, 85, 0.45);
  }
}

@keyframes bbcodeCustomGlow {
  0%,
  100% {
    text-shadow: 0 0 4px var(--vibrant-color);
  }
  50% {
    text-shadow: 0 0 4px var(--vibrant-color), 0 0 12px var(--vibrant-color);
  }
}

.bbcode-center {
  text-align: center;
}

.bbcode-right {
  text-align: right;
}

.bbcode-hr {
  margin: 0;
  border: none;
  border-top: 1px solid var(--border);
}

.bbcode-spoiler {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(#f8fbff, #eef4f9);
  box-shadow: inset 0 1px 0 #ffffff;
  overflow: hidden;
}

.bbcode-spoiler summary {
  cursor: pointer;
  padding: 8px 14px;
  background: var(--button-bg);
  color: var(--button-text);
  font-weight: bold;
  box-shadow: var(--button-shadow);
  user-select: none;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
}

.bbcode-spoiler summary:hover {
  background: var(--button-hover-bg);
  color: var(--button-hover-text);
  box-shadow: var(--button-hover-shadow);
}

.bbcode-spoiler summary:active {
  background: var(--button-active-bg);
  box-shadow: var(--button-active-shadow);
}

.bbcode-spoiler-content {
  padding: 12px 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.bbcode-youtube {
  position: relative;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 16 / 9;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #000;
  overflow: hidden;
}

.bbcode-youtube iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
}

.bbcode-list {
  margin: 0;
  padding-left: 28px;
}

.bbcode-list li {
  margin: 6px 0;
}

.bbcode-error {
  padding: 10px 12px;
  border: 1px solid #d8b5b5;
  border-radius: 8px;
  background: linear-gradient(#fff5f5, #ffeaea);
  color: #a32d2d;
  font-size: 14px;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .bbcode-vibrant {
    animation: none;
    color: #3a85d7;
    text-shadow: 0 0 7px rgba(58, 133, 215, 0.35);
  }

  .bbcode-vibrant.custom {
    color: var(--vibrant-color);
    text-shadow: 0 0 7px var(--vibrant-color);
  }
}
