/* Backgrounds (public/ui/fun.js, Settings > Background). Saved on this phone only (localStorage sp.bg).
   html[data-bg] turns on a fixed layer behind everything; cards and lists stay solid, so text keeps its contrast.
   The paintings were made once with scripts/make-backgrounds.mjs; everything else is CSS. */
html[data-bg] { background: var(--bg); }
html[data-bg] body { background: transparent !important; }
html[data-bg] body::before, html[data-bg] body::after { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; }
html[data-bg] body::before { background: var(--bg) !important; }
html[data-bg] header.top { background: transparent; border-bottom-color: transparent; }
/* Increase Contrast and printing get the plain background. */
@media (prefers-contrast: more) { html[data-bg] body::after { display: none; } }
@media print { html[data-bg] body::before, html[data-bg] body::after { display: none; } }

/* Previews in Settings */
.bgsw { position: relative; display: block; width: 44px; height: 66px; border-radius: 12px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); isolation: isolate; }
.bgsw::after { content: ""; position: absolute; inset: 0; }
.backgrounds { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }

html[data-bg="linen"] body::after, .bgsw[data-sw="linen"]::after { opacity: .55; background: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20width%3D'200'%20height%3D'200'%3E%3Cfilter%20id%3D'n'%3E%3CfeTurbulence%20type%3D'fractalNoise'%20baseFrequency%3D'.9'%20numOctaves%3D'2'%20stitchTiles%3D'stitch'%2F%3E%3CfeColorMatrix%20values%3D'0%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%20.5%200'%2F%3E%3C%2Ffilter%3E%3Crect%20width%3D'200'%20height%3D'200'%20filter%3D'url(%23n)'%2F%3E%3C%2Fsvg%3E"), repeating-linear-gradient(0deg, color-mix(in srgb, var(--ink) 4%, transparent) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--ink) 4%, transparent) 0 1px, transparent 1px 3px); background-size: 200px, auto, auto; }
html[data-bg="gingham"] body::after, .bgsw[data-sw="gingham"]::after { background: repeating-linear-gradient(0deg, color-mix(in srgb, var(--pa) 9%, transparent) 0 14px, transparent 14px 28px),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--pa) 9%, transparent) 0 14px, transparent 14px 28px); }
html[data-bg="jars"] body::after, .bgsw[data-sw="jars"]::after { background: color-mix(in srgb, var(--ink) 7%, transparent); -webkit-mask: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20width%3D'120'%20height%3D'120'%20viewBox%3D'0%200%20120%20120'%3E%20%3Cg%20fill%3D'%23000'%3E%20%3Crect%20x%3D'14'%20y%3D'10'%20width%3D'22'%20height%3D'5'%20rx%3D'2'%2F%3E%3Cpath%20d%3D'M12%2017h26v4c3%202%203%204%203%207v20c0%203-2%205-5%205H14c-3%200-5-2-5-5V28c0-3%200-5%203-7z'%2F%3E%20%3Crect%20x%3D'72'%20y%3D'64'%20width%3D'24'%20height%3D'30'%20rx%3D'3'%2F%3E%3Crect%20x%3D'70'%20y%3D'62'%20width%3D'28'%20height%3D'4'%20rx%3D'2'%2F%3E%3Crect%20x%3D'70'%20y%3D'92'%20width%3D'28'%20height%3D'4'%20rx%3D'2'%2F%3E%20%3Cpath%20d%3D'M88%208h6v8c4%203%206%206%206%2011v24c0%202-2%204-4%204H86c-2%200-4-2-4-4V27c0-5%202-8%206-11z'%2F%3E%20%3Cpath%20d%3D'M18%2072l4-6h16l4%206-2%204%202%204v22c0%202-2%204-4%204H22c-2%200-4-2-4-4V80l2-4z'%2F%3E%20%3C%2Fg%3E%3C%2Fsvg%3E") 0 0 / 120px; mask: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20width%3D'120'%20height%3D'120'%20viewBox%3D'0%200%20120%20120'%3E%20%3Cg%20fill%3D'%23000'%3E%20%3Crect%20x%3D'14'%20y%3D'10'%20width%3D'22'%20height%3D'5'%20rx%3D'2'%2F%3E%3Cpath%20d%3D'M12%2017h26v4c3%202%203%204%203%207v20c0%203-2%205-5%205H14c-3%200-5-2-5-5V28c0-3%200-5%203-7z'%2F%3E%20%3Crect%20x%3D'72'%20y%3D'64'%20width%3D'24'%20height%3D'30'%20rx%3D'3'%2F%3E%3Crect%20x%3D'70'%20y%3D'62'%20width%3D'28'%20height%3D'4'%20rx%3D'2'%2F%3E%3Crect%20x%3D'70'%20y%3D'92'%20width%3D'28'%20height%3D'4'%20rx%3D'2'%2F%3E%20%3Cpath%20d%3D'M88%208h6v8c4%203%206%206%206%2011v24c0%202-2%204-4%204H86c-2%200-4-2-4-4V27c0-5%202-8%206-11z'%2F%3E%20%3Cpath%20d%3D'M18%2072l4-6h16l4%206-2%204%202%204v22c0%202-2%204-4%204H22c-2%200-4-2-4-4V80l2-4z'%2F%3E%20%3C%2Fg%3E%3C%2Fsvg%3E") 0 0 / 120px; }
html[data-bg="herbs"] body::after, .bgsw[data-sw="herbs"]::after { background: color-mix(in srgb, var(--pa) 14%, transparent); -webkit-mask: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20width%3D'160'%20height%3D'160'%20viewBox%3D'0%200%20160%20160'%3E%20%3Cg%20fill%3D'none'%20stroke%3D'%23000'%20stroke-width%3D'2.2'%20stroke-linecap%3D'round'%3E%20%3Cpath%20d%3D'M30%2070%20C34%2050%2040%2034%2052%2018'%2F%3E%3Cpath%20d%3D'M120%20150%20C116%20128%20118%20112%20132%2096'%2F%3E%3C%2Fg%3E%20%3Cg%20fill%3D'%23000'%3E%20%3Cellipse%20cx%3D'36'%20cy%3D'56'%20rx%3D'9'%20ry%3D'4'%20transform%3D'rotate(-35%2036%2056)'%2F%3E%3Cellipse%20cx%3D'44'%20cy%3D'44'%20rx%3D'9'%20ry%3D'4'%20transform%3D'rotate(35%2044%2044)'%2F%3E%20%3Cellipse%20cx%3D'42'%20cy%3D'34'%20rx%3D'8'%20ry%3D'3.6'%20transform%3D'rotate(-40%2042%2034)'%2F%3E%3Cellipse%20cx%3D'52'%20cy%3D'26'%20rx%3D'8'%20ry%3D'3.6'%20transform%3D'rotate(30%2052%2026)'%2F%3E%20%3Cellipse%20cx%3D'117'%20cy%3D'130'%20rx%3D'10'%20ry%3D'4.5'%20transform%3D'rotate(-30%20117%20130)'%2F%3E%3Cellipse%20cx%3D'126'%20cy%3D'118'%20rx%3D'10'%20ry%3D'4.5'%20transform%3D'rotate(40%20126%20118)'%2F%3E%20%3Cellipse%20cx%3D'123'%20cy%3D'106'%20rx%3D'8'%20ry%3D'3.8'%20transform%3D'rotate(-35%20123%20106)'%2F%3E%20%3Ccircle%20cx%3D'98'%20cy%3D'40'%20r%3D'5'%2F%3E%3Ccircle%20cx%3D'106'%20cy%3D'46'%20r%3D'4'%2F%3E%3Ccircle%20cx%3D'96'%20cy%3D'50'%20r%3D'3.5'%2F%3E%20%3Ccircle%20cx%3D'60'%20cy%3D'124'%20r%3D'3'%2F%3E%3Ccircle%20cx%3D'66'%20cy%3D'130'%20r%3D'2.6'%2F%3E%20%3C%2Fg%3E%3C%2Fsvg%3E") 0 0 / 160px; mask: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20width%3D'160'%20height%3D'160'%20viewBox%3D'0%200%20160%20160'%3E%20%3Cg%20fill%3D'none'%20stroke%3D'%23000'%20stroke-width%3D'2.2'%20stroke-linecap%3D'round'%3E%20%3Cpath%20d%3D'M30%2070%20C34%2050%2040%2034%2052%2018'%2F%3E%3Cpath%20d%3D'M120%20150%20C116%20128%20118%20112%20132%2096'%2F%3E%3C%2Fg%3E%20%3Cg%20fill%3D'%23000'%3E%20%3Cellipse%20cx%3D'36'%20cy%3D'56'%20rx%3D'9'%20ry%3D'4'%20transform%3D'rotate(-35%2036%2056)'%2F%3E%3Cellipse%20cx%3D'44'%20cy%3D'44'%20rx%3D'9'%20ry%3D'4'%20transform%3D'rotate(35%2044%2044)'%2F%3E%20%3Cellipse%20cx%3D'42'%20cy%3D'34'%20rx%3D'8'%20ry%3D'3.6'%20transform%3D'rotate(-40%2042%2034)'%2F%3E%3Cellipse%20cx%3D'52'%20cy%3D'26'%20rx%3D'8'%20ry%3D'3.6'%20transform%3D'rotate(30%2052%2026)'%2F%3E%20%3Cellipse%20cx%3D'117'%20cy%3D'130'%20rx%3D'10'%20ry%3D'4.5'%20transform%3D'rotate(-30%20117%20130)'%2F%3E%3Cellipse%20cx%3D'126'%20cy%3D'118'%20rx%3D'10'%20ry%3D'4.5'%20transform%3D'rotate(40%20126%20118)'%2F%3E%20%3Cellipse%20cx%3D'123'%20cy%3D'106'%20rx%3D'8'%20ry%3D'3.8'%20transform%3D'rotate(-35%20123%20106)'%2F%3E%20%3Ccircle%20cx%3D'98'%20cy%3D'40'%20r%3D'5'%2F%3E%3Ccircle%20cx%3D'106'%20cy%3D'46'%20r%3D'4'%2F%3E%3Ccircle%20cx%3D'96'%20cy%3D'50'%20r%3D'3.5'%2F%3E%20%3Ccircle%20cx%3D'60'%20cy%3D'124'%20r%3D'3'%2F%3E%3Ccircle%20cx%3D'66'%20cy%3D'130'%20r%3D'2.6'%2F%3E%20%3C%2Fg%3E%3C%2Fsvg%3E") 0 0 / 160px; }
html[data-bg="terrazzo"] body::after, .bgsw[data-sw="terrazzo"]::after { background: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20width%3D'180'%20height%3D'180'%20viewBox%3D'0%200%20180%20180'%3E%20%3Cpath%20d%3D'M20%2030l12-4%206%2010-10%206z'%20fill%3D'%23D49A2E'%2F%3E%3Cpath%20d%3D'M120%2020l14%203-3%2012-12-2z'%20fill%3D'%234E7D8A'%2F%3E%20%3Cpath%20d%3D'M70%2080l9%202-2%209-9-3z'%20fill%3D'%23A8432C'%2F%3E%3Cpath%20d%3D'M150%20110l10%206-6%209-9-6z'%20fill%3D'%238FA67A'%2F%3E%20%3Cpath%20d%3D'M30%20140l16-2%202%2010-14%204z'%20fill%3D'%234E7D8A'%2F%3E%3Cpath%20d%3D'M100%20150l7-6%206%207-7%205z'%20fill%3D'%23D49A2E'%2F%3E%20%3Ccircle%20cx%3D'60'%20cy%3D'30'%20r%3D'2.5'%20fill%3D'%231F2421'%2F%3E%3Ccircle%20cx%3D'160'%20cy%3D'60'%20r%3D'2'%20fill%3D'%23A8432C'%2F%3E%3Ccircle%20cx%3D'95'%20cy%3D'115'%20r%3D'2.2'%20fill%3D'%231F2421'%2F%3E%20%3Ccircle%20cx%3D'15'%20cy%3D'95'%20r%3D'3'%20fill%3D'%238FA67A'%2F%3E%3Ccircle%20cx%3D'135'%20cy%3D'165'%20r%3D'2'%20fill%3D'%231F2421'%2F%3E%3Cpath%20d%3D'M80%2040l5%201-1%205-5-1z'%20fill%3D'%238FA67A'%2F%3E%20%3C%2Fsvg%3E") 0 0 / 180px; opacity: .22; }
html[data-bg="sunrise"] body::after, .bgsw[data-sw="sunrise"]::after { background: radial-gradient(60% 45% at 10% 0%, #f6c9a8aa, transparent 70%), radial-gradient(55% 40% at 100% 18%, #c9dcc0bb, transparent 70%),
    radial-gradient(70% 50% at 80% 100%, #b9d3da99, transparent 70%), radial-gradient(50% 40% at 0% 85%, #f1dba2aa, transparent 70%); }
html[data-bg="paint-garden"] body::after, .bgsw[data-sw="paint-garden"]::after { background: url("art/bg-garden.webp") center / cover; }
html[data-bg="paint-watercolour"] body::after, .bgsw[data-sw="paint-watercolour"]::after { background: url("art/bg-watercolour.webp") center / cover; }
html[data-bg="paint-orchard"] body::after, .bgsw[data-sw="paint-orchard"]::after { background: url("art/bg-orchard.webp") center / cover; }
html[data-bg="paint-hills"] body::after, .bgsw[data-sw="paint-hills"]::after { background: url("art/bg-hills.webp") center / cover; }

/* Dark mode: night paintings for the garden and hills; the others are dimmed. */
:root[data-theme="dark"][data-bg="terrazzo"] body::after, :root[data-theme="dark"] .bgsw[data-sw="terrazzo"]::after { opacity: .28; }
:root[data-theme="dark"][data-bg="sunrise"] body::after, :root[data-theme="dark"] .bgsw[data-sw="sunrise"]::after { background: radial-gradient(60% 45% at 10% 0%, #5a3a2c, transparent 70%), radial-gradient(55% 40% at 100% 18%, #2e4433, transparent 70%),
    radial-gradient(70% 50% at 80% 100%, #24414a, transparent 70%), radial-gradient(50% 40% at 0% 85%, #4a3d22, transparent 70%); }
:root[data-theme="dark"][data-bg="paint-garden"] body::after, :root[data-theme="dark"] .bgsw[data-sw="paint-garden"]::after { background-image: url("art/bg-night-garden.webp"); }
:root[data-theme="dark"][data-bg="paint-hills"] body::after, :root[data-theme="dark"] .bgsw[data-sw="paint-hills"]::after { background-image: url("art/bg-night-hills.webp"); }
:root[data-theme="dark"][data-bg="paint-watercolour"] body::after, :root[data-theme="dark"] .bgsw[data-sw="paint-watercolour"]::after { filter: brightness(.36) saturate(.85); }
:root[data-theme="dark"][data-bg="paint-orchard"] body::after, :root[data-theme="dark"] .bgsw[data-sw="paint-orchard"]::after { filter: brightness(.36) saturate(.85); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"])[data-bg="terrazzo"] body::after, :root:not([data-theme="light"]) .bgsw[data-sw="terrazzo"]::after { opacity: .28; }
  :root:not([data-theme="light"])[data-bg="sunrise"] body::after, :root:not([data-theme="light"]) .bgsw[data-sw="sunrise"]::after { background: radial-gradient(60% 45% at 10% 0%, #5a3a2c, transparent 70%), radial-gradient(55% 40% at 100% 18%, #2e4433, transparent 70%),
    radial-gradient(70% 50% at 80% 100%, #24414a, transparent 70%), radial-gradient(50% 40% at 0% 85%, #4a3d22, transparent 70%); }
  :root:not([data-theme="light"])[data-bg="paint-garden"] body::after, :root:not([data-theme="light"]) .bgsw[data-sw="paint-garden"]::after { background-image: url("art/bg-night-garden.webp"); }
  :root:not([data-theme="light"])[data-bg="paint-hills"] body::after, :root:not([data-theme="light"]) .bgsw[data-sw="paint-hills"]::after { background-image: url("art/bg-night-hills.webp"); }
  :root:not([data-theme="light"])[data-bg="paint-watercolour"] body::after, :root:not([data-theme="light"]) .bgsw[data-sw="paint-watercolour"]::after { filter: brightness(.36) saturate(.85); }
  :root:not([data-theme="light"])[data-bg="paint-orchard"] body::after, :root:not([data-theme="light"]) .bgsw[data-sw="paint-orchard"]::after { filter: brightness(.36) saturate(.85); }
}

/* The previews are small, so their patterns are drawn smaller too. */
.bgsw[data-sw="jars"]::after { -webkit-mask-size: 40px; mask-size: 40px; }
.bgsw[data-sw="herbs"]::after { -webkit-mask-size: 48px; mask-size: 48px; }
.bgsw[data-sw="terrazzo"]::after { background-size: 56px; opacity: .45; }
.bgsw[data-sw="gingham"]::after { background-size: auto; }
.bgsw[data-sw="paint-hills"]::after { background-position: center 88%; }
