@font-face {
	font-family: 'Alegreya';
	font-style: normal;
	font-weight: 400 800;
	font-display: swap;
	src: url(fonts/alegreya-cyrillic.woff2) format('woff2');
	unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
	font-family: 'Alegreya';
	font-style: normal;
	font-weight: 400 800;
	font-display: swap;
	src: url(fonts/alegreya-latin.woff2) format('woff2');
	unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Лазурит решётки, золото для прочитанного, холодная бумага */
:root {
	--bg: #e9ecf3;
	--ink: #19203d;
	--muted: #545c7e;
	--line: #cdd3e2;
	--paper: #ffffff;
	--paper-ink: #19203d;
	--paper-line: #e1e5ee;
	--lapis: #26368c;
	--lapis-dark: #1b2870;
	--gold: #a8760f;
	--mark: rgba(194, 139, 28, .3);
	--cell: 33px; /* клетка листа в примере, конструкторе и дешифраторе */
	color-scheme: light;
}
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0f1328;
		--ink: #e4e7f2;
		--muted: #a3aac8;
		--line: #2c3358;
		--paper: #e8eaf1;
		--paper-line: #cfd4e2;
		--lapis: #3448b0;
		--lapis-dark: #2a3b97;
		--gold: #e0ae45;
		--mark: rgba(224, 174, 69, .32);
		color-scheme: dark;
	}
}

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

body {
	margin: 0;
	background: var(--bg);
	color: var(--ink);
	font: 400 1.125rem/1.6 'Alegreya', Georgia, serif;
	-webkit-text-size-adjust: 100%;
}

.wrap {
	width: min(100% - 32px, 1120px);
	margin-inline: auto;
}

h1, h2, h3 { margin: 0; line-height: 1.15; }
h2 { font-size: clamp(1.75rem, 3.5vw, 2.25rem); font-weight: 700; }
h3 { font-size: 1.3rem; font-weight: 700; margin-top: 2rem; }
p { margin: .75rem 0 0; }

:focus-visible {
	outline: 3px solid var(--gold);
	outline-offset: 2px;
}

/* Первый экран */
.hero {
	display: grid;
	gap: 48px;
	align-items: center;
	padding-block: clamp(40px, 8vw, 104px) clamp(32px, 6vw, 72px);
}
@media (min-width: 860px) {
	.hero { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
}
h1 {
	font-size: clamp(3.25rem, 9vw, 6.75rem);
	font-weight: 800;
	line-height: .92;
	letter-spacing: -.015em;
}
.author {
	margin-top: 1.25rem;
	font-size: 1.35rem;
	color: var(--muted);
}
.lead {
	max-width: 42ch;
	margin-top: 1.5rem;
	font-size: 1.3rem;
}

.demo {
	justify-self: center;
	width: min(100%, 420px);
	margin: 0;
}
/* Поля решётки выступают на 1/15 листа: при таком отступе край карточки совпадает с краем блока */
.demo-sheet { padding: calc(100% / 17); }
/* «Прочитано» всегда под кнопкой, чтобы строка не прыгала при повороте */
.demo figcaption {
	display: grid;
	gap: 12px;
	margin-top: 16px;
}
.demo .btn { justify-self: start; }
.demo-read { margin: 0; color: var(--muted); }
.demo-read span { color: var(--ink); white-space: pre-wrap; }
mark {
	background: var(--mark);
	color: inherit;
	border-radius: 2px;
}

/* Лист с клетками и решётка поверх */
.sheet {
	--size: 6;
	position: relative;
	display: grid;
	grid-template-columns: repeat(var(--size), 1fr);
	aspect-ratio: 1;
	container-type: inline-size;
	background-color: var(--paper);
	background-image:
		linear-gradient(var(--paper-line) 1px, transparent 1px),
		linear-gradient(90deg, var(--paper-line) 1px, transparent 1px);
	background-size: calc(100% / var(--size)) calc(100% / var(--size));
	border: 1px solid var(--paper-line);
	color: var(--paper-ink);
}
.sheet > span {
	display: grid;
	place-items: center;
	font-size: calc(58cqi / var(--size));
	font-weight: 600;
	line-height: 1;
	white-space: pre;
}
.grille {
	position: absolute;
	top: calc(-40% / var(--size));
	left: calc(-40% / var(--size));
	width: calc(100% + 80% / var(--size));
	height: calc(100% + 80% / var(--size));
	fill: var(--lapis);
	filter: drop-shadow(0 2px 3px rgba(15, 20, 50, .4));
	transform: rotate(calc(var(--turn, 0) * 90deg));
	transition: transform .8s cubic-bezier(.5, 0, .2, 1);
}

/* Разделы */
.block { padding-block: clamp(40px, 6vw, 80px); }
.block-head { max-width: 66ch; }
.block-head .btn { margin-top: 20px; }
/* На узком экране кнопки стоят в строке одни: по центру */
@media (max-width: 600px) {
	.demo .btn { justify-self: center; }
	.block-head .btn { display: block; margin-inline: auto; }
}

.theory { display: grid; gap: 48px 64px; }
@media (min-width: 900px) {
	.theory { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
}
.prose p { max-width: 66ch; }
.prose h2 ~ h2 { margin-top: 2.5rem; }
.letter { margin: 0; }
.letter img {
	display: block;
	width: 100%;
	height: auto;
	margin-top: 20px;
	border-radius: 4px;
}
.letter figcaption { font-size: 1rem; color: var(--muted); }
.letter strong { color: var(--ink); }

.turns {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr));
	gap: 24px;
	margin-top: 24px;
}
.turns > figure { margin: 0; padding: 8%; }
.turns figcaption {
	margin-top: 14px;
	text-align: center;
	font-size: 1rem;
	color: var(--muted);
}
#encrypt-grid { grid-template-columns: minmax(0, 240px); }
/* Колонка под лист 8×8 и поля решётки (0,4 клетки с каждой стороны) */
#constructor, #decrypt-grid {
	grid-template-columns: repeat(auto-fill, min(100%, calc(var(--cell) * 8 + 34px)));
}
#constructor figure, #decrypt-grid figure { padding: 16px; }
#constructor .sheet, #decrypt-grid .sheet {
	width: calc(var(--cell) * var(--size) + 2px);
	max-width: 100%;
}
/* Когда весь ряд помещается на экране, он выходит за колонку текста поровну в обе стороны:
   4 × 298 + 3 × 24 = 1264 px и 5 × 298 + 4 × 24 = 1586 px, плюс поля по 16 px */
