/* ==========================================================================
   /health/ — WHOOP sleep, recovery and training (lib/whoop/render.js).
   Loaded only on that page. Built on the site's theme variables, so light,
   paper and dark all work; only the WHOOP data colours are defined here.
   ========================================================================== */

.health {
	/* Recovery zones use the site's own green and red (see .archive-legend). */
	--hl-high: #27933c;
	--hl-mid: #dc9c0a;
	--hl-low: #e23939;
	/* Strain is the site accent: blue in light/dark, ink in paper. */
	--hl-strain: var(--text-color-link);
	--hl-sleep: #6475bb;
	--hl-muted: var(--text-color-soft);
	--hl-faint: color-mix(in oklab, var(--border-color) 55%, transparent);
}

@media (prefers-color-scheme: dark) {
	html:not([data-theme]) .health {
		--hl-high: #47cf79;
		--hl-mid: #fcc447;
		--hl-low: #f75c61;
		--hl-sleep: #8f9ee6;
	}
}

html[data-theme="dark"] .health {
	--hl-high: #47cf79;
	--hl-mid: #fcc447;
	--hl-low: #f75c61;
	--hl-sleep: #8f9ee6;
}

/* Paper is the quiet, monochrome theme: sleep goes to a muted ink-violet. */
html[data-theme="paper"] .health {
	--hl-sleep: #5f5b86;
}

/* One class of specificity: beats the site's `main ul` rules, but loses to the
   component rules below so their margins apply. */
.health :where(ul, ol, li, dl, dd, figure) {
	margin: 0;
	padding: 0;
	list-style: none;
}

.hl-nowrap { white-space: nowrap; }
.hl-small { font-size: 0.75rem; }
.hl-phone-only { display: none; }

/* --- Hero --------------------------------------------------------------- */

.hl-hero {
	margin: 2.25rem 0 0.5rem;
	text-align: center;
}

/* Small caps labels, as on /archive/ and /stats/. */
.hl-today,
.hl-ring figcaption,
.hl-card-head h3 {
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--text-color-muted);
}

.hl-today { margin: 0 0 1.25rem; }

.hl-rings {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: clamp(0.75rem, 5vw, 2.5rem);
	max-width: 30rem;
	margin: 0 auto;
}

.hl-ring {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.6rem;
}

.hl-ring-box {
	position: relative;
	width: 100%;
	max-width: 8.5rem;
	aspect-ratio: 1;
}

.hl-ring-box svg {
	display: block;
	width: 100%;
	height: 100%;
	transform: rotate(-90deg);
}

.hl-ring-track { stroke: var(--border-color); }
.hl-c-sleep { stroke: var(--hl-sleep); }
.hl-c-high { stroke: var(--hl-high); }
.hl-c-mid { stroke: var(--hl-mid); }
.hl-c-low { stroke: var(--hl-low); }
.hl-c-strain { stroke: var(--hl-strain); }

.hl-ring-value {
	animation: hl-ring-draw 1.2s cubic-bezier(0.2, 0, 0, 1) both;
	animation-delay: calc(150ms + var(--i, 0) * 90ms);
}

@keyframes hl-ring-draw {
	from { stroke-dashoffset: var(--len); }
}

.hl-ring-value-text {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	font-size: clamp(1.15rem, 4.6vw, 1.65rem);
	font-weight: 700;
	letter-spacing: -0.02em;
	font-variant-numeric: tabular-nums;
}

.hl-summary {
	max-width: 28rem;
	margin: 2rem auto 0;
	font-size: 0.9rem;
	color: var(--text-color-muted);
	text-wrap: balance;
}

.hl-summary strong {
	font-weight: 700;
	color: var(--text-color);
}

/* --- Sections & cards --------------------------------------------------- */

.hl-section {
	display: grid;
	gap: 1rem;
	margin-top: 3.5rem;
	scroll-margin-top: 1rem;
}

