/* =====================================================================
   Brawin HQ — single.css
   Loaded ONLY on single blog posts. Uses the theme's existing design
   tokens (--accent, --card, --border, --radius, --ease, etc.).
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. REVEAL SAFETY NET  (fixes the blank-body bug)
   .reveal starts at opacity:0 and only becomes visible when site.js adds
   .in. If that JS ever fails, the post body stayed invisible → blank page.
   Here the post body is guaranteed visible; the entrance animation still
   plays normally when JS is working.
--------------------------------------------------------------------- */
.bhq-single .prose.is-safe { opacity: 1; transform: none; }
/* Still allow a gentle fade-in when JS is present and hasn't fired yet. */
.js .bhq-single .prose.is-safe:not(.in) { opacity: 1; }

/* Extra belt-and-braces: never let the article body sit fully hidden. */
.bhq-single article .prose { opacity: 1 !important; transform: none !important; }

/* ---------------------------------------------------------------------
   2. RIGHT-HAND FIXED CTA RAIL
--------------------------------------------------------------------- */
.bhq-rail {
  position: fixed;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-grad);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: inset 0 1px 0 var(--card-hi), 0 24px 60px -24px rgba(0,0,0,0.6);
}

.bhq-rail-btn {
  position: relative;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--text-2);
  border: 1px solid transparent;
  transition: color .25s var(--ease), background .25s var(--ease),
              border-color .25s var(--ease), transform .25s var(--ease);
}
.bhq-rail-btn svg { width: 19px; height: 19px; }
.bhq-rail-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
  transform: translateX(-3px);
}
.bhq-rail-label {
  display: none; /* icon-only rail; label shown as tooltip instead */
}
.bhq-rail-sep {
  height: 1px;
  margin: 2px 8px;
  background: var(--border);
}

/* tooltip on hover */
.bhq-rail-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: .72rem;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
  box-shadow: 0 10px 30px -12px rgba(0,0,0,0.6);
}
.bhq-rail-btn[data-tip]:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* ---------------------------------------------------------------------
   3. NEWSLETTER POPUP (modal)
   Critical layout props are forced so no theme cascade / transformed
   ancestor can drop the popup into normal page flow.
