@use '../lib/colors';
@use '../lib/layout';
@use '../lib/motion';
@use '../lib/typography';

body {
	margin: 0;
	color: colors.$main-text;
}

%title {
	@extend %content-gutter;
	margin-top: layout.$huge-gap;
	margin-bottom: layout.$large-gap;
	font-size: typography.$title-size;
	line-height: typography.$heading-line-height;
	text-align: center;
	overflow-wrap: anywhere;
}

h1 {
	@extend %title;
}

%heading {
	@extend %content-gutter;
	margin-top: layout.$large-gap;
	margin-bottom: layout.$large-gap;
	font-size: typography.$heading-size;
	line-height: typography.$heading-line-height;
	overflow-wrap: anywhere;

	&:after {
		content: '';
		display: block;
		width: 8rem;
		height: 0.3rem;
		margin-top: 0.2rem;
		border-radius: 0.5rem;
		background-color: colors.$blue-800;

		@include colors.coderdojo-theme {
			background-color: colors.$brown-800;
		}
	}
}

h2 {
	@extend %heading;
}

%subheading {
	@extend %content-gutter;
	font-size: typography.$subheading-size;
	line-height: typography.$heading-line-height;
	overflow-wrap: anywhere;
}

h3 {
	@extend %subheading;
}

p,
pre {
	@extend %content-gutter;
}

ul,
ol,
dl {
	@extend %content-gutter;
}

li {
	margin: layout.$small-gap 0;
}

dt {
	margin: layout.$normal-gap 0;
	font-weight: typography.$emphasized-weight;
	color: colors.$blue-800;

	@include colors.coderdojo-theme {
		color: colors.$brown-800;
	}
}

dd {
	margin: layout.$normal-gap 0 layout.$normal-gap layout.$large-gap;
}

em {
	background-color: colors.$teal-300;
	padding: 0 layout.$small-gap 0 layout.$small-gap;

	@include colors.coderdojo-theme {
		background-color: colors.$orange-300;
	}
}

:any-link,
a[href] {
	color: colors.$main-text;
	transition: color motion.$subtle;

	&:hover {
		color: colors.$blue-800;

		@include colors.coderdojo-theme {
			color: colors.$brown-800;
		}
	}
}

blockquote {
	$color: colors.$teal-300;

	@include colors.coderdojo-theme {
		$color: colors.$orange-300;
	}

	@extend %narrow-content-gutter;
	padding-left: layout.$small-gap;
	padding-right: layout.$small-gap;
	$border: 0.5em solid $color;
	border-top: $border;
	border-bottom: $border;

	> p:only-child > a:only-child > img:only-child {
		display: block;
		max-width: 100%;
		max-height: 60rem;
		margin: 0 auto;
	}
}

.cta-link {
	display: block;
	margin: 0 auto;
	padding: 0 layout.$normal-gap;
	max-width: layout.$narrow-content-width;
	text-align: center;
	text-decoration: none;
	line-height: 3rem;
	border: 1px solid colors.$main-text;
	transition:
		font motion.$subtle,
		border-color motion.$subtle,
		color motion.$subtle;

	&:hover {
		border-color: colors.$blue-800;
		font-weight: typography.$emphasized-weight;
		font-size: 110%;

		@include colors.coderdojo-theme {
			border-color: colors.$brown-800;
		}
	}
}

ul.link-grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: layout.$larger-gap layout.$normal-gap;
	justify-items: center;
	align-items: center;
	padding: 0;
	list-style: none;

	@media screen and (min-width: layout.$breakpoint) {
		&:not(.large) {
			grid-template-columns: repeat(3, 1fr);
		}

		&.large {
			gap: layout.$normal-gap;

			> li > a {
				display: flex;
				align-items: center;

				> img {
					max-width: 6rem;
					margin-right: layout.$normal-gap;
				}
			}
		}
	}

	&.large {
		@extend %narrow-content-gutter;
	}

	> li {
		> a {
			display: inline-block;
			padding: layout.$normal-gap;
			text-align: center;
			text-decoration: none;
			color: colors.$gray-600;
			transition:
				color motion.$subtle,
				box-shadow motion.$subtle;

			> img {
				display: block;
				margin: 0 auto layout.$small-gap auto;
				max-width: 100%;
				max-height: 6rem;
			}

			&:hover {
				@include colors.card-shadow;
			}
		}
	}
}

.post-list {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	@extend %content-gutter;
	margin-top: layout.$huge-gap;
	margin-bottom: layout.$huge-gap;

	@media screen and (min-width: layout.$breakpoint) {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: layout.$normal-gap;
		justify-content: stretch;
	}
}

:any-link.post-card {
	display: block;
	padding-top: layout.$normal-gap;
	padding-bottom: layout.$normal-gap;
	text-decoration: none;
	transition:
		background-color motion.$subtle,
		color motion.$subtle,
		box-shadow motion.$subtle;

	@media screen and (min-width: layout.$breakpoint) {
		padding-left: layout.$normal-gap;
		padding-right: layout.$normal-gap;
	}

	&:hover {
		@include colors.card-shadow;
		background-color: colors.$yellow-300;
		color: colors.$blue-800;

		@include colors.coderdojo-theme {
			background-color: colors.$green-300;
		}
	}

	&.external {
		color: colors.$brown-800;

		> time {
			color: colors.$brown-500;
		}

		&:hover {
			background-color: colors.$teal-300;
		}
	}

	> :first-child {
		margin-top: 0;
	}

	> :last-child {
		margin-top: 0;
	}

	> h2,
	> p {
		margin-left: 0;
		margin-right: 0;
	}

	> h2 {
		@extend %subheading;

		&::after {
			display: none;
		}

		> img {
			display: inline-block;
			max-width: 4em;
			max-height: 1em;
		}

		+ time {
			margin-top: -1 * layout.$normal-gap;
		}
	}

	> time {
		display: block;
		color: colors.$gray-600;

		+ p {
			margin-top: layout.$small-gap;
		}
	}
}

.post-metadata {
	text-align: center;
	color: colors.$blue-800;

	@include colors.coderdojo-theme {
		color: colors.$brown-800;
	}

	> img {
		display: block;
		margin: 0 auto layout.$small-gap auto;
		max-height: 6rem;
	}
}
