diff --git a/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs b/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs
index ce37107..7fe0edf 100644
--- a/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs
+++ b/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs
@@ -197,15 +197,16 @@ public class MailTemplateRendererTests
}
[Fact]
- public void InDarkMode_TheCardStandsOutFromThePage_AndHasABorder()
+ public void InDarkMode_TheCardStandsOutFromThePage_AndHasASubtleBorderOnlyInTheDarkRules()
{
var html = _renderer.Render(MailKind.Invitation, "nl", Model()).Html;
MailTemplateRenderer.DarkCard.Should().NotBe(MailTemplateRenderer.DarkPage);
// clearly lighter than the page, not the near-identical shades it used to be
- MailColours.Contrast(MailTemplateRenderer.DarkCard, MailTemplateRenderer.DarkPage).Should().BeGreaterThanOrEqualTo(1.4);
+ MailColours.Contrast(MailTemplateRenderer.DarkCard, MailTemplateRenderer.DarkPage).Should().BeGreaterThanOrEqualTo(1.6);
html.Should().Contain($".mail-page{{background:{MailTemplateRenderer.DarkPage} !important;}}")
- .And.Contain($".mail-card{{background:{MailTemplateRenderer.DarkCard} !important;color:#f3f4f6 !important;border:1px solid #475569 !important;}}");
+ .And.Contain($".mail-card{{background:{MailTemplateRenderer.DarkCard} !important;color:#f3f4f6 !important;border:1px solid {MailTemplateRenderer.DarkCardBorder} !important;}}");
+ MailTemplateRenderer.DarkCardBorder.Should().Be("#394457");
// light mode is untouched: white card on the light grey page
html.Should().Contain("bgcolor=\"#f3f4f6\"").And.Contain("bgcolor=\"#ffffff\"");
}
@@ -270,16 +271,17 @@ public class MailTemplateRendererTests
}
[Fact]
- public void TheCard_HasAnInlineBorder_ThatSurvivesClientsThatStripTheStyleBlock_AndOutlookHasItsOwnRules()
+ public void LightMode_HasNoBorder_AndOutlookHasItsOwnDarkRules()
{
var html = _renderer.Render(MailKind.Invitation, "nl", Model()).Html;
- // inline, so it also exists where ", StringComparison.Ordinal)];
+
+ foreach (System.Text.RegularExpressions.Match tag in System.Text.RegularExpressions.Regex.Matches(html, "<(?[a-z0-9]+)(?[^>]*style=\"[^\"]*[^-]color:[^\"]*\"[^>]*)>"))
+ {
+ var attrs = tag.Groups["attrs"].Value;
+ var classes = System.Text.RegularExpressions.Regex.Match(attrs, "class=\"(?[^\"]*)\"").Groups["c"].Value
+ .Split(' ', StringSplitOptions.RemoveEmptyEntries);
+ // the button link and the logo/site-name cells are handled by their own classes; the card itself by .mail-card
+ var overridden = classes.Any(c => darkBlock.Contains("." + c + "{") || darkBlock.Contains("." + c + " a{"))
+ || (tag.Groups["name"].Value == "a" && darkBlock.Contains(".mail-btn a{")); // the button link, via its cell
+ overridden.Should().BeTrue($"<{tag.Groups["name"].Value}{attrs}> keeps a fixed colour in dark mode");
+ }
+ }
+
+ [Fact]
+ public void ClientConversionSimulation_DocumentsWhatSurvives_TheLightPairLosesItsDifferenceButTheDarkRulesKeepIt()
+ {
+ // A client that converts colours itself (Gmail app, non-Gmail account) ignores our dark rules. Model: invert the HSL
+ // lightness of the inline light colours. It is an approximation, written down so nobody expects more of the
+ // light pair; the real clients cannot be tested in code.
+ static string Invert(string hex)
+ {
+ int R(int i) => Convert.ToInt32(hex.Substring(i, 2), 16);
+ var (r, g, b) = (R(1) / 255.0, R(3) / 255.0, R(5) / 255.0);
+ double max = Math.Max(r, Math.Max(g, b)), min = Math.Min(r, Math.Min(g, b)), l = (max + min) / 2, d = max - min;
+ double h = 0, sat = 0;
+ if (d > 0)
+ {
+ sat = l > 0.5 ? d / (2 - max - min) : d / (max + min);
+ h = max == r ? ((g - b) / d + (g < b ? 6 : 0)) : max == g ? (b - r) / d + 2 : (r - g) / d + 4;
+ h /= 6;
+ }
+ var l2 = 1 - l;
+ double Hue(double p, double q, double t)
+ {
+ if (t < 0) t += 1; if (t > 1) t -= 1;
+ return t < 1.0 / 6 ? p + (q - p) * 6 * t : t < 0.5 ? q : t < 2.0 / 3 ? p + (q - p) * (2.0 / 3 - t) * 6 : p;
+ }
+ double r2, g2, b2;
+ if (sat == 0) r2 = g2 = b2 = l2;
+ else
+ {
+ var q = l2 < 0.5 ? l2 * (1 + sat) : l2 + sat - l2 * sat;
+ var p = 2 * l2 - q;
+ r2 = Hue(p, q, h + 1.0 / 3); g2 = Hue(p, q, h); b2 = Hue(p, q, h - 1.0 / 3);
+ }
+ return $"#{(int)Math.Round(r2 * 255):x2}{(int)Math.Round(g2 * 255):x2}{(int)Math.Round(b2 * 255):x2}";
+ }
+
+ var light = MailColours.Contrast("#f3f4f6", "#ffffff");
+ var converted = MailColours.Contrast(Invert("#f3f4f6"), Invert("#ffffff"));
+ var darkRules = MailColours.Contrast(MailTemplateRenderer.DarkCard, MailTemplateRenderer.DarkPage);
+
+ light.Should().BeApproximately(1.10, 0.02);
+ converted.Should().BeLessThan(light); // ~1.06: the conversion removes the difference
+ darkRules.Should().BeGreaterThan(light * 1.4); // 1.62: our own dark rules keep a clearly visible difference
+ }
+
[Fact]
public void TheCard_HasAGutterOnNarrowScreens_InlineOnTheOuterCell_SoThePageColourShowsAtTheSides()
{
diff --git a/src/SlpModularCms.Core/Email/MailTemplateRenderer.cs b/src/SlpModularCms.Core/Email/MailTemplateRenderer.cs
index bc2a847..cbeab6f 100644
--- a/src/SlpModularCms.Core/Email/MailTemplateRenderer.cs
+++ b/src/SlpModularCms.Core/Email/MailTemplateRenderer.cs
@@ -159,11 +159,12 @@ public sealed class MailTemplateRenderer : IMailTemplateRenderer
private static string E(string value) => WebUtility.HtmlEncode(value);
// Dark mode mirrors the light layout: the outer page is the darker surface and the card stands out against it
- // (the earlier #111827 / #1f2937 pair was nearly the same shade, so the card vanished). A 1px border keeps the
- // edge visible in clients that re-colour the mail themselves (Gmail app, Outlook) and flatten the two backgrounds.
- public const string DarkPage = "#0a0e14";
- public const string DarkCard = "#273244";
- private const string DarkCardBorder = "#475569";
+ // (the earlier #111827 / #1f2937 pair was nearly the same shade, so the card vanished). The border exists ONLY in
+ // the dark rules (subtle); light mode has no border. Clients that convert the colours themselves (Gmail app on a
+ // non-Gmail account) ignore these rules and show the card less clearly - accepted by Bryan.
+ public const string DarkPage = "#080b10";
+ public const string DarkCard = "#2b3648";
+ public const string DarkCardBorder = "#394457";
private static string BuildHtml(
MailModel model, string site, string colour, string? greeting, string heading, string intro,
@@ -197,12 +198,12 @@ public sealed class MailTemplateRenderer : IMailTemplateRenderer
sb.Append("}");
// Outlook.com / Outlook apps ignore the media query and mark their own dark mode with these attributes.
sb.Append($"[data-ogsb] .mail-page{{background-color:{DarkPage} !important;}}");
- sb.Append($"[data-ogsb] .mail-card{{background-color:{DarkCard} !important;border-color:{DarkCardBorder} !important;}}");
+ sb.Append($"[data-ogsb] .mail-card{{background-color:{DarkCard} !important;border:1px solid {DarkCardBorder} !important;}}");
sb.Append("[data-ogsc] .mail-card{color:#f3f4f6 !important;}[data-ogsc] .mail-muted{color:#9ca3af !important;}");
sb.Append("");
sb.Append("");
sb.Append("