--------------------------------------------------------------------- */
.bhq-single .bhq-popup,
.bhq-popup {
  position: fixed !important;
  inset: 0 !important;
  z-index: 9999 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 20px;
  margin: 0 !important;
  width: auto !important;
  max-width: none !important;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s var(--ease), visibility .35s var(--ease);
}
.bhq-popup.show {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.bhq-popup-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.bhq-popup .bhq-popup-card {
  position: relative;
  width: min(440px, 100%);
  max-width: 100%;
  margin: 0;
  padding: 34px 30px 28px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface, #0D0D10);
  background: var(--card-grad), var(--surface);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 var(--card-hi), 0 40px 90px -28px rgba(0,0,0,0.75);
  transform: translateY(16px) scale(0.98);
  transition: transform .4s var(--ease);
  text-align: left;
}
.bhq-popup.show .bhq-popup-card { transform: translateY(0) scale(1); }

.bhq-popup-card .kicker { margin-bottom: 10px; }
.bhq-popup-card .h2 { margin: 0 0 8px; }
.bhq-popup-card .muted { margin: 0 0 20px; font-size: .92rem; }

.bhq-popup-form { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.bhq-popup-form .field { width: 100%; }

.bhq-popup-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  color: var(--text-3);
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: color .2s var(--ease), border-color .2s var(--ease);
}
.bhq-popup-close:hover { color: var(--text); border-color: var(--border-2); }
.bhq-popup-close svg { width: 16px; height: 16px; }

.bhq-popup-dismiss {
  display: block;
  margin: 14px auto 0;
  padding: 4px 8px;
  font-size: .78rem;
  color: var(--text-3);
  background: none;
  border: none;
  cursor: pointer;
  transition: color .2s var(--ease);
}
.bhq-popup-dismiss:hover { color: var(--text-2); }

/* ---------------------------------------------------------------------
   4. (bottom hover bar removed — replaced by popup above)
--------------------------------------------------------------------- */

/* ---------------------------------------------------------------------
   5. RESPONSIVE
--------------------------------------------------------------------- */

/* Tablet: shrink rail so it doesn't crowd the text column */
@media (max-width: 1100px) {
  .bhq-rail { right: 12px; }
}

/* Below 900px: hide the vertical rail (its actions live in the bottom bar
   + inline cards) so it never overlaps content on narrow screens. */
@media (max-width: 900px) {
  .bhq-rail { display: none; }
}

/* Mobile: popup fits small screens comfortably */
@media (max-width: 640px) {
  .bhq-popup { padding: 16px; }
  .bhq-popup-card { padding: 30px 22px 24px; }
}

/* Respect reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .bhq-popup,
  .bhq-popup-card,
  .bhq-rail-btn { transition: none; }
}

/* =====================================================================
   POST LAYOUT — column, TOC, prose typography
   All colours come from the theme's existing tokens so the post body
   adapts to the site's dark background automatically.
   ===================================================================== */

/* --- shared 820px column -------------------------------------------
   The title, featured image and body all use .container.narrow, so
   they align on the same left/right edge. (.narrow = 820px, defined
   in about.css and loaded globally.) Redeclared here so single posts
   never depend on another page's stylesheet.
------------------------------------------------------------------- */
.bhq-single .narrow { max-width: 820px; }

/* featured cover — same width as text, 1200x630 banner ratio */
.bhq-single .single-cover {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--surface-2);
  aspect-ratio: 1200 / 630;
}
.bhq-single .single-cover-img {
  display: block; width: 100%; height: 100%;
  object-fit: cover; object-position: center top;
}

/* --- layout: TOC + body --------------------------------------------
   Sidebar sits in the left gutter on wide screens WITHOUT narrowing
   the text column: the grid column is created outside .narrow via a
   negative margin, so the prose keeps its full 820px measure.
------------------------------------------------------------------- */
.single-layout { display: block; }

/* 1360px is the first width where a 200px sidebar + 40px gap still
   clears the viewport edge once the 820px column is centred inside
   the 1200px container. Below this the TOC becomes a card instead. */
@media (min-width: 1360px) {
  .single-layout.has-toc {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 40px;
    /* pull the sidebar into the gutter, keep prose at its full measure */
    margin-left: -240px;
  }
}

/* --- table of contents --------------------------------------------- */
.bhq-toc { margin: 0 0 32px; }

@media (min-width: 1360px) {
  .bhq-toc {
    position: sticky; top: 120px; align-self: start;
    max-height: calc(100vh - 160px); overflow-y: auto;
    margin: 0;
    /* thin scrollbar, themed */
    scrollbar-width: thin; scrollbar-color: var(--border-2) transparent;
  }
  .bhq-toc::-webkit-scrollbar { width: 4px; }
  .bhq-toc::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
}

/* mobile/tablet: a collapsible card above the post */
@media (max-width: 1359px) {
  .bhq-toc-inner {
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--card); padding: 4px 18px;
  }
}

.bhq-toc-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-3); padding: 14px 0; cursor: pointer; list-style: none;
}
.bhq-toc-head::-webkit-details-marker { display: none; }
.bhq-toc-chev { width: 16px; height: 16px; transition: transform .3s var(--ease); flex: none; }
.bhq-toc-inner[open] .bhq-toc-chev { transform: rotate(180deg); }

/* on desktop the TOC is always open and the chevron is noise */
@media (min-width: 1360px) {
  .bhq-toc-head { cursor: default; padding-top: 0; }
  .bhq-toc-chev { display: none; }
}

