/*
 * Trying2 — CRT screen effect (optional layer on top of main.css).
 * Turned on with body classes: t2-crt + t2-crt--light | t2-crt--medium | t2-crt--strong.
 * Everything sits in fixed, click-through overlays, so layout and clicks are untouched.
 */

body.t2-crt {
	--crt-lines: 0.16;   /* scanline darkness */
	--crt-vignette: 0.4; /* dark corners */
	--crt-glow: 0.35;    /* phosphor glow on text */
	--crt-grain: 0.035;  /* noise */
	--crt-frame: 18px;   /* rounded screen corners */
}
body.t2-crt--medium {
	--crt-lines: 0.24;
	--crt-vignette: 0.55;
	--crt-glow: 0.55;
	--crt-grain: 0.055;
	--crt-frame: 26px;
}
body.t2-crt--strong {
	--crt-lines: 0.34;
	--crt-vignette: 0.7;
	--crt-glow: 0.75;
	--crt-grain: 0.08;
	--crt-frame: 34px;
}

/* 1. Scanlines */
body.t2-crt #page::after {
	content: "";
	position: fixed;
	inset: 0;
	z-index: 9998;
	pointer-events: none;
	background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, var(--crt-lines)) 0 1px, transparent 1px 3px);
}

/* 4. Grain: light animated noise (body::before is the grid, body::after is free) */
body.t2-crt::after {
	content: "";
	position: fixed;
	inset: -50px;
	z-index: 9997;
	pointer-events: none;
	opacity: var(--crt-grain);
	background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
	background-size: 160px 160px;
	animation: t2-crt-grain 0.6s steps(3) infinite;
}
@keyframes t2-crt-grain {
	0%   { transform: translate(0, 0); }
	33%  { transform: translate(-40px, 30px); }
	66%  { transform: translate(30px, -45px); }
	100% { transform: translate(0, 0); }
}

/* 2. Vignette + rounded glass corners */
body.t2-crt #page::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: 9999;
	pointer-events: none;
	border-radius: var(--crt-frame);
	box-shadow:
		0 0 0 60px #050506,                                  /* masks the corners outside the curve */
		inset 0 0 120px rgba(0, 0, 0, var(--crt-vignette)),  /* dark edges */
		inset 0 0 18px rgba(124, 151, 255, 0.08);            /* faint blue rim */
	background: radial-gradient(ellipse at 50% 45%, rgba(124, 151, 255, 0.04), transparent 60%);
}

/* 3. Phosphor glow: pixel text, titles and logo */
body.t2-crt .t2-px,
body.t2-crt .t2-h,
body.t2-crt .t2-about__title {
	text-shadow:
		0 0 1px currentColor,
		0 0 8px rgba(124, 151, 255, var(--crt-glow));
}
/* blue-only colour split on the big titles (no red) */
body.t2-crt .t2-h--xl,
body.t2-crt .t2-about__title {
	text-shadow:
		-1.5px 0 rgba(26, 60, 255, calc(var(--crt-glow) + 0.15)),
		1.5px 0 rgba(124, 200, 255, calc(var(--crt-glow) * 0.6)),
		0 0 10px rgba(124, 151, 255, var(--crt-glow));
}
body.t2-crt .t2-logo {
	filter:
		drop-shadow(-1.5px 0 rgba(26, 60, 255, 0.6))
		drop-shadow(1.5px 0 rgba(124, 200, 255, 0.35))
		drop-shadow(0 0 10px rgba(124, 151, 255, var(--crt-glow)));
}

/* Product photos stay true to colour: a thin clear frame keeps them a touch brighter than the overlay */
body.t2-crt .t2-card__media img,
body.t2-crt ul.products li.product img {
	filter: brightness(1.04) contrast(1.02);
}

/* 6. Power-on: the screen "switches on" each time the homepage loads (inline script adds html.t2-crt-boot) */
.t2-crt-power { display: none; }
html.t2-crt-boot .t2-crt-power {
	display: block;
	position: fixed;
	inset: 0;
	z-index: 10000;
	pointer-events: none;
	background: #050506;
	animation: t2-crt-power-bg 0.9s ease-out forwards;
}
html.t2-crt-boot .t2-crt-power::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	top: 50%;
	height: 2px;
	margin-top: -1px;
	background: #E6ECFF;
	box-shadow: 0 0 24px 6px rgba(124, 151, 255, 0.8);
	transform: scaleX(0);
	animation: t2-crt-power-line 0.9s ease-out forwards;
}
@keyframes t2-crt-power-bg {
	0%, 45% { opacity: 1; }
	100%    { opacity: 0; visibility: hidden; }
}
@keyframes t2-crt-power-line {
	0%   { transform: scale(0, 1); opacity: 1; }
	30%  { transform: scale(1, 1); opacity: 1; }
	45%  { transform: scale(1, 1); opacity: 1; }
	75%  { transform: scale(1, 300); opacity: 0.35; }
	100% { transform: scale(1, 400); opacity: 0; }
}

@media (max-width: 782px) {
	body.t2-crt { --crt-frame: 12px; }
	body.t2-crt #page::before { box-shadow: 0 0 0 60px #050506, inset 0 0 70px rgba(0, 0, 0, var(--crt-vignette)); }
}

@media (prefers-reduced-motion: reduce) {
	body.t2-crt::after { animation: none; }
	html.t2-crt-boot .t2-crt-power { display: none; }
}

/* Light theme: keep the black (inverted) logo under the glow */
html[data-t2-theme="light"] body.t2-crt .t2-header__logo .t2-logo,
html[data-t2-theme="light"] body.t2-crt .t2-hero__logo .t2-logo {
	filter:
		invert(1)
		drop-shadow(-1.5px 0 rgba(26, 60, 255, 0.5))
		drop-shadow(0 0 8px rgba(124, 151, 255, calc(var(--crt-glow) * 0.6)));
}
