/* Day ↔ Night: the sun and moon cycle played by the top-bar button (js/theme.js).
   html.theme-cycling is set for the length of the cycle; html[data-cycle] is "dusk" (to Night)
   or "dawn" (to Day). Everything here is decoration: aria-hidden, no pointer events. */

@property --light-angle { syntax: '<angle>'; inherits: false; initial-value: 180deg; }
@property --light-color { syntax: '<color>'; inherits: false; initial-value: rgba(255, 255, 255, 0); }
@property --shade-color { syntax: '<color>'; inherits: false; initial-value: rgba(0, 0, 0, 0); }

/* While the cycle plays, the rest of the hero holds still, so the page turn-over lines up. */
html.theme-cycling .hero-house, html.theme-cycling .house-scene, html.theme-cycling .name-track,
html.theme-cycling .hero-art::before, html.theme-cycling .floating-chip { animation-play-state: paused; }

/* ---------------------------------------------------------------- the sky behind the house */
.sky-cycle {
  position: absolute; inset: -14% -14% 0; z-index: -1; pointer-events: none;
  container-type: size;
  /* a soft horizon a little above the glass base, and soft edges all round */
  -webkit-mask-image: linear-gradient(to bottom, #000 64%, transparent 79%), radial-gradient(closest-side, #000 72%, transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to bottom, #000 64%, transparent 79%), radial-gradient(closest-side, #000 72%, transparent);
  mask-composite: intersect;
}
@media (max-width: 680px) { .sky-cycle { inset: -12% 0 0; } }

.sky-wash { position: absolute; inset: 0; opacity: 0; }
.sky-wash-sun {
  background:
    radial-gradient(42cqw 30cqh at var(--sun-x) 74%, rgba(255, 168, 92, 0.85), rgba(255, 120, 120, 0.4) 45%, transparent 75%),
    linear-gradient(to bottom, rgba(150, 110, 220, 0.18), rgba(255, 150, 120, 0.22) 70%, transparent);
}
.sky-wash-moon { background: radial-gradient(40cqw 34cqh at var(--moon-x) 40%, rgba(143, 216, 238, 0.45), rgba(169, 139, 255, 0.25) 50%, transparent 78%); }
html[data-cycle='dusk'] .sky-cycle { --sun-x: 84%; --moon-x: 22%; }
html[data-cycle='dawn'] .sky-cycle { --sun-x: 16%; --moon-x: 78%; }

/* The sun and moon ride opposite ends of one arm that turns clockwise round a point on the horizon. */
.sky-orbit { position: absolute; left: 50%; top: 72%; width: 0; height: 0; --r: 40cqw; }
.sky-body { position: absolute; left: 0; top: 0; border-radius: 50%; }
.sky-sun {
  width: 11cqw; height: 11cqw; margin: -5.5cqw;
  transform: translateY(calc(-1 * var(--r)));
  background: radial-gradient(circle, #fffbea 0 42%, #ffe2a0 58%, #ffc46e 70%, rgba(255, 196, 110, 0) 72%);
  box-shadow: 0 0 5cqw 1.5cqw rgba(255, 205, 120, 0.55), 0 0 14cqw 5cqw rgba(255, 175, 95, 0.25);
}
.sky-sun::after { /* reddens as it nears the horizon */
  content: ''; position: absolute; inset: 0; border-radius: 50%; opacity: 0;
  background: radial-gradient(circle, #ffd6a0 0 30%, #ff8a5c 66%, rgba(255, 110, 90, 0) 72%);
  box-shadow: 0 0 6cqw 2cqw rgba(255, 110, 90, 0.5);
}
.sky-moon {
  width: 8cqw; height: 8cqw; margin: -4cqw;
  transform: rotate(180deg) translateY(calc(-1 * var(--r)));
  background: radial-gradient(circle at 36% 34%, #ffffff, #e6ecff 46%, #c4ccf0 72%);
  box-shadow: inset -1.4cqw -0.9cqw 0 rgba(110, 120, 190, 0.32), 0 0 3cqw 0.6cqw rgba(143, 216, 238, 0.5), 0 0 10cqw 3cqw rgba(169, 139, 255, 0.28);
}

html[data-cycle='dusk'] .sky-orbit { animation: orbit-dusk var(--cycle-ms) linear both, sky-bodies-in var(--cycle-ms) linear both; }
html[data-cycle='dawn'] .sky-orbit { animation: orbit-dawn var(--cycle-ms) linear both, sky-bodies-in var(--cycle-ms) linear both; }
@keyframes orbit-dusk { from { rotate: 0deg; } to { rotate: 200deg; } }
@keyframes orbit-dawn { from { rotate: 180deg; } to { rotate: 380deg; } }
@keyframes sky-bodies-in { 0% { opacity: 0; } 10% { opacity: 1; } 86% { opacity: 1; } 100% { opacity: 0; } }

html[data-cycle='dusk'] .sky-sun::after { animation: sun-redden var(--cycle-ms) linear both; }
html[data-cycle='dawn'] .sky-sun::after { animation: sun-redden-dawn var(--cycle-ms) linear both; }
@keyframes sun-redden { 0%, 18% { opacity: 0; } 42%, 100% { opacity: 1; } }
@keyframes sun-redden-dawn { 0%, 46% { opacity: 1; } 80%, 100% { opacity: 0; } }

html[data-cycle='dusk'] .sky-wash-sun { animation: wash-sunset var(--cycle-ms) ease-in-out both; }
html[data-cycle='dusk'] .sky-wash-moon { animation: wash-moonrise var(--cycle-ms) ease-in-out both; }
html[data-cycle='dawn'] .sky-wash-sun { animation: wash-sunrise var(--cycle-ms) ease-in-out both; }
html[data-cycle='dawn'] .sky-wash-moon { animation: wash-moonset var(--cycle-ms) ease-in-out both; }
@keyframes wash-sunset { 0% { opacity: 0; } 25% { opacity: 0.45; } 44% { opacity: 0.95; } 62% { opacity: 0.35; } 80%, 100% { opacity: 0; } }
@keyframes wash-moonrise { 0%, 40% { opacity: 0; } 72% { opacity: 0.8; } 100% { opacity: 0; } }
@keyframes wash-sunrise { 0%, 36% { opacity: 0; } 52% { opacity: 0.95; } 74% { opacity: 0.5; } 100% { opacity: 0; } }
@keyframes wash-moonset { 0% { opacity: 0; } 20% { opacity: 0.7; } 46%, 100% { opacity: 0; } }

/* ---------------------------------------------------------------- light on the house
   A gradient laid over the house pictures, cut to the house's outline, that comes from the side the
   sun or moon is on (--light-angle follows the arm above: light angle = body angle + 180°). */
.house-light {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  /* mask-image is set by js/theme.js: the house's own outline */
  -webkit-mask-position: center; -webkit-mask-size: contain; -webkit-mask-repeat: no-repeat;
  mask-position: center; mask-size: contain; mask-repeat: no-repeat;
}
.house-light-key { background: linear-gradient(var(--light-angle), var(--light-color) 0%, transparent 62%); mix-blend-mode: overlay; }
.house-light-shade { background: linear-gradient(var(--light-angle), transparent 15%, var(--shade-color) 85%); mix-blend-mode: multiply; }
html[data-cycle='dusk'] .house-light { animation: house-light-dusk var(--cycle-ms) linear both; }
html[data-cycle='dawn'] .house-light { animation: house-light-dawn var(--cycle-ms) linear both; }

@keyframes house-light-dusk {
  0%    { --light-angle: 180deg; --light-color: rgba(255, 240, 205, 0);    --shade-color: rgba(30, 30, 80, 0); }
  16%   { --light-angle: 212deg; --light-color: rgba(255, 228, 170, 0.6);  --shade-color: rgba(30, 30, 80, 0.2); }
  32%   { --light-angle: 244deg; --light-color: rgba(255, 172, 82, 0.85); --shade-color: rgba(40, 22, 85, 0.45); }
  42%   { --light-angle: 264deg; --light-color: rgba(255, 112, 96, 0.7);  --shade-color: rgba(40, 25, 95, 0.6); }
  49.9% { --light-angle: 278deg; --light-color: rgba(255, 112, 96, 0);    --shade-color: rgba(20, 22, 70, 0.35); }
  50%   { --light-angle: 98deg;  --light-color: rgba(143, 216, 238, 0);  --shade-color: rgba(20, 22, 70, 0.35); }
  66%   { --light-angle: 130deg; --light-color: rgba(143, 216, 238, 0.5); --shade-color: rgba(10, 12, 40, 0.3); }
  84%   { --light-angle: 166deg; --light-color: rgba(169, 139, 255, 0.4); --shade-color: rgba(10, 12, 40, 0.15); }
  100%  { --light-angle: 200deg; --light-color: rgba(169, 139, 255, 0);  --shade-color: rgba(10, 12, 40, 0); }
}
@keyframes house-light-dawn {
  0%    { --light-angle: 180deg; --light-color: rgba(143, 216, 238, 0);   --shade-color: rgba(10, 12, 40, 0); }
  20%   { --light-angle: 220deg; --light-color: rgba(143, 216, 238, 0.45); --shade-color: rgba(10, 12, 40, 0.2); }
  40%   { --light-angle: 256deg; --light-color: rgba(169, 139, 255, 0.35); --shade-color: rgba(10, 12, 40, 0.3); }
  47.9% { --light-angle: 270deg; --light-color: rgba(169, 139, 255, 0);   --shade-color: rgba(20, 22, 70, 0.3); }
  48%   { --light-angle: 94deg;  --light-color: rgba(255, 112, 96, 0);    --shade-color: rgba(20, 22, 70, 0.3); }
  56%   { --light-angle: 110deg; --light-color: rgba(255, 120, 100, 0.7); --shade-color: rgba(40, 25, 95, 0.45); }
  72%   { --light-angle: 140deg; --light-color: rgba(255, 180, 92, 0.8);  --shade-color: rgba(40, 22, 85, 0.25); }
  88%   { --light-angle: 172deg; --light-color: rgba(255, 236, 192, 0.45); --shade-color: rgba(30, 30, 80, 0.08); }
  100%  { --light-angle: 200deg; --light-color: rgba(255, 240, 205, 0);   --shade-color: rgba(30, 30, 80, 0); }
}

/* ---------------------------------------------------------------- the page turns over
   Night falls from the top of the page; day rises from the bottom. The sky keeps moving on top. */
html.theme-cycling .topbar, html.theme-cycling .tabs { view-transition-name: none; }
html.theme-cycling .sky-cycle { view-transition-name: hero-sky; }
/* The house and its two labels are lifted too, in page order, so the sky stays behind them;
   they fade from the day picture to the night one (or back) while the page turns. */
html.theme-cycling .hero-house { view-transition-name: hero-house; }
html.theme-cycling .floating-chip.chip-one { view-transition-name: hero-chip-one; }
html.theme-cycling .floating-chip.chip-two { view-transition-name: hero-chip-two; }
html.theme-cycling::view-transition-group(*),
html.theme-cycling::view-transition-old(*),
html.theme-cycling::view-transition-new(*) { animation-duration: var(--turn-ms); }
html.theme-cycling::view-transition-old(hero-sky) { display: none; }
html.theme-cycling::view-transition-new(hero-sky) { animation: none; }
html.theme-cycling::view-transition-old(root) { animation: none; }
html.theme-cycling::view-transition-new(root) {
  animation: theme-turn var(--turn-ms) cubic-bezier(0.45, 0, 0.3, 1) both;
  -webkit-mask: linear-gradient(to bottom, #000 40%, transparent 60%) 0 100% / 100% 250% no-repeat;
  mask: linear-gradient(to bottom, #000 40%, transparent 60%) 0 100% / 100% 250% no-repeat;
}
html.theme-cycling[data-cycle='dawn']::view-transition-new(root) {
  animation-name: theme-turn-dawn;
  -webkit-mask-image: linear-gradient(to top, #000 40%, transparent 60%);
  mask-image: linear-gradient(to top, #000 40%, transparent 60%);
}
@keyframes theme-turn { from { -webkit-mask-position: 0 100%; mask-position: 0 100%; } to { -webkit-mask-position: 0 0; mask-position: 0 0; } }
@keyframes theme-turn-dawn { from { -webkit-mask-position: 0 0; mask-position: 0 0; } to { -webkit-mask-position: 0 100%; mask-position: 0 100%; } }

/* The button's icon rises in as the cycle starts. */
html.theme-cycling .theme-toggle .icon { animation: toggle-icon-in 0.6s var(--ease) both; }
@keyframes toggle-icon-in { from { opacity: 0; transform: translateY(6px) rotate(-60deg); } }

@media (prefers-reduced-motion: reduce) {
  .sky-cycle, .house-light { display: none; }
}
@media (forced-colors: active) {
  .sky-cycle, .house-light { display: none; }
}
