/*
 * The report's default background (html[data-bg="blend"]; ?bg=none turns it off): four palettes from four mood pictures.
 *   paper — cream paper and a red-orange orb, near-black serif text
 *   bloom — cream-white, butter yellow above, apricot below
 *   sky   — powder blue, a pale butter corner, white below
 *   mist  — cream, a lavender-blue haze, coral and apricot glows
 * pages/moods.js gives each part of the report a mood (data-mood). The mood sets that part's text and chart tokens, so
 * every chart inside follows. The sky behind the page is one fixed layer per mood (.mood-sky); the script cross-fades
 * the layers as one part hands over to the next. Light only: the switch forces the light theme.
 */

/* ---- the four skies -------------------------------------------------------------------------------------------- */
html[data-bg="blend"] {
  --ms-noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n' x='0' y='0' width='100%25' height='100%25'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/></svg>");
  /* Each sky is a still base plate and two orb layers that drift a little with the pointer (pages/moods.js):
   * layer a follows the pointer, layer b moves away from it, so the orbs push and pull against each other. */
  --ms-paper-base: linear-gradient(180deg, #f8f1e4, #f3e7d4);
  --ms-paper-a: radial-gradient(ellipse 70% 55% at 0% 0%, rgba(255, 251, 243, .9), rgba(255, 251, 243, 0) 70%);
  --ms-paper-b: radial-gradient(circle at 104% 98%, #b8260b 0, #d4500d 9vmin, #e48213 18vmin, #ecaa32 27vmin, rgba(239, 200, 131, .55) 38vmin, rgba(239, 200, 131, 0) 52vmin);
  /* The glows sit at the edges and corners; the middle stays bright (a white wash, .mood-sky > i::after, keeps
   * the reading area clear). Review 17 Nov. */
  /* bloom: cream-white, a butter-yellow glow from the top right, apricot from the lower left */
  --ms-bloom-base: linear-gradient(180deg, #fffcf5 0%, #fdf7ec 100%);
  --ms-bloom-a:
    radial-gradient(ellipse 70vmin 56vmin at 100% 0%, rgba(251, 238, 160, .95), rgba(252, 244, 190, .5) 50%, rgba(252, 244, 190, 0) 100%),
    radial-gradient(ellipse 60vmin 40vmin at 100% 96%, rgba(244, 206, 182, .6), rgba(244, 206, 182, 0) 100%);
  --ms-bloom-b:
    radial-gradient(ellipse 66vmin 60vmin at 0% 88%, rgba(234, 172, 128, .85), rgba(239, 190, 152, .45) 55%, rgba(239, 190, 152, 0) 100%),
    radial-gradient(ellipse 34vmin 46vmin at -4% 22%, rgba(247, 214, 176, .6), rgba(247, 214, 176, 0) 100%);
  /* sky: powder blue from the left, pale butter in the top right corner, butter-white along the bottom */
  --ms-sky-base: linear-gradient(180deg, #f6f8f8 0%, #f9faf7 60%, #fcfbf4 100%);
  --ms-sky-a:
    radial-gradient(ellipse 66vmin 78vmin at -2% 26%, rgba(140, 194, 230, .9), rgba(170, 210, 236, .45) 55%, rgba(170, 210, 236, 0) 100%),
    radial-gradient(ellipse 40vmin 40vmin at 102% 92%, rgba(170, 208, 232, .5), rgba(170, 208, 232, 0) 100%);
  --ms-sky-b:
    radial-gradient(ellipse 52vmin 52vmin at 102% 0%, rgba(240, 234, 150, .92), rgba(244, 240, 186, .45) 55%, rgba(244, 240, 186, 0) 100%),
    radial-gradient(ellipse 90vmin 24vmin at 50% 106%, rgba(246, 240, 196, .55), rgba(246, 240, 196, 0) 100%);
  /* mist: cream, lavender-blue from the top left, coral from the right, apricot from the lower left */
  --ms-mist-base: linear-gradient(180deg, #fdf8ef 0%, #fdf5ec 100%);
  --ms-mist-a:
    radial-gradient(ellipse 58vmin 54vmin at 0% 12%, rgba(196, 202, 234, 1), rgba(208, 210, 236, .55) 55%, rgba(208, 210, 236, 0) 100%);
  --ms-mist-b:
    radial-gradient(ellipse 56vmin 50vmin at 102% 64%, rgba(250, 170, 148, .9), rgba(250, 186, 166, .48) 55%, rgba(250, 186, 166, 0) 100%),
    radial-gradient(ellipse 40vmin 36vmin at -2% 90%, rgba(246, 186, 132, .8), rgba(246, 186, 132, 0) 100%),
    radial-gradient(ellipse 70vmin 30vmin at 70% 108%, rgba(252, 206, 186, .55), rgba(252, 206, 186, 0) 100%);
  background: #f7eedf;
}
html[data-bg="blend"] body { background: transparent; }
/* the old in-bar switch stays hidden: the switch is the rounded square at the top right (pages/theme-button.js) */
html[data-bg="blend"] m-theme-toggle { display: none; }

.mood-sky { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.mood-sky > i { position: absolute; inset: 0; opacity: 0; }
.mood-sky > .ms-paper { opacity: 1; }
.mood-sky > i > span { position: absolute; inset: -8vmin; will-change: transform; }   /* overscan: the drift never shows an edge */
.mood-sky > i > .base { inset: 0; will-change: auto; }
/* --mx, --my: the eased pointer, -1 to 1 from the centre (pages/moods.js) */
.mood-sky > i > .a { transform: translate3d(calc(var(--mx, 0) * 5vmin), calc(var(--my, 0) * 4vmin), 0); }
.mood-sky > i > .b { transform: translate3d(calc(var(--mx, 0) * -6vmin), calc(var(--my, 0) * -5vmin), 0); }
/* the bright middle: a still white wash over the glows of every sky but the paper one */
.mood-sky > i:not(.ms-paper)::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 52% 50% at 50% 48%, rgba(255, 254, 250, .92) 0%, rgba(255, 254, 250, .7) 42%, rgba(255, 254, 250, 0) 100%);
}
.ms-paper > .base { background: var(--ms-paper-base); } .ms-paper > .a { background: var(--ms-paper-a); } .ms-paper > .b { background: var(--ms-paper-b); }
.ms-bloom > .base { background: var(--ms-bloom-base); } .ms-bloom > .a { background: var(--ms-bloom-a); } .ms-bloom > .b { background: var(--ms-bloom-b); }
.ms-sky > .base { background: var(--ms-sky-base); }     .ms-sky > .a { background: var(--ms-sky-a); }     .ms-sky > .b { background: var(--ms-sky-b); }
.ms-mist > .base { background: var(--ms-mist-base); }   .ms-mist > .a { background: var(--ms-mist-a); }   .ms-mist > .b { background: var(--ms-mist-b); }
.mood-sky > b { position: absolute; inset: 0; z-index: 3; background: var(--ms-noise) repeat; background-size: 240px 240px; mix-blend-mode: soft-light; opacity: .85; }

/* the opening does not blend to a page colour: it fades out, and the live mood sky under it shows through */
html[data-bg="blend"] .op-white { display: none; }
html[data-bg="blend"] .op-stage { opacity: calc(1 - var(--white)); }

/* ---- the page chrome: glass over the sky ------------------------------------------------------------------------ */
html[data-bg="blend"] {
  --nav-strong-bg: rgba(255, 255, 255, .34);
  --nav-soft-bg: rgba(255, 255, 255, .34);
  --nav-footer-bg: rgba(255, 255, 255, .6);
  --nav-sheet-bg: #faf6ef;
}
html[data-bg="blend"] .op-over > .overview { background: color-mix(in srgb, var(--bg) 45%, #fff); }
html[data-bg="blend"] .chapter-exit-page,
html[data-bg="blend"] .age-topbar { background: transparent; }
html[data-bg="blend"] #age-thirty { background: color-mix(in srgb, var(--cat-primary) 6%, transparent); }   /* phone band */

/* ---- the palettes: text and chart tokens per mood --------------------------------------------------------------- */
/* paper is also the page default (the nav, tooltips and dialogs sit outside the parts) */
html[data-bg="blend"], html[data-bg="blend"] [data-mood="paper"] {
  --bg: #f7eedf; --ink: #1f1a17; --ink-rgb: 31, 26, 23; --muted: #76624f; --hairline: #e6d8c3;
  --accent: #a2190d; --accent-rgb: 162, 25, 13; --accent2: #c32534; --accent2-rgb: 195, 37, 52;
  --highlight-rgb: 246, 163, 62; --pill-rgb: 234, 124, 52; --insight-rgb: 234, 124, 52; --takeaway-rgb: 234, 124, 52;
  --cat-1: #c32534; --cat-2: #ea7c34; --cat-3: #4a3a2e; --cat-4: #d28425; --cat-5: #8f1627; --cat-6: #8c7660;
  --cat-primary: #c32534; --cat-ghost: #c4b29c; --cat-alarm: #8f1627; --cat-baby: #4a3a2e;
  --div-neg: #4a3a2e; --div-pos: #c32534; --div-mid: #efe2cc;
}
html[data-bg="blend"] [data-mood="bloom"] {
  --bg: #fcf5e9; --ink: #2a2018; --ink-rgb: 42, 32, 24; --muted: #6e5d4a; --hairline: #ece0cd;
  --accent: #ba352b; --accent-rgb: 186, 53, 43; --accent2: #e35c37; --accent2-rgb: 227, 92, 55;
  --highlight-rgb: 253, 207, 163; --pill-rgb: 241, 146, 103; --insight-rgb: 200, 106, 68; --takeaway-rgb: 200, 106, 68;
  --cat-1: #e35c37; --cat-2: #e2992b; --cat-3: #6b4a33; --cat-4: #c08132; --cat-5: #ba352b; --cat-6: #cd9f7e;
  --cat-primary: #e35c37; --cat-ghost: #d8c8b2; --cat-alarm: #ba352b; --cat-baby: #6b4a33;
  --div-neg: #6b4a33; --div-pos: #e35c37; --div-mid: #f3e8d6;
}
html[data-bg="blend"] [data-mood="sky"] {
  --bg: #eef4f6; --ink: #0e2a33; --ink-rgb: 14, 42, 51; --muted: #3d5866; --hairline: #d3e2ea;
  --accent: #aa3a25; --accent-rgb: 170, 58, 37; --accent2: #da5930; --accent2-rgb: 218, 89, 48;
  --highlight-rgb: 255, 205, 125; --pill-rgb: 252, 160, 46; --insight-rgb: 252, 160, 46; --takeaway-rgb: 252, 160, 46;
  --cat-1: #da5930; --cat-2: #1f5f73; --cat-3: #d2841d; --cat-4: #0c3442; --cat-5: #aa3a25; --cat-6: #4f8496;
  --cat-primary: #da5930; --cat-ghost: #a9c3cf; --cat-alarm: #aa3a25; --cat-baby: #1f5f73;
  --div-neg: #1f5f73; --div-pos: #da5930; --div-mid: #e2edf1;
}
html[data-bg="blend"] [data-mood="mist"] {
  --bg: #f8efe8; --ink: #2b211d; --ink-rgb: 43, 33, 29; --muted: #675b54; --hairline: #e6d9cf;
  --accent: #7e322d; --accent-rgb: 126, 50, 45; --accent2: #b1423f; --accent2-rgb: 177, 66, 63;
  --highlight-rgb: 247, 226, 204; --pill-rgb: 235, 138, 90; --insight-rgb: 177, 66, 63; --takeaway-rgb: 177, 66, 63;
  --cat-1: #b1423f; --cat-2: #de7b4e; --cat-3: #4d4540; --cat-4: #c78d71; --cat-5: #7e322d; --cat-6: #958a83;
  --cat-primary: #b1423f; --cat-ghost: #cdbfb6; --cat-alarm: #7e322d; --cat-baby: #4d4540;
  --div-neg: #4d4540; --div-pos: #b1423f; --div-mid: #f1e6de;
}
/* tokens that tokens.css derives at :root: derive them again where the mood is set, so they follow it */
html[data-bg="blend"], html[data-bg="blend"] [data-mood] {
  --slot-1: var(--cat-1); --slot-2: var(--cat-2); --slot-3: var(--cat-3);
  --slot-4: var(--cat-4); --slot-5: var(--cat-5); --slot-6: var(--cat-6);
  --cat-emph: var(--cat-primary);
  --chip-bg: rgba(var(--ink-rgb), .1);
  --card-tint: rgba(var(--highlight-rgb), .16);
  --card-border: rgba(var(--ink-rgb), .4);
  --pill-bg: rgba(var(--pill-rgb), .3);
  --insight-wash: rgba(var(--insight-rgb), .06);
  --insight-bar: rgba(var(--insight-rgb), .14);
  --takeaway-wash: rgba(var(--takeaway-rgb), .06);
  --tooltip-ink: var(--ink);
  --tooltip-line: rgba(var(--ink-rgb), .18);
  --chart-border: rgba(var(--ink-rgb), .4);
  --chart-line: rgba(var(--ink-rgb), .2);
  --chart-wash: rgba(var(--ink-rgb), .05);
  --fig-line: rgba(var(--ink-rgb), .14);
  --fig-border: rgba(var(--ink-rgb), .18);
  --fig-bg: color-mix(in srgb, var(--bg) 55%, #fff);
  --axis-ink: rgba(var(--ink-rgb), .3);
  --label-ink: rgba(var(--ink-rgb), .6);
  --ref-ink: rgba(var(--ink-rgb), .62);
  --ramp-from: color-mix(in srgb, var(--cat-1) 16%, var(--bg));
  --ramp-via: var(--cat-emph);
  --ramp-to: var(--cat-2);
  --ramp: linear-gradient(90deg, var(--ramp-from) 2.3%, var(--ramp-via) 48.7%, var(--ramp-to) 95.1%);
  --nav-pill-bg: var(--bg);
  color: var(--ink);
}

/* ---- typography: kickers take the mood's accent ------------------------------------------------------------------ */
html[data-bg="blend"] [data-mood] :is(.t-kicker, .age-kicker, .chapter-exit-kicker, .sc-kicker) { color: var(--accent); }

/* ---- the skies are light: dark mode has one flat page (below) ---------------------------------------------------
 * Light mode keeps the four mood skies (the blend is the report's default look; 17 Nov: the flat #f5f4f0 page of the
 * design review was tried and the blend kept). In dark mode the sky layers are hidden. */
html[data-bg="blend"][data-theme="dark"] .mood-sky > i, html[data-bg="blend"][data-theme="dark"] .mood-sky > b { display: none; }

/* ---- dark mode over the flat page (review 17 Nov) -------------------------------------------------------------
 * A warm near-black page; text and chart colours from the edition's dark palette (tokens.css), the same in every
 * part. The opening keeps its orange. */
html[data-bg="blend"][data-theme="dark"], html[data-bg="blend"][data-theme="dark"] [data-mood] {
  --bg: #141110; --ink: #f2e9e4; --ink-rgb: 242, 233, 228; --muted: rgba(242, 233, 228, .6); --hairline: rgba(242, 233, 228, .14);
  /* the pinkish-orange accent turns lilac on the dark page (review 17 Nov) */
  --accent: #c9a6ff; --accent-rgb: 201, 166, 255; --accent2: #d5a2f5; --accent2-rgb: 213, 162, 245;
  --highlight-rgb: 196, 160, 255; --pill-rgb: 196, 160, 255; --insight-rgb: 196, 160, 255; --takeaway-rgb: 196, 160, 255;
  --cat-1: #c49aff; --cat-2: #f0a35e; --cat-3: #8fd0c4; --cat-4: #e2b24f; --cat-5: #ff8fb0; --cat-6: #8fb0e8;
  --cat-primary: #c49aff; --cat-ghost: #5c514c; --cat-alarm: #ff6e8a; --cat-baby: #8fd0c4;
  --div-neg: #8fb0e8; --div-pos: #c49aff; --div-mid: #2c2522;
  --fig-bg: color-mix(in srgb, var(--bg) 94%, #fff);
  --card-tint: rgba(255, 255, 255, .03);
  --nav-sheet-bg: #1c1715;
  color-scheme: dark;
}
html[data-bg="blend"][data-theme="dark"], html[data-bg="blend"][data-theme="dark"] .mood-sky { background: #141110; }