.hl-section-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.25rem 1rem;
	padding-bottom: 0.75rem;
	border-bottom: 1px dashed var(--border-color);
}

.hl-section-head h2 {
	margin: 0;
	font-size: 1.2em; /* matches .section-heading */
}

.hl-section-head p {
	margin: 0;
	font-size: 0.8rem;
	color: var(--hl-muted);
	font-variant-numeric: tabular-nums;
}

/* Same surface, border and 8px corners as the /stats/ tiles. */
.hl-card {
	min-width: 0;
	padding: 1rem 1rem 1.1rem;
	background: var(--surface-color);
	border: 1px solid var(--border-color);
	border-radius: 8px;
}

.hl-card-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.25rem 1rem;
	margin-bottom: 1rem;
}

.hl-card-head h3 { margin: 0; }

.hl-aside {
	font-size: 0.8rem;
	color: var(--hl-muted);
	font-variant-numeric: tabular-nums;
}

.hl-pair {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
	gap: 1rem;
}

.hl-empty {
	display: grid;
	place-items: center;
	min-height: 7rem;
	margin: 0;
	font-size: 0.875rem;
	color: var(--hl-muted);
}

.hl-notice {
	padding: 1rem;
	border: 1px dashed var(--border-color);
	border-radius: var(--radius);
	color: var(--text-color-muted);
}

.hl-synced { margin-top: 3rem; }

/* --- Charts ------------------------------------------------------------- */

.hl-chart {
	display: grid;
	grid-template-columns: auto 1fr;
	column-gap: 0.6rem;
	font-size: 11px;
	line-height: 1;
	color: var(--hl-muted);
	font-variant-numeric: tabular-nums;
}

.hl-y { position: relative; }

.hl-y span {
	position: absolute;
	right: 0;
	transform: translateY(-50%);
	white-space: nowrap;
}

.hl-y .hl-y-sizer {
	position: static;
	visibility: hidden;
	transform: none;
}

.hl-plot {
	position: relative;
	height: var(--h);
}

.hl-grid {
	position: absolute;
	left: 0;
	right: 0;
	border-top: 1px dashed var(--border-color);
}

.hl-grid-avg {
	border-top-color: color-mix(in oklab, var(--text-color) 35%, transparent);
}

.hl-fill {
	position: absolute;
	inset: 0;
}

.hl-x {
	position: relative;
	height: 11px;
	margin-top: 0.6rem;
}

.hl-x span {
	position: absolute;
	transform: translateX(-50%);
	white-space: nowrap;
}

/* Daily recovery bars */
.hl-bars {
	display: flex;
	align-items: flex-end;
}

.hl-bar {
	position: relative;
	flex: 1;
	height: 100%;
}

.hl-bar span {
	position: absolute;
	left: 14%;
	right: 14%;
	bottom: 0;
	border-radius: 2px 2px 0 0;
}

.hl-bg-high { background: var(--hl-high); }
.hl-bg-mid { background: var(--hl-mid); }
.hl-bg-low { background: var(--hl-low); }
.hl-bg-strain { background: var(--hl-strain); }

.hl-legend {
	display: flex;
	align-items: center;
	gap: 0.9rem;
	font-size: 0.75rem;
}

.hl-legend li {
	display: flex;
	align-items: center;
	gap: 0.35rem;
}

.hl-swatch {
	display: inline-block;
	width: 0.5rem;
	height: 0.5rem;
	border-radius: 999px;
}

/* Line charts */
.hl-svg {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	overflow: visible;
}

.hl-line-raw { color: var(--hl-muted); opacity: 0.4; }
.hl-line-avg { color: var(--text-color); opacity: 0.35; }
.hl-tone-fg { color: var(--text-color); }
.hl-tone-sleep { color: var(--hl-sleep); }

.hl-dot {
	position: absolute;
	width: 0.6rem;
	height: 0.6rem;
	border-radius: 999px;
	background: currentColor;
	box-shadow: 0 0 0 3px var(--surface-color);
	transform: translate(-50%, -50%);
}

