/**
 * Mobile tab bar and bottom sheets.
 *
 * The bar is a strip of the site's surface with a hairline rule on top, the
 * way a supplement label is ruled; the centre medallion is the capsule-and-leaf
 * "V" of the logo cut out of the primary button colour. Sheets are shared with
 * the reading dock (dock.css turns them into popovers on desktop).
 */

/* Layout tokens ------------------------------------------------------- */
:root {
	--mv-tabbar-h: 0px;
	--mv-tabbar-space: 0px;
	--mv-tabbar-rise: 17px;
	--mv-medal-bg: var(--mv-brand-deep);
	--mv-medal-fg: var(--mv-on-dark);
	--mv-tab-current-bg: color-mix(in oklab, var(--mv-brand) 15%, transparent);
	--mv-tab-current-fg: var(--mv-brand-deep);
	--mv-glass: color-mix(in oklab, var(--mv-surface) 90%, transparent);
	--mv-glass-line: var(--mv-border);
	--mv-glass-shadow: 0 -12px 34px oklch(0.22 0.045 238 / 0.08);
}

[data-theme="dark"] {
	--mv-medal-bg: var(--mv-hero-accent);
	--mv-medal-fg: var(--mv-bg);
	--mv-tab-current-bg: color-mix(in oklab, var(--mv-hero-accent) 15%, transparent);
	--mv-tab-current-fg: var(--mv-hero-accent);
	--mv-glass: color-mix(in oklab, var(--mv-surface-raised) 88%, transparent);
	--mv-glass-shadow: 0 -14px 40px oklch(0.05 0.02 236 / 0.55);
}

.mv-tabbar { display: none; }

