<?php
declare(strict_types=1);
header('Content-Type: text/css; charset=UTF-8');
$BASE=[__DIR__.'/src/base.css',__DIR__.'/src/layout.css',__DIR__.'/src/components.css'];
$mods = isset($_GET['mods']) ? explode(',', preg_replace('/[^a-z,]/','', $_GET['mods'])) : [];
$MODULES_DIR=__DIR__.'/modules/'; $moduleFiles=[];
foreach($mods as $m){ $f=$MODULES_DIR.$m.'.css'; if(is_file($f)) $moduleFiles[]=$f; }
$files=array_merge($BASE,$moduleFiles);
$css=''; foreach($files as $f){ $css.="/*== ".basename($f)." ==*/\n".file_get_contents($f)."\n"; }
$css=preg_replace('!/\*.*?\*/!s','',$css);
$css=preg_replace('/\n\s*\n/','',$css);
$css=preg_replace('/\s*([{};,:\(\)])\s*/','$1',$css);
$css=preg_replace('/;}/','}',$css); $css=trim($css);
$etag='"'.sha1($css).'"'; header('ETag: '.$etag); header('Cache-Control: public,max-age=86400');
if(($_SERVER['HTTP_IF_NONE_MATCH']??'')===$etag){ http_response_code(304); exit; }
echo $css;
