/* Keyboard shortcuts drawer. It is the frame's colour and grows out of the
   content panel's bottom-left corner, with concave fillets where it meets the
   frame. Its shadow comes from a silhouette inside the panel's frame shade
   (layout.css), so the frame and drawer cast one continuous shadow. Motion
   uses the Material 3 expressive springs Caelestia uses: the fast spatial
   spring as the tab swells, and the default spatial spring as the sheet opens
   and as it settles back into the tab, after the content has faded. The size
   and motion variables live on the root, shared by drawer and silhouette. */
:root {
	--shortcuts-w: 0px;
	--shortcuts-h: 0px;
	--shortcuts-radius: 0px;
	--shortcuts-fillet: 0px;
	--shortcuts-move: 500ms cubic-bezier(0.38, 1.21, 0.22, 1) 70ms;
}

/* Closed, the drawer rests as a tab; hovering swells it before it opens. */
html[data-shortcuts="closed"] {
	--shortcuts-w: 84px;
	--shortcuts-h: 44px;
	--shortcuts-radius: 16px;
	--shortcuts-fillet: 16px;
}

html[data-shortcuts="hover"] {
	--shortcuts-w: 92px;
	--shortcuts-h: 48px;
	--shortcuts-radius: 18px;
	--shortcuts-fillet: 18px;
	--shortcuts-move: 350ms cubic-bezier(0.42, 1.67, 0.21, 0.9);
}

html[data-shortcuts="open"] {
	--shortcuts-w: var(--shortcuts-open-width);
	--shortcuts-h: var(--shortcuts-open-height);
	--shortcuts-radius: 28px;
	--shortcuts-fillet: 28px;
	--shortcuts-move: 500ms cubic-bezier(0.38, 1.21, 0.22, 1);
}

.shortcuts {
	position: fixed;
	left: var(--shortcuts-anchor-left);
	bottom: var(--shortcuts-anchor-bottom);
	z-index: 1000;
	pointer-events: none;
}

.shortcuts-shape,
.shortcuts-shade {
	width: var(--shortcuts-w);
	height: var(--shortcuts-h);
	transition: width var(--shortcuts-move), height var(--shortcuts-move);
}

.shortcuts-shape {
	position: relative;
}

/* The drawer's stand-in inside the panel's frame shade: invisible under the
   drawer, it gives the shared shadow the drawer's outline. */
.shortcuts-shade {
	position: absolute;
	left: 0;
	bottom: 0;
	background: var(--frame);
	border-top-right-radius: var(--shortcuts-radius);
	transition: width var(--shortcuts-move), height var(--shortcuts-move), border-radius var(--shortcuts-move);
}

.shortcuts-body {
	position: absolute;
	inset: 0;
	overflow: hidden;
	background: var(--frame);
	border-top-right-radius: var(--shortcuts-radius);
	transition: border-radius var(--shortcuts-move);
}

.shortcuts:not([data-state="hidden"]) .shortcuts-body {
	pointer-events: auto;
}

.shortcuts-fillet {
	position: absolute;
	width: var(--shortcuts-fillet);
	height: var(--shortcuts-fillet);
	/* The curve's anti-aliasing straddles its true edge, meeting the drawer's
	   straight edges without a step. */
	background: radial-gradient(circle farthest-side at 100% 0, transparent calc(100% - 0.5px), var(--frame) calc(100% + 0.5px));
	transition: width var(--shortcuts-move), height var(--shortcuts-move), opacity 200ms ease;
}

.shortcuts-fillet.top {
	left: 0;
	bottom: 100%;
}

.shortcuts-fillet.side {
	left: 100%;
	bottom: 0;
}

/* Over an open viewer the drawer has no frame to join, so it floats with a
   shadow of its own. */
html.no-scroll .shortcuts-shape {
	filter: drop-shadow(0 0 15px var(--frame-shadow));
}

html.no-scroll .shortcuts .shortcuts-fillet {
	opacity: 0;
}

html.no-scroll .shortcuts-body {
	border-radius: var(--shortcuts-radius);
}

/* The tab keeps its resting size while the shape swells and opens around it,
   so the icon and "?" key never shift by fractions of a pixel. */
.shortcuts-tab {
	position: absolute;
	left: 0;
	bottom: 0;
	width: 84px;
	height: 44px;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--s2);
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--accent);
	/* Back in the tab, its contents return as the sheet settles. */
	transition: opacity 180ms cubic-bezier(0.34, 0.8, 0.34, 1) 340ms;
}

.shortcuts:is([data-state="open"], [data-state="hidden"]) .shortcuts-tab {
	opacity: 0;
	transition: opacity 90ms ease;
}

.shortcuts-tab:focus-visible {
	outline-offset: -6px;
	border-radius: 12px;
}

.shortcuts-tab > svg {
	width: 20px;
	height: 20px;
}

.shortcuts-sheet {
	position: absolute;
	left: 0;
	bottom: 0;
	width: min(880px, calc(var(--shortcuts-panel-width) - 72px));
	max-height: calc(var(--shortcuts-panel-height) - 48px);
	overflow-y: auto;
	padding: var(--s5) var(--s5) var(--s3) var(--s3);
}

/* Content arrives after the sheet has mostly opened, column by column and
   row by row, and leaves at once. The fade is here; shortcuts.js springs each
   row in from a small offset, snapped to whole device pixels so keycap
   borders never land between pixels and sharpen when the motion stops.
   --delay is set per row by shortcuts.js, which times the spring by it too. */
:is(.shortcuts-head, .shortcuts-section h3, .shortcut) {
	opacity: 0;
	transition: opacity 70ms ease;
}

