/* Inter 4.1 variable (rsms.me/inter), self-hosted; SIL OFL 1.1, see fonts/Inter-LICENSE.txt */
@font-face {
	font-family: "Inter";
	font-style: normal;
	font-weight: 100 900;
	font-display: swap;
	src: url(fonts/InterVariable.woff2) format("woff2");
}

:root {
	/* Colors */
	--c-ink: #000;
	--c-bg: #fff;
	--c-link: #0c4f72;
	--c-link-hover: #990000;
	--c-link-visited: #5f2892;
	--c-muted: #555;
	--c-muted-light: #777;
	--c-heading: #333;
	--c-border: #999;
	--c-archive-bg: #f3f6de;
	--c-new-issue-bg: #e7e9d2;

	/* Type */
	--font-sans: "Inter", system-ui, sans-serif;
	--font-serif: Georgia, serif;

	/* Layout */
	--page-top: 30px;
	--gutter: 5%;

	/* Arrows */
	--arrow-head-w: 4px;
	--arrow-head-h: 7px;

	/* Wavy lines: SVG tiles repeated with `round`, so they always hold a whole number of waves
	   and start/end at the midline; round caps are radial-gradient dots at both ends. */
	--wave-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='4'%3E%3Cpath d='M0 2Q3-.5 6 2T12 2' fill='none' stroke='black' stroke-linecap='round'/%3E%3C/svg%3E");
	--wave-logo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='17.625' height='6'%3E%3Cpath d='M0 3Q4.406-1 8.813 3T17.625 3' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

*, *::before, *::after { box-sizing: border-box; }

html { overflow-x: clip; }

body {
	display: grid;
	grid-template-rows: auto 1fr auto;
	min-height: calc(100dvh - var(--page-top));
	margin: var(--page-top) 0 0;
	font-family: var(--font-sans);
	font-size: 0.8rem;
	background-color: var(--c-bg);

	/* grayscale antialiasing (macOS WebKit/Blink and Firefox); no-op elsewhere */
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
}

img { border: 0; }
h1, h2, h3, p, figure { margin: 0; }

a {
	color: var(--c-link);
	text-decoration-thickness: max(.5px, .04em); /* hairline on retina, scales a little with big links */
	text-underline-offset: .2em;
	text-decoration-skip-ink: auto;

	&:hover { color: var(--c-link-hover); }
	&:visited { color: var(--c-link-visited); }
	&:visited:hover { color: var(--c-link-hover); }
}

/* "Длина / Барабан" stamp in the top-left corner */
body::before {
	content: "";
	position: absolute;
	top: 3px;
	left: 7px;
	z-index: 1;
	width: 120px;
	height: 48px;
	background: url(img/baraban.webp) no-repeat top left / 120px 48px;
}

/* Arrows: a 1px line pattern (gradient tile: `--on` px of ink every `--period` px,
   anchored to the right) with an arrowhead at the right end */
.arrow {
	--on: 1px;
	--period: 1px;
	--dir: to left; /* which tile edge the ink sits on */

	position: relative;
	height: var(--arrow-head-h);
	margin: 50px 10px 0;
	background: linear-gradient(var(--dir), var(--c-ink) var(--on), #0000 0) right center / var(--period) 1px repeat-x;

	&::after {
		content: "";
		position: absolute;
		top: 0;
		right: 0;
		width: var(--arrow-head-w);
		height: var(--arrow-head-h);
		background: var(--c-ink);
		clip-path: polygon(0 0, 100% 50%, 0 100%);
	}

	&.arrow--archive { margin: 80px 20px 0 10px; }
	&.arrow--dotted { --period: 3px; }
	&.arrow--dotted-wide { --period: 4px; }
	&.arrow--dashed { --on: 2px; --period: 5px; --dir: to right; }
	&.arrow--wavy {
		padding-right: var(--arrow-head-w); /* end where the arrowhead starts */
		background:
			radial-gradient(circle, var(--c-ink) .35px, #0000 .5px) left -.5px center / 1px 1px no-repeat padding-box,
			var(--wave-arrow) left center / 12px 4px round no-repeat content-box;
	}
}

/* Header */
.masthead {
	display: grid;
	grid-template-columns: 20fr 15fr 20fr 15fr 20fr 10fr;
	align-items: start;
	padding: 0 var(--gutter);

	/* locomobile engraving: last grid item, after "Издается…" */
	&::after {
		content: "";
		width: 120px;
		height: 95px;
		background: url(img/aggr.webp) 0 0 / 120px 95px;
	}
}

/* Logo with a wavy underline that rolls right-to-left on hover */
.logo {
	--cap: radial-gradient(circle, var(--c-ink) .55px, #0000 .75px);
	--wave-w: 281px; /* content box: 286px minus 4px + 1px padding */
	--wave-period: calc(var(--wave-w) / 16); /* 16 whole waves */

	position: relative;
	z-index: 30;
	width: 286px;
	height: 116px;
	padding: 0 1px 0 4px;
	background:
		var(--cap) left 3.25px bottom 2.25px / 1.5px 1.5px no-repeat padding-box,
		var(--cap) right .25px bottom 2.25px / 1.5px 1.5px no-repeat padding-box,
		var(--wave-logo) left 0 bottom / var(--wave-period) 6px repeat-x content-box;
	/* rolls while hovered, pauses in place on leave and resumes from there */
	animation: logo-wave-roll .6s linear infinite paused;

	& img {
		position: absolute;
		top: 0;
		left: 5px;
		z-index: 40;
	}

	&:hover {
		animation-play-state: running;
	}
}

@keyframes logo-wave-roll {
	/* caps ride the wave: centre y = 3 ∓ 8t ± 8t² per half-period (quadratic segments of --wave-logo) */
	0% { background-position: left 3.25px bottom 2.25px, right .25px bottom 2.25px, left 0 bottom; }
	6.25% { background-position: left 3.25px bottom 3.125px, right .25px bottom 3.125px, left calc(-0.0625 * var(--wave-period)) bottom; }
	12.5% { background-position: left 3.25px bottom 3.75px, right .25px bottom 3.75px, left calc(-0.125 * var(--wave-period)) bottom; }
	18.75% { background-position: left 3.25px bottom 4.125px, right .25px bottom 4.125px, left calc(-0.1875 * var(--wave-period)) bottom; }
	25% { background-position: left 3.25px bottom 4.25px, right .25px bottom 4.25px, left calc(-0.25 * var(--wave-period)) bottom; }
	31.25% { background-position: left 3.25px bottom 4.125px, right .25px bottom 4.125px, left calc(-0.3125 * var(--wave-period)) bottom; }
	37.5% { background-position: left 3.25px bottom 3.75px, right .25px bottom 3.75px, left calc(-0.375 * var(--wave-period)) bottom; }
	43.75% { background-position: left 3.25px bottom 3.125px, right .25px bottom 3.125px, left calc(-0.4375 * var(--wave-period)) bottom; }
	50% { background-position: left 3.25px bottom 2.25px, right .25px bottom 2.25px, left calc(-0.5 * var(--wave-period)) bottom; }
	56.25% { background-position: left 3.25px bottom 1.375px, right .25px bottom 1.375px, left calc(-0.5625 * var(--wave-period)) bottom; }
	62.5% { background-position: left 3.25px bottom 0.75px, right .25px bottom 0.75px, left calc(-0.625 * var(--wave-period)) bottom; }
	68.75% { background-position: left 3.25px bottom 0.375px, right .25px bottom 0.375px, left calc(-0.6875 * var(--wave-period)) bottom; }
	75% { background-position: left 3.25px bottom 0.25px, right .25px bottom 0.25px, left calc(-0.75 * var(--wave-period)) bottom; }
	81.25% { background-position: left 3.25px bottom 0.375px, right .25px bottom 0.375px, left calc(-0.8125 * var(--wave-period)) bottom; }
	87.5% { background-position: left 3.25px bottom 0.75px, right .25px bottom 0.75px, left calc(-0.875 * var(--wave-period)) bottom; }
	93.75% { background-position: left 3.25px bottom 1.375px, right .25px bottom 1.375px, left calc(-0.9375 * var(--wave-period)) bottom; }
	100% { background-position: left 3.25px bottom 2.25px, right .25px bottom 2.25px, left calc(-1 * var(--wave-period)) bottom; }
}

.names { margin-top: 29px; }
.since { margin-top: 44px; }

/* Archive */
.archives {
	display: grid;
	grid-template-columns: auto 15fr 20fr 15fr 20fr 15fr auto;
	align-items: start;
	--pad-top: 20px;
	--pad-bottom: 30px;

	margin: 60px 0;
	padding: var(--pad-top) var(--gutter) var(--pad-bottom);
	background-color: var(--c-archive-bg);
}

.archives__title {
	text-align: center;

	/* typography emblem above the title */
	&::before {
		content: "";
		display: block;
		width: 120px;
		height: 117px;
		margin: 20px 0 1em;
		background: url(img/typo.webp) 0 0 / 120px 117px;
	}

	& h2 {
		margin-bottom: 0.5em;
		font-size: 1.2em;
		font-weight: normal;
		color: var(--c-heading);
	}

	& p {
		font-size: 0.8em;
		color: var(--c-muted-light);
	}
}

.issues {
	--item-gap: 1.5em;
	--item-line-height: 2;
	--link-size: 1.5em;
	--size-size: .7em;
	--size-color: var(--c-muted);

	&.issues--v2 {
		--item-gap: 2em;
		--item-line-height: 1.5;
		--link-size: 2.5em;
		--size-size: smaller;
		--size-color: currentColor;
	}

	& h3 {
		margin-bottom: 1em;
		font-size: inherit;
		text-align: center;

		& .page-icon { margin-right: 5px; vertical-align: baseline; }
	}

	& ul {
		display: flex;
		flex-wrap: wrap;
		margin: 0;
		padding: 0;
		list-style: none;
	}

	& li {
		padding-right: var(--item-gap);
		line-height: var(--item-line-height);
	}

	& a {
		font-family: var(--font-serif);
		font-size: var(--link-size);

		&:visited { color: var(--c-muted); }
		&:hover, &:visited:hover { color: var(--c-link-hover); }
	}

	/* file size in KB, typeset like a <sup>; the gap is one Inter space (.282em) of the list text */
	& li[data-size]::after {
		content: attr(data-size) "\a0КБ";
		margin-inline-start: calc(.282 * .8rem);
		font-size: var(--size-size, smaller);
		vertical-align: super;
		color: var(--size-color, currentColor);
		letter-spacing: .04em;
	}
}

/* Fills the archive row with equal insets from the section's top and bottom edges */
.new-issue {
	--inset: 15px;

	align-self: stretch;
	display: flex;
	flex-direction: column;
	margin-block: calc(var(--inset) - var(--pad-top)) calc(var(--inset) - var(--pad-bottom));
	padding: 20px;
	border-radius: 8px;
	background-color: var(--c-new-issue-bg);

	& h3 {
		margin-bottom: 2em;
		font-size: inherit;
		text-align: center;
	}
}

.paper {
	--border-w: 2px;
	--fold: 18px;

	/* A3 landscape sheet: fixed height, width from the ISO √2 ratio; centred in the stretched box */
	position: relative;
	height: 165px;
	aspect-ratio: 1.4142;
	margin-block: auto;
	display: grid;
	place-content: center;
	padding: 50px 1em;
	text-wrap: balance;
	border: var(--border-w) dashed var(--c-border);
	background-color: var(--c-bg);
	color: var(--c-muted);
	text-align: center;

	/* folded corner: ::before hides the paper corner, ::after is the flap on top of it */
	&::before,
	&::after {
		content: "";
		position: absolute;
		top: calc(-1 * var(--border-w));
		right: calc(-1 * var(--border-w));
		width: var(--fold);
		height: var(--fold);
	}

	&::before {
		background-color: var(--c-new-issue-bg);
	}

	/* gray outer triangle, white inner triangle inset by --border-w on every side
	   (padding-box diagonal lies w/√2 outside the clipped hypotenuse, so pull the stop in by w·(1 + 1/√2)) */
	&::after {
		border: solid var(--c-border);
		border-width: 0 0 var(--border-w) var(--border-w);
		background: linear-gradient(to top right, var(--c-bg) calc(50% - var(--border-w) * 1.707), var(--c-border) 0) padding-box;
		background-color: var(--c-border);
		clip-path: polygon(0 0, 100% 100%, 0 100%);
	}
}

/* Railway footer */
.railway {
	--rail-top: 10px;

	position: relative;
	height: 125px;
	padding-top: 50px;
	overflow-x: clip;
	/* @2x sprite: gray strip (30px tile) over rails (28px tile), 420px = LCM so both repeat seamlessly */
	background: url(img/railway.webp) repeat-x left bottom / 420px 22px;
	image-rendering: pixelated;

	/* @2x pixel-art assets: keep hard pixel edges at any scale */
	& img, & .station__picture { image-rendering: pixelated; }
}

.railway__arrow {
	display: block;
	width: 40px;
	height: 5px;
	margin-left: 25%;
	background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='5' shape-rendering='crispEdges'%3E%3Cpath fill='%23b4b4b4' d='M0 0h11v1H0zM1 1h11v1H1zM1 3h11v1H1zM0 4h11v1H0zM2 2h38v1H2zM37 0h1v5h-1zM38 1h1v3h-1z'/%3E%3C/svg%3E"); /* fletched arrow */
}

.train {
	position: absolute;
	bottom: var(--rail-top);
	left: 0;
	z-index: 3;
	cursor: grab;
	touch-action: pan-y;
	user-select: none;

	&:active { cursor: grabbing; }
}

.station {
	position: absolute;
	right: var(--gutter);
	bottom: 22px;
	z-index: 2;
	display: flex;
	align-items: end;
	justify-content: space-between;
	gap: 1em;
	width: min(693px, 90%);
}

.station__picture {
	flex: none;
	width: 343px;
	height: 43px;
	background: url(img/station.webp) no-repeat 0 0 / 343px 43px;
}

.station__zoom {
	padding: 0 0 4px;
	border: 0;
	background: none;
	font: inherit;
	color: var(--c-link);
	cursor: pointer;

	&:hover { color: var(--c-link-hover); }

	& img { margin-right: 5px; vertical-align: bottom; }
	& span { border-bottom: 1px dashed currentColor; }
}

/* Zoomed station popover */
.station-zoomed {
	inset: auto 20% 10% auto;
	width: fit-content;
	height: fit-content;
	margin: 0;
	padding: 15px 15px 16px; /* bottom = gray strip height */
	overflow: hidden;
	border: 1px solid var(--c-border);
	background-color: var(--c-bg);

	& > img { position: relative; display: block; }
	& img { image-rendering: pixelated; }
}

/* Labels over the zoomed picture: left edges and the shared baseline (y=37 of the 590×132
   image) match the leader lines drawn in it */
.station-zoomed__labels {
	--baseline: 37px;
	--line: 10px;

	position: absolute;
	top: 15px;
	left: 15px;
	width: 590px;
	height: 132px;
	margin: 0;
	padding: 0;
	list-style: none;
	font: 10px/var(--line) var(--font-sans);
	color: var(--c-ink);

	& li {
		position: absolute;
		left: var(--x);
		/* line box bottom sits ~1px below the baseline */
		bottom: calc(100% - var(--baseline) - 1px);
		white-space: nowrap;
	}
}

.station-zoomed__gray {
	position: absolute;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 16px;
	background: linear-gradient(#8c8c8c 0 2px, #a5a5a5 0 4px, #a0a0a0 0 6px, #a5a5a5 0 8px, #aeaeae 0 10px, #c1c1c1 0 12px, #d8d8d8 0 14px, #eee 0);
}

.station-zoomed__close {
	position: absolute;
	top: 5px;
	right: 5px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--c-border);
	line-height: 0;
	cursor: pointer;

	&:hover { color: var(--c-link-hover); }
}
