@layer pages {
	.game-journal {
		padding-block-end: 5rem;
	}

	.journal-hero {
		position: relative;
		isolation: isolate;
		min-block-size: 25rem;
		padding-block: 2rem 3.5rem;
		overflow: clip;
		background:
			url("../../assets/images/gallery-symbols.svg?v=2") center / 15rem 11.25rem,
			var(--color-brand);
		color: white;

		&::before {
			position: absolute;
			inset: 0;
			z-index: 0;
			background:
				linear-gradient(
					color-mix(in oklch, white 5%, transparent) 1px,
					transparent 1px
				),
				linear-gradient(
					90deg,
					color-mix(in oklch, white 5%, transparent) 1px,
					transparent 1px
				);
			background-attachment: fixed;
			background-size: var(--grid-size) var(--grid-size);
			content: "";
			mask-image: linear-gradient(to right, black, transparent 38%);
			pointer-events: none;
		}

		&::after {
			position: absolute;
			inset: 0;
			z-index: -1;
			background:
				linear-gradient(
					90deg,
					var(--color-brand) 0%,
					color-mix(in srgb, var(--color-brand) 82%, transparent) 45%,
					color-mix(in srgb, var(--color-brand) 50%, transparent)
				),
				linear-gradient(to top, var(--color-brand), transparent 48%);
			content: "";
			pointer-events: none;
		}
	}

	.game-backdrop {
		position: absolute;
		inset: 0;
		z-index: -2;
		display: block;

		img {
			inline-size: 100%;
			block-size: 100%;
			filter: saturate(0.72) contrast(0.88);
			object-fit: cover;
			object-position: center 36%;
		}
	}

	.journal-identity {
		position: relative;
		z-index: 1;
		inline-size: min(100% - 5rem, 72rem);
		margin-inline: auto;
	}

	.journal-identity {
		display: grid;
		grid-template-columns: 11rem minmax(0, 1fr);
		align-items: end;
		gap: 1.75rem;
		margin-block-start: 2.25rem;

		hgroup {
			padding-block-end: 0.5rem;
		}

		.eyebrow .eyebrow-year {
			color: rgb(255 255 255 / 72%);
			font-weight: 650;
		}

		/* A small gold trophy chip when the game reached a game-of-the-year list. */
		.goty-award {
			display: inline-block;
			width: fit-content;
			padding-block: 0.22rem;
			padding-inline: 0.55rem;
			border-radius: 999px;
			margin-block-start: 0.45rem;
			background: var(--color-highlight);
			box-shadow: 0 0.25rem 0.9rem rgb(0 0 0 / 24%);
			color: var(--color-brand-deep);
			font-family: var(--font-sans);
			/* a touch smaller than interface labels, easing down on phones */
			font-size: clamp(0.58rem, 0.5rem + 0.3vw, 0.68rem);
			font-weight: 800;
			letter-spacing: 0.04em;
			text-decoration: none;
			text-transform: uppercase;

			&:is(:hover, :focus-visible) {
				box-shadow: 0 0.35rem 1.1rem rgb(0 0 0 / 32%);
			}

			&:focus-visible {
				outline: 3px solid rgb(255 255 255 / 45%);
				outline-offset: 0.2rem;
			}
		}

		.eyebrow {
			/* above the display h1; the gold badge stays below it */
			z-index: 2;
		}

		h1 {
			/* above the goty-award gold badge that follows it in the DOM */
			position: relative;
			z-index: 1;
			max-inline-size: 13ch;
			margin: 0;
			font-family: var(--font-display);
			font-size: clamp(3.5rem, 7vw, 6.5rem);
			font-weight: 300;
			letter-spacing: -0.065em;
			line-height: 0.82;
			text-wrap: balance;

			span {
				color: var(--color-accent);
			}

			/* Long titles can use the available space beside the cover. */
			&.long {
				max-inline-size: none;
				overflow-wrap: anywhere;
				font-size: clamp(2.7rem, 5.2vw, 4.6rem);
				letter-spacing: -0.045em;
			}

			&.very-long {
				font-size: clamp(2.2rem, 4vw, 3.6rem);
				line-height: 1.05;
			}
		}
	}


	.journal-flash {
		inline-size: min(100% - 5rem, 72rem);
		padding: 0.9rem 1rem;
		border-inline-start: 0.25rem solid var(--color-accent);
		border-radius: 0.25rem;
		margin: 1.5rem auto 0;
		background: var(--color-highlight);
		color: var(--color-brand-deep);
		font-family: var(--font-sans);
		font-size: 0.72rem;
		font-weight: 750;
	}

	.journal-form {
		position: relative;
		z-index: 2;
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(18rem, 21rem);
		gap: 1.25rem;
		inline-size: min(100% - 5rem, 72rem);
		margin: -1.5rem auto 0;
	}

	.journal-flash + .journal-form {
		margin-block-start: 1.25rem;
	}

	.journal-errors {
		grid-column: 1 / -1;
		margin: 0;
	}

	.notes-sheet,
	.tracking-sheet {
		position: relative;
		background: var(--color-surface);
		box-shadow: var(--shadow-panel);
	}

	.notes-sheet {
		padding: 2rem 2.25rem 2.6rem;
		border-radius: 0.25rem 0.25rem 0 0;
		/* the tape and torn edge come from the shared .paper-edge recipe */

		header h2 span {
			color: var(--color-accent);
		}

		header {
			margin-block-end: 1.4rem;

			h2 {
				color: var(--color-text);
				font-family: var(--font-display);
				font-size: 2.6rem;
				font-weight: 300;
				letter-spacing: -0.04em;
				line-height: 1;
			}

			> p:last-child {
				margin-block-start: 0.45rem;
				color: var(--color-text-muted);
				font-size: 0.75rem;
			}
		}

		/* Write and preview share the notebook margins and handwriting type. */
		:is(textarea, .rendered-notes) {
			inline-size: 100%;
			padding: 0.25rem 0.5rem 1rem 2rem;
			color: var(--color-text);
			font-family: var(--font-serif);
			font-size: 0.95rem;
			/* Integer pixels on purpose: WebKit snaps the used line height to a
			   whole pixel, so a fractional rhythm (1.8rem) lets the text drift
			   away from the ruling line by line on Safari. */
			line-height: 28px;
		}

		/* The ruling lives on the textarea itself: with background-attachment:
		   local the browser paints it in the same pass as the scrolled text,
		   so the rules stay glued to the lines in every browser — no scroll
		   bookkeeping. The vertical offset keeps the rules under the first
		   text line, matching the top padding. */
		textarea {
			min-block-size: 23rem;
			border: 0;
			outline: 0;
			/* Handwritten weight only for the writing surface; the rendered
		preview keeps its own weights from the Markdown. */
			font-weight: 500;
			background:
				linear-gradient(
					90deg,
					transparent 1rem,
					var(--paper-margin) 1rem 1.05rem,
					transparent 1.05rem
				),
				repeating-linear-gradient(
					to bottom,
					transparent 0 calc(28px - 1px),
					var(--color-rule) calc(28px - 1px) 28px
				);
			background-attachment: local;
			background-position: 0 0.25rem;

			/* Firefox drops a single tile of a repeating gradient on retina
			   screens while the fallback shifts the ruling. A tiled bitmap has
			   no gradient tessellation, so Firefox paints it reliably at any
			   pixel density; the pixel colour mirrors --color-rule over the
			   paper surface. Chrome and Safari keep the crisp gradient below. */
			@supports (-moz-appearance: none) {
				& {
					background-image:
						linear-gradient(
							90deg,
							transparent 1rem,
							var(--paper-margin) 1rem 1.05rem,
							transparent 1.05rem
						),
						url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAcCAYAAACgXdXMAAAAEklEQVR4nGO49+A5A8OgIP4DAGYJSwzzdzAYAAAAAElFTkSuQmCC");
				}
			}
			resize: vertical;

			&:focus-visible {
				outline: 3px solid var(--color-focus);
				outline-offset: 0.25rem;
			}
		}

		.notes-toolbar {
			display: grid;
			grid-template-columns: repeat(2, 1fr);
			gap: 0.35rem;
			padding: 0.3rem;
			border-radius: 0.65rem;
			margin-block-end: 1rem;
			background: var(--color-surface-muted);

			.notes-tab {
				display: grid;
				min-block-size: 2.8rem;
				border: 0;
				border-radius: 0.4rem;
				background: transparent;
				color: var(--color-text-muted);
				cursor: pointer;
				font-family: var(--font-sans);
				font-size: var(--font-size-label);
				font-weight: 800;
				place-items: center;
				text-align: center;

				&.is-active {
					background: var(--color-surface);
					box-shadow: var(--shadow-raised);
					color: var(--color-brand);
				}

				&:focus-visible {
					outline: 3px solid var(--color-focus);
				}
			}
		}

		&:has([hx-target="#notes-preview-body"].htmx-request) #notes-preview-body {
			opacity: 0;
			transition: none;
		}

		@media (prefers-reduced-motion: no-preference) {
			#notes-preview-body {
				transition: opacity 220ms ease-out;
			}
		}

		.notes-preview-empty {
			margin-block-start: 1.8rem;
			color: var(--color-text-muted);
			font-style: italic;
		}

		.rendered-notes {
			/* Rendered notes read like a printout: margins only, no ruling. */
			background: linear-gradient(
				90deg,
				transparent 1rem,
				var(--paper-margin) 1rem 1.05rem,
				transparent 1.05rem
			);
		}
	}

	.tracking-sheet {
		/* the tape comes from .paper-tape-center; only the blue-tinted
		   knock-off size and angle are local */
		--tape-top: -0.45rem;
		--tape-size: 3.75rem;
		--tape-thickness: 1rem;
		--tape-rotate: -2deg;
		--tape-color: color-mix(in oklch, var(--color-brand) 13%, transparent);

		align-self: start;
		padding: 1.6rem;
		border: 1px solid var(--color-rule);
		border-radius: 0.4rem;
		background: color-mix(
			in oklch,
			var(--color-highlight) 5%,
			var(--color-surface)
		);
		rotate: 0.2deg;

		> h2 {
			margin-block-end: 1.4rem;
			color: var(--color-text);
			font-family: var(--font-sans);
			font-size: 1.15rem;
			font-weight: 850;
		}
	}

	.kind-selector {
		margin-block-start: 1.4rem;
		padding: 0;
		border: 0;

		legend {
			padding: 0;
			margin-block-end: 0.65rem;
			color: var(--color-brand);
			font-family: var(--font-sans);
			font-size: var(--font-size-label);
			font-weight: 800;
		}
	}

	/* the demo / full / both release switcher: the account-menu pill track
	   idea, as a radio group inside the tracking sheet; the pressed pill
	   reads as raised, like the EN/SK language toggle */
	.kind-switch {
		display: flex;
		gap: 0.2rem;
		padding: 0.2rem;
		border-radius: 0.5rem;
		background: var(--color-surface-muted);

		.kind-option {
			position: relative;
			display: block;
			flex: 1;
			min-block-size: 2rem;
			border-radius: 0.4rem;
			color: var(--color-text-muted);
			cursor: pointer;
			font-family: var(--font-sans);
			font-size: var(--font-size-label);
			font-weight: 750;
			letter-spacing: 0.04em;
			line-height: 2rem;
			text-align: center;
			text-transform: uppercase;

			input {
				position: absolute;
				opacity: 0;
			}

			&:has(input:focus-visible) {
				outline: 3px solid var(--color-focus);
			}
		}

		.kind-option:has(input:checked) {
			background: var(--color-surface);
			color: var(--color-brand-deep);
			box-shadow: 0 1px 2px rgb(0 0 0 / 0.18);
		}
	}

	.kind-hint {
		margin-block-start: 0.5rem;
		color: var(--color-text-muted);
		font-size: var(--font-size-micro);
	}

	.status-selector {
		padding: 0;
		border: 0;

		legend {
			padding: 0;
			margin-block-end: 0.65rem;
			color: var(--color-brand);
			font-family: var(--font-sans);
			font-size: var(--font-size-label);
			font-weight: 800;
		}
	}

	.status-options {
		display: grid;
		gap: 0.45rem;
	}

	.status-choice {
		position: relative;
		display: grid;
		grid-template-columns: auto minmax(0, 1fr);
		align-items: center;
		gap: 0.6rem;
		min-block-size: 2.7rem;
		padding: 0.45rem 0.65rem;
		border: 1px solid var(--color-rule);
		border-radius: 0.4rem;
		background: var(--color-surface);
		/* darkened past 4.5:1 on the white card (Lighthouse contrast) */
		color: color-mix(in oklch, var(--color-text) 25%, var(--color-text-muted));
		cursor: pointer;
		font-family: var(--font-sans);
		font-size: 0.72rem;
		font-weight: 750;

		input {
			position: absolute;
			opacity: 0;
		}

		> span {
			display: grid;
			inline-size: 1.45rem;
			aspect-ratio: 1;
			border-radius: 50%;
			background: var(--color-surface-muted);
			font-size: var(--font-size-micro);
			place-items: center;
		}

		&:has(input:focus-visible) {
			outline: 3px solid var(--color-focus);
		}
	}

	.status-choice-playing:has(input:checked) {
		border-color: var(--status-color);
		background: var(--status-color);
		color: var(--status-ink);
	}

	.status-choice-finished:has(input:checked) {
		border-color: var(--status-color);
		background: var(--status-color);
		color: var(--status-ink);
	}

	.status-choice-backlog:has(input:checked) {
		border-color: var(--status-color);
		background: var(--status-color);
		color: var(--status-ink);
	}

	.status-choice:has(input:checked) > span {
		background: rgb(255 255 255 / 18%);
	}

	:is(.journal-rating, .journal-field) {
		display: grid;
		gap: 0.45rem;
		margin-block-start: 1.4rem;
		color: var(--color-brand);
		font-family: var(--font-sans);
		font-size: var(--font-size-label);
		font-weight: 750;
	}

	.journal-field input {
		inline-size: 100%;
		min-block-size: 2.8rem;
		padding: 0.65rem 0.75rem;
		border: 1px solid var(--color-rule);
		border-radius: 0.4rem;
		outline: 0;
		background: var(--color-surface);
		color: var(--color-text);
		font-family: var(--font-sans);
		font-size: 0.75rem;
		font-weight: 650;

		&::placeholder {
			/* the hint speaks in italics, like a margin note under the field */
			font-style: italic;
		}

		&:focus-visible {
			border-color: var(--color-brand);
			outline: 3px solid var(--color-focus);
		}
	}

	.journal-tracking-column {
		display: grid;
		gap: 1.25rem;
		align-self: start;
	}

	/* the save button sizes like the homepage add button everywhere except
	   small phones; on the wide two-column layout it is centered under the
	   tracking sheet with room to breathe */
	.journal-form-footer {
		display: flex;
		justify-content: center;
		margin-block-start: 0.75rem;

		.primary-button {
			min-block-size: 3.6rem;
			padding: 0.95rem 1.5rem;
			font-size: 0.75rem;
		}
	}

	.remove-game {
		inline-size: min(100% - 5rem, 72rem);
		/* clear the journal sheet's torn hem, like the list fold */
		margin: 4rem auto 0;
		font-family: var(--font-sans);

		details {
			padding-block-start: 1rem;
			border-block-start: 1px solid var(--color-rule);
		}

		summary {
			inline-size: max-content;
			color: var(--color-text-muted);
			cursor: pointer;
			font-size: var(--font-size-label);
			font-weight: 750;
		}

		p {
			margin-block-start: 0.8rem;
			color: var(--color-text-muted);
			font-size: 0.72rem;
		}

		button {
			padding: 0.65rem 0.8rem;
			border: 1px solid var(--color-accent);
			border-radius: 0.35rem;
			margin-block-start: 0.8rem;
			background: transparent;
			color: var(--color-accent);
			cursor: pointer;
			font-family: var(--font-sans);
			font-size: var(--font-size-micro);
			font-weight: 800;
			text-transform: uppercase;

			&:is(:hover, :focus-visible) {
				background: var(--color-accent);
				color: white;
			}
		}
	}
}

