-- =============================================================================
-- File: ArenaCore/Core/UI.Vanity.lua - v8.0 RENAMED
-- =============================================================================
local addonName, _ns = ...
local addon = _G.ArenaCore or {}
_G.ArenaCore = addon
local V = {}
addon.Vanity = V
-- START: REPLACE with this code block
do
  -- Method-style helpers to correctly handle calls from other files
  function addon:CreateFlatTexture(parent, layer, sublevel, color, alpha)
    local lvl = sublevel or 0
    -- Safety check to prevent this exact error
    if type(lvl) ~= "number" then lvl = 0 end
    
    if lvl > 7 then lvl = 7 elseif lvl < -8 then lvl = -8 end
    
    local t = parent:CreateTexture(nil, layer or "BACKGROUND", nil, math.floor(lvl))
    local c = color or {0.1, 0.1, 0.1, 1}
    local a = alpha or c[4] or 1
    t:SetColorTexture(c[1], c[2], c[3], a)
    return t
  end
  function addon:AddHairlineRect(frame, color, alpha, z)
    local c = color or COLORS.BORDER_LIGHT; local a = alpha or 1; local lvl = z or 6
    -- Use 'self:' to call the method version
    local t=self:CreateFlatTexture(frame,"OVERLAY",lvl,c,a);t:SetPoint("TOPLEFT",0,0);t:SetPoint("TOPRIGHT",0,0);t:SetHeight(1)
    local b=self:CreateFlatTexture(frame,"OVERLAY",lvl,c,a);b:SetPoint("BOTTOMLEFT",0,0);b:SetPoint("BOTTOMRIGHT",0,0);b:SetHeight(1)
    local l=self:CreateFlatTexture(frame,"OVERLAY",lvl,c,a);l:SetPoint("TOPLEFT",0,0);l:SetPoint("BOTTOMLEFT",0,0);l:SetWidth(1)
    local r=self:CreateFlatTexture(frame,"OVERLAY",lvl,c,a);r:SetPoint("TOPRIGHT",0,0);r:SetPoint("BOTTOMRIGHT",0,0);r:SetWidth(1)
  end
  function addon:CreateStyledText(parent, text, size, color, layer, flags)
    local fs = parent:CreateFontString(nil, layer or "OVERLAY")
    -- Set font BEFORE setting text to avoid "Font not set" errors
    local fontSet = fs:SetFont("Interface\\AddOns\\ArenaCore\\Media\\Fonts\\arenacore.ttf", tonumber(size) or 12, flags or "")
    if not fontSet then
      -- Fallback to WoW default font
      fs:SetFont("Fonts\\FRIZQT__.TTF", tonumber(size) or 12, flags or "")
    end
    fs:SetText(text or "")
    if type(color) == "table" then
      fs:SetTextColor(unpack(color))
    else
      fs:SetTextColor(1, 1, 1, 1)
    end
    fs:SetShadowOffset(0, 0)
    return fs
  end
  function addon:CreateTexturedButton(parent, w, h, label, texBase, name)
    local b = CreateFrame("Button", name or nil, parent)
    b:SetSize(w, h)
    local path = "Interface\\AddOns\\ArenaCore\\Media\\" .. texBase .. ".tga"
    local n = b:CreateTexture(nil, "BACKGROUND")
    n:SetAllPoints(); n:SetTexture(path);
    b:SetNormalTexture(n)
    local hlt = b:CreateTexture(nil, "HIGHLIGHT")
    hlt:SetAllPoints(); hlt:SetTexture(path); hlt:SetVertexColor(1, 1, 1, 0.85)
    b:SetHighlightTexture(hlt)
    if label and label ~= "" then
      -- Use 'self:' to call the method version
      local t = self:CreateStyledText(b, label, 12, COLORS.TEXT, "OVERLAY", "")
      t:SetPoint("CENTER", 0, 0)
      b.text = t
    end
    return b
  end
  function addon:CreateProfileStyleButton(parent, width, height, text, colorType, fontSize)
    if not parent then return nil end
    local btn = CreateFrame("Button", nil, parent)
    btn:SetSize(width, height)
    btn:EnableMouse(true)
    btn:RegisterForClicks("LeftButtonUp")
    local colors = {
      primary = {
        bg = {0.545, 0.271, 1.000, 1},
        border = {0.4, 0.2, 0.7, 1},
        hover = {0.645, 0.371, 1.000, 1}
      },
      success = {
        bg = {0.133, 0.667, 0.267, 1},
        border = {0.1, 0.5, 0.2, 1},
        hover = {0.233, 0.767, 0.367, 1}
      },
      emerald = {
        bg = {0.2, 0.8, 0.4, 1},
        border = {0.15, 0.65, 0.3, 1},
        hover = {0.3, 0.9, 0.5, 1}
      },
      danger = {
        bg = {0.863, 0.176, 0.176, 1},
        border = {0.6, 0.1, 0.1, 1},
        hover = {0.963, 0.276, 0.276, 1}
      }
    }
    local color = colors[colorType] or colors.primary
    local bg = btn:CreateTexture(nil, "BACKGROUND")
    bg:SetAllPoints()
    bg:SetColorTexture(color.bg[1], color.bg[2], color.bg[3], color.bg[4])
    btn.bg = bg
    local border = btn:CreateTexture(nil, "BORDER")
    border:SetAllPoints()
    border:SetColorTexture(color.border[1], color.border[2], color.border[3], color.border[4])
    border:SetPoint("TOPLEFT", 1, -1)
    border:SetPoint("TOPRIGHT", -1, -1)
    border:SetPoint("BOTTOMLEFT", 1, 1)
    border:SetPoint("BOTTOMRIGHT", -1, 1)
    btn.border = border
    local btnText = btn:CreateFontString(nil, "OVERLAY", nil, 7)
    btnText:SetFont("Interface/AddOns/ArenaCore/Media/Fonts/arenacore.ttf", fontSize or 11)
    btnText:SetText(text or "")
    btnText:SetTextColor(1, 1, 1, 1)
    btnText:SetPoint("CENTER", 0, 0)
    btn.text = btnText
    -- Add purple glow overlay on hover
    local glow = btn:CreateTexture(nil, "OVERLAY")
    glow:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\tab-purple-matte.tga")
    glow:SetAllPoints()
    glow:SetBlendMode("ADD")
    glow:SetAlpha(0)
    btn.glow = glow
    btn:SetScript("OnEnter", function(self)
      self.bg:SetColorTexture(color.hover[1], color.hover[2], color.hover[3], color.hover[4])
      -- Fade in purple glow
      if self.glow then
        self.glow:SetAlpha(0.3)
      end
    end)
    btn:SetScript("OnLeave", function(self)
      self.bg:SetColorTexture(color.bg[1], color.bg[2], color.bg[3], color.bg[4])
      -- Fade out purple glow
      if self.glow then
        self.glow:SetAlpha(0)
      end
    end)
    return btn
  end