.bhq-toc-list {
  list-style: none; margin: 0 0 14px; padding: 0;
  display: flex; flex-direction: column; gap: 2px;
  border-left: 1px solid var(--border);
}
.bhq-toc-item a {
  display: block; padding: 7px 0 7px 16px; margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-3); font-size: 14px; line-height: 1.45;
  text-decoration: none; transition: color .2s, border-color .2s;
}
.bhq-toc-item.lvl-3 a { padding-left: 30px; font-size: 13px; }
.bhq-toc-item a:hover { color: var(--text); border-left-color: var(--text-3); }
/* active section, driven by the scroll-spy in single.php */
.bhq-toc-item.is-active > a { color: var(--accent); border-left-color: var(--accent); }

/* anchor offset so a clicked heading isn't hidden under the fixed header */
.bhq-single .prose :is(h2, h3)[id] { scroll-margin-top: 110px; }

/* =====================================================================
   PROSE — the actual post body written in the WordPress editor.
   Without these rules the content falls back to browser defaults
   (black text / blue links) which is invisible on a dark background.
   ===================================================================== */
.bhq-single .prose { color: var(--text-2); font-size: 1.08rem; line-height: 1.75; }

.bhq-single .prose > * + * { margin-top: 24px; }

.bhq-single .prose p { color: var(--text-2); text-wrap: pretty; }
.bhq-single .prose p strong,
.bhq-single .prose li strong { color: var(--text); font-weight: 600; }
.bhq-single .prose em { font-style: italic; }

/* headings */
.bhq-single .prose h2,
.bhq-single .prose h3,
.bhq-single .prose h4 {
  color: var(--text); font-weight: 600; letter-spacing: -0.02em;
  line-height: 1.25; text-wrap: balance;
}
.bhq-single .prose h2 { font-size: clamp(1.6rem, 2.6vw, 2rem); margin-top: 56px; }
.bhq-single .prose h3 { font-size: clamp(1.25rem, 2vw, 1.45rem); margin-top: 40px; }
.bhq-single .prose h4 { font-size: 1.1rem; margin-top: 32px; }
.bhq-single .prose h2 + p,
.bhq-single .prose h3 + p,
.bhq-single .prose h4 + p { margin-top: 14px; }

/* links — same treatment for internal and external */
.bhq-single .prose a:not(.btn):not(.link-arrow) {
  color: var(--accent); text-decoration: underline;
  text-underline-offset: 3px; text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  transition: text-decoration-color .2s, color .2s;
}
.bhq-single .prose a:not(.btn):not(.link-arrow):hover {
  text-decoration-color: var(--accent);
}

/* lists */
.bhq-single .prose ul,
.bhq-single .prose ol { padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.bhq-single .prose li { position: relative; padding-left: 28px; color: var(--text-2); }
.bhq-single .prose ul > li::before {
  content: ""; position: absolute; left: 8px; top: 0.66em;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); opacity: .75;
}
.bhq-single .prose ol { counter-reset: bhq-ol; }
.bhq-single .prose ol > li { counter-increment: bhq-ol; }
.bhq-single .prose ol > li::before {
  content: counter(bhq-ol) "."; position: absolute; left: 0; top: 0;
  font-family: var(--font-mono); font-size: 0.9em; color: var(--accent);
  line-height: inherit; font-weight: 500;
}
/* nested lists shouldn't double-space */
.bhq-single .prose li > ul,
.bhq-single .prose li > ol { margin-top: 12px; }

/* images added inside the post */
.bhq-single .prose img {
  max-width: 100%; height: auto; display: block;
  border-radius: var(--radius); border: 1px solid var(--border);
}
.bhq-single .prose figure { margin: 36px 0; }
.bhq-single .prose figcaption {
  margin-top: 12px; font-size: 13px; color: var(--text-3);
  text-align: center; font-family: var(--font-mono);
}
/* WordPress alignment classes */
.bhq-single .prose .aligncenter { margin-inline: auto; }
.bhq-single .prose .alignleft { float: left; margin: 6px 28px 20px 0; max-width: 50%; }
.bhq-single .prose .alignright { float: right; margin: 6px 0 20px 28px; max-width: 50%; }
.bhq-single .prose .alignwide,
.bhq-single .prose .alignfull { margin-inline: auto; }
@media (max-width: 640px) {
  .bhq-single .prose .alignleft,
  .bhq-single .prose .alignright { float: none; margin-inline: auto; max-width: 100%; }
}
.bhq-single .prose .wp-block-image { margin: 36px 0; }

