/* A calendar of commits (heatmap.js): a square per day, darker for more
   commits on light, brighter on dark, in one hue. The steps were checked
   as an ordinal ramp against each theme's background (monotone lightness,
   a visible gap between steps, the faintest above 2:1); days without
   commits take the hairline colour and recede. */

.heatmap {
	--heat-0: var(--hairline);
	--heat-1: #5b6b57;
	--heat-2: #738665;
	--heat-3: #8da373;
	--heat-4: #a7c080;
	--heat-gap: 3px;
	--heat-label: 32px;
	position: relative;
	/* No wider than its squares at their largest, so the period and the
	   scale line up with the calendar's ends. */
	max-width: calc(var(--heat-label) + var(--weeks, 53) * (15px + var(--heat-gap)) + 4px);
	container-type: inline-size;
}

html[data-theme="light"]:not([data-browser="ladybird"]) .heatmap {
	--heat-1: #a6b07a;
	--heat-2: #8f9b59;
	--heat-3: #788737;
	--heat-4: #627300;
}

.heatmap-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--s2) var(--s4);
	margin-bottom: var(--s3);
}

.heatmap-total {
	margin: 0;
	font-size: 14px;
	color: var(--muted);
}

.heatmap-total strong {
	color: var(--text);
}

/* The calendar scrolls sideways where even its smallest squares don't fit,
   showing the latest weeks, with room under them for a scrollbar. */
.heatmap-scroll {
	padding-bottom: var(--s2);
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scrollbar-width: none;
}

.heatmap-scroll::-webkit-scrollbar {
	display: none;
}

/* Squares grow with the space, from 10px to 15px (14px at least for a
   finger); the padding keeps room for a focused day's ring. */
.heatmap-grid {
	--heat-cell: clamp(10px, (100cqw - var(--heat-label) - var(--weeks) * var(--heat-gap) - 4px) / var(--weeks), 15px);
	display: grid;
	grid-template-columns: var(--heat-label) repeat(var(--weeks), var(--heat-cell));
	grid-template-rows: 16px repeat(7, var(--heat-cell));
	gap: var(--heat-gap);
	width: max-content;
	padding: 2px;
}

.heatmap-grid [role="row"],
.heatmap-labels {
	display: contents;
}

.heatmap-month,
.heatmap-weekday {
	font-size: 11px;
	line-height: 16px;
	color: var(--muted);
	white-space: nowrap;
	user-select: none;
	--selection-line: none;
}

.heatmap-month {
	grid-row: 1;
}

/* The weekdays stay in view as the weeks scroll under them. */
.heatmap-weekday {
	position: sticky;
	left: 0;
	z-index: 1;
	grid-column: 1;
	align-self: stretch;
	display: flex;
	align-items: center;
	margin-left: -2px;
	padding-left: 2px;
	background: var(--bg);
	box-shadow: var(--heat-gap) 0 var(--bg);
	line-height: 1;
}

.heatmap-day,
.heatmap-key {
	border-radius: 2px;
	background: var(--heat-0);
}

/* A day whose count changes as the history moves on eases to its new
   colour. */
.heatmap-day {
	transition: background-color 600ms var(--ease-effects);
}

.heatmap-day[data-outside] {
	visibility: hidden;
}

.heatmap-day[data-level="1"],
.heatmap-key[data-level="1"] {
	background: var(--heat-1);
}

.heatmap-day[data-level="2"],
.heatmap-key[data-level="2"] {
	background: var(--heat-2);
}

.heatmap-day[data-level="3"],
.heatmap-key[data-level="3"] {
	background: var(--heat-3);
}

.heatmap-day[data-level="4"],
.heatmap-key[data-level="4"] {
	background: var(--heat-4);
}

/* The day under the pointer stands out from its neighbours. */
.heatmap-day[data-day]:hover {
	outline: 1px solid var(--text);
	outline-offset: 1px;
}

.heatmap-day:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
}

.heatmap-foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--s2) var(--s4);
	margin-top: var(--s2);
}