.hl-dot-label {
	position: absolute;
	transform: translateY(-165%);
	white-space: nowrap;
	color: var(--text-color);
	text-shadow: 0 0 6px var(--surface-color), 0 0 2px var(--surface-color);
}

/* Bedtime and wake-up */
.hl-nights { display: flex; }

.hl-night {
	position: relative;
	flex: 1;
	height: 100%;
}

.hl-night span {
	position: absolute;
	left: 18%;
	right: 18%;
	border-radius: 999px;
	background: var(--hl-sleep);
}

.hl-night .hl-irregular { opacity: 0.5; }

/* Sleep stages */
.hl-stagebar {
	display: flex;
	gap: 2px;
	height: 0.6rem;
	overflow: hidden;
	border-radius: 999px;
}

.hl-stage-deep { background: var(--hl-sleep); }
.hl-stage-rem { background: color-mix(in oklab, var(--hl-sleep) 62%, var(--surface-color)); }
.hl-stage-light { background: color-mix(in oklab, var(--hl-sleep) 32%, var(--surface-color)); }
.hl-stage-awake { background: color-mix(in oklab, var(--hl-muted) 40%, var(--surface-color)); }

.hl-stages {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 1rem;
	margin-top: 1.1rem;
}

.hl-stages dt,
.hl-times dt {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	font-size: 0.75rem;
	color: var(--hl-muted);
}

.hl-stages .hl-swatch { border-radius: 2px; }