/* blockquote */
.bhq-single .prose blockquote {
  margin: 36px 0; padding: 4px 0 4px 26px;
  border-left: 2px solid var(--accent);
  color: var(--text); font-size: 1.15rem; line-height: 1.65;
}
.bhq-single .prose blockquote p { color: var(--text); }
.bhq-single .prose blockquote cite {
  display: block; margin-top: 12px; font-size: 13px;
  color: var(--text-3); font-style: normal; font-family: var(--font-mono);
}

/* code */
.bhq-single .prose code {
  font-family: var(--font-mono); font-size: 0.88em;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 6px; color: var(--text);
}
.bhq-single .prose pre {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; overflow-x: auto;
  margin: 32px 0;
}
.bhq-single .prose pre code { background: none; border: 0; padding: 0; font-size: 0.86rem; line-height: 1.6; }

/* tables */
.bhq-single .prose table {
  width: 100%; border-collapse: collapse; margin: 32px 0;
  font-size: 0.95rem; display: block; overflow-x: auto;
}
.bhq-single .prose th,
.bhq-single .prose td {
  border: 1px solid var(--border); padding: 12px 16px; text-align: left;
}
.bhq-single .prose th {
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 13px;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.bhq-single .prose td { color: var(--text-2); }
.bhq-single .prose tbody tr:hover td { background: var(--card); }

.bhq-single .prose hr {
  border: 0; height: 1px; background: var(--border); margin: 48px 0;
}

/* =====================================================================
   RANK MATH FAQ BLOCK
   Rank Math outputs bare HTML with no dark-theme CSS, so it inherits
   browser defaults. Styling here is purely visual — the FAQPage JSON-LD
   schema Rank Math emits is untouched and keeps working.
   ===================================================================== */
.bhq-single .prose #rank-math-faq,
.bhq-single .prose .rank-math-block { margin: 44px 0; }

.bhq-single .prose .rank-math-list { list-style: none; margin: 0; padding: 0; }

.bhq-single .prose .rank-math-list-item {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); padding: 22px 26px; margin: 0 0 12px;
  transition: border-color .3s;
}
.bhq-single .prose .rank-math-list-item:hover { border-color: var(--border-2); }
.bhq-single .prose .rank-math-list-item:last-child { margin-bottom: 0; }

/* the question — Rank Math renders it as h3 by default */
.bhq-single .prose .rank-math-question {
  margin: 0; padding: 0 0 0 30px; position: relative;
  color: var(--text); font-weight: 600;
  font-size: 1.08rem !important; line-height: 1.45; letter-spacing: -0.01em;
}
.bhq-single .prose .rank-math-question::before {
  content: "Q"; position: absolute; left: 0; top: 0;
  font-family: var(--font-mono); font-size: 13px;
  color: var(--accent); font-weight: 500;
}
.bhq-single .prose .rank-math-answer {
  margin: 12px 0 0; padding-left: 30px; color: var(--text-2);
}
.bhq-single .prose .rank-math-answer p { margin: 0 0 10px; color: var(--text-2); }
.bhq-single .prose .rank-math-answer p:last-child { margin-bottom: 0; }
.bhq-single .prose .rank-math-answer a { color: var(--accent); }

@media (max-width: 640px) {
  .bhq-single .prose .rank-math-list-item { padding: 18px 18px; }
}

/* =====================================================================
   REVISIONS — header width, sticky TOC, duplicate TOC, mobile tables
   ===================================================================== */

