/* The header, footer, and side gutters form one opaque frame around a rounded
   content panel that scrolls on its own, after the Caelestia shell's border. */
body {
	display: flex;
	flex-direction: column;
	height: 100vh;
	height: 100dvh;
}

body > header,
body > footer {
	flex-shrink: 0;
	line-height: 24px;
	user-select: none;
	--selection-line: none;
}

/* Bar text centres on whole pixels: integer line boxes, and a transparent top
   border to balance the 1px hover border under each link. */
body > header a,
body > footer a {
	border-top: 1px solid transparent;
}

/* The name and the links share one box height, so they line up side by side
   and the stacked narrow header has equal space above and below. */
body > header a {
	padding: 2px 0;
}

.content-frame {
	position: relative;
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	min-height: 0;
	margin: 0 var(--frame-gap);
	border-radius: var(--frame-radius);
	overflow: hidden;
	background: var(--bg);
	z-index: 0;
}

/* The frame's shadow falls on the content, so it is drawn above it. A
   frame-coloured ring around the panel, and any drawer silhouette added
   inside it, cast one drop shadow inward. Frame and drawer then shade as a
   single shape, the way Caelestia shadows its border and drawers together. */
.frame-shade {
	position: absolute;
	inset: 0;
	border-radius: inherit;
	box-shadow: 0 0 0 64px var(--frame);
	filter: drop-shadow(0 0 15px var(--frame-shadow));
	pointer-events: none;
	z-index: 2;
}

/* Fine noise in overlay blend dithers the shadow's gradient, which otherwise
   bands, most visibly in Firefox. Overlay around mid-grey averages to no
   change, shifting each pixel by about one colour level at most. */
.content-frame::after {
	content: "";
	position: absolute;
	inset: 0;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' stitchTiles='stitch'/%3E%3CfeColorMatrix values='1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='128' height='128' filter='url(%23n)'/%3E%3C/svg%3E");
	background-size: 128px;
	mix-blend-mode: overlay;
	opacity: 0.1;
	pointer-events: none;
	z-index: 3;
}

.content-scroll {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	min-height: 0;
	border-radius: inherit;
	overflow: auto;
}

/* Content moving in or out on a route change stays inside (transitions.css). */
main {
	flex: 1 0 auto;
	overflow-y: clip;
}

/* Focused by the router as the keyboard scrolling target, not by the user. */
main:focus {
	outline: none;
}

.wrap {
	padding: 0 var(--page-pad);
}

/* The header and footer span the frame's gutters as well, so their content
   lines up with the panel's content at every width. */
body > header .wrap,
body > footer .wrap {
	padding-inline: calc(var(--page-pad) + var(--frame-gap));
}

main section {
	padding: var(--s7) 0;
}

/* The pages' content grid: twelve columns, six on tablets, four on phones. */
.grid {
	display: grid;
	grid-template-columns: repeat(12, minmax(0, 1fr));
	gap: var(--s5);
}

@media (max-width: 940px) {
	.grid {
		grid-template-columns: repeat(6, minmax(0, 1fr));
	}
}

@media (max-width: 600px) {
	.grid {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

/* The status bar: name on the left, navigation centred, and Faye's local
   time and the theme toggle on the right. Narrow windows give the navigation
   its own row. */
.nav {
	position: relative;
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	grid-template-areas: "id links status";
	align-items: center;
	column-gap: var(--s5);
	padding-block: var(--s4);
}

.id {
	grid-area: id;
	justify-self: start;
	font-weight: 600;
	letter-spacing: 0.2px;
	white-space: nowrap;
}

.links {
	grid-area: links;
	display: flex;
	gap: var(--s5);
}

/* Material 3 tab label roles: on-surface-variant at rest, on-surface on
   hover or focus, and the accent for the current page. The snake answers
   hover by leaning toward the link, so the links' own underline is off. */
/* The cursor's highlight is a pill with room either side (cursor.js). */
.links a {
	--cursor-pad: 4px 10px;
	--cursor-radius: 999px;
	border-bottom: 1px solid transparent;
	color: var(--muted);
	transition: color 200ms cubic-bezier(0.2, 0, 0, 1);
}

.links a:hover,
.links a:focus-visible {
	color: var(--text);
	border-color: transparent;
}

.links a[aria-current="page"] {
	color: var(--accent);
}

.links a {
	background: none;
}

.status {
	grid-area: status;
	justify-self: end;
	display: flex;
	align-items: center;
	gap: var(--s4);
	font-size: 0.85rem;
	color: var(--muted);
	white-space: nowrap;
}

.status-clock {
	font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
	.nav {
		grid-template-columns: 1fr auto;
		grid-template-areas:
			"id status"
			"links links";
		row-gap: var(--s3);
	}

	.links {
		justify-self: start;
		gap: var(--s4);
	}
}

@media (max-width: 400px) {
	.links {
		gap: var(--s3);
	}
}

body > footer {
	/* base.css asks for geometric precision so text widths match across
	   engines; in the footer, Chromium's default whole-pixel metrics are what
	   the line heights below are tuned to centre on. */
	text-rendering: auto;
	padding: var(--s2) 0;
	padding-bottom: calc(var(--s2) + env(safe-area-inset-bottom, 0px));
	color: var(--muted);
	font-size: 0.95rem;
}

.footer-row {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 12px;
	min-height: 28px;
}

.footer-left,
.footer-right {
	flex: 0 1 auto;
}

/* Chromium rounds Comic Mono's ascent and descent at 15.2px to 14 + 3px. An
   odd line height leaves even leading, so the text centres as in Firefox. */
.footer-left {
	line-height: 25px;
}

/* The link's smaller text gets its own line box instead of sitting on the
   baseline of the larger footer text. */
.footer-right {
	display: flex;
	align-items: center;
}

.footer-link {
	font-family: var(--font-mono);
	font-size: 0.85rem;
	color: var(--muted);
}

.footer-center {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	text-align: center;
	opacity: 0;
	transition: opacity 160ms ease;
	white-space: nowrap;
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.footer-center svg {
	width: 1em;
	height: 1em;
}

@media (max-width: 540px) {
	html[data-browser="ladybird"] .footer-center {
		position: static;
		transform: none;
		flex: 1 0 100%;
		justify-content: center;
		order: 3;
	}
}

@media (max-height: 480px) {
	main section {
		padding: var(--s4) 0;
	}

	.nav {
		padding-block: var(--s2);
	}

	body > footer {
		padding: var(--s1) 0;
		padding-bottom: calc(var(--s1) + env(safe-area-inset-bottom, 0px));
	}
}

/* When the frame cannot leave room for content, the document scrolls instead. */
@media (max-height: 240px), (max-width: 280px) and (max-height: 300px) {
	body {
		height: auto;
		min-height: 100vh;
	}

	.content-frame,
	.content-scroll {
		flex: none;
		overflow: visible;
	}

	/* The panel no longer clips, so its shadow can't come from a ring outside it. */
	.frame-shade {
		box-shadow: inset 0 0 15px var(--frame-shadow);
		filter: none;
	}
}