@layer motion {
	@media (hover: hover) and (pointer: fine) and (
			prefers-reduced-motion: no-preference
		) {
		/* hovering an option previews its status colour, like the tabs;
		   a checked option keeps its solid state untouched */
		.status-choice {
			transition:
				border-color 120ms ease,
				background-color 120ms ease;
		}

		.status-choice-playing:not(:has(input:checked)):hover {
			border-color: var(--status-color);
			background: color-mix(
				in oklch,
				var(--status-color) 8%,
				var(--color-surface)
			);
			color: var(--status-color);
		}

		.status-choice-finished:not(:has(input:checked)):hover {
			border-color: var(--status-color);
			background: color-mix(
				in oklch,
				var(--status-color) 8%,
				var(--color-surface)
			);
			color: var(--status-color);
		}

		.status-choice-backlog:not(:has(input:checked)):hover {
			border-color: var(--status-color);
			background: color-mix(
				in oklch,
				var(--status-color) 12%,
				var(--color-surface)
			);
			color: var(--status-ink);
		}
	}
}

@layer accessibility {
	@media (forced-colors: active) {
		:is(.journal-cover, .notes-sheet, .tracking-sheet, .status-choice) {
			border: 1px solid CanvasText;
		}

		.journal-cover[data-cover-drift]::after {
			display: none;
		}
	}
}

