/* ============================================================
   COMMUNITY FORUM — discussion board + threaded discussion page
   ------------------------------------------------------------
   Only uses existing theme variables (--bg-card, --accent, …) so
   the forum inherits light/dark themes automatically.
   ============================================================ */

.forum-wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md) 4rem;
}

/* ---------------- Hero ---------------- */
.forum-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.forum-hero h1 {
  margin: 0 0 .35rem;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  gap: .55rem;
}
.forum-hero p {
  margin: 0;
  color: var(--text-secondary);
  font-size: .9rem;
  line-height: 1.55;
  max-width: 56ch;
}
.forum-hero a { color: var(--accent); }

/* ---------------- Boards ---------------- */
.forum-boards {
  display: flex;
  gap: .25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--space-lg);
  overflow-x: auto;
  scrollbar-width: none;
}
.forum-boards::-webkit-scrollbar { display: none; }
.board-tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  padding: .7rem .9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s ease, border-color .15s ease;
}
.board-tab:hover { color: var(--text-primary); }
.board-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------------- Composer ---------------- */
.forum-composer {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}
.composer-row {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-bottom: .6rem;
}
.composer-title {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  font: inherit;
  font-size: 1.02rem;
  font-weight: 700;
  padding: .45rem .1rem;
  outline: none;
}
.composer-title::placeholder { color: var(--text-muted); font-weight: 500; }
.composer-title:focus { border-bottom-color: var(--accent); }
.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-top: .65rem;
}

.forum-guest {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
  margin-bottom: var(--space-lg);
}
.forum-guest p { color: var(--text-secondary); margin: 0 0 .75rem; font-size: .92rem; }

/* ---------------- Filters ---------------- */
.forum-filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-bottom: .75rem;
}
.forum-sorts { display: flex; gap: .35rem; flex-wrap: wrap; }
.sort-pill {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--text-secondary);
  font: inherit;
  font-size: .82rem;
  font-weight: 600;
  padding: .4rem .8rem;
  cursor: pointer;
  transition: all .15s ease;
}
.sort-pill:hover { color: var(--text-primary); border-color: var(--accent); }
.sort-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.forum-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 200px;
}
.forum-search i {
  position: absolute;
  left: .7rem;
  color: var(--text-muted);
  font-size: .82rem;
  pointer-events: none;
}
.forum-search input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--text-primary);
  font: inherit;
  font-size: .88rem;
  padding: .5rem 2rem .5rem 2rem;
  outline: none;
}
.forum-search input:focus { border-color: var(--accent); }
.forum-search button {
  position: absolute;
  right: .45rem;
  background: none;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: .25rem;
  font-size: .8rem;
}

/* ---------------- Tag chips ---------------- */
.tag-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag-chips.scroll-x {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: .25rem;
  margin-bottom: .5rem;
}
.tag-chips.scroll-x::-webkit-scrollbar { display: none; }
.tag-chip {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--text-secondary);
  font: inherit;
  font-size: .78rem;
  font-weight: 600;
  padding: .32rem .7rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}
.tag-chip:hover { color: var(--text-primary); border-color: var(--accent); }
.tag-chip.active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: var(--accent);
  color: var(--accent);
}

/* Staff-only tags (Announcement / New Feature) — rendered for admins and
   moderators only, marked so they read as privileged. */
