+ my $zopfli = which 'zopfli';
+ system $zopfli => $file if $zopfli;
+ gzip $file => "$file.gz", -Level => 9, Minimal => 1 unless $zopfli;
+}
+
+sub write_gzfile {
+ my ($file, @content) = @_;
+ write_file $file, @content;
+ gzip_file $file
+}
+
+sub read_css_into_blocks {
+ my ($file) = @_;
+ my (@blocks, $block);
+ for (read_file $file) {
+ $block .= $_;
+ if (/^}/) {
+ push @blocks, $block;
+ $block = '';
+ }
+ }
+ \@blocks
+}
+
+my $default_theme = 'cyborg';
+
+sub theme_prefix {
+ my ($theme, $decl, $default) = @_;
+ return $decl if $theme eq $default_theme || !$decl;
+ return '' if $decl eq $default;
+
+ $default =~ s/[^{]*{\n//;
+ $default =~ s/\n}[^}]*//;
+ $decl =~ s/^$_$//m for split "\n", $default;
+ $decl =~ s/\n+/\n/g;
+
+ my $prefix = "html.$theme";
+ my ($first_line) = $decl =~ /([^{]*){/;
+ $first_line =~ s/(,\s+)/$1 $prefix /g;
+ $first_line = "$prefix $first_line";
+ $decl =~ s/([^{]*){/$first_line\{/;
+ $decl