end
-- END: REPLACE with this code block
-- Define necessary colors locally to avoid errors
local COLORS = {
  PRIMARY      = {0.545, 0.271, 1.000, 1}, -- #8B45FF
  TEXT         = {1.000, 1.000, 1.000, 1},
  TEXT_2       = {0.706, 0.706, 0.706, 1}, -- #B4B4B4
  BG           = {0.165, 0.165, 0.165, 1}, -- #2A2A2A
  -- INPUT_DARK removed - using centralized definition from UI.lua
  BORDER       = {0.196, 0.196, 0.196, 1}, -- #323232
  BORDER_LIGHT = {0.278, 0.278, 0.278, 1}, -- #474747
}
-- Icons
local ICONS = {
  HEART = "Interface\\AddOns\\ArenaCore\\Media\\UI\\arena-core-heart.tga",
  SWORD = "Interface\\AddOns\\ArenaCore\\Media\\UI\\arena-core-sword.tga",
}
-- Motto pool
V.MOTTO_LINES = {
  "No Excuses, Only Results",
  "One Mistake, Game Over",
  "Precision Over Panic",
  "Dominate or Be Dominated",
  "Every Bind Counts",
  "Pressure Creates Power",
  "Control The Chaos",
  "Only Skill Survives",
  "Strength Through Struggle",
  "Don't Forget To Press Wall",
  "Timing Beats Talent",
  "Fear The Calm Before The Burst",
  "Earn Every Victory",
  "It's Out Of Your Control, Just Press",
  "Best Game Ever Made",
  "Even Venruki Didn't Block Once",
}
-- Public helper: page motto strip (callable anytime)
function V:EnsureMottoStrip(parent)
  parent._mottoStrip = parent._mottoStrip or CreateFrame("Frame", nil, parent)
  local bar = parent._mottoStrip
  bar:ClearAllPoints()
  bar:SetPoint("TOPLEFT", parent, "TOPLEFT", 6, -8)
  bar:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -6, -8)
  bar:SetHeight(40)
  if not bar.bg then
    bar.bg = bar:CreateTexture(nil, "BACKGROUND", nil, 0)
    bar.bg:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\bar-orange-matte.tga") -- Using your matte texture
    bar.bg:SetAllPoints()
    bar.text = bar:CreateFontString(nil, "OVERLAY")
    -- CRITICAL FIX: Set font BEFORE setting text
    local fontSet = bar.text:SetFont("Interface\\AddOns\\ArenaCore\\Media\\Fonts\\arenacore.ttf", 13, "")
    if not fontSet then
      -- Fallback to WoW default font if custom font fails
      bar.text:SetFont("Fonts\\FRIZQT__.TTF", 13, "")
    end
    bar.text:SetPoint("CENTER", 0, 0)
  end
  local pick = math.random(1, #self.MOTTO_LINES)
  bar.text:SetText(self.MOTTO_LINES[pick])
  return bar
end
-- ============================================================================
-- Patch Notes Popup (RE-SKINNED)
-- ============================================================================
function V:ShowPatchNotes()
  -- Patch notes popup - debug removed for clean release
  
  -- FORCE RECREATE: Destroy old frame to apply new styling
  if addon._patchFrame then
    -- Destroying old frame for fresh styling
    addon._patchFrame:Hide()
    addon._patchFrame = nil
  end
  -- Create a plain Frame, NOT a BackdropTemplate
  local f = CreateFrame("Frame", "ArenaCorePatchNotes", UIParent)
  f:SetSize(520, 600); f:SetPoint("CENTER", 0, 0); f:SetFrameStrata("DIALOG")
  f:SetMovable(true); f:SetClampedToScreen(true); f:EnableMouse(true); f:RegisterForDrag("LeftButton")
  f:SetScript("OnDragStart", f.StartMoving); f:SetScript("OnDragStop", f.StopMovingOrSizing)
  
  -- Frame created, applying ArenaCore skin
  if not f._skin then
   -- Background using ArenaCore styling (matching other pages)
local bg = addon:CreateFlatTexture(f, "BACKGROUND", 1, COLORS.BG, 1)
bg:SetAllPoints()
-- Border using ArenaCore styling
addon:AddWindowEdge(f, 1, 0)
-- Header matching other configuration windows
local header = CreateFrame("Frame", nil, f)
header:SetPoint("TOPLEFT", 8, -8)
header:SetPoint("TOPRIGHT", -8, -8)
header:SetHeight(50)
-- Header background - solid dark color (no texture, simpler approach)
local headerBg = addon:CreateFlatTexture(header, "BACKGROUND", 1, {0.12, 0.12, 0.12, 1}, 1)
headerBg:SetAllPoints()
-- Purple accent line (hairline like main UI)
local accent = addon:CreateFlatTexture(header, "OVERLAY", 3, COLORS.PRIMARY, 1)
accent:SetPoint("TOPLEFT", 0, 0)
accent:SetPoint("TOPRIGHT", 0, 0)
accent:SetHeight(2)
-- Header border
local hbLight = addon:CreateFlatTexture(header, "OVERLAY", 2, COLORS.BORDER_LIGHT, 0.8)
hbLight:SetPoint("BOTTOMLEFT", 0, 0)
hbLight:SetPoint("BOTTOMRIGHT", 0, 0)
hbLight:SetHeight(1)
       -- Style the title text (NO outline) - now in header
    f._title = addon:CreateStyledText(header, "What's new in v" .. (addon.Version or "0.10.2b"), 14, COLORS.TEXT, "OVERLAY", "")
    f._title:SetPoint("LEFT", 15, 0)
    -- Style the close button to match the main panel's - now in header
    f._close = addon:CreateProfileStyleButton(header, 36, 36, "", "danger", 16)
    f._close:SetPoint("RIGHT", -10, 0)
    local xText = addon:CreateStyledText(f._close, "×", 16, COLORS.TEXT, "OVERLAY", "")
    xText:SetPoint("CENTER", 0, 0)
    f._close:SetScript("OnClick", function() f:Hide() end)
    -- Create scroll frame for content
    local scrollFrame = CreateFrame("ScrollFrame", nil, f)
    scrollFrame:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 7, -15)
    scrollFrame:SetPoint("BOTTOMRIGHT", -14, 14)
    
    local scrollChild = CreateFrame("Frame", nil, scrollFrame)
    scrollChild:SetWidth(scrollFrame:GetWidth() - 20)
    scrollChild:SetHeight(1000) -- Set initial height for dividers to show
    scrollFrame:SetScrollChild(scrollChild)
    
    -- Style the body text (NO outline) - positioned in scroll child
    f._body = addon:CreateStyledText(scrollChild, "", 12, COLORS.TEXT_2, "OVERLAY", "")
    f._body:SetPoint("TOPLEFT", 0, 0)
    f._body:SetPoint("TOPRIGHT", 0, 0)
    f._body:SetJustifyH("LEFT"); f._body:SetJustifyV("TOP")
    f._body:SetSpacing(3)
    
    -- Enable mouse wheel scrolling
    scrollFrame:EnableMouseWheel(true)
    scrollFrame:SetScript("OnMouseWheel", function(self, delta)
        local current = self:GetVerticalScroll()
        local maxScroll = self:GetVerticalScrollRange()
        local newScroll = math.max(0, math.min(maxScroll, current - (delta * 20)))
        self:SetVerticalScroll(newScroll)
    end)
    
    f._scrollFrame = scrollFrame
    f._scrollChild = scrollChild
    
    
    f._skin = true
  end
  -- Build release notes with color coding and formatting
  local notes = table.concat({
    "\n|A:Crosshair_Important_128:32:32|a |cffFF7A18Scroll down|r |cff44FF44to see all changes in this build|r\n\n",
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cffFFD700              ADDON RELEASE NOTES              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cffFFD700Addon:|r ARENA CORE\n",
    "|cffFFD700Version:|r |cffB266FFv0.10.2b|r\n",
    "|cffFFD700Build:|r |cffB266FF12.0+|r\n",
    "|cffFFD700Game Version:|r |cff8B45FFRetail - Midnight|r\n",
    "|cffFFD700Release Date:|r 04/07/2026\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.10.2b CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff00FF00>> BUG FIXES:\n\n",
    
    "|cff44FF44• FIXED:|r |cffFF7A18A rare edge case issue|r |cff44FF44with some users experiencing a|r |cffFF7A18DR icon|r |cff44FF44not fully clearing in arena.|r\n\n",
    
    "|cff44FF44• FIXED:|r |cffFF7A18FrameSort addon integration|r |cff44FF44now fully working again after being|r |cffFF7A18broken|r |cff44FF44in previous updates.|r\n\n",
    
    "|cff44FF44• FIXED:|r |cffFF7A18Issue with some settings|r |cff44FF44not saving properly when using a|r |cffFF7A18custom profile layout|r |cff44FF44configuration.|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.10.2 CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff00FF00>> NEW FEATURES:\n\n",
    
    "|cff44FF44• ADDED:|r |cffFF7A18New Edit Mode button|r |cff44FF44in the UI header, intuitive edit mode allows users to use|r |cffFF7A18Shift+Click|r |cff44FF44to drag various elements freely now such as|r |cffFF7A18Class Icons, Racials, Trinkets, Cast Bars|r |cff44FF44and more.|r\n\n",
    
    "|cff44FF44• ADDED:|r |cffFF7A18New layout editor|r |cff44FF44when using the|r |cffFF7A18Unlock|r |cff44FF44button, no need for the new edit mode feature, you can still use|r |cffFF7A18Shift+Click|r |cff44FF44using the simple|r |cffFF7A18Unlock|r |cff44FF44button|r\n\n",
    
    "|cff00FF00>> BUG FIXES:\n\n",
    
    "|cff44FF44• FIXED:|r |cffFF7A18Spec icons|r |cff44FF44not coming back in test mode if user disables the|r |cffFF7A18spec icon feature|r |cff44FF44that replaces class icons|r\n\n",
    
    "|cff44FF44• FIXED:|r |cffFF7A18Crowd control auras|r |cff44FF44not coming back in test mode if you had them|r |cffFF7A18disabled then re enabled|r |cff44FF44them|r\n\n",
    
    "|cff44FF44• FIXED:|r |cffFF7A18CC auras|r |cff44FF44not showing due to the above issue in the|r |cffFF7A18UI|r\n\n",
    
    "|cff44FF44• ADDED:|r |cffFF7A18More team mismatch guards|r |cff44FF44to help with incorrect data being displayed in|r |cffFF7A18skirms|r |cff44FF44and other rare edge cases|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.10.1.1b CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff44FF44• Made changes to adapt to the new|r |cffFF7A18API changes by blizzard|r|cff44FF44, seems never ending :(|r\n\n",
    
    "|cff44FF44• Fixes|r |cffFF7A18lots of visual and timing issues|r |cff44FF44for various features as a result.|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.10.1.1 CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff44FF44• Fixed|r |cffFF7A18trinket tracking|r |cff44FF44in|r |cffFF7A18Solo Shuffle|r |cff44FF44(and a couple related variables).|r\n\n",
    
    "|cff44FF44• Cleaned up|r |cffFF7A18visual edge cases|r |cff44FF44across the board.|r\n\n",
    
    "|cff44FF44• Fixed|r |cffFF7A18Racial icons|r |cff44FF44sometimes not properly using the saved|r |cffFF7A18border theme|r |cff44FF44in arena matches.|r\n\n",
    
    "|cff44FF44• Fixed a visual issue with|r |cffFF7A18DR icons|r |cff44FF44sometimes showing in|r |cffFF7A18prep room|r |cff44FF44of arena matches.|r\n\n",
    
    "|cff44FF44• Fixed an edge case where|r |cffFF7A18arena frame spacing|r |cff44FF44wasn't changing in real time on certain themes.|r\n\n",
    
    "|cff44FF44• Fixed an issue with|r |cffFF7A18DR Tracking|r |cff44FF44on various themes.|r\n\n",
    
    "|cff44FF44• Cleaned up some backend edge cases so arena features behave|r |cffFF7A18smoother|r|cff44FF44.|r\n\n",
    
    "|cff00FF00>> NEW FEATURES:\n\n",
    
    "|cff44FF44• ADDED:|r |cffFF7A18Custom Layouts|r |cff44FF44page has begun to be built, currently added|r |cffFF7A18Venruki's|r |cff44FF44profile/layout, with more to come.|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.10.1.0 CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff00FF00>> PERFORMANCE:\n\n",
    "|cffB266FF• Improved memory/CPU usage performance overall for the entire addon.|r\n",
    "|cffFFFFFFGeneral optimizations across the board to keep things lighter and smoother.|r\n\n",
    "|cff00FF00>> FRAME SYSTEM + SETTINGS:\n\n",
    "|cffB266FF• Improved frame backgrounds and the overall system for frame design and settings.|r\n",
    "|cffFFFFFFMore consistent visuals and cleaner behavior when applying + saving settings.|r\n\n",
    "|cffB266FF• Improved the smoothness of slider settings visually (trinkets + more) while editing.|r\n",
    "|cffFFFFFFLess jank while dragging sliders so you can actually enjoy tweaking stuff.|r\n\n",
    "|cffB266FF• Fixed various visual issues some users ran into when saving specific settings.|r\n",
    "|cffFFFFFFMore reliable save/restore behavior with fewer weird edge cases.|r\n\n",
    "|cff00FF00>> TARGET HIGHLIGHT:\n\n",
    "|cffB266FF• Target Highlight improvements.|r\n",
    "|cffFFFFFFYou can now disable it, or move it to highlight the Class Icon instead of the full frame.|r\n\n",
    "|cff00FF00>> THEMES + VISUAL POLISH:\n\n",
    "|cffB266FF• Added a dark color theme to the original default Arena Core theme.|r\n",
    "|cffFFFFFFCleaner vibe, better contrast, and easier on the eyes in-game.|r\n\n",
    "|cffB266FF• Fixed DR borders visually and improved their styling.|r\n",
    "|cffFFFFFFMore consistent borders + better pixel snapping for clean rendering.|r\n\n",
    "|cffB266FF• Improved spell cast bar fill texture/colors and styling.|r\n",
    "|cffFFFFFFCast bars should look cleaner and more consistent across themes.|r\n\n",
    "|cffB266FF• Added the texture back (like before Midnight) for uninterruptible casts on the cast bar.|r\n",
    "|cffFFFFFFUninterruptible casts are once again visually obvious at a glance.|r\n\n",
    "|cffB266FF• Improved pixel-perfect styling for borders, frames, and more.|r\n",
    "|cffFFFFFFSmall details, big difference. Everything lines up cleaner now.|r\n\n",
    "|cff00FF00>> JUST BLASTIN':\n\n",
    "|cffB266FF• Added a Border Thickness slider for the Just Blastin' theme.|r\n",
    "|cffFFFFFFYou can now fine-tune the pixel border thickness in real time (1px to 5px).|r\n\n",
    "|cff00FF00>> CAST BARS:\n\n",
    "|cffB266FF• Added Blizzard \"shield\" size slider for uninterruptible casts located in the Spell Icons sub page under Cast Bars.|r\n",
    "|cffFFFFFFYou can now scale the shield icon that appears behind spell icons for uninterruptible casts (50% to 200%).|r\n\n",
    "|cffB266FF• Added Cast Bar Uninterruptible custom texture drop down menu so users can choose their own texture for these.|r\n",
    "|cffFFFFFFPick any texture from the dropdown to customize how uninterruptible casts look on the cast bar.|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.10.0.0b CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "\n|cffB266FFFixed issue with some settings persisting/not saving properly|r\n\n",
    "|cffB266FFMAJOR COMPLETE UI/UX OVERHAUL - ESSENTIAL UPDATE|r\n\n",
    
    "|cffFFD700NOTE THAT THIS IS A ESSENTIALLY A COMPLETE OVERHAUL:|r\n",
    "|cffFFFFFFYou will likely need to make fine tune adjustments to your settings and placements of things as a result, but will be worth it.\n\n",
    
    "|cff00FF00>> COMPLETE UI/UX OVERHAUL:|r\n\n",
    
    "|cffB266FF• ONE PAGE UI SYSTEM|r\n",
    "|cffFFFFFFComplete UI/UX overhaul. EVERYTHING was redone on the backend and almost all visuals have changed. Massive upgrades to the UI. There are NO longer separate windows for various pages/settings. A new ONE page UI system. Things are easier to find, look at, use and read.\n\n",
    
    "|cffB266FF• EASIER NAVIGATION|r\n",
    "|cffFFFFFFIt may take time getting used to things again, but long term health and the ability to follow the pages easier and use the settings will attract more users.\n\n",
    
    "|cff00FF00>> PROFILES OVERHAUL:|r\n\n",
    
    "|cffB266FF• THEME-SPECIFIC PROFILES|r\n",
    "|cffFFFFFFProfiles now share all settings properly for each respective theme, you can now set up each theme available and all proper settings will be shared for those themes.\n\n",
    
    "|cffB266FF• PERFECT PROFILE SHARING|r\n",
    "|cffFFFFFFSharing shares ALL settings, so the end user who receives the profile code will get the users exact set up.\n\n",
    
    "|cff00FF00>> VISUAL PERFECTION:|r\n\n",
    
    "|cffB266FF• PIXEL PERFECT PLACEMENT|r\n",
    "|cffFFFFFFPixel perfect placement and syncing across all assets, no more mis aligned borders that are very slightly off or don't match.\n\n",
    
    "|cff00FF00>> CLEANER EXPERIENCE:|r\n\n",
    
    "|cffB266FF• CLEANED UP CHAT MESSAGES|r\n",
    "|cffFFFFFFCleaned up in game chat messages such as reload messages and other needs no longer needed.\n\n",
    
    "|cff00FF00>> UNLIMITED CUSTOMIZATION:|r\n\n",
    
    "|cffB266FF• FULL CUSTOMIZATION|r\n",
    "|cffFFFFFFFully customize anything and everything now. The doors are blown wide open.. change the theme and styling of the DR borders, Trinkets, Racials and more.\n\n",
    
    "|cffB266FF• CUSTOM COLOR PICKER|r\n",
    "|cffFFFFFFCustom color picker built in for certain themes so the user can fully control their own specific look and feel.\n\n",
    
    "|cff00FF00>> PERFORMANCE OPTIMIZATIONS:|r\n\n",
    
    "|cffB266FF• CODE CLEANUP|r\n",
    "|cffFFFFFFCleaned up old code, pages and features for Midnight. Pages like Classpacks, Blackout and more are now removed and replaced with a cleaner UI set up and easier navigation.\n\n",
    
    "|cffB266FF• BETTER PERFORMANCE|r\n",
    "|cffFFFFFFSome aspects of these features may come back in a different way in the future, but for now.. better performance over all and less CPU usage.\n\n",
    
    "|cff00FF00>> NEW PERFORMANCE PAGE:|r\n\n",
    
    "|cffB266FF• PERFORMANCE PRESETS|r\n",
    "|cffFFFFFFNew Feature/Page: Performance.. use the custom preset for graphics settings curated by one of the best players on the planet. Gain FPS and the edge you need in pvp.\n\n",
    
    "|cff00FF00>> ENDLESS NEW OPTIONS:|r\n\n",
    
    "|cffB266FF• ADVANCED CUSTOMIZATION|r\n",
    "|cffFFFFFFEndless new options and settings for fine tuning how you want things to look, even so much as adding a glow line for the spiral animations for CC auras, DR animations and more..\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.9.3.2 CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff00FF00>> BUG FIXES/IMPROVEMENTS:|r\n\n",
    "|cffFFD700• Backend cleanup (pre-Midnight)|r\n",
    "|cffFFFFFFSome backend code clean up left behind before Midnight. This ensures no issues lingering from before the Midnight changes. Lots of edge case bug fixes and positioning saving issues as well now all resolved.|r\n\n",
    "|cffFFD700• Stability + performance|r\n",
    "|cffFFFFFFStability fixes and better performance overall in prep for Midnight release.|r\n\n",
    "|cffFFD700• DR icon placement changes|r\n",
    "|cffFFFFFFYou may need to re-adjust your DR icon placement in test mode after this update, please look at this before entering arena! We got rid of a lot of pre-Midnight old code that cleaned a lot of things up and made changes to some placement icons.|r\n\n",
    "|cffB266FF• BIG NEW UPDATE COMING SOON|r\n",
    "|cffFFFFFFBIG NEW UPDATE COMING SOON BEFORE MIDNIGHT SEASON 1 RELEASES join the discord and be on the look out!|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.9.3.1 CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff44FF44>> NEW FEATURES:|r\n\n",
    
    "|cffB266FF• Brand NEW Arena Frame theme|r\n",
    "|cffFFFFFFMinimalist styling with simple Arena Core flare with a nice default layout|r\n\n",
    
    "|cffB266FF• Status text positioning|r\n",
    "|cffFFFFFFAdded health text etc positioning options|r\n\n",
    
    "|cffB266FF• CC Auras in test mode|r\n",
    "|cffFFFFFFAdded CC Auras functionality while in test mode|r\n\n",
    
    "|cffB266FF• Color+Texture glows to current target|r\n",
    "|cffFFFFFFAdded Color+Texture glows to your current target when using the Class Indicator icons above friendly targets (you will want this)|r\n\n",
    
    "|cffB266FF• Custom color + glow to your healer|r\n",
    "|cffFFFFFFAdded custom color + glow to your healer if you have Wheres My Healer feature on (you will want this)|r\n\n",
    
    "|cff00FF00>> BUG FIXES/IMPROVEMENTS:|r\n\n",
    "|cffFFD700• Secret value API fixes|r\n",
    "|cffFFFFFFMade proper fixes to avoid secret errors with new API changes|r\n\n",
    
    "|cffFFD700• Cast bar test mode settings|r\n",
    "|cffFFFFFFFixed issue with cast bars not using your exact settings from test mode inside of arena games|r\n\n",
    
    "|cffFFD700• DR tracking consistency|r\n",
    "|cffFFFFFFFixed issues with DR tracking not being 100% consistent|r\n\n",
    
    "|cffFFD700• DR custom border colors|r\n",
    "|cffFFFFFFFixed the DR custom border colors if you have this option on|r\n\n",
    
    "|cffFFD700• Friendly nameplates player names|r\n",
    "|cffFFFFFFFixed issue with player names showing on friendly nameplates if you have the class indicators on|r\n\n",
    
    "|cffFFD700• Trinket cooldown flickering|r\n",
    "|cffFFFFFFFixed an issue with Trinket cooldowns sometimes flickering|r\n\n",
    
    "|cffFFD700• Custom Racial icons improvement|r\n",
    "|cffFFFFFFImproved the custom Racial icons in prep room when no data is available xD pay attention to this for a good laugh|r\n\n",
    
    "|cffFFD700• UI settings cleanup|r\n",
    "|cffFFFFFFFixed a lot of various settings within the entire UI and cleaned various things up overall|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.9.2.3 CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff00FF00>> BUG FIXES:|r\n\n",
    
    "|cffFFD700• Test Mode Data Leak|r\n",
    "|cffFFFFFFFixed an issue with stale data from test mode leaking into arena prep room.|r\n\n",
    
    "|cffFFD700• Cast Bar Alignment|r\n",
    "|cffFFFFFFFixed issues with cast bars not properly lining up exactly as it shows in test mode.|r\n\n",
    
    "|cffFFD700• Friendly Health Bars|r\n",
    "|cffFFFFFFFixed an issue with health bars not being hidden when you use the Hide Friendly Health Bar toggle.|r\n\n",
    
    "|cffFFD700• Trinket Data|r\n",
    "|cffFFFFFFFixed an issue with Trinkets using proper data.|r\n\n",
    
    "|cff44FF44>> NEW FEATURES:|r\n\n",
    
    "|cffB266FF• Link Horizontal Toggle|r\n",
    "|cffFFFFFFAdded a new \"Link Horizontal\" toggle on the More Goodies page for the Class/Pointer Icons on friendly targets\n",
    "so you can easily auto align them pixel perfectly, along with new values it uses so they match up better.|r\n\n",
    
    "|cffB266FF• Easter Egg|r\n",
    "|cffFFFFFFAdded an easter egg to frames for lol's.|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff44FF44              v0.9.2.2 CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cff44FF44>> NEW FEATURES:\n\n",
    
    "|cffB266FF• Platynator Addon Support|r\n",
    "|cffFFFFFFAdded support for Platynator addon with various features connecting directly such as Enemy Nameplate Names and more.\n",
    "All functions now work correctly with proper integration between ArenaCore and Platynator.|r\n\n",
    
    "|cffB266FF• Target Highlight Thickness Control|r\n",
    "|cffFFFFFFYou can now edit the thickness/thinness of the Target highlight around the arena frames.\n",
    "Find this in the Arena Frames page at the very bottom using the toggle.|r\n\n",
    
    "|cffB266FF• NEW PAGE: Frames/Nameplates|r\n",
    "|cffFFFFFFVarious new mods coming soon! On this page you can find a new feature for Enemy Nameplate Names\n",
    "with various options. For example, you can set enemy player nameplate names to their Spec, Arena number, and more!|r\n\n",
    
    "|cff00FF00>> BUG FIXES:|r\n\n",
    
    "|cffFFD700• Racial Icons|r\n",
    "|cffFFFFFFFixed small issue with racial icons choosing random icons on first round of solo shuffle or normal arena games.|r\n\n",
    
    "|cffFFD700• Cast Bars|r\n",
    "|cffFFFFFFFixed issue with some cast bars/info not properly clearing per round in solo shuffle.|r\n\n",
    
    "|cffFFD700• Death Icons|r\n",
    "|cffFFFFFFFixed Death icons randomly showing over portraits in prep room and when gates open.|r\n\n",
    
    "|cffFFD700• Settings Persistence|r\n",
    "|cffFFFFFFFixed an issue with certain positioning settings not properly saving on reload/new game load.|r\n\n",
    
    "|cffFFAA00>> PATCH 0.9.2.1 NOTES:|r\n\n",
    
    "|cffB266FF• Added support for Platynator addon|r\n",
    "|cffFFFFFFVarious features connect directly to Platynator with working correct functions such as Enemy Name Plate Names etc.|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    
    "|cffFF6644Please understand there are various issues within the Blizzard default UI that are out of my control,\n",
    "such as Party/Class indicators overlapping on certain UI elements, Health bars of nameplates not properly\n",
    "hiding when you toggle the checkbox for it, and more.\n\n",
    
    "When Blizzard fixes their UI issues, Arena Core will continue to update to ensure everything keeps running\n",
    "as smoothly as it can. Please join the Discord for more active updates and insight with us. <3|r\n\n",
    
    "|cffFFD700-----------------------------------------------------|r\n",
    "|cff8B45FF              v0.9.2.0 CHANGELOG              |r\n",
    "|cffFFD700-----------------------------------------------------|r\n\n",
    
    "|cffFFD700BIG UPDATES AND CHANGES:|r\n\n",
    
    "|cffFF6644COMPLETE Arena Core OVERHAUL: PLEASE READ!|r\n\n",
    
    "|cffFFFFFFMidnight has taken its toll on every addon in the game in some form or light, unfortunately that means Arena Core was hit hard.\n",
    "For the time being, a lot of features you have come to love have been disabled. As Midnight continues to create new addon API's, \n",
    "Arena Core will adjust in real time as needed and re enable features as they become available. (if ever)\n",
    "I will personally be updating any news/big changes coming to Arena Core on my Twitter/X if you would like to stay in the loop\n",
    "https://x.com/PeralexIRL\n\n",
    
    "|cff44FF44Right now, the core values you expect from an Arena Frame addon are working just fine. As well as additional features you will find.\n",
    "Fun and useful additions that range from Party/Class icon indicators for friendly players, Font modding, custom cast bars, textures,\n",
    "even the loved Arena Core reward system etc are all working as intended.\n\n",
    
    "|cffFFFFFFThere will be constant updates as I continue to find new ways to come out with features as well as new cosmetics so this can be the\n",
    "full feature packed addon you know and love.\n\n",
    
    "|cffFFAA00If you are not someone who updates addons very often, I urge you not only for Arena Core, but addons as a whole to check DAILY\n",
    "for the foreseeable future as Midnight addon developers are surely going to be working over time to create bug fixes and new features.\n\n",
    
    "|cff8B45FFBIG INCOMING: Arena Core will be coming out with its own \"weak aura\" style maker for arena prep room, think \"change talents\" reminders etc.\n",
    "along with other goodies people are wanting. As well as a big update to the Blackout feature I have ideas for and more that will be PUMPING OUT,\n",
    "so please keep checking for updates.\n\n",
    
    "|cffFFFFFFYou will find various other areas within the UI that explain certain changes and updates.\n",
    "My core focus for this update was STABILITY and function over form. Some things I went the safe route with to ensure you have virtually no errors or problems as much as possible.\n",
    "Things will change almost daily as I continue to work on things and make improvements and create new features for.\n\n",
    
    "|cff44FF44PLEASE join the discord as I am keeping people updated not only about Arena Core, but addons in general so you can stay in the loop about API changes and what might be coming back.\n\n",
    
    "|cffFF69B4<3 you.\n"
  })
  
  f._body:SetText(notes)
  
  -- Update scroll child height based on text height
  C_Timer.After(0.1, function()
    if f._body and f._scrollChild then
      local textHeight = f._body:GetStringHeight()
      f._scrollChild:SetHeight(math.max(textHeight + 20, f._scrollFrame:GetHeight()))
    end
  end)
  
  -- Reset scroll to top
  if f._scrollFrame then
    f._scrollFrame:SetVerticalScroll(0)
  end
  
  f:Show(); addon._patchFrame = f
