Guest User

Bttmodernmobile

a guest
Oct 13th, 2026
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 291.76 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         Bitcointalk Modern Theme + Mobile View
  3. // @namespace    bitcointalk-modern-theme
  4. // @version      4.0.9.1
  5. // @description  Modern light/dark/system theme for bitcointalk.org with separate customisable Main and Accent presets, plus an OFF mode.
  6. // @license      MIT
  7. // @match        *://*.bitcointalk.org/*
  8. // @match        *://bitcointalk.org/*
  9. // @run-at       document-start
  10. // @grant        GM_setValue
  11. // @grant        GM_getValue
  12. // @downloadURL https://update.greasyfork.org/scripts/575401/Bitcointalk%20Modern%20Theme.user.js
  13. // @updateURL https://update.greasyfork.org/scripts/575401/Bitcointalk%20Modern%20Theme.meta.js
  14. // ==/UserScript==
  15.  
  16. (function () {
  17.   'use strict';
  18.  
  19.   // ===========================================================================
  20.   // Configuration
  21.   // ===========================================================================
  22.  
  23.   const MAIN_PRESETS_DARK = {
  24.     slate: { name: 'Slate (default)', base: '#15171D' },
  25.     midnight: { name: 'Midnight', base: '#0F1424' },
  26.     forest: { name: 'Forest', base: '#0E1A18' },
  27.     plum: { name: 'Plum', base: '#1A0F1F' },
  28.     charcoal: { name: 'Charcoal', base: '#141414' },
  29.   };
  30.   const MAIN_PRESETS_LIGHT = {
  31.     // v2.10.30: "Classic" preset rebuilt against the actual classic SMF
  32.     // Bitcointalk theme. Body wash is now a near-neutral cool grey
  33.     // (#EEF0F3) so the page reads as a desaturated grey-white rather than
  34.     // an azure tint. The visible blue in the original lives only in two
  35.     // places: the catbg/header band (#5B7FA0 navy) and the link colour
  36.     // (#225588). Both are kept in their own rules below.
  37.     sky: { name: 'Classic (default)', base: '#EEF0F3' },
  38.     // v2.10.32: "Pearl" given a clear sky-blue identity (the visible azure
  39.     // tint that the old "Classic" preset used to have, before v2.10.30
  40.     // moved Classic to a neutral grey). New base #E5ECF3 + a clean blue
  41.     // accent so the preset reads as "blue & white" rather than the
  42.     // previous neutral-with-indigo-tint that came across as violet.
  43.     pearl: { name: 'Sky Blue', base: '#E5ECF3' },
  44.     cream: { name: 'Soft Cream', base: '#F4EFE6' },
  45.     mint: { name: 'Soft Mint', base: '#EEF3EF' },
  46.     rose: { name: 'Soft Rose', base: '#F5EEEE' },
  47.   };
  48.  
  49.   const AUTO_ACCENT_MAP = {
  50.     light: {
  51.       // v2.10.28: classic SMF Bitcointalk uses the legendary #225588 blue
  52.       // for links throughout. Switching the auto-accent for the Classic
  53.       // preset to that exact hex pulls links, hover states and the active
  54.       // nav tab much closer to the original look.
  55.       sky:   '#225588',  // classic SMF Bitcointalk link blue
  56.       // v2.10.32: pearl auto-accent moved from indigo (#3A3DAA, which read
  57.        // as violet on the cool body wash) to a clean medium blue that pairs
  58.        // naturally with the pearl base #E5ECF3.
  59.       pearl: '#1E5FA8',  // clean medium blue
  60.       cream: '#9A6842',  // muted rust
  61.       mint:  '#4C735D',  // muted pine
  62.       rose:  '#7B5662',  // muted plum
  63.     },
  64.     dark: {
  65.       slate:    '#7F84D8', // muted periwinkle
  66.       midnight: '#8E84CF', // muted lavender
  67.       forest:   '#55B7A9', // muted aqua
  68.       plum:     '#B779C2', // muted orchid
  69.       charcoal: '#CC8E45', // muted amber
  70.     },
  71.   };
  72.  
  73.   const ACCENTS_DARK = {
  74.     orange: { name: 'Bitcoin Orange', base: '#F7931A' },
  75.   };
  76.   const ACCENTS_LIGHT = {
  77.     orange: { name: 'Bitcoin Orange', base: '#D97706' },
  78.   };
  79.  
  80.   const DEFAULT_THEME = 'dark';
  81.   const SCRIPT_VERSION = '4.0.9'; // build-injected from package.json (see build.mjs)
  82.   const DEFAULT_ACCENT_DARK_KEY = 'orange';
  83.   const DEFAULT_ACCENT_LIGHT_KEY = 'auto';
  84.   const DEFAULT_MAIN_DARK_KEY = 'slate';
  85.   const DEFAULT_MAIN_LIGHT_KEY = 'sky';
  86.   const DEFAULT_CUSTOM_MAIN_DARK = '#15171D';
  87.   const DEFAULT_CUSTOM_MAIN_LIGHT = '#F4F5F8';
  88.   const DEFAULT_CUSTOM_ACCENT_DARK = '#F7931A';
  89.   const DEFAULT_CUSTOM_ACCENT_LIGHT = '#5B7FA0';
  90.   const DEFAULT_MOBILE_VERSION = 'auto';
  91.   const DEFAULT_TOPIC_READ_SHADING = 'on';
  92.  
  93.   const KEY_THEME = 'bt-modern-theme';
  94.   const KEY_THEME_PRIOR = 'bt-modern-theme-prior';
  95.   const KEY_MAIN_DARK = 'bt-modern-main-dark';
  96.   const KEY_MAIN_LIGHT = 'bt-modern-main-light';
  97.   const KEY_ACCENT_DARK = 'bt-modern-accent-dark';
  98.   const KEY_ACCENT_LIGHT = 'bt-modern-accent-light';
  99.   const KEY_MAIN_DARK_CUSTOM = 'bt-modern-main-dark-custom';
  100.   const KEY_MAIN_LIGHT_CUSTOM = 'bt-modern-main-light-custom';
  101.   const KEY_ACCENT_DARK_CUSTOM = 'bt-modern-accent-dark-custom';
  102.   const KEY_ACCENT_LIGHT_CUSTOM = 'bt-modern-accent-light-custom';
  103.   const KEY_MOBILE_VERSION = 'bt-modern-mobile-version';
  104.   const KEY_TOPIC_READ_SHADING = 'bt-modern-topic-read-shading';
  105.   const KEY_TOPIC_READ_STATE = 'bt-modern-topic-read-state';
  106.   const TOPIC_READ_STATE_MAX_ENTRIES = 800;
  107.  
  108.   const ALL_KEYS = [
  109.     KEY_THEME,
  110.     KEY_THEME_PRIOR,
  111.     KEY_MAIN_DARK, KEY_MAIN_LIGHT,
  112.     KEY_ACCENT_DARK, KEY_ACCENT_LIGHT,
  113.     KEY_MAIN_DARK_CUSTOM, KEY_MAIN_LIGHT_CUSTOM,
  114.     KEY_ACCENT_DARK_CUSTOM, KEY_ACCENT_LIGHT_CUSTOM,
  115.     KEY_MOBILE_VERSION,
  116.     KEY_TOPIC_READ_SHADING,
  117.     KEY_TOPIC_READ_STATE,
  118.   ];
  119.  
  120.   // Safari flash guard constants (integrated extreme-fast variant)
  121.   const NAV_SELECTOR = 'a[href]';
  122.   const INCOMING_HOLD_STYLE_ID = 'bt-paint-hold';
  123.   const OUTGOING_HOLD_STYLE_ID = 'bt-pre-nav-hold';
  124.   const HOLD_REVEALED_ATTR = 'data-bt-revealed';
  125.   const NAV_UNTIL_SESSION_KEY = 'bt-modern-nav-hold-until';
  126.   const NAV_BG_SESSION_KEY = 'bt-modern-nav-hold-bg';
  127.   const OUTGOING_UNLOAD_FAILSAFE_MS = 1500;
  128.   const NAV_HOLD_SESSION_MS = 800;
  129.   // ===========================================================================
  130.   // Storage layer
  131.   // ===========================================================================
  132.  
  133.   const hasGM = typeof GM_getValue === 'function' && typeof GM_setValue === 'function';
  134.  
  135.   function lsGet(key) {
  136.     try { return localStorage.getItem(key); } catch (e) { return null; }
  137.   }
  138.   function lsSet(key, value) {
  139.     try { localStorage.setItem(key, value); return true; } catch (e) { return false; }
  140.   }
  141.   function gmGet(key) {
  142.     if (!hasGM) return null;
  143.     try {
  144.       const v = GM_getValue(key, null);
  145.       return v == null ? null : String(v);
  146.     } catch (e) { return null; }
  147.   }
  148.   function gmSet(key, value) {
  149.     if (!hasGM) return false;
  150.     try { GM_setValue(key, String(value)); return true; } catch (e) { return false; }
  151.   }
  152.   function ssGet(key) {
  153.     try {
  154.       const v = sessionStorage.getItem(key);
  155.       return v == null || v === '' ? null : v;
  156.     } catch (e) { return null; }
  157.   }
  158.   function ssSet(key, value) {
  159.     try { sessionStorage.setItem(key, String(value)); } catch (e) {}
  160.   }
  161.   function ssRemove(key) {
  162.     try { sessionStorage.removeItem(key); } catch (e) {}
  163.   }
  164.  
  165.   function getPref(key, fallback) {
  166.     let v = gmGet(key);
  167.     if (v == null || v === '') v = lsGet(key);
  168.     if (v == null || v === '') return fallback;
  169.     return v;
  170.   }
  171.  
  172.   function setPref(key, value) {
  173.     const lsOk = lsSet(key, value);
  174.     const gmOk = gmSet(key, value);
  175.     return lsOk || gmOk;
  176.   }
  177.  
  178.   function syncStores() {
  179.     ALL_KEYS.forEach(k => {
  180.       const ls = lsGet(k);
  181.       const gm = gmGet(k);
  182.       if (gm && (!ls || ls === '')) lsSet(k, gm);
  183.       else if (ls && (!gm || gm === '') && hasGM) gmSet(k, ls);
  184.     });
  185.   }
  186.  
  187.   function getMobileVersionPreference() {
  188.     const preference = getPref(KEY_MOBILE_VERSION, DEFAULT_MOBILE_VERSION);
  189.     return preference === 'on' || preference === 'off' || preference === 'balanced'
  190.       ? preference
  191.       : 'auto';
  192.   }
  193.  
  194.   function shouldUseAutomaticMobilePerformance() {
  195.     const compactViewport = !!(
  196.       window.matchMedia && window.matchMedia('(max-width: 820px)').matches
  197.     );
  198.     const compactScreen = !!(
  199.       window.screen && Math.min(window.screen.width || Infinity, window.screen.height || Infinity) <= 820
  200.     );
  201.     const coarsePointer = !!(
  202.       (window.matchMedia && window.matchMedia('(any-pointer: coarse)').matches) ||
  203.       (navigator && navigator.maxTouchPoints > 0)
  204.     );
  205.     const mobileUA = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile/i.test(
  206.       (navigator && navigator.userAgent) || ''
  207.     );
  208.     return compactViewport || ((coarsePointer || mobileUA) && compactScreen) || (mobileUA && coarsePointer);
  209.   }
  210.  
  211.   function getEffectiveMobileMode(preference = getMobileVersionPreference()) {
  212.     if (preference === 'on') return 'lite';
  213.     if (preference === 'balanced') return 'balanced';
  214.     if (preference === 'off') return 'full';
  215.     return shouldUseAutomaticMobilePerformance() ? 'balanced' : 'full';
  216.   }
  217.  
  218.   function getRuntimeMobileMode() {
  219.     const mode = document.documentElement && document.documentElement.getAttribute('data-bt-mobile-mode');
  220.     return mode === 'full' || mode === 'balanced' || mode === 'lite'
  221.       ? mode
  222.       : getEffectiveMobileMode();
  223.   }
  224.  
  225.   function isMobileLite() {
  226.     return getRuntimeMobileMode() === 'lite';
  227.   }
  228.  
  229.   function isMobileBalanced() {
  230.     return getRuntimeMobileMode() === 'balanced';
  231.   }
  232.  
  233.   function isMobilePerformanceMode() {
  234.     return getRuntimeMobileMode() !== 'full';
  235.   }
  236.  
  237.   function isTopicReadShadingEnabled() {
  238.     return getPref(KEY_TOPIC_READ_SHADING, DEFAULT_TOPIC_READ_SHADING) === 'on';
  239.   }
  240.  
  241.   function updateMobileLiteAttribute() {
  242.     const root = document.documentElement;
  243.     const mode = getEffectiveMobileMode();
  244.     const optimized = mode === 'full' ? 'false' : 'true';
  245.     if (root.getAttribute('data-bt-mobile-mode') !== mode) {
  246.       root.setAttribute('data-bt-mobile-mode', mode);
  247.     }
  248.     // Retain the original attribute as a CSS compatibility flag for both
  249.     // performance-oriented modes.
  250.     if (root.getAttribute('data-bt-mobile-lite') !== optimized) {
  251.       root.setAttribute('data-bt-mobile-lite', optimized);
  252.     }
  253.   }
  254.  
  255.   function updatePageAttribute() {
  256.     let page = '';
  257.     try {
  258.       if (isMeritPage()) page = 'merit';
  259.       else if (isTrustPage()) page = 'trust';
  260.     } catch (e) {}
  261.     if (page) {
  262.       if (document.documentElement.getAttribute('data-bt-page') !== page) {
  263.         document.documentElement.setAttribute('data-bt-page', page);
  264.       }
  265.     } else if (document.documentElement.hasAttribute('data-bt-page')) {
  266.       document.documentElement.removeAttribute('data-bt-page');
  267.     }
  268.   }
  269.  
  270.   function isMeritPage() {
  271.     try {
  272.       const search = window.location.search || '';
  273.       const params = new URLSearchParams(search);
  274.       const action = (params.get('action') || '').toLowerCase();
  275.       return action === 'merit' || action.indexOf('merit;') === 0 || /[?;&]action=merit(?:[;&]|$)/i.test(search);
  276.     } catch (e) {
  277.       return /[?;&]action=merit(?:[;&]|$)/i.test(window.location.search || '');
  278.     }
  279.   }
  280.  
  281.   function isTrustPage() {
  282.     try {
  283.       const search = window.location.search || '';
  284.       const params = new URLSearchParams(search);
  285.       const action = (params.get('action') || '').toLowerCase();
  286.       return action === 'trust' || action.indexOf('trust;') === 0 || /[?;&]action=trust(?:[;&]|$)/i.test(search);
  287.     } catch (e) {
  288.       return /[?;&]action=trust(?:[;&]|$)/i.test(window.location.search || '');
  289.     }
  290.   }
  291.   // ===========================================================================
  292.   // Color helpers
  293.   // ===========================================================================
  294.  
  295.   function sanitizeHex(hex, fallback = '#000000') {
  296.     const v = String(hex || '').trim();
  297.     const fallbackValue = String(fallback || '').trim();
  298.     const fallbackMatch = fallbackValue.match(/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/);
  299.     const fb = fallbackMatch
  300.       ? '#' + (
  301.           fallbackMatch[1].length === 3
  302.             ? fallbackMatch[1].split('').map(ch => ch + ch).join('')
  303.             : fallbackMatch[1]
  304.         ).toUpperCase()
  305.       : '#000000';
  306.  
  307.     const match = v.match(/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/);
  308.     if (!match) return fb;
  309.  
  310.     const body = match[1];
  311.     return '#' + (
  312.       body.length === 3
  313.         ? body.split('').map(ch => ch + ch).join('')
  314.         : body
  315.     ).toUpperCase();
  316.   }
  317.  
  318.   function hexToRgb(hex) {
  319.     hex = sanitizeHex(hex, '#000000');
  320.     const c = String(hex || '').replace('#', '');
  321.     const full = c.length === 3 ? c.split('').map(x => x + x).join('') : c;
  322.     const n = parseInt(full, 16);
  323.     return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
  324.   }
  325.   function clamp(v, min, max) { return Math.max(min, Math.min(max, v)); }
  326.   function rgbToHex(r, g, b) {
  327.     return '#' + [r, g, b]
  328.       .map(x => clamp(Math.round(x), 0, 255).toString(16).padStart(2, '0'))
  329.       .join('');
  330.   }
  331.   function lighten(hex, amt) {
  332.     const { r, g, b } = hexToRgb(hex);
  333.     return rgbToHex(r + (255 - r) * amt, g + (255 - g) * amt, b + (255 - b) * amt);
  334.   }
  335.   function darken(hex, amt) {
  336.     const { r, g, b } = hexToRgb(hex);
  337.     return rgbToHex(r * (1 - amt), g * (1 - amt), b * (1 - amt));
  338.   }
  339.   function rgbToHsl(r, g, b) {
  340.     r /= 255; g /= 255; b /= 255;
  341.     const max = Math.max(r, g, b), min = Math.min(r, g, b);
  342.     let h, s; const l = (max + min) / 2;
  343.     if (max === min) {
  344.       h = 0; s = 0;
  345.     } else {
  346.       const d = max - min;
  347.       s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  348.       if (max === r) h = ((g - b) / d + (g < b ? 6 : 0));
  349.       else if (max === g) h = (b - r) / d + 2;
  350.       else h = (r - g) / d + 4;
  351.       h /= 6;
  352.     }
  353.     return { h, s, l };
  354.   }
  355.   function hslToRgb(h, s, l) {
  356.     let r, g, b;
  357.     if (s === 0) {
  358.       r = g = b = l;
  359.     } else {
  360.       const hue2rgb = (p, q, t) => {
  361.         if (t < 0) t += 1;
  362.         if (t > 1) t -= 1;
  363.         if (t < 1 / 6) return p + (q - p) * 6 * t;
  364.         if (t < 1 / 2) return q;
  365.         if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  366.         return p;
  367.       };
  368.       const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  369.       const p = 2 * l - q;
  370.       r = hue2rgb(p, q, h + 1 / 3);
  371.       g = hue2rgb(p, q, h);
  372.       b = hue2rgb(p, q, h - 1 / 3);
  373.     }
  374.     return { r: r * 255, g: g * 255, b: b * 255 };
  375.   }
  376.   function adjustHsl(hex, deltaL, deltaS) {
  377.     const { r, g, b } = hexToRgb(hex);
  378.     const hsl = rgbToHsl(r, g, b);
  379.     const newL = clamp(hsl.l + deltaL, 0, 1);
  380.     const newS = clamp(hsl.s + deltaS, 0, 1);
  381.     const rgb = hslToRgb(hsl.h, newS, newL);
  382.     return sanitizeHex(rgbToHex(rgb.r, rgb.g, rgb.b), sanitizeHex(hex, '#000000'));
  383.   }
  384.   function relativeLuminance(hex) {
  385.     const { r, g, b } = hexToRgb(hex);
  386.     const [R, G, B] = [r, g, b].map(v => {
  387.       v /= 255;
  388.       return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
  389.     });
  390.     return 0.2126 * R + 0.7152 * G + 0.0722 * B;
  391.   }
  392.   function contrastRatio(first, second) {
  393.     const firstLuminance = relativeLuminance(first);
  394.     const secondLuminance = relativeLuminance(second);
  395.     return (Math.max(firstLuminance, secondLuminance) + 0.05) /
  396.       (Math.min(firstLuminance, secondLuminance) + 0.05);
  397.   }
  398.   function readableTextColor(background) {
  399.     const darkText = '#1A1D21';
  400.     const lightText = '#FFFFFF';
  401.     const darkContrast = contrastRatio(background, darkText);
  402.     const lightContrast = contrastRatio(background, lightText);
  403.  
  404.     // Prefer the existing theme colours when they meet WCAG AA. Around the
  405.     // narrow mid-luminance range where neither does, pure black is the safe
  406.     // fallback and still guarantees readable text on the custom background.
  407.     if (darkContrast >= 4.5 && darkContrast >= lightContrast) return darkText;
  408.     if (lightContrast >= 4.5) return lightText;
  409.     return '#000000';
  410.   }
  411.   function deriveAccent(hex) {
  412.     return {
  413.       base: hex,
  414.       hover: lighten(hex, 0.15),
  415.       active: darken(hex, 0.10),
  416.       onText: readableTextColor(hex),
  417.     };
  418.   }
  419.  
  420.   function deriveMainPalette(hex, theme, mainKey) {
  421.     if (theme === 'dark') {
  422.       return {
  423.         bg: hex,
  424.         bgEnd: darken(hex, 0.06),
  425.         surface1: lighten(hex, 0.06),
  426.         surface2: lighten(hex, 0.12),
  427.         surface3: lighten(hex, 0.20),
  428.         postBg: lighten(hex, 0.055),
  429.         postAltBg: lighten(hex, 0.085),
  430.         posterBg: lighten(hex, 0.050),
  431.         posterAltBg: lighten(hex, 0.075),
  432.         inputBg: darken(hex, 0.06),
  433.         quoteBg: lighten(hex, 0.04),
  434.         codeBg: darken(hex, 0.06),
  435.         border: 'rgba(255,255,255,0.07)',
  436.         border2: 'rgba(255,255,255,0.14)',
  437.         text: '#E3E3E8',
  438.         text2: '#A8B0BA',
  439.         text3: '#6B7480',
  440.         iconFilter: 'invert(1) opacity(0.75)',
  441.         shadow: '0 1px 0 rgba(0,0,0,0.2)',
  442.         shadowLg: '0 12px 32px rgba(0,0,0,0.35)',
  443.       };
  444.     }
  445.  
  446.     // Light theme: all surfaces derive from the chosen main hex with hue
  447.     // preserved (HSL adjust). v2.8.3 also derives post alternation colours
  448.     // from the selected light theme, rather than hardcoding Classic/Sky.
  449.     //
  450.     // v2.10.28: when the Classic (sky) preset is active, we override the
  451.     // surface tones with hand-picked SMF Bitcointalk values instead of the
  452.     // generic adjustHsl derivation. This gives us:
  453.     //   surface1  → windowbg-equivalent (the post background)
  454.     //   surface2  → titlebg-equivalent (sub-category headers)
  455.     //   surface3  → catbg-equivalent (top category headers, deeper blue)
  456.     // Other presets continue to use the algorithmic derivation so their
  457.     // chromatic identity is preserved.
  458.     //
  459.     // v2.10.30: Classic surface/post/border/quote/code values further
  460.     // desaturated toward neutral cool grey to match the original SMF look,
  461.     // which reads much more grey than blue against a white browser canvas.
  462.     // The catbg-equivalent (surface3) is the only place that retains a
  463.     // visible blue tint, since classic SMF Bitcointalk uses a steel-blue
  464.     // for category headers.
  465.     const isClassic = mainKey === 'sky';
  466.  
  467.     // Keep the Classic blue identity while making its white 13px tab label
  468.     // meet the 4.5:1 normal-text contrast threshold.
  469.     const navActiveBg = isClassic ? '#557898' : adjustHsl(hex, -0.38, 0.36);
  470.     return {
  471.       bg: hex,
  472.       bgEnd: adjustHsl(hex, -0.025, 0.04),
  473.       // v2.10.30: classic SMF surfaces. Posts on near-white (the original's
  474.       // windowbg is essentially #F8F9FA), titlebg as a soft grey-blue band,
  475.       // catbg as a saturated navy (the iconic SMF header colour).
  476.       surface1: isClassic ? '#FAFBFC' : adjustHsl(hex, -0.055, 0.12),
  477.       surface2: isClassic ? '#D8DDE5' : adjustHsl(hex, -0.12, 0.20),
  478.       surface3: isClassic ? '#5B7FA0' : adjustHsl(hex, -0.20, 0.28),
  479.  
  480.       // v2.10.30: classic alternation in cool neutral greys. The originals
  481.       // were #F0F4F7 / #F8F9FA — both very light, very desaturated. We use
  482.       // pure white for the primary windowbg and a faintest grey for the
  483.       // alternate row so the stripe is visible without becoming blue.
  484.       postBg: isClassic ? '#FFFFFF' : adjustHsl(hex, -0.010, 0.015),
  485.       postAltBg: isClassic ? '#F2F4F7' : adjustHsl(hex, -0.045, 0.060),
  486.       posterBg: isClassic ? '#F0F2F5' : adjustHsl(hex, -0.035, 0.045),
  487.       posterAltBg: isClassic ? '#E6E9EE' : adjustHsl(hex, -0.070, 0.090),
  488.  
  489.       navActiveBg,
  490.       navActiveText: readableTextColor(navActiveBg),
  491.       inputBg: '#FFFFFF',
  492.       quoteBg: isClassic ? '#EFF2F6' : adjustHsl(hex, -0.02, 0.04),
  493.       codeBg: isClassic ? '#E0E4EB' : adjustHsl(hex, -0.09, 0.18),
  494.       // v2.10.30: classic borders as solid neutral greys, not rgba —
  495.        // semi-transparent borders pick up the underlying tint and read as
  496.        // bluish on a cool-grey body. Solid #C0C5CC / #99A0AB give the
  497.        // crisp grey separators of the classic SMF theme.
  498.       border: isClassic ? '#C0C5CC' : 'rgba(0,0,0,0.08)',
  499.       border2: isClassic ? '#99A0AB' : 'rgba(0,0,0,0.16)',
  500.       text: isClassic ? '#000000' : '#1A1D21',
  501.       text2: isClassic ? '#3F4754' : '#4A5058',
  502.       text3: isClassic ? '#6E7785' : '#7A8088',
  503.       iconFilter: 'opacity(0.7)',
  504.       shadow: '0 1px 0 rgba(0,0,0,0.04)',
  505.       shadowLg: '0 12px 32px rgba(0,0,0,0.12)',
  506.     };
  507.   }
  508.  
  509.   function deriveAutoAccent(mainHex, theme, mainKey) {
  510.     mainHex = sanitizeHex(mainHex, theme === 'dark' ? DEFAULT_CUSTOM_MAIN_DARK : DEFAULT_CUSTOM_MAIN_LIGHT);
  511.     if (mainKey && AUTO_ACCENT_MAP[theme] && AUTO_ACCENT_MAP[theme][mainKey]) {
  512.       return sanitizeHex(AUTO_ACCENT_MAP[theme][mainKey], theme === 'dark' ? DEFAULT_CUSTOM_ACCENT_DARK : DEFAULT_CUSTOM_ACCENT_LIGHT);
  513.     }
  514.     const { r, g, b } = hexToRgb(mainHex);
  515.     const hsl = rgbToHsl(r, g, b);
  516.     if (hsl.s < 0.05) {
  517.       return sanitizeHex(theme === 'dark' ? '#E8A04A' : '#B5552B', theme === 'dark' ? DEFAULT_CUSTOM_ACCENT_DARK : DEFAULT_CUSTOM_ACCENT_LIGHT);
  518.     }
  519.     const newH = hsl.h;
  520.     const newS = Math.min(0.65, Math.max(0.50, hsl.s + 0.25));
  521.     const newL = theme === 'dark' ? 0.62 : 0.38;
  522.     const rgb = hslToRgb(newH, newS, newL);
  523.     return sanitizeHex(rgbToHex(rgb.r, rgb.g, rgb.b), theme === 'dark' ? DEFAULT_CUSTOM_ACCENT_DARK : DEFAULT_CUSTOM_ACCENT_LIGHT);
  524.   }
  525.  
  526.   function toCssVar(name) {
  527.     return '--bt-' + name
  528.       .replace(/([A-Z]|\d+)/g, '-$1')
  529.       .toLowerCase()
  530.       .replace(/^-/, '');
  531.   }
  532.   // ===========================================================================
  533.   // Theme application
  534.   // ===========================================================================
  535.  
  536.   function getEffectiveTheme(pref) {
  537.     if (pref === 'off') return 'off';
  538.     if (pref === 'system') {
  539.       return window.matchMedia &&
  540.         window.matchMedia('(prefers-color-scheme: dark)').matches
  541.         ? 'dark' : 'light';
  542.     }
  543.     return pref === 'light' ? 'light' : 'dark';
  544.   }
  545.  
  546.   function getMainKey(theme) {
  547.     const def = theme === 'dark' ? DEFAULT_MAIN_DARK_KEY : DEFAULT_MAIN_LIGHT_KEY;
  548.     return getPref(theme === 'dark' ? KEY_MAIN_DARK : KEY_MAIN_LIGHT, def);
  549.   }
  550.   function getAccentKey(theme) {
  551.     const def = theme === 'dark' ? DEFAULT_ACCENT_DARK_KEY : DEFAULT_ACCENT_LIGHT_KEY;
  552.     return getPref(theme === 'dark' ? KEY_ACCENT_DARK : KEY_ACCENT_LIGHT, def);
  553.   }
  554.   function getActiveMainHex(theme) {
  555.     const presets = theme === 'dark' ? MAIN_PRESETS_DARK : MAIN_PRESETS_LIGHT;
  556.     const key = getMainKey(theme);
  557.     if (key === 'custom') {
  558.       const def = theme === 'dark' ? DEFAULT_CUSTOM_MAIN_DARK : DEFAULT_CUSTOM_MAIN_LIGHT;
  559.       return sanitizeHex(getPref(theme === 'dark' ? KEY_MAIN_DARK_CUSTOM : KEY_MAIN_LIGHT_CUSTOM, def), def);
  560.     }
  561.     const fallbackKey = theme === 'dark' ? DEFAULT_MAIN_DARK_KEY : DEFAULT_MAIN_LIGHT_KEY;
  562.     return sanitizeHex((presets[key] || presets[fallbackKey]).base, presets[fallbackKey].base);
  563.   }
  564.   function getActiveAccentHex(theme) {
  565.     const presets = theme === 'dark' ? ACCENTS_DARK : ACCENTS_LIGHT;
  566.     const key = getAccentKey(theme);
  567.     if (key === 'auto') {
  568.       return deriveAutoAccent(getActiveMainHex(theme), theme, getMainKey(theme));
  569.     }
  570.     if (key === 'custom') {
  571.       const def = theme === 'dark' ? DEFAULT_CUSTOM_ACCENT_DARK : DEFAULT_CUSTOM_ACCENT_LIGHT;
  572.       return sanitizeHex(getPref(theme === 'dark' ? KEY_ACCENT_DARK_CUSTOM : KEY_ACCENT_LIGHT_CUSTOM, def), def);
  573.     }
  574.     if (presets[key]) {
  575.       return sanitizeHex(presets[key].base, presets.orange ? presets.orange.base : '#F7931A');
  576.     }
  577.     return deriveAutoAccent(getActiveMainHex(theme), theme, getMainKey(theme));
  578.   }
  579.  
  580.   // ===========================================================================
  581.   // Replacement visibility / OFF-mode restoration
  582.   // ===========================================================================
  583.   //
  584.   // We replace classic SMF image buttons with modern spans/SVGs. Earlier builds
  585.   // hid the original <img> nodes with inline `display:none !important`.
  586.   // That is stronger than stylesheet rules, so when OFF mode disabled the theme
  587.   // stylesheet the original BBCode/Quote buttons stayed hidden. This helper is
  588.   // the OFF-mode fix: it explicitly restores original images and hides only our
  589.   // replacement nodes.
  590.   function setModernizedControlsActive(active, scope = document) {
  591.     const showOriginals = !active;
  592.  
  593.     queryAllWithin(scope, 'img[data-bt-replaced="1"], img[data-bt-smiley="1"]').forEach(img => {
  594.       // v2.10.15: inline-icon IMGs (lock + new) are handled via src swap.
  595.       // Skip the display:none codepath here and route to src restore/apply.
  596.       if (img.dataset.btInlineIconActive === '1' || Object.prototype.hasOwnProperty.call(img.dataset, 'btOriginalSrc')) {
  597.         if (active) {
  598.           // Re-apply the modern src in case OFF mode reverted it. Pick the
  599.           // right data-URL based on the recorded type.
  600.           if (img.dataset.btTopicType === 'locked') {
  601.             applyInlineIconSrc(img, INLINE_LOCK_DATAURL);
  602.           } else if (img.dataset.btTopicType === 'newPost') {
  603.             applyInlineIconSrc(img, INLINE_NEW_DATAURL);
  604.           } else if (img.dataset.btTopicType === 'sticky') {
  605.             applyInlineIconSrc(img, INLINE_STICKY_DATAURL);
  606.           }
  607.         } else {
  608.           restoreInlineIconSrc(img);
  609.         }
  610.         return;
  611.       }
  612.  
  613.       if (active) {
  614.         if (!Object.prototype.hasOwnProperty.call(img.dataset, 'btOriginalStyle')) {
  615.           img.dataset.btOriginalStyle = img.getAttribute('style') || '';
  616.         }
  617.         img.style.setProperty('display', 'none', 'important');
  618.       } else {
  619.         if (Object.prototype.hasOwnProperty.call(img.dataset, 'btOriginalStyle')) {
  620.           const originalStyle = img.dataset.btOriginalStyle || '';
  621.           if (originalStyle) img.setAttribute('style', originalStyle);
  622.           else img.removeAttribute('style');
  623.         } else {
  624.           img.style.removeProperty('display');
  625.           if (!img.getAttribute('style')) img.removeAttribute('style');
  626.         }
  627.       }
  628.     });
  629.  
  630.     // Hide/show our modern replacement UI. Important: do NOT hide every
  631.     // .bt-post-action in OFF mode, because +Merit and #post anchors are real
  632.     // site links that merely receive this class for styling. Only replacement
  633.     // spans created from hidden image buttons carry data-bt-replacement="1".
  634.     queryAllWithin(scope, '.bt-bbc-icon, .bt-smiley, .bt-topic-icon[data-bt-replacement="1"], .bt-post-action[data-bt-replacement="1"]').forEach(el => {
  635.       if (showOriginals) {
  636.         el.style.setProperty('display', 'none', 'important');
  637.       } else {
  638.         el.style.removeProperty('display');
  639.         if (!el.getAttribute('style')) el.removeAttribute('style');
  640.       }
  641.     });
  642.  
  643.     // Re-apply / clear special topic tints when toggling the theme. Original
  644.     // inline backgrounds are preserved for a faithful OFF-mode restoration.
  645.     queryAllWithin(scope, 'tr.bt-row-sticky, tr.bt-row-locked').forEach(tr => {
  646.       if (active) {
  647.         applySpecialTopicRowTintInline(tr);
  648.       } else {
  649.         clearSpecialTopicRowTintInline(tr);
  650.       }
  651.     });
  652.  
  653.   }
  654.  
  655.   function isThemeActiveNow() {
  656.     const active = document.documentElement && document.documentElement.getAttribute('data-bt-active');
  657.     if (active === 'true') return true;
  658.     if (active === 'false') return false;
  659.     return getEffectiveTheme(getPref(KEY_THEME, DEFAULT_THEME)) !== 'off';
  660.   }
  661.  
  662.   let lastModernizedControlsActive = null;
  663.  
  664.   function setRootAttributeIfChanged(root, name, value) {
  665.     if (root.getAttribute(name) !== value) root.setAttribute(name, value);
  666.   }
  667.  
  668.   function setRootStyleIfChanged(root, name, value) {
  669.     if (root.style.getPropertyValue(name) !== value) root.style.setProperty(name, value);
  670.   }
  671.  
  672.   function setModernizedControlsState(active) {
  673.     if (lastModernizedControlsActive === active) return;
  674.     lastModernizedControlsActive = active;
  675.     setModernizedControlsActive(active);
  676.   }
  677.  
  678.   function applyTheme() {
  679.     const themePref = getPref(KEY_THEME, DEFAULT_THEME);
  680.     const effective = getEffectiveTheme(themePref);
  681.     const root = document.documentElement;
  682.     updateMobileLiteAttribute();
  683.     updatePageAttribute();
  684.  
  685.     if (effective === 'off') {
  686.       cancelPendingFontLoad();
  687.       setRootAttributeIfChanged(root, 'data-bt-active', 'false');
  688.       setRootAttributeIfChanged(root, 'data-bt-theme-pref', themePref);
  689.       if (themeStyleEl && !themeStyleEl.disabled) themeStyleEl.disabled = true;
  690.       if (root.style.colorScheme) root.style.colorScheme = '';
  691.       setModernizedControlsState(false);
  692.       updateSwitcherUI(themePref, effective, null, null, null, null);
  693.       return;
  694.     }
  695.  
  696.     const mainKey = getMainKey(effective);
  697.     const accentKey = getAccentKey(effective);
  698.     const mainHex = getActiveMainHex(effective);
  699.     const accentHex = getActiveAccentHex(effective);
  700.     const palette = deriveMainPalette(mainHex, effective, mainKey);
  701.     const accent = deriveAccent(accentHex);
  702.  
  703.     setRootAttributeIfChanged(root, 'data-bt-active', 'true');
  704.     setRootAttributeIfChanged(root, 'data-bt-theme', effective);
  705.     setRootAttributeIfChanged(root, 'data-bt-theme-pref', themePref);
  706.     setRootAttributeIfChanged(root, 'data-bt-main', mainKey);
  707.     setRootAttributeIfChanged(root, 'data-bt-accent', accentKey);
  708.     if (root.style.colorScheme !== effective) root.style.colorScheme = effective;
  709.  
  710.     Object.entries(palette).forEach(([k, v]) => setRootStyleIfChanged(root, toCssVar(k), v));
  711.     setRootStyleIfChanged(root, '--bt-accent', accent.base);
  712.     setRootStyleIfChanged(root, '--bt-accent-h', accent.hover);
  713.     setRootStyleIfChanged(root, '--bt-accent-a', accent.active);
  714.     setRootStyleIfChanged(root, '--bt-on-accent', accent.onText);
  715.  
  716.     if (themeStyleEl && themeStyleEl.disabled) themeStyleEl.disabled = false;
  717.     setModernizedControlsState(!isMobileLite());
  718.     ensureFonts();
  719.  
  720.     updateSwitcherUI(themePref, effective, mainKey, accentKey, mainHex, accentHex);
  721.   }
  722.  
  723.   function updateSwitcherFromPreferences() {
  724.     const themePref = getPref(KEY_THEME, DEFAULT_THEME);
  725.     const effective = getEffectiveTheme(themePref);
  726.     if (effective === 'off') {
  727.       updateSwitcherUI(themePref, effective, null, null, null, null);
  728.       return;
  729.     }
  730.     updateSwitcherUI(
  731.       themePref,
  732.       effective,
  733.       getMainKey(effective),
  734.       getAccentKey(effective),
  735.       getActiveMainHex(effective),
  736.       getActiveAccentHex(effective)
  737.     );
  738.   }
  739.  
  740.   function updateSwitcherUI(themePref, effective, mainKey, accentKey, mainHex, accentHex) {
  741.     const sw = document.getElementById('bt-switcher');
  742.     if (!sw) return;
  743.     ensureSettingsToggleControls(sw);
  744.  
  745.     const mainBtn = sw.querySelector('#bt-switcher-button');
  746.     if (mainBtn) {
  747.       if (themePref === 'off') {
  748.         mainBtn.innerHTML = '<span class="bt-sw-on-text">ON</span>';
  749.         mainBtn.title = 'Turn the theme back on';
  750.         mainBtn.setAttribute('aria-label', 'Turn the theme back on');
  751.       } else {
  752.         mainBtn.innerHTML = ICONS.cog;
  753.         mainBtn.title = 'Theme settings';
  754.         mainBtn.setAttribute('aria-label', 'Theme settings');
  755.       }
  756.     }
  757.  
  758.     const customizeEl = sw.querySelector('.bt-sw-customize');
  759.     if (customizeEl) {
  760.       const hide = themePref === 'system' || themePref === 'off';
  761.       customizeEl.style.display = hide ? 'none' : '';
  762.     }
  763.     const titleEl = sw.querySelector('#bt-sw-customize-title');
  764.     if (titleEl && effective !== 'off') {
  765.       titleEl.textContent = `Customise ${effective === 'dark' ? 'Dark' : 'Light'} Colours`;
  766.     }
  767.  
  768.     sw.querySelectorAll('[data-theme]').forEach(b => {
  769.       b.classList.toggle('selected', b.dataset.theme === themePref);
  770.     });
  771.     const offBtn = sw.querySelector('[data-theme="off"]');
  772.     if (offBtn) {
  773.       const lbl = offBtn.querySelector('.bt-sw-theme-label');
  774.       if (lbl) lbl.textContent = themePref === 'off' ? 'ON' : 'OFF';
  775.       offBtn.title = themePref === 'off' ? 'Turn the theme back on' : 'Turn the theme off';
  776.     }
  777.  
  778.     if (effective !== 'off') {
  779.       rebuildSwatches(sw, 'main', effective, mainKey, mainHex);
  780.       rebuildSwatches(sw, 'accent', effective, accentKey, accentHex);
  781.     }
  782.  
  783.     const mobileBtn = sw.querySelector('#bt-sw-mobile-version');
  784.     if (mobileBtn) {
  785.       const mobilePreference = getMobileVersionPreference();
  786.       const mobileMode = getEffectiveMobileMode(mobilePreference);
  787.       const mobileOptimized = mobileMode !== 'full';
  788.       const modeName = mobileMode === 'balanced' ? 'Balanced' : mobileMode === 'lite' ? 'Lite' : 'Full';
  789.       mobileBtn.classList.toggle('selected', mobileOptimized);
  790.       mobileBtn.classList.toggle('bt-sw-mobile-on', mobileOptimized);
  791.       mobileBtn.classList.toggle('bt-sw-mobile-auto', mobilePreference === 'auto');
  792.       const nextModeName = mobilePreference === 'auto'
  793.         ? 'Full'
  794.         : mobilePreference === 'off' ? 'Balanced' : mobilePreference === 'balanced' ? 'Lite' : 'Auto';
  795.       mobileBtn.title = mobilePreference === 'auto'
  796.         ? `Automatic mobile performance (${modeName} now). Click for ${nextModeName}.`
  797.         : `Mobile performance: ${modeName}. Click for ${nextModeName}.`;
  798.       mobileBtn.setAttribute(
  799.         'aria-pressed',
  800.         mobilePreference === 'auto' ? 'mixed' : mobileOptimized ? 'true' : 'false'
  801.       );
  802.       const label = mobileBtn.querySelector('.bt-sw-theme-label');
  803.       if (label) {
  804.         label.textContent = mobilePreference === 'auto'
  805.           ? `Mobile: Auto (${modeName})`
  806.           : `Mobile: ${modeName}`;
  807.       }
  808.       const state = mobileBtn.querySelector('.bt-sw-toggle-state');
  809.       if (state) {
  810.         state.textContent = mobilePreference === 'auto'
  811.           ? 'AUTO'
  812.           : mobileMode === 'balanced' ? 'BAL' : mobileMode === 'lite' ? 'LITE' : 'FULL';
  813.       }
  814.     }
  815.  
  816.     const readBtn = sw.querySelector('#bt-sw-read-shading');
  817.     if (readBtn) {
  818.       const readOn = isTopicReadShadingEnabled();
  819.       readBtn.classList.toggle('selected', readOn);
  820.       readBtn.classList.toggle('bt-sw-read-on', readOn);
  821.       readBtn.title = readOn ? 'Turn read-post shading off' : 'Shade posts you have already read';
  822.       readBtn.setAttribute('aria-pressed', readOn ? 'true' : 'false');
  823.       const state = readBtn.querySelector('.bt-sw-toggle-state');
  824.       if (state) state.textContent = readOn ? 'ON' : 'OFF';
  825.     }
  826.   }
  827.  
  828.   function ensureSettingsToggleControls(sw) {
  829.     if (!sw) return null;
  830.     const panel = sw.querySelector('#bt-switcher-panel');
  831.     if (!panel) return null;
  832.  
  833.     let section = sw.querySelector('.bt-sw-performance-section');
  834.     if (!section) {
  835.       section = document.createElement('div');
  836.       section.className = 'bt-sw-section bt-sw-performance-section';
  837.       const customize = panel.querySelector('.bt-sw-customize');
  838.       if (customize) panel.insertBefore(section, customize);
  839.       else panel.appendChild(section);
  840.     }
  841.  
  842.     function ensureToggle(id, extraClass, label, title, pressed) {
  843.       let btn = sw.querySelector(`#${id}`);
  844.       if (!btn) {
  845.         section.insertAdjacentHTML('beforeend', `
  846.           <button type="button" class="bt-sw-toggle ${extraClass}" id="${id}" title="${title}" aria-pressed="${pressed}">
  847.             <span class="bt-sw-theme-label">${label}</span>
  848.             <span class="bt-sw-toggle-spacer"></span>
  849.             <span class="bt-sw-toggle-track" aria-hidden="true"><span class="bt-sw-toggle-knob"></span></span>
  850.             <span class="bt-sw-toggle-state">${pressed === 'true' ? 'ON' : 'OFF'}</span>
  851.           </button>
  852.         `);
  853.         btn = sw.querySelector(`#${id}`);
  854.       }
  855.       return btn;
  856.     }
  857.  
  858.     const mobileBtn = ensureToggle(
  859.       'bt-sw-mobile-version',
  860.       'bt-sw-mobile-toggle',
  861.       'Mobile mode',
  862.       'Cycle Auto, Full, Balanced and Lite mobile performance',
  863.       'false'
  864.     );
  865.     const readBtn = ensureToggle(
  866.       'bt-sw-read-shading',
  867.       'bt-sw-read-toggle',
  868.       'Read shading',
  869.       'Shade posts you have already read',
  870.       'true'
  871.     );
  872.  
  873.     if (mobileBtn && mobileBtn.dataset.btMobileBound !== '1') {
  874.       mobileBtn.dataset.btMobileBound = '1';
  875.       mobileBtn.addEventListener('click', () => {
  876.         const previousMode = getEffectiveMobileMode();
  877.         const current = getMobileVersionPreference();
  878.         const next = current === 'off'
  879.           ? 'balanced'
  880.           : current === 'balanced' ? 'on' : current === 'on' ? 'auto' : 'off';
  881.         setPref(KEY_MOBILE_VERSION, next);
  882.         applyTheme();
  883.         reconcileMobileRuntime(previousMode, getEffectiveMobileMode(), true);
  884.       });
  885.     }
  886.  
  887.     if (readBtn && readBtn.dataset.btReadBound !== '1') {
  888.       readBtn.dataset.btReadBound = '1';
  889.       readBtn.addEventListener('click', () => {
  890.         const next = isTopicReadShadingEnabled() ? 'off' : 'on';
  891.         setPref(KEY_TOPIC_READ_SHADING, next);
  892.         if (next === 'off') clearReadPostMarks();
  893.         else markReadPostsForCurrentTopic();
  894.         applyTheme();
  895.       });
  896.     }
  897.  
  898.     return { mobileBtn, readBtn };
  899.   }
  900.  
  901.   function rebuildSwatches(sw, kind, effective, selectedKey, currentHex) {
  902.     const row = sw.querySelector(`#bt-sw-${kind}-row`);
  903.     if (!row) return;
  904.     const presets = kind === 'main'
  905.       ? (effective === 'dark' ? MAIN_PRESETS_DARK : MAIN_PRESETS_LIGHT)
  906.       : (effective === 'dark' ? ACCENTS_DARK : ACCENTS_LIGHT);
  907.     const customDef = kind === 'main'
  908.       ? (effective === 'dark' ? DEFAULT_CUSTOM_MAIN_DARK : DEFAULT_CUSTOM_MAIN_LIGHT)
  909.       : (effective === 'dark' ? DEFAULT_CUSTOM_ACCENT_DARK : DEFAULT_CUSTOM_ACCENT_LIGHT);
  910.     const customStorageKey = kind === 'main'
  911.       ? (effective === 'dark' ? KEY_MAIN_DARK_CUSTOM : KEY_MAIN_LIGHT_CUSTOM)
  912.       : (effective === 'dark' ? KEY_ACCENT_DARK_CUSTOM : KEY_ACCENT_LIGHT_CUSTOM);
  913.     const customHex = sanitizeHex(getPref(customStorageKey, customDef), customDef);
  914.     const safeCurrentHex = sanitizeHex(currentHex, customHex);
  915.     const isCustomSelected = selectedKey === 'custom';
  916.     const isAutoSelected = selectedKey === 'auto';
  917.     const signature = [kind, effective, selectedKey, safeCurrentHex, customHex].join('|');
  918.     if (row.dataset.btSwatchSignature === signature && row.dataset.btPreviewing !== '1') return;
  919.     row.dataset.btSwatchSignature = signature;
  920.     delete row.dataset.btPreviewing;
  921.  
  922.     const presetSwatches = Object.entries(presets).map(([key, p]) => {
  923.       const safePresetHex = sanitizeHex(p.base, customDef);
  924.       return `<button type="button" class="bt-sw-swatch${key === selectedKey ? ' selected' : ''}" data-${kind}="${key}" title="${p.name}" style="background:${safePresetHex}"></button>`;
  925.     }).join('');
  926.  
  927.     const autoSwatch = kind === 'accent'
  928.       ? `<button type="button" class="bt-sw-swatch bt-sw-auto${isAutoSelected ? ' selected' : ''}" data-${kind}="auto" title="Auto (matches your Main)"></button>`
  929.       : '';
  930.  
  931.     row.innerHTML = autoSwatch + presetSwatches + `
  932.       <span class="bt-sw-custom-wrap${isCustomSelected ? ' selected' : ''}" data-target="${kind}" title="Custom ${kind} colour">
  933.         <span class="bt-sw-custom-display"${isCustomSelected ? ` style="background:${safeCurrentHex}"` : ''}></span>
  934.         <input type="color" data-target="${kind}" value="${customHex}" aria-label="Custom ${kind} colour" />
  935.       </span>
  936.     `;
  937.   }
  938.   // ===========================================================================
  939.   // Maintab and navigation markers
  940.   // ===========================================================================
  941.  
  942.   function fixMaintabCaps(scope = document) {
  943.     const tabs = queryAllWithin(scope, '[class*="maintab"], [class*="mirrortab"]');
  944.     if (scope !== document && scope.closest) {
  945.       const parentTab = scope.closest('[class*="maintab"], [class*="mirrortab"]');
  946.       if (parentTab && !tabs.includes(parentTab)) tabs.push(parentTab);
  947.     }
  948.  
  949.     const candidateTables = new Set();
  950.     tabs.forEach(el => {
  951.       const text = (el.textContent || '').replace(/\s+/g, '');
  952.       el.classList.toggle('bt-empty-tab-cap', !text);
  953.       const table = el.closest('table');
  954.       if (table) candidateTables.add(table);
  955.     });
  956.  
  957.     candidateTables.forEach(table => {
  958.       const rows = Array.from(table.rows || []);
  959.       const isMainNavigation = table.classList.contains('bt-main-nav') || rows.some(row => (
  960.         Array.from(row.cells || []).some(cell => (
  961.           cell.matches('td[class*="maintab_"]') &&
  962.           Array.from(cell.children).some(child => (
  963.             child.localName === 'a' &&
  964.             (child.getAttribute('href') || '').includes('action=help')
  965.           ))
  966.         ))
  967.       ));
  968.       if (!isMainNavigation) return;
  969.  
  970.       table.classList.add('bt-main-nav');
  971.       rows.forEach(row => {
  972.         Array.from(row.cells || []).forEach(cell => {
  973.           if (!cell.matches('td[class*="maintab_"]')) return;
  974.           const hasDirectLink = Array.from(cell.children).some(child => child.localName === 'a');
  975.           cell.classList.toggle('bt-main-nav-item', hasDirectLink);
  976.         });
  977.       });
  978.     });
  979.   }
  980.  
  981.   const TOPIC_ACTION_TEXTS = new Set([
  982.     'reply',
  983.     'unwatch',
  984.     'notify',
  985.     'mark unread',
  986.     'add poll',
  987.     'print',
  988.     'send this topic',
  989.     'view topic archive',
  990.   ]);
  991.  
  992.   function normaliseTopicActionText(text) {
  993.     return String(text || '').replace(/\s+/g, ' ').trim().toLowerCase();
  994.   }
  995.  
  996.   function markTopicActionBars(scope = document) {
  997.     const cells = queryAllWithin(scope, 'td[class*="maintab_"], td[class*="mirrortab_"]');
  998.     if (scope !== document && scope.closest) {
  999.       const parentCell = scope.closest('td[class*="maintab_"], td[class*="mirrortab_"]');
  1000.       if (parentCell && !cells.includes(parentCell)) cells.push(parentCell);
  1001.     }
  1002.     const tables = new Set(cells.map(cell => cell.closest('table')).filter(Boolean));
  1003.     tables.forEach(table => {
  1004.       if (!table.classList.contains('bt-topic-action-bar')) {
  1005.         const links = Array.from(table.querySelectorAll('a'));
  1006.         if (!links.some(a => TOPIC_ACTION_TEXTS.has(normaliseTopicActionText(a.textContent)))) return;
  1007.       }
  1008.  
  1009.       table.classList.add('bt-topic-action-bar');
  1010.       table.querySelectorAll('td[class*="maintab_"], td[class*="mirrortab_"]').forEach(td => {
  1011.         td.classList.add('bt-topic-action-cell');
  1012.       });
  1013.     });
  1014.  
  1015.     // SMF 2.x Curve can render the same thread actions as a buttonlist with a
  1016.     // sprite on both the anchor and its nested span.
  1017.     const buttonLists = queryAllWithin(scope, '.buttonlist');
  1018.     if (scope !== document && scope.closest) {
  1019.       const parentList = scope.closest('.buttonlist');
  1020.       if (parentList && !buttonLists.includes(parentList)) buttonLists.push(parentList);
  1021.     }
  1022.     buttonLists.forEach(list => {
  1023.       const links = Array.from(list.querySelectorAll('a[class*="button_strip_"]'));
  1024.       if (!links.some(a => TOPIC_ACTION_TEXTS.has(normaliseTopicActionText(a.textContent)))) return;
  1025.       list.classList.add('bt-topic-action-bar');
  1026.     });
  1027.   }
  1028.  
  1029.   // ===========================================================================
  1030.   // BBCode icons
  1031.   // ===========================================================================
  1032.  
  1033.   const BBCODE_SVGS = {
  1034.     bold: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4h7a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/><path d="M6 12h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"/></svg>',
  1035.     italic: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>',
  1036.     underline: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3v8a6 6 0 0 0 12 0V3"/><line x1="4" y1="21" x2="20" y2="21"/></svg>',
  1037.     strike: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 4H9a3 3 0 0 0-2.83 4M14 12a4 4 0 0 1 0 8H6"/><line x1="4" y1="12" x2="20" y2="12"/></svg>',
  1038.     pre: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>',
  1039.     code: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
  1040.     quote: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.75-2-2-2H4c-1.25 0-2 .75-2 2v6c0 1.25.75 2 2 2h1v1c0 1-1 2-2 2v3c0 1 0 1 1 1z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.75-2-2-2h-4c-1.25 0-2 .75-2 2v6c0 1.25.75 2 2 2h1v1c0 1-1 2-2 2v3c0 1 0 1 1 1z"/></svg>',
  1041.     img: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',
  1042.     url: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',
  1043.     email: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><polyline points="22,6 12,13 2,6"/></svg>',
  1044.     ftp: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>',
  1045.     flash: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>',
  1046.     youtube: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22.54 6.42a2.78 2.78 0 0 0-1.94-2C18.88 4 12 4 12 4s-6.88 0-8.6.46a2.78 2.78 0 0 0-1.94 2A29 29 0 0 0 1 11.75a29 29 0 0 0 .46 5.33A2.78 2.78 0 0 0 3.4 19c1.72.46 8.6.46 8.6.46s6.88 0 8.6-.46a2.78 2.78 0 0 0 1.94-2 29 29 0 0 0 .46-5.25 29 29 0 0 0-.46-5.33z"/><polygon points="9.75 15.02 15.5 11.75 9.75 8.48 9.75 15.02"/></svg>',
  1047.     list: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><circle cx="3.5" cy="6" r="1"/><circle cx="3.5" cy="12" r="1"/><circle cx="3.5" cy="18" r="1"/></svg>',
  1048.     orderlist: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg>',
  1049.     left: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="17" y1="10" x2="3" y2="10"/><line x1="21" y1="6" x2="3" y2="6"/><line x1="21" y1="14" x2="3" y2="14"/><line x1="17" y1="18" x2="3" y2="18"/></svg>',
  1050.     center: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="10" x2="6" y2="10"/><line x1="21" y1="6" x2="3" y2="6"/><line x1="21" y1="14" x2="3" y2="14"/><line x1="18" y1="18" x2="6" y2="18"/></svg>',
  1051.     right: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="21" y1="10" x2="7" y2="10"/><line x1="21" y1="6" x2="3" y2="6"/><line x1="21" y1="14" x2="3" y2="14"/><line x1="21" y1="18" x2="7" y2="18"/></svg>',
  1052.     hr: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"/></svg>',
  1053.     sub: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 5l8 11"/><path d="M12 5L4 16"/><text x="14" y="22" font-size="9" fill="currentColor" stroke="none">2</text></svg>',
  1054.     sup: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 8l8 11"/><path d="M12 8L4 19"/><text x="14" y="9" font-size="9" fill="currentColor" stroke="none">2</text></svg>',
  1055.     tt: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 4 20 4 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="4" x2="12" y2="20"/></svg>',
  1056.     font: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 4 20 4 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="4" x2="12" y2="20"/></svg>',
  1057.     size: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7V4h18v3"/><path d="M8 20h8"/><path d="M12 4v16"/><path d="M18 14v6"/><path d="M15 14h6"/></svg>',
  1058.     color: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10c.93 0 1.69-.76 1.69-1.69 0-.43-.16-.83-.43-1.13-.27-.31-.43-.71-.43-1.13a1.69 1.69 0 0 1 1.69-1.69h1.99c3.04 0 5.49-2.45 5.49-5.49C22 6.04 17.52 2 12 2z"/><circle cx="6.5" cy="11.5" r="1.5"/><circle cx="9.5" cy="7.5" r="1.5"/><circle cx="14.5" cy="7.5" r="1.5"/><circle cx="17.5" cy="11.5" r="1.5"/></svg>',
  1059.     table: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/></svg>',
  1060.     glow: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>',
  1061.     shadow: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 3a9 9 0 0 1 0 18z" fill="currentColor"/></svg>',
  1062.     spoiler: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>',
  1063.     abbr: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>',
  1064.     bitcoin: '<svg viewBox="0 0 24 24" fill="currentColor" stroke="none"><path d="M16.43 11.36c.5-.4.85-1 .85-1.74 0-1.6-1.27-2.66-3.06-2.84V5h-1.5v1.7H11V5H9.5v1.7H7v1.5h1.2V16H7v1.5h2.5V19H11v-1.5h1.72V19h1.5v-1.5c2.05 0 3.34-1.18 3.34-3 0-.93-.42-1.74-1.13-2.14zm-5.93-3.16h2.74c.74 0 1.3.42 1.3 1.2 0 .76-.56 1.2-1.3 1.2H10.5V8.2zm3.04 7.6H10.5v-2.6h3.04c.83 0 1.46.5 1.46 1.3 0 .8-.63 1.3-1.46 1.3z"/></svg>',
  1065.     trow: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><rect x="3" y="9" width="18" height="6" fill="currentColor" stroke="none" opacity="0.35"/></svg>',
  1066.     tcol: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="15" y1="3" x2="15" y2="21"/><rect x="9" y="3" width="6" height="18" fill="currentColor" stroke="none" opacity="0.35"/></svg>',
  1067.     trash: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/><path d="M9 6V4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2"/></svg>',
  1068.     pencil: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"/></svg>',
  1069.   };
  1070.  
  1071.   const BBCODE_ALIASES = {
  1072.     italic: ['italicize'],
  1073.     bold: ['bolden'],
  1074.     strike: ['strikethrough', 'linethrough'],
  1075.     tt: ['teletype', 'monospace', 'tele'],
  1076.     font: ['fontface', 'fontname', 'face'],
  1077.     color: ['colour', 'fontcolour', 'fontcolor'],
  1078.     size: ['fontsize'],
  1079.     left: ['alignleft'],
  1080.     center: ['aligncenter'],
  1081.     right: ['alignright'],
  1082.     list: ['bullist'],
  1083.     orderlist: ['numlist', 'numberedlist'],
  1084.     img: ['image', 'picture'],
  1085.     url: ['link', 'hyperlink'],
  1086.     email: ['mail'],
  1087.     youtube: ['video', 'youtu'],
  1088.     hr: ['horizontalrule'],
  1089.     sub: ['subscript'],
  1090.     sup: ['superscript'],
  1091.     bitcoin: ['btc'],
  1092.     trow: ['tr'],
  1093.     tcol: ['td'],
  1094.     trash: ['delete', 'remove', 'del'],
  1095.     pencil: ['modify', 'edit', 'pen'],
  1096.   };
  1097.   Object.entries(BBCODE_ALIASES).forEach(([canon, aliases]) => {
  1098.     aliases.forEach(a => { BBCODE_SVGS[a] = BBCODE_SVGS[canon]; });
  1099.   });
  1100.   // ===========================================================================
  1101.   // Topic-list / board-list / message-status icon modernisation
  1102.   // ===========================================================================
  1103.   //
  1104.   // Bitcointalk thread-list and thread-header pages still use classic SMF GIFs:
  1105.   // topic state icons, locked/sticky/poll icons, and message icons such as
  1106.   // exclamation/question/lamp/thumbs. These are not BBCode compose toolbar
  1107.   // icons, so they need a separate pass. The originals stay in the DOM and are
  1108.   // restored in OFF mode via setModernizedControlsActive().
  1109.   const TOPIC_ICON_SVGS = {
  1110.     topic: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6.5A2.5 2.5 0 0 1 6.5 4h11A2.5 2.5 0 0 1 20 6.5v8A2.5 2.5 0 0 1 17.5 17H9l-5 3v-13.5z"/><line x1="8" y1="9" x2="16" y2="9"/><line x1="8" y1="12" x2="14" y2="12"/></svg>',
  1111.     hot: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8.5 14.5A3.5 3.5 0 0 0 12 21a6 6 0 0 0 6-6c0-4-3-6-4.5-9.5-.4 2.4-1.6 3.9-3.5 5.2C8.5 11.7 8 12.8 8.5 14.5z"/><path d="M12 21c-1.2-1-1.6-2.4-.9-4 .5-1.1 1.4-1.8 2-3 .7 1.2 1.4 2.2 1.4 3.6A3.2 3.2 0 0 1 12 21z"/></svg>',
  1112.     veryhot: '<svg viewBox="0 0 24 24" fill="rgba(217,48,37,0.18)" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7.5 14.5A4.5 4.5 0 0 0 12 21a7 7 0 0 0 7-7c0-4.4-3.2-6.7-4.8-10.5-.5 2.7-1.9 4.4-4 5.9-1.8 1.3-2.9 2.8-2.7 5.1z"/><path d="M12 21c-1.5-1.2-2-2.8-1.1-4.7.6-1.3 1.7-2.1 2.4-3.5.9 1.4 1.7 2.6 1.7 4.2A3.8 3.8 0 0 1 12 21z" fill="rgba(217,48,37,0.35)"/><path d="M5 9c-1 .9-1.5 2-1.3 3.3" fill="none"/></svg>',
  1113.     poll: '<svg viewBox="0 0 24 24" fill="rgba(139,92,246,0.25)" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="20" x2="20" y2="20" fill="none"/><rect x="6" y="10" width="3" height="7" rx="1"/><rect x="11" y="6" width="3" height="11" rx="1"/><rect x="16" y="13" width="3" height="4" rx="1"/></svg>',
  1114.     moved: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="M13 6l6 6-6 6"/><path d="M5 5v14"/></svg>',
  1115.     important: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><line x1="12" y1="7" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
  1116.     question: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M9.4 9a3 3 0 1 1 4.9 2.3c-1.3.9-2.3 1.5-2.3 3.2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg>',
  1117.     idea: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18h6"/><path d="M10 22h4"/><path d="M8 14a6 6 0 1 1 8 0c-1.2.9-1.5 1.8-1.5 3h-5c0-1.2-.3-2.1-1.5-3z"/></svg>',
  1118.     thumbsUp: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"/><path d="M7 11l4-8a3 3 0 0 1 3 3v4h5a2 2 0 0 1 2 2l-1 7a3 3 0 0 1-3 3H7z"/></svg>',
  1119.     thumbsDown: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 2h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-3"/><path d="M17 13l-4 8a3 3 0 0 1-3-3v-4H5a2 2 0 0 1-2-2l1-7a3 3 0 0 1 3-3h10z"/></svg>',
  1120.     smile: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><line x1="9" y1="9" x2="9.01" y2="9"/><line x1="15" y1="9" x2="15.01" y2="9"/></svg>',
  1121.     angry: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M8 8l3 2"/><path d="M16 8l-3 2"/><path d="M8 16s1.5-1.5 4-1.5S16 16 16 16"/></svg>',
  1122.     standard: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 4h7l5 5v11a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z"/><path d="M14 4v5h5"/></svg>',
  1123.   };
  1124.  
  1125.   // ===========================================================================
  1126.   // v2.10.15: Inline status icons via src replacement
  1127.   // ===========================================================================
  1128.   //
  1129.   // Classic SMF places certain status icons as <img> elements that the browser
  1130.   // already positions correctly:
  1131.   //   • quick_lock.gif lives on the lock'd thread row with align="right" — the
  1132.   //     browser floats it to the right edge of the subject cell automatically.
  1133.   //   • the "new" indicator is an <img> inside <a href="...new">, which sits
  1134.   //     naturally after the topic title.
  1135.   //
  1136.   // Earlier versions tried to hide these <img>s and inject synthetic spans in
  1137.   // their place. That fights the SMF layout and led to the wrapper-position
  1138.   // and visibility bugs in 2.10.13/2.10.14. The cleaner approach is to keep
  1139.   // every <img> exactly where SMF rendered it and only swap its `src` to a
  1140.   // modern SVG data-URL. OFF mode restoration becomes trivial: put the
  1141.   // original src back.
  1142.   //
  1143.   // Colors are baked into the SVGs because data-URL SVGs run in their own
  1144.   // document context and cannot read the host page's CSS variables. Gold for
  1145.   // the lock matches the classic Bitcointalk yellow padlock; the dark-blue
  1146.   // pill for "new" matches the original SMF "new" badge tint.
  1147.  
  1148.   const INLINE_LOCK_SVG = (
  1149.     // v2.10.17: bumped from 14×14 to 17×17 to match the upsized sticky pin.
  1150.     '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 14" width="17" height="17">' +
  1151.       '<path d="M4.2 6V4.2C4.2 2.65 5.45 1.4 7 1.4C8.55 1.4 9.8 2.65 9.8 4.2V6" ' +
  1152.         'fill="none" stroke="#a17710" stroke-width="1.3" stroke-linecap="round"/>' +
  1153.       '<rect x="2.6" y="6" width="8.8" height="6.6" rx="1.1" fill="#e8b923" stroke="#a17710" stroke-width="0.6"/>' +
  1154.       '<circle cx="7" cy="9" r="0.85" fill="#7a5808"/>' +
  1155.       '<rect x="6.55" y="9" width="0.9" height="2.2" rx="0.3" fill="#7a5808"/>' +
  1156.     '</svg>'
  1157.   );
  1158.  
  1159.   const INLINE_NEW_SVG = (
  1160.     '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 13" width="26" height="13">' +
  1161.       '<rect x="0" y="0" width="26" height="13" rx="6.5" fill="#4d6c8c"/>' +
  1162.       '<text x="13" y="9.6" text-anchor="middle" ' +
  1163.         'font-family="-apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif" ' +
  1164.         'font-size="8" font-weight="600" fill="#ffffff" letter-spacing="0.2">new</text>' +
  1165.     '</svg>'
  1166.   );
  1167.  
  1168.   // v2.10.17: bumped from 14×14 to 17×17 for better visual presence next to
  1169.   // the topic title — the previous size felt cramped especially compared to
  1170.   // the title's 13px font.
  1171.   const INLINE_STICKY_SVG = (
  1172.     '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 14" width="17" height="17">' +
  1173.       '<line x1="8.5" y1="8.5" x2="12.5" y2="12.5" stroke="#4a4a4a" stroke-width="1" stroke-linecap="round"/>' +
  1174.       '<circle cx="6" cy="6" r="4" fill="#cc3838" stroke="#7a2020" stroke-width="0.6"/>' +
  1175.       '<ellipse cx="4.6" cy="4.8" rx="1.1" ry="0.8" fill="#ee9595" opacity="0.75"/>' +
  1176.     '</svg>'
  1177.   );
  1178.  
  1179.   function svgToDataUrl(svg) {
  1180.     return 'data:image/svg+xml;utf8,' + encodeURIComponent(svg);
  1181.   }
  1182.  
  1183.   const INLINE_LOCK_DATAURL = svgToDataUrl(INLINE_LOCK_SVG);
  1184.   const INLINE_NEW_DATAURL = svgToDataUrl(INLINE_NEW_SVG);
  1185.   const INLINE_STICKY_DATAURL = svgToDataUrl(INLINE_STICKY_SVG);
  1186.  
  1187.   // True when the IMG is the standalone lock indicator that SMF places to the
  1188.   // right of a topic title. Compound state icons like sticky_locked.gif live
  1189.   // in the left state column and are handled separately.
  1190.   function isInlineLockImage(img) {
  1191.     const src = (img.getAttribute('src') || '').toLowerCase();
  1192.     if (!/lock/.test(src)) return false;
  1193.     if (/sticky[_-]?locked|locked[_-]?(post|sticky|topic|poll)/.test(src)) return false;
  1194.     // align="right" is the SMF tell — only inline lock indicators use it.
  1195.     if ((img.getAttribute('align') || '').toLowerCase() === 'right') return true;
  1196.     // Fallback: filenames like quick_lock.gif / lock.gif that aren't compound.
  1197.     return /(^|[/_-])(quick[_-]?lock|lock)\.(gif|png)/.test(src);
  1198.   }
  1199.  
  1200.   // v2.10.16: standalone sticky-pin indicator that SMF places to the right of
  1201.   // a sticky topic title. Same parsing rules as the lock detector — exclude
  1202.   // compound left-column icons (sticky_post / sticky_locked / sticky_poll),
  1203.   // trigger on align="right", fall back to filename pattern.
  1204.   function isInlineStickyImage(img) {
  1205.     const src = (img.getAttribute('src') || '').toLowerCase();
  1206.     if (!/sticky|pin/.test(src)) return false;
  1207.     if (/sticky[_-]?(locked|post|poll|topic)|locked[_-]?sticky/.test(src)) return false;
  1208.     if ((img.getAttribute('align') || '').toLowerCase() === 'right') return true;
  1209.     return /(^|[/_-])(quick[_-]?sticky|sticky|pin|pinned)\.(gif|png)/.test(src);
  1210.   }
  1211.  
  1212.   // True when the IMG is the "new" indicator wrapped in <a href="...new">.
  1213.   function isInlineNewImage(img) {
  1214.     const src = (img.getAttribute('src') || '').toLowerCase();
  1215.     if (!/(^|[/_-])(new|unread)/.test(src)) return false;
  1216.     const link = img.closest('a[href*="topic="]');
  1217.     if (!link) return false;
  1218.     const href = (link.getAttribute('href') || '').toLowerCase();
  1219.     return /[#;]new\b|;topicseen|msg\d+/.test(href);
  1220.   }
  1221.  
  1222.   // Swap the IMG's src to a modern SVG data-URL while preserving the original
  1223.   // for OFF-mode restoration. Returns true if the swap was applied (or already
  1224.   // in place), false otherwise.
  1225.   function applyInlineIconSrc(img, dataUrl) {
  1226.     if (!img || !dataUrl) return false;
  1227.     if (img.dataset.btInlineIconActive === '1' && img.getAttribute('src') === dataUrl) return true;
  1228.     if (!Object.prototype.hasOwnProperty.call(img.dataset, 'btOriginalSrc')) {
  1229.       img.dataset.btOriginalSrc = img.getAttribute('src') || '';
  1230.     }
  1231.     img.setAttribute('src', dataUrl);
  1232.     img.dataset.btInlineIconActive = '1';
  1233.     img.dataset.btReplaced = '1';
  1234.     return true;
  1235.   }
  1236.  
  1237.   function restoreInlineIconSrc(img) {
  1238.     if (!img) return;
  1239.     if (img.dataset.btInlineIconActive !== '1') return;
  1240.     const originalSrc = img.dataset.btOriginalSrc;
  1241.     if (typeof originalSrc === 'string') img.setAttribute('src', originalSrc);
  1242.     img.dataset.btInlineIconActive = '0';
  1243.   }
  1244.  
  1245.   // Mark and tint the topic subject cell for both standalone inline markers
  1246.   // and compound left-column status images. The inline declaration is only a
  1247.   // compatibility fallback; the stylesheet owns the final colour and hover
  1248.   // state through palette-derived variables.
  1249.   function findSpecialTopicSubjectCell(statusImg) {
  1250.     if (!statusImg) return null;
  1251.     const titleLink = findTopicTitleLinkNear(statusImg);
  1252.     return (titleLink && titleLink.closest('td')) || statusImg.closest('td');
  1253.   }
  1254.  
  1255.   function markSpecialTopicRow(statusImg, type) {
  1256.     if (!statusImg || (type !== 'sticky' && type !== 'locked')) return;
  1257.     const tr = statusImg.closest('tr');
  1258.     const subjectCell = findSpecialTopicSubjectCell(statusImg);
  1259.     if (!tr || !subjectCell) return;
  1260.     tr.classList.add(`bt-row-${type}`);
  1261.     subjectCell.classList.add('bt-cell-special-subject', `bt-cell-${type}-subject`);
  1262.     Array.from(tr.children).forEach(cell => {
  1263.       if (cell.matches('td')) cell.classList.add('bt-cell-special-topic');
  1264.     });
  1265.     applySpecialTopicRowTintInline(tr);
  1266.   }
  1267.  
  1268.   function applySpecialTopicRowTintInline(tr) {
  1269.     if (!tr) return;
  1270.     const root = document.documentElement;
  1271.     const themeActive = root.getAttribute('data-bt-active') === 'true';
  1272.     if (!themeActive) return;
  1273.     const cells = Array.from(tr.children).filter(cell => cell.matches('td'));
  1274.     if (!cells.length) return;
  1275.     const type = tr.classList.contains('bt-row-sticky') ? 'sticky' : 'locked';
  1276.     cells.forEach(cell => {
  1277.       cell.classList.add('bt-cell-special-topic');
  1278.       if (!Object.prototype.hasOwnProperty.call(cell.dataset, 'btOriginalSpecialBgColor')) {
  1279.         cell.dataset.btOriginalSpecialBgColor = cell.style.getPropertyValue('background-color');
  1280.         cell.dataset.btOriginalSpecialBgColorPriority = cell.style.getPropertyPriority('background-color');
  1281.         cell.dataset.btOriginalSpecialBgImage = cell.style.getPropertyValue('background-image');
  1282.         cell.dataset.btOriginalSpecialBgImagePriority = cell.style.getPropertyPriority('background-image');
  1283.       }
  1284.       cell.style.setProperty('background-color', `var(--bt-${type}-row-bg)`);
  1285.       cell.style.setProperty('background-image', 'none');
  1286.     });
  1287.     tr.dataset.btSpecialTintApplied = '1';
  1288.   }
  1289.  
  1290.   function clearSpecialTopicRowTintInline(tr) {
  1291.     if (!tr) return;
  1292.     const cells = Array.from(tr.children).filter(cell => cell.matches('td'));
  1293.     cells.forEach(cell => {
  1294.       if (!Object.prototype.hasOwnProperty.call(cell.dataset, 'btOriginalSpecialBgColor')) return;
  1295.       const restoreProperty = (name, value, priority) => {
  1296.         cell.style.removeProperty(name);
  1297.         if (value) cell.style.setProperty(name, value, priority || '');
  1298.       };
  1299.       restoreProperty(
  1300.         'background-color',
  1301.         cell.dataset.btOriginalSpecialBgColor,
  1302.         cell.dataset.btOriginalSpecialBgColorPriority
  1303.       );
  1304.       restoreProperty(
  1305.         'background-image',
  1306.         cell.dataset.btOriginalSpecialBgImage,
  1307.         cell.dataset.btOriginalSpecialBgImagePriority
  1308.       );
  1309.     });
  1310.     tr.dataset.btSpecialTintApplied = '0';
  1311.   }
  1312.  
  1313.   // Typography is now handled entirely by static CSS. This migration runs
  1314.   // once at startup to remove inline markers left by an older userscript
  1315.   // instance without putting document-wide scans back into the live paths.
  1316.   function clearLegacyInlineSizing() {
  1317.     const selector = [
  1318.       '.bt-breadcrumb-fixed',
  1319.       '.bt-header-sized',
  1320.       '.bt-header-self-sized',
  1321.       '.bt-merit-sized',
  1322.       '.bt-compose-sized',
  1323.     ].join(', ');
  1324.  
  1325.     document.querySelectorAll(selector).forEach(el => {
  1326.       if (el.classList.contains('bt-breadcrumb-fixed')) {
  1327.         el.style.removeProperty('font-size');
  1328.         el.style.removeProperty('line-height');
  1329.         if (Object.prototype.hasOwnProperty.call(el.dataset, 'btOriginalFs')) {
  1330.           if (el.dataset.btOriginalFs) el.style.fontSize = el.dataset.btOriginalFs;
  1331.           delete el.dataset.btOriginalFs;
  1332.         }
  1333.         el.querySelectorAll('*').forEach(child => {
  1334.           child.style.removeProperty('font-size');
  1335.           child.style.removeProperty('line-height');
  1336.         });
  1337.         el.classList.remove('bt-breadcrumb-fixed');
  1338.       }
  1339.  
  1340.       if (el.classList.contains('bt-header-sized')) {
  1341.         el.style.removeProperty('font-size');
  1342.         el.style.removeProperty('line-height');
  1343.         if (Object.prototype.hasOwnProperty.call(el.dataset, 'btOriginalHdrFs')) {
  1344.           if (el.dataset.btOriginalHdrFs) el.style.fontSize = el.dataset.btOriginalHdrFs;
  1345.           delete el.dataset.btOriginalHdrFs;
  1346.         }
  1347.         el.querySelectorAll('*').forEach(child => {
  1348.           child.style.removeProperty('font-size');
  1349.           child.style.removeProperty('line-height');
  1350.         });
  1351.         el.classList.remove('bt-header-sized');
  1352.       }
  1353.  
  1354.       if (el.classList.contains('bt-header-self-sized')) {
  1355.         el.style.removeProperty('font-size');
  1356.         el.style.removeProperty('line-height');
  1357.         el.style.removeProperty('font-weight');
  1358.         if (Object.prototype.hasOwnProperty.call(el.dataset, 'btOriginalHdrSelfFs')) {
  1359.           if (el.dataset.btOriginalHdrSelfFs) el.style.fontSize = el.dataset.btOriginalHdrSelfFs;
  1360.           if (el.dataset.btOriginalHdrSelfLh) el.style.lineHeight = el.dataset.btOriginalHdrSelfLh;
  1361.           if (el.dataset.btOriginalHdrSelfFw) el.style.fontWeight = el.dataset.btOriginalHdrSelfFw;
  1362.           delete el.dataset.btOriginalHdrSelfFs;
  1363.           delete el.dataset.btOriginalHdrSelfLh;
  1364.           delete el.dataset.btOriginalHdrSelfFw;
  1365.         }
  1366.         el.classList.remove('bt-header-self-sized');
  1367.       }
  1368.  
  1369.       if (el.classList.contains('bt-merit-sized')) {
  1370.         el.style.removeProperty('font-size');
  1371.         el.style.removeProperty('line-height');
  1372.         el.style.removeProperty('font-family');
  1373.         el.style.removeProperty('letter-spacing');
  1374.         if (Object.prototype.hasOwnProperty.call(el.dataset, 'btOriginalMeritFs')) {
  1375.           if (el.dataset.btOriginalMeritFs) el.style.fontSize = el.dataset.btOriginalMeritFs;
  1376.           if (el.dataset.btOriginalMeritLh) el.style.lineHeight = el.dataset.btOriginalMeritLh;
  1377.           if (el.dataset.btOriginalMeritFamily) el.style.fontFamily = el.dataset.btOriginalMeritFamily;
  1378.           delete el.dataset.btOriginalMeritFs;
  1379.           delete el.dataset.btOriginalMeritLh;
  1380.           delete el.dataset.btOriginalMeritFamily;
  1381.         }
  1382.         el.classList.remove('bt-merit-sized');
  1383.       }
  1384.  
  1385.       if (el.classList.contains('bt-compose-sized')) {
  1386.         el.style.removeProperty('font-size');
  1387.         el.style.removeProperty('line-height');
  1388.         if (Object.prototype.hasOwnProperty.call(el.dataset, 'btOriginalComposeFs')) {
  1389.           if (el.dataset.btOriginalComposeFs) el.style.fontSize = el.dataset.btOriginalComposeFs;
  1390.           if (el.dataset.btOriginalComposeLh) el.style.lineHeight = el.dataset.btOriginalComposeLh;
  1391.           delete el.dataset.btOriginalComposeFs;
  1392.           delete el.dataset.btOriginalComposeLh;
  1393.         }
  1394.         el.classList.remove('bt-compose-sized');
  1395.       }
  1396.     });
  1397.  
  1398.     removeMeritLockStyle();
  1399.   }
  1400.  
  1401.   function removeMeritLockStyle() {
  1402.     const style = document.getElementById('bt-merit-lock-css');
  1403.     if (style) style.remove();
  1404.   }
  1405.  
  1406.   function stopMeritSizingObserver() {
  1407.     // Kept as a no-op compatibility hook for mobile/runtime reconciliation.
  1408.     removeMeritLockStyle();
  1409.   }
  1410.  
  1411.   function getImageBaseName(img) {
  1412.     const src = img.getAttribute('src') || '';
  1413.     const clean = src.split(/[?#]/)[0];
  1414.     const file = clean.slice(clean.lastIndexOf('/') + 1);
  1415.     return file
  1416.       .replace(/\.(?:gif|png|jpe?g|webp)$/i, '')
  1417.       .toLowerCase()
  1418.       .replace(/^(?:topic|theme|smf|icon)_/, '');
  1419.   }
  1420.  
  1421.   function topicIconHaystack(img) {
  1422.     const src = (img.getAttribute('src') || '').toLowerCase();
  1423.     const name = getImageBaseName(img);
  1424.     const label = ((img.getAttribute('alt') || '') + ' ' + (img.getAttribute('title') || '')).toLowerCase();
  1425.     return { src, name, label, hay: `${src} ${name} ${label}` };
  1426.   }
  1427.  
  1428.   function isCompoundStickyTopicIconName(name, hay) {
  1429.     // sticky_post / sticky_poll / sticky_locked are the LEFT topic-state icon.
  1430.     // They are not the inline PIN marker. The inline pin is usually a small
  1431.     // standalone sticky/pin/pinned icon near the title.
  1432.     return /(?:^|[_-])sticky(?:[_-](?:post|poll|locked)|locked)(?:[_-]|$)/.test(name) ||
  1433.       /sticky_(?:post|poll|locked)/.test(name) ||
  1434.       /stickylocked|stickied_post|stickied_poll/.test(name) ||
  1435.       /sticky[_-]?(?:topic|thread|post|poll|locked)|(?:^|[_-])sticky(?:[_-]|$).*(?:post|poll|locked)/.test(hay);
  1436.   }
  1437.  
  1438.   function isCompoundLockedTopicIconName(name, hay) {
  1439.     return /locked?[_-](?:post|poll|topic|thread)/.test(name) ||
  1440.       /(?:^|[_-])locked(?:[_-](?:post|poll|topic|thread)|post|poll)(?:[_-]|$)/.test(name) ||
  1441.       /sticky[_-]?locked/.test(name) ||
  1442.       /lock(?:ed)?[_-]?(?:topic|thread|post|poll)|(?:^|[_-])lock(?:ed)?(?:[_-]|$).*(?:post|poll|topic|thread)/.test(hay);
  1443.   }
  1444.  
  1445.   function topicIconTypeForImage(img) {
  1446.     const { src, name, label, hay } = topicIconHaystack(img);
  1447.  
  1448.     // Avoid touching avatars, rank images, logos, the compose toolbar, and
  1449.     // actual inline post images. Thread/message icons can live in wrappers
  1450.     // such as .td_headerandpost, but should not live inside the .post body.
  1451.     if (
  1452.       img.closest('#bbcBox_message, .bbc_buttons, [id^="bbc_"], td.post, .post, .personalmessage, .signature, .poster_info') ||
  1453.       /avatar|rank|star|user|flag|logo/i.test(src)
  1454.     ) {
  1455.       return null;
  1456.     }
  1457.  
  1458.     const looksLikeTopicIcon =
  1459.       /\/topic\//i.test(src) ||
  1460.       /(?:^|[_-])(normal|hot|veryhot|very_hot|locked|lock|sticky|pin|pinned|sticky_locked|poll|moved|redirect|new|unread)(?:[_-]|$)/i.test(name) &&
  1461.       /(post|topic|poll|locked|lock|sticky|pin|pinned|hot|veryhot|normal|moved|redirect|new|unread)/i.test(name + ' ' + label);
  1462.  
  1463.     const looksLikeMessageIcon =
  1464.       /\/post\//i.test(src) ||
  1465.       /\/message/i.test(src) ||
  1466.       /(?:^|[_-])(standard|xx|exclam|exclamation|question|lamp|idea|thumbup|thumbdown|thumb_up|thumb_down|smiley|happy|angry|sad|cheesy|grin|wink|new|unread)(?:[_-]|$)/i.test(name);
  1467.  
  1468.     if (!looksLikeTopicIcon && !looksLikeMessageIcon) return null;
  1469.  
  1470.     if (/(^|[_\s./-])(new|unread)([_\s./-]|$)|\bnew\b|\bunread\b/.test(hay)) return 'newPost';
  1471.     if (/moved|redirect/.test(hay)) return 'moved';
  1472.  
  1473.     const compoundSticky = isCompoundStickyTopicIconName(name, hay);
  1474.     const compoundLocked = isCompoundLockedTopicIconName(name, hay);
  1475.  
  1476.     // Compound SMF files such as sticky_locked.gif, locked_post.gif and
  1477.     // sticky_post.gif are LEFT-column folder/topic-state images. In the
  1478.     // classic visual layout, the PIN/LOCK markers belong beside the title.
  1479.     // Therefore this function returns only the neutral left-state icon; the
  1480.     // row tint and any native inline marker carry the sticky/locked state.
  1481.     if (compoundSticky || compoundLocked) {
  1482.       if (/poll/.test(hay)) return 'poll';
  1483.       if (/veryhot|very_hot|very hot/.test(hay)) return 'veryhot';
  1484.       if (/(^|[_\s/-])hot([_\s./-]|$)/.test(hay)) return 'hot';
  1485.       return 'topic';
  1486.     }
  1487.  
  1488.     if (/sticky|pinned|\bpin\b/.test(hay)) return 'sticky';
  1489.     if (/locked|\block\b/.test(hay)) return 'locked';
  1490.     if (/poll/.test(hay)) return 'poll';
  1491.     if (/veryhot|very_hot|very hot/.test(hay)) return 'veryhot';
  1492.     if (/(^|[_\s/-])hot([_\s./-]|$)/.test(hay)) return 'hot';
  1493.  
  1494.     if (/exclam|exclamation|important|warning|alert|\!/.test(hay)) return 'important';
  1495.     if (/question|\?/.test(hay)) return 'question';
  1496.     if (/lamp|idea|lightbulb|bulb/.test(hay)) return 'idea';
  1497.     if (/thumbup|thumb_up|thumbs? up|\+1/.test(hay)) return 'thumbsUp';
  1498.     if (/thumbdown|thumb_down|thumbs? down|-1/.test(hay)) return 'thumbsDown';
  1499.     if (/angry|mad/.test(hay)) return 'angry';
  1500.     if (/smiley|happy|cheesy|grin|wink|sad/.test(hay)) return 'smile';
  1501.     if (/standard|xx/.test(hay)) return 'standard';
  1502.  
  1503.     return 'topic';
  1504.   }
  1505.  
  1506.   function findTopicTitleLinkNear(img) {
  1507.     const row = img.closest('tr');
  1508.     const scope = row || img.closest('td') || document;
  1509.     const links = Array.from(scope.querySelectorAll('a[href*="topic="]'));
  1510.     return links.find(a => {
  1511.       const text = (a.textContent || '').replace(/\s+/g, ' ').trim();
  1512.       const href = a.getAttribute('href') || '';
  1513.       if (!text) return false;
  1514.       // SMF action links can appear before the title and may themselves be
  1515.       // labelled "New". Use their URL markers to distinguish them so a real
  1516.       // topic whose complete title is "New" remains a valid candidate.
  1517.       if (/(?:[.;]new(?:[#;]|$)|#new$|[.;]topicseen(?:[;#]|$)|[.;]msg\d+(?:[;#]|$)|#msg\d+$)/i.test(href)) {
  1518.         return false;
  1519.       }
  1520.       if (/^(?:last post|last edit|notify)\W*$/i.test(text)) return false;
  1521.       return true;
  1522.     }) || null;
  1523.   }
  1524.  
  1525.   function modernizeTopicListIcons(scope = document) {
  1526.     // v2.10.17: clean up any leftover bt-topic-icon spans that previous
  1527.     // versions of this script accidentally created inside compose-panel
  1528.     // smiley links. Without this, users upgrading from 2.10.15/16 keep
  1529.     // seeing the duplicate outline glyphs until they hard-reload.
  1530.     queryAllWithin(scope,
  1531.       'a[onclick*="replaceText"] > span.bt-topic-icon[data-bt-replacement="1"]'
  1532.     ).forEach(span => span.remove());
  1533.  
  1534.     const imgs = queryAllWithin(scope,
  1535.       'img[src*="/topic/"], img[src*="/post/"], img[src*="/Post/"], ' +
  1536.       'img[src*="normal_post"], img[src*="hot_post"], img[src*="veryhot_post"], ' +
  1537.       'img[src*="locked_post"], img[src*="lock_post"], img[src*="sticky_post"], img[src*="sticky_locked"], ' +
  1538.       'img[src*="lock"], img[src*="locked"], img[src*="sticky"], img[src*="pin"], img[src*="pinned"], ' +
  1539.       'img[src*="new"], img[src*="unread"], img[alt*="New"], img[title*="New"], img[alt*="new"], img[title*="new"], ' +
  1540.       'img[alt*="Sticky"], img[title*="Sticky"], img[alt*="Pinned"], img[title*="Pinned"], ' +
  1541.       'img[alt*="Locked"], img[title*="Locked"], img[alt*="Lock"], img[title*="Lock"], ' +
  1542.       'img[src*="normal_poll"], img[src*="hot_poll"], img[src*="veryhot_poll"], ' +
  1543.       'img[src*="locked_poll"], img[src*="sticky_poll"], ' +
  1544.       'img[src*="moved"], img[src*="redirect"], ' +
  1545.       'img[src*="exclam"], img[src*="exclamation"], img[src*="question"], ' +
  1546.       'img[src*="lamp"], img[src*="idea"], img[src*="thumbup"], img[src*="thumbdown"], ' +
  1547.       'img[src*="thumb_up"], img[src*="thumb_down"], img[src*="standard"], img[src*="xx.gif"], ' +
  1548.       'img[src*="smiley"], img[src*="happy"], img[src*="angry"]'
  1549.     );
  1550.  
  1551.     imgs.forEach(img => {
  1552.       if (img.dataset.btTopicIcon === '1' || img.dataset.btReplaced === '1') return;
  1553.  
  1554.       // v2.10.17: critical exclusion. modernizeTopicListIcons must never touch
  1555.       // smiley images that live inside the compose smiley panel — those are
  1556.       // owned by modernizeSmileys, which renders them as native emoji. The
  1557.       // old selector matched smiley.gif/happy.gif/angry.gif anywhere on the
  1558.       // page and inserted outline SVG spans on top of the emoji spans,
  1559.       // producing two visually inconsistent smiley layers in the same <a>.
  1560.       // Detection: the smiley panel uses <a onclick="replaceText(...)"> and
  1561.       // sits inside the post form (#postmodify / form[name=postmodify]).
  1562.       const inComposeSmileyPanel =
  1563.         img.closest('a[onclick*="replaceText"]') ||
  1564.         img.dataset.btSmiley === '1' ||
  1565.         (img.closest('form[name="postmodify"], #postmodify, form[action*="action=post"]') &&
  1566.          /\/Smileys\//i.test(img.getAttribute('src') || ''));
  1567.       if (inComposeSmileyPanel) return;
  1568.  
  1569.       // v2.10.15: Inline LOCK and NEW are handled by replacing the IMG src
  1570.       // with a modern SVG data-URL. The IMG keeps its native SMF position
  1571.       // (align="right" for lock, inside <a href="...new"> for new) so the
  1572.       // browser does the layout for us. No synthetic span, no display:none.
  1573.       // v2.10.16: STICKY pushpin added with the same approach.
  1574.       if (isInlineStickyImage(img)) {
  1575.         applyInlineIconSrc(img, INLINE_STICKY_DATAURL);
  1576.         img.dataset.btTopicIcon = '1';
  1577.         img.dataset.btTopicType = 'sticky';
  1578.         img.classList.add('bt-inline-status-img', 'bt-inline-status-img--sticky');
  1579.         markSpecialTopicRow(img, 'sticky');
  1580.         return;
  1581.       }
  1582.       if (isInlineLockImage(img)) {
  1583.         applyInlineIconSrc(img, INLINE_LOCK_DATAURL);
  1584.         img.dataset.btTopicIcon = '1';
  1585.         img.dataset.btTopicType = 'locked';
  1586.         img.classList.add('bt-inline-status-img', 'bt-inline-status-img--locked');
  1587.         markSpecialTopicRow(img, 'locked');
  1588.         return;
  1589.       }
  1590.       if (isInlineNewImage(img)) {
  1591.         applyInlineIconSrc(img, INLINE_NEW_DATAURL);
  1592.         img.dataset.btTopicIcon = '1';
  1593.         img.dataset.btTopicType = 'newPost';
  1594.         img.classList.add('bt-inline-status-img', 'bt-inline-status-img--newPost');
  1595.         return;
  1596.       }
  1597.  
  1598.       const { name, hay } = topicIconHaystack(img);
  1599.       const compoundSticky = isCompoundStickyTopicIconName(name, hay);
  1600.       const compoundLocked = isCompoundLockedTopicIconName(name, hay) || /sticky[_-]?locked/.test(name + ' ' + hay);
  1601.  
  1602.       // Compound folder/status images live in the first column, so resolve
  1603.       // the actual subject cell through its topic link before applying tints.
  1604.       if (compoundLocked) markSpecialTopicRow(img, 'locked');
  1605.       if (compoundSticky) markSpecialTopicRow(img, 'sticky');
  1606.  
  1607.       // Compound SMF icons such as sticky_locked.gif are left-column state
  1608.       // icons (folder + pin overlay). v2.10.15 follows the classic layout:
  1609.       // sticky/locked compounds render only as the modernised left-column
  1610.       // folder icon, with no extra inline marker beside the title. The lone
  1611.       // quick_lock.gif is the only inline status indicator (handled above).
  1612.  
  1613.       const type = topicIconTypeForImage(img);
  1614.       if (!type) return;
  1615.  
  1616.       // If a standalone status image did not match one of the safe in-place
  1617.       // replacements above, retain the native image. Hiding it here would
  1618.       // leave no visual control at all because these types deliberately do
  1619.       // not receive a synthetic span in the left state column.
  1620.       if (type === 'sticky' || type === 'locked' || type === 'newPost') {
  1621.         img.dataset.btTopicIcon = '1';
  1622.         return;
  1623.       }
  1624.  
  1625.       const svg = TOPIC_ICON_SVGS[type];
  1626.       if (!svg) return;
  1627.  
  1628.       img.dataset.btTopicIcon = '1';
  1629.       img.dataset.btReplaced = '1';
  1630.       if (!Object.prototype.hasOwnProperty.call(img.dataset, 'btOriginalStyle')) {
  1631.         img.dataset.btOriginalStyle = img.getAttribute('style') || '';
  1632.       }
  1633.       img.style.setProperty('display', 'none', 'important');
  1634.  
  1635.       const span = document.createElement('span');
  1636.       span.className = `bt-topic-icon bt-topic-icon--${type}`;
  1637.       span.dataset.btReplacement = '1';
  1638.       span.dataset.btTopicType = type;
  1639.       span.title = img.alt || img.title || type;
  1640.       span.setAttribute('role', 'img');
  1641.       span.setAttribute('aria-label', span.title);
  1642.       span.innerHTML = svg;
  1643.       const iconSvg = span.querySelector('svg');
  1644.       if (iconSvg) {
  1645.         iconSvg.setAttribute('aria-hidden', 'true');
  1646.         iconSvg.setAttribute('focusable', 'false');
  1647.       }
  1648.  
  1649.       if (img.parentNode) {
  1650.         img.parentNode.insertBefore(span, img);
  1651.       }
  1652.     });
  1653.  
  1654.     if (!isThemeActiveNow()) setModernizedControlsActive(false, scope);
  1655.   }
  1656.  
  1657.   function configureImageProxyAccessibility(proxy, image, label) {
  1658.     const interactiveParent = image.closest('a[href], button');
  1659.     if (interactiveParent) {
  1660.       proxy.setAttribute('aria-hidden', 'true');
  1661.       proxy.removeAttribute('aria-label');
  1662.       if (
  1663.         !interactiveParent.hasAttribute('aria-label') &&
  1664.         !(interactiveParent.textContent || '').trim()
  1665.       ) {
  1666.         interactiveParent.setAttribute('aria-label', label);
  1667.       }
  1668.       return;
  1669.     }
  1670.  
  1671.     proxy.setAttribute('role', 'button');
  1672.     proxy.setAttribute('tabindex', '0');
  1673.     proxy.setAttribute('aria-label', label);
  1674.     proxy.addEventListener('keydown', (event) => {
  1675.       if (event.key !== 'Enter' && event.key !== ' ') return;
  1676.       event.preventDefault();
  1677.       proxy.click();
  1678.     });
  1679.   }
  1680.  
  1681.   function modernizeBBCodeIcons(scope = document) {
  1682.     const imgs = queryAllWithin(scope,
  1683.       '#bbcBox_message img, .bbc_buttons img, [id^="bbc_"] img, ' +
  1684.       'img[src*="/bbc/"], img[src*="bbc_"], ' +
  1685.       'img[src*="/frostee/"], img[src*="frostee_"], ' +
  1686.       'img.reply_button, img.remove_button, img.modify_button, ' +
  1687.       'img[class$="_button"]'
  1688.     );
  1689.     imgs.forEach(img => {
  1690.       if (img.dataset.btReplaced === '1') return;
  1691.       const src = img.getAttribute('src') || '';
  1692.       const m = src.match(/\/(\w+)\.(?:gif|png)/i);
  1693.       const name = m ? m[1].toLowerCase().replace(/^(bbc|frostee|theme)_/, '') : '';
  1694.  
  1695.       const isPostAction = /\/frostee\//i.test(src) ||
  1696.                            img.classList.contains('reply_button') ||
  1697.                            img.classList.contains('modify_button') ||
  1698.                            img.classList.contains('remove_button');
  1699.       if (isPostAction) {
  1700.         const POST_ACTION_LABELS = {
  1701.           quote: 'Quote',
  1702.           edit: 'Edit',
  1703.           modify: 'Edit',
  1704.           delete: 'Delete',
  1705.           remove: 'Delete',
  1706.         };
  1707.         const label = POST_ACTION_LABELS[name];
  1708.         if (label) {
  1709.           const span = document.createElement('span');
  1710.           span.className = 'bt-post-action';
  1711.           span.dataset.btReplacement = '1';
  1712.           span.title = img.alt || img.title || label;
  1713.           span.textContent = label;
  1714.           configureImageProxyAccessibility(span, img, span.title);
  1715.           span.addEventListener('click', (e) => {
  1716.             e.preventDefault();
  1717.             e.stopPropagation();
  1718.             img.click();
  1719.           });
  1720.           img.dataset.btReplaced = '1';
  1721.           if (!Object.prototype.hasOwnProperty.call(img.dataset, 'btOriginalStyle')) {
  1722.             img.dataset.btOriginalStyle = img.getAttribute('style') || '';
  1723.           }
  1724.           img.style.setProperty('display', 'none', 'important');
  1725.           img.parentNode.insertBefore(span, img);
  1726.           return;
  1727.         }
  1728.       }
  1729.  
  1730.       const svg = BBCODE_SVGS[name];
  1731.       if (!svg) return;
  1732.  
  1733.       const span = document.createElement('span');
  1734.       span.className = 'bt-bbc-icon';
  1735.       span.title = img.alt || img.title || name;
  1736.       configureImageProxyAccessibility(span, img, span.title);
  1737.       span.innerHTML = svg;
  1738.       const iconSvg = span.querySelector('svg');
  1739.       if (iconSvg) {
  1740.         iconSvg.setAttribute('aria-hidden', 'true');
  1741.         iconSvg.setAttribute('focusable', 'false');
  1742.       }
  1743.       span.addEventListener('click', (e) => {
  1744.         e.preventDefault();
  1745.         e.stopPropagation();
  1746.         img.click();
  1747.       });
  1748.  
  1749.       img.dataset.btReplaced = '1';
  1750.       if (!Object.prototype.hasOwnProperty.call(img.dataset, 'btOriginalStyle')) {
  1751.         img.dataset.btOriginalStyle = img.getAttribute('style') || '';
  1752.       }
  1753.       img.style.setProperty('display', 'none', 'important');
  1754.       img.parentNode.insertBefore(span, img);
  1755.     });
  1756.     if (!isThemeActiveNow()) setModernizedControlsActive(false, scope);
  1757.   }
  1758.   // ===========================================================================
  1759.   // New-PM highlight (client-side port of PowerGlove's SMF patch)
  1760.   // ===========================================================================
  1761.   //
  1762.   // PowerGlove's original patch is server-side (SMF Themes/default/index.template.php):
  1763.   // when $context['user']['unread_messages'] > 0 it renders a small indicator
  1764.   // next to the "Messages" maintab. We cannot touch bitcointalk's PHP, so we
  1765.   // reproduce it in the DOM. SMF already prints the unread count inside the PM
  1766.   // link as "[<strong>N</strong>]", so we read it and flag the tab; the
  1767.   // stylesheet then lights it up with a pulsing accent dot.
  1768.  
  1769.   const PM_LINK_SELECTOR =
  1770.     '[class*="maintab_"] a[href*="action=pm"], ' +
  1771.     '#main_menu a[href*="action=pm"], ' +
  1772.     '.dropmenu a[href*="action=pm"]';
  1773.  
  1774.   function pmUnreadCount(link) {
  1775.     // Preferred signal: the bold count SMF renders for unread PMs.
  1776.     const strong = link.querySelector('strong');
  1777.     if (strong) {
  1778.       const n = parseInt((strong.textContent || '').replace(/\D+/g, ''), 10);
  1779.       if (n > 0) return n;
  1780.     }
  1781.     // Fallback: a bracketed number anywhere in the link text, e.g. "[3]".
  1782.     const m = (link.textContent || '').match(/\[\s*(\d+)\s*\]/);
  1783.     if (m) {
  1784.       const n = parseInt(m[1], 10);
  1785.       if (n > 0) return n;
  1786.     }
  1787.     return 0;
  1788.   }
  1789.  
  1790.   function highlightUnreadPm(scope = document) {
  1791.     let links;
  1792.     try {
  1793.       links = queryAllWithin(scope, PM_LINK_SELECTOR);
  1794.     } catch (e) {
  1795.       return;
  1796.     }
  1797.     links.forEach((link) => {
  1798.       const count = pmUnreadCount(link);
  1799.       const tab = link.closest('td[class*="maintab_"], li') || link;
  1800.       if (count > 0) {
  1801.         link.classList.add('bt-pm-unread');
  1802.         tab.classList.add('bt-pm-unread-tab');
  1803.         link.setAttribute('data-bt-pm-count', String(count));
  1804.       } else {
  1805.         link.classList.remove('bt-pm-unread');
  1806.         tab.classList.remove('bt-pm-unread-tab');
  1807.         link.removeAttribute('data-bt-pm-count');
  1808.       }
  1809.     });
  1810.   }
  1811.   // ===========================================================================
  1812.   // Smiley modernisation
  1813.   // ===========================================================================
  1814.  
  1815.   const SMILEY_ALIASES = {
  1816.     happy: 'smiley', cheesy: 'grin', grin: 'grin', lol: 'laugh', laugh: 'laugh',
  1817.     cry: 'sad', mad: 'angry', surprised: 'shocked', huh: 'confused', undecided: 'confused',
  1818.     sunglasses: 'cool', embarrassed: 'confused', lipsrsealed: 'confused', kiss: 'smiley',
  1819.     rolleyes: 'confused', evil: 'angry', azn: 'cool', afro: 'cool', police: 'cool',
  1820.     wassat: 'confused', chocked: 'shocked', skeptical: 'confused', facepalm: 'sad',
  1821.     thumbup: 'thumbsup', thumbs_up: 'thumbsup', thumbdown: 'thumbsdown', thumbs_down: 'thumbsdown',
  1822.     tick: 'check',
  1823.     // v2.10.16: SMF Bitcointalk serves the default-smile button as smile.gif
  1824.     // (not smiley.gif), so without this alias it slipped through and stayed
  1825.     // as the original GIF while every other glyph rendered as an emoji.
  1826.     smile: 'smiley'
  1827.   };
  1828.  
  1829.   // Keep this map ASCII-only. Bitcointalk can expose a legacy page encoding,
  1830.   // which would turn literal UTF-8 emoji in the userscript into mojibake.
  1831.   // JavaScript decodes these Unicode escapes only after the script is loaded.
  1832.   const SMILEY_EMOJI = {
  1833.     smiley: '\u{1F60A}', wink: '\u{1F609}', grin: '\u{1F600}',
  1834.     laugh: '\u{1F604}', sad: '\u{1F61E}', angry: '\u{1F62C}',
  1835.     shocked: '\u{1F62E}', cool: '\u{1F60E}', confused: '\u{1F615}',
  1836.     tongue: '\u{1F61B}', heart: '\u2764\uFE0F',
  1837.     thumbsup: '\u{1F44D}', thumbsdown: '\u{1F44E}', star: '\u2B50',
  1838.     fire: '\u{1F525}', check: '\u2705', cross: '\u274C'
  1839.   };
  1840.  
  1841.   function smileyGlyphForName(name) {
  1842.     const key = SMILEY_EMOJI[name] ? name : SMILEY_ALIASES[name];
  1843.     return key ? SMILEY_EMOJI[key] : null;
  1844.   }
  1845.  
  1846.   function stylePostMetaButtons(scope = document) {
  1847.     queryAllWithin(scope, 'a').forEach(a => {
  1848.       if (a.dataset.btPostMeta === '1') return;
  1849.       const text = (a.textContent || '').trim();
  1850.       const href = a.getAttribute('href') || '';
  1851.       const isMerit = /^\+\s*merit\b/i.test(text);
  1852.       const isMsgNum = /^#\d+$/.test(text) &&
  1853.         /(topic=|#msg|action=display|action=profile)/i.test(href);
  1854.       if (isMerit || isMsgNum) {
  1855.         a.classList.add('bt-post-action');
  1856.         a.dataset.btPostMeta = '1';
  1857.       }
  1858.     });
  1859.   }
  1860.  
  1861.   function modernizeSmileys(scope = document) {
  1862.     const imgs = queryAllWithin(scope,
  1863.       'img[src*="Smileys/"], img[src*="/smileys/"], img.smiley'
  1864.     );
  1865.     imgs.forEach(img => {
  1866.       if (img.dataset.btSmiley === '1') return;
  1867.       const src = img.getAttribute('src') || '';
  1868.       if (!/(Smileys|smileys|smiley)/i.test(src) && !img.classList.contains('smiley')) return;
  1869.       const m = src.match(/\/(\w+)\.(?:gif|png|jpg)/i);
  1870.       const name = m ? m[1].toLowerCase() : '';
  1871.       const glyph = smileyGlyphForName(name);
  1872.       if (!glyph) return;
  1873.  
  1874.       const span = document.createElement('span');
  1875.       span.className = 'bt-smiley bt-smiley-modern bt-smiley-native';
  1876.       span.textContent = glyph;
  1877.       span.title = img.alt || img.title || name;
  1878.  
  1879.       img.dataset.btSmiley = '1';
  1880.       if (!Object.prototype.hasOwnProperty.call(img.dataset, 'btOriginalStyle')) {
  1881.         img.dataset.btOriginalStyle = img.getAttribute('style') || '';
  1882.       }
  1883.       img.style.setProperty('display', 'none', 'important');
  1884.       img.parentNode.insertBefore(span, img);
  1885.     });
  1886.     if (!isThemeActiveNow()) setModernizedControlsActive(false, scope);
  1887.   }
  1888.  
  1889.   // ===========================================================================
  1890.   // CSS
  1891.   // ===========================================================================
  1892.   const css = `
  1893.     :root[data-bt-theme="dark"] {
  1894.       --bt-bg: #1A1D21;
  1895.       --bt-surface-1: #22262B;
  1896.       --bt-surface-2: #2A2F35;
  1897.       --bt-surface-3: #343A41;
  1898.       --bt-border: rgba(255,255,255,0.07);
  1899.       --bt-border-2: rgba(255,255,255,0.14);
  1900.       --bt-text: #E3E3E8;
  1901.       --bt-text-2: #A8B0BA;
  1902.       --bt-text-3: #6B7480;
  1903.       --bt-input-bg: #14171B;
  1904.       --bt-quote-bg: #1F2328;
  1905.       --bt-code-bg: #14171B;
  1906.       --bt-bg-end: #17191D;
  1907.       --bt-icon-filter: invert(1) opacity(0.75);
  1908.       --bt-shadow: 0 1px 0 rgba(0,0,0,0.2);
  1909.       --bt-shadow-lg: 0 12px 32px rgba(0,0,0,0.35);
  1910.     }
  1911.     :root[data-bt-theme="light"] {
  1912.       --bt-bg: #F2F4F7;
  1913.       --bt-surface-1: #E3E6EA;
  1914.       --bt-surface-2: #D7DAE0;
  1915.       --bt-surface-3: #C5C8CD;
  1916.       --bt-post-bg: #EEF3F7;
  1917.       --bt-post-alt-bg: #E3EBF1;
  1918.       --bt-poster-bg: #E8EEF3;
  1919.       --bt-poster-alt-bg: #DCE7EE;
  1920.       --bt-border: rgba(0,0,0,0.08);
  1921.       --bt-border-2: rgba(0,0,0,0.16);
  1922.       --bt-text: #1A1D21;
  1923.       --bt-text-2: #4A5058;
  1924.       --bt-text-3: #7A8088;
  1925.       --bt-input-bg: #FFFFFF;
  1926.       --bt-quote-bg: #E1E4E8;
  1927.       --bt-code-bg: #DBDEE3;
  1928.       --bt-bg-end: #E9ECEF;
  1929.       --bt-icon-filter: opacity(0.7);
  1930.       --bt-shadow: 0 1px 0 rgba(0,0,0,0.04);
  1931.       --bt-shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
  1932.     }
  1933.     :root {
  1934.       --bt-radius: 10px;
  1935.       --bt-radius-sm: 6px;
  1936.       --bt-radius-lg: 14px;
  1937.       --bt-font: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  1938.       --bt-mono: 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
  1939.       --bt-trans: 150ms ease;
  1940.       --bt-danger: #EF4444;
  1941.       --bt-accent: #F7931A;
  1942.       --bt-accent-h: #FFA733;
  1943.       --bt-accent-a: #E08410;
  1944.       --bt-on-accent: #1A1D21;
  1945.     }
  1946.  
  1947.     /*-- BT_ALWAYS_ON_START --*/
  1948.     :root[data-bt-active="false"] .bt-bbc-icon,
  1949.     :root[data-bt-active="false"] .bt-smiley,
  1950.     :root[data-bt-active="false"] .bt-topic-icon[data-bt-replacement="1"],
  1951.     :root[data-bt-active="false"] .bt-post-action[data-bt-replacement="1"] {
  1952.       display: none !important;
  1953.     }
  1954.     [data-bt-no-transitions] *,
  1955.     [data-bt-no-transitions] *::before,
  1956.     [data-bt-no-transitions] *::after {
  1957.       transition: none !important;
  1958.       animation-duration: 0s !important;
  1959.     }
  1960.     /*-- BT_ALWAYS_ON_END --*/
  1961.  
  1962.     html,
  1963.     body {
  1964.       background: var(--bt-bg) !important;
  1965.       color: var(--bt-text) !important;
  1966.       font-family: var(--bt-font) !important;
  1967.       font-size: 12px !important;
  1968.       -webkit-font-smoothing: antialiased;
  1969.       text-rendering: optimizeLegibility;
  1970.     }
  1971.  
  1972.     body {
  1973.       background:
  1974.         radial-gradient(140% 100% at 15% -10%, color-mix(in srgb, var(--bt-accent) 6%, transparent) 0%, transparent 55%),
  1975.         radial-gradient(120% 100% at 90% -5%,  color-mix(in srgb, var(--bt-accent) 3%, transparent) 0%, transparent 60%),
  1976.         linear-gradient(180deg, var(--bt-bg) 0%, var(--bt-bg-end) 100%) !important;
  1977.       background-attachment: fixed !important;
  1978.     }
  1979.  
  1980.     body, td, th, tr { color: var(--bt-text) !important; }
  1981.     h1, h2, h3, h4, h5, h6 {
  1982.       color: var(--bt-text) !important;
  1983.       font-weight: 600 !important;
  1984.       letter-spacing: -0.005em;
  1985.     }
  1986.  
  1987.     a, a:link, a:visited {
  1988.       color: var(--bt-accent) !important;
  1989.       text-decoration: none !important;
  1990.       transition: color var(--bt-trans) !important;
  1991.     }
  1992.     a:hover, a:active, a:focus {
  1993.       color: var(--bt-accent-h) !important;
  1994.       text-decoration: none !important;
  1995.     }
  1996.  
  1997.     #upper_section, #header, #wrapper, #content_section, #main_content_section,
  1998.     #footer_section, .frame, #bodyarea, .navigate_section, .roundframe,
  1999.     #content {
  2000.       background: transparent !important;
  2001.       color: var(--bt-text) !important;
  2002.     }
  2003.  
  2004.     table.bordercolor,
  2005.     table.table_list,
  2006.     table.table_grid,
  2007.     .tborder {
  2008.       background: var(--bt-surface-1) !important;
  2009.       border: 1px solid var(--bt-border-2) !important;
  2010.       border-radius: var(--bt-radius) !important;
  2011.       overflow: hidden !important;
  2012.       border-spacing: 0 !important;
  2013.       box-shadow: var(--bt-shadow);
  2014.     }
  2015.  
  2016.     /* Neutralize unclassed SMF grid cells and every sprite-based corner. */
  2017.     :root[data-bt-active="true"][data-bt-theme] body table.bordercolor > tbody > tr > td,
  2018.     :root[data-bt-active="true"][data-bt-theme] body table.table_list > tbody > tr > td,
  2019.     :root[data-bt-active="true"][data-bt-theme] body table.table_grid > tbody > tr > td,
  2020.     :root[data-bt-active="true"][data-bt-theme] body table.tborder > tbody > tr > td,
  2021.     :root[data-bt-active="true"][data-bt-theme] body .tborder > tbody > tr > td {
  2022.       background-color: var(--bt-surface-1) !important;
  2023.       background-image: none !important;
  2024.       border-color: var(--bt-border) !important;
  2025.     }
  2026.     :root[data-bt-active="true"][data-bt-theme] body table.bordercolor td[bgcolor],
  2027.     :root[data-bt-active="true"][data-bt-theme] body table.bordercolor td[background],
  2028.     :root[data-bt-active="true"][data-bt-theme] body .tborder td[bgcolor],
  2029.     :root[data-bt-active="true"][data-bt-theme] body .tborder td[background],
  2030.     :root[data-bt-active="true"][data-bt-theme] body td[class*="windowbg"] td[bgcolor],
  2031.     :root[data-bt-active="true"][data-bt-theme] body td[class*="windowbg"] td[background] {
  2032.       background-color: var(--bt-surface-1) !important;
  2033.       background-image: none !important;
  2034.     }
  2035.     :root[data-bt-active="true"][data-bt-theme] body .topslice,
  2036.     :root[data-bt-active="true"][data-bt-theme] body .botslice,
  2037.     :root[data-bt-active="true"][data-bt-theme] body .upperframe,
  2038.     :root[data-bt-active="true"][data-bt-theme] body .lowerframe {
  2039.       display: none !important;
  2040.       width: 0 !important;
  2041.       height: 0 !important;
  2042.       min-height: 0 !important;
  2043.       margin: 0 !important;
  2044.       padding: 0 !important;
  2045.       border: 0 !important;
  2046.       background: none !important;
  2047.     }
  2048.     :root[data-bt-active="true"][data-bt-theme] body .topslice > *,
  2049.     :root[data-bt-active="true"][data-bt-theme] body .botslice > *,
  2050.     :root[data-bt-active="true"][data-bt-theme] body .upperframe > *,
  2051.     :root[data-bt-active="true"][data-bt-theme] body .lowerframe > * {
  2052.       display: none !important;
  2053.       width: 0 !important;
  2054.       height: 0 !important;
  2055.       margin: 0 !important;
  2056.       padding: 0 !important;
  2057.       border: 0 !important;
  2058.       background: none !important;
  2059.       background-image: none !important;
  2060.     }
  2061.     :root[data-bt-active="true"][data-bt-theme] body .cat_bar,
  2062.     :root[data-bt-active="true"][data-bt-theme] body .title_bar,
  2063.     :root[data-bt-active="true"][data-bt-theme] body .title_barIC,
  2064.     :root[data-bt-active="true"][data-bt-theme] body .sub_bar {
  2065.       padding-left: 0 !important;
  2066.       padding-right: 0 !important;
  2067.       background: none !important;
  2068.       border-radius: var(--bt-radius-sm) !important;
  2069.       overflow: hidden !important;
  2070.     }
  2071.     :root[data-bt-active="true"][data-bt-theme] body .cat_bar > [class*="catbg"],
  2072.     :root[data-bt-active="true"][data-bt-theme] body .title_bar > [class*="titlebg"],
  2073.     :root[data-bt-active="true"][data-bt-theme] body .title_barIC > [class*="titlebg"],
  2074.     :root[data-bt-active="true"][data-bt-theme] body .sub_bar > [class*="titlebg"],
  2075.     :root[data-bt-active="true"][data-bt-theme] body div.windowbg,
  2076.     :root[data-bt-active="true"][data-bt-theme] body div.windowbg2,
  2077.     :root[data-bt-active="true"][data-bt-theme] body div.windowbg3 {
  2078.       border-radius: var(--bt-radius-sm) !important;
  2079.       overflow: hidden !important;
  2080.     }
  2081.  
  2082.     [class*="windowbg"],
  2083.     td[class*="windowbg"],
  2084.     tr[class*="windowbg"] > td {
  2085.       background-color: var(--bt-surface-1) !important;
  2086.       background-image: none !important;
  2087.       color: var(--bt-text) !important;
  2088.       border-color: var(--bt-border) !important;
  2089.       border-bottom: 1px solid var(--bt-border) !important;
  2090.     }
  2091.  
  2092.     /* Trust feedback marks negative comments with an inline color:red on
  2093.        the windowbg cell. Preserve that native warning in every theme instead
  2094.        of letting the generic table text reset above make it neutral. */
  2095.     #bodyarea td.windowbg[style*="color:red"],
  2096.     #bodyarea td.windowbg[style*="color: red"] {
  2097.       color: red !important;
  2098.     }
  2099.  
  2100.     tr.windowbg:hover > td,
  2101.     tr.windowbg2:hover > td,
  2102.     tr.windowbg3:hover > td {
  2103.       background-color: var(--bt-surface-2) !important;
  2104.     }
  2105.  
  2106.     /* v2.8.1: restore the classic-looking post alternation on light-theme
  2107.        thread pages. The previous attempt only caught a narrow header row on
  2108.        some thread layouts (the "Report to moderator" strip), because the
  2109.        actual post body/sidebar wrappers are often .td_headerandpost, .post,
  2110.        .poster and .poster_info rather than the row cell that carries
  2111.        windowbg/windowbg2 itself.
  2112.  
  2113.        We therefore paint BOTH the row cells and the common wrappers inside
  2114.        them, so the entire post block alternates again like classic
  2115.        bitcointalk/SMF. */
  2116.     :root[data-bt-theme="light"] tr.windowbg > td,
  2117.     :root[data-bt-theme="light"] td.windowbg,
  2118.     :root[data-bt-theme="light"] tr.windowbg td.td_headerandpost,
  2119.     :root[data-bt-theme="light"] td.windowbg.td_headerandpost,
  2120.     :root[data-bt-theme="light"] tr.windowbg td.post,
  2121.     :root[data-bt-theme="light"] td.windowbg.post,
  2122.     :root[data-bt-theme="light"] tr.windowbg td.poster,
  2123.     :root[data-bt-theme="light"] tr.windowbg td.poster_info,
  2124.     :root[data-bt-theme="light"] td.windowbg.poster,
  2125.     :root[data-bt-theme="light"] td.windowbg.poster_info {
  2126.       background-color: #e9f0f7 !important;
  2127.       background-image: none !important;
  2128.     }
  2129.  
  2130.     :root[data-bt-theme="light"] tr.windowbg2 > td,
  2131.     :root[data-bt-theme="light"] td.windowbg2,
  2132.     :root[data-bt-theme="light"] tr.windowbg2 td.td_headerandpost,
  2133.     :root[data-bt-theme="light"] td.windowbg2.td_headerandpost,
  2134.     :root[data-bt-theme="light"] tr.windowbg2 td.post,
  2135.     :root[data-bt-theme="light"] td.windowbg2.post,
  2136.     :root[data-bt-theme="light"] tr.windowbg2 td.poster,
  2137.     :root[data-bt-theme="light"] tr.windowbg2 td.poster_info,
  2138.     :root[data-bt-theme="light"] td.windowbg2.poster,
  2139.     :root[data-bt-theme="light"] td.windowbg2.poster_info {
  2140.       background-color: #dfe9f3 !important;
  2141.       background-image: none !important;
  2142.     }
  2143.  
  2144.     :root[data-bt-theme="light"] tr.windowbg3 > td,
  2145.     :root[data-bt-theme="light"] td.windowbg3,
  2146.     :root[data-bt-theme="light"] tr.windowbg3 td.td_headerandpost,
  2147.     :root[data-bt-theme="light"] td.windowbg3.td_headerandpost,
  2148.     :root[data-bt-theme="light"] tr.windowbg3 td.post,
  2149.     :root[data-bt-theme="light"] td.windowbg3.post,
  2150.     :root[data-bt-theme="light"] tr.windowbg3 td.poster,
  2151.     :root[data-bt-theme="light"] tr.windowbg3 td.poster_info,
  2152.     :root[data-bt-theme="light"] td.windowbg3.poster,
  2153.     :root[data-bt-theme="light"] td.windowbg3.poster_info {
  2154.       background-color: #e9f0f7 !important;
  2155.       background-image: none !important;
  2156.     }
  2157.  
  2158.     :root[data-bt-theme="light"] tr.windowbg:hover > td,
  2159.     :root[data-bt-theme="light"] tr.windowbg:hover td.td_headerandpost,
  2160.     :root[data-bt-theme="light"] tr.windowbg:hover td.post,
  2161.     :root[data-bt-theme="light"] tr.windowbg:hover td.poster,
  2162.     :root[data-bt-theme="light"] tr.windowbg:hover td.poster_info,
  2163.     :root[data-bt-theme="light"] tr.windowbg2:hover > td,
  2164.     :root[data-bt-theme="light"] tr.windowbg2:hover td.td_headerandpost,
  2165.     :root[data-bt-theme="light"] tr.windowbg2:hover td.post,
  2166.     :root[data-bt-theme="light"] tr.windowbg2:hover td.poster,
  2167.     :root[data-bt-theme="light"] tr.windowbg2:hover td.poster_info,
  2168.     :root[data-bt-theme="light"] tr.windowbg3:hover > td,
  2169.     :root[data-bt-theme="light"] tr.windowbg3:hover td.td_headerandpost,
  2170.     :root[data-bt-theme="light"] tr.windowbg3:hover td.post,
  2171.     :root[data-bt-theme="light"] tr.windowbg3:hover td.poster,
  2172.     :root[data-bt-theme="light"] tr.windowbg3:hover td.poster_info {
  2173.       background-color: #d7e3ef !important;
  2174.       background-image: none !important;
  2175.     }
  2176.  
  2177.     :root[data-bt-active="true"] td.bt-read-post {
  2178.       position: relative !important;
  2179.     }
  2180.     :root[data-bt-active="true"] td.bt-read-post::after {
  2181.       content: "";
  2182.       position: absolute;
  2183.       inset: 0;
  2184.       z-index: 30;
  2185.       pointer-events: none;
  2186.       background: rgba(128, 128, 128, 0.22);
  2187.       backdrop-filter: grayscale(0.75) saturate(0.5);
  2188.       -webkit-backdrop-filter: grayscale(0.75) saturate(0.5);
  2189.     }
  2190.     :root[data-bt-active="true"][data-bt-theme="dark"] td.bt-read-post::after {
  2191.       background: rgba(170, 170, 170, 0.12);
  2192.     }
  2193.  
  2194.     .poster, td.poster, .poster_info, td.poster_info, [id*="poster"] {
  2195.       background-color: var(--bt-surface-1) !important;
  2196.       background-image: none !important;
  2197.       color: var(--bt-text) !important;
  2198.     }
  2199.     :root[data-bt-theme="dark"] td.poster_info *,
  2200.     :root[data-bt-theme="dark"] td.poster *,
  2201.     :root[data-bt-theme="dark"] .poster_info * {
  2202.       color: var(--bt-text-2) !important;
  2203.     }
  2204.     :root[data-bt-theme="dark"] td.poster_info b a,
  2205.     :root[data-bt-theme="dark"] td.poster_info h4 a,
  2206.     :root[data-bt-theme="dark"] .poster_info b a,
  2207.     :root[data-bt-theme="dark"] .poster_info h4 a {
  2208.       color: var(--bt-text) !important;
  2209.       font-weight: 600 !important;
  2210.     }
  2211.     :root[data-bt-theme="dark"] td.poster_info b a:hover,
  2212.     :root[data-bt-theme="dark"] td.poster_info h4 a:hover,
  2213.     :root[data-bt-theme="dark"] .poster_info b a:hover,
  2214.     :root[data-bt-theme="dark"] .poster_info h4 a:hover {
  2215.       color: var(--bt-accent) !important;
  2216.     }
  2217.     :root[data-bt-theme="dark"] td.poster_info a,
  2218.     :root[data-bt-theme="dark"] .poster_info a {
  2219.       color: var(--bt-accent) !important;
  2220.     }
  2221.     :root[data-bt-theme="dark"] td.poster_info a:hover,
  2222.     :root[data-bt-theme="dark"] .poster_info a:hover {
  2223.       color: var(--bt-accent-h) !important;
  2224.     }
  2225.     :root[data-bt-theme="dark"] td.poster_info img,
  2226.     :root[data-bt-theme="dark"] .poster_info img { color: initial !important; }
  2227.  
  2228.     table.bordercolor tr[style] > td,
  2229.     table.bordercolor td[style],
  2230.     .tborder tr[style] > td,
  2231.     .tborder td[style] {
  2232.       background-color: var(--bt-surface-1) !important;
  2233.       background-image: none !important;
  2234.     }
  2235.  
  2236.     [class*="catbg"], [class*="titlebg"], td[class*="catbg"], td[class*="titlebg"],
  2237.     th[class*="catbg"], th[class*="titlebg"], tr[class*="catbg"] > td,
  2238.     tr[class*="catbg"] > th, tr[class*="catbg"] td, tr[class*="catbg"] th,
  2239.     tr[class*="titlebg"] > td, tr[class*="titlebg"] > th, tr[class*="titlebg"] td,
  2240.     tr[class*="titlebg"] th, h3[class*="catbg"], h4[class*="catbg"],
  2241.     h3[class*="titlebg"], h4[class*="titlebg"] {
  2242.       background-color: var(--bt-surface-2) !important;
  2243.       background-image: none !important;
  2244.       color: var(--bt-text) !important;
  2245.       border-bottom: 1px solid var(--bt-border-2) !important;
  2246.       font-weight: 600 !important;
  2247.       letter-spacing: 0.01em;
  2248.       text-shadow: none !important;
  2249.     }
  2250.     [class*="catbg"] a, [class*="titlebg"] a, tr[class*="catbg"] a, tr[class*="titlebg"] a {
  2251.       color: var(--bt-text) !important;
  2252.     }
  2253.     [class*="catbg"] a:hover, [class*="titlebg"] a:hover, tr[class*="catbg"] a:hover, tr[class*="titlebg"] a:hover {
  2254.       color: var(--bt-accent) !important;
  2255.     }
  2256.  
  2257.     /* v2.10.39: catbg/titlebg headers (the navy/grey banner above content
  2258.        sections) include the topic header row "Topic: ... (Read N times)"
  2259.        above each thread's posts. SMF inherits a large font-size for these
  2260.        cells from the legacy theme stylesheet, which makes the topic title
  2261.        look oversized vs the body text and the breadcrumb. Bring it back
  2262.        down to match the classic SMF Bitcointalk subject size: 13-14px,
  2263.        semibold (the bold weight is already set above). */
  2264.     body [class*="catbg"],
  2265.     body [class*="titlebg"],
  2266.     body td[class*="catbg"],
  2267.     body td[class*="titlebg"],
  2268.     body tr[class*="catbg"] > td,
  2269.     body tr[class*="titlebg"] > td,
  2270.     body [class*="catbg"] b,
  2271.     body [class*="titlebg"] b,
  2272.     body [class*="catbg"] span:not(.smalltext),
  2273.     body [class*="titlebg"] span:not(.smalltext),
  2274.     body [class*="catbg"] a,
  2275.     body [class*="titlebg"] a {
  2276.       font-size: 14px !important;
  2277.       line-height: 1.4 !important;
  2278.     }
  2279.  
  2280.     /* v3.0.35: data in alto a destra (span.smalltext dentro #smfheader td.titlebg2)
  2281.        deve rimanere a 13px — escluso dalla regola sopra tramite :not(.smalltext)
  2282.        e ribadito qui per battere qualsiasi .smalltext baseline */
  2283.     body [class*="catbg"] span.smalltext,
  2284.     body [class*="titlebg"] span.smalltext,
  2285.     #smfheader td.titlebg2 span.smalltext,
  2286.     #smfheader td.titlebg2[align="right"] span.smalltext,
  2287.     #smfheader td.titlebg2 span.smalltext * {
  2288.       font-size: 13px !important;
  2289.       line-height: normal !important;
  2290.     }
  2291.  
  2292.     /* v2.10.28: when the Classic (sky) preset is active in the light theme,
  2293.        reproduce the SMF Bitcointalk gradient look more faithfully:
  2294.         - catbg = top-level category banners → deep blue gradient with white text
  2295.         - titlebg = sub-section headers → light blue gradient with dark text
  2296.        This matches the original cascade where each header layer has its own
  2297.        distinct identity instead of both falling back to the same surface tone. */
  2298.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body [class*="catbg"],
  2299.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body td[class*="catbg"],
  2300.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body th[class*="catbg"],
  2301.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body tr[class*="catbg"] > td,
  2302.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body tr[class*="catbg"] > th {
  2303.       background: linear-gradient(180deg, #8FA8CE 0%, #6E8EBE 100%) !important;
  2304.       color: #FFFFFF !important;
  2305.       border-bottom: 1px solid #5C7AAB !important;
  2306.     }
  2307.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body [class*="catbg"] a,
  2308.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body tr[class*="catbg"] a {
  2309.       color: #FFFFFF !important;
  2310.     }
  2311.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body [class*="catbg"] a:hover,
  2312.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body tr[class*="catbg"] a:hover {
  2313.       color: #FFE08A !important;
  2314.       text-decoration: underline !important;
  2315.     }
  2316.  
  2317.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body [class*="titlebg"],
  2318.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body td[class*="titlebg"],
  2319.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body th[class*="titlebg"],
  2320.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body tr[class*="titlebg"] > td,
  2321.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body tr[class*="titlebg"] > th {
  2322.       background: linear-gradient(180deg, #DDE5F0 0%, #C2D2E5 100%) !important;
  2323.       color: #1F2A3A !important;
  2324.       border-bottom: 1px solid #A6B7CD !important;
  2325.     }
  2326.  
  2327.     /* Classic Bitcointalk uses the legendary #225588 link blue everywhere
  2328.        except inside the dark catbg banners. Reinforce that for normal body
  2329.        links so the page reads as authentically classic. */
  2330.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body td[class*="windowbg"] a:link,
  2331.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body td[class*="windowbg"] a:visited,
  2332.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body .post a:link,
  2333.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body .post a:visited {
  2334.       color: #225588 !important;
  2335.     }
  2336.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body td[class*="windowbg"] a:hover,
  2337.     :root[data-bt-theme="light"][data-bt-main="sky"][data-bt-active="true"] body .post a:hover {
  2338.       color: #1A4570 !important;
  2339.       text-decoration: underline !important;
  2340.     }
  2341.  
  2342.     th {
  2343.       background-color: var(--bt-surface-2) !important;
  2344.       background-image: none !important;
  2345.       color: var(--bt-text) !important;
  2346.     }
  2347.  
  2348.     .post, td.post, #preview_body, #preview_section, #preview_section td,
  2349.     #preview_section table, .personalmessage, td.personalmessage {
  2350.       background-color: var(--bt-surface-1) !important;
  2351.       background-image: none !important;
  2352.       color: var(--bt-text) !important;
  2353.     }
  2354.     .post { line-height: 1.6 !important; font-size: 14px !important; }
  2355.     .signature {
  2356.       color: var(--bt-text-3) !important;
  2357.       border-top: 1px solid var(--bt-border) !important;
  2358.       padding-top: 8px !important;
  2359.       margin-top: 12px !important;
  2360.       font-size: 12px !important;
  2361.     }
  2362.     .smalltext, .middletext, .small_header, .nav, a.nav, .navPages, .prevnext,
  2363.     .lastpostcol, .ignored_topic, .utusers, .utusers a {
  2364.       color: var(--bt-text-2) !important;
  2365.     }
  2366.     .smalltext a, .middletext a, .small_header a, .lastpostcol a {
  2367.       color: var(--bt-accent) !important;
  2368.     }
  2369.  
  2370.     .quoteheader, .codeheader {
  2371.       background: var(--bt-surface-3) !important;
  2372.       color: var(--bt-text-2) !important;
  2373.       border: 1px solid var(--bt-border) !important;
  2374.       border-bottom: none !important;
  2375.       border-radius: var(--bt-radius-sm) var(--bt-radius-sm) 0 0 !important;
  2376.       padding: 6px 10px !important;
  2377.       font-size: 12px !important;
  2378.       font-weight: 500 !important;
  2379.     }
  2380.     .codeheader {
  2381.       box-sizing: border-box !important;
  2382.       width: 96% !important;
  2383.       max-width: 100% !important;
  2384.     }
  2385.     .quote,
  2386.     blockquote.bbc_standard_quote,
  2387.     blockquote.bbc_alternate_quote {
  2388.       background: var(--bt-quote-bg) !important;
  2389.       background-image: none !important;
  2390.       color: var(--bt-text-2) !important;
  2391.       border: 1px solid var(--bt-border) !important;
  2392.       border-left: 3px solid var(--bt-accent) !important;
  2393.       border-radius: 0 var(--bt-radius-sm) var(--bt-radius-sm) var(--bt-radius-sm) !important;
  2394.       padding: 10px 14px !important;
  2395.       margin: 6px 0 12px !important;
  2396.       font-size: var(--bt-fs-small) !important;
  2397.       line-height: 1.4 !important;
  2398.       overflow: auto !important;
  2399.     }
  2400.     .code {
  2401.       background: var(--bt-code-bg) !important;
  2402.       color: var(--bt-text) !important;
  2403.       font-family: var(--bt-mono) !important;
  2404.       border: 1px solid var(--bt-border) !important;
  2405.       border-radius: 0 0 var(--bt-radius-sm) var(--bt-radius-sm) !important;
  2406.       padding: 10px 14px !important;
  2407.       box-sizing: border-box !important;
  2408.       width: 96% !important;
  2409.       max-width: 100% !important;
  2410.       overflow: auto !important;
  2411.     }
  2412.  
  2413.     .button_submit, .button_reset, input[type="submit"], input[type="button"],
  2414.     input[type="reset"], button:not([id^="bt-"]):not([class^="bt-sw-"]),
  2415.     .button:not([id^="bt-"]) {
  2416.       background: var(--bt-accent) !important;
  2417.       color: var(--bt-on-accent) !important;
  2418.       border: 1px solid var(--bt-accent) !important;
  2419.       border-radius: var(--bt-radius-sm) !important;
  2420.       padding: 5px 10px !important;
  2421.       font-family: var(--bt-font) !important;
  2422.       font-weight: 600 !important;
  2423.       font-size: 12px !important;
  2424.       cursor: pointer !important;
  2425.       transition: background var(--bt-trans), transform var(--bt-trans), box-shadow var(--bt-trans) !important;
  2426.       box-shadow: none !important;
  2427.       text-shadow: none !important;
  2428.     }
  2429.     .button_submit:hover, .button_reset:hover, input[type="submit"]:hover,
  2430.     input[type="button"]:hover, input[type="reset"]:hover,
  2431.     button:not([id^="bt-"]):not([class^="bt-sw-"]):hover,
  2432.     .button:not([id^="bt-"]):hover {
  2433.       background: var(--bt-accent-h) !important;
  2434.       border-color: var(--bt-accent-h) !important;
  2435.       box-shadow: 0 2px 12px color-mix(in srgb, var(--bt-accent) 30%, transparent) !important;
  2436.       transform: translateY(-1px);
  2437.       color: var(--bt-on-accent) !important;
  2438.     }
  2439.     .button_submit:active, input[type="submit"]:active {
  2440.       background: var(--bt-accent-a) !important;
  2441.       transform: translateY(0) !important;
  2442.     }
  2443.  
  2444.     a.button {
  2445.       background: transparent !important;
  2446.       color: var(--bt-text) !important;
  2447.       border: 1px solid var(--bt-border-2) !important;
  2448.     }
  2449.     a.button:hover {
  2450.       border-color: var(--bt-accent) !important;
  2451.       color: var(--bt-accent) !important;
  2452.       background: color-mix(in srgb, var(--bt-accent) 10%, transparent) !important;
  2453.       box-shadow: none !important;
  2454.       transform: none !important;
  2455.     }
  2456.  
  2457.     /* v2.10.27: topic action bar (Reply | Unwatch | Notify | Mark unread |
  2458.        Print | View topic archive) compacted vertically and horizontally so
  2459.        it occupies less of the precious top/bottom-of-thread real estate.
  2460.        Reductions: padding 3×7 → 2×6, font-size 12→11px, letter-spacing
  2461.        0.04em→0.02em, margin-right 3→2px. Results in a strip roughly 25%
  2462.        shorter without losing readability. */
  2463.     a.quotebutton, a.replybutton, a.modifybutton, a.removebutton, a.reportbutton,
  2464.     a.splitbutton, a.notifybutton, a.markreadbutton, a.unwatchbutton,
  2465.     a.printbutton, a.archivebutton {
  2466.       display: inline-block !important;
  2467.       background: transparent !important;
  2468.       color: var(--bt-text-2) !important;
  2469.       border: 1px solid var(--bt-border-2) !important;
  2470.       border-radius: var(--bt-radius-sm) !important;
  2471.       padding: 2px 6px !important;
  2472.       margin: 0 2px 0 0 !important;
  2473.       font-family: var(--bt-font) !important;
  2474.       font-weight: 500 !important;
  2475.       font-size: 11px !important;
  2476.       text-transform: uppercase !important;
  2477.       letter-spacing: 0.02em !important;
  2478.       line-height: 1.3 !important;
  2479.       text-decoration: none !important;
  2480.       box-shadow: none !important;
  2481.       text-shadow: none !important;
  2482.       transition: background var(--bt-trans), color var(--bt-trans), border-color var(--bt-trans) !important;
  2483.       cursor: pointer !important;
  2484.     }
  2485.     a.quotebutton:hover, a.replybutton:hover, a.modifybutton:hover,
  2486.     a.removebutton:hover, a.reportbutton:hover, a.splitbutton:hover,
  2487.     a.notifybutton:hover, a.markreadbutton:hover, a.unwatchbutton:hover,
  2488.     a.printbutton:hover, a.archivebutton:hover {
  2489.       background: var(--bt-accent) !important;
  2490.       color: var(--bt-on-accent) !important;
  2491.       border-color: var(--bt-accent) !important;
  2492.       transform: none !important;
  2493.       box-shadow: none !important;
  2494.     }
  2495.  
  2496.     /* Curve thread actions: the anchor and its nested span are two halves of
  2497.        one menu_gfx.png sprite. Replace both layers with one CSS button. */
  2498.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul {
  2499.       display: flex !important;
  2500.       align-items: center !important;
  2501.       flex-wrap: wrap !important;
  2502.       gap: 4px !important;
  2503.       margin: 0 !important;
  2504.       padding: 0 !important;
  2505.       background: transparent !important;
  2506.       list-style: none !important;
  2507.     }
  2508.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li {
  2509.       float: none !important;
  2510.       margin: 0 !important;
  2511.       padding: 0 !important;
  2512.       background: transparent !important;
  2513.       background-image: none !important;
  2514.       border: 0 !important;
  2515.       box-shadow: none !important;
  2516.       list-style: none !important;
  2517.     }
  2518.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li > a[class*="button_strip_"] {
  2519.       display: inline-flex !important;
  2520.       align-items: center !important;
  2521.       min-height: 0 !important;
  2522.       height: auto !important;
  2523.       margin: 0 !important;
  2524.       padding: 3px 8px !important;
  2525.       background: var(--bt-surface-2) !important;
  2526.       background-image: none !important;
  2527.       border: 1px solid var(--bt-border-2) !important;
  2528.       border-radius: var(--bt-radius-sm) !important;
  2529.       box-shadow: none !important;
  2530.       color: var(--bt-text-2) !important;
  2531.       filter: none !important;
  2532.       font-family: var(--bt-font) !important;
  2533.       font-size: 11px !important;
  2534.       font-weight: 500 !important;
  2535.       letter-spacing: 0.02em !important;
  2536.       line-height: 1.3 !important;
  2537.       text-decoration: none !important;
  2538.       text-shadow: none !important;
  2539.       text-transform: uppercase !important;
  2540.     }
  2541.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li > a[class*="button_strip_"] > span {
  2542.       display: inline !important;
  2543.       width: auto !important;
  2544.       height: auto !important;
  2545.       margin: 0 !important;
  2546.       padding: 0 !important;
  2547.       background: transparent !important;
  2548.       background-image: none !important;
  2549.       border: 0 !important;
  2550.       border-radius: 0 !important;
  2551.       box-shadow: none !important;
  2552.       color: inherit !important;
  2553.       filter: none !important;
  2554.       font: inherit !important;
  2555.       letter-spacing: inherit !important;
  2556.       line-height: inherit !important;
  2557.       text-shadow: none !important;
  2558.       text-transform: inherit !important;
  2559.     }
  2560.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li > a[class*="button_strip_"] > span::before,
  2561.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li > a[class*="button_strip_"] > span::after {
  2562.       background: transparent !important;
  2563.       background-image: none !important;
  2564.       border: 0 !important;
  2565.       box-shadow: none !important;
  2566.       filter: none !important;
  2567.     }
  2568.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li > a[class*="button_strip_"].active,
  2569.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li > a[class*="button_strip_"]:hover,
  2570.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li > a[class*="button_strip_"]:focus-visible {
  2571.       background: var(--bt-accent) !important;
  2572.       background-image: none !important;
  2573.       border-color: var(--bt-accent) !important;
  2574.       color: var(--bt-on-accent) !important;
  2575.       box-shadow: none !important;
  2576.     }
  2577.     :root[data-bt-active="true"][data-bt-theme] body .buttonlist ul > li > a[class*="button_strip_"].active {
  2578.       font-weight: 600 !important;
  2579.     }
  2580.  
  2581.     /* Curve quick actions put quickbuttons.png on the LI. */
  2582.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.quote_button,
  2583.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.remove_button,
  2584.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.modify_button,
  2585.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.approve_button,
  2586.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.restore_button,
  2587.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.split_button,
  2588.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.reply_button,
  2589.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.reply_all_button,
  2590.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li.notify_button {
  2591.       margin-left: 4px !important;
  2592.       padding: 0 !important;
  2593.       background: transparent !important;
  2594.       background-image: none !important;
  2595.       border: 0 !important;
  2596.       box-shadow: none !important;
  2597.     }
  2598.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li[class$="_button"] > a {
  2599.       display: inline-flex !important;
  2600.       align-items: center !important;
  2601.       width: auto !important;
  2602.       height: auto !important;
  2603.       min-height: 0 !important;
  2604.       padding: 2px 6px !important;
  2605.       background: transparent !important;
  2606.       background-image: none !important;
  2607.       border: 1px solid var(--bt-border-2) !important;
  2608.       border-radius: var(--bt-radius-sm) !important;
  2609.       color: var(--bt-text-2) !important;
  2610.       font-family: var(--bt-font) !important;
  2611.       font-size: 11px !important;
  2612.       font-weight: 500 !important;
  2613.       line-height: 1.3 !important;
  2614.       text-decoration: none !important;
  2615.       text-shadow: none !important;
  2616.     }
  2617.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li[class$="_button"] > a:hover,
  2618.     :root[data-bt-active="true"][data-bt-theme] body ul.quickbuttons > li[class$="_button"] > a:focus-visible {
  2619.       background: var(--bt-accent) !important;
  2620.       border-color: var(--bt-accent) !important;
  2621.       color: var(--bt-on-accent) !important;
  2622.     }
  2623.  
  2624.     /* Replace topic-table pinned/locked GIF backgrounds with theme-native
  2625.        mask icons while retaining the state at the same edge of the cell. */
  2626.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.stickybg2,
  2627.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.lockedbg2,
  2628.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.locked_sticky2 {
  2629.       position: relative !important;
  2630.       padding-right: 34px !important;
  2631.       background-image: none !important;
  2632.     }
  2633.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.stickybg2::after,
  2634.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.lockedbg2::after,
  2635.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.locked_sticky2::before,
  2636.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.locked_sticky2::after {
  2637.       content: "" !important;
  2638.       position: absolute !important;
  2639.       top: 5px !important;
  2640.       right: 7px !important;
  2641.       width: 14px !important;
  2642.       height: 14px !important;
  2643.       background: var(--bt-accent) !important;
  2644.       background-image: none !important;
  2645.       -webkit-mask-position: center !important;
  2646.       -webkit-mask-repeat: no-repeat !important;
  2647.       -webkit-mask-size: contain !important;
  2648.       mask-position: center !important;
  2649.       mask-repeat: no-repeat !important;
  2650.       mask-size: contain !important;
  2651.     }
  2652.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.stickybg2::after,
  2653.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.locked_sticky2::before {
  2654.       -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Cpath%20fill='black'%20d='M15%204l5%205-4%201-4.5%204.5.5%204.5-2%202-3.5-6.5L1%2011l2-2%204.5.5L12%205z'/%3E%3C/svg%3E") !important;
  2655.       mask-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Cpath%20fill='black'%20d='M15%204l5%205-4%201-4.5%204.5.5%204.5-2%202-3.5-6.5L1%2011l2-2%204.5.5L12%205z'/%3E%3C/svg%3E") !important;
  2656.     }
  2657.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.lockedbg2::after,
  2658.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.locked_sticky2::after {
  2659.       -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Cpath%20fill='black'%20d='M5%2010h14v10H5zM8%2010V7a4%204%200%200%201%208%200v3h-2V7a2%202%200%200%200-4%200v3z'/%3E%3C/svg%3E") !important;
  2660.       mask-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Cpath%20fill='black'%20d='M5%2010h14v10H5zM8%2010V7a4%204%200%200%201%208%200v3h-2V7a2%202%200%200%200-4%200v3z'/%3E%3C/svg%3E") !important;
  2661.     }
  2662.     :root[data-bt-active="true"][data-bt-theme] body .topic_table td.locked_sticky2::before {
  2663.       right: 23px !important;
  2664.     }
  2665.  
  2666.     .bt-post-action {
  2667.       display: inline-block !important;
  2668.       padding: 3px 7px !important;
  2669.       margin: 0 3px 0 0 !important;
  2670.       background: transparent !important;
  2671.       color: var(--bt-text-2) !important;
  2672.       border: 1px solid var(--bt-border-2) !important;
  2673.       border-radius: var(--bt-radius-sm) !important;
  2674.       font-family: var(--bt-font) !important;
  2675.       font-weight: 500 !important;
  2676.       font-size: 12px !important;
  2677.       text-transform: uppercase !important;
  2678.       letter-spacing: 0.04em !important;
  2679.       cursor: pointer !important;
  2680.       vertical-align: middle !important;
  2681.       transition: background var(--bt-trans), color var(--bt-trans), border-color var(--bt-trans) !important;
  2682.     }
  2683.     .bt-post-action:hover {
  2684.       background: var(--bt-accent) !important;
  2685.       color: var(--bt-on-accent) !important;
  2686.       border-color: var(--bt-accent) !important;
  2687.       text-decoration: none !important;
  2688.     }
  2689.     a.bt-post-action, a.bt-post-action:link, a.bt-post-action:visited {
  2690.       color: var(--bt-text-2) !important;
  2691.     }
  2692.     a.bt-post-action:hover { color: var(--bt-on-accent) !important; }
  2693.     span[title="Quote to clipboard"] { display: none !important; }
  2694.  
  2695.     input[type="text"], input[type="password"], input[type="email"],
  2696.     input[type="search"], input[type="url"], input[type="number"],
  2697.     textarea, select {
  2698.       background: var(--bt-input-bg) !important;
  2699.       color: var(--bt-text) !important;
  2700.       border: 1px solid var(--bt-border-2) !important;
  2701.       border-radius: var(--bt-radius-sm) !important;
  2702.       padding: 8px 10px !important;
  2703.       font-family: var(--bt-font) !important;
  2704.       font-size: 13px !important;
  2705.       transition: border-color var(--bt-trans), box-shadow var(--bt-trans) !important;
  2706.       outline: none !important;
  2707.     }
  2708.     input[type="text"]:focus, input[type="password"]:focus,
  2709.     input[type="email"]:focus, input[type="search"]:focus,
  2710.     input[type="url"]:focus, input[type="number"]:focus,
  2711.     textarea:focus, select:focus {
  2712.       border-color: var(--bt-accent) !important;
  2713.       box-shadow: 0 0 0 3px color-mix(in srgb, var(--bt-accent) 20%, transparent) !important;
  2714.     }
  2715.     textarea {
  2716.       min-height: 120px !important;
  2717.       line-height: 1.5 !important;
  2718.       font-family: var(--bt-font) !important;
  2719.       font-size: 13px !important;
  2720.     }
  2721.     .richedit_resize {
  2722.       position: relative !important;
  2723.       height: 7px !important;
  2724.       background: var(--bt-surface-2) !important;
  2725.       background-image: none !important;
  2726.       border: 1px solid var(--bt-border) !important;
  2727.       border-top: 0 !important;
  2728.       cursor: ns-resize !important;
  2729.     }
  2730.     .richedit_resize::after {
  2731.       content: "" !important;
  2732.       position: absolute !important;
  2733.       top: 3px !important;
  2734.       left: 50% !important;
  2735.       width: 34px !important;
  2736.       height: 1px !important;
  2737.       margin-left: -17px !important;
  2738.       background: var(--bt-border-2) !important;
  2739.       border-radius: 1px !important;
  2740.     }
  2741.  
  2742.     #bbcBox_message, .bbc_buttons, #post_modify, .post_buttons {
  2743.       background: var(--bt-surface-2) !important;
  2744.       border: 1px solid var(--bt-border) !important;
  2745.       border-radius: var(--bt-radius-sm) !important;
  2746.       padding: 6px !important;
  2747.     }
  2748.     #bbcBox_message img, .bbc_buttons img {
  2749.       filter: var(--bt-icon-filter) !important;
  2750.       transition: filter var(--bt-trans) !important;
  2751.     }
  2752.     #bbcBox_message img:hover, .bbc_buttons img:hover { filter: none !important; }
  2753.  
  2754.     .bt-bbc-icon {
  2755.       display: inline-flex !important;
  2756.       align-items: center !important;
  2757.       justify-content: center !important;
  2758.       width: 26px !important;
  2759.       height: 26px !important;
  2760.       margin: 1px !important;
  2761.       padding: 4px !important;
  2762.       border-radius: var(--bt-radius-sm) !important;
  2763.       color: var(--bt-text-2) !important;
  2764.       background: transparent !important;
  2765.       cursor: pointer !important;
  2766.       vertical-align: middle !important;
  2767.       transition: background var(--bt-trans), color var(--bt-trans) !important;
  2768.       box-sizing: border-box !important;
  2769.     }
  2770.     .bt-bbc-icon svg {
  2771.       width: 100% !important;
  2772.       height: 100% !important;
  2773.       display: block !important;
  2774.     }
  2775.     .bt-bbc-icon:hover {
  2776.       background: color-mix(in srgb, var(--bt-accent) 18%, transparent) !important;
  2777.       color: var(--bt-accent) !important;
  2778.     }
  2779.     .bt-bbc-icon:focus,
  2780.     .bt-post-action:focus {
  2781.       outline: 2px solid var(--bt-accent) !important;
  2782.       outline-offset: 2px !important;
  2783.     }
  2784.  
  2785.     .bt-topic-icon {
  2786.       display: inline-flex !important;
  2787.       align-items: center !important;
  2788.       justify-content: center !important;
  2789.       width: 17px !important;
  2790.       height: 17px !important;
  2791.       margin: 0 4px 0 0 !important;
  2792.       padding: 1px !important;
  2793.       border-radius: 4px !important;
  2794.       color: var(--bt-text-2) !important;
  2795.       background: transparent !important;
  2796.       border: none !important;
  2797.       vertical-align: -3px !important;
  2798.       box-sizing: border-box !important;
  2799.       transition: color var(--bt-trans), background var(--bt-trans), opacity var(--bt-trans) !important;
  2800.       opacity: 1 !important;
  2801.     }
  2802.     .bt-topic-icon svg {
  2803.       width: 100% !important;
  2804.       height: 100% !important;
  2805.       display: block !important;
  2806.       stroke-width: 2.25 !important;
  2807.     }
  2808.     .bt-topic-icon:hover {
  2809.       color: var(--bt-accent) !important;
  2810.       background: color-mix(in srgb, var(--bt-accent) 10%, transparent) !important;
  2811.     }
  2812.  
  2813.     /* v2.10.25: distinct hue for very-hot topics so they pop visually beyond
  2814.        the default accent. Hot stays on the accent (warm orange) for continuity,
  2815.        very-hot bumps to a saturated red — a visual "+1 alarm" over hot. Poll
  2816.        gets its own colour (purple/indigo) so it's identifiable as a poll at a
  2817.        glance without reading the icon shape. */
  2818.     .bt-topic-icon--hot,
  2819.     .bt-topic-icon--question,
  2820.     .bt-topic-icon--idea,
  2821.     .bt-topic-icon--thumbsUp {
  2822.       color: var(--bt-accent) !important;
  2823.     }
  2824.     .bt-topic-icon--veryhot {
  2825.       color: #d93025 !important; /* fire-red, theme-agnostic for instant recognition */
  2826.     }
  2827.     .bt-topic-icon--poll {
  2828.       color: #8b5cf6 !important; /* indigo/violet — consistent across light & dark themes */
  2829.     }
  2830.     .bt-topic-icon--important,
  2831.     .bt-topic-icon--thumbsDown,
  2832.     .bt-topic-icon--angry {
  2833.       color: var(--bt-danger) !important;
  2834.     }
  2835.     .bt-topic-icon--standard,
  2836.     .bt-topic-icon--smile {
  2837.       color: var(--bt-text-2) !important;
  2838.     }
  2839.  
  2840.     /* v2.10.15: inline status IMGs whose src has been swapped to the modern
  2841.        SVG data-URL (lock + new). The browser sizes them from the SVG's
  2842.        width/height attributes, so we just need to harmonise vertical
  2843.        alignment with the topic title baseline and add a small horizontal
  2844.        margin so they don't kiss the surrounding text. */
  2845.     img.bt-inline-status-img {
  2846.       vertical-align: -2px !important;
  2847.       margin: 0 4px !important;
  2848.       border: 0 !important;
  2849.       background: transparent !important;
  2850.       box-shadow: none !important;
  2851.       filter: none !important;
  2852.       opacity: 1 !important;
  2853.     }
  2854.     img.bt-inline-status-img--locked {
  2855.       /* SMF places this with align="right". Keep the baseline cleaner than
  2856.          the SVG's natural drop. */
  2857.       vertical-align: -3px !important;
  2858.     }
  2859.     img.bt-inline-status-img--sticky {
  2860.       /* v2.10.16: pushpin sits on the right edge alongside the lock. Tilted
  2861.          needle reads better with a slight baseline drop. */
  2862.       vertical-align: -3px !important;
  2863.     }
  2864.     img.bt-inline-status-img--newPost {
  2865.       vertical-align: -2px !important;
  2866.     }
  2867.  
  2868.     /* Locked and sticky tints apply only to the topic subject cell. Both are
  2869.        derived from the active Main palette, so Cream, Mint, Rose and custom
  2870.        themes never inherit the classic fixed light-blue background. */
  2871.     :root[data-bt-theme="light"] {
  2872.       --bt-locked-row-bg: color-mix(
  2873.         in srgb,
  2874.         var(--bt-post-bg, var(--bt-surface-1)) 72%,
  2875.         var(--bt-surface-2) 28%
  2876.       );
  2877.       --bt-locked-row-bg-hover: color-mix(
  2878.         in srgb,
  2879.         var(--bt-post-bg, var(--bt-surface-1)) 55%,
  2880.         var(--bt-surface-2) 45%
  2881.       );
  2882.       --bt-sticky-row-bg: color-mix(
  2883.         in srgb,
  2884.         var(--bt-post-bg, var(--bt-surface-1)) 55%,
  2885.         var(--bt-surface-2) 45%
  2886.       );
  2887.       --bt-sticky-row-bg-hover: color-mix(
  2888.         in srgb,
  2889.         var(--bt-post-bg, var(--bt-surface-1)) 35%,
  2890.         var(--bt-surface-2) 65%
  2891.       );
  2892.     }
  2893.     :root[data-bt-theme="dark"] {
  2894.       --bt-locked-row-bg: color-mix(in srgb, var(--bt-surface-1) 78%, var(--bt-surface-2) 22%);
  2895.       --bt-locked-row-bg-hover: color-mix(in srgb, var(--bt-surface-1) 60%, var(--bt-surface-2) 40%);
  2896.       --bt-sticky-row-bg: color-mix(in srgb, var(--bt-surface-1) 65%, var(--bt-surface-2) 35%);
  2897.       --bt-sticky-row-bg-hover: color-mix(in srgb, var(--bt-surface-1) 40%, var(--bt-surface-2) 60%);
  2898.     }
  2899.     :root[data-bt-active="true"][data-bt-theme] body tr.bt-row-locked > td.bt-cell-special-topic {
  2900.       background-color: var(--bt-locked-row-bg) !important;
  2901.       background-image: none !important;
  2902.     }
  2903.     :root[data-bt-active="true"][data-bt-theme] body tr.bt-row-locked:hover > td.bt-cell-special-topic {
  2904.       background-color: var(--bt-locked-row-bg-hover) !important;
  2905.     }
  2906.     :root[data-bt-active="true"][data-bt-theme] body tr.bt-row-sticky > td.bt-cell-special-topic {
  2907.       background-color: var(--bt-sticky-row-bg) !important;
  2908.       background-image: none !important;
  2909.     }
  2910.     :root[data-bt-active="true"][data-bt-theme] body tr.bt-row-sticky:hover > td.bt-cell-special-topic {
  2911.       background-color: var(--bt-sticky-row-bg-hover) !important;
  2912.     }
  2913.  
  2914.     .bt-smiley {
  2915.       display: inline-block !important;
  2916.       font-size: 1.15em !important;
  2917.       line-height: 1 !important;
  2918.       vertical-align: -0.12em !important;
  2919.       font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji",
  2920.                    "Twemoji Mozilla", sans-serif !important;
  2921.     }
  2922.  
  2923.     [class*="maintab_"],
  2924.     [class*="mirrortab_"] {
  2925.       display: inline-block !important;
  2926.       margin: 0 !important;
  2927.       padding: 0 !important;
  2928.       border-radius: 0 !important;
  2929.       background-color: var(--bt-surface-2) !important;
  2930.       background-image: none !important;
  2931.       border: 1px solid var(--bt-border) !important;
  2932.       border-left: none !important;
  2933.       box-shadow: none !important;
  2934.       text-shadow: none !important;
  2935.       transition: background-color var(--bt-trans), border-color var(--bt-trans) !important;
  2936.       vertical-align: middle !important;
  2937.       line-height: 1 !important;
  2938.       width: auto !important;
  2939.       min-width: 0 !important;
  2940.       height: auto !important;
  2941.     }
  2942.     .bt-empty-tab-cap,
  2943.     .maintab_active_first,
  2944.     .maintab_active_last,
  2945.     .mirrortab_active_first,
  2946.     .mirrortab_active_last {
  2947.       display: none !important;
  2948.     }
  2949.     .maintab_back,
  2950.     .maintab_active_back,
  2951.     .mirrortab_back,
  2952.     .mirrortab_active_back {
  2953.       border-left: 1px solid var(--bt-border) !important;
  2954.       border-top-left-radius: var(--bt-radius-sm) !important;
  2955.       border-bottom-left-radius: var(--bt-radius-sm) !important;
  2956.       border-top-right-radius: var(--bt-radius-sm) !important;
  2957.       border-bottom-right-radius: var(--bt-radius-sm) !important;
  2958.       margin-right: 4px !important;
  2959.       overflow: hidden !important;
  2960.     }
  2961.     [class*="maintab_"] a,
  2962.     [class*="maintab_"] a:link,
  2963.     [class*="maintab_"] a:visited,
  2964.     [class*="mirrortab_"] a,
  2965.     [class*="mirrortab_"] a:link,
  2966.     [class*="mirrortab_"] a:visited {
  2967.       display: inline-block !important;
  2968.       padding: 6px 14px !important;
  2969.       margin: 0 !important;
  2970.       color: var(--bt-text-2) !important;
  2971.       font-family: var(--bt-font) !important;
  2972.       font-weight: 500 !important;
  2973.       font-size: 13px !important; /* v3.0.35: was 12px */
  2974.       text-transform: uppercase !important;
  2975.       letter-spacing: 0.05em !important;
  2976.       transition: color var(--bt-trans) !important;
  2977.       background: transparent !important;
  2978.       background-image: none !important;
  2979.       border: none !important;
  2980.       box-shadow: none !important;
  2981.       text-shadow: none !important;
  2982.       line-height: 1 !important;
  2983.     }
  2984.  
  2985.     /* ----------------------------------------------------------------------
  2986.        New-PM highlight — client-side port of PowerGlove's SMF patch. When the
  2987.        PM maintab has unread messages (flagged by highlightUnreadPm), show a
  2988.        pulsing accent dot before the link, in place of the original icon.
  2989.        ---------------------------------------------------------------------- */
  2990.     [class*="maintab_"] a.bt-pm-unread::before,
  2991.     #main_menu a.bt-pm-unread::before,
  2992.     .dropmenu a.bt-pm-unread::before {
  2993.       content: "" !important;
  2994.       display: inline-block !important;
  2995.       width: 7px !important;
  2996.       height: 7px !important;
  2997.       margin-right: 7px !important;
  2998.       border-radius: 50% !important;
  2999.       background: var(--bt-accent) !important;
  3000.       vertical-align: 1px !important;
  3001.       animation: bt-pm-pulse 2s ease-out infinite !important;
  3002.     }
  3003.     .maintab_active_back a.bt-pm-unread::before,
  3004.     .mirrortab_active_back a.bt-pm-unread::before {
  3005.       background: var(--bt-on-accent) !important;
  3006.     }
  3007.     @keyframes bt-pm-pulse {
  3008.       0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bt-accent) 55%, transparent); }
  3009.       70%  { box-shadow: 0 0 0 6px color-mix(in srgb, var(--bt-accent) 0%, transparent); }
  3010.       100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bt-accent) 0%, transparent); }
  3011.     }
  3012.  
  3013.     /* v2.10.29 / v3.2.3: compact override ONLY for mirrortab_ (topic action bar:
  3014.        Reply | Unwatch | Notify | Mark unread | Print | view topic archive).
  3015.        Earlier attempts failed because the markup uses raw <a> elements
  3016.        inside <td class="mirrortab_back">, NOT a.replybutton/a.notifybutton —
  3017.        those classes don't exist in this SMF theme. The general maintab/
  3018.        mirrortab rule above (padding 6×14, font-size 12px, letter-spacing
  3019.        0.05em) is shared with the top navigation menu, so we override only
  3020.        mirrortab here to avoid affecting the main nav. */
  3021.     .mirrortab_first,
  3022.     .mirrortab_last,
  3023.     .mirrortab_active_first,
  3024.     .mirrortab_active_last {
  3025.       display: none !important;
  3026.     }
  3027.     [class*="mirrortab_"] {
  3028.       white-space: nowrap !important;
  3029.       border-left: 1px solid var(--bt-border) !important;
  3030.       border-radius: var(--bt-radius-sm) !important;
  3031.     }
  3032.     [class*="mirrortab_"] a,
  3033.     [class*="mirrortab_"] a:link,
  3034.     [class*="mirrortab_"] a:visited {
  3035.       padding: 2px 5px !important;
  3036.       font-size: 11px !important;
  3037.       letter-spacing: 0 !important;
  3038.       line-height: 1.15 !important;
  3039.       white-space: nowrap !important;
  3040.     }
  3041.     /* Tighten the cell itself so vertical padding from the <td> doesn't
  3042.        reintroduce the height we just removed from the links. */
  3043.     td[class*="mirrortab_"] {
  3044.       padding-top: 2px !important;
  3045.       padding-bottom: 2px !important;
  3046.     }
  3047.     .maintab_first:hover, .maintab_back:hover, .maintab_last:hover {
  3048.       background-color: var(--bt-surface-3) !important;
  3049.       border-color: var(--bt-border-2) !important;
  3050.     }
  3051.     .maintab_first:hover a, .maintab_back:hover a, .maintab_last:hover a {
  3052.       color: var(--bt-text) !important;
  3053.     }
  3054.     .maintab_active_back,
  3055.     .mirrortab_active_back {
  3056.       background-color: var(--bt-accent) !important;
  3057.       border-color: var(--bt-accent) !important;
  3058.     }
  3059.     .maintab_active_back a,
  3060.     .maintab_active_back a:hover,
  3061.     .mirrortab_active_back a,
  3062.     .mirrortab_active_back a:hover {
  3063.       color: var(--bt-on-accent) !important;
  3064.       font-weight: 600 !important;
  3065.     }
  3066.  
  3067.     /* v2.7.15: In LIGHT themes, selected main/mirror tabs use a
  3068.        theme-derived extrapolated colour: it continues from Main -> surface3
  3069.        by the same interval again. In other words, if surface3 is the
  3070.        "intermediate/illuminated" tone, the active tab doubles that HSL move. */
  3071.     :root[data-bt-theme="light"] .maintab_active_back,
  3072.     :root[data-bt-theme="light"] .mirrortab_active_back {
  3073.       background-color: var(--bt-nav-active-bg, var(--bt-surface-3)) !important;
  3074.       border-color: var(--bt-nav-active-bg, var(--bt-border-2)) !important;
  3075.     }
  3076.     :root[data-bt-theme="light"] .maintab_active_back a,
  3077.     :root[data-bt-theme="light"] .maintab_active_back a:hover,
  3078.     :root[data-bt-theme="light"] .mirrortab_active_back a,
  3079.     :root[data-bt-theme="light"] .mirrortab_active_back a:hover {
  3080.       color: var(--bt-nav-active-text, var(--bt-text)) !important;
  3081.       font-weight: 600 !important;
  3082.     }
  3083.     .maintab_active_first.maintab_active_first,
  3084.     .maintab_active_last.maintab_active_last,
  3085.     .mirrortab_active_first.mirrortab_active_first,
  3086.     .mirrortab_active_last.mirrortab_active_last {
  3087.       display: none !important;
  3088.     }
  3089.  
  3090.     #main_menu, .dropmenu {
  3091.       background: transparent !important;
  3092.       background-image: none !important;
  3093.       border: none !important;
  3094.       box-shadow: none !important;
  3095.     }
  3096.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li,
  3097.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li {
  3098.       background: var(--bt-surface-2) !important;
  3099.       background-image: none !important;
  3100.       border: 1px solid var(--bt-border) !important;
  3101.       border-radius: var(--bt-radius-sm) !important;
  3102.       margin-right: 4px !important;
  3103.       box-shadow: none !important;
  3104.       filter: none !important;
  3105.       text-shadow: none !important;
  3106.     }
  3107.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li {
  3108.       overflow: hidden !important;
  3109.     }
  3110.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li,
  3111.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu > li {
  3112.       overflow: visible !important;
  3113.     }
  3114.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li > ul {
  3115.       background: var(--bt-surface-2) !important;
  3116.       background-image: none !important;
  3117.       border: 1px solid var(--bt-border-2) !important;
  3118.       border-radius: var(--bt-radius-sm) !important;
  3119.       box-shadow: var(--bt-shadow-lg) !important;
  3120.       overflow: visible !important;
  3121.     }
  3122.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li > ul > li {
  3123.       margin: 0 !important;
  3124.       border: 0 !important;
  3125.       border-radius: 0 !important;
  3126.       box-shadow: none !important;
  3127.       overflow: visible !important;
  3128.     }
  3129.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li.chosen,
  3130.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li.chosen,
  3131.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li.active,
  3132.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li.active,
  3133.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li:has(> a.active),
  3134.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li:has(> a.active),
  3135.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li:has(> a.chosen),
  3136.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li:has(> a.chosen) {
  3137.       background: var(--bt-accent) !important;
  3138.       background-image: none !important;
  3139.       border-color: var(--bt-accent) !important;
  3140.     }
  3141.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li > a,
  3142.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li > a {
  3143.       display: block !important;
  3144.       background: transparent !important;
  3145.       background-image: none !important;
  3146.       color: var(--bt-text-2) !important;
  3147.       padding: 6px 14px !important;
  3148.       font-size: 13px !important;
  3149.       text-transform: uppercase !important;
  3150.       letter-spacing: 0.05em !important;
  3151.       border: 0 !important;
  3152.       border-radius: 0 !important;
  3153.       box-shadow: none !important;
  3154.       filter: none !important;
  3155.       text-shadow: none !important;
  3156.     }
  3157.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li > a span,
  3158.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li > a span {
  3159.       margin: 0 !important;
  3160.       padding: 0 !important;
  3161.       color: inherit !important;
  3162.       background: transparent !important;
  3163.       background-image: none !important;
  3164.       border: 0 !important;
  3165.       border-radius: 0 !important;
  3166.       box-shadow: none !important;
  3167.       filter: none !important;
  3168.       text-shadow: none !important;
  3169.     }
  3170.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li > a span::before,
  3171.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li > a span::after,
  3172.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li > a span::before,
  3173.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li > a span::after {
  3174.       background: transparent !important;
  3175.       background-image: none !important;
  3176.       border: 0 !important;
  3177.       box-shadow: none !important;
  3178.       filter: none !important;
  3179.     }
  3180.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li.chosen > a,
  3181.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li.chosen > a,
  3182.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li.active > a,
  3183.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li.active > a,
  3184.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li:has(> a.active) > a,
  3185.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li:has(> a.active) > a,
  3186.     :root[data-bt-active="true"][data-bt-theme] body #main_menu li:has(> a.chosen) > a,
  3187.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu li:has(> a.chosen) > a,
  3188.     :root[data-bt-active="true"][data-bt-theme] body #main_menu a.active,
  3189.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu a.active,
  3190.     :root[data-bt-active="true"][data-bt-theme] body #main_menu a.chosen,
  3191.     :root[data-bt-active="true"][data-bt-theme] body .dropmenu a.chosen {
  3192.       background: transparent !important;
  3193.       background-image: none !important;
  3194.       color: var(--bt-on-accent) !important;
  3195.       font-weight: 600 !important;
  3196.       box-shadow: none !important;
  3197.     }
  3198.  
  3199.     #upper_section {
  3200.       border-bottom: 1px solid var(--bt-border) !important;
  3201.       position: relative !important;
  3202.     }
  3203.     #top_section, #upshrink_header, .navigate_section ul, .navigate_section {
  3204.       background: transparent !important;
  3205.       color: var(--bt-text-2) !important;
  3206.     }
  3207.     .navigate_section a, .navigate_section a:link, .navigate_section a:visited {
  3208.       color: var(--bt-text-2) !important;
  3209.     }
  3210.     .navigate_section a:hover { color: var(--bt-accent) !important; }
  3211.     .navigate_section .last a, .navigate_section li:last-child a {
  3212.       color: var(--bt-text) !important;
  3213.       font-weight: 600 !important;
  3214.     }
  3215.     /* v2.10.33: breadcrumb sizing rule moved below the smalltext/middletext
  3216.        block — see the override declared after that block. The classic
  3217.        breadcrumb sits inside <td class="middletext">, which the smalltext
  3218.        block was sizing down to --bt-fs-small. Since CSS at equal specificity
  3219.        is decided by source order, the override has to come after. */
  3220.     #header img, #logo { filter: brightness(1.05) !important; }
  3221.  
  3222.     hr {
  3223.       border: none !important;
  3224.       border-top: 1px solid var(--bt-border) !important;
  3225.       margin: 16px 0 !important;
  3226.     }
  3227.  
  3228.     #footer_section, .copywrite {
  3229.       background: transparent !important;
  3230.       color: var(--bt-text-3) !important;
  3231.       border-top: 1px solid var(--bt-border) !important;
  3232.     }
  3233.     #footer_section a, .copywrite a { color: var(--bt-text-2) !important; }
  3234.     #footer_section a:hover, .copywrite a:hover { color: var(--bt-accent) !important; }
  3235.  
  3236.     .information, .descbox, .infobox {
  3237.       background: var(--bt-surface-2) !important;
  3238.       color: var(--bt-text-2) !important;
  3239.       border: 1px solid var(--bt-border) !important;
  3240.       border-radius: var(--bt-radius-sm) !important;
  3241.       padding: 10px 12px !important;
  3242.     }
  3243.     .is_directory {
  3244.       position: relative !important;
  3245.       padding-left: 20px !important;
  3246.       background: transparent !important;
  3247.       background-image: none !important;
  3248.     }
  3249.     .is_directory::before {
  3250.       content: "" !important;
  3251.       position: absolute !important;
  3252.       left: 1px !important;
  3253.       top: 0.3em !important;
  3254.       width: 12px !important;
  3255.       height: 8px !important;
  3256.       background: color-mix(in srgb, var(--bt-accent) 18%, transparent) !important;
  3257.       border: 1px solid var(--bt-accent) !important;
  3258.       border-radius: 2px !important;
  3259.       box-sizing: border-box !important;
  3260.     }
  3261.     .errorbox, .noticebox {
  3262.       background: color-mix(in srgb, var(--bt-danger) 12%, transparent) !important;
  3263.       border: 1px solid color-mix(in srgb, var(--bt-danger) 40%, transparent) !important;
  3264.       color: var(--bt-danger) !important;
  3265.       border-radius: var(--bt-radius-sm) !important;
  3266.       padding: 10px 12px !important;
  3267.     }
  3268.     #ajax_in_progress {
  3269.       background: var(--bt-surface-2) !important;
  3270.       background-image: none !important;
  3271.       color: var(--bt-accent) !important;
  3272.       border-bottom: 2px solid var(--bt-accent) !important;
  3273.       box-shadow: var(--bt-shadow-lg) !important;
  3274.     }
  3275.  
  3276.     .pagelinks { color: var(--bt-text-2) !important; }
  3277.     .pagelinks a, .pagelinks a:link, .pagelinks a:visited {
  3278.       color: var(--bt-text-2) !important;
  3279.       padding: 4px 8px !important;
  3280.       border-radius: var(--bt-radius-sm) !important;
  3281.       transition: background var(--bt-trans), color var(--bt-trans) !important;
  3282.     }
  3283.     .pagelinks a:hover {
  3284.       background: color-mix(in srgb, var(--bt-accent) 12%, transparent) !important;
  3285.       color: var(--bt-accent) !important;
  3286.     }
  3287.     .pagelinks strong {
  3288.       background: var(--bt-accent) !important;
  3289.       color: var(--bt-on-accent) !important;
  3290.       padding: 4px 8px !important;
  3291.       border-radius: var(--bt-radius-sm) !important;
  3292.     }
  3293.  
  3294.     /* v2.10.26: top-of-page pagelinks (« 1 2 3 ... 1234 » above topic tables
  3295.        or post lists) are page-level navigation and must be readable — same
  3296.        size as body text in classic Bitcointalk. Earlier versions collapsed
  3297.        them all to --bt-fs-pagelinks (10px), which is appropriate only for
  3298.        the per-topic mini paginators inside subject cells. The dedicated
  3299.        per-topic rule (further down, scoped to td[class*="windowbg"] with
  3300.        :has(> a[href*="topic="])) keeps those at 10px without affecting the
  3301.        page-level paginator. */
  3302.     .pagelinks,
  3303.     .pagelinks a,
  3304.     .pagelinks a:link,
  3305.     .pagelinks a:visited,
  3306.     .pagelinks strong,
  3307.     .pagelinks b {
  3308.       font-size: var(--bt-fs-base) !important;
  3309.       line-height: 1.35 !important;
  3310.       font-weight: 400 !important;
  3311.       vertical-align: baseline !important;
  3312.     }
  3313.     .pagelinks a,
  3314.     .pagelinks a:link,
  3315.     .pagelinks a:visited,
  3316.     .pagelinks strong,
  3317.     .pagelinks b {
  3318.       display: inline-block !important;
  3319.       min-width: 0 !important;
  3320.       padding: 1px 4px !important;
  3321.       margin: 0 1px !important;
  3322.       border-radius: 4px !important;
  3323.     }
  3324.     .pagelinks strong,
  3325.     .pagelinks b {
  3326.       font-weight: 600 !important;
  3327.     }
  3328.  
  3329.     .poster h4 a, .poster h4 a:link, .poster h4 a:visited {
  3330.       color: var(--bt-text) !important;
  3331.       font-weight: 600 !important;
  3332.     }
  3333.     .poster h4 a:hover { color: var(--bt-accent) !important; }
  3334.     .poster ul, .poster li {
  3335.       color: var(--bt-text-3) !important;
  3336.       font-size: 12px !important;
  3337.     }
  3338.     .avatar, img.avatar {
  3339.       border-radius: var(--bt-radius-sm) !important;
  3340.       border: 1px solid var(--bt-border) !important;
  3341.     }
  3342.  
  3343.     * { scrollbar-width: thin; scrollbar-color: var(--bt-surface-3) var(--bt-bg); }
  3344.     *::-webkit-scrollbar { width: 10px; height: 10px; }
  3345.     *::-webkit-scrollbar-track { background: var(--bt-bg); }
  3346.     *::-webkit-scrollbar-thumb {
  3347.       background: var(--bt-surface-3);
  3348.       border-radius: 5px;
  3349.       border: 2px solid var(--bt-bg);
  3350.     }
  3351.     *::-webkit-scrollbar-thumb:hover { background: var(--bt-accent); }
  3352.  
  3353.     ::selection {
  3354.       background: color-mix(in srgb, var(--bt-accent) 35%, transparent);
  3355.       color: var(--bt-text);
  3356.     }
  3357.  
  3358.     img[src*="bullet"], img[src*="off"], img[src*="on"] { opacity: 0.85; }
  3359.  
  3360.     select {
  3361.       appearance: none !important;
  3362.       -webkit-appearance: none !important;
  3363.       background-image:
  3364.         linear-gradient(45deg, transparent 50%, var(--bt-text-2) 50%),
  3365.         linear-gradient(135deg, var(--bt-text-2) 50%, transparent 50%) !important;
  3366.       background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50% !important;
  3367.       background-size: 5px 5px, 5px 5px !important;
  3368.       background-repeat: no-repeat !important;
  3369.       padding-right: 28px !important;
  3370.     }
  3371.  
  3372.     /* Mobile performance profiles keep the same layout and palette. Balanced
  3373.        retains progressive DOM modernisation; Lite keeps the minimal path. */
  3374.     :root[data-bt-mobile-lite="true"] {
  3375.       --bt-radius: 6px;
  3376.       --bt-radius-sm: 4px;
  3377.       --bt-radius-lg: 8px;
  3378.       --bt-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  3379.       --bt-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  3380.       --bt-trans: 0ms linear;
  3381.       --bt-shadow: none;
  3382.       --bt-shadow-lg: none;
  3383.     }
  3384.  
  3385.     :root[data-bt-mobile-lite="true"],
  3386.     :root[data-bt-mobile-lite="true"] body {
  3387.       -webkit-font-smoothing: auto;
  3388.       text-rendering: auto;
  3389.     }
  3390.  
  3391.     :root[data-bt-mobile-lite="true"] body {
  3392.       background: var(--bt-bg) !important;
  3393.       background-attachment: scroll !important;
  3394.     }
  3395.  
  3396.     :root[data-bt-mobile-lite="true"] [class*="maintab_"] a.bt-pm-unread::before,
  3397.     :root[data-bt-mobile-lite="true"] #main_menu a.bt-pm-unread::before,
  3398.     :root[data-bt-mobile-lite="true"] .dropmenu a.bt-pm-unread::before,
  3399.     :root[data-bt-mobile-lite="true"][data-bt-active="false"] #bt-switcher-button {
  3400.       animation: none !important;
  3401.     }
  3402.  
  3403.     :root[data-bt-mobile-lite="true"] table.bordercolor,
  3404.     :root[data-bt-mobile-lite="true"] table.table_list,
  3405.     :root[data-bt-mobile-lite="true"] table.table_grid,
  3406.     :root[data-bt-mobile-lite="true"] .tborder,
  3407.     :root[data-bt-mobile-lite="true"] #bt-switcher-button,
  3408.     :root[data-bt-mobile-lite="true"] #bt-switcher-panel {
  3409.       box-shadow: none !important;
  3410.     }
  3411.  
  3412.     :root[data-bt-mobile-lite="true"] table.bordercolor,
  3413.     :root[data-bt-mobile-lite="true"] table.table_list,
  3414.     :root[data-bt-mobile-lite="true"] table.table_grid,
  3415.     :root[data-bt-mobile-lite="true"] .tborder {
  3416.       border-radius: var(--bt-radius-sm) !important;
  3417.     }
  3418.  
  3419.     :root[data-bt-mobile-lite="true"] #header img,
  3420.     :root[data-bt-mobile-lite="true"] #logo,
  3421.     :root[data-bt-mobile-lite="true"] #bbcBox_message img,
  3422.     :root[data-bt-mobile-lite="true"] .bbc_buttons img {
  3423.       filter: none !important;
  3424.     }
  3425.  
  3426.     /*-- BT_ALWAYS_ON_START --*/
  3427.     #bt-switcher {
  3428.       position: fixed !important;
  3429.       top: 8px !important;
  3430.       right: 8px !important;
  3431.       z-index: 10000 !important;
  3432.       font-family: var(--bt-font) !important;
  3433.       font-size: 13px !important;
  3434.       color: var(--bt-text, #1A1D21) !important;
  3435.       line-height: 1 !important;
  3436.     }
  3437.     #bt-switcher-button {
  3438.       display: flex !important;
  3439.       align-items: center !important;
  3440.       justify-content: center !important;
  3441.       width: 32px !important;
  3442.       height: 32px !important;
  3443.       padding: 0 !important;
  3444.       margin: 0 !important;
  3445.       border-radius: 50% !important;
  3446.       background: var(--bt-surface-2, #2A2F35) !important;
  3447.       color: var(--bt-text-2, #A8B0BA) !important;
  3448.       border: 1px solid var(--bt-border-2, rgba(255,255,255,0.14)) !important;
  3449.       cursor: pointer !important;
  3450.       transition: background var(--bt-trans), color var(--bt-trans), transform 200ms ease !important;
  3451.       box-shadow: var(--bt-shadow, 0 1px 0 rgba(0,0,0,0.2)) !important;
  3452.       text-shadow: none !important;
  3453.       font: inherit !important;
  3454.       text-transform: none !important;
  3455.       letter-spacing: 0 !important;
  3456.     }
  3457.     #bt-switcher-button:hover {
  3458.       background: var(--bt-surface-3, #343A41) !important;
  3459.       color: var(--bt-text, #E3E3E8) !important;
  3460.       transform: rotate(20deg);
  3461.     }
  3462.     #bt-switcher-button svg {
  3463.       width: 18px;
  3464.       height: 18px;
  3465.       pointer-events: none !important;
  3466.     }
  3467.  
  3468.     :root[data-bt-active="false"] #bt-switcher-button {
  3469.       width: auto !important;
  3470.       min-width: 44px !important;
  3471.       padding: 0 12px !important;
  3472.       border-radius: 14px !important;
  3473.       background: #2A2F35 !important;
  3474.       color: #FFFFFF !important;
  3475.       border: 1px solid #4ADE80 !important;
  3476.       font-weight: 700 !important;
  3477.       font-size: 11px !important;
  3478.       text-transform: uppercase !important;
  3479.       letter-spacing: 0.08em !important;
  3480.       box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4) !important;
  3481.       animation: bt-pulse-on 2.4s ease-in-out infinite;
  3482.     }
  3483.     :root[data-bt-active="false"] #bt-switcher-button:hover {
  3484.       background: #4ADE80 !important;
  3485.       color: #1A1D21 !important;
  3486.       transform: none !important;
  3487.       animation: none;
  3488.     }
  3489.     .bt-sw-on-text { display: inline-block; line-height: 1; }
  3490.     @keyframes bt-pulse-on {
  3491.       0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.0); }
  3492.       50%      { box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.18); }
  3493.     }
  3494.  
  3495.     #bt-switcher-panel {
  3496.       position: absolute !important;
  3497.       top: 40px !important;
  3498.       right: 0 !important;
  3499.       min-width: 300px !important;
  3500.       max-height: calc(100vh - 56px) !important;
  3501.       max-height: calc(100dvh - 56px) !important;
  3502.       overflow-y: auto !important;
  3503.       overscroll-behavior: contain !important;
  3504.       box-sizing: border-box !important;
  3505.       background: var(--bt-surface-1, #22262B) !important;
  3506.       border: 1px solid var(--bt-border-2, rgba(255,255,255,0.14)) !important;
  3507.       border-radius: var(--bt-radius, 10px) !important;
  3508.       padding: 14px !important;
  3509.       box-shadow: var(--bt-shadow-lg, 0 12px 32px rgba(0,0,0,0.35)) !important;
  3510.       display: block !important;
  3511.       opacity: 0 !important;
  3512.       pointer-events: none !important;
  3513.       transform: translateY(-4px) !important;
  3514.       visibility: hidden !important;
  3515.       transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease !important;
  3516.       color: var(--bt-text, #E3E3E8) !important;
  3517.     }
  3518.     #bt-switcher.open #bt-switcher-panel {
  3519.       opacity: 1 !important;
  3520.       pointer-events: auto !important;
  3521.       transform: translateY(0) !important;
  3522.       visibility: visible !important;
  3523.     }
  3524.     #bt-switcher-panel button {
  3525.       touch-action: manipulation !important;
  3526.       -webkit-tap-highlight-color: transparent !important;
  3527.     }
  3528.     #bt-switcher-panel input[type="color"] {
  3529.       touch-action: auto !important;
  3530.       -webkit-tap-highlight-color: transparent !important;
  3531.     }
  3532.     .bt-sw-section { margin-bottom: 14px; }
  3533.     .bt-sw-section:last-child { margin-bottom: 0; }
  3534.     .bt-sw-performance-section {
  3535.       padding: 0 !important;
  3536.       border: 1px solid var(--bt-border, rgba(255,255,255,0.07)) !important;
  3537.       border-radius: var(--bt-radius-sm, 6px) !important;
  3538.       background: var(--bt-surface-2, #2A2F35) !important;
  3539.       min-height: 32px !important;
  3540.       overflow: hidden !important;
  3541.     }
  3542.     .bt-sw-label {
  3543.       display: block !important;
  3544.       font-size: 10px !important;
  3545.       font-weight: 600 !important;
  3546.       text-transform: uppercase !important;
  3547.       letter-spacing: 0.08em !important;
  3548.       color: var(--bt-text-3, #6B7480) !important;
  3549.       margin-bottom: 8px !important;
  3550.     }
  3551.     .bt-sw-version-badge {
  3552.       display: inline-block !important;
  3553.       margin-left: 6px !important;
  3554.       padding: 2px 5px !important;
  3555.       border-radius: 999px !important;
  3556.       background: #EF4444 !important;
  3557.       color: #FFFFFF !important;
  3558.       font-size: 10px !important;
  3559.       font-weight: 800 !important;
  3560.       letter-spacing: 0 !important;
  3561.       vertical-align: 1px !important;
  3562.     }
  3563.     .bt-sw-local-badge {
  3564.       display: inline-block !important;
  3565.       margin-left: 6px !important;
  3566.       padding: 2px 6px !important;
  3567.       border-radius: 999px !important;
  3568.       background: #DC2626 !important;
  3569.       color: #FFFFFF !important;
  3570.       font-size: 10px !important;
  3571.       font-weight: 800 !important;
  3572.       letter-spacing: 0.06em !important;
  3573.       vertical-align: 1px !important;
  3574.       text-transform: uppercase !important;
  3575.       box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3) inset !important;
  3576.     }
  3577.     .bt-sw-row {
  3578.       display: flex !important;
  3579.       gap: 6px !important;
  3580.       align-items: center !important;
  3581.       flex-wrap: wrap !important;
  3582.     }
  3583.     .bt-sw-theme-btn {
  3584.       flex: 1 !important;
  3585.       min-width: 0 !important;
  3586.       display: inline-flex !important;
  3587.       align-items: center !important;
  3588.       justify-content: center !important;
  3589.       gap: 5px !important;
  3590.       padding: 8px 6px !important;
  3591.       margin: 0 !important;
  3592.       background: var(--bt-surface-2, #2A2F35) !important;
  3593.       color: var(--bt-text-2, #A8B0BA) !important;
  3594.       border: 1px solid var(--bt-border, rgba(255,255,255,0.07)) !important;
  3595.       border-radius: var(--bt-radius-sm, 6px) !important;
  3596.       cursor: pointer !important;
  3597.       font-family: var(--bt-font) !important;
  3598.       font-size: 11px !important;
  3599.       font-weight: 500 !important;
  3600.       text-transform: none !important;
  3601.       letter-spacing: 0 !important;
  3602.       text-shadow: none !important;
  3603.       box-shadow: none !important;
  3604.       transition: background var(--bt-trans), color var(--bt-trans), border-color var(--bt-trans) !important;
  3605.       line-height: 1 !important;
  3606.     }
  3607.     .bt-sw-theme-btn:hover {
  3608.       background: var(--bt-surface-3, #343A41) !important;
  3609.       color: var(--bt-text, #E3E3E8) !important;
  3610.       transform: none !important;
  3611.     }
  3612.     .bt-sw-theme-btn.selected {
  3613.       background: var(--bt-accent, #F7931A) !important;
  3614.       color: var(--bt-on-accent, #1A1D21) !important;
  3615.       border-color: var(--bt-accent, #F7931A) !important;
  3616.     }
  3617.     .bt-sw-theme-btn svg { width: 14px; height: 14px; }
  3618.     .bt-sw-theme-btn[data-theme="off"].selected {
  3619.       background: var(--bt-danger, #EF4444) !important;
  3620.       color: #FFFFFF !important;
  3621.       border-color: var(--bt-danger, #EF4444) !important;
  3622.     }
  3623.  
  3624.     .bt-sw-toggle {
  3625.       width: 100% !important;
  3626.       display: flex !important;
  3627.       align-items: center !important;
  3628.       justify-content: space-between !important;
  3629.       gap: 10px !important;
  3630.       padding: 3px 8px !important;
  3631.       margin: 0 !important;
  3632.       background: transparent !important;
  3633.       color: var(--bt-text-2, #A8B0BA) !important;
  3634.       border: none !important;
  3635.       border-radius: var(--bt-radius-sm, 6px) !important;
  3636.       cursor: pointer !important;
  3637.       font-family: var(--bt-font) !important;
  3638.       font-size: 11px !important;
  3639.       font-weight: 500 !important;
  3640.       line-height: 1 !important;
  3641.       text-shadow: none !important;
  3642.       box-shadow: none !important;
  3643.       transition: background var(--bt-trans), color var(--bt-trans), border-color var(--bt-trans) !important;
  3644.     }
  3645.     .bt-sw-toggle-spacer {
  3646.       flex: 1 1 auto !important;
  3647.     }
  3648.     .bt-sw-toggle + .bt-sw-toggle {
  3649.       border-top: 1px solid var(--bt-border, rgba(255,255,255,0.07)) !important;
  3650.       border-radius: 0 !important;
  3651.     }
  3652.     .bt-sw-toggle .bt-sw-theme-label {
  3653.       flex: 1 1 auto !important;
  3654.       text-align: left !important;
  3655.       font-size: 11px !important;
  3656.       font-weight: 600 !important;
  3657.       color: inherit !important;
  3658.       white-space: nowrap !important;
  3659.     }
  3660.     .bt-sw-toggle:hover {
  3661.       background: transparent !important;
  3662.       color: var(--bt-text, #E3E3E8) !important;
  3663.       transform: none !important;
  3664.     }
  3665.     /* v3.0.37: toggle ridisegnato — knob perfettamente centrato
  3666.        Math (track 44×24, border-box):
  3667.          track interno = 44×24 (con 1px border incluso)
  3668.          knob 20×20 (border-box, niente bordo) posizionato a top:2 left:2
  3669.          → gap verticale: 2px sopra, 24-2-20 = 2px sotto  ✓ centrato
  3670.          → gap orizzontale OFF: 2px sx, 22px dx
  3671.          → gap orizzontale ON:  translateX(20px) → 22px sx, 2px dx  */
  3672.     .bt-sw-toggle-track {
  3673.       width: 44px !important;
  3674.       height: 24px !important;
  3675.       flex: 0 0 44px !important;
  3676.       position: relative !important;
  3677.       box-sizing: border-box !important;
  3678.       padding: 0 !important;
  3679.       border-radius: 999px !important;
  3680.       background: var(--bt-surface-2, #D8DDE5) !important;
  3681.       border: 1px solid var(--bt-border-2, #99A0AB) !important;
  3682.       transition: background 200ms cubic-bezier(0.4, 0, 0.2, 1),
  3683.                   border-color 200ms cubic-bezier(0.4, 0, 0.2, 1) !important;
  3684.     }
  3685.     .bt-sw-toggle-knob {
  3686.       position: absolute !important;
  3687.       top: 2px !important;
  3688.       left: 2px !important;
  3689.       width: 20px !important;
  3690.       height: 20px !important;
  3691.       box-sizing: border-box !important;
  3692.       border-radius: 50% !important;
  3693.       background: #FFFFFF !important;
  3694.       border: 0 !important;
  3695.       box-shadow: 0 2px 4px rgba(0,0,0,0.18),
  3696.                   0 1px 2px rgba(0,0,0,0.10) !important;
  3697.       transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1),
  3698.                   background 200ms cubic-bezier(0.4, 0, 0.2, 1),
  3699.                   box-shadow 200ms !important;
  3700.     }
  3701.     .bt-sw-toggle:hover .bt-sw-toggle-knob {
  3702.       box-shadow: 0 3px 6px rgba(0,0,0,0.22),
  3703.                   0 1px 2px rgba(0,0,0,0.10) !important;
  3704.     }
  3705.     .bt-sw-toggle.selected {
  3706.       color: var(--bt-text, #E3E3E8) !important;
  3707.     }
  3708.     .bt-sw-toggle.selected .bt-sw-toggle-track {
  3709.       background: var(--bt-accent, #F7931A) !important;
  3710.       border-color: var(--bt-accent, #F7931A) !important;
  3711.     }
  3712.     .bt-sw-toggle.selected .bt-sw-toggle-knob {
  3713.       transform: translateX(20px) !important;
  3714.       background: #FFFFFF !important;
  3715.     }
  3716.     .bt-sw-mobile-toggle.bt-sw-mobile-auto .bt-sw-toggle-track {
  3717.       background: color-mix(in srgb, var(--bt-accent, #F7931A) 45%, var(--bt-surface-3, #343A41)) !important;
  3718.       border-color: color-mix(in srgb, var(--bt-accent, #F7931A) 60%, transparent) !important;
  3719.     }
  3720.     .bt-sw-mobile-toggle.bt-sw-mobile-auto .bt-sw-toggle-knob {
  3721.       transform: translateX(10px) !important;
  3722.     }
  3723.     .bt-sw-toggle:active .bt-sw-toggle-knob {
  3724.       width: 22px !important; /* leggero squash al click per feel tattile */
  3725.     }
  3726.     .bt-sw-toggle.selected:active .bt-sw-toggle-knob {
  3727.       transform: translateX(18px) !important;
  3728.     }
  3729.     .bt-sw-toggle-state {
  3730.       display: none !important;
  3731.     }
  3732.     .bt-sw-toggle.selected .bt-sw-toggle-state {
  3733.       color: var(--bt-accent, #F7931A) !important;
  3734.     }
  3735.  
  3736.     .bt-sw-customize {
  3737.       margin-top: 14px;
  3738.       padding-top: 14px;
  3739.       border-top: 1px solid var(--bt-border, rgba(255,255,255,0.07));
  3740.     }
  3741.     .bt-sw-customize-title {
  3742.       display: block;
  3743.       text-align: center;
  3744.       font-size: 11px;
  3745.       font-weight: 600;
  3746.       letter-spacing: 0.05em;
  3747.       color: var(--bt-text, #E3E3E8);
  3748.       margin-bottom: 12px;
  3749.     }
  3750.  
  3751.     .bt-sw-swatch {
  3752.       width: 26px !important;
  3753.       height: 26px !important;
  3754.       padding: 0 !important;
  3755.       margin: 0 !important;
  3756.       border-radius: 50% !important;
  3757.       border: 2px solid transparent !important;
  3758.       cursor: pointer !important;
  3759.       transition: transform var(--bt-trans), border-color var(--bt-trans) !important;
  3760.       box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15) !important;
  3761.       font-size: 0 !important;
  3762.       text-shadow: none !important;
  3763.     }
  3764.     .bt-sw-swatch:hover { transform: scale(1.12) !important; }
  3765.     .bt-sw-swatch.selected { border-color: var(--bt-text, #E3E3E8) !important; }
  3766.  
  3767.     .bt-sw-auto {
  3768.       width: auto !important;
  3769.       min-width: 44px !important;
  3770.       padding: 0 8px !important;
  3771.       height: 26px !important;
  3772.       border-radius: 13px !important;
  3773.       background: conic-gradient(#ef4444, #f59e0b, #10b981, #3b82f6, #8b5cf6, #ef4444) !important;
  3774.       display: inline-flex !important;
  3775.       align-items: center !important;
  3776.       justify-content: center !important;
  3777.       color: #FFFFFF !important;
  3778.       font-weight: 700 !important;
  3779.       font-size: 9px !important;
  3780.       letter-spacing: 0.06em !important;
  3781.       line-height: 1 !important;
  3782.       text-shadow: 0 1px 2px rgba(0,0,0,0.6) !important;
  3783.       font-family: var(--bt-font) !important;
  3784.     }
  3785.     .bt-sw-auto::before { content: 'AUTO'; }
  3786.  
  3787.     .bt-sw-custom-wrap {
  3788.       position: relative;
  3789.       display: inline-block;
  3790.       width: 26px;
  3791.       height: 26px;
  3792.     }
  3793.     .bt-sw-custom-wrap input[type="color"] {
  3794.       position: absolute !important;
  3795.       inset: 0 !important;
  3796.       width: 100% !important;
  3797.       height: 100% !important;
  3798.       padding: 0 !important;
  3799.       margin: 0 !important;
  3800.       border: 0 !important;
  3801.       border-radius: 50% !important;
  3802.       background: transparent !important;
  3803.       cursor: pointer !important;
  3804.       opacity: 0 !important;
  3805.       box-shadow: none !important;
  3806.     }
  3807.     .bt-sw-custom-display {
  3808.       width: 26px;
  3809.       height: 26px;
  3810.       border-radius: 50%;
  3811.       border: 2px solid transparent;
  3812.       pointer-events: none;
  3813.       box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
  3814.       transition: border-color var(--bt-trans);
  3815.       background: conic-gradient(#ef4444, #f59e0b, #10b981, #3b82f6, #8b5cf6, #ef4444);
  3816.       display: flex;
  3817.       align-items: center;
  3818.       justify-content: center;
  3819.       color: #FFFFFF;
  3820.       font-weight: 700;
  3821.       font-size: 14px;
  3822.       line-height: 1;
  3823.       text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  3824.     }
  3825.     .bt-sw-custom-display::before { content: '+'; }
  3826.     .bt-sw-custom-wrap.selected .bt-sw-custom-display::before { content: ''; }
  3827.     .bt-sw-custom-wrap.selected .bt-sw-custom-display {
  3828.       border-color: var(--bt-text, #E3E3E8);
  3829.     }
  3830.     .bt-sw-info {
  3831.       display: flex !important;
  3832.       flex-direction: column !important;
  3833.       align-items: center !important;
  3834.       gap: 8px !important;
  3835.       margin-top: 14px !important;
  3836.       padding-top: 12px !important;
  3837.       border-top: 1px solid var(--bt-border, rgba(255,255,255,0.07)) !important;
  3838.       color: var(--bt-text-3, #6B7480) !important;
  3839.       font-size: 10px !important;
  3840.     }
  3841.     .bt-sw-credit {
  3842.       color: var(--bt-text-2, #A8B0BA) !important;
  3843.       letter-spacing: 0.02em !important;
  3844.     }
  3845.     .bt-sw-credit strong {
  3846.       color: var(--bt-text, #E3E3E8) !important;
  3847.       font-weight: 700 !important;
  3848.     }
  3849.     .bt-sw-info-meta {
  3850.       width: 100% !important;
  3851.       display: flex !important;
  3852.       align-items: center !important;
  3853.       justify-content: center !important;
  3854.       gap: 8px !important;
  3855.       flex-wrap: wrap !important;
  3856.     }
  3857.     .bt-sw-thread-link,
  3858.     .bt-sw-thread-link:link,
  3859.     .bt-sw-thread-link:visited {
  3860.       display: inline-flex !important;
  3861.       align-items: center !important;
  3862.       gap: 3px !important;
  3863.       color: var(--bt-accent, #F7931A) !important;
  3864.       font-size: 10px !important;
  3865.       font-weight: 600 !important;
  3866.       text-decoration: none !important;
  3867.     }
  3868.     .bt-sw-thread-link:hover,
  3869.     .bt-sw-thread-link:focus {
  3870.       color: var(--bt-accent-h, #FFA733) !important;
  3871.       text-decoration: underline !important;
  3872.     }
  3873.     .bt-sw-installed-version {
  3874.       display: inline-flex !important;
  3875.       align-items: center !important;
  3876.       min-height: 18px !important;
  3877.       padding: 2px 6px !important;
  3878.       border: 1px solid var(--bt-border, rgba(255,255,255,0.07)) !important;
  3879.       border-radius: 999px !important;
  3880.       background: var(--bt-surface-2, #2A2F35) !important;
  3881.       color: var(--bt-text-2, #A8B0BA) !important;
  3882.       font-size: 9px !important;
  3883.       font-weight: 600 !important;
  3884.       letter-spacing: 0.03em !important;
  3885.       white-space: nowrap !important;
  3886.     }
  3887.     :root[data-bt-mobile-lite="true"] #bt-switcher-button,
  3888.     :root[data-bt-mobile-lite="true"] #bt-switcher-panel,
  3889.     :root[data-bt-mobile-lite="true"] .bt-sw-theme-btn,
  3890.     :root[data-bt-mobile-lite="true"] .bt-sw-toggle,
  3891.     :root[data-bt-mobile-lite="true"] .bt-sw-toggle-track,
  3892.     :root[data-bt-mobile-lite="true"] .bt-sw-toggle-knob,
  3893.     :root[data-bt-mobile-lite="true"] .bt-sw-swatch,
  3894.     :root[data-bt-mobile-lite="true"] .bt-sw-custom-display {
  3895.       transition: none !important;
  3896.       animation: none !important;
  3897.       box-shadow: none !important;
  3898.     }
  3899.     :root[data-bt-mobile-lite="true"] #bt-switcher-button:hover,
  3900.     :root[data-bt-mobile-lite="true"] .bt-sw-swatch:hover {
  3901.       transform: none !important;
  3902.     }
  3903.     :root[data-bt-mobile-lite="true"] #bt-switcher-panel {
  3904.       min-width: min(300px, calc(100vw - 24px)) !important;
  3905.       max-width: calc(100vw - 24px) !important;
  3906.     }
  3907.     @media (prefers-reduced-motion: reduce) {
  3908.       :root[data-bt-active="true"] *,
  3909.       :root[data-bt-active="true"] *::before,
  3910.       :root[data-bt-active="true"] *::after,
  3911.       #bt-switcher,
  3912.       #bt-switcher *,
  3913.       #bt-switcher *::before,
  3914.       #bt-switcher *::after {
  3915.         animation: none !important;
  3916.         transition: none !important;
  3917.         scroll-behavior: auto !important;
  3918.       }
  3919.     }
  3920.     /*-- BT_ALWAYS_ON_END --*/
  3921.  
  3922.  
  3923.     /* ============================================================
  3924.        v2.8.3 — LIGHT THREAD POST ALTERNATION, FINAL OVERRIDE
  3925.  
  3926.        Theme-aware version. The post colours come from the active light
  3927.        palette, not from Classic hardcoded blue:
  3928.          --bt-post-bg
  3929.          --bt-post-alt-bg
  3930.          --bt-poster-bg
  3931.          --bt-poster-alt-bg
  3932.  
  3933.        So Classic, Pearl, Cream, Mint and Rose each get their own matching
  3934.        alternation. This block deliberately sits at the END of the theme CSS
  3935.        so it wins over broad rules like .post, .poster_info and td[style].
  3936.        ============================================================ */
  3937.  
  3938.     :root[data-bt-theme="light"] tr.windowbg,
  3939.     :root[data-bt-theme="light"] td.windowbg,
  3940.     :root[data-bt-theme="light"] tr.windowbg > td,
  3941.     :root[data-bt-theme="light"] table.bordercolor tr.windowbg > td,
  3942.     :root[data-bt-theme="light"] table.bordercolor td.windowbg,
  3943.     :root[data-bt-theme="light"] .tborder tr.windowbg > td,
  3944.     :root[data-bt-theme="light"] .tborder td.windowbg {
  3945.       background-color: var(--bt-post-bg, var(--bt-surface-1)) !important;
  3946.       background-image: none !important;
  3947.     }
  3948.  
  3949.     :root[data-bt-theme="light"] tr.windowbg2,
  3950.     :root[data-bt-theme="light"] td.windowbg2,
  3951.     :root[data-bt-theme="light"] tr.windowbg2 > td,
  3952.     :root[data-bt-theme="light"] table.bordercolor tr.windowbg2 > td,
  3953.     :root[data-bt-theme="light"] table.bordercolor td.windowbg2,
  3954.     :root[data-bt-theme="light"] .tborder tr.windowbg2 > td,
  3955.     :root[data-bt-theme="light"] .tborder td.windowbg2 {
  3956.       background-color: var(--bt-post-alt-bg, var(--bt-surface-2)) !important;
  3957.       background-image: none !important;
  3958.     }
  3959.  
  3960.     :root[data-bt-theme="light"] tr.windowbg3,
  3961.     :root[data-bt-theme="light"] td.windowbg3,
  3962.     :root[data-bt-theme="light"] tr.windowbg3 > td,
  3963.     :root[data-bt-theme="light"] table.bordercolor tr.windowbg3 > td,
  3964.     :root[data-bt-theme="light"] table.bordercolor td.windowbg3,
  3965.     :root[data-bt-theme="light"] .tborder tr.windowbg3 > td,
  3966.     :root[data-bt-theme="light"] .tborder td.windowbg3 {
  3967.       background-color: var(--bt-post-bg, var(--bt-surface-1)) !important;
  3968.       background-image: none !important;
  3969.     }
  3970.  
  3971.     /* Visible post body/wrapper. */
  3972.     :root[data-bt-theme="light"] tr.windowbg .td_headerandpost,
  3973.     :root[data-bt-theme="light"] td.windowbg.td_headerandpost,
  3974.     :root[data-bt-theme="light"] td.windowbg .td_headerandpost,
  3975.     :root[data-bt-theme="light"] tr.windowbg .post,
  3976.     :root[data-bt-theme="light"] td.windowbg .post,
  3977.     :root[data-bt-theme="light"] tr.windowbg td.post,
  3978.     :root[data-bt-theme="light"] td.windowbg.post,
  3979.     :root[data-bt-theme="light"] tr.windowbg td[style],
  3980.     :root[data-bt-theme="light"] td.windowbg td[style] {
  3981.       background-color: var(--bt-post-bg, var(--bt-surface-1)) !important;
  3982.       background-image: none !important;
  3983.     }
  3984.  
  3985.     :root[data-bt-theme="light"] tr.windowbg2 .td_headerandpost,
  3986.     :root[data-bt-theme="light"] td.windowbg2.td_headerandpost,
  3987.     :root[data-bt-theme="light"] td.windowbg2 .td_headerandpost,
  3988.     :root[data-bt-theme="light"] tr.windowbg2 .post,
  3989.     :root[data-bt-theme="light"] td.windowbg2 .post,
  3990.     :root[data-bt-theme="light"] tr.windowbg2 td.post,
  3991.     :root[data-bt-theme="light"] td.windowbg2.post,
  3992.     :root[data-bt-theme="light"] tr.windowbg2 td[style],
  3993.     :root[data-bt-theme="light"] td.windowbg2 td[style] {
  3994.       background-color: var(--bt-post-alt-bg, var(--bt-surface-2)) !important;
  3995.       background-image: none !important;
  3996.     }
  3997.  
  3998.     :root[data-bt-theme="light"] tr.windowbg3 .td_headerandpost,
  3999.     :root[data-bt-theme="light"] td.windowbg3.td_headerandpost,
  4000.     :root[data-bt-theme="light"] td.windowbg3 .td_headerandpost,
  4001.     :root[data-bt-theme="light"] tr.windowbg3 .post,
  4002.     :root[data-bt-theme="light"] td.windowbg3 .post,
  4003.     :root[data-bt-theme="light"] tr.windowbg3 td.post,
  4004.     :root[data-bt-theme="light"] td.windowbg3.post,
  4005.     :root[data-bt-theme="light"] tr.windowbg3 td[style],
  4006.     :root[data-bt-theme="light"] td.windowbg3 td[style] {
  4007.       background-color: var(--bt-post-bg, var(--bt-surface-1)) !important;
  4008.       background-image: none !important;
  4009.     }
  4010.  
  4011.     /* Poster/sidebar column: same theme family, slightly deeper for separation. */
  4012.     :root[data-bt-theme="light"] tr.windowbg .poster,
  4013.     :root[data-bt-theme="light"] tr.windowbg .poster_info,
  4014.     :root[data-bt-theme="light"] td.windowbg.poster,
  4015.     :root[data-bt-theme="light"] td.windowbg.poster_info {
  4016.       background-color: var(--bt-poster-bg, var(--bt-post-bg)) !important;
  4017.       background-image: none !important;
  4018.     }
  4019.  
  4020.     :root[data-bt-theme="light"] tr.windowbg2 .poster,
  4021.     :root[data-bt-theme="light"] tr.windowbg2 .poster_info,
  4022.     :root[data-bt-theme="light"] td.windowbg2.poster,
  4023.     :root[data-bt-theme="light"] td.windowbg2.poster_info {
  4024.       background-color: var(--bt-poster-alt-bg, var(--bt-post-alt-bg)) !important;
  4025.       background-image: none !important;
  4026.     }
  4027.  
  4028.     :root[data-bt-theme="light"] tr.windowbg3 .poster,
  4029.     :root[data-bt-theme="light"] tr.windowbg3 .poster_info,
  4030.     :root[data-bt-theme="light"] td.windowbg3.poster,
  4031.     :root[data-bt-theme="light"] td.windowbg3.poster_info {
  4032.       background-color: var(--bt-poster-bg, var(--bt-post-bg)) !important;
  4033.       background-image: none !important;
  4034.     }
  4035.  
  4036.     /* Keep quote/code/input blocks distinct inside alternating posts. */
  4037.     :root[data-bt-theme="light"] tr.windowbg .quote,
  4038.     :root[data-bt-theme="light"] tr.windowbg2 .quote,
  4039.     :root[data-bt-theme="light"] tr.windowbg3 .quote,
  4040.     :root[data-bt-theme="light"] td.windowbg .quote,
  4041.     :root[data-bt-theme="light"] td.windowbg2 .quote,
  4042.     :root[data-bt-theme="light"] td.windowbg3 .quote {
  4043.       background-color: var(--bt-quote-bg) !important;
  4044.       border-left-color: var(--bt-accent) !important;
  4045.     }
  4046.  
  4047.     :root[data-bt-theme="light"] tr.windowbg .code,
  4048.     :root[data-bt-theme="light"] tr.windowbg2 .code,
  4049.     :root[data-bt-theme="light"] tr.windowbg3 .code,
  4050.     :root[data-bt-theme="light"] td.windowbg .code,
  4051.     :root[data-bt-theme="light"] td.windowbg2 .code,
  4052.     :root[data-bt-theme="light"] td.windowbg3 .code {
  4053.       background-color: var(--bt-code-bg) !important;
  4054.     }
  4055.  
  4056.     :root[data-bt-theme="light"] tr.windowbg input,
  4057.     :root[data-bt-theme="light"] tr.windowbg2 input,
  4058.     :root[data-bt-theme="light"] tr.windowbg3 input,
  4059.     :root[data-bt-theme="light"] tr.windowbg textarea,
  4060.     :root[data-bt-theme="light"] tr.windowbg2 textarea,
  4061.     :root[data-bt-theme="light"] tr.windowbg3 textarea,
  4062.     :root[data-bt-theme="light"] tr.windowbg select,
  4063.     :root[data-bt-theme="light"] tr.windowbg2 select,
  4064.     :root[data-bt-theme="light"] tr.windowbg3 select {
  4065.       background-color: var(--bt-input-bg) !important;
  4066.     }
  4067.  
  4068.  
  4069.  
  4070.     /* ============================================================
  4071.        v2.10.7 — TYPOGRAPHY NORMALISATION
  4072.  
  4073.        Goal: keep the modern theme visually close to classic Bitcointalk text
  4074.        sizing, while removing the internal inconsistency introduced by many
  4075.        scattered 10/11/12px overrides. OFF mode remains clean because this CSS
  4076.        block is part of the disabled theme stylesheet, not an always-on rule.
  4077.        ============================================================ */
  4078.  
  4079.     :root {
  4080.       /* v3.0.3 typography pass against measured classic/OFF Bitcointalk:
  4081.          - base/post 13px match classic table and body text
  4082.          - small 11px matches classic smalltext/meta blocks
  4083.          - micro 10px preserves compact auxiliary text
  4084.          - compose 14px keeps the message editor aligned with forum body text
  4085.          - pagelinks stay compact as per-topic micro-navigation */
  4086.       --bt-fs-base: 13px;
  4087.       --bt-fs-small: 11px;
  4088.       --bt-fs-micro: 10px;
  4089.       --bt-fs-post: 13px;
  4090.       --bt-fs-pagelinks: 10px;
  4091.       --bt-fs-compose: 14px;
  4092.       --bt-lh-base: normal;
  4093.       --bt-lh-post: 1.55;
  4094.     }
  4095.  
  4096.     html,
  4097.     body {
  4098.       font-size: var(--bt-fs-base) !important;
  4099.       line-height: var(--bt-lh-base) !important;
  4100.     }
  4101.  
  4102.     body,
  4103.     table,
  4104.     td,
  4105.     th,
  4106.     tr,
  4107.     dd,
  4108.     dt,
  4109.     input,
  4110.     select,
  4111.     textarea,
  4112.     button:not([id^="bt-"]):not([class^="bt-sw-"]) {
  4113.       font-size: var(--bt-fs-base) !important;
  4114.     }
  4115.  
  4116.     table.table_list td,
  4117.     table.table_grid td,
  4118.     table.bordercolor td,
  4119.     .tborder td,
  4120.     [class*="windowbg"],
  4121.     [class*="windowbg"] td,
  4122.     .windowbg,
  4123.     .windowbg2,
  4124.     .windowbg3,
  4125.     .catbg,
  4126.     .catbg2,
  4127.     .titlebg,
  4128.     .titlebg2,
  4129.     [class*="catbg"],
  4130.     [class*="titlebg"] {
  4131.       font-size: var(--bt-fs-base) !important;
  4132.       line-height: var(--bt-lh-base) !important;
  4133.     }
  4134.  
  4135.     .post,
  4136.     td.post,
  4137.     .personalmessage,
  4138.     td.personalmessage,
  4139.     #preview_body,
  4140.     #preview_section,
  4141.     #preview_section td {
  4142.       font-size: var(--bt-fs-post) !important;
  4143.       line-height: var(--bt-lh-post) !important;
  4144.     }
  4145.  
  4146.     .post font[size="1"],
  4147.     td.post font[size="1"],
  4148.     .personalmessage font[size="1"],
  4149.     td.personalmessage font[size="1"],
  4150.     #preview_body font[size="1"],
  4151.     #preview_section font[size="1"],
  4152.     .post font[size="1"] *,
  4153.     td.post font[size="1"] *,
  4154.     .personalmessage font[size="1"] *,
  4155.     td.personalmessage font[size="1"] *,
  4156.     #preview_body font[size="1"] *,
  4157.     #preview_section font[size="1"] * {
  4158.       font-size: var(--bt-fs-small) !important;
  4159.       line-height: normal !important;
  4160.     }
  4161.  
  4162.     /* Classic Bitcointalk uses many small meta labels, but they should not
  4163.        collapse to tiny 10/11px text in the modern layer.
  4164.        v2.10.26: removed .nav / a.nav from this list — those are breadcrumb
  4165.        links (Bitcoin Forum > Economy > Economics > ...) and should render at
  4166.        body size, NOT at small-meta size. Same for .navPages. */
  4167.     .smalltext,
  4168.     .middletext,
  4169.     .small_header,
  4170.     .prevnext,
  4171.     .lastpostcol,
  4172.     .ignored_topic,
  4173.     .utusers,
  4174.     .utusers a,
  4175.     .poster ul,
  4176.     .poster li,
  4177.     .poster_info,
  4178.     td.poster_info,
  4179.     .poster,
  4180.     td.poster,
  4181.     .signature,
  4182.     .quoteheader,
  4183.     .codeheader {
  4184.       font-size: var(--bt-fs-small) !important;
  4185.       line-height: normal !important;
  4186.     }
  4187.     .codeheader {
  4188.       font-size: 10px !important;
  4189.       line-height: 12px !important;
  4190.     }
  4191.  
  4192.     table td.smalltext,
  4193.     table td.middletext,
  4194.     table.bordercolor td.smalltext,
  4195.     table.bordercolor td.middletext,
  4196.     table.tborder td.smalltext,
  4197.     table.tborder td.middletext,
  4198.     .tborder td.smalltext,
  4199.     .tborder td.middletext,
  4200.     [class*="windowbg"] td.smalltext,
  4201.     [class*="windowbg"] td.middletext,
  4202.     td[class*="windowbg"] td.smalltext,
  4203.     td[class*="windowbg"] td.middletext {
  4204.       font-size: var(--bt-fs-small) !important;
  4205.       line-height: normal !important;
  4206.     }
  4207.  
  4208.     /* Breadcrumb (Bitcoin Forum > Economy > Economics > ...) at 14px to
  4209.        keep page navigation legible above a thread. The earlier rule was placed
  4210.        BEFORE the smalltext/middletext block above and lost the source-order
  4211.        battle since SMF puts the breadcrumb inside <td class="middletext">.
  4212.        Now declared after, with higher specificity (.navigate_section.navigate_section
  4213.        and the body-prefixed form for direct .nav containers) so it wins
  4214.        both by specificity AND by source order. */
  4215.     /* v2.10.35: SMF Bitcointalk injects an inline style="font-size: smaller"
  4216.        directly on the breadcrumb container <div class="nav">. That inline
  4217.        style cascades to every descendant via inheritance. CSS rules without
  4218.        !important can never beat an inline style by specificity, but a CSS
  4219.        rule WITH !important does win. The fix: !important on the .nav
  4220.        container itself plus a universal descendant selector so every <a>,
  4221.        <b>, text-wrapping element ends up at body size, including the
  4222.        <b><a>...</a></b> structure SMF actually uses for breadcrumb links
  4223.        and the bare " > " text nodes that float as direct children. */
  4224.     body div.nav.nav,
  4225.     body div.nav.nav *,
  4226.     body .navigate_section.navigate_section,
  4227.     body .navigate_section.navigate_section *,
  4228.     body td.middletext .nav,
  4229.     body td.middletext .nav * {
  4230.       font-size: 14px !important;
  4231.       line-height: 1.4 !important;
  4232.     }
  4233.  
  4234.     /* Static replacements for the former text-scanning news-header pass. */
  4235.     #upshrink_news,
  4236.     #upshrink_news *,
  4237.     #news,
  4238.     #news *,
  4239.     .news,
  4240.     .news *,
  4241.     .newstitle,
  4242.     .newstitle * {
  4243.       font-size: var(--bt-fs-small) !important;
  4244.       line-height: normal !important;
  4245.     }
  4246.  
  4247.     /* Topic rows and board indexes: make titles and row text match the classic
  4248.        density instead of looking smaller than the surrounding chrome. */
  4249.     table.table_list a[href*="topic="],
  4250.     table.bordercolor a[href*="topic="],
  4251.     .tborder a[href*="topic="],
  4252.     [class*="windowbg"] a[href*="topic="],
  4253.     span[id^="msg_"] a,
  4254.     .subject,
  4255.     .topic_subject {
  4256.       font-size: var(--bt-fs-base) !important;
  4257.       line-height: var(--bt-lh-base) !important;
  4258.     }
  4259.  
  4260.     table.table_list .pagelinks a[href*="topic="],
  4261.     table.bordercolor .pagelinks a[href*="topic="],
  4262.     .tborder .pagelinks a[href*="topic="],
  4263.     [class*="windowbg"] .pagelinks a[href*="topic="] {
  4264.       font-size: var(--bt-fs-pagelinks) !important;
  4265.       line-height: 1.15 !important;
  4266.     }
  4267.  
  4268.     /* v2.10.25: per-topic mini pagelinks sit inside <span class="smalltext">
  4269.        (or "middletext"), NOT inside .pagelinks — SMF renders them as raw
  4270.        <a> elements. The earlier rule [class*="windowbg"] a[href*="topic="]
  4271.        was hitting them with --bt-fs-base (13px) before our pagelink rule
  4272.        had a chance to match.
  4273.        v2.10.25 narrows the match to ONLY the smalltext blocks that actually
  4274.        contain topic/board page-jump links, using :has(). The previous v2.10.23
  4275.        form was too broad — it caught every smalltext inside any windowbg cell,
  4276.        including "Show unread posts since last visit", "Watchlist", "Total time
  4277.        logged in:", etc. which live in user-info windowbg cells. */
  4278.     :root[data-bt-active="true"][data-bt-theme] body td[class*="windowbg"] span.smalltext:has(> a[href*="topic="]),
  4279.     :root[data-bt-active="true"][data-bt-theme] body td[class*="windowbg"] span.middletext:has(> a[href*="topic="]),
  4280.     :root[data-bt-active="true"][data-bt-theme] body td[class*="windowbg"] span.smalltext:has(> a[href*="topic="]) > a,
  4281.     :root[data-bt-active="true"][data-bt-theme] body td[class*="windowbg"] span.middletext:has(> a[href*="topic="]) > a {
  4282.       font-size: var(--bt-fs-pagelinks) !important;
  4283.       line-height: 1.2 !important;
  4284.     }
  4285.  
  4286.     :root[data-bt-active="true"] #smfheader td.titlebg2[align="right"],
  4287.     :root[data-bt-active="true"] #smfheader td.titlebg2[align="right"] span.smalltext,
  4288.     :root[data-bt-active="true"] #smfheader td.titlebg2[align="right"] span.smalltext * {
  4289.       font-family: Verdana, Arial, Helvetica, sans-serif !important;
  4290.       font-size: 13px !important;
  4291.       font-weight: 400 !important;
  4292.       line-height: normal !important;
  4293.       letter-spacing: 0 !important;
  4294.     }
  4295.  
  4296.     [class*="catbg"] a,
  4297.     [class*="titlebg"] a,
  4298.     th a,
  4299.     td[class*="catbg"] a,
  4300.     td[class*="titlebg"] a {
  4301.       font-size: var(--bt-fs-base) !important;
  4302.       line-height: var(--bt-lh-base) !important;
  4303.     }
  4304.  
  4305.     /* v3.0.19: Merit summary needs to follow the classic skin, where the
  4306.        document-like content is visibly larger than the modern table density.
  4307.        This is deliberately late in the typography block so it wins over the
  4308.        global 13px table/body normalisation above. */
  4309.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea {
  4310.       font-family: Verdana, Arial, Helvetica, sans-serif !important;
  4311.       font-size: 13px !important;
  4312.       line-height: 1.32 !important;
  4313.     }
  4314.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea p,
  4315.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea div,
  4316.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea span,
  4317.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea table,
  4318.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea tbody,
  4319.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea tr,
  4320.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea td,
  4321.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea th,
  4322.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea ul,
  4323.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea ol,
  4324.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea li,
  4325.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea b,
  4326.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea strong,
  4327.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea a {
  4328.       font-family: Verdana, Arial, Helvetica, sans-serif !important;
  4329.       font-size: 13px !important;
  4330.       line-height: 1.32 !important;
  4331.     }
  4332.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea h1,
  4333.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea h1 * {
  4334.       font-family: Verdana, Arial, Helvetica, sans-serif !important;
  4335.       font-size: 23px !important;
  4336.       line-height: 1.24 !important;
  4337.       letter-spacing: 0 !important;
  4338.     }
  4339.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea h2,
  4340.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea h2 *,
  4341.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea h3,
  4342.     :root[data-bt-active="true"][data-bt-page="merit"] #bodyarea h3 * {
  4343.       font-family: Verdana, Arial, Helvetica, sans-serif !important;
  4344.       font-size: 17px !important;
  4345.       line-height: 1.28 !important;
  4346.       letter-spacing: 0 !important;
  4347.     }
  4348.  
  4349.     /* v3.0: normal form controls use body-sized text; the post-composition
  4350.        message area gets its own larger writing size below. */
  4351.     textarea,
  4352.     textarea[name="message"],
  4353.     #message,
  4354.     #quickReply textarea,
  4355.     #postmodify textarea,
  4356.     #post_modify textarea,
  4357.     input[type="text"],
  4358.     input[type="password"],
  4359.     input[type="email"],
  4360.     input[type="search"],
  4361.     input[type="url"],
  4362.     input[type="number"],
  4363.     select {
  4364.       font-family: var(--bt-font) !important;
  4365.       font-size: 14px !important;
  4366.       line-height: 1.4 !important;
  4367.     }
  4368.  
  4369.     textarea[name="message"],
  4370.     #message,
  4371.     #quickReply textarea,
  4372.     #postmodify textarea[name="message"],
  4373.     #post_modify textarea[name="message"] {
  4374.       font-size: var(--bt-fs-compose) !important;
  4375.       line-height: 1.45 !important;
  4376.     }
  4377.  
  4378.     textarea.editor[name="message"],
  4379.     #postmodify textarea.editor[name="message"],
  4380.     #post_modify textarea.editor[name="message"],
  4381.     form[name="postmodify"] textarea.editor[name="message"],
  4382.     form[action*="action=post"] textarea.editor[name="message"] {
  4383.       font-size: var(--bt-fs-compose) !important;
  4384.       line-height: 1.45 !important;
  4385.     }
  4386.  
  4387.     input[type="submit"],
  4388.     /* v2.10.28: removed topic-action buttons (replybutton/notifybutton/etc.)
  4389.        and .bt-post-action from this universal button rule. They get a more
  4390.        compact treatment in their own rule below — this rule kept overriding
  4391.        the compact sizing because it appears later in the cascade and
  4392.        therefore won at equal specificity. */
  4393.     input[type="button"],
  4394.     input[type="reset"],
  4395.     button:not([id^="bt-"]):not([class^="bt-sw-"]),
  4396.     a.button,
  4397.     .button_submit,
  4398.     .button_reset,
  4399.     .button,
  4400.     a[role="button"],
  4401.     span[role="button"],
  4402.     .poster_info button,
  4403.     .poster_info input[type="button"],
  4404.     .poster_info input[type="submit"],
  4405.     .poster_info a[class*="button"],
  4406.     .poster_info span[class*="button"],
  4407.     .poster_info a[class*="Button"],
  4408.     .poster_info span[class*="Button"] {
  4409.       font-size: var(--bt-fs-small) !important;
  4410.       line-height: 1.2 !important;
  4411.       padding-top: 4px !important;
  4412.       padding-bottom: 4px !important;
  4413.       padding-left: 8px !important;
  4414.       padding-right: 8px !important;
  4415.       min-height: 0 !important;
  4416.     }
  4417.  
  4418.     /* v2.10.28: compact topic action bar (Reply | Unwatch | Notify | ...).
  4419.        Declared after the universal button rule above so it wins by source
  4420.        order at equal specificity, and uses high-specificity selectors anyway
  4421.        (a.replybutton.replybutton — class repetition trick — to outweigh any
  4422.        theme rule that targets just the single class). */
  4423.     a.quotebutton.quotebutton,
  4424.     a.replybutton.replybutton,
  4425.     a.modifybutton.modifybutton,
  4426.     a.removebutton.removebutton,
  4427.     a.reportbutton.reportbutton,
  4428.     a.splitbutton.splitbutton,
  4429.     a.notifybutton.notifybutton,
  4430.     a.markreadbutton.markreadbutton,
  4431.     a.unwatchbutton.unwatchbutton,
  4432.     a.printbutton.printbutton,
  4433.     a.archivebutton.archivebutton,
  4434.     .bt-post-action.bt-post-action {
  4435.       font-size: 11px !important;
  4436.       line-height: 1.3 !important;
  4437.       padding-top: 2px !important;
  4438.       padding-bottom: 2px !important;
  4439.       padding-left: 6px !important;
  4440.       padding-right: 6px !important;
  4441.       margin: 0 2px 0 0 !important;
  4442.       letter-spacing: 0.02em !important;
  4443.       min-height: 0 !important;
  4444.       height: auto !important;
  4445.     }
  4446.  
  4447.     input[type="submit"],
  4448.     .button_submit {
  4449.       padding-top: 5px !important;
  4450.       padding-bottom: 5px !important;
  4451.       padding-left: 10px !important;
  4452.       padding-right: 10px !important;
  4453.       font-size: var(--bt-fs-small) !important;
  4454.       line-height: 1.2 !important;
  4455.     }
  4456.  
  4457.     [class*="maintab_"] a,
  4458.     .dropmenu a,
  4459.     #main_menu a {
  4460.       font-size: 13px !important;
  4461.       line-height: 1.15 !important;
  4462.     }
  4463.  
  4464.     .quote,
  4465.     .code {
  4466.       font-size: var(--bt-fs-small) !important;
  4467.       line-height: 1.3 !important;
  4468.     }
  4469.     .code {
  4470.       font-size: 12px !important;
  4471.       line-height: 1.3 !important;
  4472.     }
  4473.  
  4474.     /* Compose toolbar icon buttons remain compact, but do not shrink text in
  4475.        the editor or in the rest of the compose page. */
  4476.     #bbcBox_message .bt-bbc-icon,
  4477.     .bbc_buttons .bt-bbc-icon,
  4478.     [id^="bbc_"] .bt-bbc-icon {
  4479.       width: 22px !important;
  4480.       height: 22px !important;
  4481.       padding: 3px !important;
  4482.     }
  4483.  
  4484.     #bbcBox_message img,
  4485.     .bbc_buttons img,
  4486.     [id^="bbc_"] img {
  4487.       max-width: 22px !important;
  4488.       max-height: 22px !important;
  4489.     }
  4490.  
  4491.     #smileyBox_message .bt-smiley,
  4492.     #smileyBox_message img,
  4493.     [id^="smileyBox"] .bt-smiley,
  4494.     [id^="smileyBox"] img,
  4495.     #postmodify .bt-smiley,
  4496.     #postmodify img.smiley,
  4497.     #post_modify .bt-smiley,
  4498.     #post_modify img.smiley,
  4499.     form[action*="post"] .bt-smiley,
  4500.     form[action*="post"] img.smiley {
  4501.       font-size: var(--bt-fs-base) !important;
  4502.       width: 14px !important;
  4503.       height: 14px !important;
  4504.       max-width: 14px !important;
  4505.       max-height: 14px !important;
  4506.       line-height: 1 !important;
  4507.       vertical-align: -0.12em !important;
  4508.     }
  4509.  
  4510.     #smileyBox_message .bt-smiley,
  4511.     [id^="smileyBox"] .bt-smiley,
  4512.     #postmodify .bt-smiley,
  4513.     #post_modify .bt-smiley,
  4514.     form[action*="post"] .bt-smiley {
  4515.       display: inline-flex !important;
  4516.       align-items: center !important;
  4517.       justify-content: center !important;
  4518.       width: 18px !important;
  4519.       height: 18px !important;
  4520.       color: var(--bt-text2) !important;
  4521.     }
  4522.  
  4523.     #smileyBox_message .bt-smiley-native,
  4524.     [id^="smileyBox"] .bt-smiley-native,
  4525.     #postmodify .bt-smiley-native,
  4526.     #post_modify .bt-smiley-native,
  4527.     form[action*="post"] .bt-smiley-native {
  4528.       font-family: Apple Color Emoji, Segoe UI Emoji, Noto Color Emoji, sans-serif !important;
  4529.       font-size: 16px !important;
  4530.       line-height: 18px !important;
  4531.       color: initial !important;
  4532.       text-rendering: optimizeLegibility !important;
  4533.     }
  4534.  
  4535.     /* The theme switcher is intentionally separate UI: keep its compact scale
  4536.        and avoid forum-wide typography overrides leaking into it. */
  4537.     #bt-switcher,
  4538.     #bt-switcher * {
  4539.       line-height: 1 !important;
  4540.     }
  4541.  
  4542.     /* =========================================================================
  4543.        v3.0.34 — DEFENSIVE FINAL OVERRIDES (must stay at end of stylesheet)
  4544.        Force 13px on the SMF header date (top-right) and the main navigation
  4545.        menu links. Specificity is bumped with html body and the [data-bt-active]
  4546.        root attribute so these rules beat any earlier --bt-fs-small reset.
  4547.        Source-order placement at the end of the CSS string guarantees they win
  4548.        over rules with equal specificity. */
  4549.     html body #smfheader td.titlebg2[align="right"],
  4550.     html body #smfheader td.titlebg2[align="right"] *,
  4551.     html body #smfheader td.titlebg2[align="right"] span.smalltext,
  4552.     html body #smfheader td.titlebg2[align="right"] span.smalltext * {
  4553.       font-size: 13px !important;
  4554.       line-height: normal !important;
  4555.     }
  4556.  
  4557.     html body [class*="maintab_"],
  4558.     html body [class*="maintab_"] a,
  4559.     html body [class*="maintab_"] a:link,
  4560.     html body [class*="maintab_"] a:visited,
  4561.     html body [class*="maintab_"] a:hover,
  4562.     html body [class*="maintab_"] a:active,
  4563.     html body .dropmenu,
  4564.     html body .dropmenu a,
  4565.     html body #main_menu,
  4566.     html body #main_menu a {
  4567.       font-size: 13px !important;
  4568.     }
  4569.  
  4570.     /* Desktop main navigation: one segmented bar, including the whitespace
  4571.        between SMF table cells. The runtime marks the Help-bearing table once,
  4572.        avoiding repeated relational-selector work during style recalculation. */
  4573.     @media (min-width: 821px) {
  4574.       html[data-bt-mobile-mode="full"] body table.bt-main-nav {
  4575.         width: fit-content !important;
  4576.         max-width: 100% !important;
  4577.         border-spacing: 0 !important;
  4578.         border-collapse: separate !important;
  4579.       }
  4580.       html[data-bt-mobile-mode="full"] body table.bt-main-nav > tbody {
  4581.         display: block !important;
  4582.       }
  4583.       html[data-bt-mobile-mode="full"] body table.bt-main-nav > tbody > tr {
  4584.         display: flex !important;
  4585.         flex-wrap: wrap !important;
  4586.         gap: 0 !important;
  4587.         padding: 0 !important;
  4588.         background: var(--bt-surface-2) !important;
  4589.         border: 1px solid var(--bt-border-2) !important;
  4590.         border-radius: var(--bt-radius) !important;
  4591.         overflow: hidden !important;
  4592.       }
  4593.       html[data-bt-mobile-mode="full"] body table.bt-main-nav > tbody > tr > td[class*="maintab_"] {
  4594.         flex: 0 0 auto !important;
  4595.         margin: 0 !important;
  4596.         padding: 0 !important;
  4597.         border: 0 !important;
  4598.         border-radius: 0 !important;
  4599.       }
  4600.       html[data-bt-mobile-mode="full"] body table.bt-main-nav > tbody > tr > .bt-main-nav-item ~ .bt-main-nav-item {
  4601.         border-inline-start: 1px solid var(--bt-border) !important;
  4602.       }
  4603.       html[data-bt-mobile-mode="full"] body table.bt-main-nav > tbody > tr > td > a {
  4604.         display: inline-flex !important;
  4605.         align-items: center !important;
  4606.         justify-content: center !important;
  4607.         box-sizing: border-box !important;
  4608.         min-height: 26px !important;
  4609.         padding: 3px 14px !important;
  4610.         text-transform: none !important;
  4611.         letter-spacing: 0.01em !important;
  4612.         white-space: nowrap !important;
  4613.       }
  4614.       html[data-bt-mobile-mode="full"] body table.bt-main-nav > tbody > tr > .maintab_active_back > a {
  4615.         color: var(--bt-on-accent) !important;
  4616.         font-weight: 600 !important;
  4617.       }
  4618.       html[data-bt-mobile-mode="full"][data-bt-theme="light"] body table.bt-main-nav > tbody > tr > .maintab_active_back > a {
  4619.         color: var(--bt-nav-active-text, var(--bt-text)) !important;
  4620.       }
  4621.       html[data-bt-mobile-mode="full"] body table.bt-main-nav > tbody > tr > td > a:focus-visible {
  4622.         outline: 2px solid currentColor !important;
  4623.         outline-offset: -4px !important;
  4624.         border-radius: var(--bt-radius-sm) !important;
  4625.       }
  4626.     }
  4627.  
  4628.     /* v3.2.3/v3.2.4: final topic-action-bar override. Keep this after all generic
  4629.        navigation typography so the main nav can stay roomy while Reply /
  4630.        Unwatch / Notify / Add poll / Print remain compact on one line.
  4631.        v3.2.4 marks both mirrortab and maintab action tables with
  4632.        .bt-topic-action-bar, because Bitcointalk uses maintab at the bottom
  4633.        of some topic pages. */
  4634.     html body table.bt-topic-action-bar {
  4635.       display: inline-table !important;
  4636.       width: auto !important;
  4637.       max-width: 100% !important;
  4638.       border-collapse: separate !important;
  4639.       border-spacing: 0 !important;
  4640.       white-space: nowrap !important;
  4641.     }
  4642.     html body table.bt-topic-action-bar tbody {
  4643.       display: inline !important;
  4644.       white-space: nowrap !important;
  4645.     }
  4646.     html body table.bt-topic-action-bar tr {
  4647.       display: inline !important;
  4648.       white-space: nowrap !important;
  4649.     }
  4650.     html body table.bt-topic-action-bar .maintab_first,
  4651.     html body table.bt-topic-action-bar .maintab_last,
  4652.     html body table.bt-topic-action-bar .maintab_active_first,
  4653.     html body table.bt-topic-action-bar .maintab_active_last,
  4654.     html body table.bt-topic-action-bar .mirrortab_first,
  4655.     html body table.bt-topic-action-bar .mirrortab_last,
  4656.     html body table.bt-topic-action-bar .mirrortab_active_first,
  4657.     html body table.bt-topic-action-bar .mirrortab_active_last {
  4658.       display: none !important;
  4659.     }
  4660.     html body table.bt-topic-action-bar [class*="maintab_"],
  4661.     html body table.bt-topic-action-bar [class*="mirrortab_"] {
  4662.       display: inline-block !important;
  4663.       white-space: nowrap !important;
  4664.       padding-top: 1px !important;
  4665.       padding-bottom: 1px !important;
  4666.       border-left: 1px solid var(--bt-border) !important;
  4667.       border-radius: 0 !important;
  4668.     }
  4669.     html body table.bt-topic-action-bar [class*="maintab_"]:first-child,
  4670.     html body table.bt-topic-action-bar [class*="mirrortab_"]:first-child {
  4671.       border-left: 1px solid var(--bt-border) !important;
  4672.       border-top-left-radius: var(--bt-radius-sm) !important;
  4673.       border-bottom-left-radius: var(--bt-radius-sm) !important;
  4674.     }
  4675.     html body table.bt-topic-action-bar [class*="maintab_"]:last-child,
  4676.     html body table.bt-topic-action-bar [class*="mirrortab_"]:last-child {
  4677.       border-top-right-radius: var(--bt-radius-sm) !important;
  4678.       border-bottom-right-radius: var(--bt-radius-sm) !important;
  4679.     }
  4680.     html body table.bt-topic-action-bar [class*="maintab_"] a,
  4681.     html body table.bt-topic-action-bar [class*="maintab_"] a:link,
  4682.     html body table.bt-topic-action-bar [class*="maintab_"] a:visited,
  4683.     html body table.bt-topic-action-bar [class*="maintab_"] a:hover,
  4684.     html body table.bt-topic-action-bar [class*="maintab_"] a:active,
  4685.     html body table.bt-topic-action-bar [class*="mirrortab_"] a,
  4686.     html body table.bt-topic-action-bar [class*="mirrortab_"] a:link,
  4687.     html body table.bt-topic-action-bar [class*="mirrortab_"] a:visited,
  4688.     html body table.bt-topic-action-bar [class*="mirrortab_"] a:hover,
  4689.     html body table.bt-topic-action-bar [class*="mirrortab_"] a:active {
  4690.       display: inline-block !important;
  4691.       padding: 2px 5px !important;
  4692.       font-size: 11px !important;
  4693.       line-height: 1.15 !important;
  4694.       letter-spacing: 0 !important;
  4695.       white-space: nowrap !important;
  4696.     }
  4697.     html body [class*="mirrortab_"] {
  4698.       display: inline-block !important;
  4699.       white-space: nowrap !important;
  4700.       padding-top: 1px !important;
  4701.       padding-bottom: 1px !important;
  4702.       border-left: 1px solid var(--bt-border) !important;
  4703.       border-radius: var(--bt-radius-sm) !important;
  4704.     }
  4705.     html body .mirrortab_first,
  4706.     html body .mirrortab_last,
  4707.     html body .mirrortab_active_first,
  4708.     html body .mirrortab_active_last {
  4709.       display: none !important;
  4710.     }
  4711.     html body [class*="mirrortab_"] a,
  4712.     html body [class*="mirrortab_"] a:link,
  4713.     html body [class*="mirrortab_"] a:visited,
  4714.     html body [class*="mirrortab_"] a:hover,
  4715.     html body [class*="mirrortab_"] a:active {
  4716.       display: inline-block !important;
  4717.       padding: 2px 5px !important;
  4718.       font-size: 11px !important;
  4719.       line-height: 1.15 !important;
  4720.       letter-spacing: 0 !important;
  4721.       white-space: nowrap !important;
  4722.     }
  4723.  
  4724.     /* =========================================================================
  4725.        v3.0.38 — TYPOGRAPHIC HARMONY FINAL PASS
  4726.        Several SMF pages inject large inherited sizes into headings, title bars
  4727.        and post wrappers. Keep the modern theme close to the classic scale:
  4728.        normal content/post text at 13px, compact meta at 11px, compose at 14px.
  4729.        Merit has its own page-specific block above, so it is excluded here. */
  4730.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #bodyarea,
  4731.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #content_section,
  4732.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #main_content_section,
  4733.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body table.bordercolor td,
  4734.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .tborder td,
  4735.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body td.windowbg,
  4736.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body td.windowbg2,
  4737.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body td.windowbg3,
  4738.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .post,
  4739.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body td.post,
  4740.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .personalmessage,
  4741.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body td.personalmessage,
  4742.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #preview_body,
  4743.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #preview_section,
  4744.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #preview_section td {
  4745.       font-size: 13px !important;
  4746.     }
  4747.  
  4748.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="catbg"],
  4749.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="titlebg"],
  4750.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body td[class*="catbg"],
  4751.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body td[class*="titlebg"],
  4752.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body th[class*="catbg"],
  4753.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body th[class*="titlebg"],
  4754.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="catbg"] b,
  4755.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="titlebg"] b,
  4756.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="catbg"] strong,
  4757.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="titlebg"] strong,
  4758.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="catbg"] span:not(.smalltext),
  4759.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="titlebg"] span:not(.smalltext),
  4760.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="catbg"] a,
  4761.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body [class*="titlebg"] a {
  4762.       font-size: 13px !important;
  4763.       line-height: 1.35 !important;
  4764.       letter-spacing: 0 !important;
  4765.     }
  4766.  
  4767.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #bodyarea h1,
  4768.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #content_section h1,
  4769.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #main_content_section h1 {
  4770.       font-size: 18px !important;
  4771.       line-height: 1.25 !important;
  4772.       font-weight: 600 !important;
  4773.       letter-spacing: 0 !important;
  4774.     }
  4775.  
  4776.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #bodyarea h2,
  4777.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #bodyarea h3,
  4778.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #content_section h2,
  4779.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #content_section h3,
  4780.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #main_content_section h2,
  4781.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body #main_content_section h3,
  4782.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .poster h4,
  4783.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .poster h4 a,
  4784.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .poster_info h4,
  4785.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .poster_info h4 a {
  4786.       font-size: 15px !important;
  4787.       line-height: 1.3 !important;
  4788.       font-weight: 600 !important;
  4789.       letter-spacing: 0 !important;
  4790.     }
  4791.  
  4792.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .smalltext,
  4793.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .middletext,
  4794.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .small_header,
  4795.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .prevnext,
  4796.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .lastpostcol,
  4797.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .ignored_topic,
  4798.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .utusers,
  4799.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .poster ul,
  4800.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .poster li,
  4801.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .poster_info,
  4802.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body td.poster_info,
  4803.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .signature,
  4804.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .quoteheader,
  4805.     html[data-bt-active="true"]:not([data-bt-page="merit"]) body .codeheader {
  4806.       font-size: 11px !important;
  4807.       line-height: normal !important;
  4808.     }
  4809.  
  4810.     /* =========================================================================
  4811.        INTEGRATED BITCOINTALK MOBILE VIEW
  4812.        Active whenever Mobile mode is enabled (Auto on mobile/compact screens,
  4813.        Balanced, or Lite) and the theme is ON.
  4814.        ========================================================================= */
  4815.     :root[data-bt-active="true"][data-bt-mobile-lite="true"] {
  4816.       --bt-fs-base: 18px;
  4817.       --bt-fs-small: 15px;
  4818.       --bt-fs-micro: 13px;
  4819.       --bt-fs-post: 20px;
  4820.       --bt-fs-pagelinks: 14px;
  4821.       --bt-fs-compose: 16px;
  4822.       --bt-lh-base: 1.5;
  4823.       --bt-lh-post: 1.6;
  4824.     }
  4825.  
  4826.     html[data-bt-active="true"][data-bt-mobile-lite="true"],
  4827.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body {
  4828.       width: 100% !important;
  4829.       max-width: 100vw !important;
  4830.       overflow-x: hidden !important;
  4831.       margin: 0 !important;
  4832.       padding: 5px !important;
  4833.       box-sizing: border-box !important;
  4834.       font-size: 18px !important;
  4835.       line-height: 1.5 !important;
  4836.     }
  4837.  
  4838.     /* Base Typography for Mobile (18px, strictly excluding switcher UI and signatures) */
  4839.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body #bodyarea,
  4840.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body #content_section,
  4841.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body #main_content_section,
  4842.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body p:not(#bt-switcher *):not(.signature):not(.signature *),
  4843.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body div:not(#bt-switcher):not(#bt-switcher *):not(.post):not(.personalmessage):not(.quote):not(.code):not(.quoteheader):not(.codeheader):not(.smalltext):not(.middletext):not(.signature):not(.signature *),
  4844.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body span:not(#bt-switcher *):not(.smalltext):not(.middletext):not(.prevnext):not(.bt-bbc-icon):not(.bt-topic-icon):not(.bt-smiley):not(.bt-post-action):not(.signature):not(.signature *),
  4845.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body td:not(.post):not(.personalmessage):not(.smalltext):not(.middletext):not(.poster_info):not(.signature):not(.signature *),
  4846.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body th:not(.signature):not(.signature *),
  4847.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body a:not(#bt-switcher *):not(.bt-post-action):not(.poster_info *):not(.signature):not(.signature *) {
  4848.       font-size: 18px !important;
  4849.       line-height: 1.5 !important;
  4850.     }
  4851.  
  4852.     /* Link readability on mobile (underline standard links, keep buttons/tabs/signatures clean) */
  4853.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body a:link:not(.nav):not(.bt-post-action):not(.button):not([class*="button"]):not(#bt-switcher *):not(.signature):not(.signature *),
  4854.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body a:visited:not(.nav):not(.bt-post-action):not(.button):not([class*="button"]):not(#bt-switcher *):not(.signature):not(.signature *) {
  4855.       text-decoration: underline !important;
  4856.     }
  4857.  
  4858.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body [class*="maintab_"] a,
  4859.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body [class*="mirrortab_"] a,
  4860.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body #main_menu a,
  4861.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .dropmenu a,
  4862.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .nav,
  4863.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .nav a,
  4864.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body a:hover {
  4865.       text-decoration: none !important;
  4866.     }
  4867.  
  4868.     /* Main Post Text Sizing (20px) */
  4869.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .post,
  4870.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body td.post,
  4871.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .personalmessage,
  4872.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body td.personalmessage,
  4873.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body #preview_body,
  4874.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body #preview_section,
  4875.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body #preview_section td,
  4876.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .post > div:not(.quote):not(.code):not(.quoteheader):not(.codeheader):not(.signature),
  4877.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .post > td:not(.signature),
  4878.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .post td:not(.signature):not(.signature *),
  4879.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .post span:not(.bt-smiley):not(.bt-post-action):not(.signature):not(.signature *),
  4880.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .post a:not(.bt-post-action):not(.signature):not(.signature *) {
  4881.       font-size: 20px !important;
  4882.       line-height: 1.6 !important;
  4883.     }
  4884.  
  4885.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .post h4,
  4886.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .post h5 {
  4887.       font-size: 22px !important;
  4888.       font-weight: bold !important;
  4889.       line-height: 1.4 !important;
  4890.     }
  4891.  
  4892.     /* Quotes and Code Blocks (17px, theme-aware borders) */
  4893.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quote,
  4894.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quote p,
  4895.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quote div:not(.quoteheader):not(.codeheader),
  4896.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quote span:not(.bt-smiley),
  4897.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quote td,
  4898.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quote a,
  4899.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .code,
  4900.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .code span,
  4901.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .code a {
  4902.       font-size: 17px !important;
  4903.       line-height: 1.4 !important;
  4904.     }
  4905.  
  4906.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quote,
  4907.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .code {
  4908.       border: 1px solid var(--bt-border-2) !important;
  4909.       padding: 8px !important;
  4910.       margin: 6px 0 !important;
  4911.     }
  4912.  
  4913.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quote {
  4914.       border-left: 3px solid var(--bt-accent) !important;
  4915.     }
  4916.  
  4917.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quoteheader,
  4918.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .quoteheader a,
  4919.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .codeheader {
  4920.       font-size: 14px !important;
  4921.       line-height: 1.35 !important;
  4922.     }
  4923.  
  4924.     /* Smalltext & Poster Metadata (15px, strictly excluding .signature and its children!) */
  4925.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .smalltext:not(.signature):not(.signature *),
  4926.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .smalltext span:not(.bt-topic-icon):not(.bt-post-action):not(.signature):not(.signature *),
  4927.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .smalltext a:not(.bt-post-action):not(.signature):not(.signature *),
  4928.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .middletext:not(.signature):not(.signature *),
  4929.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .small_header,
  4930.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .lastpostcol,
  4931.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .lastpostcol a,
  4932.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .poster_info,
  4933.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body td.poster_info,
  4934.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .poster_info a,
  4935.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .poster ul,
  4936.     html[data-bt-active="true"][data-bt-mobile-lite="true"]:not([data-bt-page="merit"]) body .poster li {
  4937.       font-size: 15px !important;
  4938.       line-height: 1.4 !important;
  4939.     }
  4940.  
  4941.     /* Navigation, Headers, and Prev/Next */
  4942.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .nav,
  4943.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body div.nav.nav,
  4944.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body div.nav.nav *,
  4945.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .navigate_section.navigate_section,
  4946.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .navigate_section.navigate_section *,
  4947.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.middletext .nav,
  4948.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.middletext .nav *,
  4949.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body #header,
  4950.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body #footer {
  4951.       font-size: 18px !important;
  4952.       line-height: 1.45 !important;
  4953.       width: 100% !important;
  4954.     }
  4955.  
  4956.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body span.prevnext a:link,
  4957.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body span.prevnext a:visited {
  4958.       font-size: 22px !important;
  4959.     }
  4960.  
  4961.     /* Full-width Main Navigation Menu on Mobile (HOME | HELP | SEARCH | PROFILE | MY MESSAGES | MEMBERS | MORE | LOGOUT) */
  4962.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table:not(.bt-topic-action-bar):has(td[class*="maintab_"]) {
  4963.       display: table !important;
  4964.       width: 100% !important;
  4965.       max-width: 100% !important;
  4966.       margin-left: 0 !important;
  4967.       margin-right: 0 !important;
  4968.       border-collapse: collapse !important;
  4969.       table-layout: auto !important;
  4970.     }
  4971.  
  4972.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table:not(.bt-topic-action-bar):has(td[class*="maintab_"]) > tbody {
  4973.       display: table-row-group !important;
  4974.       width: 100% !important;
  4975.     }
  4976.  
  4977.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table:not(.bt-topic-action-bar):has(td[class*="maintab_"]) > tbody > tr {
  4978.       display: table-row !important;
  4979.       width: 100% !important;
  4980.     }
  4981.  
  4982.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.maintab_first:not(.bt-topic-action-cell),
  4983.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.maintab_last:not(.bt-topic-action-cell),
  4984.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.maintab_active_first:not(.bt-topic-action-cell),
  4985.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.maintab_active_last:not(.bt-topic-action-cell) {
  4986.       display: none !important;
  4987.     }
  4988.  
  4989.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.maintab_back:not(.bt-topic-action-cell),
  4990.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.maintab_active_back:not(.bt-topic-action-cell) {
  4991.       display: table-cell !important;
  4992.       width: auto !important;
  4993.       text-align: center !important;
  4994.       vertical-align: middle !important;
  4995.       border: 1px solid var(--bt-border-2) !important;
  4996.       border-radius: 0 !important;
  4997.     }
  4998.  
  4999.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.maintab_back:not(.bt-topic-action-cell) > a,
  5000.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.maintab_active_back:not(.bt-topic-action-cell) > a {
  5001.       display: block !important;
  5002.       width: 100% !important;
  5003.       box-sizing: border-box !important;
  5004.       text-align: center !important;
  5005.       padding: 8px 6px !important;
  5006.       font-size: 16px !important;
  5007.       white-space: nowrap !important;
  5008.     }
  5009.  
  5010.     /* Layout & Controls */
  5011.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table:not(.signature table):not(.bt-topic-action-bar) {
  5012.       width: 100% !important;
  5013.       max-width: 100% !important;
  5014.       box-sizing: border-box !important;
  5015.     }
  5016.  
  5017.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table.bt-topic-action-bar {
  5018.       max-width: 100% !important;
  5019.       white-space: normal !important;
  5020.     }
  5021.  
  5022.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td:not(.signature td) {
  5023.       word-wrap: break-word !important;
  5024.       overflow-wrap: break-word !important;
  5025.       max-width: 100% !important;
  5026.     }
  5027.  
  5028.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body input:not([type="color"]):not([type="checkbox"]):not([type="radio"]),
  5029.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body textarea,
  5030.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body select {
  5031.       border: 1px solid var(--bt-border-2) !important;
  5032.       font-size: 16px !important;
  5033.       padding: 6px !important;
  5034.     }
  5035.  
  5036.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body textarea {
  5037.       font-family: var(--bt-font), verdana, sans-serif !important;
  5038.       width: 95% !important;
  5039.       max-width: 100% !important;
  5040.       box-sizing: border-box !important;
  5041.     }
  5042.  
  5043.     /* Image Sizing Fixes */
  5044.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body img[src*="buttons"],
  5045.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body img[src*="smiley"],
  5046.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body img[src*="Smileys"],
  5047.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body img[src*="icons"] {
  5048.       max-width: none !important;
  5049.       height: auto !important;
  5050.     }
  5051.  
  5052.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .post img:not(.signature img):not([data-bt-replaced="1"]):not([data-bt-smiley="1"]):not(.smiley):not([src*="Smileys/"]):not([src*="/smileys/"]):not([src*="buttons"]):not([src*="icons"]) {
  5053.       max-width: 80% !important;
  5054.       max-height: 350px !important;
  5055.       width: auto !important;
  5056.       height: auto !important;
  5057.       display: block !important;
  5058.       margin: 8px 0 !important;
  5059.       object-fit: contain !important;
  5060.     }
  5061.  
  5062.     /* Signature Preservation (100% faithful BBCode sizing, alignment, and smooth horizontal scroll) */
  5063.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .signature,
  5064.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body td.signature,
  5065.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body div.signature {
  5066.       display: block !important;
  5067.       width: 100% !important;
  5068.       max-width: 100% !important;
  5069.       overflow-x: auto !important;
  5070.       overflow-y: hidden !important;
  5071.       -webkit-overflow-scrolling: touch !important;
  5072.       margin-top: 10px !important;
  5073.       padding-top: 6px !important;
  5074.       padding-bottom: 4px !important;
  5075.       border-top: 1px solid var(--bt-border) !important;
  5076.       color: var(--bt-text-3) !important;
  5077.       background: transparent !important;
  5078.       font-size: 11px !important;
  5079.       line-height: 1.3em !important;
  5080.       white-space: normal !important;
  5081.       box-sizing: border-box !important;
  5082.     }
  5083.  
  5084.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table.bordercolor .signature table,
  5085.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .tborder .signature table,
  5086.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .signature table {
  5087.       width: max-content !important;
  5088.       max-width: none !important;
  5089.       table-layout: auto !important;
  5090.       border-collapse: separate !important;
  5091.       border-spacing: 0 !important;
  5092.       background: transparent !important;
  5093.       border: none !important;
  5094.       box-shadow: none !important;
  5095.       font-size: inherit !important;
  5096.       line-height: inherit !important;
  5097.       white-space: normal !important;
  5098.     }
  5099.  
  5100.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table.bordercolor .signature tbody,
  5101.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table.bordercolor .signature tr,
  5102.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .signature tbody,
  5103.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .signature tr {
  5104.       font-size: inherit !important;
  5105.       line-height: inherit !important;
  5106.       white-space: normal !important;
  5107.       background: transparent !important;
  5108.     }
  5109.  
  5110.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body table.bordercolor .signature td,
  5111.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .tborder .signature td,
  5112.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body [class*="windowbg"] .signature td,
  5113.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .signature td {
  5114.       width: auto !important;
  5115.       max-width: none !important;
  5116.       padding: 0 2px !important;
  5117.       vertical-align: top !important;
  5118.       font-size: inherit !important;
  5119.       line-height: inherit !important;
  5120.       word-wrap: normal !important;
  5121.       overflow-wrap: normal !important;
  5122.       white-space: nowrap !important;
  5123.       background: transparent !important;
  5124.       border: none !important;
  5125.     }
  5126.  
  5127.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body .signature img {
  5128.       max-width: none !important;
  5129.       height: auto !important;
  5130.       display: inline-block !important;
  5131.     }
  5132.  
  5133.     /* Keep Theme Switcher UI compact on mobile */
  5134.     html[data-bt-active="true"][data-bt-mobile-lite="true"] body #bt-switcher {
  5135.       font-size: 13px !important;
  5136.       line-height: 1 !important;
  5137.     }
  5138.  
  5139.     /* Trust feedback uses Verdana in the classic Bitcointalk theme. Limit the
  5140.        classic face to the received/sent feedback grids, leaving the rest of
  5141.        the modern theme typography unchanged. */
  5142.     html[data-bt-active="true"][data-bt-page="trust"] body #bodyarea > h5 + .tborder > table.bordercolor,
  5143.     html[data-bt-active="true"][data-bt-page="trust"] body #bodyarea > h5 + .tborder > table.bordercolor td,
  5144.     html[data-bt-active="true"][data-bt-page="trust"] body #bodyarea > h5 + .tborder > table.bordercolor td *,
  5145.     html[data-bt-active="true"][data-bt-page="trust"] body #bodyarea > #untrusted > .tborder > table.bordercolor,
  5146.     html[data-bt-active="true"][data-bt-page="trust"] body #bodyarea > #untrusted > .tborder > table.bordercolor td,
  5147.     html[data-bt-active="true"][data-bt-page="trust"] body #bodyarea > #untrusted > .tborder > table.bordercolor td * {
  5148.       font-family: Verdana, Arial, Helvetica, sans-serif !important;
  5149.     }
  5150.   `;
  5151.  
  5152.   // ===========================================================================
  5153.   // CSS injection
  5154.   // ===========================================================================
  5155.  
  5156.   function splitCss(src) {
  5157.     const startMarker = '/*-- BT_ALWAYS_ON_START --*/';
  5158.     const endMarker = '/*-- BT_ALWAYS_ON_END --*/';
  5159.     let theme = '';
  5160.     let always = '';
  5161.     let i = 0;
  5162.     while (i < src.length) {
  5163.       const startIdx = src.indexOf(startMarker, i);
  5164.       if (startIdx === -1) {
  5165.         theme += src.slice(i);
  5166.         break;
  5167.       }
  5168.       theme += src.slice(i, startIdx);
  5169.       const after = startIdx + startMarker.length;
  5170.       const endIdx = src.indexOf(endMarker, after);
  5171.       if (endIdx === -1) {
  5172.         always += src.slice(after);
  5173.         break;
  5174.       }
  5175.       always += src.slice(after, endIdx);
  5176.       i = endIdx + endMarker.length;
  5177.     }
  5178.     return { theme, always };
  5179.   }
  5180.  
  5181.   let themeStyleEl = null;
  5182.   let alwaysStyleEl = null;
  5183.   let fontIdleHandle = null;
  5184.   let fontFrameHandle = null;
  5185.  
  5186.   function cancelPendingFontLoad() {
  5187.     if (fontIdleHandle !== null && typeof cancelIdleCallback === 'function') {
  5188.       cancelIdleCallback(fontIdleHandle);
  5189.     }
  5190.     if (fontFrameHandle !== null) cancelAnimationFrame(fontFrameHandle);
  5191.     fontIdleHandle = null;
  5192.     fontFrameHandle = null;
  5193.     const existing = document.getElementById('bt-fonts');
  5194.     if (existing) existing.remove();
  5195.   }
  5196.  
  5197.   function appendAsyncFontStylesheet() {
  5198.     fontIdleHandle = null;
  5199.     fontFrameHandle = null;
  5200.     if (!isThemeActiveNow() || isMobilePerformanceMode() || document.getElementById('bt-fonts')) return;
  5201.  
  5202.     const link = document.createElement('link');
  5203.     link.id = 'bt-fonts';
  5204.     link.rel = 'stylesheet';
  5205.     link.media = 'print';
  5206.     link.dataset.btAsync = '1';
  5207.     link.href =
  5208.       'https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;500;600;700' +
  5209.       '&family=JetBrains+Mono:wght@400;500&display=swap';
  5210.     link.addEventListener('load', () => {
  5211.       if (isThemeActiveNow() && !isMobilePerformanceMode()) link.media = 'all';
  5212.       else link.remove();
  5213.     }, { once: true });
  5214.     (document.head || document.documentElement).appendChild(link);
  5215.   }
  5216.  
  5217.   function ensureFonts() {
  5218.     // Optional fonts are deferred until the browser is idle and start with a
  5219.     // non-matching media query, so they never block the initial render. OFF
  5220.     // and both performance modes cancel work queued while Full was active.
  5221.     if (!isThemeActiveNow() || isMobilePerformanceMode()) {
  5222.       cancelPendingFontLoad();
  5223.       return;
  5224.     }
  5225.     if (document.getElementById('bt-fonts') || fontIdleHandle !== null || fontFrameHandle !== null) return;
  5226.  
  5227.     if (typeof requestIdleCallback === 'function') {
  5228.       fontIdleHandle = requestIdleCallback(appendAsyncFontStylesheet, { timeout: 1200 });
  5229.     } else {
  5230.       fontFrameHandle = requestAnimationFrame(appendAsyncFontStylesheet);
  5231.     }
  5232.   }
  5233.  
  5234.   function injectCSS() {
  5235.     const { theme, always } = splitCss(css);
  5236.     themeStyleEl = document.createElement('style');
  5237.     themeStyleEl.id = 'bt-theme-css';
  5238.     themeStyleEl.textContent = theme;
  5239.     (document.head || document.documentElement).appendChild(themeStyleEl);
  5240.  
  5241.     alwaysStyleEl = document.createElement('style');
  5242.     alwaysStyleEl.id = 'bt-always-css';
  5243.     alwaysStyleEl.textContent = always;
  5244.     (document.head || document.documentElement).appendChild(alwaysStyleEl);
  5245.  
  5246.     if (isThemeActiveNow()) ensureFonts();
  5247.   }
  5248.   // ===========================================================================
  5249.   // Switcher UI
  5250.   // ===========================================================================
  5251.  
  5252.   const ICONS = {
  5253.     cog: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>',
  5254.     sun: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"/></svg>',
  5255.     moon: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>',
  5256.     monitor: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><path d="M8 21h8M12 17v4"/></svg>',
  5257.     power: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18.36 6.64a9 9 0 1 1-12.73 0"/><line x1="12" y1="2" x2="12" y2="12"/></svg>',
  5258.   };
  5259.  
  5260.   // True for the "Locale" dev build (its @name ends with " Locale"), so the
  5261.   // settings panel can show red version/LOCAL badges to tell it apart from the
  5262.   // published build at a glance.
  5263.   const BT_IS_LOCAL = !!(
  5264.     typeof GM_info !== 'undefined' &&
  5265.     GM_info.script &&
  5266.     / Locale\b/i.test(GM_info.script.name || '')
  5267.   );
  5268.  
  5269.   function buildSwitcher(host) {
  5270.     if (document.getElementById('bt-switcher')) return;
  5271.  
  5272.     const container = document.createElement('div');
  5273.     container.id = 'bt-switcher';
  5274.     container.innerHTML = `
  5275.       <button id="bt-switcher-button" type="button" title="Theme settings" aria-label="Theme settings" aria-controls="bt-switcher-panel" aria-expanded="false">
  5276.         ${ICONS.cog}
  5277.       </button>
  5278.       <div id="bt-switcher-panel" role="dialog" aria-label="Theme settings" aria-hidden="true">
  5279.         <div class="bt-sw-section">
  5280.           <span class="bt-sw-label">Mode${BT_IS_LOCAL ? ` <span class="bt-sw-version-badge">v${SCRIPT_VERSION}</span> <span class="bt-sw-local-badge">LOCAL</span>` : ''}</span>
  5281.           <div class="bt-sw-row">
  5282.             <button type="button" class="bt-sw-theme-btn" data-theme="light" title="Light">
  5283.               ${ICONS.sun}<span class="bt-sw-theme-label">Light</span>
  5284.             </button>
  5285.             <button type="button" class="bt-sw-theme-btn" data-theme="dark" title="Dark">
  5286.               ${ICONS.moon}<span class="bt-sw-theme-label">Dark</span>
  5287.             </button>
  5288.             <button type="button" class="bt-sw-theme-btn" data-theme="system" title="Follow system">
  5289.               ${ICONS.monitor}<span class="bt-sw-theme-label">Auto</span>
  5290.             </button>
  5291.             <button type="button" class="bt-sw-theme-btn" data-theme="off" title="Turn the theme off">
  5292.               ${ICONS.power}<span class="bt-sw-theme-label">OFF</span>
  5293.             </button>
  5294.           </div>
  5295.         </div>
  5296.         <div class="bt-sw-section bt-sw-performance-section">
  5297.           <button type="button" class="bt-sw-toggle bt-sw-mobile-toggle" id="bt-sw-mobile-version" title="Use the lightweight mobile version" aria-pressed="false">
  5298.             <span class="bt-sw-theme-label">Mobile version</span>
  5299.             <span class="bt-sw-toggle-spacer"></span>
  5300.             <span class="bt-sw-toggle-track" aria-hidden="true"><span class="bt-sw-toggle-knob"></span></span>
  5301.             <span class="bt-sw-toggle-state">OFF</span>
  5302.           </button>
  5303.           <button type="button" class="bt-sw-toggle bt-sw-read-toggle" id="bt-sw-read-shading" title="Shade posts you have already read" aria-pressed="true">
  5304.             <span class="bt-sw-theme-label">Read shading</span>
  5305.             <span class="bt-sw-toggle-spacer"></span>
  5306.             <span class="bt-sw-toggle-track" aria-hidden="true"><span class="bt-sw-toggle-knob"></span></span>
  5307.             <span class="bt-sw-toggle-state">ON</span>
  5308.           </button>
  5309.         </div>
  5310.         <div class="bt-sw-customize">
  5311.           <span class="bt-sw-customize-title" id="bt-sw-customize-title">Customise Colours</span>
  5312.           <div class="bt-sw-section">
  5313.             <span class="bt-sw-label">Main</span>
  5314.             <div class="bt-sw-row" id="bt-sw-main-row"></div>
  5315.           </div>
  5316.           <div class="bt-sw-section">
  5317.             <span class="bt-sw-label">Accent</span>
  5318.             <div class="bt-sw-row" id="bt-sw-accent-row"></div>
  5319.           </div>
  5320.         </div>
  5321.         <div class="bt-sw-info" aria-label="Theme information">
  5322.           <span class="bt-sw-credit">Developed with love by <strong>fillippone</strong></span>
  5323.           <div class="bt-sw-info-meta">
  5324.             <a class="bt-sw-thread-link" href="https://bitcointalk.org/index.php?topic=5581374.0" target="_blank" rel="noopener noreferrer">Bitcointalk thread <span aria-hidden="true">&#8599;</span></a>
  5325.             <span class="bt-sw-installed-version">Installed v${SCRIPT_VERSION}${BT_IS_LOCAL ? ' | LOCAL' : ''}</span>
  5326.           </div>
  5327.         </div>
  5328.       </div>
  5329.     `;
  5330.     host.appendChild(container);
  5331.  
  5332.     const btn = container.querySelector('#bt-switcher-button');
  5333.     const panel = container.querySelector('#bt-switcher-panel');
  5334.     let activeCustomColorPreview = null;
  5335.     let colorPreviewFocusTimer = null;
  5336.     let colorPickerWindowBlurred = false;
  5337.  
  5338.     const clearColorPreviewState = () => {
  5339.       activeCustomColorPreview = null;
  5340.       colorPickerWindowBlurred = false;
  5341.       if (colorPreviewFocusTimer) clearTimeout(colorPreviewFocusTimer);
  5342.       colorPreviewFocusTimer = null;
  5343.     };
  5344.     const rollbackCustomColorPreview = () => {
  5345.       if (!activeCustomColorPreview) return;
  5346.       const hadPreview = activeCustomColorPreview.previewed;
  5347.       clearColorPreviewState();
  5348.       // The live preview never writes preferences, so reapplying the stored
  5349.       // theme is a complete rollback, including Auto accent derivation and UI.
  5350.       if (hadPreview) applyTheme();
  5351.     };
  5352.     const beginCustomColorSession = (input) => {
  5353.       if (!input || !input.matches('input[type="color"][data-target]')) return;
  5354.       if (activeCustomColorPreview && activeCustomColorPreview.input === input) return;
  5355.       activeCustomColorPreview = {
  5356.         kind: input.dataset.target,
  5357.         input,
  5358.         previewed: false,
  5359.       };
  5360.       colorPickerWindowBlurred = false;
  5361.     };
  5362.     const setSwitcherOpen = (open, restoreFocus = false) => {
  5363.       container.classList.toggle('open', open);
  5364.       btn.setAttribute('aria-expanded', open ? 'true' : 'false');
  5365.       panel.setAttribute('aria-hidden', open ? 'false' : 'true');
  5366.       if (!open && restoreFocus) btn.focus();
  5367.     };
  5368.     const activateSwitcher = (e) => {
  5369.       if (e && typeof e.button === 'number' && e.button !== 0) return;
  5370.       e.stopPropagation();
  5371.       const currentPref = getPref(KEY_THEME, DEFAULT_THEME);
  5372.       if (currentPref === 'off') {
  5373.         const previousMode = getEffectiveMobileMode();
  5374.         const prior = getPref(KEY_THEME_PRIOR, 'dark');
  5375.         setPref(KEY_THEME, prior);
  5376.         applyTheme();
  5377.         reconcileMobileRuntime(previousMode, getEffectiveMobileMode(), true);
  5378.         return;
  5379.       }
  5380.       setSwitcherOpen(!container.classList.contains('open'));
  5381.     };
  5382.  
  5383.     // Resolve pointer actions on release, after checking that the pointer did
  5384.     // not turn into a swipe. This preserves immediate one-tap controls without
  5385.     // firing a button while the user scrolls the internally scrollable panel.
  5386.     const MAX_PRESS_MOVE = 8;
  5387.     const installSafePointerActivation = (surface, resolveControl, activate) => {
  5388.       let pending = null;
  5389.       let suppressedControl = null;
  5390.       let suppressionTimer = null;
  5391.  
  5392.       const clearPending = () => { pending = null; };
  5393.       surface.addEventListener('pointerdown', (e) => {
  5394.         if (typeof e.button === 'number' && e.button !== 0) return;
  5395.         if (e.isPrimary === false) return;
  5396.         const control = resolveControl(e);
  5397.         if (!control || control.disabled) return;
  5398.         pending = {
  5399.           control,
  5400.           pointerId: e.pointerId,
  5401.           startX: e.clientX,
  5402.           startY: e.clientY,
  5403.           moved: false,
  5404.         };
  5405.       });
  5406.       surface.addEventListener('pointermove', (e) => {
  5407.         if (!pending || e.pointerId !== pending.pointerId) return;
  5408.         if (Math.hypot(e.clientX - pending.startX, e.clientY - pending.startY) > MAX_PRESS_MOVE) {
  5409.           pending.moved = true;
  5410.         }
  5411.       });
  5412.       surface.addEventListener('pointercancel', clearPending);
  5413.       surface.addEventListener('pointerup', (e) => {
  5414.         if (!pending || e.pointerId !== pending.pointerId) return;
  5415.         const press = pending;
  5416.         clearPending();
  5417.         if (resolveControl(e) !== press.control || !press.control.isConnected) return;
  5418.  
  5419.         e.preventDefault();
  5420.         e.stopPropagation();
  5421.         suppressedControl = press.control;
  5422.         if (suppressionTimer) clearTimeout(suppressionTimer);
  5423.         suppressionTimer = setTimeout(() => {
  5424.           suppressedControl = null;
  5425.           suppressionTimer = null;
  5426.         }, 1000);
  5427.         // A mouse drag can still emit a compatible click when it is released
  5428.         // over its starting button. Suppress that click without activating.
  5429.         if (press.moved) return;
  5430.         activate(press.control, e);
  5431.       });
  5432.       surface.addEventListener('click', (e) => {
  5433.         // Keyboard and assistive-technology clicks have detail 0 and continue
  5434.         // through the normal click handlers.
  5435.         if (!suppressedControl || e.detail === 0) return;
  5436.         const control = resolveControl(e);
  5437.         if (control !== suppressedControl) return;
  5438.         e.preventDefault();
  5439.         e.stopImmediatePropagation();
  5440.         suppressedControl = null;
  5441.         if (suppressionTimer) clearTimeout(suppressionTimer);
  5442.         suppressionTimer = null;
  5443.       }, true);
  5444.     };
  5445.  
  5446.     installSafePointerActivation(
  5447.       btn,
  5448.       (e) => (e.target === btn || btn.contains(e.target) ? btn : null),
  5449.       (_control, e) => activateSwitcher(e)
  5450.     );
  5451.     btn.addEventListener('click', (e) => {
  5452.       activateSwitcher(e);
  5453.     });
  5454.  
  5455.     installSafePointerActivation(
  5456.       panel,
  5457.       (e) => {
  5458.         const control = e.target.closest && e.target.closest('button');
  5459.         return control && panel.contains(control) ? control : null;
  5460.       },
  5461.       control => control.click()
  5462.     );
  5463.  
  5464.     document.addEventListener('click', (e) => {
  5465.       if (!container.contains(e.target)) {
  5466.         rollbackCustomColorPreview();
  5467.         setSwitcherOpen(false);
  5468.       }
  5469.     });
  5470.     document.addEventListener('keydown', (e) => {
  5471.       if (e.key === 'Escape' && container.classList.contains('open')) {
  5472.         rollbackCustomColorPreview();
  5473.         setSwitcherOpen(false, true);
  5474.       }
  5475.     });
  5476.  
  5477.     // A native colour picker does not have a uniform close signal across
  5478.     // browsers. Cover its explicit cancel event, focus changes, Escape, and
  5479.     // the common window blur/focus cycle used by operating-system pickers.
  5480.     panel.addEventListener('pointerdown', (e) => beginCustomColorSession(e.target), true);
  5481.     panel.addEventListener('click', (e) => beginCustomColorSession(e.target), true);
  5482.     panel.addEventListener('cancel', (e) => {
  5483.       if (activeCustomColorPreview && e.target === activeCustomColorPreview.input) {
  5484.         rollbackCustomColorPreview();
  5485.       }
  5486.     }, true);
  5487.     panel.addEventListener('focusout', (e) => {
  5488.       if (!activeCustomColorPreview || e.target !== activeCustomColorPreview.input) return;
  5489.       if (colorPreviewFocusTimer) clearTimeout(colorPreviewFocusTimer);
  5490.       colorPreviewFocusTimer = setTimeout(() => {
  5491.         colorPreviewFocusTimer = null;
  5492.         if (
  5493.           activeCustomColorPreview &&
  5494.           activeCustomColorPreview.previewed &&
  5495.           document.activeElement !== activeCustomColorPreview.input
  5496.         ) {
  5497.           rollbackCustomColorPreview();
  5498.         }
  5499.       }, 0);
  5500.     });
  5501.     window.addEventListener('blur', () => {
  5502.       if (activeCustomColorPreview) colorPickerWindowBlurred = true;
  5503.     });
  5504.     window.addEventListener('focus', () => {
  5505.       if (!activeCustomColorPreview || !colorPickerWindowBlurred) return;
  5506.       if (colorPreviewFocusTimer) clearTimeout(colorPreviewFocusTimer);
  5507.       colorPreviewFocusTimer = setTimeout(() => {
  5508.         colorPreviewFocusTimer = null;
  5509.         rollbackCustomColorPreview();
  5510.       }, 100);
  5511.     });
  5512.  
  5513.     container.querySelectorAll('.bt-sw-theme-btn').forEach(b => {
  5514.       b.addEventListener('click', () => {
  5515.         if (!b.dataset.theme) return;
  5516.         const wasActive = isThemeActiveNow();
  5517.         const previousMode = getEffectiveMobileMode();
  5518.         const choice = b.dataset.theme;
  5519.         if (choice === 'off') {
  5520.           const current = getPref(KEY_THEME, DEFAULT_THEME);
  5521.           if (current === 'off') {
  5522.             const prior = getPref(KEY_THEME_PRIOR, 'dark');
  5523.             setPref(KEY_THEME, prior);
  5524.           } else {
  5525.             setPref(KEY_THEME_PRIOR, current);
  5526.             setPref(KEY_THEME, 'off');
  5527.           }
  5528.           setSwitcherOpen(false);
  5529.         } else {
  5530.           setPref(KEY_THEME, choice);
  5531.         }
  5532.         applyTheme();
  5533.         reconcileMobileRuntime(
  5534.           previousMode,
  5535.           getEffectiveMobileMode(),
  5536.           !wasActive && isThemeActiveNow()
  5537.         );
  5538.       });
  5539.     });
  5540.  
  5541.     ensureSettingsToggleControls(container);
  5542.  
  5543.     function handleSwatchClick(kind) {
  5544.       return (e) => {
  5545.         const swatch = e.target.closest(`[data-${kind}]`);
  5546.         if (!swatch || swatch.tagName === 'INPUT') return;
  5547.         const themeNow = getEffectiveTheme(getPref(KEY_THEME, DEFAULT_THEME));
  5548.         if (themeNow === 'off') return;
  5549.         const storageKey = kind === 'main'
  5550.           ? (themeNow === 'dark' ? KEY_MAIN_DARK : KEY_MAIN_LIGHT)
  5551.           : (themeNow === 'dark' ? KEY_ACCENT_DARK : KEY_ACCENT_LIGHT);
  5552.         setPref(storageKey, swatch.dataset[kind]);
  5553.         applyTheme();
  5554.       };
  5555.     }
  5556.     container.querySelector('#bt-sw-main-row').addEventListener('click', handleSwatchClick('main'));
  5557.     container.querySelector('#bt-sw-accent-row').addEventListener('click', handleSwatchClick('accent'));
  5558.  
  5559.     function getCustomColorChange(kind, input) {
  5560.       const themeNow = getEffectiveTheme(getPref(KEY_THEME, DEFAULT_THEME));
  5561.       if (themeNow === 'off') return null;
  5562.       const storageKey = kind === 'main'
  5563.         ? (themeNow === 'dark' ? KEY_MAIN_DARK : KEY_MAIN_LIGHT)
  5564.         : (themeNow === 'dark' ? KEY_ACCENT_DARK : KEY_ACCENT_LIGHT);
  5565.       const customStorageKey = kind === 'main'
  5566.         ? (themeNow === 'dark' ? KEY_MAIN_DARK_CUSTOM : KEY_MAIN_LIGHT_CUSTOM)
  5567.         : (themeNow === 'dark' ? KEY_ACCENT_DARK_CUSTOM : KEY_ACCENT_LIGHT_CUSTOM);
  5568.       const fallback = kind === 'main'
  5569.         ? (themeNow === 'dark' ? DEFAULT_CUSTOM_MAIN_DARK : DEFAULT_CUSTOM_MAIN_LIGHT)
  5570.         : (themeNow === 'dark' ? DEFAULT_CUSTOM_ACCENT_DARK : DEFAULT_CUSTOM_ACCENT_LIGHT);
  5571.       return {
  5572.         themeNow,
  5573.         storageKey,
  5574.         customStorageKey,
  5575.         safeValue: sanitizeHex(input.value, fallback),
  5576.       };
  5577.     }
  5578.  
  5579.     function previewCustomColor(kind, input, change) {
  5580.       const root = document.documentElement;
  5581.       if (kind === 'main') {
  5582.         const palette = deriveMainPalette(change.safeValue, change.themeNow, 'custom');
  5583.         Object.entries(palette).forEach(([k, v]) => root.style.setProperty(toCssVar(k), v));
  5584.         root.setAttribute('data-bt-main', 'custom');
  5585.  
  5586.         // Auto accent follows a custom Main colour during the drag as well.
  5587.         if (getAccentKey(change.themeNow) === 'auto') {
  5588.           const accent = deriveAccent(
  5589.             deriveAutoAccent(change.safeValue, change.themeNow, 'custom')
  5590.           );
  5591.           root.style.setProperty('--bt-accent', accent.base);
  5592.           root.style.setProperty('--bt-accent-h', accent.hover);
  5593.           root.style.setProperty('--bt-accent-a', accent.active);
  5594.           root.style.setProperty('--bt-on-accent', accent.onText);
  5595.         }
  5596.       } else {
  5597.         const accent = deriveAccent(change.safeValue);
  5598.         root.setAttribute('data-bt-accent', 'custom');
  5599.         root.style.setProperty('--bt-accent', accent.base);
  5600.         root.style.setProperty('--bt-accent-h', accent.hover);
  5601.         root.style.setProperty('--bt-accent-a', accent.active);
  5602.         root.style.setProperty('--bt-on-accent', accent.onText);
  5603.       }
  5604.  
  5605.       const row = input.closest('.bt-sw-row');
  5606.       if (!row) return;
  5607.       row.dataset.btPreviewing = '1';
  5608.       row.querySelectorAll('.bt-sw-swatch.selected').forEach(swatch => {
  5609.         swatch.classList.remove('selected');
  5610.       });
  5611.       const wrap = input.closest('.bt-sw-custom-wrap');
  5612.       if (!wrap) return;
  5613.       wrap.classList.add('selected');
  5614.       const display = wrap.querySelector('.bt-sw-custom-display');
  5615.       if (display) display.style.background = change.safeValue;
  5616.     }
  5617.  
  5618.     function handleColorInput(kind) {
  5619.       return (e) => {
  5620.         if (!e.target.matches(`input[type="color"][data-target="${kind}"]`)) return;
  5621.         const change = getCustomColorChange(kind, e.target);
  5622.         if (!change) return;
  5623.         beginCustomColorSession(e.target);
  5624.         activeCustomColorPreview.previewed = true;
  5625.         // Do not call applyTheme() here: it rebuilds the swatch row and would
  5626.         // remove the active color input before the drag can continue.
  5627.         previewCustomColor(kind, e.target, change);
  5628.       };
  5629.     }
  5630.  
  5631.     function handleColorChange(kind) {
  5632.       return (e) => {
  5633.         if (!e.target.matches(`input[type="color"][data-target="${kind}"]`)) return;
  5634.         const change = getCustomColorChange(kind, e.target);
  5635.         if (!change) return;
  5636.         const input = e.target;
  5637.         // WebKit may emit change more than once while its native picker is
  5638.         // still being manipulated. Keep the original input node connected:
  5639.         // rebuilding this row here detaches the picker after its first value.
  5640.         beginCustomColorSession(input);
  5641.         previewCustomColor(kind, input, change);
  5642.         setPref(change.customStorageKey, change.safeValue);
  5643.         setPref(change.storageKey, 'custom');
  5644.         const row = input.closest('.bt-sw-row');
  5645.         if (row) {
  5646.           row.dataset.btSwatchSignature = [
  5647.             kind,
  5648.             change.themeNow,
  5649.             'custom',
  5650.             change.safeValue,
  5651.             change.safeValue,
  5652.           ].join('|');
  5653.           delete row.dataset.btPreviewing;
  5654.         }
  5655.         clearColorPreviewState();
  5656.       };
  5657.     }
  5658.     container.querySelector('#bt-sw-main-row').addEventListener('input', handleColorInput('main'));
  5659.     container.querySelector('#bt-sw-accent-row').addEventListener('input', handleColorInput('accent'));
  5660.     container.querySelector('#bt-sw-main-row').addEventListener('change', handleColorChange('main'));
  5661.     container.querySelector('#bt-sw-accent-row').addEventListener('change', handleColorChange('accent'));
  5662.  
  5663.     updateSwitcherFromPreferences();
  5664.   }
  5665.  
  5666.   function injectSwitcher() {
  5667.     const host =
  5668.       document.body ||
  5669.       document.getElementById('upper_section') ||
  5670.       document.getElementById('header') ||
  5671.       document.documentElement;
  5672.     if (host) buildSwitcher(host);
  5673.   }
  5674.   // ===========================================================================
  5675.   // Integrated Safari flash guard
  5676.   // ===========================================================================
  5677.  
  5678.   function getHoldBackground() {
  5679.     const pref = getPref(KEY_THEME, DEFAULT_THEME);
  5680.     const effective = getEffectiveTheme(pref);
  5681.     if (effective === 'off') {
  5682.       clearNavigationHold();
  5683.       return null;
  5684.     }
  5685.     const fallback = effective === 'dark' ? DEFAULT_CUSTOM_MAIN_DARK : DEFAULT_CUSTOM_MAIN_LIGHT;
  5686.     const holdUntil = Number(ssGet(NAV_UNTIL_SESSION_KEY) || 0);
  5687.     const fromSession = holdUntil >= Date.now() ? ssGet(NAV_BG_SESSION_KEY) : null;
  5688.     if (fromSession) return sanitizeHex(fromSession, fallback);
  5689.     clearNavigationHold();
  5690.     return sanitizeHex(getActiveMainHex(effective) || fallback, fallback);
  5691.   }
  5692.  
  5693.   function getCurrentThemeBackground() {
  5694.     const root = document.documentElement;
  5695.     const fallback = getHoldBackground() || DEFAULT_CUSTOM_MAIN_DARK;
  5696.     try {
  5697.       const inlineVar = root && root.style ? root.style.getPropertyValue('--bt-bg').trim() : '';
  5698.       if (inlineVar) return sanitizeHex(inlineVar, fallback);
  5699.     } catch (e) {}
  5700.     try {
  5701.       const computedVar = getComputedStyle(root).getPropertyValue('--bt-bg').trim();
  5702.       if (computedVar) return sanitizeHex(computedVar, fallback);
  5703.     } catch (e) {}
  5704.     return sanitizeHex(fallback, DEFAULT_CUSTOM_MAIN_DARK);
  5705.   }
  5706.  
  5707.   function holdCss(bg, revealedSelector) {
  5708.     bg = sanitizeHex(bg, getEffectiveTheme(getPref(KEY_THEME, DEFAULT_THEME)) === 'light' ? DEFAULT_CUSTOM_MAIN_LIGHT : DEFAULT_CUSTOM_MAIN_DARK);
  5709.     const scheme = getEffectiveTheme(getPref(KEY_THEME, DEFAULT_THEME)) === 'light' ? 'light' : 'dark';
  5710.     return `
  5711.       html${revealedSelector} {
  5712.         background: ${bg} !important;
  5713.         color-scheme: ${scheme} !important;
  5714.       }
  5715.       html${revealedSelector}::before {
  5716.         content: '' !important;
  5717.         position: fixed !important;
  5718.         inset: 0 !important;
  5719.         width: 100vw !important;
  5720.         height: 100vh !important;
  5721.         background: ${bg} !important;
  5722.         z-index: 2147483647 !important;
  5723.         pointer-events: none !important;
  5724.       }
  5725.       html${revealedSelector} body {
  5726.         visibility: hidden !important;
  5727.         opacity: 0 !important;
  5728.         background: ${bg} !important;
  5729.       }
  5730.     `;
  5731.   }
  5732.  
  5733.   function injectTransientStyle(id, cssText) {
  5734.     let style = document.getElementById(id);
  5735.     if (!style) {
  5736.       style = document.createElement('style');
  5737.       style.id = id;
  5738.       (document.documentElement || document.head || document.body).appendChild(style);
  5739.     }
  5740.     style.textContent = cssText;
  5741.     return style;
  5742.   }
  5743.  
  5744.   function removeTransientStyle(id) {
  5745.     const style = document.getElementById(id);
  5746.     if (style) style.remove();
  5747.   }
  5748.  
  5749.   let incomingRevealTimer = null;
  5750.   let outgoingRestoreTimer = null;
  5751.  
  5752.   function clearNavigationHold() {
  5753.     ssRemove(NAV_UNTIL_SESSION_KEY);
  5754.     ssRemove(NAV_BG_SESSION_KEY);
  5755.   }
  5756.  
  5757.   function clearOutgoingRestoreTimer() {
  5758.     if (outgoingRestoreTimer !== null) clearTimeout(outgoingRestoreTimer);
  5759.     outgoingRestoreTimer = null;
  5760.   }
  5761.  
  5762.   function releaseOutgoingHold() {
  5763.     clearOutgoingRestoreTimer();
  5764.     removeTransientStyle(OUTGOING_HOLD_STYLE_ID);
  5765.     clearNavigationHold();
  5766.   }
  5767.  
  5768.   function holdPaint() {
  5769.     if (document.readyState === 'complete') return false;
  5770.     const bg = getHoldBackground();
  5771.     if (!bg) return false;
  5772.  
  5773.     const root = document.documentElement;
  5774.     const holdStyle = injectTransientStyle(
  5775.       INCOMING_HOLD_STYLE_ID,
  5776.       holdCss(bg, `:not([${HOLD_REVEALED_ATTR}])`)
  5777.     );
  5778.  
  5779.     if (typeof MutationObserver !== 'undefined') {
  5780.       const observer = new MutationObserver(() => {
  5781.         if (!document.getElementById(INCOMING_HOLD_STYLE_ID)) {
  5782.           try { document.documentElement.appendChild(holdStyle); } catch (e) {}
  5783.         }
  5784.       });
  5785.       try {
  5786.         observer.observe(root, { childList: true });
  5787.         holdStyle._btObserver = observer;
  5788.       } catch (e) {}
  5789.     }
  5790.  
  5791.     incomingRevealTimer = setTimeout(() => revealNow(), 1500);
  5792.     return true;
  5793.   }
  5794.  
  5795.   function revealNow() {
  5796.     if (incomingRevealTimer !== null) clearTimeout(incomingRevealTimer);
  5797.     incomingRevealTimer = null;
  5798.     document.documentElement.setAttribute(HOLD_REVEALED_ATTR, '');
  5799.     const holdStyle = document.getElementById(INCOMING_HOLD_STYLE_ID);
  5800.     if (holdStyle && holdStyle._btObserver) {
  5801.       try { holdStyle._btObserver.disconnect(); } catch (e) {}
  5802.     }
  5803.     removeTransientStyle(INCOMING_HOLD_STYLE_ID);
  5804.     clearNavigationHold();
  5805.   }
  5806.  
  5807.   function releasePaint() {
  5808.     revealNow();
  5809.   }
  5810.  
  5811.   function markNavigationHold(bg) {
  5812.     const effective = getEffectiveTheme(getPref(KEY_THEME, DEFAULT_THEME));
  5813.     const fallback = effective === 'light' ? DEFAULT_CUSTOM_MAIN_LIGHT : DEFAULT_CUSTOM_MAIN_DARK;
  5814.     ssSet(NAV_UNTIL_SESSION_KEY, String(Date.now() + NAV_HOLD_SESSION_MS));
  5815.     ssSet(NAV_BG_SESSION_KEY, sanitizeHex(bg, fallback));
  5816.   }
  5817.  
  5818.   function primeNavigationHold() {
  5819.     if (getPref(KEY_THEME, DEFAULT_THEME) === 'off') {
  5820.       releaseOutgoingHold();
  5821.       return false;
  5822.     }
  5823.     const bg = getCurrentThemeBackground();
  5824.     markNavigationHold(bg);
  5825.     return true;
  5826.   }
  5827.  
  5828.   function applyOutgoingHold(restoreAfterMs = OUTGOING_UNLOAD_FAILSAFE_MS) {
  5829.     if (!primeNavigationHold()) return false;
  5830.     const bg = getCurrentThemeBackground();
  5831.     injectTransientStyle(OUTGOING_HOLD_STYLE_ID, holdCss(bg, ''));
  5832.     clearOutgoingRestoreTimer();
  5833.     if (restoreAfterMs !== null) {
  5834.       outgoingRestoreTimer = setTimeout(
  5835.         () => releaseOutgoingHold(),
  5836.         restoreAfterMs
  5837.       );
  5838.     }
  5839.     return true;
  5840.   }
  5841.  
  5842.   function isPlainPrimaryActivation(e) {
  5843.     if (e.defaultPrevented) return false;
  5844.     if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;
  5845.     if (typeof e.button === 'number' && e.button !== 0) return false;
  5846.     return true;
  5847.   }
  5848.  
  5849.   function shouldHoldForLink(a, e) {
  5850.     if (!a || !isPlainPrimaryActivation(e)) return false;
  5851.     if (!targetsCurrentBrowsingContext(a.getAttribute('target'))) return false;
  5852.     if (a.hasAttribute('download')) return false;
  5853.  
  5854.     const href = a.getAttribute('href') || '';
  5855.     if (!href) return false;
  5856.     if (href.startsWith('#')) return false;
  5857.     if (/^\s*javascript:/i.test(href)) return false;
  5858.  
  5859.     let url;
  5860.     try {
  5861.       url = new URL(href, window.location.href);
  5862.     } catch (e2) {
  5863.       return false;
  5864.     }
  5865.     if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
  5866.  
  5867.     if (
  5868.       url.origin === window.location.origin &&
  5869.       url.pathname === window.location.pathname &&
  5870.       url.search === window.location.search &&
  5871.       url.hash
  5872.     ) {
  5873.       return false;
  5874.     }
  5875.     return true;
  5876.   }
  5877.  
  5878.   function targetsCurrentBrowsingContext(target) {
  5879.     target = String(target || '').trim().toLowerCase();
  5880.     if (!target || target === '_self' || target === '_parent' || target === '_top') return true;
  5881.     return !!window.name && target === String(window.name).toLowerCase();
  5882.   }
  5883.  
  5884.   function shouldHoldForForm(form, e) {
  5885.     if (!form || e.defaultPrevented) return false;
  5886.     const submitter = e.submitter || null;
  5887.     const targetOverride = submitter && submitter.getAttribute
  5888.       ? submitter.getAttribute('formtarget')
  5889.       : null;
  5890.     const target = targetOverride !== null ? targetOverride : form.getAttribute('target');
  5891.     if (!targetsCurrentBrowsingContext(target)) return false;
  5892.  
  5893.     const methodOverride = submitter && submitter.getAttribute
  5894.       ? submitter.getAttribute('formmethod')
  5895.       : null;
  5896.     const method = String(
  5897.       methodOverride !== null ? methodOverride : (form.getAttribute('method') || 'get')
  5898.     ).toLowerCase();
  5899.     return method !== 'dialog';
  5900.   }
  5901.  
  5902.   function targetLinkFromEvent(e) {
  5903.     const target = e.target;
  5904.     return target && target.closest ? target.closest(NAV_SELECTOR) : null;
  5905.   }
  5906.  
  5907.   function installPreNavigationHold() {
  5908.     // Prime only after a complete, uncancelled click. Hiding the document on
  5909.     // pointerdown removes the link from hit-testing before mouseup/click and
  5910.     // prevents navigation entirely. Click covers mouse, touch, keyboard and
  5911.     // programmatic anchor activation without altering the current page.
  5912.     document.addEventListener('click', (e) => {
  5913.       const a = targetLinkFromEvent(e);
  5914.       if (!shouldHoldForLink(a, e)) return;
  5915.       primeNavigationHold();
  5916.     });
  5917.  
  5918.     // Delegation covers reply/new-topic composition, PM sends, Merit awards,
  5919.     // login/search and any forms inserted after startup. The bubble phase lets
  5920.     // form-level validation or preventDefault handlers cancel first.
  5921.     document.addEventListener('submit', (e) => {
  5922.       const form = e.target;
  5923.       if (!shouldHoldForForm(form, e)) return;
  5924.       primeNavigationHold();
  5925.     });
  5926.  
  5927.     window.addEventListener('beforeunload', () => {
  5928.       // A real page exit may outlive the short cancelled-click timeout. Keep
  5929.       // the cover longer, with a failsafe for a cancelled beforeunload prompt.
  5930.       applyOutgoingHold(OUTGOING_UNLOAD_FAILSAFE_MS);
  5931.     });
  5932.     window.addEventListener('pagehide', () => {
  5933.       // pagehide confirms that the document is leaving or entering BFCache;
  5934.       // pageshow releases the persistent cover if this document returns.
  5935.       applyOutgoingHold(null);
  5936.     });
  5937.     window.addEventListener('pageshow', () => {
  5938.       releaseOutgoingHold();
  5939.       document.documentElement.setAttribute(HOLD_REVEALED_ATTR, '');
  5940.     });
  5941.   }
  5942.   // ===========================================================================
  5943.   // Topic read tracker
  5944.   // ===========================================================================
  5945.  
  5946.   let topicReadView = null;
  5947.  
  5948.   function parseTopicIdFromUrl(url) {
  5949.     try {
  5950.       const u = new URL(url || window.location.href, window.location.href);
  5951.       const topic = u.searchParams.get('topic') || '';
  5952.       const m = topic.match(/^(\d+)/);
  5953.       if (m) return m[1];
  5954.     } catch (e) {}
  5955.  
  5956.     const fallback = String(url || window.location.href || '').match(/[?;&]topic=(\d+)/i);
  5957.     return fallback ? fallback[1] : null;
  5958.   }
  5959.  
  5960.   function parsePostNo(text) {
  5961.     const m = String(text || '').match(/#\s*(\d+)/);
  5962.     if (!m) return 0;
  5963.     const n = parseInt(m[1], 10);
  5964.     return Number.isFinite(n) && n > 0 ? n : 0;
  5965.   }
  5966.  
  5967.   function parseMsgIdFromHref(href) {
  5968.     const m = String(href || '').match(/(?:[.#]|%23)msg(\d+)/i);
  5969.     if (!m) return 0;
  5970.     const n = parseInt(m[1], 10);
  5971.     return Number.isFinite(n) && n > 0 ? n : 0;
  5972.   }
  5973.  
  5974.   function readTopicReadState() {
  5975.     const raw = getPref(KEY_TOPIC_READ_STATE, '');
  5976.     if (!raw) return { v: 1, topics: {} };
  5977.     try {
  5978.       const parsed = JSON.parse(raw);
  5979.       if (!parsed || typeof parsed !== 'object') return { v: 1, topics: {} };
  5980.       if (!parsed.topics || typeof parsed.topics !== 'object') parsed.topics = {};
  5981.       parsed.v = 1;
  5982.       return parsed;
  5983.     } catch (e) {
  5984.       return { v: 1, topics: {} };
  5985.     }
  5986.   }
  5987.  
  5988.   function writeTopicReadState(state) {
  5989.     if (!state || !state.topics) return false;
  5990.  
  5991.     const entries = Object.entries(state.topics);
  5992.     if (entries.length > TOPIC_READ_STATE_MAX_ENTRIES) {
  5993.       entries
  5994.         .sort((a, b) => ((b[1] && b[1].updatedAt) || 0) - ((a[1] && a[1].updatedAt) || 0))
  5995.         .slice(TOPIC_READ_STATE_MAX_ENTRIES)
  5996.         .forEach(([topicId]) => { delete state.topics[topicId]; });
  5997.     }
  5998.  
  5999.     try {
  6000.       return setPref(KEY_TOPIC_READ_STATE, JSON.stringify(state));
  6001.     } catch (e) {
  6002.       return false;
  6003.     }
  6004.   }
  6005.  
  6006.   function mergeReadRanges(ranges, nextRange) {
  6007.     const all = Array.isArray(ranges) ? ranges.slice() : [];
  6008.     if (nextRange && nextRange.length === 2 && nextRange[0] > 0 && nextRange[1] >= nextRange[0]) {
  6009.       all.push([nextRange[0], nextRange[1]]);
  6010.     }
  6011.     all.sort((a, b) => a[0] - b[0]);
  6012.  
  6013.     const merged = [];
  6014.     all.forEach(range => {
  6015.       if (!Array.isArray(range) || range.length !== 2) return;
  6016.       const start = parseInt(range[0], 10);
  6017.       const end = parseInt(range[1], 10);
  6018.       if (!Number.isFinite(start) || !Number.isFinite(end) || start <= 0 || end < start) return;
  6019.  
  6020.       const last = merged[merged.length - 1];
  6021.       if (last && start <= last[1] + 1) {
  6022.         if (end > last[1]) last[1] = end;
  6023.       } else {
  6024.         merged.push([start, end]);
  6025.       }
  6026.     });
  6027.  
  6028.     return merged.slice(-80);
  6029.   }
  6030.  
  6031.   function normaliseReadRanges(record) {
  6032.     if (!record || typeof record !== 'object') return [];
  6033.     const ranges = mergeReadRanges(record.ranges, null);
  6034.     if (ranges.length) return ranges;
  6035.  
  6036.     const lastPostNo = parseInt(record.lastPostNo, 10) || 0;
  6037.     return lastPostNo > 0 ? [[1, lastPostNo]] : [];
  6038.   }
  6039.  
  6040.   function postNoInReadRanges(postNo, ranges) {
  6041.     return Array.isArray(ranges) && ranges.some(range => {
  6042.       if (!Array.isArray(range) || range.length !== 2) return false;
  6043.       return postNo >= range[0] && postNo <= range[1];
  6044.     });
  6045.   }
  6046.  
  6047.   function readPostSurfaceNodes(postShell) {
  6048.     if (!postShell) return [];
  6049.     const nodes = [postShell];
  6050.     try {
  6051.       postShell.querySelectorAll(
  6052.         ':scope > table, :scope > table > tbody > tr > td, ' +
  6053.         'td.td_headerandpost, td.td_headerandpost > table, ' +
  6054.         'td.td_headerandpost > table > tbody > tr > td, ' +
  6055.         'div.post, td.poster, td.poster_info'
  6056.       ).forEach(node => {
  6057.         if (node && node.nodeType === Node.ELEMENT_NODE) nodes.push(node);
  6058.       });
  6059.     } catch (e) {}
  6060.     return nodes;
  6061.   }
  6062.  
  6063.   function setReadPostMark(post, isRead) {
  6064.     readPostSurfaceNodes(post.shell).forEach(node => {
  6065.       node.classList.remove(
  6066.         'bt-read-post-surface',
  6067.         'bt-read-post-surface-alt',
  6068.         'bt-read-post-surface-main'
  6069.       );
  6070.       node.removeAttribute('data-bt-read-post');
  6071.     });
  6072.     post.shell.classList.toggle('bt-read-post', isRead);
  6073.     if (isRead) post.shell.setAttribute('data-bt-read-post', 'true');
  6074.     else post.shell.removeAttribute('data-bt-read-post');
  6075.   }
  6076.  
  6077.   function clearReadPostMarks() {
  6078.     document.querySelectorAll('.bt-read-post, .bt-read-post-surface').forEach(node => {
  6079.       node.classList.remove(
  6080.         'bt-read-post',
  6081.         'bt-read-post-surface',
  6082.         'bt-read-post-surface-main',
  6083.         'bt-read-post-surface-alt'
  6084.       );
  6085.       node.removeAttribute('data-bt-read-post');
  6086.     });
  6087.     if (topicReadView) topicReadView.lastProcessedSignature = '';
  6088.   }
  6089.  
  6090.   function collectTopicPosts(topicId) {
  6091.     const seen = new Set();
  6092.     const posts = [];
  6093.  
  6094.     document.querySelectorAll('a.message_number[href*="msg"]').forEach(link => {
  6095.       const postNo = parsePostNo(link.textContent);
  6096.       const msgId = parseMsgIdFromHref(link.getAttribute('href') || link.href);
  6097.       if (!postNo || !msgId || seen.has(msgId)) return;
  6098.  
  6099.       const hrefTopicId = parseTopicIdFromUrl(link.getAttribute('href') || link.href);
  6100.       if (hrefTopicId && hrefTopicId !== topicId) return;
  6101.  
  6102.       const headerCell = link.closest('td.td_headerandpost');
  6103.       const postShell = headerCell ? headerCell.closest('td[class*="windowbg"]') : null;
  6104.       if (!postShell) return;
  6105.  
  6106.       seen.add(msgId);
  6107.       posts.push({ postNo, msgId, shell: postShell });
  6108.     });
  6109.  
  6110.     posts.sort((a, b) => a.postNo - b.postNo);
  6111.     return posts;
  6112.   }
  6113.  
  6114.   function markReadPostsForCurrentTopic() {
  6115.     if (!isTopicReadShadingEnabled()) {
  6116.       clearReadPostMarks();
  6117.       return;
  6118.     }
  6119.  
  6120.     const topicId = parseTopicIdFromUrl(window.location.href);
  6121.     if (!topicId) return;
  6122.  
  6123.     const posts = collectTopicPosts(topicId);
  6124.     if (!posts.length) return;
  6125.  
  6126.     const first = posts[0];
  6127.     const last = posts[posts.length - 1];
  6128.     const postSignature = `${posts.length}:${first.msgId}:${last.msgId}`;
  6129.     if (
  6130.       topicReadView &&
  6131.       topicReadView.topicId === topicId &&
  6132.       topicReadView.lastProcessedSignature === postSignature
  6133.     ) {
  6134.       return;
  6135.     }
  6136.  
  6137.     const state = readTopicReadState();
  6138.     if (!topicReadView || topicReadView.topicId !== topicId) {
  6139.       const record = state.topics[topicId] || {};
  6140.       topicReadView = {
  6141.         topicId,
  6142.         readRangesBefore: normaliseReadRanges(record),
  6143.         lastProcessedSignature: '',
  6144.       };
  6145.     }
  6146.  
  6147.     posts.forEach(post => {
  6148.       setReadPostMark(post, postNoInReadRanges(post.postNo, topicReadView.readRangesBefore));
  6149.     });
  6150.  
  6151.     const current = state.topics[topicId] || {};
  6152.     const lastPostNo = Math.max(parseInt(current.lastPostNo, 10) || 0, last.postNo);
  6153.     const lastMsgId = lastPostNo === last.postNo ? last.msgId : (parseInt(current.lastMsgId, 10) || 0);
  6154.     const ranges = mergeReadRanges(current.ranges, [first.postNo, last.postNo]);
  6155.     const previousRanges = JSON.stringify(normaliseReadRanges(current));
  6156.     const nextRanges = JSON.stringify(ranges);
  6157.  
  6158.     state.topics[topicId] = {
  6159.       lastPostNo,
  6160.       lastMsgId,
  6161.       updatedAt: Date.now(),
  6162.       ranges,
  6163.     };
  6164.     if (
  6165.       lastPostNo !== (parseInt(current.lastPostNo, 10) || 0) ||
  6166.       lastMsgId !== (parseInt(current.lastMsgId, 10) || 0) ||
  6167.       nextRanges !== previousRanges
  6168.     ) {
  6169.       writeTopicReadState(state);
  6170.     }
  6171.     topicReadView.lastProcessedSignature = postSignature;
  6172.   }
  6173.   // ===========================================================================
  6174.   // Init
  6175.   // ===========================================================================
  6176.  
  6177.   function setupRootAttributes() {
  6178.     let pref = null;
  6179.     if (hasGM) {
  6180.       try {
  6181.         const v = GM_getValue(KEY_THEME, null);
  6182.         if (v != null && v !== '') pref = String(v);
  6183.       } catch (e) {}
  6184.     }
  6185.     if (!pref) {
  6186.       try {
  6187.         const v = localStorage.getItem(KEY_THEME);
  6188.         if (v != null && v !== '') pref = v;
  6189.       } catch (e) {}
  6190.     }
  6191.     if (!pref) pref = DEFAULT_THEME;
  6192.  
  6193.     const effective = getEffectiveTheme(pref);
  6194.     const root = document.documentElement;
  6195.     root.setAttribute('data-bt-no-transitions', '');
  6196.     updateMobileLiteAttribute();
  6197.     updatePageAttribute();
  6198.  
  6199.     if (effective === 'off') {
  6200.       root.setAttribute('data-bt-active', 'false');
  6201.       return;
  6202.     }
  6203.  
  6204.     root.setAttribute('data-bt-active', 'true');
  6205.     root.setAttribute('data-bt-theme', effective);
  6206.     root.style.colorScheme = effective;
  6207.   }
  6208.  
  6209.   const paintHeld = holdPaint();
  6210.   setupRootAttributes();
  6211.   syncStores();
  6212.   injectCSS();
  6213.   clearLegacyInlineSizing();
  6214.   applyTheme();
  6215.   if (paintHeld) releasePaint();
  6216.   installPreNavigationHold();
  6217.  
  6218.   function enableTransitions() {
  6219.     requestAnimationFrame(() => {
  6220.       requestAnimationFrame(() => {
  6221.         document.documentElement.removeAttribute('data-bt-no-transitions');
  6222.       });
  6223.     });
  6224.   }
  6225.   if (document.readyState === 'loading') {
  6226.     document.addEventListener('DOMContentLoaded', enableTransitions, { once: true });
  6227.   } else {
  6228.     enableTransitions();
  6229.   }
  6230.  
  6231.   window.addEventListener('storage', (e) => {
  6232.     if (e && e.key && ALL_KEYS.indexOf(e.key) !== -1) {
  6233.       if (e.key === KEY_TOPIC_READ_STATE) {
  6234.         topicReadView = null;
  6235.         markReadPostsForCurrentTopic();
  6236.       } else {
  6237.         const wasActive = document.documentElement.getAttribute('data-bt-active') === 'true';
  6238.         const previousMode = document.documentElement.getAttribute('data-bt-mobile-mode') || getEffectiveMobileMode();
  6239.         applyTheme();
  6240.         const nextMode = getEffectiveMobileMode();
  6241.         reconcileMobileRuntime(previousMode, nextMode, !wasActive && isThemeActiveNow());
  6242.       }
  6243.     }
  6244.   });
  6245.  
  6246.   let modernizeTimer = null;
  6247.   let modernizeIdleHandle = null;
  6248.   let modernizeFrameHandle = null;
  6249.   let modernizeObserver = null;
  6250.   let modernizeQueuedAt = 0;
  6251.   const pendingModernizeRoots = new Set();
  6252.   const MODERNIZE_DEBOUNCE_MS = 180;
  6253.   const BALANCED_MODERNIZE_DEBOUNCE_MS = 320;
  6254.   const MODERNIZE_MAX_WAIT_MS = 600;
  6255.   const MODERNIZE_BATCH_ROOT_THRESHOLD = 32;
  6256.   const BALANCED_WORK_BUDGET_MS = 7;
  6257.   const BALANCED_WORK_CHUNK_MAX = 24;
  6258.  
  6259.   const BALANCED_CANDIDATE_SELECTOR = [
  6260.     'img[src*="/topic/"]',
  6261.     'img[src*="/post/"]',
  6262.     'img[src*="/Post/"]',
  6263.     'img[src*="normal_post"]',
  6264.     'img[src*="hot_post"]',
  6265.     'img[src*="veryhot_post"]',
  6266.     'img[src*="lock"]',
  6267.     'img[src*="sticky"]',
  6268.     'img[src*="pin"]',
  6269.     'img[src*="new"]',
  6270.     'img[src*="unread"]',
  6271.     'img[alt*="Locked"]',
  6272.     'img[title*="Locked"]',
  6273.     'img[alt*="Sticky"]',
  6274.     'img[title*="Sticky"]',
  6275.     '#bbcBox_message img',
  6276.     '.bbc_buttons img',
  6277.     '[id^="bbc_"] img',
  6278.     'img[src*="/bbc/"]',
  6279.     'img[src*="bbc_"]',
  6280.     'img[src*="/frostee/"]',
  6281.     'img[src*="frostee_"]',
  6282.     'img.reply_button',
  6283.     'img.remove_button',
  6284.     'img.modify_button',
  6285.     'img[class$="_button"]',
  6286.     'img[src*="Smileys/"]',
  6287.     'img[src*="/smileys/"]',
  6288.     'img.smiley',
  6289.     'a.message_number',
  6290.     'a[href*="action=merit"]',
  6291.   ].join(', ');
  6292.  
  6293.   let balancedVisibilityObserver = null;
  6294.   let balancedIdleHandle = null;
  6295.   let balancedFrameHandle = null;
  6296.   const balancedReadyElements = [];
  6297.   const balancedPendingElements = new Set();
  6298.   const balancedProcessedElements = new WeakSet();
  6299.  
  6300.   function queryAllWithin(scope, selector) {
  6301.     if (!scope || scope === document || scope.nodeType === Node.DOCUMENT_NODE) {
  6302.       return Array.from(document.querySelectorAll(selector));
  6303.     }
  6304.     if (scope.nodeType !== Node.ELEMENT_NODE) return [];
  6305.     const results = [];
  6306.     if (scope.matches(selector)) results.push(scope);
  6307.     scope.querySelectorAll(selector).forEach(element => results.push(element));
  6308.     return results;
  6309.   }
  6310.  
  6311.   function scopeTouches(scope, selector) {
  6312.     if (!scope || scope === document || scope.nodeType === Node.DOCUMENT_NODE) return true;
  6313.     if (scope.nodeType !== Node.ELEMENT_NODE) return false;
  6314.     return scope.matches(selector) || !!scope.closest(selector) || !!scope.querySelector(selector);
  6315.   }
  6316.  
  6317.   function runBalancedCandidate(element) {
  6318.     if (!element || !element.isConnected || balancedProcessedElements.has(element)) return;
  6319.     modernizeBBCodeIcons(element);
  6320.     modernizeTopicListIcons(element);
  6321.     modernizeSmileys(element);
  6322.     stylePostMetaButtons(element);
  6323.     balancedProcessedElements.add(element);
  6324.   }
  6325.  
  6326.   function scheduleBalancedWork() {
  6327.     if (
  6328.       balancedIdleHandle !== null || balancedFrameHandle !== null ||
  6329.       !balancedReadyElements.length || !isMobileBalanced() || !isThemeActiveNow()
  6330.     ) return;
  6331.  
  6332.     if (typeof requestIdleCallback === 'function') {
  6333.       balancedIdleHandle = requestIdleCallback(processBalancedWork, { timeout: 900 });
  6334.     } else {
  6335.       balancedFrameHandle = requestAnimationFrame(processBalancedWork);
  6336.     }
  6337.   }
  6338.  
  6339.   function processBalancedWork(deadline) {
  6340.     balancedIdleHandle = null;
  6341.     balancedFrameHandle = null;
  6342.     if (!isMobileBalanced() || !isThemeActiveNow()) {
  6343.       stopBalancedModernization();
  6344.       return;
  6345.     }
  6346.  
  6347.     const startedAt = performance.now();
  6348.     let processed = 0;
  6349.     while (balancedReadyElements.length && processed < BALANCED_WORK_CHUNK_MAX) {
  6350.       if (
  6351.         processed > 0 &&
  6352.         (performance.now() - startedAt >= BALANCED_WORK_BUDGET_MS ||
  6353.           (deadline && typeof deadline.timeRemaining === 'function' && !deadline.didTimeout && deadline.timeRemaining() < 2))
  6354.       ) break;
  6355.  
  6356.       const element = balancedReadyElements.shift();
  6357.       balancedPendingElements.delete(element);
  6358.       runBalancedCandidate(element);
  6359.       processed += 1;
  6360.     }
  6361.     if (balancedReadyElements.length) scheduleBalancedWork();
  6362.   }
  6363.  
  6364.   function ensureBalancedVisibilityObserver() {
  6365.     if (balancedVisibilityObserver || typeof IntersectionObserver === 'undefined') return balancedVisibilityObserver;
  6366.     balancedVisibilityObserver = new IntersectionObserver(entries => {
  6367.       entries.forEach(entry => {
  6368.         if (!entry.isIntersecting && entry.intersectionRatio <= 0) return;
  6369.         if (balancedVisibilityObserver) balancedVisibilityObserver.unobserve(entry.target);
  6370.         balancedReadyElements.push(entry.target);
  6371.       });
  6372.       scheduleBalancedWork();
  6373.     }, { rootMargin: '500px 0px' });
  6374.     return balancedVisibilityObserver;
  6375.   }
  6376.  
  6377.   function isBalancedCandidateComplete(element) {
  6378.     if (balancedProcessedElements.has(element)) return true;
  6379.     if (element.matches('a')) return element.dataset.btPostMeta === '1';
  6380.     return (
  6381.       element.dataset.btTopicIcon === '1' ||
  6382.       element.dataset.btReplaced === '1' ||
  6383.       element.dataset.btSmiley === '1'
  6384.     );
  6385.   }
  6386.  
  6387.   function queueBalancedCandidates(scope = document) {
  6388.     if (!isMobileBalanced() || !isThemeActiveNow()) return;
  6389.     const observer = ensureBalancedVisibilityObserver();
  6390.     queryAllWithin(scope, BALANCED_CANDIDATE_SELECTOR).forEach(element => {
  6391.       if (
  6392.         !element.isConnected || isBalancedCandidateComplete(element) ||
  6393.         balancedPendingElements.has(element)
  6394.       ) return;
  6395.       balancedPendingElements.add(element);
  6396.       if (observer) observer.observe(element);
  6397.       else balancedReadyElements.push(element);
  6398.     });
  6399.     if (!observer) scheduleBalancedWork();
  6400.   }
  6401.  
  6402.   function stopBalancedModernization() {
  6403.     if (balancedIdleHandle !== null && typeof cancelIdleCallback === 'function') {
  6404.       cancelIdleCallback(balancedIdleHandle);
  6405.     }
  6406.     if (balancedFrameHandle !== null) cancelAnimationFrame(balancedFrameHandle);
  6407.     balancedIdleHandle = null;
  6408.     balancedFrameHandle = null;
  6409.     balancedReadyElements.length = 0;
  6410.     balancedPendingElements.clear();
  6411.     if (balancedVisibilityObserver) {
  6412.       try { balancedVisibilityObserver.disconnect(); } catch (e) {}
  6413.       balancedVisibilityObserver = null;
  6414.     }
  6415.   }
  6416.  
  6417.   function queueModernizeRoot(node) {
  6418.     if (!node || node.nodeType !== Node.ELEMENT_NODE || isModernThemeOwnedNode(node)) return;
  6419.     const root = node === document.body || node === document.documentElement ? document : node;
  6420.     for (const queued of pendingModernizeRoots) {
  6421.       if (queued === document || (queued.contains && queued.contains(root))) return;
  6422.       if (root === document || (root.contains && root.contains(queued))) pendingModernizeRoots.delete(queued);
  6423.     }
  6424.     pendingModernizeRoots.add(root);
  6425.   }
  6426.  
  6427.   function runModernizeForScope(scope) {
  6428.     modernizeBBCodeIcons(scope);
  6429.     modernizeTopicListIcons(scope);
  6430.     modernizeSmileys(scope);
  6431.     stylePostMetaButtons(scope);
  6432.     markTopicActionBars(scope);
  6433.     fixMaintabCaps(scope);
  6434.     highlightUnreadPm(scope);
  6435.   }
  6436.  
  6437.   function runBalancedModernizeForScope(scope) {
  6438.     markTopicActionBars(scope);
  6439.     fixMaintabCaps(scope);
  6440.     highlightUnreadPm(scope);
  6441.     queueBalancedCandidates(scope);
  6442.   }
  6443.  
  6444.   function flushModernizeQueue() {
  6445.     modernizeIdleHandle = null;
  6446.     modernizeFrameHandle = null;
  6447.     const mobileMode = getRuntimeMobileMode();
  6448.     if (mobileMode === 'lite' || !isThemeActiveNow()) {
  6449.       pendingModernizeRoots.clear();
  6450.       modernizeQueuedAt = 0;
  6451.       return;
  6452.     }
  6453.  
  6454.     const roots = Array.from(pendingModernizeRoots).filter(root => root === document || root.isConnected);
  6455.     pendingModernizeRoots.clear();
  6456.     modernizeQueuedAt = 0;
  6457.     if (!roots.length) return;
  6458.  
  6459.     let needsReadTracking = false;
  6460.     roots.forEach(scope => {
  6461.       if (mobileMode === 'balanced') runBalancedModernizeForScope(scope);
  6462.       else runModernizeForScope(scope);
  6463.       needsReadTracking ||= scopeTouches(scope, 'a.message_number[href*="msg"]');
  6464.     });
  6465.  
  6466.     if (needsReadTracking) markReadPostsForCurrentTopic();
  6467.   }
  6468.  
  6469.   function scheduleModernize(nodes = []) {
  6470.     const mobileMode = getRuntimeMobileMode();
  6471.     if (mobileMode === 'lite' || !isThemeActiveNow()) return;
  6472.     Array.from(nodes).forEach(queueModernizeRoot);
  6473.     if (!pendingModernizeRoots.size) return;
  6474.  
  6475.     const now = Date.now();
  6476.     if (!modernizeQueuedAt) modernizeQueuedAt = now;
  6477.     if (modernizeTimer) clearTimeout(modernizeTimer);
  6478.     const elapsed = now - modernizeQueuedAt;
  6479.     modernizeTimer = setTimeout(() => {
  6480.       modernizeTimer = null;
  6481.       const currentMobileMode = getRuntimeMobileMode();
  6482.       if (currentMobileMode === 'lite' || !isThemeActiveNow()) {
  6483.         pendingModernizeRoots.clear();
  6484.         modernizeQueuedAt = 0;
  6485.         return;
  6486.       }
  6487.       if (typeof requestIdleCallback === 'function') {
  6488.         modernizeIdleHandle = requestIdleCallback(flushModernizeQueue, { timeout: 500 });
  6489.       } else {
  6490.         modernizeFrameHandle = requestAnimationFrame(flushModernizeQueue);
  6491.       }
  6492.     }, elapsed >= MODERNIZE_MAX_WAIT_MS
  6493.       ? 0
  6494.       : mobileMode === 'balanced' ? BALANCED_MODERNIZE_DEBOUNCE_MS : MODERNIZE_DEBOUNCE_MS);
  6495.   }
  6496.  
  6497.   function runEssentialPasses() {
  6498.     markTopicActionBars();
  6499.     markReadPostsForCurrentTopic();
  6500.     fixMaintabCaps();
  6501.     highlightUnreadPm();
  6502.   }
  6503.  
  6504.   function runFullEnhancementPasses() {
  6505.     stopBalancedModernization();
  6506.     modernizeBBCodeIcons();
  6507.     modernizeTopicListIcons();
  6508.     modernizeSmileys();
  6509.     stylePostMetaButtons();
  6510.   }
  6511.  
  6512.   function runInitialPasses() {
  6513.     runEssentialPasses();
  6514.     if (isMobileLite()) {
  6515.       stopBalancedModernization();
  6516.       stopMeritSizingObserver();
  6517.       return;
  6518.     }
  6519.     if (isMobileBalanced()) {
  6520.       queueBalancedCandidates();
  6521.       return;
  6522.     }
  6523.     runFullEnhancementPasses();
  6524.   }
  6525.  
  6526.   function reconcileMobileRuntime(previousMode = null, nextMode = getEffectiveMobileMode(), forceInitialPass = false) {
  6527.     if (nextMode === 'lite' || !isThemeActiveNow()) {
  6528.       stopModernizeObserver();
  6529.       stopBalancedModernization();
  6530.       stopMeritSizingObserver();
  6531.       return;
  6532.     }
  6533.  
  6534.     ensureFonts();
  6535.     if (nextMode === 'balanced') {
  6536.       if (forceInitialPass || previousMode !== 'balanced') {
  6537.         runEssentialPasses();
  6538.         queueBalancedCandidates();
  6539.       }
  6540.     } else {
  6541.       stopBalancedModernization();
  6542.       if (forceInitialPass || previousMode !== 'full') {
  6543.         runEssentialPasses();
  6544.         runFullEnhancementPasses();
  6545.       }
  6546.     }
  6547.     installModernizeObserver();
  6548.   }
  6549.  
  6550.   function stopModernizeObserver() {
  6551.     if (modernizeTimer) {
  6552.       clearTimeout(modernizeTimer);
  6553.       modernizeTimer = null;
  6554.     }
  6555.     if (modernizeIdleHandle !== null && typeof cancelIdleCallback === 'function') {
  6556.       cancelIdleCallback(modernizeIdleHandle);
  6557.       modernizeIdleHandle = null;
  6558.     }
  6559.     if (modernizeFrameHandle !== null) {
  6560.       cancelAnimationFrame(modernizeFrameHandle);
  6561.       modernizeFrameHandle = null;
  6562.     }
  6563.     pendingModernizeRoots.clear();
  6564.     modernizeQueuedAt = 0;
  6565.     if (modernizeObserver) {
  6566.       try { modernizeObserver.disconnect(); } catch (e) {}
  6567.       modernizeObserver = null;
  6568.     }
  6569.   }
  6570.  
  6571.   const MODERN_THEME_OWNED_SELECTOR = [
  6572.     '#bt-switcher',
  6573.     '[data-bt-replacement="1"]',
  6574.     '.bt-bbc-icon',
  6575.     '.bt-smiley-modern',
  6576.   ].join(', ');
  6577.  
  6578.   const INCREMENTAL_STATE_ANCESTOR_SELECTOR = [
  6579.     PM_LINK_SELECTOR,
  6580.     '[class*="maintab"]',
  6581.     '[class*="mirrortab"]',
  6582.     'a.message_number[href*="msg"]',
  6583.   ].join(', ');
  6584.  
  6585.   function isModernThemeOwnedNode(node) {
  6586.     if (!node || node.nodeType !== Node.ELEMENT_NODE) return false;
  6587.     return !!(node.matches(MODERN_THEME_OWNED_SELECTOR) || node.closest(MODERN_THEME_OWNED_SELECTOR));
  6588.   }
  6589.  
  6590.   function mutationModernizeRoot(mutation) {
  6591.     if (isModernThemeOwnedNode(mutation.target)) return null;
  6592.     const target = mutation.target && mutation.target.nodeType === Node.ELEMENT_NODE
  6593.       ? mutation.target
  6594.       : null;
  6595.     if (!target) return null;
  6596.     return target.closest
  6597.       ? target.closest(INCREMENTAL_STATE_ANCESTOR_SELECTOR) || target
  6598.       : target;
  6599.   }
  6600.  
  6601.   function addedModernizeNodes(mutation) {
  6602.     if (isModernThemeOwnedNode(mutation.target)) return [];
  6603.     const nodes = Array.from(mutation.addedNodes || []).filter(node => (
  6604.       node.nodeType === Node.ELEMENT_NODE && !isModernThemeOwnedNode(node)
  6605.     ));
  6606.     const target = mutation.target && mutation.target.nodeType === Node.ELEMENT_NODE
  6607.       ? mutation.target
  6608.       : null;
  6609.     const stateAncestor = target && target.closest
  6610.       ? target.closest(INCREMENTAL_STATE_ANCESTOR_SELECTOR)
  6611.       : null;
  6612.     const batchRoot = stateAncestor || target;
  6613.     if (nodes.length > MODERNIZE_BATCH_ROOT_THRESHOLD && batchRoot) return [batchRoot];
  6614.     if (stateAncestor && !nodes.includes(stateAncestor)) nodes.push(stateAncestor);
  6615.     return nodes;
  6616.   }
  6617.  
  6618.   function installModernizeObserver() {
  6619.     if (modernizeObserver || isMobileLite() || !isThemeActiveNow() || typeof MutationObserver === 'undefined') return;
  6620.     modernizeObserver = new MutationObserver((mutations) => {
  6621.       const addedNodes = mutations.flatMap(addedModernizeNodes);
  6622.       if (!addedNodes.length) return;
  6623.       if (addedNodes.length > MODERNIZE_BATCH_ROOT_THRESHOLD) {
  6624.         const batchRoots = Array.from(new Set(mutations.map(mutationModernizeRoot).filter(Boolean)));
  6625.         scheduleModernize(batchRoots.length ? batchRoots : addedNodes);
  6626.       } else {
  6627.         scheduleModernize(addedNodes);
  6628.       }
  6629.     });
  6630.     if (document.body) {
  6631.       modernizeObserver.observe(document.body, { childList: true, subtree: true });
  6632.     } else {
  6633.       document.addEventListener('DOMContentLoaded', () => {
  6634.         if (!isMobileLite() && document.body) {
  6635.           modernizeObserver.observe(document.body, { childList: true, subtree: true });
  6636.         }
  6637.       }, { once: true });
  6638.     }
  6639.   }
  6640.  
  6641.   if (document.readyState === 'loading') {
  6642.     document.addEventListener('DOMContentLoaded', () => {
  6643.       injectSwitcher();
  6644.       runInitialPasses();
  6645.     }, { once: true });
  6646.   } else {
  6647.     injectSwitcher();
  6648.     runInitialPasses();
  6649.   }
  6650.  
  6651.   installModernizeObserver();
  6652.  
  6653.   if (window.matchMedia) {
  6654.     const mq = window.matchMedia('(prefers-color-scheme: dark)');
  6655.     const reapply = () => {
  6656.       if (getPref(KEY_THEME, DEFAULT_THEME) === 'system') applyTheme();
  6657.     };
  6658.     if (mq.addEventListener) mq.addEventListener('change', reapply);
  6659.     else if (mq.addListener) mq.addListener(reapply);
  6660.  
  6661.     const mobileMq = window.matchMedia('(max-width: 820px)');
  6662.     let lastAutomaticMobileMode = getEffectiveMobileMode();
  6663.     let mobileModeTimer = null;
  6664.     const reapplyAutomaticMobileMode = () => {
  6665.       if (getMobileVersionPreference() !== 'auto') {
  6666.         lastAutomaticMobileMode = getEffectiveMobileMode();
  6667.         return;
  6668.       }
  6669.       if (mobileModeTimer) clearTimeout(mobileModeTimer);
  6670.       mobileModeTimer = setTimeout(() => {
  6671.         mobileModeTimer = null;
  6672.         const nextMobileMode = getEffectiveMobileMode();
  6673.         if (nextMobileMode === lastAutomaticMobileMode) return;
  6674.         const previousMobileMode = lastAutomaticMobileMode;
  6675.         lastAutomaticMobileMode = nextMobileMode;
  6676.         applyTheme();
  6677.         reconcileMobileRuntime(previousMobileMode, nextMobileMode, true);
  6678.       }, 150);
  6679.     };
  6680.     if (mobileMq.addEventListener) mobileMq.addEventListener('change', reapplyAutomaticMobileMode);
  6681.     else if (mobileMq.addListener) mobileMq.addListener(reapplyAutomaticMobileMode);
  6682.     window.addEventListener('orientationchange', reapplyAutomaticMobileMode);
  6683.   }
  6684. })();
  6685.  
Add Comment
Please, Sign In to add comment