.hl-stages dd {
	margin-top: 0.25rem;
	font-size: 0.9rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.hl-stages dd span {
	font-weight: 400;
	color: var(--hl-muted);
}

.hl-times {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 1rem;
	margin-top: 1.1rem;
	padding-top: 1.1rem;
	border-top: 1px dashed var(--border-color);
}

.hl-times dd {
	margin-top: 0.35rem;
	font-size: 1.4rem; /* matches .stat-value */
	font-weight: 700;
	letter-spacing: -0.02em;
	font-variant-numeric: tabular-nums;
}

.hl-icon {
	width: 1rem;
	height: 1rem;
	flex-shrink: 0;
}

.hl-icon-sm {
	width: 0.9rem;
	height: 0.9rem;
}

/* Training heatmap */
.hl-heatmap {
	display: grid;
	grid-template-columns: auto repeat(var(--weeks), minmax(0, 1fr));
	gap: 3px;
	font-size: 10px;
	line-height: 1;
	color: var(--hl-muted);
}

.hl-month {
	height: 1rem;
	white-space: nowrap;
}

.hl-weekday {
	align-self: center;
	padding-right: 0.4rem;
}

.hl-cell {
	display: block;
	aspect-ratio: 1;
	border-radius: 2px;
}

.hl-cell-empty { background: var(--hl-faint); }
.hl-cell-0 { background: color-mix(in oklab, var(--hl-strain) 16%, var(--surface-color)); }
.hl-cell-1 { background: color-mix(in oklab, var(--hl-strain) 36%, var(--surface-color)); }
.hl-cell-2 { background: color-mix(in oklab, var(--hl-strain) 56%, var(--surface-color)); }
.hl-cell-3 { background: color-mix(in oklab, var(--hl-strain) 80%, var(--surface-color)); }
.hl-cell-4 { background: var(--hl-strain); }

.hl-scale {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 0.3rem;
	margin-top: 0.9rem;
	font-size: 11px;
	color: var(--hl-muted);
}

.hl-scale .hl-cell {
	width: 0.6rem;
	height: 0.6rem;
}

.hl-scale span:first-child { margin-right: 0.2rem; }
.hl-scale span:last-child { margin-left: 0.2rem; }

/* By sport */
.hl-sports {
	display: grid;
	gap: 1rem;
}

.hl-sport {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	min-width: 0;
}

.hl-sport .hl-icon { color: var(--hl-muted); }

.hl-sport-name {
	overflow: hidden;
	font-size: 0.9rem;
	font-weight: 700;
	white-space: nowrap;
	text-overflow: ellipsis;
}

/* Outlined pill, like the year chips on /archive/. */
.hl-chip {
	flex-shrink: 0;
	padding: 0.2rem 0.5rem;
	font-size: 0.72rem;
	font-weight: 600;
	line-height: 1;
	color: var(--text-color-soft);
	border: 1px solid var(--border-color);
	border-radius: 999px;
	font-variant-numeric: tabular-nums;
}

.hl-sport-hours {
	flex-shrink: 0;
	margin-left: auto;
	font-size: 0.9rem;
	font-variant-numeric: tabular-nums;
}

.hl-track {
	display: block;
	height: 4px;
	margin: 0.5rem 0 0 1.6rem;
	background: var(--hl-faint);
	border-radius: 999px;
}

.hl-track > span {
	display: block;
	height: 100%;
	background: var(--text-color);
	border-radius: inherit;
}

.hl-track-sm {
	width: 3rem;
	margin: 0;
}

.hl-track-sm > .hl-bg-strain { background: var(--hl-strain); }

.hl-more summary {
	display: inline-flex;
	margin-top: 1rem;
	padding: 0.32rem 0.75rem;
	font-size: 0.8rem;
	font-weight: 700;
	color: var(--text-color);
	border: 1px solid var(--border-color);
	border-radius: 999px;
	list-style: none;
	cursor: pointer;
}

.hl-more summary::-webkit-details-marker { display: none; }
.hl-more summary:hover { background: var(--surface-color-hover); }

.hl-more[open] summary { margin-bottom: 1rem; }
.hl-more .hl-when-open,
.hl-more[open] .hl-when-closed { display: none; }
.hl-more[open] .hl-when-open { display: inline; }

/* Recent activities */
.hl-timeline { position: relative; }

.hl-timeline::before {
	content: "";
	position: absolute;
	top: 0.75rem;
	bottom: 1.5rem;
	left: 1.125rem;
	width: 1px;
	background: var(--border-color);
}

.hl-day {
	position: relative;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	height: 1.75rem;
	margin: 0;
	font-size: 0.75rem;
	color: var(--hl-muted);
}

.hl-day-dot {
	display: flex;
	justify-content: center;
	width: 2.25rem;
}

.hl-day-dot::before {
	content: "";
	width: 0.375rem;
	height: 0.375rem;
	border-radius: 999px;
	background: var(--hl-muted);
	box-shadow: 0 0 0 4px var(--surface-color);
}

.hl-activity {
	position: relative;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.35rem 0;
}

.hl-badge {
	display: grid;
	place-items: center;
	flex-shrink: 0;
	width: 2.25rem;
	height: 2.25rem;
	background: var(--surface-color);
	border: 1px solid var(--border-color);
	border-radius: 999px;
}

.hl-activity-text {
	flex: 1;
	min-width: 0;
}

.hl-activity-text p {
	margin: 0;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.hl-activity-text p:first-child {
	font-size: 0.9rem;
	font-weight: 700;
}

.hl-activity-text p:last-child {
	font-size: 0.75rem;
	color: var(--hl-muted);
	font-variant-numeric: tabular-nums;
}

.hl-strain {
	display: flex;
	flex-shrink: 0;
	align-items: center;
	gap: 0.8rem;
}

.hl-strain-value {
	width: 2rem;
	font-size: 0.9rem;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

/* --- Phones ------------------------------------------------------------- */

@media (max-width: 34em) {
	.hl-wide-only { display: none; }
	.hl-phone-only { display: inline; }
	.hl-stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.hl-heatmap { grid-template-columns: auto repeat(var(--phone-weeks), minmax(0, 1fr)); }
	.hl-card { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
	.hl-ring-value { animation: none; }
}