end
-- ============================================================================
-- Links Popup (similar to patch notes)
-- ============================================================================
function V:ShowLinksPopup()
  if addon._linksFrame and addon._linksFrame:IsShown() then return end
  -- Create a plain Frame, NOT a BackdropTemplate
  local f = addon._linksFrame or CreateFrame("Frame", "ArenaCoreLinks", UIParent)
  f:SetSize(280, 140); f:SetPoint("CENTER", 0, 60); f:SetFrameStrata("DIALOG")
  f:SetMovable(true); f:SetClampedToScreen(true); f:EnableMouse(true); f:RegisterForDrag("LeftButton")
  f:SetScript("OnDragStart", f.StartMoving); f:SetScript("OnDragStop", f.StopMovingOrSizing)
  if not f._skin then
    -- Apply the dark matte background texture, just like a group box
    local bg = f:CreateTexture(nil, "BACKGROUND")
    bg:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\box-dark-matte.tga")
    bg:SetAllPoints()
    -- Add the hairline border
    addon:AddHairlineRect(f, COLORS.BORDER_LIGHT, 0.9, 6)
    -- Add the purple accent line at the top
    local accent = addon:CreateFlatTexture(f, "OVERLAY", 7, COLORS.PRIMARY, 1)
    accent:SetPoint("TOPLEFT", 0, 0); accent:SetPoint("TOPRIGHT", 0, 0); accent:SetHeight(1)
    -- Style the title text
    f._title = addon:CreateStyledText(f, "Arena Core Social", 13, COLORS.PRIMARY, "OVERLAY", "")
    f._title:SetPoint("TOPLEFT", 14, -12)
    -- Style the close button to match the main panel's
    f._close = addon:CreateProfileStyleButton(f, 30, 30, "", "danger", 14)
    f._close:SetPoint("TOPRIGHT", -8, -8)
    local xText = addon:CreateStyledText(f._close, "×", 14, COLORS.TEXT, "OVERLAY", "")
    xText:SetPoint("CENTER", 0, 0)
    f._close:SetScript("OnClick", function() f:Hide() end)
    -- Create Discord button (using ProfileStyleButton to match Save Settings)
    f._discordBtn = addon:CreateProfileStyleButton(f, 100, 32, "Discord", "primary", 11)
    f._discordBtn:SetPoint("BOTTOM", 0, 50)
    f._discordBtn:SetScript("OnClick", function()
      -- Show chat message
      if ChatFrame1 then
        ChatFrame1:AddMessage("|cff8B45FFArenaCore:|r https://acdiscord.com", 1, 1, 1)
      end
      -- Open copy/paste window
      V:ShowDiscordLinkPopup()
    end)
    -- Create Website button (using ProfileStyleButton to match Save Settings)
    f._websiteBtn = addon:CreateProfileStyleButton(f, 100, 32, "Website", "primary", 11)
    f._websiteBtn:SetPoint("BOTTOM", 0, 14)
    f._websiteBtn:SetScript("OnClick", function()
      if ChatFrame1 then
        ChatFrame1:AddMessage("|cff8B45FFArenaCore:|r https://ArenaCore.io", 1, 1, 1)
      end
    end)
    f._skin = true
  end
  f:Show(); addon._linksFrame = f
