/*
 * BlackSpigot Unslop & Performance Layer (v1)
 * Scoped strictly to BlackSpigot hosts via html.bs-exact-theme / bsu_mobile_assets.
 * Preserves brand palette (dark obsidian + forged terracotta/copper + gold Ultra) and 100% of SEO copy.
 *
 * Layer ordering note: in CSS Cascade Level 5, `!important` declarations in EARLIER layers
 * override later layers and unlayered `!important` — placing `bsu-polish` first gives deterministic
 * cleanup of legacy animation/slop/layout bugs without mutating NF/FusionFallExactTheme core templates.
 */
@layer bsu-polish, blackspigot-ultra-prefix, blackspigot-mobile;

@layer bsu-polish {

  /* =========================================================================
   * 1. GPU / COMPOSITOR PERFORMANCE — Kill heavy continuous loops & overlays
   * ========================================================================= */

  /* Remove full-viewport CRT scanlines + blurred sweep overlays everywhere */
  html.bs-exact-theme::before,
  html.bs-exact-theme::after {
    content: none !important;
    display: none !important;
    animation: none !important;
    filter: none !important;
  }

  /* Avoid expensive full-screen blend pass on ambient constellation canvas */
  html.bs-exact-theme #bs-particle-network {
    mix-blend-mode: normal !important;
    opacity: 0.72 !important;
    pointer-events: none !important;
    contain: strict;
  }

  /* Stop per-mousemove full-page 5-layer radial-gradient invalidation */
  html.bs-exact-theme .p-pageWrapper {
    background-image:
      radial-gradient(900px circle at 16% 0%, rgba(164, 72, 54, 0.14), transparent 58%),
      radial-gradient(760px circle at 86% 6%, rgba(186, 128, 72, 0.08), transparent 55%),
      linear-gradient(180deg, #101218 0%, #0d0f14 48%, #0a0c10 100%) !important;
  }

  /* Stop non-composited infinite background-position, left, drop-shadow & sparkle loops */
  html.bs-exact-theme .p-pageWrapper::before,
  html.bs-exact-theme .p-header::before,
  html.bs-exact-theme .categoryList-item::before,
  html.bs-exact-theme .categoryList-item::after,
  html.bs-exact-theme a[data-nav-id="xfrm"],
  html.bs-exact-theme a[data-nav-id="xfrm"]::before,
  html.bs-exact-theme a[data-nav-id="xfrm"]::after,
  html.bs-exact-theme a[data-nav-id="xfrm"] .ffNavLabel::after,
  html.bs-exact-theme .label.resourceAutoPrefix--ultra::before,
  html.bs-exact-theme .label.resourceAutoPrefix--ultra::after,
  html.bs-exact-theme .bsShop-evil,
  html.bs-exact-theme .bsShop-evil::before,
  html.bs-exact-theme .bsShop-evil::after,
  html.bs-exact-theme .bsCompatibility-spark,
  html.bs-exact-theme .bsCompatibility-signal,
  html.bs-exact-theme .bsBuildUltra::before,
  html.bs-exact-theme .bsBuildUltra::after,
  html.bs-exact-theme .bsu-plans .bsu-fx i,
  html.bs-exact-theme .bsu-card--ultra::before {
    animation: none !important;
    filter: none !important;
  }

  /* Hide decorative looping sheen & floating sparkle dots */
  html.bs-exact-theme .categoryList-item::before,
  html.bs-exact-theme .label.resourceAutoPrefix--ultra::before,
  html.bs-exact-theme .bsu-plans .bsu-fx,
  html.bs-exact-theme .offCanvasMenu a[data-nav-id="xfrm"]::before,
  html.bs-exact-theme .offCanvasMenu a[data-nav-id="xfrm"]::after {
    display: none !important;
    content: none !important;
  }

  /* Strip expensive backdrop-filter blur over live WebGL 3D canvases */
  html.bs-exact-theme .nfModelPreview-toolbar,
  html.bs-exact-theme .nfModelPreview-timeline,
  html.bs-exact-theme .nfModelPreview-status,
  html.bs-exact-theme .nfModelOverview,
  html.bs-exact-theme .bsBuildUltra {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  html.bs-exact-theme .nfModelPreview-timeline,
  html.bs-exact-theme .nfModelPreview-status {
    background: rgba(16, 19, 25, 0.92) !important;
  }

  /* Layout containment on repeating cards to accelerate scroll & reflow */
  html.bs-exact-theme .structItem--resource,
  html.bs-exact-theme .bsShop-bossCard,
  html.bs-exact-theme .bsMosaic-tile,
  html.bs-exact-theme .bsf-resource {
    contain: layout style;
  }

  /* Respect prefers-reduced-motion globally */
  @media (prefers-reduced-motion: reduce) {
    html.bs-exact-theme *,
    html.bs-exact-theme *::before,
    html.bs-exact-theme *::after {
      animation-duration: 0.001ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.001ms !important;
      scroll-behavior: auto !important;
    }
  }

  /* =========================================================================
   * 2. WEB FLOOR — Contrast, Focus Rings, Tabular Numbers, Browser Surfaces
   * ========================================================================= */
  html.bs-exact-theme {
    color-scheme: dark;
    accent-color: #c86448;
  }

  html.bs-exact-theme input::placeholder,
  html.bs-exact-theme textarea::placeholder {
    color: rgba(232, 222, 217, 0.62) !important;
    opacity: 1 !important;
  }

  html.bs-exact-theme :is(a, button, summary, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid #e6a972 !important;
    outline-offset: 2px !important;
  }

  html.bs-exact-theme :is(
    .structItem-metaItem dd,
    .pairs dd,
    .bsu-price,
    .categoryList-label + span,
    .bsf-categoryHeading h3 span,
    .pageNav-page,
    .pageNavSimple-el
  ) {
    font-variant-numeric: tabular-nums;
  }

  /* Dark-mode Froala editor icons everywhere on BlackSpigot (not just forums) */
  html.bs-exact-theme .fr-toolbar .fr-command.fr-btn svg,
  html.bs-exact-theme .fr-popup .fr-command.fr-btn svg {
    fill: #ede3df !important;
    color: #ede3df !important;
  }

  /* Calm, authentic Ultra badge (keep gold brand identity, drop neon glow/sparkle noise) */
  html.bs-exact-theme .label.resourceAutoPrefix--ultra {
    text-shadow: 0 1px 1px #1d1103 !important;
    box-shadow: inset 0 1px 0 rgba(255, 240, 172, 0.35) !important;
  }
  html.bs-exact-theme .label.resourceAutoPrefix--ultra::after {
    text-shadow: none !important;
    opacity: 0.9 !important;
  }

  /* =========================================================================
   * 3. HEADER, SEARCH & MID-WIDTH (~1000px) NAVIGATION BUGS
   * ========================================================================= */

  /* Make the header search magnifying glass clearly visible against dark input */
  html.bs-exact-theme .p-header .xb-searchWrapper::before {
    border-color: rgba(236, 224, 216, 0.85) !important;
  }
  html.bs-exact-theme .p-header .xb-searchWrapper::after {
    background-color: rgba(236, 224, 216, 0.85) !important;
  }
  html.bs-exact-theme .p-header .xb-search button,
  html.bs-exact-theme .p-header .xb-search .fa--xf,
  html.bs-exact-theme .p-header .xb-search svg {
    color: #e2d2c8 !important;
    fill: #e2d2c8 !important;
  }

  /* Prevent quick-search dropdown from overflowing medium desktop viewports */
  html.bs-exact-theme .p-header .xb-searchQuickPanel,
  html.bs-exact-theme .p-header .xfrm-quickSearchResults {
    max-width: min(680px, calc(100vw - 28px)) !important;
  }

  /* Fix mid-width desktop nav bar clipping & ugly vertical scrollbar (901px–1280px) */
  @media (min-width: 901px) and (max-width: 1280px) {
    html.bs-exact-theme .p-nav-inner {
      overflow: hidden !important;
      padding-left: 10px !important;
      padding-right: 10px !important;
    }
    html.bs-exact-theme .p-nav-scroller {
      overflow: visible !important;
    }
    html.bs-exact-theme .p-nav-list {
      flex-wrap: nowrap !important;
      justify-content: center !important;
      gap: 2px !important;
    }
    html.bs-exact-theme .p-nav-list .p-navEl-link {
      padding-left: 10px !important;
      padding-right: 10px !important;
      font-size: 11px !important;
      white-space: nowrap !important;
    }
    html.bs-exact-theme a[data-nav-id="xfrm"] .ffNavLabel::before,
    html.bs-exact-theme a[data-nav-id="nfBsBuildsSchematics"] .ffNavLabel::before {
      font-size: 9px !important;
    }
  }

  @media (min-width: 901px) {
    html.bs-exact-theme .p-nav-inner,
    html.bs-exact-theme .p-nav-scroller {
      overflow-y: hidden !important;
      scrollbar-width: none !important;
    }
    html.bs-exact-theme .p-nav-inner::-webkit-scrollbar,
    html.bs-exact-theme .p-nav-scroller::-webkit-scrollbar {
      display: none !important;
    }
  }

  /* =========================================================================
   * 4. HOMEPAGE STOREFRONT — Double Chevrons, Video Cards, Mobile H1 & Chips
   * ========================================================================= */

  /* Fix double overlapping chevron bug (shared-v46 added '⌄' on top of nf_bs_shop rotated L-border) */
  html.bs-shop-page body .bsMosaic .bsShop-discovery summary::after {
    content: '' !important;
    display: inline-block !important;
    flex: none !important;
    width: 6px !important;
    height: 6px !important;
    margin-left: 6px !important;
    padding: 0 !important;
    border-style: solid !important;
    border-color: #d4a47d !important;
    border-width: 0 1.5px 1.5px 0 !important;
    background: none !important;
    transform: translateY(-2px) rotate(45deg) !important;
    transition: transform 0.15s ease !important;
  }
  html.bs-shop-page body .bsMosaic .bsShop-discovery details[open] > summary::after {
    transform: translateY(1px) rotate(-135deg) !important;
  }
  html.bs-shop-page body .bsMosaic .bsShop-collection > summary::after {
    margin-left: auto !important;
  }

  /* Crisp dark backing while WebP poster decodes */
  html.bs-shop-page .bsShop-media {
    background-color: #14171f !important;
  }
  html.bs-shop-page .bsShop-media > video,
  html.bs-shop-page .bsShop-media > img {
    background-color: #14171f;
  }

  /* Calm down showcase card borders, shadows & remove gratuitous hover zoom */
  html.bs-shop-page .bsShop-bossCard,
  html.bs-shop-page .bsMosaic-tile {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28) !important;
    transition: border-color 0.16s ease, background-color 0.16s ease !important;
  }
  html.bs-shop-page .bsShop-bossCard:hover,
  html.bs-shop-page .bsMosaic-tile:hover {
    transform: none !important;
    border-color: rgba(214, 134, 104, 0.58) !important;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.36) !important;
  }
  html.bs-shop-page .bsShop-bossCard:hover .bsShop-media > img,
  html.bs-shop-page .bsShop-bossCard:hover .bsShop-media > video,
  html.bs-shop-page .bsMosaic-image:hover > img {
    transform: none !important;
  }

  /* Remove ugly horizontal OS scrollbar inside homepage card tag chips */
  html.bs-shop-page .bsShop-chips {
    display: flex !important;
    flex-wrap: wrap !important;
    overflow: visible !important;
    gap: 5px !important;
    scrollbar-width: none !important;
  }
  html.bs-shop-page .bsShop-chips::-webkit-scrollbar {
    display: none !important;
  }

  /* Mobile homepage H1 pill overflow & Latest uploads chevron alignment */
  @media (max-width: 900px) {
    html.bs-shop-page body.nf-bs-exact .p-body-header {
      padding: 8px 12px !important;
      margin: 4px 0 10px !important;
      border-radius: 6px !important;
      background: rgba(24, 27, 35, 0.72) !important;
      border: 1px solid rgba(186, 128, 96, 0.22) !important;
      border-left: 3px solid #c4644e !important;
      box-sizing: border-box !important;
      overflow: hidden !important;
    }
    html.bs-shop-page body.nf-bs-exact .p-body-header .p-title-value,
    html.bs-shop-page body.nf-bs-exact .p-body-header h1 {
      font-size: clamp(17px, 4.8vw, 22px) !important;
      line-height: 1.25 !important;
      white-space: normal !important;
      overflow-wrap: break-word !important;
      margin: 0 !important;
      padding: 0 !important;
    }
    html.bs-shop-page body .bsMosaic .bsShop-discovery .bsShop-latest > summary {
      justify-content: flex-start !important;
      gap: 6px !important;
      padding-left: 4px !important;
    }
    html.bs-shop-page body .bsMosaic .bsShop-discovery .bsShop-latest > summary::after {
      margin-left: 4px !important;
    }
  }

  /* =========================================================================
   * 5. MOBILE HAMBURGER DRAWER — Alignment, Scrollbars, Close Button, Input
   * ========================================================================= */
  html.bs-exact-theme .offCanvasMenu-content {
    overflow-x: hidden !important;
    scrollbar-width: thin !important;
    scrollbar-color: rgba(186, 128, 96, 0.35) transparent !important;
  }
  html.bs-exact-theme .offCanvasMenu-content::-webkit-scrollbar {
    width: 4px !important;
    height: 0 !important;
  }
  html.bs-exact-theme .offCanvasMenu-content .offCanvasMenu-closer {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    border-radius: 6px !important;
  }
  /* Left-align ALL mobile drawer nav links consistently (no centered Minecraft Downloads) */
  html.bs-exact-theme .offCanvasMenu .offCanvasMenu-link,
  html.bs-exact-theme .offCanvasMenu a[data-nav-id="xfrm"],
  html.bs-exact-theme .offCanvasMenu a[data-nav-id="nfBsBuildsSchematics"] {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    text-align: left !important;
    gap: 10px !important;
    padding: 11px 14px !important;
    min-height: 48px !important;
  }
  html.bs-exact-theme .offCanvasMenu a[data-nav-id="xfrm"] .ffNavLabel,
  html.bs-exact-theme .offCanvasMenu a[data-nav-id="nfBsBuildsSchematics"] .ffNavLabel {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    transform: none !important;
    text-align: left !important;
  }
  html.bs-exact-theme .offCanvasMenu a[data-nav-id="xfrm"] .ffNavLabel::before,
  html.bs-exact-theme .offCanvasMenu a[data-nav-id="nfBsBuildsSchematics"] .ffNavLabel::before {
    position: static !important;
    order: 2 !important;
    margin-top: 1px !important;
    font-size: 10.5px !important;
    line-height: 1.25 !important;
    text-align: left !important;
    opacity: 0.78 !important;
  }
  html.bs-exact-theme .offCanvasMenu .bsx-drawerSearch input {
    font-size: 13px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  /* =========================================================================
   * 6. RESOURCE CATALOG & CATEGORIES — Single-Row Toolbar, Stars, Toggler, SEO Hub
   * ========================================================================= */

  /* Keep sort links + List/Gallery + Quick jump + Saved · N on ONE clean desktop row */
  @media (min-width: 1180px) {
    html.bsx-catalogPage body.nf-bs-exact .bsx-browseTools {
      flex-wrap: nowrap !important;
      justify-content: space-between !important;
      gap: 6px !important;
      padding: 8px 10px !important;
    }
    html.bsx-catalogPage body.nf-bs-exact .bsx-sortLinks {
      gap: 4px !important;
      flex-wrap: nowrap !important;
      min-width: 0 !important;
    }
    html.bsx-catalogPage body.nf-bs-exact .bsx-viewSwitch {
      gap: 3px !important;
      flex-shrink: 0 !important;
      margin-left: auto !important;
    }
    html.bsx-catalogPage body.nf-bs-exact :is(.bsx-browseTools a, .bsx-browseTools button) {
      padding: 5px 8px !important;
      min-height: 31px !important;
      font-size: 11.5px !important;
      white-space: nowrap !important;
      flex-shrink: 0 !important;
    }
  }

  /* Raise empty star icon contrast so rating rows don't look broken */
  html.bs-exact-theme body .ratingStars .ratingStars-star::before {
    color: #938673 !important;
  }
  html.bs-exact-theme body .ratingStars .ratingStars-star--full::before,
  html.bs-exact-theme body .ratingStars .ratingStars-star--half::after {
    color: #f6c963 !important;
  }

  /* Fix Rust .16/ category subtree toggler click swallowed by .categoryList-link::after */
  html.bs-exact-theme .categoryList-toggler {
    position: relative !important;
    z-index: 6 !important;
  }

  /* Calm hover & remove hover-scale jump on resource rows */
  html.bs-exact-theme .structItem--resource:hover {
    transform: none !important;
  }

  /* Balance the 7-card SEO category hub grid (preserves 100% of SEO copy & links) */
  html.bs-exact-theme .nfSeo-discoveryGrid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  @media (min-width: 901px) {
    html.bs-exact-theme .nfSeo-discoveryGrid > a:last-child:nth-child(3n + 1) {
      grid-column: 1 / -1 !important;
    }
    html.bs-exact-theme .nfSeo-discoveryGrid > a:nth-last-child(2):nth-child(3n + 1) {
      grid-column: span 1 !important;
    }
    html.bs-exact-theme .nfSeo-discoveryGrid > a:last-child:nth-child(3n + 2) {
      grid-column: span 2 !important;
    }
  }
  @media (max-width: 900px) {
    html.bs-exact-theme .nfSeo-discoveryGrid {
      grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    html.bs-exact-theme .nfSeo-discoveryGrid > a:last-child:nth-child(odd) {
      grid-column: 1 / -1 !important;
    }
  }
  @media (max-width: 540px) {
    html.bs-exact-theme .nfSeo-discoveryGrid {
      grid-template-columns: 1fr !important;
    }
  }

  /* =========================================================================
   * 7. SINGLE RESOURCE PAGE — Active Tab Bar, Mobile Scrollbar, Sticky Sidebar
   * ========================================================================= */

  /* Replace cramped vertical yellow line colliding with "Overview" text */
  html[data-template="xfrm_resource_view"].bs-exact-theme .bsResource-index a[aria-current="location"] {
    border-left: 0 !important;
    padding-left: 0 !important;
    color: #ffe2b3 !important;
    box-shadow: inset 0 -2px 0 #e0a458 !important;
  }

  /* Hide ugly brown OS horizontal scrollbar under mobile resource tabs + soft right edge */
  @media (max-width: 900px) {
    html[data-template="xfrm_resource_view"].bs-exact-theme .tabs--standalone,
    html[data-template="xfrm_resource_view"].bs-exact-theme .tabs--standalone .hScroller-scroll {
      scrollbar-width: none !important;
      -ms-overflow-style: none !important;
    }
    html[data-template="xfrm_resource_view"].bs-exact-theme .tabs--standalone::-webkit-scrollbar,
    html[data-template="xfrm_resource_view"].bs-exact-theme .tabs--standalone .hScroller-scroll::-webkit-scrollbar {
      display: none !important;
      height: 0 !important;
    }
  }

  /* Keep right sidebar sticky on desktop single-resource view to prevent huge empty gutter */
  @media (min-width: 901px) {
    html[data-template="xfrm_resource_view"].bs-exact-theme .p-body-sidebar {
      position: sticky !important;
      top: 18px !important;
      align-self: start !important;
    }
  }

  /* =========================================================================
   * 8. FORUMS — Kill FusionFall Neon Green, Fix Mobile Widget Icons & Chevrons
   * ========================================================================= */

  /* Replace leftover FusionFall #7ee000 neon green sticky thread accent with copper */
  html.bs-exact-theme .structItem--thread.is-sticky {
    border-left: 2px solid #c86448 !important;
  }

  /* Hide tiny squished corner icons protruding outside padding on widget minorHeaders */
  html.bs-exact-theme .block[data-widget-key] .block-minorHeader::before {
    display: none !important;
    content: none !important;
  }
  html.bs-exact-theme .block[data-widget-key] .block-minorHeader {
    padding-left: 16px !important;
  }

  /* Improve contrast on category collapse toggles atop terracotta gradient headers */
  html.bs-exact-theme .block--category .block-header .collapseTrigger,
  html.bs-exact-theme .block--category .block-header .collapseTrigger::before {
    color: #fff2ea !important;
    opacity: 0.92 !important;
  }

  /* Tone down lone diagonal arrow on forum resource cards with zero downloads */
  html.bs-exact-theme .bsf-resourceCopy > span > span[aria-hidden="true"] {
    opacity: 0.45 !important;
    transition: opacity 0.15s ease, transform 0.15s ease;
  }
  html.bs-exact-theme .bsf-resource:hover .bsf-resourceCopy > span > span[aria-hidden="true"] {
    opacity: 0.95 !important;
  }

  /* =========================================================================
   * 9. REGISTER / PLANS & MOBILE BOTTOM BAR CLEARANCE
   * ========================================================================= */

  /* Remove distracting glow halos on plans cards while preserving gold Ultra authority */
  html.bs-exact-theme .bsu-plans .bsu-card--ultra {
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 224, 152, 0.22) !important;
  }
  html.bs-exact-theme .bsu-promoToggle-icon {
    width: 14px !important;
    height: 14px !important;
    object-fit: contain !important;
    image-rendering: auto !important;
  }

  /* Never let the floating mobile bottom nav overlap footer links */
  @media (max-width: 900px) {
    html.bs-exact-theme .p-footer {
      padding-bottom: 92px !important;
    }
    /* Hide single-resource floating upsell bar on /register/ and /account/upgrades */
    html[data-template="af_paidregistrations_accounttype"].bs-exact-theme .bsx-actionbar,
    html[data-template="account_upgrades"].bs-exact-theme .bsx-actionbar {
      display: none !important;
    }
  }
}