/* --- (2) Title + featured image match the newsletter block ----------
   The newsletter uses a plain .container (max 1200 - 56 padding = 1144).
   Header and cover now use the same, so all three align on one edge.
   The body stays at 820px: ~75ch is the readable measure for long text.
   On narrow screens .container already collapses to the viewport, so
   these become fluid automatically — no fixed widths to break mobile.
------------------------------------------------------------------- */
.bhq-single .single-head-col,
.bhq-single .single-cover-col { max-width: var(--maxw); }

/* Cover art keeps its 1200x630 ratio and simply scales with the column,
   so it never overflows or distorts on a phone. */
.bhq-single .single-cover { width: 100%; }

/* --- (4) Tables: real horizontal scroll on small screens ------------
   Previously `display:block; overflow-x:auto` was on the <table> itself,
   which collapses the table box and lets cells shrink instead of scroll.
   The fix: keep the table a proper table (so columns keep their width)
   and put the scrolling on a wrapper injected by JS.
------------------------------------------------------------------- */
.bhq-single .prose table {
  display: table; width: 100%; border-collapse: collapse;
  margin: 0; font-size: 0.95rem;
}
.bhq-single .prose .bhq-table-scroll {
  margin: 32px 0; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  scrollbar-width: thin; scrollbar-color: var(--border-2) transparent;
}
.bhq-single .prose .bhq-table-scroll::-webkit-scrollbar { height: 6px; }
.bhq-single .prose .bhq-table-scroll::-webkit-scrollbar-thumb {
  background: var(--border-2); border-radius: 6px;
}
/* Stop cells collapsing to unreadable slivers; force the scroll instead. */
.bhq-single .prose .bhq-table-scroll table { min-width: 560px; }
.bhq-single .prose th,
.bhq-single .prose td { white-space: normal; }

/* subtle "more this way" cue while the table can still scroll */
.bhq-single .prose .bhq-table-scroll.can-scroll {
  -webkit-mask-image: linear-gradient(to right, #000 88%, transparent 100%);
          mask-image: linear-gradient(to right, #000 88%, transparent 100%);
}

@media (max-width: 640px) {
  .bhq-single .prose .bhq-table-scroll table { min-width: 480px; }
  .bhq-single .prose th,
  .bhq-single .prose td { padding: 10px 12px; }
}

/* --- (1) Only ever show ONE table of contents ----------------------
   If a TOC block is placed inside the post content (Rank Math, a TOC
   plugin, or a manual list), hide it while our sidebar TOC is present.
   The sidebar is authoritative; the in-body copy is the duplicate.
------------------------------------------------------------------- */
.single-layout.has-toc .prose #rank-math-toc,
.single-layout.has-toc .prose .rank-math-toc,
.single-layout.has-toc .prose .wp-block-rank-math-toc-block,
.single-layout.has-toc .prose .ez-toc-container,
.single-layout.has-toc .prose #ez-toc-container,
.single-layout.has-toc .prose .lwptoc,
.single-layout.has-toc .prose .wp-block-table-of-contents,
.single-layout.has-toc .prose .bhq-dupe-toc { display: none !important; }

/* --- (3) Sticky TOC that never breaks ------------------------------
   position:sticky fails silently if ANY ancestor has overflow other
   than visible, so the chain from .bhq-toc up to <body> is pinned to
   overflow:visible. The rail also gets its own internal scroll for
   posts with very long heading lists.
------------------------------------------------------------------- */
@media (min-width: 1360px) {
  .bhq-single .single-body-wrap,
  .bhq-single .single-body-wrap > .container,
  .bhq-single .single-layout { overflow: visible; }

  .bhq-toc {
    position: -webkit-sticky; position: sticky;
    top: 104px;
    align-self: start;
    /* never taller than the viewport, so the end of a long list is reachable */
    max-height: calc(100vh - 140px);
    overflow-y: auto; overscroll-behavior: contain;
  }
  /* keep the sticky element from being stretched by the grid */
  .single-layout.has-toc { align-items: start; }
}