end
-- ============================================================================
-- Discord Link Popup (copyable link window)
-- ============================================================================
function V:ShowDiscordLinkPopup()
  if addon._discordLinkFrame and addon._discordLinkFrame:IsShown() then return end
  -- Create a plain Frame, NOT a BackdropTemplate
  local f = addon._discordLinkFrame or CreateFrame("Frame", "ArenaCoreDiscordLink", UIParent)
  f:SetSize(320, 160); f:SetPoint("CENTER", 0, 60); f:SetFrameStrata("FULLSCREEN_DIALOG")
  f:SetMovable(true); f:SetClampedToScreen(true); f:EnableMouse(true); f:RegisterForDrag("LeftButton")
  f:SetScript("OnDragStart", f.StartMoving); f:SetScript("OnDragStop", f.StopMovingOrSizing)
  if not f._skin then
    -- Apply the dark matte background texture, just like a group box
    local bg = f:CreateTexture(nil, "BACKGROUND")
    bg:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\box-dark-matte.tga")
    bg:SetAllPoints()
    -- Add the hairline border
    addon:AddHairlineRect(f, COLORS.BORDER_LIGHT, 0.9, 6)
    -- Add the purple accent line at the top
    local accent = addon:CreateFlatTexture(f, "OVERLAY", 7, COLORS.PRIMARY, 1)
    accent:SetPoint("TOPLEFT", 0, 0); accent:SetPoint("TOPRIGHT", 0, 0); accent:SetHeight(1)
    -- Style the title text
    f._title = addon:CreateStyledText(f, "Arena Core Discord", 13, COLORS.PRIMARY, "OVERLAY", "")
    f._title:SetPoint("TOPLEFT", 14, -12)
    -- Style the close button to match the main panel's
    f._close = addon:CreateProfileStyleButton(f, 30, 30, "", "danger", 14)
    f._close:SetPoint("TOPRIGHT", -8, -8)
    local xText = addon:CreateStyledText(f._close, "×", 14, COLORS.TEXT, "OVERLAY", "")
    xText:SetPoint("CENTER", 0, 0)
    f._close:SetScript("OnClick", function() f:Hide() end)
    -- Instruction text
    f._instructionText = addon:CreateStyledText(f, "Copy the Discord link below:", 11, COLORS.TEXT_2, "OVERLAY", "")
    f._instructionText:SetPoint("TOP", 0, -45)
    -- Create EditBox for copyable link
    local linkBox = CreateFrame("EditBox", nil, f)
    linkBox:SetSize(280, 32)
    linkBox:SetPoint("TOP", 0, -70)
    linkBox:SetAutoFocus(false)
    linkBox:SetMultiLine(false)
    linkBox:SetMaxLetters(0)
    
    -- Set font for EditBox
    local fontSet = linkBox:SetFont("Interface\\AddOns\\ArenaCore\\Media\\Fonts\\arenacore.ttf", 12, "")
    if not fontSet then
      linkBox:SetFont("Fonts\\FRIZQT__.TTF", 12, "")
    end
    
    -- EditBox background
    local linkBg = addon:CreateFlatTexture(linkBox, "BACKGROUND", 1, {0.08, 0.08, 0.08, 1}, 1)
    linkBg:SetAllPoints()
    
    -- EditBox border
    addon:AddHairlineRect(linkBox, COLORS.BORDER_LIGHT, 0.8, 6)
    
    -- Set the Discord link
    linkBox:SetText("https://acdiscord.com")
    linkBox:SetTextColor(1, 1, 1, 1)  -- White text color
    linkBox:SetCursorPosition(0)
    
    -- Select all text when clicked
    linkBox:SetScript("OnEditFocusGained", function(self)
      self:HighlightText()
    end)
    
    linkBox:SetScript("OnEscapePressed", function(self)
      self:ClearFocus()
    end)
    
    linkBox:SetScript("OnEnterPressed", function(self)
      self:ClearFocus()
    end)
    
    f._linkBox = linkBox
    -- Helper text
    f._helperText = addon:CreateStyledText(f, "Click the link to select all, then Ctrl+C to copy", 10, COLORS.TEXT_2, "OVERLAY", "")
    f._helperText:SetPoint("BOTTOM", 0, 14)
    f._skin = true
  end
  -- Auto-select the link when window opens
  if f._linkBox then
    C_Timer.After(0.1, function()
      if f._linkBox then
        f._linkBox:SetFocus()
        f._linkBox:HighlightText()
      end
    end)
  end
  f:Show(); addon._discordLinkFrame = f