main { container-type: inline-size; }
@container (min-width: 1296px) {
	#constructor { width: 1264px; margin-inline: calc((100% - 1264px) / 2); }
}
@container (min-width: 1618px) {
	#decrypt-grid { width: 1586px; margin-inline: calc((100% - 1586px) / 2); }
}

/* Пример: шаги по порядку; номер, текст и карта каждого шага стоят в общих строках сетки,
   поэтому карты в одном ряду начинаются на одной высоте при любой длине текста */
.steps {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
	gap: 0 40px;
	margin: 20px 0 0;
	padding: 0;
	list-style: none;
	counter-reset: step;
}
.steps li {
	display: grid;
	grid-row: span 3;
	grid-template-rows: subgrid;
	padding-bottom: 48px;
	counter-increment: step;
}
.steps li > * { align-self: start; }
.steps li::before {
	content: counter(step);
	display: block;
	font-size: 2.75rem;
	font-weight: 800;
	line-height: 1;
	color: var(--gold);
}
.steps p { margin: 8px 0 20px; }
/* В примере и дешифраторе трафарет полупрозрачный: под ним видны закрытые буквы */
#steps .grille, #decrypt-grid .grille { fill-opacity: .78; }
.steps .sheet { width: min(100% - 32px, calc(var(--cell) * var(--size) + 2px)); margin: 16px; }
.phrase {
	display: block;
	font-size: 1.6rem;
	font-weight: 600;
	line-height: 1.3;
	quotes: '«' '»';
}

/* Шифратор и дешифратор */
.field {
	display: flex;
	flex-wrap: wrap;
	justify-content: center; /* кнопка, перенесённая на свою строку */
	gap: 12px;
	max-width: 720px;
	margin-top: 20px;
}
.field input, .cipher {
	flex: 1 1 260px;
	min-width: 0;
	padding: 12px 14px;
	font: inherit;
	color: var(--paper-ink);
	background: var(--paper);
	border: 1.5px solid var(--line);
	border-radius: 6px;
}
.field input::placeholder { color: #6b7290; }
.btn {
	padding: 12px 22px;
	font: inherit;
	font-weight: 700;
	color: #fff;
	background: var(--lapis);
	border: 0;
	border-radius: 6px;
	cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--lapis-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.empty { color: var(--muted); }
.cipher {
	display: block;
	width: 100%;
	max-width: 720px;
	margin-top: 12px;
	letter-spacing: .06em;
}
.plain {
	font-size: 1.6rem;
	font-weight: 600;
	white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
	.grille { transition: none; }
}