@media (width <= 64rem) {
	@layer pages {
		/* the tracking aside keeps its width, so the notes sheet must be
		   allowed to breathe: stack the journal form earlier than the hero */
		.journal-form {
			grid-template-columns: 1fr;
		}

		.journal-tracking-column .tracking-sheet {
			margin-block-start: 0.75rem;
		}

		.journal-form-footer {
			justify-content: flex-end;
			margin-block-start: 0;
		}

		.journal-errors {
			grid-column: auto;
		}
	}
}

@media (width <= 52rem) {
	@layer pages {
		.app-shell:has(.game-journal-page) > .site-header {
			background: transparent;
			box-shadow: none;
		}

		.journal-hero {
			min-block-size: calc(21rem + 4.25rem);
			padding-block: calc(1.5rem + 4.25rem) 3rem;
			margin-block-start: -4.25rem;

			&::before {
				mask-image: linear-gradient(to bottom, black, transparent 38%);
			}
		}

		:is(.journal-identity, .journal-form, .journal-flash, .remove-game) {
			inline-size: min(100% - 2rem, 72rem);
		}

		.journal-identity {
			grid-template-columns: 8.5rem minmax(0, 1fr);
			gap: 1.2rem;
			margin-block-start: 2rem;

			h1 {
				font-size: clamp(2.8rem, 12vw, 4.5rem);
			}

			h1.long {
				font-size: clamp(2.15rem, 8.5vw, 3.3rem);
			}

			h1.very-long {
				font-size: clamp(1.7rem, 5vw, 2.6rem);
			}
		}

		.tracking-sheet {
			rotate: 0deg;
		}

		/* 16px keeps iOS Safari from zooming the page into journal fields */
		.notes-sheet textarea {
			font-size: 1rem;
		}

		.journal-field input {
			font-size: 1rem;
		}
	}
}