.heatmap-legend {
	display: flex;
	align-items: center;
	gap: 3px;
	font-size: 11px;
	color: var(--muted);
}

.heatmap-legend > span:first-child {
	margin-right: 4px;
}

.heatmap-legend > span:nth-child(7) {
	margin-left: 4px;
}

.heatmap-key {
	width: 11px;
	height: 11px;
}

/* M3's text button, for the table of months. */
.heatmap-toggle {
	appearance: none;
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: var(--s1);
	height: 32px;
	margin-left: calc(var(--s2) * -1);
	padding: 0 var(--s3) 0 var(--s2);
	border: 0;
	border-radius: 16px;
	background: none;
	color: var(--ink-accent, var(--accent));
	font: inherit;
	font-size: 13px;
}

.heatmap-toggle::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	background: currentColor;
	opacity: 0;
	transition: opacity 150ms var(--ease-effects);
}

.heatmap-toggle:hover::before {
	opacity: 0.08;
}

.heatmap-toggle svg {
	width: 16px;
	height: 16px;
	transition: rotate 200ms cubic-bezier(0.2, 0, 0, 1);
}

.heatmap-toggle[aria-expanded="true"] svg {
	rotate: 90deg;
}

.heatmap-table {
	width: 100%;
	max-width: 360px;
	margin-top: var(--s2);
	border-collapse: collapse;
	font-size: 13px;
}

.heatmap-table th,
.heatmap-table td {
	padding: 6px var(--s3) 6px 0;
	border-bottom: 1px solid var(--hairline);
	text-align: left;
	font-weight: 400;
}

.heatmap-table thead th {
	color: var(--muted);
	font-size: 12px;
}

.heatmap-table td,
.heatmap-table thead th:last-child {
	padding-right: 0;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

/* The day's count, on the glass the site's menus and cards use (as the
   line-count card, hover-card.css): the count leads, the date under it. */
.heatmap-tip {
	position: absolute;
	z-index: 4;
	display: flex;
	flex-direction: column;
	gap: 2px;
	max-width: 260px;
	padding: var(--s2) var(--s3);
	border-radius: var(--s2);
	background: color-mix(in srgb, var(--popup) 82%, transparent);
	-webkit-backdrop-filter: blur(24px) saturate(1.4);
	backdrop-filter: blur(24px) saturate(1.4);
	box-shadow:
		inset 0 0 0 1px color-mix(in srgb, var(--text) 9%, transparent),
		0 1px 2px rgb(0 0 0 / 0.3),
		0 2px 6px 2px rgb(0 0 0 / 0.15);
	color: var(--text);
	font-size: 12px;
	line-height: 16px;
	white-space: nowrap;
	pointer-events: none;
}

.heatmap-tip span {
	color: var(--muted);
}

.heatmap-tip li span:last-child {
	color: var(--text);
	font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
	.heatmap-tip {
		background: var(--popup);
		-webkit-backdrop-filter: none;
		backdrop-filter: none;
	}
}

.heatmap-tip[hidden] {
	display: none;
}

.heatmap-tip:not(.placing) {
	transition:
		left 160ms cubic-bezier(0.2, 0, 0, 1),
		top 160ms cubic-bezier(0.2, 0, 0, 1);
}

.heatmap-tip strong {
	font-size: 13px;
}

.heatmap-tip ul {
	margin: 4px 0 0;
	padding: 0;
	list-style: none;
}

.heatmap-tip li {
	display: flex;
	justify-content: space-between;
	gap: var(--s3);
}

@media (prefers-reduced-motion: reduce) {
	.heatmap-toggle::before,
	.heatmap-toggle svg,
	.heatmap-tip:not(.placing),
	.heatmap-day {
		transition: none;
	}
}

@media (pointer: coarse) {
	.heatmap-grid {
		--heat-cell: clamp(14px, (100cqw - var(--heat-label) - var(--weeks) * var(--heat-gap) - 4px) / var(--weeks), 15px);
	}
}