@media (max-width: 1023px) {
	:root {
		--mv-tabbar-h: 64px;
		--mv-tabbar-space: calc(var(--mv-tabbar-h) + env(safe-area-inset-bottom, 0px));
		--afp-c-sheet-offset: var(--mv-tabbar-space);
	}

	/* Space reserved server-side, in the footer's own colour. */
	body.mv-has-tabbar::after {
		content: "";
		display: block;
		height: var(--mv-tabbar-space);
		background: var(--mv-footer-deep, var(--mv-footer-bg));
	}

	.mv-tabbar {
		position: fixed;
		inset-inline: 0;
		bottom: 0;
		z-index: 80;
		display: block;
		padding: 0 max(6px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(6px, env(safe-area-inset-left, 0px));
		border-top: 1px solid var(--mv-glass-line);
		background: var(--mv-glass);
		box-shadow: var(--mv-glass-shadow);
		-webkit-backdrop-filter: saturate(1.5) blur(18px);
		backdrop-filter: saturate(1.5) blur(18px);
		transition: transform var(--mv-dur) var(--mv-ease), opacity var(--mv-dur) var(--mv-ease);
	}

	/* The label's double rule, drawn once along the top edge. */
	.mv-tabbar::before {
		content: "";
		position: absolute;
		inset: 3px 0 auto;
		height: 1px;
		background: color-mix(in oklab, var(--mv-glass-line) 55%, transparent);
		pointer-events: none;
	}

	.mv-tabbar__list {
		display: flex;
		align-items: stretch;
		justify-content: space-between;
		gap: 2px;
		max-width: 620px;
		height: var(--mv-tabbar-h);
		margin: 0 auto;
		padding: 0;
		list-style: none;
	}

	.mv-tabbar__list > li {
		display: flex;
		flex: 1 1 0;
		min-width: max-content;
		margin: 0;
	}

	.mv-tabbar__tab {
		position: relative;
		display: flex;
		flex: 1;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		gap: 3px;
		min-width: max-content;
		min-height: 48px;
		padding: 6px 2px 5px;
		border-radius: 14px;
		color: var(--mv-text-muted);
		font-family: var(--mv-font-body);
		font-size: 12px;
		font-weight: 650;
		letter-spacing: -0.005em;
		line-height: 1.1;
		text-decoration: none;
		-webkit-tap-highlight-color: transparent;
	}

	.mv-tabbar__tab:hover { color: var(--mv-text); }
	.mv-tabbar__tab:focus-visible { outline: 2px solid var(--mv-focus); outline-offset: -2px; }

	.mv-tabbar__label { white-space: nowrap; }

	.mv-tabbar__icon {
		position: relative;
		display: grid;
		place-items: center;
		width: 52px;
		height: 30px;
		border-radius: var(--mv-radius-pill);
		transition: background-color var(--mv-dur) var(--mv-ease), color var(--mv-dur) var(--mv-ease);
	}

	.mv-tabbar__tab[aria-current="page"] { color: var(--mv-text); }
	.mv-tabbar__tab[aria-current="page"] .mv-tabbar__icon {
		background: var(--mv-tab-current-bg);
		color: var(--mv-tab-current-fg);
	}
	.mv-tabbar__tab[aria-current="page"] .mv-tabbar__icon .mv-icon { stroke-width: 2.1; }
	.mv-tabbar__tab[aria-expanded="true"] .mv-tabbar__icon { background: var(--mv-interactive-hover); color: var(--mv-text); }

	.mv-tabbar__icon--avatar img {
		width: 26px;
		height: 26px;
		border-radius: 50%;
		object-fit: cover;
		box-shadow: 0 0 0 1.5px var(--mv-surface), 0 0 0 2.5px var(--mv-border-strong);
	}
	.mv-tabbar__tab[aria-current="page"] .mv-tabbar__icon--avatar img { box-shadow: 0 0 0 1.5px var(--mv-surface), 0 0 0 3px var(--mv-tab-current-fg); }

	.mv-tabbar__badge {
		position: absolute;
		top: -3px;
		right: 6px;
		min-width: 18px;
		height: 18px;
		padding: 0 5px;
		border: 2px solid var(--mv-surface);
		border-radius: var(--mv-radius-pill);
		background: var(--mv-danger);
		color: #fff;
		font-size: 10.5px;
		font-weight: 800;
		line-height: 14px;
		text-align: center;
	}

	/* Centre medallion ----------------------------------------------------- */
	.mv-tabbar__tab--center { gap: 2px; padding-top: 0; }

	.mv-tabbar__medal {
		position: relative;
		display: grid;
		place-items: center;
		width: 56px;
		height: 56px;
		margin-top: -22px;
		border-radius: 50%;
		background: var(--mv-medal-bg);
		color: var(--mv-medal-fg);
		box-shadow:
			0 0 0 4px var(--mv-surface),
			0 12px 26px color-mix(in oklab, var(--mv-medal-bg) 34%, transparent);
		transition: transform var(--mv-dur) var(--mv-ease);
	}

	/* A second, finer ring: the capsule's printed edge. */
	.mv-tabbar__medal::after {
		content: "";
		position: absolute;
		inset: 4px;
		border: 1px solid color-mix(in oklab, var(--mv-medal-fg) 32%, transparent);
		border-radius: 50%;
		pointer-events: none;
	}

	.mv-tabbar__emblem {
		width: 32px;
		height: 32px;
		background: currentColor;
		-webkit-mask: var(--mv-emblem) center / contain no-repeat;
		mask: var(--mv-emblem) center / contain no-repeat;
	}

	.mv-tabbar__medal.is-member::before {
		content: "";
		position: absolute;
		top: 1px;
		right: 1px;
		width: 13px;
		height: 13px;
		border: 2px solid var(--mv-surface);
		border-radius: 50%;
		background: var(--mv-success);
	}

	.mv-tabbar__tab--center:active .mv-tabbar__medal { transform: scale(0.96); }
	.mv-tabbar__tab--center[aria-current="page"] { color: var(--mv-text); }
	.mv-tabbar__tab--center[aria-current="page"] .mv-tabbar__medal { box-shadow: 0 0 0 4px var(--mv-surface), 0 0 0 6px var(--mv-tab-current-fg), 0 12px 26px color-mix(in oklab, var(--mv-medal-bg) 34%, transparent); }

	/* Smallest phones: five labels side by side without clipping. */
	@media (max-width: 359px) {
		.mv-tabbar { padding-inline: max(4px, env(safe-area-inset-left, 0px)); }
		.mv-tabbar__list { gap: 0; }
		.mv-tabbar__list > li { flex: 1 1 auto; }
		.mv-tabbar__tab { padding-inline: 0; letter-spacing: -0.015em; }
		.mv-tabbar__icon { width: 44px; }
	}

	/* Typing: the virtual keyboard owns the bottom of the screen. */
	html.mv-typing .mv-tabbar { transform: translateY(110%); opacity: 0; pointer-events: none; }

	/* Third-party floats sit above the bar, never under it. */
	body.mv-has-tabbar #consentpilot-floating-btn { bottom: calc(var(--mv-tabbar-space) + var(--mv-tabbar-rise) + 12px); }
	body.mv-has-tabbar .mv-article-toolbar__menu,
	body.mv-has-tabbar .mv-discussion-message__report form { bottom: calc(var(--mv-tabbar-space) + 12px); z-index: 90; }
}

/* While a sheet is open: no background scroll, no floating extras. */
html.mv-sheet-open,
html.mv-sheet-open body { overflow: hidden; }
html.mv-sheet-open #consentpilot-floating-btn,
html.mv-sheet-open .afp-sheet { visibility: hidden; }

/* Consent floating button, in the site's surface and accent in both modes. */
#consentpilot-floating-btn {
	border-color: var(--mv-border-strong);
	background: var(--mv-surface-raised);
	color: var(--mv-tab-current-fg);
	box-shadow: var(--mv-shadow-sm);
}

