/*
 * The rainbow theme, the first mascot theme (docs/how-to-mascots.md): deep
 * rainbow colors, unicorns, bouncing rainbows, a rainbow Outlook line, and
 * bananas on the pressure meter. Ten quick clicks anywhere turn it on for a
 * day (rainbow_secret_controller.js). Nothing on the page mentions it.
 * mascots.css places and moves the animals; this file only says what the
 * rainbow theme looks like. A new theme copies this file's shape.
 */

/* Soft, the first version, kept as a reference. Nothing turns it on. The
   map's hues, each mixed into --color-page, so the same rule is pastel in
   light mode and deep in dark mode. A fixed layer rather than
   background-attachment: fixed, which iOS Safari ignores. */
[data-backdrop="rainbow"] {
  --rainbow-mix: 34%;
  --rainbow-tile: color-mix(in srgb, var(--color-surface) 68%, transparent);
  --rainbow-tile-border: color-mix(in srgb, var(--color-border) 55%, transparent);
}

[data-backdrop="rainbow"][data-theme="dark"] {
  --rainbow-mix: 30%;
  --rainbow-tile: color-mix(in srgb, var(--color-surface) 62%, transparent);
}

[data-backdrop="rainbow"] body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(
    135deg,
    color-mix(in srgb, #7c3aed var(--rainbow-mix), var(--color-page)) 0%,
    color-mix(in srgb, #2563eb var(--rainbow-mix), var(--color-page)) 18%,
    color-mix(in srgb, #06b6d4 var(--rainbow-mix), var(--color-page)) 34%,
    color-mix(in srgb, #22c55e var(--rainbow-mix), var(--color-page)) 50%,
    color-mix(in srgb, #facc15 var(--rainbow-mix), var(--color-page)) 66%,
    color-mix(in srgb, #f97316 var(--rainbow-mix), var(--color-page)) 82%,
    color-mix(in srgb, #ef4444 var(--rainbow-mix), var(--color-page)) 100%
  );
}

/* Tiles and panels go see-through, so the color shows through. Soft frosts
   them like the map controls. */
[data-backdrop="rainbow"] .tile,
[data-backdrop="rainbow"] .panel,
[data-mascots="rainbow"] .tile,
[data-mascots="rainbow"] .panel {
  background: var(--rainbow-tile);
  border-color: var(--rainbow-tile-border);
}

[data-backdrop="rainbow"] .tile,
[data-backdrop="rainbow"] .panel {
  -webkit-backdrop-filter: var(--frost-blur);
  backdrop-filter: var(--frost-blur);
}

/* ---- The theme --------------------------------------------------------- */

[data-mascots="rainbow"] {
  --rainbow-mix: 62%;
  --rainbow-tile: color-mix(in srgb, var(--color-surface) 84%, transparent);
  --rainbow-tile-border: color-mix(in srgb, var(--color-border) 60%, transparent);

  /* The drawing for each role (mascots.css lists them). */
  --mascot-walk: url("/assets/decor/unicorn-b5d8c89f.svg");
  --mascot-sit: url("/assets/decor/unicorn-sit-9a95f7bb.svg");
  --mascot-walk-rare: url("/assets/decor/unicorn-purple-5ebf8cf8.svg");
  --mascot-sit-rare: url("/assets/decor/unicorn-purple-sit-ed10a46f.svg");
  --mascot-sleep: url("/assets/decor/unicorn-sleep-cb58e583.svg");
  --mascot-wake: url("/assets/decor/unicorn-wake-820ff449.svg");
  --mascot-chew: url("/assets/decor/unicorn-chew-d8d7c766.svg");
  --mascot-hang: url("/assets/decor/unicorn-hang-bcd213af.svg");
  --mascot-wave: url("/assets/decor/unicorn-wave-1d264930.svg");
  --mascot-fly: url("/assets/decor/unicorn-fly-edd2bb04.svg");
  --mascot-fly-shy: url("/assets/decor/unicorn-fly-blush-ae1029fb.svg");
  --mascot-puff: url("/assets/decor/toot-3abef71d.svg");
  --mascot-puff-burst: url("/assets/decor/toot-burst-2b87dd6d.svg");
  --mascot-bounce: url("/assets/decor/rainbow-4cba34d7.svg");

  /* The burst lines take the next of these on each click, red to violet
     and round again. */
  --mascot-puff-colors: #f87171 #fb923c #fde047 #4ade80 #60a5fa #a78bfa;

  /* The unicorn drawings are 64 by 56, the rainbow 0.65 as tall as wide,
     and the toot comes out of the rump, 0.3 in from the tail end and 0.6
     down. */
  --mascot-aspect: 0.875;
  --mascot-bounce-aspect: 0.65;
  --mascot-puff-x: 0.3;
  --mascot-puff-y: 0.6;
}

[data-mascots="rainbow"][data-theme="dark"] {
  --rainbow-mix: 88%;
  --rainbow-tile: color-mix(in srgb, var(--color-surface) 72%, transparent);
}

/* No frosted blur here: the rainbows move behind the tiles, so every tile
   they cross would blur its backdrop again on every frame, which is what
   made the page stutter. The tiles are a little more solid instead. */
[data-mascots="rainbow"] .tile,
[data-mascots="rainbow"] .panel {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

[data-mascots="rainbow"] body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(
    135deg,
    color-mix(in srgb, #5b21b6 var(--rainbow-mix), var(--color-page)) 0%,
    color-mix(in srgb, #1d4ed8 var(--rainbow-mix), var(--color-page)) 18%,
    color-mix(in srgb, #0e7490 var(--rainbow-mix), var(--color-page)) 34%,
    color-mix(in srgb, #15803d var(--rainbow-mix), var(--color-page)) 50%,
    color-mix(in srgb, #ca8a04 var(--rainbow-mix), var(--color-page)) 66%,
    color-mix(in srgb, #c2410c var(--rainbow-mix), var(--color-page)) 82%,
    color-mix(in srgb, #b91c1c var(--rainbow-mix), var(--color-page)) 100%
  );
}

/* Rainbow temperature line: red up high, violet down low. */
[data-mascots="rainbow"] .today-line,
[data-mascots="rainbow"] .today-line.is-ahead {
  stroke: url(#today-rainbow);
  stroke-width: 3.5;
  opacity: 1;
}

/* ---- Where the drawings meet the page ---------------------------------- */

/* The unicorn chewing the moon, its mouth in a bite out of the first lit
   part of the moon. The moon disk is radius 20 in a 64 box
   (Weather::MoonDisk), so its left edge is 18.75% in. --bite is where the
   lit part starts, across the 64 box: 0.1875 from first quarter through
   full and waning, further right on a waxing moon, where the left side is
   dark (mascot_controller.js reads it from the drawing). The unicorn moves
   right with it. The drawing's mouth is at 59.1, 33.1 of 64 by 56, so at
   3.3rem by 2.9rem it sits 3.05rem across and 1.71rem down: with the moon
   2.4rem in, that is just inside the bite. */
[data-mascots="rainbow"] .forecast-moon-current:has(.mascot-chewer) {
  padding-left: 2.4rem;
}

[data-mascots="rainbow"] .mascot-chewer {
  top: calc(50% - 1.71rem);
  left: calc((var(--bite) - 0.1875) * 2.25rem);
  width: 3.3rem;
  height: 2.9rem;
}

[data-mascots="rainbow"] .forecast-moon-current:has(.mascot-chewer) .forecast-moon-symbol {
  -webkit-mask: radial-gradient(circle at calc(var(--bite) * 100%) 50%, transparent 0.27rem, #000 0.29rem);
  mask: radial-gradient(circle at calc(var(--bite) * 100%) 50%, transparent 0.27rem, #000 0.29rem);
}

/* Nothing to eat at new moon: it sits beside the moon and waits. */
[data-mascots="rainbow"] .forecast-moon-current.is-new-moon .mascot-chewer {
  top: calc(50% - 1.1rem);
  left: 0;
  width: 2.3rem;
  height: 2rem;
}

[data-mascots="rainbow"] .forecast-moon-current.is-new-moon .forecast-moon-symbol {
  -webkit-mask: none;
  mask: none;
}

/* The hanging unicorn grips with its hooves, 3 of 64 down the drawing. */
[data-mascots="rainbow"] .mascot-hang {
  margin-top: calc(-2.56rem * 3 / 64);
}

/* ---- Bananas for the pressure chevrons --------------------------------- */

[data-mascots="rainbow"] .forecast-pressure-marker:is(.is-rising, .is-falling, .is-rising-fast, .is-falling-fast, .is-rising-very-fast, .is-falling-very-fast) svg {
  --bananas: 100%;
  background: url("/assets/decor/banana-ac7dcabf.svg") left center / var(--bananas) 100% repeat-x;
}

[data-mascots="rainbow"] .forecast-pressure-marker:is(.is-rising, .is-falling, .is-rising-fast, .is-falling-fast, .is-rising-very-fast, .is-falling-very-fast) svg path {
  display: none;
}

[data-mascots="rainbow"] .forecast-pressure-marker:is(.is-rising-fast, .is-falling-fast) svg { --bananas: 50%; }
[data-mascots="rainbow"] .forecast-pressure-marker:is(.is-rising-very-fast, .is-falling-very-fast) svg { --bananas: 33.333%; }

/* A bunch is wider than a chevron, so the marker widens to fit one, two,
   or three bunches. */
[data-mascots="rainbow"] .forecast-pressure-marker:is(.is-rising, .is-falling) { width: calc(1.45rem * 16 / 22); }
[data-mascots="rainbow"] .forecast-pressure-marker:is(.is-rising-fast, .is-falling-fast) { width: calc(1.45rem * 28 / 22); }
[data-mascots="rainbow"] .forecast-pressure-marker:is(.is-rising-very-fast, .is-falling-very-fast) { width: calc(1.45rem * 40 / 22); }
[data-mascots="rainbow"] .forecast-pressure-marker:is(.is-falling, .is-falling-fast, .is-falling-very-fast) svg { transform: scaleX(-1); }