@media (width <= 38rem) {
	@layer pages {
		.journal-hero {
			min-block-size: calc(18rem + 4.25rem);
		}

		.journal-identity {
			grid-template-columns: 6.5rem minmax(0, 1fr);
			align-items: center;
			gap: 1rem;

			h1 {
				font-size: clamp(2.35rem, 11.5vw, 3.5rem);
			}

			h1.long {
				font-size: clamp(1.8rem, 8vw, 2.55rem);
			}

			h1.very-long {
				font-size: clamp(1.4rem, 5vw, 1.9rem);
			}
		}

		.notes-sheet {
			padding: 1.5rem 1.25rem 2rem;

			textarea {
				min-block-size: 20rem;
				font-size: 1rem;
			}
		}

		.tracking-sheet {
			padding: 1.35rem 1.25rem;
		}

		.journal-form-footer .primary-button {
			min-block-size: 3rem;
			padding: 0.8rem 1.15rem;
			font-size: var(--font-size-label);
		}

		.remove-game {
			margin-block-start: 3rem;
		}
	}
}

@media (width > 52rem) {
	@layer pages {
		/* Start at 17.5 lines rather than 14; keep the writing area resizable. */
		.game-journal-page .notes-sheet textarea {
			block-size: calc(490px + 1.25rem);
			min-block-size: 28.75rem;
		}
	}
}