/* Sheets --------------------------------------------------------------- */
.mv-sheet {
	position: fixed;
	inset: 0;
	z-index: 1050;
}
.mv-sheet[hidden] { display: none; }

.mv-sheet__scrim {
	position: absolute;
	inset: 0;
	background: var(--mv-overlay-soft);
	opacity: 0;
	transition: opacity var(--mv-dur) var(--mv-ease);
}

.mv-sheet__panel {
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	max-height: min(86svh, 760px);
	border-top: 1px solid var(--mv-border);
	border-radius: 24px 24px 0 0;
	background: var(--mv-surface-raised);
	color: var(--mv-text);
	box-shadow: var(--mv-shadow);
	transform: translateY(104%);
	transition: transform 360ms var(--mv-ease);
	outline: 0;
}

.mv-sheet.is-open .mv-sheet__scrim { opacity: 1; }
.mv-sheet.is-open .mv-sheet__panel { transform: none; }

@media (min-width: 600px) {
	.mv-sheet__panel {
		left: 50%;
		right: auto;
		width: min(560px, calc(100% - 32px));
		translate: -50% 0;
	}
}

.mv-sheet__grip {
	flex: none;
	width: 40px;
	height: 4px;
	margin: 8px auto 0;
	border-radius: var(--mv-radius-pill);
	background: var(--mv-border-strong);
}

.mv-sheet__head {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 14px 10px 20px;
	border-bottom: 1px solid var(--mv-border);
}

.mv-sheet__title {
	margin: 0;
	font-family: var(--mv-font-heading);
	font-size: 1.15rem;
	font-weight: 780;
	letter-spacing: -0.02em;
	line-height: 1.2;
}

.mv-sheet__close {
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--mv-text-muted);
	cursor: pointer;
}
.mv-sheet__close:hover { background: var(--mv-interactive-hover); color: var(--mv-text); }

.mv-sheet__body {
	flex: 1 1 auto;
	min-height: 0;
	padding: 16px 20px calc(20px + env(safe-area-inset-bottom, 0px));
	overflow-y: auto;
	overscroll-behavior: contain;
}

.mv-sheet__kicker {
	margin: 20px 0 10px;
	color: var(--mv-text-muted);
	font-size: 0.72rem;
	font-weight: 750;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

.mv-sheet__lede { margin: 0 0 12px; color: var(--mv-text-muted); font-size: 0.86rem; }

/* Explore: search */
.mv-sheet-search {
	position: relative;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 5px 5px 5px 14px;
	border: 1px solid var(--mv-search-border);
	border-radius: var(--mv-radius-pill);
	background: var(--mv-search-bg);
}
.mv-sheet-search:focus-within { box-shadow: 0 0 0 4px var(--mv-search-ring); border-color: var(--mv-focus); }
.mv-sheet-search__icon { flex: none; color: var(--mv-text-muted); }
.mv-sheet-search input {
	flex: 1;
	min-width: 0;
	min-height: 40px;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--mv-text);
	font: inherit;
	font-size: 16px;
	outline: 0;
}
.mv-sheet-search input::placeholder { color: var(--mv-text-muted); opacity: 1; }
.mv-sheet-search button {
	flex: none;
	min-height: 40px;
	padding: 0 16px;
	border: 0;
	border-radius: var(--mv-radius-pill);
	background: var(--mv-search-button);
	color: var(--mv-on-dark);
	font: inherit;
	font-size: 0.9rem;
	font-weight: 750;
	cursor: pointer;
}
[data-theme="dark"] .mv-sheet-search button { background: var(--mv-hero-accent); color: var(--mv-bg); }