end
-- Header vanity -------------------------------------------------------------
function V:AttachHeader()
  if not addon.header or addon._vanityHeader then return end
  
  -- Check if Shade UI theme is active
  local activeTheme = addon.ThemeManager and addon.ThemeManager:GetActiveTheme() or "default"
  local isShadeUI = (activeTheme == "shade_ui")
  -- Header title text next to logo (far left, large) - ONLY for default theme
  if not addon._headerTitle and not isShadeUI then
    -- Create container for title + underline
    local titleContainer = CreateFrame("Frame", nil, addon.header)
    titleContainer:SetPoint("LEFT", 70, 0) -- Position to match original
    titleContainer:SetSize(250, 40)
    
    local title = titleContainer:CreateFontString(nil, "OVERLAY", nil, 7)
    -- Set font BEFORE setting text - large bold size
    local fontSet = title:SetFont("Interface\\AddOns\\ArenaCore\\Media\\Fonts\\arenacore.ttf", 28, "OUTLINE")
    if not fontSet then
      title:SetFont("Fonts\\FRIZQT__.TTF", 28, "OUTLINE")
    end
    title:SetTextColor(1, 1, 1, 1)
    title:SetText("ARENA CORE")
    title:SetPoint("TOPLEFT", 0, 0)
    
    -- Purple gradient underline effect using custom texture
    local underline = titleContainer:CreateTexture(nil, "OVERLAY", nil, 6)
    underline:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\purpleheader.tga")
    underline:SetPoint("BOTTOM", title, "BOTTOM", 0, -6)
    underline:SetSize(220, 8) -- Adjust width to match text length
    
    addon._headerTitle = title
    addon._headerTitleUnderline = underline
  end
  -- Version tag click easter egg
  if addon.versionFrame and not addon.versionFrame.__vanityEasterEgg then
    local vClick = CreateFrame("Button", nil, addon.versionFrame)
    vClick:SetAllPoints()
    vClick:SetScript("OnClick", function()
      if IsControlKeyDown() and IsAltKeyDown() then
        local sword = "|T"..ICONS.SWORD..":14:14:0:0:64:64:2:62:2:62|t"
        print("|cff8B45FFArena Core:|r " .. sword .. " Obsidian Mode Unlocked " .. sword)
        if PlaySound and SOUNDKIT then pcall(PlaySound, SOUNDKIT.UI_EPICLOOT_TOAST, "Master") end
      end
    end)
    addon.versionFrame.__vanityEasterEgg = true
  end
  -- Changelog button (was "?")
  local notesBtn = addon:CreateProfileStyleButton(addon.header, 90, 24, "Changelog", "primary", 12)
  if addon.header.__acSave then
    notesBtn:SetPoint("TOPRIGHT", addon.header.__acSave, "TOPLEFT", 92, 27)
  elseif addon.header.__acClose then
    notesBtn:SetPoint("RIGHT", addon.header.__acClose, "LEFT", -8, 0)
  else
    notesBtn:SetPoint("TOPRIGHT", -140, -8)
  end
  notesBtn:SetScript("OnClick", function() V:ShowPatchNotes() end)
  -- Add "NEW" indicator to Changelog button
  local newIndicator = notesBtn:CreateFontString(nil, "OVERLAY")
  newIndicator:SetFont("Interface\\AddOns\\ArenaCore\\Media\\Fonts\\arenacore.ttf", 8, "OUTLINE")
  newIndicator:SetText("|cffFFD700NEW|r")
  newIndicator:SetPoint("LEFT", notesBtn.text, "RIGHT", 3, 0)
  -- Simple pulsing animation for the NEW indicator
  -- NOTE: FontStrings don't support SetScript - use the parent frame instead
  local pulseTime = 0
  notesBtn:SetScript("OnUpdate", function(self, elapsed)
    pulseTime = pulseTime + elapsed
    local alpha = 0.5 + math.sin(pulseTime * 2) * 0.5
    newIndicator:SetAlpha(alpha)
  end)
  -- Subtle pulse on header accent (one-time)
  local target = addon.header._accent
  if target and not addon._accentPulse then
    local ag = target:CreateAnimationGroup()
    local a1 = ag:CreateAnimation("Alpha"); a1:SetFromAlpha(1); a1:SetToAlpha(0.85); a1:SetDuration(1.6); a1:SetSmoothing("IN_OUT")
    local a2 = ag:CreateAnimation("Alpha"); a2:SetFromAlpha(0.85); a2:SetToAlpha(1); a2:SetDuration(1.6); a2:SetSmoothing("IN_OUT")
    ag:SetLooping("REPEAT"); ag:Play()
    addon._accentPulse = ag
  end
  -- Sword logo
  if not addon._swordLogo then
    local logo = addon.header:CreateTexture(nil, "OVERLAY", nil, 7)
    logo:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\logoarena.tga")
    logo:SetSize(160, 160)
    logo:SetPoint("TOPLEFT", addon.header, "TOPLEFT", -60, 50)  -- Moved up from 36 to 50
    logo:SetTexCoord(0.002, 0.998, 0.002, 0.998)
    logo:SetVertexColor(1, 1, 1, 1)
    logo:SetBlendMode("BLEND")
    logo:SetRotation(math.rad(-25))
    addon._swordLogo = logo
  end
  addon._vanityHeader = true