.tag-chip-staff {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--warning, #f5a524) 55%, transparent);
  color: var(--warning, #f5a524);
}
.tag-chip-staff:hover { border-color: var(--warning, #f5a524); }
.tag-chip-staff.active {
  background: color-mix(in srgb, var(--warning, #f5a524) 18%, transparent);
  border-style: solid;
  border-color: var(--warning, #f5a524);
  color: var(--warning, #f5a524);
}

.tag-badge {
  display: inline-block;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 999px;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 700;
  padding: .18rem .55rem;
  cursor: pointer;
  font-family: inherit;
}
.tag-badge:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.forum-count {
  color: var(--text-muted);
  font-size: .8rem;
  margin: 0 0 .6rem;
}

/* ---------------- Post cards ---------------- */
.forum-list { display: flex; flex-direction: column; gap: .7rem; }

.forum-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}
.forum-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.forum-card.pinned {
  border-left: 3px solid #f59e0b;
  background: linear-gradient(90deg, rgba(245, 158, 11, .07), transparent 55%), var(--bg-card);
}

.fc-head {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex-wrap: wrap;
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: .5rem;
}
.fc-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.fc-avatar.sm { width: 24px; height: 24px; }
.fc-author {
  color: var(--text-primary);
  font-weight: 700;
  text-decoration: none;
  font-size: .86rem;
}
.fc-author:hover { color: var(--accent); }
.fc-dot { opacity: .5; }

.fc-post-title {
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: .3rem;
}
.fc-post-title:hover { color: var(--accent); }

.fc-excerpt {
  color: var(--text-secondary);
  font-size: .9rem;
  line-height: 1.55;
  max-height: 4.7em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 60%, transparent);
          mask-image: linear-gradient(180deg, #000 60%, transparent);
}
.fc-excerpt img { max-width: 120px; max-height: 80px; border-radius: var(--radius-sm); }

/* Post image preview on the board (kept OUT of the clamped excerpt so
   uploaded images are always visible on discussion.html). */
.fc-media {
  display: grid;
  grid-template-columns: 1fr;
  gap: .35rem;
  margin-top: .6rem;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.fc-media.multi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fc-media img {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-md);
  background: var(--bg-secondary, rgba(255,255,255,.04));
}
.fc-media.multi img { max-height: 150px; }
.fc-media:empty { display: none; }

.fc-foot {
  display: flex;
  align-items: center;
  gap: .9rem;
  flex-wrap: wrap;
  margin-top: .75rem;
  font-size: .8rem;
  color: var(--text-muted);
}
.fc-stat { display: inline-flex; align-items: center; gap: .3rem; }
.fc-tag-badges { margin-left: auto; display: flex; gap: .3rem; flex-wrap: wrap; }

.forum-pinned-badge {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .66rem; font-weight: 800; letter-spacing: .03em;
  padding: .12rem .45rem; border-radius: 999px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff; text-transform: uppercase;
}

.forum-empty {
  background: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-secondary);
}
.forum-empty i { font-size: 1.8rem; opacity: .5; }

.forum-skeleton {
  height: 108px;
  border-radius: var(--radius-lg);
  margin-bottom: .7rem;
  background: linear-gradient(90deg,
    var(--bg-card) 25%,
    color-mix(in srgb, var(--bg-card) 70%, #808080 30%) 50%,
    var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: forum-shimmer 1.3s infinite;
}
@keyframes forum-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   THREAD PAGE
   ============================================================ */
.thread-crumbs {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}
.thread-crumbs a { color: var(--accent); text-decoration: none; font-weight: 600; }
.thread-crumbs span:last-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.thread-op {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}
.thread-title {
  margin: .35rem 0 .55rem;
  font-size: 1.4rem;
  line-height: 1.3;
}
.thread-tags { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .85rem; }
.thread-body {
  color: var(--text-secondary);
  font-size: .95rem;
  line-height: 1.65;
  word-break: break-word;
}
.thread-body img { max-width: 100%; border-radius: var(--radius-md); }
.thread-op-actions {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border-color);
}
.thread-reactions {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  margin-top: .6rem;
}

.thread-replies-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-bottom: .85rem;
}
.thread-replies-head h2 {
  margin: 0;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: .45rem;
}
.thread-replies-head .muted { color: var(--text-muted); font-size: .85rem; font-weight: 500; }

/* ---------------- Nested replies ----------------
   Structure mirrors chapter.html: a comment card, then the child
   replies in a sibling container (`.thread-children`) that is
   indented once, exactly like `.replies-container`. Children are
   never nested inside the parent card, so the avatar gutter can
   no longer stack up and push deep branches out of the layout. */
/* Same black, bordered surface as chapter.html's #commentsList. */
.thread-replies {
  min-width: 0;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 0 var(--space-md);
  overflow: hidden;
}

.thread-node { position: relative; min-width: 0; }
.thread-node-main { min-width: 0; }

/* Branch wrapper (rail + children) */
.thread-branch { position: relative; min-width: 0; }

.thread-children {
  margin-top: var(--space-sm);
  padding-left: var(--space-md);
  border-left: 2px solid var(--bg-tertiary);
  min-width: 0;
}
.thread-branch:hover > .thread-children {
  border-left-color: color-mix(in srgb, var(--accent, #6366f1) 45%, var(--bg-tertiary));
}

/* Past the indent cap the rail stays but the gutter stops growing,
   so extremely deep chains can never overflow horizontally. */
.thread-node-flat > .thread-node-main > .thread-branch > .thread-children {
  padding-left: var(--space-sm);
  border-left-style: dashed;
}

/* Clickable rail: the vertical line folds the whole branch. */
.thread-rail {
  position: absolute;
  left: -6px;
  top: 0;
  bottom: 0;
  width: 14px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  z-index: 1;
}
.thread-node.collapsed > .thread-node-main > .thread-branch { display: none; }

.thread-node-content { min-width: 0; }

.branch-toggle {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary, transparent);
  color: var(--text-muted);
  font-size: .6rem;
  cursor: pointer;
  flex-shrink: 0;
}
.branch-toggle:hover { color: var(--accent); border-color: var(--accent); }

.branch-count {
  font-size: .72rem;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 999px;
  padding: .1rem .45rem;
}

.thread-reply-form { margin: .5rem 0 .25rem; min-width: 0; }
.thread-reply-form[hidden] { display: none; }

@media (max-width: 640px) {
  .forum-wrap { padding: var(--space-md) .75rem 4rem; }
  .thread-op { padding: var(--space-md); }
  .thread-title { font-size: 1.2rem; }
  .thread-children { padding-left: var(--space-sm); }
  .fc-tag-badges { margin-left: 0; width: 100%; }
}

/* ============================================================
   COMMENT SECTION REDESIGN (2 major improvements)
   1) "Reply Card" — avatar gutter + single-line identity row so
      username, badges, time, body and actions never collide.
   2) "Threaded conversation rail" — one continuous connector per
      branch, avatar-anchored, with a collapse chip on every
      branch and a clear "replying to @user" context line.
   ============================================================ */

/* -------- 1. Reply card ---------------------------------- */
.yv-reply-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: .6rem;
  align-items: start;
  background: color-mix(in srgb, var(--bg-card) 65%, transparent);
  border: 1px solid color-mix(in srgb, var(--border-color) 70%, transparent);
  border-radius: var(--radius-md, 10px);
  padding: .6rem .7rem;
  transition: border-color .15s ease, background .15s ease;
}
.yv-reply-card:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border-color));
  background: var(--bg-card);
}

.yv-reply-gutter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  position: relative;
}
.yv-reply-gutter .fc-avatar.sm { width: 32px; height: 32px; }

/* Identity row: one clean line, never a wall of wrapped chips. */
.yv-reply-head {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: nowrap;
  overflow: hidden;
  margin-bottom: .15rem;
  min-width: 0;
}
.yv-reply-head .fc-author {
  font-size: .88rem;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}
.yv-reply-head .fc-time { white-space: nowrap; flex-shrink: 0; font-size: .76rem; }

/* Badge cluster: compact, calm (no glow), horizontally scrollable. */
.fc-badges {
  display: flex;
  align-items: center;
  gap: .25rem;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 0 1 auto;
  mask-image: linear-gradient(90deg, #000 85%, transparent);
  -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.fc-badges::-webkit-scrollbar { display: none; }
.yv-reply-head .fc-badges > * {
  flex-shrink: 0;
  box-shadow: none !important;
  filter: none !important;
  text-shadow: none !important;
  font-size: .66rem !important;
  padding: .08rem .38rem !important;
  line-height: 1.5;
}

/* Body + actions align to the content column. */
.yv-reply .thread-body { color: var(--text-primary); font-size: .92rem; line-height: 1.6; }
.yv-reply-actions {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-top: .35rem;
}
.yv-action-spacer { flex: 1; }
.yv-reply-actions .comment-btn.subtle {
  opacity: .45;
  transition: opacity .15s ease;
}
.yv-reply-card:hover .comment-btn.subtle,
.yv-reply-actions .comment-btn.subtle:focus-visible { opacity: 1; }

/* -------- 2. Threaded conversation rail ------------------ */
.thread-node.yv-reply { padding: .1rem 0; }

/* Collapse chip: always visible per branch, states are obvious. */
.branch-count {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  margin: .1rem 0 .3rem;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  font: inherit;
  font-size: .72rem;
  font-weight: 700;
  padding: .15rem .5rem;
  border-radius: 999px;
  cursor: pointer;
}
.branch-count:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.branch-count.collapsed {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}

/* Context line so deep replies stay readable. */
.yv-reply-context {
  font-size: .74rem;
  color: var(--text-muted);
  margin-bottom: .3rem;
  display: flex;
  align-items: center;
  gap: .3rem;
}
.yv-reply-context span { color: var(--accent); font-weight: 600; }

@media (max-width: 640px) {
  .yv-reply-card { grid-template-columns: 28px minmax(0, 1fr); gap: .5rem; padding: .55rem .6rem; }
  .yv-reply-gutter .fc-avatar.sm { width: 26px; height: 26px; }
  .yv-reply-head .fc-author { max-width: 45%; }
}

/* Gutter refinements: toggle hangs under the avatar without shifting rows. */
.yv-reply-gutter { padding-bottom: .2rem; }
.yv-reply-gutter .branch-toggle {
  width: 16px; height: 16px; font-size: .55rem;
  border-radius: 999px;
}

/* ------------------------------------------------------------
   Thread replies use the same comment cards as chapter.html
   ------------------------------------------------------------ */
.thread-replies .comment-card { min-width: 0; }
.thread-replies .comment-card > .comment-body { min-width: 0; flex: 1; }
/* Long usernames / links / unbroken words must wrap, never widen the row. */
.thread-replies .comment-author,
.thread-replies .comment-content,
.thread-replies .yv-reply-context,
.thread-replies .comment-time {
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}
.thread-replies .comment-author { display: inline-block; max-width: 100%; }
.thread-replies .comment-content img,
.thread-replies .comment-image,
.thread-replies .comment-gif-wrap { max-width: 100%; }
.thread-replies .comment-card .comment-content img,
.thread-replies .comment-card .comment-image { border-radius: var(--radius-md); height: auto; }
.thread-replies .comment-footer { flex-wrap: wrap; }
.yv-reply-context {
  font-size: .75rem;
  color: var(--text-muted);
  margin: .1rem 0 .25rem;
  white-space: normal;
}
.yv-reply-context span { color: var(--accent); }
.yv-reply-context i { margin-right: .25rem; }