/* Explore: universes */
.mv-sheet-universes { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.mv-sheet-universes a {
	position: relative;
	display: grid;
	grid-template-columns: 56px minmax(0, 1fr) auto;
	align-items: center;
	gap: 14px;
	min-height: 72px;
	padding: 8px 12px 8px 8px;
	overflow: hidden;
	border: 1px solid var(--mv-border);
	border-radius: var(--mv-radius-md);
	background: var(--mv-surface);
	color: var(--mv-text);
	text-decoration: none;
}
.mv-sheet-universes a::before {
	content: "";
	position: absolute;
	inset-block: 12px;
	inset-inline-start: 0;
	width: 3px;
	border-radius: 0 3px 3px 0;
	background: var(--mv-silo);
}
.mv-sheet-universes a:hover { border-color: var(--mv-silo-line); background: var(--mv-silo-soft); }
.mv-sheet-universes__media {
	display: grid;
	place-items: center;
	width: 56px;
	height: 56px;
	overflow: hidden;
	border-radius: 14px;
	background: var(--mv-silo-soft);
	color: var(--mv-silo-text);
}
.mv-sheet-universes__media img { width: 100%; height: 100%; object-fit: cover; }
.mv-sheet-universes__text { display: grid; gap: 2px; min-width: 0; }
.mv-sheet-universes__text strong { font-size: 0.98rem; font-weight: 750; line-height: 1.25; }
.mv-sheet-universes__text small { color: var(--mv-silo-text); font-size: 0.8rem; font-weight: 650; }
.mv-sheet-universes__go { color: var(--mv-text-muted); }

/* Explore: quick links */
.mv-sheet-quick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.mv-sheet-quick a {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 52px;
	padding: 10px 12px;
	border: 1px solid var(--mv-border);
	border-radius: var(--mv-radius-sm);
	background: var(--mv-surface);
	color: var(--mv-text);
	font-size: 0.92rem;
	font-weight: 700;
	line-height: 1.2;
	text-decoration: none;
}
.mv-sheet-quick a .mv-icon { flex: none; color: var(--mv-tab-current-fg); }
.mv-sheet-quick a:hover { background: var(--mv-interactive-hover); }

/* Account */
.mv-sheet-identity {
	display: grid;
	grid-template-columns: 48px minmax(0, 1fr) auto;
	align-items: center;
	gap: 12px;
	padding: 10px 12px;
	border: 1px solid var(--mv-border);
	border-radius: var(--mv-radius-md);
	background: var(--mv-surface);
	color: var(--mv-text);
	text-decoration: none;
}
.mv-sheet-identity img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.mv-sheet-identity span { display: grid; gap: 2px; min-width: 0; }
.mv-sheet-identity strong { overflow: hidden; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.mv-sheet-identity small { color: var(--mv-text-muted); font-size: 0.82rem; }

.mv-sheet-links { display: grid; gap: 2px; margin: 12px 0 0; padding: 0; list-style: none; }
.mv-sheet-links :is(a, button) {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	min-height: 48px;
	padding: 10px 12px;
	border: 0;
	border-radius: var(--mv-radius-sm);
	background: transparent;
	color: var(--mv-text);
	font: inherit;
	font-size: 0.96rem;
	font-weight: 650;
	text-align: start;
	text-decoration: none;
	cursor: pointer;
}
.mv-sheet-links :is(a, button):hover { background: var(--mv-interactive-hover); }
.mv-sheet-links :is(a, button) > .mv-icon { flex: none; color: var(--mv-text-muted); }
.mv-sheet-links :is(a, button) > span:not(.mv-sheet-links__count) { flex: 1; }
.mv-sheet-links__count {
	min-width: 24px;
	padding: 2px 8px;
	border-radius: var(--mv-radius-pill);
	background: var(--mv-tab-current-bg);
	color: var(--mv-tab-current-fg);
	font-size: 0.78rem;
	font-weight: 800;
	text-align: center;
}

.mv-sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--mv-border); }
.mv-sheet-foot__logout { color: var(--mv-text-muted); font-size: 0.9rem; font-weight: 650; }

@media (prefers-reduced-motion: reduce) {
	.mv-tabbar,
	.mv-tabbar__icon,
	.mv-tabbar__medal,
	.mv-sheet__scrim,
	.mv-sheet__panel { transition: none; }
}

@media print {
	.mv-tabbar,
	.mv-sheet { display: none !important; }
	body.mv-has-tabbar::after { display: none; }
}