end
-- Content vanity ------------------------------------------------------------
function V:AttachContent()
  if not addon.contentBox or addon._vanityContent then return end
  -- tiny mascot bottom-right
  local m = addon.contentBox:CreateTexture(nil, "OVERLAY", nil, 6)
  m:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\Logo\\arena_core_clean.tga")
  m:SetSize(80, 22)
  m:SetPoint("BOTTOMRIGHT", -12, 10)
  m:SetVertexColor(1, 1, 1, 0.10)
  addon._mascot = m
  addon._vanityContent = true
end
-- Footer vanity -------------------------------------------------------------
local FOOTER_HEIGHT = 28
function V:AttachFooter()
  if not addon.configFrame or addon._footer then return end
  local frame = addon.configFrame
  -- Grow once only
  local w, h = frame:GetSize(); frame:SetSize(w, h + FOOTER_HEIGHT)
  local footer = CreateFrame("Frame", nil, frame)
  footer:SetPoint("BOTTOMLEFT", 1, 1); footer:SetPoint("BOTTOMRIGHT", -1, 1)
  footer:SetHeight(FOOTER_HEIGHT)
  -- Check if Shade UI theme is active
  local activeTheme = addon.ThemeManager and addon.ThemeManager:GetActiveTheme() or "default"
  local isShadeUI = (activeTheme == "shade_ui")
  
  -- Use HEADER_BG for footer (darker, more consistent) - but hide for Shade UI
  local footerColor = addon.COLORS.HEADER_BG or addon.COLORS.INPUT_DARK or {0.102, 0.102, 0.102, 1}
  local fill = addon:CreateFlatTexture(footer, "BACKGROUND", 1, footerColor, 1)
  fill:SetAllPoints()
  if isShadeUI then
    fill:Hide() -- Hide footer background for Shade UI theme
  end
  
  local top  = addon:CreateFlatTexture(footer, "OVERLAY", 1, COLORS.PRIMARY, 0.9)
  top:SetPoint("TOPLEFT", 0, 0); top:SetPoint("TOPRIGHT", 0, 0); top:SetHeight(1)
  if isShadeUI then
    local discordBtn = CreateFrame("Button", nil, footer)
    discordBtn:SetSize(84, 20)
    discordBtn:SetPoint("BOTTOMLEFT", footer, "BOTTOMLEFT", 32, 4)
    local discordBg = addon:CreateFlatTexture(discordBtn, "BACKGROUND", 1, COLORS.PRIMARY, 1)
    discordBg:SetAllPoints()
    local discordBorder = addon:CreateFlatTexture(discordBtn, "BORDER", 2, {0.4, 0.2, 0.7, 1}, 1)
    discordBorder:SetPoint("TOPLEFT", 1, -1)
    discordBorder:SetPoint("BOTTOMRIGHT", -1, 1)
    local discordIcon = discordBtn:CreateTexture(nil, "OVERLAY")
    discordIcon:SetAtlas("communities-icon-chat")
    discordIcon:SetSize(16, 16)
    discordIcon:SetPoint("LEFT", discordBtn, "LEFT", 6, 0)
    local discordText = discordBtn:CreateFontString(nil, "OVERLAY")
    discordText:SetFont(addon.FONT_PATH, 9)
    discordText:SetText("DISCORD")
    discordText:SetTextColor(1, 1, 1, 1)
    discordText:SetPoint("LEFT", discordIcon, "RIGHT", 4, 0)
    local glow = discordBtn:CreateTexture(nil, "OVERLAY")
    glow:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\tab-purple-matte.tga")
    glow:SetAllPoints()
    glow:SetBlendMode("ADD")
    glow:SetAlpha(0)
    discordBtn.glow = glow
    discordBtn:SetScript("OnEnter", function()
      discordBg:SetColorTexture(0.645, 0.371, 1.000, 1)
      if discordBtn.glow then
        discordBtn.glow:SetAlpha(0.3)
      end
    end)
    discordBtn:SetScript("OnLeave", function()
      discordBg:SetColorTexture(0.545, 0.271, 1.000, 1)
      if discordBtn.glow then
        discordBtn.glow:SetAlpha(0)
      end
    end)
    discordBtn:SetScript("OnClick", function()
      if addon.Vanity and addon.Vanity.ShowDiscordLinkPopup then
        addon.Vanity:ShowDiscordLinkPopup()
      end
    end)
  end
  local row = CreateFrame("Frame", nil, footer); row:SetPoint("CENTER", 0, 0); row:SetHeight(FOOTER_HEIGHT)
  row:SetWidth(200) -- Set initial width
  
  local pre = addon:CreateStyledText(row, "made with", 12, COLORS.TEXT_2); pre:SetPoint("CENTER", -40, 0)
  
  local heart = row:CreateTexture(nil, "OVERLAY", nil, 7)
  heart:SetTexture(ICONS.HEART); heart:SetSize(20, 20); heart:SetPoint("LEFT", pre, "RIGHT", 6, 0)
  heart:SetTexCoord(0.002, 0.998, 0.002, 0.998); heart:SetBlendMode("BLEND"); heart:SetVertexColor(0.95, 0.15, 0.20, 1)
  
  local post = addon:CreateStyledText(row, "by peralex", 12, COLORS.TEXT_2); post:SetPoint("LEFT", heart, "RIGHT", 6, 0)
  -- Add subtle button next to the footer text
  local subtleBtn = CreateFrame("Button", nil, footer)
  subtleBtn:SetSize(110, 20)
  subtleBtn:SetPoint("LEFT", post, "RIGHT", 15, 0)
  -- Add background texture to make it look like a proper button
  local btnBg = addon:CreateFlatTexture(subtleBtn, "BACKGROUND", 1, COLORS.BG, 1)
  btnBg:SetAllPoints()
  -- Add border for definition
  addon:AddHairlineRect(subtleBtn, COLORS.BORDER_LIGHT, 0.6, 6)
  
  local btnText = addon:CreateStyledText(subtleBtn, "click this, do it", 11, COLORS.TEXT_2)
  btnText:ClearAllPoints()
  btnText:SetPoint("CENTER", 0, 0)
  subtleBtn:SetScript("OnClick", function() V:ShowLinksPopup() end)
  -- Add purple glow overlay on hover (same as ProfileStyle buttons)
  local glow = subtleBtn:CreateTexture(nil, "OVERLAY")
  glow:SetTexture("Interface\\AddOns\\ArenaCore\\Media\\UI\\tab-purple-matte.tga")
  glow:SetAllPoints()
  glow:SetBlendMode("ADD")
  glow:SetAlpha(0)
  subtleBtn.glow = glow
  subtleBtn:SetScript("OnEnter", function(self)
    if self.glow then
      self.glow:SetAlpha(0.3)
    end
  end)
  subtleBtn:SetScript("OnLeave", function(self)
    if self.glow then
      self.glow:SetAlpha(0)
    end
  end)
  -- Update width after UI is loaded to ensure proper centering
  C_Timer.After(0.1, function()
    local wpre = pre and pre:GetStringWidth() or 60
    local wpost = post and post:GetStringWidth() or 70
    local wbtn = subtleBtn and subtleBtn:GetWidth() or 80
    local totalWidth = wpre + wpost + heart:GetWidth() + wbtn + 30
    row:SetWidth(totalWidth)
    -- Shift left to compensate for the longer button and center properly
    row:ClearAllPoints()
    row:SetPoint("CENTER", footer, "CENTER", -60, 0)
  end)
  -- Move version badge into the footer (bottom-right)
  if addon.versionFrame then
    addon.versionFrame:SetParent(footer)
    addon.versionFrame:ClearAllPoints()
    addon.versionFrame:SetPoint("BOTTOMRIGHT", footer, "BOTTOMRIGHT", -40, 2)
  end
  addon._footer = footer
  -- Re-anchor sidebar/content bottoms upward by FOOTER_HEIGHT
  -- CRITICAL FIX: Don't override sidebar width - let the theme control it
  -- The hardcoded 240 was causing Shade UI's 160px sidebar to be resized
  if addon.sidebar then 
    -- Don't call ClearAllPoints or SetWidth - let the theme's sidebar positioning stay intact
    -- Just adjust the bottom position for the footer
    -- addon.sidebar:ClearAllPoints(); addon.sidebar:SetPoint("TOPLEFT", 8, -(70 + 8)); addon.sidebar:SetPoint("BOTTOMLEFT", 8, 8 + FOOTER_HEIGHT); addon.sidebar:SetWidth(240)
  end
  if addon.contentArea then 
    -- Don't reposition content area - let the theme control it
    -- addon.contentArea:ClearAllPoints(); addon.contentArea:SetPoint("TOPLEFT", 240 + 8 + 1, -(70 + 8)); addon.contentArea:SetPoint("BOTTOMRIGHT", -8, 8 + FOOTER_HEIGHT)
  end
end
-- Attach everything once -----------------------------------------------------
function V:AttachAll()
  V:AttachHeader(); V:AttachContent(); V:AttachFooter()
  
  if addon.configFrame and addon.tipText then
    local initial_pick = math.random(1, #V.MOTTO_LINES)
    addon.tipText:SetText(V.MOTTO_LINES[initial_pick])
    addon.configFrame:HookScript("OnShow", function()
        -- CRITICAL FIX: Ensure all UI fonts are set before showing
        if addon.EnsureUIFontObjects then
            addon.EnsureUIFontObjects()
        end
        if addon.FixUIFontsRecursively then
            addon.FixUIFontsRecursively(addon.configFrame)
        end
        
        if addon.tipText:IsShown() then
            local pick = math.random(1, #V.MOTTO_LINES)
            addon.tipText:SetText(V.MOTTO_LINES[pick])
        end
    end)
  end
end