.shortcuts[data-state="open"] :is(.shortcuts-head, .shortcuts-section h3, .shortcut) {
	opacity: 1;
	transition: opacity 240ms cubic-bezier(0.34, 0.8, 0.34, 1) var(--delay);
}

.shortcuts-head {
	display: flex;
	align-items: center;
	gap: var(--s4);
}

.shortcuts-title {
	margin: 0;
	font-size: 13px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--accent);
}

/* The status line holds the hint and, while keys are pressed, the live
   combination (shortcuts.js); the two cross over in place, so the header
   never changes height. */
.shortcuts-status {
	position: relative;
	flex: 1;
	display: grid;
	min-height: 22px;
	margin: 0;
	font-size: 12px;
	color: var(--muted);
}

.shortcuts-hint,
.shortcuts-combo {
	grid-area: 1 / 1;
	display: flex;
	align-items: center;
	gap: 3px;
	white-space: nowrap;
	transition:
		opacity 150ms cubic-bezier(0.34, 0.8, 0.34, 1),
		translate 350ms cubic-bezier(0.42, 1.67, 0.21, 0.9);
}

.shortcuts-combo {
	opacity: 0;
	translate: 0 4px;
}

.shortcuts-status[data-showing="combo"] .shortcuts-combo {
	opacity: 1;
	translate: 0 0;
}

.shortcuts-status[data-showing="combo"] .shortcuts-hint {
	opacity: 0;
	translate: 0 -4px;
}

.shortcuts-then {
	margin: 0 4px;
	color: var(--muted);
}

.shortcuts-arrow {
	display: inline-flex;
	margin: 0 4px;
	color: var(--accent);
}

.shortcuts-arrow svg {
	width: 14px;
	height: 14px;
}

.shortcuts-does {
	color: var(--accent);
	animation: comboNamed 350ms cubic-bezier(0.42, 1.67, 0.21, 0.9);
}

@keyframes comboNamed {
	from {
		opacity: 0;
		translate: -4px 0;
	}
}

/* The row the combination makes lights up; a sequence begun arms every
   row it could finish. */
.shortcut {
	position: relative;
}

.shortcut::before {
	content: "";
	position: absolute;
	inset: 0 -6px;
	border-radius: 6px;
	background: var(--accent);
	opacity: 0;
	transition: opacity 400ms cubic-bezier(0.34, 0.8, 0.34, 1);
	pointer-events: none;
}

.shortcut.armed::before {
	opacity: 0.06;
	transition-duration: 150ms;
}

.shortcut.matched::before {
	opacity: 0.14;
	transition-duration: 80ms;
}

.shortcut.matched dd {
	color: var(--accent);
}

.shortcut dd {
	transition: color 200ms cubic-bezier(0.34, 0.8, 0.34, 1);
}

/* The close button is an .icon-button (icon-button.css); negative margins
   keep the header row at the icon's height. */
.shortcuts-close {
	margin: -8px -8px -8px 0;
}

.shortcuts-sections {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
	gap: var(--s4) var(--s6);
	margin-top: var(--s4);
}

.shortcuts-section h3 {
	margin: 0 0 var(--s2);
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--muted);
}

/* Rows share their section's columns, so the keys column fits its widest
   entry and every description lines up. */
.shortcuts-section dl {
	display: grid;
	grid-template-columns: max-content 1fr;
	column-gap: var(--s3);
	margin: 0;
}

.shortcut {
	display: grid;
	grid-column: 1 / -1;
	grid-template-columns: subgrid;
	align-items: center;
	min-height: 26px;
}

.shortcut dt {
	display: flex;
	align-items: center;
	gap: 3px;
}

.shortcut dd {
	margin: 0;
	font-size: 12px;
	color: var(--text);
}

.shortcut-join,
.shortcut-or {
	font-size: 11px;
	color: var(--muted);
}

.shortcut-or {
	margin: 0 2px;
}

.shortcuts kbd {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	font-family: var(--font-mono);
	font-size: 11px;
	line-height: 1;
	color: var(--text);
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 4px;
	box-shadow: 0 1px 0 var(--border);
}

.shortcuts kbd svg {
	width: 12px;
	height: 12px;
}

/* A keycap stays down while its key is held, taking the accent, and
   springs back up when it's let go. */
.shortcuts kbd {
	transition:
		translate 350ms cubic-bezier(0.42, 1.67, 0.21, 0.9),
		box-shadow 350ms cubic-bezier(0.42, 1.67, 0.21, 0.9),
		background-color 200ms cubic-bezier(0.34, 0.8, 0.34, 1),
		border-color 200ms cubic-bezier(0.34, 0.8, 0.34, 1),
		color 200ms cubic-bezier(0.34, 0.8, 0.34, 1);
}

.shortcuts kbd.held {
	translate: 0 1px;
	box-shadow: 0 0 0 var(--accent);
	background: color-mix(in oklab, var(--accent), var(--bg) 80%);
	border-color: var(--accent);
	color: var(--accent);
	transition-duration: 60ms;
}

/* The first frame shows the drawer where it is, without animating it in. */
html.shortcuts-instant :is(.shortcuts, .shortcuts *, .shortcuts-shade, .shortcuts-shade *) {
	transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
	:root,
	html[data-shortcuts] {
		--shortcuts-move: 0s;
	}

	.shortcuts :is(.shortcuts-head, .shortcuts-section h3, .shortcut, .shortcuts-tab),
	.shortcuts[data-state] :is(.shortcuts-head, .shortcuts-section h3, .shortcut, .shortcuts-tab) {
		transition: opacity 150ms ease;
	}

	.shortcuts kbd,
	.shortcuts kbd.held,
	.shortcuts-hint,
	.shortcuts-combo,
	.shortcut::before {
		transition-property: opacity, background-color, border-color, color;
	}

	.shortcuts-does {
		animation: none;
	}
}
